[Libreoffice-commits] .: vcl/inc vcl/source

Libreoffice Gerrit user logerrit at kemper.freedesktop.org
Tue Dec 11 06:05:12 PST 2012


 vcl/inc/vcl/builder.hxx       |   16 ++++++++++++++--
 vcl/inc/vcl/lstbox.hxx        |    2 ++
 vcl/source/control/lstbox.cxx |    9 +++++++++
 vcl/source/window/builder.cxx |   26 +++++++++++++++++++++-----
 4 files changed, 46 insertions(+), 7 deletions(-)

New commits:
commit a930214c40389b82ee1060ed65669dc772ed36ea
Author: Caolán McNamara <caolanm at redhat.com>
Date:   Tue Dec 11 14:03:18 2012 +0000

    support 'active' property in ListBox
    
    Change-Id: Ib1219e8e7031febd4f9cc599cb19426f974eac9c

diff --git a/vcl/inc/vcl/builder.hxx b/vcl/inc/vcl/builder.hxx
index 4ca873f..e34da3a 100644
--- a/vcl/inc/vcl/builder.hxx
+++ b/vcl/inc/vcl/builder.hxx
@@ -81,19 +81,31 @@ private:
     };
 
     typedef StringPair RadioButtonGroupMap;
-    typedef StringPair ComboBoxModelMap;
     typedef StringPair ButtonImageWidgetMap;
     typedef StringPair TextBufferMap;
     typedef StringPair WidgetAdjustmentMap;
     typedef StringPair ButtonMenuMap;
 
+    struct ComboBoxModelMap
+    {
+        OString m_sID;
+        OString m_sValue;
+        sal_Int32 m_nActiveId;
+        ComboBoxModelMap(const OString &rId, const OString &rValue, sal_Int32 nActiveId)
+            : m_sID(rId)
+            , m_sValue(rValue)
+            , m_nActiveId(nActiveId)
+        {
+        }
+    };
+
     struct ListStore
     {
         typedef std::vector<OString> row;
         std::vector<row> m_aEntries;
     };
     const ListStore* get_model_by_name(OString sID) const;
-    static void mungeModel(ListBox &rTarget, const ListStore &rStore);
+    static void mungeModel(ListBox &rTarget, const ListStore &rStore, sal_uInt16 nActiveId);
 
     typedef stringmap TextBuffer;
     const TextBuffer* get_buffer_by_name(OString sID) const;
diff --git a/vcl/inc/vcl/lstbox.hxx b/vcl/inc/vcl/lstbox.hxx
index f90a63e..849da52 100644
--- a/vcl/inc/vcl/lstbox.hxx
+++ b/vcl/inc/vcl/lstbox.hxx
@@ -217,6 +217,8 @@ public:
      */
     using Control::GetIndexForPoint;
     long GetIndexForPoint( const Point& rPoint, sal_uInt16& rPos ) const;
+
+    virtual bool set_property(const rtl::OString &rKey, const rtl::OString &rValue);
 };
 
 // ----------------
diff --git a/vcl/source/control/lstbox.cxx b/vcl/source/control/lstbox.cxx
index 94f58d1..99ee4d0 100644
--- a/vcl/source/control/lstbox.cxx
+++ b/vcl/source/control/lstbox.cxx
@@ -1540,6 +1540,15 @@ const Wallpaper& ListBox::GetDisplayBackground() const
     return mpImplLB->GetDisplayBackground();
 }
 
+bool ListBox::set_property(const rtl::OString &rKey, const rtl::OString &rValue)
+{
+    if (rKey == "active")
+        SelectEntryPos(rValue.toInt32());
+    else
+        return Control::set_property(rKey, rValue);
+    return true;
+}
+
 // =======================================================================
 MultiListBox::MultiListBox( Window* pParent, WinBits nStyle ) :
     ListBox( WINDOW_MULTILISTBOX )
diff --git a/vcl/source/window/builder.cxx b/vcl/source/window/builder.cxx
index 39c5e0a..2bba9f4 100644
--- a/vcl/source/window/builder.cxx
+++ b/vcl/source/window/builder.cxx
@@ -162,7 +162,7 @@ VclBuilder::VclBuilder(Window *pParent, OUString sUIDir, OUString sUIFile, OStri
         const ListStore *pStore = get_model_by_name(aI->m_sValue);
         SAL_WARN_IF(!pTarget || !pStore, "vcl", "missing elements of combobox/liststore");
         if (pTarget && pStore)
-            mungeModel(*pTarget, *pStore);
+            mungeModel(*pTarget, *pStore, aI->m_nActiveId);
     }
 
     //Set TextView buffers when everything has been imported
@@ -575,12 +575,28 @@ bool VclBuilder::extractScrollAdjustment(const OString &id, stringmap &rMap)
     return false;
 }
 
+namespace
+{
+    sal_Int32 extractActive(VclBuilder::stringmap &rMap)
+    {
+        sal_Int32 nActiveId = 0;
+        VclBuilder::stringmap::iterator aFind = rMap.find(OString("active"));
+        if (aFind != rMap.end())
+        {
+            nActiveId = aFind->second.toInt32();
+            rMap.erase(aFind);
+        }
+        return nActiveId;
+    }
+}
+
 bool VclBuilder::extractModel(const OString &id, stringmap &rMap)
 {
     VclBuilder::stringmap::iterator aFind = rMap.find(OString("model"));
     if (aFind != rMap.end())
     {
-        m_pParserState->m_aModelMaps.push_back(ComboBoxModelMap(id, aFind->second));
+        m_pParserState->m_aModelMaps.push_back(ComboBoxModelMap(id, aFind->second,
+            extractActive(rMap)));
         rMap.erase(aFind);
         return true;
     }
@@ -1994,7 +2010,7 @@ const VclBuilder::Adjustment *VclBuilder::get_adjustment_by_name(OString sID) co
     return NULL;
 }
 
-void VclBuilder::mungeModel(ListBox &rTarget, const ListStore &rStore)
+void VclBuilder::mungeModel(ListBox &rTarget, const ListStore &rStore, sal_uInt16 nActiveId)
 {
     for (std::vector<ListStore::row>::const_iterator aI = rStore.m_aEntries.begin(), aEnd = rStore.m_aEntries.end();
         aI != aEnd; ++aI)
@@ -2007,8 +2023,8 @@ void VclBuilder::mungeModel(ListBox &rTarget, const ListStore &rStore)
             rTarget.SetEntryData(nEntry, (void*)nValue);
         }
     }
-    if (!rStore.m_aEntries.empty())
-        rTarget.SelectEntryPos(0);
+    if (nActiveId < rStore.m_aEntries.size())
+        rTarget.SelectEntryPos(nActiveId);
 }
 
 void VclBuilder::mungeSpinAdjustment(NumericFormatter &rTarget, const Adjustment &rAdjustment)


More information about the Libreoffice-commits mailing list