]>
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
;
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 newfile
= WXEXTHELP_SEPARATOR
;
121 const wxChar
*cptr
= wxGetLocale()->GetName().c_str();
122 while(*cptr
&& *cptr
!= _T('_'))
123 newfile
<< *(cptr
++);
124 if(wxDirExists(newfile
))
129 if(! wxDirExists(file
))
132 mapFile
<< file
<< WXEXTHELP_SEPARATOR
<< WXEXTHELP_MAPFILE
;
134 else // try to reload old file
137 if(! wxFileExists(mapFile
))
141 m_MapList
= new wxList
;
144 FILE *input
= fopen(mapFile
.fn_str(),"rt");
149 if(fgets(buffer
,WXEXTHELP_BUFLEN
,input
) && *buffer
!= WXEXTHELP_COMMENTCHAR
)
151 len
= strlen(buffer
);
152 if(buffer
[len
-1] == '\n')
153 buffer
[len
-1] = '\0'; // cut of trailing newline
154 if(sscanf(buffer
,"%d", &id
) != 1)
156 for(i
=0; isdigit(buffer
[i
])||isspace(buffer
[i
])||buffer
[i
]=='-'; i
++)
157 ; // find begin of URL
159 while(buffer
[i
] && ! isspace(buffer
[i
]) && buffer
[i
] !=
160 WXEXTHELP_COMMENTCHAR
)
162 while(buffer
[i
] && buffer
[i
] != WXEXTHELP_COMMENTCHAR
)
166 doc
= (buffer
+ i
+ 1); // skip the comment character
167 m_MapList
->Append(new wxExtHelpMapEntry(id
,url
,doc
));
170 }while(! feof(input
));
173 m_MapFile
= file
; // now it's valid
179 wxHTMLHelpControllerBase::DisplayContents()
183 wxBusyCursor b
; // display a busy cursor
184 return KeywordSearch("");
188 wxHTMLHelpControllerBase::DisplaySection(int sectionNo
)
193 wxBusyCursor b
; // display a busy cursor
194 wxNode
*node
= m_MapList
->First();
195 wxExtHelpMapEntry
*entry
;
198 entry
= (wxExtHelpMapEntry
*)node
->Data();
199 if(entry
->id
== sectionNo
)
200 return DisplayHelp(entry
->url
);
207 wxHTMLHelpControllerBase::DisplayBlock(long blockNo
)
209 return DisplaySection((int)blockNo
);
213 wxHTMLHelpControllerBase::KeywordSearch(const wxString
& k
)
218 wxBusyCursor b
; // display a busy cursor
219 wxString
*choices
= new wxString
[m_NumOfEntries
];
220 wxString
*urls
= new wxString
[m_NumOfEntries
];
221 wxString compA
, compB
;
225 bool showAll
= k
.IsEmpty();
226 wxNode
*node
= m_MapList
->First();
227 wxExtHelpMapEntry
*entry
;
229 compA
= k
; compA
.LowerCase(); // we compare case insensitive
232 entry
= (wxExtHelpMapEntry
*)node
->Data();
233 compB
= entry
->doc
; compB
.LowerCase();
234 if((showAll
|| compB
.Contains(k
)) && ! compB
.IsEmpty())
236 urls
[idx
] = entry
->url
;
238 // choices[idx] = (**i).doc.Contains((**i).doc.Before(WXEXTHELP_COMMENTCHAR));
239 //if(choices[idx].IsEmpty()) // didn't contain the ';'
240 // choices[idx] = (**i).doc;
242 for(j
=0;entry
->doc
.c_str()[j
]
243 && entry
->doc
.c_str()[j
] != WXEXTHELP_COMMENTCHAR
; j
++)
244 choices
[idx
] << entry
->doc
.c_str()[j
];
251 rc
= DisplayHelp(urls
[0]);
254 wxMessageBox(_("No entries found."));
259 idx
= wxGetSingleChoiceIndex(showAll
? _("Help Index") : _("Relevant entries:"),
260 showAll
? _("Help Index") : _("Entries found"),
263 rc
= DisplayHelp(urls
[idx
]);
275 wxHTMLHelpControllerBase::Quit()
281 wxHTMLHelpControllerBase::OnQuit()