Added helpview utility
[wxWidgets.git] / utils / helpview / src / helpview.cpp
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
37 class AlternateArtProvider : public wxArtProvider
38 {
39 protected:
40 virtual wxBitmap CreateBitmap(const wxArtID& id, const wxArtClient& client,
41 const wxSize& size);
42 };
43
44 // ----------------------------------------------------------------------------
45 // private classes
46 // ----------------------------------------------------------------------------
47
48
49 IMPLEMENT_APP(hvApp)
50
51
52 bool hvApp::OnInit()
53 {
54 #ifdef __WXMOTIF__
55 delete wxLog::SetActiveTarget(new wxLogStderr); // So dialog boxes aren't used
56 #endif
57
58 wxArtProvider::PushProvider(new AlternateArtProvider);
59
60 wxInitAllImageHandlers();
61 wxFileSystem::AddHandler(new wxZipFSHandler);
62
63 SetVendorName("wxWindows");
64 SetAppName("wxHTMLHelp");
65 wxConfig::Get(); // create an instance
66
67 help = new wxHtmlHelpController(
68 wxHF_DEFAULT_STYLE|wxHF_FLAT_TOOLBAR|wxHF_OPEN_FILES
69 );
70
71 help->SetTitleFormat(wxT("%s"));
72 if (argc < 2) {
73 if (!OpenBook(help))
74 return FALSE;
75 }
76
77 for (int i = 1; i < argc; i++)
78 help -> AddBook(argv[i]);
79
80 #ifdef __WXMOTIF__
81 delete wxLog::SetActiveTarget(new wxLogGui);
82 #endif
83
84 help -> DisplayContents();
85
86 return TRUE;
87 }
88
89
90 int hvApp::OnExit()
91 {
92 delete help;
93 delete wxConfig::Set(NULL);
94
95 return 0;
96 }
97
98 bool hvApp::OpenBook(wxHtmlHelpController* controller)
99 {
100 wxString s = wxFileSelector(_("Open help file"),
101 wxGetCwd(),
102 wxEmptyString,
103 wxEmptyString,
104 _(
105 "Help books (*.htb)|*.htb|Help books (*.zip)|*.zip|\
106 HTML Help Project (*.hhp)|*.hhp"),
107 wxOPEN | wxFILE_MUST_EXIST,
108 NULL);
109
110 if (!s.IsEmpty())
111 {
112 wxString ext = s.Right(4).Lower();
113 if (ext == _T(".zip") || ext == _T(".htb") || ext == _T(".hhp"))
114 {
115 wxBusyCursor bcur;
116 controller->AddBook(s);
117 return TRUE;
118 }
119 }
120 return FALSE;
121 }
122
123 /*
124 * Art provider class
125 */
126
127 // ---------------------------------------------------------------------
128 // helper macros
129 // ---------------------------------------------------------------------
130
131 // Standard macro for getting a resource from XPM file:
132 #define ART(artId, xpmRc) \
133 if ( id == artId ) return wxBitmap(xpmRc##_xpm);
134
135 // Compatibility hack to use wxApp::GetStdIcon of overriden by the user
136 #if WXWIN_COMPATIBILITY_2_2
137 #define GET_STD_ICON_FROM_APP(iconId) \
138 if ( client == wxART_MESSAGE_BOX ) \
139 { \
140 wxIcon icon = wxTheApp->GetStdIcon(iconId); \
141 if ( icon.Ok() ) \
142 { \
143 wxBitmap bmp; \
144 bmp.CopyFromIcon(icon); \
145 return bmp; \
146 } \
147 }
148 #else
149 #define GET_STD_ICON_FROM_APP(iconId)
150 #endif
151
152 // There are two ways of getting the standard icon: either via XPMs or via
153 // wxIcon ctor. This depends on the platform:
154 #if defined(__WXUNIVERSAL__)
155 #define CREATE_STD_ICON(iconId, xpmRc) return wxNullBitmap;
156 #elif defined(__WXGTK__) || defined(__WXMOTIF__)
157 #define CREATE_STD_ICON(iconId, xpmRc) return wxBitmap(xpmRc##_xpm);
158 #else
159 #define CREATE_STD_ICON(iconId, xpmRc) \
160 { \
161 wxIcon icon(_T(iconId)); \
162 wxBitmap bmp; \
163 bmp.CopyFromIcon(icon); \
164 return bmp; \
165 }
166 #endif
167
168 // Macro used in CreateBitmap to get wxICON_FOO icons:
169 #define ART_MSGBOX(artId, iconId, xpmRc) \
170 if ( id == artId ) \
171 { \
172 GET_STD_ICON_FROM_APP(iconId) \
173 CREATE_STD_ICON(#iconId, xpmRc) \
174 }
175
176 // ---------------------------------------------------------------------
177 // XPMs with the art
178 // ---------------------------------------------------------------------
179
180 // XPM hack: make the arrays const
181 //#define static static const
182
183 #include "bitmaps/helpback.xpm"
184 #include "bitmaps/helpbook.xpm"
185 #include "bitmaps/helpdown.xpm"
186 #include "bitmaps/helpforward.xpm"
187 #include "bitmaps/helpoptions.xpm"
188 #include "bitmaps/helppage.xpm"
189 #include "bitmaps/helpsidepanel.xpm"
190 #include "bitmaps/helpup.xpm"
191 #include "bitmaps/helpuplevel.xpm"
192 #include "bitmaps/helpicon.xpm"
193 #include "bitmaps/helpopen.xpm"
194
195 //#undef static
196
197 // ---------------------------------------------------------------------
198 // CreateBitmap routine
199 // ---------------------------------------------------------------------
200
201 wxBitmap AlternateArtProvider::CreateBitmap(const wxArtID& id,
202 const wxArtClient& client,
203 const wxSize& WXUNUSED(size))
204 {
205 ART(wxART_HELP_SIDE_PANEL, helpsidepanel)
206 ART(wxART_HELP_SETTINGS, helpoptions)
207 ART(wxART_HELP_BOOK, helpbook)
208 ART(wxART_HELP_FOLDER, helpbook)
209 ART(wxART_HELP_PAGE, helppage)
210 //ART(wxART_ADD_BOOKMARK, addbookm)
211 //ART(wxART_DEL_BOOKMARK, delbookm)
212 ART(wxART_GO_BACK, helpback)
213 ART(wxART_GO_FORWARD, helpforward)
214 ART(wxART_GO_UP, helpup)
215 ART(wxART_GO_DOWN, helpdown)
216 ART(wxART_GO_TO_PARENT, helpuplevel)
217 ART(wxART_FILE_OPEN, helpopen)
218 if (client == wxART_HELP_BROWSER)
219 {
220 ART(wxART_FRAME_ICON, helpicon)
221 }
222
223 //ART(wxART_GO_HOME, home)
224
225 // Any wxWindows icons not implemented here
226 // will be provided by the default art provider.
227 return wxNullBitmap;
228 }