Version 5.2.6.1, tag libreoffice-5.2.6.1
[LibreOffice.git] / sc / source / ui / inc / ChildWindowWrapper.hxx
blob1f4920d7a56621c5fd26a74da41b31efd4ac3383
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 ChildWindowWrapper : public SfxChildWindow
24 public:
25 ChildWindowWrapper( vcl::Window* pParentP, sal_uInt16 nId,
26 SfxBindings* pBindings, 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 SetWindow( pViewShell->CreateRefDialog( pBindings, this, pInfo, pParentP, WindowID ) );
36 else
37 SetWindow( nullptr );
39 if (pViewShell && !GetWindow())
40 pViewShell->GetViewFrame()->SetChildWindow( nId, false );
43 static SfxChildWindow* CreateImpl(
44 vcl::Window *pParent, sal_uInt16 nId,
45 SfxBindings *pBindings, SfxChildWinInfo* pInfo )
47 SfxChildWindow* pWindow = new ChildWindowWrapper(pParent, nId, pBindings, pInfo);
48 return pWindow;
51 static void RegisterChildWindow (
52 bool bVisible = false,
53 SfxModule* pModule = nullptr,
54 SfxChildWindowFlags nFlags = SfxChildWindowFlags::NONE)
56 SfxChildWinFactory* pFactory = new SfxChildWinFactory(ChildWindowWrapper::CreateImpl, WindowID, CHILDWIN_NOPOS );
57 pFactory->aInfo.nFlags |= nFlags;
58 pFactory->aInfo.bVisible = bVisible;
59 SfxChildWindow::RegisterChildWindow(pModule, pFactory);
62 virtual SfxChildWinInfo GetInfo() const override
64 SfxChildWinInfo aInfo = SfxChildWindow::GetInfo();
65 static_cast<SfxModelessDialog*>(GetWindow())->FillInfo( aInfo );
66 return aInfo;
69 static sal_uInt16 GetChildWindowId()
71 return WindowID;
74 private:
75 static ScTabViewShell* getTabViewShell( SfxBindings *pBindings )
77 if( !pBindings )
78 return nullptr;
79 SfxDispatcher* pDispacher = pBindings ->GetDispatcher();
80 if( !pDispacher )
81 return nullptr;
82 SfxViewFrame* pFrame = pDispacher->GetFrame();
83 if( !pFrame )
84 return nullptr;
85 SfxViewShell* pViewShell = pFrame->GetViewShell();
86 if( !pViewShell )
87 return nullptr;
88 return dynamic_cast<ScTabViewShell*>( pViewShell );
92 #endif // INCLUDED_SC_SOURCE_UI_INC_CHILDWINDOWWRAPPER_HXX
94 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */