]> git.saurik.com Git - wxWidgets.git/blob - src/html/helpctrl.cpp
fix for MSWDetachWindowMenu when "&Window" string is translated
[wxWidgets.git] / src / html / helpctrl.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: helpctrl.cpp
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
7 // RCS-ID: $Id$
8 // Copyright: (c) Harm van der Heijden and Vaclav Slavik
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifdef __GNUG__
13 #pragma implementation
14 #endif
15
16 // For compilers that support precompilation, includes "wx.h".
17 #include "wx/wxprec.h"
18
19 #ifdef __BORLANDC__
20 #pragma hdrstop
21 #endif
22
23 #include "wx/defs.h"
24
25 #if wxUSE_HTML && wxUSE_STREAMS
26
27 #include "wx/html/helpctrl.h"
28 #include "wx/wx.h"
29 #include "wx/busyinfo.h"
30
31 IMPLEMENT_DYNAMIC_CLASS(wxHtmlHelpController, wxHelpControllerBase)
32
33 wxHtmlHelpController::wxHtmlHelpController(int style)
34 {
35 m_helpFrame = NULL;
36 m_Config = NULL;
37 m_ConfigRoot = wxEmptyString;
38 m_titleFormat = _("Help: %s");
39 m_FrameStyle = style;
40 }
41
42 wxHtmlHelpController::~wxHtmlHelpController()
43 {
44 if (m_Config)
45 WriteCustomization(m_Config, m_ConfigRoot);
46 if (m_helpFrame)
47 DestroyHelpWindow();
48 }
49
50
51 void wxHtmlHelpController::DestroyHelpWindow()
52 {
53 //if (m_Config) WriteCustomization(m_Config, m_ConfigRoot);
54 if (m_helpFrame)
55 m_helpFrame->Destroy();
56 }
57
58 void wxHtmlHelpController::OnCloseFrame(wxCloseEvent& evt)
59 {
60 evt.Skip();
61
62 OnQuit();
63
64 m_helpFrame->SetController((wxHelpControllerBase*) NULL);
65 m_helpFrame = NULL;
66 }
67
68 void wxHtmlHelpController::SetTitleFormat(const wxString& title)
69 {
70 m_titleFormat = title;
71 if (m_helpFrame)
72 m_helpFrame->SetTitleFormat(title);
73 }
74
75
76 bool wxHtmlHelpController::AddBook(const wxString& book, bool show_wait_msg)
77 {
78 wxBusyCursor cur;
79 #if wxUSE_BUSYINFO
80 wxBusyInfo* busy = NULL;
81 wxString info;
82 if (show_wait_msg)
83 {
84 info.Printf(_("Adding book %s"), book.c_str());
85 busy = new wxBusyInfo(info);
86 }
87 #endif
88 bool retval = m_helpData.AddBook(book);
89 #if wxUSE_BUSYINFO
90 if (show_wait_msg)
91 delete busy;
92 #endif
93 return retval;
94 }
95
96
97
98 wxHtmlHelpFrame *wxHtmlHelpController::CreateHelpFrame(wxHtmlHelpData *data)
99 {
100 return new wxHtmlHelpFrame(data);
101 }
102
103
104 void wxHtmlHelpController::CreateHelpWindow()
105 {
106 if (m_helpFrame)
107 {
108 m_helpFrame->Raise();
109 return ;
110 }
111
112 if (m_Config == NULL)
113 {
114 m_Config = wxConfigBase::Get(FALSE);
115 if (m_Config != NULL)
116 m_ConfigRoot = _T("wxWindows/wxHtmlHelpController");
117 }
118
119 m_helpFrame = CreateHelpFrame(&m_helpData);
120 m_helpFrame->SetController(this);
121
122 if (m_Config)
123 m_helpFrame->UseConfig(m_Config, m_ConfigRoot);
124
125 m_helpFrame->Create(NULL, wxID_HTML_HELPFRAME, wxEmptyString, m_FrameStyle);
126 m_helpFrame->SetTitleFormat(m_titleFormat);
127 m_helpFrame->Show(TRUE);
128 }
129
130 void wxHtmlHelpController::ReadCustomization(wxConfigBase* cfg, const wxString& path)
131 {
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);
136 }
137
138 void wxHtmlHelpController::WriteCustomization(wxConfigBase* cfg, const wxString& path)
139 {
140 /* typically called by the controllers OnCloseFrame handler */
141 if (m_helpFrame && cfg)
142 m_helpFrame->WriteCustomization(cfg, path);
143 }
144
145 void wxHtmlHelpController::UseConfig(wxConfigBase *config, const wxString& rootpath)
146 {
147 m_Config = config;
148 m_ConfigRoot = rootpath;
149 if (m_helpFrame) m_helpFrame->UseConfig(config, rootpath);
150 ReadCustomization(config, rootpath);
151 }
152
153 //// Backward compatibility with wxHelpController API
154
155 bool wxHtmlHelpController::Initialize(const wxString& file)
156 {
157 wxString dir, filename, ext;
158 wxSplitPath(file, & dir, & filename, & ext);
159
160 if (!dir.IsEmpty())
161 dir = dir + wxString(wxT("/"));
162
163 // Try to find a suitable file
164 wxString actualFilename = dir + filename + wxString(wxT(".zip"));
165 if (!wxFileExists(actualFilename))
166 {
167 actualFilename = dir + filename + wxString(wxT(".htb"));
168 if (!wxFileExists(actualFilename))
169 {
170 actualFilename = dir + filename + wxString(wxT(".hhp"));
171 if (!wxFileExists(actualFilename))
172 return FALSE;
173 }
174 }
175
176 return AddBook(actualFilename);
177 }
178
179 bool wxHtmlHelpController::LoadFile(const wxString& WXUNUSED(file))
180 {
181 // Don't reload the file or we'll have it appear again, presumably.
182 return TRUE;
183 }
184
185 bool wxHtmlHelpController::DisplaySection(int sectionNo)
186 {
187 return Display(sectionNo);
188 }
189
190 void wxHtmlHelpController::SetFrameParameters(const wxString& title,
191 const wxSize& size,
192 const wxPoint& pos,
193 bool WXUNUSED(newFrameEachTime))
194 {
195 SetTitleFormat(title);
196 if (m_helpFrame)
197 {
198 m_helpFrame->SetSize(pos.x, pos.y, size.x, size.y);
199 }
200 }
201
202 wxFrame* wxHtmlHelpController::GetFrameParameters(wxSize *size,
203 wxPoint *pos,
204 bool *newFrameEachTime)
205 {
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();
212 return m_helpFrame;
213 }
214
215 bool wxHtmlHelpController::Quit()
216 {
217 DestroyHelpWindow();
218 return TRUE;
219 }
220
221
222 #endif