]>
Commit | Line | Data |
---|---|---|
4e4152e4 JS |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: helpview.h | |
3 | // Purpose: HelpView application | |
4 | // A standalone viewer for wxHTML Help (.htb) files | |
5 | // Author: Vaclav Slavik, Julian Smart | |
6 | // Modified by: | |
7 | // Created: 2002-07-09 | |
8 | // RCS-ID: $Id$ | |
9 | // Copyright: (c) 2002 Vaclav Slavik, Julian Smart and others | |
10 | // Licence: wxWindows licence | |
11 | ///////////////////////////////////////////////////////////////////////////// | |
12 | ||
13 | #ifdef __GNUG__ | |
14 | #pragma implementation "help.cpp" | |
15 | #endif | |
16 | ||
17 | // For compilers that support precompilation, includes "wx/wx.h". | |
18 | #include "wx/wxprec.h" | |
19 | ||
20 | #ifdef __BORLANDC__ | |
21 | #pragma hdrstop | |
22 | #endif | |
23 | ||
24 | // for all others, include the necessary headers (this file is usually all you | |
25 | // need because it includes almost all "standard" wxWindows headers | |
26 | #ifndef WX_PRECOMP | |
27 | #include "wx/wx.h" | |
28 | #endif | |
29 | ||
30 | #include "wx/image.h" | |
31 | #include "wx/wxhtml.h" | |
32 | #include "wx/fs_zip.h" | |
33 | #include "wx/log.h" | |
34 | #include "wx/artprov.h" | |
35 | #include "wx/filedlg.h" | |
36 | ||
877c86a2 JS |
37 | #include "helpview.h" |
38 | ||
4e4152e4 JS |
39 | class AlternateArtProvider : public wxArtProvider |
40 | { | |
41 | protected: | |
42 | virtual wxBitmap CreateBitmap(const wxArtID& id, const wxArtClient& client, | |
43 | const wxSize& size); | |
44 | }; | |
45 | ||
46 | // ---------------------------------------------------------------------------- | |
47 | // private classes | |
48 | // ---------------------------------------------------------------------------- | |
49 | ||
50 | ||
51 | IMPLEMENT_APP(hvApp) | |
52 | ||
53 | ||
54 | bool hvApp::OnInit() | |
55 | { | |
56 | #ifdef __WXMOTIF__ | |
57 | delete wxLog::SetActiveTarget(new wxLogStderr); // So dialog boxes aren't used | |
58 | #endif | |
59 | ||
60 | wxArtProvider::PushProvider(new AlternateArtProvider); | |
61 | ||
62 | wxInitAllImageHandlers(); | |
63 | wxFileSystem::AddHandler(new wxZipFSHandler); | |
64 | ||
65 | SetVendorName("wxWindows"); | |
66 | SetAppName("wxHTMLHelp"); | |
67 | wxConfig::Get(); // create an instance | |
68 | ||
69 | help = new wxHtmlHelpController( | |
70 | wxHF_DEFAULT_STYLE|wxHF_FLAT_TOOLBAR|wxHF_OPEN_FILES | |
71 | ); | |
72 | ||
73 | help->SetTitleFormat(wxT("%s")); | |
74 | if (argc < 2) { | |
75 | if (!OpenBook(help)) | |
76 | return FALSE; | |
77 | } | |
78 | ||
79 | for (int i = 1; i < argc; i++) | |
80 | help -> AddBook(argv[i]); | |
81 | ||
82 | #ifdef __WXMOTIF__ | |
83 | delete wxLog::SetActiveTarget(new wxLogGui); | |
84 | #endif | |
85 | ||
86 | help -> DisplayContents(); | |
87 | ||
88 | return TRUE; | |
89 | } | |
90 | ||
91 | ||
92 | int hvApp::OnExit() | |
93 | { | |
94 | delete help; | |
95 | delete wxConfig::Set(NULL); | |
96 | ||
97 | return 0; | |
98 | } | |
99 | ||
100 | bool hvApp::OpenBook(wxHtmlHelpController* controller) | |
101 | { | |
102 | wxString s = wxFileSelector(_("Open help file"), | |
103 | wxGetCwd(), | |
104 | wxEmptyString, | |
105 | wxEmptyString, | |
106 | _( | |
107 | "Help books (*.htb)|*.htb|Help books (*.zip)|*.zip|\ | |
108 | HTML Help Project (*.hhp)|*.hhp"), | |
109 | wxOPEN | wxFILE_MUST_EXIST, | |
110 | NULL); | |
111 | ||
112 | if (!s.IsEmpty()) | |
113 | { | |
114 | wxString ext = s.Right(4).Lower(); | |
115 | if (ext == _T(".zip") || ext == _T(".htb") || ext == _T(".hhp")) | |
116 | { | |
117 | wxBusyCursor bcur; | |
118 | controller->AddBook(s); | |
119 | return TRUE; | |
120 | } | |
121 | } | |
122 | return FALSE; | |
123 | } | |
124 | ||
125 | /* | |
126 | * Art provider class | |
127 | */ | |
128 | ||
129 | // --------------------------------------------------------------------- | |
130 | // helper macros | |
131 | // --------------------------------------------------------------------- | |
132 | ||
133 | // Standard macro for getting a resource from XPM file: | |
134 | #define ART(artId, xpmRc) \ | |
135 | if ( id == artId ) return wxBitmap(xpmRc##_xpm); | |
136 | ||
137 | // Compatibility hack to use wxApp::GetStdIcon of overriden by the user | |
138 | #if WXWIN_COMPATIBILITY_2_2 | |
139 | #define GET_STD_ICON_FROM_APP(iconId) \ | |
140 | if ( client == wxART_MESSAGE_BOX ) \ | |
141 | { \ | |
142 | wxIcon icon = wxTheApp->GetStdIcon(iconId); \ | |
143 | if ( icon.Ok() ) \ | |
144 | { \ | |
145 | wxBitmap bmp; \ | |
146 | bmp.CopyFromIcon(icon); \ | |
147 | return bmp; \ | |
148 | } \ | |
149 | } | |
150 | #else | |
151 | #define GET_STD_ICON_FROM_APP(iconId) | |
152 | #endif | |
153 | ||
154 | // There are two ways of getting the standard icon: either via XPMs or via | |
155 | // wxIcon ctor. This depends on the platform: | |
156 | #if defined(__WXUNIVERSAL__) | |
157 | #define CREATE_STD_ICON(iconId, xpmRc) return wxNullBitmap; | |
158 | #elif defined(__WXGTK__) || defined(__WXMOTIF__) | |
159 | #define CREATE_STD_ICON(iconId, xpmRc) return wxBitmap(xpmRc##_xpm); | |
160 | #else | |
161 | #define CREATE_STD_ICON(iconId, xpmRc) \ | |
162 | { \ | |
163 | wxIcon icon(_T(iconId)); \ | |
164 | wxBitmap bmp; \ | |
165 | bmp.CopyFromIcon(icon); \ | |
166 | return bmp; \ | |
167 | } | |
168 | #endif | |
169 | ||
170 | // Macro used in CreateBitmap to get wxICON_FOO icons: | |
171 | #define ART_MSGBOX(artId, iconId, xpmRc) \ | |
172 | if ( id == artId ) \ | |
173 | { \ | |
174 | GET_STD_ICON_FROM_APP(iconId) \ | |
175 | CREATE_STD_ICON(#iconId, xpmRc) \ | |
176 | } | |
177 | ||
178 | // --------------------------------------------------------------------- | |
179 | // XPMs with the art | |
180 | // --------------------------------------------------------------------- | |
181 | ||
182 | // XPM hack: make the arrays const | |
183 | //#define static static const | |
184 | ||
185 | #include "bitmaps/helpback.xpm" | |
186 | #include "bitmaps/helpbook.xpm" | |
187 | #include "bitmaps/helpdown.xpm" | |
188 | #include "bitmaps/helpforward.xpm" | |
189 | #include "bitmaps/helpoptions.xpm" | |
190 | #include "bitmaps/helppage.xpm" | |
191 | #include "bitmaps/helpsidepanel.xpm" | |
192 | #include "bitmaps/helpup.xpm" | |
193 | #include "bitmaps/helpuplevel.xpm" | |
194 | #include "bitmaps/helpicon.xpm" | |
195 | #include "bitmaps/helpopen.xpm" | |
196 | ||
197 | //#undef static | |
198 | ||
199 | // --------------------------------------------------------------------- | |
200 | // CreateBitmap routine | |
201 | // --------------------------------------------------------------------- | |
202 | ||
203 | wxBitmap AlternateArtProvider::CreateBitmap(const wxArtID& id, | |
204 | const wxArtClient& client, | |
205 | const wxSize& WXUNUSED(size)) | |
206 | { | |
207 | ART(wxART_HELP_SIDE_PANEL, helpsidepanel) | |
208 | ART(wxART_HELP_SETTINGS, helpoptions) | |
209 | ART(wxART_HELP_BOOK, helpbook) | |
210 | ART(wxART_HELP_FOLDER, helpbook) | |
211 | ART(wxART_HELP_PAGE, helppage) | |
212 | //ART(wxART_ADD_BOOKMARK, addbookm) | |
213 | //ART(wxART_DEL_BOOKMARK, delbookm) | |
214 | ART(wxART_GO_BACK, helpback) | |
215 | ART(wxART_GO_FORWARD, helpforward) | |
216 | ART(wxART_GO_UP, helpup) | |
217 | ART(wxART_GO_DOWN, helpdown) | |
218 | ART(wxART_GO_TO_PARENT, helpuplevel) | |
219 | ART(wxART_FILE_OPEN, helpopen) | |
220 | if (client == wxART_HELP_BROWSER) | |
221 | { | |
222 | ART(wxART_FRAME_ICON, helpicon) | |
223 | } | |
224 | ||
225 | //ART(wxART_GO_HOME, home) | |
226 | ||
227 | // Any wxWindows icons not implemented here | |
228 | // will be provided by the default art provider. | |
229 | return wxNullBitmap; | |
230 | } |