Version 6.4.0.3, tag libreoffice-6.4.0.3
[LibreOffice.git] / sc / source / ui / inc / ChildWindowWrapper.hxx
blobdad043e22143d801c2c43d12be0b485a4391c184
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 */
11 #ifndef INCLUDED_SC_SOURCE_UI_INC_CHILDWINDOWWRAPPER_HXX
12 #define INCLUDED_SC_SOURCE_UI_INC_CHILDWINDOWWRAPPER_HXX
14 #include <sfx2/basedlgs.hxx>
15 #include <sfx2/dispatch.hxx>
16 #include <sfx2/viewfrm.hxx>
17 #include <sfx2/childwin.hxx>
19 #include "tabvwsh.hxx"
21 template <sal_Int16 WindowID>
22 class ChildControllerWrapper : public SfxChildWindow
24 public:
25 ChildControllerWrapper(vcl::Window* pParentP, sal_uInt16 nId,
26 SfxBindings* pBindings, const SfxChildWinInfo* pInfo)
27 : SfxChildWindow(pParentP, nId)
29 ScTabViewShell* pViewShell = getTabViewShell( pBindings );
30 if (!pViewShell)
31 pViewShell = dynamic_cast< ScTabViewShell *>( SfxViewShell::Current() );
32 OSL_ENSURE(pViewShell, "Missing view shell!");
34 if (pViewShell)
35 SetController(pViewShell->CreateRefDialogController(pBindings, this, pInfo, pParentP->GetFrameWeld(), WindowID));
37 if (pViewShell && !GetController())
38 pViewShell->GetViewFrame()->SetChildWindow( nId, false );
41 static std::unique_ptr<SfxChildWindow> CreateImpl(
42 vcl::Window *pParent, sal_uInt16 nId,
43 SfxBindings *pBindings, SfxChildWinInfo* pInfo )
45 return std::make_unique<ChildControllerWrapper>(pParent, nId, pBindings, pInfo);
48 static void RegisterChildWindow (
49 bool bVisible = false,
50 SfxModule* pModule = nullptr,
51 SfxChildWindowFlags nFlags = SfxChildWindowFlags::NONE)
53 auto pFactory = std::make_unique<SfxChildWinFactory>(ChildControllerWrapper::CreateImpl, WindowID, CHILDWIN_NOPOS );
54 pFactory->aInfo.nFlags |= nFlags;
55 pFactory->aInfo.bVisible = bVisible;
56 SfxChildWindow::RegisterChildWindow(pModule, std::move(pFactory));
59 static sal_uInt16 GetChildWindowId()
61 return WindowID;
64 private:
65 static ScTabViewShell* getTabViewShell( const SfxBindings *pBindings )
67 if( !pBindings )
68 return nullptr;
69 SfxDispatcher* pDispacher = pBindings ->GetDispatcher();
70 if( !pDispacher )
71 return nullptr;
72 SfxViewFrame* pFrame = pDispacher->GetFrame();
73 if( !pFrame )
74 return nullptr;
75 SfxViewShell* pViewShell = pFrame->GetViewShell();
76 if( !pViewShell )
77 return nullptr;
78 return dynamic_cast<ScTabViewShell*>( pViewShell );
82 #endif // INCLUDED_SC_SOURCE_UI_INC_CHILDWINDOWWRAPPER_HXX
84 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */