]>
Commit | Line | Data |
---|---|---|
8ec2b484 HH |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: helpctrl.cpp | |
3 | // Purpose: wxHtmlHelpController | |
f42b1601 | 4 | // Notes: Based on htmlhelp.cpp, implementing a monolithic |
8ec2b484 HH |
5 | // HTML Help controller class, by Vaclav Slavik |
6 | // Author: Harm van der Heijden and Vaclav Slavik | |
69941f05 | 7 | // RCS-ID: $Id$ |
8ec2b484 HH |
8 | // Copyright: (c) Harm van der Heijden and Vaclav Slavik |
9 | // Licence: wxWindows licence | |
10 | ///////////////////////////////////////////////////////////////////////////// | |
11 | ||
12 | #ifdef __GNUG__ | |
69941f05 | 13 | #pragma implementation |
8ec2b484 HH |
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 | ||
f42b1601 RD |
31 | IMPLEMENT_DYNAMIC_CLASS(wxHtmlHelpController, wxEvtHandler) |
32 | ||
8ec2b484 | 33 | BEGIN_EVENT_TABLE(wxHtmlHelpController, wxEvtHandler) |
d5bb85a0 | 34 | EVT_CLOSE(wxHtmlHelpController::OnCloseFrame) |
8ec2b484 HH |
35 | END_EVENT_TABLE() |
36 | ||
d5bb85a0 | 37 | wxHtmlHelpController::wxHtmlHelpController(int style) |
8ec2b484 HH |
38 | { |
39 | m_helpFrame = NULL; | |
40 | m_Config = NULL; | |
41 | m_ConfigRoot = wxEmptyString; | |
42 | m_titleFormat = _("Help: %s"); | |
d5bb85a0 | 43 | m_FrameStyle = style; |
8ec2b484 HH |
44 | } |
45 | ||
46 | wxHtmlHelpController::~wxHtmlHelpController() | |
47 | { | |
48 | WriteCustomization(m_Config, m_ConfigRoot); | |
49 | if (m_helpFrame) | |
b854b7b8 | 50 | DestroyHelpWindow(); |
8ec2b484 HH |
51 | } |
52 | ||
b854b7b8 VS |
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 | ||
8ec2b484 HH |
69 | void wxHtmlHelpController::SetTitleFormat(const wxString& title) |
70 | { | |
71 | m_titleFormat = title; | |
72 | if (m_helpFrame) | |
d5bb85a0 | 73 | m_helpFrame->SetTitleFormat(title); |
8ec2b484 HH |
74 | } |
75 | ||
d5bb85a0 | 76 | |
8ec2b484 HH |
77 | bool wxHtmlHelpController::AddBook(const wxString& book, bool show_wait_msg) |
78 | { | |
79 | wxBusyCursor cur; | |
80 | #if wxUSE_BUSYINFO | |
69941f05 | 81 | wxBusyInfo* busy = NULL; |
8ec2b484 HH |
82 | wxString info; |
83 | if (show_wait_msg) { | |
d5bb85a0 VS |
84 | info.Printf(_("Adding book %s"), book.c_str()); |
85 | busy = new wxBusyInfo(info); | |
8ec2b484 HH |
86 | } |
87 | #endif | |
88 | bool retval = m_helpData.AddBook(book); | |
89 | #if wxUSE_BUSYINFO | |
90 | if (show_wait_msg) | |
d5bb85a0 VS |
91 | delete busy; |
92 | #endif | |
8ec2b484 HH |
93 | return retval; |
94 | } | |
95 | ||
b854b7b8 VS |
96 | |
97 | ||
98 | wxHtmlHelpFrame *wxHtmlHelpController::CreateHelpFrame(wxHtmlHelpData *data) | |
99 | { | |
100 | return new wxHtmlHelpFrame(data); | |
101 | } | |
102 | ||
103 | ||
052e12db | 104 | void wxHtmlHelpController::CreateHelpWindow() |
8ec2b484 HH |
105 | { |
106 | if (m_helpFrame) { | |
d5bb85a0 VS |
107 | m_helpFrame->Raise(); |
108 | return ; | |
8ec2b484 | 109 | } |
d5bb85a0 | 110 | |
74accc50 VS |
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 | ||
b854b7b8 | 118 | m_helpFrame = CreateHelpFrame(&m_helpData); |
8ec2b484 | 119 | m_helpFrame->PushEventHandler(this); |
74accc50 | 120 | |
8ec2b484 | 121 | if (m_Config) |
d5bb85a0 | 122 | m_helpFrame->UseConfig(m_Config, m_ConfigRoot); |
74accc50 | 123 | |
d5bb85a0 | 124 | m_helpFrame->Create(NULL, wxID_HTML_HELPFRAME, wxEmptyString, m_FrameStyle); |
8ec2b484 HH |
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) | |
d5bb85a0 | 134 | m_helpFrame->ReadCustomization(cfg, path); |
8ec2b484 HH |
135 | } |
136 | ||
137 | void wxHtmlHelpController::WriteCustomization(wxConfigBase* cfg, const wxString& path) | |
138 | { | |
139 | /* typically called by the controllers OnCloseFrame handler */ | |
140 | if (m_helpFrame) | |
d5bb85a0 | 141 | m_helpFrame->WriteCustomization(cfg, path); |
8ec2b484 HH |
142 | } |
143 | ||
721ab905 VS |
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 | ||
8ec2b484 | 153 | #endif |