]>
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
31 #include "wx/wxhtml.h"
32 #include "wx/fs_zip.h"
34 #include "wx/artprov.h"
35 #include "wx/filedlg.h"
39 class AlternateArtProvider
: public wxArtProvider
42 virtual wxBitmap
CreateBitmap(const wxArtID
& id
, const wxArtClient
& client
,
58 delete wxLog::SetActiveTarget(new wxLogStderr
); // So dialog boxes aren't used
61 wxArtProvider::PushProvider(new AlternateArtProvider
);
63 int istyle
= wxHF_DEFAULT_STYLE
;
65 wxArtProvider::PushProvider(new AlternateArtProvider
);
67 wxString service
, windowName
, book
[10], 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 ) {
99 book
[bookCount
] = argStr
;
102 else if ( argStr
== wxT("--server") )
105 #if defined(__WXMSW__)
106 service
= wxT("generic_helpservice");
107 #elif defined(__UNIX__)
108 service
= wxT("/tmp/") + wxString(wxT("generic_helpservice"));
110 service
= wxT("4242");
113 else if ( !hasService
)
119 else if ( !hasWindowName
)
122 hasWindowName
= TRUE
;
124 else if ( argStr
.Find( wxT("--Style") ) >= 0 )
127 wxString numb
= argStr
.AfterLast(wxT('e'));
128 if ( !(numb
.ToLong(&i
) ) )
130 wxLogError( wxT("Integer conversion failed for --Style") );
139 //unknown - could be topic?
143 //no book - query user
146 wxString s
= wxFileSelector( wxT("Open help file"),
151 "Help books (*.htb)|*.htb|Help books (*.zip)|*.zip|\
152 HTML Help Project (*.hhp)|*.hhp"),
153 wxOPEN
| wxFILE_MUST_EXIST
,
165 if ( createServer
) {
166 // Create a new server
167 m_server
= new hvServer
;
169 if ( !m_server
->Create(service
) ) {
170 wxString wxm
= wxT("Server Create failed - service: ");
171 wxString xxm
= wxm
<< service
;
173 //if MSW quits here, probably another copy already exists
177 createServer
= FALSE
;
183 wxInitAllImageHandlers();
184 wxFileSystem::AddHandler(new wxZipFSHandler
);
186 SetVendorName(wxT("wxWindows") );
187 SetAppName(wxT("wxHTMLHelpServer") );
188 wxConfig::Get(); // create an instance
190 m_helpController
= new wxHtmlHelpController( istyle
);
192 if ( !hasWindowName
)
193 titleFormat
= wxT("Help: %s") ;
197 windowName
.Replace( wxT("_"), wxT(" ") );
198 titleFormat
= windowName
;
201 m_helpController
->SetTitleFormat( titleFormat
);
203 for( i
=0; i
< bookCount
; i
++ )
205 wxFileName
fileName(book
[i
]);
206 m_helpController
->AddBook(fileName
);
210 delete wxLog::SetActiveTarget(new wxLogGui
);
213 m_helpController
-> DisplayContents();
222 wxNode
* node
= m_connections
.First();
225 wxNode
* next
= node
->Next();
226 hvConnection
* connection
= (hvConnection
*) node
->Data();
227 connection
->Disconnect();
231 m_connections
.Clear();
240 delete m_helpController
;
241 delete wxConfig::Set(NULL
);
246 bool hvApp::OpenBook(wxHtmlHelpController
* controller
)
248 wxString s
= wxFileSelector(_("Open help file"),
253 "Help books (*.htb)|*.htb|Help books (*.zip)|*.zip|\
254 HTML Help Project (*.hhp)|*.hhp"),
255 wxOPEN
| wxFILE_MUST_EXIST
,
260 wxString ext
= s
.Right(4).Lower();
261 if (ext
== _T(".zip") || ext
== _T(".htb") || ext
== _T(".hhp"))
264 wxFileName
fileName(s
);
265 controller
->AddBook(fileName
);
276 // ---------------------------------------------------------------------
278 // ---------------------------------------------------------------------
280 // Standard macro for getting a resource from XPM file:
281 #define ART(artId, xpmRc) \
282 if ( id == artId ) return wxBitmap(xpmRc##_xpm);
284 // Compatibility hack to use wxApp::GetStdIcon of overriden by the user
285 #if WXWIN_COMPATIBILITY_2_2
286 #define GET_STD_ICON_FROM_APP(iconId) \
287 if ( client == wxART_MESSAGE_BOX ) \
289 wxIcon icon = wxTheApp->GetStdIcon(iconId); \
293 bmp.CopyFromIcon(icon); \
298 #define GET_STD_ICON_FROM_APP(iconId)
301 // There are two ways of getting the standard icon: either via XPMs or via
302 // wxIcon ctor. This depends on the platform:
303 #if defined(__WXUNIVERSAL__)
304 #define CREATE_STD_ICON(iconId, xpmRc) return wxNullBitmap;
305 #elif defined(__WXGTK__) || defined(__WXMOTIF__)
306 #define CREATE_STD_ICON(iconId, xpmRc) return wxBitmap(xpmRc##_xpm);
308 #define CREATE_STD_ICON(iconId, xpmRc) \
310 wxIcon icon(_T(iconId)); \
312 bmp.CopyFromIcon(icon); \
317 // Macro used in CreateBitmap to get wxICON_FOO icons:
318 #define ART_MSGBOX(artId, iconId, xpmRc) \
321 GET_STD_ICON_FROM_APP(iconId) \
322 CREATE_STD_ICON(#iconId, xpmRc) \
325 // ---------------------------------------------------------------------
327 // ---------------------------------------------------------------------
329 // XPM hack: make the arrays const
330 //#define static static const
332 #include "bitmaps/helpback.xpm"
333 #include "bitmaps/helpbook.xpm"
334 #include "bitmaps/helpdown.xpm"
335 #include "bitmaps/helpforward.xpm"
336 #include "bitmaps/helpoptions.xpm"
337 #include "bitmaps/helppage.xpm"
338 #include "bitmaps/helpsidepanel.xpm"
339 #include "bitmaps/helpup.xpm"
340 #include "bitmaps/helpuplevel.xpm"
341 #include "bitmaps/helpicon.xpm"
342 #include "bitmaps/helpopen.xpm"
346 // ---------------------------------------------------------------------
347 // CreateBitmap routine
348 // ---------------------------------------------------------------------
350 wxBitmap
AlternateArtProvider::CreateBitmap(const wxArtID
& id
,
351 const wxArtClient
& client
,
352 const wxSize
& WXUNUSED(size
))
354 ART(wxART_HELP_SIDE_PANEL
, helpsidepanel
)
355 ART(wxART_HELP_SETTINGS
, helpoptions
)
356 ART(wxART_HELP_BOOK
, helpbook
)
357 ART(wxART_HELP_FOLDER
, helpbook
)
358 ART(wxART_HELP_PAGE
, helppage
)
359 //ART(wxART_ADD_BOOKMARK, addbookm)
360 //ART(wxART_DEL_BOOKMARK, delbookm)
361 ART(wxART_GO_BACK
, helpback
)
362 ART(wxART_GO_FORWARD
, helpforward
)
363 ART(wxART_GO_UP
, helpup
)
364 ART(wxART_GO_DOWN
, helpdown
)
365 ART(wxART_GO_TO_PARENT
, helpuplevel
)
366 ART(wxART_FILE_OPEN
, helpopen
)
367 if (client
== wxART_HELP_BROWSER
)
369 //ART(wxART_FRAME_ICON, helpicon)
370 ART(wxART_HELP
, helpicon
)
373 //ART(wxART_GO_HOME, home)
375 // Any wxWindows icons not implemented here
376 // will be provided by the default art provider.
382 wxConnectionBase
*hvServer::OnAcceptConnection(const wxString
& topic
)
384 if (topic
== wxT("HELP"))
385 return new hvConnection();
390 // ----------------------------------------------------------------------------
392 // ----------------------------------------------------------------------------
394 hvConnection::hvConnection()
397 wxGetApp().GetConnections().Append(this);
400 hvConnection::~hvConnection()
402 wxGetApp().GetConnections().DeleteObject(this);
405 bool hvConnection::OnExecute(const wxString
& WXUNUSED(topic
),
408 wxIPCFormat
WXUNUSED(format
))
410 // wxLogStatus("Execute command: %s", data);
412 if ( !wxStrncmp( data
, wxT("--intstring"), 11 ) )
415 wxString argStr
= data
;
416 wxString numb
= argStr
.AfterLast(wxT('g'));
417 if ( !(numb
.ToLong(&i
) ) ) {
418 wxLogError( wxT("Integer conversion failed for --intstring") );
421 wxGetApp().GetHelpController()->Display(int(i
));
426 wxGetApp().GetHelpController()->Display(data
);
432 bool hvConnection::OnPoke(const wxString
& WXUNUSED(topic
),
433 const wxString
& item
,
436 wxIPCFormat
WXUNUSED(format
))
438 // wxLogStatus("Poke command: %s = %s", item.c_str(), data);
439 //topic is not tested
441 if ( wxGetApp().GetHelpController() )
443 if ( item
== wxT("--AddBook") )
445 wxGetApp().GetHelpController()->AddBook(data
);
447 else if ( item
== wxT("--DisplayContents") )
449 wxGetApp().GetHelpController()->DisplayContents();
451 else if ( item
== wxT("--DisplayIndex") )
453 wxGetApp().GetHelpController()->DisplayIndex();
455 else if ( item
== wxT("--KeywordSearch") )
457 wxGetApp().GetHelpController()->KeywordSearch(data
);
459 else if ( item
== wxT("--SetTitleFormat") )
461 wxString newname
= data
;
462 newname
.Replace( wxT("_"), wxT(" ") );
463 wxGetApp().GetHelpController()->SetTitleFormat(newname
);
464 //does not redraw title bar?
465 //wxGetApp().GetHelpController()->ReFresh(); - or something
467 else if ( item
== wxT("--SetTempDir") )
469 wxGetApp().GetHelpController()->SetTempDir(data
);
471 else if ( item
== wxT("--YouAreDead") )
473 // don't really know how to kill app from down here...
474 // use wxKill from client instead
475 //wxWindow *win = wxTheApp->GetTopWindow();
484 wxChar
*hvConnection::OnRequest(const wxString
& WXUNUSED(topic
),
485 const wxString
& WXUNUSED(item
),
486 int * WXUNUSED(size
),
487 wxIPCFormat
WXUNUSED(format
))
492 bool hvConnection::OnStartAdvise(const wxString
& WXUNUSED(topic
),
493 const wxString
& WXUNUSED(item
))