]>
git.saurik.com Git - wxWidgets.git/blob - src/generic/helpxlp.cpp
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Help system: wxHelp implementation
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart and Markus Holzem
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "helpxlp.h"
16 // For compilers that support precompilation, includes "wx.h".
17 #include "wx/wxprec.h"
27 #include "wx/generic/helpxlp.h"
39 #include <sys/unistd.h>
46 #define WX_HELP_TIMEOUT 15 /* was 30 */
49 #define _MAXPATHLEN 500
51 // MAX length of Help descriptor
52 #define _MAX_HELP_LEN 500
54 #include "wx/generic/helpxlp.h"
56 #if !USE_SHARED_LIBRARY
59 IMPLEMENT_CLASS(wxXLPHelpClient
, wxDDEClient
)
60 IMPLEMENT_CLASS(wxXLPHelpConnection
, wxDDEConnection
)
62 IMPLEMENT_CLASS(wxXLPHelpClient
, wxTCPClient
)
63 IMPLEMENT_CLASS(wxXLPHelpConnection
, wxTCPConnection
)
66 IMPLEMENT_CLASS(wxXLPHelpController
, wxHelpControllerBase
)
69 wxXLPHelpController::wxXLPHelpController(void):
72 helpFile
= ""; helpServer
= -1; helpHost
= "";
73 helpRunning
= FALSE
; helpConnection
= NULL
;
76 wxXLPHelpController::~wxXLPHelpController(void)
80 bool wxXLPHelpController::Initialize(const wxString
& filename
, int server
)
84 if (wxGetHostName(host_buf
, sizeof(host_buf
)))
95 bool wxXLPHelpController::LoadFile(const wxString
& file
)
104 char buf
[_MAX_HELP_LEN
];
105 sprintf(buf
, "f %s", (const char*) file
);
107 return helpConnection
->Execute(buf
);
111 bool wxXLPHelpController::DisplayContents(void)
119 return helpConnection
->Execute("s -1");
124 bool wxXLPHelpController::DisplaySection(int section
)
131 char buf
[_MAX_HELP_LEN
];
132 sprintf(buf
, "s %d", section
);
134 return helpConnection
->Execute(buf
);
138 bool wxXLPHelpController::DisplayBlock(long block
)
145 char buf
[_MAX_HELP_LEN
];
146 sprintf(buf
, "b %ld", block
);
148 return helpConnection
->Execute(buf
);
152 bool wxXLPHelpController::KeywordSearch(const wxString
& k
)
160 sprintf(buf
, "k %s", (const char*) k
);
162 return helpConnection
->Execute(buf
);
166 bool wxXLPHelpController::Quit(void)
169 return helpConnection
->Disconnect(); // Calls OnQuit via OnDisconnect
173 void wxXLPHelpController::OnQuit(void)
177 bool wxXLPHelpController::Run(void)
180 if (!helpFile
|| !helpHost
|| helpRunning
)
184 if (!helpFile
|| helpRunning
)
190 // Invent a server name that's likely to be unique but different from
192 (void)time(¤t_time
);
193 if (helpServer
== -1)
194 helpServer
= (int)(4000 + (current_time
% 4000));
196 // Only one instance of wxHelp at a time
201 sprintf(server
, "%d", helpServer
);
203 // Only one instance of wxHelp under Windows.
204 // See if there's already an instance of wxHelp
205 if ((helpConnection
= (wxXLPHelpConnection
*)helpClient
.MakeConnection(helpHost
, server
, "WXHELP")))
212 // Start help process in server modus
213 // char *argv[] = {"wxhelp", "-server", server, NULL}; // HP compiler complains
220 if (wxExecute((char **)argv
) == FALSE
)
221 return FALSE
; // Maybe we should print a message?
224 (void)time(&start_time
);
225 // Give it some time to respond
228 helpConnection
= (wxXLPHelpConnection
*)helpClient
.MakeConnection(helpHost
, server
, "WXHELP");
229 (void)time(¤t_time
);
230 } while (!helpConnection
&& ((current_time
- start_time
) < WX_HELP_TIMEOUT
));
232 if (helpConnection
== NULL
) {
234 sprintf(buf
, (const char *) _("Connection to wxHelp timed out in %d seconds"), WX_HELP_TIMEOUT
);
235 (void)wxMessageBox(buf
, _("Error"));
242 wxXLPHelpConnection::wxXLPHelpConnection(wxXLPHelpController
*instance
)
244 helpInstance
= instance
;
247 bool wxXLPHelpConnection::OnDisconnect(void)
249 helpInstance
->OnQuit();
250 helpInstance
->helpRunning
= FALSE
;
251 helpInstance
->helpConnection
= NULL
;
252 helpInstance
->helpServer
= -1;