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