]>
git.saurik.com Git - wxWidgets.git/blob - src/html/helpfrm.cpp
ea22fa9b6edb0bb7b02e0997d031529795f8c29e
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
8 // Copyright: (c) Harm van der Heijden and Vaclav Slavik
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // For compilers that support precompilation, includes "wx.h"
14 #include "wx/wxprec.h"
23 #include "wx/object.h"
24 #include "wx/dynarray.h"
28 #include "wx/stream.h"
33 #include "wx/bmpbuttn.h"
34 #include "wx/statbox.h"
35 #include "wx/radiobox.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"
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"
60 IMPLEMENT_DYNAMIC_CLASS(wxHtmlHelpFrame
, wxFrame
)
62 BEGIN_EVENT_TABLE(wxHtmlHelpFrame
, wxFrame
)
63 EVT_ACTIVATE(wxHtmlHelpFrame::OnActivate
)
64 EVT_CLOSE(wxHtmlHelpFrame::OnCloseWindow
)
66 EVT_MENU(wxID_CLOSE
, wxHtmlHelpFrame::OnClose
)
67 EVT_MENU(wxID_ABOUT
, wxHtmlHelpFrame::OnAbout
)
68 EVT_MENU(wxID_HELP_CONTENTS
, wxHtmlHelpFrame::OnAbout
)
72 wxHtmlHelpFrame::wxHtmlHelpFrame(wxWindow
* parent
, wxWindowID id
, const wxString
& title
,
73 int style
, wxHtmlHelpData
* data
,
74 wxConfigBase
*config
, const wxString
& rootpath
)
77 Create(parent
, id
, title
, style
, config
, rootpath
);
80 void wxHtmlHelpFrame::Init(wxHtmlHelpData
* data
)
82 // Simply pass the pointer on to the help window
85 m_helpController
= (wxHtmlHelpController
*) NULL
;
88 void wxHtmlHelpFrame::SetController(wxHtmlHelpController
* controller
)
90 m_helpController
= controller
;
92 m_HtmlHelpWin
->SetController(controller
);
95 // Create: builds the GUI components.
96 bool wxHtmlHelpFrame::Create(wxWindow
* parent
, wxWindowID id
,
97 const wxString
& WXUNUSED(title
), int style
,
98 wxConfigBase
*config
, const wxString
& rootpath
)
100 m_HtmlHelpWin
= new wxHtmlHelpWindow(m_Data
);
101 m_HtmlHelpWin
->SetController(m_helpController
);
103 m_HtmlHelpWin
->UseConfig(config
, rootpath
);
105 wxFrame::Create(parent
, id
, _("Help"),
106 wxPoint(m_HtmlHelpWin
->GetCfgData().x
, m_HtmlHelpWin
->GetCfgData().y
),
107 wxSize(m_HtmlHelpWin
->GetCfgData().w
, m_HtmlHelpWin
->GetCfgData().h
),
108 wxDEFAULT_FRAME_STYLE
, wxT("wxHtmlHelp"));
112 m_HtmlHelpWin
->Create(this, wxID_ANY
, wxDefaultPosition
, wxDefaultSize
,
113 wxTAB_TRAVERSAL
|wxNO_BORDER
, style
);
115 GetPosition(& (m_HtmlHelpWin
->GetCfgData().x
), & (m_HtmlHelpWin
->GetCfgData()).y
);
117 SetIcon(wxArtProvider::GetIcon(wxART_HELP
, wxART_HELP_BROWSER
));
119 // On the Mac, each modeless frame must have a menubar.
120 // TODO: add more menu items, and perhaps add a style to show
121 // the menubar: compulsory on the Mac, optional elsewhere.
123 wxMenuBar
* menuBar
= new wxMenuBar
;
125 wxMenu
* fileMenu
= new wxMenu
;
126 fileMenu
->Append(wxID_HTML_OPENFILE
, _("&Open..."));
127 fileMenu
->AppendSeparator();
128 fileMenu
->Append(wxID_CLOSE
, _("&Close"));
130 wxMenu
* helpMenu
= new wxMenu
;
131 helpMenu
->Append(wxID_ABOUT
, _("&About..."));
132 // Ensures we don't get an empty help menu
133 helpMenu
->Append(wxID_HELP_CONTENTS
, _("&About..."));
135 menuBar
->Append(fileMenu
,_("&File"));
136 menuBar
->Append(helpMenu
,_("&Help"));
140 m_HtmlHelpWin
->GetHtmlWindow()->SetRelatedFrame(this, m_TitleFormat
);
142 m_HtmlHelpWin
->GetHtmlWindow()->SetRelatedStatusBar(0);
147 wxHtmlHelpFrame::~wxHtmlHelpFrame()
151 void wxHtmlHelpFrame::SetTitleFormat(const wxString
& format
)
153 if (GetHelpWindow() && GetHelpWindow()->GetHtmlWindow())
154 GetHelpWindow()->GetHtmlWindow()->SetRelatedFrame(this, format
);
155 m_TitleFormat
= format
;
163 void wxHtmlHelpFrame::OnActivate(wxActivateEvent
& event
)
165 // This saves one mouse click when using the
166 // wxHTML for context sensitive help systems
168 // NB: wxActivateEvent is a bit broken in wxGTK
169 // and is sometimes sent when it should not be
170 if (event
.GetActive() && m_HtmlHelpWin
)
171 m_HtmlHelpWin
->GetHtmlWindow()->SetFocus();
177 void wxHtmlHelpFrame::OnCloseWindow(wxCloseEvent
& evt
)
181 GetSize(& (m_HtmlHelpWin
->GetCfgData().w
), &(m_HtmlHelpWin
->GetCfgData().h
));
182 GetPosition(& (m_HtmlHelpWin
->GetCfgData().x
), & (m_HtmlHelpWin
->GetCfgData().y
));
192 if (m_HtmlHelpWin
->GetSplitterWindow() && m_HtmlHelpWin
->GetCfgData().navig_on
)
193 m_HtmlHelpWin
->GetCfgData().sashpos
= m_HtmlHelpWin
->GetSplitterWindow()->GetSashPosition();
195 if (m_helpController
&& m_helpController
->IsKindOf(CLASSINFO(wxHtmlHelpController
)))
197 ((wxHtmlHelpController
*) m_helpController
)->OnCloseFrame(evt
);
203 // Make the help controller's frame 'modal' if
205 void wxHtmlHelpFrame::AddGrabIfNeeded()
207 // So far, wxGTK only
209 bool needGrab
= false;
211 // Check if there are any modal windows present,
212 // in which case we need to add a grab.
213 for ( wxWindowList::iterator it
= wxTopLevelWindows
.begin();
214 it
!= wxTopLevelWindows
.end();
218 wxDialog
*dialog
= wxDynamicCast(win
, wxDialog
);
220 if (dialog
&& dialog
->IsModal())
230 void wxHtmlHelpFrame::UseConfig(wxConfigBase
*config
, const wxString
& rootPath
)
233 m_HtmlHelpWin
->UseConfig(config
, rootPath
);
237 void wxHtmlHelpFrame::OnClose(wxCommandEvent
& WXUNUSED(event
))
242 void wxHtmlHelpFrame::OnAbout(wxCommandEvent
& WXUNUSED(event
))
244 wxMessageBox(wxT("wxWidgets HTML Help Viewer (c) 1998-2006, Vaclav Slavik et al"), wxT("HelpView"),
245 wxICON_INFORMATION
|wxOK
, this);
249 // we don't want to prevent the app from closing just because a help window
251 bool wxHtmlHelpFrame::ShouldPreventAppExit() const
253 return (wx_const_cast(wxHtmlHelpFrame
*, this) == wxTheApp
->GetTopWindow());
256 #endif // wxUSE_WXHTML_HELP