]>
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
;
83 info
.Printf(_("Adding book %s"), book
.c_str());
84 busy
= new wxBusyInfo(info
);
87 bool retval
= m_helpData
.AddBook(book
);
97 wxHtmlHelpFrame
*wxHtmlHelpController::CreateHelpFrame(wxHtmlHelpData
*data
)
99 return new wxHtmlHelpFrame(data
);
103 void wxHtmlHelpController::CreateHelpWindow()
106 m_helpFrame
->Raise();
110 if (m_Config
== NULL
)
112 m_Config
= wxConfigBase::Get(FALSE
);
113 if (m_Config
!= NULL
)
114 m_ConfigRoot
= _T("wxWindows/wxHtmlHelpController");
117 m_helpFrame
= CreateHelpFrame(&m_helpData
);
118 m_helpFrame
->SetController(this);
121 m_helpFrame
->UseConfig(m_Config
, m_ConfigRoot
);
123 m_helpFrame
->Create(NULL
, wxID_HTML_HELPFRAME
, wxEmptyString
, m_FrameStyle
);
124 m_helpFrame
->SetTitleFormat(m_titleFormat
);
125 m_helpFrame
->Show(TRUE
);
128 void wxHtmlHelpController::ReadCustomization(wxConfigBase
* cfg
, const wxString
& path
)
130 /* should not be called by the user; call UseConfig, and the controller
131 * will do the rest */
132 if (m_helpFrame
&& cfg
)
133 m_helpFrame
->ReadCustomization(cfg
, path
);
136 void wxHtmlHelpController::WriteCustomization(wxConfigBase
* cfg
, const wxString
& path
)
138 /* typically called by the controllers OnCloseFrame handler */
139 if (m_helpFrame
&& cfg
)
140 m_helpFrame
->WriteCustomization(cfg
, path
);
143 void wxHtmlHelpController::UseConfig(wxConfigBase
*config
, const wxString
& rootpath
)
146 m_ConfigRoot
= rootpath
;
147 if (m_helpFrame
) m_helpFrame
-> UseConfig(config
, rootpath
);
148 ReadCustomization(config
, rootpath
);
151 //// Backward compatibility with wxHelpController API
153 bool wxHtmlHelpController::Initialize(const wxString
& file
)
155 wxString dir
, filename
, ext
;
156 wxSplitPath(file
, & dir
, & filename
, & ext
);
159 dir
= dir
+ wxString(wxT("/"));
161 // Try to find a suitable file
162 wxString actualFilename
= dir
+ filename
+ wxString(wxT(".zip"));
163 if (!wxFileExists(actualFilename
))
165 actualFilename
= dir
+ filename
+ wxString(wxT(".htb"));
166 if (!wxFileExists(actualFilename
))
168 actualFilename
= dir
+ filename
+ wxString(wxT(".hhp"));
169 if (!wxFileExists(actualFilename
))
174 return AddBook(actualFilename
);
177 bool wxHtmlHelpController::LoadFile(const wxString
& WXUNUSED(file
))
179 // Don't reload the file or we'll have it appear again, presumably.
183 bool wxHtmlHelpController::DisplaySection(int sectionNo
)
185 return Display(sectionNo
);
188 void wxHtmlHelpController::SetFrameParameters(const wxString
& title
,
191 bool WXUNUSED(newFrameEachTime
))
193 SetTitleFormat(title
);
196 m_helpFrame
->SetSize(pos
.x
, pos
.y
, size
.x
, size
.y
);
200 wxFrame
* wxHtmlHelpController::GetFrameParameters(wxSize
*size
,
202 bool *newFrameEachTime
)
204 if (newFrameEachTime
)
205 (* newFrameEachTime
) = FALSE
;
206 if (size
&& m_helpFrame
)
207 (* size
) = m_helpFrame
->GetSize();
208 if (pos
&& m_helpFrame
)
209 (* pos
) = m_helpFrame
->GetPosition();
213 bool wxHtmlHelpController::Quit()