diff options
author | Caolán McNamara <caolanm@redhat.com> | 2012-12-11 14:03:18 +0000 |
---|---|---|
committer | Caolán McNamara <caolanm@redhat.com> | 2012-12-11 14:04:51 +0000 |
commit | a930214c40389b82ee1060ed65669dc772ed36ea (patch) | |
tree | d1c6c3a68ae2e3b2a78cac29127c897adce96943 | |
parent | 7ba2c823cac8998dfc0c2e19470f5edee70e63f0 (diff) |
support 'active' property in ListBox
Change-Id: Ib1219e8e7031febd4f9cc599cb19426f974eac9c
-rw-r--r-- | vcl/inc/vcl/builder.hxx | 16 | ||||
-rw-r--r-- | vcl/inc/vcl/lstbox.hxx | 2 | ||||
-rw-r--r-- | vcl/source/control/lstbox.cxx | 9 | ||||
-rw-r--r-- | vcl/source/window/builder.cxx | 26 |
4 files changed, 46 insertions, 7 deletions
diff --git a/vcl/inc/vcl/builder.hxx b/vcl/inc/vcl/builder.hxx index 4ca873f2d35e..e34da3aefcc8 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 f90a63e365a6..849da52a79a3 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 94f58d14520e..99ee4d0259bf 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 39c5e0a2bed7..2bba9f4d2085 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) |