]> git.saurik.com Git - wxWidgets.git/blame - utils/helpview/src/client.cpp
use stock buttons in generic dialogs
[wxWidgets.git] / utils / helpview / src / client.cpp
CommitLineData
2b5f62a0
VZ
1/////////////////////////////////////////////////////////////////////////////
2// Name: client.cpp
3// Purpose: Remote help sample client
4// Author: Julian Smart
4fe30bce 5// Modified by: Eric Dowty
2b5f62a0
VZ
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
59IMPLEMENT_APP(MyApp)
60
61BEGIN_EVENT_TABLE(MyFrame, wxFrame)
62EVT_MENU(CLIENT_QUIT, MyFrame::OnExit)
63EVT_MENU(CLIENT_HELPMAIN, MyFrame::OnHelp_Main)
64EVT_MENU(CLIENT_HELPBOOK1, MyFrame::OnHelp_Book1)
65EVT_MENU(CLIENT_HELPBOOK2, MyFrame::OnHelp_Book2)
66
67EVT_MENU(CLIENT_HELPINDEX, MyFrame::OnHelp_Index)
68EVT_MENU(CLIENT_HELPCONTENTS, MyFrame::OnHelp_Contents)
69EVT_MENU(CLIENT_HELPSEARCH, MyFrame::OnHelp_Search)
70EVT_MENU(CLIENT_HELPTITLE, MyFrame::OnHelp_Title)
71EVT_MENU(CLIENT_HELPADDBOOK, MyFrame::OnHelp_Addbook)
72EVT_MENU(CLIENT_HELPTEMPDIR, MyFrame::OnHelp_Tempdir)
73EVT_MENU(CLIENT_HELPQUIT, MyFrame::OnHelp_Quitserver)
74
75EVT_MENU(DIALOG_MODAL, MyFrame::ModalDlg)
76EVT_BUTTON(BUTTON_MODAL, MyFrame::ModalDlg)
77END_EVENT_TABLE()
78
79// ----------------------------------------------------------------------------
80// globals
81// ----------------------------------------------------------------------------
82
83wxListBox *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
95bool MyApp::OnInit()
96{
97 wxString a_appname, a_service, a_windowname, a_book;
4fe30bce 98
2b5f62a0 99 m_help = NULL;
4fe30bce 100
2b5f62a0
VZ
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
be5a51fb 105 a_service = "/tmp/wxWidgets-helpconnection";
2b5f62a0
VZ
106 //a_service = "4242";
107 a_windowname = "HTML Help Test: %s";
4fe30bce 108
2b5f62a0
VZ
109#if defined(__WXMSW__)
110 a_appname = "helpview.exe";
111#else
112 a_appname = "./helpview";
113#endif
4fe30bce 114
2b5f62a0
VZ
115 //a_book = "helpfiles/testing.hhp";
116 a_book = "test.zip";
4fe30bce
WS
117
118 wxConfig *conf = (wxConfig*) wxConfig::Get();
119
2b5f62a0
VZ
120#if defined(USE_REMOTE)
121 m_help = new wxRemoteHtmlHelpController();
4fe30bce
WS
122 m_help->SetServer( a_appname );
123 m_help->SetService( a_service );
2b5f62a0
VZ
124#else
125 m_help = new wxHtmlHelpController();
126#endif
4fe30bce
WS
127
128 //this is a dummy for wxRemoteHtmlHelpController
2b5f62a0 129 m_help->UseConfig(conf);
4fe30bce
WS
130
131 m_help->AddBook( a_book );
132 m_help->SetTitleFormat( a_windowname );
133
134 // Create the main frame window
2b5f62a0 135 MyFrame* frame = new MyFrame(NULL, "Help Client");
4fe30bce
WS
136 frame->Show(true);
137
138 return true;
2b5f62a0
VZ
139}
140
141int MyApp::OnExit()
142{
143 delete m_help;
4fe30bce 144 delete wxConfig::Set(NULL);
2b5f62a0
VZ
145 return 0;
146}
147
148// Define my frame constructor
149MyFrame::MyFrame(wxFrame *frame, const wxString& title)
4fe30bce 150: wxFrame(frame, wxID_ANY, title, wxDefaultPosition, wxSize( 200, 100 ) )
2b5f62a0
VZ
151{
152 m_panel = NULL;
4fe30bce 153
2b5f62a0
VZ
154 // Give it an icon
155 SetIcon(wxICON(mondrian));
4fe30bce 156
2b5f62a0
VZ
157 // Make a menubar
158 wxMenu *file_menu = new wxMenu;
4fe30bce 159
2b5f62a0
VZ
160 file_menu->Append(CLIENT_HELPMAIN, "Help - Main");
161 file_menu->Append(CLIENT_HELPBOOK1, "Help - Book1");
162 file_menu->Append(CLIENT_HELPBOOK2, "Help - Book2");
4fe30bce 163
2b5f62a0
VZ
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");
4fe30bce 171
2b5f62a0
VZ
172 file_menu->Append(DIALOG_MODAL, "Modal dialog");
173 file_menu->Append(CLIENT_QUIT, "Quit");
4fe30bce 174
2b5f62a0 175 wxMenuBar *menu_bar = new wxMenuBar;
4fe30bce 176
2b5f62a0 177 menu_bar->Append(file_menu, "File");
4fe30bce 178
2b5f62a0
VZ
179 // Associate the menu bar with the frame
180 SetMenuBar(menu_bar);
4fe30bce 181
2b5f62a0
VZ
182 // Make a panel
183 m_panel = new wxPanel(this );
4fe30bce 184
dabbc6a5 185 m_modalbutton = new wxButton( this, BUTTON_MODAL, "Modal Dialog",
4fe30bce 186 wxPoint(10,10), wxDefaultSize );
2b5f62a0
VZ
187}
188
189void MyFrame::OnHelp_Book1(wxCommandEvent& event)
190{
4fe30bce 191 wxGetApp().m_help->Display( "book1.htm" );
2b5f62a0
VZ
192}
193
194void MyFrame::OnHelp_Book2(wxCommandEvent& event)
195{
4fe30bce 196 wxGetApp().m_help->Display( "book2.htm" );
2b5f62a0
VZ
197}
198
199void MyFrame::OnHelp_Main(wxCommandEvent& event)
200{
4fe30bce 201 wxGetApp().m_help->Display( "main.htm" );
2b5f62a0
VZ
202}
203
204void MyFrame::OnHelp_Index(wxCommandEvent& event)
205{
4fe30bce 206 wxGetApp().m_help->DisplayIndex( );
2b5f62a0
VZ
207}
208void MyFrame::OnHelp_Contents(wxCommandEvent& event)
209{
4fe30bce 210 wxGetApp().m_help->DisplayContents( );
2b5f62a0
VZ
211}
212
213void MyFrame::OnHelp_Search(wxCommandEvent& event)
214{
4fe30bce 215 wxGetApp().m_help->KeywordSearch( "enjoy" );
2b5f62a0
VZ
216}
217void MyFrame::OnHelp_Title(wxCommandEvent& event)
218{
4fe30bce 219 wxGetApp().m_help->SetTitleFormat( "Another_Title: %s" );
2b5f62a0
VZ
220}
221void MyFrame::OnHelp_Addbook(wxCommandEvent& event)
222{
4fe30bce 223 wxGetApp().m_help->AddBook("helpfiles/another.hhp" );
2b5f62a0
VZ
224}
225void MyFrame::OnHelp_Tempdir(wxCommandEvent& event)
226{
4fe30bce 227 wxGetApp().m_help->SetTempDir( "tempdir" );
2b5f62a0
VZ
228}
229
230void MyFrame::OnHelp_Quitserver(wxCommandEvent& event)
231{
4fe30bce
WS
232 // if (!wxGetApp().m_help->m_connection->Poke( wxT("--YouAreDead"), wxT("") ) )
233 // wxLogError(wxT("wxRemoteHtmlHelpController - YouAreDead Failed"));
234
235 wxGetApp().m_help->Quit();
2b5f62a0
VZ
236}
237
238void MyFrame::OnExit(wxCommandEvent& event)
239{
240 Close();
241}
242
243void MyFrame::ModalDlg(wxCommandEvent& WXUNUSED(event))
244{
245 MyModalDialog dlg(this);
246 dlg.ShowModal();
247}
248
249BEGIN_EVENT_TABLE(MyModalDialog, wxDialog)
4fe30bce 250EVT_BUTTON(wxID_ANY, MyModalDialog::OnButton)
2b5f62a0
VZ
251END_EVENT_TABLE()
252
253// ----------------------------------------------------------------------------
254// MyModalDialog
255// ----------------------------------------------------------------------------
256
257MyModalDialog::MyModalDialog(wxWindow *parent)
4fe30bce 258: wxDialog(parent, wxID_ANY, wxString("Modal dialog"))
2b5f62a0
VZ
259{
260 wxBoxSizer *sizerTop = new wxBoxSizer(wxHORIZONTAL);
4fe30bce
WS
261
262 m_main = new wxButton(this, wxID_ANY, "Main");
263 m_book1 = new wxButton(this, wxID_ANY, "Book1");
264 m_book2 = new wxButton(this, wxID_ANY, "Book2");
2b5f62a0
VZ
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);
4fe30bce 268
2b5f62a0 269 SetSizer(sizerTop);
4fe30bce 270
2b5f62a0
VZ
271 sizerTop->SetSizeHints(this);
272 sizerTop->Fit(this);
4fe30bce 273
2b5f62a0
VZ
274 m_main->SetFocus();
275 m_main->SetDefault();
276}
277
278void MyModalDialog::OnButton(wxCommandEvent& event)
279{
280 if ( event.GetEventObject() == m_main )
281 {
282 wxGetApp().m_help->Display( "main.htm" );
283 }
284 else if ( event.GetEventObject() == m_book1 )
285 {
286 wxGetApp().m_help->Display( "book1.htm" );
287 }
288 else if ( event.GetEventObject() == m_book2 )
289 {
290 wxGetApp().m_help->Display( "book2.htm" );
291 }
292 else
293 {
294 event.Skip();
295 }
296}
297