]>
git.saurik.com Git - wxWidgets.git/blob - src/generic/helpwxht.cpp
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: A help controller using the wxHTML classes
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"
43 #if !defined(__WINDOWS__) && !defined(__OS2__)
47 IMPLEMENT_CLASS(wxHelpControllerHtml
, wxHTMLHelpControllerBase
)
50 This class implements help via wxHTML.
51 It requires the name of a directory containing the documentation
52 and a file mapping numerical Section numbers to relative URLS.
55 class wxForceHtmlFilter
: public wxHtmlFilter
58 virtual wxString
ReadFile(const wxFSFile
& file
) const
60 wxInputStream
*s
= file
.GetStream();
64 if (s
== NULL
) return wxEmptyString
;
65 src
= new char[s
-> GetSize()+1];
66 src
[s
-> GetSize()] = 0;
67 s
-> Read(src
, s
-> GetSize());
73 virtual bool CanRead(const wxFSFile
& file
) const
75 wxString filename
= file
.GetLocation();
76 if(filename
.Length() >= 5 &&
78 filename
.Right(4).MakeUpper() == ".HTM" ||
79 filename
.Right(5).MakeUpper() == ".HTML"))
86 #define FRAME_WIDTH 500
87 #define FRAME_HEIGHT 400
88 #define LAYOUT_X_MARGIN 2
89 #define LAYOUT_Y_MARGIN 2
91 #define BUTTON_WIDTH 70
92 #define MAX_COMBO_ENTRIES 25
94 class wxHelpFrame
: public wxFrame
97 wxHelpFrame(wxWindow
*parent
, int id
, const wxString
&title
,
98 const wxPoint
&pos
, const wxSize
&size
,
99 wxHelpControllerHtml
*controller
);
101 void OnClose(wxCloseEvent
&ev
);
102 void OnButton(wxCommandEvent
&ev
);
103 bool LoadPage(const wxString
&url
) { return m_htmlwin
->LoadPage(url
); }
105 wxHelpControllerHtml
*m_controller
;
106 wxHtmlWindow
*m_htmlwin
;
107 wxHtmlFilter
*m_filter
;
109 long m_IdBack
, m_IdFwd
, m_IdContents
, m_IdCombo
, m_IdSearch
;
110 DECLARE_EVENT_TABLE()
113 BEGIN_EVENT_TABLE(wxHelpFrame
, wxFrame
)
114 EVT_CLOSE(wxHelpFrame::OnClose
)
115 EVT_BUTTON(-1, wxHelpFrame::OnButton
)
120 wxHelpFrame::OnButton(wxCommandEvent
&ev
)
125 m_htmlwin
->HistoryBack();
126 else if(id
== m_IdFwd
)
127 m_htmlwin
->HistoryForward();
128 else if(id
== m_IdContents
)
129 m_controller
->DisplayContents();
130 else if(id
== m_IdSearch
)
132 wxString str
= m_combo
->GetValue();
133 if(m_combo
->FindString(str
) == -1 && m_combo
->Number() < MAX_COMBO_ENTRIES
)
134 m_combo
->Append(str
);
135 m_controller
->KeywordSearch(str
);
139 wxHelpFrame::wxHelpFrame(wxWindow
*parent
, int id
,
140 const wxString
&title
,
141 const wxPoint
&pos
, const wxSize
&size
,
142 wxHelpControllerHtml
*controller
)
143 : wxFrame(parent
, id
, title
, pos
, size
)
146 m_controller
= controller
;
147 m_htmlwin
= new wxHtmlWindow(this,-1,wxDefaultPosition
,wxSize(FRAME_WIDTH
,
150 m_IdBack
= wxWindow::NewControlId();
151 m_IdFwd
= wxWindow::NewControlId();
152 m_IdContents
= wxWindow::NewControlId();
153 m_IdCombo
= wxWindow::NewControlId();
154 m_IdSearch
= wxWindow::NewControlId();
156 wxButton
*btn_back
= new wxButton(this, m_IdBack
, _("Back"));
157 wxButton
*btn_fwd
= new wxButton(this, m_IdFwd
, _("Forward"));
158 wxButton
*btn_contents
= new wxButton(this, m_IdContents
, _("Contents"));
159 m_combo
= new wxComboBox(this, m_IdCombo
);
160 wxButton
*btn_search
= new wxButton(this, m_IdSearch
, _("Search"));
162 m_filter
= new wxForceHtmlFilter
;
164 wxLayoutConstraints
*c
;
166 c
= new wxLayoutConstraints
;
167 c
->left
.SameAs(this, wxLeft
, 2*LAYOUT_X_MARGIN
);
168 c
->width
.Absolute(BUTTON_WIDTH
);
169 c
->top
.SameAs(this, wxTop
, 2*LAYOUT_Y_MARGIN
);
171 btn_back
->SetConstraints(c
);
173 c
= new wxLayoutConstraints
;
174 c
->left
.SameAs(btn_back
, wxRight
, 2*LAYOUT_X_MARGIN
);
175 c
->width
.Absolute(BUTTON_WIDTH
);
176 c
->top
.SameAs(this, wxTop
, 2*LAYOUT_Y_MARGIN
);
178 btn_fwd
->SetConstraints(c
);
180 c
= new wxLayoutConstraints
;
181 c
->left
.SameAs(btn_fwd
, wxRight
, 2*LAYOUT_X_MARGIN
);
182 c
->width
.Absolute(BUTTON_WIDTH
);
183 c
->top
.SameAs(this, wxTop
, 2*LAYOUT_Y_MARGIN
);
185 btn_contents
->SetConstraints(c
);
187 c
= new wxLayoutConstraints
;
188 c
->left
.SameAs(btn_contents
, wxRight
, 2*LAYOUT_X_MARGIN
);
189 c
->width
.Absolute(3*BUTTON_WIDTH
);
190 c
->top
.SameAs(this, wxTop
, 2*LAYOUT_Y_MARGIN
);
192 m_combo
->SetConstraints(c
);
194 c
= new wxLayoutConstraints
;
195 c
->left
.SameAs(m_combo
, wxRight
, 2*LAYOUT_X_MARGIN
);
196 c
->width
.Absolute(BUTTON_WIDTH
);
197 c
->top
.SameAs(this, wxTop
, 2*LAYOUT_Y_MARGIN
);
199 btn_search
->SetConstraints(c
);
202 c
= new wxLayoutConstraints
;
203 c
->left
.SameAs(this, wxLeft
, 2*LAYOUT_X_MARGIN
);
204 c
->right
.SameAs(this, wxRight
, 2*LAYOUT_X_MARGIN
);
205 c
->top
.SameAs(btn_back
, wxBottom
, 2*LAYOUT_Y_MARGIN
);
206 c
->bottom
.SameAs(this, wxBottom
, 2*LAYOUT_Y_MARGIN
);
207 m_htmlwin
->SetConstraints(c
);
211 m_htmlwin
->SetRelatedFrame(this, title
);
212 m_htmlwin
->SetRelatedStatusBar(0);
213 m_htmlwin
->AddFilter(m_filter
);
216 // Motif needs a nudge to get it to resize properly
218 wxSizeEvent
event(size
, GetId());
219 GetEventHandler()->ProcessEvent(event
);
225 wxHelpFrame::~wxHelpFrame()
230 wxHelpFrame::OnClose(wxCloseEvent
&WXUNUSED(ev
))
232 wxASSERT(m_controller
);
233 m_controller
->m_Frame
= NULL
;
238 m_controller
->GetFrameParameters(NULL
, NULL
, &newFrame
);
239 m_controller
->SetFrameParameters(GetTitle(), GetSize(),
245 wxHelpControllerHtml::wxHelpControllerHtml(void)
250 SetFrameParameters(_("Help: %s"),
251 wxSize(FRAME_WIDTH
, FRAME_HEIGHT
),
255 wxHelpControllerHtml::~wxHelpControllerHtml(void)
257 if(m_Frame
&& ! m_NewFrameEachTime
)
269 wxHelpControllerHtml::DisplayHelp(wxString
const &relativeURL
)
271 wxBusyCursor b
; // display a busy cursor
274 url
<< m_MapFile
<< SEP
<< relativeURL
;
275 if(! m_Frame
|| m_NewFrameEachTime
)
277 m_Frame
= new wxHelpFrame(NULL
, -1, m_FrameTitle
,
278 m_FramePosition
+wxPoint(m_offset
,m_offset
),
281 if(m_NewFrameEachTime
)
290 return m_Frame
->LoadPage(url
);
295 wxHelpControllerHtml::SetFrameParameters(const wxString
&title
,
300 m_FrameTitle
= title
;
302 m_FramePosition
= pos
;
303 m_NewFrameEachTime
= newFrame
;
307 wxHelpControllerHtml::GetFrameParameters(wxSize
*size
,
311 if(size
) *size
= m_FrameSize
;
312 if(pos
) *pos
= m_FramePosition
;
313 if(newframe
) *newframe
= m_NewFrameEachTime
;