]>
git.saurik.com Git - wxWidgets.git/blob - src/html/helpfrm.cpp
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 // Copyright: (c) Harm van der Heijden and Vaclav Slavik
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
11 // For compilers that support precompilation, includes "wx.h"
13 #include "wx/wxprec.h"
22 #include "wx/object.h"
23 #include "wx/dynarray.h"
27 #include "wx/stream.h"
32 #include "wx/bmpbuttn.h"
33 #include "wx/statbox.h"
34 #include "wx/radiobox.h"
36 #include "wx/settings.h"
37 #include "wx/msgdlg.h"
38 #include "wx/textctrl.h"
39 #include "wx/toolbar.h"
40 #include "wx/choicdlg.h"
41 #include "wx/filedlg.h"
44 #include "wx/html/helpfrm.h"
45 #include "wx/html/helpctrl.h"
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"
54 #include "wx/fontenum.h"
55 #include "wx/artprov.h"
56 #include "wx/spinctrl.h"
58 IMPLEMENT_DYNAMIC_CLASS(wxHtmlHelpFrame
, wxFrame
)
60 BEGIN_EVENT_TABLE(wxHtmlHelpFrame
, wxFrame
)
61 EVT_ACTIVATE(wxHtmlHelpFrame::OnActivate
)
62 EVT_CLOSE(wxHtmlHelpFrame::OnCloseWindow
)
64 EVT_MENU(wxID_CLOSE
, wxHtmlHelpFrame::OnClose
)
65 EVT_MENU(wxID_ABOUT
, wxHtmlHelpFrame::OnAbout
)
66 EVT_MENU(wxID_HELP_CONTENTS
, wxHtmlHelpFrame::OnAbout
)
70 wxHtmlHelpFrame::wxHtmlHelpFrame(wxWindow
* parent
, wxWindowID id
, const wxString
& title
,
71 int style
, wxHtmlHelpData
* data
73 , wxConfigBase
*config
, const wxString
& rootpath
74 #endif // wxUSE_CONFIG
78 Create(parent
, id
, title
, style
81 #endif // wxUSE_CONFIG
85 void wxHtmlHelpFrame::Init(wxHtmlHelpData
* data
)
87 // Simply pass the pointer on to the help window
90 m_helpController
= NULL
;
91 m_shouldPreventAppExit
= false;
94 void wxHtmlHelpFrame::SetController(wxHtmlHelpController
* controller
)
96 m_helpController
= controller
;
98 m_HtmlHelpWin
->SetController(controller
);
101 // Create: builds the GUI components.
102 bool wxHtmlHelpFrame::Create(wxWindow
* parent
, wxWindowID id
,
103 const wxString
& WXUNUSED(title
), int style
105 , wxConfigBase
*config
, const wxString
& rootpath
106 #endif // wxUSE_CONFIG
109 m_HtmlHelpWin
= new wxHtmlHelpWindow(m_Data
);
110 m_HtmlHelpWin
->SetController(m_helpController
);
113 m_HtmlHelpWin
->UseConfig(config
, rootpath
);
114 #endif // wxUSE_CONFIG
116 wxFrame::Create(parent
, id
, _("Help"),
117 wxPoint(m_HtmlHelpWin
->GetCfgData().x
, m_HtmlHelpWin
->GetCfgData().y
),
118 wxSize(m_HtmlHelpWin
->GetCfgData().w
, m_HtmlHelpWin
->GetCfgData().h
),
119 wxDEFAULT_FRAME_STYLE
, wxT("wxHtmlHelp"));
123 m_HtmlHelpWin
->Create(this, wxID_ANY
, wxDefaultPosition
, wxDefaultSize
,
124 wxTAB_TRAVERSAL
|wxNO_BORDER
, style
);
126 GetPosition(& (m_HtmlHelpWin
->GetCfgData().x
), & (m_HtmlHelpWin
->GetCfgData()).y
);
128 SetIcons(wxArtProvider::GetIconBundle(wxART_HELP
, wxART_FRAME_ICON
));
130 // On the Mac, each modeless frame must have a menubar.
131 // TODO: add more menu items, and perhaps add a style to show
132 // the menubar: compulsory on the Mac, optional elsewhere.
134 wxMenuBar
* menuBar
= new wxMenuBar
;
136 wxMenu
* fileMenu
= new wxMenu
;
137 fileMenu
->Append(wxID_HTML_OPENFILE
, _("&Open..."));
138 fileMenu
->AppendSeparator();
139 fileMenu
->Append(wxID_CLOSE
, _("&Close"));
141 wxMenu
* helpMenu
= new wxMenu
;
142 helpMenu
->Append(wxID_ABOUT
, _("&About"));
143 // Ensures we don't get an empty help menu
144 helpMenu
->Append(wxID_HELP_CONTENTS
, _("&About"));
146 menuBar
->Append(fileMenu
,_("&File"));
147 menuBar
->Append(helpMenu
,_("&Help"));
151 m_HtmlHelpWin
->GetHtmlWindow()->SetRelatedFrame(this, m_TitleFormat
);
153 m_HtmlHelpWin
->GetHtmlWindow()->SetRelatedStatusBar(0);
158 wxHtmlHelpFrame::~wxHtmlHelpFrame()
162 void wxHtmlHelpFrame::SetTitleFormat(const wxString
& format
)
164 if (GetHelpWindow() && GetHelpWindow()->GetHtmlWindow())
165 GetHelpWindow()->GetHtmlWindow()->SetRelatedFrame(this, format
);
166 m_TitleFormat
= format
;
174 void wxHtmlHelpFrame::OnActivate(wxActivateEvent
& event
)
176 // This saves one mouse click when using the
177 // wxHTML for context sensitive help systems
179 // NB: wxActivateEvent is a bit broken in wxGTK
180 // and is sometimes sent when it should not be
181 if (event
.GetActive() && m_HtmlHelpWin
)
182 m_HtmlHelpWin
->GetHtmlWindow()->SetFocus();
188 void wxHtmlHelpFrame::OnCloseWindow(wxCloseEvent
& evt
)
192 GetSize(& (m_HtmlHelpWin
->GetCfgData().w
), &(m_HtmlHelpWin
->GetCfgData().h
));
193 GetPosition(& (m_HtmlHelpWin
->GetCfgData().x
), & (m_HtmlHelpWin
->GetCfgData().y
));
203 if (m_HtmlHelpWin
->GetSplitterWindow() && m_HtmlHelpWin
->GetCfgData().navig_on
)
204 m_HtmlHelpWin
->GetCfgData().sashpos
= m_HtmlHelpWin
->GetSplitterWindow()->GetSashPosition();
206 if (m_helpController
&& wxDynamicCast(m_helpController
, wxHtmlHelpController
))
208 ((wxHtmlHelpController
*) m_helpController
)->OnCloseFrame(evt
);
214 // Make the help controller's frame 'modal' if
216 void wxHtmlHelpFrame::AddGrabIfNeeded()
218 // So far, wxGTK only
220 bool needGrab
= false;
222 // Check if there are any modal windows present,
223 // in which case we need to add a grab.
224 for ( wxWindowList::iterator it
= wxTopLevelWindows
.begin();
225 it
!= wxTopLevelWindows
.end();
229 wxDialog
*dialog
= wxDynamicCast(win
, wxDialog
);
231 if (dialog
&& dialog
->IsModal())
242 void wxHtmlHelpFrame::UseConfig(wxConfigBase
*config
, const wxString
& rootPath
)
245 m_HtmlHelpWin
->UseConfig(config
, rootPath
);
247 #endif // wxUSE_CONFIG
249 void wxHtmlHelpFrame::SetShouldPreventAppExit(bool enable
)
251 m_shouldPreventAppExit
= enable
;
255 void wxHtmlHelpFrame::OnClose(wxCommandEvent
& WXUNUSED(event
))
260 void wxHtmlHelpFrame::OnAbout(wxCommandEvent
& WXUNUSED(event
))
262 wxMessageBox(wxT("wxWidgets HTML Help Viewer (c) 1998-2006, Vaclav Slavik et al"), wxT("HelpView"),
263 wxICON_INFORMATION
|wxOK
, this);
267 #endif // wxUSE_WXHTML_HELP