]>
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(void)
46 m_MapList
= (wxList
*) NULL
;
51 wxHTMLHelpControllerBase::DeleteList(void)
55 wxNode
*node
= m_MapList
->First();
58 delete (wxExtHelpMapEntry
*)node
->Data();
60 node
= m_MapList
->First();
63 m_MapList
= (wxList
*) NULL
;
67 wxHTMLHelpControllerBase::~wxHTMLHelpControllerBase(void)
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 char* f
= wxGetWorkingDirectory();
101 delete[] f
; // wxGetWorkingDirectory returns new memory
102 file
<< WXEXTHELP_SEPARATOR
<< ifile
;
107 // If a locale is set, look in file/localename, i.e.
108 // If passed "/usr/local/myapp/help" and the current wxLocale is
109 // set to be "de", then look in "/usr/local/myapp/help/de/"
110 // first and fall back to "/usr/local/myapp/help" if that
112 if(wxGetLocale() && !wxGetLocale()->GetName().IsEmpty())
115 newfile
<< WXEXTHELP_SEPARATOR
<< wxGetLocale()->GetName();
116 if(wxDirExists(newfile
))
120 if(! wxDirExists(file
))
123 mapFile
<< file
<< WXEXTHELP_SEPARATOR
<< WXEXTHELP_MAPFILE
;
125 else // try to reload old file
128 if(! wxFileExists(mapFile
))
132 m_MapList
= new wxList
;
135 FILE *input
= fopen(mapFile
.c_str(),"rt");
140 if(fgets(buffer
,WXEXTHELP_BUFLEN
,input
) && *buffer
!= WXEXTHELP_COMMENTCHAR
)
142 len
= strlen(buffer
);
143 if(buffer
[len
-1] == '\n')
144 buffer
[len
-1] = '\0'; // cut of trailing newline
145 if(sscanf(buffer
,"%d", &id
) != 1)
147 for(i
=0; isdigit(buffer
[i
])||isspace(buffer
[i
])||buffer
[i
]=='-'; i
++)
148 ; // find begin of URL
150 while(buffer
[i
] && ! isspace(buffer
[i
]) && buffer
[i
] !=
151 WXEXTHELP_COMMENTCHAR
)
153 while(buffer
[i
] && buffer
[i
] != WXEXTHELP_COMMENTCHAR
)
157 doc
= (buffer
+ i
+ 1); // skip the comment character
158 m_MapList
->Append(new wxExtHelpMapEntry(id
,url
,doc
));
161 }while(! feof(input
));
164 m_MapFile
= file
; // now it's valid
170 wxHTMLHelpControllerBase::DisplayContents(void)
174 wxBusyCursor b
; // display a busy cursor
175 return KeywordSearch("");
179 wxHTMLHelpControllerBase::DisplaySection(int sectionNo
)
184 wxBusyCursor b
; // display a busy cursor
185 wxNode
*node
= m_MapList
->First();
186 wxExtHelpMapEntry
*entry
;
189 entry
= (wxExtHelpMapEntry
*)node
->Data();
190 if(entry
->id
== sectionNo
)
191 return DisplayHelp(entry
->url
);
198 wxHTMLHelpControllerBase::DisplayBlock(long blockNo
)
200 return DisplaySection((int)blockNo
);
204 wxHTMLHelpControllerBase::KeywordSearch(const wxString
& k
)
209 wxBusyCursor b
; // display a busy cursor
210 wxString
*choices
= new wxString
[m_NumOfEntries
];
211 wxString
*urls
= new wxString
[m_NumOfEntries
];
212 wxString compA
, compB
;
216 bool showAll
= k
.IsEmpty();
217 wxNode
*node
= m_MapList
->First();
218 wxExtHelpMapEntry
*entry
;
220 compA
= k
; compA
.LowerCase(); // we compare case insensitive
223 entry
= (wxExtHelpMapEntry
*)node
->Data();
224 compB
= entry
->doc
; compB
.LowerCase();
225 if((showAll
|| compB
.Contains(k
)) && ! compB
.IsEmpty())
227 urls
[idx
] = entry
->url
;
229 // choices[idx] = (**i).doc.Contains((**i).doc.Before(WXEXTHELP_COMMENTCHAR));
230 //if(choices[idx].IsEmpty()) // didn't contain the ';'
231 // choices[idx] = (**i).doc;
233 for(j
=0;entry
->doc
.c_str()[j
]
234 && entry
->doc
.c_str()[j
] != WXEXTHELP_COMMENTCHAR
; j
++)
235 choices
[idx
] << entry
->doc
.c_str()[j
];
242 rc
= DisplayHelp(urls
[0]);
245 wxMessageBox(_("No entries found."));
250 idx
= wxGetSingleChoiceIndex(showAll
? _("Help Index") : _("Relevant entries:"),
251 showAll
? _("Help Index") : _("Entries found"),
254 rc
= DisplayHelp(urls
[idx
]);
266 wxHTMLHelpControllerBase::Quit(void)
272 wxHTMLHelpControllerBase::OnQuit(void)