]>
git.saurik.com Git - wxWidgets.git/blob - src/generic/helpwxht.cpp
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: an external help controller for wxWindows
4 // Author: Karsten Ballueder
8 // Copyright: (c) Karsten Ballueder
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
13 # pragma implementation "helpwxht.h"
16 #include "wx/wxprec.h"
25 # include "wx/string.h"
26 # include "wx/utils.h"
29 # include "wx/layout.h"
30 # include "wx/combobox.h"
33 #include "wx/helpbase.h"
34 #include "wx/generic/helpwxht.h"
35 #include "wx/html/htmlwin.h"
45 IMPLEMENT_CLASS(wxHelpControllerHtml
, wxHTMLHelpControllerBase
)
48 This class implements help via wxHTML.
49 It requires the name of a directory containing the documentation
50 and a file mapping numerical Section numbers to relative URLS.
53 class wxForceHtmlFilter
: public wxHtmlFilter
56 virtual wxString
ReadFile(const wxFSFile
& file
) const
58 wxInputStream
*s
= file
.GetStream();
62 if (s
== NULL
) return wxEmptyString
;
63 src
= new char[s
-> GetSize()+1];
64 src
[s
-> GetSize()] = 0;
65 s
-> Read(src
, s
-> GetSize());
71 virtual bool CanRead(const wxFSFile
& file
) const
73 wxString filename
= file
.GetLocation();
74 if(filename
.Length() >= 5 &&
76 filename
.Right(4).MakeUpper() == ".HTM" ||
77 filename
.Right(5).MakeUpper() == ".HTML"))
84 #define FRAME_WIDTH 500
85 #define FRAME_HEIGHT 400
86 #define LAYOUT_X_MARGIN 2
87 #define LAYOUT_Y_MARGIN 2
89 #define BUTTON_WIDTH 70
90 #define MAX_COMBO_ENTRIES 25
92 class wxHelpFrame
: public wxFrame
95 wxHelpFrame(wxWindow
*parent
, int id
, const wxString
&title
,
96 const wxPoint
&pos
, const wxSize
&size
,
97 wxHelpControllerHtml
*controller
);
99 void OnClose(wxCloseEvent
&ev
);
100 void OnButton(wxCommandEvent
&ev
);
101 bool LoadPage(const wxString
&url
) { return m_htmlwin
->LoadPage(url
); }
103 wxHelpControllerHtml
*m_controller
;
104 wxHtmlWindow
*m_htmlwin
;
105 wxHtmlFilter
*m_filter
;
107 long m_IdBack
, m_IdFwd
, m_IdContents
, m_IdCombo
, m_IdSearch
;
108 DECLARE_EVENT_TABLE()
111 BEGIN_EVENT_TABLE(wxHelpFrame
, wxFrame
)
112 EVT_CLOSE(wxHelpFrame::OnClose
)
113 EVT_BUTTON(-1, wxHelpFrame::OnButton
)
118 wxHelpFrame::OnButton(wxCommandEvent
&ev
)
123 m_htmlwin
->HistoryBack();
124 else if(id
== m_IdFwd
)
125 m_htmlwin
->HistoryForward();
126 else if(id
== m_IdContents
)
127 m_controller
->DisplayContents();
128 else if(id
== m_IdSearch
)
130 wxString str
= m_combo
->GetValue();
131 if(m_combo
->FindString(str
) == -1 && m_combo
->Number() < MAX_COMBO_ENTRIES
)
132 m_combo
->Append(str
);
133 m_controller
->KeywordSearch(str
);
137 wxHelpFrame::wxHelpFrame(wxWindow
*parent
, int id
,
138 const wxString
&title
,
139 const wxPoint
&pos
, const wxSize
&size
,
140 wxHelpControllerHtml
*controller
)
141 : wxFrame(parent
, id
, title
, pos
, size
)
144 m_controller
= controller
;
145 m_htmlwin
= new wxHtmlWindow(this,-1,wxDefaultPosition
,wxSize(FRAME_WIDTH
,
148 m_IdBack
= wxWindow::NewControlId();
149 m_IdFwd
= wxWindow::NewControlId();
150 m_IdContents
= wxWindow::NewControlId();
151 m_IdCombo
= wxWindow::NewControlId();
152 m_IdSearch
= wxWindow::NewControlId();
154 wxButton
*btn_back
= new wxButton(this, m_IdBack
, _("Back"));
155 wxButton
*btn_fwd
= new wxButton(this, m_IdFwd
, _("Forward"));
156 wxButton
*btn_contents
= new wxButton(this, m_IdContents
, _("Contents"));
157 m_combo
= new wxComboBox(this, m_IdCombo
);
158 wxButton
*btn_search
= new wxButton(this, m_IdSearch
, _("Search"));
160 m_filter
= new wxForceHtmlFilter
;
162 wxLayoutConstraints
*c
;
164 c
= new wxLayoutConstraints
;
165 c
->left
.SameAs(this, wxLeft
, 2*LAYOUT_X_MARGIN
);
166 c
->width
.Absolute(BUTTON_WIDTH
);
167 c
->top
.SameAs(this, wxTop
, 2*LAYOUT_Y_MARGIN
);
169 btn_back
->SetConstraints(c
);
171 c
= new wxLayoutConstraints
;
172 c
->left
.SameAs(btn_back
, wxRight
, 2*LAYOUT_X_MARGIN
);
173 c
->width
.Absolute(BUTTON_WIDTH
);
174 c
->top
.SameAs(this, wxTop
, 2*LAYOUT_Y_MARGIN
);
176 btn_fwd
->SetConstraints(c
);
178 c
= new wxLayoutConstraints
;
179 c
->left
.SameAs(btn_fwd
, wxRight
, 2*LAYOUT_X_MARGIN
);
180 c
->width
.Absolute(BUTTON_WIDTH
);
181 c
->top
.SameAs(this, wxTop
, 2*LAYOUT_Y_MARGIN
);
183 btn_contents
->SetConstraints(c
);
185 c
= new wxLayoutConstraints
;
186 c
->left
.SameAs(btn_contents
, wxRight
, 2*LAYOUT_X_MARGIN
);
187 c
->width
.Absolute(3*BUTTON_WIDTH
);
188 c
->top
.SameAs(this, wxTop
, 2*LAYOUT_Y_MARGIN
);
190 m_combo
->SetConstraints(c
);
192 c
= new wxLayoutConstraints
;
193 c
->left
.SameAs(m_combo
, wxRight
, 2*LAYOUT_X_MARGIN
);
194 c
->width
.Absolute(BUTTON_WIDTH
);
195 c
->top
.SameAs(this, wxTop
, 2*LAYOUT_Y_MARGIN
);
197 btn_search
->SetConstraints(c
);
200 c
= new wxLayoutConstraints
;
201 c
->left
.SameAs(this, wxLeft
, 2*LAYOUT_X_MARGIN
);
202 c
->right
.SameAs(this, wxRight
, 2*LAYOUT_X_MARGIN
);
203 c
->top
.SameAs(btn_back
, wxBottom
, 2*LAYOUT_Y_MARGIN
);
204 c
->bottom
.SameAs(this, wxBottom
, 2*LAYOUT_Y_MARGIN
);
205 m_htmlwin
->SetConstraints(c
);
209 m_htmlwin
->SetRelatedFrame(this, title
);
210 m_htmlwin
->SetRelatedStatusBar(0);
211 m_htmlwin
->AddFilter(m_filter
);
216 wxHelpFrame::~wxHelpFrame()
221 wxHelpFrame::OnClose(wxCloseEvent
&ev
)
223 wxASSERT(m_controller
);
224 m_controller
->m_Frame
= NULL
;
229 m_controller
->GetFrameParameters(NULL
, NULL
, &newFrame
);
230 m_controller
->SetFrameParameters(GetTitle(), GetSize(),
236 wxHelpControllerHtml::wxHelpControllerHtml(void)
241 SetFrameParameters(_("Help: %s"),
242 wxSize(FRAME_WIDTH
, FRAME_HEIGHT
),
246 wxHelpControllerHtml::~wxHelpControllerHtml(void)
248 if(m_Frame
&& ! m_NewFrameEachTime
)
260 wxHelpControllerHtml::DisplayHelp(wxString
const &relativeURL
)
262 wxBusyCursor b
; // display a busy cursor
265 url
<< m_MapFile
<< SEP
<< relativeURL
;
266 if(! m_Frame
|| m_NewFrameEachTime
)
268 m_Frame
= new wxHelpFrame(NULL
, -1, m_FrameTitle
,
269 m_FramePosition
+wxPoint(m_offset
,m_offset
),
272 if(m_NewFrameEachTime
)
281 return m_Frame
->LoadPage(url
);
286 wxHelpControllerHtml::SetFrameParameters(const wxString
&title
,
291 m_FrameTitle
= title
;
293 m_FramePosition
= pos
;
294 m_NewFrameEachTime
= newFrame
;
298 wxHelpControllerHtml::GetFrameParameters(wxSize
*size
,
302 if(size
) *size
= m_FrameSize
;
303 if(pos
) *pos
= m_FramePosition
;
304 if(newframe
) *newframe
= m_NewFrameEachTime
;