]> git.saurik.com Git - wxWidgets.git/blob - utils/helpview/src/client.cpp
Don't lie about wxImageList in XRC format spec.
[wxWidgets.git] / utils / helpview / src / client.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: client.cpp
3 // Purpose: Remote help sample client
4 // Author: Julian Smart
5 // Modified by: Eric Dowty
6 // Created: 25/01/99
7 // Copyright: (c) Julian Smart
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
10
11 // ============================================================================
12 // declarations
13 // ============================================================================
14
15 // ----------------------------------------------------------------------------
16 // headers
17 // ----------------------------------------------------------------------------
18
19 #define USE_REMOTE 1
20
21 // For compilers that support precompilation, includes "wx.h".
22 #include "wx/wxprec.h"
23
24 #ifdef __BORLANDC__
25 #pragma hdrstop
26 #endif
27
28 #ifndef WX_PRECOMP
29 #include "wx/wx.h"
30 #endif
31
32 #include <math.h>
33
34 #include "wx/process.h"
35 #include "wx/helpbase.h"
36 #include "wx/html/helpfrm.h"
37 #include "wx/html/helpctrl.h"
38 #include "wx/config.h"
39
40 // Settings common to both executables: determines whether
41 // we're using TCP/IP or real DDE.
42
43 //#include "ddesetup.h"
44 //#define wxUSE_DDE_FOR_IPC 0
45 #include <wx/ipc.h>
46
47 #ifndef wxHAS_IMAGES_IN_RESOURCES
48 #include "mondrian.xpm"
49 #endif
50
51 #include "remhelp.h"
52 #include "client.h"
53
54 // ----------------------------------------------------------------------------
55 // wxWin macros
56 // ----------------------------------------------------------------------------
57
58 IMPLEMENT_APP(MyApp)
59
60 BEGIN_EVENT_TABLE(MyFrame, wxFrame)
61 EVT_MENU(CLIENT_QUIT, MyFrame::OnExit)
62 EVT_MENU(CLIENT_HELPMAIN, MyFrame::OnHelp_Main)
63 EVT_MENU(CLIENT_HELPBOOK1, MyFrame::OnHelp_Book1)
64 EVT_MENU(CLIENT_HELPBOOK2, MyFrame::OnHelp_Book2)
65
66 EVT_MENU(CLIENT_HELPINDEX, MyFrame::OnHelp_Index)
67 EVT_MENU(CLIENT_HELPCONTENTS, MyFrame::OnHelp_Contents)
68 EVT_MENU(CLIENT_HELPSEARCH, MyFrame::OnHelp_Search)
69 EVT_MENU(CLIENT_HELPTITLE, MyFrame::OnHelp_Title)
70 EVT_MENU(CLIENT_HELPADDBOOK, MyFrame::OnHelp_Addbook)
71 EVT_MENU(CLIENT_HELPTEMPDIR, MyFrame::OnHelp_Tempdir)
72 EVT_MENU(CLIENT_HELPQUIT, MyFrame::OnHelp_Quitserver)
73
74 EVT_MENU(DIALOG_MODAL, MyFrame::ModalDlg)
75 EVT_BUTTON(BUTTON_MODAL, MyFrame::ModalDlg)
76 END_EVENT_TABLE()
77
78 // ----------------------------------------------------------------------------
79 // globals
80 // ----------------------------------------------------------------------------
81
82 wxListBox *the_list = NULL;
83
84 // ============================================================================
85 // implementation
86 // ============================================================================
87
88 // ----------------------------------------------------------------------------
89 // MyApp
90 // ----------------------------------------------------------------------------
91
92 // The `main program' equivalent, creating the windows and returning the
93 // main frame
94 bool MyApp::OnInit()
95 {
96 wxString a_appname, a_service, a_windowname, a_book;
97
98 m_help = NULL;
99
100 // for MSW (DDE classes), a_service is 'service name', apparently an arbitrary string
101 // for Unix, should be a valid file name (for a nonexistent file)
102 // for nonMSW, nonUnix, must be port number, for example "4242" (TCP/IP based classes)
103 // should be unique to the client app
104 a_service = "/tmp/wxWidgets-helpconnection";
105 //a_service = "4242";
106 a_windowname = "HTML Help Test: %s";
107
108 #if defined(__WXMSW__)
109 a_appname = "helpview.exe";
110 #else
111 a_appname = "./helpview";
112 #endif
113
114 //a_book = "helpfiles/testing.hhp";
115 a_book = "test.zip";
116
117 wxConfig *conf = (wxConfig*) wxConfig::Get();
118
119 #if defined(USE_REMOTE)
120 m_help = new wxRemoteHtmlHelpController();
121 m_help->SetServer( a_appname );
122 m_help->SetService( a_service );
123 #else
124 m_help = new wxHtmlHelpController();
125 #endif
126
127 //this is a dummy for wxRemoteHtmlHelpController
128 m_help->UseConfig(conf);
129
130 m_help->AddBook( a_book );
131 m_help->SetTitleFormat( a_windowname );
132
133 // Create the main frame window
134 MyFrame* frame = new MyFrame(NULL, "Help Client");
135 frame->Show(true);
136
137 return true;
138 }
139
140 int MyApp::OnExit()
141 {
142 delete m_help;
143 delete wxConfig::Set(NULL);
144 return 0;
145 }
146
147 // Define my frame constructor
148 MyFrame::MyFrame(wxFrame *frame, const wxString& title)
149 : wxFrame(frame, wxID_ANY, title, wxDefaultPosition, wxSize( 200, 100 ) )
150 {
151 m_panel = NULL;
152
153 // Give it an icon
154 SetIcon(wxICON(mondrian));
155
156 // Make a menubar
157 wxMenu *file_menu = new wxMenu;
158
159 file_menu->Append(CLIENT_HELPMAIN, "Help - Main");
160 file_menu->Append(CLIENT_HELPBOOK1, "Help - Book1");
161 file_menu->Append(CLIENT_HELPBOOK2, "Help - Book2");
162
163 file_menu->Append(CLIENT_HELPINDEX, "Help - DisplayIndex");
164 file_menu->Append(CLIENT_HELPCONTENTS, "Help - DisplayContents");
165 file_menu->Append(CLIENT_HELPSEARCH, "Help - KeywordSearch");
166 file_menu->Append(CLIENT_HELPTITLE, "Help - SetTitleFormat");
167 file_menu->Append(CLIENT_HELPADDBOOK, "Help - AddBook");
168 file_menu->Append(CLIENT_HELPTEMPDIR, "Help - SetTempDir");
169 file_menu->Append(CLIENT_HELPQUIT, "Help - Kill Server");
170
171 file_menu->Append(DIALOG_MODAL, "Modal dialog");
172 file_menu->Append(CLIENT_QUIT, "Quit");
173
174 wxMenuBar *menu_bar = new wxMenuBar;
175
176 menu_bar->Append(file_menu, "File");
177
178 // Associate the menu bar with the frame
179 SetMenuBar(menu_bar);
180
181 // Make a panel
182 m_panel = new wxPanel(this );
183
184 m_modalbutton = new wxButton( this, BUTTON_MODAL, "Modal Dialog",
185 wxPoint(10,10), wxDefaultSize );
186 }
187
188 void MyFrame::OnHelp_Book1(wxCommandEvent& event)
189 {
190 wxGetApp().m_help->Display( "book1.htm" );
191 }
192
193 void MyFrame::OnHelp_Book2(wxCommandEvent& event)
194 {
195 wxGetApp().m_help->Display( "book2.htm" );
196 }
197
198 void MyFrame::OnHelp_Main(wxCommandEvent& event)
199 {
200 wxGetApp().m_help->Display( "main.htm" );
201 }
202
203 void MyFrame::OnHelp_Index(wxCommandEvent& event)
204 {
205 wxGetApp().m_help->DisplayIndex( );
206 }
207 void MyFrame::OnHelp_Contents(wxCommandEvent& event)
208 {
209 wxGetApp().m_help->DisplayContents( );
210 }
211
212 void MyFrame::OnHelp_Search(wxCommandEvent& event)
213 {
214 wxGetApp().m_help->KeywordSearch( "enjoy" );
215 }
216 void MyFrame::OnHelp_Title(wxCommandEvent& event)
217 {
218 wxGetApp().m_help->SetTitleFormat( "Another_Title: %s" );
219 }
220 void MyFrame::OnHelp_Addbook(wxCommandEvent& event)
221 {
222 wxGetApp().m_help->AddBook("helpfiles/another.hhp" );
223 }
224 void MyFrame::OnHelp_Tempdir(wxCommandEvent& event)
225 {
226 wxGetApp().m_help->SetTempDir( "tempdir" );
227 }
228
229 void MyFrame::OnHelp_Quitserver(wxCommandEvent& event)
230 {
231 // if (!wxGetApp().m_help->m_connection->Poke( wxT("--YouAreDead"), wxT("") ) )
232 // wxLogError(wxT("wxRemoteHtmlHelpController - YouAreDead Failed"));
233
234 wxGetApp().m_help->Quit();
235 }
236
237 void MyFrame::OnExit(wxCommandEvent& event)
238 {
239 Close();
240 }
241
242 void MyFrame::ModalDlg(wxCommandEvent& WXUNUSED(event))
243 {
244 MyModalDialog dlg(this);
245 dlg.ShowModal();
246 }
247
248 BEGIN_EVENT_TABLE(MyModalDialog, wxDialog)
249 EVT_BUTTON(wxID_ANY, MyModalDialog::OnButton)
250 END_EVENT_TABLE()
251
252 // ----------------------------------------------------------------------------
253 // MyModalDialog
254 // ----------------------------------------------------------------------------
255
256 MyModalDialog::MyModalDialog(wxWindow *parent)
257 : wxDialog(parent, wxID_ANY, wxString("Modal dialog"))
258 {
259 wxBoxSizer *sizerTop = new wxBoxSizer(wxHORIZONTAL);
260
261 m_main = new wxButton(this, wxID_ANY, "Main");
262 m_book1 = new wxButton(this, wxID_ANY, "Book1");
263 m_book2 = new wxButton(this, wxID_ANY, "Book2");
264 sizerTop->Add(m_main, 0, wxALIGN_CENTER | wxALL, 5);
265 sizerTop->Add(m_book1, 0, wxALIGN_CENTER | wxALL, 5);
266 sizerTop->Add(m_book2, 0, wxALIGN_CENTER | wxALL, 5);
267
268 SetSizer(sizerTop);
269
270 sizerTop->SetSizeHints(this);
271 sizerTop->Fit(this);
272
273 m_main->SetFocus();
274 m_main->SetDefault();
275 }
276
277 void MyModalDialog::OnButton(wxCommandEvent& event)
278 {
279 if ( event.GetEventObject() == m_main )
280 {
281 wxGetApp().m_help->Display( "main.htm" );
282 }
283 else if ( event.GetEventObject() == m_book1 )
284 {
285 wxGetApp().m_help->Display( "book1.htm" );
286 }
287 else if ( event.GetEventObject() == m_book2 )
288 {
289 wxGetApp().m_help->Display( "book2.htm" );
290 }
291 else
292 {
293 event.Skip();
294 }
295 }
296