From 05d4077b724f91fca736d3c3fd64f28e304d7172 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Caol=C3=A1n=20McNamara?= Date: Mon, 1 Sep 2014 07:17:09 +0100 Subject: [PATCH] rearrange matters to get FloatingWindows working loaded from .ui Change-Id: I099c810533c4590ee3182e1edf27e9038ed44f30 --- include/vcl/dialog.hxx | 5 +--- include/vcl/floatwin.hxx | 5 ++-- include/vcl/syswin.hxx | 11 +++++--- vcl/source/uipreviewer/previewer.cxx | 19 ++++++++----- vcl/source/window/builder.cxx | 41 ++++++++++++++++++++++++---- vcl/source/window/dialog.cxx | 19 ++++--------- vcl/source/window/floatwin.cxx | 20 +++++++++++++- vcl/source/window/syswin.cxx | 17 +++++------- 8 files changed, 91 insertions(+), 46 deletions(-) diff --git a/include/vcl/dialog.hxx b/include/vcl/dialog.hxx index 94ea7d66e680..804de4afd368 100644 --- a/include/vcl/dialog.hxx +++ b/include/vcl/dialog.hxx @@ -39,7 +39,6 @@ class VclButtonBox; class VCL_DLLPUBLIC Dialog : public SystemWindow { private: - Window* mpDialogParent; Dialog* mpPrevExecuteDlg; DialogImpl* mpDialogImpl; long mnMousePositioned; @@ -47,7 +46,6 @@ private: bool mbOldSaveBack; bool mbInClose; bool mbModalMode; - bool mbIsDefferedInit; VclButtonBox* mpActionArea; VclBox* mpContentArea; @@ -67,8 +65,7 @@ protected: public: SAL_DLLPRIVATE bool IsInClose() const { return mbInClose; } - SAL_DLLPRIVATE void doDeferredInit(bool bResizable); - SAL_DLLPRIVATE bool isDeferredInit() const { return mbIsDefferedInit; } + virtual void doDeferredInit(bool bResizable) SAL_OVERRIDE; protected: explicit Dialog( WindowType nType ); diff --git a/include/vcl/floatwin.hxx b/include/vcl/floatwin.hxx index 75dc561920a7..67626273c016 100644 --- a/include/vcl/floatwin.hxx +++ b/include/vcl/floatwin.hxx @@ -117,9 +117,10 @@ public: SAL_DLLPRIVATE void ImplEndPopupMode( sal_uInt16 nFlags = 0, sal_uLong nFocusId = 0 ); SAL_DLLPRIVATE Rectangle& ImplGetItemEdgeClipRect(); SAL_DLLPRIVATE bool ImplIsInPrivatePopupMode() const { return mbInPopupMode; } + virtual void doDeferredInit(bool bResizable) SAL_OVERRIDE; public: - explicit FloatingWindow( Window* pParent, WinBits nStyle = WB_STDFLOATWIN ); + explicit FloatingWindow(Window* pParent, WinBits nStyle = WB_STDFLOATWIN); explicit FloatingWindow(Window* pParent, const OString& rID, const OUString& rUIXMLDescription); explicit FloatingWindow( Window* pParent, const ResId& ); virtual ~FloatingWindow(); @@ -131,7 +132,7 @@ public: virtual void PopupModeEnd(); void SetTitleType( sal_uInt16 nTitle ); - sal_uInt16 GetTitleType() const { return mnTitle; } + sal_uInt16 GetTitleType() const { return mnTitle; } void StartPopupMode( const Rectangle& rRect, sal_uLong nFlags = 0 ); void StartPopupMode( ToolBox* pBox, sal_uLong nFlags = 0 ); diff --git a/include/vcl/syswin.hxx b/include/vcl/syswin.hxx index 033018b19ba2..168a0eb4a116 100644 --- a/include/vcl/syswin.hxx +++ b/include/vcl/syswin.hxx @@ -147,17 +147,19 @@ private: bool mbDockBtn; bool mbHideBtn; bool mbSysChild; - bool mbIsDefferedInit; bool mbIsCalculatingInitialLayoutSize; bool mbInitialLayoutDone; sal_uInt16 mnMenuBarMode; sal_uInt16 mnIcon; ImplData* mpImplData; Timer maLayoutTimer; - +protected: + bool mbIsDefferedInit; + Window* mpDialogParent; public: using Window::ImplIsInTaskPaneList; SAL_DLLPRIVATE bool ImplIsInTaskPaneList( Window* pWin ); + SAL_DLLPRIVATE bool isDeferredInit() const { return mbIsDefferedInit; } private: SAL_DLLPRIVATE void Init(); @@ -168,7 +170,7 @@ private: protected: // Single argument ctors shall be explicit. explicit SystemWindow(WindowType nType); - explicit SystemWindow(Window* pParent, const OString& rID, const OUString& rUIXMLDescription, WindowType nType); + void loadUI(Window* pParent, const OString& rID, const OUString& rUIXMLDescription); void SetWindowStateData( const WindowStateData& rData ); @@ -187,7 +189,6 @@ public: virtual void Resizing( Size& rSize ); virtual void Resize() SAL_OVERRIDE; virtual Size GetOptimalSize() const SAL_OVERRIDE; - virtual void StateChanged(StateChangedType nStateChange) SAL_OVERRIDE; virtual void queue_resize(StateChangedType eReason = STATE_CHANGE_LAYOUT) SAL_OVERRIDE; bool isLayoutEnabled() const; void setOptimalLayoutSize(); @@ -274,6 +275,8 @@ public: const Link& GetCloseHdl() const; SAL_DLLPRIVATE bool hasPendingLayout() const { return maLayoutTimer.IsActive(); } + + virtual void doDeferredInit(bool bResizable); }; #endif // INCLUDED_VCL_SYSWIN_HXX diff --git a/vcl/source/uipreviewer/previewer.cxx b/vcl/source/uipreviewer/previewer.cxx index 346f4d3ccc0b..80400595f40b 100644 --- a/vcl/source/uipreviewer/previewer.cxx +++ b/vcl/source/uipreviewer/previewer.cxx @@ -70,17 +70,22 @@ int UIPreviewApp::Main() { VclBuilder aBuilder(pDialog, OUString(), uifiles[0]); - Dialog *pRealDialog = dynamic_cast(aBuilder.get_widget_root()); + Window *pRoot = aBuilder.get_widget_root(); + Dialog *pRealDialog = dynamic_cast(pRoot); if (!pRealDialog) pRealDialog = pDialog; - if (pRealDialog) - { - pRealDialog->SetText(OUString("LibreOffice ui-previewer")); - pRealDialog->SetStyle(pDialog->GetStyle()|WB_CLOSEABLE); - pRealDialog->Execute(); - } + pRealDialog->SetText(OUString("LibreOffice ui-previewer")); + pRealDialog->SetStyle(pDialog->GetStyle()|WB_CLOSEABLE); + /* + Force a new STATE_CHANGE_INITSHOW for the edge case where pRoot + is not a dialog or contents of a dialog, but instead a visible floating window + which may have had initshow already done before it was given children + */ + pRoot->Hide(); + pRoot->Show(); + pRealDialog->Execute(); } delete pDialog; diff --git a/vcl/source/window/builder.cxx b/vcl/source/window/builder.cxx index 636e2278535a..3016ea67de54 100644 --- a/vcl/source/window/builder.cxx +++ b/vcl/source/window/builder.cxx @@ -176,7 +176,7 @@ VclBuilder::VclBuilder(Window *pParent, const OUString& sUIDir, const OUString& , m_pParserState(new ParserState) , m_xFrame(rFrame) { - m_bToplevelHasDeferredInit = pParent && pParent->IsDialog() && static_cast(pParent)->isDeferredInit(); + m_bToplevelHasDeferredInit = pParent && pParent->IsSystemWindow() && static_cast(pParent)->isDeferredInit(); m_bToplevelHasDeferredProperties = m_bToplevelHasDeferredInit; sal_Int32 nIdx = m_sHelpRoot.lastIndexOf('.'); @@ -571,6 +571,18 @@ OString VclBuilder::extractCustomProperty(VclBuilder::stringmap &rMap) namespace { + OString extractTypeHint(VclBuilder::stringmap &rMap) + { + OString sRet("normal"); + VclBuilder::stringmap::iterator aFind = rMap.find(OString("type-hint")); + if (aFind != rMap.end()) + { + sRet = aFind->second; + rMap.erase(aFind); + } + return sRet; + } + bool extractResizable(VclBuilder::stringmap &rMap) { bool bResizable = true; @@ -1571,6 +1583,21 @@ Window *VclBuilder::makeObject(Window *pParent, const OString &name, const OStri return NULL; // no widget to be created } } + else if (name == "GtkWindow") + { + WinBits nBits = WB_SYSTEMWINDOW|WB_MOVEABLE|WB_3DLOOK|WB_CLOSEABLE|WB_HIDE; + if (extractResizable(rMap)) + nBits |= WB_SIZEABLE; + OString sType(extractTypeHint(rMap)); + if (sType == "utility") + { + pWindow = new FloatingWindow(pParent, nBits); + } + else + { + SAL_WARN("vcl.layout", "no mapping yet for GtkWindow of type " << sType.getStr() << " yet"); + } + } else { sal_Int32 nDelim = name.indexOf('-'); @@ -1660,13 +1687,17 @@ Window *VclBuilder::insertObject(Window *pParent, const OString &rClass, if (m_pParent && !isConsideredGtkPseudo(m_pParent) && !m_sID.isEmpty() && rID.equals(m_sID)) { pCurrentChild = m_pParent; - //toplevels default to resizable - if (pCurrentChild->IsDialog()) + + //toplevels default to resizable and apparently you can't change them + //afterwards, so we need to wait until now before we can truly + //initialize the dialog. + if (pParent->IsSystemWindow()) { - Dialog *pDialog = static_cast(pCurrentChild); - pDialog->doDeferredInit(extractResizable(rProps)); + SystemWindow *pSysWin = static_cast(pCurrentChild); + pSysWin->doDeferredInit(extractResizable(rProps)); m_bToplevelHasDeferredInit = false; } + if (pCurrentChild->GetHelpId().isEmpty()) { pCurrentChild->SetHelpId(m_sHelpRoot + m_sID); diff --git a/vcl/source/window/dialog.cxx b/vcl/source/window/dialog.cxx index 1fa6f40c9994..d23d2af64f3e 100644 --- a/vcl/source/window/dialog.cxx +++ b/vcl/source/window/dialog.cxx @@ -339,7 +339,6 @@ struct DialogImpl void Dialog::ImplInitDialogData() { mpWindowImpl->mbDialog = true; - mpDialogParent = NULL; mpPrevExecuteDlg = NULL; mbInExecute = false; mbOldSaveBack = false; @@ -450,7 +449,6 @@ void Dialog::ImplInitSettings() Dialog::Dialog( WindowType nType ) : SystemWindow( nType ) - , mbIsDefferedInit(false) { ImplInitDialogData(); } @@ -491,26 +489,21 @@ void Dialog::doDeferredInit(bool bResizable) } Dialog::Dialog(Window* pParent, const OString& rID, const OUString& rUIXMLDescription) - : SystemWindow( WINDOW_DIALOG ) - , mbIsDefferedInit(true) + : SystemWindow(WINDOW_DIALOG) { ImplInitDialogData(); - mpDialogParent = pParent; //will be unset in doDeferredInit - m_pUIBuilder = new VclBuilder(this, getUIRootDir(), rUIXMLDescription, rID); + loadUI(pParent, rID, rUIXMLDescription); } Dialog::Dialog(Window* pParent, const OString& rID, const OUString& rUIXMLDescription, WindowType nType) - : SystemWindow( nType ) - , mbIsDefferedInit(true) + : SystemWindow(nType) { ImplInitDialogData(); - mpDialogParent = pParent; //will be unset in doDeferredInit - m_pUIBuilder = new VclBuilder(this, getUIRootDir(), rUIXMLDescription, rID); + loadUI(pParent, rID, rUIXMLDescription); } -Dialog::Dialog( Window* pParent, WinBits nStyle ) - : SystemWindow( WINDOW_DIALOG ) - , mbIsDefferedInit(false) +Dialog::Dialog(Window* pParent, WinBits nStyle) + : SystemWindow(WINDOW_DIALOG) { ImplInitDialogData(); ImplInit( pParent, nStyle ); diff --git a/vcl/source/window/floatwin.cxx b/vcl/source/window/floatwin.cxx index cda5def119c9..5b35585847a4 100644 --- a/vcl/source/window/floatwin.cxx +++ b/vcl/source/window/floatwin.cxx @@ -165,8 +165,21 @@ FloatingWindow::FloatingWindow( Window* pParent, const ResId& rResId ) : } FloatingWindow::FloatingWindow(Window* pParent, const OString& rID, const OUString& rUIXMLDescription) - : SystemWindow(pParent, rID, rUIXMLDescription, WINDOW_FLOATINGWINDOW) + : SystemWindow(WINDOW_FLOATINGWINDOW) { + loadUI(pParent, rID, rUIXMLDescription); +} + +//Find the real parent stashed in mpDialogParent. +void FloatingWindow::doDeferredInit(bool bResizable) +{ + WinBits nBits = WB_MOVEABLE|WB_3DLOOK; + if (bResizable) + nBits |= WB_SIZEABLE; + Window *pParent = mpDialogParent; + mpDialogParent = NULL; + ImplInit(pParent, nBits); + mbIsDefferedInit = false; } void FloatingWindow::ImplLoadRes( const ResId& rResId ) @@ -554,6 +567,11 @@ bool FloatingWindow::Notify( NotifyEvent& rNEvt ) void FloatingWindow::StateChanged( StateChangedType nType ) { + if (nType == STATE_CHANGE_INITSHOW) + { + DoInitialLayout(); + } + SystemWindow::StateChanged( nType ); if ( nType == STATE_CHANGE_CONTROLBACKGROUND ) diff --git a/vcl/source/window/syswin.cxx b/vcl/source/window/syswin.cxx index a3e6ef7b395e..db072cce083f 100644 --- a/vcl/source/window/syswin.cxx +++ b/vcl/source/window/syswin.cxx @@ -81,6 +81,7 @@ void SystemWindow::Init() mbInitialLayoutDone = false; mnMenuBarMode = MENUBAR_MODE_NORMAL; mnIcon = 0; + mpDialogParent = NULL; //To-Do, reuse maResizeTimer maLayoutTimer.SetTimeout(50); @@ -89,14 +90,15 @@ void SystemWindow::Init() SystemWindow::SystemWindow(WindowType nType) : Window(nType) + , mbIsDefferedInit(false) { Init(); } -SystemWindow::SystemWindow(Window* pParent, const OString& rID, const OUString& rUIXMLDescription, WindowType nType) - : Window(pParent, nType) +void SystemWindow::loadUI(Window* pParent, const OString& rID, const OUString& rUIXMLDescription) { - Init(); + mbIsDefferedInit = true; + mpDialogParent = pParent; //should be unset in doDeferredInit m_pUIBuilder = new VclBuilder(this, getUIRootDir(), rUIXMLDescription, rID); } @@ -1102,14 +1104,9 @@ void SystemWindow::DoInitialLayout() } } -void SystemWindow::StateChanged( StateChangedType nType ) +void SystemWindow::doDeferredInit(bool /*bResizable*/) { - Window::StateChanged(nType); - - if (nType == STATE_CHANGE_INITSHOW && !mbInitialLayoutDone) - { - DoInitialLayout(); - } + SAL_WARN("vcl.layout", "SystemWindow in layout without doDeferredInit impl"); } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */