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 
20 template <sal_Int16 WindowID>
22 {
23 public:
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  {
52  auto pFactory = std::make_unique<SfxChildWinFactory>(ChildControllerWrapper::CreateImpl, WindowID, CHILDWIN_NOPOS );
53  pFactory->aInfo.nFlags |= nFlags;
54  pFactory->aInfo.bVisible = bVisible;
55  SfxChildWindow::RegisterChildWindow(pModule, std::move(pFactory));
56  }
57 
58  static sal_uInt16 GetChildWindowId()
59  {
60  return WindowID;
61  }
62 
63 private:
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: */
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()