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