diff options
author | Jan Holesovsky <kendy@suse.cz> | 2013-06-05 17:26:24 +0200 |
---|---|---|
committer | Jan Holesovsky <kendy@suse.cz> | 2013-06-05 18:32:56 +0200 |
commit | 4c597ce679c786bd927e9abf158047cb4d7bc46f (patch) | |
tree | 5610c1ddc3f712c557ca2e456604b337560ed227 | |
parent | 287bc2bb767eeb7c942282d36564ba42ea2723b4 (diff) |
widget layout: Introduce a way to specify MetricBox in .ui.
Uses the same trick as MetricField - you set the units in the 'id' of
GtkComboBox in form like id="something:0mm", or id="something:0 degrees" (for
custom units).
Change-Id: I572c653b97e75dcf47f934415139e1bfb06dc89b
-rw-r--r-- | vcl/source/window/builder.cxx | 48 |
1 files changed, 33 insertions, 15 deletions
diff --git a/vcl/source/window/builder.cxx b/vcl/source/window/builder.cxx index 3824497a7f5d..73a06c8730fd 100644 --- a/vcl/source/window/builder.cxx +++ b/vcl/source/window/builder.cxx @@ -678,6 +678,20 @@ namespace return pWindow; } + OString extractUnit(const OString& sPattern) + { + OString sUnit(sPattern); + for (sal_Int32 i = 0; i < sPattern.getLength(); ++i) + { + if (sPattern[i] != '.' && sPattern[i] != ',' && sPattern[i] != '0') + { + sUnit = sPattern.copy(i); + break; + } + } + return sUnit; + } + FieldUnit detectMetricUnit(OString sUnit) { FieldUnit eUnit = FUNIT_NONE; @@ -708,10 +722,8 @@ namespace eUnit = FUNIT_LINE; else if (sUnit == "%") eUnit = FUNIT_PERCENT; - - // if lack of unit is not intentional - if (sUnit != "0") - assert(eUnit != FUNIT_NONE); //unknown unit + else if (sUnit != "0") + eUnit = FUNIT_CUSTOM; return eUnit; } @@ -1045,16 +1057,7 @@ Window *VclBuilder::makeObject(Window *pParent, const OString &name, const OStri { OString sAdjustment = extractAdjustment(rMap); OString sPattern = extractCustomProperty(rMap); - OString sUnit = sPattern; - - for (sal_Int32 i = 0; i < sPattern.getLength(); ++i) - { - if (sPattern[i] != '.' && sPattern[i] != ',' && sPattern[i] != '0') - { - sUnit = sPattern.copy(i); - break; - } - } + OString sUnit = extractUnit(sPattern); WinBits nBits = WB_LEFT|WB_BORDER|WB_3DLOOK; if (!id.endsWith("-nospin")) @@ -1089,6 +1092,8 @@ Window *VclBuilder::makeObject(Window *pParent, const OString &name, const OStri SAL_INFO("vcl.layout", "making metric field for " << name.getStr() << " " << sUnit.getStr()); MetricField *pField = new MetricField(pParent, nBits); pField->SetUnit(eUnit); + if (eUnit == FUNIT_CUSTOM) + pField->SetCustomUnitText(OStringToOUString(sUnit, RTL_TEXTENCODING_UTF8)); pWindow = pField; } } @@ -1097,8 +1102,21 @@ Window *VclBuilder::makeObject(Window *pParent, const OString &name, const OStri pWindow = new FixedHyperlink(pParent, WB_CENTER|WB_VCENTER|WB_3DLOOK|WB_NOLABEL); else if ((name == "GtkComboBox") || (name == "GtkComboBoxText") || (name == "VclComboBoxText")) { + OString sPattern = extractCustomProperty(rMap); extractModel(id, rMap); - if (extractEntry(rMap)) + + if (!sPattern.isEmpty()) + { + OString sUnit = extractUnit(sPattern); + FieldUnit eUnit = detectMetricUnit(sUnit); + SAL_INFO("vcl.layout", "making metric box for " << name.getStr() << " " << sUnit.getStr()); + MetricBox *pBox = new MetricBox(pParent, WB_LEFT|WB_DROPDOWN|WB_VCENTER|WB_3DLOOK); + pBox->SetUnit(eUnit); + if (eUnit == FUNIT_CUSTOM) + pBox->SetCustomUnitText(OStringToOUString(sUnit, RTL_TEXTENCODING_UTF8)); + pWindow = pBox; + } + else if (extractEntry(rMap)) { ComboBox* pComboBox = new ComboBox(pParent, WB_LEFT|WB_DROPDOWN|WB_VCENTER|WB_3DLOOK); pComboBox->EnableAutoSize(true); |