]>
git.saurik.com Git - wxWidgets.git/blob - utils/helpview/src/client.cpp
218d658a707b1dc2cc785df319c1859981f651ad
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Remote help sample client
4 // Author: Julian Smart
5 // Modified by: Eric Dowty
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
22 // For compilers that support precompilation, includes "wx.h".
23 #include "wx/wxprec.h"
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"
41 // Settings common to both executables: determines whether
42 // we're using TCP/IP or real DDE.
44 //#include "ddesetup.h"
45 //#define wxUSE_DDE_FOR_IPC 0
48 #if defined(__WXGTK__) || defined(__WXMOTIF__)
49 #include "mondrian.xpm"
55 // ----------------------------------------------------------------------------
57 // ----------------------------------------------------------------------------
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
)
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
)
75 EVT_MENU(DIALOG_MODAL
, MyFrame::ModalDlg
)
76 EVT_BUTTON(BUTTON_MODAL
, MyFrame::ModalDlg
)
79 // ----------------------------------------------------------------------------
81 // ----------------------------------------------------------------------------
83 wxListBox
*the_list
= NULL
;
85 // ============================================================================
87 // ============================================================================
89 // ----------------------------------------------------------------------------
91 // ----------------------------------------------------------------------------
93 // The `main program' equivalent, creating the windows and returning the
97 wxString a_appname
, a_service
, a_windowname
, a_book
;
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/wxWidgets-helpconnection";
106 //a_service = "4242";
107 a_windowname
= "HTML Help Test: %s";
109 #if defined(__WXMSW__)
110 a_appname
= "helpview.exe";
112 a_appname
= "./helpview";
115 //a_book = "helpfiles/testing.hhp";
118 wxConfig
*conf
= (wxConfig
*) wxConfig::Get();
120 #if defined(USE_REMOTE)
121 m_help
= new wxRemoteHtmlHelpController();
122 m_help
->SetServer( a_appname
);
123 m_help
->SetService( a_service
);
125 m_help
= new wxHtmlHelpController();
128 //this is a dummy for wxRemoteHtmlHelpController
129 m_help
->UseConfig(conf
);
131 m_help
->AddBook( a_book
);
132 m_help
->SetTitleFormat( a_windowname
);
134 // Create the main frame window
135 MyFrame
* frame
= new MyFrame(NULL
, "Help Client");
144 delete wxConfig::Set(NULL
);
148 // Define my frame constructor
149 MyFrame::MyFrame(wxFrame
*frame
, const wxString
& title
)
150 : wxFrame(frame
, -1, title
, wxDefaultPosition
, wxSize( 200, 100 ) )
155 SetIcon(wxICON(mondrian
));
158 wxMenu
*file_menu
= new wxMenu
;
160 file_menu
->Append(CLIENT_HELPMAIN
, "Help - Main");
161 file_menu
->Append(CLIENT_HELPBOOK1
, "Help - Book1");
162 file_menu
->Append(CLIENT_HELPBOOK2
, "Help - Book2");
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");
172 file_menu
->Append(DIALOG_MODAL
, "Modal dialog");
173 file_menu
->Append(CLIENT_QUIT
, "Quit");
175 wxMenuBar
*menu_bar
= new wxMenuBar
;
177 menu_bar
->Append(file_menu
, "File");
179 // Associate the menu bar with the frame
180 SetMenuBar(menu_bar
);
183 m_panel
= new wxPanel(this );
185 m_modalbutton
= new wxButton( this, BUTTON_MODAL
, "Modal Dialog",
186 wxPoint(10,10), wxSize(-1, -1) );
189 void MyFrame::OnHelp_Book1(wxCommandEvent
& event
)
191 wxGetApp().m_help
->Display( "book1.htm" );
194 void MyFrame::OnHelp_Book2(wxCommandEvent
& event
)
196 wxGetApp().m_help
->Display( "book2.htm" );
199 void MyFrame::OnHelp_Main(wxCommandEvent
& event
)
201 wxGetApp().m_help
->Display( "main.htm" );
204 void MyFrame::OnHelp_Index(wxCommandEvent
& event
)
206 wxGetApp().m_help
->DisplayIndex( );
208 void MyFrame::OnHelp_Contents(wxCommandEvent
& event
)
210 wxGetApp().m_help
->DisplayContents( );
213 void MyFrame::OnHelp_Search(wxCommandEvent
& event
)
215 wxGetApp().m_help
->KeywordSearch( "enjoy" );
217 void MyFrame::OnHelp_Title(wxCommandEvent
& event
)
219 wxGetApp().m_help
->SetTitleFormat( "Another_Title: %s" );
221 void MyFrame::OnHelp_Addbook(wxCommandEvent
& event
)
223 wxGetApp().m_help
->AddBook("helpfiles/another.hhp" );
225 void MyFrame::OnHelp_Tempdir(wxCommandEvent
& event
)
227 wxGetApp().m_help
->SetTempDir( "tempdir" );
230 void MyFrame::OnHelp_Quitserver(wxCommandEvent
& event
)
232 // if (!wxGetApp().m_help->m_connection->Poke( wxT("--YouAreDead"), wxT("") ) )
233 // wxLogError(wxT("wxRemoteHtmlHelpController - YouAreDead Failed"));
235 wxGetApp().m_help
->Quit();
238 void MyFrame::OnExit(wxCommandEvent
& event
)
243 void MyFrame::ModalDlg(wxCommandEvent
& WXUNUSED(event
))
245 MyModalDialog
dlg(this);
249 BEGIN_EVENT_TABLE(MyModalDialog
, wxDialog
)
250 EVT_BUTTON(-1, MyModalDialog::OnButton
)
253 // ----------------------------------------------------------------------------
255 // ----------------------------------------------------------------------------
257 MyModalDialog::MyModalDialog(wxWindow
*parent
)
258 : wxDialog(parent
, -1, wxString("Modal dialog"))
260 wxBoxSizer
*sizerTop
= new wxBoxSizer(wxHORIZONTAL
);
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);
272 sizerTop
->SetSizeHints(this);
276 m_main
->SetDefault();
279 void MyModalDialog::OnButton(wxCommandEvent
& event
)
281 if ( event
.GetEventObject() == m_main
)
283 wxGetApp().m_help
->Display( "main.htm" );
285 else if ( event
.GetEventObject() == m_book1
)
287 wxGetApp().m_help
->Display( "book1.htm" );
289 else if ( event
.GetEventObject() == m_book2
)
291 wxGetApp().m_help
->Display( "book2.htm" );