]> git.saurik.com Git - wxWidgets.git/blob - src/html/helpfrm.cpp
add Create to wxDocParentFrame
[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 WXPRECOMP
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 // WXPRECOMP
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 {
74 Init(data);
75 Create(parent, id, title, style);
76 }
77
78 void wxHtmlHelpFrame::Init(wxHtmlHelpData* data)
79 {
80 // Simply pass the pointer on to the help window
81 m_Data = data;
82 m_HtmlHelpWin = NULL;
83 m_helpController = (wxHtmlHelpController*) NULL;
84 }
85
86 // Create: builds the GUI components.
87 bool wxHtmlHelpFrame::Create(wxWindow* parent, wxWindowID id,
88 const wxString& WXUNUSED(title), int style)
89 {
90 m_HtmlHelpWin = new wxHtmlHelpWindow(m_Data);
91
92 wxFrame::Create(parent, id, _("Help"),
93 wxPoint(m_HtmlHelpWin->GetCfgData().x, m_HtmlHelpWin->GetCfgData().y),
94 wxSize(m_HtmlHelpWin->GetCfgData().w, m_HtmlHelpWin->GetCfgData().h),
95 wxDEFAULT_FRAME_STYLE, wxT("wxHtmlHelp"));
96 #if wxUSE_STATUSBAR
97 CreateStatusBar();
98 #endif
99 m_HtmlHelpWin->Create(this, wxID_ANY, wxDefaultPosition, wxDefaultSize,
100 wxTAB_TRAVERSAL|wxNO_BORDER, style);
101
102 GetPosition(& (m_HtmlHelpWin->GetCfgData().x), & (m_HtmlHelpWin->GetCfgData()).y);
103
104 SetIcon(wxArtProvider::GetIcon(wxART_HELP, wxART_HELP_BROWSER));
105
106 // On the Mac, each modeless frame must have a menubar.
107 // TODO: add more menu items, and perhaps add a style to show
108 // the menubar: compulsory on the Mac, optional elsewhere.
109 #ifdef __WXMAC__
110 wxMenuBar* menuBar = new wxMenuBar;
111
112 wxMenu* fileMenu = new wxMenu;
113 fileMenu->Append(wxID_HTML_OPENFILE, _("&Open..."));
114 fileMenu->AppendSeparator();
115 fileMenu->Append(wxID_CLOSE, _("&Close"));
116
117 wxMenu* helpMenu = new wxMenu;
118 helpMenu->Append(wxID_ABOUT, _("&About..."));
119 // Ensures we don't get an empty help menu
120 helpMenu->Append(wxID_HELP_CONTENTS, _("&About..."));
121
122 menuBar->Append(fileMenu,_("&File"));
123 menuBar->Append(helpMenu,_("&Help"));
124 SetMenuBar(menuBar);
125 #endif
126
127 m_HtmlHelpWin->GetHtmlWindow()->SetRelatedFrame(this, m_TitleFormat);
128 #if wxUSE_STATUSBAR
129 m_HtmlHelpWin->GetHtmlWindow()->SetRelatedStatusBar(0);
130 #endif
131 return true;
132 }
133
134 wxHtmlHelpFrame::~wxHtmlHelpFrame()
135 {
136 }
137
138 void wxHtmlHelpFrame::SetTitleFormat(const wxString& format)
139 {
140 if (GetHelpWindow() && GetHelpWindow()->GetHtmlWindow())
141 GetHelpWindow()->GetHtmlWindow()->SetRelatedFrame(this, format);
142 m_TitleFormat = format;
143 }
144
145 /*
146 EVENT HANDLING :
147 */
148
149
150 void wxHtmlHelpFrame::OnActivate(wxActivateEvent& event)
151 {
152 // This saves one mouse click when using the
153 // wxHTML for context sensitive help systems
154 #ifndef __WXGTK__
155 // NB: wxActivateEvent is a bit broken in wxGTK
156 // and is sometimes sent when it should not be
157 if (event.GetActive() && m_HtmlHelpWin)
158 m_HtmlHelpWin->GetHtmlWindow()->SetFocus();
159 #endif
160
161 event.Skip();
162 }
163
164 void wxHtmlHelpFrame::OnCloseWindow(wxCloseEvent& evt)
165 {
166 if (!IsIconized())
167 {
168 GetSize(& (m_HtmlHelpWin->GetCfgData().w), &(m_HtmlHelpWin->GetCfgData().h));
169 GetPosition(& (m_HtmlHelpWin->GetCfgData().x), & (m_HtmlHelpWin->GetCfgData().y));
170 }
171
172 #ifdef __WXGTK__
173 if (IsGrabbed())
174 {
175 RemoveGrab();
176 }
177 #endif
178
179 if (m_HtmlHelpWin->GetSplitterWindow() && m_HtmlHelpWin->GetCfgData().navig_on)
180 m_HtmlHelpWin->GetCfgData().sashpos = m_HtmlHelpWin->GetSplitterWindow()->GetSashPosition();
181
182 if (m_helpController && m_helpController->IsKindOf(CLASSINFO(wxHtmlHelpController)))
183 {
184 ((wxHtmlHelpController*) m_helpController)->OnCloseFrame(evt);
185 }
186
187 evt.Skip();
188 }
189
190 // Make the help controller's frame 'modal' if
191 // needed
192 void wxHtmlHelpFrame::AddGrabIfNeeded()
193 {
194 // So far, wxGTK only
195 #ifdef __WXGTK__
196 bool needGrab = false;
197
198 // Check if there are any modal windows present,
199 // in which case we need to add a grab.
200 for ( wxWindowList::iterator it = wxTopLevelWindows.begin();
201 it != wxTopLevelWindows.end();
202 ++it )
203 {
204 wxWindow *win = *it;
205 wxDialog *dialog = wxDynamicCast(win, wxDialog);
206
207 if (dialog && dialog->IsModal())
208 needGrab = true;
209 }
210
211 if (needGrab)
212 AddGrab();
213 #endif // __WXGTK__
214 }
215
216 // For compatibility
217 void wxHtmlHelpFrame::UseConfig(wxConfigBase *config, const wxString& rootPath)
218 {
219 if (m_HtmlHelpWin)
220 m_HtmlHelpWin->UseConfig(config, rootPath);
221 }
222
223 #ifdef __WXMAC__
224 void wxHtmlHelpFrame::OnClose(wxCommandEvent& event)
225 {
226 Close(true);
227 }
228
229 void wxHtmlHelpFrame::OnAbout(wxCommandEvent& event)
230 {
231 wxMessageBox(wxT("wxWidgets HTML Help Viewer (c) 1998-2006, Vaclav Slavik et al"), wxT("HelpView"),
232 wxICON_INFORMATION|wxOK, this);
233 }
234 #endif
235
236 #endif // wxUSE_WXHTML_HELP