]>
Commit | Line | Data |
---|---|---|
8ec2b484 | 1 | ///////////////////////////////////////////////////////////////////////////// |
8e3f3880 | 2 | // Name: src/html/helpfrm.cpp |
8ec2b484 | 3 | // Purpose: wxHtmlHelpFrame |
d5bb85a0 | 4 | // Notes: Based on htmlhelp.cpp, implementing a monolithic |
8ec2b484 HH |
5 | // HTML Help controller class, by Vaclav Slavik |
6 | // Author: Harm van der Heijden and Vaclav Slavik | |
8ec2b484 | 7 | // Copyright: (c) Harm van der Heijden and Vaclav Slavik |
65571936 | 8 | // Licence: wxWindows licence |
8ec2b484 HH |
9 | ///////////////////////////////////////////////////////////////////////////// |
10 | ||
c32bfc10 VS |
11 | // For compilers that support precompilation, includes "wx.h" |
12 | ||
8ec2b484 HH |
13 | #include "wx/wxprec.h" |
14 | ||
15 | #ifdef __BORLANDC__ | |
8e3f3880 | 16 | #pragma hdrstop |
8ec2b484 HH |
17 | #endif |
18 | ||
3379ed37 | 19 | #if wxUSE_WXHTML_HELP |
07b8d7ec | 20 | |
b4f4d3dd | 21 | #ifndef WX_PRECOMP |
8e3f3880 | 22 | #include "wx/object.h" |
ad9835c9 | 23 | #include "wx/dynarray.h" |
07b8d7ec VZ |
24 | #include "wx/intl.h" |
25 | #include "wx/log.h" | |
530ecef0 WS |
26 | #if wxUSE_STREAMS |
27 | #include "wx/stream.h" | |
28 | #endif | |
07b8d7ec | 29 | |
07b8d7ec VZ |
30 | #include "wx/sizer.h" |
31 | ||
32 | #include "wx/bmpbuttn.h" | |
33 | #include "wx/statbox.h" | |
34 | #include "wx/radiobox.h" | |
3b3dc801 | 35 | #include "wx/menu.h" |
9eddec69 | 36 | #include "wx/settings.h" |
c718e0b3 | 37 | #include "wx/msgdlg.h" |
fec9cc08 | 38 | #include "wx/textctrl.h" |
4e3e485b | 39 | #include "wx/toolbar.h" |
949c9f74 WS |
40 | #include "wx/choicdlg.h" |
41 | #include "wx/filedlg.h" | |
b4f4d3dd | 42 | #endif // WX_PRECOMP |
c718e0b3 | 43 | |
8ec2b484 | 44 | #include "wx/html/helpfrm.h" |
b4414c1f | 45 | #include "wx/html/helpctrl.h" |
8ec2b484 HH |
46 | #include "wx/notebook.h" |
47 | #include "wx/imaglist.h" | |
48 | #include "wx/treectrl.h" | |
49 | #include "wx/tokenzr.h" | |
50 | #include "wx/wfstream.h" | |
51 | #include "wx/html/htmlwin.h" | |
52 | #include "wx/busyinfo.h" | |
53 | #include "wx/progdlg.h" | |
83efdf33 | 54 | #include "wx/fontenum.h" |
f435c1f0 | 55 | #include "wx/artprov.h" |
c269cf62 | 56 | #include "wx/spinctrl.h" |
8ec2b484 | 57 | |
3755cfa6 | 58 | IMPLEMENT_DYNAMIC_CLASS(wxHtmlHelpFrame, wxFrame) |
8ec2b484 | 59 | |
3755cfa6 JS |
60 | BEGIN_EVENT_TABLE(wxHtmlHelpFrame, wxFrame) |
61 | EVT_ACTIVATE(wxHtmlHelpFrame::OnActivate) | |
62 | EVT_CLOSE(wxHtmlHelpFrame::OnCloseWindow) | |
63 | #ifdef __WXMAC__ | |
64 | EVT_MENU(wxID_CLOSE, wxHtmlHelpFrame::OnClose) | |
65 | EVT_MENU(wxID_ABOUT, wxHtmlHelpFrame::OnAbout) | |
66 | EVT_MENU(wxID_HELP_CONTENTS, wxHtmlHelpFrame::OnAbout) | |
da4cc40c | 67 | #endif |
3755cfa6 | 68 | END_EVENT_TABLE() |
8ec2b484 HH |
69 | |
70 | wxHtmlHelpFrame::wxHtmlHelpFrame(wxWindow* parent, wxWindowID id, const wxString& title, | |
b4246849 VZ |
71 | int style, wxHtmlHelpData* data |
72 | #if wxUSE_CONFIG | |
73 | , wxConfigBase *config, const wxString& rootpath | |
74 | #endif // wxUSE_CONFIG | |
75 | ) | |
8ec2b484 HH |
76 | { |
77 | Init(data); | |
b4246849 VZ |
78 | Create(parent, id, title, style |
79 | #if wxUSE_CONFIG | |
80 | , config, rootpath | |
81 | #endif // wxUSE_CONFIG | |
82 | ); | |
8ec2b484 | 83 | } |
d5bb85a0 | 84 | |
8ec2b484 HH |
85 | void wxHtmlHelpFrame::Init(wxHtmlHelpData* data) |
86 | { | |
3755cfa6 JS |
87 | // Simply pass the pointer on to the help window |
88 | m_Data = data; | |
89 | m_HtmlHelpWin = NULL; | |
d3b9f782 | 90 | m_helpController = NULL; |
bd45b3e1 | 91 | m_shouldPreventAppExit = false; |
8ec2b484 HH |
92 | } |
93 | ||
664d1729 VS |
94 | void wxHtmlHelpFrame::SetController(wxHtmlHelpController* controller) |
95 | { | |
96 | m_helpController = controller; | |
97 | if ( m_HtmlHelpWin ) | |
98 | m_HtmlHelpWin->SetController(controller); | |
99 | } | |
100 | ||
d5bb85a0 | 101 | // Create: builds the GUI components. |
3379ed37 | 102 | bool wxHtmlHelpFrame::Create(wxWindow* parent, wxWindowID id, |
b4246849 VZ |
103 | const wxString& WXUNUSED(title), int style |
104 | #if wxUSE_CONFIG | |
105 | , wxConfigBase *config, const wxString& rootpath | |
106 | #endif // wxUSE_CONFIG | |
107 | ) | |
8ec2b484 | 108 | { |
3755cfa6 | 109 | m_HtmlHelpWin = new wxHtmlHelpWindow(m_Data); |
664d1729 | 110 | m_HtmlHelpWin->SetController(m_helpController); |
b4246849 VZ |
111 | #if wxUSE_CONFIG |
112 | if ( config ) | |
18fc6059 | 113 | m_HtmlHelpWin->UseConfig(config, rootpath); |
b4246849 | 114 | #endif // wxUSE_CONFIG |
03647350 | 115 | |
8e3f3880 | 116 | wxFrame::Create(parent, id, _("Help"), |
3755cfa6 | 117 | wxPoint(m_HtmlHelpWin->GetCfgData().x, m_HtmlHelpWin->GetCfgData().y), |
8e3f3880 | 118 | wxSize(m_HtmlHelpWin->GetCfgData().w, m_HtmlHelpWin->GetCfgData().h), |
5229b11d | 119 | wxDEFAULT_FRAME_STYLE, wxT("wxHtmlHelp")); |
3755cfa6 JS |
120 | #if wxUSE_STATUSBAR |
121 | CreateStatusBar(); | |
122 | #endif | |
8e3f3880 | 123 | m_HtmlHelpWin->Create(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, |
3755cfa6 | 124 | wxTAB_TRAVERSAL|wxNO_BORDER, style); |
8ec2b484 | 125 | |
3755cfa6 | 126 | GetPosition(& (m_HtmlHelpWin->GetCfgData().x), & (m_HtmlHelpWin->GetCfgData()).y); |
5c172c17 | 127 | |
6c4a2734 | 128 | SetIcons(wxArtProvider::GetIconBundle(wxART_HELP, wxART_FRAME_ICON)); |
9ffdee80 | 129 | |
d9b21c9f JS |
130 | // On the Mac, each modeless frame must have a menubar. |
131 | // TODO: add more menu items, and perhaps add a style to show | |
132 | // the menubar: compulsory on the Mac, optional elsewhere. | |
133 | #ifdef __WXMAC__ | |
134 | wxMenuBar* menuBar = new wxMenuBar; | |
135 | ||
136 | wxMenu* fileMenu = new wxMenu; | |
137 | fileMenu->Append(wxID_HTML_OPENFILE, _("&Open...")); | |
d9b21c9f JS |
138 | fileMenu->AppendSeparator(); |
139 | fileMenu->Append(wxID_CLOSE, _("&Close")); | |
140 | ||
b05206c9 | 141 | wxMenu* helpMenu = new wxMenu; |
2d143b66 | 142 | helpMenu->Append(wxID_ABOUT, _("&About")); |
322a5b45 | 143 | // Ensures we don't get an empty help menu |
2d143b66 | 144 | helpMenu->Append(wxID_HELP_CONTENTS, _("&About")); |
d9b21c9f | 145 | |
c3eeb758 RD |
146 | menuBar->Append(fileMenu,_("&File")); |
147 | menuBar->Append(helpMenu,_("&Help")); | |
d9b21c9f JS |
148 | SetMenuBar(menuBar); |
149 | #endif | |
150 | ||
3755cfa6 | 151 | m_HtmlHelpWin->GetHtmlWindow()->SetRelatedFrame(this, m_TitleFormat); |
67a99992 | 152 | #if wxUSE_STATUSBAR |
3755cfa6 | 153 | m_HtmlHelpWin->GetHtmlWindow()->SetRelatedStatusBar(0); |
8fbc9912 | 154 | #endif |
dabbc6a5 | 155 | return true; |
8ec2b484 HH |
156 | } |
157 | ||
158 | wxHtmlHelpFrame::~wxHtmlHelpFrame() | |
159 | { | |
b854b7b8 | 160 | } |
b854b7b8 | 161 | |
721ab905 VS |
162 | void wxHtmlHelpFrame::SetTitleFormat(const wxString& format) |
163 | { | |
3755cfa6 JS |
164 | if (GetHelpWindow() && GetHelpWindow()->GetHtmlWindow()) |
165 | GetHelpWindow()->GetHtmlWindow()->SetRelatedFrame(this, format); | |
721ab905 VS |
166 | m_TitleFormat = format; |
167 | } | |
168 | ||
8ec2b484 HH |
169 | /* |
170 | EVENT HANDLING : | |
171 | */ | |
172 | ||
173 | ||
d45bc436 RR |
174 | void wxHtmlHelpFrame::OnActivate(wxActivateEvent& event) |
175 | { | |
176 | // This saves one mouse click when using the | |
177 | // wxHTML for context sensitive help systems | |
2b5f62a0 VZ |
178 | #ifndef __WXGTK__ |
179 | // NB: wxActivateEvent is a bit broken in wxGTK | |
180 | // and is sometimes sent when it should not be | |
3755cfa6 JS |
181 | if (event.GetActive() && m_HtmlHelpWin) |
182 | m_HtmlHelpWin->GetHtmlWindow()->SetFocus(); | |
2b5f62a0 | 183 | #endif |
fbd90401 VS |
184 | |
185 | event.Skip(); | |
d45bc436 RR |
186 | } |
187 | ||
3755cfa6 | 188 | void wxHtmlHelpFrame::OnCloseWindow(wxCloseEvent& evt) |
8ec2b484 | 189 | { |
3755cfa6 | 190 | if (!IsIconized()) |
4f9297b0 | 191 | { |
3755cfa6 JS |
192 | GetSize(& (m_HtmlHelpWin->GetCfgData().w), &(m_HtmlHelpWin->GetCfgData().h)); |
193 | GetPosition(& (m_HtmlHelpWin->GetCfgData().x), & (m_HtmlHelpWin->GetCfgData().y)); | |
8ec2b484 | 194 | } |
8ec2b484 | 195 | |
3755cfa6 JS |
196 | #ifdef __WXGTK__ |
197 | if (IsGrabbed()) | |
0646614d | 198 | { |
3755cfa6 | 199 | RemoveGrab(); |
0646614d | 200 | } |
3755cfa6 | 201 | #endif |
8ec2b484 | 202 | |
3755cfa6 JS |
203 | if (m_HtmlHelpWin->GetSplitterWindow() && m_HtmlHelpWin->GetCfgData().navig_on) |
204 | m_HtmlHelpWin->GetCfgData().sashpos = m_HtmlHelpWin->GetSplitterWindow()->GetSashPosition(); | |
8ec2b484 | 205 | |
345c78ca | 206 | if (m_helpController && wxDynamicCast(m_helpController, wxHtmlHelpController)) |
4f9297b0 | 207 | { |
3755cfa6 | 208 | ((wxHtmlHelpController*) m_helpController)->OnCloseFrame(evt); |
4f9297b0 | 209 | } |
f0b6a33f | 210 | |
3755cfa6 | 211 | evt.Skip(); |
f0b6a33f VS |
212 | } |
213 | ||
3755cfa6 JS |
214 | // Make the help controller's frame 'modal' if |
215 | // needed | |
216 | void wxHtmlHelpFrame::AddGrabIfNeeded() | |
f0b6a33f | 217 | { |
3755cfa6 JS |
218 | // So far, wxGTK only |
219 | #ifdef __WXGTK__ | |
8e3f3880 WS |
220 | bool needGrab = false; |
221 | ||
3755cfa6 JS |
222 | // Check if there are any modal windows present, |
223 | // in which case we need to add a grab. | |
3e63c315 MW |
224 | for ( wxWindowList::iterator it = wxTopLevelWindows.begin(); |
225 | it != wxTopLevelWindows.end(); | |
226 | ++it ) | |
4f9297b0 | 227 | { |
3e63c315 | 228 | wxWindow *win = *it; |
3755cfa6 | 229 | wxDialog *dialog = wxDynamicCast(win, wxDialog); |
8ec2b484 | 230 | |
3755cfa6 | 231 | if (dialog && dialog->IsModal()) |
8e3f3880 | 232 | needGrab = true; |
0646614d | 233 | } |
8ec2b484 | 234 | |
3755cfa6 JS |
235 | if (needGrab) |
236 | AddGrab(); | |
237 | #endif // __WXGTK__ | |
8ec2b484 HH |
238 | } |
239 | ||
b4246849 | 240 | #if wxUSE_CONFIG |
3755cfa6 JS |
241 | // For compatibility |
242 | void wxHtmlHelpFrame::UseConfig(wxConfigBase *config, const wxString& rootPath) | |
382e6efe | 243 | { |
3755cfa6 JS |
244 | if (m_HtmlHelpWin) |
245 | m_HtmlHelpWin->UseConfig(config, rootPath); | |
8ec2b484 | 246 | } |
b4246849 | 247 | #endif // wxUSE_CONFIG |
8ec2b484 | 248 | |
bd45b3e1 VZ |
249 | void wxHtmlHelpFrame::SetShouldPreventAppExit(bool enable) |
250 | { | |
251 | m_shouldPreventAppExit = enable; | |
252 | } | |
253 | ||
d9b21c9f | 254 | #ifdef __WXMAC__ |
8a088306 | 255 | void wxHtmlHelpFrame::OnClose(wxCommandEvent& WXUNUSED(event)) |
d9b21c9f | 256 | { |
dabbc6a5 | 257 | Close(true); |
d9b21c9f JS |
258 | } |
259 | ||
8a088306 | 260 | void wxHtmlHelpFrame::OnAbout(wxCommandEvent& WXUNUSED(event)) |
d9b21c9f | 261 | { |
3755cfa6 | 262 | wxMessageBox(wxT("wxWidgets HTML Help Viewer (c) 1998-2006, Vaclav Slavik et al"), wxT("HelpView"), |
d9b21c9f JS |
263 | wxICON_INFORMATION|wxOK, this); |
264 | } | |
265 | #endif | |
266 | ||
3379ed37 | 267 | #endif // wxUSE_WXHTML_HELP |