]>
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"
25 #if wxUSE_HTML && wxUSE_STREAMS
27 #include "wx/html/helpctrl.h"
29 #include "wx/busyinfo.h"
31 IMPLEMENT_DYNAMIC_CLASS(wxHtmlHelpController
, wxHelpControllerBase
)
33 wxHtmlHelpController::wxHtmlHelpController(int style
)
37 m_ConfigRoot
= wxEmptyString
;
38 m_titleFormat
= _("Help: %s");
42 wxHtmlHelpController::~wxHtmlHelpController()
45 WriteCustomization(m_Config
, m_ConfigRoot
);
51 void wxHtmlHelpController::DestroyHelpWindow()
53 //if (m_Config) WriteCustomization(m_Config, m_ConfigRoot);
55 m_helpFrame
->Destroy();
58 void wxHtmlHelpController::OnCloseFrame(wxCloseEvent
& evt
)
64 m_helpFrame
->SetController((wxHelpControllerBase
*) NULL
);
68 void wxHtmlHelpController::SetTitleFormat(const wxString
& title
)
70 m_titleFormat
= title
;
72 m_helpFrame
->SetTitleFormat(title
);
76 bool wxHtmlHelpController::AddBook(const wxString
& book
, bool show_wait_msg
)
80 wxBusyInfo
* busy
= NULL
;
84 info
.Printf(_("Adding book %s"), book
.c_str());
85 busy
= new wxBusyInfo(info
);
88 bool retval
= m_helpData
.AddBook(book
);
98 wxHtmlHelpFrame
*wxHtmlHelpController::CreateHelpFrame(wxHtmlHelpData
*data
)
100 return new wxHtmlHelpFrame(data
);
104 void wxHtmlHelpController::CreateHelpWindow()
108 m_helpFrame
->Raise();
112 if (m_Config
== NULL
)
114 m_Config
= wxConfigBase::Get(FALSE
);
115 if (m_Config
!= NULL
)
116 m_ConfigRoot
= _T("wxWindows/wxHtmlHelpController");
119 m_helpFrame
= CreateHelpFrame(&m_helpData
);
120 m_helpFrame
->SetController(this);
123 m_helpFrame
->UseConfig(m_Config
, m_ConfigRoot
);
125 m_helpFrame
->Create(NULL
, wxID_HTML_HELPFRAME
, wxEmptyString
, m_FrameStyle
);
126 m_helpFrame
->SetTitleFormat(m_titleFormat
);
127 m_helpFrame
->Show(TRUE
);
130 void wxHtmlHelpController::ReadCustomization(wxConfigBase
* cfg
, const wxString
& path
)
132 /* should not be called by the user; call UseConfig, and the controller
133 * will do the rest */
134 if (m_helpFrame
&& cfg
)
135 m_helpFrame
->ReadCustomization(cfg
, path
);
138 void wxHtmlHelpController::WriteCustomization(wxConfigBase
* cfg
, const wxString
& path
)
140 /* typically called by the controllers OnCloseFrame handler */
141 if (m_helpFrame
&& cfg
)
142 m_helpFrame
->WriteCustomization(cfg
, path
);
145 void wxHtmlHelpController::UseConfig(wxConfigBase
*config
, const wxString
& rootpath
)
148 m_ConfigRoot
= rootpath
;
149 if (m_helpFrame
) m_helpFrame
->UseConfig(config
, rootpath
);
150 ReadCustomization(config
, rootpath
);
153 //// Backward compatibility with wxHelpController API
155 bool wxHtmlHelpController::Initialize(const wxString
& file
)
157 wxString dir
, filename
, ext
;
158 wxSplitPath(file
, & dir
, & filename
, & ext
);
161 dir
= dir
+ wxString(wxT("/"));
163 // Try to find a suitable file
164 wxString actualFilename
= dir
+ filename
+ wxString(wxT(".zip"));
165 if (!wxFileExists(actualFilename
))
167 actualFilename
= dir
+ filename
+ wxString(wxT(".htb"));
168 if (!wxFileExists(actualFilename
))
170 actualFilename
= dir
+ filename
+ wxString(wxT(".hhp"));
171 if (!wxFileExists(actualFilename
))
176 return AddBook(actualFilename
);
179 bool wxHtmlHelpController::LoadFile(const wxString
& WXUNUSED(file
))
181 // Don't reload the file or we'll have it appear again, presumably.
185 bool wxHtmlHelpController::DisplaySection(int sectionNo
)
187 return Display(sectionNo
);
190 void wxHtmlHelpController::SetFrameParameters(const wxString
& title
,
193 bool WXUNUSED(newFrameEachTime
))
195 SetTitleFormat(title
);
198 m_helpFrame
->SetSize(pos
.x
, pos
.y
, size
.x
, size
.y
);
202 wxFrame
* wxHtmlHelpController::GetFrameParameters(wxSize
*size
,
204 bool *newFrameEachTime
)
206 if (newFrameEachTime
)
207 (* newFrameEachTime
) = FALSE
;
208 if (size
&& m_helpFrame
)
209 (* size
) = m_helpFrame
->GetSize();
210 if (pos
&& m_helpFrame
)
211 (* pos
) = m_helpFrame
->GetPosition();
215 bool wxHtmlHelpController::Quit()