]>
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"
29 #include "wx/layout.h"
30 #include "wx/combobox.h"
31 #include "wx/button.h"
34 #include "wx/helpbase.h"
35 #include "wx/generic/helpwxht.h"
36 #include "wx/html/htmlwin.h"
44 #if !defined(__WINDOWS__) && !defined(__OS2__)
49 #include "wx/mac/private.h"
52 IMPLEMENT_CLASS(wxHelpControllerHtml
, wxHTMLHelpControllerBase
)
55 This class implements help via wxHTML.
56 It requires the name of a directory containing the documentation
57 and a file mapping numerical Section numbers to relative URLS.
60 class wxForceHtmlFilter
: public wxHtmlFilter
63 virtual wxString
ReadFile(const wxFSFile
& file
) const
65 wxInputStream
*s
= file
.GetStream();
69 if (s
== NULL
) return wxEmptyString
;
70 src
= new char[s
-> GetSize()+1];
71 src
[s
-> GetSize()] = 0;
72 s
-> Read(src
, s
-> GetSize());
78 virtual bool CanRead(const wxFSFile
& file
) const
80 wxString filename
= file
.GetLocation();
81 if(filename
.Length() >= 5 &&
83 filename
.Right(4).MakeUpper() == ".HTM" ||
84 filename
.Right(5).MakeUpper() == ".HTML"))
91 #define FRAME_WIDTH 500
92 #define FRAME_HEIGHT 400
93 #define LAYOUT_X_MARGIN 2
94 #define LAYOUT_Y_MARGIN 2
96 #define BUTTON_WIDTH 70
97 #define MAX_COMBO_ENTRIES 25
99 class wxHelpFrame
: public wxFrame
102 wxHelpFrame(wxWindow
*parent
, int id
, const wxString
&title
,
103 const wxPoint
&pos
, const wxSize
&size
,
104 wxHelpControllerHtml
*controller
);
106 void OnClose(wxCloseEvent
&ev
);
107 void OnButton(wxCommandEvent
&ev
);
108 bool LoadPage(const wxString
&url
) { return m_htmlwin
->LoadPage(url
); }
110 wxHelpControllerHtml
*m_controller
;
111 wxHtmlWindow
*m_htmlwin
;
112 wxHtmlFilter
*m_filter
;
114 long m_IdBack
, m_IdFwd
, m_IdContents
, m_IdCombo
, m_IdSearch
;
115 DECLARE_EVENT_TABLE()
118 BEGIN_EVENT_TABLE(wxHelpFrame
, wxFrame
)
119 EVT_CLOSE(wxHelpFrame::OnClose
)
120 EVT_BUTTON(-1, wxHelpFrame::OnButton
)
125 wxHelpFrame::OnButton(wxCommandEvent
&ev
)
130 m_htmlwin
->HistoryBack();
131 else if(id
== m_IdFwd
)
132 m_htmlwin
->HistoryForward();
133 else if(id
== m_IdContents
)
134 m_controller
->DisplayContents();
135 else if(id
== m_IdSearch
)
137 wxString str
= m_combo
->GetValue();
138 if(m_combo
->FindString(str
) == -1 && m_combo
->GetCount() < MAX_COMBO_ENTRIES
)
139 m_combo
->Append(str
);
140 m_controller
->KeywordSearch(str
);
144 wxHelpFrame::wxHelpFrame(wxWindow
*parent
, int id
,
145 const wxString
&title
,
146 const wxPoint
&pos
, const wxSize
&size
,
147 wxHelpControllerHtml
*controller
)
148 : wxFrame(parent
, id
, title
, pos
, size
)
151 m_controller
= controller
;
152 m_htmlwin
= new wxHtmlWindow(this,-1,wxDefaultPosition
,wxSize(FRAME_WIDTH
,
155 m_IdBack
= wxWindow::NewControlId();
156 m_IdFwd
= wxWindow::NewControlId();
157 m_IdContents
= wxWindow::NewControlId();
158 m_IdCombo
= wxWindow::NewControlId();
159 m_IdSearch
= wxWindow::NewControlId();
161 wxButton
*btn_back
= new wxButton(this, m_IdBack
, _("Back"));
162 wxButton
*btn_fwd
= new wxButton(this, m_IdFwd
, _("Forward"));
163 wxButton
*btn_contents
= new wxButton(this, m_IdContents
, _("Contents"));
164 m_combo
= new wxComboBox(this, m_IdCombo
);
165 wxButton
*btn_search
= new wxButton(this, m_IdSearch
, _("Search"));
167 m_filter
= new wxForceHtmlFilter
;
169 wxLayoutConstraints
*c
;
171 c
= new wxLayoutConstraints
;
172 c
->left
.SameAs(this, wxLeft
, 2*LAYOUT_X_MARGIN
);
173 c
->width
.Absolute(BUTTON_WIDTH
);
174 c
->top
.SameAs(this, wxTop
, 2*LAYOUT_Y_MARGIN
);
176 btn_back
->SetConstraints(c
);
178 c
= new wxLayoutConstraints
;
179 c
->left
.SameAs(btn_back
, wxRight
, 2*LAYOUT_X_MARGIN
);
180 c
->width
.Absolute(BUTTON_WIDTH
);
181 c
->top
.SameAs(this, wxTop
, 2*LAYOUT_Y_MARGIN
);
183 btn_fwd
->SetConstraints(c
);
185 c
= new wxLayoutConstraints
;
186 c
->left
.SameAs(btn_fwd
, wxRight
, 2*LAYOUT_X_MARGIN
);
187 c
->width
.Absolute(BUTTON_WIDTH
);
188 c
->top
.SameAs(this, wxTop
, 2*LAYOUT_Y_MARGIN
);
190 btn_contents
->SetConstraints(c
);
192 c
= new wxLayoutConstraints
;
193 c
->left
.SameAs(btn_contents
, wxRight
, 2*LAYOUT_X_MARGIN
);
194 c
->width
.Absolute(3*BUTTON_WIDTH
);
195 c
->top
.SameAs(this, wxTop
, 2*LAYOUT_Y_MARGIN
);
197 m_combo
->SetConstraints(c
);
199 c
= new wxLayoutConstraints
;
200 c
->left
.SameAs(m_combo
, wxRight
, 2*LAYOUT_X_MARGIN
);
201 c
->width
.Absolute(BUTTON_WIDTH
);
202 c
->top
.SameAs(this, wxTop
, 2*LAYOUT_Y_MARGIN
);
204 btn_search
->SetConstraints(c
);
207 c
= new wxLayoutConstraints
;
208 c
->left
.SameAs(this, wxLeft
, 2*LAYOUT_X_MARGIN
);
209 c
->right
.SameAs(this, wxRight
, 2*LAYOUT_X_MARGIN
);
210 c
->top
.SameAs(btn_back
, wxBottom
, 2*LAYOUT_Y_MARGIN
);
211 c
->bottom
.SameAs(this, wxBottom
, 2*LAYOUT_Y_MARGIN
);
212 m_htmlwin
->SetConstraints(c
);
216 m_htmlwin
->SetRelatedFrame(this, title
);
217 m_htmlwin
->SetRelatedStatusBar(0);
218 m_htmlwin
->AddFilter(m_filter
);
221 // Motif needs a nudge to get it to resize properly
223 wxSizeEvent
event(size
, GetId());
224 GetEventHandler()->ProcessEvent(event
);
230 wxHelpFrame::~wxHelpFrame()
235 wxHelpFrame::OnClose(wxCloseEvent
&WXUNUSED(ev
))
237 wxASSERT(m_controller
);
238 m_controller
->m_Frame
= NULL
;
243 m_controller
->GetFrameParameters(NULL
, NULL
, &newFrame
);
244 m_controller
->SetFrameParameters(GetTitle(), GetSize(),
250 wxHelpControllerHtml::wxHelpControllerHtml(void)
255 SetFrameParameters(_("Help: %s"),
256 wxSize(FRAME_WIDTH
, FRAME_HEIGHT
),
260 wxHelpControllerHtml::~wxHelpControllerHtml(void)
262 if(m_Frame
&& ! m_NewFrameEachTime
)
274 wxHelpControllerHtml::DisplayHelp(const wxString
&relativeURL
)
276 wxBusyCursor b
; // display a busy cursor
279 wxString mapfileurl
= m_MapFile
;
280 #if defined(__WXMAC__) && !defined(__DARWIN__)
281 mapfileurl
= wxMac2UnixFilename(m_MapFile
) ;
283 url
<< mapfileurl
<< SEP
<< relativeURL
;
284 if(! m_Frame
|| m_NewFrameEachTime
)
286 m_Frame
= new wxHelpFrame(NULL
, -1, m_FrameTitle
,
287 m_FramePosition
+wxPoint(m_offset
,m_offset
),
290 if(m_NewFrameEachTime
)
299 return m_Frame
->LoadPage(url
);
304 wxHelpControllerHtml::SetFrameParameters(const wxString
&title
,
309 m_FrameTitle
= title
;
311 m_FramePosition
= pos
;
312 m_NewFrameEachTime
= newFrame
;
316 wxHelpControllerHtml::GetFrameParameters(wxSize
*size
,
320 if(size
) *size
= m_FrameSize
;
321 if(pos
) *pos
= m_FramePosition
;
322 if(newframe
) *newframe
= m_NewFrameEachTime
;
326 #endif // wxUSE_WXHTML_HELP