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