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 // Copyright: (c) Harm van der Heijden and Vaclav Slavik
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
10
11 // For compilers that support precompilation, includes "wx.h"
12
13 #include "wx/wxprec.h"
14
15
16 #if wxUSE_WXHTML_HELP
17
18 #ifndef WX_PRECOMP
19 #include "wx/object.h"
20 #include "wx/dynarray.h"
21 #include "wx/intl.h"
22 #include "wx/log.h"
23 #if wxUSE_STREAMS
24 #include "wx/stream.h"
25 #endif
26
27 #include "wx/sizer.h"
28
29 #include "wx/bmpbuttn.h"
30 #include "wx/statbox.h"
31 #include "wx/radiobox.h"
32 #include "wx/menu.h"
33 #include "wx/settings.h"
34 #include "wx/msgdlg.h"
35 #include "wx/textctrl.h"
36 #include "wx/toolbar.h"
37 #include "wx/choicdlg.h"
38 #include "wx/filedlg.h"
39 #endif // WX_PRECOMP
40
41 #include "wx/html/helpfrm.h"
42 #include "wx/html/helpctrl.h"
43 #include "wx/notebook.h"
44 #include "wx/imaglist.h"
45 #include "wx/treectrl.h"
46 #include "wx/tokenzr.h"
47 #include "wx/wfstream.h"
48 #include "wx/html/htmlwin.h"
49 #include "wx/busyinfo.h"
50 #include "wx/progdlg.h"
51 #include "wx/fontenum.h"
52 #include "wx/artprov.h"
53 #include "wx/spinctrl.h"
54
55 wxIMPLEMENT_DYNAMIC_CLASS(wxHtmlHelpFrame, wxFrame);
56
wxBEGIN_EVENT_TABLE(wxHtmlHelpFrame,wxFrame)57 wxBEGIN_EVENT_TABLE(wxHtmlHelpFrame, wxFrame)
58 EVT_ACTIVATE(wxHtmlHelpFrame::OnActivate)
59 EVT_CLOSE(wxHtmlHelpFrame::OnCloseWindow)
60 wxEND_EVENT_TABLE()
61
62 wxHtmlHelpFrame::wxHtmlHelpFrame(wxWindow* parent, wxWindowID id, const wxString& title,
63 int style, wxHtmlHelpData* data
64 #if wxUSE_CONFIG
65 , wxConfigBase *config, const wxString& rootpath
66 #endif // wxUSE_CONFIG
67 )
68 {
69 Init(data);
70 Create(parent, id, title, style
71 #if wxUSE_CONFIG
72 , config, rootpath
73 #endif // wxUSE_CONFIG
74 );
75 }
76
Init(wxHtmlHelpData * data)77 void wxHtmlHelpFrame::Init(wxHtmlHelpData* data)
78 {
79 // Simply pass the pointer on to the help window
80 m_Data = data;
81 m_HtmlHelpWin = NULL;
82 m_helpController = NULL;
83 m_shouldPreventAppExit = false;
84 }
85
SetController(wxHtmlHelpController * controller)86 void wxHtmlHelpFrame::SetController(wxHtmlHelpController* controller)
87 {
88 m_helpController = controller;
89 if ( m_HtmlHelpWin )
90 m_HtmlHelpWin->SetController(controller);
91 }
92
93 // Create: builds the GUI components.
Create(wxWindow * parent,wxWindowID id,const wxString & WXUNUSED (title),int style,wxConfigBase * config,const wxString & rootpath)94 bool wxHtmlHelpFrame::Create(wxWindow* parent, wxWindowID id,
95 const wxString& WXUNUSED(title), int style
96 #if wxUSE_CONFIG
97 , wxConfigBase *config, const wxString& rootpath
98 #endif // wxUSE_CONFIG
99 )
100 {
101 m_HtmlHelpWin = new wxHtmlHelpWindow(m_Data);
102 m_HtmlHelpWin->SetController(m_helpController);
103 #if wxUSE_CONFIG
104 if ( config )
105 m_HtmlHelpWin->UseConfig(config, rootpath);
106 #endif // wxUSE_CONFIG
107
108 wxFrame::Create(parent, id, _("Help"),
109 wxPoint(m_HtmlHelpWin->GetCfgData().x, m_HtmlHelpWin->GetCfgData().y),
110 wxSize(m_HtmlHelpWin->GetCfgData().w, m_HtmlHelpWin->GetCfgData().h),
111 wxDEFAULT_FRAME_STYLE, wxT("wxHtmlHelp"));
112 #if wxUSE_STATUSBAR
113 CreateStatusBar();
114 #endif
115 m_HtmlHelpWin->Create(this, wxID_ANY, wxDefaultPosition, wxDefaultSize,
116 wxTAB_TRAVERSAL|wxNO_BORDER, style);
117
118 GetPosition(& (m_HtmlHelpWin->GetCfgData().x), & (m_HtmlHelpWin->GetCfgData()).y);
119
120 SetIcons(wxArtProvider::GetIconBundle(wxART_HELP, wxART_FRAME_ICON));
121
122 m_HtmlHelpWin->GetHtmlWindow()->SetRelatedFrame(this, m_TitleFormat);
123 #if wxUSE_STATUSBAR
124 m_HtmlHelpWin->GetHtmlWindow()->SetRelatedStatusBar(0);
125 #endif
126 return true;
127 }
128
~wxHtmlHelpFrame()129 wxHtmlHelpFrame::~wxHtmlHelpFrame()
130 {
131 }
132
SetTitleFormat(const wxString & format)133 void wxHtmlHelpFrame::SetTitleFormat(const wxString& format)
134 {
135 if (GetHelpWindow() && GetHelpWindow()->GetHtmlWindow())
136 GetHelpWindow()->GetHtmlWindow()->SetRelatedFrame(this, format);
137 m_TitleFormat = format;
138 }
139
140 /*
141 EVENT HANDLING :
142 */
143
144
OnActivate(wxActivateEvent & event)145 void wxHtmlHelpFrame::OnActivate(wxActivateEvent& event)
146 {
147 // This saves one mouse click when using the
148 // wxHTML for context sensitive help systems
149 #ifndef __WXGTK__
150 // NB: wxActivateEvent is a bit broken in wxGTK
151 // and is sometimes sent when it should not be
152 if (event.GetActive() && m_HtmlHelpWin)
153 m_HtmlHelpWin->GetHtmlWindow()->SetFocus();
154 #endif
155
156 event.Skip();
157 }
158
OnCloseWindow(wxCloseEvent & evt)159 void wxHtmlHelpFrame::OnCloseWindow(wxCloseEvent& evt)
160 {
161 if (!IsIconized())
162 {
163 GetSize(& (m_HtmlHelpWin->GetCfgData().w), &(m_HtmlHelpWin->GetCfgData().h));
164 GetPosition(& (m_HtmlHelpWin->GetCfgData().x), & (m_HtmlHelpWin->GetCfgData().y));
165 }
166
167 #ifdef __WXGTK__
168 if (IsGrabbed())
169 {
170 RemoveGrab();
171 }
172 #endif
173
174 if (m_HtmlHelpWin->GetSplitterWindow() && m_HtmlHelpWin->GetCfgData().navig_on)
175 m_HtmlHelpWin->GetCfgData().sashpos = m_HtmlHelpWin->GetSplitterWindow()->GetSashPosition();
176
177 if (m_helpController && wxDynamicCast(m_helpController, wxHtmlHelpController))
178 {
179 ((wxHtmlHelpController*) m_helpController)->OnCloseFrame(evt);
180 }
181
182 evt.Skip();
183 }
184
185 // Make the help controller's frame 'modal' if
186 // needed
AddGrabIfNeeded()187 void wxHtmlHelpFrame::AddGrabIfNeeded()
188 {
189 // So far, wxGTK only
190 #ifdef __WXGTK__
191 bool needGrab = false;
192
193 // Check if there are any modal windows present,
194 // in which case we need to add a grab.
195 for ( wxWindowList::iterator it = wxTopLevelWindows.begin();
196 it != wxTopLevelWindows.end();
197 ++it )
198 {
199 wxWindow *win = *it;
200 wxDialog *dialog = wxDynamicCast(win, wxDialog);
201
202 if (dialog && dialog->IsModal())
203 needGrab = true;
204 }
205
206 if (needGrab)
207 AddGrab();
208 #endif // __WXGTK__
209 }
210
211 #if wxUSE_CONFIG
212 // For compatibility
UseConfig(wxConfigBase * config,const wxString & rootPath)213 void wxHtmlHelpFrame::UseConfig(wxConfigBase *config, const wxString& rootPath)
214 {
215 if (m_HtmlHelpWin)
216 m_HtmlHelpWin->UseConfig(config, rootPath);
217 }
218 #endif // wxUSE_CONFIG
219
SetShouldPreventAppExit(bool enable)220 void wxHtmlHelpFrame::SetShouldPreventAppExit(bool enable)
221 {
222 m_shouldPreventAppExit = enable;
223 }
224
225 #endif // wxUSE_WXHTML_HELP
226