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