]>
git.saurik.com Git - wxWidgets.git/blob - src/generic/helpxlp.cpp
532fc03bcf2633cde92c82127efbefa28b8e2e72
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"
58 IMPLEMENT_CLASS(wxXLPHelpClient
, wxDDEClient
)
59 IMPLEMENT_CLASS(wxXLPHelpConnection
, wxDDEConnection
)
61 IMPLEMENT_CLASS(wxXLPHelpClient
, wxTCPClient
)
62 IMPLEMENT_CLASS(wxXLPHelpConnection
, wxTCPConnection
)
65 IMPLEMENT_CLASS(wxXLPHelpController
, wxHelpControllerBase
)
67 // suppress annoying warning "'this' used in base member init list" (so what?)
69 #pragma warning(disable: 4355)
72 wxXLPHelpController::wxXLPHelpController(void)
75 helpFile
= ""; helpServer
= -1; helpHost
= "";
76 helpRunning
= FALSE
; helpConnection
= NULL
;
80 #pragma warning(default: 4355)
83 wxXLPHelpController::~wxXLPHelpController(void)
87 bool wxXLPHelpController::Initialize(const wxString
& filename
, int server
)
91 if (wxGetHostName(host_buf
, sizeof(host_buf
)))
101 bool wxXLPHelpController::LoadFile(const wxString
& file
)
110 char buf
[_MAX_HELP_LEN
];
111 sprintf(buf
, "f %s", (const char*) file
);
113 return helpConnection
->Execute(buf
);
117 bool wxXLPHelpController::DisplayContents(void)
125 return helpConnection
->Execute("s -1");
130 bool wxXLPHelpController::DisplaySection(int section
)
137 char buf
[_MAX_HELP_LEN
];
138 sprintf(buf
, "s %d", section
);
140 return helpConnection
->Execute(buf
);
144 bool wxXLPHelpController::DisplayBlock(long block
)
151 char buf
[_MAX_HELP_LEN
];
152 sprintf(buf
, "b %ld", block
);
154 return helpConnection
->Execute(buf
);
158 bool wxXLPHelpController::KeywordSearch(const wxString
& k
)
166 sprintf(buf
, "k %s", (const char*) k
);
168 return helpConnection
->Execute(buf
);
172 bool wxXLPHelpController::Quit(void)
175 return helpConnection
->Disconnect(); // Calls OnQuit via OnDisconnect
179 void wxXLPHelpController::OnQuit(void)
183 bool wxXLPHelpController::Run(void)
186 if (!helpFile
|| !helpHost
|| helpRunning
)
190 if (!helpFile
|| helpRunning
)
196 // Invent a server name that's likely to be unique but different from
198 (void)time(¤t_time
);
199 if (helpServer
== -1)
200 helpServer
= (int)(4000 + (current_time
% 4000));
202 // Only one instance of wxHelp at a time
207 sprintf(server
, "%d", helpServer
);
209 // Only one instance of wxHelp under Windows.
210 // See if there's already an instance of wxHelp
211 if ((helpConnection
= (wxXLPHelpConnection
*)helpClient
.MakeConnection(helpHost
, server
, "WXHELP")))
218 // Start help process in server modus
219 // char *argv[] = {"wxhelp", "-server", server, NULL}; // HP compiler complains
226 if (wxExecute((char **)argv
) == FALSE
)
227 return FALSE
; // Maybe we should print a message?
230 (void)time(&start_time
);
231 // Give it some time to respond
234 helpConnection
= (wxXLPHelpConnection
*)helpClient
.MakeConnection(helpHost
, server
, "WXHELP");
235 (void)time(¤t_time
);
236 } while (!helpConnection
&& ((current_time
- start_time
) < WX_HELP_TIMEOUT
));
238 if (helpConnection
== NULL
) {
240 sprintf(buf
, (const char *) _("Connection to wxHelp timed out in %d seconds"), WX_HELP_TIMEOUT
);
241 (void)wxMessageBox(buf
, _("Error"));
248 wxXLPHelpConnection::wxXLPHelpConnection(wxXLPHelpController
*instance
)
250 helpInstance
= instance
;
253 bool wxXLPHelpConnection::OnDisconnect(void)
255 helpInstance
->OnQuit();
256 helpInstance
->helpRunning
= FALSE
;
257 helpInstance
->helpConnection
= NULL
;
258 helpInstance
->helpServer
= -1;