LibreOffice Module sc (master) 1
ChildWindowWrapper.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 */
10
11#pragma once
12
13#include <sfx2/dispatch.hxx>
14#include <sfx2/viewfrm.hxx>
15#include <sfx2/childwin.hxx>
16#include <osl/diagnose.h>
17
18#include "tabvwsh.hxx"
19
20template <sal_Int16 WindowID>
22{
23public:
24 ChildControllerWrapper(vcl::Window* pParentP, sal_uInt16 nId,
25 SfxBindings* pBindings, const SfxChildWinInfo* pInfo)
26 : SfxChildWindow(pParentP, nId)
27 {
28 ScTabViewShell* pViewShell = getTabViewShell( pBindings );
29 if (!pViewShell)
30 pViewShell = dynamic_cast< ScTabViewShell *>( SfxViewShell::Current() );
31 OSL_ENSURE(pViewShell, "Missing view shell!");
32
33 if (pViewShell)
34 SetController(pViewShell->CreateRefDialogController(pBindings, this, pInfo, pParentP->GetFrameWeld(), WindowID));
35
36 if (pViewShell && !GetController())
37 pViewShell->GetViewFrame().SetChildWindow( nId, false );
38 }
39
40 static std::unique_ptr<SfxChildWindow> CreateImpl(
41 vcl::Window *pParent, sal_uInt16 nId,
42 SfxBindings *pBindings, SfxChildWinInfo* pInfo )
43 {
44 return std::make_unique<ChildControllerWrapper>(pParent, nId, pBindings, pInfo);
45 }
46
47 static void RegisterChildWindow (
48 bool bVisible = false,
49 SfxModule* pModule = nullptr,
50 SfxChildWindowFlags nFlags = SfxChildWindowFlags::NONE)
51 {
53 aFactory.aInfo.nFlags |= nFlags;
54 aFactory.aInfo.bVisible = bVisible;
55 SfxChildWindow::RegisterChildWindow(pModule, aFactory);
56 }
57
58 static sal_uInt16 GetChildWindowId()
59 {
60 return WindowID;
61 }
62
63private:
64 static ScTabViewShell* getTabViewShell( const SfxBindings *pBindings )
65 {
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 );
78 }
79};
80
81/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
SfxChildWindowFlags
#define CHILDWIN_NOPOS
static sal_uInt16 GetChildWindowId()
static ScTabViewShell * getTabViewShell(const SfxBindings *pBindings)
ChildControllerWrapper(vcl::Window *pParentP, sal_uInt16 nId, SfxBindings *pBindings, const SfxChildWinInfo *pInfo)
static void RegisterChildWindow(bool bVisible=false, SfxModule *pModule=nullptr, SfxChildWindowFlags nFlags=SfxChildWindowFlags::NONE)
static std::unique_ptr< SfxChildWindow > CreateImpl(vcl::Window *pParent, sal_uInt16 nId, SfxBindings *pBindings, SfxChildWinInfo *pInfo)
std::shared_ptr< SfxModelessDialogController > CreateRefDialogController(SfxBindings *pB, SfxChildWindow *pCW, const SfxChildWinInfo *pInfo, weld::Window *pParent, sal_uInt16 nSlotId)
Definition: tabvwshc.cxx:115
SfxDispatcher * GetDispatcher() const
void SetController(std::shared_ptr< SfxDialogController > controller)
static void RegisterChildWindow(SfxModule *, const SfxChildWinFactory &)
VclPtr< vcl::Window > pParent
std::shared_ptr< SfxDialogController > & GetController()
SfxViewFrame * GetFrame() const
SfxViewShell * GetViewShell() const
void SetChildWindow(sal_uInt16 nId, bool bVisible, bool bSetFocus=true)
SfxViewFrame & GetViewFrame() const
static SAL_WARN_UNUSED_RESULT SfxViewShell * Current()
weld::Window * GetFrameWeld() const
sal_Int16 nId
SfxChildWinInfo aInfo
SfxChildWindowFlags nFlags
bool bVisible