]>
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
)))
103 bool wxXLPHelpController::LoadFile(const wxString
& file
)
112 char buf
[_MAX_HELP_LEN
];
113 sprintf(buf
, "f %s", (const char*) file
);
115 return helpConnection
->Execute(buf
);
119 bool wxXLPHelpController::DisplayContents(void)
127 return helpConnection
->Execute("s -1");
132 bool wxXLPHelpController::DisplaySection(int section
)
139 char buf
[_MAX_HELP_LEN
];
140 sprintf(buf
, "s %d", section
);
142 return helpConnection
->Execute(buf
);
146 bool wxXLPHelpController::DisplayBlock(long block
)
153 char buf
[_MAX_HELP_LEN
];
154 sprintf(buf
, "b %ld", block
);
156 return helpConnection
->Execute(buf
);
160 bool wxXLPHelpController::KeywordSearch(const wxString
& k
)
168 sprintf(buf
, "k %s", (const char*) k
);
170 return helpConnection
->Execute(buf
);
174 bool wxXLPHelpController::Quit(void)
177 return helpConnection
->Disconnect(); // Calls OnQuit via OnDisconnect
181 void wxXLPHelpController::OnQuit(void)
185 bool wxXLPHelpController::Run(void)
188 if (!helpFile
|| !helpHost
|| helpRunning
)
192 if (!helpFile
|| helpRunning
)
198 // Invent a server name that's likely to be unique but different from
200 (void)time(¤t_time
);
201 if (helpServer
== -1)
202 helpServer
= (int)(4000 + (current_time
% 4000));
204 // Only one instance of wxHelp at a time
209 sprintf(server
, "%d", helpServer
);
211 // Only one instance of wxHelp under Windows.
212 // See if there's already an instance of wxHelp
213 if ((helpConnection
= (wxXLPHelpConnection
*)helpClient
.MakeConnection(helpHost
, server
, "WXHELP")))
220 // Start help process in server modus
221 // char *argv[] = {"wxhelp", "-server", server, NULL}; // HP compiler complains
228 if (wxExecute((char **)argv
) == FALSE
)
229 return FALSE
; // Maybe we should print a message?
232 (void)time(&start_time
);
233 // Give it some time to respond
236 helpConnection
= (wxXLPHelpConnection
*)helpClient
.MakeConnection(helpHost
, server
, "WXHELP");
237 (void)time(¤t_time
);
238 } while (!helpConnection
&& ((current_time
- start_time
) < WX_HELP_TIMEOUT
));
240 if (helpConnection
== NULL
) {
242 sprintf(buf
, (const char *) _("Connection to wxHelp timed out in %d seconds"), WX_HELP_TIMEOUT
);
243 (void)wxMessageBox(buf
, _("Error"));
250 wxXLPHelpConnection::wxXLPHelpConnection(wxXLPHelpController
*instance
)
252 helpInstance
= instance
;
255 bool wxXLPHelpConnection::OnDisconnect(void)
257 helpInstance
->OnQuit();
258 helpInstance
->helpRunning
= FALSE
;
259 helpInstance
->helpConnection
= NULL
;
260 helpInstance
->helpServer
= -1;