]>
git.saurik.com Git - wxWidgets.git/blob - src/generic/helphtml.cpp
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: base class for html help systems
4 // Author: Karsten Ballueder
8 // Copyright: (c) Karsten Ballueder
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
13 # pragma implementation "helphtml.h"
16 #include "wx/wxprec.h"
24 #include "wx/string.h"
30 #include "wx/helpbase.h"
31 #include "wx/generic/helpext.h"
43 class wxExtHelpMapEntry
: public wxObject
49 wxExtHelpMapEntry(int iid
, wxString
const &iurl
, wxString
const &idoc
)
50 { id
= iid
; url
= iurl
; doc
= idoc
; }
53 IMPLEMENT_ABSTRACT_CLASS(wxHTMLHelpControllerBase
, wxHelpControllerBase
)
56 This class implements help via an external browser.
57 It requires the name of a directory containing the documentation
58 and a file mapping numerical Section numbers to relative URLS.
61 wxHTMLHelpControllerBase::wxHTMLHelpControllerBase()
63 m_MapList
= (wxList
*) NULL
;
68 wxHTMLHelpControllerBase::DeleteList()
72 wxNode
*node
= m_MapList
->First();
75 delete (wxExtHelpMapEntry
*)node
->Data();
77 node
= m_MapList
->First();
80 m_MapList
= (wxList
*) NULL
;
84 wxHTMLHelpControllerBase::~wxHTMLHelpControllerBase()
89 /** This must be called to tell the controller where to find the
91 @param file - NOT a filename, but a directory name.
92 @return true on success
95 wxHTMLHelpControllerBase::Initialize(const wxString
& file
)
97 return LoadFile(file
);
101 // ifile is the name of the base help directory
103 wxHTMLHelpControllerBase::LoadFile(const wxString
& ifile
)
105 wxString mapFile
, file
, url
, doc
;
107 char buffer
[WXEXTHELP_BUFLEN
];
109 wxBusyCursor b
; // display a busy cursor
111 if(! ifile
.IsEmpty())
114 if(! wxIsAbsolutePath(file
))
116 wxChar
* f
= wxGetWorkingDirectory();
118 delete[] f
; // wxGetWorkingDirectory returns new memory
119 file
<< WXEXTHELP_SEPARATOR
<< ifile
;
125 // If a locale is set, look in file/localename, i.e.
126 // If passed "/usr/local/myapp/help" and the current wxLocale is
127 // set to be "de", then look in "/usr/local/myapp/help/de/"
128 // first and fall back to "/usr/local/myapp/help" if that
130 if(wxGetLocale() && !wxGetLocale()->GetName().IsEmpty())
133 newfile
<< WXEXTHELP_SEPARATOR
<< wxGetLocale()->GetName();
134 if(wxDirExists(newfile
))
138 newfile
= WXEXTHELP_SEPARATOR
;
139 const wxChar
*cptr
= wxGetLocale()->GetName().c_str();
140 while(*cptr
&& *cptr
!= _T('_'))
141 newfile
<< *(cptr
++);
142 if(wxDirExists(newfile
))
148 if(! wxDirExists(file
))
151 mapFile
<< file
<< WXEXTHELP_SEPARATOR
<< WXEXTHELP_MAPFILE
;
153 else // try to reload old file
156 if(! wxFileExists(mapFile
))
160 m_MapList
= new wxList
;
163 FILE *input
= fopen(mapFile
.fn_str(),"rt");
168 if(fgets(buffer
,WXEXTHELP_BUFLEN
,input
) && *buffer
!= WXEXTHELP_COMMENTCHAR
)
170 len
= strlen(buffer
);
171 if(buffer
[len
-1] == '\n')
172 buffer
[len
-1] = '\0'; // cut of trailing newline
173 if(sscanf(buffer
,"%d", &id
) != 1)
175 for(i
=0; isdigit(buffer
[i
])||isspace(buffer
[i
])||buffer
[i
]=='-'; i
++)
176 ; // find begin of URL
178 while(buffer
[i
] && ! isspace(buffer
[i
]) && buffer
[i
] !=
179 WXEXTHELP_COMMENTCHAR
)
181 while(buffer
[i
] && buffer
[i
] != WXEXTHELP_COMMENTCHAR
)
185 doc
= (buffer
+ i
+ 1); // skip the comment character
186 m_MapList
->Append(new wxExtHelpMapEntry(id
,url
,doc
));
189 }while(! feof(input
));
192 m_MapFile
= file
; // now it's valid
198 wxHTMLHelpControllerBase::DisplayContents()
204 wxNode
*node
= m_MapList
->First();
205 wxExtHelpMapEntry
*entry
;
208 entry
= (wxExtHelpMapEntry
*)node
->Data();
209 if(entry
->id
== CONTENTS_ID
)
211 contents
= entry
->url
;
218 if(contents
.Length() && wxFileExists(contents
.BeforeLast('#')))
219 rc
= DisplaySection(CONTENTS_ID
);
221 // if not found, open homemade toc:
222 return rc
? TRUE
: KeywordSearch("");
226 wxHTMLHelpControllerBase::DisplaySection(int sectionNo
)
231 wxBusyCursor b
; // display a busy cursor
232 wxNode
*node
= m_MapList
->First();
233 wxExtHelpMapEntry
*entry
;
236 entry
= (wxExtHelpMapEntry
*)node
->Data();
237 if(entry
->id
== sectionNo
)
238 return DisplayHelp(entry
->url
);
245 wxHTMLHelpControllerBase::DisplayBlock(long blockNo
)
247 return DisplaySection((int)blockNo
);
251 wxHTMLHelpControllerBase::KeywordSearch(const wxString
& k
)
256 wxBusyCursor b
; // display a busy cursor
257 wxString
*choices
= new wxString
[m_NumOfEntries
];
258 wxString
*urls
= new wxString
[m_NumOfEntries
];
259 wxString compA
, compB
;
263 bool showAll
= k
.IsEmpty();
264 wxNode
*node
= m_MapList
->First();
265 wxExtHelpMapEntry
*entry
;
267 compA
= k
; compA
.LowerCase(); // we compare case insensitive
270 entry
= (wxExtHelpMapEntry
*)node
->Data();
271 compB
= entry
->doc
; compB
.LowerCase();
272 if((showAll
|| compB
.Contains(k
)) && ! compB
.IsEmpty())
274 urls
[idx
] = entry
->url
;
276 // choices[idx] = (**i).doc.Contains((**i).doc.Before(WXEXTHELP_COMMENTCHAR));
277 //if(choices[idx].IsEmpty()) // didn't contain the ';'
278 // choices[idx] = (**i).doc;
280 for(j
=0;entry
->doc
.c_str()[j
]
281 && entry
->doc
.c_str()[j
] != WXEXTHELP_COMMENTCHAR
; j
++)
282 choices
[idx
] << entry
->doc
.c_str()[j
];
289 rc
= DisplayHelp(urls
[0]);
292 wxMessageBox(_("No entries found."));
297 idx
= wxGetSingleChoiceIndex(showAll
? _("Help Index") : _("Relevant entries:"),
298 showAll
? _("Help Index") : _("Entries found"),
301 rc
= DisplayHelp(urls
[idx
]);
313 wxHTMLHelpControllerBase::Quit()
319 wxHTMLHelpControllerBase::OnQuit()