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