]>
git.saurik.com Git - wxWidgets.git/blob - src/generic/helphtml.cpp
1 /*-*- c++ -*-********************************************************
2 * helphtml.cpp - base class for html help systems *
4 * (C) 1999 by Karsten Ballüder (Ballueder@usa.net) *
7 *******************************************************************/
9 # pragma implementation "helphtml.h"
13 #include "wx/helpbase.h"
14 #include "wx/generic/helpext.h"
15 #include "wx/string.h"
26 class wxExtHelpMapEntry
: public wxObject
32 wxExtHelpMapEntry(int iid
, wxString
const &iurl
, wxString
const &idoc
)
33 { id
= iid
; url
= iurl
; doc
= idoc
; }
36 IMPLEMENT_ABSTRACT_CLASS(wxHTMLHelpControllerBase
, wxHelpControllerBase
)
39 This class implements help via an external browser.
40 It requires the name of a directory containing the documentation
41 and a file mapping numerical Section numbers to relative URLS.
44 wxHTMLHelpControllerBase::wxHTMLHelpControllerBase()
46 m_MapList
= (wxList
*) NULL
;
51 wxHTMLHelpControllerBase::DeleteList()
55 wxNode
*node
= m_MapList
->First();
58 delete (wxExtHelpMapEntry
*)node
->Data();
60 node
= m_MapList
->First();
63 m_MapList
= (wxList
*) NULL
;
67 wxHTMLHelpControllerBase::~wxHTMLHelpControllerBase()
72 /** This must be called to tell the controller where to find the
74 @param file - NOT a filename, but a directory name.
75 @return true on success
78 wxHTMLHelpControllerBase::Initialize(const wxString
& file
)
80 return LoadFile(file
);
84 // ifile is the name of the base help directory
86 wxHTMLHelpControllerBase::LoadFile(const wxString
& ifile
)
88 wxString mapFile
, file
, url
, doc
;
90 char buffer
[WXEXTHELP_BUFLEN
];
92 wxBusyCursor b
; // display a busy cursor
97 if(! wxIsAbsolutePath(file
))
99 wxChar
* f
= wxGetWorkingDirectory();
101 delete[] f
; // wxGetWorkingDirectory returns new memory
102 file
<< WXEXTHELP_SEPARATOR
<< ifile
;
108 // If a locale is set, look in file/localename, i.e.
109 // If passed "/usr/local/myapp/help" and the current wxLocale is
110 // set to be "de", then look in "/usr/local/myapp/help/de/"
111 // first and fall back to "/usr/local/myapp/help" if that
113 if(wxGetLocale() && !wxGetLocale()->GetName().IsEmpty())
116 newfile
<< WXEXTHELP_SEPARATOR
<< wxGetLocale()->GetName();
117 if(wxDirExists(newfile
))
121 newfile
= WXEXTHELP_SEPARATOR
;
122 const wxChar
*cptr
= wxGetLocale()->GetName().c_str();
123 while(*cptr
&& *cptr
!= _T('_'))
124 newfile
<< *(cptr
++);
125 if(wxDirExists(newfile
))
131 if(! wxDirExists(file
))
134 mapFile
<< file
<< WXEXTHELP_SEPARATOR
<< WXEXTHELP_MAPFILE
;
136 else // try to reload old file
139 if(! wxFileExists(mapFile
))
143 m_MapList
= new wxList
;
146 FILE *input
= fopen(mapFile
.fn_str(),"rt");
151 if(fgets(buffer
,WXEXTHELP_BUFLEN
,input
) && *buffer
!= WXEXTHELP_COMMENTCHAR
)
153 len
= strlen(buffer
);
154 if(buffer
[len
-1] == '\n')
155 buffer
[len
-1] = '\0'; // cut of trailing newline
156 if(sscanf(buffer
,"%d", &id
) != 1)
158 for(i
=0; isdigit(buffer
[i
])||isspace(buffer
[i
])||buffer
[i
]=='-'; i
++)
159 ; // find begin of URL
161 while(buffer
[i
] && ! isspace(buffer
[i
]) && buffer
[i
] !=
162 WXEXTHELP_COMMENTCHAR
)
164 while(buffer
[i
] && buffer
[i
] != WXEXTHELP_COMMENTCHAR
)
168 doc
= (buffer
+ i
+ 1); // skip the comment character
169 m_MapList
->Append(new wxExtHelpMapEntry(id
,url
,doc
));
172 }while(! feof(input
));
175 m_MapFile
= file
; // now it's valid
181 wxHTMLHelpControllerBase::DisplayContents()
185 wxBusyCursor b
; // display a busy cursor
186 return KeywordSearch("");
190 wxHTMLHelpControllerBase::DisplaySection(int sectionNo
)
195 wxBusyCursor b
; // display a busy cursor
196 wxNode
*node
= m_MapList
->First();
197 wxExtHelpMapEntry
*entry
;
200 entry
= (wxExtHelpMapEntry
*)node
->Data();
201 if(entry
->id
== sectionNo
)
202 return DisplayHelp(entry
->url
);
209 wxHTMLHelpControllerBase::DisplayBlock(long blockNo
)
211 return DisplaySection((int)blockNo
);
215 wxHTMLHelpControllerBase::KeywordSearch(const wxString
& k
)
220 wxBusyCursor b
; // display a busy cursor
221 wxString
*choices
= new wxString
[m_NumOfEntries
];
222 wxString
*urls
= new wxString
[m_NumOfEntries
];
223 wxString compA
, compB
;
227 bool showAll
= k
.IsEmpty();
228 wxNode
*node
= m_MapList
->First();
229 wxExtHelpMapEntry
*entry
;
231 compA
= k
; compA
.LowerCase(); // we compare case insensitive
234 entry
= (wxExtHelpMapEntry
*)node
->Data();
235 compB
= entry
->doc
; compB
.LowerCase();
236 if((showAll
|| compB
.Contains(k
)) && ! compB
.IsEmpty())
238 urls
[idx
] = entry
->url
;
240 // choices[idx] = (**i).doc.Contains((**i).doc.Before(WXEXTHELP_COMMENTCHAR));
241 //if(choices[idx].IsEmpty()) // didn't contain the ';'
242 // choices[idx] = (**i).doc;
244 for(j
=0;entry
->doc
.c_str()[j
]
245 && entry
->doc
.c_str()[j
] != WXEXTHELP_COMMENTCHAR
; j
++)
246 choices
[idx
] << entry
->doc
.c_str()[j
];
253 rc
= DisplayHelp(urls
[0]);
256 wxMessageBox(_("No entries found."));
261 idx
= wxGetSingleChoiceIndex(showAll
? _("Help Index") : _("Relevant entries:"),
262 showAll
? _("Help Index") : _("Entries found"),
265 rc
= DisplayHelp(urls
[idx
]);
277 wxHTMLHelpControllerBase::Quit()
283 wxHTMLHelpControllerBase::OnQuit()