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"
56 static PyObject* mod_dict = NULL; // will be set by init
58 #include <wx/html/mod_templ.h>
60 TAG_HANDLER_BEGIN(PYTHONTAG, "PYTHON")
69 bool doSave = wxPyRestoreThread();
71 if (tag.HasParam("FLOAT"))
72 tag.ScanParam("FLOAT", "%i", &fl);
73 PyObject* pyfunc = PyDict_GetItemString(mod_dict, "WidgetStarter");
75 errmsg = "Could not find object WidgetStarter";
78 if (! PyCallable_Check(pyfunc)) {
79 errmsg = "WidgetStarter does not appear to be callable";
82 SWIG_MakePtr(pbuf, m_WParser->GetWindow(), "_wxPyHtmlWindow_p");
83 PyObject* arglist = Py_BuildValue("(s,s)", pbuf,
84 (const char*)tag.GetAllParams());
86 errmsg = "Failed making argument list";
89 PyObject* ret = PyEval_CallObject(pyfunc, arglist);
92 errmsg = "An error occured while calling WidgetStarter";
98 if (PyString_Check(ret)) {
99 char* thisc = PyString_AsString(ret);
100 SWIG_GetPtr(thisc, (void**)&wnd, "_wxWindow_p");
104 errmsg = "Could not make a wxWindow pointer from return ptr";
107 wxPySaveThread(doSave);
109 m_WParser->OpenContainer()->InsertCell(new wxHtmlWidgetCell(wnd, fl));
113 wxPySaveThread(doSave);
115 /* we got out of the loop. Must be an error. Show a box stating it. */
116 wnd = new wxTextCtrl( m_WParser -> GetWindow(), -1,
117 errmsg, wxPoint(0,0),
118 wxSize(300, 100), wxTE_MULTILINE );
120 m_WParser->OpenContainer()->InsertCell(new wxHtmlWidgetCell(wnd, 100));
124 TAG_HANDLER_END(PYTHONTAG)
126 TAGS_MODULE_BEGIN(PythonTag)
128 TAGS_MODULE_ADD(PYTHONTAG)
130 TAGS_MODULE_END(PythonTag)
132 // Note: see also the init function where we add the module!
136 //---------------------------------------------------------------------------
156 HTML_INDENT_HORIZONTAL,
157 HTML_INDENT_VERTICAL,
161 HTML_COND_ISIMAGEMAP,
166 //---------------------------------------------------------------------------
170 // Never need to create a new tag from Python...
171 //wxHtmlTag(const wxString& source, int pos, int end_pos, wxHtmlTagsCache* cache);
174 bool HasParam(const wxString& par);
175 wxString GetParam(const wxString& par, int with_commas = FALSE);
177 // Can't do this one as-is, but GetParam should be enough...
178 //int ScanParam(const wxString& par, const char *format, void* param);
180 wxString GetAllParams();
189 //---------------------------------------------------------------------------
193 // wxHtmlParser(); This is an abstract base class...
195 void SetFS(wxFileSystem *fs);
196 wxFileSystem* GetFS();
197 wxObject* Parse(const wxString& source);
198 void InitParser(const wxString& source);
200 void DoParsing(int begin_pos, int end_pos);
201 // wxObject* GetProduct();
202 void AddTagHandler(wxHtmlTagHandler *handler);
203 wxString* GetSource();
206 // void AddText(const char* txt) = 0;
207 // void AddTag(const wxHtmlTag& tag);
211 //---------------------------------------------------------------------------
213 class wxHtmlWinParser : public wxHtmlParser {
215 wxHtmlWinParser(wxWindow *wnd);
217 void SetDC(wxDC *dc);
221 wxWindow* GetWindow();
222 void SetFonts(wxString normal_face, int normal_italic_mode,
223 wxString fixed_face, int fixed_italic_mode, int *LIST);
225 wxHtmlContainerCell* GetContainer();
226 wxHtmlContainerCell* OpenContainer();
227 wxHtmlContainerCell* CloseContainer();
229 void SetFontSize(int s);
231 void SetFontBold(int x);
233 void SetFontItalic(int x);
234 int GetFontUnderlined();
235 void SetFontUnderlined(int x);
237 void SetFontFixed(int x);
239 void SetAlign(int a);
240 const wxColour& GetLinkColor();
241 void SetLinkColor(const wxColour& clr);
242 const wxColour& GetActualColor();
243 void SetActualColor(const wxColour& clr);
244 const wxString& GetLink();
245 void SetLink(const wxString& link);
246 wxFont* CreateCurrentFont();
251 //---------------------------------------------------------------------------
254 class wxPyHtmlTagHandler : public wxHtmlTagHandler {
256 wxPyHtmlTagHandler() : wxHtmlTagHandler() {};
258 wxHtmlParser* GetParser() { return m_Parser; }
259 void ParseInner(const wxHtmlTag& tag) { wxHtmlTagHandler::ParseInner(tag); }
261 DEC_PYCALLBACK_STRING__pure(GetSupportedTags);
262 DEC_PYCALLBACK_BOOL_TAG_pure(HandleTag);
267 IMP_PYCALLBACK_STRING__pure(wxPyHtmlTagHandler, wxHtmlTagHandler, GetSupportedTags);
268 IMP_PYCALLBACK_BOOL_TAG_pure(wxPyHtmlTagHandler, wxHtmlTagHandler, HandleTag);
272 %name(wxHtmlTagHandler) class wxPyHtmlTagHandler {
274 wxPyHtmlTagHandler();
276 void _setSelf(PyObject* self);
277 %pragma(python) addtomethod = "__init__:self._setSelf(self)"
279 void SetParser(wxHtmlParser *parser);
280 wxHtmlParser* GetParser();
281 void ParseInner(const wxHtmlTag& tag);
285 //---------------------------------------------------------------------------
288 class wxPyHtmlWinTagHandler : public wxHtmlWinTagHandler {
290 wxPyHtmlWinTagHandler() : wxHtmlWinTagHandler() {};
292 wxHtmlWinParser* GetParser() { return m_WParser; }
293 void ParseInner(const wxHtmlTag& tag)
294 { wxHtmlWinTagHandler::ParseInner(tag); }
296 DEC_PYCALLBACK_STRING__pure(GetSupportedTags);
297 DEC_PYCALLBACK_BOOL_TAG_pure(HandleTag);
302 IMP_PYCALLBACK_STRING__pure(wxPyHtmlWinTagHandler, wxHtmlWinTagHandler, GetSupportedTags);
303 IMP_PYCALLBACK_BOOL_TAG_pure(wxPyHtmlWinTagHandler, wxHtmlWinTagHandler, HandleTag);
307 %name(wxHtmlWinTagHandler) class wxPyHtmlWinTagHandler : public wxPyHtmlTagHandler {
309 wxPyHtmlWinTagHandler();
311 void _setSelf(PyObject* self);
312 %pragma(python) addtomethod = "__init__:self._setSelf(self)"
314 void SetParser(wxHtmlParser *parser);
315 wxHtmlWinParser* GetParser();
316 void ParseInner(const wxHtmlTag& tag);
320 //---------------------------------------------------------------------------
324 class wxPyHtmlTagsModule : public wxHtmlTagsModule {
326 wxPyHtmlTagsModule(PyObject* thc) : wxHtmlTagsModule() {
327 m_tagHandlerClass = thc;
328 Py_INCREF(m_tagHandlerClass);
329 RegisterModule(this);
330 wxHtmlWinParser::AddModule(this);
334 Py_DECREF(m_tagHandlerClass);
335 m_tagHandlerClass = NULL;
336 for (int x=0; x < m_objArray.GetCount(); x++) {
337 PyObject* obj = (PyObject*)m_objArray.Item(x);
342 void FillHandlersTable(wxHtmlWinParser *parser) {
343 // Wave our magic wand... (if it works it's a miracle! ;-)
345 // First, make a new instance of the tag handler
346 bool doSave = wxPyRestoreThread();
347 PyObject* arg = Py_BuildValue("()");
348 PyObject* obj = PyInstance_New(m_tagHandlerClass, arg, NULL);
350 wxPySaveThread(doSave);
352 // now figure out where it's C++ object is...
353 wxPyHtmlWinTagHandler* thPtr;
354 if (SWIG_GetPtrObj(obj, (void **)&thPtr, "_wxPyHtmlWinTagHandler_p"))
358 parser->AddTagHandler(thPtr);
365 PyObject* m_tagHandlerClass;
366 wxArrayPtrVoid m_objArray;
374 void wxHtmlWinParser_AddTagHandler(PyObject* tagHandlerClass) {
375 // Dynamically create a new wxModule. Refcounts tagHandlerClass
376 // and adds itself to the wxModules list and to the wxHtmlWinParser.
377 new wxPyHtmlTagsModule(tagHandlerClass);
381 //---------------------------------------------------------------------------
382 //---------------------------------------------------------------------------
388 void SetParent(wxHtmlContainerCell *p);
389 wxHtmlContainerCell* GetParent();
395 wxString GetLink(int x = 0, int y = 0);
396 wxHtmlCell* GetNext();
397 void SetPos(int x, int y);
398 void SetLink(const wxString& link);
399 void SetNext(wxHtmlCell *cell);
401 void Draw(wxDC& dc, int x, int y, int view_y1, int view_y2);
402 void DrawInvisible(wxDC& dc, int x, int y);
403 const wxHtmlCell* Find(int condition, const void* param);
407 class wxHtmlContainerCell : public wxHtmlCell {
409 wxHtmlContainerCell(wxHtmlContainerCell *parent);
411 void InsertCell(wxHtmlCell *cell);
412 void SetAlignHor(int al);
414 void SetAlignVer(int al);
416 void SetIndent(int i, int what, int units = HTML_UNITS_PIXELS);
417 int GetIndent(int ind);
418 int GetIndentUnits(int ind);
419 void SetAlign(const wxHtmlTag& tag);
420 void SetWidthFloat(int w, int units);
421 %name(SetWidthFloatFromTag)void SetWidthFloat(const wxHtmlTag& tag);
422 void SetMinHeight(int h, int align = HTML_ALIGN_TOP);
423 int GetMaxLineWidth();
424 void SetBackgroundColour(const wxColour& clr);
425 void SetBorder(const wxColour& clr1, const wxColour& clr2);
426 wxHtmlCell* GetFirstCell();
432 class wxHtmlWidgetCell : public wxHtmlCell {
434 wxHtmlWidgetCell(wxWindow* wnd, int w = 0);
440 //---------------------------------------------------------------------------
441 //---------------------------------------------------------------------------
442 //---------------------------------------------------------------------------
444 // item of history list
445 class HtmlHistoryItem {
447 HtmlHistoryItem(const char* p, const char* a);
451 const wxString& GetPage();
452 const wxString& GetAnchor();
456 //---------------------------------------------------------------------------
458 class wxPyHtmlWindow : public wxHtmlWindow {
460 wxPyHtmlWindow(wxWindow *parent, wxWindowID id = -1,
461 const wxPoint& pos = wxDefaultPosition,
462 const wxSize& size = wxDefaultSize,
463 long style = wxHW_SCROLLBAR_AUTO,
464 const wxString& name = "htmlWindow")
465 : wxHtmlWindow(parent, id, pos, size, style, name) {};
467 DEC_PYCALLBACK__STRING(OnLinkClicked);
472 IMP_PYCALLBACK__STRING(wxPyHtmlWindow, wxHtmlWindow, OnLinkClicked);
477 %name(wxHtmlWindow) class wxPyHtmlWindow : public wxScrolledWindow {
479 wxPyHtmlWindow(wxWindow *parent, int id = -1,
480 wxPoint& pos = wxPyDefaultPosition,
481 wxSize& size = wxPyDefaultSize,
482 int flags=wxHW_SCROLLBAR_AUTO,
483 char* name = "htmlWindow");
485 void _setSelf(PyObject* self);
486 %pragma(python) addtomethod = "__init__:self._setSelf(self)"
487 %pragma(python) addtomethod = "__init__:wx._StdWindowCallbacks(self)"
488 %pragma(python) addtomethod = "__init__:wx._StdOnScrollCallbacks(self)"
491 bool SetPage(const char* source);
492 // Set HTML page and display it. !! source is HTML document itself,
493 // it is NOT address/filename of HTML document. If you want to
494 // specify document location, use LoadPage() istead
495 // Return value : FALSE if an error occured, TRUE otherwise
497 bool LoadPage(const char* location);
498 // Load HTML page from given location. Location can be either
499 // a) /usr/wxGTK2/docs/html/wx.htm
500 // b) http://www.somewhere.uk/document.htm
501 // c) ftp://ftp.somesite.cz/pub/something.htm
502 // In case there is no prefix (http:,ftp:), the method
503 // will try to find it itself (1. local file, then http or ftp)
504 // After the page is loaded, the method calls SetPage() to display it.
505 // Note : you can also use path relative to previously loaded page
506 // Return value : same as SetPage
508 wxString GetOpenedPage();
509 // Returns full location of opened page
511 void SetRelatedFrame(wxFrame* frame, const char* format);
512 // sets frame in which page title will be displayed. Format is format of
513 // frame title, e.g. "HtmlHelp : %s". It must contain exactly one %s
514 wxFrame* GetRelatedFrame();
516 void SetRelatedStatusBar(int bar);
517 // after(!) calling SetRelatedFrame, this sets statusbar slot where messages
518 // will be displayed. Default is -1 = no messages.
520 void SetFonts(wxString normal_face, int normal_italic_mode,
521 wxString fixed_face, int fixed_italic_mode, int *LIST);
522 // sets fonts to be used when displaying HTML page.
523 // *_italic_mode can be either wxSLANT or wxITALIC
525 void SetTitle(const char* title);
526 // Sets the title of the window
527 // (depending on the information passed to SetRelatedFrame() method)
529 void SetBorders(int b);
530 // Sets space between text and window borders.
532 void ReadCustomization(wxConfigBase *cfg, char* path = "");
533 // saves custom settings into cfg config. it will use the path 'path'
534 // if given, otherwise it will save info into currently selected path.
535 // saved values : things set by SetFonts, SetBorders.
537 void WriteCustomization(wxConfigBase *cfg, char* path = "");
541 bool HistoryForward();
542 // Goes to previous/next page (in browsing history)
543 // Returns TRUE if successful, FALSE otherwise
547 wxHtmlContainerCell* GetInternalRepresentation();
548 // Returns pointer to conteiners/cells structure.
549 // It should be used ONLY when printing
551 wxHtmlWinParser* GetParser();
554 void base_OnLinkClicked(const char* link);
555 // called when users clicked on hypertext link. Default behavior is to
556 // call LoadPage(loc)
560 // Static methods are mapped to stand-alone functions
562 void wxHtmlWindow_AddFilter(wxHtmlFilter *filter) {
563 wxHtmlWindow::AddFilter(filter);
568 //---------------------------------------------------------------------------
569 //---------------------------------------------------------------------------
572 extern "C" SWIGEXPORT(void) inithtmlhelpc();
579 /* This is a bit cheesy. SWIG happens to call the dictionary d...
580 * I save it here, 'cause I don't know how to get it back later! */
586 wxClassInfo::CleanUpClasses();
587 wxClassInfo::InitializeClasses();
590 /* specifically add our python tag handler; it doesn't seem to
591 * happen by itself... */
592 wxHtmlWinParser::AddModule(new HTML_ModulePythonTag());
595 // Until wxFileSystem is wrapped...
597 wxFileSystem::AddHandler(new wxZipFSHandler);
601 //----------------------------------------------------------------------
602 // And this gets appended to the shadow class file.
603 //----------------------------------------------------------------------
605 %pragma(python) include="_extras.py";
607 //---------------------------------------------------------------------------