[Libreoffice-commits] .: Branch 'feature/cmclayouttrans' - cui/uiconfig sw/uiconfig vcl/inc vcl/source

Caolán McNamara caolan at kemper.freedesktop.org
Fri Aug 17 05:57:40 PDT 2012


 cui/uiconfig/ui/10000.ui      |    3 +
 sw/uiconfig/sw/ui/20872.ui    |    6 +++
 vcl/inc/vcl/builder.hxx       |    4 +-
 vcl/source/src/units.src      |    2 -
 vcl/source/window/builder.cxx |   77 ++++++++++++++++++++++++++++++++++++++++--
 5 files changed, 85 insertions(+), 7 deletions(-)

New commits:
commit ed040d2118a178f87ad1094b0b2873af32c0041c
Author: Caolán McNamara <caolanm at redhat.com>
Date:   Fri Aug 17 13:49:40 2012 +0100

    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

diff --git a/cui/uiconfig/ui/10000.ui b/cui/uiconfig/ui/10000.ui
index 2ccc3dc..a14db03 100644
--- a/cui/uiconfig/ui/10000.ui
+++ b/cui/uiconfig/ui/10000.ui
@@ -186,7 +186,7 @@
                                 <property name="visible">True</property>
                                 <property name="can_focus">True</property>
                                 <property name="invisible_char">●</property>
-                                <property name="format">%</property>
+                                <property name="pattern">0%</property>
                               </object>
                               <packing>
                                 <property name="expand">False</property>
@@ -298,6 +298,7 @@
                                 <property name="visible">True</property>
                                 <property name="can_focus">True</property>
                                 <property name="invisible_char">●</property>
+                                <property name="pattern">0</property>
                               </object>
                               <packing>
                                 <property name="expand">False</property>
diff --git a/sw/uiconfig/sw/ui/20872.ui b/sw/uiconfig/sw/ui/20872.ui
index 777d049..21d8538 100644
--- a/sw/uiconfig/sw/ui/20872.ui
+++ b/sw/uiconfig/sw/ui/20872.ui
@@ -169,6 +169,7 @@
                         <property name="can_focus">True</property>
                         <property name="invisible_char">●</property>
                         <property name="invisible_char_set">True</property>
+                        <property name="pattern">0.00cm</property>
                       </object>
                       <packing>
                         <property name="left_attach">1</property>
@@ -197,6 +198,7 @@
                         <property name="can_focus">True</property>
                         <property name="invisible_char">●</property>
                         <property name="invisible_char_set">True</property>
+                        <property name="pattern">0.00cm</property>
                       </object>
                       <packing>
                         <property name="left_attach">1</property>
@@ -211,6 +213,7 @@
                         <property name="can_focus">True</property>
                         <property name="invisible_char">●</property>
                         <property name="invisible_char_set">True</property>
+                        <property name="pattern">0.00cm</property>
                       </object>
                       <packing>
                         <property name="left_attach">1</property>
@@ -284,6 +287,7 @@
                         <property name="invisible_char">●</property>
                         <property name="adjustment">adjustment2</property>
                         <property name="digits">2</property>
+                        <property name="pattern">0.00cm</property>
                       </object>
                       <packing>
                         <property name="left_attach">1</property>
@@ -331,6 +335,7 @@
                         <property name="invisible_char">●</property>
                         <property name="adjustment">adjustment1</property>
                         <property name="digits">2</property>
+                        <property name="pattern">0.00cm</property>
                       </object>
                       <packing>
                         <property name="left_attach">1</property>
@@ -346,6 +351,7 @@
                         <property name="invisible_char">●</property>
                         <property name="adjustment">adjustment1</property>
                         <property name="digits">2</property>
+                        <property name="pattern">0.00cm</property>
                       </object>
                       <packing>
                         <property name="left_attach">1</property>
diff --git a/vcl/inc/vcl/builder.hxx b/vcl/inc/vcl/builder.hxx
index ff346dd..05c40d4 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 2402356..3a69a10 100644
--- a/vcl/source/src/units.src
+++ b/vcl/source/src/units.src
@@ -33,7 +33,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 a9e5601..218b9fd 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());
 


More information about the Libreoffice-commits mailing list