]>
Commit | Line | Data |
---|---|---|
2b5f62a0 VZ |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: client.cpp | |
3 | // Purpose: Remote help sample client | |
4 | // Author: Julian Smart | |
4fe30bce | 5 | // Modified by: Eric Dowty |
2b5f62a0 | 6 | // Created: 25/01/99 |
2b5f62a0 VZ |
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 | ||
e7092398 | 47 | #ifndef wxHAS_IMAGES_IN_RESOURCES |
2b5f62a0 VZ |
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; | |
4fe30bce | 97 | |
2b5f62a0 | 98 | m_help = NULL; |
4fe30bce | 99 | |
2b5f62a0 VZ |
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 | |
be5a51fb | 104 | a_service = "/tmp/wxWidgets-helpconnection"; |
2b5f62a0 VZ |
105 | //a_service = "4242"; |
106 | a_windowname = "HTML Help Test: %s"; | |
4fe30bce | 107 | |
2b5f62a0 VZ |
108 | #if defined(__WXMSW__) |
109 | a_appname = "helpview.exe"; | |
110 | #else | |
111 | a_appname = "./helpview"; | |
112 | #endif | |
4fe30bce | 113 | |
2b5f62a0 VZ |
114 | //a_book = "helpfiles/testing.hhp"; |
115 | a_book = "test.zip"; | |
4fe30bce WS |
116 | |
117 | wxConfig *conf = (wxConfig*) wxConfig::Get(); | |
118 | ||
2b5f62a0 VZ |
119 | #if defined(USE_REMOTE) |
120 | m_help = new wxRemoteHtmlHelpController(); | |
4fe30bce WS |
121 | m_help->SetServer( a_appname ); |
122 | m_help->SetService( a_service ); | |
2b5f62a0 VZ |
123 | #else |
124 | m_help = new wxHtmlHelpController(); | |
125 | #endif | |
4fe30bce WS |
126 | |
127 | //this is a dummy for wxRemoteHtmlHelpController | |
2b5f62a0 | 128 | m_help->UseConfig(conf); |
4fe30bce WS |
129 | |
130 | m_help->AddBook( a_book ); | |
131 | m_help->SetTitleFormat( a_windowname ); | |
132 | ||
133 | // Create the main frame window | |
2b5f62a0 | 134 | MyFrame* frame = new MyFrame(NULL, "Help Client"); |
4fe30bce WS |
135 | frame->Show(true); |
136 | ||
137 | return true; | |
2b5f62a0 VZ |
138 | } |
139 | ||
140 | int MyApp::OnExit() | |
141 | { | |
142 | delete m_help; | |
4fe30bce | 143 | delete wxConfig::Set(NULL); |
2b5f62a0 VZ |
144 | return 0; |
145 | } | |
146 | ||
147 | // Define my frame constructor | |
148 | MyFrame::MyFrame(wxFrame *frame, const wxString& title) | |
4fe30bce | 149 | : wxFrame(frame, wxID_ANY, title, wxDefaultPosition, wxSize( 200, 100 ) ) |
2b5f62a0 VZ |
150 | { |
151 | m_panel = NULL; | |
4fe30bce | 152 | |
2b5f62a0 VZ |
153 | // Give it an icon |
154 | SetIcon(wxICON(mondrian)); | |
4fe30bce | 155 | |
2b5f62a0 VZ |
156 | // Make a menubar |
157 | wxMenu *file_menu = new wxMenu; | |
4fe30bce | 158 | |
2b5f62a0 VZ |
159 | file_menu->Append(CLIENT_HELPMAIN, "Help - Main"); |
160 | file_menu->Append(CLIENT_HELPBOOK1, "Help - Book1"); | |
161 | file_menu->Append(CLIENT_HELPBOOK2, "Help - Book2"); | |
4fe30bce | 162 | |
2b5f62a0 VZ |
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"); | |
4fe30bce | 170 | |
2b5f62a0 VZ |
171 | file_menu->Append(DIALOG_MODAL, "Modal dialog"); |
172 | file_menu->Append(CLIENT_QUIT, "Quit"); | |
4fe30bce | 173 | |
2b5f62a0 | 174 | wxMenuBar *menu_bar = new wxMenuBar; |
4fe30bce | 175 | |
2b5f62a0 | 176 | menu_bar->Append(file_menu, "File"); |
4fe30bce | 177 | |
2b5f62a0 VZ |
178 | // Associate the menu bar with the frame |
179 | SetMenuBar(menu_bar); | |
4fe30bce | 180 | |
2b5f62a0 VZ |
181 | // Make a panel |
182 | m_panel = new wxPanel(this ); | |
4fe30bce | 183 | |
dabbc6a5 | 184 | m_modalbutton = new wxButton( this, BUTTON_MODAL, "Modal Dialog", |
4fe30bce | 185 | wxPoint(10,10), wxDefaultSize ); |
2b5f62a0 VZ |
186 | } |
187 | ||
188 | void MyFrame::OnHelp_Book1(wxCommandEvent& event) | |
189 | { | |
4fe30bce | 190 | wxGetApp().m_help->Display( "book1.htm" ); |
2b5f62a0 VZ |
191 | } |
192 | ||
193 | void MyFrame::OnHelp_Book2(wxCommandEvent& event) | |
194 | { | |
4fe30bce | 195 | wxGetApp().m_help->Display( "book2.htm" ); |
2b5f62a0 VZ |
196 | } |
197 | ||
198 | void MyFrame::OnHelp_Main(wxCommandEvent& event) | |
199 | { | |
4fe30bce | 200 | wxGetApp().m_help->Display( "main.htm" ); |
2b5f62a0 VZ |
201 | } |
202 | ||
203 | void MyFrame::OnHelp_Index(wxCommandEvent& event) | |
204 | { | |
4fe30bce | 205 | wxGetApp().m_help->DisplayIndex( ); |
2b5f62a0 VZ |
206 | } |
207 | void MyFrame::OnHelp_Contents(wxCommandEvent& event) | |
208 | { | |
4fe30bce | 209 | wxGetApp().m_help->DisplayContents( ); |
2b5f62a0 VZ |
210 | } |
211 | ||
212 | void MyFrame::OnHelp_Search(wxCommandEvent& event) | |
213 | { | |
4fe30bce | 214 | wxGetApp().m_help->KeywordSearch( "enjoy" ); |
2b5f62a0 VZ |
215 | } |
216 | void MyFrame::OnHelp_Title(wxCommandEvent& event) | |
217 | { | |
4fe30bce | 218 | wxGetApp().m_help->SetTitleFormat( "Another_Title: %s" ); |
2b5f62a0 VZ |
219 | } |
220 | void MyFrame::OnHelp_Addbook(wxCommandEvent& event) | |
221 | { | |
4fe30bce | 222 | wxGetApp().m_help->AddBook("helpfiles/another.hhp" ); |
2b5f62a0 VZ |
223 | } |
224 | void MyFrame::OnHelp_Tempdir(wxCommandEvent& event) | |
225 | { | |
4fe30bce | 226 | wxGetApp().m_help->SetTempDir( "tempdir" ); |
2b5f62a0 VZ |
227 | } |
228 | ||
229 | void MyFrame::OnHelp_Quitserver(wxCommandEvent& event) | |
230 | { | |
4fe30bce WS |
231 | // if (!wxGetApp().m_help->m_connection->Poke( wxT("--YouAreDead"), wxT("") ) ) |
232 | // wxLogError(wxT("wxRemoteHtmlHelpController - YouAreDead Failed")); | |
233 | ||
234 | wxGetApp().m_help->Quit(); | |
2b5f62a0 VZ |
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) | |
4fe30bce | 249 | EVT_BUTTON(wxID_ANY, MyModalDialog::OnButton) |
2b5f62a0 VZ |
250 | END_EVENT_TABLE() |
251 | ||
252 | // ---------------------------------------------------------------------------- | |
253 | // MyModalDialog | |
254 | // ---------------------------------------------------------------------------- | |
255 | ||
256 | MyModalDialog::MyModalDialog(wxWindow *parent) | |
4fe30bce | 257 | : wxDialog(parent, wxID_ANY, wxString("Modal dialog")) |
2b5f62a0 VZ |
258 | { |
259 | wxBoxSizer *sizerTop = new wxBoxSizer(wxHORIZONTAL); | |
4fe30bce WS |
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"); | |
2b5f62a0 VZ |
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); | |
4fe30bce | 267 | |
2b5f62a0 | 268 | SetSizer(sizerTop); |
4fe30bce | 269 | |
2b5f62a0 VZ |
270 | sizerTop->SetSizeHints(this); |
271 | sizerTop->Fit(this); | |
4fe30bce | 272 | |
2b5f62a0 VZ |
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 |