1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 #ifndef SD_FRAMEWORK_VIEW_SHELL_WRAPPER_HXX
29 #define SD_FRAMEWORK_VIEW_SHELL_WRAPPER_HXX
30 
31 #include "MutexOwner.hxx"
32 #include <com/sun/star/drawing/framework/XView.hpp>
33 #include <com/sun/star/drawing/framework/XRelocatableResource.hpp>
34 #include <com/sun/star/awt/XWindow.hpp>
35 #include <com/sun/star/lang/XUnoTunnel.hpp>
36 #include <osl/mutex.hxx>
37 #include <cppuhelper/compbase4.hxx>
38 #include <cppuhelper/implbase1.hxx>
39 
40 #include <boost/shared_ptr.hpp>
41 
42 namespace {
43 
44 typedef ::cppu::WeakComponentImplHelper4    <   ::com::sun::star::lang::XUnoTunnel
45                                             ,   ::com::sun::star::awt::XWindowListener
46                                             ,   ::com::sun::star::drawing::framework::XRelocatableResource
47                                             ,   ::com::sun::star::drawing::framework::XView
48                                             >   ViewShellWrapperInterfaceBase;
49 
50 } // end of anonymous namespace.
51 
52 namespace sd { class ViewShell; }
53 
54 namespace sd { namespace framework {
55 
56 /** This class wraps ViewShell objects and makes them look like an XView.
57     Most importantly it provides a tunnel to the ViewShell implementation.
58     Then it forwards size changes of the pane window to the view shell.
59 */
60 class ViewShellWrapper  :private sd::MutexOwner
61                         ,public ViewShellWrapperInterfaceBase
62 {
63 public:
64     /** Create a new ViewShellWrapper object that wraps the given ViewShell
65         object.
66         @param pViewShell
67             The ViewShell object to wrap.
68         @param rsViewURL
69             URL of the view type of the wrapped view shell.
70         @param rxWindow
71             This window reference is optional.  When a valid reference is
72             given then size changes of the referenced window are forwarded
73             to the ViewShell object.
74     */
75     ViewShellWrapper (
76         ::boost::shared_ptr<ViewShell> pViewShell,
77         const ::com::sun::star::uno::Reference<
78             ::com::sun::star::drawing::framework::XResourceId>& rxViewId,
79         const ::com::sun::star::uno::Reference<com::sun::star::awt::XWindow>& rxWindow);
80     virtual ~ViewShellWrapper (void);
81 
82     virtual void SAL_CALL disposing (void);
83 
84     static const ::com::sun::star::uno::Sequence<sal_Int8>& getUnoTunnelId (void);
85 
86     /** This method is typically used together with the XUnoTunnel interface
87         to obtain a pointer to the wrapped ViewShell object for a given
88         XView object.
89     */
90     ::boost::shared_ptr<ViewShell> GetViewShell (void);
91 
92     // XUnoTunnel
93 
94     virtual sal_Int64 SAL_CALL getSomething (const com::sun::star::uno::Sequence<sal_Int8>& rId)
95         throw (com::sun::star::uno::RuntimeException);
96 
97     // XResource
98 
99     virtual ::com::sun::star::uno::Reference<com::sun::star::drawing::framework::XResourceId>
100         SAL_CALL getResourceId (void)
101         throw (com::sun::star::uno::RuntimeException);
102 
103     virtual sal_Bool SAL_CALL isAnchorOnly (void)
104         throw (com::sun::star::uno::RuntimeException);
105 
106 
107     // XRelocatableResource
108 
109     virtual sal_Bool SAL_CALL relocateToAnchor (
110         const ::com::sun::star::uno::Reference<
111             com::sun::star::drawing::framework::XResource>& xResource)
112         throw (com::sun::star::uno::RuntimeException);
113 
114 
115     // XWindowListener
116 
117     virtual void SAL_CALL windowResized(
118         const ::com::sun::star::awt::WindowEvent& rEvent)
119         throw (::com::sun::star::uno::RuntimeException);
120 
121     virtual void SAL_CALL windowMoved(
122         const ::com::sun::star::awt::WindowEvent& rEvent)
123         throw (::com::sun::star::uno::RuntimeException);
124 
125     virtual void SAL_CALL windowShown(
126         const ::com::sun::star::lang::EventObject& rEvent)
127         throw (::com::sun::star::uno::RuntimeException);
128 
129     virtual void SAL_CALL windowHidden(
130         const ::com::sun::star::lang::EventObject& rEvent)
131         throw (::com::sun::star::uno::RuntimeException);
132 
133 
134     // XEventListener
135 
136     virtual void SAL_CALL disposing(
137         const com::sun::star::lang::EventObject& rEvent)
138         throw (com::sun::star::uno::RuntimeException);
139 
140 private:
141     ::boost::shared_ptr< ViewShell >                                                            mpViewShell;
142     const ::com::sun::star::uno::Reference< com::sun::star::drawing::framework::XResourceId >   mxViewId;
143     ::com::sun::star::uno::Reference<com::sun::star::awt::XWindow >                             mxWindow;
144 };
145 
146 } } // end of namespace sd::framework
147 
148 #endif
149