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 
17 #include "tabvwsh.hxx"
18 
19 template <sal_Int16 WindowID>
21 {
22 public:
23  ChildControllerWrapper(vcl::Window* pParentP, sal_uInt16 nId,
24  SfxBindings* pBindings, const SfxChildWinInfo* pInfo)
25  : SfxChildWindow(pParentP, nId)
26  {
27  ScTabViewShell* pViewShell = getTabViewShell( pBindings );
28  if (!pViewShell)
29  pViewShell = dynamic_cast< ScTabViewShell *>( SfxViewShell::Current() );
30  OSL_ENSURE(pViewShell, "Missing view shell!");
31 
32  if (pViewShell)
33  SetController(pViewShell->CreateRefDialogController(pBindings, this, pInfo, pParentP->GetFrameWeld(), WindowID));
34 
35  if (pViewShell && !GetController())
36  pViewShell->GetViewFrame()->SetChildWindow( nId, false );
37  }
38 
39  static std::unique_ptr<SfxChildWindow> CreateImpl(
40  vcl::Window *pParent, sal_uInt16 nId,
41  SfxBindings *pBindings, SfxChildWinInfo* pInfo )
42  {
43  return std::make_unique<ChildControllerWrapper>(pParent, nId, pBindings, pInfo);
44  }
45 
46  static void RegisterChildWindow (
47  bool bVisible = false,
48  SfxModule* pModule = nullptr,
49  SfxChildWindowFlags nFlags = SfxChildWindowFlags::NONE)
50  {
51  auto pFactory = std::make_unique<SfxChildWinFactory>(ChildControllerWrapper::CreateImpl, WindowID, CHILDWIN_NOPOS );
52  pFactory->aInfo.nFlags |= nFlags;
53  pFactory->aInfo.bVisible = bVisible;
54  SfxChildWindow::RegisterChildWindow(pModule, std::move(pFactory));
55  }
56 
57  static sal_uInt16 GetChildWindowId()
58  {
59  return WindowID;
60  }
61 
62 private:
63  static ScTabViewShell* getTabViewShell( const SfxBindings *pBindings )
64  {
65  if( !pBindings )
66  return nullptr;
67  SfxDispatcher* pDispacher = pBindings ->GetDispatcher();
68  if( !pDispacher )
69  return nullptr;
70  SfxViewFrame* pFrame = pDispacher->GetFrame();
71  if( !pFrame )
72  return nullptr;
73  SfxViewShell* pViewShell = pFrame->GetViewShell();
74  if( !pViewShell )
75  return nullptr;
76  return dynamic_cast<ScTabViewShell*>( pViewShell );
77  }
78 };
79 
80 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
std::shared_ptr< SfxDialogController > & GetController()
SfxViewFrame * GetViewFrame() const
bool bVisible
static void RegisterChildWindow(bool bVisible=false, SfxModule *pModule=nullptr, SfxChildWindowFlags nFlags=SfxChildWindowFlags::NONE)
weld::Window * GetFrameWeld() const
static std::unique_ptr< SfxChildWindow > CreateImpl(vcl::Window *pParent, sal_uInt16 nId, SfxBindings *pBindings, SfxChildWinInfo *pInfo)
SfxChildWindowFlags
static SfxViewShell * Current()
#define CHILDWIN_NOPOS
static void RegisterChildWindow(SfxModule *, std::unique_ptr< SfxChildWinFactory >)
VclPtr< vcl::Window > pParent
ChildControllerWrapper(vcl::Window *pParentP, sal_uInt16 nId, SfxBindings *pBindings, const SfxChildWinInfo *pInfo)
SfxViewShell * GetViewShell() const
static ScTabViewShell * getTabViewShell(const SfxBindings *pBindings)
std::shared_ptr< SfxModelessDialogController > CreateRefDialogController(SfxBindings *pB, SfxChildWindow *pCW, const SfxChildWinInfo *pInfo, weld::Window *pParent, sal_uInt16 nSlotId)
Definition: tabvwshc.cxx:111
SfxViewFrame * GetFrame() const
void SetController(std::shared_ptr< SfxDialogController > controller)
void SetChildWindow(sal_uInt16 nId, bool bVisible, bool bSetFocus=true)
SfxDispatcher * GetDispatcher() const
static sal_uInt16 GetChildWindowId()