LibreOffice Module vcl (master)  1
dialog.hxx
Go to the documentation of this file.
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 #if !defined(VCL_DLLIMPLEMENTATION) && !defined(TOOLKIT_DLLIMPLEMENTATION) && !defined(VCL_INTERNALS)
23 #error "don't use this in new code"
24 #endif
25 
26 #include <memory>
27 #include <string_view>
28 
29 #include <vcl/dllapi.h>
30 #include <vcl/syswin.hxx>
31 #include <vcl/vclptr.hxx>
32 #include <vcl/abstdlg.hxx>
33 
34 struct DialogImpl;
35 class Button;
36 class PushButton;
37 class VclBox;
38 class VclButtonBox;
39 
41 {
42 public:
43  enum class InitFlag
44  {
46  Default,
47 
49  NoParent
50  };
51 
52 private:
53  std::unique_ptr<DialogImpl> mpDialogImpl;
57  bool mbInClose;
59  InitFlag mnInitFlag; // used for deferred init
60 
63 
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);
68 
69  virtual void ApplySettings(vcl::RenderContext& rRenderContext) override;
70 
71  SAL_DLLPRIVATE Dialog (const Dialog &) = delete;
72  SAL_DLLPRIVATE Dialog & operator= (const Dialog &) = delete;
73 
74  DECL_DLLPRIVATE_LINK(ImplAsyncCloseHdl, void*, void);
75  DECL_DLLPRIVATE_LINK(ResponseHdl, Button*, void);
76 
77 protected:
78  void ImplInitDialog( vcl::Window* pParent, WinBits nStyle, InitFlag eFlag = InitFlag::Default );
79 
81  void ImplLOKNotifier(vcl::Window* pParent);
82 
83 public:
84  SAL_DLLPRIVATE bool IsInClose() const { return mbInClose; }
85  virtual void doDeferredInit(WinBits nBits) override;
86  SAL_DLLPRIVATE void disposeOwnedButtons();
87 
88 protected:
89  explicit Dialog( WindowType nType );
90  explicit Dialog( vcl::Window* pParent, std::u16string_view rID, const OUString& rUIXMLDescription);
91  virtual void Draw( OutputDevice* pDev, const Point& rPos, DrawFlags nFlags ) override;
92  virtual void settingOptimalLayoutSize(Window *pBox) override;
93 
94 protected:
95  friend class VclBuilder;
96  friend class SalInstanceBuilder;
97  void set_action_area(VclButtonBox* pBox);
98  void set_content_area(VclBox* pBox);
99 
100 public:
101  explicit Dialog( vcl::Window* pParent, WinBits nStyle = WB_STDDIALOG, InitFlag eFlag = InitFlag::Default );
102  virtual ~Dialog() override;
103  virtual void dispose() override;
104 
105  // get the default parent for a dialog as is done in standard initialization
106  static vcl::Window* GetDefaultParent(WinBits nStyle);
107 
108  virtual bool EventNotify( NotifyEvent& rNEvt ) override;
109  virtual void StateChanged( StateChangedType nStateChange ) override;
110  virtual void DataChanged( const DataChangedEvent& rDCEvt ) override;
111  virtual void Command( const CommandEvent& rCEvt ) override;
112  virtual void PixelInvalidate(const tools::Rectangle* pRectangle) override;
113 
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; }
118 
119  virtual bool Close() override;
120 
121  short Execute();
122  bool IsInExecute() const { return mbInExecute; }
123  // Return true when dialog is synchronously executed (calling ::Execute())
124  bool IsInSyncExecute() const { return mbInSyncExecute; };
125 
126  virtual FactoryFunction GetUITestFactory() const override;
127 
128 private:
129  bool ImplStartExecute();
130  static void ImplEndExecuteModal();
131  void ImplSetModalInputMode(bool bModal);
132 public:
133 
135  bool StartExecuteAsync(VclAbstractDialog::AsyncContext &rCtx);
136 
137  // Dialog::Execute replacement API
138 
139 
140  void EndDialog( tools::Long nResult = RET_CANCEL );
141 
142  void GetDrawWindowBorder( sal_Int32& rLeftBorder, sal_Int32& rTopBorder,
143  sal_Int32& rRightBorder, sal_Int32& rBottomBorder ) const;
144 
145  void SetModalInputMode( bool bModal );
146  bool IsModalInputMode() const { return mbModalMode; }
147 
148  void GrabFocusToFirstControl();
149  virtual void Resize() override;
150 
151  void Activate() override;
152 
153  void SetPopupMenuHdl(const Link<const CommandEvent&, bool>& rLink);
154  void SetInstallLOKNotifierHdl(const Link<void*, vcl::ILibreOfficeKitNotifier*>& rLink);
155  void SetLOKTunnelingState(bool bEnabled);
156 
157  void add_button(PushButton* pButton, int nResponse, bool bTransferOwnership);
158  void set_default_response(int nResponse);
159  int get_default_response() const;
160  vcl::Window* get_widget_for_response(int nResponse);
161 
162  void DumpAsPropertyTree(tools::JsonWriter& rJsonWriter) override;
163 };
164 
165 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual FactoryFunction GetUITestFactory() const
Definition: window.cxx:3930
virtual bool EventNotify(NotifyEvent &rNEvt) override
Definition: syswin.cxx:171
VclBox * get_content_area()
Definition: dialog.hxx:117
#define VCL_DLLPUBLIC
Definition: dllapi.h:29
long Long
bool IsInSyncExecute() const
Definition: dialog.hxx:124
std::function< std::unique_ptr< UIObject >vcl::Window *)> FactoryFunction
VclPtr< VclButtonBox > mpActionArea
Definition: dialog.hxx:61
StateChangedType
Definition: window.hxx:289
sal_Int64 WinBits
virtual void DumpAsPropertyTree(tools::JsonWriter &)
Dumps itself and potentially its children to a property tree, to be written easily to JSON...
Definition: window.cxx:3341
Creates a hierarchy of vcl::Windows (widgets) from a .ui file for dialogs, sidebar, etc.
Definition: builder.hxx:66
bool mbModalMode
Definition: dialog.hxx:58
bool mbInSyncExecute
Definition: dialog.hxx:56
bool IsModalInputMode() const
Definition: dialog.hxx:146
virtual bool Close()
Definition: syswin.cxx:266
bool mbInClose
Definition: dialog.hxx:57
VclPtr< VclBox > mpContentArea
Definition: dialog.hxx:62
virtual void doDeferredInit(WinBits nBits)
Definition: syswin.cxx:1108
DrawFlags
Definition: window.hxx:332
virtual void ApplySettings(vcl::RenderContext &rRenderContext)
Definition: window.cxx:3840
bool mbInExecute
Definition: dialog.hxx:55
Some things multiple-inherit from VclAbstractDialog and OutputDevice, so we need to use virtual inher...
Definition: outdev.hxx:303
virtual void Draw(::OutputDevice *pDev, const Point &rPos, DrawFlags nFlags)
Definition: window.cxx:1822
virtual void PixelInvalidate(const tools::Rectangle *pRectangle)
Notification about some rectangle of the output device got invalidated.
Definition: paint.cxx:1198
DECL_DLLPRIVATE_LINK(ImplHandleLayoutTimerHdl, Timer *, void)
bool IsInExecute() const
Definition: dialog.hxx:122
virtual bool set_property(const OString &rKey, const OUString &rValue)
Definition: window2.cxx:1444
InitFlag
Definition: dialog.hxx:43
VclButtonBox * get_action_area()
Definition: dialog.hxx:116
virtual void dispose() override
This is intended to be used to clear any locally held references to other Window-subclass objects...
Definition: syswin.cxx:101
virtual void queue_resize(StateChangedType eReason=StateChangedType::Layout) override
Definition: syswin.cxx:993
WindowType
virtual void settingOptimalLayoutSize(Window *pBox)
Definition: syswin.cxx:1069
InitFlag mnInitFlag
Definition: dialog.hxx:59
virtual void Activate()
Definition: window.cxx:1830
virtual void StateChanged(StateChangedType nStateChange)
Definition: window.cxx:1933
OutputDevice & operator=(const OutputDevice &)=delete
virtual void Command(const CommandEvent &rCEvt)
Definition: window.cxx:1916
std::unique_ptr< DialogImpl > mpDialogImpl
Definition: dialog.hxx:53
SAL_DLLPRIVATE bool IsInClose() const
Definition: dialog.hxx:84
virtual void Resize() override
Definition: syswin.cxx:1005
tools::Long mnMousePositioned
Definition: dialog.hxx:54
virtual void DataChanged(const DataChangedEvent &rDCEvt)
Definition: event.cxx:36