merged 2.4 branch into the trunk

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@18040 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2002-12-04 14:11:26 +00:00
parent 59a944cb63
commit 2b5f62a0b2
1057 changed files with 37805 additions and 24034 deletions

View File

@@ -0,0 +1,298 @@
/////////////////////////////////////////////////////////////////////////////
// Name: client.cpp
// Purpose: Remote help sample client
// Author: Julian Smart
// Modified by: Eric Dowty
// Created: 25/01/99
// RCS-ID: $Id$
// 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>
#if defined(__WXGTK__) || defined(__WXMOTIF__)
#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/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
// ----------------------------------------------------------------------------
MyModalDialog::MyModalDialog(wxWindow *parent)
: wxDialog(parent, -1, wxString("Modal dialog"))
{
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();
}
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();
}
}

View File

@@ -0,0 +1,167 @@
# Microsoft Developer Studio Project File - Name="htmlclient" - Package Owner=<4>
# Microsoft Developer Studio Generated Build File, Format Version 6.00
# ** DO NOT EDIT **
# TARGTYPE "Win32 (x86) Application" 0x0101
CFG=htmlclient - Win32 Debug
!MESSAGE This is not a valid makefile. To build this project using NMAKE,
!MESSAGE use the Export Makefile command and run
!MESSAGE
!MESSAGE NMAKE /f "client.mak".
!MESSAGE
!MESSAGE You can specify a configuration when running NMAKE
!MESSAGE by defining the macro CFG on the command line. For example:
!MESSAGE
!MESSAGE NMAKE /f "client.mak" CFG="htmlclient - Win32 Debug"
!MESSAGE
!MESSAGE Possible choices for configuration are:
!MESSAGE
!MESSAGE "htmlclient - Win32 Release DLL" (based on "Win32 (x86) Application")
!MESSAGE "htmlclient - Win32 Debug DLL" (based on "Win32 (x86) Application")
!MESSAGE "htmlclient - Win32 Release" (based on "Win32 (x86) Application")
!MESSAGE "htmlclient - Win32 Debug" (based on "Win32 (x86) Application")
!MESSAGE
# Begin Project
# PROP AllowPerConfigDependencies 0
# PROP Scc_ProjName ""
# PROP Scc_LocalPath ""
CPP=cl.exe
MTL=midl.exe
RSC=rc.exe
!IF "$(CFG)" == "htmlclient - Win32 Release DLL"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 0
# PROP BASE Output_Dir "ReleaseDll"
# PROP BASE Intermediate_Dir "ReleaseDll"
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 0
# PROP Output_Dir "ReleaseDll"
# PROP Intermediate_Dir "ReleaseDll"
# 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 /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 ../../..\lib\wxmsw233.lib /nologo /subsystem:windows /machine:I386
!ELSEIF "$(CFG)" == "htmlclient - Win32 Debug DLL"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 1
# PROP BASE Output_Dir "DebugDll"
# PROP BASE Intermediate_Dir "DebugDll"
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 1
# PROP Output_Dir "DebugDll"
# PROP Intermediate_Dir "DebugDll"
# 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 /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 ../../..\lib\wxmsw233d.lib /nologo /subsystem:windows /debug /machine:I386 /pdbtype:sept
!ELSEIF "$(CFG)" == "htmlclient - Win32 Release"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 0
# PROP BASE Output_Dir "Release"
# PROP BASE Intermediate_Dir "Release"
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 0
# PROP Output_Dir "Release"
# PROP Intermediate_Dir "Release"
# 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 /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 ../../..\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"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 1
# PROP BASE Output_Dir "Debug"
# PROP BASE Intermediate_Dir "Debug"
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 1
# PROP Output_Dir "Debug"
# PROP Intermediate_Dir "Debug"
# 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 /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 ../../..\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
# Begin Target
# Name "htmlclient - Win32 Release DLL"
# Name "htmlclient - Win32 Debug DLL"
# Name "htmlclient - Win32 Release"
# Name "htmlclient - Win32 Debug"
# Begin Source File
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

@@ -0,0 +1 @@
#include "wx/msw/wx.rc"

View File

@@ -43,57 +43,200 @@ protected:
const wxSize& size);
};
// ----------------------------------------------------------------------------
// private classes
// ----------------------------------------------------------------------------
IMPLEMENT_APP(hvApp)
hvApp::hvApp()
{
#if hvUSE_IPC
m_server = NULL;
#endif
}
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
help = new wxHtmlHelpController(
wxHF_DEFAULT_STYLE|wxHF_FLAT_TOOLBAR|wxHF_OPEN_FILES
);
help->SetTitleFormat(wxT("%s"));
if (argc < 2) {
if (!OpenBook(help))
return FALSE;
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++ )
{
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?
}
}
for (int i = 1; i < argc; i++)
help -> AddBook(argv[i]);
//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
help -> DisplayContents();
m_helpController -> DisplayContents();
return TRUE;
}
int hvApp::OnExit()
{
delete help;
#if hvUSE_IPC
wxNode* node = m_connections.First();
while (node)
{
wxNode* next = node->Next();
hvConnection* connection = (hvConnection*) node->Data();
connection->Disconnect();
delete connection;
node = next;
}
m_connections.Clear();
if (m_server)
{
delete m_server;
m_server = NULL;
}
#endif
delete m_helpController;
delete wxConfig::Set(NULL);
return 0;
}
@@ -104,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();
@@ -123,8 +266,8 @@ HTML Help Project (*.hhp)|*.hhp"),
}
/*
* Art provider class
*/
* Art provider class
*/
// ---------------------------------------------------------------------
// helper macros
@@ -132,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
@@ -205,26 +348,148 @@ 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_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 == wxT("HELP"))
return new hvConnection();
else
return NULL;
}
// ----------------------------------------------------------------------------
// hvConnection
// ----------------------------------------------------------------------------
hvConnection::hvConnection()
: wxConnection()
{
wxGetApp().GetConnections().Append(this);
}
hvConnection::~hvConnection()
{
wxGetApp().GetConnections().DeleteObject(this);
}
bool hvConnection::OnExecute(const wxString& WXUNUSED(topic),
wxChar *data,
int WXUNUSED(size),
wxIPCFormat WXUNUSED(format))
{
// 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;
}
bool hvConnection::OnPoke(const wxString& WXUNUSED(topic),
const wxString& item,
wxChar *data,
int WXUNUSED(size),
wxIPCFormat WXUNUSED(format))
{
// 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))
{
return NULL;
}
bool hvConnection::OnStartAdvise(const wxString& WXUNUSED(topic),
const wxString& WXUNUSED(item))
{
return TRUE;
}
#endif
// hvUSE_IPC

View File

@@ -55,7 +55,7 @@ BSC32=bscmake.exe
# 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 ../../..\lib\wxmsw233.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 ../../..\lib\wxmsw234.lib /nologo /subsystem:windows /machine:I386
!ELSEIF "$(CFG)" == "htmlhelpview - Win32 Debug DLL"
@@ -81,7 +81,7 @@ BSC32=bscmake.exe
# 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 ../../..\lib\wxmsw233d.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 ../../..\lib\wxmsw234d.lib /nologo /subsystem:windows /debug /machine:I386 /pdbtype:sept
!ELSEIF "$(CFG)" == "htmlhelpview - Win32 Release"

View File

@@ -16,27 +16,79 @@
#pragma interface "help.cpp"
#endif
// Define a new application type, each program should derive a class from wxApp
#define hvVERSION 1.02
// If 1, start a server to allow this to be used
// as an external help viewer.
#define hvUSE_IPC 1
#if hvUSE_IPC
#include <wx/ipc.h>
class hvConnection;
class hvServer;
#endif
/*!
* The helpview application class.
*/
class hvApp : public wxApp
{
public:
// override base class virtuals
// ----------------------------
public:
hvApp();
// 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)
/// Initialise the application.
virtual bool OnInit();
virtual bool OnInit();
virtual int OnExit();
/// Clean up the application's data.
virtual int OnExit();
/// Prompt the user for a book to open
bool OpenBook(wxHtmlHelpController* controller);
// Prompt the user for a book to open
bool OpenBook(wxHtmlHelpController* controller);
/// Returns the help controller.
wxHtmlHelpController* GetHelpController() { return m_helpController; }
private:
wxHtmlHelpController *help;
#if hvUSE_IPC
/// Returns the list of connections.
wxList& GetConnections() { return m_connections; }
#endif
private:
wxHtmlHelpController* m_helpController;
#if hvUSE_IPC
wxList m_connections;
hvServer* m_server;
#endif
};
#if hvUSE_IPC
class hvConnection : public wxConnection
{
public:
hvConnection();
~hvConnection();
bool OnExecute(const wxString& topic, wxChar*data, int size, wxIPCFormat format);
wxChar *OnRequest(const wxString& topic, const wxString& item, int *size, wxIPCFormat format);
bool OnPoke(const wxString& topic, const wxString& item, wxChar *data, int size, wxIPCFormat format);
bool OnStartAdvise(const wxString& topic, const wxString& item);
private:
};
class hvServer: public wxServer
{
public:
wxConnectionBase *OnAcceptConnection(const wxString& topic);
};
#endif
#endif
// _WX_HELPVIEW_H_

View File

@@ -0,0 +1,35 @@
The HTML help client-server pair sample consists of three parts:
1) The Client, derived from Client from the IPC samples and now containing wxRemoteHtmlHelpController
2) The Server, derived from helpview - the app is called helpview
3) The sample help files, specifically called by the Client, which are from the HTML/Help sample
Normally, the Client is started first, and it will in turn start up the Server (helpview) the first time help is requested with Display. If the Server is to be started first, the default service name ("generic_helpservice" for MSW, "/tmp/generic_helpservice" for Unix or "4242" otherwise) should be used for the connection in the client.
It is assumed that there will be one copy of the server for each app which uses help. Depending on the OS, it may be possible to use different instances of the same server, or even to use one instance of the server (probably not a good idea) to service more than one app requesting help.
At the moment, if a connection has been established and if the client is killed, the server is also killed. If the client is started up again, it will use the same connection.
If USE_REMOTE in client.cpp is undefined, the "client" app will use wxHtmlHelpController instead of wxRemoteHtmlHelpController, that is the remote server will not be used. In MSW, this results in freezing of the help window when called from a modal dialog. In GTK, the window is not frozen, but it must be closed before you can return to the app itself.
------------------------------------------------
wxRemoteHtmlHelpController Class
This class can be added to an application (the client) to provide wxWindows HTML help. It will start up the remote help controller (helpview) the first time the Display member function is called, passing the server the connection name or port number, the name of the help window and the help book (.hhp, .htb, .zip). This class will only work with a particular server app, helpview.
Most of the functions of wxHtmlHelpController are available - the relevant arguments are just passed to wxHtmlHelpController in the server. The functions involving wxConfig are not implemented - the config parameters (font, windows size and position) are kept in the server.
Use the members SetServer and SetService to pass the name of the server app and service name or port. This must be done before the first call to the Display member function, or defaults will be used. The default server app is "helpview" and default service depends on the platform: for MSW it is "appname_helpservice" (a service name string); for UNIX platforms it is "/tmp/appname_helpservice" (a file name) and otherwise it is "4242" (a TCP/IP port number), where "appname" is the name of the application without extension.
A wxRemoteHtmlHelpController can be created in wxApp::OnInit, or some high level window like a mainframe. It should be deleted explicitly, for example in wxApp::OnExit, or else the various connection objects are deleted in the wrong order. Using a wxRemoteHtmlHelpController member of wxApp does not work because of problems on exit.
This has been tested on wxMSW and wxGTK. It does not work on wxMac because the connection classes, as well as wxExecute, are not fully supported.
----------------------------------------------
Changes to helpview sample
The constructor now tests the command-line arguments, looking first for help books (containing .hhp, .htb, .zip). Then it looks for "--server". If arguments not falling in these categories are present, they are taken to be 1) the service name or 2) the window name (see wxRemoteHtmlHelpController for the meaning of service name).
The client passes most functions of wxHtmlHelpController, with argument, to helpview using wxConnection::Poke. The string for the Display function is passed with wxConnection::Execute.

View File

@@ -0,0 +1,409 @@
/////////////////////////////////////////////////////////////////////////////
// Name: remhelp.cpp
// Purpose: Remote help controller class
// Author: Eric Dowty
// Modified by:
// Created: 2002-11-18
// RCS-ID: $Id$
// Copyright: (c) Julian Smart
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#if defined(__GNUG__) && !defined(__APPLE__)
#pragma implementation remhelp.h
#endif
// 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/confbase.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
#if defined(__WXGTK__) || defined(__WXMOTIF__)
#include "mondrian.xpm"
#endif
#include "remhelp.h"
#include "client.h"
#if !defined(USE_REMOTE)
#include <wx/html/helpctrl.h>
#endif
//////////////////
//////////////////
// helper classes
rhhcClient::rhhcClient( bool *isconn_a )
{
isconn_2 = isconn_a;
}
wxConnectionBase *rhhcClient::OnMakeConnection()
{
return new rhhcConnection( isconn_2 );
}
rhhcConnection::rhhcConnection( bool *isconn_a )
: wxConnection()
{
isconn_3 = isconn_a;
*isconn_3 = TRUE;
}
rhhcConnection::~rhhcConnection()
{
*isconn_3 = FALSE;
}
bool rhhcConnection::OnAdvise(const wxString& topic, const wxString& item, char *data, int size, wxIPCFormat format)
{
return TRUE;
}
bool rhhcConnection::OnDisconnect()
{
*isconn_3 = FALSE;
return wxConnection::OnDisconnect();
}
//////////////////////////////////////////
/////////////////////////////////////////
// wxRemoteHtmlHelpController class
IMPLEMENT_CLASS(wxRemoteHtmlHelpController, wxHelpControllerBase)
wxRemoteHtmlHelpController::wxRemoteHtmlHelpController(int style )
{
m_style = style;
m_connection = NULL;
m_client = NULL;
m_pid = 0;
isconn_1 = FALSE;
m_process = NULL;
// defaults
//
// server app is assumed to be local
//
// 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
wxString thename = wxGetApp().GetAppName();
#if defined(__WXMSW__)
m_appname = wxT("helpview.exe");
m_service = thename + wxString(wxT("_helpservice"));
#elif defined(__UNIX__)
m_appname = wxT("./helpview");
m_service = wxT("/tmp/") + thename + wxString(wxT("_helpservice"));
#else
m_appname = wxT("./helpview");
m_service = wxT("4242");
#endif
m_book = thename + wxT(".hhp"); // or .htb or .zip
m_windowname = thename + wxT(" Help: %s");
//underscores for spaces
m_windowname.Replace( wxT(" "), wxT("_") );
}
void wxRemoteHtmlHelpController::SetService(wxString& a_service)
{
m_service = a_service;
}
void wxRemoteHtmlHelpController::SetServer(wxString& a_appname)
{
m_appname = a_appname;
}
void wxRemoteHtmlHelpController::OnQuit()
{
//kill the Server here?
//this function is not called ?
}
wxRemoteHtmlHelpController::~wxRemoteHtmlHelpController()
{
if ( isconn_1 )
{
//if (!m_connection->Poke( wxT("--YouAreDead"), wxT("") ) )
// wxLogError(wxT("wxRemoteHtmlHelpController - YouAreDead Failed"));
// Kill the server. This could be an option.
Quit();
m_connection->Disconnect();
delete m_connection;
delete m_process;
m_process = NULL;
}
if( m_client )
delete m_client; //should be automatic?
}
bool wxRemoteHtmlHelpController::DoConnection()
{
wxString cmd, blank;
int nsleep;
blank = wxT(" ");
// ignored under DDE, host name in TCP/IP based classes
wxString hostName = wxT("localhost");
// Create a new client
if( !m_client ) m_client = new rhhcClient(&isconn_1);
nsleep = 0;
// suppress the log messages from MakeConnection()
{
wxLogNull nolog;
//first try to connect assuming server is running
if( !isconn_1 )
m_connection = (rhhcConnection *)m_client->MakeConnection(hostName, m_service, wxT("HELP") );
//if not, start server
if( !isconn_1 ) {
wxString stylestr;
stylestr.Printf( wxT("--Style%d"), m_style );
cmd = m_appname + blank + m_service + blank + m_windowname + blank + m_book + blank + stylestr;
m_process = new wxProcess(NULL);
m_pid = wxExecute( cmd, FALSE, m_process );
// leaks - wxExecute itself (if not deleted) and in wxExecute at
// wxExecuteData *data = new wxExecuteData;
if( m_pid <= 0 ) {
wxLogError( wxT("wxRemoteHtmlHelpController - Failed to start Help server") );
return FALSE;
}
}
while ( !isconn_1 )
{
//try every second for a while, then leave it to user
wxSleep(1);
if( nsleep > 4 ) {
if ( wxMessageBox( wxT("Failed to make connection to Help server.\nRetry?") ,
wxT("wxRemoteHtmlHelpController Error"),
wxICON_ERROR | wxYES_NO | wxCANCEL ) != wxYES )
{
// no server
return FALSE;
}
}
nsleep++;
m_connection = (rhhcConnection *)m_client->MakeConnection(hostName, m_service, wxT("HELP") );
}
}
if (!m_connection->StartAdvise(wxT("Item"))) {
wxLogError(wxT("wxRemoteHtmlHelpController - StartAdvise failed") );
return FALSE;
}
return TRUE;
}
bool wxRemoteHtmlHelpController::LoadFile(const wxString& WXUNUSED(file))
{
return TRUE;
}
bool wxRemoteHtmlHelpController::DisplaySection(int sectionNo)
{
Display(sectionNo);
return TRUE;
}
bool wxRemoteHtmlHelpController::DisplayBlock(long blockNo)
{
return DisplaySection((int)blockNo);
}
bool wxRemoteHtmlHelpController::Quit()
{
//this code from exec sample - branches left in for testing
// sig = 3, 6, 9 or 12 all kill server with no apparent problem
// but give error message on MSW - timout?
int sig = 15; //3 = quit; 6 = abort; 9 = kill; 15 = terminate
/*
switch ( sig )
{
default:
wxFAIL_MSG( _T("unexpected return value") );
// fall through
case -1:
// cancelled
return FALSE;
case wxSIGNONE:
case wxSIGHUP:
case wxSIGINT:
case wxSIGQUIT:
case wxSIGILL:
case wxSIGTRAP:
case wxSIGABRT:
case wxSIGEMT:
case wxSIGFPE:
case wxSIGKILL:
case wxSIGBUS:
case wxSIGSEGV:
case wxSIGSYS:
case wxSIGPIPE:
case wxSIGALRM:
case wxSIGTERM:
break;
}
*/
if ( sig == 0 )
{
if ( wxProcess::Exists(m_pid) )
wxLogStatus(_T("Process %ld is running."), m_pid);
else
wxLogStatus(_T("No process with pid = %ld."), m_pid);
}
else // not SIGNONE
{
wxKillError rc = wxProcess::Kill(m_pid, (wxSignal)sig);
if ( rc == wxKILL_OK )
{
wxLogStatus(_T("Process %ld killed with signal %d."), m_pid, sig);
}
else
{
static const wxChar *errorText[] =
{
_T(""), // no error
_T("signal not supported"),
_T("permission denied"),
_T("no such process"),
_T("unspecified error"),
};
// sig = 3, 6, 9 or 12 all kill server with no apparent problem
// but give error message on MSW - timout?
//
//wxLogError(_T("Failed to kill process %ld with signal %d: %s"),
// m_pid, sig, errorText[rc]);
}
}
return TRUE;
}
void wxRemoteHtmlHelpController::Display(const wxString& helpfile)
{
if( !isconn_1 ) {
if( !DoConnection() ) return;
}
if (!m_connection->Execute( helpfile, -1 ) )
wxLogError(wxT("wxRemoteHtmlHelpController - Display Failed"));
}
void wxRemoteHtmlHelpController::Display(const int id)
{
if( !isconn_1 ) {
if( !DoConnection() ) return;
}
wxString intstring;
intstring.Printf( "--intstring%d", id );
if (!m_connection->Execute( intstring, -1 ) )
wxLogError(wxT("wxRemoteHtmlHelpController - Display Failed"));
}
bool wxRemoteHtmlHelpController::AddBook(const wxString& book, bool show_wait_msg)
{
//ignore show_wait_msg - there shouldn't be a delay in this step
//show_wait_msg = TRUE could be transmitted with ++AddBook
m_book = book;
if( isconn_1 ) {
if (!m_connection->Poke( wxT("--AddBook"), (char*)book.c_str() ) )
wxLogError(wxT("wxRemoteHtmlHelpController - AddBook Failed"));
return FALSE;
}
return TRUE;
}
bool wxRemoteHtmlHelpController::DisplayContents()
{
if( isconn_1 ) {
if (!m_connection->Poke( wxT("--DisplayContents"), wxT("") ) ) {
wxLogError(wxT("wxRemoteHtmlHelpController - DisplayContents Failed"));
return FALSE;
}
}
return TRUE;
}
void wxRemoteHtmlHelpController::DisplayIndex()
{
if( isconn_1 ) {
if (!m_connection->Poke( wxT("--DisplayIndex"), wxT("") ) )
wxLogError(wxT("wxRemoteHtmlHelpController - DisplayIndex Failed"));
}
}
bool wxRemoteHtmlHelpController::KeywordSearch(const wxString& keyword)
{
if( isconn_1 ) {
if (!m_connection->Poke( wxT("--KeywordSearch"), (char*)keyword.c_str() ) ) {
wxLogError(wxT("wxRemoteHtmlHelpController - KeywordSearch Failed"));
return FALSE;
}
}
return TRUE;
}
void wxRemoteHtmlHelpController::SetTitleFormat(const wxString& format)
{
m_windowname = format;
m_windowname.Replace( wxT(" "), wxT("_") );
if( isconn_1 ) {
if (!m_connection->Poke( wxT("--SetTitleFormat"), (char*)format.c_str() ) )
wxLogError(wxT("wxRemoteHtmlHelpController - SetTitleFormat Failed"));
}
}
void wxRemoteHtmlHelpController::SetTempDir(const wxString& path)
{
if( isconn_1 ) {
if (!m_connection->Poke( wxT("--SetTempDir"), (char*)path.c_str() ) )
wxLogError(wxT("wxRemoteHtmlHelpController - SetTempDir Failed"));
}
}

View File

@@ -0,0 +1,97 @@
/////////////////////////////////////////////////////////////////////////////
// Name: remhelp.h
// Purpose: Remote help controller class
// Author: Eric Dowty
// Modified by:
// Created: 2002-11-18
// RCS-ID: $Id$
// Copyright: (c) Julian Smart
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#if defined(__GNUG__) && !defined(__APPLE__)
#pragma interface remhelp.h
#endif
#ifndef _WX_REMHELP_H_
#define _WX_REMHELP_H_
#include <wx/helpbase.h>
#include <wx/ipc.h>
#include <wx/html/helpctrl.h>
class WXDLLEXPORT wxConfigBase;
class rhhcConnection : public wxConnection
{
public:
rhhcConnection(bool *isconn_a);
~rhhcConnection();
bool OnAdvise(const wxString& topic, const wxString& item, char *data, int size, wxIPCFormat format);
bool OnDisconnect();
bool *isconn_3;
};
class rhhcClient: public wxClient
{
public:
rhhcClient(bool *isconn_a);
//~rhhcClient( );
wxConnectionBase *OnMakeConnection();
bool *isconn_2;
};
class wxRemoteHtmlHelpController : public wxHelpControllerBase
{
DECLARE_CLASS(wxRemoteHtmlHelpController)
public:
wxRemoteHtmlHelpController(int style = wxHF_DEFAULT_STYLE);
~wxRemoteHtmlHelpController();
void OnQuit(void);
void SetService(wxString& a_service);
void SetServer(wxString& a_appname); //could be wxHelpController::SetViewer
//standard wxHtmlHelpController functions
bool AddBook(const wxString& book, bool show_wait_msg = FALSE);
void Display(const wxString& x);
void Display(const int id);
bool DisplayContents();
void DisplayIndex();
bool KeywordSearch(const wxString& keyword);
void SetTempDir(const wxString& path);
void SetTitleFormat(const wxString& format);
//dummies - config is in server
void UseConfig(wxConfigBase* config, const wxString& rootpath = wxEmptyString) {};
void ReadCustomization(wxConfigBase* cfg, wxString path = wxEmptyString) {};
void WriteCustomization(wxConfigBase* cfg, wxString path = wxEmptyString) {};
//virtuals from wxHelpControllerBase - not in wxHtmlHelpController
//won't compile without these
bool LoadFile(const class wxString &); //dummy
bool DisplaySection(int);
bool DisplayBlock(long);
bool Quit(void);
private:
void OnExit(wxCommandEvent& event);
bool DoConnection();
rhhcConnection *m_connection;
rhhcClient *m_client;
wxProcess *m_process;
int m_pid;
int m_style;
wxString m_appname;
wxString m_service;
wxString m_windowname;
wxString m_book;
bool isconn_1;
};
#endif
// _WX_REMHELP_H_