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