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>
24 //---------------------------------------------------------------------------
27 %include my_typemaps.i
43 static wxString wxPyEmptyStr("");
44 static wxPoint wxPyDefaultPosition(wxDefaultPosition);
45 static wxSize wxPyDefaultSize(wxDefaultSize);
47 static PyThreadState* wxPyThreadState;
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")
69 #ifdef WXP_WITH_THREAD
70 PyEval_RestoreThread(wxPyThreadState);
72 if (tag.HasParam("FLOAT"))
73 tag.ScanParam("FLOAT", "%i", &fl);
74 PyObject* pyfunc = PyDict_GetItemString(mod_dict, "WidgetStarter");
76 errmsg = "Could not find object WidgetStarter";
79 if (! PyCallable_Check(pyfunc)) {
80 errmsg = "WidgetStarter does not appear to be callable";
83 SWIG_MakePtr(pbuf, m_WParser->GetWindow(), "_wxHtmlWindow_p");
84 PyObject* arglist = Py_BuildValue("(s,s)", pbuf,
85 (const char*)tag.GetAllParams());
87 errmsg = "Failed making argument list";
90 PyObject* ret = PyEval_CallObject(pyfunc, arglist);
93 errmsg = "An error occured while calling WidgetStarter";
99 if (PyString_Check(ret)) {
100 char* thisc = PyString_AsString(ret);
101 SWIG_GetPtr(thisc, (void**)&wnd, "_wxWindow_p");
105 errmsg = "Could not make a wxWindow pointer from return ptr";
108 #ifdef WXP_WITH_THREAD
112 m_WParser->OpenContainer()->InsertCell(new wxHtmlWidgetCell(wnd, fl));
116 /* we got out of the loop. Must be an error. Show a box stating it. */
118 #ifdef WXP_WITH_THREAD
122 wnd = new wxTextCtrl( m_WParser -> GetWindow(), -1,
123 errmsg, wxPoint(0,0),
124 wxSize(300, 100), wxTE_MULTILINE );
126 m_WParser->OpenContainer()->InsertCell(new wxHtmlWidgetCell(wnd, 100));
130 TAG_HANDLER_END(PYTHONTAG)
132 TAGS_MODULE_BEGIN(PythonTag)
134 TAGS_MODULE_ADD(PYTHONTAG)
136 TAGS_MODULE_END(PythonTag)
138 // Note: see also the init function where we add the module!
142 //---------------------------------------------------------------------------
144 // item of history list
145 class HtmlHistoryItem
148 HtmlHistoryItem(const char* p, const char* a);
149 int GetPos() const {return m_Pos;}
150 void SetPos(int p) {m_Pos = p;}
151 const wxString& GetPage() const ;
152 const wxString& GetAnchor() const ;
155 class wxHtmlWindow : public wxScrolledWindow
158 wxHtmlWindow(wxWindow *parent, wxWindowID id = -1,
159 const wxPoint& pos = wxPyDefaultPosition,
160 const wxSize& size = wxPyDefaultSize,
161 int flags=wxHW_SCROLLBAR_AUTO,
162 const char* name = "htmlWindow");
163 %pragma(python) addtomethod = "__init__:wx._StdWindowCallbacks(self)"
164 %pragma(python) addtomethod = "__init__:wx._StdOnScrollCallbacks(self)"
166 bool SetPage(const char* source);
167 // Set HTML page and display it. !! source is HTML document itself,
168 // it is NOT address/filename of HTML document. If you want to
169 // specify document location, use LoadPage() istead
170 // Return value : FALSE if an error occured, TRUE otherwise
172 bool LoadPage(const char* location);
173 // Load HTML page from given location. Location can be either
174 // a) /usr/wxGTK2/docs/html/wx.htm
175 // b) http://www.somewhere.uk/document.htm
176 // c) ftp://ftp.somesite.cz/pub/something.htm
177 // In case there is no prefix (http:,ftp:), the method
178 // will try to find it itself (1. local file, then http or ftp)
179 // After the page is loaded, the method calls SetPage() to display it.
180 // Note : you can also use path relative to previously loaded page
181 // Return value : same as SetPage
183 wxString GetOpenedPage() const {return m_OpenedPage;}
184 // Returns full location of opened page
186 void SetRelatedFrame(wxFrame* frame, const char* format);
187 // sets frame in which page title will be displayed. Format is format of
188 // frame title, e.g. "HtmlHelp : %s". It must contain exactly one %s
189 wxFrame* GetRelatedFrame() const;
191 void SetRelatedStatusBar(int bar);
192 // after(!) calling SetRelatedFrame, this sets statusbar slot where messages
193 // will be displayed. Default is -1 = no messages.
195 void SetFonts(wxString normal_face, int normal_italic_mode, wxString fixed_face, int fixed_italic_mode, int *sizes);
196 // sets fonts to be used when displaying HTML page.
197 // *_italic_mode can be either wxSLANT or wxITALIC
199 void SetTitle(const char* title);
200 // Sets the title of the window
201 // (depending on the information passed to SetRelatedFrame() method)
203 void SetBorders(int b);
204 // Sets space between text and window borders.
206 //virtual void ReadCustomization(wxConfigBase *cfg, wxString path = wxEmptyString);
207 // saves custom settings into cfg config. it will use the path 'path'
208 // if given, otherwise it will save info into currently selected path.
209 // saved values : things set by SetFonts, SetBorders.
210 //virtual void WriteCustomization(wxConfigBase *cfg, wxString path = wxEmptyString);
214 bool HistoryForward();
215 // Goes to previous/next page (in browsing history)
216 // Returns TRUE if successful, FALSE otherwise
220 //wxHtmlContainerCell* GetInternalRepresentation() const;
221 // Returns pointer to conteiners/cells structure.
222 // It should be used ONLY when printing
224 //static void AddFilter(wxHtmlFilter *filter);
227 /* This function needs to be eventified! */
228 //virtual void OnLinkClicked(const char* link);
229 // called when users clicked on hypertext link. Default behavior is to
230 // call LoadPage(loc)
232 //static void CleanUpStatics();
233 // cleans static variables
238 //---------------------------------------------------------------------------
242 /* This is a bit cheesy. SWIG happens to call the dictionary d...
243 * I save it here, 'cause I don't know how to get it back later! */
245 wxPyThreadState = PyThreadState_Get();
246 wxClassInfo::CleanUpClasses();
247 wxClassInfo::InitializeClasses();
249 /* specifically add our python tag handler; it doesn't seem to
250 * happen by itself... */
251 wxHtmlWinParser::AddModule(new HTML_ModulePythonTag());
253 // Until wxFileSystem is wrapped...
255 wxFileSystem::AddHandler(new wxZipFSHandler);
259 //---------------------------------------------------------------------------