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" wxWidgets 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
, titleFormat
, argStr
;
75 bool hasService
= false;
76 bool hasWindowName
= false;
77 bool createServer
= false;
83 // Help books are recognized by extension ".hhp" ".htb" or ".zip".
84 // Service and window_name can occur anywhere in arguments,
85 // but service must be first
86 // Other arguments (topic?) could be added
88 // modes of operation:
89 // 1) no arguments - stand alone, prompt user for book
90 // 2) books only - stand alone, open books
91 // 3) "--server" as (any) arg - start connection with default service;
92 // also open any books passed as other arguments
93 // 4) at least one argument which is not book, and not "--server" - take first
94 // such argument as service, second (if present) as window name,
95 // start service, open any books
97 for( i
=1; i
<argc
; i
++ )
101 if ( argStr
.Find( wxT(".hhp") ) >= 0
102 || argStr
.Find( wxT(".htb") ) >= 0
103 || argStr
.Find( wxT(".zip") ) >= 0 )
105 book
[bookCount
] = argStr
;
108 else if ( argStr
== wxT("--server") )
111 #if defined(__WXMSW__)
112 service
= wxT("generic_helpservice");
113 #elif defined(__UNIX__)
114 service
= wxT("/tmp/") + wxString(wxT("generic_helpservice"));
116 service
= wxT("4242");
119 else if ( !hasService
)
125 else if ( !hasWindowName
)
128 hasWindowName
= true;
130 else if ( argStr
.Find( wxT("--Style") ) >= 0 )
133 wxString numb
= argStr
.AfterLast(wxT('e'));
134 if ( !(numb
.ToLong(&i
) ) )
136 wxLogError( wxT("Integer conversion failed for --Style") );
145 //unknown - could be topic?
149 // No book - query user; but not on Mac, since there
150 // may be an AppleEvent to open a document on the way
154 wxString s
= wxFileSelector( wxT("Open help file"),
158 wxT("Help books (*.htb)|*.htb|Help books (*.zip)|*.zip|HTML Help Project (*.hhp)|*.hhp"),
159 wxOPEN
| wxFILE_MUST_EXIST
,
174 // Create a new server
175 m_server
= new hvServer
;
177 if ( !m_server
->Create(service
) )
179 wxString wxm
= wxT("Server Create failed - service: ");
180 wxString xxm
= wxm
<< service
;
182 //if MSW quits here, probably another copy already exists
185 createServer
= false;
186 wxUnusedVar(createServer
);
192 wxInitAllImageHandlers();
193 wxFileSystem::AddHandler(new wxZipFSHandler
);
195 SetVendorName(wxT("wxWidgets") );
196 SetAppName(wxT("wxHTMLHelpServer") );
197 wxConfig::Get(); // create an instance
199 m_helpController
= new wxHtmlHelpController( istyle
);
201 if ( !hasWindowName
)
203 titleFormat
= wxT("Help: %s") ;
208 windowName
.Replace( wxT("_"), wxT(" ") );
209 titleFormat
= windowName
;
212 m_helpController
->SetTitleFormat( titleFormat
);
214 for( i
=0; i
<bookCount
; i
++ )
216 wxFileName
fileName(book
[i
]);
217 m_helpController
->AddBook(fileName
);
221 delete wxLog::SetActiveTarget(new wxLogGui
);
224 m_helpController
->DisplayContents();
233 wxObjectList::compatibility_iterator node
= m_connections
.GetFirst();
236 wxObjectList::compatibility_iterator next
= node
->GetNext();
237 hvConnection
* connection
= (hvConnection
*) node
->GetData();
238 connection
->Disconnect();
242 m_connections
.Clear();
251 delete m_helpController
;
252 delete wxConfig::Set(NULL
);
257 bool hvApp::OpenBook(wxHtmlHelpController
* controller
)
259 wxString s
= wxFileSelector(_("Open help file"),
264 "Help books (*.htb)|*.htb|Help books (*.zip)|*.zip|\
265 HTML Help Project (*.hhp)|*.hhp"),
266 wxOPEN
| wxFILE_MUST_EXIST
,
271 wxString ext
= s
.Right(4).Lower();
272 if (ext
== _T(".zip") || ext
== _T(".htb") || ext
== _T(".hhp"))
275 wxFileName
fileName(s
);
276 controller
->AddBook(fileName
);
285 /// Respond to Apple Event for opening a document
286 void hvApp::MacOpenFile(const wxString
& filename
)
289 wxFileName
fileName(filename
);
290 m_helpController
->AddBook(fileName
);
291 m_helpController
->DisplayContents();
300 // ---------------------------------------------------------------------
302 // ---------------------------------------------------------------------
304 // Standard macro for getting a resource from XPM file:
305 #define ART(artId, xpmRc) \
306 if ( id == artId ) return wxBitmap(xpmRc##_xpm);
308 // Compatibility hack to use wxApp::GetStdIcon of overriden by the user
309 #if WXWIN_COMPATIBILITY_2_2
310 #define GET_STD_ICON_FROM_APP(iconId) \
311 if ( client == wxART_MESSAGE_BOX ) \
313 wxIcon icon = wxTheApp->GetStdIcon(iconId); \
317 bmp.CopyFromIcon(icon); \
322 #define GET_STD_ICON_FROM_APP(iconId)
325 // There are two ways of getting the standard icon: either via XPMs or via
326 // wxIcon ctor. This depends on the platform:
327 #if defined(__WXUNIVERSAL__)
328 #define CREATE_STD_ICON(iconId, xpmRc) return wxNullBitmap;
329 #elif defined(__WXGTK__) || defined(__WXMOTIF__)
330 #define CREATE_STD_ICON(iconId, xpmRc) return wxBitmap(xpmRc##_xpm);
332 #define CREATE_STD_ICON(iconId, xpmRc) \
334 wxIcon icon(_T(iconId)); \
336 bmp.CopyFromIcon(icon); \
341 // Macro used in CreateBitmap to get wxICON_FOO icons:
342 #define ART_MSGBOX(artId, iconId, xpmRc) \
345 GET_STD_ICON_FROM_APP(iconId) \
346 CREATE_STD_ICON(#iconId, xpmRc) \
349 // ---------------------------------------------------------------------
351 // ---------------------------------------------------------------------
353 // XPM hack: make the arrays const
354 //#define static static const
356 #include "bitmaps/helpback.xpm"
357 #include "bitmaps/helpbook.xpm"
358 #include "bitmaps/helpdown.xpm"
359 #include "bitmaps/helpforward.xpm"
360 #include "bitmaps/helpoptions.xpm"
361 #include "bitmaps/helppage.xpm"
362 #include "bitmaps/helpsidepanel.xpm"
363 #include "bitmaps/helpup.xpm"
364 #include "bitmaps/helpuplevel.xpm"
365 #include "bitmaps/helpicon.xpm"
366 #include "bitmaps/helpopen.xpm"
370 // ---------------------------------------------------------------------
371 // CreateBitmap routine
372 // ---------------------------------------------------------------------
374 wxBitmap
AlternateArtProvider::CreateBitmap(const wxArtID
& id
,
375 const wxArtClient
& client
,
376 const wxSize
& WXUNUSED(size
))
378 ART(wxART_HELP_SIDE_PANEL
, helpsidepanel
)
379 ART(wxART_HELP_SETTINGS
, helpoptions
)
380 ART(wxART_HELP_BOOK
, helpbook
)
381 ART(wxART_HELP_FOLDER
, helpbook
)
382 ART(wxART_HELP_PAGE
, helppage
)
383 //ART(wxART_ADD_BOOKMARK, addbookm)
384 //ART(wxART_DEL_BOOKMARK, delbookm)
385 ART(wxART_GO_BACK
, helpback
)
386 ART(wxART_GO_FORWARD
, helpforward
)
387 ART(wxART_GO_UP
, helpup
)
388 ART(wxART_GO_DOWN
, helpdown
)
389 ART(wxART_GO_TO_PARENT
, helpuplevel
)
390 ART(wxART_FILE_OPEN
, helpopen
)
391 if (client
== wxART_HELP_BROWSER
)
393 //ART(wxART_FRAME_ICON, helpicon)
394 ART(wxART_HELP
, helpicon
)
397 //ART(wxART_GO_HOME, home)
399 // Any wxWidgets icons not implemented here
400 // will be provided by the default art provider.
406 wxConnectionBase
*hvServer::OnAcceptConnection(const wxString
& topic
)
408 if (topic
== wxT("HELP"))
409 return new hvConnection();
414 // ----------------------------------------------------------------------------
416 // ----------------------------------------------------------------------------
418 hvConnection::hvConnection()
421 wxGetApp().GetConnections().Append(this);
424 hvConnection::~hvConnection()
426 wxGetApp().GetConnections().DeleteObject(this);
429 bool hvConnection::OnExecute(const wxString
& WXUNUSED(topic
),
432 wxIPCFormat
WXUNUSED(format
))
434 // wxLogStatus("Execute command: %s", data);
436 if ( !wxStrncmp( data
, wxT("--intstring"), 11 ) )
439 wxString argStr
= data
;
440 wxString numb
= argStr
.AfterLast(wxT('g'));
441 if ( !(numb
.ToLong(&i
) ) )
443 wxLogError( wxT("Integer conversion failed for --intstring") );
447 wxGetApp().GetHelpController()->Display(int(i
));
452 wxGetApp().GetHelpController()->Display(data
);
458 bool hvConnection::OnPoke(const wxString
& WXUNUSED(topic
),
459 const wxString
& item
,
462 wxIPCFormat
WXUNUSED(format
))
464 // wxLogStatus("Poke command: %s = %s", item.c_str(), data);
465 //topic is not tested
467 if ( wxGetApp().GetHelpController() )
469 if ( item
== wxT("--AddBook") )
471 wxGetApp().GetHelpController()->AddBook(data
);
473 else if ( item
== wxT("--DisplayContents") )
475 wxGetApp().GetHelpController()->DisplayContents();
477 else if ( item
== wxT("--DisplayIndex") )
479 wxGetApp().GetHelpController()->DisplayIndex();
481 else if ( item
== wxT("--KeywordSearch") )
483 wxGetApp().GetHelpController()->KeywordSearch(data
);
485 else if ( item
== wxT("--SetTitleFormat") )
487 wxString newname
= data
;
488 newname
.Replace( wxT("_"), wxT(" ") );
489 wxGetApp().GetHelpController()->SetTitleFormat(newname
);
490 //does not redraw title bar?
491 //wxGetApp().GetHelpController()->ReFresh(); - or something
493 else if ( item
== wxT("--SetTempDir") )
495 wxGetApp().GetHelpController()->SetTempDir(data
);
497 else if ( item
== wxT("--YouAreDead") )
499 // don't really know how to kill app from down here...
500 // use wxKill from client instead
501 //wxWindow *win = wxTheApp->GetTopWindow();
510 wxChar
*hvConnection::OnRequest(const wxString
& WXUNUSED(topic
),
511 const wxString
& WXUNUSED(item
),
512 int * WXUNUSED(size
),
513 wxIPCFormat
WXUNUSED(format
))
518 bool hvConnection::OnStartAdvise(const wxString
& WXUNUSED(topic
),
519 const wxString
& WXUNUSED(item
))
524 #endif // #if wxUSE_IPC