diff options
author | Caolán McNamara <caolanm@redhat.com> | 2020-02-07 16:00:49 +0000 |
---|---|---|
committer | Caolán McNamara <caolanm@redhat.com> | 2020-02-08 20:29:52 +0100 |
commit | 9d4f31de3e2cb25d94a47b29e3bea0133372c65d (patch) | |
tree | 7050ab3d331ba4a4ba1095adfb2021f77d441665 | |
parent | 15664830235fd3d34dc633affa87824e5c10cb79 (diff) |
weld LibBox and LanguageBox Item Windows
Change-Id: Ifdbef243093b588887c3d3fe1efcaf2e4c7c982a
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/88235
Tested-by: Jenkins
Reviewed-by: Caolán McNamara <caolanm@redhat.com>
-rw-r--r-- | basctl/UIConfig_basicide.mk | 1 | ||||
-rw-r--r-- | basctl/inc/pch/precompiled_basctl.hxx | 3 | ||||
-rw-r--r-- | basctl/source/basicide/IDEComboBox.cxx | 227 | ||||
-rw-r--r-- | basctl/source/inc/IDEComboBox.hxx | 30 | ||||
-rw-r--r-- | basctl/uiconfig/basicide/ui/combobox.ui | 23 |
5 files changed, 176 insertions, 108 deletions
diff --git a/basctl/UIConfig_basicide.mk b/basctl/UIConfig_basicide.mk index 97ced734236a..874c1cff4e9c 100644 --- a/basctl/UIConfig_basicide.mk +++ b/basctl/UIConfig_basicide.mk @@ -36,6 +36,7 @@ $(eval $(call gb_UIConfig_add_toolbarfiles,modules/BasicIDE,\ $(eval $(call gb_UIConfig_add_uifiles,modules/BasicIDE,\ basctl/uiconfig/basicide/ui/basicmacrodialog \ basctl/uiconfig/basicide/ui/breakpointmenus \ + basctl/uiconfig/basicide/ui/combobox \ basctl/uiconfig/basicide/ui/defaultlanguage \ basctl/uiconfig/basicide/ui/deletelangdialog \ basctl/uiconfig/basicide/ui/dialogpage \ diff --git a/basctl/inc/pch/precompiled_basctl.hxx b/basctl/inc/pch/precompiled_basctl.hxx index 8c25e3543e5a..64dc508a07c3 100644 --- a/basctl/inc/pch/precompiled_basctl.hxx +++ b/basctl/inc/pch/precompiled_basctl.hxx @@ -13,7 +13,7 @@ manual changes will be rewritten by the next run of update_pch.sh (which presumably also fixes all possible problems, so it's usually better to use it). - Generated on 2020-02-05 19:54:23 using: + Generated on 2020-02-07 17:31:33 using: ./bin/update_pch basctl basctl --cutoff=3 --exclude:system --include:module --exclude:local If after updating build fails, use the following command to locate conflicting headers: @@ -134,6 +134,7 @@ #include <vcl/jobset.hxx> #include <vcl/keycod.hxx> #include <vcl/keycodes.hxx> +#include <vcl/layout.hxx> #include <vcl/lstbox.hxx> #include <vcl/mapmod.hxx> #include <vcl/menu.hxx> diff --git a/basctl/source/basicide/IDEComboBox.cxx b/basctl/source/basicide/IDEComboBox.cxx index 93daa7771548..240eafb63d39 100644 --- a/basctl/source/basicide/IDEComboBox.cxx +++ b/basctl/source/basicide/IDEComboBox.cxx @@ -73,10 +73,10 @@ void LibBoxControl::StateChanged(sal_uInt16, SfxItemState eState, const SfxPoolI return; if (eState != SfxItemState::DEFAULT) - pBox->Disable(); + pBox->set_sensitive(false); else { - pBox->Enable(); + pBox->set_sensitive(true); pBox->Update(dynamic_cast<SfxStringItem const*>(pState)); } } @@ -87,17 +87,36 @@ VclPtr<vcl::Window> LibBoxControl::CreateItemWindow(vcl::Window* pParent) } DocListenerBox::DocListenerBox(vcl::Window* pParent) - : ListBox(pParent, WinBits(WB_BORDER | WB_DROPDOWN)) + : InterimItemWindow(pParent, "modules/BasicIDE/ui/combobox.ui", "ComboBox") + , m_xWidget(m_xBuilder->weld_combo_box("combobox")) , maNotifier(*this) { + m_xWidget->connect_changed(LINK(this, DocListenerBox, SelectHdl)); + m_xWidget->connect_key_press(LINK(this, DocListenerBox, KeyInputHdl)); } +void DocListenerBox::set_sensitive(bool bSensitive) +{ + Enable(bSensitive); + m_xWidget->set_sensitive(bSensitive); +} + +IMPL_LINK(DocListenerBox, KeyInputHdl, const KeyEvent&, rKEvt, bool) +{ + return HandleKeyInput(rKEvt); +} + +bool DocListenerBox::HandleKeyInput(const KeyEvent& rKEvt) { return ChildKeyInput(rKEvt); } + +IMPL_LINK_NOARG(DocListenerBox, SelectHdl, weld::ComboBox&, void) { Select(); } + DocListenerBox::~DocListenerBox() { disposeOnce(); } void DocListenerBox::dispose() { maNotifier.dispose(); - ListBox::dispose(); + m_xWidget.reset(); + InterimItemWindow::dispose(); } /// Only calls FillBox(). Parameter is not used. @@ -133,10 +152,14 @@ LibBox::LibBox(vcl::Window* pParent) FillBox(); mbIgnoreSelect = true; // do not yet transfer select of 0 mbFillBox = true; - SelectEntryPos(0); - maCurrentText = GetEntry(0); - SetSizePixel(Size(250, 200)); + m_xWidget->set_active(0); + maCurrentText = m_xWidget->get_text(0); mbIgnoreSelect = false; + + m_xWidget->connect_focus_in(LINK(this, LibBox, FocusInHdl)); + m_xWidget->connect_focus_out(LINK(this, LibBox, FocusOutHdl)); + + SetSizePixel(m_xWidget->get_preferred_size()); } LibBox::~LibBox() { disposeOnce(); } @@ -159,8 +182,8 @@ void LibBox::Update(const SfxStringItem* pItem) maCurrentText = IDEResId(RID_STR_ALL); } - if (GetSelectedEntry() != maCurrentText) - SelectEntry(maCurrentText); + if (m_xWidget->get_active_text() != maCurrentText) + m_xWidget->set_active_text(maCurrentText); } void LibBox::ReleaseFocus() @@ -180,18 +203,20 @@ void LibBox::ReleaseFocus() void LibBox::FillBox() { - SetUpdateMode(false); + m_xWidget->freeze(); mbIgnoreSelect = true; - maCurrentText = GetSelectedEntry(); + maCurrentText = m_xWidget->get_active_text(); - SelectEntryPos(0); + m_xWidget->set_active(0); ClearBox(); // create list box entries - sal_Int32 nPos = InsertEntry(IDEResId(RID_STR_ALL)); - SetEntryData(nPos, new LibEntry(ScriptDocument::getApplicationScriptDocument(), - LIBRARY_LOCATION_UNKNOWN, OUString())); + LibEntry* pEntry = new LibEntry(ScriptDocument::getApplicationScriptDocument(), + LIBRARY_LOCATION_UNKNOWN, OUString()); + OUString sId(OUString::number(reinterpret_cast<sal_Int64>(pEntry))); + m_xWidget->append(sId, IDEResId(RID_STR_ALL)); + InsertEntries(ScriptDocument::getApplicationScriptDocument(), LIBRARY_LOCATION_USER); InsertEntries(ScriptDocument::getApplicationScriptDocument(), LIBRARY_LOCATION_SHARE); @@ -202,14 +227,10 @@ void LibBox::FillBox() InsertEntries(doc, LIBRARY_LOCATION_DOCUMENT); } - SetUpdateMode(true); + m_xWidget->thaw(); - SelectEntry(maCurrentText); - if (!GetSelectedEntryCount()) - { - SelectEntryPos(GetEntryCount()); - maCurrentText = GetSelectedEntry(); - } + m_xWidget->set_active_text(maCurrentText); + maCurrentText = m_xWidget->get_active_text(); mbIgnoreSelect = false; } @@ -227,71 +248,71 @@ void LibBox::InsertEntries(const ScriptDocument& rDocument, LibraryLocation eLoc { OUString aName(rDocument.getTitle(eLocation)); OUString aEntryText(CreateMgrAndLibStr(aName, aLibName)); - sal_Int32 nPos = InsertEntry(aEntryText); - SetEntryData(nPos, new LibEntry(rDocument, eLocation, aLibName)); + LibEntry* pEntry = new LibEntry(rDocument, eLocation, aLibName); + m_xWidget->append(OUString::number(reinterpret_cast<sal_Int64>(pEntry)), aEntryText); } } } -bool LibBox::PreNotify(NotifyEvent& rNEvt) +bool LibBox::HandleKeyInput(const KeyEvent& rKEvt) { bool bDone = false; - if (rNEvt.GetType() == MouseNotifyEvent::KEYINPUT) + + sal_uInt16 nKeyCode = rKEvt.GetKeyCode().GetCode(); + switch (nKeyCode) { - KeyEvent aKeyEvt = *rNEvt.GetKeyEvent(); - sal_uInt16 nKeyCode = aKeyEvt.GetKeyCode().GetCode(); - switch (nKeyCode) + case KEY_RETURN: { - case KEY_RETURN: - { - NotifyIDE(); - bDone = true; - } - break; - case KEY_ESCAPE: - { - SelectEntry(maCurrentText); - ReleaseFocus(); - bDone = true; - } - break; + NotifyIDE(); + bDone = true; } - } - else if (rNEvt.GetType() == MouseNotifyEvent::GETFOCUS) - { - if (mbFillBox) + break; + case KEY_ESCAPE: { - FillBox(); - mbFillBox = false; + m_xWidget->set_active_text(maCurrentText); + ReleaseFocus(); + bDone = true; } + break; } - else if (rNEvt.GetType() == MouseNotifyEvent::LOSEFOCUS) + + return bDone || DocListenerBox::HandleKeyInput(rKEvt); +} + +IMPL_LINK_NOARG(LibBox, FocusInHdl, weld::Widget&, void) +{ + if (mbFillBox) { - if (!HasChildPathFocus(true)) - { - mbIgnoreSelect = true; - mbFillBox = true; - } + FillBox(); + mbFillBox = false; } +} - return bDone || ListBox::PreNotify(rNEvt); +IMPL_LINK_NOARG(LibBox, FocusOutHdl, weld::Widget&, void) +{ + if (!m_xWidget + ->has_focus()) // comboboxes can be comprised of multiple widgets, ensure all have lost focus + { + mbIgnoreSelect = true; + mbFillBox = true; + } } void LibBox::Select() { - if (!IsTravelSelect()) + if (m_xWidget->changed_by_menu()) { if (!mbIgnoreSelect) NotifyIDE(); else - SelectEntry(maCurrentText); // since 306... (Select after Escape) + m_xWidget->set_active_text(maCurrentText); // (Select after Escape) } } void LibBox::NotifyIDE() { - sal_Int32 nSelPos = GetSelectedEntryPos(); - if (LibEntry* pEntry = static_cast<LibEntry*>(GetEntryData(nSelPos))) + LibEntry* pEntry = reinterpret_cast<LibEntry*>(m_xWidget->get_active_id().toInt64()); + if (pEntry) { const ScriptDocument& aDocument(pEntry->GetDocument()); SfxUnoAnyItem aDocumentItem(SID_BASICIDE_ARG_DOCUMENT_MODEL, @@ -307,13 +328,13 @@ void LibBox::NotifyIDE() void LibBox::ClearBox() { - sal_Int32 nCount = GetEntryCount(); + sal_Int32 nCount = m_xWidget->get_count(); for (sal_Int32 i = 0; i < nCount; ++i) { - LibEntry* pEntry = static_cast<LibEntry*>(GetEntryData(i)); + LibEntry* pEntry = reinterpret_cast<LibEntry*>(m_xWidget->get_id(i).toInt64()); delete pEntry; } - ListBox::Clear(); + m_xWidget->clear(); } // class LanguageBoxControl ---------------------------------------------- @@ -346,10 +367,10 @@ void LanguageBoxControl::StateChanged(sal_uInt16, SfxItemState eState, const Sfx if (LanguageBox* pBox = static_cast<LanguageBox*>(GetToolBox().GetItemWindow(GetId()))) { if (eState != SfxItemState::DEFAULT) - pBox->Disable(); + pBox->set_sensitive(false); else { - pBox->Enable(); + pBox->set_sensitive(true); pBox->Update(dynamic_cast<SfxStringItem const*>(pItem)); } } @@ -367,8 +388,9 @@ LanguageBox::LanguageBox(vcl::Window* pParent) , msDefaultLanguageStr(IDEResId(RID_STR_TRANSLATION_DEFAULT)) , mbIgnoreSelect(false) { - SetSizePixel(Size(210, 200)); FillBox(); + + SetSizePixel(m_xWidget->get_preferred_size()); } LanguageBox::~LanguageBox() { disposeOnce(); } @@ -381,21 +403,21 @@ void LanguageBox::dispose() void LanguageBox::FillBox() { - SetUpdateMode(false); + m_xWidget->freeze(); mbIgnoreSelect = true; - msCurrentText = GetSelectedEntry(); + msCurrentText = m_xWidget->get_active_text(); ClearBox(); std::shared_ptr<LocalizationMgr> pCurMgr(GetShell()->GetCurLocalizationMgr()); if (pCurMgr->isLibraryLocalized()) { - Enable(); + set_sensitive(true); Locale aDefaultLocale = pCurMgr->getStringResourceManager()->getDefaultLocale(); Locale aCurrentLocale = pCurMgr->getStringResourceManager()->getCurrentLocale(); Sequence<Locale> aLocaleSeq = pCurMgr->getStringResourceManager()->getLocales(); const Locale* pLocale = aLocaleSeq.getConstArray(); sal_Int32 i, nCount = aLocaleSeq.getLength(); - sal_Int32 nSelPos = LISTBOX_ENTRY_NOTFOUND; + sal_Int32 nSelPos = -1; for (i = 0; i < nCount; ++i) { bool bIsDefault = localesAreEqual(aDefaultLocale, pLocale[i]); @@ -406,44 +428,45 @@ void LanguageBox::FillBox() { sLanguage += " " + msDefaultLanguageStr; } - sal_Int32 nPos = InsertEntry(sLanguage); - SetEntryData(nPos, new LanguageEntry(pLocale[i], bIsDefault)); + LanguageEntry* pEntry = new LanguageEntry(pLocale[i], bIsDefault); + OUString sId(OUString::number(reinterpret_cast<sal_Int64>(pEntry))); + m_xWidget->append(sId, sLanguage); if (bIsCurrent) - nSelPos = nPos; + nSelPos = i; } - if (nSelPos != LISTBOX_ENTRY_NOTFOUND) + if (nSelPos != -1) { - SelectEntryPos(nSelPos); - msCurrentText = GetSelectedEntry(); + m_xWidget->set_active(nSelPos); + msCurrentText = m_xWidget->get_active_text(); } } else { - InsertEntry(msNotLocalizedStr); - SelectEntryPos(0); - Disable(); + m_xWidget->append_text(msNotLocalizedStr); + m_xWidget->set_active(0); + set_sensitive(false); } - SetUpdateMode(true); + m_xWidget->thaw(); mbIgnoreSelect = false; } void LanguageBox::ClearBox() { - sal_Int32 nCount = GetEntryCount(); + sal_Int32 nCount = m_xWidget->get_count(); for (sal_Int32 i = 0; i < nCount; ++i) { - LanguageEntry* pEntry = static_cast<LanguageEntry*>(GetEntryData(i)); + LanguageEntry* pEntry = reinterpret_cast<LanguageEntry*>(m_xWidget->get_id(i).toInt64()); delete pEntry; } - ListBox::Clear(); + m_xWidget->clear(); } void LanguageBox::SetLanguage() { - LanguageEntry* pEntry = static_cast<LanguageEntry*>(GetSelectedEntryData()); + LanguageEntry* pEntry = reinterpret_cast<LanguageEntry*>(m_xWidget->get_active_id().toInt64()); if (pEntry) GetShell()->GetCurLocalizationMgr()->handleSetCurrentLocale(pEntry->m_aLocale); } @@ -453,33 +476,31 @@ void LanguageBox::Select() if (!mbIgnoreSelect) SetLanguage(); else - SelectEntry(msCurrentText); // Select after Escape + m_xWidget->set_active_text(msCurrentText); // Select after Escape } -bool LanguageBox::PreNotify(NotifyEvent& rNEvt) +bool LanguageBox::HandleKeyInput(const KeyEvent& rKEvt) { bool bDone = false; - if (rNEvt.GetType() == MouseNotifyEvent::KEYINPUT) + + sal_uInt16 nKeyCode = rKEvt.GetKeyCode().GetCode(); + switch (nKeyCode) { - sal_uInt16 nKeyCode = rNEvt.GetKeyEvent()->GetKeyCode().GetCode(); - switch (nKeyCode) + case KEY_RETURN: { - case KEY_RETURN: - { - SetLanguage(); - bDone = true; - } - break; - case KEY_ESCAPE: - { - SelectEntry(msCurrentText); - bDone = true; - } - break; + SetLanguage(); + bDone = true; + } + break; + case KEY_ESCAPE: + { + m_xWidget->set_active_text(msCurrentText); + bDone = true; } + break; } - return bDone || ListBox::PreNotify(rNEvt); + return bDone || DocListenerBox::HandleKeyInput(rKEvt); } void LanguageBox::Update(const SfxStringItem* pItem) @@ -489,8 +510,8 @@ void LanguageBox::Update(const SfxStringItem* pItem) if (pItem && !pItem->GetValue().isEmpty()) { msCurrentText = pItem->GetValue(); - if (GetSelectedEntry() != msCurrentText) - SelectEntry(msCurrentText); + if (m_xWidget->get_active_text() != msCurrentText) + m_xWidget->set_active_text(msCurrentText); } } diff --git a/basctl/source/inc/IDEComboBox.hxx b/basctl/source/inc/IDEComboBox.hxx index 5f09bfd8a212..02c0812e9ad0 100644 --- a/basctl/source/inc/IDEComboBox.hxx +++ b/basctl/source/inc/IDEComboBox.hxx @@ -22,7 +22,7 @@ #include <svl/stritem.hxx> #include <sfx2/tbxctrl.hxx> -#include <vcl/lstbox.hxx> +#include <sfx2/InterimItemWindow.hxx> #include "doceventnotifier.hxx" #include "scriptdocument.hxx" @@ -79,16 +79,28 @@ public: * Base class for ComboBoxes which need to update their content according * to the list of open documents. */ -class DocListenerBox : public ListBox, public DocumentEventListener +class DocListenerBox : public InterimItemWindow, public DocumentEventListener { +private: + DECL_LINK(SelectHdl, weld::ComboBox&, void); + DECL_LINK(KeyInputHdl, const KeyEvent&, bool); + protected: + std::unique_ptr<weld::ComboBox> m_xWidget; + /// @param pParent -- parent window DocListenerBox(vcl::Window* pParent); virtual ~DocListenerBox() override; virtual void dispose() override; + virtual void Select() = 0; virtual void FillBox() = 0; + virtual void GetFocus() override { m_xWidget->grab_focus(); } + + /// key strokes the ComboBox receives + virtual bool HandleKeyInput(const KeyEvent& rKEvt); + private: // DocumentEventListener virtual void onDocumentCreated(const ScriptDocument& _rDoc) override; @@ -102,6 +114,9 @@ private: virtual void onDocumentModeChanged(const ScriptDocument& _rDoc) override; DocumentEventNotifier maNotifier; + +public: + void set_sensitive(bool bSensitive); }; /*! @@ -135,7 +150,7 @@ protected: * @param rNEvt represents mouse event * @return a bool value: true if was handled, and false if there was nothing handled */ - virtual bool PreNotify(NotifyEvent& rNEvt) override; + //TODO virtual bool PreNotify(NotifyEvent& rNEvt) override; private: static void ReleaseFocus(); @@ -154,6 +169,11 @@ private: /// Fill up the combobox virtual void FillBox() override; + virtual bool HandleKeyInput(const KeyEvent& rKEvt) override; + + DECL_LINK(FocusInHdl, weld::Widget&, void); + DECL_LINK(FocusOutHdl, weld::Widget&, void); + OUString maCurrentText; bool mbIgnoreSelect; bool mbFillBox; ///< If true, when FillBox() is called @@ -229,13 +249,15 @@ protected: /// Called for setting language when user selects a language in ComboBox virtual void Select() override; + virtual bool HandleKeyInput(const KeyEvent& rKEvt) override; + /*! * Handle keystrokes and mouse * * @param rNEvt represents mouse event * @return a bool value: true if was handled, and false if there was nothing handled */ - virtual bool PreNotify(NotifyEvent& rNEvt) override; + //TODO virtual bool PreNotify(NotifyEvent& rNEvt) override; private: /// Delete all languages from ComboBox diff --git a/basctl/uiconfig/basicide/ui/combobox.ui b/basctl/uiconfig/basicide/ui/combobox.ui new file mode 100644 index 000000000000..8c3ed9ad2a35 --- /dev/null +++ b/basctl/uiconfig/basicide/ui/combobox.ui @@ -0,0 +1,23 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- Generated with glade 3.22.1 --> +<interface domain="basctl"> + <requires lib="gtk+" version="3.18"/> + <object class="GtkBox" id="ComboBox"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <property name="hexpand">True</property> + <property name="spacing">6</property> + <child> + <object class="GtkComboBoxText" id="combobox"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <property name="hexpand">True</property> + </object> + <packing> + <property name="expand">False</property> + <property name="fill">True</property> + <property name="position">0</property> + </packing> + </child> + </object> +</interface> |