1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: SWIG definitions of html classes
7 // Created: 25-nov-1998
9 // Copyright: (c) 1998 by Total Control Software
10 // Licence: wxWindows license
11 /////////////////////////////////////////////////////////////////////////////
18 #include <wx/html/htmlwin.h>
20 #include <wx/fs_zip.h>
21 #include <wx/fs_inet.h>
22 #include <wx/wfstream.h>
26 //---------------------------------------------------------------------------
29 %include my_typemaps.i
40 //---------------------------------------------------------------------------
44 wxString wxPyEmptyStr("");
45 wxPoint wxPyDefaultPosition(wxDefaultPosition);
46 wxSize wxPyDefaultSize(wxDefaultSize);
50 %pragma(python) code = "import wx,htmlhelper"
51 %pragma(python) code = "widget = htmlc"
55 static PyObject* mod_dict = NULL; // will be set by init
57 #include <wx/html/mod_templ.h>
59 TAG_HANDLER_BEGIN(PYTHONTAG, "PYTHON")
68 bool doSave = wxPyRestoreThread();
70 if (tag.HasParam("FLOAT"))
71 tag.ScanParam("FLOAT", "%i", &fl);
72 PyObject* pyfunc = PyDict_GetItemString(mod_dict, "WidgetStarter");
74 errmsg = "Could not find object WidgetStarter";
77 if (! PyCallable_Check(pyfunc)) {
78 errmsg = "WidgetStarter does not appear to be callable";
81 SWIG_MakePtr(pbuf, m_WParser->GetWindow(), "_wxPyHtmlWindow_p");
82 PyObject* arglist = Py_BuildValue("(s,s)", pbuf,
83 (const char*)tag.GetAllParams());
85 errmsg = "Failed making argument list";
88 PyObject* ret = PyEval_CallObject(pyfunc, arglist);
91 errmsg = "An error occured while calling WidgetStarter";
97 if (PyString_Check(ret)) {
98 char* thisc = PyString_AsString(ret);
99 SWIG_GetPtr(thisc, (void**)&wnd, "_wxWindow_p");
103 errmsg = "Could not make a wxWindow pointer from return ptr";
106 wxPySaveThread(doSave);
108 m_WParser->OpenContainer()->InsertCell(new wxHtmlWidgetCell(wnd, fl));
112 wxPySaveThread(doSave);
114 /* we got out of the loop. Must be an error. Show a box stating it. */
115 wnd = new wxTextCtrl( m_WParser -> GetWindow(), -1,
116 errmsg, wxPoint(0,0),
117 wxSize(300, 100), wxTE_MULTILINE );
119 m_WParser->OpenContainer()->InsertCell(new wxHtmlWidgetCell(wnd, 100));
123 TAG_HANDLER_END(PYTHONTAG)
125 TAGS_MODULE_BEGIN(PythonTag)
127 TAGS_MODULE_ADD(PYTHONTAG)
129 TAGS_MODULE_END(PythonTag)
131 // Note: see also the init function where we add the module!
135 //---------------------------------------------------------------------------
136 //---------------------------------------------------------------------------
140 // Never need to create a new tag...
141 //wxHtmlTag(const wxString& source, int pos, int end_pos, wxHtmlTagsCache* cache);
144 bool HasParam(const wxString& par);
145 wxString GetParam(const wxString& par, int with_commas = FALSE);
147 // Can't do this one as-is, but GetParam should be enough...
148 //int ScanParam(const wxString& par, const char *format, void* param);
150 wxString GetAllParams();
159 //---------------------------------------------------------------------------
163 // wxHtmlParser(); This is an abstract base class...
165 void SetFS(wxFileSystem *fs);
166 wxFileSystem* GetFS();
167 wxObject* Parse(const wxString& source);
168 void InitParser(const wxString& source);
170 void DoParsing(int begin_pos, int end_pos);
171 // wxObject* GetProduct();
172 void AddTagHandler(wxHtmlTagHandler *handler);
173 wxString* GetSource();
176 // void AddText(const char* txt) = 0;
177 // void AddTag(const wxHtmlTag& tag);
181 //---------------------------------------------------------------------------
183 class wxHtmlWinParser : public wxHtmlParser {
185 wxHtmlWinParser(wxWindow *wnd);
187 void SetDC(wxDC *dc);
191 wxWindow* GetWindow();
192 void SetFonts(wxString normal_face, int normal_italic_mode,
193 wxString fixed_face, int fixed_italic_mode, int *LIST);
195 wxHtmlContainerCell* GetContainer();
196 wxHtmlContainerCell* OpenContainer();
197 wxHtmlContainerCell* CloseContainer();
199 void SetFontSize(int s);
201 void SetFontBold(int x);
203 void SetFontItalic(int x);
204 int GetFontUnderlined();
205 void SetFontUnderlined(int x);
207 void SetFontFixed(int x);
209 void SetAlign(int a);
210 const wxColour& GetLinkColor();
211 void SetLinkColor(const wxColour& clr);
212 const wxColour& GetActualColor();
213 void SetActualColor(const wxColour& clr);
214 const wxString& GetLink();
215 void SetLink(const wxString& link);
216 wxFont* CreateCurrentFont();
221 //---------------------------------------------------------------------------
224 class wxPyHtmlTagHandler : public wxHtmlTagHandler {
226 wxPyHtmlTagHandler() : wxHtmlTagHandler() {};
228 wxHtmlParser* GetParser() { return m_Parser; }
229 void ParseInner(const wxHtmlTag& tag) { wxHtmlTagHandler::ParseInner(tag); }
231 DEC_PYCALLBACK_STRING__pure(GetSupportedTags);
232 DEC_PYCALLBACK_BOOL_TAG_pure(HandleTag);
237 IMP_PYCALLBACK_STRING__pure(wxPyHtmlTagHandler, wxHtmlTagHandler, GetSupportedTags);
238 IMP_PYCALLBACK_BOOL_TAG_pure(wxPyHtmlTagHandler, wxHtmlTagHandler, HandleTag);
243 %name(wxHtmlTagHandler) class wxPyHtmlTagHandler {
245 wxPyHtmlTagHandler();
247 void _setSelf(PyObject* self);
248 %pragma(python) addtomethod = "__init__:self._setSelf(self)"
250 void SetParser(wxHtmlParser *parser);
251 wxHtmlParser* GetParser();
252 void ParseInner(const wxHtmlTag& tag);
256 //---------------------------------------------------------------------------
259 class wxPyHtmlWinTagHandler : public wxHtmlWinTagHandler {
261 wxPyHtmlWinTagHandler() : wxHtmlWinTagHandler() {};
263 wxHtmlWinParser* GetParser() { return m_WParser; }
264 void ParseInner(const wxHtmlTag& tag)
265 { wxHtmlWinTagHandler::ParseInner(tag); }
267 DEC_PYCALLBACK_STRING__pure(GetSupportedTags);
268 DEC_PYCALLBACK_BOOL_TAG_pure(HandleTag);
273 IMP_PYCALLBACK_STRING__pure(wxPyHtmlWinTagHandler, wxHtmlWinTagHandler, GetSupportedTags);
274 IMP_PYCALLBACK_BOOL_TAG_pure(wxPyHtmlWinTagHandler, wxHtmlWinTagHandler, HandleTag);
279 %name(wxHtmlWinTagHandler) class wxPyHtmlWinTagHandler : public wxPyHtmlTagHandler {
281 wxPyHtmlWinTagHandler();
283 void _setSelf(PyObject* self);
284 %pragma(python) addtomethod = "__init__:self._setSelf(self)"
286 void SetParser(wxHtmlParser *parser);
287 wxHtmlWinParser* GetParser();
288 void ParseInner(const wxHtmlTag& tag);
292 //---------------------------------------------------------------------------
296 class wxPyHtmlTagsModule : public wxHtmlTagsModule {
298 wxPyHtmlTagsModule(PyObject* thc) : wxHtmlTagsModule() {
299 m_tagHandlerClass = thc;
300 Py_INCREF(m_tagHandlerClass);
301 RegisterModule(this);
302 wxHtmlWinParser::AddModule(this);
306 Py_DECREF(m_tagHandlerClass);
307 m_tagHandlerClass = NULL;
308 for (int x=0; x < m_objArray.GetCount(); x++) {
309 PyObject* obj = (PyObject*)m_objArray.Item(x);
314 void FillHandlersTable(wxHtmlWinParser *parser) {
315 // Wave our magic wand... (if it works it's a miracle! ;-)
317 // First, make a new instance of the tag handler
318 PyObject* arg = Py_BuildValue("()");
319 PyObject* obj = PyInstance_New(m_tagHandlerClass, arg, NULL);
322 // now figure out where it's C++ object is...
323 wxPyHtmlWinTagHandler* thPtr;
324 if (SWIG_GetPtrObj(obj, (void **)&thPtr, "_wxPyHtmlWinTagHandler_p"))
328 parser->AddTagHandler(thPtr);
335 PyObject* m_tagHandlerClass;
336 wxArrayPtrVoid m_objArray;
344 void wxHtmlWinParser_AddTagHandler(PyObject* tagHandlerClass) {
345 // Dynamically create a new wxModule. Refcounts tagHandlerClass
346 // and adds itself to the wxModules list and to the wxHtmlWinParser.
347 new wxPyHtmlTagsModule(tagHandlerClass);
353 //---------------------------------------------------------------------------
354 //---------------------------------------------------------------------------
355 //---------------------------------------------------------------------------
357 // item of history list
358 class HtmlHistoryItem {
360 HtmlHistoryItem(const char* p, const char* a);
364 const wxString& GetPage();
365 const wxString& GetAnchor();
369 //---------------------------------------------------------------------------
371 class wxPyHtmlWindow : public wxHtmlWindow {
373 wxPyHtmlWindow(wxWindow *parent, wxWindowID id = -1,
374 const wxPoint& pos = wxDefaultPosition,
375 const wxSize& size = wxDefaultSize,
376 long style = wxHW_SCROLLBAR_AUTO,
377 const wxString& name = "htmlWindow")
378 : wxHtmlWindow(parent, id, pos, size, style, name) {};
380 DEC_PYCALLBACK__STRING(OnLinkClicked);
385 IMP_PYCALLBACK__STRING(wxPyHtmlWindow, wxHtmlWindow, OnLinkClicked);
390 %name(wxHtmlWindow) class wxPyHtmlWindow : public wxScrolledWindow {
392 wxPyHtmlWindow(wxWindow *parent, int id = -1,
393 wxPoint& pos = wxPyDefaultPosition,
394 wxSize& size = wxPyDefaultSize,
395 int flags=wxHW_SCROLLBAR_AUTO,
396 char* name = "htmlWindow");
398 void _setSelf(PyObject* self);
399 %pragma(python) addtomethod = "__init__:self._setSelf(self)"
400 %pragma(python) addtomethod = "__init__:wx._StdWindowCallbacks(self)"
401 %pragma(python) addtomethod = "__init__:wx._StdOnScrollCallbacks(self)"
404 bool SetPage(const char* source);
405 // Set HTML page and display it. !! source is HTML document itself,
406 // it is NOT address/filename of HTML document. If you want to
407 // specify document location, use LoadPage() istead
408 // Return value : FALSE if an error occured, TRUE otherwise
410 bool LoadPage(const char* location);
411 // Load HTML page from given location. Location can be either
412 // a) /usr/wxGTK2/docs/html/wx.htm
413 // b) http://www.somewhere.uk/document.htm
414 // c) ftp://ftp.somesite.cz/pub/something.htm
415 // In case there is no prefix (http:,ftp:), the method
416 // will try to find it itself (1. local file, then http or ftp)
417 // After the page is loaded, the method calls SetPage() to display it.
418 // Note : you can also use path relative to previously loaded page
419 // Return value : same as SetPage
421 wxString GetOpenedPage();
422 // Returns full location of opened page
424 void SetRelatedFrame(wxFrame* frame, const char* format);
425 // sets frame in which page title will be displayed. Format is format of
426 // frame title, e.g. "HtmlHelp : %s". It must contain exactly one %s
427 wxFrame* GetRelatedFrame();
429 void SetRelatedStatusBar(int bar);
430 // after(!) calling SetRelatedFrame, this sets statusbar slot where messages
431 // will be displayed. Default is -1 = no messages.
433 void SetFonts(wxString normal_face, int normal_italic_mode,
434 wxString fixed_face, int fixed_italic_mode, int *LIST);
435 // sets fonts to be used when displaying HTML page.
436 // *_italic_mode can be either wxSLANT or wxITALIC
438 void SetTitle(const char* title);
439 // Sets the title of the window
440 // (depending on the information passed to SetRelatedFrame() method)
442 void SetBorders(int b);
443 // Sets space between text and window borders.
445 void ReadCustomization(wxConfigBase *cfg, char* path = "");
446 // saves custom settings into cfg config. it will use the path 'path'
447 // if given, otherwise it will save info into currently selected path.
448 // saved values : things set by SetFonts, SetBorders.
450 void WriteCustomization(wxConfigBase *cfg, char* path = "");
454 bool HistoryForward();
455 // Goes to previous/next page (in browsing history)
456 // Returns TRUE if successful, FALSE otherwise
460 wxHtmlContainerCell* GetInternalRepresentation();
461 // Returns pointer to conteiners/cells structure.
462 // It should be used ONLY when printing
465 void base_OnLinkClicked(const char* link);
466 // called when users clicked on hypertext link. Default behavior is to
467 // call LoadPage(loc)
471 // Static methods are mapped to stand-alone functions
473 void wxHtmlWindow_AddFilter(wxHtmlFilter *filter) {
474 wxHtmlWindow::AddFilter(filter);
479 //---------------------------------------------------------------------------
480 //---------------------------------------------------------------------------
483 extern "C" SWIGEXPORT(void) inithtmlhelpc();
489 /* This is a bit cheesy. SWIG happens to call the dictionary d...
490 * I save it here, 'cause I don't know how to get it back later! */
495 wxClassInfo::CleanUpClasses();
496 wxClassInfo::InitializeClasses();
498 /* specifically add our python tag handler; it doesn't seem to
499 * happen by itself... */
500 wxHtmlWinParser::AddModule(new HTML_ModulePythonTag());
502 // Until wxFileSystem is wrapped...
504 wxFileSystem::AddHandler(new wxZipFSHandler);
508 //---------------------------------------------------------------------------