]>
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 // suppress annoying warning "'this' used in base member init list" (so what?)
71 #pragma warning(disable: 4355)
74 wxXLPHelpController::wxXLPHelpController(void)
77 helpFile
= ""; helpServer
= -1; helpHost
= "";
78 helpRunning
= FALSE
; helpConnection
= NULL
;
82 #pragma warning(default: 4355)
85 wxXLPHelpController::~wxXLPHelpController(void)
89 bool wxXLPHelpController::Initialize(const wxString
& filename
, int server
)
93 if (wxGetHostName(host_buf
, sizeof(host_buf
)))
104 bool wxXLPHelpController::LoadFile(const wxString
& file
)
113 char buf
[_MAX_HELP_LEN
];
114 sprintf(buf
, "f %s", (const char*) file
);
116 return helpConnection
->Execute(buf
);
120 bool wxXLPHelpController::DisplayContents(void)
128 return helpConnection
->Execute("s -1");
133 bool wxXLPHelpController::DisplaySection(int section
)
140 char buf
[_MAX_HELP_LEN
];
141 sprintf(buf
, "s %d", section
);
143 return helpConnection
->Execute(buf
);
147 bool wxXLPHelpController::DisplayBlock(long block
)
154 char buf
[_MAX_HELP_LEN
];
155 sprintf(buf
, "b %ld", block
);
157 return helpConnection
->Execute(buf
);
161 bool wxXLPHelpController::KeywordSearch(const wxString
& k
)
169 sprintf(buf
, "k %s", (const char*) k
);
171 return helpConnection
->Execute(buf
);
175 bool wxXLPHelpController::Quit(void)
178 return helpConnection
->Disconnect(); // Calls OnQuit via OnDisconnect
182 void wxXLPHelpController::OnQuit(void)
186 bool wxXLPHelpController::Run(void)
189 if (!helpFile
|| !helpHost
|| helpRunning
)
193 if (!helpFile
|| helpRunning
)
199 // Invent a server name that's likely to be unique but different from
201 (void)time(¤t_time
);
202 if (helpServer
== -1)
203 helpServer
= (int)(4000 + (current_time
% 4000));
205 // Only one instance of wxHelp at a time
210 sprintf(server
, "%d", helpServer
);
212 // Only one instance of wxHelp under Windows.
213 // See if there's already an instance of wxHelp
214 if ((helpConnection
= (wxXLPHelpConnection
*)helpClient
.MakeConnection(helpHost
, server
, "WXHELP")))
221 // Start help process in server modus
222 // char *argv[] = {"wxhelp", "-server", server, NULL}; // HP compiler complains
229 if (wxExecute((char **)argv
) == FALSE
)
230 return FALSE
; // Maybe we should print a message?
233 (void)time(&start_time
);
234 // Give it some time to respond
237 helpConnection
= (wxXLPHelpConnection
*)helpClient
.MakeConnection(helpHost
, server
, "WXHELP");
238 (void)time(¤t_time
);
239 } while (!helpConnection
&& ((current_time
- start_time
) < WX_HELP_TIMEOUT
));
241 if (helpConnection
== NULL
) {
243 sprintf(buf
, (const char *) _("Connection to wxHelp timed out in %d seconds"), WX_HELP_TIMEOUT
);
244 (void)wxMessageBox(buf
, _("Error"));
251 wxXLPHelpConnection::wxXLPHelpConnection(wxXLPHelpController
*instance
)
253 helpInstance
= instance
;
256 bool wxXLPHelpConnection::OnDisconnect(void)
258 helpInstance
->OnQuit();
259 helpInstance
->helpRunning
= FALSE
;
260 helpInstance
->helpConnection
= NULL
;
261 helpInstance
->helpServer
= -1;