1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 #ifndef INCLUDED_VCL_DIALOG_HXX
21 #define INCLUDED_VCL_DIALOG_HXX
24 #include <vcl/dllapi.h>
25 #include <vcl/syswin.hxx>
26 #include <vcl/vclptr.hxx>
27 #include <vcl/abstdlg.hxx>
34 class VCL_DLLPUBLIC Dialog
: public SystemWindow
39 /** Use given parent or get a default one using GetDefaultParent(...) */
47 std::unique_ptr
<DialogImpl
> mpDialogImpl
;
48 long mnMousePositioned
;
54 bool const mbForceBorderWindow
;
55 InitFlag
const mnInitFlag
; // used for deferred init
57 VclPtr
<VclButtonBox
> mpActionArea
;
58 VclPtr
<VclBox
> mpContentArea
;
60 SAL_DLLPRIVATE
void RemoveFromDlgList();
61 SAL_DLLPRIVATE
void ImplInitDialogData();
62 SAL_DLLPRIVATE
void ImplInitSettings();
63 SAL_DLLPRIVATE VclPtr
<vcl::Window
> AddBorderWindow(vcl::Window
* pParent
, WinBits nBits
);
65 virtual void ApplySettings(vcl::RenderContext
& rRenderContext
) override
;
67 SAL_DLLPRIVATE
Dialog (const Dialog
&) = delete;
68 SAL_DLLPRIVATE Dialog
& operator= (const Dialog
&) = delete;
70 DECL_DLLPRIVATE_LINK(ImplAsyncCloseHdl
, void*, void);
71 DECL_DLLPRIVATE_LINK(ResponseHdl
, Button
*, void);
73 // ensureRepaint - triggers Application::Yield until the dialog is
74 // completely repainted. Sometimes needed for dialogs showing progress
79 using Window::ImplInit
;
80 void ImplInit( vcl::Window
* pParent
, WinBits nStyle
, InitFlag eFlag
= InitFlag::Default
);
82 /// Find and set the LOK notifier according to the pParent.
83 void ImplLOKNotifier(vcl::Window
* pParent
);
86 SAL_DLLPRIVATE
bool IsInClose() const { return mbInClose
; }
87 virtual void doDeferredInit(WinBits nBits
) override
;
88 SAL_DLLPRIVATE
void disposeOwnedButtons();
91 explicit Dialog( WindowType nType
);
92 explicit Dialog( vcl::Window
* pParent
, const OUString
& rID
, const OUString
& rUIXMLDescription
, WindowType nType
, InitFlag eFlag
= InitFlag::Default
, bool bBorder
= false );
93 virtual void Draw( OutputDevice
* pDev
, const Point
& rPos
, const Size
& rSize
, DrawFlags nFlags
) override
;
94 virtual void settingOptimalLayoutSize(Window
*pBox
) override
;
97 friend class VclBuilder
;
98 void set_action_area(VclButtonBox
* pBox
);
99 void set_content_area(VclBox
* pBox
);
102 explicit Dialog( vcl::Window
* pParent
, WinBits nStyle
= WB_STDDIALOG
, InitFlag eFlag
= InitFlag::Default
);
103 explicit Dialog( vcl::Window
* pParent
, const OUString
& rID
, const OUString
& rUIXMLDescription
);
104 virtual ~Dialog() override
;
105 virtual void dispose() override
;
107 // get the default parent for a dialog as is done in standard initialization
108 static vcl::Window
* GetDefaultParent(WinBits nStyle
);
110 virtual bool EventNotify( NotifyEvent
& rNEvt
) override
;
111 virtual void StateChanged( StateChangedType nStateChange
) override
;
112 virtual void DataChanged( const DataChangedEvent
& rDCEvt
) override
;
114 virtual void queue_resize(StateChangedType eReason
= StateChangedType::Layout
) override
;
115 virtual bool set_property(const OString
&rKey
, const OUString
&rValue
) override
;
116 VclButtonBox
* get_action_area() { return mpActionArea
; }
117 VclBox
* get_content_area() { return mpContentArea
; }
119 virtual bool Close() override
;
121 // try to extract content and return as Bitmap. To do that reliably, a Yield-loop
122 // like in Execute() has to be executed and it is necessary to detect when the
124 virtual void PrePaint(vcl::RenderContext
& rRenderContext
) override
;
125 virtual void PostPaint(vcl::RenderContext
& rRenderContext
) override
;
127 // Screenshot interface
128 virtual std::vector
<OString
> getAllPageUIXMLDescriptions() const;
129 virtual bool selectPageByUIXMLDescription(const OString
& rUIXMLDescription
);
130 BitmapEx
createScreenshot();
132 virtual short Execute();
133 bool IsInExecute() const { return mbInExecute
; }
134 // Return true when dialog is synchronously executed (calling ::Execute())
135 bool IsInSyncExecute() const { return mbInSyncExecute
; };
137 virtual FactoryFunction
GetUITestFactory() const override
;
140 bool ImplStartExecute();
141 static void ImplEndExecuteModal();
142 void ImplSetModalInputMode(bool bModal
);
145 /// Returns true if the dialog successfully starts
146 bool StartExecuteAsync(const std::function
<void(sal_Int32
)> &rEndDialogFn
)
148 VclAbstractDialog::AsyncContext aCtx
;
150 aCtx
.maEndDialogFn
= rEndDialogFn
;
151 return StartExecuteAsync(aCtx
);
154 /// Commence execution of a modal dialog, disposes owner on failure
155 virtual bool StartExecuteAsync(VclAbstractDialog::AsyncContext
&rCtx
);
157 // Dialog::Execute replacement API
160 void EndDialog( long nResult
= RET_CANCEL
);
161 static void EndAllDialogs( vcl::Window
const * pParent
);
163 // returns the most recent of the currently executing modal dialogs
164 static VclPtr
<Dialog
> GetMostRecentExecutingDialog();
166 void GetDrawWindowBorder( sal_Int32
& rLeftBorder
, sal_Int32
& rTopBorder
,
167 sal_Int32
& rRightBorder
, sal_Int32
& rBottomBorder
) const;
169 void SetModalInputMode( bool bModal
);
170 bool IsModalInputMode() const { return mbModalMode
; }
172 void GrabFocusToFirstControl();
173 virtual void Resize() override
;
175 void Activate() override
;
178 void SetInstallLOKNotifierHdl(const Link
<void*, vcl::ILibreOfficeKitNotifier
*>& rLink
);
180 void add_button(PushButton
* pButton
, int nResponse
, bool bTransferOwnership
);
181 void set_default_response(int nResponse
);
182 int get_default_response();
183 vcl::Window
* get_widget_for_response(int nResponse
);
186 class VCL_DLLPUBLIC ModelessDialog
: public Dialog
188 ModelessDialog (const ModelessDialog
&) = delete;
189 ModelessDialog
& operator= (const ModelessDialog
&) = delete;
192 explicit ModelessDialog( vcl::Window
* pParent
, const OUString
& rID
, const OUString
& rUIXMLDescription
, Dialog::InitFlag eFlag
= Dialog::InitFlag::Default
);
195 class VCL_DLLPUBLIC ModalDialog
: public Dialog
198 explicit ModalDialog( vcl::Window
* pParent
, const OUString
& rID
, const OUString
& rUIXMLDescription
, bool bBorder
= false );
206 SAL_DLLPRIVATE
ModalDialog (const ModalDialog
&) = delete;
207 SAL_DLLPRIVATE ModalDialog
& operator= (const ModalDialog
&) = delete;
210 #endif // INCLUDED_VCL_DIALOG_HXX
212 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */