]> git.saurik.com Git - wxWidgets.git/blob - src/html/helpctrl.cpp
OGL: misc.cpp clashes with misc.c frim iODBC, therefore
[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
26
27 #include "wx/html/helpctrl.h"
28 #include "wx/wx.h"
29 #include "wx/busyinfo.h"
30
31 IMPLEMENT_DYNAMIC_CLASS(wxHtmlHelpController, wxEvtHandler)
32
33 BEGIN_EVENT_TABLE(wxHtmlHelpController, wxEvtHandler)
34 EVT_CLOSE(wxHtmlHelpController::OnCloseFrame)
35 END_EVENT_TABLE()
36
37 wxHtmlHelpController::wxHtmlHelpController(int style)
38 {
39 m_helpFrame = NULL;
40 m_Config = NULL;
41 m_ConfigRoot = wxEmptyString;
42 m_titleFormat = _("Help: %s");
43 m_FrameStyle = style;
44 }
45
46 wxHtmlHelpController::~wxHtmlHelpController()
47 {
48 WriteCustomization(m_Config, m_ConfigRoot);
49 if (m_helpFrame)
50 DestroyHelpWindow();
51 }
52
53
54 void wxHtmlHelpController::DestroyHelpWindow()
55 {
56 //if (m_Config) WriteCustomization(m_Config, m_ConfigRoot);
57 if (m_helpFrame)
58 m_helpFrame->Destroy();
59 }
60
61 void wxHtmlHelpController::OnCloseFrame(wxCloseEvent& evt)
62 {
63 evt.Skip();
64
65 m_helpFrame = NULL;
66 }
67
68
69 void wxHtmlHelpController::SetTitleFormat(const wxString& title)
70 {
71 m_titleFormat = title;
72 if (m_helpFrame)
73 m_helpFrame->SetTitleFormat(title);
74 }
75
76
77 bool wxHtmlHelpController::AddBook(const wxString& book, bool show_wait_msg)
78 {
79 wxBusyCursor cur;
80 #if wxUSE_BUSYINFO
81 wxBusyInfo* busy = NULL;
82 wxString info;
83 if (show_wait_msg) {
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 m_helpFrame->Raise();
108 return ;
109 }
110
111 if (m_Config == NULL)
112 {
113 m_Config = wxConfigBase::Get(FALSE);
114 if (m_Config != NULL)
115 m_ConfigRoot = _T("wxWindows/wxHtmlHelpController");
116 }
117
118 m_helpFrame = CreateHelpFrame(&m_helpData);
119 m_helpFrame->PushEventHandler(this);
120
121 if (m_Config)
122 m_helpFrame->UseConfig(m_Config, m_ConfigRoot);
123
124 m_helpFrame->Create(NULL, wxID_HTML_HELPFRAME, wxEmptyString, m_FrameStyle);
125 m_helpFrame->SetTitleFormat(m_titleFormat);
126 m_helpFrame->Show(TRUE);
127 }
128
129 void wxHtmlHelpController::ReadCustomization(wxConfigBase* cfg, const wxString& path)
130 {
131 /* should not be called by the user; call UseConfig, and the controller
132 * will do the rest */
133 if (m_helpFrame)
134 m_helpFrame->ReadCustomization(cfg, path);
135 }
136
137 void wxHtmlHelpController::WriteCustomization(wxConfigBase* cfg, const wxString& path)
138 {
139 /* typically called by the controllers OnCloseFrame handler */
140 if (m_helpFrame)
141 m_helpFrame->WriteCustomization(cfg, path);
142 }
143
144 void wxHtmlHelpController::UseConfig(wxConfigBase *config, const wxString& rootpath)
145 {
146 m_Config = config;
147 m_ConfigRoot = rootpath;
148 if (m_helpFrame) m_helpFrame -> UseConfig(config, rootpath);
149 ReadCustomization(config, rootpath);
150 }
151
152
153 #endif