]> git.saurik.com Git - wxWidgets.git/blobdiff - utils/wxPython/modules/html/html.i
it is now possible to add custom buttons into wxHtmlHelpFrame's toolbar
[wxWidgets.git] / utils / wxPython / modules / html / html.i
index 3d6d878342dc4858ca6bd1904f8f9b2e5252702e..dfbe42c3dc27d8d16c3b247c53374f5699490d53 100644 (file)
 %{
 #include "helpers.h"
 #include <wx/html/htmlwin.h>
+#include <wx/html/htmprint.h>
 #include <wx/image.h>
 #include <wx/fs_zip.h>
 #include <wx/fs_inet.h>
 #include <wx/wfstream.h>
-#include "helpsys.h"
+
+#include "printfw.h"
 %}
 
 //---------------------------------------------------------------------------
@@ -34,6 +36,7 @@
 %extern events.i
 %extern controls.i
 %extern controls2.i
+%extern printfw.i
 
 %extern utils.i
 
@@ -47,97 +50,55 @@ wxSize wxPyDefaultSize(wxDefaultSize);
 #endif
 %}
 
-%pragma(python) code = "import wx,htmlhelper"
-%pragma(python) code = "widget = htmlc"
-
-%{
-
-static PyObject* mod_dict = NULL; // will be set by init
-
-#include <wx/html/mod_templ.h>
+%pragma(python) code = "import wx"
 
-TAG_HANDLER_BEGIN(PYTHONTAG, "PYTHON")
-    TAG_HANDLER_PROC(tag)
-    {
-        wxWindow *wnd;
-        wxString errmsg;
-        char pbuf[256];
 
-        int fl = 0;
+//---------------------------------------------------------------------------
 
-        bool doSave = wxPyRestoreThread();
-        while (1) {
-           if (tag.HasParam("FLOAT"))
-               tag.ScanParam("FLOAT", "%i", &fl);
-           PyObject* pyfunc = PyDict_GetItemString(mod_dict, "WidgetStarter");
-           if (pyfunc == NULL) {
-               errmsg = "Could not find object WidgetStarter";
-               break;
-           }
-           if (! PyCallable_Check(pyfunc)) {
-               errmsg = "WidgetStarter does not appear to be callable";
-               break;
-           }
-           SWIG_MakePtr(pbuf, m_WParser->GetWindow(), "_wxPyHtmlWindow_p");
-           PyObject* arglist = Py_BuildValue("(s,s)", pbuf,
-                               (const char*)tag.GetAllParams());
-           if (! arglist) {
-               errmsg = "Failed making argument list";
-               break;
-           }
-           PyObject* ret = PyEval_CallObject(pyfunc, arglist);
-           Py_DECREF(arglist);
-           if (ret == NULL) {
-              errmsg = "An error occured while calling WidgetStarter";
-              if (PyErr_Occurred())
-                 PyErr_Print();
-              break;
-           }
-           wnd = NULL;
-           if (PyString_Check(ret)) {
-              char* thisc = PyString_AsString(ret);
-              SWIG_GetPtr(thisc, (void**)&wnd, "_wxWindow_p");
-           }
-           Py_DECREF(ret);
-           if (! wnd) {
-               errmsg = "Could not make a wxWindow pointer from return ptr";
-               break;
-           }
-           wxPySaveThread(doSave);
-           wnd -> Show(TRUE);
-           m_WParser->OpenContainer()->InsertCell(new wxHtmlWidgetCell(wnd, fl));
-           return FALSE;
-        }
+enum {
+    wxHTML_ALIGN_LEFT,
+    wxHTML_ALIGN_CENTER,
+    wxHTML_ALIGN_RIGHT,
+    wxHTML_ALIGN_BOTTOM,
+    wxHTML_ALIGN_TOP,
 
-        wxPySaveThread(doSave);
+    wxHTML_CLR_FOREGROUND,
+    wxHTML_CLR_BACKGROUND,
 
-        /* we got out of the loop. Must be an error. Show a box stating it. */
-        wnd = new wxTextCtrl( m_WParser -> GetWindow(), -1,
-                              errmsg, wxPoint(0,0),
-                              wxSize(300, 100), wxTE_MULTILINE );
-        wnd -> Show(TRUE);
-        m_WParser->OpenContainer()->InsertCell(new wxHtmlWidgetCell(wnd, 100));
-        return FALSE;
-    }
+    wxHTML_UNITS_PIXELS,
+    wxHTML_UNITS_PERCENT,
 
-TAG_HANDLER_END(PYTHONTAG)
+    wxHTML_INDENT_LEFT,
+    wxHTML_INDENT_RIGHT,
+    wxHTML_INDENT_TOP,
+    wxHTML_INDENT_BOTTOM,
 
-TAGS_MODULE_BEGIN(PythonTag)
+    wxHTML_INDENT_HORIZONTAL,
+    wxHTML_INDENT_VERTICAL,
+    wxHTML_INDENT_ALL,
 
-    TAGS_MODULE_ADD(PYTHONTAG)
+    wxHTML_COND_ISANCHOR,
+    wxHTML_COND_ISIMAGEMAP,
+    wxHTML_COND_USER,
+};
 
-TAGS_MODULE_END(PythonTag)
 
-// Note: see also the init function where we add the module!
+//---------------------------------------------------------------------------
 
-%}
+class wxHtmlLinkInfo {
+public:
+    wxHtmlLinkInfo(const wxString& href, const wxString& target = wxEmptyString);
+    wxString GetHref();
+    wxString GetTarget();
+    wxMouseEvent* GetEvent();
+    wxHtmlCell* GetHtmlCell();
+};
 
-//---------------------------------------------------------------------------
 //---------------------------------------------------------------------------
 
 class wxHtmlTag {
 public:
-    // Never need to create a new tag...
+    // Never need to create a new tag from Python...
     //wxHtmlTag(const wxString& source, int pos, int end_pos, wxHtmlTagsCache* cache);
 
     wxString GetName();
@@ -171,6 +132,8 @@ public:
     // wxObject* GetProduct();
     void AddTagHandler(wxHtmlTagHandler *handler);
     wxString* GetSource();
+    void PushTagHandler(wxHtmlTagHandler* handler, wxString tags);
+    void PopTagHandler();
 
 
     // void AddText(const char* txt) = 0;
@@ -189,12 +152,13 @@ public:
     int GetCharHeight();
     int GetCharWidth();
     wxWindow* GetWindow();
-    void SetFonts(wxString normal_face, int normal_italic_mode,
-                  wxString fixed_face, int fixed_italic_mode, int *LIST);
+    void SetFonts(wxString normal_face, wxString fixed_face, int *LIST);
 
     wxHtmlContainerCell* GetContainer();
     wxHtmlContainerCell* OpenContainer();
+    wxHtmlContainerCell *SetContainer(wxHtmlContainerCell *c);
     wxHtmlContainerCell* CloseContainer();
+
     int GetFontSize();
     void SetFontSize(int s);
     int GetFontBold();
@@ -211,9 +175,10 @@ public:
     void SetLinkColor(const wxColour& clr);
     const wxColour& GetActualColor();
     void SetActualColor(const wxColour& clr);
-    const wxString& GetLink();
     void SetLink(const wxString& link);
     wxFont* CreateCurrentFont();
+    wxHtmlLinkInfo GetLink();
+
 };
 
 
@@ -236,7 +201,6 @@ public:
 
 IMP_PYCALLBACK_STRING__pure(wxPyHtmlTagHandler, wxHtmlTagHandler, GetSupportedTags);
 IMP_PYCALLBACK_BOOL_TAG_pure(wxPyHtmlTagHandler, wxHtmlTagHandler, HandleTag);
-
 %}
 
 
@@ -272,7 +236,6 @@ public:
 
 IMP_PYCALLBACK_STRING__pure(wxPyHtmlWinTagHandler, wxHtmlWinTagHandler, GetSupportedTags);
 IMP_PYCALLBACK_BOOL_TAG_pure(wxPyHtmlWinTagHandler, wxHtmlWinTagHandler, HandleTag);
-
 %}
 
 
@@ -305,7 +268,7 @@ public:
     void OnExit() {
         Py_DECREF(m_tagHandlerClass);
         m_tagHandlerClass = NULL;
-        for (int x=0; x < m_objArray.GetCount(); x++) {
+        for (size_t x=0; x < m_objArray.GetCount(); x++) {
             PyObject* obj = (PyObject*)m_objArray.Item(x);
             Py_DECREF(obj);
         }
@@ -315,9 +278,11 @@ public:
         // Wave our magic wand...  (if it works it's a miracle!  ;-)
 
         // First, make a new instance of the tag handler
+        bool doSave = wxPyRestoreThread();
         PyObject* arg = Py_BuildValue("()");
         PyObject* obj = PyInstance_New(m_tagHandlerClass, arg, NULL);
         Py_DECREF(arg);
+        wxPySaveThread(doSave);
 
         // now figure out where it's C++ object is...
         wxPyHtmlWinTagHandler* thPtr;
@@ -349,6 +314,74 @@ private:
 %}
 
 
+//---------------------------------------------------------------------------
+//---------------------------------------------------------------------------
+
+class wxHtmlCell {
+public:
+    wxHtmlCell();
+
+    int GetPosX();
+    int GetPosY();
+    int GetWidth();
+    int GetHeight();
+    int GetDescent();
+    wxHtmlLinkInfo* GetLink(int x = 0, int y = 0);
+    wxHtmlCell* GetNext();
+    wxHtmlContainerCell* GetParent();
+    void SetLink(const wxHtmlLinkInfo& link);
+    void SetNext(wxHtmlCell *cell);
+    void SetParent(wxHtmlContainerCell *p);
+    void SetPos(int x, int y);
+    void Layout(int w);
+    void Draw(wxDC& dc, int x, int y, int view_y1, int view_y2);
+    void DrawInvisible(wxDC& dc, int x, int y);
+    const wxHtmlCell* Find(int condition, const void* param);
+
+    bool AdjustPagebreak(int * pagebreak);
+    void SetCanLiveOnPagebreak(bool can);
+
+};
+
+
+class wxHtmlContainerCell : public wxHtmlCell {
+public:
+    wxHtmlContainerCell(wxHtmlContainerCell *parent);
+
+    void InsertCell(wxHtmlCell *cell);
+    void SetAlignHor(int al);
+    int GetAlignHor();
+    void SetAlignVer(int al);
+    int GetAlignVer();
+    void SetIndent(int i, int what, int units = wxHTML_UNITS_PIXELS);
+    int GetIndent(int ind);
+    int GetIndentUnits(int ind);
+    void SetAlign(const wxHtmlTag& tag);
+    void SetWidthFloat(int w, int units);
+    %name(SetWidthFloatFromTag)void SetWidthFloat(const wxHtmlTag& tag);
+    void SetMinHeight(int h, int align = wxHTML_ALIGN_TOP);
+    void SetBackgroundColour(const wxColour& clr);
+    void SetBorder(const wxColour& clr1, const wxColour& clr2);
+    wxHtmlCell* GetFirstCell();
+};
+
+
+
+class wxHtmlColourCell : public wxHtmlCell {
+public:
+    wxHtmlColourCell(wxColour clr, int flags = wxHTML_CLR_FOREGROUND);
+
+};
+
+
+
+class wxHtmlWidgetCell : public wxHtmlCell {
+public:
+    wxHtmlWidgetCell(wxWindow* wnd, int w = 0);
+
+};
+
+
 
 //---------------------------------------------------------------------------
 //---------------------------------------------------------------------------
@@ -377,16 +410,34 @@ public:
                    const wxString& name = "htmlWindow")
         : wxHtmlWindow(parent, id, pos, size, style, name)  {};
 
-    DEC_PYCALLBACK__STRING(OnLinkClicked);
 
+    void OnLinkClicked(const wxHtmlLinkInfo& link);
+    void base_OnLinkClicked(const wxHtmlLinkInfo& link);
+
+    DEC_PYCALLBACK__STRING(OnSetTitle);
     PYPRIVATE;
 };
 
-IMP_PYCALLBACK__STRING(wxPyHtmlWindow, wxHtmlWindow, OnLinkClicked);
 
+IMP_PYCALLBACK__STRING(wxPyHtmlWindow, wxHtmlWindow, OnSetTitle);
+
+void wxPyHtmlWindow::OnLinkClicked(const wxHtmlLinkInfo& link) {
+    bool doSave = wxPyRestoreThread();
+    if (m_myInst.findCallback("OnLinkClicked")) {
+        PyObject* obj = wxPyConstructObject((void*)&link, "wxHtmlLinkInfo");
+        m_myInst.callCallback(Py_BuildValue("(O)", obj));
+    }
+    else
+        wxHtmlWindow::OnLinkClicked(link);
+    wxPySaveThread(doSave);
+}
+void wxPyHtmlWindow::base_OnLinkClicked(const wxHtmlLinkInfo& link) {
+    wxHtmlWindow::OnLinkClicked(link);
+}
 %}
 
 
+
 %name(wxHtmlWindow) class wxPyHtmlWindow : public wxScrolledWindow {
 public:
     wxPyHtmlWindow(wxWindow *parent, int id = -1,
@@ -402,70 +453,25 @@ public:
 
 
     bool SetPage(const char* source);
-                // Set HTML page and display it. !! source is HTML document itself,
-                // it is NOT address/filename of HTML document. If you want to
-                // specify document location, use LoadPage() istead
-                // Return value : FALSE if an error occured, TRUE otherwise
-
     bool LoadPage(const char* location);
-                // Load HTML page from given location. Location can be either
-                // a) /usr/wxGTK2/docs/html/wx.htm
-                // b) http://www.somewhere.uk/document.htm
-                // c) ftp://ftp.somesite.cz/pub/something.htm
-                // In case there is no prefix (http:,ftp:), the method
-                // will try to find it itself (1. local file, then http or ftp)
-                // After the page is loaded, the method calls SetPage() to display it.
-                // Note : you can also use path relative to previously loaded page
-                // Return value : same as SetPage
-
     wxString GetOpenedPage();
-                // Returns full location of opened page
-
     void SetRelatedFrame(wxFrame* frame, const char* format);
-                // sets frame in which page title will  be displayed. Format is format of
-                // frame title, e.g. "HtmlHelp : %s". It must contain exactly one %s
     wxFrame* GetRelatedFrame();
-
     void SetRelatedStatusBar(int bar);
-                // after(!) calling SetRelatedFrame, this sets statusbar slot where messages
-                // will be displayed. Default is -1 = no messages.
-
-    void SetFonts(wxString normal_face, int normal_italic_mode,
-                  wxString fixed_face, int fixed_italic_mode, int *LIST);
-                // sets fonts to be used when displaying HTML page.
-                // *_italic_mode can be either wxSLANT or wxITALIC
-
+    void SetFonts(wxString normal_face, wxString fixed_face, int *LIST);
     void SetTitle(const char* title);
-                // Sets the title of the window
-                // (depending on the information passed to SetRelatedFrame() method)
-
     void SetBorders(int b);
-                // Sets space between text and window borders.
-
     void ReadCustomization(wxConfigBase *cfg, char* path = "");
-                // saves custom settings into cfg config. it will use the path 'path'
-                // if given, otherwise it will save info into currently selected path.
-                // saved values : things set by SetFonts, SetBorders.
-
     void WriteCustomization(wxConfigBase *cfg, char* path = "");
-                // ...
-
     bool HistoryBack();
     bool HistoryForward();
-                // Goes to previous/next page (in browsing history)
-                // Returns TRUE if successful, FALSE otherwise
     void HistoryClear();
-                // Resets history
-
-    // wxHtmlContainerCell* GetInternalRepresentation() const;
-                // Returns pointer to conteiners/cells structure.
-                // It should be used ONLY when printing
-
+    wxHtmlContainerCell* GetInternalRepresentation();
+    wxHtmlWinParser* GetParser();
 
-    void base_OnLinkClicked(const char* link);
-                // called when users clicked on hypertext link. Default behavior is to
-                // call LoadPage(loc)
 
+    void base_OnLinkClicked(const wxHtmlLinkInfo& link);
+    void base_OnSetTitle(const char* title);
 };
 
 // Static methods are mapped to stand-alone functions
@@ -476,6 +482,73 @@ public:
 %}
 
 
+//---------------------------------------------------------------------------
+//---------------------------------------------------------------------------
+
+
+class wxHtmlDCRenderer {
+public:
+    wxHtmlDCRenderer();
+    ~wxHtmlDCRenderer();
+
+    void SetDC(wxDC *dc, int maxwidth);
+    void SetSize(int width, int height);
+    void SetHtmlText(const wxString& html,
+                     const wxString& basepath = wxEmptyString,
+                     bool isdir = TRUE);
+    int Render(int x, int y, int from = 0, int dont_render = FALSE);
+    int GetTotalHeight();
+                // returns total height of the html document
+                // (compare Render's return value with this)
+};
+
+enum {
+    wxPAGE_ODD,
+    wxPAGE_EVEN,
+    wxPAGE_ALL
+};
+
+
+class wxHtmlPrintout : public wxPyPrintout {
+public:
+    wxHtmlPrintout(const char* title = "Printout");
+    ~wxHtmlPrintout();
+
+    void SetHtmlText(const wxString& html,
+                     const wxString &basepath = wxEmptyString,
+                     bool isdir = TRUE);
+    void SetHtmlFile(const wxString &htmlfile);
+    void SetHeader(const wxString& header, int pg = wxPAGE_ALL);
+    void SetFooter(const wxString& footer, int pg = wxPAGE_ALL);
+    void SetMargins(float top = 25.2, float bottom = 25.2,
+                    float left = 25.2, float right = 25.2,
+                    float spaces = 5);
+};
+
+
+
+class wxHtmlEasyPrinting {
+public:
+    wxHtmlEasyPrinting(const char* name = "Printing",
+                       wxFrame *parent_frame = NULL);
+    ~wxHtmlEasyPrinting();
+
+    void PreviewFile(const wxString &htmlfile);
+    void PreviewText(const wxString &htmltext, const wxString& basepath = wxEmptyString);
+    void PrintFile(const wxString &htmlfile);
+    void PrintText(const wxString &htmltext, const wxString& basepath = wxEmptyString);
+    void PrinterSetup();
+    void PageSetup();
+    void SetHeader(const wxString& header, int pg = wxPAGE_ALL);
+    void SetFooter(const wxString& footer, int pg = wxPAGE_ALL);
+
+    wxPrintData *GetPrintData() {return m_PrintData;}
+    wxPageSetupDialogData *GetPageSetupData() {return m_PageSetupData;}
+
+};
+
+
+
 //---------------------------------------------------------------------------
 //---------------------------------------------------------------------------
 
@@ -486,23 +559,22 @@ public:
 
 %init %{
 
-    /* This is a bit cheesy. SWIG happens to call the dictionary d...
-     * I save it here, 'cause I don't know how to get it back later! */
-    mod_dict = d;
-
-    //inithtmlhelpc();
+    inithtmlhelpc();
 
     wxClassInfo::CleanUpClasses();
     wxClassInfo::InitializeClasses();
 
-    /* specifically add our python tag handler; it doesn't seem to
-     * happen by itself... */
-    wxHtmlWinParser::AddModule(new HTML_ModulePythonTag());
-
     // Until wxFileSystem is wrapped...
     #if wxUSE_FS_ZIP
        wxFileSystem::AddHandler(new wxZipFSHandler);
     #endif
 %}
 
+//----------------------------------------------------------------------
+// And this gets appended to the shadow class file.
+//----------------------------------------------------------------------
+
+%pragma(python) include="_extras.py";
+
 //---------------------------------------------------------------------------
+