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 .
19 #ifndef INCLUDED_SFX2_CHILDWIN_HXX
20 #define INCLUDED_SFX2_CHILDWIN_HXX
23 #include <sal/config.h>
25 #include <sfx2/dllapi.h>
26 #include <sal/types.h>
27 #include <o3tl/typed_flags_set.hxx>
28 #include <vcl/window.hxx>
30 #include <sfx2/chalign.hxx>
31 #include <sfx2/basedlgs.hxx>
33 namespace com::sun::star::frame
{ class XFrame
; }
38 class SfxChildWindowContext
;
40 class SfxModelessDialogController
;
42 enum class SfxChildWindowFlags
45 ZOOMIN
= 0x01, // Fully retracted Float
46 FORCEDOCK
= 0x04, // Float forbidden
47 TASK
= 0x10, // ChildWindow inside the Task
48 CANTGETFOCUS
= 0x20, // ChildWindow can not get focus
49 ALWAYSAVAILABLE
= 0x40, // ChildWindow is never disabled
50 NEVERHIDE
= 0x80 // ChildWindow is can always made
56 template<> struct typed_flags
<SfxChildWindowFlags
> : is_typed_flags
<SfxChildWindowFlags
, 0xf5> {};
60 #define CHILDWIN_NOPOS USHRT_MAX
62 // ChildWindow Configuration
63 struct SAL_DLLPUBLIC_RTTI SfxChildWinInfo
68 SfxChildWindowFlags nFlags
;
69 OUString aExtraString
;
76 nFlags
= SfxChildWindowFlags::NONE
;
78 bool GetExtraData_Impl( SfxChildAlignment
*pAlign
) const;
81 // ChildWindow factory methods
82 typedef std::unique_ptr
<SfxChildWindow
> (*SfxChildWinCtor
)( vcl::Window
*pParentWindow
,
84 SfxBindings
*pBindings
,
85 SfxChildWinInfo
*pInfo
);
87 // ChildWindowsContexts factory methods
88 typedef std::unique_ptr
<SfxChildWindowContext
> (*SfxChildWinContextCtor
)( vcl::Window
*pParentWindow
,
89 SfxBindings
*pBindings
,
90 SfxChildWinInfo
*pInfo
);
91 struct SfxChildWinContextFactory
93 SfxChildWinContextCtor
const pCtor
; // Factory method
94 sal_uInt16
const nContextId
; // Identifier for SfxInterface
96 SfxChildWinContextFactory( SfxChildWinContextCtor pTheCtor
, sal_uInt16 nID
)
102 class SfxChildWinContextArr_Impl
;
104 struct SFX2_DLLPUBLIC SfxChildWinFactory
106 SfxChildWinCtor
const pCtor
; // Factory method
107 sal_uInt16
const nId
; // ChildWindow-Id ( SlotId )
108 SfxChildWinInfo aInfo
; // Configuration
109 sal_uInt16
const nPos
; // Position in UI
110 std::unique_ptr
<SfxChildWinContextArr_Impl
> pArr
; // Array for Contexts
112 SfxChildWinFactory( SfxChildWinCtor pTheCtor
, sal_uInt16 nID
, sal_uInt16 n
);
113 ~SfxChildWinFactory();
116 class FloatingWindow
;
117 struct SfxChildWindow_Impl
;
118 class SFX2_DLLPUBLIC SfxChildWindowContext
120 friend class SfxChildWindow
;
121 VclPtr
<vcl::Window
> pWindow
;
122 sal_uInt16 nContextId
;
125 SfxChildWindowContext( sal_uInt16 nId
);
128 virtual ~SfxChildWindowContext();
130 void SetWindow( vcl::Window
* pWin
)
132 vcl::Window
* GetWindow() const
134 sal_uInt16
GetContextId() const
135 { return nContextId
; }
137 static FloatingWindow
* GetFloatingWindow(vcl::Window
*pParent
);
139 static void RegisterChildWindowContext(SfxModule
*, sal_uInt16
, std::unique_ptr
<SfxChildWinContextFactory
>);
142 class SFX2_DLLPUBLIC SfxChildWindow
144 VclPtr
<vcl::Window
> pParent
; // parent window ( Topwindow )
145 sal_uInt16
const nType
; // ChildWindow-Id
146 VclPtr
<vcl::Window
> pWindow
; // actual contents
147 std::shared_ptr
<SfxDialogController
> xController
; // actual contents
148 SfxChildAlignment eChildAlignment
; // Current css::drawing::Alignment
149 std::unique_ptr
< SfxChildWindow_Impl
> pImpl
; // Implementation data
150 std::unique_ptr
<SfxChildWindowContext
> pContext
; // With context-sensitive ChildWindows:
151 // Another window in pWindow
152 SAL_DLLPRIVATE
void ClearWorkwin();
155 void SetWindow(const VclPtr
<vcl::Window
>& p
) { pWindow
= p
; }
156 SfxChildWindow(vcl::Window
*pParentWindow
, sal_uInt16 nId
);
159 virtual ~SfxChildWindow();
161 vcl::Window
* GetWindow() const
163 void SetController(std::shared_ptr
<SfxDialogController
> controller
) { xController
= controller
; }
164 void ClearController() { xController
.reset(); }
165 std::shared_ptr
<SfxDialogController
>& GetController() { return xController
; }
166 const std::shared_ptr
<SfxDialogController
>& GetController() const { return xController
; }
167 vcl::Window
* GetParent() const
169 SfxChildAlignment
GetAlignment() const
170 { return eChildAlignment
; }
171 void SetAlignment(SfxChildAlignment eAlign
);
173 virtual void Show( ShowFlags nFlags
);
174 sal_uInt16
GetPosition() const;
175 sal_uInt16
GetType() const
178 void CreateContext( sal_uInt16 nContextId
, SfxBindings
& );
179 sal_uInt16
GetContextId() const
180 { return pContext
? pContext
->GetContextId(): 0; }
182 vcl::Window
* GetContextWindow() const
183 { return pContext
? pContext
->GetWindow(): nullptr; }
185 vcl::Window
* GetContextWindow( SfxModule
const *pModule
) const;
187 virtual SfxChildWinInfo
GetInfo() const;
188 void SaveStatus(const SfxChildWinInfo
& rInfo
);
190 static void RegisterChildWindow(SfxModule
*, std::unique_ptr
<SfxChildWinFactory
>);
192 static std::unique_ptr
<SfxChildWindow
> CreateChildWindow( sal_uInt16
, vcl::Window
*, SfxBindings
*, SfxChildWinInfo
const &);
193 void SetHideNotDelete( bool bOn
);
194 bool IsHideNotDelete() const;
195 bool IsVisible() const;
196 void SetWantsFocus( bool );
197 bool WantsFocus() const;
199 virtual bool QueryClose();
200 const css::uno::Reference
< css::frame::XFrame
>& GetFrame() const;
201 void SetFrame( const css::uno::Reference
< css::frame::XFrame
> & );
203 SAL_DLLPRIVATE
static void InitializeChildWinFactory_Impl(sal_uInt16
, SfxChildWinInfo
&);
204 void SetVisible_Impl( bool bVis
);
205 SAL_DLLPRIVATE
void SetWorkWindow_Impl( SfxWorkWindow
* );
206 SAL_DLLPRIVATE
void Activate_Impl();
208 SAL_DLLPRIVATE SfxChildWindowContext
*
209 GetContext_Impl() const
210 { return pContext
.get(); }
211 SAL_DLLPRIVATE
void SetFactory_Impl( SfxChildWinFactory
* );
215 //! The Macro of the future ...
216 #define SFX_DECL_CHILDWINDOWCONTEXT(Class) \
217 static std::unique_ptr<SfxChildWindowContext> CreateImpl(vcl::Window *pParent, \
218 SfxBindings *pBindings, SfxChildWinInfo* pInfo ); \
219 static void RegisterChildWindowContext(sal_uInt16, SfxModule *pMod=nullptr); \
221 //! The Macro of the future ...
222 // As a parameter and because of ContextId, CreateImpl must be handed the
223 // factory. As long as Id is set to 0 and patched in
224 // SfxChildWindow::CreateContext
225 #define SFX_IMPL_CHILDWINDOWCONTEXT(Class, MyID) \
226 std::unique_ptr<SfxChildWindowContext> Class::CreateImpl( vcl::Window *pParent, \
227 SfxBindings *pBindings, SfxChildWinInfo* pInfo ) \
229 return std::make_unique<Class>(pParent,0,pBindings,pInfo);\
231 void Class::RegisterChildWindowContext(sal_uInt16 nId, SfxModule* pMod) \
233 auto pFact = std::make_unique<SfxChildWinContextFactory>( \
234 Class::CreateImpl, nId ); \
235 SfxChildWindowContext::RegisterChildWindowContext(pMod, MyID, std::move(pFact)); \
238 #define SFX_DECL_CHILDWINDOW(Class) \
240 static std::unique_ptr<SfxChildWindow> CreateImpl(vcl::Window *pParent, sal_uInt16 nId, \
241 SfxBindings *pBindings, SfxChildWinInfo* pInfo ); \
242 static void RegisterChildWindow (bool bVisible=false, SfxModule *pMod=nullptr, SfxChildWindowFlags nFlags=SfxChildWindowFlags::NONE); \
243 virtual SfxChildWinInfo GetInfo() const override
245 #define SFX_DECL_CHILDWINDOW_WITHID(Class) \
246 SFX_DECL_CHILDWINDOW(Class); \
247 static sal_uInt16 GetChildWindowId ()\
249 #define SFX_IMPL_CHILDWINDOW(Class, MyID) \
250 SFX_IMPL_POS_CHILDWINDOW(Class, MyID, CHILDWIN_NOPOS)
252 #define SFX_IMPL_CHILDWINDOW_WITHID(Class, MyID) \
253 SFX_IMPL_POS_CHILDWINDOW_WITHID(Class, MyID, CHILDWIN_NOPOS)
255 #define SFX_IMPL_POS_CHILDWINDOW(Class, MyID, Pos) \
256 std::unique_ptr<SfxChildWindow> Class::CreateImpl( vcl::Window *pParent, \
257 sal_uInt16 nId, SfxBindings *pBindings, SfxChildWinInfo* pInfo ) \
259 return std::make_unique<Class>(pParent, nId, pBindings, pInfo);\
261 void Class::RegisterChildWindow (bool bVis, SfxModule *pMod, SfxChildWindowFlags nFlags) \
263 auto pFact = std::make_unique<SfxChildWinFactory>( \
264 Class::CreateImpl, MyID, Pos ); \
265 pFact->aInfo.nFlags |= nFlags; \
266 pFact->aInfo.bVisible = bVis; \
267 SfxChildWindow::RegisterChildWindow(pMod, std::move(pFact)); \
270 #define SFX_IMPL_POS_CHILDWINDOW_WITHID(Class, MyID, Pos) \
271 SFX_IMPL_POS_CHILDWINDOW(Class, MyID, Pos) \
272 sal_uInt16 Class::GetChildWindowId () \
275 #define SFX_IMPL_FLOATINGWINDOW(Class, MyID) \
276 SFX_IMPL_CHILDWINDOW(Class, MyID) \
277 SfxChildWinInfo Class::GetInfo() const \
279 SfxChildWinInfo aInfo = SfxChildWindow::GetInfo(); \
280 static_cast<SfxFloatingWindow*>(GetWindow())->FillInfo( aInfo ); \
283 #define SFX_IMPL_MODELESSDIALOGCONTOLLER(Class, MyID) \
284 SFX_IMPL_CHILDWINDOW(Class, MyID) \
285 SfxChildWinInfo Class::GetInfo() const \
287 SfxChildWinInfo aInfo = SfxChildWindow::GetInfo(); \
288 static_cast<const SfxModelessDialogController*>(GetController().get())->FillInfo( aInfo ); \
291 #define SFX_IMPL_MODELESSDIALOGCONTOLLER_WITHID(Class, MyID) \
292 SFX_IMPL_CHILDWINDOW_WITHID(Class, MyID) \
293 SfxChildWinInfo Class::GetInfo() const \
295 SfxChildWinInfo aInfo = SfxChildWindow::GetInfo(); \
296 static_cast<const SfxModelessDialogController*>(GetController().get())->FillInfo( aInfo ); \
299 #define SFX_IMPL_DOCKINGWINDOW(Class, MyID) \
300 SFX_IMPL_CHILDWINDOW(Class, MyID) \
301 SfxChildWinInfo Class::GetInfo() const \
303 SfxChildWinInfo aInfo = SfxChildWindow::GetInfo(); \
304 static_cast<SfxDockingWindow*>(GetWindow())->FillInfo( aInfo ); \
307 #define SFX_IMPL_DOCKINGWINDOW_WITHID(Class, MyID) \
308 SFX_IMPL_CHILDWINDOW_WITHID(Class, MyID) \
309 SfxChildWinInfo Class::GetInfo() const \
311 SfxChildWinInfo aInfo = SfxChildWindow::GetInfo(); \
312 static_cast<SfxDockingWindow*>(GetWindow())->FillInfo( aInfo ); \
315 bool GetPosSizeFromString( const OUString
& rStr
, Point
& rPos
, Size
& rSize
);
317 bool GetSplitSizeFromString( const OUString
& rStr
, Size
& rSize
);
321 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */