1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ 2 /* 3 * This file is part of the LibreOffice project. 4 * 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/. 8 * 9 * This file incorporates work covered by the following license notice: 10 * 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 . 18 */ 19 20 #pragma once 21 22 #include <vcl/dllapi.h> 23 #include <vcl/idle.hxx> 24 #include <vcl/window.hxx> 25 #include <vcl/windowstate.hxx> 26 #include <com/sun/star/frame/XFrame.hpp> 27 #include <memory> 28 29 class SalInstanceBuilder; 30 class ScreenshotTest; 31 class MenuBar; 32 class MnemonicGenerator; 33 class NotebookBar; 34 class TaskPaneList; 35 class VclBuilder; 36 struct NotebookBarAddonsItem; 37 38 #define ICON_LO_DEFAULT 1 39 #define ICON_TEXT_DOCUMENT 2 40 #define ICON_SPREADSHEET_DOCUMENT 4 41 #define ICON_DRAWING_DOCUMENT 6 42 #define ICON_PRESENTATION_DOCUMENT 8 43 #define ICON_TEMPLATE 11 44 #define ICON_DATABASE_DOCUMENT 12 45 #define ICON_MATH_DOCUMENT 13 46 #define ICON_MACROLIBRARY 1 47 48 enum class MenuBarMode 49 { 50 Normal, Hide 51 }; 52 53 enum class TitleButton 54 { 55 Docking = 1, 56 Hide = 2, 57 Menu = 4, 58 }; 59 60 //helper baseclass to ease retro fitting dialogs/tabpages that load a resource 61 //to load a .ui file instead 62 // 63 //vcl requires the Window Children of a Parent Window to be destroyed before 64 //the Parent Window. VclBuilderContainer owns the VclBuilder which owns the 65 //Children Window. So the VclBuilderContainer dtor must be called before 66 //the Parent Window dtor. 67 // 68 //i.e. class Dialog : public SystemWindow, public VclBuilderContainer 69 //not class Dialog : public VclBuilderContainer, public SystemWindow 70 // 71 //With the new 'dispose' framework, it is necessary to force the builder 72 //dispose before the Window dispose; so a Dialog::dispose() method would 73 //finish: disposeBuilder(); SystemWindow::dispose() to capture this ordering. 74 75 class VCL_DLLPUBLIC SAL_LOPLUGIN_ANNOTATE("crosscast") VclBuilderContainer 76 { 77 public: 78 VclBuilderContainer(); 79 virtual ~VclBuilderContainer(); 80 void disposeBuilder(); 81 82 void setDeferredProperties(); 83 84 protected: 85 std::unique_ptr<VclBuilder> m_pUIBuilder; 86 87 friend class ::SalInstanceBuilder; 88 friend class ::ScreenshotTest; 89 }; 90 91 class VCL_DLLPUBLIC SystemWindow 92 : public vcl::Window 93 , public VclBuilderContainer 94 { 95 friend class WorkWindow; 96 class ImplData; 97 98 private: 99 class LayoutIdle: public Idle { 100 public: LayoutIdle(char const * pDebugName,SystemWindow & parent,bool transferable)101 LayoutIdle(char const * pDebugName, SystemWindow & parent, bool transferable): 102 Idle(pDebugName), parent_(parent), 103 transferState_( 104 transferable ? TransferState::Transferable : TransferState::NotTransferable) 105 {} 106 107 bool DecideTransferredExecution() override; 108 wasTransferred() const109 bool wasTransferred() const { return transferState_ == TransferState::Transferred; } 110 111 private: 112 enum class TransferState { NotTransferable, Transferable, Transferred }; 113 114 SystemWindow & parent_; 115 TransferState transferState_; 116 }; 117 118 std::unique_ptr<ImplData> mpImplData; 119 VclPtr<MenuBar> mpMenuBar; 120 OUString maNotebookBarUIFile; 121 Size maMinOutSize; 122 MenuBarMode mnMenuBarMode = MenuBarMode::Normal; 123 sal_uInt16 mnIcon = 0; 124 bool mbDockBtn : 1 = false; 125 bool mbHideBtn : 1 = false; 126 bool mbSysChild : 1 = false; 127 bool mbIsCalculatingInitialLayoutSize : 1 = false; 128 bool mbInitialLayoutSizeCalculated : 1 = false; 129 bool mbInSetNoteBookBar : 1 = false; 130 bool mbPaintComplete : 1 = false; 131 bool mbIsDeferredInit : 1 = false; 132 LayoutIdle maLayoutIdle; 133 protected: 134 VclPtr<vcl::Window> mpDialogParent; 135 public: 136 using Window::ImplIsInTaskPaneList; 137 SAL_DLLPRIVATE bool ImplIsInTaskPaneList( vcl::Window* pWin ); isDeferredInit() const138 SAL_DLLPRIVATE bool isDeferredInit() const { return mbIsDeferredInit; } 139 140 private: 141 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 ); 142 SAL_DLLPRIVATE void setPosSizeOnContainee(Size aSize, Window &rBox); 143 DECL_DLLPRIVATE_LINK( ImplHandleLayoutTimerHdl, Timer*, void ); 144 145 // try to extract content and return as Bitmap. To do that reliably, a Yield-loop 146 // like in Execute() has to be executed and it is necessary to detect when the 147 // paint is finished 148 virtual void PrePaint(vcl::RenderContext& rRenderContext) override; 149 virtual void PostPaint(vcl::RenderContext& rRenderContext) override; 150 151 // ensureRepaint - triggers Application::Yield until the dialog is 152 // completely repainted. Sometimes needed for dialogs showing progress 153 // during actions 154 SAL_DLLPRIVATE void ensureRepaint(); 155 156 protected: 157 // Single argument ctors shall be explicit. 158 SAL_DLLPRIVATE explicit SystemWindow( 159 WindowType eType, const char* pIdleDebugName, bool transferableIdle = false); 160 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>()); 161 162 SAL_DLLPRIVATE void SetWindowState(const vcl::WindowData& rData); 163 164 virtual void settingOptimalLayoutSize(Window *pBox); 165 166 SAL_DLLPRIVATE void DoInitialLayout(); 167 168 virtual void ImplDeferredInit(vcl::Window* pParent, WinBits nBits); 169 170 public: 171 virtual ~SystemWindow() override; 172 virtual void dispose() override; 173 174 virtual bool EventNotify( NotifyEvent& rNEvt ) override; 175 virtual bool PreNotify( NotifyEvent& rNEvt ) override; 176 177 virtual bool Close(); 178 virtual void TitleButtonClick( TitleButton nButton ); 179 virtual void Resizing( Size& rSize ); 180 virtual void Resize() override; 181 virtual Size GetOptimalSize() const override; 182 virtual void queue_resize(StateChangedType eReason = StateChangedType::Layout) override; 183 SAL_DLLPRIVATE bool isLayoutEnabled() const; 184 SAL_DLLPRIVATE void setOptimalLayoutSize(bool bAllowWindowShrink); isCalculatingInitialLayoutSize() const185 bool isCalculatingInitialLayoutSize() const { return mbIsCalculatingInitialLayoutSize; } isSettingUpNoteBookBar() const186 bool isSettingUpNoteBookBar() const { return mbInSetNoteBookBar; } 187 188 void SetIcon( sal_uInt16 nIcon ); GetIcon() const189 sal_uInt16 GetIcon() const { return mnIcon; } 190 // for systems like MacOSX which can display the URL a document is loaded from 191 // separately from the window title 192 void SetRepresentedURL( const OUString& ); 193 194 SAL_DLLPRIVATE void ShowTitleButton( TitleButton nButton, bool bVisible ); 195 SAL_DLLPRIVATE bool IsTitleButtonVisible( TitleButton nButton ) const; 196 197 void SetMinOutputSizePixel( const Size& rSize ); GetMinOutputSizePixel() const198 const Size& GetMinOutputSizePixel() const { return maMinOutSize; } 199 SAL_DLLPRIVATE void SetMaxOutputSizePixel( const Size& rSize ); 200 SAL_DLLPRIVATE const Size& GetMaxOutputSizePixel() const; 201 202 void SetWindowState(std::u16string_view rStr); 203 OUString GetWindowState(vcl::WindowDataMask nMask = vcl::WindowDataMask::All) const; 204 205 void SetMenuBar(MenuBar* pMenuBar); GetMenuBar() const206 MenuBar* GetMenuBar() const { return mpMenuBar; } 207 void SetMenuBarMode( MenuBarMode nMode ); 208 void CollectMenuBarMnemonics(MnemonicGenerator& rMnemonicGenerator) const; 209 int GetMenuBarHeight() const; 210 211 void SetNotebookBar(const OUString& rUIXMLDescription, 212 const css::uno::Reference<css::frame::XFrame>& rFrame, 213 const NotebookBarAddonsItem& aNotebookBarAddonsItem, 214 bool bReloadNotebookbar = false); 215 216 void CloseNotebookBar(); 217 VclPtr<NotebookBar> const & GetNotebookBar() const; 218 219 TaskPaneList* GetTaskPaneList(); 220 SAL_DLLPRIVATE void GetWindowState(vcl::WindowData& rData) const; 221 222 virtual void SetText( const OUString& rStr ) override; 223 virtual OUString GetText() const override; 224 225 /** 226 Returns the screen number the window is on 227 228 The Display Screen number is counted the same way that 229 <code>Application::GetScreenPosSizePixel</code> 230 and of course <code>SystemWindow::SetScreenNumber</code> 231 are counted in. 232 233 In case the window is positioned on multiple screens the 234 screen number returned will be of the screen containing the 235 upper left pixel of the frame area (that is of the client 236 area on system decorated windows, or the frame area of 237 undecorated resp. owner decorated windows. 238 239 @returns the screen number 240 241 @see SystemWindow::SetScreenNumber 242 */ 243 unsigned int GetScreenNumber() const; 244 /** 245 Move the Window to a new screen. The same rules for 246 positioning apply as in <code>SystemWindow::GetScreenNumber</code> 247 248 The Display Screen number is counted the same way that 249 <code>Application::GetScreenPosSizePixel</code> 250 and of course <code>SystemWindow::GetScreenNumber</code> 251 are counted in. 252 253 @see GetScreenNumber 254 */ 255 void SetScreenNumber( unsigned int nNewScreen ); 256 257 void SetApplicationID( const OUString &rApplicationID ); 258 259 bool UpdatePositionData(); 260 261 void SetCloseHdl(const Link<SystemWindow&,void>& rLink); 262 const Link<SystemWindow&,void>& GetCloseHdl() const; 263 hasPendingLayout() const264 SAL_DLLPRIVATE bool hasPendingLayout() const { return maLayoutIdle.IsActive(); } 265 266 void doDeferredInit(WinBits nBits); 267 268 // Screenshot interface 269 VclPtr<VirtualDevice> createScreenshot(); 270 }; 271 272 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ 273
