]> git.saurik.com Git - wxWidgets.git/commitdiff
added wxXmlResourceHandler::GetDimension for 1D values that may be in dialog units
authorVáclav Slavík <vslavik@fastmail.fm>
Tue, 15 Aug 2000 21:46:26 +0000 (21:46 +0000)
committerVáclav Slavík <vslavik@fastmail.fm>
Tue, 15 Aug 2000 21:46:26 +0000 (21:46 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@8111 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

16 files changed:
contrib/include/wx/xml/xmlres.h
contrib/src/xml/xh_gauge.cpp
contrib/src/xml/xh_html.cpp
contrib/src/xml/xh_sizer.cpp
contrib/src/xml/xmlres.cpp
contrib/utils/wxrcedit/df/flexgridsizer.df
contrib/utils/wxrcedit/df/gauge.df
contrib/utils/wxrcedit/df/gridsizer.df
contrib/utils/wxrcedit/df/htmlwindow.df
contrib/utils/wxrcedit/df/menuitem.df
contrib/utils/wxrcedit/df/radiobox.df [new file with mode: 0644]
contrib/utils/wxrcedit/df/sizeritem.df
contrib/utils/wxrcedit/df/spacer.df
contrib/utils/wxrcedit/nodehnd.cpp
contrib/utils/wxrcedit/prophnd.cpp
contrib/utils/wxrcedit/prophnd.h

index 34df9e753840798eb4b322db2863d2605d2b909e..7a62012ccc1d015a1ed33ebef609b0a5e8337cea 100644 (file)
@@ -249,9 +249,12 @@ class WXDLLEXPORT wxXmlResourceHandler : public wxObject
         // Get colour in HTML syntax (#RRGGBB)
         wxColour GetColour(const wxString& param);
         
-        // Get size/position:
+        // Get size/position (may be in dlg units):
         wxSize GetSize(const wxString& param = _T("size"));
         wxPoint GetPosition(const wxString& param = _T("pos"));
+
+        // Get dimension (may be in dlg units):
+        wxCoord GetDimension(const wxString& param, wxCoord defaultv = 0);
         
         // Get bitmap:
         wxBitmap GetBitmap(const wxString& param = _T("bitmap"), wxSize size = wxDefaultSize);
index 5a4f227ff827ca23995e0e5c23ddf155463cd225..14394613adb0eba6378cbae6bf3c6d712f9bb7e0 100644 (file)
@@ -50,11 +50,11 @@ wxObject *wxGaugeXmlHandler::DoCreateResource()
     }
     if( HasParam( _T("shadow") ))
     {
-        control->SetShadowWidth( GetLong( _T("shadow") ));
+        control->SetShadowWidth( GetDimension( _T("shadow") ));
     }
     if( HasParam( _T("bezel") ))
     {
-        control->SetBezelFace( GetLong( _T("bezel") ));
+        control->SetBezelFace( GetDimension( _T("bezel") ));
     }
 
     SetupWindow(control);
index ed0a5bcf4c5d7b6034a095e98fa3d5ab66593eb2..ca1b9bac2ffb4a6a51c1a841878ecc11afab644b 100644 (file)
@@ -44,7 +44,7 @@ wxObject *wxHtmlWindowXmlHandler::DoCreateResource()
 
     if( HasParam( _T("borders") ))
     {
-        control->SetBorders( GetLong( _T("borders" )));
+        control->SetBorders( GetDimension( _T("borders" )));
     }
 
     if( HasParam( _T("url") ))
index 3df8288457e368fbf9730158732482a6ead5218a..51b29c80e6431ed214facbf000095c3efc7f6c43 100644 (file)
@@ -95,14 +95,14 @@ wxObject *wxSizerXmlHandler::DoCreateResource()
                 if (sizer)
                 {
                     m_ParentSizer->Add(sizer, GetLong(_T("option")), 
-                                       GetStyle(_T("flag")), GetLong(_T("border")));
+                                       GetStyle(_T("flag")), GetDimension(_T("border")));
                     if (!(minsize == wxDefaultSize))
                         m_ParentSizer->SetItemMinSize(sizer, minsize.x, minsize.y);
                 }
                 else if (wnd)
                 {
                     m_ParentSizer->Add(wnd, GetLong(_T("option")), 
-                                       GetStyle(_T("flag")), GetLong(_T("border")));
+                                       GetStyle(_T("flag")), GetDimension(_T("border")));
                     if (!(minsize == wxDefaultSize))
                         m_ParentSizer->SetItemMinSize(wnd, minsize.x, minsize.y);
                 }
@@ -122,7 +122,7 @@ wxObject *wxSizerXmlHandler::DoCreateResource()
         wxCHECK_MSG(m_ParentSizer, NULL, _T("Incorrect syntax of XML resource: spacer not within sizer!"));
         wxSize sz = GetSize();
         m_ParentSizer->Add(sz.x, sz.y,
-            GetLong(_T("option")), GetStyle(_T("flag")), GetLong(_T("border")));
+            GetLong(_T("option")), GetStyle(_T("flag")), GetDimension(_T("border")));
         return NULL;
     }
     
@@ -150,11 +150,11 @@ wxObject *wxSizerXmlHandler::DoCreateResource()
         
         else if (m_Node->GetName() == _T("gridsizer"))
             sizer = new wxGridSizer(GetLong(_T("rows")), GetLong(_T("cols")),
-                                    GetLong(_T("vgap")), GetLong(_T("hgap")));
+                                    GetDimension(_T("vgap")), GetDimension(_T("hgap")));
                                     
         else if (m_Node->GetName() == _T("flexgridsizer"))
             sizer = new wxFlexGridSizer(GetLong(_T("rows")), GetLong(_T("cols")),
-                                    GetLong(_T("vgap")), GetLong(_T("hgap")));
+                                    GetDimension(_T("vgap")), GetDimension(_T("hgap")));
 
         wxSize minsize = GetSize(_T("minsize"));
         if (!(minsize == wxDefaultSize))
index fb4f564a575bf4027a3989719f2acf97e72d91be..b8b80c6978fc595be8b2339e4b6d58d6669a7e02 100644 (file)
@@ -552,7 +552,7 @@ wxBitmap wxXmlResourceHandler::GetBitmap(const wxString& param, wxSize size)
 
 wxIcon wxXmlResourceHandler::GetIcon(const wxString& param, wxSize size)
 {
-#ifdef __WXMSW__
+#if wxCHECK_VERSION(2,3,0) || defined(__WXMSW__)
     wxIcon icon;
     icon.CopyFromBitmap(GetBitmap(param, size));
 #else
@@ -647,6 +647,39 @@ wxPoint wxXmlResourceHandler::GetPosition(const wxString& param)
 
 
 
+wxCoord wxXmlResourceHandler::GetDimension(const wxString& param, wxCoord defaultv)
+{
+    wxString s = GetParamValue(param);
+    if (s.IsEmpty()) return defaultv;
+    bool is_dlg;
+    long sx;
+    
+    is_dlg = s[s.Length()-1] == _T('d');
+    if (is_dlg) s.RemoveLast();
+    
+    if (!s.ToLong(&sx))
+    {
+        wxLogError(_("Cannot parse dimension from '%s'."), s.mb_str());
+        return defaultv;
+    }
+    
+    if (is_dlg)
+    {
+        if (m_InstanceAsWindow)
+            return wxDLG_UNIT(m_InstanceAsWindow, wxSize(sx, 0)).x;
+        else if (m_ParentAsWindow)
+            return wxDLG_UNIT(m_ParentAsWindow, wxSize(sx, 0)).x;
+        else
+        {
+            wxLogError(_("Cannot convert dialog units: dialog unknown."));
+            return defaultv;
+        }
+    }
+    else return sx;
+}
+
+
+
 void wxXmlResourceHandler::SetupWindow(wxWindow *wnd)
 {
     //FIXME : add font, cursor
@@ -730,9 +763,6 @@ static int XMLID_LastID = wxID_HIGHEST;
     {
         if (strcmp(rec->key, str_id) == 0)
         {
-#ifdef DEBUG_XMLID_HASH
-            printf("XMLID: matched '%s' (%ith item)\n", rec->key, matchcnt);
-#endif
             return rec->id;
         }
         matchcnt++;
@@ -745,10 +775,6 @@ static int XMLID_LastID = wxID_HIGHEST;
     (*rec_var)->id = ++XMLID_LastID;
     (*rec_var)->key = strdup(str_id);
     (*rec_var)->next = NULL;
-#ifdef DEBUG_XMLID_HASH
-    printf("XMLID: new key for '%s': %i at %i (%ith item)\n", 
-           (*rec_var)->key, (*rec_var)->id, index, matchcnt);
-#endif
     
     return (*rec_var)->id;
 }
@@ -758,9 +784,6 @@ static void CleanXMLID_Record(XMLID_record *rec)
 {
     if (rec)
     {
-#ifdef DEBUG_XMLID_HASH
-        printf("XMLID: clearing '%s'\n", rec->key);
-#endif
         CleanXMLID_Record(rec->next);
         free (rec->key);
         delete rec;
index 414dd886e6bbe752c1e202f7a3172d541927f7c7..e0ceee11ae04b1d3d6aa49f25f3e155e5c98a665 100644 (file)
@@ -5,6 +5,6 @@ childtype sizer_item
 derived from panel_item
 var rows of integer
 var cols of integer
-var vgap of integer
-var hgap of integer
+var vgap of dimension
+var hgap of dimension
 var minsize of coord
index 8ebeee451ff101036f739ba29745f022d5b1989b..44a57b45b89e0d0f11960136aaabd0b863f049cd 100644 (file)
@@ -2,6 +2,6 @@ node gauge
 var style of flags wxGA_HORIZONTAL,wxGA_VERTICAL,wxGA_PROGRESSBAR,wxGA_SMOOTH
 var range of integer
 var value of integer
-var shadow of integer
-var bezel of integer
+var shadow of dimension
+var bezel of dimension
 derived from control
index ad1726206c0d33ccbb6088137f2c4016829df0bc..01fe2a287755ee72e36ab64f7db661ab470e8965 100644 (file)
@@ -5,6 +5,6 @@ childtype sizer_item
 derived from panel_item
 var rows of integer
 var cols of integer
-var vgap of integer
-var hgap of integer
+var vgap of dimension
+var hgap of dimension
 var minsize of coord
index 73dfbe6aaa2db24b4bd305965696df5b1de001a7..f727fcbcec963a82a3da1685da2867036b5aa48c 100644 (file)
@@ -1,6 +1,6 @@
 node htmlwindow
 var url of text
 var htmlcode of text
-var borders of integer
+var borders of dimension
 var style of flags wxHW_SCROLLBAR_NEVER,wxHW_SCROLLBAR_AUTO
 derived from control
index 5c487821e51376b2143ddcfaa19e0b5e8913c048..9e0f07fa3eb032d1d6c9a8f4a29700d9fff83d71 100644 (file)
@@ -6,4 +6,4 @@ var help of text
 var checkable of bool
 var checked of bool
 var enabled of bool
-derived from menu_item
\ No newline at end of file
+derived from menu_item
diff --git a/contrib/utils/wxrcedit/df/radiobox.df b/contrib/utils/wxrcedit/df/radiobox.df
new file mode 100644 (file)
index 0000000..e31e60a
--- /dev/null
@@ -0,0 +1,7 @@
+node radiobox
+var style of flags wxRA_SPECIFY_COLS,wxRA_HORIZONTAL,wxRA_SPECIFY_ROWS,wxRA_VERTICAL
+var label of text
+var dimension of integer
+var selection of integer
+var content of not_implemented
+derived from control
index 7ee1f74ecc1757a26cd70a80c65b703c1216140d..e95b4bf024ceb300bc7f711a2faf0f53674fee8b 100644 (file)
@@ -5,5 +5,5 @@ node sizeritem
 type sizeritem
 var option of integer
 var flag of flags wxEXPAND,wxALL,wxLEFT,wxRIGHT,wxTOP,wxBOTTOM,wxALIGN_CENTER,wxALIGN_LEFT,wxALIGN_TOP,wxALIGN_RIGHT,wxALIGN_BOTTOM,wxALIGN_CENTER_HORIZONTAL,wxALIGN_CENTER_VERTICAL,wxNORTH,wxSOUTH,wxEAST,wxWEST,wxGROW,wxSHAPED,wxSTRETCH_NOT
-var border of integer
+var border of dimension
 var minsize of coord
index 75a19ff40d94cebc9da50f1a6bb2b8392df7588b..a8ece713544156e195495b6dc294b3452133cf31 100644 (file)
@@ -5,6 +5,6 @@ node spacer
 type normal
 var option of integer
 var flag of flags wxEXPAND,wxALL,wxLEFT,wxRIGHT,wxTOP,wxBOTTOM,wxALIGN_CENTER,wxALIGN_LEFT,wxALIGN_TOP,wxALIGN_RIGHT,wxALIGN_BOTTOM,wxALIGN_CENTER_HORIZONTAL,wxALIGN_CENTER_VERTICAL,wxNORTH,wxSOUTH,wxEAST,wxWEST,wxGROW,wxSHAPED,wxSTRETCH_NOT
-var border of integer
+var border of dimension
 var size of coord
 derived from sizer_item
index 22e9da81c4ca9acb68d7c6648b9ff3c862863cd1..190cd00f4eea26cce8f6d573de9791d1ad972d8c 100644 (file)
@@ -102,11 +102,14 @@ void NodeInfo::Read(const wxString& filename)
             tkn.GetNextToken();
             wxString typ = tkn.GetNextToken();
             if (tkn.HasMoreTokens()) pi.MoreInfo = tkn.GetNextToken();
+            /* ADD NEW PROPERTY TYPES HERE 
+               (search for other occurences of this comment in _all_ files) */
             if (typ == "color") pi.Type = PROP_COLOR;
             else if (typ == "flags") pi.Type = PROP_FLAGS;
             else if (typ == "bool") pi.Type = PROP_BOOL;
             else if (typ == "integer") pi.Type = PROP_INTEGER;
             else if (typ == "coord") pi.Type = PROP_COORD;
+            else if (typ == "dimension") pi.Type = PROP_DIMENSION;
             else if (typ == "not_implemented") pi.Type = PROP_NOT_IMPLEMENTED;
             else /*if (typ == "text")*/ pi.Type = PROP_TEXT;
             
@@ -195,12 +198,15 @@ NodeHandler::NodeHandler(EditorFrame *frame, NodeInfo *ni) :
 
 void NodeHandler::CreatePropHandlers()
 {
+    /* ADD NEW PROPERTY TYPES HERE 
+       (search for other occurences of this comment in _all_ files) */
     s_PropHandlers[PROP_TEXT] = new TextPropertyHandler;
     s_PropHandlers[PROP_FLAGS] = new FlagsPropertyHandler;
     s_PropHandlers[PROP_COLOR] = new TextPropertyHandler;
     s_PropHandlers[PROP_BOOL] = new BoolPropertyHandler;
     s_PropHandlers[PROP_INTEGER] = new TextPropertyHandler;
     s_PropHandlers[PROP_COORD] = new CoordPropertyHandler;
+    s_PropHandlers[PROP_DIMENSION] = new DimensionPropertyHandler;
     s_PropHandlers[PROP_NOT_IMPLEMENTED] = new NotImplPropertyHandler;
 }
 
index 6e7921d58b6ea855e46e230abd03a3bb9648992c..e20288614a1de16fb33d17254ac9bdb548d065cf 100644 (file)
@@ -211,6 +211,66 @@ wxPanel *CoordPropertyHandler::CreateEditPanel(wxWindow *parent, PropsListInfo *
 
 
 
+class DimensionPropPanel : public PropertyPanel
+{
+    public:
+        DimensionPropPanel(wxWindow *parent, PropertyHandler *hnd, PropsListInfo *pli) : PropertyPanel(parent, hnd, pli)
+        {    
+            wxSizer *sizer = new wxBoxSizer(wxVERTICAL);
+            m_ed1 = NULL; m_chb = NULL;
+    
+            sizer->Add(new wxStaticText(this, -1, _("Value:")), 0, wxLEFT, 5);
+            sizer->Add(m_ed1 = new wxTextCtrl(this, ID_XEDIT, "",
+                                 wxDefaultPosition, wxDefaultSize, 0,
+                                 wxTextValidator(wxFILTER_NUMERIC)),
+                    0, wxEXPAND, 5);
+            m_ed1->SetFocus();
+    
+            sizer->Add(m_chb = new wxCheckBox(this, ID_USEDLG, _("Use dialog units")), 0, wxLEFT|wxTOP, 5);
+    
+            SetAutoLayout(TRUE);
+            SetSizer(sizer);
+            Layout();
+            
+            wxString val = XmlReadValue(pli->m_Node, pli->m_PropInfo->Name);
+            m_chb->SetValue(val.Len()>0 && val[val.Len()-1] == 'd');
+            m_ed1->SetValue(val.BeforeFirst('d'));
+        }
+        
+        void OnEdit(wxCommandEvent &event)
+        {
+            wxString val;
+            
+            if (m_ed1 == NULL || m_chb == NULL) return;
+            
+            val = m_ed1->GetValue();
+            if (val.IsEmpty()) return;
+            if (m_chb->GetValue()) val << 'd';
+            Update(val);
+        }
+        
+        wxTextCtrl *m_ed1;
+        wxCheckBox *m_chb;
+        
+        DECLARE_EVENT_TABLE()
+};
+
+BEGIN_EVENT_TABLE(DimensionPropPanel, PropertyPanel)
+    EVT_TEXT(ID_XEDIT, DimensionPropPanel::OnEdit)
+    EVT_TEXT(ID_YEDIT, DimensionPropPanel::OnEdit)
+    EVT_CHECKBOX(ID_USEDLG, DimensionPropPanel::OnEdit)
+END_EVENT_TABLE()
+
+wxPanel *DimensionPropertyHandler::CreateEditPanel(wxWindow *parent, PropsListInfo *pli)
+{
+    return new DimensionPropPanel(parent, this, pli);
+}
+
+
+
+
+
+
 
 class BoolPropPanel : public PropertyPanel
 {
index fcc725eaf0cafd03954f799f94f7432b538719bd..a130110f830d84956b779220737510945d3cf80b 100644 (file)
@@ -24,6 +24,8 @@ class WXDLLEXPORT wxWindow;
 #include "wx/xml/xml.h"
 #include "wx/dynarray.h"
 
+/* ADD NEW PROPERTY TYPES HERE 
+   (search for other occurences of this comment in _all_ files) */
 enum PropertyType
 {
     PROP_TEXT = 0,
@@ -32,9 +34,10 @@ enum PropertyType
     PROP_BOOL = 3,
     PROP_INTEGER = 4,
     PROP_COORD = 5,
-    PROP_NOT_IMPLEMENTED = 6,
+    PROP_DIMENSION = 6,
+    PROP_NOT_IMPLEMENTED = 7,
 };
-#define PROP_TYPES_CNT  7
+#define PROP_TYPES_CNT  8
 
 class PropertyInfo
 {
@@ -97,6 +100,14 @@ class CoordPropertyHandler : public PropertyHandler
 };
 
 
+class DimensionPropertyHandler : public PropertyHandler
+{
+    public:
+        DimensionPropertyHandler() {}
+        virtual wxPanel *CreateEditPanel(wxWindow *parent, PropsListInfo *pli);
+};
+
+
 class BoolPropertyHandler : public PropertyHandler
 {
     public: