]>
git.saurik.com Git - wxWidgets.git/blob - utils/helpview/src/helpview.cpp
d16e92f0ff7e7b0ea57d382fa7c6675f709da1f7
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
;
76 // Help books are recognized by extension ".hhp" ".htb" or ".zip".
77 // Service and window_name can occur anywhere in arguments,
78 // but service must be first
79 // Other arguments (topic?) could be added
81 // modes of operation:
82 // 1) no arguments - stand alone, prompt user for book
83 // 2) books only - stand alone, open books
84 // 3) "--server" as (any) arg - start connection with default service;
85 // also open any books passed as other arguments
86 // 4) at least one argument which is not book, and not "--server" - take first
87 // such argument as service, second (if present) as window name,
88 // start service, open any books
90 for( i
=1; i
< argc
; i
++ )
94 if ( argStr
.Find( wxT(".hhp") ) >= 0 ||
95 argStr
.Find( wxT(".htb") ) >= 0 ||
96 argStr
.Find( wxT(".zip") ) >= 0 ) {
97 book
[bookCount
] = argStr
;
100 else if ( argStr
== wxT("--server") )
103 #if defined(__WXMSW__)
104 service
= wxT("generic_helpservice");
105 #elif defined(__UNIX__)
106 service
= wxT("/tmp/") + wxString(wxT("generic_helpservice"));
108 service
= wxT("4242");
111 else if ( !hasService
)
117 else if ( !hasWindowName
)
120 hasWindowName
= TRUE
;
122 else if ( argStr
.Find( wxT("--Style") ) >= 0 )
125 wxString numb
= argStr
.AfterLast(wxT('e'));
126 if ( !(numb
.ToLong(&i
) ) )
128 wxLogError( wxT("Integer conversion failed for --Style") );
137 //unknown - could be topic?
141 //no book - query user
144 wxString s
= wxFileSelector( wxT("Open help file"),
149 "Help books (*.htb)|*.htb|Help books (*.zip)|*.zip|\
150 HTML Help Project (*.hhp)|*.hhp"),
151 wxOPEN
| wxFILE_MUST_EXIST
,
163 if ( createServer
) {
164 // Create a new server
165 m_server
= new hvServer
;
167 if ( !m_server
->Create(service
) ) {
168 wxString wxm
= wxT("Server Create failed - service: ");
169 wxString xxm
= wxm
<< service
;
171 //if MSW quits here, probably another copy already exists
175 createServer
= FALSE
;
181 wxInitAllImageHandlers();
182 wxFileSystem::AddHandler(new wxZipFSHandler
);
184 SetVendorName(wxT("wxWindows") );
185 SetAppName(wxT("wxHTMLHelpServer") );
186 wxConfig::Get(); // create an instance
188 m_helpController
= new wxHtmlHelpController( istyle
);
190 if ( !hasWindowName
)
191 titleFormat
= wxT("Help: %s") ;
195 windowName
.Replace( wxT("_"), wxT(" ") );
196 titleFormat
= windowName
;
199 m_helpController
->SetTitleFormat( titleFormat
);
201 for( i
=0; i
< bookCount
; i
++ )
203 m_helpController
->AddBook(book
[i
]);
207 delete wxLog::SetActiveTarget(new wxLogGui
);
210 m_helpController
-> DisplayContents();
219 wxNode
* node
= m_connections
.First();
222 wxNode
* next
= node
->Next();
223 hvConnection
* connection
= (hvConnection
*) node
->Data();
224 connection
->Disconnect();
228 m_connections
.Clear();
237 delete m_helpController
;
238 delete wxConfig::Set(NULL
);
243 bool hvApp::OpenBook(wxHtmlHelpController
* controller
)
245 wxString s
= wxFileSelector(_("Open help file"),
250 "Help books (*.htb)|*.htb|Help books (*.zip)|*.zip|\
251 HTML Help Project (*.hhp)|*.hhp"),
252 wxOPEN
| wxFILE_MUST_EXIST
,
257 wxString ext
= s
.Right(4).Lower();
258 if (ext
== _T(".zip") || ext
== _T(".htb") || ext
== _T(".hhp"))
261 controller
->AddBook(s
);
272 // ---------------------------------------------------------------------
274 // ---------------------------------------------------------------------
276 // Standard macro for getting a resource from XPM file:
277 #define ART(artId, xpmRc) \
278 if ( id == artId ) return wxBitmap(xpmRc##_xpm);
280 // Compatibility hack to use wxApp::GetStdIcon of overriden by the user
281 #if WXWIN_COMPATIBILITY_2_2
282 #define GET_STD_ICON_FROM_APP(iconId) \
283 if ( client == wxART_MESSAGE_BOX ) \
285 wxIcon icon = wxTheApp->GetStdIcon(iconId); \
289 bmp.CopyFromIcon(icon); \
294 #define GET_STD_ICON_FROM_APP(iconId)
297 // There are two ways of getting the standard icon: either via XPMs or via
298 // wxIcon ctor. This depends on the platform:
299 #if defined(__WXUNIVERSAL__)
300 #define CREATE_STD_ICON(iconId, xpmRc) return wxNullBitmap;
301 #elif defined(__WXGTK__) || defined(__WXMOTIF__)
302 #define CREATE_STD_ICON(iconId, xpmRc) return wxBitmap(xpmRc##_xpm);
304 #define CREATE_STD_ICON(iconId, xpmRc) \
306 wxIcon icon(_T(iconId)); \
308 bmp.CopyFromIcon(icon); \
313 // Macro used in CreateBitmap to get wxICON_FOO icons:
314 #define ART_MSGBOX(artId, iconId, xpmRc) \
317 GET_STD_ICON_FROM_APP(iconId) \
318 CREATE_STD_ICON(#iconId, xpmRc) \
321 // ---------------------------------------------------------------------
323 // ---------------------------------------------------------------------
325 // XPM hack: make the arrays const
326 //#define static static const
328 #include "bitmaps/helpback.xpm"
329 #include "bitmaps/helpbook.xpm"
330 #include "bitmaps/helpdown.xpm"
331 #include "bitmaps/helpforward.xpm"
332 #include "bitmaps/helpoptions.xpm"
333 #include "bitmaps/helppage.xpm"
334 #include "bitmaps/helpsidepanel.xpm"
335 #include "bitmaps/helpup.xpm"
336 #include "bitmaps/helpuplevel.xpm"
337 #include "bitmaps/helpicon.xpm"
338 #include "bitmaps/helpopen.xpm"
342 // ---------------------------------------------------------------------
343 // CreateBitmap routine
344 // ---------------------------------------------------------------------
346 wxBitmap
AlternateArtProvider::CreateBitmap(const wxArtID
& id
,
347 const wxArtClient
& client
,
348 const wxSize
& WXUNUSED(size
))
350 ART(wxART_HELP_SIDE_PANEL
, helpsidepanel
)
351 ART(wxART_HELP_SETTINGS
, helpoptions
)
352 ART(wxART_HELP_BOOK
, helpbook
)
353 ART(wxART_HELP_FOLDER
, helpbook
)
354 ART(wxART_HELP_PAGE
, helppage
)
355 //ART(wxART_ADD_BOOKMARK, addbookm)
356 //ART(wxART_DEL_BOOKMARK, delbookm)
357 ART(wxART_GO_BACK
, helpback
)
358 ART(wxART_GO_FORWARD
, helpforward
)
359 ART(wxART_GO_UP
, helpup
)
360 ART(wxART_GO_DOWN
, helpdown
)
361 ART(wxART_GO_TO_PARENT
, helpuplevel
)
362 ART(wxART_FILE_OPEN
, helpopen
)
363 if (client
== wxART_HELP_BROWSER
)
365 //ART(wxART_FRAME_ICON, helpicon)
366 ART(wxART_HELP
, helpicon
)
369 //ART(wxART_GO_HOME, home)
371 // Any wxWindows icons not implemented here
372 // will be provided by the default art provider.
378 wxConnectionBase
*hvServer::OnAcceptConnection(const wxString
& topic
)
380 if (topic
== wxT("HELP"))
381 return new hvConnection();
386 // ----------------------------------------------------------------------------
388 // ----------------------------------------------------------------------------
390 hvConnection::hvConnection()
393 wxGetApp().GetConnections().Append(this);
396 hvConnection::~hvConnection()
398 wxGetApp().GetConnections().DeleteObject(this);
401 bool hvConnection::OnExecute(const wxString
& WXUNUSED(topic
),
404 wxIPCFormat
WXUNUSED(format
))
406 // wxLogStatus("Execute command: %s", data);
408 if ( !wxStrncmp( data
, wxT("--intstring"), 11 ) )
411 wxString argStr
= data
;
412 wxString numb
= argStr
.AfterLast(wxT('g'));
413 if ( !(numb
.ToLong(&i
) ) ) {
414 wxLogError( wxT("Integer conversion failed for --intstring") );
417 wxGetApp().GetHelpController()->Display(int(i
));
422 wxGetApp().GetHelpController()->Display(data
);
428 bool hvConnection::OnPoke(const wxString
& WXUNUSED(topic
),
429 const wxString
& item
,
432 wxIPCFormat
WXUNUSED(format
))
434 // wxLogStatus("Poke command: %s = %s", item.c_str(), data);
435 //topic is not tested
437 if ( wxGetApp().GetHelpController() )
439 if ( item
== wxT("--AddBook") )
441 wxGetApp().GetHelpController()->AddBook(data
);
443 else if ( item
== wxT("--DisplayContents") )
445 wxGetApp().GetHelpController()->DisplayContents();
447 else if ( item
== wxT("--DisplayIndex") )
449 wxGetApp().GetHelpController()->DisplayIndex();
451 else if ( item
== wxT("--KeywordSearch") )
453 wxGetApp().GetHelpController()->KeywordSearch(data
);
455 else if ( item
== wxT("--SetTitleFormat") )
457 wxString newname
= data
;
458 newname
.Replace( wxT("_"), wxT(" ") );
459 wxGetApp().GetHelpController()->SetTitleFormat(newname
);
460 //does not redraw title bar?
461 //wxGetApp().GetHelpController()->ReFresh(); - or something
463 else if ( item
== wxT("--SetTempDir") )
465 wxGetApp().GetHelpController()->SetTempDir(data
);
467 else if ( item
== wxT("--YouAreDead") )
469 // don't really know how to kill app from down here...
470 // use wxKill from client instead
471 //wxWindow *win = wxTheApp->GetTopWindow();
480 wxChar
*hvConnection::OnRequest(const wxString
& WXUNUSED(topic
),
481 const wxString
& WXUNUSED(item
),
482 int * WXUNUSED(size
),
483 wxIPCFormat
WXUNUSED(format
))
488 bool hvConnection::OnStartAdvise(const wxString
& WXUNUSED(topic
),
489 const wxString
& WXUNUSED(item
))