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::PushProvider(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();
229 wxObjectList::compatibility_iterator node
= m_connections
.GetFirst();
232 wxObjectList::compatibility_iterator next
= node
->GetNext();
233 hvConnection
* connection
= (hvConnection
*) node
->GetData();
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
);
281 /// Respond to Apple Event for opening a document
282 void hvApp::MacOpenFile(const wxString
& filename
)
285 wxFileName
fileName(filename
);
286 m_helpController
->AddBook(fileName
);
287 m_helpController
->DisplayContents();
296 // ---------------------------------------------------------------------
298 // ---------------------------------------------------------------------
300 // Standard macro for getting a resource from XPM file:
301 #define ART(artId, xpmRc) \
302 if ( id == artId ) return wxBitmap(xpmRc##_xpm);
304 #define GET_STD_ICON_FROM_APP(iconId)
306 // There are two ways of getting the standard icon: either via XPMs or via
307 // wxIcon ctor. This depends on the platform:
308 #if defined(__WXUNIVERSAL__)
309 #define CREATE_STD_ICON(iconId, xpmRc) return wxNullBitmap;
310 #elif defined(__WXGTK__) || defined(__WXMOTIF__)
311 #define CREATE_STD_ICON(iconId, xpmRc) return wxBitmap(xpmRc##_xpm);
313 #define CREATE_STD_ICON(iconId, xpmRc) \
315 wxIcon icon(_T(iconId)); \
317 bmp.CopyFromIcon(icon); \
322 // Macro used in CreateBitmap to get wxICON_FOO icons:
323 #define ART_MSGBOX(artId, iconId, xpmRc) \
326 GET_STD_ICON_FROM_APP(iconId) \
327 CREATE_STD_ICON(#iconId, xpmRc) \
330 // ---------------------------------------------------------------------
332 // ---------------------------------------------------------------------
334 // XPM hack: make the arrays const
335 //#define static static const
337 #include "bitmaps/helpback.xpm"
338 #include "bitmaps/helpbook.xpm"
339 #include "bitmaps/helpdown.xpm"
340 #include "bitmaps/helpforward.xpm"
341 #include "bitmaps/helpoptions.xpm"
342 #include "bitmaps/helppage.xpm"
343 #include "bitmaps/helpsidepanel.xpm"
344 #include "bitmaps/helpup.xpm"
345 #include "bitmaps/helpuplevel.xpm"
346 #include "bitmaps/helpicon.xpm"
347 #include "bitmaps/helpopen.xpm"
351 // ---------------------------------------------------------------------
352 // CreateBitmap routine
353 // ---------------------------------------------------------------------
355 wxBitmap
AlternateArtProvider::CreateBitmap(const wxArtID
& id
,
356 const wxArtClient
& client
,
357 const wxSize
& WXUNUSED(size
))
359 ART(wxART_HELP_SIDE_PANEL
, helpsidepanel
)
360 ART(wxART_HELP_SETTINGS
, helpoptions
)
361 ART(wxART_HELP_BOOK
, helpbook
)
362 ART(wxART_HELP_FOLDER
, helpbook
)
363 ART(wxART_HELP_PAGE
, helppage
)
364 //ART(wxART_ADD_BOOKMARK, addbookm)
365 //ART(wxART_DEL_BOOKMARK, delbookm)
366 ART(wxART_GO_BACK
, helpback
)
367 ART(wxART_GO_FORWARD
, helpforward
)
368 ART(wxART_GO_UP
, helpup
)
369 ART(wxART_GO_DOWN
, helpdown
)
370 ART(wxART_GO_TO_PARENT
, helpuplevel
)
371 ART(wxART_FILE_OPEN
, helpopen
)
372 if (client
== wxART_HELP_BROWSER
)
374 //ART(wxART_FRAME_ICON, helpicon)
375 ART(wxART_HELP
, helpicon
)
378 //ART(wxART_GO_HOME, home)
380 // Any wxWidgets icons not implemented here
381 // will be provided by the default art provider.
387 wxConnectionBase
*hvServer::OnAcceptConnection(const wxString
& topic
)
389 if (topic
== wxT("HELP"))
390 return new hvConnection();
395 // ----------------------------------------------------------------------------
397 // ----------------------------------------------------------------------------
399 hvConnection::hvConnection()
402 wxGetApp().GetConnections().Append(this);
405 hvConnection::~hvConnection()
407 wxGetApp().GetConnections().DeleteObject(this);
410 bool hvConnection::OnExecute(const wxString
& WXUNUSED(topic
),
413 wxIPCFormat
WXUNUSED(format
))
415 // wxLogStatus("Execute command: %s", data);
417 if ( !wxStrncmp( data
, wxT("--intstring"), 11 ) )
420 wxString argStr
= data
;
421 wxString numb
= argStr
.AfterLast(wxT('g'));
422 if ( !(numb
.ToLong(&i
) ) )
424 wxLogError( wxT("Integer conversion failed for --intstring") );
428 wxGetApp().GetHelpController()->Display(int(i
));
433 wxGetApp().GetHelpController()->Display(data
);
439 bool hvConnection::OnPoke(const wxString
& WXUNUSED(topic
),
440 const wxString
& item
,
443 wxIPCFormat
WXUNUSED(format
))
445 // wxLogStatus("Poke command: %s = %s", item.c_str(), data);
446 //topic is not tested
448 if ( wxGetApp().GetHelpController() )
450 if ( item
== wxT("--AddBook") )
452 wxGetApp().GetHelpController()->AddBook(data
);
454 else if ( item
== wxT("--DisplayContents") )
456 wxGetApp().GetHelpController()->DisplayContents();
458 else if ( item
== wxT("--DisplayIndex") )
460 wxGetApp().GetHelpController()->DisplayIndex();
462 else if ( item
== wxT("--KeywordSearch") )
464 wxGetApp().GetHelpController()->KeywordSearch(data
);
466 else if ( item
== wxT("--SetTitleFormat") )
468 wxString newname
= data
;
469 newname
.Replace( wxT("_"), wxT(" ") );
470 wxGetApp().GetHelpController()->SetTitleFormat(newname
);
471 //does not redraw title bar?
472 //wxGetApp().GetHelpController()->ReFresh(); - or something
474 else if ( item
== wxT("--SetTempDir") )
476 wxGetApp().GetHelpController()->SetTempDir(data
);
478 else if ( item
== wxT("--YouAreDead") )
480 // don't really know how to kill app from down here...
481 // use wxKill from client instead
482 //wxWindow *win = wxTheApp->GetTopWindow();
491 wxChar
*hvConnection::OnRequest(const wxString
& WXUNUSED(topic
),
492 const wxString
& WXUNUSED(item
),
493 int * WXUNUSED(size
),
494 wxIPCFormat
WXUNUSED(format
))
499 bool hvConnection::OnStartAdvise(const wxString
& WXUNUSED(topic
),
500 const wxString
& WXUNUSED(item
))
505 #endif // #if wxUSE_IPC