]>
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
; }
39 wxBusyCursor() { wxBeginBusyCursor(); }
40 ~wxBusyCursor() { wxEndBusyCursor(); }
43 IMPLEMENT_ABSTRACT_CLASS(wxHTMLHelpControllerBase
, wxHelpControllerBase
)
46 This class implements help via an external browser.
47 It requires the name of a directory containing the documentation
48 and a file mapping numerical Section numbers to relative URLS.
51 wxHTMLHelpControllerBase::wxHTMLHelpControllerBase(void)
53 m_MapList
= (wxList
*) NULL
;
58 wxHTMLHelpControllerBase::DeleteList(void)
62 wxNode
*node
= m_MapList
->First();
65 delete (wxExtHelpMapEntry
*)node
->Data();
67 node
= m_MapList
->First();
70 m_MapList
= (wxList
*) NULL
;
74 wxHTMLHelpControllerBase::~wxHTMLHelpControllerBase(void)
79 /** This must be called to tell the controller where to find the
81 @param file - NOT a filename, but a directory name.
82 @return true on success
85 wxHTMLHelpControllerBase::Initialize(const wxString
& file
)
87 return LoadFile(file
);
91 // ifile is the name of the base help directory
93 wxHTMLHelpControllerBase::LoadFile(const wxString
& ifile
)
95 wxString mapFile
, file
, url
, doc
;
97 char buffer
[WXEXTHELP_BUFLEN
];
99 wxBusyCursor b
; // display a busy cursor
101 if(! ifile
.IsEmpty())
104 if(! wxIsAbsolutePath(file
))
106 char* f
= wxGetWorkingDirectory();
108 delete[] f
; // wxGetWorkingDirectory returns new memory
109 file
<< WXEXTHELP_SEPARATOR
<< ifile
;
114 // If a locale is set, look in file/localename, i.e.
115 // If passed "/usr/local/myapp/help" and the current wxLocale is
116 // set to be "de", then look in "/usr/local/myapp/help/de/"
117 // first and fall back to "/usr/local/myapp/help" if that
119 if(wxGetLocale() && !wxGetLocale()->GetName().IsEmpty())
122 newfile
<< WXEXTHELP_SEPARATOR
<< wxGetLocale()->GetName();
123 if(wxDirExists(newfile
))
127 if(! wxDirExists(file
))
130 mapFile
<< file
<< WXEXTHELP_SEPARATOR
<< WXEXTHELP_MAPFILE
;
132 else // try to reload old file
135 if(! wxFileExists(mapFile
))
139 m_MapList
= new wxList
;
142 FILE *input
= fopen(mapFile
.c_str(),"rt");
147 if(fgets(buffer
,WXEXTHELP_BUFLEN
,input
) && *buffer
!= WXEXTHELP_COMMENTCHAR
)
149 len
= strlen(buffer
);
150 if(buffer
[len
-1] == '\n')
151 buffer
[len
-1] = '\0'; // cut of trailing newline
152 if(sscanf(buffer
,"%d", &id
) != 1)
154 for(i
=0; isdigit(buffer
[i
])||isspace(buffer
[i
])||buffer
[i
]=='-'; i
++)
155 ; // find begin of URL
157 while(buffer
[i
] && ! isspace(buffer
[i
]) && buffer
[i
] !=
158 WXEXTHELP_COMMENTCHAR
)
160 while(buffer
[i
] && buffer
[i
] != WXEXTHELP_COMMENTCHAR
)
164 doc
= (buffer
+ i
+ 1); // skip the comment character
165 m_MapList
->Append(new wxExtHelpMapEntry(id
,url
,doc
));
168 }while(! feof(input
));
171 m_MapFile
= file
; // now it's valid
177 wxHTMLHelpControllerBase::DisplayContents(void)
181 wxBusyCursor b
; // display a busy cursor
182 return KeywordSearch("");
186 wxHTMLHelpControllerBase::DisplaySection(int sectionNo
)
191 wxBusyCursor b
; // display a busy cursor
192 wxNode
*node
= m_MapList
->First();
193 wxExtHelpMapEntry
*entry
;
196 entry
= (wxExtHelpMapEntry
*)node
->Data();
197 if(entry
->id
== sectionNo
)
198 return DisplayHelp(entry
->url
);
205 wxHTMLHelpControllerBase::DisplayBlock(long blockNo
)
207 return DisplaySection((int)blockNo
);
211 wxHTMLHelpControllerBase::KeywordSearch(const wxString
& k
)
216 wxBusyCursor b
; // display a busy cursor
217 wxString
*choices
= new wxString
[m_NumOfEntries
];
218 wxString
*urls
= new wxString
[m_NumOfEntries
];
219 wxString compA
, compB
;
223 bool showAll
= k
.IsEmpty();
224 wxNode
*node
= m_MapList
->First();
225 wxExtHelpMapEntry
*entry
;
227 compA
= k
; compA
.LowerCase(); // we compare case insensitive
230 entry
= (wxExtHelpMapEntry
*)node
->Data();
231 compB
= entry
->doc
; compB
.LowerCase();
232 if((showAll
|| compB
.Contains(k
)) && ! compB
.IsEmpty())
234 urls
[idx
] = entry
->url
;
236 // choices[idx] = (**i).doc.Contains((**i).doc.Before(WXEXTHELP_COMMENTCHAR));
237 //if(choices[idx].IsEmpty()) // didn't contain the ';'
238 // choices[idx] = (**i).doc;
240 for(j
=0;entry
->doc
.c_str()[j
]
241 && entry
->doc
.c_str()[j
] != WXEXTHELP_COMMENTCHAR
; j
++)
242 choices
[idx
] << entry
->doc
.c_str()[j
];
249 rc
= DisplayHelp(urls
[0]);
252 wxMessageBox(_("No entries found."));
257 idx
= wxGetSingleChoiceIndex(showAll
? _("Help Index") : _("Relevant entries:"),
258 showAll
? _("Help Index") : _("Entries found"),
261 rc
= DisplayHelp(urls
[idx
]);
273 wxHTMLHelpControllerBase::Quit(void)
279 wxHTMLHelpControllerBase::OnQuit(void)