]>
git.saurik.com Git - wxWidgets.git/blob - utils/wxPython/modules/html/helpsys.cpp
1 /* htmlsys.h : wxHtmlHelpSystem is an extension of the wxHtmlHelpController.
2 * mainly does two things:
3 * - extend the interface somewhat so the programmer can dictate most of the
4 * look and feel of the htmlhelp frame.
5 * - make some protected functions public (adding _ to the function name) so
6 * that SWIG can wrap them.
8 * Harm van der Heijden 32aug1999
12 #include <wx/wfstream.h>
13 #include <wx/busyinfo.h>
17 #include "bitmaps/panel.xpm"
18 #include "bitmaps/back.xpm"
19 #include "bitmaps/forward.xpm"
20 #include "bitmaps/book.xpm"
21 #include "bitmaps/folder.xpm"
22 #include "bitmaps/page.xpm"
25 IMPLEMENT_DYNAMIC_CLASS ( wxHtmlHelpSystem
, wxHtmlHelpController
)
27 // The two static funtions below are also defined in htmlhelp.cpp
28 // maybe they should be protected class functions.
29 static wxString
SafeFileName ( const wxString
& s
)
32 res
. Replace ( ":" , "_" , TRUE
);
33 res
. Replace ( " " , "_" , TRUE
);
34 res
. Replace ( "/" , "_" , TRUE
);
35 res
. Replace ( " \\ " , "_" , TRUE
);
36 res
. Replace ( "#" , "_" , TRUE
);
37 res
. Replace ( "." , "_" , TRUE
);
41 static int IndexCompareFunc ( const void * a
, const void * b
)
43 return strcmp ((( HtmlContentsItem
*) a
) -> m_Name
, (( HtmlContentsItem
*) b
) -> m_Name
);
46 bool wxHtmlHelpSystem :: AddBookParam ( const wxString
& title
, const wxString
& contfile
,
47 const wxString
& indexfile
, const wxString
& deftopic
,
48 const wxString
& path
, bool show_wait_msg
)
52 HtmlBookRecord
* bookr
;
56 // workaround for bug in ChangePathTo(name, TRUE)
57 fsys
. ChangePathTo ( path
+ "/gaga" );
59 bookr
= new HtmlBookRecord ( path
+ '/' , title
, deftopic
);
61 if ( m_ContentsCnt
% HTML_REALLOC_STEP
== 0 )
62 m_Contents
= ( HtmlContentsItem
*) realloc ( m_Contents
, ( m_ContentsCnt
+ HTML_REALLOC_STEP
) * sizeof ( HtmlContentsItem
));
63 m_Contents
[ m_ContentsCnt
]. m_Level
= 0 ;
64 m_Contents
[ m_ContentsCnt
]. m_ID
= 0 ;
65 m_Contents
[ m_ContentsCnt
]. m_Page
= new char [ deftopic
. Length () + 1 ];
66 strcpy ( m_Contents
[ m_ContentsCnt
]. m_Page
, deftopic
. c_str ());
67 m_Contents
[ m_ContentsCnt
]. m_Name
= new char [ title
. Length () + 1 ];
68 strcpy ( m_Contents
[ m_ContentsCnt
]. m_Name
, title
. c_str ());
69 m_Contents
[ m_ContentsCnt
]. m_Book
= bookr
;
72 // Try to find cached binary versions:
73 safetitle
= SafeFileName ( title
);
74 fi
= fsys
. OpenFile ( safetitle
+ ".cached" );
75 if ( fi
== NULL
) fi
= fsys
. OpenFile ( m_TempPath
+ safetitle
+ ".cached" );
76 if (( fi
== NULL
) || ( m_TempPath
== wxEmptyString
)) {
77 LoadMSProject ( bookr
, fsys
, indexfile
, contfile
, show_wait_msg
);
78 if ( m_TempPath
!= wxEmptyString
) {
79 wxFileOutputStream
* outs
= new wxFileOutputStream ( m_TempPath
+ safetitle
+ ".cached" );
80 SaveCachedBook ( bookr
, outs
);
85 LoadCachedBook ( bookr
, fi
-> GetStream ());
89 m_BookRecords
. Add ( bookr
);
91 qsort ( m_Index
, m_IndexCnt
, sizeof ( HtmlContentsItem
), IndexCompareFunc
);
96 wxToolBar
* wxHtmlHelpSystem :: CreateToolBar ( wxFrame
* frame
)
99 toolBar
= frame
-> CreateToolBar ( wxNO_BORDER
| wxTB_HORIZONTAL
| wxTB_FLAT
| wxTB_DOCKABLE
);
100 toolBar
-> SetMargins ( 2 , 2 );
101 wxBitmap
* toolBarBitmaps
[ 3 ];
104 toolBarBitmaps
[ 0 ] = new wxBitmap ( "panel" );
105 toolBarBitmaps
[ 1 ] = new wxBitmap ( "back" );
106 toolBarBitmaps
[ 2 ] = new wxBitmap ( "forward" );
109 toolBarBitmaps
[ 0 ] = new wxBitmap ( panel_xpm
);
110 toolBarBitmaps
[ 1 ] = new wxBitmap ( back_xpm
);
111 toolBarBitmaps
[ 2 ] = new wxBitmap ( forward_xpm
);
117 toolBar
-> AddTool ( wxID_HTML_PANEL
, *( toolBarBitmaps
[ 0 ]), wxNullBitmap
, FALSE
, currentX
, - 1 , ( wxObject
*) NULL
, _ ( "Show/hide navigation panel" ));
118 currentX
+= width
+ 5 ;
119 toolBar
-> AddSeparator ();
120 toolBar
-> AddTool ( wxID_HTML_BACK
, *( toolBarBitmaps
[ 1 ]), wxNullBitmap
, FALSE
, currentX
, - 1 , ( wxObject
*) NULL
, _ ( "Go back to the previous HTML page" ));
121 currentX
+= width
+ 5 ;
122 toolBar
-> AddTool ( wxID_HTML_FORWARD
, *( toolBarBitmaps
[ 2 ]), wxNullBitmap
, FALSE
, currentX
, - 1 , ( wxObject
*) NULL
, _ ( "Go forward to the next HTML page" ));
123 currentX
+= width
+ 5 ;
125 toolBar
-> Realize ();
127 // Can delete the bitmaps since they're reference counted
128 for ( int i
= 0 ; i
< 3 ; i
++) delete toolBarBitmaps
[ i
];
132 wxTreeCtrl
* wxHtmlHelpSystem :: CreateContentsTree ( wxWindow
* parent
)
135 tree
= new wxTreeCtrl ( parent
, wxID_HTML_TREECTRL
, wxDefaultPosition
,
136 wxDefaultSize
, wxTR_HAS_BUTTONS
| wxSUNKEN_BORDER
);
137 tree
-> SetImageList ( m_ContentsImageList
);
141 wxListBox
* wxHtmlHelpSystem :: CreateIndexList ( wxWindow
* parent
)
143 return new wxListBox ( parent
, wxID_HTML_INDEXLIST
, wxDefaultPosition
, wxDefaultSize
, 0 );
146 void wxHtmlHelpSystem :: SetControls ( wxFrame
* frame
, wxHtmlWindow
* htmlwin
,
147 wxTreeCtrl
* contents
, wxListBox
* index
,
148 wxListBox
* searchlist
)
152 m_ContentsBox
= contents
;
154 m_SearchList
= searchlist
;
155 m_SearchText
= NULL
; // provide your own input box
156 /* if you're setting your own controls, you and your event handlers are
157 * responsible for any splitter and notebook adjustments, not the
158 * htmlhelp framework */
164 void wxHtmlHelpSystem :: CreateHelpWindow ()
172 m_Frame
-> Show ( TRUE
);
177 wxBusyInfo
busyinfo ( _ ( "Preparing help window..." ));
180 if ( m_Config
) ReadCustomization ( m_Config
, m_ConfigRoot
);
182 m_Frame
= new wxFrame ( NULL
, - 1 , "" , wxPoint ( m_Cfg
. x
, m_Cfg
. y
), wxSize ( m_Cfg
. w
, m_Cfg
. h
));
183 m_Frame
-> PushEventHandler ( this );
184 sbar
= m_Frame
-> CreateStatusBar ();
186 CreateToolBar ( m_Frame
);
189 m_Splitter
= new wxSplitterWindow ( m_Frame
);
191 m_HtmlWin
= new wxHtmlWindow ( m_Splitter
);
192 m_HtmlWin
-> SetRelatedFrame ( m_Frame
, m_TitleFormat
);
193 m_HtmlWin
-> SetRelatedStatusBar ( 0 );
194 if ( m_Config
) m_HtmlWin
-> ReadCustomization ( m_Config
, m_ConfigRoot
);
196 m_NavigPan
= new wxNotebook ( m_Splitter
, wxID_HTML_NOTEBOOK
, wxDefaultPosition
, wxDefaultSize
);
198 m_ContentsBox
= CreateContentsTree ( m_NavigPan
);
199 m_NavigPan
-> AddPage ( m_ContentsBox
, _ ( "Contents" ));
203 wxWindow
* dummy
= new wxPanel ( m_NavigPan
, wxID_HTML_INDEXPAGE
);
204 wxLayoutConstraints
* b1
= new wxLayoutConstraints
;
205 b1
-> top
. SameAs ( dummy
, wxTop
, 0 );
206 b1
-> left
. SameAs ( dummy
, wxLeft
, 0 );
207 b1
-> width
. PercentOf ( dummy
, wxWidth
, 100 );
208 b1
-> bottom
. SameAs ( dummy
, wxBottom
, 0 );
209 m_IndexBox
= CreateIndexList ( dummy
);
210 m_IndexBox
-> SetConstraints ( b1
);
212 dummy
-> SetAutoLayout ( TRUE
);
213 m_NavigPan
-> AddPage ( dummy
, _ ( "Index" ));
217 wxWindow
* dummy
= new wxPanel ( m_NavigPan
, wxID_HTML_SEARCHPAGE
);
219 wxLayoutConstraints
* b1
= new wxLayoutConstraints
;
220 m_SearchText
= new wxTextCtrl ( dummy
, wxID_HTML_SEARCHTEXT
);
221 b1
-> top
. SameAs ( dummy
, wxTop
, 0 );
222 b1
-> left
. SameAs ( dummy
, wxLeft
, 0 );
223 b1
-> right
. SameAs ( dummy
, wxRight
, 0 );
225 m_SearchText
-> SetConstraints ( b1
);
227 wxLayoutConstraints
* b2
= new wxLayoutConstraints
;
228 m_SearchButton
= new wxButton ( dummy
, wxID_HTML_SEARCHBUTTON
, _ ( "Search!" ));
229 b2
-> top
. Below ( m_SearchText
, 10 );
230 b2
-> right
. SameAs ( dummy
, wxRight
, 10 );
233 m_SearchButton
-> SetConstraints ( b2
);
235 wxLayoutConstraints
* b3
= new wxLayoutConstraints
;
236 m_SearchList
= new wxListBox ( dummy
, wxID_HTML_SEARCHLIST
, wxDefaultPosition
, wxDefaultSize
, 0 );
237 b3
-> top
. Below ( m_SearchButton
, 10 );
238 b3
-> left
. SameAs ( dummy
, wxLeft
, 0 );
239 b3
-> right
. SameAs ( dummy
, wxRight
, 0 );
240 b3
-> bottom
. SameAs ( dummy
, wxBottom
, 0 );
241 m_SearchList
-> SetConstraints ( b3
);
243 dummy
-> SetAutoLayout ( TRUE
);
245 m_NavigPan
-> AddPage ( dummy
, _ ( "Search" ));
249 m_NavigPan
-> Show ( TRUE
);
250 m_HtmlWin
-> Show ( TRUE
);
251 m_Splitter
-> SetMinimumPaneSize ( 20 );
252 m_Splitter
-> SplitVertically ( m_NavigPan
, m_HtmlWin
, m_Cfg
. sashpos
);
253 if (! m_Cfg
. navig_on
) m_Splitter
-> Unsplit ( m_NavigPan
);
257 m_Frame
-> Show ( TRUE
);
261 void wxHtmlHelpSystem :: RefreshLists ()
267 m_SearchList
-> Clear ();
271 void wxHtmlHelpSystem :: OnToolbar ( wxCommandEvent
& event
)
273 switch ( event
. GetId ()) {
274 case wxID_HTML_BACK
:
275 if ( m_HtmlWin
) m_HtmlWin
-> HistoryBack ();
277 case wxID_HTML_FORWARD
:
278 if ( m_HtmlWin
) m_HtmlWin
-> HistoryForward ();
280 case wxID_HTML_PANEL
:
281 if (! ( m_Splitter
&& m_NavigPan
))
283 if ( m_Splitter
-> IsSplit ()) {
284 m_Cfg
. sashpos
= m_Splitter
-> GetSashPosition ();
285 m_Splitter
-> Unsplit ( m_NavigPan
);
288 m_NavigPan
-> Show ( TRUE
);
289 m_HtmlWin
-> Show ( TRUE
);
290 m_Splitter
-> SplitVertically ( m_NavigPan
, m_HtmlWin
, m_Cfg
. sashpos
);
296 void wxHtmlHelpSystem :: OnCloseWindow ( wxCloseEvent
& event
)
300 if ( m_Splitter
&& m_NavigPan
) {
301 m_Cfg
. navig_on
= m_Splitter
-> IsSplit ();
303 m_Cfg
. sashpos
= m_Splitter
-> GetSashPosition ();
304 m_Frame
-> GetPosition (& a
, & b
);
305 m_Cfg
. x
= a
, m_Cfg
. y
= b
;
306 m_Frame
-> GetSize (& a
, & b
);
307 m_Cfg
. w
= a
, m_Cfg
. h
= b
;
310 WriteCustomization ( m_Config
, m_ConfigRoot
);
311 m_HtmlWin
-> WriteCustomization ( m_Config
, m_ConfigRoot
);
318 BEGIN_EVENT_TABLE ( wxHtmlHelpSystem
, wxHtmlHelpController
)
319 EVT_TOOL_RANGE ( wxID_HTML_PANEL
, wxID_HTML_FORWARD
, wxHtmlHelpSystem :: OnToolbar
)
320 EVT_CLOSE ( wxHtmlHelpSystem :: OnCloseWindow
)