Avoid potential negative array index access to cached text.
[LibreOffice.git] / include / vcl / syswin.hxx
blobc59d7a24760c16ef404c2d75a9b2ffd5ed7b35f5
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 SAL_LOPLUGIN_ANNOTATE("crosscast") 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 mbInitialLayoutSizeCalculated;
107 bool mbPaintComplete;
108 MenuBarMode mnMenuBarMode;
109 sal_uInt16 mnIcon;
110 std::unique_ptr<ImplData> mpImplData;
111 Idle maLayoutIdle;
112 OUString maNotebookBarUIFile;
113 protected:
114 bool mbIsDeferredInit;
115 VclPtr<vcl::Window> mpDialogParent;
116 public:
117 using Window::ImplIsInTaskPaneList;
118 SAL_DLLPRIVATE bool ImplIsInTaskPaneList( vcl::Window* pWin );
119 SAL_DLLPRIVATE bool isDeferredInit() const { return mbIsDeferredInit; }
121 private:
122 static 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 );
123 SAL_DLLPRIVATE void setPosSizeOnContainee(Size aSize, Window &rBox);
124 DECL_DLLPRIVATE_LINK( ImplHandleLayoutTimerHdl, Timer*, void );
126 // try to extract content and return as Bitmap. To do that reliably, a Yield-loop
127 // like in Execute() has to be executed and it is necessary to detect when the
128 // paint is finished
129 virtual void PrePaint(vcl::RenderContext& rRenderContext) override;
130 virtual void PostPaint(vcl::RenderContext& rRenderContext) override;
132 // ensureRepaint - triggers Application::Yield until the dialog is
133 // completely repainted. Sometimes needed for dialogs showing progress
134 // during actions
135 SAL_DLLPRIVATE void ensureRepaint();
137 protected:
138 // Single argument ctors shall be explicit.
139 explicit SystemWindow(WindowType nType, const char* pIdleDebugName);
140 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>());
142 void SetWindowState(const vcl::WindowData& rData);
144 virtual void settingOptimalLayoutSize(Window *pBox);
146 SAL_DLLPRIVATE void DoInitialLayout();
148 public:
149 virtual ~SystemWindow() override;
150 virtual void dispose() override;
152 virtual bool EventNotify( NotifyEvent& rNEvt ) override;
153 virtual bool PreNotify( NotifyEvent& rNEvt ) override;
155 virtual bool Close();
156 virtual void TitleButtonClick( TitleButton nButton );
157 virtual void Resizing( Size& rSize );
158 virtual void Resize() override;
159 virtual Size GetOptimalSize() const override;
160 virtual void queue_resize(StateChangedType eReason = StateChangedType::Layout) override;
161 bool isLayoutEnabled() const;
162 void setOptimalLayoutSize(bool bAllowWindowShrink);
163 bool isCalculatingInitialLayoutSize() const { return mbIsCalculatingInitialLayoutSize; }
165 void SetIcon( sal_uInt16 nIcon );
166 sal_uInt16 GetIcon() const { return mnIcon; }
167 // for systems like MacOSX which can display the URL a document is loaded from
168 // separately from the window title
169 void SetRepresentedURL( const OUString& );
171 void ShowTitleButton( TitleButton nButton, bool bVisible );
172 bool IsTitleButtonVisible( TitleButton nButton ) const;
174 void SetMinOutputSizePixel( const Size& rSize );
175 const Size& GetMinOutputSizePixel() const { return maMinOutSize; }
176 void SetMaxOutputSizePixel( const Size& rSize );
177 const Size& GetMaxOutputSizePixel() const;
179 void SetWindowState(std::u16string_view rStr);
180 OUString GetWindowState(vcl::WindowDataMask nMask = vcl::WindowDataMask::All) const;
182 void SetMenuBar(MenuBar* pMenuBar);
183 MenuBar* GetMenuBar() const { return mpMenuBar; }
184 void SetMenuBarMode( MenuBarMode nMode );
185 void CollectMenuBarMnemonics(MnemonicGenerator& rMnemonicGenerator) const;
186 int GetMenuBarHeight() const;
188 void SetNotebookBar(const OUString& rUIXMLDescription,
189 const css::uno::Reference<css::frame::XFrame>& rFrame,
190 const NotebookBarAddonsItem& aNotebookBarAddonsItem,
191 bool bReloadNotebookbar = false);
193 void CloseNotebookBar();
194 VclPtr<NotebookBar> const & GetNotebookBar() const;
196 TaskPaneList* GetTaskPaneList();
197 void GetWindowState(vcl::WindowData& rData) const;
199 virtual void SetText( const OUString& rStr ) override;
200 virtual OUString GetText() const override;
203 Returns the screen number the window is on
205 The Display Screen number is counted the same way that
206 <code>Application::GetScreenPosSizePixel</code>
207 and of course <code>SystemWindow::SetScreenNumber</code>
208 are counted in.
210 In case the window is positioned on multiple screens the
211 screen number returned will be of the screen containing the
212 upper left pixel of the frame area (that is of the client
213 area on system decorated windows, or the frame area of
214 undecorated resp. owner decorated windows.
216 @returns the screen number
218 @see SystemWindow::SetScreenNumber
220 unsigned int GetScreenNumber() const;
222 Move the Window to a new screen. The same rules for
223 positioning apply as in <code>SystemWindow::GetScreenNumber</code>
225 The Display Screen number is counted the same way that
226 <code>Application::GetScreenPosSizePixel</code>
227 and of course <code>SystemWindow::GetScreenNumber</code>
228 are counted in.
230 @see GetScreenNumber
232 void SetScreenNumber( unsigned int nNewScreen );
234 void SetApplicationID( const OUString &rApplicationID );
236 bool UpdatePositionData();
238 void SetCloseHdl(const Link<SystemWindow&,void>& rLink);
239 const Link<SystemWindow&,void>& GetCloseHdl() const;
241 SAL_DLLPRIVATE bool hasPendingLayout() const { return maLayoutIdle.IsActive(); }
243 virtual void doDeferredInit(WinBits nBits);
245 // Screenshot interface
246 VclPtr<VirtualDevice> createScreenshot();
249 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */