tdf#149529 crash on deref deleted ScDocument*
[LibreOffice.git] / include / vcl / syswin.hxx
blob0c35073aec09798e9707c29c81ba3e9854ff082f
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #pragma once
22 #include <vcl/dllapi.h>
23 #include <vcl/idle.hxx>
24 #include <vcl/vclenum.hxx>
25 #include <vcl/window.hxx>
26 #include <vcl/windowstate.hxx>
27 #include <com/sun/star/frame/XFrame.hpp>
28 #include <memory>
30 class SalInstanceBuilder;
31 class ScreenshotTest;
32 class MenuBar;
33 class MnemonicGenerator;
34 class NotebookBar;
35 class TaskPaneList;
36 class VclBuilder;
37 struct NotebookBarAddonsItem;
39 #define ICON_LO_DEFAULT 1
40 #define ICON_TEXT_DOCUMENT 2
41 #define ICON_SPREADSHEET_DOCUMENT 4
42 #define ICON_DRAWING_DOCUMENT 6
43 #define ICON_PRESENTATION_DOCUMENT 8
44 #define ICON_TEMPLATE 11
45 #define ICON_DATABASE_DOCUMENT 12
46 #define ICON_MATH_DOCUMENT 13
47 #define ICON_MACROLIBRARY 1
49 enum class MenuBarMode
51 Normal, Hide
54 enum class TitleButton
56 Docking = 1,
57 Hide = 2,
58 Menu = 4,
61 //helper baseclass to ease retro fitting dialogs/tabpages that load a resource
62 //to load a .ui file instead
64 //vcl requires the Window Children of a Parent Window to be destroyed before
65 //the Parent Window. VclBuilderContainer owns the VclBuilder which owns the
66 //Children Window. So the VclBuilderContainer dtor must be called before
67 //the Parent Window dtor.
69 //i.e. class Dialog : public SystemWindow, public VclBuilderContainer
70 //not class Dialog : public VclBuilderContainer, public SystemWindow
72 //With the new 'dispose' framework, it is necessary to force the builder
73 //dispose before the Window dispose; so a Dialog::dispose() method would
74 //finish: disposeBuilder(); SystemWindow::dispose() to capture this ordering.
76 class VCL_DLLPUBLIC VclBuilderContainer
78 public:
79 VclBuilderContainer();
80 virtual ~VclBuilderContainer();
81 void disposeBuilder();
83 void setDeferredProperties();
85 protected:
86 std::unique_ptr<VclBuilder> m_pUIBuilder;
88 friend class ::SalInstanceBuilder;
89 friend class ::ScreenshotTest;
92 class VCL_DLLPUBLIC SystemWindow
93 : public vcl::Window
94 , public VclBuilderContainer
96 friend class WorkWindow;
97 class ImplData;
99 private:
100 VclPtr<MenuBar> mpMenuBar;
101 Size maMinOutSize;
102 bool mbDockBtn;
103 bool mbHideBtn;
104 bool mbSysChild;
105 bool mbIsCalculatingInitialLayoutSize;
106 bool mbPaintComplete;
107 MenuBarMode mnMenuBarMode;
108 sal_uInt16 mnIcon;
109 std::unique_ptr<ImplData> mpImplData;
110 Idle maLayoutIdle;
111 OUString maNotebookBarUIFile;
112 protected:
113 bool mbIsDeferredInit;
114 VclPtr<vcl::Window> mpDialogParent;
115 public:
116 using Window::ImplIsInTaskPaneList;
117 SAL_DLLPRIVATE bool ImplIsInTaskPaneList( vcl::Window* pWin );
118 SAL_DLLPRIVATE bool isDeferredInit() const { return mbIsDeferredInit; }
120 private:
121 SAL_DLLPRIVATE void ImplMoveToScreen( tools::Long& io_rX, tools::Long& io_rY, tools::Long i_nWidth, tools::Long i_nHeight, vcl::Window const * i_pConfigureWin );
122 SAL_DLLPRIVATE void setPosSizeOnContainee(Size aSize, Window &rBox);
123 DECL_DLLPRIVATE_LINK( ImplHandleLayoutTimerHdl, Timer*, void );
125 // try to extract content and return as Bitmap. To do that reliably, a Yield-loop
126 // like in Execute() has to be executed and it is necessary to detect when the
127 // paint is finished
128 virtual void PrePaint(vcl::RenderContext& rRenderContext) override;
129 virtual void PostPaint(vcl::RenderContext& rRenderContext) override;
131 // ensureRepaint - triggers Application::Yield until the dialog is
132 // completely repainted. Sometimes needed for dialogs showing progress
133 // during actions
134 SAL_DLLPRIVATE void ensureRepaint();
136 protected:
137 // Single argument ctors shall be explicit.
138 explicit SystemWindow(WindowType nType, const char* pIdleDebugName);
139 void loadUI(vcl::Window* pParent, const OString& rID, const OUString& rUIXMLDescription, const css::uno::Reference<css::frame::XFrame> &rFrame = css::uno::Reference<css::frame::XFrame>());
141 void SetWindowStateData( const WindowStateData& rData );
143 virtual void settingOptimalLayoutSize(Window *pBox);
145 SAL_DLLPRIVATE void DoInitialLayout();
147 public:
148 virtual ~SystemWindow() override;
149 virtual void dispose() override;
151 virtual bool EventNotify( NotifyEvent& rNEvt ) override;
152 virtual bool PreNotify( NotifyEvent& rNEvt ) override;
154 virtual bool Close();
155 virtual void TitleButtonClick( TitleButton nButton );
156 virtual void Resizing( Size& rSize );
157 virtual void Resize() override;
158 virtual Size GetOptimalSize() const override;
159 virtual void queue_resize(StateChangedType eReason = StateChangedType::Layout) override;
160 bool isLayoutEnabled() const;
161 void setOptimalLayoutSize();
162 bool isCalculatingInitialLayoutSize() const { return mbIsCalculatingInitialLayoutSize; }
164 void SetIcon( sal_uInt16 nIcon );
165 sal_uInt16 GetIcon() const { return mnIcon; }
166 // for systems like MacOSX which can display the URL a document is loaded from
167 // separately from the window title
168 void SetRepresentedURL( const OUString& );
170 void ShowTitleButton( TitleButton nButton, bool bVisible );
171 bool IsTitleButtonVisible( TitleButton nButton ) const;
173 void SetMinOutputSizePixel( const Size& rSize );
174 const Size& GetMinOutputSizePixel() const { return maMinOutSize; }
175 void SetMaxOutputSizePixel( const Size& rSize );
176 const Size& GetMaxOutputSizePixel() const;
178 void SetWindowState(const OString& rStr);
179 OString GetWindowState(WindowStateMask nMask = WindowStateMask::All) const;
181 void SetMenuBar(MenuBar* pMenuBar);
182 MenuBar* GetMenuBar() const { return mpMenuBar; }
183 void SetMenuBarMode( MenuBarMode nMode );
184 void CollectMenuBarMnemonics(MnemonicGenerator& rMnemonicGenerator) const;
185 int GetMenuBarHeight() const;
187 void SetNotebookBar(const OUString& rUIXMLDescription,
188 const css::uno::Reference<css::frame::XFrame>& rFrame,
189 const NotebookBarAddonsItem& aNotebookBarAddonsItem,
190 bool bReloadNotebookbar = false);
192 void CloseNotebookBar();
193 VclPtr<NotebookBar> const & GetNotebookBar() const;
195 TaskPaneList* GetTaskPaneList();
196 void GetWindowStateData( WindowStateData& rData ) const;
198 virtual void SetText( const OUString& rStr ) override;
199 virtual OUString GetText() const override;
202 Returns the screen number the window is on
204 The Display Screen number is counted the same way that
205 <code>Application::GetScreenPosSizePixel</code>
206 and of course <code>SystemWindow::SetScreenNumber</code>
207 are counted in.
209 In case the window is positioned on multiple screens the
210 screen number returned will be of the screen containing the
211 upper left pixel of the frame area (that is of the client
212 area on system decorated windows, or the frame area of
213 undecorated resp. owner decorated windows.
215 @returns the screen number
217 @see SystemWindow::SetScreenNumber
219 unsigned int GetScreenNumber() const;
221 Move the Window to a new screen. The same rules for
222 positioning apply as in <code>SystemWindow::GetScreenNumber</code>
224 The Display Screen number is counted the same way that
225 <code>Application::GetScreenPosSizePixel</code>
226 and of course <code>SystemWindow::GetScreenNumber</code>
227 are counted in.
229 @see GetScreenNumber
231 void SetScreenNumber( unsigned int nNewScreen );
233 void SetApplicationID( const OUString &rApplicationID );
235 bool UpdatePositionData();
237 void SetCloseHdl(const Link<SystemWindow&,void>& rLink);
238 const Link<SystemWindow&,void>& GetCloseHdl() const;
240 SAL_DLLPRIVATE bool hasPendingLayout() const { return maLayoutIdle.IsActive(); }
242 virtual void doDeferredInit(WinBits nBits);
244 // Screenshot interface
245 VclPtr<VirtualDevice> createScreenshot();
248 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */