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 #include "precompiled_sd.hxx"
25
26 #include "framework/ViewShellWrapper.hxx"
27 #include "framework/Pane.hxx"
28 #include "ViewShell.hxx"
29 #include "Window.hxx"
30
31 #include <com/sun/star/drawing/framework/XPane.hpp>
32 #include <com/sun/star/lang/DisposedException.hpp>
33
34 #include <rtl/uuid.h>
35 #include <toolkit/helper/vclunohelper.hxx>
36 #include <comphelper/sequence.hxx>
37 #include <cppuhelper/typeprovider.hxx>
38 #include <vcl/svapp.hxx>
39 #include <vos/mutex.hxx>
40 #include <tools/diagnose_ex.h>
41
42
43 using namespace ::com::sun::star;
44 using namespace ::com::sun::star::uno;
45 using namespace ::com::sun::star::drawing::framework;
46
47 using ::com::sun::star::awt::XWindow;
48 using ::com::sun::star::rendering::XCanvas;
49 using ::com::sun::star::lang::DisposedException;
50
51 using ::rtl::OUString;
52
53 namespace sd { namespace framework {
54
ViewShellWrapper(::boost::shared_ptr<ViewShell> pViewShell,const Reference<XResourceId> & rxViewId,const Reference<awt::XWindow> & rxWindow)55 ViewShellWrapper::ViewShellWrapper (
56 ::boost::shared_ptr<ViewShell> pViewShell,
57 const Reference<XResourceId>& rxViewId,
58 const Reference<awt::XWindow>& rxWindow)
59 : ViewShellWrapperInterfaceBase(MutexOwner::maMutex),
60 mpViewShell(pViewShell),
61 mxViewId(rxViewId),
62 mxWindow(rxWindow)
63 {
64 if (rxWindow.is())
65 {
66 rxWindow->addWindowListener(this);
67 if( bool(pViewShell) )
68 {
69 pViewShell->Resize();
70 }
71 }
72 }
73
74
75
76
~ViewShellWrapper(void)77 ViewShellWrapper::~ViewShellWrapper (void)
78 {
79 }
80
81
82
83
disposing(void)84 void SAL_CALL ViewShellWrapper::disposing (void)
85 {
86 ::osl::MutexGuard aGuard( maMutex );
87
88 OSL_TRACE("disposing ViewShellWrapper %x", this);
89 Reference<awt::XWindow> xWindow (mxWindow);
90 if (xWindow.is())
91 {
92 OSL_TRACE("removing ViewShellWrapper %x from window listener at %x", this, mxWindow.get());
93 xWindow->removeWindowListener(this);
94 }
95
96 mpViewShell.reset();
97 }
98
99
100
101
GetViewShell(void)102 ::boost::shared_ptr<ViewShell> ViewShellWrapper::GetViewShell (void)
103 {
104 return mpViewShell;
105 }
106
107
108
109
110 //----- XResource -------------------------------------------------------------
111
getResourceId(void)112 Reference<XResourceId> SAL_CALL ViewShellWrapper::getResourceId (void)
113 {
114 return mxViewId;
115 }
116
117
118
119
isAnchorOnly(void)120 sal_Bool SAL_CALL ViewShellWrapper::isAnchorOnly (void)
121 {
122 return false;
123 }
124
125
126
127
128 //----- XRelocatableResource --------------------------------------------------
129
relocateToAnchor(const Reference<XResource> & xResource)130 sal_Bool SAL_CALL ViewShellWrapper::relocateToAnchor (
131 const Reference<XResource>& xResource)
132 {
133 sal_Bool bResult (false);
134
135 Reference<XPane> xPane (xResource, UNO_QUERY);
136 if (xPane.is())
137 {
138 // Detach from the window of the old pane.
139 Reference<awt::XWindow> xWindow (mxWindow);
140 if (xWindow.is())
141 xWindow->removeWindowListener(this);
142 mxWindow = NULL;
143
144 if (mpViewShell.get() != NULL)
145 {
146 ::Window* pWindow = VCLUnoHelper::GetWindow(xPane->getWindow());
147 if (pWindow != NULL && mpViewShell->RelocateToParentWindow(pWindow))
148 {
149 bResult = sal_True;
150
151 // Attach to the window of the new pane.
152 xWindow = Reference<awt::XWindow>(xPane->getWindow(), UNO_QUERY);
153 if (xWindow.is())
154 {
155 xWindow->addWindowListener(this);
156 mpViewShell->Resize();
157 }
158 }
159 }
160 }
161
162 return bResult;
163 }
164
165
166
167
168 //----- XUnoTunnel ------------------------------------------------------------
169
getUnoTunnelId(void)170 const Sequence<sal_Int8>& ViewShellWrapper::getUnoTunnelId (void)
171 {
172 static Sequence<sal_Int8>* pSequence = NULL;
173 if (pSequence == NULL)
174 {
175 const ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() );
176 if (pSequence == NULL)
177 {
178 static ::com::sun::star::uno::Sequence<sal_Int8> aSequence (16);
179 rtl_createUuid((sal_uInt8*)aSequence.getArray(), 0, sal_True);
180 pSequence = &aSequence;
181 }
182 }
183 return *pSequence;
184 }
185
186
187
188
getSomething(const Sequence<sal_Int8> & rId)189 sal_Int64 SAL_CALL ViewShellWrapper::getSomething (const Sequence<sal_Int8>& rId)
190 {
191 sal_Int64 nResult = 0;
192
193 if (rId.getLength() == 16
194 && rtl_compareMemory(getUnoTunnelId().getConstArray(), rId.getConstArray(), 16) == 0)
195 {
196 nResult = reinterpret_cast<sal_Int64>(this);
197 }
198
199 return nResult;
200 }
201
202
203
204
205 //===== awt::XWindowListener ==================================================
206
windowResized(const awt::WindowEvent & rEvent)207 void SAL_CALL ViewShellWrapper::windowResized (const awt::WindowEvent& rEvent)
208 {
209 (void)rEvent;
210 ViewShell* pViewShell (mpViewShell.get());
211 if (pViewShell != NULL)
212 pViewShell->Resize();
213 }
214
215
216
217
windowMoved(const awt::WindowEvent & rEvent)218 void SAL_CALL ViewShellWrapper::windowMoved (const awt::WindowEvent& rEvent)
219 {
220 (void)rEvent;
221 }
222
223
224
225
windowShown(const lang::EventObject & rEvent)226 void SAL_CALL ViewShellWrapper::windowShown (const lang::EventObject& rEvent)
227 {
228 (void)rEvent;
229 ViewShell* pViewShell (mpViewShell.get());
230 if (pViewShell != NULL)
231 pViewShell->Resize();
232 }
233
234
235
236
windowHidden(const lang::EventObject & rEvent)237 void SAL_CALL ViewShellWrapper::windowHidden (const lang::EventObject& rEvent)
238 {
239 (void)rEvent;
240 }
241
242
243
244
245 //===== XEventListener ========================================================
246
disposing(const lang::EventObject & rEvent)247 void SAL_CALL ViewShellWrapper::disposing (const lang::EventObject& rEvent)
248 {
249 if (rEvent.Source == mxWindow)
250 mxWindow = NULL;
251 }
252
253
254 } } // end of namespace sd::framework
255