]>
git.saurik.com Git - wxWidgets.git/blob - utils/helpview/src/helpview.cpp
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
30 #include "wx/filename.h"
32 #include "wx/wxhtml.h"
33 #include "wx/fs_zip.h"
35 #include "wx/artprov.h"
36 #include "wx/filedlg.h"
40 class AlternateArtProvider
: public wxArtProvider
43 virtual wxBitmap
CreateBitmap(const wxArtID
& id
, const wxArtClient
& client
,
59 delete wxLog::SetActiveTarget(new wxLogStderr
); // So dialog boxes aren't used
62 wxArtProvider::PushProvider(new AlternateArtProvider
);
65 wxApp::s_macAboutMenuItemId
= wxID_ABOUT
;
66 wxFileName::MacRegisterDefaultTypeAndCreator( "htb" , 'HTBD' , 'HTBA' ) ;
69 int istyle
= wxHF_DEFAULT_STYLE
;
71 wxString service
, windowName
, book
[10], titleFormat
, argStr
;
74 bool hasService
= FALSE
;
75 bool hasWindowName
= FALSE
;
76 bool createServer
= FALSE
;
82 // Help books are recognized by extension ".hhp" ".htb" or ".zip".
83 // Service and window_name can occur anywhere in arguments,
84 // but service must be first
85 // Other arguments (topic?) could be added
87 // modes of operation:
88 // 1) no arguments - stand alone, prompt user for book
89 // 2) books only - stand alone, open books
90 // 3) "--server" as (any) arg - start connection with default service;
91 // also open any books passed as other arguments
92 // 4) at least one argument which is not book, and not "--server" - take first
93 // such argument as service, second (if present) as window name,
94 // start service, open any books
96 for( i
=1; i
< argc
; i
++ )
100 if ( argStr
.Find( wxT(".hhp") ) >= 0 ||
101 argStr
.Find( wxT(".htb") ) >= 0 ||
102 argStr
.Find( wxT(".zip") ) >= 0 ) {
103 book
[bookCount
] = argStr
;
106 else if ( argStr
== wxT("--server") )
109 #if defined(__WXMSW__)
110 service
= wxT("generic_helpservice");
111 #elif defined(__UNIX__)
112 service
= wxT("/tmp/") + wxString(wxT("generic_helpservice"));
114 service
= wxT("4242");
117 else if ( !hasService
)
123 else if ( !hasWindowName
)
126 hasWindowName
= TRUE
;
128 else if ( argStr
.Find( wxT("--Style") ) >= 0 )
131 wxString numb
= argStr
.AfterLast(wxT('e'));
132 if ( !(numb
.ToLong(&i
) ) )
134 wxLogError( wxT("Integer conversion failed for --Style") );
143 //unknown - could be topic?
147 // No book - query user; but not on Mac, since there
148 // may be an AppleEvent to open a document on the way
152 wxString s
= wxFileSelector( wxT("Open help file"),
157 "Help books (*.htb)|*.htb|Help books (*.zip)|*.zip|\
158 HTML Help Project (*.hhp)|*.hhp"),
159 wxOPEN
| wxFILE_MUST_EXIST
,
172 if ( createServer
) {
173 // Create a new server
174 m_server
= new hvServer
;
176 if ( !m_server
->Create(service
) ) {
177 wxString wxm
= wxT("Server Create failed - service: ");
178 wxString xxm
= wxm
<< service
;
180 //if MSW quits here, probably another copy already exists
184 createServer
= FALSE
;
190 wxInitAllImageHandlers();
191 wxFileSystem::AddHandler(new wxZipFSHandler
);
193 SetVendorName(wxT("wxWindows") );
194 SetAppName(wxT("wxHTMLHelpServer") );
195 wxConfig::Get(); // create an instance
197 m_helpController
= new wxHtmlHelpController( istyle
);
199 if ( !hasWindowName
)
200 titleFormat
= wxT("Help: %s") ;
204 windowName
.Replace( wxT("_"), wxT(" ") );
205 titleFormat
= windowName
;
208 m_helpController
->SetTitleFormat( titleFormat
);
210 for( i
=0; i
< bookCount
; i
++ )
212 wxFileName
fileName(book
[i
]);
213 m_helpController
->AddBook(fileName
);
217 delete wxLog::SetActiveTarget(new wxLogGui
);
220 m_helpController
-> DisplayContents();
229 wxNode
* node
= m_connections
.First();
232 wxNode
* next
= node
->Next();
233 hvConnection
* connection
= (hvConnection
*) node
->Data();
234 connection
->Disconnect();
238 m_connections
.Clear();
247 delete m_helpController
;
248 delete wxConfig::Set(NULL
);
253 bool hvApp::OpenBook(wxHtmlHelpController
* controller
)
255 wxString s
= wxFileSelector(_("Open help file"),
260 "Help books (*.htb)|*.htb|Help books (*.zip)|*.zip|\
261 HTML Help Project (*.hhp)|*.hhp"),
262 wxOPEN
| wxFILE_MUST_EXIST
,
267 wxString ext
= s
.Right(4).Lower();
268 if (ext
== _T(".zip") || ext
== _T(".htb") || ext
== _T(".hhp"))
271 wxFileName
fileName(s
);
272 controller
->AddBook(fileName
);
280 /// Respond to Apple Event for opening a document
281 void hvApp::MacOpenFile(const wxString
& filename
)
284 wxFileName
fileName(filename
);
285 m_helpController
->AddBook(fileName
);
286 m_helpController
->DisplayContents();
295 // ---------------------------------------------------------------------
297 // ---------------------------------------------------------------------
299 // Standard macro for getting a resource from XPM file:
300 #define ART(artId, xpmRc) \
301 if ( id == artId ) return wxBitmap(xpmRc##_xpm);
303 // Compatibility hack to use wxApp::GetStdIcon of overriden by the user
304 #if WXWIN_COMPATIBILITY_2_2
305 #define GET_STD_ICON_FROM_APP(iconId) \
306 if ( client == wxART_MESSAGE_BOX ) \
308 wxIcon icon = wxTheApp->GetStdIcon(iconId); \
312 bmp.CopyFromIcon(icon); \
317 #define GET_STD_ICON_FROM_APP(iconId)
320 // There are two ways of getting the standard icon: either via XPMs or via
321 // wxIcon ctor. This depends on the platform:
322 #if defined(__WXUNIVERSAL__)
323 #define CREATE_STD_ICON(iconId, xpmRc) return wxNullBitmap;
324 #elif defined(__WXGTK__) || defined(__WXMOTIF__)
325 #define CREATE_STD_ICON(iconId, xpmRc) return wxBitmap(xpmRc##_xpm);
327 #define CREATE_STD_ICON(iconId, xpmRc) \
329 wxIcon icon(_T(iconId)); \
331 bmp.CopyFromIcon(icon); \
336 // Macro used in CreateBitmap to get wxICON_FOO icons:
337 #define ART_MSGBOX(artId, iconId, xpmRc) \
340 GET_STD_ICON_FROM_APP(iconId) \
341 CREATE_STD_ICON(#iconId, xpmRc) \
344 // ---------------------------------------------------------------------
346 // ---------------------------------------------------------------------
348 // XPM hack: make the arrays const
349 //#define static static const
351 #include "bitmaps/helpback.xpm"
352 #include "bitmaps/helpbook.xpm"
353 #include "bitmaps/helpdown.xpm"
354 #include "bitmaps/helpforward.xpm"
355 #include "bitmaps/helpoptions.xpm"
356 #include "bitmaps/helppage.xpm"
357 #include "bitmaps/helpsidepanel.xpm"
358 #include "bitmaps/helpup.xpm"
359 #include "bitmaps/helpuplevel.xpm"
360 #include "bitmaps/helpicon.xpm"
361 #include "bitmaps/helpopen.xpm"
365 // ---------------------------------------------------------------------
366 // CreateBitmap routine
367 // ---------------------------------------------------------------------
369 wxBitmap
AlternateArtProvider::CreateBitmap(const wxArtID
& id
,
370 const wxArtClient
& client
,
371 const wxSize
& WXUNUSED(size
))
373 ART(wxART_HELP_SIDE_PANEL
, helpsidepanel
)
374 ART(wxART_HELP_SETTINGS
, helpoptions
)
375 ART(wxART_HELP_BOOK
, helpbook
)
376 ART(wxART_HELP_FOLDER
, helpbook
)
377 ART(wxART_HELP_PAGE
, helppage
)
378 //ART(wxART_ADD_BOOKMARK, addbookm)
379 //ART(wxART_DEL_BOOKMARK, delbookm)
380 ART(wxART_GO_BACK
, helpback
)
381 ART(wxART_GO_FORWARD
, helpforward
)
382 ART(wxART_GO_UP
, helpup
)
383 ART(wxART_GO_DOWN
, helpdown
)
384 ART(wxART_GO_TO_PARENT
, helpuplevel
)
385 ART(wxART_FILE_OPEN
, helpopen
)
386 if (client
== wxART_HELP_BROWSER
)
388 //ART(wxART_FRAME_ICON, helpicon)
389 ART(wxART_HELP
, helpicon
)
392 //ART(wxART_GO_HOME, home)
394 // Any wxWindows icons not implemented here
395 // will be provided by the default art provider.
401 wxConnectionBase
*hvServer::OnAcceptConnection(const wxString
& topic
)
403 if (topic
== wxT("HELP"))
404 return new hvConnection();
409 // ----------------------------------------------------------------------------
411 // ----------------------------------------------------------------------------
413 hvConnection::hvConnection()
416 wxGetApp().GetConnections().Append(this);
419 hvConnection::~hvConnection()
421 wxGetApp().GetConnections().DeleteObject(this);
424 bool hvConnection::OnExecute(const wxString
& WXUNUSED(topic
),
427 wxIPCFormat
WXUNUSED(format
))
429 // wxLogStatus("Execute command: %s", data);
431 if ( !wxStrncmp( data
, wxT("--intstring"), 11 ) )
434 wxString argStr
= data
;
435 wxString numb
= argStr
.AfterLast(wxT('g'));
436 if ( !(numb
.ToLong(&i
) ) ) {
437 wxLogError( wxT("Integer conversion failed for --intstring") );
440 wxGetApp().GetHelpController()->Display(int(i
));
445 wxGetApp().GetHelpController()->Display(data
);
451 bool hvConnection::OnPoke(const wxString
& WXUNUSED(topic
),
452 const wxString
& item
,
455 wxIPCFormat
WXUNUSED(format
))
457 // wxLogStatus("Poke command: %s = %s", item.c_str(), data);
458 //topic is not tested
460 if ( wxGetApp().GetHelpController() )
462 if ( item
== wxT("--AddBook") )
464 wxGetApp().GetHelpController()->AddBook(data
);
466 else if ( item
== wxT("--DisplayContents") )
468 wxGetApp().GetHelpController()->DisplayContents();
470 else if ( item
== wxT("--DisplayIndex") )
472 wxGetApp().GetHelpController()->DisplayIndex();
474 else if ( item
== wxT("--KeywordSearch") )
476 wxGetApp().GetHelpController()->KeywordSearch(data
);
478 else if ( item
== wxT("--SetTitleFormat") )
480 wxString newname
= data
;
481 newname
.Replace( wxT("_"), wxT(" ") );
482 wxGetApp().GetHelpController()->SetTitleFormat(newname
);
483 //does not redraw title bar?
484 //wxGetApp().GetHelpController()->ReFresh(); - or something
486 else if ( item
== wxT("--SetTempDir") )
488 wxGetApp().GetHelpController()->SetTempDir(data
);
490 else if ( item
== wxT("--YouAreDead") )
492 // don't really know how to kill app from down here...
493 // use wxKill from client instead
494 //wxWindow *win = wxTheApp->GetTopWindow();
503 wxChar
*hvConnection::OnRequest(const wxString
& WXUNUSED(topic
),
504 const wxString
& WXUNUSED(item
),
505 int * WXUNUSED(size
),
506 wxIPCFormat
WXUNUSED(format
))
511 bool hvConnection::OnStartAdvise(const wxString
& WXUNUSED(topic
),
512 const wxString
& WXUNUSED(item
))