Line data Source code
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 CHILD_WINDOW_WRAPPER_HXX
12 : #define CHILD_WINDOW_WRAPPER_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>
22 0 : class ChildWindowWrapper : public SfxChildWindow
23 : {
24 : public:
25 0 : ChildWindowWrapper( Window* pParentP, sal_uInt16 nId,
26 : SfxBindings* pBindings, SfxChildWinInfo* pInfo ) :
27 0 : SfxChildWindow(pParentP, nId)
28 : {
29 0 : ScTabViewShell* pViewShell = getTabViewShell( pBindings );
30 0 : if (!pViewShell)
31 0 : pViewShell = PTR_CAST( ScTabViewShell, SfxViewShell::Current() );
32 : OSL_ENSURE(pViewShell, "Missing view shell!");
33 :
34 0 : if (pViewShell)
35 0 : pWindow = pViewShell->CreateRefDialog( pBindings, this, pInfo, pParentP, WindowID );
36 : else
37 0 : pWindow = NULL;
38 :
39 0 : if (pViewShell && !pWindow)
40 0 : pViewShell->GetViewFrame()->SetChildWindow( nId, false );
41 0 : }
42 :
43 0 : static SfxChildWindow* CreateImpl(
44 : Window *pParent, sal_uInt16 nId,
45 : SfxBindings *pBindings, SfxChildWinInfo* pInfo )
46 : {
47 0 : SfxChildWindow* pWindow = new ChildWindowWrapper(pParent, nId, pBindings, pInfo);
48 0 : return pWindow;
49 : }
50 :
51 0 : static void RegisterChildWindow (
52 : bool bVisible = false,
53 : SfxModule* pModule = NULL,
54 : sal_uInt16 nFlags = 0)
55 : {
56 0 : SfxChildWinFactory* pFactory = new SfxChildWinFactory(ChildWindowWrapper::CreateImpl, WindowID, CHILDWIN_NOPOS );
57 0 : pFactory->aInfo.nFlags |= nFlags;
58 0 : pFactory->aInfo.bVisible = bVisible;
59 0 : SfxChildWindow::RegisterChildWindow(pModule, pFactory);
60 0 : }
61 :
62 0 : virtual SfxChildWinInfo GetInfo() const SAL_OVERRIDE
63 : {
64 0 : SfxChildWinInfo aInfo = SfxChildWindow::GetInfo();
65 0 : ((SfxModelessDialog*)GetWindow())->FillInfo( aInfo );
66 0 : return aInfo;
67 : }
68 :
69 0 : static sal_uInt16 GetChildWindowId()
70 : {
71 0 : return WindowID;
72 : }
73 :
74 : private:
75 0 : static ScTabViewShell* getTabViewShell( SfxBindings *pBindings )
76 : {
77 0 : if( !pBindings )
78 0 : return NULL;
79 0 : SfxDispatcher* pDispacher = pBindings ->GetDispatcher();
80 0 : if( !pDispacher )
81 0 : return NULL;
82 0 : SfxViewFrame* pFrame = pDispacher->GetFrame();
83 0 : if( !pFrame )
84 0 : return NULL;
85 0 : SfxViewShell* pViewShell = pFrame->GetViewShell();
86 0 : if( !pViewShell )
87 0 : return NULL;
88 0 : return dynamic_cast<ScTabViewShell*>( pViewShell );
89 : }
90 : };
91 :
92 : #endif // CHILD_WINDOW_WRAPPER_HXX
93 :
94 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|