summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCaolán McNamara <caolanm@redhat.com>2022-01-24 11:11:05 +0000
committerCaolán McNamara <caolanm@redhat.com>2022-01-24 15:56:59 +0100
commite2ff4206d60df486bf02931ce69c47857de6b04e (patch)
tree390da9ab99357d02d388952ad5feb91db731af51
parentf3d8750b07ff3ab89b27f0b1274b71de4924def6 (diff)
gtk4: adapt to window_[g|s]et_default_widget
Change-Id: I916e5db05f8ea10ecc8b319cc77a671ca7cbcb93 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/128859 Tested-by: Caolán McNamara <caolanm@redhat.com> Reviewed-by: Caolán McNamara <caolanm@redhat.com>
-rw-r--r--basctl/source/basicide/brkdlg.cxx6
-rw-r--r--cui/source/dialogs/hangulhanjadlg.cxx3
-rw-r--r--dbaccess/source/ui/dlg/paramdialog.cxx10
-rw-r--r--dbaccess/source/ui/misc/WCopyTable.cxx4
-rw-r--r--extensions/source/dbpilots/groupboxwiz.cxx14
-rw-r--r--include/vcl/weld.hxx11
-rw-r--r--vcl/inc/salvtables.hxx16
-rw-r--r--vcl/source/app/salvtables.cxx84
-rw-r--r--vcl/source/control/wizardmachine.cxx14
-rw-r--r--vcl/unx/gtk3/gtkinst.cxx84
10 files changed, 136 insertions, 110 deletions
diff --git a/basctl/source/basicide/brkdlg.cxx b/basctl/source/basicide/brkdlg.cxx
index 6a79d0e1da54..37ba1dbb60ae 100644
--- a/basctl/source/basicide/brkdlg.cxx
+++ b/basctl/source/basicide/brkdlg.cxx
@@ -125,16 +125,14 @@ void BreakPointDialog::CheckButtons()
m_xNewButton->set_sensitive(true);
m_xOKButton->set_sensitive(false);
m_xDelButton->set_sensitive(false);
- m_xDelButton->set_has_default(false);
- m_xNewButton->set_has_default(true);
+ m_xDialog->change_default_widget(m_xDelButton.get(), m_xNewButton.get());
}
else
{
m_xNewButton->set_sensitive(false);
m_xOKButton->set_sensitive(true);
m_xDelButton->set_sensitive(true);
- m_xNewButton->set_has_default(false);
- m_xDelButton->set_has_default(true);
+ m_xDialog->change_default_widget(m_xNewButton.get(), m_xDelButton.get());
}
}
diff --git a/cui/source/dialogs/hangulhanjadlg.cxx b/cui/source/dialogs/hangulhanjadlg.cxx
index cb1778329974..fb25df938e17 100644
--- a/cui/source/dialogs/hangulhanjadlg.cxx
+++ b/cui/source/dialogs/hangulhanjadlg.cxx
@@ -622,8 +622,7 @@ namespace svx
pNewDefButton = m_xFind.get();
}
- pOldDefButton->set_has_default(false);
- pNewDefButton->set_has_default(true);
+ m_xDialog->change_default_widget(pOldDefButton, pNewDefButton);
}
OUString HangulHanjaConversionDialog::GetCurrentSuggestion( ) const
diff --git a/dbaccess/source/ui/dlg/paramdialog.cxx b/dbaccess/source/ui/dlg/paramdialog.cxx
index 12f96d186f78..de3347682ed3 100644
--- a/dbaccess/source/ui/dlg/paramdialog.cxx
+++ b/dbaccess/source/ui/dlg/paramdialog.cxx
@@ -124,15 +124,10 @@ namespace dbaui
OnEntrySelected();
if (m_xAllParams->n_children() == 1)
- {
m_xTravelNext->set_sensitive(false);
- }
if (m_xAllParams->n_children() > 1)
- {
- m_xOKBtn->set_has_default(false);
- m_xTravelNext->set_has_default(true);
- }
+ m_xDialog->change_default_widget(m_xOKBtn.get(), m_xTravelNext.get());
}
m_xParam->grab_focus();
@@ -322,8 +317,7 @@ namespace dbaui
if (!bVisited)
{
// yes, there isn't another one -> change the "default button"
- m_xTravelNext->set_has_default(false);
- m_xOKBtn->set_has_default(true);
+ m_xDialog->change_default_widget(m_xTravelNext.get(), m_xOKBtn.get());
}
}
diff --git a/dbaccess/source/ui/misc/WCopyTable.cxx b/dbaccess/source/ui/misc/WCopyTable.cxx
index 03458111fc73..a4f04f1aa037 100644
--- a/dbaccess/source/ui/misc/WCopyTable.cxx
+++ b/dbaccess/source/ui/misc/WCopyTable.cxx
@@ -651,9 +651,9 @@ void OCopyTableWizard::construct()
if (!m_vDestColumns.empty())
// source is a html or rtf table
- m_xNextPage->set_has_default(true);
+ m_xAssistant->change_default_widget(nullptr, m_xNextPage.get());
else
- m_xFinish->set_has_default(true);
+ m_xAssistant->change_default_widget(nullptr, m_xFinish.get());
m_pTypeInfo = std::make_shared<OTypeInfo>();
m_pTypeInfo->aUIName = m_sTypeNames.getToken(TYPE_OTHER, ';');
diff --git a/extensions/source/dbpilots/groupboxwiz.cxx b/extensions/source/dbpilots/groupboxwiz.cxx
index ead0e4a4e48e..a093d9154b22 100644
--- a/extensions/source/dbpilots/groupboxwiz.cxx
+++ b/extensions/source/dbpilots/groupboxwiz.cxx
@@ -280,17 +280,21 @@ namespace dbp
m_xMoveLeft->set_sensitive(bSelectedSome);
m_xMoveRight->set_sensitive(bUnfinishedInput);
- getDialog()->enableButtons(WizardButtonFlags::NEXT, bHaveSome);
+ OControlWizard* pDialogController = getDialog();
+
+ pDialogController->enableButtons(WizardButtonFlags::NEXT, bHaveSome);
+
+ weld::Dialog* pDialog = pDialogController->getDialog();
if (bUnfinishedInput)
{
- if (!m_xMoveRight->get_has_default())
- getDialog()->defaultButton(m_xMoveRight.get());
+ if (!pDialog->is_default_widget(m_xMoveRight.get()))
+ pDialogController->defaultButton(m_xMoveRight.get());
}
else
{
- if (m_xMoveRight->get_has_default())
- getDialog()->defaultButton(WizardButtonFlags::NEXT);
+ if (pDialog->is_default_widget(m_xMoveRight.get()))
+ pDialogController->defaultButton(WizardButtonFlags::NEXT);
}
}
diff --git a/include/vcl/weld.hxx b/include/vcl/weld.hxx
index 40c2fbd86b49..af92c7640004 100644
--- a/include/vcl/weld.hxx
+++ b/include/vcl/weld.hxx
@@ -136,9 +136,6 @@ public:
// TODO: review if this has any practical difference from has_focus()
virtual bool is_active() const = 0;
- virtual void set_has_default(bool has_default) = 0;
- virtual bool get_has_default() const = 0;
-
/* size */
virtual void set_size_request(int nWidth, int nHeight) = 0;
virtual Size get_size_request() const = 0;
@@ -356,8 +353,6 @@ protected:
public:
// remove and add in one go
virtual void move(weld::Widget* pWidget, weld::Container* pNewParent) = 0;
- // recursively unset has-default on any buttons in the widget hierarchy
- virtual void recursively_unset_default_buttons() = 0;
// create an XWindow as a child of this container. The XWindow is
// suitable to contain css::awt::XControl items
virtual css::uno::Reference<css::awt::XWindow> CreateChildFrame() = 0;
@@ -535,6 +530,12 @@ public:
// desirable)
virtual bool has_toplevel_focus() const = 0;
virtual void present() = 0;
+
+ // with pOld of null, automatically find the old default widget and unset
+ // it, otherwise use as hint to the old default
+ virtual void change_default_widget(weld::Widget* pOld, weld::Widget* pNew) = 0;
+ virtual bool is_default_widget(const weld::Widget* pCandidate) const = 0;
+
virtual void set_window_state(const OString& rStr) = 0;
virtual OString get_window_state(WindowStateMask nMask) const = 0;
diff --git a/vcl/inc/salvtables.hxx b/vcl/inc/salvtables.hxx
index e21c9d48780e..b6573d2cf489 100644
--- a/vcl/inc/salvtables.hxx
+++ b/vcl/inc/salvtables.hxx
@@ -228,10 +228,6 @@ public:
virtual bool has_child_focus() const override;
- virtual void set_has_default(bool has_default) override;
-
- virtual bool get_has_default() const override;
-
virtual void show() override;
virtual void hide() override;
@@ -417,9 +413,6 @@ class SalInstanceContainer : public SalInstanceWidget, public virtual weld::Cont
protected:
VclPtr<vcl::Window> m_xContainer;
-private:
- void implResetDefault(const vcl::Window* _pWindow);
-
public:
SalInstanceContainer(vcl::Window* pContainer, SalInstanceBuilder* pBuilder,
bool bTakeOwnership);
@@ -427,7 +420,6 @@ public:
virtual void connect_container_focus_changed(const Link<Container&, void>& rLink) override;
virtual void child_grab_focus() override;
virtual void move(weld::Widget* pWidget, weld::Container* pNewParent) override;
- virtual void recursively_unset_default_buttons() override;
virtual css::uno::Reference<css::awt::XWindow> CreateChildFrame() override;
};
@@ -442,6 +434,10 @@ private:
void clear_child_help(vcl::Window* pParent);
+ void recursively_unset_default_buttons();
+
+ void implResetDefault(const vcl::Window* _pWindow);
+
public:
SalInstanceWindow(vcl::Window* pWindow, SalInstanceBuilder* pBuilder, bool bTakeOwnership);
@@ -475,6 +471,10 @@ public:
virtual void present() override;
+ virtual void change_default_widget(weld::Widget* pOld, weld::Widget* pNew) override;
+
+ virtual bool is_default_widget(const weld::Widget* pCandidate) const override;
+
virtual void set_window_state(const OString& rStr) override;
virtual OString get_window_state(WindowStateMask nMask) const override;
diff --git a/vcl/source/app/salvtables.cxx b/vcl/source/app/salvtables.cxx
index bfcd6834caac..7f33f6e7973b 100644
--- a/vcl/source/app/salvtables.cxx
+++ b/vcl/source/app/salvtables.cxx
@@ -304,13 +304,6 @@ bool SalInstanceWidget::is_active() const { return m_xWidget->IsActive(); }
bool SalInstanceWidget::has_child_focus() const { return m_xWidget->HasChildPathFocus(true); }
-void SalInstanceWidget::set_has_default(bool has_default)
-{
- m_xWidget->set_property("has-default", OUString::boolean(has_default));
-}
-
-bool SalInstanceWidget::get_has_default() const { return m_xWidget->GetStyle() & WB_DEFBUTTON; }
-
void SalInstanceWidget::show() { m_xWidget->Show(); }
void SalInstanceWidget::hide() { m_xWidget->Hide(); }
@@ -1179,30 +1172,6 @@ public:
};
}
-void SalInstanceContainer::implResetDefault(const vcl::Window* _pWindow)
-{
- vcl::Window* pChildLoop = _pWindow->GetWindow(GetWindowType::FirstChild);
- while (pChildLoop)
- {
- // does the window participate in the tabbing order?
- if (pChildLoop->GetStyle() & WB_DIALOGCONTROL)
- implResetDefault(pChildLoop);
-
- // is it a button?
- WindowType eType = pChildLoop->GetType();
- if ((WindowType::PUSHBUTTON == eType) || (WindowType::OKBUTTON == eType)
- || (WindowType::CANCELBUTTON == eType) || (WindowType::HELPBUTTON == eType)
- || (WindowType::IMAGEBUTTON == eType) || (WindowType::MENUBUTTON == eType)
- || (WindowType::MOREBUTTON == eType))
- {
- pChildLoop->SetStyle(pChildLoop->GetStyle() & ~WB_DEFBUTTON);
- }
-
- // the next one ...
- pChildLoop = pChildLoop->GetWindow(GetWindowType::Next);
- }
-}
-
void SalInstanceContainer::connect_container_focus_changed(const Link<Container&, void>& rLink)
{
ensure_event_listener();
@@ -1250,11 +1219,6 @@ void SalInstanceContainer::child_grab_focus()
pFirstChild->ImplControlFocus();
}
-void SalInstanceContainer::recursively_unset_default_buttons()
-{
- implResetDefault(m_xContainer.get());
-}
-
css::uno::Reference<css::awt::XWindow> SalInstanceContainer::CreateChildFrame()
{
auto xPage = VclPtr<VclBin>::Create(m_xContainer.get());
@@ -1514,6 +1478,54 @@ void SalInstanceWindow::present()
m_xWindow->ToTop(ToTopFlags::RestoreWhenMin | ToTopFlags::ForegroundTask);
}
+void SalInstanceWindow::implResetDefault(const vcl::Window* _pWindow)
+{
+ vcl::Window* pChildLoop = _pWindow->GetWindow(GetWindowType::FirstChild);
+ while (pChildLoop)
+ {
+ // does the window participate in the tabbing order?
+ if (pChildLoop->GetStyle() & WB_DIALOGCONTROL)
+ implResetDefault(pChildLoop);
+
+ // is it a button?
+ WindowType eType = pChildLoop->GetType();
+ if ((WindowType::PUSHBUTTON == eType) || (WindowType::OKBUTTON == eType)
+ || (WindowType::CANCELBUTTON == eType) || (WindowType::HELPBUTTON == eType)
+ || (WindowType::IMAGEBUTTON == eType) || (WindowType::MENUBUTTON == eType)
+ || (WindowType::MOREBUTTON == eType))
+ {
+ pChildLoop->SetStyle(pChildLoop->GetStyle() & ~WB_DEFBUTTON);
+ }
+
+ // the next one ...
+ pChildLoop = pChildLoop->GetWindow(GetWindowType::Next);
+ }
+}
+
+void SalInstanceWindow::recursively_unset_default_buttons() { implResetDefault(m_xWindow.get()); }
+
+void SalInstanceWindow::change_default_widget(weld::Widget* pOld, weld::Widget* pNew)
+{
+ if (!pOld)
+ recursively_unset_default_buttons();
+ else
+ {
+ SalInstanceWidget* pVclOld = dynamic_cast<SalInstanceWidget*>(pOld);
+ pVclOld->getWidget()->set_property("has-default", OUString::boolean(false));
+ }
+ if (pNew)
+ {
+ SalInstanceWidget* pVclNew = dynamic_cast<SalInstanceWidget*>(pNew);
+ pVclNew->getWidget()->set_property("has-default", OUString::boolean(true));
+ }
+}
+
+bool SalInstanceWindow::is_default_widget(const weld::Widget* pCandidate) const
+{
+ const SalInstanceWidget* pVclCandidate = dynamic_cast<const SalInstanceWidget*>(pCandidate);
+ return pVclCandidate->getWidget()->GetStyle() & WB_DEFBUTTON;
+}
+
void SalInstanceWindow::set_window_state(const OString& rStr)
{
SystemWindow* pSysWin = dynamic_cast<SystemWindow*>(m_xWindow.get());
diff --git a/vcl/source/control/wizardmachine.cxx b/vcl/source/control/wizardmachine.cxx
index 59d2514fbbce..e2ed41ff0de7 100644
--- a/vcl/source/control/wizardmachine.cxx
+++ b/vcl/source/control/wizardmachine.cxx
@@ -949,21 +949,15 @@ namespace vcl
if (_nWizardButtonFlags & WizardButtonFlags::CANCEL)
pNewDefButton = m_xCancel.get();
- if ( pNewDefButton )
- defaultButton( pNewDefButton );
- else
- m_xAssistant->recursively_unset_default_buttons();
+ defaultButton(pNewDefButton);
}
void WizardMachine::defaultButton(weld::Button* _pNewDefButton)
{
// loop through all (direct and indirect) descendants which participate in our tabbing order, and
- // reset the WB_DEFBUTTON for every window which is a button
- m_xAssistant->recursively_unset_default_buttons();
-
- // set its new style
- if (_pNewDefButton)
- _pNewDefButton->set_has_default(true);
+ // reset the WB_DEFBUTTON for every window which is a button and set _pNewDefButton as the new
+ // WB_DEFBUTTON
+ m_xAssistant->change_default_widget(nullptr, _pNewDefButton);
}
void WizardMachine::enableButtons(WizardButtonFlags _nWizardButtonFlags, bool _bEnable)
diff --git a/vcl/unx/gtk3/gtkinst.cxx b/vcl/unx/gtk3/gtkinst.cxx
index 39ebfb67bb38..ebc162dfcf65 100644
--- a/vcl/unx/gtk3/gtkinst.cxx
+++ b/vcl/unx/gtk3/gtkinst.cxx
@@ -3510,18 +3510,6 @@ public:
return false;
}
- virtual void set_has_default(bool has_default) override
- {
- g_object_set(G_OBJECT(m_pWidget), "has-default", has_default, nullptr);
- }
-
- virtual bool get_has_default() const override
- {
- gboolean has_default(false);
- g_object_get(G_OBJECT(m_pWidget), "has-default", &has_default, nullptr);
- return has_default;
- }
-
virtual void show() override
{
gtk_widget_show(m_pWidget);
@@ -3876,7 +3864,7 @@ public:
return m_pWidget;
}
- GtkWindow* getWindow()
+ GtkWindow* getWindow() const
{
return GTK_WINDOW(widget_get_toplevel(m_pWidget));
}
@@ -5692,18 +5680,6 @@ private:
gulong m_nSetFocusChildSignalId;
bool m_bChildHasFocus;
- static void implResetDefault(GtkWidget *pWidget, gpointer user_data)
- {
- if (GTK_IS_BUTTON(pWidget))
- g_object_set(G_OBJECT(pWidget), "has-default", false, nullptr);
-#if !GTK_CHECK_VERSION(4, 0, 0)
- if (GTK_IS_CONTAINER(pWidget))
- gtk_container_forall(GTK_CONTAINER(pWidget), implResetDefault, user_data);
-#else
- (void)user_data;
-#endif
- }
-
void signal_set_focus_child(bool bChildHasFocus)
{
if (m_bChildHasFocus != bChildHasFocus)
@@ -5807,11 +5783,6 @@ public:
g_object_unref(pChild);
}
- virtual void recursively_unset_default_buttons() override
- {
- implResetDefault(GTK_WIDGET(m_pContainer), nullptr);
- }
-
virtual css::uno::Reference<css::awt::XWindow> CreateChildFrame() override
{
// This will cause a GtkSalFrame to be created. With WB_SYSTEMCHILDWINDOW set it
@@ -6034,6 +6005,21 @@ private:
gulong m_nToplevelFocusChangedSignalId;
#if !GTK_CHECK_VERSION(4, 0, 0)
+ static void implResetDefault(GtkWidget *pWidget, gpointer user_data)
+ {
+ if (GTK_IS_BUTTON(pWidget))
+ g_object_set(G_OBJECT(pWidget), "has-default", false, nullptr);
+ if (GTK_IS_CONTAINER(pWidget))
+ gtk_container_forall(GTK_CONTAINER(pWidget), implResetDefault, user_data);
+ }
+
+ void recursively_unset_default_buttons()
+ {
+ implResetDefault(GTK_WIDGET(m_pWindow), nullptr);
+ }
+#endif
+
+#if !GTK_CHECK_VERSION(4, 0, 0)
static gboolean help_pressed(GtkAccelGroup*, GObject*, guint, GdkModifierType, gpointer widget)
{
GtkInstanceWindow* pThis = static_cast<GtkInstanceWindow*>(widget);
@@ -6191,6 +6177,44 @@ public:
gtk_window_present(m_pWindow);
}
+ virtual void change_default_widget(weld::Widget* pOld, weld::Widget* pNew) override
+ {
+#if GTK_CHECK_VERSION(4, 0, 0)
+ GtkInstanceWidget* pGtkNew = dynamic_cast<GtkInstanceWidget*>(pNew);
+ GtkWidget* pWidgetNew = pGtkNew ? pGtkNew->getWidget() : nullptr;
+ gtk_window_set_default_widget(m_pWindow, pWidgetNew);
+ (void)pOld;
+#else
+ if (!pOld)
+ recursively_unset_default_buttons();
+ else
+ {
+ GtkInstanceWidget* pGtkOld = dynamic_cast<GtkInstanceWidget*>(pOld);
+ GtkWidget* pWidgetOld = pGtkOld->getWidget();
+ g_object_set(G_OBJECT(pWidgetOld), "has-default", false, nullptr);
+ }
+ if (pNew)
+ {
+ GtkInstanceWidget* pGtkNew = dynamic_cast<GtkInstanceWidget*>(pNew);
+ GtkWidget* pWidgetNew = pGtkNew->getWidget();
+ g_object_set(G_OBJECT(pWidgetNew), "has-default", true, nullptr);
+ }
+#endif
+ }
+
+ virtual bool is_default_widget(const weld::Widget* pCandidate) const override
+ {
+ const GtkInstanceWidget* pGtkCandidate = dynamic_cast<const GtkInstanceWidget*>(pCandidate);
+ GtkWidget* pWidget = pGtkCandidate->getWidget();
+#if GTK_CHECK_VERSION(4, 0, 0)
+ return gtk_window_get_default_widget(m_pWindow) == pWidget;
+#else
+ gboolean has_default(false);
+ g_object_get(G_OBJECT(pWidget), "has-default", &has_default, nullptr);
+ return has_default;
+#endif
+ }
+
virtual void set_window_state(const OString& rStr) override
{
WindowStateData aData;