]>
git.saurik.com Git - wxWidgets.git/blob - utils/helpview/src/client.cpp
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Remote help sample client
4 // Author: Julian Smart
5 // Modified by: Eric Dowty
7 // Copyright: (c) Julian Smart
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
11 // ============================================================================
13 // ============================================================================
15 // ----------------------------------------------------------------------------
17 // ----------------------------------------------------------------------------
21 // For compilers that support precompilation, includes "wx.h".
22 #include "wx/wxprec.h"
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"
40 // Settings common to both executables: determines whether
41 // we're using TCP/IP or real DDE.
43 //#include "ddesetup.h"
44 //#define wxUSE_DDE_FOR_IPC 0
47 #ifndef wxHAS_IMAGES_IN_RESOURCES
48 #include "mondrian.xpm"
54 // ----------------------------------------------------------------------------
56 // ----------------------------------------------------------------------------
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
)
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
)
74 EVT_MENU(DIALOG_MODAL
, MyFrame::ModalDlg
)
75 EVT_BUTTON(BUTTON_MODAL
, MyFrame::ModalDlg
)
78 // ----------------------------------------------------------------------------
80 // ----------------------------------------------------------------------------
82 wxListBox
*the_list
= NULL
;
84 // ============================================================================
86 // ============================================================================
88 // ----------------------------------------------------------------------------
90 // ----------------------------------------------------------------------------
92 // The `main program' equivalent, creating the windows and returning the
96 wxString a_appname
, a_service
, a_windowname
, a_book
;
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";
108 #if defined(__WXMSW__)
109 a_appname
= "helpview.exe";
111 a_appname
= "./helpview";
114 //a_book = "helpfiles/testing.hhp";
117 wxConfig
*conf
= (wxConfig
*) wxConfig::Get();
119 #if defined(USE_REMOTE)
120 m_help
= new wxRemoteHtmlHelpController();
121 m_help
->SetServer( a_appname
);
122 m_help
->SetService( a_service
);
124 m_help
= new wxHtmlHelpController();
127 //this is a dummy for wxRemoteHtmlHelpController
128 m_help
->UseConfig(conf
);
130 m_help
->AddBook( a_book
);
131 m_help
->SetTitleFormat( a_windowname
);
133 // Create the main frame window
134 MyFrame
* frame
= new MyFrame(NULL
, "Help Client");
143 delete wxConfig::Set(NULL
);
147 // Define my frame constructor
148 MyFrame::MyFrame(wxFrame
*frame
, const wxString
& title
)
149 : wxFrame(frame
, wxID_ANY
, title
, wxDefaultPosition
, wxSize( 200, 100 ) )
154 SetIcon(wxICON(mondrian
));
157 wxMenu
*file_menu
= new wxMenu
;
159 file_menu
->Append(CLIENT_HELPMAIN
, "Help - Main");
160 file_menu
->Append(CLIENT_HELPBOOK1
, "Help - Book1");
161 file_menu
->Append(CLIENT_HELPBOOK2
, "Help - Book2");
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");
171 file_menu
->Append(DIALOG_MODAL
, "Modal dialog");
172 file_menu
->Append(CLIENT_QUIT
, "Quit");
174 wxMenuBar
*menu_bar
= new wxMenuBar
;
176 menu_bar
->Append(file_menu
, "File");
178 // Associate the menu bar with the frame
179 SetMenuBar(menu_bar
);
182 m_panel
= new wxPanel(this );
184 m_modalbutton
= new wxButton( this, BUTTON_MODAL
, "Modal Dialog",
185 wxPoint(10,10), wxDefaultSize
);
188 void MyFrame::OnHelp_Book1(wxCommandEvent
& event
)
190 wxGetApp().m_help
->Display( "book1.htm" );
193 void MyFrame::OnHelp_Book2(wxCommandEvent
& event
)
195 wxGetApp().m_help
->Display( "book2.htm" );
198 void MyFrame::OnHelp_Main(wxCommandEvent
& event
)
200 wxGetApp().m_help
->Display( "main.htm" );
203 void MyFrame::OnHelp_Index(wxCommandEvent
& event
)
205 wxGetApp().m_help
->DisplayIndex( );
207 void MyFrame::OnHelp_Contents(wxCommandEvent
& event
)
209 wxGetApp().m_help
->DisplayContents( );
212 void MyFrame::OnHelp_Search(wxCommandEvent
& event
)
214 wxGetApp().m_help
->KeywordSearch( "enjoy" );
216 void MyFrame::OnHelp_Title(wxCommandEvent
& event
)
218 wxGetApp().m_help
->SetTitleFormat( "Another_Title: %s" );
220 void MyFrame::OnHelp_Addbook(wxCommandEvent
& event
)
222 wxGetApp().m_help
->AddBook("helpfiles/another.hhp" );
224 void MyFrame::OnHelp_Tempdir(wxCommandEvent
& event
)
226 wxGetApp().m_help
->SetTempDir( "tempdir" );
229 void MyFrame::OnHelp_Quitserver(wxCommandEvent
& event
)
231 // if (!wxGetApp().m_help->m_connection->Poke( wxT("--YouAreDead"), wxT("") ) )
232 // wxLogError(wxT("wxRemoteHtmlHelpController - YouAreDead Failed"));
234 wxGetApp().m_help
->Quit();
237 void MyFrame::OnExit(wxCommandEvent
& event
)
242 void MyFrame::ModalDlg(wxCommandEvent
& WXUNUSED(event
))
244 MyModalDialog
dlg(this);
248 BEGIN_EVENT_TABLE(MyModalDialog
, wxDialog
)
249 EVT_BUTTON(wxID_ANY
, MyModalDialog::OnButton
)
252 // ----------------------------------------------------------------------------
254 // ----------------------------------------------------------------------------
256 MyModalDialog::MyModalDialog(wxWindow
*parent
)
257 : wxDialog(parent
, wxID_ANY
, wxString("Modal dialog"))
259 wxBoxSizer
*sizerTop
= new wxBoxSizer(wxHORIZONTAL
);
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);
270 sizerTop
->SetSizeHints(this);
274 m_main
->SetDefault();
277 void MyModalDialog::OnButton(wxCommandEvent
& event
)
279 if ( event
.GetEventObject() == m_main
)
281 wxGetApp().m_help
->Display( "main.htm" );
283 else if ( event
.GetEventObject() == m_book1
)
285 wxGetApp().m_help
->Display( "book1.htm" );
287 else if ( event
.GetEventObject() == m_book2
)
289 wxGetApp().m_help
->Display( "book2.htm" );