]>
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 /////////////////////////////////////////////////////////////////////////////
10 #pragma implementation "htmlhelp.h"
13 #include "wx/wxprec.h"
26 #include <wx/notebook.h>
27 #include <wx/imaglist.h>
28 #include <wx/treectrl.h>
29 #include <wx/tokenzr.h>
30 #include <wx/wfstream.h>
31 #include <wx/html/htmlwin.h>
32 #include <wx/html/htmlhelp.h>
33 #include <wx/busyinfo.h>
35 #if !((wxVERSION_NUMBER < 2100) || ((wxVERSION_NUMBER == 2100) && (wxBETA_NUMBER < 7)))
36 #include <wx/progdlg.h>
43 #include "bitmaps/panel.xpm"
44 #include "bitmaps/back.xpm"
45 #include "bitmaps/forward.xpm"
46 #include "bitmaps/book.xpm"
47 #include "bitmaps/folder.xpm"
48 #include "bitmaps/page.xpm"
56 #include <wx/arrimpl.cpp>
57 WX_DEFINE_OBJARRAY ( HtmlBookRecArray
)
67 //-----------------------------------------------------------------------------
68 // wxHtmlHelpController
69 //-----------------------------------------------------------------------------
72 IMPLEMENT_DYNAMIC_CLASS ( wxHtmlHelpController
, wxEvtHandler
)
75 wxHtmlHelpController :: wxHtmlHelpController () : wxEvtHandler ()
79 m_ConfigRoot
= wxEmptyString
;
80 m_TitleFormat
= _ ( "Help : %s " );
81 m_TempPath
= wxEmptyString
;
83 m_Cfg
. x
= m_Cfg
. y
= 0 ;
84 m_Cfg
. w
= 700 ; m_Cfg
. h
= 480 ;
86 m_Cfg
. navig_on
= TRUE
;
88 m_ContentsImageList
= new wxImageList ( 12 , 12 );
89 m_ContentsImageList
-> Add ( wxICON ( book
));
90 m_ContentsImageList
-> Add ( wxICON ( folder
));
91 m_ContentsImageList
-> Add ( wxICON ( page
));
102 m_SearchButton
= NULL
;
110 wxHtmlHelpController ::~ wxHtmlHelpController ()
114 m_BookRecords
. Empty ();
115 delete m_ContentsImageList
;
117 for ( i
= 0 ; i
< m_ContentsCnt
; i
++) {
118 delete [] m_Contents
[ i
]. m_Page
;
119 delete [] m_Contents
[ i
]. m_Name
;
124 for ( i
= 0 ; i
< m_IndexCnt
; i
++) {
125 delete [] m_Index
[ i
]. m_Page
;
126 delete [] m_Index
[ i
]. m_Name
;
134 void wxHtmlHelpController :: SetTempDir ( const wxString
& path
)
136 if ( path
== wxEmptyString
) m_TempPath
= path
;
138 if ( wxIsAbsolutePath ( path
)) m_TempPath
= path
;
139 else m_TempPath
= wxGetCwd () + "/" + path
;
141 if ( m_TempPath
[ m_TempPath
. Length () - 1 ] != '/' )
149 // Reads one line, stores it into buf and returns pointer to new line or NULL.
150 static char * ReadLine ( char * line
, char * buf
)
152 char * writeptr
= buf
, * readptr
= line
;
154 while (* readptr
!= 0 && * readptr
!= ' \r ' && * readptr
!= ' \n ' ) *( writeptr
++) = *( readptr
++);
156 while (* readptr
== ' \r ' || * readptr
== ' \n ' ) readptr
++;
157 if (* readptr
== 0 ) return NULL
;
162 static wxString
SafeFileName ( const wxString
& s
)
165 res
. Replace ( ":" , "_" , TRUE
);
166 res
. Replace ( " " , "_" , TRUE
);
167 res
. Replace ( "/" , "_" , TRUE
);
168 res
. Replace ( " \\ " , "_" , TRUE
);
169 res
. Replace ( "#" , "_" , TRUE
);
170 res
. Replace ( "." , "_" , TRUE
);
175 static int IndexCompareFunc ( const void * a
, const void * b
)
177 return strcmp ((( HtmlContentsItem
*) a
) -> m_Name
, (( HtmlContentsItem
*) b
) -> m_Name
);
182 bool wxHtmlHelpController :: AddBook ( const wxString
& book
, bool show_wait_msg
)
187 HtmlBookRecord
* bookr
;
191 char * buff
, * lineptr
;
194 wxString title
= _ ( "noname" ),
196 start
= wxEmptyString
,
197 contents
= wxEmptyString
, index
= wxEmptyString
;
199 if ( wxIsAbsolutePath ( book
)) bookFull
= book
;
200 else bookFull
= wxGetCwd () + "/" + book
;
202 fi
= fsys
. OpenFile ( bookFull
);
203 if ( fi
== NULL
) return FALSE
;
204 fsys
. ChangePathTo ( bookFull
);
205 s
= fi
-> GetStream ();
207 buff
= new char [ sz
+ 1 ];
213 while (( lineptr
= ReadLine ( lineptr
, linebuf
)) != NULL
) {
214 if ( strstr ( linebuf
, "Title=" ) == linebuf
)
215 title
= linebuf
+ strlen ( "Title=" );
216 if ( strstr ( linebuf
, "Default topic=" ) == linebuf
)
217 start
= linebuf
+ strlen ( "Default topic=" );
218 if ( strstr ( linebuf
, "Index file=" ) == linebuf
)
219 index
= linebuf
+ strlen ( "Index file=" );
220 if ( strstr ( linebuf
, "Contents file=" ) == linebuf
)
221 contents
= linebuf
+ strlen ( "Contents file=" );
225 bookr
= new HtmlBookRecord ( fsys
. GetPath (), title
, start
);
227 if ( m_ContentsCnt
% HTML_REALLOC_STEP
== 0 )
228 m_Contents
= ( HtmlContentsItem
*) realloc ( m_Contents
, ( m_ContentsCnt
+ HTML_REALLOC_STEP
) * sizeof ( HtmlContentsItem
));
229 m_Contents
[ m_ContentsCnt
]. m_Level
= 0 ;
230 m_Contents
[ m_ContentsCnt
]. m_ID
= 0 ;
231 m_Contents
[ m_ContentsCnt
]. m_Page
= new char [ start
. Length () + 1 ];
232 strcpy ( m_Contents
[ m_ContentsCnt
]. m_Page
, start
. c_str ());
233 m_Contents
[ m_ContentsCnt
]. m_Name
= new char [ title
. Length () + 1 ];
234 strcpy ( m_Contents
[ m_ContentsCnt
]. m_Name
, title
. c_str ());
235 m_Contents
[ m_ContentsCnt
]. m_Book
= bookr
;
238 // Try to find cached binary versions:
239 safetitle
= SafeFileName ( title
);
240 fi
= fsys
. OpenFile ( safetitle
+ ".cached" );
241 if ( fi
== NULL
) fi
= fsys
. OpenFile ( m_TempPath
+ safetitle
+ ".cached" );
242 if (( fi
== NULL
) || ( m_TempPath
== wxEmptyString
)) {
243 LoadMSProject ( bookr
, fsys
, index
, contents
, show_wait_msg
);
244 if ( m_TempPath
!= wxEmptyString
) {
245 wxFileOutputStream
* outs
= new wxFileOutputStream ( m_TempPath
+ safetitle
+ ".cached" );
246 SaveCachedBook ( bookr
, outs
);
251 LoadCachedBook ( bookr
, fi
-> GetStream ());
255 m_BookRecords
. Add ( bookr
);
257 qsort ( m_Index
, m_IndexCnt
, sizeof ( HtmlContentsItem
), IndexCompareFunc
);
265 void wxHtmlHelpController :: Display ( const wxString
& x
)
274 /* 1. try to open given file: */
276 cnt
= m_BookRecords
. GetCount ();
277 for ( i
= 0 ; i
< cnt
; i
++) {
278 f
= fsys
. OpenFile ( m_BookRecords
[ i
]. GetBasePath () + x
);
280 m_HtmlWin
-> LoadPage ( m_BookRecords
[ i
]. GetBasePath () + x
);
287 /* 2. try to find a book: */
289 for ( i
= 0 ; i
< cnt
; i
++) {
290 if ( m_BookRecords
[ i
]. GetTitle () == x
) {
291 m_HtmlWin
-> LoadPage ( m_BookRecords
[ i
]. GetBasePath () + m_BookRecords
[ i
]. GetStart ());
296 /* 3. try to find in contents: */
299 for ( i
= 0 ; i
< cnt
; i
++) {
300 if ( strcmp ( m_Contents
[ i
]. m_Name
, x
) == 0 ) {
301 m_HtmlWin
-> LoadPage ( m_Contents
[ i
]. m_Book
-> GetBasePath () + m_Contents
[ i
]. m_Page
);
307 /* 4. try to find in index: */
310 for ( i
= 0 ; i
< cnt
; i
++) {
311 if ( strcmp ( m_Index
[ i
]. m_Name
, x
) == 0 ) {
312 m_HtmlWin
-> LoadPage ( m_Index
[ i
]. m_Book
-> GetBasePath () + m_Index
[ i
]. m_Page
);
318 /* 5. if everything failed, search the documents: */
325 void wxHtmlHelpController :: Display ( const int id
)
329 for ( int i
= 0 ; i
< m_ContentsCnt
; i
++) {
330 if ( m_Contents
[ i
]. m_ID
== id
) {
331 m_HtmlWin
-> LoadPage ( m_Contents
[ i
]. m_Book
-> GetBasePath () + m_Contents
[ i
]. m_Page
);
339 void wxHtmlHelpController :: DisplayContents ()
343 if (! m_Splitter
-> IsSplit ()) {
344 m_NavigPan
-> Show ( TRUE
);
345 m_HtmlWin
-> Show ( TRUE
);
346 m_Splitter
-> SplitVertically ( m_NavigPan
, m_HtmlWin
, m_Cfg
. sashpos
);
348 m_NavigPan
-> SetSelection ( 0 );
353 void wxHtmlHelpController :: DisplayIndex ()
357 if (! m_Splitter
-> IsSplit ()) {
358 m_NavigPan
-> Show ( TRUE
);
359 m_HtmlWin
-> Show ( TRUE
);
360 m_Splitter
-> SplitVertically ( m_NavigPan
, m_HtmlWin
, m_Cfg
. sashpos
);
362 m_NavigPan
-> SetSelection ( 1 );
368 #if (wxVERSION_NUMBER < 2100) || ((wxVERSION_NUMBER == 2100) && (wxBETA_NUMBER < 7))
370 class MyProgressDlg
: public wxDialog
375 MyProgressDlg ( wxWindow
* parent
) : wxDialog ( parent
, - 1 ,
383 { m_Canceled
= FALSE
;}
384 void OnCancel ( wxCommandEvent
& event
) { m_Canceled
= TRUE
;}
385 DECLARE_EVENT_TABLE ()
387 BEGIN_EVENT_TABLE ( MyProgressDlg
, wxDialog
)
388 EVT_BUTTON ( wxID_CANCEL
, MyProgressDlg :: OnCancel
)
394 bool wxHtmlHelpController :: KeywordSearch ( const wxString
& keyword
)
398 // if these are not set, we can't continue
399 if (! ( m_SearchList
&& m_HtmlWin
))
402 if ( m_Splitter
&& m_NavigPan
&& m_SearchButton
) {
403 if (! m_Splitter
-> IsSplit ()) {
404 m_NavigPan
-> Show ( TRUE
);
405 m_HtmlWin
-> Show ( TRUE
);
406 m_Splitter
-> SplitVertically ( m_NavigPan
, m_HtmlWin
, m_Cfg
. sashpos
);
408 m_NavigPan
-> SetSelection ( 2 );
409 m_SearchList
-> Clear ();
410 m_SearchText
-> SetValue ( keyword
);
411 m_SearchButton
-> Enable ( FALSE
);
414 int cnt
= m_ContentsCnt
;
415 wxSearchEngine engine
;
418 wxString lastpage
= wxEmptyString
;
421 #if (wxVERSION_NUMBER < 2100) || ((wxVERSION_NUMBER == 2100) && (wxBETA_NUMBER < 7))
422 MyProgressDlg
progress ( m_Frame
);
424 wxStaticText
* prompt
= new wxStaticText (& progress
, - 1 , "" , wxPoint ( 20 , 50 ), wxSize ( 260 , 25 ), wxALIGN_CENTER
);
425 wxGauge
* gauge
= new wxGauge (& progress
, - 1 , cnt
, wxPoint ( 20 , 20 ), wxSize ( 260 , 25 ));
426 wxButton
* btn
= new wxButton (& progress
, wxID_CANCEL
, _ ( "Cancel" ), wxPoint ( 110 , 70 ), wxSize ( 80 , 25 ));
427 btn
= btn
; /* fool compiler :-) */
428 prompt
-> SetLabel ( _ ( "No matching page found yet" ));
430 progress
. Centre ( wxBOTH
);
433 wxProgressDialog
progress ( _ ( "Searching..." ), _ ( "No matching page found yet" ), cnt
, m_Frame
, wxPD_APP_MODAL
| wxPD_CAN_ABORT
| wxPD_AUTO_HIDE
);
436 engine
. LookFor ( keyword
);
438 for ( int i
= 0 ; i
< cnt
; i
++) {
439 #if (wxVERSION_NUMBER < 2100) || ((wxVERSION_NUMBER == 2100) && (wxBETA_NUMBER < 7))
440 gauge
-> SetValue ( i
);
441 if ( progress
. m_Canceled
) break ;
443 if ( progress
. Update ( i
) == FALSE
) break ;
447 file
= fsys
. OpenFile ( m_Contents
[ i
]. m_Book
-> GetBasePath () + m_Contents
[ i
]. m_Page
);
449 if ( lastpage
!= file
-> GetLocation ()) {
450 lastpage
= file
-> GetLocation ();
451 if ( engine
. Scan ( file
-> GetStream ())) {
452 foundstr
. Printf ( _ ( "Found %i matches" ), ++ foundcnt
);
453 #if (wxVERSION_NUMBER < 2100) || ((wxVERSION_NUMBER == 2100) && (wxBETA_NUMBER < 7))
454 prompt
-> SetLabel ( foundstr
);
456 progress
. Update ( i
, foundstr
);
459 m_SearchList
-> Append ( m_Contents
[ i
]. m_Name
, ( char *)( m_Contents
+ i
));
466 #if (wxVERSION_NUMBER < 2100) || ((wxVERSION_NUMBER == 2100) && (wxBETA_NUMBER < 7))
467 progress
. Close ( TRUE
);
471 m_SearchButton
-> Enable ( TRUE
);
473 m_SearchText
-> SetSelection ( 0 , keyword
. Length ());
474 m_SearchText
-> SetFocus ();
477 HtmlContentsItem
* it
= ( HtmlContentsItem
*) m_SearchList
-> GetClientData ( 0 );
478 if ( it
) m_HtmlWin
-> LoadPage ( it
-> m_Book
-> GetBasePath () + it
-> m_Page
);
480 return ( foundcnt
> 0 );
488 void wxHtmlHelpController :: CreateHelpWindow ()
496 m_Frame
-> Show ( TRUE
);
501 wxBusyInfo
busyinfo ( _ ( "Preparing help window..." ));
504 if ( m_Config
) ReadCustomization ( m_Config
, m_ConfigRoot
);
506 m_Frame
= new wxFrame ( NULL
, - 1 , "" , wxPoint ( m_Cfg
. x
, m_Cfg
. y
), wxSize ( m_Cfg
. w
, m_Cfg
. h
));
507 m_Frame
-> PushEventHandler ( this );
508 sbar
= m_Frame
-> CreateStatusBar ();
512 toolBar
= m_Frame
-> CreateToolBar ( wxNO_BORDER
| wxTB_HORIZONTAL
| wxTB_FLAT
| wxTB_DOCKABLE
);
513 toolBar
-> SetMargins ( 2 , 2 );
514 wxBitmap
* toolBarBitmaps
[ 3 ];
517 toolBarBitmaps
[ 0 ] = new wxBitmap ( "panel" );
518 toolBarBitmaps
[ 1 ] = new wxBitmap ( "back" );
519 toolBarBitmaps
[ 2 ] = new wxBitmap ( "forward" );
522 toolBarBitmaps
[ 0 ] = new wxBitmap ( panel_xpm
);
523 toolBarBitmaps
[ 1 ] = new wxBitmap ( back_xpm
);
524 toolBarBitmaps
[ 2 ] = new wxBitmap ( forward_xpm
);
530 toolBar
-> AddTool ( wxID_HTML_PANEL
, *( toolBarBitmaps
[ 0 ]), wxNullBitmap
, FALSE
, currentX
, - 1 , ( wxObject
*) NULL
, _ ( "Show/hide navigation panel" ));
531 currentX
+= width
+ 5 ;
532 toolBar
-> AddSeparator ();
533 toolBar
-> AddTool ( wxID_HTML_BACK
, *( toolBarBitmaps
[ 1 ]), wxNullBitmap
, FALSE
, currentX
, - 1 , ( wxObject
*) NULL
, _ ( "Go back to the previous HTML page" ));
534 currentX
+= width
+ 5 ;
535 toolBar
-> AddTool ( wxID_HTML_FORWARD
, *( toolBarBitmaps
[ 2 ]), wxNullBitmap
, FALSE
, currentX
, - 1 , ( wxObject
*) NULL
, _ ( "Go forward to the next HTML page" ));
536 currentX
+= width
+ 5 ;
538 toolBar
-> Realize ();
540 // Can delete the bitmaps since they're reference counted
541 for ( int i
= 0 ; i
< 3 ; i
++) delete toolBarBitmaps
[ i
];
546 m_Splitter
= new wxSplitterWindow ( m_Frame
);
548 m_HtmlWin
= new wxHtmlWindow ( m_Splitter
);
549 m_HtmlWin
-> SetRelatedFrame ( m_Frame
, m_TitleFormat
);
550 m_HtmlWin
-> SetRelatedStatusBar ( 0 );
551 if ( m_Config
) m_HtmlWin
-> ReadCustomization ( m_Config
, m_ConfigRoot
);
553 m_NavigPan
= new wxNotebook ( m_Splitter
, wxID_HTML_NOTEBOOK
, wxDefaultPosition
, wxDefaultSize
);
555 m_ContentsBox
= new wxTreeCtrl ( m_NavigPan
, wxID_HTML_TREECTRL
, wxDefaultPosition
, wxDefaultSize
, wxTR_HAS_BUTTONS
| wxSUNKEN_BORDER
);
556 m_ContentsBox
-> SetImageList ( m_ContentsImageList
);
557 m_NavigPan
-> AddPage ( m_ContentsBox
, _ ( "Contents" ));
561 wxWindow
* dummy
= new wxPanel ( m_NavigPan
, wxID_HTML_INDEXPAGE
);
562 wxLayoutConstraints
* b1
= new wxLayoutConstraints
;
563 b1
-> top
. SameAs ( dummy
, wxTop
, 0 );
564 b1
-> left
. SameAs ( dummy
, wxLeft
, 0 );
565 b1
-> width
. PercentOf ( dummy
, wxWidth
, 100 );
566 b1
-> bottom
. SameAs ( dummy
, wxBottom
, 0 );
567 m_IndexBox
= new wxListBox ( dummy
, wxID_HTML_INDEXLIST
, wxDefaultPosition
, wxDefaultSize
, 0 );
568 m_IndexBox
-> SetConstraints ( b1
);
569 dummy
-> SetAutoLayout ( TRUE
);
570 m_NavigPan
-> AddPage ( dummy
, _ ( "Index" ));
574 wxWindow
* dummy
= new wxPanel ( m_NavigPan
, wxID_HTML_SEARCHPAGE
);
576 wxLayoutConstraints
* b1
= new wxLayoutConstraints
;
577 m_SearchText
= new wxTextCtrl ( dummy
, wxID_HTML_SEARCHTEXT
);
578 b1
-> top
. SameAs ( dummy
, wxTop
, 0 );
579 b1
-> left
. SameAs ( dummy
, wxLeft
, 0 );
580 b1
-> right
. SameAs ( dummy
, wxRight
, 0 );
582 m_SearchText
-> SetConstraints ( b1
);
584 wxLayoutConstraints
* b2
= new wxLayoutConstraints
;
585 m_SearchButton
= new wxButton ( dummy
, wxID_HTML_SEARCHBUTTON
, _ ( "Search!" ));
586 b2
-> top
. Below ( m_SearchText
, 10 );
587 b2
-> right
. SameAs ( dummy
, wxRight
, 10 );
590 m_SearchButton
-> SetConstraints ( b2
);
592 wxLayoutConstraints
* b3
= new wxLayoutConstraints
;
593 m_SearchList
= new wxListBox ( dummy
, wxID_HTML_SEARCHLIST
, wxDefaultPosition
, wxDefaultSize
, 0 );
594 b3
-> top
. Below ( m_SearchButton
, 10 );
595 b3
-> left
. SameAs ( dummy
, wxLeft
, 0 );
596 b3
-> right
. SameAs ( dummy
, wxRight
, 0 );
597 b3
-> bottom
. SameAs ( dummy
, wxBottom
, 0 );
598 m_SearchList
-> SetConstraints ( b3
);
600 dummy
-> SetAutoLayout ( TRUE
);
602 m_NavigPan
-> AddPage ( dummy
, _ ( "Search" ));
606 m_NavigPan
-> Show ( TRUE
);
607 m_HtmlWin
-> Show ( TRUE
);
608 m_Splitter
-> SetMinimumPaneSize ( 20 );
609 m_Splitter
-> SplitVertically ( m_NavigPan
, m_HtmlWin
, m_Cfg
. sashpos
);
610 if (! m_Cfg
. navig_on
) m_Splitter
-> Unsplit ( m_NavigPan
);
614 m_Frame
-> Show ( TRUE
);
622 void wxHtmlHelpController :: CreateContents ()
624 HtmlContentsItem
* it
;
625 wxTreeItemId roots
[ MAX_ROOTS
];
626 bool imaged
[ MAX_ROOTS
];
627 int count
= m_ContentsCnt
;
629 m_ContentsBox
-> DeleteAllItems ();
630 roots
[ 0 ] = m_ContentsBox
-> AddRoot ( _ ( "(Help)" ));
633 for ( int i
= 0 ; i
< count
; i
++) {
635 roots
[ it
-> m_Level
+ 1 ] = m_ContentsBox
-> AppendItem ( roots
[ it
-> m_Level
], it
-> m_Name
, IMG_Page
, - 1 , new wxHtmlHelpTreeItemData ( it
));
636 if ( it
-> m_Level
== 0 ) {
637 m_ContentsBox
-> SetItemBold ( roots
[ 1 ], TRUE
);
638 m_ContentsBox
-> SetItemImage ( roots
[ 1 ], IMG_Book
);
639 m_ContentsBox
-> SetItemSelectedImage ( roots
[ 1 ], IMG_Book
);
642 else imaged
[ it
-> m_Level
+ 1 ] = FALSE
;
644 if (! imaged
[ it
-> m_Level
]) {
645 m_ContentsBox
-> SetItemImage ( roots
[ it
-> m_Level
], IMG_Folder
);
646 m_ContentsBox
-> SetItemSelectedImage ( roots
[ it
-> m_Level
], IMG_Folder
);
647 imaged
[ it
-> m_Level
] = TRUE
;
651 m_ContentsBox
-> Expand ( roots
[ 0 ]);
657 void wxHtmlHelpController :: CreateIndex ()
659 m_IndexBox
-> Clear ();
661 for ( int i
= 0 ; i
< m_IndexCnt
; i
++)
662 m_IndexBox
-> Append ( m_Index
[ i
]. m_Name
, ( char *)( m_Index
+ i
));
667 void wxHtmlHelpController :: RefreshLists ()
672 m_SearchList
-> Clear ();
682 void wxHtmlHelpController :: ReadCustomization ( wxConfigBase
* cfg
, wxString path
)
687 if ( path
!= wxEmptyString
) {
688 oldpath
= cfg
-> GetPath ();
689 cfg
-> SetPath ( path
);
692 m_Cfg
. navig_on
= cfg
-> Read ( "hcNavigPanel" , m_Cfg
. navig_on
) != 0 ;
693 m_Cfg
. sashpos
= cfg
-> Read ( "hcSashPos" , m_Cfg
. sashpos
);
694 m_Cfg
. x
= cfg
-> Read ( "hcX" , m_Cfg
. x
);
695 m_Cfg
. y
= cfg
-> Read ( "hcY" , m_Cfg
. y
);
696 m_Cfg
. w
= cfg
-> Read ( "hcW" , m_Cfg
. w
);
697 m_Cfg
. h
= cfg
-> Read ( "hcH" , m_Cfg
. h
);
699 if ( path
!= wxEmptyString
)
700 cfg
-> SetPath ( oldpath
);
705 void wxHtmlHelpController :: WriteCustomization ( wxConfigBase
* cfg
, wxString path
)
710 if ( path
!= wxEmptyString
) {
711 oldpath
= cfg
-> GetPath ();
712 cfg
-> SetPath ( path
);
715 cfg
-> Write ( "hcNavigPanel" , m_Cfg
. navig_on
);
716 cfg
-> Write ( "hcSashPos" , ( long ) m_Cfg
. sashpos
);
717 cfg
-> Write ( "hcX" , ( long ) m_Cfg
. x
);
718 cfg
-> Write ( "hcY" , ( long ) m_Cfg
. y
);
719 cfg
-> Write ( "hcW" , ( long ) m_Cfg
. w
);
720 cfg
-> Write ( "hcH" , ( long ) m_Cfg
. h
);
722 if ( path
!= wxEmptyString
)
723 cfg
-> SetPath ( oldpath
);
735 void wxHtmlHelpController :: OnToolbar ( wxCommandEvent
& event
)
737 switch ( event
. GetId ()) {
738 case wxID_HTML_BACK
:
739 m_HtmlWin
-> HistoryBack ();
741 case wxID_HTML_FORWARD
:
742 m_HtmlWin
-> HistoryForward ();
744 case wxID_HTML_PANEL
:
745 if ( m_Splitter
-> IsSplit ()) {
746 m_Cfg
. sashpos
= m_Splitter
-> GetSashPosition ();
747 m_Splitter
-> Unsplit ( m_NavigPan
);
750 m_NavigPan
-> Show ( TRUE
);
751 m_HtmlWin
-> Show ( TRUE
);
752 m_Splitter
-> SplitVertically ( m_NavigPan
, m_HtmlWin
, m_Cfg
. sashpos
);
760 void wxHtmlHelpController :: OnContentsSel ( wxTreeEvent
& event
)
762 wxHtmlHelpTreeItemData
* pg
;
764 pg
= ( wxHtmlHelpTreeItemData
*) m_ContentsBox
-> GetItemData ( event
. GetItem ());
765 if ( pg
) m_HtmlWin
-> LoadPage ( pg
-> GetPage ());
770 void wxHtmlHelpController :: OnIndexSel ( wxCommandEvent
& event
)
772 HtmlContentsItem
* it
= ( HtmlContentsItem
*) m_IndexBox
-> GetClientData ( m_IndexBox
-> GetSelection ());
773 if ( it
) m_HtmlWin
-> LoadPage ( it
-> m_Book
-> GetBasePath () + it
-> m_Page
);
778 void wxHtmlHelpController :: OnSearchSel ( wxCommandEvent
& event
)
780 HtmlContentsItem
* it
= ( HtmlContentsItem
*) m_SearchList
-> GetClientData ( m_SearchList
-> GetSelection ());
781 if ( it
) m_HtmlWin
-> LoadPage ( it
-> m_Book
-> GetBasePath () + it
-> m_Page
);
786 void wxHtmlHelpController :: OnCloseWindow ( wxCloseEvent
& event
)
790 m_Cfg
. navig_on
= m_Splitter
-> IsSplit ();
792 m_Cfg
. sashpos
= m_Splitter
-> GetSashPosition ();
793 m_Frame
-> GetPosition (& a
, & b
);
794 m_Cfg
. x
= a
, m_Cfg
. y
= b
;
795 m_Frame
-> GetSize (& a
, & b
);
796 m_Cfg
. w
= a
, m_Cfg
. h
= b
;
799 WriteCustomization ( m_Config
, m_ConfigRoot
);
800 m_HtmlWin
-> WriteCustomization ( m_Config
, m_ConfigRoot
);
809 void wxHtmlHelpController :: OnSearch ( wxCommandEvent
& event
)
811 wxString sr
= m_SearchText
-> GetLineText ( 0 );
813 if ( sr
!= wxEmptyString
) KeywordSearch ( sr
);
818 BEGIN_EVENT_TABLE ( wxHtmlHelpController
, wxEvtHandler
)
819 EVT_TOOL_RANGE ( wxID_HTML_PANEL
, wxID_HTML_FORWARD
, wxHtmlHelpController :: OnToolbar
)
820 EVT_TREE_SEL_CHANGED ( wxID_HTML_TREECTRL
, wxHtmlHelpController :: OnContentsSel
)
821 EVT_LISTBOX ( wxID_HTML_INDEXLIST
, wxHtmlHelpController :: OnIndexSel
)
822 EVT_LISTBOX ( wxID_HTML_SEARCHLIST
, wxHtmlHelpController :: OnSearchSel
)
823 EVT_CLOSE ( wxHtmlHelpController :: OnCloseWindow
)
824 EVT_BUTTON ( wxID_HTML_SEARCHBUTTON
, wxHtmlHelpController :: OnSearch
)
825 EVT_TEXT_ENTER ( wxID_HTML_SEARCHTEXT
, wxHtmlHelpController :: OnSearch
)