From 6a4c464b49dbfa2801818ead1b50bc9580824d00 Mon Sep 17 00:00:00 2001 From: Caolán McNamara Date: Mon, 19 Feb 2018 16:33:35 +0000 Subject: weld native message dialogs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit just the straight-forward MessageDialog cases first a) remove border_width from message dialog .ui so as to take the default border width b) retain 12 as default message dialog border for vcl widget case c) remove layour_style from message dialog button boxes so as to take the default mode (a no-op for vcl widget case) d) use gtk response ids (vcl builder will converts to vcl ones) Change-Id: I7de281093a1b64f92f71ca11e7cbba42bb658154 Reviewed-on: https://gerrit.libreoffice.org/50143 Reviewed-by: Caolán McNamara Tested-by: Caolán McNamara --- desktop/source/deployment/gui/dp_gui_dialog2.cxx | 60 +++++++++++----------- desktop/source/deployment/gui/dp_gui_dialog2.hxx | 4 +- .../deployment/gui/dp_gui_extensioncmdqueue.cxx | 34 ++++++------ desktop/source/deployment/gui/dp_gui_service.cxx | 9 ++-- 4 files changed, 56 insertions(+), 51 deletions(-) (limited to 'desktop/source/deployment') diff --git a/desktop/source/deployment/gui/dp_gui_dialog2.cxx b/desktop/source/deployment/gui/dp_gui_dialog2.cxx index f477e4245d31..9888958807b0 100644 --- a/desktop/source/deployment/gui/dp_gui_dialog2.cxx +++ b/desktop/source/deployment/gui/dp_gui_dialog2.cxx @@ -358,26 +358,24 @@ bool DialogHelper::IsSharedPkgMgr( const uno::Reference< deployment::XPackage > return xPackage->getRepositoryName() == SHARED_PACKAGE_MANAGER; } - bool DialogHelper::continueOnSharedExtension( const uno::Reference< deployment::XPackage > &xPackage, - vcl::Window *pParent, + weld::Widget* pParent, const char* pResID, bool &bHadWarning ) { if ( !bHadWarning && IsSharedPkgMgr( xPackage ) ) { const SolarMutexGuard guard; - ScopedVclPtrInstance aInfoBox(pParent, DpResId(pResID), - VclMessageType::Warning, VclButtonsType::OkCancel); + std::unique_ptr xBox(Application::CreateMessageDialog(pParent, + VclMessageType::Warning, VclButtonsType::OkCancel, DpResId(pResID))); bHadWarning = true; - return RET_OK == aInfoBox->Execute(); + return RET_OK == xBox->run(); } else return true; } - void DialogHelper::openWebBrowser( const OUString & sURL, const OUString &sTitle ) const { if ( sURL.isEmpty() ) // Nothing to do, when the URL is empty @@ -395,9 +393,10 @@ void DialogHelper::openWebBrowser( const OUString & sURL, const OUString &sTitle uno::Any exc( ::cppu::getCaughtException() ); OUString msg( ::comphelper::anyToString( exc ) ); const SolarMutexGuard guard; - ScopedVclPtrInstance< MessageDialog > aErrorBox(nullptr, msg); - aErrorBox->SetText( sTitle ); - aErrorBox->Execute(); + std::unique_ptr xErrorBox(Application::CreateMessageDialog(getFrameWeld(), + VclMessageType::Warning, VclButtonsType::Ok, msg)); + xErrorBox->set_title(sTitle); + xErrorBox->run(); } } @@ -409,30 +408,30 @@ bool DialogHelper::installExtensionWarn( const OUString &rExtensionName ) const // Check if extension installation is disabled in the expert configurations if (officecfg::Office::ExtensionManager::ExtensionSecurity::DisableExtensionInstallation::get()) { - ScopedVclPtrInstance aWarn(m_pVCLWindow, DpResId(RID_STR_WARNING_INSTALL_EXTENSION_DISABLED), - VclMessageType::Warning, VclButtonsType::Ok); - aWarn->Execute(); + std::unique_ptr xWarnBox(Application::CreateMessageDialog(getFrameWeld(), + VclMessageType::Warning, VclButtonsType::Ok, + DpResId(RID_STR_WARNING_INSTALL_EXTENSION_DISABLED))); + xWarnBox->run(); return false; } - ScopedVclPtrInstance aInfo(m_pVCLWindow, DpResId(RID_STR_WARNING_INSTALL_EXTENSION), - VclMessageType::Warning, VclButtonsType::OkCancel); - - OUString sText(aInfo->get_primary_text()); + std::unique_ptr xInfoBox(Application::CreateMessageDialog(getFrameWeld(), + VclMessageType::Warning, VclButtonsType::OkCancel, + DpResId(RID_STR_WARNING_INSTALL_EXTENSION))); + OUString sText(xInfoBox->get_primary_text()); sText = sText.replaceAll("%NAME", rExtensionName); - aInfo->set_primary_text(sText); + xInfoBox->set_primary_text(sText); - return ( RET_OK == aInfo->Execute() ); + return (RET_OK == xInfoBox->run()); } bool DialogHelper::installForAllUsers( bool &bInstallForAll ) const { const SolarMutexGuard guard; - ScopedVclPtrInstance aQuery(m_pVCLWindow, "InstallForAllDialog", - "desktop/ui/installforalldialog.ui"); - - short nRet = aQuery->Execute(); + std::unique_ptr xBuilder(Application::CreateBuilder(getFrameWeld(), "desktop/ui/installforalldialog.ui")); + std::unique_ptr xQuery(xBuilder->weld_message_dialog("InstallForAllDialog")); + short nRet = xQuery->run(); if (nRet == RET_CANCEL) return false; @@ -592,14 +591,15 @@ void ExtMgrDialog::checkEntries() bool ExtMgrDialog::removeExtensionWarn( const OUString &rExtensionName ) const { const SolarMutexGuard guard; - ScopedVclPtrInstance aInfo(const_cast(this), DpResId(RID_STR_WARNING_REMOVE_EXTENSION), - VclMessageType::Warning, VclButtonsType::OkCancel); + std::unique_ptr xInfoBox(Application::CreateMessageDialog(GetFrameWeld(), + VclMessageType::Warning, VclButtonsType::OkCancel, + DpResId(RID_STR_WARNING_REMOVE_EXTENSION))); - OUString sText(aInfo->get_primary_text()); + OUString sText(xInfoBox->get_primary_text()); sText = sText.replaceAll("%NAME", rExtensionName); - aInfo->set_primary_text(sText); + xInfoBox->set_primary_text(sText); - return ( RET_OK == aInfo->Execute() ); + return (RET_OK == xInfoBox->run()); } void ExtMgrDialog::enablePackage( const uno::Reference< deployment::XPackage > &xPackage, @@ -610,12 +610,12 @@ void ExtMgrDialog::enablePackage( const uno::Reference< deployment::XPackage > & if ( bEnable ) { - if ( ! continueOnSharedExtension( xPackage, this, RID_STR_WARNING_ENABLE_SHARED_EXTENSION, m_bEnableWarning ) ) + if (!continueOnSharedExtension(xPackage, GetFrameWeld(), RID_STR_WARNING_ENABLE_SHARED_EXTENSION, m_bEnableWarning)) return; } else { - if ( ! continueOnSharedExtension( xPackage, this, RID_STR_WARNING_DISABLE_SHARED_EXTENSION, m_bDisableWarning ) ) + if (!continueOnSharedExtension(xPackage, GetFrameWeld(), RID_STR_WARNING_DISABLE_SHARED_EXTENSION, m_bDisableWarning)) return; } @@ -634,7 +634,7 @@ void ExtMgrDialog::removePackage( const uno::Reference< deployment::XPackage > & return; } - if ( ! continueOnSharedExtension( xPackage, this, RID_STR_WARNING_REMOVE_SHARED_EXTENSION, m_bDeleteWarning ) ) + if (!continueOnSharedExtension(xPackage, GetFrameWeld(), RID_STR_WARNING_REMOVE_SHARED_EXTENSION, m_bDeleteWarning)) return; m_pManager->getCmdQueue()->removeExtension( xPackage ); diff --git a/desktop/source/deployment/gui/dp_gui_dialog2.hxx b/desktop/source/deployment/gui/dp_gui_dialog2.hxx index 29cf6b47722e..ed00106535e8 100644 --- a/desktop/source/deployment/gui/dp_gui_dialog2.hxx +++ b/desktop/source/deployment/gui/dp_gui_dialog2.hxx @@ -29,6 +29,7 @@ #include #include #include +#include #include @@ -68,6 +69,7 @@ public: void openWebBrowser( const OUString & sURL, const OUString & sTitle ) const; Dialog* getWindow() const { return m_pVCLWindow; }; + weld::Window* getFrameWeld() const { return m_pVCLWindow ? m_pVCLWindow->GetFrameWeld() : nullptr; } void PostUserEvent( const Link& rLink, void* pCaller ); void clearEventID() { m_nEventID = nullptr; } @@ -85,7 +87,7 @@ public: static bool IsSharedPkgMgr( const css::uno::Reference< css::deployment::XPackage > &); static bool continueOnSharedExtension( const css::uno::Reference< css::deployment::XPackage > &, - vcl::Window *pParent, + weld::Widget* pParent, const char* pResID, bool &bHadWarning ); diff --git a/desktop/source/deployment/gui/dp_gui_extensioncmdqueue.cxx b/desktop/source/deployment/gui/dp_gui_extensioncmdqueue.cxx index 84246cd046db..331acea1e170 100644 --- a/desktop/source/deployment/gui/dp_gui_extensioncmdqueue.cxx +++ b/desktop/source/deployment/gui/dp_gui_extensioncmdqueue.cxx @@ -62,7 +62,7 @@ #include #include #include -#include +#include #include #include "dp_gui.h" @@ -145,7 +145,7 @@ public: , m_nCurrentProgress(0) {} - Dialog * activeDialog() { return m_pDialogHelper ? m_pDialogHelper->getWindow() : nullptr; } + weld::Window* activeDialog() { return m_pDialogHelper ? m_pDialogHelper->getFrameWeld() : nullptr; } void startProgress(); void stopProgress(); @@ -421,12 +421,12 @@ void ProgressCmdEnv::handle( uno::Reference< task::XInteractionRequest > const & verExc.Deployed->getDisplayName(); { SolarMutexGuard guard; - ScopedVclPtrInstance box(m_pDialogHelper? m_pDialogHelper->getWindow() : nullptr, - DpResId(id), VclMessageType::Warning, VclButtonsType::OkCancel); + std::unique_ptr xBox(Application::CreateMessageDialog(m_pDialogHelper ? m_pDialogHelper->getFrameWeld() : nullptr, + VclMessageType::Warning, VclButtonsType::Ok, DpResId(id))); OUString s; if (bEqualNames) { - s = box->get_primary_text(); + s = xBox->get_primary_text(); } else if (!strcmp(id, RID_STR_WARNING_VERSION_EQUAL)) { @@ -447,8 +447,8 @@ void ProgressCmdEnv::handle( uno::Reference< task::XInteractionRequest > const & s = s.replaceAll("$OLDNAME", verExc.Deployed->getDisplayName()); s = s.replaceAll("$NEW", getVersion(verExc.NewVersion)); s = s.replaceAll("$DEPLOYED", getVersion(verExc.Deployed)); - box->set_primary_text(s); - approve = box->Execute() == RET_OK; + xBox->set_primary_text(s); + approve = xBox->run() == RET_OK; abort = !approve; } } @@ -476,8 +476,9 @@ void ProgressCmdEnv::handle( uno::Reference< task::XInteractionRequest > const & SolarMutexGuard guard; OUString sMsg(DpResId(RID_STR_UNSUPPORTED_PLATFORM)); sMsg = sMsg.replaceAll("%Name", platExc.package->getDisplayName()); - ScopedVclPtrInstance< MessageDialog > box(m_pDialogHelper? m_pDialogHelper->getWindow() : nullptr, sMsg); - box->Execute(); + std::unique_ptr xBox(Application::CreateMessageDialog(m_pDialogHelper ? m_pDialogHelper->getFrameWeld() : nullptr, + VclMessageType::Warning, VclButtonsType::Ok, sMsg)); + xBox->run(); approve = true; } @@ -539,8 +540,9 @@ void ProgressCmdEnv::update_( uno::Any const & rStatus ) text = ::comphelper::anyToString( rStatus ); // fallback const SolarMutexGuard aGuard; - ScopedVclPtrInstance< MessageDialog > aBox(m_pDialogHelper? m_pDialogHelper->getWindow() : nullptr, text); - aBox->Execute(); + std::unique_ptr xBox(Application::CreateMessageDialog(m_pDialogHelper ? m_pDialogHelper->getFrameWeld() : nullptr, + VclMessageType::Warning, VclButtonsType::Ok, text)); + xBox->run(); } ++m_nCurrentProgress; updateProgress(); @@ -781,11 +783,11 @@ void ExtensionCmdQueue::Thread::execute() msg = ::comphelper::anyToString(exc); const SolarMutexGuard guard; - ScopedVclPtr box( - VclPtr::Create(currentCmdEnv->activeDialog(), msg)); - if ( m_pDialogHelper ) - box->SetText( m_pDialogHelper->getWindow()->GetText() ); - box->Execute(); + std::unique_ptr xBox(Application::CreateMessageDialog(currentCmdEnv->activeDialog(), + VclMessageType::Warning, VclButtonsType::Ok, msg)); + if (m_pDialogHelper) + xBox->set_title(m_pDialogHelper->getWindow()->GetText()); + xBox->run(); //Continue with installation of the remaining extensions } { diff --git a/desktop/source/deployment/gui/dp_gui_service.cxx b/desktop/source/deployment/gui/dp_gui_service.cxx index c3d7638c00fa..1f93cdd49fb7 100644 --- a/desktop/source/deployment/gui/dp_gui_service.cxx +++ b/desktop/source/deployment/gui/dp_gui_service.cxx @@ -28,7 +28,7 @@ #include #include #include -#include +#include #include #include #include @@ -214,9 +214,10 @@ void ServiceImpl::startExecuteModal( catch (const Exception & exc) { if (bAppUp) { const SolarMutexGuard guard; - ScopedVclPtrInstance box( - Application::GetActiveTopWindow(), exc.Message); - box->Execute(); + vcl::Window* pWin = Application::GetActiveTopWindow(); + std::unique_ptr xBox(Application::CreateMessageDialog(pWin ? pWin->GetFrameWeld() : nullptr, + VclMessageType::Warning, VclButtonsType::Ok, exc.Message)); + xBox->run(); } throw; } -- cgit