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 #ifndef INCLUDED_SC_SOURCE_UI_INC_CHILDWINDOWWRAPPER_HXX
12 #define INCLUDED_SC_SOURCE_UI_INC_CHILDWINDOWWRAPPER_HXX
13 
14 #include <sfx2/basedlgs.hxx>
15 #include <sfx2/dispatch.hxx>
16 #include <sfx2/viewfrm.hxx>
17 #include <sfx2/childwin.hxx>
18 
19 #include "tabvwsh.hxx"
20 
21 template <sal_Int16 WindowID>
23 {
24 public:
25  ChildControllerWrapper(vcl::Window* pParentP, sal_uInt16 nId,
26  SfxBindings* pBindings, const SfxChildWinInfo* pInfo)
27  : SfxChildWindow(pParentP, nId)
28  {
29  ScTabViewShell* pViewShell = getTabViewShell( pBindings );
30  if (!pViewShell)
31  pViewShell = dynamic_cast< ScTabViewShell *>( SfxViewShell::Current() );
32  OSL_ENSURE(pViewShell, "Missing view shell!");
33 
34  if (pViewShell)
35  SetController(pViewShell->CreateRefDialogController(pBindings, this, pInfo, pParentP->GetFrameWeld(), WindowID));
36 
37  if (pViewShell && !GetController())
38  pViewShell->GetViewFrame()->SetChildWindow( nId, false );
39  }
40 
41  static std::unique_ptr<SfxChildWindow> CreateImpl(
42  vcl::Window *pParent, sal_uInt16 nId,
43  SfxBindings *pBindings, SfxChildWinInfo* pInfo )
44  {
45  return std::make_unique<ChildControllerWrapper>(pParent, nId, pBindings, pInfo);
46  }
47 
48  static void RegisterChildWindow (
49  bool bVisible = false,
50  SfxModule* pModule = nullptr,
51  SfxChildWindowFlags nFlags = SfxChildWindowFlags::NONE)
52  {
53  auto pFactory = std::make_unique<SfxChildWinFactory>(ChildControllerWrapper::CreateImpl, WindowID, CHILDWIN_NOPOS );
54  pFactory->aInfo.nFlags |= nFlags;
55  pFactory->aInfo.bVisible = bVisible;
56  SfxChildWindow::RegisterChildWindow(pModule, std::move(pFactory));
57  }
58 
59  static sal_uInt16 GetChildWindowId()
60  {
61  return WindowID;
62  }
63 
64 private:
65  static ScTabViewShell* getTabViewShell( const SfxBindings *pBindings )
66  {
67  if( !pBindings )
68  return nullptr;
69  SfxDispatcher* pDispacher = pBindings ->GetDispatcher();
70  if( !pDispacher )
71  return nullptr;
72  SfxViewFrame* pFrame = pDispacher->GetFrame();
73  if( !pFrame )
74  return nullptr;
75  SfxViewShell* pViewShell = pFrame->GetViewShell();
76  if( !pViewShell )
77  return nullptr;
78  return dynamic_cast<ScTabViewShell*>( pViewShell );
79  }
80 };
81 
82 #endif // INCLUDED_SC_SOURCE_UI_INC_CHILDWINDOWWRAPPER_HXX
83 
84 /* 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()