]> git.saurik.com Git - wxWidgets.git/blame - samples/html/help/help.cpp
Don't use GetThreadId() in wxMSW code.
[wxWidgets.git] / samples / html / help / help.cpp
CommitLineData
5526e819 1/////////////////////////////////////////////////////////////////////////////
197ab43d
FM
2// Name: help.cpp
3// Purpose: wxHtml sample: help test
4// Author: ?
5// Modified by:
6// Created: ?
7// RCS-ID: $Id$
8// Copyright: (c) wxWidgets team
9// Licence: wxWindows licence
5526e819
VS
10/////////////////////////////////////////////////////////////////////////////
11
5526e819 12// For compilers that support precompilation, includes "wx/wx.h".
92a19c2e 13#include "wx/wxprec.h"
5526e819
VS
14
15#ifdef __BORLANDC__
16 #pragma hdrstop
17#endif
18
19// for all others, include the necessary headers (this file is usually all you
be5a51fb 20// need because it includes almost all "standard" wxWidgets headers
5526e819 21#ifndef WX_PRECOMP
67547666 22 #include "wx/wx.h"
5526e819
VS
23#endif
24
3cc2aa56
VS
25#include "wx/image.h"
26#include "wx/html/helpfrm.h"
27#include "wx/html/helpctrl.h"
28#include "wx/filesys.h"
29#include "wx/fs_zip.h"
5526e819 30
e7092398 31#ifndef wxHAS_IMAGES_IN_RESOURCES
197ab43d
FM
32 #include "../../sample.xpm"
33#endif
34
35
5526e819
VS
36// ----------------------------------------------------------------------------
37// private classes
38// ----------------------------------------------------------------------------
39
2c997ad0 40
5526e819 41// Define a new application type, each program should derive a class from wxApp
197ab43d
FM
42class MyApp : public wxApp
43{
44public:
5526e819
VS
45 // override base class virtuals
46 // ----------------------------
2c997ad0 47
5526e819
VS
48 // this one is called on application startup and is a good place for the app
49 // initialization (doing it here and not in the ctor allows to have an error
50 // return: if OnInit() returns false, the application terminates)
197ab43d
FM
51 virtual bool OnInit();
52};
5526e819 53
2c997ad0
VS
54
55
56// Define a new frame type: this is going to be our main frame
197ab43d
FM
57class MyFrame : public wxFrame
58{
59public:
2c997ad0 60 // ctor(s)
197ab43d 61 MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size);
2c997ad0
VS
62
63 // event handlers (these functions should _not_ be virtual)
197ab43d
FM
64 void OnQuit(wxCommandEvent& event);
65 void OnHelp(wxCommandEvent& event);
66 void OnClose(wxCloseEvent& event);
67private:
68 wxHtmlHelpController help;
11fdee42 69
be5a51fb 70 // any class wishing to process wxWidgets events must use this macro
2c997ad0 71 DECLARE_EVENT_TABLE()
197ab43d 72};
2c997ad0
VS
73
74// ----------------------------------------------------------------------------
75// constants
76// ----------------------------------------------------------------------------
77
78// IDs for the controls and the menu commands
197ab43d
FM
79enum
80{
2c997ad0 81 // menu items
197ab43d
FM
82 Minimal_Quit = 1,
83 Minimal_Help
84};
2c997ad0
VS
85
86// ----------------------------------------------------------------------------
be5a51fb 87// event tables and other macros for wxWidgets
2c997ad0 88// ----------------------------------------------------------------------------
5526e819 89
be5a51fb 90// the event tables connect the wxWidgets events with the functions (event
2c997ad0
VS
91// handlers) which process them. It can be also done at run-time, but for the
92// simple menu events like this the static method is much simpler.
197ab43d
FM
93BEGIN_EVENT_TABLE(MyFrame, wxFrame)
94 EVT_MENU(Minimal_Quit, MyFrame::OnQuit)
95 EVT_MENU(Minimal_Help, MyFrame::OnHelp)
96 EVT_CLOSE(MyFrame::OnClose)
97END_EVENT_TABLE()
98
99// Create a new application object: this macro will allow wxWidgets to create
100// the application object during program execution (it's better than using a
101// static object for many reasons) and also declares the accessor function
102// wxGetApp() which will return the reference of the right type (i.e. MyApp and
103// not wxApp)
104IMPLEMENT_APP(MyApp)
105
106// ============================================================================
107// implementation
108// ============================================================================
109
110// ----------------------------------------------------------------------------
111// the application class
112// ----------------------------------------------------------------------------
113// `Main program' equivalent: the program execution "starts" here
114bool MyApp::OnInit()
115{
116 if ( !wxApp::OnInit() )
117 return false;
118
119 wxInitAllImageHandlers();
11fdee42 120#if wxUSE_STREAMS && wxUSE_ZIPSTREAM && wxUSE_ZLIB
197ab43d 121 wxFileSystem::AddHandler(new wxZipFSHandler);
5fbc988f 122#endif
197ab43d
FM
123 SetVendorName(wxT("wxWidgets"));
124 SetAppName(wxT("wxHTMLHelp"));
5612e524 125
2c997ad0 126 // Create the main application window
197ab43d
FM
127 MyFrame *frame = new MyFrame(_("HTML Help Sample"),
128 wxDefaultPosition, wxDefaultSize);
2c997ad0 129
18f42b94 130 // Show it
197ab43d 131 frame->Show(true);
2c997ad0
VS
132
133 // success: wxApp::OnRun() will be called which will enter the main message
348469c2 134 // loop and the application will run. If we returned false here, the
2c997ad0 135 // application would exit immediately.
197ab43d
FM
136 return true;
137}
2c997ad0
VS
138
139// ----------------------------------------------------------------------------
140// main frame
141// ----------------------------------------------------------------------------
142
143
144// frame constructor
197ab43d
FM
145MyFrame::MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size)
146 : wxFrame((wxFrame *)NULL, wxID_ANY, title, pos, size),
147 help(wxHF_DEFAULT_STYLE | wxHF_OPEN_FILES)
148{
149 SetIcon(wxICON(sample));
150
2c997ad0 151 // create a menu bar
197ab43d 152 wxMenu *menuFile = new wxMenu;
2c997ad0 153
197ab43d
FM
154 menuFile->Append(Minimal_Help, _("&Help"));
155 menuFile->Append(Minimal_Quit, _("E&xit"));
2c997ad0
VS
156
157 // now append the freshly created menu to the menu bar...
197ab43d
FM
158 wxMenuBar *menuBar = new wxMenuBar;
159 menuBar->Append(menuFile, _("&File"));
2c997ad0
VS
160
161 // ... and attach this menu bar to the frame
197ab43d 162 SetMenuBar(menuBar);
2c997ad0 163
197ab43d
FM
164 help.UseConfig(wxConfig::Get());
165 bool ret;
166 help.SetTempDir(wxT("."));
167 ret = help.AddBook(wxFileName(wxT("helpfiles/testing.hhp"), wxPATH_UNIX));
168 if (! ret)
2b5f62a0 169 wxMessageBox(wxT("Failed adding book helpfiles/testing.hhp"));
197ab43d
FM
170 ret = help.AddBook(wxFileName(wxT("helpfiles/another.hhp"), wxPATH_UNIX));
171 if (! ret)
2b5f62a0 172 wxMessageBox(_("Failed adding book helpfiles/another.hhp"));
197ab43d 173}
2c997ad0
VS
174
175
176// event handlers
177
197ab43d
FM
178void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event))
179{
348469c2 180 // true is to force the frame to close
197ab43d
FM
181 Close(true);
182}
183
184void MyFrame::OnHelp(wxCommandEvent& WXUNUSED(event))
185{
186 help.Display(wxT("Test HELPFILE"));
187}
188
189void MyFrame::OnClose(wxCloseEvent& event)
190{
191 // Close the help frame; this will cause the config data to
192 // get written.
193 if ( help.GetFrame() ) // returns NULL if no help frame active
194 help.GetFrame()->Close(true);
195 // now we can safely delete the config pointer
196 event.Skip();
197 delete wxConfig::Set(NULL);
198}
5526e819
VS
199
200
201