Use vcl::WindowData instead of string for window state in more places
vcl::WindowData is used to manage/store various state information for windows. It can be (de)serialized to/from string. So far, both the weld::Window API to get/set window state as well as the SvtViewOptions API were based on the string representation. Switch those and various related places to using vcl::WindowData instead to use a stronger/more specific type than just OUString in various places across the code base. Do the string (de)serialization where necessary, but otherwise prefer to use vcl::WindowData directly. Calling weld::Window::set_window_state with a WindowData param that doesn't indicate that anything should be set (i.e. whose mask is vcl::WindowDataMask::NONE) should have no effect, so drop extra checks that were previously checking whether the string representation was empty and skipping the call to weld::Window::set_window_state in that case. No change in user-observable behavior intended or seen in a quick test. Change-Id: I5bc4caeb49d0ab2bbc4fa597a5ef19d86d3aac2c Reviewed-on: https://gerrit.libreoffice.org/c/core/+/208125 Tested-by: Jenkins Reviewed-by: Michael Weghorn <m.weghorn@posteo.de>
This commit is contained in:
@@ -46,7 +46,7 @@ OUString WindowStateHelper::GetFromWindow(vcl::Window* pWin)
|
||||
{
|
||||
vcl::WindowDataMask const nMask
|
||||
= vcl::WindowDataMask::All & ~vcl::WindowDataMask::Minimized;
|
||||
return static_cast<SystemWindow*>(pWin)->GetWindowState(nMask);
|
||||
return static_cast<SystemWindow*>(pWin)->GetWindowState(nMask).toStr();
|
||||
}
|
||||
|
||||
return {};
|
||||
|
||||
@@ -226,7 +226,7 @@ OUString PersistentWindowState::implst_getWindowStateFromWindow(const css::uno::
|
||||
if ( pWindow && pWindow->IsSystemWindow() )
|
||||
{
|
||||
vcl::WindowDataMask const nMask = vcl::WindowDataMask::All & ~vcl::WindowDataMask::Minimized;
|
||||
sWindowState = static_cast<SystemWindow*>(pWindow.get())->GetWindowState(nMask);
|
||||
sWindowState = static_cast<SystemWindow*>(pWindow.get())->GetWindowState(nMask).toStr();
|
||||
}
|
||||
// <- SOLAR SAFE ------------------------
|
||||
}
|
||||
@@ -264,9 +264,9 @@ void PersistentWindowState::implst_setWindowStateOnWindow(const css::uno::Refere
|
||||
if (pWorkWindow->IsMinimized())
|
||||
return;
|
||||
|
||||
OUString sOldWindowState = pSystemWindow->GetWindowState();
|
||||
if ( sOldWindowState != sWindowState )
|
||||
pSystemWindow->SetWindowState(sWindowState);
|
||||
vcl::WindowData aOldWindowState = pSystemWindow->GetWindowState();
|
||||
if (aOldWindowState.toStr() != sWindowState)
|
||||
pSystemWindow->SetWindowState(vcl::WindowData(sWindowState));
|
||||
// <- SOLAR SAFE ------------------------
|
||||
}
|
||||
|
||||
|
||||
@@ -1814,7 +1814,7 @@ void LoadEnv::impl_applyPersistentWindowState(const css::uno::Reference< css::aw
|
||||
return;
|
||||
|
||||
SystemWindow* pSystemWindow = static_cast<SystemWindow*>(pWindowCheck.get());
|
||||
pSystemWindow->SetWindowState(sWindowState);
|
||||
pSystemWindow->SetWindowState(vcl::WindowData(sWindowState));
|
||||
// <- SOLAR SAFE
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,6 +26,7 @@
|
||||
#include <sal/types.h>
|
||||
#include <o3tl/typed_flags_set.hxx>
|
||||
#include <vcl/window.hxx>
|
||||
#include <vcl/windowstate.hxx>
|
||||
|
||||
#include <comphelper/lok.hxx>
|
||||
|
||||
@@ -63,7 +64,7 @@ struct SAL_DLLPUBLIC_RTTI SfxChildWinInfo
|
||||
{
|
||||
OUString aExtraString;
|
||||
OUString aModule;
|
||||
OUString aWinState;
|
||||
vcl::WindowData aWinState;
|
||||
Point aPos;
|
||||
Size aSize;
|
||||
SfxChildWindowFlags nFlags;
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
#include <sal/types.h>
|
||||
#include <rtl/ustring.hxx>
|
||||
#include <svtools/svtdllapi.h>
|
||||
#include <vcl/windowstate.hxx>
|
||||
|
||||
namespace com::sun::star::beans { struct NamedValue; }
|
||||
namespace com::sun::star::container { class XNameAccess; }
|
||||
@@ -143,14 +144,12 @@ class SAL_WARN_UNUSED SVT_DLLPUBLIC SvtViewOptions final
|
||||
/*-****************************************************************************************************
|
||||
@short use it to set/get the window state of your view
|
||||
@descr These value describe position/size and some other states of a window.
|
||||
Use it with right vcl methods directly. Normally it's not necessary to
|
||||
parse given string!
|
||||
|
||||
@seealso vcl methods
|
||||
*//*-*****************************************************************************************************/
|
||||
|
||||
OUString GetWindowState( ) const;
|
||||
void SetWindowState( const OUString& sState );
|
||||
vcl::WindowData GetWindowState() const;
|
||||
void SetWindowState(const vcl::WindowData& rState);
|
||||
|
||||
/*-****************************************************************************************************
|
||||
@short use it to set/get the page number which was the last active one
|
||||
|
||||
@@ -160,8 +160,6 @@ protected:
|
||||
WindowType eType, const char* pIdleDebugName, bool transferableIdle = false);
|
||||
SAL_DLLPRIVATE void loadUI(vcl::Window* pParent, const OUString& rID, const OUString& rUIXMLDescription, const css::uno::Reference<css::frame::XFrame> &rFrame = css::uno::Reference<css::frame::XFrame>());
|
||||
|
||||
SAL_DLLPRIVATE void SetWindowState(const vcl::WindowData& rData);
|
||||
|
||||
virtual void settingOptimalLayoutSize(Window *pBox);
|
||||
|
||||
SAL_DLLPRIVATE void DoInitialLayout();
|
||||
@@ -200,8 +198,8 @@ public:
|
||||
SAL_DLLPRIVATE void SetMaxOutputSizePixel( const Size& rSize );
|
||||
SAL_DLLPRIVATE const Size& GetMaxOutputSizePixel() const;
|
||||
|
||||
void SetWindowState(std::u16string_view rStr);
|
||||
OUString GetWindowState(vcl::WindowDataMask nMask = vcl::WindowDataMask::All) const;
|
||||
void SetWindowState(const vcl::WindowData& rData);
|
||||
vcl::WindowData GetWindowState(vcl::WindowDataMask nMask = vcl::WindowDataMask::All) const;
|
||||
|
||||
void SetMenuBar(MenuBar* pMenuBar);
|
||||
MenuBar* GetMenuBar() const { return mpMenuBar; }
|
||||
|
||||
@@ -17,6 +17,7 @@ struct SystemEnvData;
|
||||
|
||||
namespace vcl
|
||||
{
|
||||
class WindowData;
|
||||
enum class WindowDataMask;
|
||||
}
|
||||
|
||||
@@ -41,8 +42,8 @@ public:
|
||||
virtual bool has_toplevel_focus() const = 0;
|
||||
virtual void present() = 0;
|
||||
|
||||
virtual void set_window_state(const OUString& rStr) = 0;
|
||||
virtual OUString get_window_state(vcl::WindowDataMask nMask) const = 0;
|
||||
virtual void set_window_state(const vcl::WindowData& rState) = 0;
|
||||
virtual vcl::WindowData get_window_state(vcl::WindowDataMask nMask) const = 0;
|
||||
|
||||
virtual css::uno::Reference<css::awt::XWindow> GetXWindow() = 0;
|
||||
|
||||
|
||||
@@ -46,8 +46,7 @@ ScSortDlg::~ScSortDlg()
|
||||
{
|
||||
// tdf#153852 - Make of sort dialog resizable (and remember size)
|
||||
SvtViewOptions aDlgOpt(EViewType::Dialog, u"SortDialog"_ustr);
|
||||
OUString sWindowState = m_xDialog->get_window_state(vcl::WindowDataMask::PosSize);
|
||||
aDlgOpt.SetWindowState(sWindowState);
|
||||
aDlgOpt.SetWindowState(m_xDialog->get_window_state(vcl::WindowDataMask::PosSize));
|
||||
}
|
||||
|
||||
ScSortWarningDlg::ScSortWarningDlg(weld::Window* pParent,
|
||||
|
||||
@@ -42,7 +42,7 @@ constexpr OUString USERITEM_NAME = u"UserItem"_ustr;
|
||||
class SfxModelessDialog_Impl : public SfxListener
|
||||
{
|
||||
public:
|
||||
OUString aWinState;
|
||||
vcl::WindowData aWinState;
|
||||
SfxChildWindow* pMgr;
|
||||
bool bClosing;
|
||||
void Notify( SfxBroadcaster& rBC, const SfxHint& rHint ) override;
|
||||
@@ -71,8 +71,6 @@ void SfxModelessDialogController::Initialize(SfxChildWinInfo const *pInfo)
|
||||
if (!pInfo)
|
||||
return;
|
||||
m_xImpl->aWinState = pInfo->aWinState;
|
||||
if (m_xImpl->aWinState.isEmpty())
|
||||
return;
|
||||
m_xDialog->set_window_state(m_xImpl->aWinState);
|
||||
}
|
||||
|
||||
|
||||
@@ -392,7 +392,7 @@ friend class SfxDockingWindow;
|
||||
sal_uInt16 nDockPos;
|
||||
bool bNewLine;
|
||||
bool bDockingPrevented;
|
||||
OUString aWinState;
|
||||
vcl::WindowData aWinState;
|
||||
|
||||
explicit SfxDockingWindow_Impl(SfxDockingWindow *pBase);
|
||||
SfxChildAlignment GetLastAlignment() const
|
||||
@@ -545,7 +545,7 @@ void SfxDockingWindow::ToggleFloatingMode()
|
||||
if (IsFloatingMode())
|
||||
{
|
||||
SetAlignment(SfxChildAlignment::NOALIGNMENT);
|
||||
if (!m_pImpl->aWinState.isEmpty())
|
||||
if (m_pImpl->aWinState.mask() != vcl::WindowDataMask::NONE)
|
||||
GetFloatingWindow()->SetWindowState(m_pImpl->aWinState);
|
||||
else
|
||||
GetFloatingWindow()->SetOutputSizePixel( GetFloatingSize() );
|
||||
@@ -915,7 +915,7 @@ void SfxDockingWindow::Initialize(SfxChildWinInfo *pInfo)
|
||||
SetFloatingMode( bFloatMode );
|
||||
if ( bFloatMode )
|
||||
{
|
||||
if (!m_pImpl->aWinState.isEmpty())
|
||||
if (m_pImpl->aWinState.mask() != vcl::WindowDataMask::NONE)
|
||||
GetFloatingWindow()->SetWindowState(m_pImpl->aWinState);
|
||||
else
|
||||
GetFloatingWindow()->SetOutputSizePixel( GetFloatingSize() );
|
||||
@@ -982,7 +982,7 @@ void SfxDockingWindow::Initialize_Impl()
|
||||
if ( pFloatWin )
|
||||
{
|
||||
// initialize floating window
|
||||
if (m_pImpl->aWinState.isEmpty())
|
||||
if (m_pImpl->aWinState.mask() == vcl::WindowDataMask::NONE)
|
||||
// window state never set before, get if from defaults
|
||||
m_pImpl->aWinState = pFloatWin->GetWindowState();
|
||||
|
||||
|
||||
@@ -62,7 +62,7 @@ SfxRecordingFloatWrapper_Impl::SfxRecordingFloatWrapper_Impl(vcl::Window* pParen
|
||||
vcl::WindowData aState;
|
||||
aState.setMask(vcl::WindowDataMask::Pos);
|
||||
aState.setPos(aPos);
|
||||
pDlg->set_window_state(aState.toStr());
|
||||
pDlg->set_window_state(aState);
|
||||
|
||||
pFloatDlg->Initialize(pInfo);
|
||||
}
|
||||
|
||||
@@ -137,7 +137,7 @@ void SvtViewOptions::Delete()
|
||||
|
||||
@seealso member m_sList
|
||||
*//*-*************************************************************************************************************/
|
||||
OUString SvtViewOptions::GetWindowState() const
|
||||
vcl::WindowData SvtViewOptions::GetWindowState() const
|
||||
{
|
||||
OUString sWindowState;
|
||||
try
|
||||
@@ -154,7 +154,7 @@ OUString SvtViewOptions::GetWindowState() const
|
||||
sWindowState.clear();
|
||||
}
|
||||
|
||||
return sWindowState;
|
||||
return vcl::WindowData(sWindowState);
|
||||
}
|
||||
|
||||
|
||||
@@ -170,8 +170,11 @@ OUString SvtViewOptions::GetWindowState() const
|
||||
@seealso baseclass ::utl::ConfigItem
|
||||
@seealso method Notify()
|
||||
*//*-*************************************************************************************************************/
|
||||
void SvtViewOptions::SetWindowState( const OUString& sState )
|
||||
|
||||
void SvtViewOptions::SetWindowState(const vcl::WindowData& rState)
|
||||
{
|
||||
const OUString sState = rState.toStr();
|
||||
|
||||
try
|
||||
{
|
||||
css::uno::Reference< css::beans::XPropertySet > xNode(
|
||||
|
||||
@@ -126,10 +126,7 @@ void SwFieldDlg::Close()
|
||||
|
||||
void SwFieldDlg::Initialize(SfxChildWinInfo const *pInfo)
|
||||
{
|
||||
OUString aWinState = pInfo->aWinState;
|
||||
if (aWinState.isEmpty())
|
||||
return;
|
||||
m_xDialog->set_window_state(aWinState);
|
||||
m_xDialog->set_window_state(pInfo->aWinState);
|
||||
}
|
||||
|
||||
SfxItemSet* SwFieldDlg::CreateInputItemSet(const OUString& rID)
|
||||
|
||||
@@ -454,8 +454,7 @@ SwInsertBookmarkDlg::~SwInsertBookmarkDlg()
|
||||
{
|
||||
// tdf#146261 - Remember size of bookmark dialog
|
||||
SvtViewOptions aDlgOpt(EViewType::Dialog, u"BookmarkDialog"_ustr);
|
||||
OUString sWindowState = m_xDialog->get_window_state(vcl::WindowDataMask::PosSize);
|
||||
aDlgOpt.SetWindowState(sWindowState);
|
||||
aDlgOpt.SetWindowState(m_xDialog->get_window_state(vcl::WindowDataMask::PosSize));
|
||||
}
|
||||
|
||||
IMPL_LINK(SwInsertBookmarkDlg, HeaderBarClick, int, nColumn, void)
|
||||
|
||||
@@ -57,7 +57,7 @@ SwSyncChildWin::SwSyncChildWin(vcl::Window* _pParent,
|
||||
vcl::WindowData aState;
|
||||
aState.setMask(vcl::WindowDataMask::Pos);
|
||||
aState.setPos(aPos);
|
||||
pDlg->set_window_state(aState.toStr());
|
||||
pDlg->set_window_state(aState);
|
||||
|
||||
pInfo->aPos = pDlg->get_position();
|
||||
pInfo->aSize = pDlg->get_size();
|
||||
|
||||
@@ -34,8 +34,8 @@ public:
|
||||
virtual bool has_toplevel_focus() const override;
|
||||
virtual void present() override;
|
||||
|
||||
virtual void set_window_state(const OUString& rStr) override;
|
||||
virtual OUString get_window_state(vcl::WindowDataMask eMask) const override;
|
||||
virtual void set_window_state(const vcl::WindowData& rState) override;
|
||||
virtual vcl::WindowData get_window_state(vcl::WindowDataMask eMask) const override;
|
||||
|
||||
virtual css::uno::Reference<css::awt::XWindow> GetXWindow() override;
|
||||
|
||||
|
||||
@@ -497,9 +497,9 @@ public:
|
||||
|
||||
virtual void present() override;
|
||||
|
||||
virtual void set_window_state(const OUString& rStr) override;
|
||||
virtual void set_window_state(const vcl::WindowData& rState) override;
|
||||
|
||||
virtual OUString get_window_state(vcl::WindowDataMask nMask) const override;
|
||||
virtual vcl::WindowData get_window_state(vcl::WindowDataMask nMask) const override;
|
||||
|
||||
virtual SystemEnvData get_system_data() const override;
|
||||
|
||||
|
||||
@@ -111,29 +111,28 @@ void QtInstanceWindow::present()
|
||||
});
|
||||
}
|
||||
|
||||
void QtInstanceWindow::set_window_state(const OUString& rStr)
|
||||
void QtInstanceWindow::set_window_state(const vcl::WindowData& rState)
|
||||
{
|
||||
SolarMutexGuard g;
|
||||
|
||||
const vcl::WindowData aData(rStr);
|
||||
const vcl::WindowDataMask eMask = aData.mask();
|
||||
const vcl::WindowDataMask eMask = rState.mask();
|
||||
|
||||
GetQtInstance().RunInMainThread([&] {
|
||||
QRect aGeometry = getQWidget()->geometry();
|
||||
if (eMask & vcl::WindowDataMask::X)
|
||||
aGeometry.setX(aData.x());
|
||||
aGeometry.setX(rState.x());
|
||||
if (eMask & vcl::WindowDataMask::Y)
|
||||
aGeometry.setY(aData.y());
|
||||
aGeometry.setY(rState.y());
|
||||
if (eMask & vcl::WindowDataMask::Width)
|
||||
aGeometry.setWidth(aData.width());
|
||||
aGeometry.setWidth(rState.width());
|
||||
if (eMask & vcl::WindowDataMask::Height)
|
||||
aGeometry.setHeight(aData.height());
|
||||
aGeometry.setHeight(rState.height());
|
||||
|
||||
getQWidget()->setGeometry(aGeometry);
|
||||
|
||||
if (eMask & vcl::WindowDataMask::State)
|
||||
{
|
||||
const vcl::WindowState eState = aData.state();
|
||||
const vcl::WindowState eState = rState.state();
|
||||
if (eState & vcl::WindowState::Normal)
|
||||
getQWidget()->showNormal();
|
||||
else if (eState & vcl::WindowState::Maximized)
|
||||
@@ -144,7 +143,7 @@ void QtInstanceWindow::set_window_state(const OUString& rStr)
|
||||
});
|
||||
}
|
||||
|
||||
OUString QtInstanceWindow::get_window_state(vcl::WindowDataMask eMask) const
|
||||
vcl::WindowData QtInstanceWindow::get_window_state(vcl::WindowDataMask eMask) const
|
||||
{
|
||||
SolarMutexGuard g;
|
||||
|
||||
@@ -172,7 +171,7 @@ OUString QtInstanceWindow::get_window_state(vcl::WindowDataMask eMask) const
|
||||
}
|
||||
});
|
||||
|
||||
return aData.toStr();
|
||||
return aData;
|
||||
}
|
||||
|
||||
css::uno::Reference<css::awt::XWindow> QtInstanceWindow::GetXWindow()
|
||||
|
||||
@@ -1600,14 +1600,14 @@ void SalInstanceWindow::present()
|
||||
m_xWindow->ToTop(ToTopFlags::RestoreWhenMin | ToTopFlags::ForegroundTask);
|
||||
}
|
||||
|
||||
void SalInstanceWindow::set_window_state(const OUString& rStr)
|
||||
void SalInstanceWindow::set_window_state(const vcl::WindowData& rState)
|
||||
{
|
||||
SystemWindow* pSysWin = dynamic_cast<SystemWindow*>(m_xWindow.get());
|
||||
assert(pSysWin);
|
||||
pSysWin->SetWindowState(rStr);
|
||||
pSysWin->SetWindowState(rState);
|
||||
}
|
||||
|
||||
OUString SalInstanceWindow::get_window_state(vcl::WindowDataMask nMask) const
|
||||
vcl::WindowData SalInstanceWindow::get_window_state(vcl::WindowDataMask nMask) const
|
||||
{
|
||||
SystemWindow* pSysWin = dynamic_cast<SystemWindow*>(m_xWindow.get());
|
||||
assert(pSysWin);
|
||||
|
||||
@@ -761,7 +761,7 @@ void PrintDialog::storeToSettings()
|
||||
mxTabCtrl->get_tab_label_text(mxTabCtrl->get_current_page_ident()), batch);
|
||||
|
||||
officecfg::VCL::VCLSettings::PrintDialog::WindowState::set(
|
||||
m_xDialog->get_window_state(vcl::WindowDataMask::All), batch );
|
||||
m_xDialog->get_window_state(vcl::WindowDataMask::All).toStr(), batch);
|
||||
|
||||
officecfg::VCL::VCLSettings::PrintDialog::Collate::set( mxCollateBox->get_active(), batch );
|
||||
|
||||
@@ -791,7 +791,7 @@ void PrintDialog::readFromSettings()
|
||||
// persistent window state
|
||||
aValue = officecfg::VCL::VCLSettings::PrintDialog::WindowState::get();
|
||||
if (!aValue.isEmpty())
|
||||
m_xDialog->set_window_state(aValue);
|
||||
m_xDialog->set_window_state(vcl::WindowData(aValue));
|
||||
|
||||
// collate
|
||||
mxCollateBox->set_sensitive( officecfg::VCL::VCLSettings::PrintDialog::Collate::isReadOnly() );
|
||||
|
||||
@@ -840,19 +840,12 @@ void SystemWindow::GetWindowState(vcl::WindowData& rData) const
|
||||
}
|
||||
}
|
||||
|
||||
void SystemWindow::SetWindowState(std::u16string_view rStr)
|
||||
{
|
||||
if (rStr.empty())
|
||||
return;
|
||||
SetWindowState(vcl::WindowData(rStr));
|
||||
}
|
||||
|
||||
OUString SystemWindow::GetWindowState(vcl::WindowDataMask nMask) const
|
||||
vcl::WindowData SystemWindow::GetWindowState(vcl::WindowDataMask nMask) const
|
||||
{
|
||||
vcl::WindowData aData;
|
||||
aData.setMask(nMask);
|
||||
GetWindowState(aData);
|
||||
return aData.toStr();
|
||||
return aData;
|
||||
}
|
||||
|
||||
void SystemWindow::SetMenuBar(MenuBar* pMenuBar)
|
||||
|
||||
@@ -6494,15 +6494,14 @@ public:
|
||||
gtk_window_present(m_pWindow);
|
||||
}
|
||||
|
||||
virtual void set_window_state(const OUString& rStr) override
|
||||
virtual void set_window_state(const vcl::WindowData& rState) override
|
||||
{
|
||||
const vcl::WindowData aData(rStr);
|
||||
const auto nMask = aData.mask();
|
||||
const auto nState = aData.state() & vcl::WindowState::SystemMask;
|
||||
const auto nMask = rState.mask();
|
||||
const auto nState = rState.state() & vcl::WindowState::SystemMask;
|
||||
|
||||
if ((nMask & vcl::WindowDataMask::Size) == vcl::WindowDataMask::Size)
|
||||
{
|
||||
gtk_window_set_default_size(m_pWindow, aData.width(), aData.height());
|
||||
gtk_window_set_default_size(m_pWindow, rState.width(), rState.height());
|
||||
}
|
||||
if (nMask & vcl::WindowDataMask::State)
|
||||
{
|
||||
@@ -6515,12 +6514,12 @@ public:
|
||||
#if !GTK_CHECK_VERSION(4, 0, 0)
|
||||
if (isPositioningAllowed() && ((nMask & vcl::WindowDataMask::Pos) == vcl::WindowDataMask::Pos))
|
||||
{
|
||||
gtk_window_move(m_pWindow, aData.x(), aData.y());
|
||||
gtk_window_move(m_pWindow, rState.x(), rState.y());
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
virtual OUString get_window_state(vcl::WindowDataMask nMask) const override
|
||||
virtual vcl::WindowData get_window_state(vcl::WindowDataMask nMask) const override
|
||||
{
|
||||
bool bPositioningAllowed = isPositioningAllowed();
|
||||
|
||||
@@ -6544,7 +6543,7 @@ public:
|
||||
if (nMask & vcl::WindowDataMask::Size)
|
||||
aData.setSize(get_size());
|
||||
|
||||
return aData.toStr();
|
||||
return aData;
|
||||
}
|
||||
|
||||
virtual void connect_container_focus_changed(const Link<Container&, void>& rLink) override
|
||||
|
||||
Reference in New Issue
Block a user