summaryrefslogtreecommitdiff
path: root/vcl
diff options
context:
space:
mode:
authorCaolán McNamara <caolanm@redhat.com>2012-08-17 13:49:40 +0100
committerCaolán McNamara <caolanm@redhat.com>2012-09-28 08:48:36 +0100
commit4a9fe1a736dac09436ff31560565f1e5b7d5b46e (patch)
tree60f42753ce0298f11b37ce541a7e3dd192cde77f /vcl
parentcd998eb98d23ad4c1e5d9e56d7fdb78731b3f2d6 (diff)
distinguish between NumericFields and MetricFields
GtkSpinFields without a pattern are NumericFields Otherwise we hook off the pattern to determine what sort of field it is, only MetricFields for now and their various field units. Change-Id: I1d50b302b402516b5460774f1d689ac93bfd61ff to-do: upstream something of the "pattern" nature into gtk
Diffstat (limited to 'vcl')
-rw-r--r--vcl/inc/vcl/builder.hxx4
-rw-r--r--vcl/source/src/units.src2
-rw-r--r--vcl/source/window/builder.cxx77
3 files changed, 77 insertions, 6 deletions
diff --git a/vcl/inc/vcl/builder.hxx b/vcl/inc/vcl/builder.hxx
index ff346dd8e2f4..05c40d4dbc96 100644
--- a/vcl/inc/vcl/builder.hxx
+++ b/vcl/inc/vcl/builder.hxx
@@ -36,7 +36,7 @@
#include <vector>
class ListBox;
-class MetricField;
+class NumericFormatter;
class VCL_DLLPUBLIC VclBuilder
{
@@ -112,7 +112,7 @@ private:
typedef StringPair SpinButtonAdjustmentMap;
std::vector<SpinButtonAdjustmentMap> m_aAdjustmentMaps;
Adjustment *get_adjustment_by_name(rtl::OString sID);
- static void mungeadjustment(MetricField &rTarget, Adjustment &rAdjustment);
+ static void mungeadjustment(NumericFormatter &rTarget, Adjustment &rAdjustment);
typedef std::map<rtl::OString, rtl::OString> WidgetTranslations;
typedef std::map<rtl::OString, WidgetTranslations> Translations;
diff --git a/vcl/source/src/units.src b/vcl/source/src/units.src
index fa39df597c7a..f12daeb04d7c 100644
--- a/vcl/source/src/units.src
+++ b/vcl/source/src/units.src
@@ -31,7 +31,7 @@ StringArray SV_FUNIT_STRINGS
{
ItemList [ en-US ] =
{
- < "mm" ; FUNIT_MM ; > ;
+ < "mm" ; FUNIT_MM ; > ;
< "cm" ; FUNIT_CM ; > ;
< "m" ; FUNIT_M ; > ;
< "km" ; FUNIT_KM ; > ;
diff --git a/vcl/source/window/builder.cxx b/vcl/source/window/builder.cxx
index a9e56010832f..218b9fd3e22e 100644
--- a/vcl/source/window/builder.cxx
+++ b/vcl/source/window/builder.cxx
@@ -118,7 +118,7 @@ VclBuilder::VclBuilder(Window *pParent, rtl::OUString sUIDir, rtl::OUString sUIF
for (std::vector<SpinButtonAdjustmentMap>::iterator aI = m_aAdjustmentMaps.begin(),
aEnd = m_aAdjustmentMaps.end(); aI != aEnd; ++aI)
{
- MetricField *pTarget = static_cast<MetricField*>(get_by_name(aI->m_sID));
+ NumericFormatter *pTarget = dynamic_cast<NumericFormatter*>(get_by_name(aI->m_sID));
Adjustment *pAdjustment = get_adjustment_by_name(aI->m_sValue);
SAL_WARN_IF(!pTarget || !pAdjustment, "vcl", "missing elements of spinbutton/adjustment");
if (pTarget && pAdjustment)
@@ -202,6 +202,18 @@ void VclBuilder::handleTranslations(xmlreader::XmlReader &reader)
namespace
{
+ rtl::OString extractPattern(VclBuilder::stringmap &rMap)
+ {
+ rtl::OString sPattern;
+ VclBuilder::stringmap::iterator aFind = rMap.find(rtl::OString(RTL_CONSTASCII_STRINGPARAM("pattern")));
+ if (aFind != rMap.end())
+ {
+ sPattern = aFind->second;
+ rMap.erase(aFind);
+ }
+ return sPattern;
+ }
+
bool extractOrientation(VclBuilder::stringmap &rMap)
{
bool bVertical = false;
@@ -252,6 +264,40 @@ namespace
pWindow = new PushButton(pParent, nBits);
return pWindow;
}
+
+ FieldUnit detectMetricUnit(rtl::OString sUnit)
+ {
+ FieldUnit eUnit = FUNIT_NONE;
+
+ if (sUnit == "mm")
+ eUnit = FUNIT_MM;
+ else if (sUnit == "cm")
+ eUnit = FUNIT_CM;
+ else if (sUnit == "m")
+ eUnit = FUNIT_M;
+ else if (sUnit == "km")
+ eUnit = FUNIT_KM;
+ else if ((sUnit == "twips") || (sUnit == "twip"))
+ eUnit = FUNIT_TWIP;
+ else if (sUnit == "pt")
+ eUnit = FUNIT_POINT;
+ else if (sUnit == "pc")
+ eUnit = FUNIT_PICA;
+ else if (sUnit == "\"" || (sUnit == "in") || (sUnit == "inch"))
+ eUnit = FUNIT_INCH;
+ else if ((sUnit == "'") || (sUnit == "ft") || (sUnit == "foot") || (sUnit == "feet"))
+ eUnit = FUNIT_FOOT;
+ else if (sUnit == "mile" || (sUnit == "miles"))
+ eUnit = FUNIT_MILE;
+ else if (sUnit == "ch")
+ eUnit = FUNIT_CHAR;
+ else if (sUnit == "line")
+ eUnit = FUNIT_LINE;
+ else if (sUnit == "%")
+ eUnit = FUNIT_PERCENT;
+
+ return eUnit;
+ }
}
bool VclBuilder::extractGroup(const rtl::OString &id, stringmap &rMap)
@@ -357,7 +403,32 @@ Window *VclBuilder::makeObject(Window *pParent, const rtl::OString &name, const
else if (name.equalsL(RTL_CONSTASCII_STRINGPARAM("GtkSpinButton")))
{
extractAdjustment(id, rMap);
- pWindow = new MetricField(pParent, WB_RIGHT|WB_SPIN|WB_BORDER|WB_3DLOOK);
+ rtl::OString sPattern = extractPattern(rMap);
+ rtl::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;
+ }
+ }
+
+ FieldUnit eUnit = detectMetricUnit(sUnit);
+
+ if (sPattern.isEmpty())
+ {
+ fprintf(stderr, "making numeric field for %s %s\n", name.getStr(), sUnit.getStr());
+ pWindow = new NumericField(pParent, WB_RIGHT|WB_SPIN|WB_BORDER|WB_3DLOOK);
+ }
+ else
+ {
+ fprintf(stderr, "making metric field for %s %s\n", name.getStr(), sUnit.getStr());
+ MetricField *pField = new MetricField(pParent, WB_RIGHT|WB_SPIN|WB_BORDER|WB_3DLOOK);
+ pField->SetUnit(eUnit);
+ pWindow = pField;
+ }
}
else if (name.equalsL(RTL_CONSTASCII_STRINGPARAM("GtkComboBox")))
{
@@ -1089,7 +1160,7 @@ void VclBuilder::mungemodel(ListBox &rTarget, ListStore &rStore)
rTarget.SelectEntryPos(0);
}
-void VclBuilder::mungeadjustment(MetricField &rTarget, Adjustment &rAdjustment)
+void VclBuilder::mungeadjustment(NumericFormatter &rTarget, Adjustment &rAdjustment)
{
int nMul = rtl_math_pow10Exp(1, rTarget.GetDecimalDigits());