1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: HelpView application
4 // A standalone viewer for wxHTML Help (.htb) files
5 // Author: Vaclav Slavik, Julian Smart
8 // Copyright: (c) 2002 Vaclav Slavik, Julian Smart and others
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // For compilers that support precompilation, includes "wx/wx.h".
13 #include "wx/wxprec.h"
19 // for all others, include the necessary headers (this file is usually all you
20 // need because it includes almost all "standard" wxWidgets headers
25 #include "wx/filename.h"
27 #include "wx/wxhtml.h"
28 #include "wx/fs_zip.h"
30 #include "wx/artprov.h"
31 #include "wx/filedlg.h"
35 class AlternateArtProvider
: public wxArtProvider
38 virtual wxBitmap
CreateBitmap(const wxArtID
& id
, const wxArtClient
& client
,
54 delete wxLog::SetActiveTarget(new wxLogStderr
); // So dialog boxes aren't used
57 wxArtProvider::Push(new AlternateArtProvider
);
59 #if defined( __WXOSX_MAC__ ) && wxOSX_USE_CARBON
60 wxApp::s_macAboutMenuItemId
= wxID_ABOUT
;
61 wxFileName::MacRegisterDefaultTypeAndCreator( wxT("htb") , 'HTBD' , 'HTBA' ) ;
64 int istyle
= wxHF_DEFAULT_STYLE
;
66 wxString service
, windowName
, titleFormat
, argStr
;
70 bool hasService
= false;
71 bool hasWindowName
= false;
72 bool createServer
= false;
78 // Help books are recognized by extension ".hhp" ".htb" or ".zip".
79 // Service and window_name can occur anywhere in arguments,
80 // but service must be first
81 // Other arguments (topic?) could be added
83 // modes of operation:
84 // 1) no arguments - stand alone, prompt user for book
85 // 2) books only - stand alone, open books
86 // 3) "--server" as (any) arg - start connection with default service;
87 // also open any books passed as other arguments
88 // 4) at least one argument which is not book, and not "--server" - take first
89 // such argument as service, second (if present) as window name,
90 // start service, open any books
92 for( i
=1; i
<argc
; i
++ )
96 if ( argStr
.Find( wxT(".hhp") ) >= 0
97 || argStr
.Find( wxT(".htb") ) >= 0
98 || argStr
.Find( wxT(".zip") ) >= 0 )
100 book
[bookCount
] = argStr
;
103 else if ( argStr
== wxT("--server") )
106 #if defined(__WXMSW__)
107 service
= wxT("generic_helpservice");
108 #elif defined(__UNIX__)
109 service
= wxT("/tmp/") + wxString(wxT("generic_helpservice"));
111 service
= wxT("4242");
114 else if ( !hasService
)
120 else if ( !hasWindowName
)
123 hasWindowName
= true;
125 else if ( argStr
.Find( wxT("--Style") ) >= 0 )
128 wxString numb
= argStr
.AfterLast(wxT('e'));
129 if ( !(numb
.ToLong(&i
) ) )
131 wxLogError( wxT("Integer conversion failed for --Style") );
140 //unknown - could be topic?
144 // No book - query user; but not on Mac, since there
145 // may be an AppleEvent to open a document on the way
149 wxString s
= wxFileSelector( wxT("Open help file"),
153 wxT("Help books (*.htb)|*.htb|Help books (*.zip)|*.zip|HTML Help Project (*.hhp)|*.hhp"),
154 wxFD_OPEN
| wxFD_FILE_MUST_EXIST
,
169 // Create a new server
170 m_server
= new hvServer
;
172 if ( !m_server
->Create(service
) )
174 wxString wxm
= wxT("Server Create failed - service: ");
175 wxString xxm
= wxm
<< service
;
177 //if MSW quits here, probably another copy already exists
180 createServer
= false;
181 wxUnusedVar(createServer
);
187 wxInitAllImageHandlers();
188 wxFileSystem::AddHandler(new wxZipFSHandler
);
190 SetVendorName(wxT("wxWidgets") );
191 SetAppName(wxT("wxHTMLHelpServer") );
192 wxConfig::Get(); // create an instance
194 m_helpController
= new wxHtmlHelpController( istyle
);
196 if ( !hasWindowName
)
198 titleFormat
= wxT("Help: %s") ;
203 windowName
.Replace( wxT("_"), wxT(" ") );
204 titleFormat
= windowName
;
207 m_helpController
->SetTitleFormat( titleFormat
);
209 for( i
=0; i
<bookCount
; i
++ )
211 wxFileName
fileName(book
[i
]);
212 m_helpController
->AddBook(fileName
);
216 delete wxLog::SetActiveTarget(new wxLogGui
);
219 m_helpController
->DisplayContents();
228 wxObjectList::compatibility_iterator node
= m_connections
.GetFirst();
231 wxObjectList::compatibility_iterator next
= node
->GetNext();
232 hvConnection
* connection
= (hvConnection
*) node
->GetData();
233 connection
->Disconnect();
237 m_connections
.Clear();
246 delete m_helpController
;
247 delete wxConfig::Set(NULL
);
252 bool hvApp::OpenBook(wxHtmlHelpController
* controller
)
254 wxString s
= wxFileSelector(_("Open help file"),
259 "Help books (*.htb)|*.htb|Help books (*.zip)|*.zip|\
260 HTML Help Project (*.hhp)|*.hhp"),
261 wxFD_OPEN
| wxFD_FILE_MUST_EXIST
,
266 wxString ext
= s
.Right(4).Lower();
267 if (ext
== wxT(".zip") || ext
== wxT(".htb") || ext
== wxT(".hhp"))
270 wxFileName
fileName(s
);
271 controller
->AddBook(fileName
);
280 /// Respond to Apple Event for opening a document
281 void hvApp::MacOpenFiles(const wxArrayString
& fileNames
)
284 wxFileName
fileName(fileNames
[0]);
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 #define GET_STD_ICON_FROM_APP(iconId)
305 // There are two ways of getting the standard icon: either via XPMs or via
306 // wxIcon ctor. This depends on the platform:
307 #if defined(__WXUNIVERSAL__)
308 #define CREATE_STD_ICON(iconId, xpmRc) return wxNullBitmap;
309 #elif defined(__WXGTK__) || defined(__WXMOTIF__)
310 #define CREATE_STD_ICON(iconId, xpmRc) return wxBitmap(xpmRc##_xpm);
312 #define CREATE_STD_ICON(iconId, xpmRc) \
314 wxIcon icon(wxT(iconId)); \
316 bmp.CopyFromIcon(icon); \
321 // Macro used in CreateBitmap to get wxICON_FOO icons:
322 #define ART_MSGBOX(artId, iconId, xpmRc) \
325 GET_STD_ICON_FROM_APP(iconId) \
326 CREATE_STD_ICON(#iconId, xpmRc) \
329 // ---------------------------------------------------------------------
331 // ---------------------------------------------------------------------
333 // XPM hack: make the arrays const
334 //#define static static const
336 #include "bitmaps/helpback.xpm"
337 #include "bitmaps/helpbook.xpm"
338 #include "bitmaps/helpdown.xpm"
339 #include "bitmaps/helpforward.xpm"
340 #include "bitmaps/helpoptions.xpm"
341 #include "bitmaps/helppage.xpm"
342 #include "bitmaps/helpsidepanel.xpm"
343 #include "bitmaps/helpup.xpm"
344 #include "bitmaps/helpuplevel.xpm"
345 #include "bitmaps/helpicon.xpm"
346 #include "bitmaps/helpopen.xpm"
350 // ---------------------------------------------------------------------
351 // CreateBitmap routine
352 // ---------------------------------------------------------------------
354 wxBitmap
AlternateArtProvider::CreateBitmap(const wxArtID
& id
,
355 const wxArtClient
& client
,
356 const wxSize
& WXUNUSED(size
))
358 ART(wxART_HELP_SIDE_PANEL
, helpsidepanel
)
359 ART(wxART_HELP_SETTINGS
, helpoptions
)
360 ART(wxART_HELP_BOOK
, helpbook
)
361 ART(wxART_HELP_FOLDER
, helpbook
)
362 ART(wxART_HELP_PAGE
, helppage
)
363 //ART(wxART_ADD_BOOKMARK, addbookm)
364 //ART(wxART_DEL_BOOKMARK, delbookm)
365 ART(wxART_GO_BACK
, helpback
)
366 ART(wxART_GO_FORWARD
, helpforward
)
367 ART(wxART_GO_UP
, helpup
)
368 ART(wxART_GO_DOWN
, helpdown
)
369 ART(wxART_GO_TO_PARENT
, helpuplevel
)
370 ART(wxART_FILE_OPEN
, helpopen
)
371 if (client
== wxART_HELP_BROWSER
)
373 //ART(wxART_FRAME_ICON, helpicon)
374 ART(wxART_HELP
, helpicon
)
377 //ART(wxART_GO_HOME, home)
379 // Any wxWidgets icons not implemented here
380 // will be provided by the default art provider.
386 wxConnectionBase
*hvServer::OnAcceptConnection(const wxString
& topic
)
388 if (topic
== wxT("HELP"))
389 return new hvConnection();
394 // ----------------------------------------------------------------------------
396 // ----------------------------------------------------------------------------
398 hvConnection::hvConnection()
401 wxGetApp().GetConnections().Append(this);
404 hvConnection::~hvConnection()
406 wxGetApp().GetConnections().DeleteObject(this);
409 bool hvConnection::OnExec(const wxString
& WXUNUSED(topic
),
410 const wxString
& data
)
412 // wxLogStatus("Execute command: %s", data);
414 if ( data
== "--intstring" )
417 wxString argStr
= data
;
418 wxString numb
= argStr
.AfterLast(wxT('g'));
419 if ( !(numb
.ToLong(&i
) ) )
421 wxLogError( wxT("Integer conversion failed for --intstring") );
425 wxGetApp().GetHelpController()->Display(int(i
));
430 wxGetApp().GetHelpController()->Display(data
);
436 bool hvConnection::OnPoke(const wxString
& WXUNUSED(topic
),
437 const wxString
& item
,
442 const wxString data
= GetTextFromData(buf
, size
, format
);
444 // wxLogStatus("Poke command: %s = %s", item.c_str(), data);
445 //topic is not tested
447 if ( wxGetApp().GetHelpController() )
449 if ( item
== wxT("--AddBook") )
451 wxGetApp().GetHelpController()->AddBook(data
);
453 else if ( item
== wxT("--DisplayContents") )
455 wxGetApp().GetHelpController()->DisplayContents();
457 else if ( item
== wxT("--DisplayIndex") )
459 wxGetApp().GetHelpController()->DisplayIndex();
461 else if ( item
== wxT("--KeywordSearch") )
463 wxGetApp().GetHelpController()->KeywordSearch(data
);
465 else if ( item
== wxT("--SetTitleFormat") )
467 wxString newname
= data
;
468 newname
.Replace( wxT("_"), wxT(" ") );
469 wxGetApp().GetHelpController()->SetTitleFormat(newname
);
470 //does not redraw title bar?
471 //wxGetApp().GetHelpController()->ReFresh(); - or something
473 else if ( item
== wxT("--SetTempDir") )
475 wxGetApp().GetHelpController()->SetTempDir(data
);
477 else if ( item
== wxT("--YouAreDead") )
479 // don't really know how to kill app from down here...
480 // use wxKill from client instead
481 //wxWindow *win = wxTheApp->GetTopWindow();
490 #endif // #if wxUSE_IPC