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
This commit is contained in:
Václav Slavík 2000-08-15 21:46:26 +00:00
parent b6b0af42a0
commit bebb14d53d
16 changed files with 142 additions and 32 deletions

View 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);

View 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);

View 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") ))

View 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))

View 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;

View 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

View 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

View 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

View 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

View 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
derived from menu_item

View File

@ -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

View 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

View 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

View 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;
}

View 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
{

View 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: