]> git.saurik.com Git - wxWidgets.git/blob - src/html/helpctrl.cpp
If the number or float editor is being used but the values are
[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 "helpctrl.h"
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 #if wxUSE_WXHTML_HELP
24
25 #ifndef WX_PRECOMP
26     #include "wx/app.h"
27     #include "wx/intl.h"
28 #endif // WX_PRECOMP
29
30 #include "wx/html/helpctrl.h"
31 #include "wx/busyinfo.h"
32
33 #ifdef __WXGTK__
34     // for the hack in AddGrabIfNeeded()
35     #include "wx/dialog.h"
36 #endif // __WXGTK__
37
38 #if wxUSE_HELP
39     #include "wx/tipwin.h"
40 #endif
41
42 IMPLEMENT_DYNAMIC_CLASS(wxHtmlHelpController, wxHelpControllerBase)
43
44 wxHtmlHelpController::wxHtmlHelpController(int style)
45 {
46     m_helpFrame = NULL;
47     m_Config = NULL;
48     m_ConfigRoot = wxEmptyString;
49     m_titleFormat = _("Help: %s");
50     m_FrameStyle = style;
51 }
52
53 wxHtmlHelpController::~wxHtmlHelpController()
54 {
55     if (m_Config)
56         WriteCustomization(m_Config, m_ConfigRoot);
57     if (m_helpFrame)
58         DestroyHelpWindow();
59 }
60
61
62 void wxHtmlHelpController::DestroyHelpWindow()
63 {
64     //if (m_Config) WriteCustomization(m_Config, m_ConfigRoot);
65     if (m_helpFrame)
66         m_helpFrame->Destroy();
67 }
68
69 void wxHtmlHelpController::OnCloseFrame(wxCloseEvent& evt)
70 {
71     evt.Skip();
72
73     OnQuit();
74
75     m_helpFrame->SetController((wxHelpControllerBase*) NULL);
76     m_helpFrame = NULL;
77 }
78
79 void wxHtmlHelpController::SetTitleFormat(const wxString& title)
80 {
81     m_titleFormat = title;
82     if (m_helpFrame)
83         m_helpFrame->SetTitleFormat(title);
84 }
85
86
87 bool wxHtmlHelpController::AddBook(const wxString& book, bool show_wait_msg)
88 {
89     wxBusyCursor cur;
90 #if wxUSE_BUSYINFO
91     wxBusyInfo* busy = NULL;
92     wxString info;
93     if (show_wait_msg)
94     {
95         info.Printf(_("Adding book %s"), book.c_str());
96         busy = new wxBusyInfo(info);
97     }
98 #endif
99     bool retval = m_helpData.AddBook(book);
100 #if wxUSE_BUSYINFO
101     if (show_wait_msg)
102         delete busy;
103 #endif
104     if (m_helpFrame) 
105         m_helpFrame->RefreshLists();
106     return retval;
107 }
108
109
110
111 wxHtmlHelpFrame *wxHtmlHelpController::CreateHelpFrame(wxHtmlHelpData *data)
112 {
113     return new wxHtmlHelpFrame(data);
114 }
115
116
117 void wxHtmlHelpController::CreateHelpWindow()
118 {
119     if (m_helpFrame)
120     {
121         m_helpFrame->Raise();
122         return ;
123     }
124
125     if (m_Config == NULL)
126     {
127         m_Config = wxConfigBase::Get(FALSE);
128         if (m_Config != NULL)
129             m_ConfigRoot = _T("wxWindows/wxHtmlHelpController");
130     }
131
132     m_helpFrame = CreateHelpFrame(&m_helpData);
133     m_helpFrame->SetController(this);
134
135     if (m_Config)
136         m_helpFrame->UseConfig(m_Config, m_ConfigRoot);
137
138     m_helpFrame->Create(NULL, wxID_HTML_HELPFRAME, wxEmptyString, m_FrameStyle);
139     m_helpFrame->SetTitleFormat(m_titleFormat);
140     m_helpFrame->Show(TRUE);
141 }
142
143 void wxHtmlHelpController::ReadCustomization(wxConfigBase* cfg, const wxString& path)
144 {
145     /* should not be called by the user; call UseConfig, and the controller
146      * will do the rest */
147     if (m_helpFrame && cfg)
148         m_helpFrame->ReadCustomization(cfg, path);
149 }
150
151 void wxHtmlHelpController::WriteCustomization(wxConfigBase* cfg, const wxString& path)
152 {
153     /* typically called by the controllers OnCloseFrame handler */
154     if (m_helpFrame && cfg)
155         m_helpFrame->WriteCustomization(cfg, path);
156 }
157
158 void wxHtmlHelpController::UseConfig(wxConfigBase *config, const wxString& rootpath)
159 {
160     m_Config = config;
161     m_ConfigRoot = rootpath;
162     if (m_helpFrame) m_helpFrame->UseConfig(config, rootpath);
163     ReadCustomization(config, rootpath);
164 }
165
166 //// Backward compatibility with wxHelpController API
167
168 bool wxHtmlHelpController::Initialize(const wxString& file)
169 {
170     wxString dir, filename, ext;
171     wxSplitPath(file, & dir, & filename, & ext);
172
173     if (!dir.IsEmpty())
174         dir = dir + wxString(wxT("/"));
175
176     // Try to find a suitable file
177     wxString actualFilename = dir + filename + wxString(wxT(".zip"));
178     if (!wxFileExists(actualFilename))
179     {
180         actualFilename = dir + filename + wxString(wxT(".htb"));
181         if (!wxFileExists(actualFilename))
182         {
183             actualFilename = dir + filename + wxString(wxT(".hhp"));
184             if (!wxFileExists(actualFilename))
185                 return FALSE;
186         }
187     }
188
189     return AddBook(actualFilename);
190 }
191
192 bool wxHtmlHelpController::LoadFile(const wxString& WXUNUSED(file))
193 {
194     // Don't reload the file or we'll have it appear again, presumably.
195     return TRUE;
196 }
197
198 bool wxHtmlHelpController::DisplaySection(int sectionNo)
199 {
200     return Display(sectionNo);
201 }
202
203 bool wxHtmlHelpController::DisplayTextPopup(const wxString& text, const wxPoint& WXUNUSED(pos))
204 {
205 #if wxUSE_TIPWINDOW
206     static wxTipWindow* s_tipWindow = NULL;
207
208     if (s_tipWindow)
209     {
210         // Prevent s_tipWindow being nulled in OnIdle,
211         // thereby removing the chance for the window to be closed by ShowHelp
212         s_tipWindow->SetTipWindowPtr(NULL);
213         s_tipWindow->Close();
214     }
215     s_tipWindow = NULL;
216
217     if ( !text.empty() )
218     {
219         s_tipWindow = new wxTipWindow(wxTheApp->GetTopWindow(), text, 100, & s_tipWindow);
220
221         return TRUE;
222     }
223 #endif // wxUSE_TIPWINDOW
224
225     return FALSE;
226 }
227
228 void wxHtmlHelpController::SetFrameParameters(const wxString& title,
229                                    const wxSize& size,
230                                    const wxPoint& pos,
231                                    bool WXUNUSED(newFrameEachTime))
232 {
233     SetTitleFormat(title);
234     if (m_helpFrame)
235     {
236         m_helpFrame->SetSize(pos.x, pos.y, size.x, size.y);
237     }
238 }
239
240 wxFrame* wxHtmlHelpController::GetFrameParameters(wxSize *size,
241                                    wxPoint *pos,
242                                    bool *newFrameEachTime)
243 {
244     if (newFrameEachTime)
245         (* newFrameEachTime) = FALSE;
246     if (size && m_helpFrame)
247         (* size) = m_helpFrame->GetSize();
248     if (pos && m_helpFrame)
249         (* pos) = m_helpFrame->GetPosition();
250     return m_helpFrame;
251 }
252
253 bool wxHtmlHelpController::Quit()
254 {
255     DestroyHelpWindow();
256     return TRUE;
257 }
258
259 // Make the help controller's frame 'modal' if
260 // needed
261 void wxHtmlHelpController::AddGrabIfNeeded()
262 {
263     // So far, wxGTK only
264 #ifdef __WXGTK__
265     bool needGrab = FALSE;
266     
267     // Check if there are any modal windows present,
268     // in which case we need to add a grab.
269     for ( wxWindowList::Node * node = wxTopLevelWindows.GetFirst();
270           node;
271           node = node->GetNext() )
272     {
273         wxWindow *win = node->GetData();
274         wxDialog *dialog = wxDynamicCast(win, wxDialog);
275
276         if (dialog && dialog->IsModal())
277             needGrab = TRUE;
278     }
279
280     if (needGrab && m_helpFrame)
281         m_helpFrame->AddGrab();
282 #endif // __WXGTK__
283 }
284
285 bool wxHtmlHelpController::Display(const wxString& x)
286 {
287     CreateHelpWindow();
288     bool success = m_helpFrame->Display(x);
289     AddGrabIfNeeded();
290     return success;    
291 }
292
293 bool wxHtmlHelpController::Display(int id)
294 {
295     CreateHelpWindow();
296     bool success = m_helpFrame->Display(id);
297     AddGrabIfNeeded();
298     return success;
299 }
300
301 bool wxHtmlHelpController::DisplayContents()
302 {
303     CreateHelpWindow();
304     bool success = m_helpFrame->DisplayContents();
305     AddGrabIfNeeded();
306     return success;
307 }
308
309 bool wxHtmlHelpController::DisplayIndex()
310 {
311     CreateHelpWindow();
312     bool success = m_helpFrame->DisplayIndex();
313     AddGrabIfNeeded();
314     return success;
315 }
316
317 bool wxHtmlHelpController::KeywordSearch(const wxString& keyword)
318 {
319     CreateHelpWindow();
320     bool success = m_helpFrame->KeywordSearch(keyword);
321     AddGrabIfNeeded();
322     return success;
323 }
324
325 #endif // wxUSE_WXHTML_HELP
326