]>
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"
26 #include "wx/string.h"
32 #include "wx/helpbase.h"
33 #include "wx/generic/helpext.h"
45 class wxExtHelpMapEntry
: public wxObject
51 wxExtHelpMapEntry(int iid
, wxString
const &iurl
, wxString
const &idoc
)
52 { id
= iid
; url
= iurl
; doc
= idoc
; }
55 IMPLEMENT_ABSTRACT_CLASS(wxHTMLHelpControllerBase
, wxHelpControllerBase
)
58 This class implements help via an external browser.
59 It requires the name of a directory containing the documentation
60 and a file mapping numerical Section numbers to relative URLS.
63 wxHTMLHelpControllerBase::wxHTMLHelpControllerBase()
65 m_MapList
= (wxList
*) NULL
;
70 wxHTMLHelpControllerBase::DeleteList()
74 wxNode
*node
= m_MapList
->First();
77 delete (wxExtHelpMapEntry
*)node
->Data();
79 node
= m_MapList
->First();
82 m_MapList
= (wxList
*) NULL
;
86 wxHTMLHelpControllerBase::~wxHTMLHelpControllerBase()
91 /** This must be called to tell the controller where to find the
93 @param file - NOT a filename, but a directory name.
94 @return true on success
97 wxHTMLHelpControllerBase::Initialize(const wxString
& file
)
99 return LoadFile(file
);
103 // ifile is the name of the base help directory
105 wxHTMLHelpControllerBase::LoadFile(const wxString
& ifile
)
107 wxString mapFile
, file
, url
, doc
;
109 char buffer
[WXEXTHELP_BUFLEN
];
111 wxBusyCursor b
; // display a busy cursor
113 if(! ifile
.IsEmpty())
116 if(! wxIsAbsolutePath(file
))
118 wxChar
* f
= wxGetWorkingDirectory();
120 delete[] f
; // wxGetWorkingDirectory returns new memory
121 file
<< WXEXTHELP_SEPARATOR
<< ifile
;
127 // If a locale is set, look in file/localename, i.e.
128 // If passed "/usr/local/myapp/help" and the current wxLocale is
129 // set to be "de", then look in "/usr/local/myapp/help/de/"
130 // first and fall back to "/usr/local/myapp/help" if that
132 if(wxGetLocale() && !wxGetLocale()->GetName().IsEmpty())
135 newfile
<< WXEXTHELP_SEPARATOR
<< wxGetLocale()->GetName();
136 if(wxDirExists(newfile
))
140 newfile
= WXEXTHELP_SEPARATOR
;
141 const wxChar
*cptr
= wxGetLocale()->GetName().c_str();
142 while(*cptr
&& *cptr
!= _T('_'))
143 newfile
<< *(cptr
++);
144 if(wxDirExists(newfile
))
150 if(! wxDirExists(file
))
153 mapFile
<< file
<< WXEXTHELP_SEPARATOR
<< WXEXTHELP_MAPFILE
;
155 else // try to reload old file
158 if(! wxFileExists(mapFile
))
162 m_MapList
= new wxList
;
165 FILE *input
= fopen(mapFile
.fn_str(),"rt");
170 if(fgets(buffer
,WXEXTHELP_BUFLEN
,input
) && *buffer
!= WXEXTHELP_COMMENTCHAR
)
172 len
= strlen(buffer
);
173 if(buffer
[len
-1] == '\n')
174 buffer
[len
-1] = '\0'; // cut of trailing newline
175 if(sscanf(buffer
,"%d", &id
) != 1)
177 for(i
=0; isdigit(buffer
[i
])||isspace(buffer
[i
])||buffer
[i
]=='-'; i
++)
178 ; // find begin of URL
180 while(buffer
[i
] && ! isspace(buffer
[i
]) && buffer
[i
] !=
181 WXEXTHELP_COMMENTCHAR
)
183 while(buffer
[i
] && buffer
[i
] != WXEXTHELP_COMMENTCHAR
)
187 doc
= (buffer
+ i
+ 1); // skip the comment character
188 m_MapList
->Append(new wxExtHelpMapEntry(id
,url
,doc
));
191 }while(! feof(input
));
194 m_MapFile
= file
; // now it's valid
200 wxHTMLHelpControllerBase::DisplayContents()
206 wxNode
*node
= m_MapList
->First();
207 wxExtHelpMapEntry
*entry
;
210 entry
= (wxExtHelpMapEntry
*)node
->Data();
211 if(entry
->id
== CONTENTS_ID
)
213 contents
= entry
->url
;
220 if(contents
.Length() && wxFileExists(contents
.BeforeLast('#')))
221 rc
= DisplaySection(CONTENTS_ID
);
223 // if not found, open homemade toc:
224 return rc
? TRUE
: KeywordSearch("");
228 wxHTMLHelpControllerBase::DisplaySection(int sectionNo
)
233 wxBusyCursor b
; // display a busy cursor
234 wxNode
*node
= m_MapList
->First();
235 wxExtHelpMapEntry
*entry
;
238 entry
= (wxExtHelpMapEntry
*)node
->Data();
239 if(entry
->id
== sectionNo
)
240 return DisplayHelp(entry
->url
);
247 wxHTMLHelpControllerBase::DisplayBlock(long blockNo
)
249 return DisplaySection((int)blockNo
);
253 wxHTMLHelpControllerBase::KeywordSearch(const wxString
& k
)
258 wxBusyCursor b
; // display a busy cursor
259 wxString
*choices
= new wxString
[m_NumOfEntries
];
260 wxString
*urls
= new wxString
[m_NumOfEntries
];
261 wxString compA
, compB
;
265 bool showAll
= k
.IsEmpty();
266 wxNode
*node
= m_MapList
->First();
267 wxExtHelpMapEntry
*entry
;
269 compA
= k
; compA
.LowerCase(); // we compare case insensitive
272 entry
= (wxExtHelpMapEntry
*)node
->Data();
273 compB
= entry
->doc
; compB
.LowerCase();
274 if((showAll
|| compB
.Contains(k
)) && ! compB
.IsEmpty())
276 urls
[idx
] = entry
->url
;
278 // choices[idx] = (**i).doc.Contains((**i).doc.Before(WXEXTHELP_COMMENTCHAR));
279 //if(choices[idx].IsEmpty()) // didn't contain the ';'
280 // choices[idx] = (**i).doc;
282 for(j
=0;entry
->doc
.c_str()[j
]
283 && entry
->doc
.c_str()[j
] != WXEXTHELP_COMMENTCHAR
; j
++)
284 choices
[idx
] << entry
->doc
.c_str()[j
];
291 rc
= DisplayHelp(urls
[0]);
294 wxMessageBox(_("No entries found."));
299 idx
= wxGetSingleChoiceIndex(showAll
? _("Help Index") : _("Relevant entries:"),
300 showAll
? _("Help Index") : _("Entries found"),
303 rc
= DisplayHelp(urls
[idx
]);
315 wxHTMLHelpControllerBase::Quit()
321 wxHTMLHelpControllerBase::OnQuit()