]>
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 wxApp::s_macAboutMenuItemId
= wxID_ABOUT
;
66 wxFileName::MacRegisterDefaultTypeAndCreator( "htb" , 'HTBD' , 'HTBA' ) ;
69 int istyle
= wxHF_DEFAULT_STYLE
;
71 wxString service
, windowName
, book
[10], titleFormat
, argStr
;
74 bool hasService
= false;
75 bool hasWindowName
= false;
76 bool createServer
= false;
82 // Help books are recognized by extension ".hhp" ".htb" or ".zip".
83 // Service and window_name can occur anywhere in arguments,
84 // but service must be first
85 // Other arguments (topic?) could be added
87 // modes of operation:
88 // 1) no arguments - stand alone, prompt user for book
89 // 2) books only - stand alone, open books
90 // 3) "--server" as (any) arg - start connection with default service;
91 // also open any books passed as other arguments
92 // 4) at least one argument which is not book, and not "--server" - take first
93 // such argument as service, second (if present) as window name,
94 // start service, open any books
96 for( i
=1; i
<argc
; i
++ )
100 if ( argStr
.Find( wxT(".hhp") ) >= 0
101 || argStr
.Find( wxT(".htb") ) >= 0
102 || argStr
.Find( wxT(".zip") ) >= 0 )
104 book
[bookCount
] = argStr
;
107 else if ( argStr
== wxT("--server") )
110 #if defined(__WXMSW__)
111 service
= wxT("generic_helpservice");
112 #elif defined(__UNIX__)
113 service
= wxT("/tmp/") + wxString(wxT("generic_helpservice"));
115 service
= wxT("4242");
118 else if ( !hasService
)
124 else if ( !hasWindowName
)
127 hasWindowName
= true;
129 else if ( argStr
.Find( wxT("--Style") ) >= 0 )
132 wxString numb
= argStr
.AfterLast(wxT('e'));
133 if ( !(numb
.ToLong(&i
) ) )
135 wxLogError( wxT("Integer conversion failed for --Style") );
144 //unknown - could be topic?
148 // No book - query user; but not on Mac, since there
149 // may be an AppleEvent to open a document on the way
153 wxString s
= wxFileSelector( wxT("Open help file"),
157 wxT("Help books (*.htb)|*.htb|Help books (*.zip)|*.zip|HTML Help Project (*.hhp)|*.hhp"),
158 wxOPEN
| wxFILE_MUST_EXIST
,
173 // Create a new server
174 m_server
= new hvServer
;
176 if ( !m_server
->Create(service
) )
178 wxString wxm
= wxT("Server Create failed - service: ");
179 wxString xxm
= wxm
<< service
;
181 //if MSW quits here, probably another copy already exists
184 createServer
= false;
185 wxUnusedVar(createServer
);
191 wxInitAllImageHandlers();
192 wxFileSystem::AddHandler(new wxZipFSHandler
);
194 SetVendorName(wxT("wxWindows") );
195 SetAppName(wxT("wxHTMLHelpServer") );
196 wxConfig::Get(); // create an instance
198 m_helpController
= new wxHtmlHelpController( istyle
);
200 if ( !hasWindowName
)
202 titleFormat
= wxT("Help: %s") ;
207 windowName
.Replace( wxT("_"), wxT(" ") );
208 titleFormat
= windowName
;
211 m_helpController
->SetTitleFormat( titleFormat
);
213 for( i
=0; i
<bookCount
; i
++ )
215 wxFileName
fileName(book
[i
]);
216 m_helpController
->AddBook(fileName
);
220 delete wxLog::SetActiveTarget(new wxLogGui
);
223 m_helpController
->DisplayContents();
232 wxNode
* node
= m_connections
.GetFirst();
235 wxNode
* next
= node
->GetNext();
236 hvConnection
* connection
= (hvConnection
*) node
->GetData();
237 connection
->Disconnect();
241 m_connections
.Clear();
250 delete m_helpController
;
251 delete wxConfig::Set(NULL
);
256 bool hvApp::OpenBook(wxHtmlHelpController
* controller
)
258 wxString s
= wxFileSelector(_("Open help file"),
263 "Help books (*.htb)|*.htb|Help books (*.zip)|*.zip|\
264 HTML Help Project (*.hhp)|*.hhp"),
265 wxOPEN
| wxFILE_MUST_EXIST
,
270 wxString ext
= s
.Right(4).Lower();
271 if (ext
== _T(".zip") || ext
== _T(".htb") || ext
== _T(".hhp"))
274 wxFileName
fileName(s
);
275 controller
->AddBook(fileName
);
284 /// Respond to Apple Event for opening a document
285 void hvApp::MacOpenFile(const wxString
& filename
)
288 wxFileName
fileName(filename
);
289 m_helpController
->AddBook(fileName
);
290 m_helpController
->DisplayContents();
299 // ---------------------------------------------------------------------
301 // ---------------------------------------------------------------------
303 // Standard macro for getting a resource from XPM file:
304 #define ART(artId, xpmRc) \
305 if ( id == artId ) return wxBitmap(xpmRc##_xpm);
307 // Compatibility hack to use wxApp::GetStdIcon of overriden by the user
308 #if WXWIN_COMPATIBILITY_2_2
309 #define GET_STD_ICON_FROM_APP(iconId) \
310 if ( client == wxART_MESSAGE_BOX ) \
312 wxIcon icon = wxTheApp->GetStdIcon(iconId); \
316 bmp.CopyFromIcon(icon); \
321 #define GET_STD_ICON_FROM_APP(iconId)
324 // There are two ways of getting the standard icon: either via XPMs or via
325 // wxIcon ctor. This depends on the platform:
326 #if defined(__WXUNIVERSAL__)
327 #define CREATE_STD_ICON(iconId, xpmRc) return wxNullBitmap;
328 #elif defined(__WXGTK__) || defined(__WXMOTIF__)
329 #define CREATE_STD_ICON(iconId, xpmRc) return wxBitmap(xpmRc##_xpm);
331 #define CREATE_STD_ICON(iconId, xpmRc) \
333 wxIcon icon(_T(iconId)); \
335 bmp.CopyFromIcon(icon); \
340 // Macro used in CreateBitmap to get wxICON_FOO icons:
341 #define ART_MSGBOX(artId, iconId, xpmRc) \
344 GET_STD_ICON_FROM_APP(iconId) \
345 CREATE_STD_ICON(#iconId, xpmRc) \
348 // ---------------------------------------------------------------------
350 // ---------------------------------------------------------------------
352 // XPM hack: make the arrays const
353 //#define static static const
355 #include "bitmaps/helpback.xpm"
356 #include "bitmaps/helpbook.xpm"
357 #include "bitmaps/helpdown.xpm"
358 #include "bitmaps/helpforward.xpm"
359 #include "bitmaps/helpoptions.xpm"
360 #include "bitmaps/helppage.xpm"
361 #include "bitmaps/helpsidepanel.xpm"
362 #include "bitmaps/helpup.xpm"
363 #include "bitmaps/helpuplevel.xpm"
364 #include "bitmaps/helpicon.xpm"
365 #include "bitmaps/helpopen.xpm"
369 // ---------------------------------------------------------------------
370 // CreateBitmap routine
371 // ---------------------------------------------------------------------
373 wxBitmap
AlternateArtProvider::CreateBitmap(const wxArtID
& id
,
374 const wxArtClient
& client
,
375 const wxSize
& WXUNUSED(size
))
377 ART(wxART_HELP_SIDE_PANEL
, helpsidepanel
)
378 ART(wxART_HELP_SETTINGS
, helpoptions
)
379 ART(wxART_HELP_BOOK
, helpbook
)
380 ART(wxART_HELP_FOLDER
, helpbook
)
381 ART(wxART_HELP_PAGE
, helppage
)
382 //ART(wxART_ADD_BOOKMARK, addbookm)
383 //ART(wxART_DEL_BOOKMARK, delbookm)
384 ART(wxART_GO_BACK
, helpback
)
385 ART(wxART_GO_FORWARD
, helpforward
)
386 ART(wxART_GO_UP
, helpup
)
387 ART(wxART_GO_DOWN
, helpdown
)
388 ART(wxART_GO_TO_PARENT
, helpuplevel
)
389 ART(wxART_FILE_OPEN
, helpopen
)
390 if (client
== wxART_HELP_BROWSER
)
392 //ART(wxART_FRAME_ICON, helpicon)
393 ART(wxART_HELP
, helpicon
)
396 //ART(wxART_GO_HOME, home)
398 // Any wxWindows icons not implemented here
399 // will be provided by the default art provider.
405 wxConnectionBase
*hvServer::OnAcceptConnection(const wxString
& topic
)
407 if (topic
== wxT("HELP"))
408 return new hvConnection();
413 // ----------------------------------------------------------------------------
415 // ----------------------------------------------------------------------------
417 hvConnection::hvConnection()
420 wxGetApp().GetConnections().Append(this);
423 hvConnection::~hvConnection()
425 wxGetApp().GetConnections().DeleteObject(this);
428 bool hvConnection::OnExecute(const wxString
& WXUNUSED(topic
),
431 wxIPCFormat
WXUNUSED(format
))
433 // wxLogStatus("Execute command: %s", data);
435 if ( !wxStrncmp( data
, wxT("--intstring"), 11 ) )
438 wxString argStr
= data
;
439 wxString numb
= argStr
.AfterLast(wxT('g'));
440 if ( !(numb
.ToLong(&i
) ) )
442 wxLogError( wxT("Integer conversion failed for --intstring") );
446 wxGetApp().GetHelpController()->Display(int(i
));
451 wxGetApp().GetHelpController()->Display(data
);
457 bool hvConnection::OnPoke(const wxString
& WXUNUSED(topic
),
458 const wxString
& item
,
461 wxIPCFormat
WXUNUSED(format
))
463 // wxLogStatus("Poke command: %s = %s", item.c_str(), data);
464 //topic is not tested
466 if ( wxGetApp().GetHelpController() )
468 if ( item
== wxT("--AddBook") )
470 wxGetApp().GetHelpController()->AddBook(data
);
472 else if ( item
== wxT("--DisplayContents") )
474 wxGetApp().GetHelpController()->DisplayContents();
476 else if ( item
== wxT("--DisplayIndex") )
478 wxGetApp().GetHelpController()->DisplayIndex();
480 else if ( item
== wxT("--KeywordSearch") )
482 wxGetApp().GetHelpController()->KeywordSearch(data
);
484 else if ( item
== wxT("--SetTitleFormat") )
486 wxString newname
= data
;
487 newname
.Replace( wxT("_"), wxT(" ") );
488 wxGetApp().GetHelpController()->SetTitleFormat(newname
);
489 //does not redraw title bar?
490 //wxGetApp().GetHelpController()->ReFresh(); - or something
492 else if ( item
== wxT("--SetTempDir") )
494 wxGetApp().GetHelpController()->SetTempDir(data
);
496 else if ( item
== wxT("--YouAreDead") )
498 // don't really know how to kill app from down here...
499 // use wxKill from client instead
500 //wxWindow *win = wxTheApp->GetTopWindow();
509 wxChar
*hvConnection::OnRequest(const wxString
& WXUNUSED(topic
),
510 const wxString
& WXUNUSED(item
),
511 int * WXUNUSED(size
),
512 wxIPCFormat
WXUNUSED(format
))
517 bool hvConnection::OnStartAdvise(const wxString
& WXUNUSED(topic
),
518 const wxString
& WXUNUSED(item
))
523 #endif // #if hvUSE_IPC