1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Remote help controller class
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #if defined(__GNUG__) && !defined(__APPLE__)
13 #pragma implementation remhelp.h
16 // For compilers that support precompilation, includes "wx.h".
17 #include "wx/wxprec.h"
29 #include "wx/process.h"
30 #include "wx/confbase.h"
32 // Settings common to both executables: determines whether
33 // we're using TCP/IP or real DDE.
35 //#include "ddesetup.h"
36 //#define wxUSE_DDE_FOR_IPC 0
38 #if defined(__WXGTK__) || defined(__WXMOTIF__)
39 #include "mondrian.xpm"
45 #if !defined(USE_REMOTE)
46 #include <wx/html/helpctrl.h>
53 rhhcClient::rhhcClient( bool *isconn_a
)
58 wxConnectionBase
*rhhcClient::OnMakeConnection()
60 return new rhhcConnection( isconn_2
);
63 rhhcConnection::rhhcConnection( bool *isconn_a
)
70 rhhcConnection::~rhhcConnection()
75 bool rhhcConnection::OnAdvise(const wxString
& topic
, const wxString
& item
, char *data
, int size
, wxIPCFormat format
)
80 bool rhhcConnection::OnDisconnect()
84 return wxConnection::OnDisconnect();
87 //////////////////////////////////////////
88 /////////////////////////////////////////
90 // wxRemoteHtmlHelpController class
92 IMPLEMENT_CLASS(wxRemoteHtmlHelpController
, wxHelpControllerBase
)
94 wxRemoteHtmlHelpController::wxRemoteHtmlHelpController(int style
)
105 // server app is assumed to be local
107 // for MSW (DDE classes), a_service is 'service name', apparently an arbitrary string
108 // for Unix, should be a valid file name (for a nonexistent file)
109 // for nonMSW, nonUnix, must be port number, for example "4242" (TCP/IP based classes)
110 // should be unique to the client app
112 wxString thename
= wxGetApp().GetAppName();
113 #if defined(__WXMSW__)
114 m_appname
= wxT("helpview.exe");
115 m_service
= thename
+ wxString(wxT("_helpservice"));
116 #elif defined(__UNIX__)
117 m_appname
= wxT("./helpview");
118 m_service
= wxT("/tmp/") + thename
+ wxString(wxT("_helpservice"));
120 m_appname
= wxT("./helpview");
121 m_service
= wxT("4242");
124 m_book
= thename
+ wxT(".hhp"); // or .htb or .zip
125 m_windowname
= thename
+ wxT(" Help: %s");
126 //underscores for spaces
127 m_windowname
.Replace( wxT(" "), wxT("_") );
130 void wxRemoteHtmlHelpController::SetService(wxString
& a_service
)
132 m_service
= a_service
;
134 void wxRemoteHtmlHelpController::SetServer(wxString
& a_appname
)
136 m_appname
= a_appname
;
139 void wxRemoteHtmlHelpController::OnQuit()
141 //kill the Server here?
142 //this function is not called ?
145 wxRemoteHtmlHelpController::~wxRemoteHtmlHelpController()
149 //if (!m_connection->Poke( wxT("--YouAreDead"), wxT("") ) )
150 // wxLogError(wxT("wxRemoteHtmlHelpController - YouAreDead Failed"));
152 // Kill the server. This could be an option.
155 m_connection
->Disconnect();
162 delete m_client
; //should be automatic?
166 bool wxRemoteHtmlHelpController::DoConnection()
173 // ignored under DDE, host name in TCP/IP based classes
174 wxString hostName
= wxT("localhost");
176 // Create a new client
177 if( !m_client
) m_client
= new rhhcClient(&isconn_1
);
181 // suppress the log messages from MakeConnection()
185 //first try to connect assuming server is running
187 m_connection
= (rhhcConnection
*)m_client
->MakeConnection(hostName
, m_service
, wxT("HELP") );
189 //if not, start server
193 stylestr
.Printf( wxT("--Style%d"), m_style
);
195 cmd
= m_appname
+ blank
+ m_service
+ blank
+ m_windowname
+ blank
+ m_book
+ blank
+ stylestr
;
197 m_process
= new wxProcess(NULL
);
198 m_pid
= wxExecute( cmd
, FALSE
, m_process
);
199 // leaks - wxExecute itself (if not deleted) and in wxExecute at
200 // wxExecuteData *data = new wxExecuteData;
202 wxLogError( wxT("wxRemoteHtmlHelpController - Failed to start Help server") );
209 //try every second for a while, then leave it to user
212 if ( wxMessageBox( wxT("Failed to make connection to Help server.\nRetry?") ,
213 wxT("wxRemoteHtmlHelpController Error"),
214 wxICON_ERROR
| wxYES_NO
| wxCANCEL
) != wxYES
)
222 m_connection
= (rhhcConnection
*)m_client
->MakeConnection(hostName
, m_service
, wxT("HELP") );
226 if (!m_connection
->StartAdvise(wxT("Item"))) {
227 wxLogError(wxT("wxRemoteHtmlHelpController - StartAdvise failed") );
234 bool wxRemoteHtmlHelpController::LoadFile(const wxString
& WXUNUSED(file
))
238 bool wxRemoteHtmlHelpController::DisplaySection(int sectionNo
)
243 bool wxRemoteHtmlHelpController::DisplayBlock(long blockNo
)
245 return DisplaySection((int)blockNo
);
248 bool wxRemoteHtmlHelpController::Quit()
250 //this code from exec sample - branches left in for testing
251 // sig = 3, 6, 9 or 12 all kill server with no apparent problem
252 // but give error message on MSW - timout?
253 int sig
= 15; //3 = quit; 6 = abort; 9 = kill; 15 = terminate
259 wxFAIL_MSG( _T("unexpected return value") );
288 if ( wxProcess::Exists(m_pid
) )
289 wxLogStatus(_T("Process %ld is running."), m_pid
);
291 wxLogStatus(_T("No process with pid = %ld."), m_pid
);
295 wxKillError rc
= wxProcess::Kill(m_pid
, (wxSignal
)sig
);
296 if ( rc
== wxKILL_OK
)
298 wxLogStatus(_T("Process %ld killed with signal %d."), m_pid
, sig
);
302 static const wxChar
*errorText
[] =
305 _T("signal not supported"),
306 _T("permission denied"),
307 _T("no such process"),
308 _T("unspecified error"),
311 // sig = 3, 6, 9 or 12 all kill server with no apparent problem
312 // but give error message on MSW - timout?
314 //wxLogError(_T("Failed to kill process %ld with signal %d: %s"),
315 // m_pid, sig, errorText[rc]);
323 void wxRemoteHtmlHelpController::Display(const wxString
& helpfile
)
326 if( !DoConnection() ) return;
329 if (!m_connection
->Execute( helpfile
, -1 ) )
330 wxLogError(wxT("wxRemoteHtmlHelpController - Display Failed"));
334 void wxRemoteHtmlHelpController::Display(const int id
)
337 if( !DoConnection() ) return;
341 intstring
.Printf( "--intstring%d", id
);
343 if (!m_connection
->Execute( intstring
, -1 ) )
344 wxLogError(wxT("wxRemoteHtmlHelpController - Display Failed"));
348 bool wxRemoteHtmlHelpController::AddBook(const wxString
& book
, bool show_wait_msg
)
350 //ignore show_wait_msg - there shouldn't be a delay in this step
351 //show_wait_msg = TRUE could be transmitted with ++AddBook
355 if (!m_connection
->Poke( wxT("--AddBook"), (char*)book
.c_str() ) )
356 wxLogError(wxT("wxRemoteHtmlHelpController - AddBook Failed"));
363 bool wxRemoteHtmlHelpController::DisplayContents()
366 if (!m_connection
->Poke( wxT("--DisplayContents"), wxT("") ) ) {
367 wxLogError(wxT("wxRemoteHtmlHelpController - DisplayContents Failed"));
373 void wxRemoteHtmlHelpController::DisplayIndex()
376 if (!m_connection
->Poke( wxT("--DisplayIndex"), wxT("") ) )
377 wxLogError(wxT("wxRemoteHtmlHelpController - DisplayIndex Failed"));
380 bool wxRemoteHtmlHelpController::KeywordSearch(const wxString
& keyword
)
383 if (!m_connection
->Poke( wxT("--KeywordSearch"), (char*)keyword
.c_str() ) ) {
384 wxLogError(wxT("wxRemoteHtmlHelpController - KeywordSearch Failed"));
391 void wxRemoteHtmlHelpController::SetTitleFormat(const wxString
& format
)
393 m_windowname
= format
;
394 m_windowname
.Replace( wxT(" "), wxT("_") );
397 if (!m_connection
->Poke( wxT("--SetTitleFormat"), (char*)format
.c_str() ) )
398 wxLogError(wxT("wxRemoteHtmlHelpController - SetTitleFormat Failed"));
402 void wxRemoteHtmlHelpController::SetTempDir(const wxString
& path
)
405 if (!m_connection
->Poke( wxT("--SetTempDir"), (char*)path
.c_str() ) )
406 wxLogError(wxT("wxRemoteHtmlHelpController - SetTempDir Failed"));