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 /////////////////////////////////////////////////////////////////////////////
13 // For compilers that support precompilation, includes "wx/wx.h".
14 #include "wx/wxprec.h"
20 // for all others, include the necessary headers (this file is usually all you
21 // need because it includes almost all "standard" wxWidgets headers
26 #include "wx/filename.h"
28 #include "wx/wxhtml.h"
29 #include "wx/fs_zip.h"
31 #include "wx/artprov.h"
32 #include "wx/filedlg.h"
36 class AlternateArtProvider
: public wxArtProvider
39 virtual wxBitmap
CreateBitmap(const wxArtID
& id
, const wxArtClient
& client
,
55 delete wxLog::SetActiveTarget(new wxLogStderr
); // So dialog boxes aren't used
58 wxArtProvider::Push(new AlternateArtProvider
);
61 wxApp::s_macAboutMenuItemId
= wxID_ABOUT
;
62 wxFileName::MacRegisterDefaultTypeAndCreator( wxT("htb") , 'HTBD' , 'HTBA' ) ;
65 int istyle
= wxHF_DEFAULT_STYLE
;
67 wxString service
, windowName
, titleFormat
, argStr
;
71 bool hasService
= false;
72 bool hasWindowName
= false;
73 bool createServer
= false;
79 // Help books are recognized by extension ".hhp" ".htb" or ".zip".
80 // Service and window_name can occur anywhere in arguments,
81 // but service must be first
82 // Other arguments (topic?) could be added
84 // modes of operation:
85 // 1) no arguments - stand alone, prompt user for book
86 // 2) books only - stand alone, open books
87 // 3) "--server" as (any) arg - start connection with default service;
88 // also open any books passed as other arguments
89 // 4) at least one argument which is not book, and not "--server" - take first
90 // such argument as service, second (if present) as window name,
91 // start service, open any books
93 for( i
=1; i
<argc
; i
++ )
97 if ( argStr
.Find( wxT(".hhp") ) >= 0
98 || argStr
.Find( wxT(".htb") ) >= 0
99 || argStr
.Find( wxT(".zip") ) >= 0 )
101 book
[bookCount
] = argStr
;
104 else if ( argStr
== wxT("--server") )
107 #if defined(__WXMSW__)
108 service
= wxT("generic_helpservice");
109 #elif defined(__UNIX__)
110 service
= wxT("/tmp/") + wxString(wxT("generic_helpservice"));
112 service
= wxT("4242");
115 else if ( !hasService
)
121 else if ( !hasWindowName
)
124 hasWindowName
= true;
126 else if ( argStr
.Find( wxT("--Style") ) >= 0 )
129 wxString numb
= argStr
.AfterLast(wxT('e'));
130 if ( !(numb
.ToLong(&i
) ) )
132 wxLogError( wxT("Integer conversion failed for --Style") );
141 //unknown - could be topic?
145 // No book - query user; but not on Mac, since there
146 // may be an AppleEvent to open a document on the way
150 wxString s
= wxFileSelector( wxT("Open help file"),
154 wxT("Help books (*.htb)|*.htb|Help books (*.zip)|*.zip|HTML Help Project (*.hhp)|*.hhp"),
155 wxFD_OPEN
| wxFD_FILE_MUST_EXIST
,
170 // Create a new server
171 m_server
= new hvServer
;
173 if ( !m_server
->Create(service
) )
175 wxString wxm
= wxT("Server Create failed - service: ");
176 wxString xxm
= wxm
<< service
;
178 //if MSW quits here, probably another copy already exists
181 createServer
= false;
182 wxUnusedVar(createServer
);
188 wxInitAllImageHandlers();
189 wxFileSystem::AddHandler(new wxZipFSHandler
);
191 SetVendorName(wxT("wxWidgets") );
192 SetAppName(wxT("wxHTMLHelpServer") );
193 wxConfig::Get(); // create an instance
195 m_helpController
= new wxHtmlHelpController( istyle
);
197 if ( !hasWindowName
)
199 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();
222 SetTopWindow(m_helpController
->GetFrame());
231 wxObjectList::compatibility_iterator node
= m_connections
.GetFirst();
234 wxObjectList::compatibility_iterator next
= node
->GetNext();
235 hvConnection
* connection
= (hvConnection
*) node
->GetData();
236 connection
->Disconnect();
240 m_connections
.Clear();
249 delete m_helpController
;
250 delete wxConfig::Set(NULL
);
255 bool hvApp::OpenBook(wxHtmlHelpController
* controller
)
257 wxString s
= wxFileSelector(_("Open help file"),
262 "Help books (*.htb)|*.htb|Help books (*.zip)|*.zip|\
263 HTML Help Project (*.hhp)|*.hhp"),
264 wxFD_OPEN
| wxFD_FILE_MUST_EXIST
,
269 wxString ext
= s
.Right(4).Lower();
270 if (ext
== _T(".zip") || ext
== _T(".htb") || ext
== _T(".hhp"))
273 wxFileName
fileName(s
);
274 controller
->AddBook(fileName
);
283 /// Respond to Apple Event for opening a document
284 void hvApp::MacOpenFile(const wxString
& filename
)
287 wxFileName
fileName(filename
);
288 m_helpController
->AddBook(fileName
);
289 m_helpController
->DisplayContents();
298 // ---------------------------------------------------------------------
300 // ---------------------------------------------------------------------
302 // Standard macro for getting a resource from XPM file:
303 #define ART(artId, xpmRc) \
304 if ( id == artId ) return wxBitmap(xpmRc##_xpm);
306 #define GET_STD_ICON_FROM_APP(iconId)
308 // There are two ways of getting the standard icon: either via XPMs or via
309 // wxIcon ctor. This depends on the platform:
310 #if defined(__WXUNIVERSAL__)
311 #define CREATE_STD_ICON(iconId, xpmRc) return wxNullBitmap;
312 #elif defined(__WXGTK__) || defined(__WXMOTIF__)
313 #define CREATE_STD_ICON(iconId, xpmRc) return wxBitmap(xpmRc##_xpm);
315 #define CREATE_STD_ICON(iconId, xpmRc) \
317 wxIcon icon(_T(iconId)); \
319 bmp.CopyFromIcon(icon); \
324 // Macro used in CreateBitmap to get wxICON_FOO icons:
325 #define ART_MSGBOX(artId, iconId, xpmRc) \
328 GET_STD_ICON_FROM_APP(iconId) \
329 CREATE_STD_ICON(#iconId, xpmRc) \
332 // ---------------------------------------------------------------------
334 // ---------------------------------------------------------------------
336 // XPM hack: make the arrays const
337 //#define static static const
339 #include "bitmaps/helpback.xpm"
340 #include "bitmaps/helpbook.xpm"
341 #include "bitmaps/helpdown.xpm"
342 #include "bitmaps/helpforward.xpm"
343 #include "bitmaps/helpoptions.xpm"
344 #include "bitmaps/helppage.xpm"
345 #include "bitmaps/helpsidepanel.xpm"
346 #include "bitmaps/helpup.xpm"
347 #include "bitmaps/helpuplevel.xpm"
348 #include "bitmaps/helpicon.xpm"
349 #include "bitmaps/helpopen.xpm"
353 // ---------------------------------------------------------------------
354 // CreateBitmap routine
355 // ---------------------------------------------------------------------
357 wxBitmap
AlternateArtProvider::CreateBitmap(const wxArtID
& id
,
358 const wxArtClient
& client
,
359 const wxSize
& WXUNUSED(size
))
361 ART(wxART_HELP_SIDE_PANEL
, helpsidepanel
)
362 ART(wxART_HELP_SETTINGS
, helpoptions
)
363 ART(wxART_HELP_BOOK
, helpbook
)
364 ART(wxART_HELP_FOLDER
, helpbook
)
365 ART(wxART_HELP_PAGE
, helppage
)
366 //ART(wxART_ADD_BOOKMARK, addbookm)
367 //ART(wxART_DEL_BOOKMARK, delbookm)
368 ART(wxART_GO_BACK
, helpback
)
369 ART(wxART_GO_FORWARD
, helpforward
)
370 ART(wxART_GO_UP
, helpup
)
371 ART(wxART_GO_DOWN
, helpdown
)
372 ART(wxART_GO_TO_PARENT
, helpuplevel
)
373 ART(wxART_FILE_OPEN
, helpopen
)
374 if (client
== wxART_HELP_BROWSER
)
376 //ART(wxART_FRAME_ICON, helpicon)
377 ART(wxART_HELP
, helpicon
)
380 //ART(wxART_GO_HOME, home)
382 // Any wxWidgets icons not implemented here
383 // will be provided by the default art provider.
389 wxConnectionBase
*hvServer::OnAcceptConnection(const wxString
& topic
)
391 if (topic
== wxT("HELP"))
392 return new hvConnection();
397 // ----------------------------------------------------------------------------
399 // ----------------------------------------------------------------------------
401 hvConnection::hvConnection()
404 wxGetApp().GetConnections().Append(this);
407 hvConnection::~hvConnection()
409 wxGetApp().GetConnections().DeleteObject(this);
412 bool hvConnection::OnExecute(const wxString
& WXUNUSED(topic
),
415 wxIPCFormat
WXUNUSED(format
))
417 // wxLogStatus("Execute command: %s", data);
419 if ( !wxStrncmp( data
, wxT("--intstring"), 11 ) )
422 wxString argStr
= data
;
423 wxString numb
= argStr
.AfterLast(wxT('g'));
424 if ( !(numb
.ToLong(&i
) ) )
426 wxLogError( wxT("Integer conversion failed for --intstring") );
430 wxGetApp().GetHelpController()->Display(int(i
));
435 wxGetApp().GetHelpController()->Display(data
);
441 bool hvConnection::OnPoke(const wxString
& WXUNUSED(topic
),
442 const wxString
& item
,
445 wxIPCFormat
WXUNUSED(format
))
447 // wxLogStatus("Poke command: %s = %s", item.c_str(), data);
448 //topic is not tested
450 if ( wxGetApp().GetHelpController() )
452 if ( item
== wxT("--AddBook") )
454 wxGetApp().GetHelpController()->AddBook(data
);
456 else if ( item
== wxT("--DisplayContents") )
458 wxGetApp().GetHelpController()->DisplayContents();
460 else if ( item
== wxT("--DisplayIndex") )
462 wxGetApp().GetHelpController()->DisplayIndex();
464 else if ( item
== wxT("--KeywordSearch") )
466 wxGetApp().GetHelpController()->KeywordSearch(data
);
468 else if ( item
== wxT("--SetTitleFormat") )
470 wxString newname
= data
;
471 newname
.Replace( wxT("_"), wxT(" ") );
472 wxGetApp().GetHelpController()->SetTitleFormat(newname
);
473 //does not redraw title bar?
474 //wxGetApp().GetHelpController()->ReFresh(); - or something
476 else if ( item
== wxT("--SetTempDir") )
478 wxGetApp().GetHelpController()->SetTempDir(data
);
480 else if ( item
== wxT("--YouAreDead") )
482 // don't really know how to kill app from down here...
483 // use wxKill from client instead
484 //wxWindow *win = wxTheApp->GetTopWindow();
493 wxChar
*hvConnection::OnRequest(const wxString
& WXUNUSED(topic
),
494 const wxString
& WXUNUSED(item
),
495 int * WXUNUSED(size
),
496 wxIPCFormat
WXUNUSED(format
))
501 bool hvConnection::OnStartAdvise(const wxString
& WXUNUSED(topic
),
502 const wxString
& WXUNUSED(item
))
507 #endif // #if wxUSE_IPC