Stop leaking all ScPostIt instances.
[LibreOffice.git] / sc / source / ui / inc / ChildWindowWrapper.hxx
bloba9bc144eabdd3c6e23667ce77bfa0de540882934
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 #ifndef CHILD_WINDOW_WRAPPER_HXX
12 #define CHILD_WINDOW_WRAPPER_HXX
14 #include <sfx2/basedlgs.hxx>
15 #include <sfx2/dispatch.hxx>
16 #include <sfx2/viewfrm.hxx>
17 #include <sfx2/childwin.hxx>
19 #include "tabvwsh.hxx"
21 template <sal_Int16 WindowID>
22 class ChildWindowWrapper : public SfxChildWindow
24 public:
25 ChildWindowWrapper( Window* pParentP, sal_uInt16 nId,
26 SfxBindings* pBindings, SfxChildWinInfo* pInfo ) :
27 SfxChildWindow(pParentP, nId)
29 ScTabViewShell* pViewShell = getTabViewShell( pBindings );
30 if (!pViewShell)
31 pViewShell = PTR_CAST( ScTabViewShell, SfxViewShell::Current() );
32 OSL_ENSURE(pViewShell, "Missing view shell!");
34 if (pViewShell)
35 pWindow = pViewShell->CreateRefDialog( pBindings, this, pInfo, pParentP, WindowID );
36 else
37 pWindow = NULL;
39 if (pViewShell && !pWindow)
40 pViewShell->GetViewFrame()->SetChildWindow( nId, false );
43 static SfxChildWindow* CreateImpl(
44 Window *pParent, sal_uInt16 nId,
45 SfxBindings *pBindings, SfxChildWinInfo* pInfo )
47 SfxChildWindow* pWindow = new ChildWindowWrapper(pParent, nId, pBindings, pInfo);
48 return pWindow;
51 static void RegisterChildWindow (
52 sal_Bool bVisible = sal_False,
53 SfxModule* pModule = NULL,
54 sal_uInt16 nFlags = 0)
56 SfxChildWinFactory* pFactory = new SfxChildWinFactory(ChildWindowWrapper::CreateImpl, WindowID, CHILDWIN_NOPOS );
57 pFactory->aInfo.nFlags |= nFlags;
58 pFactory->aInfo.bVisible = bVisible;
59 SfxChildWindow::RegisterChildWindow(pModule, pFactory);
62 virtual SfxChildWinInfo GetInfo() const
64 SfxChildWinInfo aInfo = SfxChildWindow::GetInfo();
65 ((SfxModelessDialog*)GetWindow())->FillInfo( aInfo );
66 return aInfo;
69 static sal_uInt16 GetChildWindowId()
71 return WindowID;
74 private:
75 static ScTabViewShell* getTabViewShell( SfxBindings *pBindings )
77 if( !pBindings )
78 return NULL;
79 SfxDispatcher* pDispacher = pBindings ->GetDispatcher();
80 if( !pDispacher )
81 return NULL;
82 SfxViewFrame* pFrame = pDispacher->GetFrame();
83 if( !pFrame )
84 return NULL;
85 SfxViewShell* pViewShell = pFrame->GetViewShell();
86 if( !pViewShell )
87 return NULL;
88 return dynamic_cast<ScTabViewShell*>( pViewShell );
92 #endif // CHILD_WINDOW_WRAPPER_HXX
94 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */