From: Václav Slavík Date: Tue, 15 Aug 2000 21:46:26 +0000 (+0000) Subject: added wxXmlResourceHandler::GetDimension for 1D values that may be in dialog units X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/bebb14d53dc0efbf04e57934a70ae39e10819d96 added wxXmlResourceHandler::GetDimension for 1D values that may be in dialog units git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@8111 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/contrib/include/wx/xml/xmlres.h b/contrib/include/wx/xml/xmlres.h index 34df9e7538..7a62012ccc 100644 --- a/contrib/include/wx/xml/xmlres.h +++ b/contrib/include/wx/xml/xmlres.h @@ -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); diff --git a/contrib/src/xml/xh_gauge.cpp b/contrib/src/xml/xh_gauge.cpp index 5a4f227ff8..14394613ad 100644 --- a/contrib/src/xml/xh_gauge.cpp +++ b/contrib/src/xml/xh_gauge.cpp @@ -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); diff --git a/contrib/src/xml/xh_html.cpp b/contrib/src/xml/xh_html.cpp index ed0a5bcf4c..ca1b9bac2f 100644 --- a/contrib/src/xml/xh_html.cpp +++ b/contrib/src/xml/xh_html.cpp @@ -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") )) diff --git a/contrib/src/xml/xh_sizer.cpp b/contrib/src/xml/xh_sizer.cpp index 3df8288457..51b29c80e6 100644 --- a/contrib/src/xml/xh_sizer.cpp +++ b/contrib/src/xml/xh_sizer.cpp @@ -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)) diff --git a/contrib/src/xml/xmlres.cpp b/contrib/src/xml/xmlres.cpp index fb4f564a57..b8b80c6978 100644 --- a/contrib/src/xml/xmlres.cpp +++ b/contrib/src/xml/xmlres.cpp @@ -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; diff --git a/contrib/utils/wxrcedit/df/flexgridsizer.df b/contrib/utils/wxrcedit/df/flexgridsizer.df index 414dd886e6..e0ceee11ae 100644 --- a/contrib/utils/wxrcedit/df/flexgridsizer.df +++ b/contrib/utils/wxrcedit/df/flexgridsizer.df @@ -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 diff --git a/contrib/utils/wxrcedit/df/gauge.df b/contrib/utils/wxrcedit/df/gauge.df index 8ebeee451f..44a57b45b8 100644 --- a/contrib/utils/wxrcedit/df/gauge.df +++ b/contrib/utils/wxrcedit/df/gauge.df @@ -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 diff --git a/contrib/utils/wxrcedit/df/gridsizer.df b/contrib/utils/wxrcedit/df/gridsizer.df index ad1726206c..01fe2a2877 100644 --- a/contrib/utils/wxrcedit/df/gridsizer.df +++ b/contrib/utils/wxrcedit/df/gridsizer.df @@ -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 diff --git a/contrib/utils/wxrcedit/df/htmlwindow.df b/contrib/utils/wxrcedit/df/htmlwindow.df index 73dfbe6aaa..f727fcbcec 100644 --- a/contrib/utils/wxrcedit/df/htmlwindow.df +++ b/contrib/utils/wxrcedit/df/htmlwindow.df @@ -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 diff --git a/contrib/utils/wxrcedit/df/menuitem.df b/contrib/utils/wxrcedit/df/menuitem.df index 5c487821e5..9e0f07fa3e 100644 --- a/contrib/utils/wxrcedit/df/menuitem.df +++ b/contrib/utils/wxrcedit/df/menuitem.df @@ -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 index 0000000000..e31e60ae1a --- /dev/null +++ b/contrib/utils/wxrcedit/df/radiobox.df @@ -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 diff --git a/contrib/utils/wxrcedit/df/sizeritem.df b/contrib/utils/wxrcedit/df/sizeritem.df index 7ee1f74ecc..e95b4bf024 100644 --- a/contrib/utils/wxrcedit/df/sizeritem.df +++ b/contrib/utils/wxrcedit/df/sizeritem.df @@ -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 diff --git a/contrib/utils/wxrcedit/df/spacer.df b/contrib/utils/wxrcedit/df/spacer.df index 75a19ff40d..a8ece71354 100644 --- a/contrib/utils/wxrcedit/df/spacer.df +++ b/contrib/utils/wxrcedit/df/spacer.df @@ -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 diff --git a/contrib/utils/wxrcedit/nodehnd.cpp b/contrib/utils/wxrcedit/nodehnd.cpp index 22e9da81c4..190cd00f4e 100644 --- a/contrib/utils/wxrcedit/nodehnd.cpp +++ b/contrib/utils/wxrcedit/nodehnd.cpp @@ -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; } diff --git a/contrib/utils/wxrcedit/prophnd.cpp b/contrib/utils/wxrcedit/prophnd.cpp index 6e7921d58b..e20288614a 100644 --- a/contrib/utils/wxrcedit/prophnd.cpp +++ b/contrib/utils/wxrcedit/prophnd.cpp @@ -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 { diff --git a/contrib/utils/wxrcedit/prophnd.h b/contrib/utils/wxrcedit/prophnd.h index fcc725eaf0..a130110f83 100644 --- a/contrib/utils/wxrcedit/prophnd.h +++ b/contrib/utils/wxrcedit/prophnd.h @@ -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: