]>
git.saurik.com Git - wxWidgets.git/blob - src/html/helpctrl.cpp
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxHtmlHelpController
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 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation
16 // For compilers that support precompilation, includes "wx.h".
17 #include "wx/wxprec.h"
27 #include "wx/html/helpctrl.h"
29 #include "wx/busyinfo.h"
31 IMPLEMENT_DYNAMIC_CLASS(wxHtmlHelpController
, wxHelpControllerBase
)
34 BEGIN_EVENT_TABLE(wxHtmlHelpController
, wxEvtHandler
)
35 EVT_CLOSE(wxHtmlHelpController::OnCloseFrame
)
39 wxHtmlHelpController::wxHtmlHelpController(int style
)
43 m_ConfigRoot
= wxEmptyString
;
44 m_titleFormat
= _("Help: %s");
48 wxHtmlHelpController::~wxHtmlHelpController()
50 WriteCustomization(m_Config
, m_ConfigRoot
);
56 void wxHtmlHelpController::DestroyHelpWindow()
58 //if (m_Config) WriteCustomization(m_Config, m_ConfigRoot);
60 m_helpFrame
->Destroy();
63 void wxHtmlHelpController::OnCloseFrame(wxCloseEvent
& evt
)
69 m_helpFrame
->SetController((wxHelpControllerBase
*) NULL
);
73 void wxHtmlHelpController::SetTitleFormat(const wxString
& title
)
75 m_titleFormat
= title
;
77 m_helpFrame
->SetTitleFormat(title
);
81 bool wxHtmlHelpController::AddBook(const wxString
& book
, bool show_wait_msg
)
85 wxBusyInfo
* busy
= NULL
;
88 info
.Printf(_("Adding book %s"), book
.c_str());
89 busy
= new wxBusyInfo(info
);
92 bool retval
= m_helpData
.AddBook(book
);
102 wxHtmlHelpFrame
*wxHtmlHelpController::CreateHelpFrame(wxHtmlHelpData
*data
)
104 return new wxHtmlHelpFrame(data
);
108 void wxHtmlHelpController::CreateHelpWindow()
111 m_helpFrame
->Raise();
115 if (m_Config
== NULL
)
117 m_Config
= wxConfigBase::Get(FALSE
);
118 if (m_Config
!= NULL
)
119 m_ConfigRoot
= _T("wxWindows/wxHtmlHelpController");
122 m_helpFrame
= CreateHelpFrame(&m_helpData
);
123 m_helpFrame
->SetController(this);
124 // m_helpFrame->PushEventHandler(this);
127 m_helpFrame
->UseConfig(m_Config
, m_ConfigRoot
);
129 m_helpFrame
->Create(NULL
, wxID_HTML_HELPFRAME
, wxEmptyString
, m_FrameStyle
);
130 m_helpFrame
->SetTitleFormat(m_titleFormat
);
131 m_helpFrame
->Show(TRUE
);
134 void wxHtmlHelpController::ReadCustomization(wxConfigBase
* cfg
, const wxString
& path
)
136 /* should not be called by the user; call UseConfig, and the controller
137 * will do the rest */
139 m_helpFrame
->ReadCustomization(cfg
, path
);
142 void wxHtmlHelpController::WriteCustomization(wxConfigBase
* cfg
, const wxString
& path
)
144 /* typically called by the controllers OnCloseFrame handler */
146 m_helpFrame
->WriteCustomization(cfg
, path
);
149 void wxHtmlHelpController::UseConfig(wxConfigBase
*config
, const wxString
& rootpath
)
152 m_ConfigRoot
= rootpath
;
153 if (m_helpFrame
) m_helpFrame
-> UseConfig(config
, rootpath
);
154 ReadCustomization(config
, rootpath
);
157 //// Backward compatibility with wxHelpController API
159 bool wxHtmlHelpController::Initialize(const wxString
& file
)
161 wxString dir
, filename
, ext
;
162 wxSplitPath(file
, & dir
, & filename
, & ext
);
165 dir
= dir
+ wxString(_("/"));
167 // Try to find a suitable file
168 wxString actualFilename
= dir
+ filename
+ wxString(_(".zip"));
169 if (!wxFileExists(actualFilename
))
171 actualFilename
= dir
+ filename
+ wxString(_(".htb"));
172 if (!wxFileExists(actualFilename
))
174 actualFilename
= dir
+ filename
+ wxString(_(".hhp"));
175 if (!wxFileExists(actualFilename
))
180 return AddBook(actualFilename
);
183 bool wxHtmlHelpController::LoadFile(const wxString
& WXUNUSED(file
))
185 // Don't reload the file or we'll have it appear again, presumably.
189 bool wxHtmlHelpController::DisplaySection(int sectionNo
)
191 return Display(sectionNo
);
194 void wxHtmlHelpController::SetFrameParameters(const wxString
& title
,
197 bool WXUNUSED(newFrameEachTime
))
199 SetTitleFormat(title
);
202 m_helpFrame
->SetSize(pos
.x
, pos
.y
, size
.x
, size
.y
);
206 wxFrame
* wxHtmlHelpController::GetFrameParameters(wxSize
*size
,
208 bool *newFrameEachTime
)
210 if (newFrameEachTime
)
211 (* newFrameEachTime
) = FALSE
;
212 if (size
&& m_helpFrame
)
213 (* size
) = m_helpFrame
->GetSize();
214 if (pos
&& m_helpFrame
)
215 (* pos
) = m_helpFrame
->GetPosition();
219 bool wxHtmlHelpController::Quit()