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