]>
git.saurik.com Git - wxWidgets.git/blob - src/html/htmlhelp.cpp
2 // Purpose: Help controller
3 // Author: Vaclav Slavik
4 // Copyright: (c) 1999 Vaclav Slavik
5 // Licence: wxWindows Licence
6 /////////////////////////////////////////////////////////////////////////////
8 #error This file should not be compiled! Update your build system! \
9 (configure users, rerun configure to get a new Makefile) \
10 Instead of htmlhelp[_io], use helpdata, helpfrm and helpctrl. This \
11 file is only left to point out the problem and will be removed r.s.n.
14 #pragma implementation "htmlhelp.h"
17 #include "wx/wxprec.h"
28 #include <wx/notebook.h>
29 #include <wx/imaglist.h>
30 #include <wx/treectrl.h>
31 #include <wx/tokenzr.h>
32 #include <wx/wfstream.h>
33 #include <wx/html/htmlwin.h>
34 #include <wx/html/htmlhelp.h>
35 #include <wx/busyinfo.h>
37 #if !((wxVERSION_NUMBER < 2100) || ((wxVERSION_NUMBER == 2100) && (wxBETA_NUMBER < 7)))
38 #include <wx/progdlg.h>
45 // XPM hack: make the arrays const
46 #define static static const
48 #include "bitmaps/panel.xpm"
49 #include "bitmaps/back.xpm"
50 #include "bitmaps/forward.xpm"
51 #include "bitmaps/book.xpm"
52 #include "bitmaps/folder.xpm"
53 #include "bitmaps/page.xpm"
63 #include <wx/arrimpl.cpp>
64 WX_DEFINE_OBJARRAY ( HtmlBookRecArray
)
74 //-----------------------------------------------------------------------------
75 // wxHtmlHelpController
76 //-----------------------------------------------------------------------------
79 IMPLEMENT_DYNAMIC_CLASS ( wxHtmlHelpController
, wxEvtHandler
)
82 wxHtmlHelpController :: wxHtmlHelpController () : wxEvtHandler ()
86 m_ConfigRoot
= wxEmptyString
;
87 m_TitleFormat
= _ ( "Help : %s " );
88 m_TempPath
= wxEmptyString
;
90 m_Cfg
. x
= m_Cfg
. y
= 0 ;
91 m_Cfg
. w
= 700 ; m_Cfg
. h
= 480 ;
93 m_Cfg
. navig_on
= TRUE
;
95 m_ContentsImageList
= new wxImageList ( 12 , 12 );
96 m_ContentsImageList
-> Add ( wxICON ( book
));
97 m_ContentsImageList
-> Add ( wxICON ( folder
));
98 m_ContentsImageList
-> Add ( wxICON ( page
));
106 m_ContentsBox
= NULL
;
109 m_SearchButton
= NULL
;
117 wxHtmlHelpController ::~ wxHtmlHelpController ()
121 m_BookRecords
. Empty ();
122 delete m_ContentsImageList
;
124 for ( i
= 0 ; i
< m_ContentsCnt
; i
++) {
125 delete [] m_Contents
[ i
]. m_Page
;
126 delete [] m_Contents
[ i
]. m_Name
;
131 for ( i
= 0 ; i
< m_IndexCnt
; i
++) {
132 delete [] m_Index
[ i
]. m_Page
;
133 delete [] m_Index
[ i
]. m_Name
;
141 void wxHtmlHelpController :: SetTempDir ( const wxString
& path
)
143 if ( path
== wxEmptyString
) m_TempPath
= path
;
145 if ( wxIsAbsolutePath ( path
)) m_TempPath
= path
;
146 else m_TempPath
= wxGetCwd () + "/" + path
;
148 if ( m_TempPath
[ m_TempPath
. Length () - 1 ] != '/' )
156 // Reads one line, stores it into buf and returns pointer to new line or NULL.
157 static char * ReadLine ( char * line
, char * buf
)
159 char * writeptr
= buf
, * readptr
= line
;
161 while (* readptr
!= 0 && * readptr
!= ' \r ' && * readptr
!= ' \n ' ) *( writeptr
++) = *( readptr
++);
163 while (* readptr
== ' \r ' || * readptr
== ' \n ' ) readptr
++;
164 if (* readptr
== 0 ) return NULL
;
169 static wxString
SafeFileName ( const wxString
& s
)
172 res
. Replace ( _T ( ":" ), _T ( "_" ), TRUE
);
173 res
. Replace ( _T ( " " ), _T ( "_" ), TRUE
);
174 res
. Replace ( _T ( "/" ), _T ( "_" ), TRUE
);
175 res
. Replace ( _T ( " \\ " ), _T ( "_" ), TRUE
);
176 res
. Replace ( _T ( "#" ), _T ( "_" ), TRUE
);
177 res
. Replace ( _T ( "." ), _T ( "_" ), TRUE
);
182 static int IndexCompareFunc ( const void * a
, const void * b
)
184 return strcmp ((( HtmlContentsItem
*) a
) -> m_Name
, (( HtmlContentsItem
*) b
) -> m_Name
);
189 bool wxHtmlHelpController :: AddBook ( const wxString
& book
, bool show_wait_msg
)
194 HtmlBookRecord
* bookr
;
198 char * buff
, * lineptr
;
201 wxString title
= _ ( "noname" ),
203 start
= wxEmptyString
,
204 contents
= wxEmptyString
, index
= wxEmptyString
;
206 if ( wxIsAbsolutePath ( book
)) bookFull
= book
;
207 else bookFull
= wxGetCwd () + "/" + book
;
209 fi
= fsys
. OpenFile ( bookFull
);
210 if ( fi
== NULL
) return FALSE
;
211 fsys
. ChangePathTo ( bookFull
);
212 s
= fi
-> GetStream ();
214 buff
= new char [ sz
+ 1 ];
220 while (( lineptr
= ReadLine ( lineptr
, linebuf
)) != NULL
) {
221 if ( strstr ( linebuf
, "Title=" ) == linebuf
)
222 title
= linebuf
+ strlen ( "Title=" );
223 if ( strstr ( linebuf
, "Default topic=" ) == linebuf
)
224 start
= linebuf
+ strlen ( "Default topic=" );
225 if ( strstr ( linebuf
, "Index file=" ) == linebuf
)
226 index
= linebuf
+ strlen ( "Index file=" );
227 if ( strstr ( linebuf
, "Contents file=" ) == linebuf
)
228 contents
= linebuf
+ strlen ( "Contents file=" );
232 bookr
= new HtmlBookRecord ( fsys
. GetPath (), title
, start
);
234 if ( m_ContentsCnt
% HTML_REALLOC_STEP
== 0 )
235 m_Contents
= ( HtmlContentsItem
*) realloc ( m_Contents
, ( m_ContentsCnt
+ HTML_REALLOC_STEP
) * sizeof ( HtmlContentsItem
));
236 m_Contents
[ m_ContentsCnt
]. m_Level
= 0 ;
237 m_Contents
[ m_ContentsCnt
]. m_ID
= 0 ;
238 m_Contents
[ m_ContentsCnt
]. m_Page
= new char [ start
. Length () + 1 ];
239 strcpy ( m_Contents
[ m_ContentsCnt
]. m_Page
, start
. c_str ());
240 m_Contents
[ m_ContentsCnt
]. m_Name
= new char [ title
. Length () + 1 ];
241 strcpy ( m_Contents
[ m_ContentsCnt
]. m_Name
, title
. c_str ());
242 m_Contents
[ m_ContentsCnt
]. m_Book
= bookr
;
245 // Try to find cached binary versions:
246 safetitle
= SafeFileName ( title
);
247 fi
= fsys
. OpenFile ( safetitle
+ ".cached" );
248 if ( fi
== NULL
) fi
= fsys
. OpenFile ( m_TempPath
+ safetitle
+ ".cached" );
249 if (( fi
== NULL
) || ( m_TempPath
== wxEmptyString
)) {
250 LoadMSProject ( bookr
, fsys
, index
, contents
, show_wait_msg
);
251 if ( m_TempPath
!= wxEmptyString
) {
252 wxFileOutputStream
* outs
= new wxFileOutputStream ( m_TempPath
+ safetitle
+ ".cached" );
253 SaveCachedBook ( bookr
, outs
);
258 LoadCachedBook ( bookr
, fi
-> GetStream ());
262 m_BookRecords
. Add ( bookr
);
264 qsort ( m_Index
, m_IndexCnt
, sizeof ( HtmlContentsItem
), IndexCompareFunc
);
272 void wxHtmlHelpController :: Display ( const wxString
& x
)
281 /* 1. try to open given file: */
283 cnt
= m_BookRecords
. GetCount ();
284 for ( i
= 0 ; i
< cnt
; i
++) {
285 f
= fsys
. OpenFile ( m_BookRecords
[ i
]. GetBasePath () + x
);
287 m_HtmlWin
-> LoadPage ( m_BookRecords
[ i
]. GetBasePath () + x
);
294 /* 2. try to find a book: */
296 for ( i
= 0 ; i
< cnt
; i
++) {
297 if ( m_BookRecords
[ i
]. GetTitle () == x
) {
298 m_HtmlWin
-> LoadPage ( m_BookRecords
[ i
]. GetBasePath () + m_BookRecords
[ i
]. GetStart ());
303 /* 3. try to find in contents: */
306 for ( i
= 0 ; i
< cnt
; i
++) {
307 if ( strcmp ( m_Contents
[ i
]. m_Name
, x
) == 0 ) {
308 m_HtmlWin
-> LoadPage ( m_Contents
[ i
]. m_Book
-> GetBasePath () + m_Contents
[ i
]. m_Page
);
314 /* 4. try to find in index: */
317 for ( i
= 0 ; i
< cnt
; i
++) {
318 if ( strcmp ( m_Index
[ i
]. m_Name
, x
) == 0 ) {
319 m_HtmlWin
-> LoadPage ( m_Index
[ i
]. m_Book
-> GetBasePath () + m_Index
[ i
]. m_Page
);
325 /* 5. if everything failed, search the documents: */
332 void wxHtmlHelpController :: Display ( const int id
)
336 for ( int i
= 0 ; i
< m_ContentsCnt
; i
++) {
337 if ( m_Contents
[ i
]. m_ID
== id
) {
338 m_HtmlWin
-> LoadPage ( m_Contents
[ i
]. m_Book
-> GetBasePath () + m_Contents
[ i
]. m_Page
);
346 void wxHtmlHelpController :: DisplayContents ()
350 if (! m_Splitter
-> IsSplit ()) {
351 m_NavigPan
-> Show ( TRUE
);
352 m_HtmlWin
-> Show ( TRUE
);
353 m_Splitter
-> SplitVertically ( m_NavigPan
, m_HtmlWin
, m_Cfg
. sashpos
);
355 m_NavigPan
-> SetSelection ( 0 );
360 void wxHtmlHelpController :: DisplayIndex ()
364 if (! m_Splitter
-> IsSplit ()) {
365 m_NavigPan
-> Show ( TRUE
);
366 m_HtmlWin
-> Show ( TRUE
);
367 m_Splitter
-> SplitVertically ( m_NavigPan
, m_HtmlWin
, m_Cfg
. sashpos
);
369 m_NavigPan
-> SetSelection ( 1 );
375 #if (wxVERSION_NUMBER < 2100) || ((wxVERSION_NUMBER == 2100) && (wxBETA_NUMBER < 7))
377 class MyProgressDlg
: public wxDialog
382 MyProgressDlg ( wxWindow
* parent
) : wxDialog ( parent
, - 1 ,
391 { m_Canceled
= FALSE
;}
392 void OnCancel ( wxCommandEvent
& event
) { m_Canceled
= TRUE
;}
393 DECLARE_EVENT_TABLE ()
395 BEGIN_EVENT_TABLE ( MyProgressDlg
, wxDialog
)
396 EVT_BUTTON ( wxID_CANCEL
, MyProgressDlg :: OnCancel
)
402 bool wxHtmlHelpController :: KeywordSearch ( const wxString
& keyword
)
406 // if these are not set, we can't continue
407 if (! ( m_SearchList
&& m_HtmlWin
))
410 if ( m_Splitter
&& m_NavigPan
&& m_SearchButton
) {
411 if (! m_Splitter
-> IsSplit ()) {
412 m_NavigPan
-> Show ( TRUE
);
413 m_HtmlWin
-> Show ( TRUE
);
414 m_Splitter
-> SplitVertically ( m_NavigPan
, m_HtmlWin
, m_Cfg
. sashpos
);
416 m_NavigPan
-> SetSelection ( 2 );
417 m_SearchList
-> Clear ();
418 m_SearchText
-> SetValue ( keyword
);
419 m_SearchButton
-> Enable ( FALSE
);
422 int cnt
= m_ContentsCnt
;
423 wxSearchEngine engine
;
426 wxString lastpage
= wxEmptyString
;
429 #if (wxVERSION_NUMBER < 2100) || ((wxVERSION_NUMBER == 2100) && (wxBETA_NUMBER < 7))
430 MyProgressDlg
progress ( m_Frame
);
432 wxStaticText
* prompt
= new wxStaticText (& progress
, - 1 , "" , wxPoint ( 20 , 50 ), wxSize ( 260 , 25 ), wxALIGN_CENTER
);
433 wxGauge
* gauge
= new wxGauge (& progress
, - 1 , cnt
, wxPoint ( 20 , 20 ), wxSize ( 260 , 25 ));
434 wxButton
* btn
= new wxButton (& progress
, wxID_CANCEL
, _ ( "Cancel" ), wxPoint ( 110 , 70 ), wxSize ( 80 , 25 ));
435 btn
= btn
; /* fool compiler :-) */
436 prompt
-> SetLabel ( _ ( "No matching page found yet" ));
438 progress
. Centre ( wxBOTH
);
441 wxProgressDialog
progress ( _ ( "Searching..." ), _ ( "No matching page found yet" ), cnt
, m_Frame
, wxPD_APP_MODAL
| wxPD_CAN_ABORT
| wxPD_AUTO_HIDE
);
444 engine
. LookFor ( keyword
);
446 for ( int i
= 0 ; i
< cnt
; i
++) {
447 #if (wxVERSION_NUMBER < 2100) || ((wxVERSION_NUMBER == 2100) && (wxBETA_NUMBER < 7))
448 gauge
-> SetValue ( i
);
449 if ( progress
. m_Canceled
) break ;
451 if ( progress
. Update ( i
) == FALSE
) break ;
455 file
= fsys
. OpenFile ( m_Contents
[ i
]. m_Book
-> GetBasePath () + m_Contents
[ i
]. m_Page
);
457 if ( lastpage
!= file
-> GetLocation ()) {
458 lastpage
= file
-> GetLocation ();
459 if ( engine
. Scan ( file
-> GetStream ())) {
460 foundstr
. Printf ( _ ( "Found %i matches" ), ++ foundcnt
);
461 #if (wxVERSION_NUMBER < 2100) || ((wxVERSION_NUMBER == 2100) && (wxBETA_NUMBER < 7))
462 prompt
-> SetLabel ( foundstr
);
464 progress
. Update ( i
, foundstr
);
467 m_SearchList
-> Append ( m_Contents
[ i
]. m_Name
, ( char *)( m_Contents
+ i
));
474 #if (wxVERSION_NUMBER < 2100) || ((wxVERSION_NUMBER == 2100) && (wxBETA_NUMBER < 7))
475 progress
. Close ( TRUE
);
479 m_SearchButton
-> Enable ( TRUE
);
481 m_SearchText
-> SetSelection ( 0 , keyword
. Length ());
482 m_SearchText
-> SetFocus ();
485 HtmlContentsItem
* it
= ( HtmlContentsItem
*) m_SearchList
-> GetClientData ( 0 );
486 if ( it
) m_HtmlWin
-> LoadPage ( it
-> m_Book
-> GetBasePath () + it
-> m_Page
);
488 return ( foundcnt
> 0 );
496 void wxHtmlHelpController :: CreateHelpWindow ()
504 m_Frame
-> Show ( TRUE
);
509 wxBusyInfo
busyinfo ( _ ( "Preparing help window..." ));
512 if ( m_Config
) ReadCustomization ( m_Config
, m_ConfigRoot
);
514 m_Frame
= new wxFrame ( NULL
, - 1 , "" , wxPoint ( m_Cfg
. x
, m_Cfg
. y
), wxSize ( m_Cfg
. w
, m_Cfg
. h
));
515 m_Frame
-> PushEventHandler ( this );
516 sbar
= m_Frame
-> CreateStatusBar ();
520 toolBar
= m_Frame
-> CreateToolBar ( wxNO_BORDER
| wxTB_HORIZONTAL
| wxTB_FLAT
| wxTB_DOCKABLE
);
521 toolBar
-> SetMargins ( 2 , 2 );
522 wxBitmap
* toolBarBitmaps
[ 3 ];
525 toolBarBitmaps
[ 0 ] = new wxBitmap ( "panel" );
526 toolBarBitmaps
[ 1 ] = new wxBitmap ( "back" );
527 toolBarBitmaps
[ 2 ] = new wxBitmap ( "forward" );
530 toolBarBitmaps
[ 0 ] = new wxBitmap ( panel_xpm
);
531 toolBarBitmaps
[ 1 ] = new wxBitmap ( back_xpm
);
532 toolBarBitmaps
[ 2 ] = new wxBitmap ( forward_xpm
);
538 toolBar
-> AddTool ( wxID_HTML_PANEL
, *( toolBarBitmaps
[ 0 ]), wxNullBitmap
, FALSE
, currentX
, - 1 , ( wxObject
*) NULL
, _ ( "Show/hide navigation panel" ));
539 currentX
+= width
+ 5 ;
540 toolBar
-> AddSeparator ();
541 toolBar
-> AddTool ( wxID_HTML_BACK
, *( toolBarBitmaps
[ 1 ]), wxNullBitmap
, FALSE
, currentX
, - 1 , ( wxObject
*) NULL
, _ ( "Go back to the previous HTML page" ));
542 currentX
+= width
+ 5 ;
543 toolBar
-> AddTool ( wxID_HTML_FORWARD
, *( toolBarBitmaps
[ 2 ]), wxNullBitmap
, FALSE
, currentX
, - 1 , ( wxObject
*) NULL
, _ ( "Go forward to the next HTML page" ));
544 currentX
+= width
+ 5 ;
546 toolBar
-> Realize ();
548 // Can delete the bitmaps since they're reference counted
549 for ( int i
= 0 ; i
< 3 ; i
++) delete toolBarBitmaps
[ i
];
554 m_Splitter
= new wxSplitterWindow ( m_Frame
);
556 m_HtmlWin
= new wxHtmlWindow ( m_Splitter
);
557 m_HtmlWin
-> SetRelatedFrame ( m_Frame
, m_TitleFormat
);
558 m_HtmlWin
-> SetRelatedStatusBar ( 0 );
559 if ( m_Config
) m_HtmlWin
-> ReadCustomization ( m_Config
, m_ConfigRoot
);
561 m_NavigPan
= new wxNotebook ( m_Splitter
, wxID_HTML_NOTEBOOK
, wxDefaultPosition
, wxDefaultSize
);
563 m_ContentsBox
= new wxTreeCtrl ( m_NavigPan
, wxID_HTML_TREECTRL
, wxDefaultPosition
, wxDefaultSize
, wxTR_HAS_BUTTONS
| wxSUNKEN_BORDER
);
564 m_ContentsBox
-> SetImageList ( m_ContentsImageList
);
565 m_NavigPan
-> AddPage ( m_ContentsBox
, _ ( "Contents" ));
569 wxWindow
* dummy
= new wxPanel ( m_NavigPan
, wxID_HTML_INDEXPAGE
);
570 wxLayoutConstraints
* b1
= new wxLayoutConstraints
;
571 b1
-> top
. SameAs ( dummy
, wxTop
, 0 );
572 b1
-> left
. SameAs ( dummy
, wxLeft
, 0 );
573 b1
-> width
. PercentOf ( dummy
, wxWidth
, 100 );
574 b1
-> bottom
. SameAs ( dummy
, wxBottom
, 0 );
575 m_IndexBox
= new wxListBox ( dummy
, wxID_HTML_INDEXLIST
, wxDefaultPosition
, wxDefaultSize
, 0 );
576 m_IndexBox
-> SetConstraints ( b1
);
577 dummy
-> SetAutoLayout ( TRUE
);
578 m_NavigPan
-> AddPage ( dummy
, _ ( "Index" ));
582 wxWindow
* dummy
= new wxPanel ( m_NavigPan
, wxID_HTML_SEARCHPAGE
);
584 wxLayoutConstraints
* b1
= new wxLayoutConstraints
;
585 m_SearchText
= new wxTextCtrl ( dummy
, wxID_HTML_SEARCHTEXT
);
586 b1
-> top
. SameAs ( dummy
, wxTop
, 0 );
587 b1
-> left
. SameAs ( dummy
, wxLeft
, 0 );
588 b1
-> right
. SameAs ( dummy
, wxRight
, 0 );
590 m_SearchText
-> SetConstraints ( b1
);
592 wxLayoutConstraints
* b2
= new wxLayoutConstraints
;
593 m_SearchButton
= new wxButton ( dummy
, wxID_HTML_SEARCHBUTTON
, _ ( "Search!" ));
594 b2
-> top
. Below ( m_SearchText
, 10 );
595 b2
-> right
. SameAs ( dummy
, wxRight
, 10 );
598 m_SearchButton
-> SetConstraints ( b2
);
600 wxLayoutConstraints
* b3
= new wxLayoutConstraints
;
601 m_SearchList
= new wxListBox ( dummy
, wxID_HTML_SEARCHLIST
, wxDefaultPosition
, wxDefaultSize
, 0 );
602 b3
-> top
. Below ( m_SearchButton
, 10 );
603 b3
-> left
. SameAs ( dummy
, wxLeft
, 0 );
604 b3
-> right
. SameAs ( dummy
, wxRight
, 0 );
605 b3
-> bottom
. SameAs ( dummy
, wxBottom
, 0 );
606 m_SearchList
-> SetConstraints ( b3
);
608 dummy
-> SetAutoLayout ( TRUE
);
610 m_NavigPan
-> AddPage ( dummy
, _ ( "Search" ));
614 m_NavigPan
-> Show ( TRUE
);
615 m_HtmlWin
-> Show ( TRUE
);
616 m_Splitter
-> SetMinimumPaneSize ( 20 );
617 m_Splitter
-> SplitVertically ( m_NavigPan
, m_HtmlWin
, m_Cfg
. sashpos
);
618 if (! m_Cfg
. navig_on
) m_Splitter
-> Unsplit ( m_NavigPan
);
622 m_Frame
-> Show ( TRUE
);
630 void wxHtmlHelpController :: CreateContents ()
632 HtmlContentsItem
* it
;
633 wxTreeItemId roots
[ MAX_ROOTS
];
634 bool imaged
[ MAX_ROOTS
];
635 int count
= m_ContentsCnt
;
637 m_ContentsBox
-> DeleteAllItems ();
638 roots
[ 0 ] = m_ContentsBox
-> AddRoot ( _ ( "(Help)" ));
641 for ( int i
= 0 ; i
< count
; i
++) {
643 roots
[ it
-> m_Level
+ 1 ] = m_ContentsBox
-> AppendItem ( roots
[ it
-> m_Level
], it
-> m_Name
, IMG_Page
, - 1 , new wxHtmlHelpTreeItemData ( it
));
644 if ( it
-> m_Level
== 0 ) {
645 m_ContentsBox
-> SetItemBold ( roots
[ 1 ], TRUE
);
646 m_ContentsBox
-> SetItemImage ( roots
[ 1 ], IMG_Book
);
647 m_ContentsBox
-> SetItemSelectedImage ( roots
[ 1 ], IMG_Book
);
650 else imaged
[ it
-> m_Level
+ 1 ] = FALSE
;
652 if (! imaged
[ it
-> m_Level
]) {
653 m_ContentsBox
-> SetItemImage ( roots
[ it
-> m_Level
], IMG_Folder
);
654 m_ContentsBox
-> SetItemSelectedImage ( roots
[ it
-> m_Level
], IMG_Folder
);
655 imaged
[ it
-> m_Level
] = TRUE
;
659 m_ContentsBox
-> Expand ( roots
[ 0 ]);
665 void wxHtmlHelpController :: CreateIndex ()
667 m_IndexBox
-> Clear ();
669 for ( int i
= 0 ; i
< m_IndexCnt
; i
++)
670 m_IndexBox
-> Append ( m_Index
[ i
]. m_Name
, ( char *)( m_Index
+ i
));
675 void wxHtmlHelpController :: RefreshLists ()
680 m_SearchList
-> Clear ();
690 void wxHtmlHelpController :: ReadCustomization ( wxConfigBase
* cfg
, wxString path
)
695 if ( path
!= wxEmptyString
) {
696 oldpath
= cfg
-> GetPath ();
697 cfg
-> SetPath ( path
);
700 m_Cfg
. navig_on
= cfg
-> Read ( "hcNavigPanel" , m_Cfg
. navig_on
) != 0 ;
701 m_Cfg
. sashpos
= cfg
-> Read ( "hcSashPos" , m_Cfg
. sashpos
);
702 m_Cfg
. x
= cfg
-> Read ( "hcX" , m_Cfg
. x
);
703 m_Cfg
. y
= cfg
-> Read ( "hcY" , m_Cfg
. y
);
704 m_Cfg
. w
= cfg
-> Read ( "hcW" , m_Cfg
. w
);
705 m_Cfg
. h
= cfg
-> Read ( "hcH" , m_Cfg
. h
);
707 if ( path
!= wxEmptyString
)
708 cfg
-> SetPath ( oldpath
);
713 void wxHtmlHelpController :: WriteCustomization ( wxConfigBase
* cfg
, wxString path
)
718 if ( path
!= wxEmptyString
) {
719 oldpath
= cfg
-> GetPath ();
720 cfg
-> SetPath ( path
);
723 cfg
-> Write ( "hcNavigPanel" , m_Cfg
. navig_on
);
724 cfg
-> Write ( "hcSashPos" , ( long ) m_Cfg
. sashpos
);
725 cfg
-> Write ( "hcX" , ( long ) m_Cfg
. x
);
726 cfg
-> Write ( "hcY" , ( long ) m_Cfg
. y
);
727 cfg
-> Write ( "hcW" , ( long ) m_Cfg
. w
);
728 cfg
-> Write ( "hcH" , ( long ) m_Cfg
. h
);
730 if ( path
!= wxEmptyString
)
731 cfg
-> SetPath ( oldpath
);
743 void wxHtmlHelpController :: OnToolbar ( wxCommandEvent
& event
)
745 switch ( event
. GetId ()) {
746 case wxID_HTML_BACK
:
747 m_HtmlWin
-> HistoryBack ();
749 case wxID_HTML_FORWARD
:
750 m_HtmlWin
-> HistoryForward ();
752 case wxID_HTML_PANEL
:
753 if ( m_Splitter
-> IsSplit ()) {
754 m_Cfg
. sashpos
= m_Splitter
-> GetSashPosition ();
755 m_Splitter
-> Unsplit ( m_NavigPan
);
758 m_NavigPan
-> Show ( TRUE
);
759 m_HtmlWin
-> Show ( TRUE
);
760 m_Splitter
-> SplitVertically ( m_NavigPan
, m_HtmlWin
, m_Cfg
. sashpos
);
768 void wxHtmlHelpController :: OnContentsSel ( wxTreeEvent
& event
)
770 wxHtmlHelpTreeItemData
* pg
;
772 pg
= ( wxHtmlHelpTreeItemData
*) m_ContentsBox
-> GetItemData ( event
. GetItem ());
773 if ( pg
) m_HtmlWin
-> LoadPage ( pg
-> GetPage ());
778 void wxHtmlHelpController :: OnIndexSel ( wxCommandEvent
& event
)
780 HtmlContentsItem
* it
= ( HtmlContentsItem
*) m_IndexBox
-> GetClientData ( m_IndexBox
-> GetSelection ());
781 if ( it
) m_HtmlWin
-> LoadPage ( it
-> m_Book
-> GetBasePath () + it
-> m_Page
);
786 void wxHtmlHelpController :: OnSearchSel ( wxCommandEvent
& event
)
788 HtmlContentsItem
* it
= ( HtmlContentsItem
*) m_SearchList
-> GetClientData ( m_SearchList
-> GetSelection ());
789 if ( it
) m_HtmlWin
-> LoadPage ( it
-> m_Book
-> GetBasePath () + it
-> m_Page
);
794 void wxHtmlHelpController :: OnCloseWindow ( wxCloseEvent
& event
)
798 m_Cfg
. navig_on
= m_Splitter
-> IsSplit ();
800 m_Cfg
. sashpos
= m_Splitter
-> GetSashPosition ();
801 m_Frame
-> GetPosition (& a
, & b
);
802 m_Cfg
. x
= a
, m_Cfg
. y
= b
;
803 m_Frame
-> GetSize (& a
, & b
);
804 m_Cfg
. w
= a
, m_Cfg
. h
= b
;
807 WriteCustomization ( m_Config
, m_ConfigRoot
);
808 m_HtmlWin
-> WriteCustomization ( m_Config
, m_ConfigRoot
);
817 void wxHtmlHelpController :: OnSearch ( wxCommandEvent
& event
)
819 wxString sr
= m_SearchText
-> GetLineText ( 0 );
821 if ( sr
!= wxEmptyString
) KeywordSearch ( sr
);
826 BEGIN_EVENT_TABLE ( wxHtmlHelpController
, wxEvtHandler
)
827 EVT_TOOL_RANGE ( wxID_HTML_PANEL
, wxID_HTML_FORWARD
, wxHtmlHelpController :: OnToolbar
)
828 EVT_TREE_SEL_CHANGED ( wxID_HTML_TREECTRL
, wxHtmlHelpController :: OnContentsSel
)
829 EVT_LISTBOX ( wxID_HTML_INDEXLIST
, wxHtmlHelpController :: OnIndexSel
)
830 EVT_LISTBOX ( wxID_HTML_SEARCHLIST
, wxHtmlHelpController :: OnSearchSel
)
831 EVT_CLOSE ( wxHtmlHelpController :: OnCloseWindow
)
832 EVT_BUTTON ( wxID_HTML_SEARCHBUTTON
, wxHtmlHelpController :: OnSearch
)
833 EVT_TEXT_ENTER ( wxID_HTML_SEARCHTEXT
, wxHtmlHelpController :: OnSearch
)