tdf#130857 qt weld: Implement QtInstanceWidget::strip_mnemonic
[LibreOffice.git] / sc / source / ui / inc / ChildWindowWrapper.hxx
blob926e456c87cecb20e8eee99209e7c1d1149d5753
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 #pragma once
13 #include <sfx2/dispatch.hxx>
14 #include <sfx2/viewfrm.hxx>
15 #include <sfx2/childwin.hxx>
16 #include <osl/diagnose.h>
18 #include "tabvwsh.hxx"
20 template <sal_Int16 WindowID>
21 class ChildControllerWrapper : public SfxChildWindow
23 public:
24 ChildControllerWrapper(vcl::Window* pParentP, sal_uInt16 nId,
25 SfxBindings* pBindings, SfxChildWinInfo* pInfo)
26 : SfxChildWindow(pParentP, nId)
28 ScTabViewShell* pViewShell = getTabViewShell( pBindings );
29 if (!pViewShell)
30 pViewShell = dynamic_cast< ScTabViewShell *>( SfxViewShell::Current() );
31 OSL_ENSURE(pViewShell, "Missing view shell!");
33 if (pViewShell)
34 SetController(pViewShell->CreateRefDialogController(pBindings, this, pInfo, pParentP->GetFrameWeld(), WindowID));
36 if (pViewShell && !GetController())
37 pViewShell->GetViewFrame().SetChildWindow( nId, false );
40 static std::unique_ptr<SfxChildWindow> CreateImpl(
41 vcl::Window *pParent, sal_uInt16 nId,
42 SfxBindings *pBindings, SfxChildWinInfo* pInfo )
44 return std::make_unique<ChildControllerWrapper>(pParent, nId, pBindings, pInfo);
47 static void RegisterChildWindow (
48 bool bVisible = false,
49 SfxModule* pModule = nullptr,
50 SfxChildWindowFlags nFlags = SfxChildWindowFlags::NONE)
52 SfxChildWinFactory aFactory(ChildControllerWrapper::CreateImpl, WindowID, CHILDWIN_NOPOS );
53 aFactory.aInfo.nFlags |= nFlags;
54 aFactory.aInfo.bVisible = bVisible;
55 SfxChildWindow::RegisterChildWindow(pModule, aFactory);
58 static sal_uInt16 GetChildWindowId()
60 return WindowID;
63 private:
64 static ScTabViewShell* getTabViewShell( const SfxBindings *pBindings )
66 if( !pBindings )
67 return nullptr;
68 SfxDispatcher* pDispacher = pBindings ->GetDispatcher();
69 if( !pDispacher )
70 return nullptr;
71 SfxViewFrame* pFrame = pDispacher->GetFrame();
72 if( !pFrame )
73 return nullptr;
74 SfxViewShell* pViewShell = pFrame->GetViewShell();
75 if( !pViewShell )
76 return nullptr;
77 return dynamic_cast<ScTabViewShell*>( pViewShell );
81 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */