1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #ifndef SD_FRAMEWORK_VIEW_SHELL_WRAPPER_HXX
25 #define SD_FRAMEWORK_VIEW_SHELL_WRAPPER_HXX
26 
27 #include "MutexOwner.hxx"
28 #include <com/sun/star/drawing/framework/XView.hpp>
29 #include <com/sun/star/drawing/framework/XRelocatableResource.hpp>
30 #include <com/sun/star/awt/XWindow.hpp>
31 #include <com/sun/star/lang/XUnoTunnel.hpp>
32 #include <osl/mutex.hxx>
33 #include <cppuhelper/compbase4.hxx>
34 #include <cppuhelper/implbase1.hxx>
35 
36 #include <boost/shared_ptr.hpp>
37 
38 namespace {
39 
40 typedef ::cppu::WeakComponentImplHelper4    <   ::com::sun::star::lang::XUnoTunnel
41                                             ,   ::com::sun::star::awt::XWindowListener
42                                             ,   ::com::sun::star::drawing::framework::XRelocatableResource
43                                             ,   ::com::sun::star::drawing::framework::XView
44                                             >   ViewShellWrapperInterfaceBase;
45 
46 } // end of anonymous namespace.
47 
48 namespace sd { class ViewShell; }
49 
50 namespace sd { namespace framework {
51 
52 /** This class wraps ViewShell objects and makes them look like an XView.
53     Most importantly it provides a tunnel to the ViewShell implementation.
54     Then it forwards size changes of the pane window to the view shell.
55 */
56 class ViewShellWrapper  :private sd::MutexOwner
57                         ,public ViewShellWrapperInterfaceBase
58 {
59 public:
60     /** Create a new ViewShellWrapper object that wraps the given ViewShell
61         object.
62         @param pViewShell
63             The ViewShell object to wrap.
64         @param rsViewURL
65             URL of the view type of the wrapped view shell.
66         @param rxWindow
67             This window reference is optional.  When a valid reference is
68             given then size changes of the referenced window are forwarded
69             to the ViewShell object.
70     */
71     ViewShellWrapper (
72         ::boost::shared_ptr<ViewShell> pViewShell,
73         const ::com::sun::star::uno::Reference<
74             ::com::sun::star::drawing::framework::XResourceId>& rxViewId,
75         const ::com::sun::star::uno::Reference<com::sun::star::awt::XWindow>& rxWindow);
76     virtual ~ViewShellWrapper (void);
77 
78     virtual void SAL_CALL disposing (void);
79 
80     static const ::com::sun::star::uno::Sequence<sal_Int8>& getUnoTunnelId (void);
81 
82     /** This method is typically used together with the XUnoTunnel interface
83         to obtain a pointer to the wrapped ViewShell object for a given
84         XView object.
85     */
86     ::boost::shared_ptr<ViewShell> GetViewShell (void);
87 
88     // XUnoTunnel
89 
90     virtual sal_Int64 SAL_CALL getSomething (const com::sun::star::uno::Sequence<sal_Int8>& rId)
91         throw (com::sun::star::uno::RuntimeException);
92 
93     // XResource
94 
95     virtual ::com::sun::star::uno::Reference<com::sun::star::drawing::framework::XResourceId>
96         SAL_CALL getResourceId (void)
97         throw (com::sun::star::uno::RuntimeException);
98 
99     virtual sal_Bool SAL_CALL isAnchorOnly (void)
100         throw (com::sun::star::uno::RuntimeException);
101 
102 
103     // XRelocatableResource
104 
105     virtual sal_Bool SAL_CALL relocateToAnchor (
106         const ::com::sun::star::uno::Reference<
107             com::sun::star::drawing::framework::XResource>& xResource)
108         throw (com::sun::star::uno::RuntimeException);
109 
110 
111     // XWindowListener
112 
113     virtual void SAL_CALL windowResized(
114         const ::com::sun::star::awt::WindowEvent& rEvent)
115         throw (::com::sun::star::uno::RuntimeException);
116 
117     virtual void SAL_CALL windowMoved(
118         const ::com::sun::star::awt::WindowEvent& rEvent)
119         throw (::com::sun::star::uno::RuntimeException);
120 
121     virtual void SAL_CALL windowShown(
122         const ::com::sun::star::lang::EventObject& rEvent)
123         throw (::com::sun::star::uno::RuntimeException);
124 
125     virtual void SAL_CALL windowHidden(
126         const ::com::sun::star::lang::EventObject& rEvent)
127         throw (::com::sun::star::uno::RuntimeException);
128 
129 
130     // XEventListener
131 
132     virtual void SAL_CALL disposing(
133         const com::sun::star::lang::EventObject& rEvent)
134         throw (com::sun::star::uno::RuntimeException);
135 
136 private:
137     ::boost::shared_ptr< ViewShell >                                                            mpViewShell;
138     const ::com::sun::star::uno::Reference< com::sun::star::drawing::framework::XResourceId >   mxViewId;
139     ::com::sun::star::uno::Reference<com::sun::star::awt::XWindow >                             mxWindow;
140 };
141 
142 } } // end of namespace sd::framework
143 
144 #endif
145