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