Update git submodules
[LibreOffice.git] / include / vcl / toolkit / dialog.hxx
blob7b61ed4c68c760dd819678ba0adf6a0ef1e9e039
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 #if !defined(VCL_DLLIMPLEMENTATION) && !defined(TOOLKIT_DLLIMPLEMENTATION) && !defined(VCL_INTERNALS)
23 #error "don't use this in new code"
24 #endif
26 #include <memory>
27 #include <string_view>
29 #include <vcl/dllapi.h>
30 #include <vcl/syswin.hxx>
31 #include <vcl/vclptr.hxx>
32 #include <vcl/abstdlg.hxx>
34 struct DialogImpl;
35 class Button;
36 class PushButton;
37 class VclBox;
38 class VclButtonBox;
40 class VCL_DLLPUBLIC Dialog : public SystemWindow
42 public:
43 enum class InitFlag
45 /** Use given parent or get a default one using GetDefaultParent(...) */
46 Default,
48 /** No Parent */
49 NoParent
52 private:
53 std::unique_ptr<DialogImpl> mpDialogImpl;
54 tools::Long mnMousePositioned;
55 bool mbInExecute;
56 bool mbInSyncExecute;
57 bool mbInClose;
58 bool mbModalMode;
59 InitFlag mnInitFlag; // used for deferred init
61 VclPtr<VclButtonBox> mpActionArea;
62 VclPtr<VclBox> mpContentArea;
64 SAL_DLLPRIVATE void RemoveFromDlgList();
65 SAL_DLLPRIVATE void ImplInitDialogData();
66 SAL_DLLPRIVATE void ImplInitSettings();
67 SAL_DLLPRIVATE VclPtr<vcl::Window> AddBorderWindow(vcl::Window* pParent, WinBits nBits);
69 virtual void ApplySettings(vcl::RenderContext& rRenderContext) override;
71 SAL_DLLPRIVATE Dialog (const Dialog &) = delete;
72 SAL_DLLPRIVATE Dialog & operator= (const Dialog &) = delete;
74 DECL_DLLPRIVATE_LINK(ImplAsyncCloseHdl, void*, void);
75 DECL_DLLPRIVATE_LINK(ResponseHdl, Button*, void);
77 // get the default parent for a dialog as is done in standard initialization
78 SAL_DLLPRIVATE static vcl::Window* GetDefaultParent(WinBits nStyle);
80 protected:
81 void ImplInitDialog( vcl::Window* pParent, WinBits nStyle, InitFlag eFlag = InitFlag::Default );
82 virtual void ImplDeferredInit(vcl::Window* pParent, WinBits nBits) override;
84 /// Find and set the LOK notifier according to the pParent.
85 void ImplLOKNotifier(vcl::Window* pParent);
87 public:
88 SAL_DLLPRIVATE bool IsInClose() const { return mbInClose; }
89 SAL_DLLPRIVATE void disposeOwnedButtons();
91 SAL_DLLPRIVATE static vcl::Window* GetDefDialogParent();
93 protected:
94 explicit Dialog( WindowType nType );
95 explicit Dialog( vcl::Window* pParent, const OUString& rID, const OUString& rUIXMLDescription);
96 virtual void Draw( OutputDevice* pDev, const Point& rPos, SystemTextColorFlags nFlags ) override;
97 virtual void settingOptimalLayoutSize(Window *pBox) override;
99 protected:
100 friend class VclBuilder;
101 friend class SalInstanceBuilder;
102 void set_action_area(VclButtonBox* pBox);
103 void set_content_area(VclBox* pBox);
104 vcl::Window* GetFirstControlForFocus();
106 public:
107 explicit Dialog( vcl::Window* pParent, WinBits nStyle = WB_STDDIALOG, InitFlag eFlag = InitFlag::Default );
108 virtual ~Dialog() override;
109 virtual void dispose() override;
111 virtual bool EventNotify( NotifyEvent& rNEvt ) override;
112 virtual void StateChanged( StateChangedType nStateChange ) override;
113 virtual void DataChanged( const DataChangedEvent& rDCEvt ) override;
114 virtual void Command( const CommandEvent& rCEvt ) override;
115 virtual void PixelInvalidate(const tools::Rectangle* pRectangle) override;
117 virtual void queue_resize(StateChangedType eReason = StateChangedType::Layout) override;
118 virtual bool set_property(const OUString &rKey, const OUString &rValue) override;
119 VclButtonBox* get_action_area() { return mpActionArea; }
120 VclBox* get_content_area() { return mpContentArea; }
122 virtual bool Close() override;
124 short Execute();
125 bool IsInExecute() const { return mbInExecute; }
126 // Return true when dialog is synchronously executed (calling ::Execute())
127 bool IsInSyncExecute() const { return mbInSyncExecute; };
129 virtual FactoryFunction GetUITestFactory() const override;
131 private:
132 bool ImplStartExecute();
133 static void ImplEndExecuteModal();
134 void ImplSetModalInputMode(bool bModal);
136 public:
138 /// Commence execution of a modal dialog, disposes owner on failure
139 bool StartExecuteAsync(VclAbstractDialog::AsyncContext &rCtx);
141 // Dialog::Execute replacement API
144 void EndDialog( tools::Long nResult = RET_CANCEL );
146 void GetDrawWindowBorder( sal_Int32& rLeftBorder, sal_Int32& rTopBorder,
147 sal_Int32& rRightBorder, sal_Int32& rBottomBorder ) const;
149 void SetModalInputMode( bool bModal );
150 bool IsModalInputMode() const { return mbModalMode; }
152 void GrabFocusToFirstControl();
153 virtual void Resize() override;
155 void Activate() override;
157 void SetPopupMenuHdl(const Link<const CommandEvent&, bool>& rLink);
158 void SetInstallLOKNotifierHdl(const Link<void*, vcl::ILibreOfficeKitNotifier*>& rLink);
159 void SetLOKTunnelingState(bool bEnabled);
161 void add_button(PushButton* pButton, int nResponse, bool bTransferOwnership);
162 void set_default_response(int nResponse);
163 int get_default_response() const;
164 vcl::Window* get_widget_for_response(int nResponse);
166 void DumpAsPropertyTree(tools::JsonWriter& rJsonWriter) override;
169 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */