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