]>
git.saurik.com Git - wxWidgets.git/blob - utils/helpview/src/helpview.cpp
40202308466f47c0e67439c3cc062790dd1b5108
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: HelpView application
4 // A standalone viewer for wxHTML Help (.htb) files
5 // Author: Vaclav Slavik, Julian Smart
9 // Copyright: (c) 2002 Vaclav Slavik, Julian Smart and others
10 // Licence: wxWindows licence
11 /////////////////////////////////////////////////////////////////////////////
14 #pragma implementation "help.cpp"
17 // For compilers that support precompilation, includes "wx/wx.h".
18 #include "wx/wxprec.h"
24 // for all others, include the necessary headers (this file is usually all you
25 // need because it includes almost all "standard" wxWindows headers
31 #include "wx/wxhtml.h"
32 #include "wx/fs_zip.h"
34 #include "wx/artprov.h"
35 #include "wx/filedlg.h"
39 class AlternateArtProvider
: public wxArtProvider
42 virtual wxBitmap
CreateBitmap(const wxArtID
& id
, const wxArtClient
& client
,
58 delete wxLog::SetActiveTarget(new wxLogStderr
); // So dialog boxes aren't used
61 wxArtProvider::PushProvider(new AlternateArtProvider
);
63 int istyle
= wxHF_DEFAULT_STYLE
;
65 wxString service
, windowName
, book
[10], titleFormat
, argStr
;
68 bool hasService
= FALSE
;
69 bool hasWindowName
= FALSE
;
70 bool createServer
= FALSE
;
76 // Help books are recognized by extension ".hhp" ".htb" or ".zip".
77 // Service and window_name can occur anywhere in arguments,
78 // but service must be first
79 // Other arguments (topic?) could be added
81 // modes of operation:
82 // 1) no arguments - stand alone, prompt user for book
83 // 2) books only - stand alone, open books
84 // 3) "--server" as (any) arg - start connection with default service;
85 // also open any books passed as other arguments
86 // 4) at least one argument which is not book, and not "--server" - take first
87 // such argument as service, second (if present) as window name,
88 // start service, open any books
90 for( i
=1; i
< argc
; i
++ )
94 if ( argStr
.Find( wxT(".hhp") ) >= 0 ||
95 argStr
.Find( wxT(".htb") ) >= 0 ||
96 argStr
.Find( wxT(".zip") ) >= 0 ) {
97 book
[bookCount
] = argStr
;
100 else if ( argStr
== wxT("--server") )
103 #if defined(__WXMSW__)
104 service
= wxT("generic_helpservice");
105 #elif defined(__UNIX__)
106 service
= wxT("/tmp/") + wxString(wxT("generic_helpservice"));
108 service
= wxT("4242");
111 else if ( !hasService
)
117 else if ( !hasWindowName
)
120 hasWindowName
= TRUE
;
122 else if ( argStr
.Find( wxT("--Style") ) >= 0 )
125 wxString numb
= argStr
.AfterLast(wxT('e'));
126 if ( !(numb
.ToLong(&i
) ) )
128 wxLogError( wxT("Integer conversion failed for --Style") );
137 //unknown - could be topic?
141 //no book - query user
144 wxString s
= wxFileSelector( wxT("Open help file"),
149 "Help books (*.htb)|*.htb|Help books (*.zip)|*.zip|\
150 HTML Help Project (*.hhp)|*.hhp"),
151 wxOPEN
| wxFILE_MUST_EXIST
,
163 if ( createServer
) {
164 // Create a new server
165 m_server
= new hvServer
;
167 if ( !m_server
->Create(service
) ) {
168 wxString wxm
= wxT("Server Create failed - service: ");
169 wxString xxm
= wxm
<< service
;
171 //if MSW quits here, probably another copy already exists
175 createServer
= FALSE
;
181 wxInitAllImageHandlers();
182 wxFileSystem::AddHandler(new wxZipFSHandler
);
184 SetVendorName(wxT("wxWindows") );
185 SetAppName(wxT("wxHTMLHelpServer") );
186 wxConfig::Get(); // create an instance
188 m_helpController
= new wxHtmlHelpController( istyle
);
190 if ( !hasWindowName
)
191 titleFormat
= wxT("Help: %s") ;
195 windowName
.Replace( wxT("_"), wxT(" ") );
196 titleFormat
= windowName
;
199 m_helpController
->SetTitleFormat( titleFormat
);
201 for( i
=0; i
< bookCount
; i
++ )
203 wxFileName
fileName(book
[i
]);
204 m_helpController
->AddBook(fileName
);
208 delete wxLog::SetActiveTarget(new wxLogGui
);
211 m_helpController
-> DisplayContents();
220 wxNode
* node
= m_connections
.First();
223 wxNode
* next
= node
->Next();
224 hvConnection
* connection
= (hvConnection
*) node
->Data();
225 connection
->Disconnect();
229 m_connections
.Clear();
238 delete m_helpController
;
239 delete wxConfig::Set(NULL
);
244 bool hvApp::OpenBook(wxHtmlHelpController
* controller
)
246 wxString s
= wxFileSelector(_("Open help file"),
251 "Help books (*.htb)|*.htb|Help books (*.zip)|*.zip|\
252 HTML Help Project (*.hhp)|*.hhp"),
253 wxOPEN
| wxFILE_MUST_EXIST
,
258 wxString ext
= s
.Right(4).Lower();
259 if (ext
== _T(".zip") || ext
== _T(".htb") || ext
== _T(".hhp"))
262 wxFileName
fileName(s
);
263 controller
->AddBook(fileName
);
274 // ---------------------------------------------------------------------
276 // ---------------------------------------------------------------------
278 // Standard macro for getting a resource from XPM file:
279 #define ART(artId, xpmRc) \
280 if ( id == artId ) return wxBitmap(xpmRc##_xpm);
282 // Compatibility hack to use wxApp::GetStdIcon of overriden by the user
283 #if WXWIN_COMPATIBILITY_2_2
284 #define GET_STD_ICON_FROM_APP(iconId) \
285 if ( client == wxART_MESSAGE_BOX ) \
287 wxIcon icon = wxTheApp->GetStdIcon(iconId); \
291 bmp.CopyFromIcon(icon); \
296 #define GET_STD_ICON_FROM_APP(iconId)
299 // There are two ways of getting the standard icon: either via XPMs or via
300 // wxIcon ctor. This depends on the platform:
301 #if defined(__WXUNIVERSAL__)
302 #define CREATE_STD_ICON(iconId, xpmRc) return wxNullBitmap;
303 #elif defined(__WXGTK__) || defined(__WXMOTIF__)
304 #define CREATE_STD_ICON(iconId, xpmRc) return wxBitmap(xpmRc##_xpm);
306 #define CREATE_STD_ICON(iconId, xpmRc) \
308 wxIcon icon(_T(iconId)); \
310 bmp.CopyFromIcon(icon); \
315 // Macro used in CreateBitmap to get wxICON_FOO icons:
316 #define ART_MSGBOX(artId, iconId, xpmRc) \
319 GET_STD_ICON_FROM_APP(iconId) \
320 CREATE_STD_ICON(#iconId, xpmRc) \
323 // ---------------------------------------------------------------------
325 // ---------------------------------------------------------------------
327 // XPM hack: make the arrays const
328 //#define static static const
330 #include "bitmaps/helpback.xpm"
331 #include "bitmaps/helpbook.xpm"
332 #include "bitmaps/helpdown.xpm"
333 #include "bitmaps/helpforward.xpm"
334 #include "bitmaps/helpoptions.xpm"
335 #include "bitmaps/helppage.xpm"
336 #include "bitmaps/helpsidepanel.xpm"
337 #include "bitmaps/helpup.xpm"
338 #include "bitmaps/helpuplevel.xpm"
339 #include "bitmaps/helpicon.xpm"
340 #include "bitmaps/helpopen.xpm"
344 // ---------------------------------------------------------------------
345 // CreateBitmap routine
346 // ---------------------------------------------------------------------
348 wxBitmap
AlternateArtProvider::CreateBitmap(const wxArtID
& id
,
349 const wxArtClient
& client
,
350 const wxSize
& WXUNUSED(size
))
352 ART(wxART_HELP_SIDE_PANEL
, helpsidepanel
)
353 ART(wxART_HELP_SETTINGS
, helpoptions
)
354 ART(wxART_HELP_BOOK
, helpbook
)
355 ART(wxART_HELP_FOLDER
, helpbook
)
356 ART(wxART_HELP_PAGE
, helppage
)
357 //ART(wxART_ADD_BOOKMARK, addbookm)
358 //ART(wxART_DEL_BOOKMARK, delbookm)
359 ART(wxART_GO_BACK
, helpback
)
360 ART(wxART_GO_FORWARD
, helpforward
)
361 ART(wxART_GO_UP
, helpup
)
362 ART(wxART_GO_DOWN
, helpdown
)
363 ART(wxART_GO_TO_PARENT
, helpuplevel
)
364 ART(wxART_FILE_OPEN
, helpopen
)
365 if (client
== wxART_HELP_BROWSER
)
367 //ART(wxART_FRAME_ICON, helpicon)
368 ART(wxART_HELP
, helpicon
)
371 //ART(wxART_GO_HOME, home)
373 // Any wxWindows icons not implemented here
374 // will be provided by the default art provider.
380 wxConnectionBase
*hvServer::OnAcceptConnection(const wxString
& topic
)
382 if (topic
== wxT("HELP"))
383 return new hvConnection();
388 // ----------------------------------------------------------------------------
390 // ----------------------------------------------------------------------------
392 hvConnection::hvConnection()
395 wxGetApp().GetConnections().Append(this);
398 hvConnection::~hvConnection()
400 wxGetApp().GetConnections().DeleteObject(this);
403 bool hvConnection::OnExecute(const wxString
& WXUNUSED(topic
),
406 wxIPCFormat
WXUNUSED(format
))
408 // wxLogStatus("Execute command: %s", data);
410 if ( !wxStrncmp( data
, wxT("--intstring"), 11 ) )
413 wxString argStr
= data
;
414 wxString numb
= argStr
.AfterLast(wxT('g'));
415 if ( !(numb
.ToLong(&i
) ) ) {
416 wxLogError( wxT("Integer conversion failed for --intstring") );
419 wxGetApp().GetHelpController()->Display(int(i
));
424 wxGetApp().GetHelpController()->Display(data
);
430 bool hvConnection::OnPoke(const wxString
& WXUNUSED(topic
),
431 const wxString
& item
,
434 wxIPCFormat
WXUNUSED(format
))
436 // wxLogStatus("Poke command: %s = %s", item.c_str(), data);
437 //topic is not tested
439 if ( wxGetApp().GetHelpController() )
441 if ( item
== wxT("--AddBook") )
443 wxGetApp().GetHelpController()->AddBook(data
);
445 else if ( item
== wxT("--DisplayContents") )
447 wxGetApp().GetHelpController()->DisplayContents();
449 else if ( item
== wxT("--DisplayIndex") )
451 wxGetApp().GetHelpController()->DisplayIndex();
453 else if ( item
== wxT("--KeywordSearch") )
455 wxGetApp().GetHelpController()->KeywordSearch(data
);
457 else if ( item
== wxT("--SetTitleFormat") )
459 wxString newname
= data
;
460 newname
.Replace( wxT("_"), wxT(" ") );
461 wxGetApp().GetHelpController()->SetTitleFormat(newname
);
462 //does not redraw title bar?
463 //wxGetApp().GetHelpController()->ReFresh(); - or something
465 else if ( item
== wxT("--SetTempDir") )
467 wxGetApp().GetHelpController()->SetTempDir(data
);
469 else if ( item
== wxT("--YouAreDead") )
471 // don't really know how to kill app from down here...
472 // use wxKill from client instead
473 //wxWindow *win = wxTheApp->GetTopWindow();
482 wxChar
*hvConnection::OnRequest(const wxString
& WXUNUSED(topic
),
483 const wxString
& WXUNUSED(item
),
484 int * WXUNUSED(size
),
485 wxIPCFormat
WXUNUSED(format
))
490 bool hvConnection::OnStartAdvise(const wxString
& WXUNUSED(topic
),
491 const wxString
& WXUNUSED(item
))