]>
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"
41 class wxExtHelpMapEntry
: public wxObject
47 wxExtHelpMapEntry(int iid
, wxString
const &iurl
, wxString
const &idoc
)
48 { id
= iid
; url
= iurl
; doc
= idoc
; }
51 IMPLEMENT_ABSTRACT_CLASS(wxHTMLHelpControllerBase
, wxHelpControllerBase
)
54 This class implements help via an external browser.
55 It requires the name of a directory containing the documentation
56 and a file mapping numerical Section numbers to relative URLS.
59 wxHTMLHelpControllerBase::wxHTMLHelpControllerBase()
61 m_MapList
= (wxList
*) NULL
;
66 wxHTMLHelpControllerBase::DeleteList()
70 wxNode
*node
= m_MapList
->First();
73 delete (wxExtHelpMapEntry
*)node
->Data();
75 node
= m_MapList
->First();
78 m_MapList
= (wxList
*) NULL
;
82 wxHTMLHelpControllerBase::~wxHTMLHelpControllerBase()
87 /** This must be called to tell the controller where to find the
89 @param file - NOT a filename, but a directory name.
90 @return true on success
93 wxHTMLHelpControllerBase::Initialize(const wxString
& file
)
95 return LoadFile(file
);
99 // ifile is the name of the base help directory
101 wxHTMLHelpControllerBase::LoadFile(const wxString
& ifile
)
103 wxString mapFile
, file
, url
, doc
;
105 char buffer
[WXEXTHELP_BUFLEN
];
107 wxBusyCursor b
; // display a busy cursor
109 if(! ifile
.IsEmpty())
112 if(! wxIsAbsolutePath(file
))
114 wxChar
* f
= wxGetWorkingDirectory();
116 delete[] f
; // wxGetWorkingDirectory returns new memory
117 file
<< WXEXTHELP_SEPARATOR
<< ifile
;
123 // If a locale is set, look in file/localename, i.e.
124 // If passed "/usr/local/myapp/help" and the current wxLocale is
125 // set to be "de", then look in "/usr/local/myapp/help/de/"
126 // first and fall back to "/usr/local/myapp/help" if that
128 if(wxGetLocale() && !wxGetLocale()->GetName().IsEmpty())
131 newfile
<< WXEXTHELP_SEPARATOR
<< wxGetLocale()->GetName();
132 if(wxDirExists(newfile
))
136 newfile
= WXEXTHELP_SEPARATOR
;
137 const wxChar
*cptr
= wxGetLocale()->GetName().c_str();
138 while(*cptr
&& *cptr
!= _T('_'))
139 newfile
<< *(cptr
++);
140 if(wxDirExists(newfile
))
146 if(! wxDirExists(file
))
149 mapFile
<< file
<< WXEXTHELP_SEPARATOR
<< WXEXTHELP_MAPFILE
;
151 else // try to reload old file
154 if(! wxFileExists(mapFile
))
158 m_MapList
= new wxList
;
161 FILE *input
= fopen(mapFile
.fn_str(),"rt");
166 if(fgets(buffer
,WXEXTHELP_BUFLEN
,input
) && *buffer
!= WXEXTHELP_COMMENTCHAR
)
168 len
= strlen(buffer
);
169 if(buffer
[len
-1] == '\n')
170 buffer
[len
-1] = '\0'; // cut of trailing newline
171 if(sscanf(buffer
,"%d", &id
) != 1)
173 for(i
=0; isdigit(buffer
[i
])||isspace(buffer
[i
])||buffer
[i
]=='-'; i
++)
174 ; // find begin of URL
176 while(buffer
[i
] && ! isspace(buffer
[i
]) && buffer
[i
] !=
177 WXEXTHELP_COMMENTCHAR
)
179 while(buffer
[i
] && buffer
[i
] != WXEXTHELP_COMMENTCHAR
)
183 doc
= (buffer
+ i
+ 1); // skip the comment character
184 m_MapList
->Append(new wxExtHelpMapEntry(id
,url
,doc
));
187 }while(! feof(input
));
190 m_MapFile
= file
; // now it's valid
196 wxHTMLHelpControllerBase::DisplayContents()
200 wxBusyCursor b
; // display a busy cursor
201 return KeywordSearch("");
205 wxHTMLHelpControllerBase::DisplaySection(int sectionNo
)
210 wxBusyCursor b
; // display a busy cursor
211 wxNode
*node
= m_MapList
->First();
212 wxExtHelpMapEntry
*entry
;
215 entry
= (wxExtHelpMapEntry
*)node
->Data();
216 if(entry
->id
== sectionNo
)
217 return DisplayHelp(entry
->url
);
224 wxHTMLHelpControllerBase::DisplayBlock(long blockNo
)
226 return DisplaySection((int)blockNo
);
230 wxHTMLHelpControllerBase::KeywordSearch(const wxString
& k
)
235 wxBusyCursor b
; // display a busy cursor
236 wxString
*choices
= new wxString
[m_NumOfEntries
];
237 wxString
*urls
= new wxString
[m_NumOfEntries
];
238 wxString compA
, compB
;
242 bool showAll
= k
.IsEmpty();
243 wxNode
*node
= m_MapList
->First();
244 wxExtHelpMapEntry
*entry
;
246 compA
= k
; compA
.LowerCase(); // we compare case insensitive
249 entry
= (wxExtHelpMapEntry
*)node
->Data();
250 compB
= entry
->doc
; compB
.LowerCase();
251 if((showAll
|| compB
.Contains(k
)) && ! compB
.IsEmpty())
253 urls
[idx
] = entry
->url
;
255 // choices[idx] = (**i).doc.Contains((**i).doc.Before(WXEXTHELP_COMMENTCHAR));
256 //if(choices[idx].IsEmpty()) // didn't contain the ';'
257 // choices[idx] = (**i).doc;
259 for(j
=0;entry
->doc
.c_str()[j
]
260 && entry
->doc
.c_str()[j
] != WXEXTHELP_COMMENTCHAR
; j
++)
261 choices
[idx
] << entry
->doc
.c_str()[j
];
268 rc
= DisplayHelp(urls
[0]);
271 wxMessageBox(_("No entries found."));
276 idx
= wxGetSingleChoiceIndex(showAll
? _("Help Index") : _("Relevant entries:"),
277 showAll
? _("Help Index") : _("Entries found"),
280 rc
= DisplayHelp(urls
[idx
]);
292 wxHTMLHelpControllerBase::Quit()
298 wxHTMLHelpControllerBase::OnQuit()