]>
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 wxFileName::MacRegisterDefaultTypeAndCreator( "htb" , 'HTBD' , 'HTBA' ) ;
68 int istyle
= wxHF_DEFAULT_STYLE
;
70 wxString service
, windowName
, book
[10], titleFormat
, argStr
;
73 bool hasService
= FALSE
;
74 bool hasWindowName
= FALSE
;
75 bool createServer
= FALSE
;
81 // Help books are recognized by extension ".hhp" ".htb" or ".zip".
82 // Service and window_name can occur anywhere in arguments,
83 // but service must be first
84 // Other arguments (topic?) could be added
86 // modes of operation:
87 // 1) no arguments - stand alone, prompt user for book
88 // 2) books only - stand alone, open books
89 // 3) "--server" as (any) arg - start connection with default service;
90 // also open any books passed as other arguments
91 // 4) at least one argument which is not book, and not "--server" - take first
92 // such argument as service, second (if present) as window name,
93 // start service, open any books
95 for( i
=1; i
< argc
; i
++ )
99 if ( argStr
.Find( wxT(".hhp") ) >= 0 ||
100 argStr
.Find( wxT(".htb") ) >= 0 ||
101 argStr
.Find( wxT(".zip") ) >= 0 ) {
102 book
[bookCount
] = argStr
;
105 else if ( argStr
== wxT("--server") )
108 #if defined(__WXMSW__)
109 service
= wxT("generic_helpservice");
110 #elif defined(__UNIX__)
111 service
= wxT("/tmp/") + wxString(wxT("generic_helpservice"));
113 service
= wxT("4242");
116 else if ( !hasService
)
122 else if ( !hasWindowName
)
125 hasWindowName
= TRUE
;
127 else if ( argStr
.Find( wxT("--Style") ) >= 0 )
130 wxString numb
= argStr
.AfterLast(wxT('e'));
131 if ( !(numb
.ToLong(&i
) ) )
133 wxLogError( wxT("Integer conversion failed for --Style") );
142 //unknown - could be topic?
146 // No book - query user; but not on Mac, since there
147 // may be an AppleEvent to open a document on the way
151 wxString s
= wxFileSelector( wxT("Open help file"),
156 "Help books (*.htb)|*.htb|Help books (*.zip)|*.zip|\
157 HTML Help Project (*.hhp)|*.hhp"),
158 wxOPEN
| wxFILE_MUST_EXIST
,
171 if ( createServer
) {
172 // Create a new server
173 m_server
= new hvServer
;
175 if ( !m_server
->Create(service
) ) {
176 wxString wxm
= wxT("Server Create failed - service: ");
177 wxString xxm
= wxm
<< service
;
179 //if MSW quits here, probably another copy already exists
183 createServer
= FALSE
;
189 wxInitAllImageHandlers();
190 wxFileSystem::AddHandler(new wxZipFSHandler
);
192 SetVendorName(wxT("wxWindows") );
193 SetAppName(wxT("wxHTMLHelpServer") );
194 wxConfig::Get(); // create an instance
196 m_helpController
= new wxHtmlHelpController( istyle
);
198 if ( !hasWindowName
)
199 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 wxNode
* node
= m_connections
.First();
231 wxNode
* next
= node
->Next();
232 hvConnection
* connection
= (hvConnection
*) node
->Data();
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 wxOPEN
| wxFILE_MUST_EXIST
,
266 wxString ext
= s
.Right(4).Lower();
267 if (ext
== _T(".zip") || ext
== _T(".htb") || ext
== _T(".hhp"))
270 wxFileName
fileName(s
);
271 controller
->AddBook(fileName
);
279 /// Respond to Apple Event for opening a document
280 void hvApp::MacOpenFile(const wxString
& filename
)
283 wxFileName
fileName(filename
);
284 m_helpController
->AddBook(fileName
);
285 m_helpController
->DisplayContents();
294 // ---------------------------------------------------------------------
296 // ---------------------------------------------------------------------
298 // Standard macro for getting a resource from XPM file:
299 #define ART(artId, xpmRc) \
300 if ( id == artId ) return wxBitmap(xpmRc##_xpm);
302 // Compatibility hack to use wxApp::GetStdIcon of overriden by the user
303 #if WXWIN_COMPATIBILITY_2_2
304 #define GET_STD_ICON_FROM_APP(iconId) \
305 if ( client == wxART_MESSAGE_BOX ) \
307 wxIcon icon = wxTheApp->GetStdIcon(iconId); \
311 bmp.CopyFromIcon(icon); \
316 #define GET_STD_ICON_FROM_APP(iconId)
319 // There are two ways of getting the standard icon: either via XPMs or via
320 // wxIcon ctor. This depends on the platform:
321 #if defined(__WXUNIVERSAL__)
322 #define CREATE_STD_ICON(iconId, xpmRc) return wxNullBitmap;
323 #elif defined(__WXGTK__) || defined(__WXMOTIF__)
324 #define CREATE_STD_ICON(iconId, xpmRc) return wxBitmap(xpmRc##_xpm);
326 #define CREATE_STD_ICON(iconId, xpmRc) \
328 wxIcon icon(_T(iconId)); \
330 bmp.CopyFromIcon(icon); \
335 // Macro used in CreateBitmap to get wxICON_FOO icons:
336 #define ART_MSGBOX(artId, iconId, xpmRc) \
339 GET_STD_ICON_FROM_APP(iconId) \
340 CREATE_STD_ICON(#iconId, xpmRc) \
343 // ---------------------------------------------------------------------
345 // ---------------------------------------------------------------------
347 // XPM hack: make the arrays const
348 //#define static static const
350 #include "bitmaps/helpback.xpm"
351 #include "bitmaps/helpbook.xpm"
352 #include "bitmaps/helpdown.xpm"
353 #include "bitmaps/helpforward.xpm"
354 #include "bitmaps/helpoptions.xpm"
355 #include "bitmaps/helppage.xpm"
356 #include "bitmaps/helpsidepanel.xpm"
357 #include "bitmaps/helpup.xpm"
358 #include "bitmaps/helpuplevel.xpm"
359 #include "bitmaps/helpicon.xpm"
360 #include "bitmaps/helpopen.xpm"
364 // ---------------------------------------------------------------------
365 // CreateBitmap routine
366 // ---------------------------------------------------------------------
368 wxBitmap
AlternateArtProvider::CreateBitmap(const wxArtID
& id
,
369 const wxArtClient
& client
,
370 const wxSize
& WXUNUSED(size
))
372 ART(wxART_HELP_SIDE_PANEL
, helpsidepanel
)
373 ART(wxART_HELP_SETTINGS
, helpoptions
)
374 ART(wxART_HELP_BOOK
, helpbook
)
375 ART(wxART_HELP_FOLDER
, helpbook
)
376 ART(wxART_HELP_PAGE
, helppage
)
377 //ART(wxART_ADD_BOOKMARK, addbookm)
378 //ART(wxART_DEL_BOOKMARK, delbookm)
379 ART(wxART_GO_BACK
, helpback
)
380 ART(wxART_GO_FORWARD
, helpforward
)
381 ART(wxART_GO_UP
, helpup
)
382 ART(wxART_GO_DOWN
, helpdown
)
383 ART(wxART_GO_TO_PARENT
, helpuplevel
)
384 ART(wxART_FILE_OPEN
, helpopen
)
385 if (client
== wxART_HELP_BROWSER
)
387 //ART(wxART_FRAME_ICON, helpicon)
388 ART(wxART_HELP
, helpicon
)
391 //ART(wxART_GO_HOME, home)
393 // Any wxWindows icons not implemented here
394 // will be provided by the default art provider.
400 wxConnectionBase
*hvServer::OnAcceptConnection(const wxString
& topic
)
402 if (topic
== wxT("HELP"))
403 return new hvConnection();
408 // ----------------------------------------------------------------------------
410 // ----------------------------------------------------------------------------
412 hvConnection::hvConnection()
415 wxGetApp().GetConnections().Append(this);
418 hvConnection::~hvConnection()
420 wxGetApp().GetConnections().DeleteObject(this);
423 bool hvConnection::OnExecute(const wxString
& WXUNUSED(topic
),
426 wxIPCFormat
WXUNUSED(format
))
428 // wxLogStatus("Execute command: %s", data);
430 if ( !wxStrncmp( data
, wxT("--intstring"), 11 ) )
433 wxString argStr
= data
;
434 wxString numb
= argStr
.AfterLast(wxT('g'));
435 if ( !(numb
.ToLong(&i
) ) ) {
436 wxLogError( wxT("Integer conversion failed for --intstring") );
439 wxGetApp().GetHelpController()->Display(int(i
));
444 wxGetApp().GetHelpController()->Display(data
);
450 bool hvConnection::OnPoke(const wxString
& WXUNUSED(topic
),
451 const wxString
& item
,
454 wxIPCFormat
WXUNUSED(format
))
456 // wxLogStatus("Poke command: %s = %s", item.c_str(), data);
457 //topic is not tested
459 if ( wxGetApp().GetHelpController() )
461 if ( item
== wxT("--AddBook") )
463 wxGetApp().GetHelpController()->AddBook(data
);
465 else if ( item
== wxT("--DisplayContents") )
467 wxGetApp().GetHelpController()->DisplayContents();
469 else if ( item
== wxT("--DisplayIndex") )
471 wxGetApp().GetHelpController()->DisplayIndex();
473 else if ( item
== wxT("--KeywordSearch") )
475 wxGetApp().GetHelpController()->KeywordSearch(data
);
477 else if ( item
== wxT("--SetTitleFormat") )
479 wxString newname
= data
;
480 newname
.Replace( wxT("_"), wxT(" ") );
481 wxGetApp().GetHelpController()->SetTitleFormat(newname
);
482 //does not redraw title bar?
483 //wxGetApp().GetHelpController()->ReFresh(); - or something
485 else if ( item
== wxT("--SetTempDir") )
487 wxGetApp().GetHelpController()->SetTempDir(data
);
489 else if ( item
== wxT("--YouAreDead") )
491 // don't really know how to kill app from down here...
492 // use wxKill from client instead
493 //wxWindow *win = wxTheApp->GetTopWindow();
502 wxChar
*hvConnection::OnRequest(const wxString
& WXUNUSED(topic
),
503 const wxString
& WXUNUSED(item
),
504 int * WXUNUSED(size
),
505 wxIPCFormat
WXUNUSED(format
))
510 bool hvConnection::OnStartAdvise(const wxString
& WXUNUSED(topic
),
511 const wxString
& WXUNUSED(item
))