1 /////////////////////////////////////////////////////////////////////////////
 
   3 // Purpose:     SWIG interface for other wxXml classes
 
   7 // Created:     4-June-2001
 
   9 // Copyright:   (c) 2003 by Total Control Software
 
  10 // Licence:     wxWindows license
 
  11 /////////////////////////////////////////////////////////////////////////////
 
  16 //---------------------------------------------------------------------------
 
  21 %{ // C++ version of Python aware wxXmlResourceHandler, for the pure virtual
 
  22    // callbacks, as well as to make some protected things public so they can
 
  24 class wxPyXmlResourceHandler : public wxXmlResourceHandler {
 
  26     wxPyXmlResourceHandler() : wxXmlResourceHandler() {}
 
  27     //~wxPyXmlResourceHandler();
 
  29     // Base class virtuals
 
  31     DEC_PYCALLBACK_OBJECT__pure(DoCreateResource);
 
  32     DEC_PYCALLBACK_BOOL_NODE_pure(CanHandle);
 
  35     // accessors for protected members
 
  37     wxXmlResource* GetResource()        { return m_resource; }
 
  38     wxXmlNode* GetNode()                { return m_node; }
 
  39     wxString GetClass()                 { return m_class; }
 
  40     wxObject* GetParent()               { return m_parent; }
 
  41     wxObject* GetInstance()             { return m_instance; }
 
  42     wxWindow* GetParentAsWindow()       { return m_parentAsWindow; }
 
  43     wxWindow* GetInstanceAsWindow()     { return m_instanceAsWindow; }
 
  46     // turn some protected methods into public via delegation
 
  48     bool IsOfClass(wxXmlNode *node, const wxString& classname)
 
  49         { return wxXmlResourceHandler::IsOfClass(node, classname); }
 
  51     wxString GetNodeContent(wxXmlNode *node)
 
  52         { return wxXmlResourceHandler::GetNodeContent(node); }
 
  54     bool HasParam(const wxString& param)
 
  55         { return wxXmlResourceHandler::HasParam(param); }
 
  57     wxXmlNode *GetParamNode(const wxString& param)
 
  58         { return wxXmlResourceHandler::GetParamNode(param); }
 
  60     wxString GetParamValue(const wxString& param)
 
  61         { return wxXmlResourceHandler::GetParamValue(param); }
 
  63     void AddStyle(const wxString& name, int value)
 
  64         { wxXmlResourceHandler::AddStyle(name, value); }
 
  66     void AddWindowStyles()
 
  67         { wxXmlResourceHandler::AddWindowStyles(); }
 
  69     int GetStyle(const wxString& param = wxT("style"), int defaults = 0)
 
  70         { return wxXmlResourceHandler::GetStyle(param, defaults); }
 
  72     wxString GetText(const wxString& param, bool translate = True)
 
  73         { return wxXmlResourceHandler::GetText(param, translate); }
 
  76         { return wxXmlResourceHandler::GetID(); }
 
  79         { return wxXmlResourceHandler::GetName(); }
 
  81     bool GetBool(const wxString& param, bool defaultv = False)
 
  82         { return wxXmlResourceHandler::GetBool(param, defaultv); }
 
  84     long GetLong( const wxString& param, long defaultv = 0 )
 
  85         { return wxXmlResourceHandler::GetLong(param, defaultv); }
 
  87     wxColour GetColour(const wxString& param)
 
  88         { return wxXmlResourceHandler::GetColour(param); }
 
  90     wxSize GetSize(const wxString& param = wxT("size"))
 
  91         { return wxXmlResourceHandler::GetSize(param); }
 
  93     wxPoint GetPosition(const wxString& param = wxT("pos"))
 
  94         { return wxXmlResourceHandler::GetPosition(param); }
 
  96     wxCoord GetDimension(const wxString& param, wxCoord defaultv = 0)
 
  97         { return wxXmlResourceHandler::GetDimension(param, defaultv); }
 
  99     wxBitmap GetBitmap(const wxString& param = wxT("bitmap"),
 
 100                        const wxArtClient& defaultArtClient = wxART_OTHER,
 
 101                        wxSize size = wxDefaultSize)
 
 102         { return wxXmlResourceHandler::GetBitmap(param, defaultArtClient, size); }
 
 104     wxIcon GetIcon(const wxString& param = wxT("icon"),
 
 105                    const wxArtClient& defaultArtClient = wxART_OTHER,
 
 106                    wxSize size = wxDefaultSize)
 
 107         { return wxXmlResourceHandler::GetIcon(param, defaultArtClient, size); }
 
 109     wxFont GetFont(const wxString& param = wxT("font"))
 
 110         { return wxXmlResourceHandler::GetFont(param); }
 
 112     void SetupWindow(wxWindow *wnd)
 
 113         { wxXmlResourceHandler::SetupWindow(wnd); }
 
 115     void CreateChildren(wxObject *parent, bool this_hnd_only = False)
 
 116         { wxXmlResourceHandler::CreateChildren(parent, this_hnd_only); }
 
 118     void CreateChildrenPrivately(wxObject *parent, wxXmlNode *rootnode = NULL)
 
 119         { wxXmlResourceHandler::CreateChildrenPrivately(parent, rootnode); }
 
 121     wxObject *CreateResFromNode(wxXmlNode *node,
 
 122                                 wxObject *parent, wxObject *instance = NULL)
 
 123         { return wxXmlResourceHandler::CreateResFromNode(node, parent, instance); }
 
 125     wxFileSystem& GetCurFileSystem()
 
 126         { return wxXmlResourceHandler::GetCurFileSystem(); }
 
 132 IMP_PYCALLBACK_OBJECT__pure(wxPyXmlResourceHandler, wxXmlResourceHandler, DoCreateResource);
 
 133 IMP_PYCALLBACK_BOOL_NODE_pure(wxPyXmlResourceHandler, wxXmlResourceHandler, CanHandle);
 
 138 // Now the version that will be SWIGged.
 
 141 %name(XmlResourceHandler) class wxPyXmlResourceHandler : public wxObject {
 
 143     %pythonAppend wxPyXmlResourceHandler "self._setCallbackInfo(self, XmlResourceHandler)"
 
 144     wxPyXmlResourceHandler() : wxXmlResourceHandler() {}
 
 145     //~wxPyXmlResourceHandler();
 
 147     void _setCallbackInfo(PyObject* self, PyObject* _class);
 
 150     // Creates an object (menu, dialog, control, ...) from an XML node.
 
 151     // Should check for validity.
 
 152     // parent is a higher-level object (usually window, dialog or panel)
 
 153     // that is often neccessary to create the resource.
 
 154     // If instance is non-NULL it should not create a new instance via 'new' but
 
 155     // should rather use this one, and call its Create method.
 
 156     wxObject *CreateResource(wxXmlNode *node, wxObject *parent,
 
 159     // Sets the parent resource.
 
 160     void SetParentResource(wxXmlResource *res);
 
 163     wxXmlResource* GetResource()        { return m_resource; }
 
 164     wxXmlNode* GetNode()                { return m_node; }
 
 165     wxString GetClass()                 { return m_class; }
 
 166     wxObject* GetParent()               { return m_parent; }
 
 167     wxObject* GetInstance()             { return m_instance; }
 
 168     wxWindow* GetParentAsWindow()       { return m_parentAsWindow; }
 
 169     wxWindow* GetInstanceAsWindow()     { return m_instanceAsWindow; }
 
 172     // Returns true if the node has a property class equal to classname,
 
 173     // e.g. <object class="wxDialog">.
 
 174     bool IsOfClass(wxXmlNode *node, const wxString& classname);
 
 176     // Gets node content from wxXML_ENTITY_NODE
 
 177     // The problem is, <tag>content<tag> is represented as
 
 178     // wxXML_ENTITY_NODE name="tag", content=""
 
 179     //    |-- wxXML_TEXT_NODE or
 
 180     //        wxXML_CDATA_SECTION_NODE name="" content="content"
 
 181     wxString GetNodeContent(wxXmlNode *node);
 
 183     // Check to see if a parameter exists.
 
 184     bool HasParam(const wxString& param);
 
 186     // Finds the node or returns NULL.
 
 187     wxXmlNode *GetParamNode(const wxString& param);
 
 189     // Finds the parameter value or returns the empty string.
 
 190     wxString GetParamValue(const wxString& param);
 
 192     // Add a style flag (e.g. wxMB_DOCKABLE) to the list of flags
 
 193     // understood by this handler.
 
 194     void AddStyle(const wxString& name, int value);
 
 196     // Add styles common to all wxWindow-derived classes.
 
 197     void AddWindowStyles();
 
 199     // Gets style flags from text in form "flag | flag2| flag3 |..."
 
 200     // Only understads flags added with AddStyle
 
 201     int GetStyle(const wxString& param = wxPyStyleString, int defaults = 0);
 
 203     // Gets text from param and does some conversions:
 
 204     // - replaces \n, \r, \t by respective chars (according to C syntax)
 
 205     // - replaces _ by & and __ by _ (needed for _File => &File because of XML)
 
 206     // - calls wxGetTranslations (unless disabled in wxXmlResource)
 
 207     wxString GetText(const wxString& param, bool translate = True);
 
 209     // Returns the XRCID.
 
 212     // Returns the resource name.
 
 215     // Gets a bool flag (1, t, yes, on, true are True, everything else is False).
 
 216     bool GetBool(const wxString& param, bool defaultv = False);
 
 218     // Gets the integer value from the parameter.
 
 219     long GetLong( const wxString& param, long defaultv = 0 );
 
 221     // Gets colour in HTML syntax (#RRGGBB).
 
 222     wxColour GetColour(const wxString& param);
 
 224     // Gets the size (may be in dialog units).
 
 225     wxSize GetSize(const wxString& param = wxPySizeString);
 
 227     // Gets the position (may be in dialog units).
 
 228     wxPoint GetPosition(const wxString& param = wxPyPosString);
 
 230     // Gets a dimension (may be in dialog units).
 
 231     wxCoord GetDimension(const wxString& param, wxCoord defaultv = 0);
 
 234     wxBitmap GetBitmap(const wxString& param = wxPyBitmapString,
 
 235                        const wxArtClient& defaultArtClient = wxART_OTHER,
 
 236                        wxSize size = wxDefaultSize);
 
 239     wxIcon GetIcon(const wxString& param = wxPyIconString,
 
 240                    const wxArtClient& defaultArtClient = wxART_OTHER,
 
 241                    wxSize size = wxDefaultSize);
 
 244     wxFont GetFont(const wxString& param = wxPyFontString);
 
 246     // Sets common window options.
 
 247     void SetupWindow(wxWindow *wnd);
 
 250     void CreateChildren(wxObject *parent, bool this_hnd_only = False);
 
 253     void CreateChildrenPrivately(wxObject *parent, wxXmlNode *rootnode = NULL);
 
 255     // Creates a resource from a node.
 
 256     wxObject *CreateResFromNode(wxXmlNode *node,
 
 257                                 wxObject *parent, wxObject *instance = NULL);
 
 260     wxFileSystem& GetCurFileSystem();
 
 265 //---------------------------------------------------------------------------
 
 266 //---------------------------------------------------------------------------