Added Eric Dowty's wxRemoteHtmlController class and test app,

with mods to helpview for full control


git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/branches/WX_2_4_BRANCH@17894 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Julian Smart
2002-11-18 14:43:32 +00:00
parent 01e3574ea2
commit 39560cbe68
4 changed files with 643 additions and 398 deletions

View File

@@ -1,309 +1,298 @@
/////////////////////////////////////////////////////////////////////////////
// Name: client.cpp
// Purpose: Tests helpview in server mode.
// Purpose: Remote help sample client
// Author: Julian Smart
// Modified by:
// Created: 2002-10-08
// Modified by: Eric Dowty
// Created: 25/01/99
// RCS-ID: $Id$
// Copyright: (c) Julian Smart
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#if defined(__GNUG__) && !defined(__APPLE__)
#pragma implementation "client.cpp"
#pragma interface "client.cpp"
#endif
// ============================================================================
// declarations
// ============================================================================
// For compilers that support precompilation, includes "wx/wx.h".
// ----------------------------------------------------------------------------
// headers
// ----------------------------------------------------------------------------
#define USE_REMOTE 1
// For compilers that support precompilation, includes "wx.h".
#include "wx/wxprec.h"
#ifdef __BORLANDC__
#pragma hdrstop
#endif
// for all others, include the necessary headers (this file is usually all you
// need because it includes almost all "standard" wxWindows headers
#ifndef WX_PRECOMP
#include "wx/wx.h"
#include "wx/wx.h"
#endif
#include "wx/ipc.h"
#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>
#if defined(__WXGTK__) || defined(__WXMOTIF__)
#include "mondrian.xpm"
#endif
#include "remhelp.h"
#include "client.h"
// ----------------------------------------------------------------------------
// private classes
// wxWin macros
// ----------------------------------------------------------------------------
class MyConnection: public wxConnection
{
public:
MyConnection();
~MyConnection();
IMPLEMENT_APP(MyApp)
bool OnAdvise(const wxString& topic, const wxString& item, wxChar *data, int size, wxIPCFormat format);
bool OnDisconnect();
};
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)
class MyClient: public wxClient
{
public:
wxConnectionBase *OnMakeConnection();
};
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)
// Define a new application type, each program should derive a class from wxApp
class HelpClientApp : public wxApp
{
public:
// override base class virtuals
// ----------------------------
// this one is called on application startup and is a good place for the app
// initialization (doing it here and not in the ctor allows to have an error
// return: if OnInit() returns false, the application terminates)
virtual bool OnInit();
};
// Define a new frame type: this is going to be our main frame
class HelpClientFrame : public wxFrame
{
friend MyClient;
friend MyConnection;
public:
// ctor(s)
HelpClientFrame(const wxString& title, const wxPoint& pos, const wxSize& size);
// event handlers (these functions should _not_ be virtual)
void OnQuit(wxCommandEvent& event);
void OnHelpPage(wxCommandEvent& event);
void OnHelpContents(wxCommandEvent& event);
void OnClose(wxCloseEvent& event);
bool CreateConnection();
private:
MyConnection* m_connection;
MyClient* m_client;
// any class wishing to process wxWindows events must use this macro
DECLARE_EVENT_TABLE()
};
HelpClientFrame* g_MainFrame = NULL;
// ----------------------------------------------------------------------------
// constants
// ----------------------------------------------------------------------------
// IDs for the controls and the menu commands
enum
{
// menu items
HelpClient_Quit = 1,
HelpClient_HelpPage,
HelpClient_HelpContents,
};
// ----------------------------------------------------------------------------
// event tables and other macros for wxWindows
// ----------------------------------------------------------------------------
// the event tables connect the wxWindows events with the functions (event
// handlers) which process them. It can be also done at run-time, but for the
// simple menu events like this the static method is much simpler.
BEGIN_EVENT_TABLE(HelpClientFrame, wxFrame)
EVT_MENU(HelpClient_Quit, HelpClientFrame::OnQuit)
EVT_MENU(HelpClient_HelpPage, HelpClientFrame::OnHelpPage)
EVT_MENU(HelpClient_HelpContents, HelpClientFrame::OnHelpContents)
EVT_CLOSE(HelpClientFrame::OnClose)
EVT_MENU(DIALOG_MODAL, MyFrame::ModalDlg)
EVT_BUTTON(BUTTON_MODAL, MyFrame::ModalDlg)
END_EVENT_TABLE()
// Create a new application object: this macro will allow wxWindows to create
// the application object during program execution (it's better than using a
// static object for many reasons) and also declares the accessor function
// wxGetApp() which will return the reference of the right type (i.e. HelpClientApp and
// not wxApp)
IMPLEMENT_APP(HelpClientApp)
// ----------------------------------------------------------------------------
// globals
// ----------------------------------------------------------------------------
wxListBox *the_list = NULL;
// ============================================================================
// implementation
// ============================================================================
// ----------------------------------------------------------------------------
// the application class
// MyApp
// ----------------------------------------------------------------------------
// `Main program' equivalent: the program execution "starts" here
bool HelpClientApp::OnInit()
{
SetVendorName("wxWindows");
SetAppName("Help Client Demo");
// Create the main application window
HelpClientFrame *frame = new HelpClientFrame("Help Client Demo",
wxPoint(50, 50), wxSize(150, 50));
// Show it and tell the application that it's our main window
// @@@ what does it do exactly, in fact? is it necessary here?
frame->Show(TRUE);
SetTopWindow(frame);
// success: wxApp::OnRun() will be called which will enter the main message
// loop and the application will run. If we returned FALSE here, the
// application would exit immediately.
return TRUE;
}
// ----------------------------------------------------------------------------
// 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/wxWindows-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, -1, 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), wxSize(-1, -1) );
}
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(-1, MyModalDialog::OnButton)
END_EVENT_TABLE()
// ----------------------------------------------------------------------------
// MyModalDialog
// ----------------------------------------------------------------------------
// frame constructor
HelpClientFrame::HelpClientFrame(const wxString& title, const wxPoint& pos, const wxSize& size)
: wxFrame((wxFrame *)NULL, -1, title, pos, size)
MyModalDialog::MyModalDialog(wxWindow *parent)
: wxDialog(parent, -1, wxString("Modal dialog"))
{
g_MainFrame = this;
// create a menu bar
wxMenu *menuFile = new wxMenu;
menuFile->Append(HelpClient_HelpContents, "&Help Contents");
menuFile->Append(HelpClient_HelpPage, "Help Page");
menuFile->AppendSeparator();
menuFile->Append(HelpClient_Quit, "E&xit");
// now append the freshly created menu to the menu bar...
wxMenuBar *menuBar = new wxMenuBar;
menuBar->Append(menuFile, "&File");
// ... and attach this menu bar to the frame
SetMenuBar(menuBar);
m_connection = NULL;
m_client = new MyClient;
wxBoxSizer *sizerTop = new wxBoxSizer(wxHORIZONTAL);
m_main = new wxButton(this, -1, "Main");
m_book1 = new wxButton(this, -1, "Book1");
m_book2 = new wxButton(this, -1, "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);
SetAutoLayout(TRUE);
SetSizer(sizerTop);
sizerTop->SetSizeHints(this);
sizerTop->Fit(this);
m_main->SetFocus();
m_main->SetDefault();
}
// event handlers
void HelpClientFrame::OnQuit(wxCommandEvent& WXUNUSED(event))
void MyModalDialog::OnButton(wxCommandEvent& event)
{
// TRUE is to force the frame to close
Close(TRUE);
}
void HelpClientFrame::OnHelpPage(wxCommandEvent& WXUNUSED(event))
{
if (CreateConnection())
if ( event.GetEventObject() == m_main )
{
m_connection->Execute(wxT("Book 1"));
wxGetApp().m_help->Display( "main.htm" );
}
}
void HelpClientFrame::OnHelpContents(wxCommandEvent& WXUNUSED(event))
{
if (CreateConnection())
else if ( event.GetEventObject() == m_book1 )
{
m_connection->Execute(wxT("test.zip"));
wxGetApp().m_help->Display( "book1.htm" );
}
}
void HelpClientFrame::OnClose(wxCloseEvent& event)
{
if (m_connection)
else if ( event.GetEventObject() == m_book2 )
{
m_connection->Disconnect();
delete m_connection;
m_connection = NULL;
wxGetApp().m_help->Display( "book2.htm" );
}
delete m_client;
event.Skip();
}
bool HelpClientFrame::CreateConnection()
{
if (m_connection)
return TRUE;
wxString cmd;
#if defined(__WXMSW__)
cmd = "helpview.exe --server test.zip";
#else
cmd = "./helpview --server test.zip";
#endif
wxProcess *process = new wxProcess(this);
int pid = wxExecute( cmd, FALSE, process );
if( pid <= 0 ) {
wxMessageBox( "Failed to start server" );
return FALSE;
}
// service name (DDE classes) or port number (TCP/IP based classes)
wxString service = wxT("4242");
// ignored under DDE, host name in TCP/IP based classes
wxString hostName = wxT("localhost");
int nsleep = 0;
// suppress the log messages from MakeConnection()
else
{
wxLogNull nolog;
m_connection = (MyConnection *)m_client->MakeConnection(hostName, service, wxT("HELP"));
while ( !m_connection)
{
//try every second for a while
wxSleep(1);
if( nsleep > 4 ) {
if ( wxMessageBox("Failed to make connection to server.\nRetry?",
"Client Demo Error",
wxICON_ERROR | wxYES_NO | wxCANCEL ) != wxYES )
{
// no server
return FALSE;
}
}
nsleep++;
m_connection = (MyConnection *)m_client->MakeConnection(hostName, service, "HELP");
}
event.Skip();
}
return (m_connection != NULL);
}
wxConnectionBase *MyClient::OnMakeConnection()
{
return new MyConnection;
}
MyConnection::MyConnection()
: wxConnection()
{
g_MainFrame->m_connection = this;
}
MyConnection::~MyConnection()
{
g_MainFrame->m_connection = NULL;
}
bool MyConnection::OnAdvise(const wxString& topic, const wxString& item, char *data, int size, wxIPCFormat format)
{
return TRUE;
}
bool MyConnection::OnDisconnect()
{
g_MainFrame->m_connection = NULL;
delete this;
return TRUE;
}

View File

@@ -24,13 +24,14 @@ CFG=htmlclient - Win32 Debug
!MESSAGE
# Begin Project
# PROP AllowPerConfigDependencies 0
# PROP Scc_ProjName ""
# PROP Scc_LocalPath ""
CPP=cl.exe
MTL=midl.exe
RSC=rc.exe
!ELSEIF "$(CFG)" == "htmlclient - Win32 Release DLL"
!IF "$(CFG)" == "htmlclient - Win32 Release DLL"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 0
@@ -44,19 +45,19 @@ RSC=rc.exe
# PROP Ignore_Export_Lib 0
# PROP Target_Dir ""
# ADD BASE CPP /nologo /W4 /O2 /D "NDEBUG" /D "WIN32" /D "_WINDOWS" /D WINVER=0x400 /YX /FD /c
# ADD CPP /nologo /W4 /O2 /I "../../../include" /D "NDEBUG" /D "WIN32" /D "_WINDOWS" /D WINVER=0x400 /D WIN32 /D WINVER=0x400 /D _MT /D wxUSE_GUI=1 /YX /FD /c /MD /D WXUSINGDLL /I../../..\lib\mswdll
# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /o NUL /win32
# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /o NUL /win32
# ADD BASE RSC /l 0x409 /d "NDEBUG" /I "../../../include"
# ADD RSC /l 0x409 /d "NDEBUG" /I "../../../include"
# ADD CPP /nologo /MD /W4 /O2 /I "../../../include" /D "NDEBUG" /D "WIN32" /D "_WINDOWS" /D WINVER=0x400 /D "_MT" /D wxUSE_GUI=1 /D "WXUSINGDLL" /YX /FD /I../../..\lib\mswdll /c
# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /o "NUL" /win32
# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /o "NUL" /win32
# ADD BASE RSC /l 0x409 /i "../../../include" /d "NDEBUG"
# ADD RSC /l 0x409 /i "../../../include" /d "NDEBUG"
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LINK32=link.exe
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib comctl32.lib rpcrt4.lib wsock32.lib /nologo /subsystem:windows /machine:I386
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib comctl32.lib rpcrt4.lib wsock32.lib /nologo /subsystem:windows /machine:I386 ../../..\lib\wxmsw233.lib
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib comctl32.lib rpcrt4.lib wsock32.lib ../../..\lib\wxmsw233.lib /nologo /subsystem:windows /machine:I386
!ELSEIF "$(CFG)" == "htmlclient - Win32 Debug DLL"
!ELSEIF "$(CFG)" == "htmlclient - Win32 Debug DLL"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 1
@@ -70,19 +71,19 @@ LINK32=link.exe
# PROP Ignore_Export_Lib 0
# PROP Target_Dir ""
# ADD BASE CPP /nologo /W4 /Zi /Od /D "_DEBUG" /D "WIN32" /D "_WINDOWS" /D WINVER=0x400 /YX /FD /c
# ADD CPP /nologo /W4 /Zi /Od /I "../../../include" /D "_DEBUG" /D "WIN32" /D "_WINDOWS" /D WINVER=0x400 /D WIN32 /D WINVER=0x400 /D _MT /D wxUSE_GUI=1 /YX /FD /c /MDd /D "__WXDEBUG__" /D "WXDEBUG=1" /D WXUSINGDLL /I../../..\lib\mswdlld
# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /o NUL /win32
# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /o NUL /win32
# ADD BASE RSC /l 0x409 /d "_DEBUG" /I "../../../include"
# ADD RSC /l 0x409 /d "_DEBUG" /I "../../../include"
# ADD CPP /nologo /MDd /W4 /Zi /Od /I "../../../include" /D "_DEBUG" /D "WIN32" /D "_WINDOWS" /D WINVER=0x400 /D "_MT" /D wxUSE_GUI=1 /D "__WXDEBUG__" /D WXDEBUG=1 /D "WXUSINGDLL" /YX /FD /I../../..\lib\mswdlld /c
# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /o "NUL" /win32
# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /o "NUL" /win32
# ADD BASE RSC /l 0x409 /i "../../../include" /d "_DEBUG"
# ADD RSC /l 0x409 /i "../../../include" /d "_DEBUG"
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LINK32=link.exe
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib comctl32.lib rpcrt4.lib wsock32.lib /nologo /subsystem:windows /debug /machine:I386 /pdbtype:sept
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib comctl32.lib rpcrt4.lib wsock32.lib /nologo /subsystem:windows /debug /machine:I386 /pdbtype:sept ../../..\lib\wxmsw233d.lib
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib comctl32.lib rpcrt4.lib wsock32.lib ../../..\lib\wxmsw233d.lib /nologo /subsystem:windows /debug /machine:I386 /pdbtype:sept
!ELSEIF "$(CFG)" == "htmlclient - Win32 Release"
!ELSEIF "$(CFG)" == "htmlclient - Win32 Release"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 0
@@ -96,19 +97,19 @@ LINK32=link.exe
# PROP Ignore_Export_Lib 0
# PROP Target_Dir ""
# ADD BASE CPP /nologo /W4 /O2 /D "NDEBUG" /D "WIN32" /D "_WINDOWS" /D WINVER=0x400 /YX /FD /c
# ADD CPP /nologo /W4 /O2 /I "../../../include" /D "NDEBUG" /D "WIN32" /D "_WINDOWS" /D WINVER=0x400 /D WIN32 /D WINVER=0x400 /D _MT /D wxUSE_GUI=1 /YX /FD /c /MD /I../../..\lib\msw
# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /o NUL /win32
# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /o NUL /win32
# ADD BASE RSC /l 0x409 /d "NDEBUG" /I "../../../include"
# ADD RSC /l 0x409 /d "NDEBUG" /I "../../../include"
# ADD CPP /nologo /MD /W4 /O2 /I "../../../include" /D "NDEBUG" /D "WIN32" /D "_WINDOWS" /D WINVER=0x400 /D "_MT" /D wxUSE_GUI=1 /YX /FD /I../../..\lib\msw /c
# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /o "NUL" /win32
# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /o "NUL" /win32
# ADD BASE RSC /l 0x409 /i "../../../include" /d "NDEBUG"
# ADD RSC /l 0x409 /i "../../../include" /d "NDEBUG"
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LINK32=link.exe
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib comctl32.lib rpcrt4.lib wsock32.lib /nologo /subsystem:windows /machine:I386
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib comctl32.lib rpcrt4.lib wsock32.lib /nologo /subsystem:windows /machine:I386 ../../..\lib\zlib.lib ../../..\lib\regex.lib ../../..\lib\png.lib ../../..\lib\jpeg.lib ../../..\lib\tiff.lib ../../..\lib\wxmsw.lib
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib comctl32.lib rpcrt4.lib wsock32.lib ../../..\lib\zlib.lib ../../..\lib\regex.lib ../../..\lib\png.lib ../../..\lib\jpeg.lib ../../..\lib\tiff.lib ../../..\lib\wxmsw.lib /nologo /subsystem:windows /machine:I386
!ELSEIF "$(CFG)" == "htmlclient - Win32 Debug"
!ELSEIF "$(CFG)" == "htmlclient - Win32 Debug"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 1
@@ -122,17 +123,17 @@ LINK32=link.exe
# PROP Ignore_Export_Lib 0
# PROP Target_Dir ""
# ADD BASE CPP /nologo /W4 /Zi /Od /D "_DEBUG" /D "WIN32" /D "_WINDOWS" /D WINVER=0x400 /YX /FD /c
# ADD CPP /nologo /W4 /Zi /Od /I "../../../include" /D "_DEBUG" /D "WIN32" /D "_WINDOWS" /D WINVER=0x400 /D WIN32 /D WINVER=0x400 /D _MT /D wxUSE_GUI=1 /YX /FD /c /MDd /D "__WXDEBUG__" /D "WXDEBUG=1" /I../../..\lib\mswd
# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /o NUL /win32
# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /o NUL /win32
# ADD BASE RSC /l 0x409 /d "_DEBUG" /I "../../../include"
# ADD RSC /l 0x409 /d "_DEBUG" /I "../../../include"
# ADD CPP /nologo /MDd /W4 /Zi /Od /I "../../../include" /D "_DEBUG" /D "WIN32" /D "_WINDOWS" /D WINVER=0x400 /D "_MT" /D wxUSE_GUI=1 /D "__WXDEBUG__" /D WXDEBUG=1 /YX /FD /I../../..\lib\mswd /c
# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /o "NUL" /win32
# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /o "NUL" /win32
# ADD BASE RSC /l 0x409 /i "../../../include" /d "_DEBUG"
# ADD RSC /l 0x409 /i "../../../include" /d "_DEBUG"
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LINK32=link.exe
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib comctl32.lib rpcrt4.lib wsock32.lib /nologo /subsystem:windows /debug /machine:I386 /pdbtype:sept
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib comctl32.lib rpcrt4.lib wsock32.lib /nologo /subsystem:windows /debug /machine:I386 /pdbtype:sept ../../..\lib\zlibd.lib ../../..\lib\regexd.lib ../../..\lib\pngd.lib ../../..\lib\jpegd.lib ../../..\lib\tiffd.lib ../../..\lib\wxmswd.lib
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib comctl32.lib rpcrt4.lib wsock32.lib ../../..\lib\zlibd.lib ../../..\lib\regexd.lib ../../..\lib\pngd.lib ../../..\lib\jpegd.lib ../../..\lib\tiffd.lib ../../..\lib\wxmswd.lib /nologo /subsystem:windows /debug /machine:I386 /pdbtype:sept
!ENDIF
@@ -148,7 +149,19 @@ SOURCE=.\client.cpp
# End Source File
# Begin Source File
SOURCE=.\client.h
# End Source File
# Begin Source File
SOURCE=.\client.rc
# End Source File
# Begin Source File
SOURCE=.\remhelp.cpp
# End Source File
# Begin Source File
SOURCE=.\remhelp.h
# End Source File
# End Target
# End Project

View File

@@ -0,0 +1,87 @@
/////////////////////////////////////////////////////////////////////////////
// Name: client.h
// Purpose: Remote help sample client
// Author: Julian Smart
// Modified by: Eric Dowty
// Created: 2002-11-18
// RCS-ID: $Id$
// Copyright: (c) Julian Smart
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
// Define a new application
class MyApp: public wxApp
{
public:
virtual bool OnInit();
virtual int OnExit();
#if defined(USE_REMOTE)
wxRemoteHtmlHelpController *m_help;
#else
wxHtmlHelpController *m_help;
#endif
};
DECLARE_APP(MyApp)
// Define a new frame
class MyFrame: public wxFrame
{
public:
MyFrame(wxFrame *frame, const wxString& title);
private:
void OnExit(wxCommandEvent& event);
void OnHelp_Main(wxCommandEvent& event);
void OnHelp_Book1(wxCommandEvent& event);
void OnHelp_Book2(wxCommandEvent& event);
void OnHelp_Index(wxCommandEvent& event);
void OnHelp_Contents(wxCommandEvent& event);
void OnHelp_Search(wxCommandEvent& event);
void OnHelp_Title(wxCommandEvent& event);
void OnHelp_Addbook(wxCommandEvent& event);
void OnHelp_Tempdir(wxCommandEvent& event);
void OnHelp_Quitserver(wxCommandEvent& event);
void ModalDlg(wxCommandEvent& event);
wxPanel *m_panel;
wxButton *m_modalbutton;
DECLARE_EVENT_TABLE()
};
class MyModalDialog : public wxDialog
{
public:
MyModalDialog(wxWindow *parent);
private:
void OnButton(wxCommandEvent& event);
wxButton *m_main;
wxButton *m_book1;
wxButton *m_book2;
DECLARE_EVENT_TABLE()
};
#define CLIENT_QUIT wxID_EXIT
#define CLIENT_EXECUTE 2
#define CLIENT_REQUEST 3
#define CLIENT_POKE 4
#define CLIENT_HELPMAIN 5
#define CLIENT_HELPBOOK1 6
#define CLIENT_HELPBOOK2 7
#define DIALOG_MODAL 8
#define BUTTON_MODAL 9
#define CLIENT_HELPINDEX 10
#define CLIENT_HELPCONTENTS 11
#define CLIENT_HELPSEARCH 12
#define CLIENT_HELPTITLE 13
#define CLIENT_HELPADDBOOK 14
#define CLIENT_HELPTEMPDIR 15
#define CLIENT_HELPQUIT 16

View File

@@ -43,7 +43,6 @@ protected:
const wxSize& size);
};
IMPLEMENT_APP(hvApp)
hvApp::hvApp()
@@ -58,58 +57,158 @@ bool hvApp::OnInit()
#ifdef __WXMOTIF__
delete wxLog::SetActiveTarget(new wxLogStderr); // So dialog boxes aren't used
#endif
wxArtProvider::PushProvider(new AlternateArtProvider);
wxInitAllImageHandlers();
wxFileSystem::AddHandler(new wxZipFSHandler);
SetVendorName("wxWindows");
SetAppName("wxHTMLHelp");
wxConfig::Get(); // create an instance
m_helpController = new wxHtmlHelpController(
wxHF_DEFAULT_STYLE|wxHF_FLAT_TOOLBAR|wxHF_OPEN_FILES
);
m_helpController->SetTitleFormat(wxT("%s"));
if (argc < 2) {
if (!OpenBook(m_helpController))
return FALSE;
}
bool useAsServer = FALSE;
// If started with --server, use as help server.
for (int i = 1; i < argc; i++)
int istyle = wxHF_DEFAULT_STYLE;
wxArtProvider::PushProvider(new AlternateArtProvider);
wxString service, windowName, book[10], titleFormat, argStr;
int bookCount = 0;
int i;
bool hasService = FALSE;
bool hasWindowName = FALSE;
bool createServer = FALSE;
m_server = NULL;
// Help books are recognized by extension ".hhp" ".htb" or ".zip".
// Service and window_name can occur anywhere in arguments,
// but service must be first
// Other arguments (topic?) could be added
// modes of operation:
// 1) no arguments - stand alone, prompt user for book
// 2) books only - stand alone, open books
// 3) "--server" as (any) arg - start connection with default service;
// also open any books passed as other arguments
// 4) at least one argument which is not book, and not "--server" - take first
// such argument as service, second (if present) as window name,
// start service, open any books
for( i=1; i < argc; i++ )
{
if (wxString(wxT("--server")) == argv[i])
useAsServer = TRUE;
else
m_helpController -> AddBook(argv[i]);
argStr = argv[i];
if ( argStr.Find( wxT(".hhp") ) >= 0 ||
argStr.Find( wxT(".htb") ) >= 0 ||
argStr.Find( wxT(".zip") ) >= 0 ) {
book[bookCount] = argStr;
bookCount++;
}
else if ( argStr == wxT("--server") )
{
createServer = TRUE;
#if defined(__WXMSW__)
service = wxT("generic_helpservice");
#elif defined(__UNIX__)
service = wxT("/tmp/") + wxString(wxT("generic_helpservice"));
#else
service = wxT("4242");
#endif
}
else if ( !hasService )
{
service = argStr;
hasService = TRUE;
createServer = TRUE;
}
else if ( !hasWindowName )
{
windowName = argStr;
hasWindowName = TRUE;
}
else if ( argStr.Find( wxT("--Style") ) >= 0 )
{
long i;
wxString numb = argStr.AfterLast(wxT('e'));
if ( !(numb.ToLong(&i) ) )
{
wxLogError( wxT("Integer conversion failed for --Style") );
}
else
{
istyle = i;
}
}
else
{
//unknown - could be topic?
}
}
//no book - query user
if ( bookCount < 1 )
{
wxString s = wxFileSelector( wxT("Open help file"),
wxGetCwd(),
wxEmptyString,
wxEmptyString,
wxT(
"Help books (*.htb)|*.htb|Help books (*.zip)|*.zip|\
HTML Help Project (*.hhp)|*.hhp"),
wxOPEN | wxFILE_MUST_EXIST,
NULL);
if (!s.IsEmpty())
{
book[0] = s;
bookCount = 1;
}
}
#if hvUSE_IPC
if ( createServer ) {
// Create a new server
m_server = new hvServer;
if ( !m_server->Create(service) ) {
wxString wxm = wxT("Server Create failed - service: ");
wxString xxm = wxm << service;
wxLogError( xxm );
//if MSW quits here, probably another copy already exists
return FALSE;
}
createServer = FALSE;
}
#endif // hvUSE_IPC
//now add help
wxInitAllImageHandlers();
wxFileSystem::AddHandler(new wxZipFSHandler);
SetVendorName(wxT("wxWindows") );
SetAppName(wxT("wxHTMLHelpServer") );
wxConfig::Get(); // create an instance
m_helpController = new wxHtmlHelpController( istyle );
if ( !hasWindowName )
titleFormat = wxT("Help: %s") ;
else
{
//remove underscores
windowName.Replace( wxT("_"), wxT(" ") );
titleFormat = windowName;
}
m_helpController->SetTitleFormat( titleFormat );
for( i=0; i < bookCount; i++ )
{
m_helpController->AddBook(book[i]);
}
#ifdef __WXMOTIF__
delete wxLog::SetActiveTarget(new wxLogGui);
#endif
m_helpController -> DisplayContents();
if (m_helpController->GetFrame())
{
wxString verStr;
verStr.Printf(wxT("HelpView %.2f, built %s"), hvVERSION, __DATE__);
m_helpController->GetFrame()->SetStatusText(verStr);
}
#if hvUSE_IPC
if (useAsServer)
{
m_server = new hvServer;
m_server->Create(wxT("4242"));
}
#endif
return TRUE;
}
@@ -127,17 +226,17 @@ int hvApp::OnExit()
node = next;
}
m_connections.Clear();
if (m_server)
{
delete m_server;
m_server = NULL;
}
#endif
delete m_helpController;
delete wxConfig::Set(NULL);
return 0;
}
@@ -148,11 +247,11 @@ bool hvApp::OpenBook(wxHtmlHelpController* controller)
wxEmptyString,
wxEmptyString,
_(
"Help books (*.htb)|*.htb|Help books (*.zip)|*.zip|\
HTML Help Project (*.hhp)|*.hhp"),
wxOPEN | wxFILE_MUST_EXIST,
NULL);
"Help books (*.htb)|*.htb|Help books (*.zip)|*.zip|\
HTML Help Project (*.hhp)|*.hhp"),
wxOPEN | wxFILE_MUST_EXIST,
NULL);
if (!s.IsEmpty())
{
wxString ext = s.Right(4).Lower();
@@ -167,8 +266,8 @@ HTML Help Project (*.hhp)|*.hhp"),
}
/*
* Art provider class
*/
* Art provider class
*/
// ---------------------------------------------------------------------
// helper macros
@@ -176,48 +275,48 @@ HTML Help Project (*.hhp)|*.hhp"),
// Standard macro for getting a resource from XPM file:
#define ART(artId, xpmRc) \
if ( id == artId ) return wxBitmap(xpmRc##_xpm);
if ( id == artId ) return wxBitmap(xpmRc##_xpm);
// Compatibility hack to use wxApp::GetStdIcon of overriden by the user
#if WXWIN_COMPATIBILITY_2_2
#define GET_STD_ICON_FROM_APP(iconId) \
if ( client == wxART_MESSAGE_BOX ) \
{ \
wxIcon icon = wxTheApp->GetStdIcon(iconId); \
if ( icon.Ok() ) \
{ \
wxBitmap bmp; \
bmp.CopyFromIcon(icon); \
return bmp; \
} \
}
#define GET_STD_ICON_FROM_APP(iconId) \
if ( client == wxART_MESSAGE_BOX ) \
{ \
wxIcon icon = wxTheApp->GetStdIcon(iconId); \
if ( icon.Ok() ) \
{ \
wxBitmap bmp; \
bmp.CopyFromIcon(icon); \
return bmp; \
} \
}
#else
#define GET_STD_ICON_FROM_APP(iconId)
#define GET_STD_ICON_FROM_APP(iconId)
#endif
// There are two ways of getting the standard icon: either via XPMs or via
// wxIcon ctor. This depends on the platform:
#if defined(__WXUNIVERSAL__)
#define CREATE_STD_ICON(iconId, xpmRc) return wxNullBitmap;
#define CREATE_STD_ICON(iconId, xpmRc) return wxNullBitmap;
#elif defined(__WXGTK__) || defined(__WXMOTIF__)
#define CREATE_STD_ICON(iconId, xpmRc) return wxBitmap(xpmRc##_xpm);
#define CREATE_STD_ICON(iconId, xpmRc) return wxBitmap(xpmRc##_xpm);
#else
#define CREATE_STD_ICON(iconId, xpmRc) \
{ \
wxIcon icon(_T(iconId)); \
wxBitmap bmp; \
bmp.CopyFromIcon(icon); \
return bmp; \
}
#define CREATE_STD_ICON(iconId, xpmRc) \
{ \
wxIcon icon(_T(iconId)); \
wxBitmap bmp; \
bmp.CopyFromIcon(icon); \
return bmp; \
}
#endif
// Macro used in CreateBitmap to get wxICON_FOO icons:
#define ART_MSGBOX(artId, iconId, xpmRc) \
if ( id == artId ) \
{ \
GET_STD_ICON_FROM_APP(iconId) \
CREATE_STD_ICON(#iconId, xpmRc) \
}
{ \
GET_STD_ICON_FROM_APP(iconId) \
CREATE_STD_ICON(#iconId, xpmRc) \
}
// ---------------------------------------------------------------------
// XPMs with the art
@@ -249,36 +348,36 @@ wxBitmap AlternateArtProvider::CreateBitmap(const wxArtID& id,
const wxSize& WXUNUSED(size))
{
ART(wxART_HELP_SIDE_PANEL, helpsidepanel)
ART(wxART_HELP_SETTINGS, helpoptions)
ART(wxART_HELP_BOOK, helpbook)
ART(wxART_HELP_FOLDER, helpbook)
ART(wxART_HELP_PAGE, helppage)
//ART(wxART_ADD_BOOKMARK, addbookm)
//ART(wxART_DEL_BOOKMARK, delbookm)
ART(wxART_GO_BACK, helpback)
ART(wxART_GO_FORWARD, helpforward)
ART(wxART_GO_UP, helpup)
ART(wxART_GO_DOWN, helpdown)
ART(wxART_GO_TO_PARENT, helpuplevel)
ART(wxART_FILE_OPEN, helpopen)
if (client == wxART_HELP_BROWSER)
{
//ART(wxART_FRAME_ICON, helpicon)
ART(wxART_HELP, helpicon)
}
//ART(wxART_GO_HOME, home)
// Any wxWindows icons not implemented here
// will be provided by the default art provider.
return wxNullBitmap;
ART(wxART_HELP_SETTINGS, helpoptions)
ART(wxART_HELP_BOOK, helpbook)
ART(wxART_HELP_FOLDER, helpbook)
ART(wxART_HELP_PAGE, helppage)
//ART(wxART_ADD_BOOKMARK, addbookm)
//ART(wxART_DEL_BOOKMARK, delbookm)
ART(wxART_GO_BACK, helpback)
ART(wxART_GO_FORWARD, helpforward)
ART(wxART_GO_UP, helpup)
ART(wxART_GO_DOWN, helpdown)
ART(wxART_GO_TO_PARENT, helpuplevel)
ART(wxART_FILE_OPEN, helpopen)
if (client == wxART_HELP_BROWSER)
{
//ART(wxART_FRAME_ICON, helpicon)
ART(wxART_HELP, helpicon)
}
//ART(wxART_GO_HOME, home)
// Any wxWindows icons not implemented here
// will be provided by the default art provider.
return wxNullBitmap;
}
#if hvUSE_IPC
wxConnectionBase *hvServer::OnAcceptConnection(const wxString& topic)
{
if (topic == "HELP")
if (topic == wxT("HELP"))
return new hvConnection();
else
return NULL;
@@ -289,7 +388,7 @@ wxConnectionBase *hvServer::OnAcceptConnection(const wxString& topic)
// ----------------------------------------------------------------------------
hvConnection::hvConnection()
: wxConnection()
: wxConnection()
{
wxGetApp().GetConnections().Append(this);
}
@@ -304,9 +403,24 @@ bool hvConnection::OnExecute(const wxString& WXUNUSED(topic),
int WXUNUSED(size),
wxIPCFormat WXUNUSED(format))
{
// wxLogStatus("Execute command: %s", data);
wxGetApp().GetHelpController()->Display(data);
// wxLogStatus("Execute command: %s", data);
if ( !wxStrncmp( data, wxT("--intstring"), 11 ) )
{
long i;
wxString argStr = data;
wxString numb = argStr.AfterLast(wxT('g'));
if ( !(numb.ToLong(&i) ) ) {
wxLogError( wxT("Integer conversion failed for --intstring") );
}
else {
wxGetApp().GetHelpController()->Display(int(i));
}
}
else
{
wxGetApp().GetHelpController()->Display(data);
}
return TRUE;
}
@@ -317,14 +431,56 @@ bool hvConnection::OnPoke(const wxString& WXUNUSED(topic),
int WXUNUSED(size),
wxIPCFormat WXUNUSED(format))
{
// wxLogStatus("Poke command: %s = %s", item.c_str(), data);
// wxLogStatus("Poke command: %s = %s", item.c_str(), data);
//topic is not tested
if ( wxGetApp().GetHelpController() )
{
if ( item == wxT("--AddBook") )
{
wxGetApp().GetHelpController()->AddBook(data);
}
else if ( item == wxT("--DisplayContents") )
{
wxGetApp().GetHelpController()->DisplayContents();
}
else if ( item == wxT("--DisplayIndex") )
{
wxGetApp().GetHelpController()->DisplayIndex();
}
else if ( item == wxT("--KeywordSearch") )
{
wxGetApp().GetHelpController()->KeywordSearch(data);
}
else if ( item == wxT("--SetTitleFormat") )
{
wxString newname = data;
newname.Replace( wxT("_"), wxT(" ") );
wxGetApp().GetHelpController()->SetTitleFormat(newname);
//does not redraw title bar?
//wxGetApp().GetHelpController()->ReFresh(); - or something
}
else if ( item == wxT("--SetTempDir") )
{
wxGetApp().GetHelpController()->SetTempDir(data);
}
else if ( item == wxT("--YouAreDead") )
{
// don't really know how to kill app from down here...
// use wxKill from client instead
//wxWindow *win = wxTheApp->GetTopWindow();
//if ( win )
// win->Destroy();
}
}
return TRUE;
}
wxChar *hvConnection::OnRequest(const wxString& WXUNUSED(topic),
const wxString& WXUNUSED(item),
int * WXUNUSED(size),
wxIPCFormat WXUNUSED(format))
const wxString& WXUNUSED(item),
int * WXUNUSED(size),
wxIPCFormat WXUNUSED(format))
{
return NULL;
}