]>
git.saurik.com Git - wxWidgets.git/blob - src/generic/helpwxht.cpp
66e90901e2311788d672bb6c0ad20480b5c24f3e
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"
32 #include "wx/helpbase.h"
33 #include "wx/generic/helpwxht.h"
34 #include "wx/html/htmlwin.h"
44 IMPLEMENT_CLASS(wxHelpControllerHtml
, wxHTMLHelpControllerBase
)
47 This class implements help via wxHTML.
48 It requires the name of a directory containing the documentation
49 and a file mapping numerical Section numbers to relative URLS.
52 class wxForceHtmlFilter
: public wxHtmlFilter
55 virtual wxString
ReadFile(const wxFSFile
& file
)
57 wxInputStream
*s
= file
.GetStream();
61 if (s
== NULL
) return wxEmptyString
;
62 src
= new char[s
-> GetSize()+1];
63 src
[s
-> GetSize()] = 0;
64 s
-> Read(src
, s
-> GetSize());
70 virtual bool CanRead(const wxFSFile
& file
)
72 wxString filename
= file
.GetLocation();
73 if(filename
.Length() >= 5 &&
75 filename
.Right(4).MakeUpper() == ".HTM" ||
76 filename
.Right(5).MakeUpper() == ".HTML"))
83 #define FRAME_WIDTH 500
84 #define FRAME_HEIGHT 400
85 #define LAYOUT_X_MARGIN 2
86 #define LAYOUT_Y_MARGIN 2
88 #define BUTTON_WIDTH 70
89 #define MAX_COMBO_ENTRIES 25
91 class wxHelpFrame
: public wxFrame
94 wxHelpFrame(wxWindow
*parent
, int id
, const wxString
&title
,
95 const wxPoint
&pos
, const wxSize
&size
,
96 wxHelpControllerHtml
*controller
);
98 void OnClose(wxCloseEvent
&ev
);
99 void OnButton(wxCommandEvent
&ev
);
100 bool LoadPage(const wxString
&url
) { return m_htmlwin
->LoadPage(url
); }
102 wxHelpControllerHtml
*m_controller
;
103 wxHtmlWindow
*m_htmlwin
;
104 wxHtmlFilter
*m_filter
;
106 long m_IdBack
, m_IdFwd
, m_IdContents
, m_IdCombo
, m_IdSearch
;
107 DECLARE_EVENT_TABLE()
110 BEGIN_EVENT_TABLE(wxHelpFrame
, wxFrame
)
111 EVT_CLOSE(wxHelpFrame::OnClose
)
112 EVT_BUTTON(-1, wxHelpFrame::OnButton
)
117 wxHelpFrame::OnButton(wxCommandEvent
&ev
)
122 m_htmlwin
->HistoryBack();
123 else if(id
== m_IdFwd
)
124 m_htmlwin
->HistoryForward();
125 else if(id
== m_IdContents
)
126 m_controller
->DisplayContents();
127 else if(id
== m_IdSearch
)
129 wxString str
= m_combo
->GetValue();
130 if(m_combo
->FindString(str
) == -1 && m_combo
->Number() < MAX_COMBO_ENTRIES
)
131 m_combo
->Append(str
);
132 m_controller
->KeywordSearch(str
);
136 wxHelpFrame::wxHelpFrame(wxWindow
*parent
, int id
,
137 const wxString
&title
,
138 const wxPoint
&pos
, const wxSize
&size
,
139 wxHelpControllerHtml
*controller
)
140 : wxFrame(parent
, id
, title
, pos
, size
)
143 m_controller
= controller
;
144 m_htmlwin
= new wxHtmlWindow(this,-1,wxDefaultPosition
,wxSize(FRAME_WIDTH
,
147 m_IdBack
= wxWindow::NewControlId();
148 m_IdFwd
= wxWindow::NewControlId();
149 m_IdContents
= wxWindow::NewControlId();
150 m_IdCombo
= wxWindow::NewControlId();
151 m_IdSearch
= wxWindow::NewControlId();
153 wxButton
*btn_back
= new wxButton(this, m_IdBack
, _("Back"));
154 wxButton
*btn_fwd
= new wxButton(this, m_IdFwd
, _("Forward"));
155 wxButton
*btn_contents
= new wxButton(this, m_IdContents
, _("Contents"));
156 m_combo
= new wxComboBox(this, m_IdCombo
);
157 wxButton
*btn_search
= new wxButton(this, m_IdSearch
, _("Search"));
159 m_filter
= new wxForceHtmlFilter
;
161 wxLayoutConstraints
*c
;
163 c
= new wxLayoutConstraints
;
164 c
->left
.SameAs(this, wxLeft
, 2*LAYOUT_X_MARGIN
);
165 c
->width
.Absolute(BUTTON_WIDTH
);
166 c
->top
.SameAs(this, wxTop
, 2*LAYOUT_Y_MARGIN
);
168 btn_back
->SetConstraints(c
);
170 c
= new wxLayoutConstraints
;
171 c
->left
.SameAs(btn_back
, wxRight
, 2*LAYOUT_X_MARGIN
);
172 c
->width
.Absolute(BUTTON_WIDTH
);
173 c
->top
.SameAs(this, wxTop
, 2*LAYOUT_Y_MARGIN
);
175 btn_fwd
->SetConstraints(c
);
177 c
= new wxLayoutConstraints
;
178 c
->left
.SameAs(btn_fwd
, wxRight
, 2*LAYOUT_X_MARGIN
);
179 c
->width
.Absolute(BUTTON_WIDTH
);
180 c
->top
.SameAs(this, wxTop
, 2*LAYOUT_Y_MARGIN
);
182 btn_contents
->SetConstraints(c
);
184 c
= new wxLayoutConstraints
;
185 c
->left
.SameAs(btn_contents
, wxRight
, 2*LAYOUT_X_MARGIN
);
186 c
->width
.Absolute(3*BUTTON_WIDTH
);
187 c
->top
.SameAs(this, wxTop
, 2*LAYOUT_Y_MARGIN
);
189 m_combo
->SetConstraints(c
);
191 c
= new wxLayoutConstraints
;
192 c
->left
.SameAs(m_combo
, wxRight
, 2*LAYOUT_X_MARGIN
);
193 c
->width
.Absolute(BUTTON_WIDTH
);
194 c
->top
.SameAs(this, wxTop
, 2*LAYOUT_Y_MARGIN
);
196 btn_search
->SetConstraints(c
);
199 c
= new wxLayoutConstraints
;
200 c
->left
.SameAs(this, wxLeft
, 2*LAYOUT_X_MARGIN
);
201 c
->right
.SameAs(this, wxRight
, 2*LAYOUT_X_MARGIN
);
202 c
->top
.SameAs(btn_back
, wxBottom
, 2*LAYOUT_Y_MARGIN
);
203 c
->bottom
.SameAs(this, wxBottom
, 2*LAYOUT_Y_MARGIN
);
204 m_htmlwin
->SetConstraints(c
);
208 m_htmlwin
->SetRelatedFrame(this, title
);
209 m_htmlwin
->SetRelatedStatusBar(0);
210 m_htmlwin
->AddFilter(m_filter
);
215 wxHelpFrame::~wxHelpFrame()
220 wxHelpFrame::OnClose(wxCloseEvent
&ev
)
222 wxASSERT(m_controller
);
223 m_controller
->m_Frame
= NULL
;
228 m_controller
->GetFrameParameters(NULL
, NULL
, &newFrame
);
229 m_controller
->SetFrameParameters(GetTitle(), GetSize(),
235 wxHelpControllerHtml::wxHelpControllerHtml(void)
240 SetFrameParameters(_("Help: %s"),
241 wxSize(FRAME_WIDTH
, FRAME_HEIGHT
),
245 wxHelpControllerHtml::~wxHelpControllerHtml(void)
247 if(m_Frame
&& ! m_NewFrameEachTime
)
259 wxHelpControllerHtml::DisplayHelp(wxString
const &relativeURL
)
261 wxBusyCursor b
; // display a busy cursor
264 url
<< m_MapFile
<< SEP
<< relativeURL
;
265 if(! m_Frame
|| m_NewFrameEachTime
)
267 m_Frame
= new wxHelpFrame(NULL
, -1, m_FrameTitle
,
268 m_FramePosition
+wxPoint(m_offset
,m_offset
),
271 if(m_NewFrameEachTime
)
280 return m_Frame
->LoadPage(url
);
285 wxHelpControllerHtml::SetFrameParameters(const wxString
&title
,
290 m_FrameTitle
= title
;
292 m_FramePosition
= pos
;
293 m_NewFrameEachTime
= newFrame
;
297 wxHelpControllerHtml::GetFrameParameters(wxSize
*size
= NULL
,
299 bool *newframe
= NULL
)
301 if(size
) *size
= m_FrameSize
;
302 if(pos
) *pos
= m_FramePosition
;
303 if(newframe
) *newframe
= m_NewFrameEachTime
;