diff options
author | Caolán McNamara <caolanm@redhat.com> | 2018-11-05 15:08:47 +0000 |
---|---|---|
committer | Caolán McNamara <caolanm@redhat.com> | 2018-11-07 22:01:20 +0100 |
commit | a977098f59a4c931c6f8a1d423720e682f5ed047 (patch) | |
tree | d865c854cc2e6c0151b0b4aea4b7865cc1822585 | |
parent | 6311f7ffce8f64b0773d2ad3ea7be3be683924c0 (diff) |
map GtkTreeView to SvTreeViewBox now it is in vcl
Change-Id: I8ab8421354a296cb6382f28fd3bd40372e0665df
Reviewed-on: https://gerrit.libreoffice.org/62908
Tested-by: Jenkins
Reviewed-by: Caolán McNamara <caolanm@redhat.com>
Tested-by: Caolán McNamara <caolanm@redhat.com>
-rw-r--r-- | cui/qa/uitest/dialogs/pastedlg.py | 5 | ||||
-rw-r--r-- | include/vcl/builder.hxx | 2 | ||||
-rw-r--r-- | include/vcl/lstbox.hxx | 4 | ||||
-rw-r--r-- | include/vcl/treelistbox.hxx | 2 | ||||
-rw-r--r-- | include/vcl/treelistentry.hxx | 7 | ||||
-rw-r--r-- | sw/qa/uitest/table/tdf116737.py | 5 | ||||
-rw-r--r-- | uitest/manual_tests/calc.py | 2 | ||||
-rw-r--r-- | vcl/inc/listbox.hxx | 6 | ||||
-rw-r--r-- | vcl/source/app/salvtables.cxx | 123 | ||||
-rw-r--r-- | vcl/source/control/imp_listbox.cxx | 15 | ||||
-rw-r--r-- | vcl/source/control/listbox.cxx | 5 | ||||
-rw-r--r-- | vcl/source/treelist/treelistbox.cxx | 9 | ||||
-rw-r--r-- | vcl/source/treelist/uiobject.cxx | 3 | ||||
-rw-r--r-- | vcl/source/window/builder.cxx | 52 | ||||
-rw-r--r-- | vcl/unx/gtk3/gtk3gtkinst.cxx | 16 |
15 files changed, 156 insertions, 100 deletions
diff --git a/cui/qa/uitest/dialogs/pastedlg.py b/cui/qa/uitest/dialogs/pastedlg.py index 4c17adac33d3..ccd33e02d11e 100644 --- a/cui/qa/uitest/dialogs/pastedlg.py +++ b/cui/qa/uitest/dialogs/pastedlg.py @@ -29,10 +29,11 @@ class Test(UITestCase): self.ui_test.execute_dialog_through_command(".uno:PasteSpecial") pasteSpecial = self.xUITest.getTopFocusWindow() formats = pasteSpecial.getChild("list") - entryCount = int(get_state_as_dict(formats)["EntryCount"]) + entryCount = int(get_state_as_dict(formats)["Children"]) items = [] for index in range(entryCount): - formats.executeAction("SELECT", mkPropertyValues({"POS": str(index)})) + entry = formats.getChild(str(index)) + entry.executeAction("SELECT", tuple()) items.append(get_state_as_dict(formats)["SelectEntryText"]) # Make sure there is no RTF vs Richtext duplication. diff --git a/include/vcl/builder.hxx b/include/vcl/builder.hxx index 534789b12cb2..203b44e96871 100644 --- a/include/vcl/builder.hxx +++ b/include/vcl/builder.hxx @@ -43,6 +43,7 @@ class PopupMenu; class SalInstanceBuilder; class ScreenshotTest; class ScrollBar; +class SvTreeListBox; class Slider; class DateField; class TimeField; @@ -220,6 +221,7 @@ private: const ListStore* get_model_by_name(const OString& sID) const; void mungeModel(ListBox &rTarget, const ListStore &rStore, sal_uInt16 nActiveId); void mungeModel(ComboBox &rTarget, const ListStore &rStore, sal_uInt16 nActiveId); + void mungeModel(SvTreeListBox &rTarget, const ListStore &rStore, sal_uInt16 nActiveId); typedef stringmap TextBuffer; const TextBuffer* get_buffer_by_name(const OString& sID) const; diff --git a/include/vcl/lstbox.hxx b/include/vcl/lstbox.hxx index 8ee51a2681fb..332233158b98 100644 --- a/include/vcl/lstbox.hxx +++ b/include/vcl/lstbox.hxx @@ -69,12 +69,10 @@ class ImplListBoxFloatingWindow; class ImplBtn; class ImplWin; class ImplListBoxWindow; -class SalInstanceEntryTreeView; class VCL_DLLPUBLIC ListBox : public Control { private: - friend SalInstanceEntryTreeView; VclPtr<ImplListBox> mpImplLB; VclPtr<ImplListBoxFloatingWindow> mpFloatWin; VclPtr<ImplWin> mpImplWin; @@ -178,8 +176,6 @@ public: void* GetEntryData( sal_Int32 nPos ) const; void* GetSelectedEntryData() const { return GetEntryData(GetSelectedEntryPos()); } - void SetEntryTextColor(sal_Int32 nPos, const Color* pTextColor); - /** this methods stores a combination of flags from the ListBoxEntryFlags::* defines at the given entry. See description of the possible ListBoxEntryFlags::* flags diff --git a/include/vcl/treelistbox.hxx b/include/vcl/treelistbox.hxx index 464b9d30f864..36dd643eb473 100644 --- a/include/vcl/treelistbox.hxx +++ b/include/vcl/treelistbox.hxx @@ -192,6 +192,7 @@ namespace o3tl struct SvTreeListBoxImpl; class SalInstanceTreeView; +class SalInstanceEntryTreeView; class VCL_DLLPUBLIC SvTreeListBox :public Control @@ -205,6 +206,7 @@ class VCL_DLLPUBLIC SvTreeListBox friend class IconViewImpl; friend class TreeControlPeer; friend class SalInstanceTreeView; + friend class SalInstanceEntryTreeView; std::unique_ptr<SvTreeListBoxImpl> mpImpl; Link<SvTreeListBox*,void> aCheckButtonHdl; diff --git a/include/vcl/treelistentry.hxx b/include/vcl/treelistentry.hxx index c734729174ce..b318bb3c440f 100644 --- a/include/vcl/treelistentry.hxx +++ b/include/vcl/treelistentry.hxx @@ -63,6 +63,7 @@ class VCL_DLLPUBLIC SvTreeListEntry void* pUserData; SvTLEntryFlags nEntryFlags; Color maBackColor; + std::unique_ptr<Color> mxTextColor; private: void ClearChildren(); @@ -108,8 +109,12 @@ public: SvTLEntryFlags GetFlags() const { return nEntryFlags;} void SetFlags( SvTLEntryFlags nFlags ); - void SetBackColor( const Color& aColor ) { maBackColor = aColor; } + void SetBackColor( const Color& rColor ) { maBackColor = rColor; } const Color& GetBackColor() const { return maBackColor; } + + void SetTextColor( const Color* pColor ) { mxTextColor.reset(pColor ? new Color(*pColor) : nullptr); } + const Color* GetTextColor() const { return mxTextColor.get(); } + SvTreeListEntry* GetParent() const { return pParent; } SvTreeListEntry* NextSibling() const; diff --git a/sw/qa/uitest/table/tdf116737.py b/sw/qa/uitest/table/tdf116737.py index 37a09f2a65f4..17ac2eb3f0ec 100644 --- a/sw/qa/uitest/table/tdf116737.py +++ b/sw/qa/uitest/table/tdf116737.py @@ -25,9 +25,8 @@ class tdf116737(UITestCase): xDialog = self.xUITest.getTopFocusWindow() formatlbinstable = xDialog.getChild("formatlbinstable") - props = {"TEXT": "Simple List Shaded"} - actionProps = mkPropertyValues(props) - formatlbinstable.executeAction("SELECT", actionProps) + entry = formatlbinstable.getChild("11") #Simple List Shaded + entry.executeAction("SELECT", tuple()) xOkBtn = xDialog.getChild("ok") self.ui_test.close_dialog_through_button(xOkBtn) diff --git a/uitest/manual_tests/calc.py b/uitest/manual_tests/calc.py index 9c86b6c3e6d9..1b7897983a38 100644 --- a/uitest/manual_tests/calc.py +++ b/uitest/manual_tests/calc.py @@ -51,7 +51,7 @@ class ManualCalcTests(UITestCase): xListBox = xSelectNameDlg.getChild("treeview") xListBoxState = get_state_as_dict(xListBox) - self.assertEqual(xListBoxState["SelectEntryCount"], "1") + self.assertEqual(xListBoxState["SelectionCount"], "1") self.assertEqual(xListBoxState["SelectEntryText"], "my_database") xOkBtn = xSelectNameDlg.getChild("ok") diff --git a/vcl/inc/listbox.hxx b/vcl/inc/listbox.hxx index 8cc0592147b7..c448c923ed9f 100644 --- a/vcl/inc/listbox.hxx +++ b/vcl/inc/listbox.hxx @@ -48,7 +48,6 @@ struct ImplEntryType { OUString const maStr; SalLayoutGlyphs maStrGlyphs; - std::unique_ptr<Color> mxTextColor; Image const maImage; void* mpUserData; bool mbIsSelected; @@ -135,9 +134,6 @@ public: void SetEntryFlags( sal_Int32 nPos, ListBoxEntryFlags nFlags ); ListBoxEntryFlags GetEntryFlags( sal_Int32 nPos ) const; - void SetEntryTextColor(sal_Int32 nPos, const Color* pColor); - const Color* GetEntryTextColor(sal_Int32 nPos) const; - void SelectEntry( sal_Int32 nPos, bool bSelect ); sal_Int32 GetSelectedEntryCount() const; @@ -428,8 +424,6 @@ public: void SetEntryFlags( sal_Int32 nPos, ListBoxEntryFlags nFlags ); - void SetEntryTextColor(sal_Int32 nPos, const Color* pTextColor) { maLBWindow->GetEntryList()->SetEntryTextColor(nPos, pTextColor); } - void SelectEntry( sal_Int32 nPos, bool bSelect ); void SetNoSelection(); void ResetCurrentPos() { maLBWindow->ResetCurrentPos(); } diff --git a/vcl/source/app/salvtables.cxx b/vcl/source/app/salvtables.cxx index 490d89006399..c849343e02c7 100644 --- a/vcl/source/app/salvtables.cxx +++ b/vcl/source/app/salvtables.cxx @@ -43,8 +43,11 @@ #include <vcl/prgsbar.hxx> #include <vcl/slider.hxx> #include <vcl/sysdata.hxx> +#include <vcl/svlbitm.hxx> #include <vcl/tabctrl.hxx> #include <vcl/tabpage.hxx> +#include <vcl/treelistbox.hxx> +#include <vcl/treelistentry.hxx> #include <vcl/toolkit/unowrap.hxx> #include <vcl/weld.hxx> #include <bitmaps.hlst> @@ -1749,13 +1752,13 @@ IMPL_LINK(SalInstanceEntry, CursorListener, VclWindowEvent&, rEvent, void) class SalInstanceTreeView : public SalInstanceContainer, public virtual weld::TreeView { private: - VclPtr<ListBox> m_xTreeView; + VclPtr<SvTreeListBox> m_xTreeView; - DECL_LINK(SelectHdl, ListBox&, void); - DECL_LINK(DoubleClickHdl, ListBox&, void); + DECL_LINK(SelectHdl, SvTreeListBox*, void); + DECL_LINK(DoubleClickHdl, SvTreeListBox*, bool); public: - SalInstanceTreeView(ListBox* pTreeView, bool bTakeOwnership) + SalInstanceTreeView(SvTreeListBox* pTreeView, bool bTakeOwnership) : SalInstanceContainer(pTreeView, bTakeOwnership) , m_xTreeView(pTreeView) { @@ -1766,52 +1769,61 @@ public: virtual void insert(int pos, const OUString& rStr, const OUString* pId, const OUString* pIconName, VirtualDevice* pImageSurface) override { auto nInsertPos = pos == -1 ? COMBOBOX_APPEND : pos; - sal_Int32 nInsertedAt; + void* pUserData = pId ? new OUString(*pId) : nullptr; + if (!pIconName && !pImageSurface) - nInsertedAt = m_xTreeView->InsertEntry(rStr, nInsertPos); - else if (pIconName) - nInsertedAt = m_xTreeView->InsertEntry(rStr, createImage(*pIconName), nInsertPos); + m_xTreeView->InsertEntry(rStr, nullptr, false, nInsertPos, pUserData); else - nInsertedAt = m_xTreeView->InsertEntry(rStr, createImage(*pImageSurface), nInsertPos); - if (pId) - m_xTreeView->SetEntryData(nInsertedAt, new OUString(*pId)); + { + SvTreeListEntry* pEntry = new SvTreeListEntry; + Image aImage(pIconName ? createImage(*pIconName) : createImage(*pImageSurface)); + pEntry->AddItem(o3tl::make_unique<SvLBoxContextBmp>(aImage, aImage, false)); + pEntry->AddItem(o3tl::make_unique<SvLBoxString>(rStr)); + pEntry->SetUserData(pUserData); + m_xTreeView->Insert(pEntry, nInsertPos); + } } virtual void set_font_color(int pos, const Color& rColor) const override { - m_xTreeView->SetEntryTextColor(pos, &rColor); + SvTreeListEntry* pEntry = m_xTreeView->GetEntry(nullptr, pos); + pEntry->SetTextColor(&rColor); } virtual void remove(int pos) override { - m_xTreeView->RemoveEntry(pos); + SvTreeListEntry* pEntry = m_xTreeView->GetEntry(nullptr, pos); + m_xTreeView->RemoveEntry(pEntry); } virtual int find_text(const OUString& rText) const override { - sal_Int32 nRet = m_xTreeView->GetEntryPos(rText); - if (nRet == LISTBOX_ENTRY_NOTFOUND) - return -1; - return nRet; + for (SvTreeListEntry* pEntry = m_xTreeView->First(); pEntry; pEntry = m_xTreeView->Next(pEntry)) + { + if (m_xTreeView->GetEntryText(pEntry) == rText) + return m_xTreeView->GetAbsPos(pEntry); + } + return -1; } virtual int find_id(const OUString& rId) const override { - sal_Int32 nCount = m_xTreeView->GetEntryCount(); - for (sal_Int32 nPos = 0; nPos < nCount; ++nPos) + for (SvTreeListEntry* pEntry = m_xTreeView->First(); pEntry; pEntry = m_xTreeView->Next(pEntry)) { - OUString* pId = static_cast<OUString*>(m_xTreeView->GetEntryData(nPos)); + const OUString* pId = static_cast<const OUString*>(pEntry->GetUserData()); if (!pId) continue; if (rId == *pId) - return nPos; + return m_xTreeView->GetAbsPos(pEntry); } return -1; } virtual void set_top_entry(int pos) override { - m_xTreeView->SetTopEntry(pos); + SvTreeList* pModel = m_xTreeView->GetModel(); + SvTreeListEntry* pEntry = pModel->GetEntry(nullptr, pos); + pModel->Move(pEntry, nullptr, 0); } virtual void clear() override @@ -1827,44 +1839,52 @@ public: virtual void select(int pos) override { assert(m_xTreeView->IsUpdateMode() && "don't select when frozen"); + disable_notify_events(); if (pos == -1) - m_xTreeView->SetNoSelection(); + m_xTreeView->SelectAll(false); else - m_xTreeView->SelectEntryPos(pos); + { + SvTreeListEntry* pEntry = m_xTreeView->GetEntry(nullptr, pos); + m_xTreeView->Select(pEntry, true); + } + enable_notify_events(); } virtual void unselect(int pos) override { assert(m_xTreeView->IsUpdateMode() && "don't select when frozen"); + disable_notify_events(); if (pos == -1) + m_xTreeView->SelectAll(true); + else { - for (sal_Int32 i = 0; i < m_xTreeView->GetEntryCount(); ++i) - m_xTreeView->SelectEntryPos(i); + SvTreeListEntry* pEntry = m_xTreeView->GetEntry(nullptr, pos); + m_xTreeView->Select(pEntry, false); } - else - m_xTreeView->SelectEntryPos(pos, false); + enable_notify_events(); } virtual std::vector<int> get_selected_rows() const override { std::vector<int> aRows; - sal_Int32 nCount = m_xTreeView->GetSelectedEntryCount(); - aRows.reserve(nCount); - for (sal_Int32 i = 0; i < nCount; ++i) - aRows.push_back(m_xTreeView->GetSelectedEntryPos(i)); + aRows.reserve(m_xTreeView->GetSelectionCount()); + for (SvTreeListEntry* pEntry = m_xTreeView->FirstSelected(); pEntry; pEntry = m_xTreeView->NextSelected(pEntry)) + aRows.push_back(m_xTreeView->GetAbsPos(pEntry)); return aRows; } virtual OUString get_text(int pos) const override { - return m_xTreeView->GetEntry(pos); + SvTreeListEntry* pEntry = m_xTreeView->GetEntry(nullptr, pos); + return m_xTreeView->GetEntryText(pEntry); } const OUString* getEntryData(int index) const { - return static_cast<const OUString*>(m_xTreeView->GetEntryData(index)); + SvTreeListEntry* pEntry = m_xTreeView->GetEntry(nullptr, index); + return static_cast<const OUString*>(pEntry->GetUserData()); } virtual OUString get_id(int pos) const override @@ -1877,25 +1897,25 @@ public: virtual int get_selected_index() const override { - const sal_Int32 nRet = m_xTreeView->GetSelectedEntryPos(); - if (nRet == LISTBOX_ENTRY_NOTFOUND) + SvTreeListEntry* pEntry = m_xTreeView->FirstSelected(); + if (!pEntry) return -1; - return nRet; + return m_xTreeView->GetAbsPos(pEntry); } virtual void set_selection_mode(bool bMultiple) override { - m_xTreeView->EnableMultiSelection(bMultiple); + m_xTreeView->SetSelectionMode(bMultiple ? SelectionMode::Multiple : SelectionMode::Single); } virtual int count_selected_rows() const override { - return m_xTreeView->GetSelectedEntryCount(); + return m_xTreeView->GetSelectionCount(); } virtual int get_height_rows(int nRows) const override { - return m_xTreeView->CalcWindowSizePixel(nRows); + return m_xTreeView->GetEntryHeight() * nRows; } virtual void make_sorted() override @@ -1903,30 +1923,31 @@ public: m_xTreeView->SetStyle(m_xTreeView->GetStyle() | WB_SORT); } - ListBox& getTreeView() + SvTreeListBox& getTreeView() { return *m_xTreeView; } virtual ~SalInstanceTreeView() override { - m_xTreeView->SetDoubleClickHdl(Link<ListBox&, void>()); - m_xTreeView->SetSelectHdl(Link<ListBox&, void>()); + m_xTreeView->SetDoubleClickHdl(Link<SvTreeListBox*, bool>()); + m_xTreeView->SetSelectHdl(Link<SvTreeListBox*, void>()); } }; -IMPL_LINK_NOARG(SalInstanceTreeView, SelectHdl, ListBox&, void) +IMPL_LINK_NOARG(SalInstanceTreeView, SelectHdl, SvTreeListBox*, void) { if (notify_events_disabled()) return; signal_changed(); } -IMPL_LINK_NOARG(SalInstanceTreeView, DoubleClickHdl, ListBox&, void) +IMPL_LINK_NOARG(SalInstanceTreeView, DoubleClickHdl, SvTreeListBox*, bool) { if (notify_events_disabled()) - return; + return false; signal_row_activated(); + return false; } class SalInstanceSpinButton : public SalInstanceEntry, public virtual weld::SpinButton @@ -2710,9 +2731,11 @@ IMPL_LINK(SalInstanceEntryTreeView, KeyPressListener, VclWindowEvent&, rEvent, v if (nKeyCode == KEY_UP || nKeyCode == KEY_DOWN || nKeyCode == KEY_PAGEUP || nKeyCode == KEY_PAGEDOWN) { m_pTreeView->disable_notify_events(); - ListBox& rListBox = m_pTreeView->getTreeView(); - NotifyEvent aNotifyEvt(MouseNotifyEvent::KEYINPUT, reinterpret_cast<vcl::Window*>(rListBox.mpImplWin.get()), &rKeyEvent); - rListBox.PreNotify(aNotifyEvt); + auto& rListBox = m_pTreeView->getTreeView(); + if (!rListBox.FirstSelected()) + rListBox.Select(rListBox.First(), true); + else + rListBox.KeyInput(rKeyEvent); m_xEntry->set_text(m_xTreeView->get_selected_text()); m_xEntry->select_region(0, -1); m_pTreeView->enable_notify_events(); @@ -2927,7 +2950,7 @@ public: virtual std::unique_ptr<weld::TreeView> weld_tree_view(const OString &id, bool bTakeOwnership) override { - ListBox* pTreeView = m_xBuilder->get<ListBox>(id); + SvTreeListBox* pTreeView = m_xBuilder->get<SvTreeListBox>(id); return pTreeView ? o3tl::make_unique<SalInstanceTreeView>(pTreeView, bTakeOwnership) : nullptr; } diff --git a/vcl/source/control/imp_listbox.cxx b/vcl/source/control/imp_listbox.cxx index 265a9589ff63..bd6c0b04214c 100644 --- a/vcl/source/control/imp_listbox.cxx +++ b/vcl/source/control/imp_listbox.cxx @@ -370,19 +370,6 @@ void* ImplEntryList::GetEntryData( sal_Int32 nPos ) const return pImplEntry ? pImplEntry->mpUserData : nullptr; } -void ImplEntryList::SetEntryTextColor(sal_Int32 nPos, const Color* pColor) -{ - ImplEntryType* pImplEntry = GetEntry(nPos); - if (pImplEntry) - pImplEntry->mxTextColor.reset(pColor ? new Color(*pColor) : nullptr); -} - -const Color* ImplEntryList::GetEntryTextColor(sal_Int32 nPos) const -{ - ImplEntryType* pImplEntry = GetEntry(nPos); - return pImplEntry ? pImplEntry->mxTextColor.get() : nullptr; -} - void ImplEntryList::SetEntryFlags( sal_Int32 nPos, ListBoxEntryFlags nFlags ) { ImplEntryType* pImplEntry = GetEntry( nPos ); @@ -1743,8 +1730,6 @@ void ImplListBoxWindow::ImplPaint(vcl::RenderContext& rRenderContext, sal_Int32 ApplySettings(rRenderContext); if (!IsEnabled()) rRenderContext.SetTextColor(rStyleSettings.GetDisableColor()); - else if (const Color* pTextColor = mpEntryList->GetEntryTextColor(nPos)) - rRenderContext.SetTextColor(*pTextColor); } rRenderContext.SetTextFillColor(); diff --git a/vcl/source/control/listbox.cxx b/vcl/source/control/listbox.cxx index 40949fd3fb5d..cfc5a83f97b1 100644 --- a/vcl/source/control/listbox.cxx +++ b/vcl/source/control/listbox.cxx @@ -1090,11 +1090,6 @@ void* ListBox::GetEntryData( sal_Int32 nPos ) const return mpImplLB->GetEntryList()->GetEntryData( nPos + mpImplLB->GetEntryList()->GetMRUCount() ); } -void ListBox::SetEntryTextColor(sal_Int32 nPos, const Color* pTextColor) -{ - mpImplLB->SetEntryTextColor(nPos + mpImplLB->GetEntryList()->GetMRUCount(), pTextColor); -} - void ListBox::SetEntryFlags( sal_Int32 nPos, ListBoxEntryFlags nFlags ) { mpImplLB->SetEntryFlags( nPos + mpImplLB->GetEntryList()->GetMRUCount(), nFlags ); diff --git a/vcl/source/treelist/treelistbox.cxx b/vcl/source/treelist/treelistbox.cxx index a1f580e66a64..7507394801de 100644 --- a/vcl/source/treelist/treelistbox.cxx +++ b/vcl/source/treelist/treelistbox.cxx @@ -2745,10 +2745,13 @@ void SvTreeListBox::PaintEntry1(SvTreeListEntry& rEntry, long nLine, vcl::Render { aWallpaper.SetColor(rSettings.GetFieldColor()); } - else if (bCurFontIsSel) + else if (bCurFontIsSel || rEntry.GetTextColor()) { bCurFontIsSel = false; - rRenderContext.SetTextColor(aBackupTextColor); + if (const auto* pCustomTextColor = rEntry.GetTextColor()) + rRenderContext.SetTextColor(*pCustomTextColor); + else + rRenderContext.SetTextColor(aBackupTextColor); rRenderContext.SetFont(aBackupFont); } else @@ -2825,7 +2828,7 @@ void SvTreeListBox::PaintEntry1(SvTreeListEntry& rEntry, long nLine, vcl::Render nCurTab++; } - if (bCurFontIsSel) + if (bCurFontIsSel || rEntry.GetTextColor()) { rRenderContext.SetTextColor(aBackupTextColor); rRenderContext.SetFont(aBackupFont); diff --git a/vcl/source/treelist/uiobject.cxx b/vcl/source/treelist/uiobject.cxx index 2c6312861865..dcb120058352 100644 --- a/vcl/source/treelist/uiobject.cxx +++ b/vcl/source/treelist/uiobject.cxx @@ -35,6 +35,9 @@ StringMap TreeListUIObject::get_state() aMap["Children"] = OUString::number(mxTreeList->GetChildCount(nullptr)); aMap["LevelChildren"] = OUString::number(mxTreeList->GetLevelChildCount(nullptr)); aMap["CheckBoxList"] = OUString::boolean(isCheckBoxList(mxTreeList)); + SvTreeListEntry* pEntry = mxTreeList->FirstSelected(); + aMap["SelectEntryText"] = pEntry ? mxTreeList->GetEntryText(pEntry) : OUString(); + return aMap; } diff --git a/vcl/source/window/builder.cxx b/vcl/source/window/builder.cxx index df0b82a9b6f6..ece1380052f5 100644 --- a/vcl/source/window/builder.cxx +++ b/vcl/source/window/builder.cxx @@ -39,6 +39,8 @@ #include <vcl/tabpage.hxx> #include <vcl/throbber.hxx> #include <vcl/toolbox.hxx> +#include <vcl/treelistbox.hxx> +#include <vcl/treelistentry.hxx> #include <vcl/vclmedit.hxx> #include <vcl/settings.hxx> #include <vcl/slider.hxx> @@ -491,13 +493,16 @@ VclBuilder::VclBuilder(vcl::Window *pParent, const OUString& sUIDir, const OUStr vcl::Window* pTarget = get<vcl::Window>(elem.m_sID); ListBox *pListBoxTarget = dynamic_cast<ListBox*>(pTarget); ComboBox *pComboBoxTarget = dynamic_cast<ComboBox*>(pTarget); + SvTreeListBox *pTreeBoxTarget = dynamic_cast<SvTreeListBox*>(pTarget); // pStore may be empty const ListStore *pStore = get_model_by_name(elem.m_sValue.toUtf8()); - SAL_WARN_IF(!pListBoxTarget && !pComboBoxTarget, "vcl", "missing elements of combobox"); + SAL_WARN_IF(!pListBoxTarget && !pComboBoxTarget && !pTreeBoxTarget, "vcl", "missing elements of combobox"); if (pListBoxTarget && pStore) mungeModel(*pListBoxTarget, *pStore, elem.m_nActiveId); else if (pComboBoxTarget && pStore) mungeModel(*pComboBoxTarget, *pStore, elem.m_nActiveId); + else if (pTreeBoxTarget && pStore) + mungeModel(*pTreeBoxTarget, *pStore, elem.m_nActiveId); } //Set TextView buffers when everything has been imported @@ -1809,10 +1814,10 @@ VclPtr<vcl::Window> VclBuilder::makeObject(vcl::Window *pParent, const OString & else if (name == "GtkTreeView") { //To-Do - //a) make SvTreeViewBox the default target for GtkTreeView + //a) make SvTreeListBox the default target for GtkTreeView //b) remove the non-drop down mode of ListBox and convert - // everything over to SvTreeViewBox - //c) remove the users of makeSvTreeViewBox + // everything over to SvTreeListBox + //c) remove the users of makeSvTreeListBox extractModel(id, rMap); WinBits nWinStyle = WB_CLIPCHILDREN|WB_LEFT|WB_VCENTER|WB_3DLOOK|WB_SIMPLEMODE; if (m_bLegacy) @@ -1821,11 +1826,18 @@ VclPtr<vcl::Window> VclBuilder::makeObject(vcl::Window *pParent, const OString & if (!sBorder.isEmpty()) nWinStyle |= WB_BORDER; } - //ListBox manages its own scrolling, + //ListBox/SvTreeListBox manages its own scrolling, vcl::Window *pRealParent = prepareWidgetOwnScrolling(pParent, nWinStyle); if (pRealParent != pParent) nWinStyle |= WB_BORDER; - xWindow = VclPtr<ListBox>::Create(pRealParent, nWinStyle); + if (m_bLegacy) + xWindow = VclPtr<ListBox>::Create(pRealParent, nWinStyle); + else + { + VclPtrInstance<SvTreeListBox> xBox(pRealParent, nWinStyle); + xBox->SetNoAutoCurEntry(true); + xWindow = xBox; + } if (pRealParent != pParent) cleanupWidgetOwnScrolling(pParent, xWindow, rMap); } @@ -3998,6 +4010,34 @@ void VclBuilder::mungeModel(ListBox &rTarget, const ListStore &rStore, sal_uInt1 rTarget.SelectEntryPos(nActiveId); } +void VclBuilder::mungeModel(SvTreeListBox &rTarget, const ListStore &rStore, sal_uInt16 nActiveId) +{ + for (auto const& entry : rStore.m_aEntries) + { + const ListStore::row &rRow = entry; + auto pEntry = rTarget.InsertEntry(rRow[0]); + if (rRow.size() > 1) + { + if (m_bLegacy) + { + sal_IntPtr nValue = rRow[1].toInt32(); + pEntry->SetUserData(reinterpret_cast<void*>(nValue)); + } + else + { + if (!rRow[1].isEmpty()) + pEntry->SetUserData(new OUString(rRow[1])); + } + } + } + if (nActiveId < rStore.m_aEntries.size()) + { + SvTreeListEntry* pEntry = rTarget.GetEntry(nullptr, nActiveId); + rTarget.Select(pEntry); + } +} + + void VclBuilder::mungeAdjustment(NumericFormatter &rTarget, const Adjustment &rAdjustment) { int nMul = rtl_math_pow10Exp(1, rTarget.GetDecimalDigits()); diff --git a/vcl/unx/gtk3/gtk3gtkinst.cxx b/vcl/unx/gtk3/gtk3gtkinst.cxx index c0768ddffc2e..3c3e5d25588f 100644 --- a/vcl/unx/gtk3/gtk3gtkinst.cxx +++ b/vcl/unx/gtk3/gtk3gtkinst.cxx @@ -5620,10 +5620,18 @@ private: gboolean ret; m_pTreeView->disable_notify_events(); GtkWidget* pWidget = m_pTreeView->getWidget(); - gtk_widget_grab_focus(pWidget); - g_signal_emit_by_name(pWidget, "key-press-event", pEvent, &ret); - m_xEntry->set_text(m_xTreeView->get_selected_text()); - gtk_widget_grab_focus(m_pEntry->getWidget()); + if (m_pTreeView->get_selected_index() == -1) + { + m_pTreeView->select(0); + m_xEntry->set_text(m_xTreeView->get_selected_text()); + } + else + { + gtk_widget_grab_focus(pWidget); + g_signal_emit_by_name(pWidget, "key-press-event", pEvent, &ret); + m_xEntry->set_text(m_xTreeView->get_selected_text()); + gtk_widget_grab_focus(m_pEntry->getWidget()); + } m_xEntry->select_region(0, -1); m_pTreeView->enable_notify_events(); m_pEntry->fire_signal_changed(); |