]>
Commit | Line | Data |
---|---|---|
4b123bb9 HH |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: html.i | |
3 | // Purpose: SWIG definitions of html classes | |
4 | // | |
5 | // Author: Robin Dunn | |
6 | // | |
7 | // Created: 25-nov-1998 | |
8 | // RCS-ID: $Id$ | |
9 | // Copyright: (c) 1998 by Total Control Software | |
10 | // Licence: wxWindows license | |
11 | ///////////////////////////////////////////////////////////////////////////// | |
12 | ||
13 | ||
14 | %module html | |
15 | ||
16 | %{ | |
17 | #include "helpers.h" | |
18 | #include <wx/html/htmlwin.h> | |
19 | #include <wx/image.h> | |
20 | #include <wx/fs_zip.h> | |
21 | #include <wx/fs_inet.h> | |
22 | %} | |
23 | ||
24 | //--------------------------------------------------------------------------- | |
25 | ||
26 | %include typemaps.i | |
27 | %include my_typemaps.i | |
28 | ||
29 | %extern wx.i | |
30 | %extern windows.i | |
31 | %extern _defs.i | |
32 | %extern events.i | |
33 | //%extern windows2.i | |
34 | //%extern windows3.i | |
35 | //%extern frames.i | |
36 | //%extern misc.i | |
37 | //%extern gdi.i | |
38 | //%extern controls.i | |
39 | ||
40 | ||
41 | %{ | |
42 | #ifdef __WXMSW__ | |
43 | static wxString wxPyEmptyStr(""); | |
44 | static wxPoint wxPyDefaultPosition(wxDefaultPosition); | |
45 | static wxSize wxPyDefaultSize(wxDefaultSize); | |
46 | #endif | |
47 | static PyThreadState* wxPyThreadState; | |
48 | %} | |
49 | ||
50 | %pragma(python) code = "import wx,htmlhelper" | |
51 | %pragma(python) code = "widget = htmlc" | |
52 | ||
53 | %{ | |
54 | ||
55 | static PyObject* mod_dict = NULL; // will be set by init | |
56 | ||
57 | #include <wx/html/mod_templ.h> | |
58 | ||
59 | TAG_HANDLER_BEGIN(PYTHONTAG, "PYTHON") | |
60 | TAG_HANDLER_PROC(tag) | |
61 | { | |
62 | wxWindow *wnd; | |
63 | wxString errmsg; | |
64 | char pbuf[256]; | |
65 | ||
66 | int fl = 0; | |
67 | ||
68 | while (1) { | |
69 | #ifdef WXP_WITH_THREAD | |
70 | PyEval_RestoreThread(wxPyThreadState); | |
71 | #endif | |
72 | if (tag.HasParam("FLOAT")) | |
73 | tag.ScanParam("FLOAT", "%i", &fl); | |
74 | PyObject* pyfunc = PyDict_GetItemString(mod_dict, "WidgetStarter"); | |
75 | if (pyfunc == NULL) { | |
76 | errmsg = "Could not find object WidgetStarter"; | |
77 | break; | |
78 | } | |
79 | if (! PyCallable_Check(pyfunc)) { | |
80 | errmsg = "WidgetStarter does not appear to be callable"; | |
81 | break; | |
82 | } | |
83 | SWIG_MakePtr(pbuf, m_WParser->GetWindow(), "_wxHtmlWindow_p"); | |
84 | PyObject* arglist = Py_BuildValue("(s,s)", pbuf, | |
85 | (const char*)tag.GetAllParams()); | |
86 | if (! arglist) { | |
87 | errmsg = "Failed making argument list"; | |
88 | break; | |
89 | } | |
90 | PyObject* ret = PyEval_CallObject(pyfunc, arglist); | |
91 | Py_DECREF(arglist); | |
92 | if (ret == NULL) { | |
93 | errmsg = "An error occured while calling WidgetStarter"; | |
94 | if (PyErr_Occurred()) | |
95 | PyErr_Print(); | |
96 | break; | |
97 | } | |
98 | wnd = NULL; | |
99 | if (PyString_Check(ret)) { | |
100 | char* thisc = PyString_AsString(ret); | |
101 | SWIG_GetPtr(thisc, (void**)&wnd, "_wxWindow_p"); | |
102 | } | |
103 | Py_DECREF(ret); | |
104 | if (! wnd) { | |
105 | errmsg = "Could not make a wxWindow pointer from return ptr"; | |
106 | break; | |
107 | } | |
108 | #ifdef WXP_WITH_THREAD | |
109 | PyEval_SaveThread(); | |
110 | #endif | |
111 | wnd -> Show(TRUE); | |
112 | m_WParser->OpenContainer()->InsertCell(new wxHtmlWidgetCell(wnd, fl)); | |
113 | return FALSE; | |
114 | } | |
115 | ||
116 | /* we got out of the loop. Must be an error. Show a box stating it. */ | |
117 | ||
118 | #ifdef WXP_WITH_THREAD | |
119 | PyEval_SaveThread(); | |
120 | #endif | |
121 | ||
122 | wnd = new wxTextCtrl( m_WParser -> GetWindow(), -1, | |
123 | errmsg, wxPoint(0,0), | |
124 | wxSize(300, 100), wxTE_MULTILINE ); | |
125 | wnd -> Show(TRUE); | |
126 | m_WParser->OpenContainer()->InsertCell(new wxHtmlWidgetCell(wnd, 100)); | |
127 | return FALSE; | |
128 | } | |
129 | ||
130 | TAG_HANDLER_END(PYTHONTAG) | |
131 | ||
132 | TAGS_MODULE_BEGIN(PythonTag) | |
133 | ||
134 | TAGS_MODULE_ADD(PYTHONTAG) | |
135 | ||
136 | TAGS_MODULE_END(PythonTag) | |
137 | ||
138 | // Note: see also the init function where we add the module! | |
139 | ||
140 | %} | |
141 | ||
142 | //--------------------------------------------------------------------------- | |
143 | ||
144 | // item of history list | |
145 | class HtmlHistoryItem | |
146 | { | |
147 | public: | |
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 ; | |
153 | }; | |
154 | ||
155 | class wxHtmlWindow : public wxScrolledWindow | |
156 | { | |
157 | public: | |
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)" | |
165 | ||
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 | |
171 | ||
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 | |
182 | ||
183 | wxString GetOpenedPage() const {return m_OpenedPage;} | |
184 | // Returns full location of opened page | |
185 | ||
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; | |
190 | ||
191 | void SetRelatedStatusBar(int bar); | |
192 | // after(!) calling SetRelatedFrame, this sets statusbar slot where messages | |
193 | // will be displayed. Default is -1 = no messages. | |
194 | ||
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 | |
198 | ||
199 | void SetTitle(const char* title); | |
200 | // Sets the title of the window | |
201 | // (depending on the information passed to SetRelatedFrame() method) | |
202 | ||
203 | void SetBorders(int b); | |
204 | // Sets space between text and window borders. | |
205 | ||
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); | |
211 | // ... | |
212 | ||
213 | bool HistoryBack(); | |
214 | bool HistoryForward(); | |
215 | // Goes to previous/next page (in browsing history) | |
216 | // Returns TRUE if successful, FALSE otherwise | |
217 | void HistoryClear(); | |
218 | // Resets history | |
219 | ||
220 | //wxHtmlContainerCell* GetInternalRepresentation() const; | |
221 | // Returns pointer to conteiners/cells structure. | |
222 | // It should be used ONLY when printing | |
223 | ||
224 | //static void AddFilter(wxHtmlFilter *filter); | |
225 | // Adds input filter | |
226 | ||
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) | |
231 | ||
232 | //static void CleanUpStatics(); | |
233 | // cleans static variables | |
234 | ||
235 | }; | |
236 | ||
237 | ||
238 | //--------------------------------------------------------------------------- | |
239 | ||
240 | %init %{ | |
241 | ||
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! */ | |
244 | mod_dict = d; | |
245 | wxPyThreadState = PyThreadState_Get(); | |
246 | wxClassInfo::CleanUpClasses(); | |
247 | wxClassInfo::InitializeClasses(); | |
248 | ||
249 | /* specifically add our python tag handler; it doesn't seem to | |
250 | * happen by itself... */ | |
251 | wxHtmlWinParser::AddModule(new HTML_ModulePythonTag()); | |
252 | ||
253 | // Until wxFileSystem is wrapped... | |
254 | #if wxUSE_FS_ZIP | |
255 | wxFileSystem::AddHandler(new wxZipFSHandler); | |
256 | #endif | |
257 | %} | |
258 | ||
259 | //--------------------------------------------------------------------------- |