Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : :
30 : : #include "framework/ViewShellWrapper.hxx"
31 : : #include "framework/Pane.hxx"
32 : : #include "taskpane/ToolPanelViewShell.hxx"
33 : : #include "ViewShell.hxx"
34 : : #include "Window.hxx"
35 : :
36 : : #include <com/sun/star/drawing/framework/XPane.hpp>
37 : : #include <com/sun/star/lang/DisposedException.hpp>
38 : :
39 : : #include <toolkit/helper/vclunohelper.hxx>
40 : : #include <comphelper/sequence.hxx>
41 : : #include <comphelper/servicehelper.hxx>
42 : : #include <cppuhelper/typeprovider.hxx>
43 : : #include <vcl/svapp.hxx>
44 : : #include <osl/mutex.hxx>
45 : : #include <tools/diagnose_ex.h>
46 : :
47 : :
48 : : using namespace ::com::sun::star;
49 : : using namespace ::com::sun::star::uno;
50 : : using namespace ::com::sun::star::drawing::framework;
51 : :
52 : : using ::com::sun::star::awt::XWindow;
53 : : using ::com::sun::star::rendering::XCanvas;
54 : : using ::com::sun::star::lang::DisposedException;
55 : :
56 : : using ::rtl::OUString;
57 : : using ::sd::toolpanel::ToolPanelViewShell;
58 : :
59 : : namespace sd { namespace framework {
60 : :
61 : 286 : ViewShellWrapper::ViewShellWrapper (
62 : : ::boost::shared_ptr<ViewShell> pViewShell,
63 : : const Reference<XResourceId>& rxViewId,
64 : : const Reference<awt::XWindow>& rxWindow)
65 : : : ViewShellWrapperInterfaceBase(MutexOwner::maMutex),
66 : : mpViewShell(pViewShell),
67 : : mxViewId(rxViewId),
68 [ + - ]: 286 : mxWindow(rxWindow)
69 : : {
70 [ + - ]: 286 : if (rxWindow.is())
71 : : {
72 [ + - ][ + - ]: 286 : rxWindow->addWindowListener(this);
[ + - ]
73 [ + - ]: 286 : if (pViewShell != NULL)
74 : : {
75 [ + - ]: 286 : pViewShell->Resize();
76 : : }
77 : : }
78 : 286 : }
79 : :
80 : :
81 : :
82 : :
83 [ + - ][ + - ]: 286 : ViewShellWrapper::~ViewShellWrapper (void)
84 : : {
85 [ - + ]: 572 : }
86 : :
87 : :
88 : :
89 : :
90 : 286 : void SAL_CALL ViewShellWrapper::disposing (void)
91 : : {
92 [ + - ]: 286 : ::osl::MutexGuard aGuard( maMutex );
93 : :
94 : : OSL_TRACE("disposing ViewShellWrapper %x", this);
95 : 286 : Reference<awt::XWindow> xWindow (mxWindow);
96 [ + + ]: 286 : if (xWindow.is())
97 : : {
98 : : OSL_TRACE("removing ViewShellWrapper %x from window listener at %x", this, mxWindow.get());
99 [ + - ][ + - ]: 130 : xWindow->removeWindowListener(this);
[ + - ]
100 : : }
101 : :
102 [ + - ][ + - ]: 286 : mpViewShell.reset();
103 : 286 : }
104 : :
105 : :
106 : :
107 : :
108 : 7083 : ::boost::shared_ptr<ViewShell> ViewShellWrapper::GetViewShell (void)
109 : : {
110 : 7083 : return mpViewShell;
111 : : }
112 : :
113 : :
114 : :
115 : :
116 : : //----- XResource -------------------------------------------------------------
117 : :
118 : 605 : Reference<XResourceId> SAL_CALL ViewShellWrapper::getResourceId (void)
119 : : throw (RuntimeException)
120 : : {
121 : 605 : return mxViewId;
122 : : }
123 : :
124 : :
125 : :
126 : :
127 : 904 : sal_Bool SAL_CALL ViewShellWrapper::isAnchorOnly (void)
128 : : throw (RuntimeException)
129 : : {
130 : 904 : return false;
131 : : }
132 : :
133 : :
134 : :
135 : :
136 : : //----- XRelocatableResource --------------------------------------------------
137 : :
138 : 156 : sal_Bool SAL_CALL ViewShellWrapper::relocateToAnchor (
139 : : const Reference<XResource>& xResource)
140 : : throw (RuntimeException)
141 : : {
142 : 156 : sal_Bool bResult (false);
143 : :
144 [ + - ]: 156 : Reference<XPane> xPane (xResource, UNO_QUERY);
145 [ + - ]: 156 : if (xPane.is())
146 : : {
147 : : // Detach from the window of the old pane.
148 : 156 : Reference<awt::XWindow> xWindow (mxWindow);
149 [ + - ]: 156 : if (xWindow.is())
150 [ + - ][ + - ]: 156 : xWindow->removeWindowListener(this);
[ + - ]
151 [ + - ]: 156 : mxWindow = NULL;
152 : :
153 [ + - ]: 156 : if (mpViewShell.get() != NULL)
154 : : {
155 [ + - ][ + - ]: 156 : ::Window* pWindow = VCLUnoHelper::GetWindow(xPane->getWindow());
[ + - ]
156 [ + - ][ + - ]: 156 : if (pWindow != NULL && mpViewShell->RelocateToParentWindow(pWindow))
[ + - ][ + - ]
157 : : {
158 : 156 : bResult = sal_True;
159 : :
160 : : // Attach to the window of the new pane.
161 [ + - ][ + - ]: 156 : xWindow = Reference<awt::XWindow>(xPane->getWindow(), UNO_QUERY);
[ + - ][ + - ]
162 [ + - ]: 156 : if (xWindow.is())
163 : : {
164 [ + - ][ + - ]: 156 : xWindow->addWindowListener(this);
[ + - ]
165 [ + - ]: 156 : mpViewShell->Resize();
166 : : }
167 : : }
168 : 156 : }
169 : : }
170 : :
171 : 156 : return bResult;
172 : : }
173 : :
174 : :
175 : :
176 : :
177 : : //----- XUnoTunnel ------------------------------------------------------------
178 : :
179 : : namespace
180 : : {
181 : : class theViewShellWrapperUnoTunnelId : public rtl::Static< UnoTunnelIdInit, theViewShellWrapperUnoTunnelId> {};
182 : : }
183 : :
184 : 14166 : const Sequence<sal_Int8>& ViewShellWrapper::getUnoTunnelId (void)
185 : : {
186 : 14166 : return theViewShellWrapperUnoTunnelId::get().getSeq();
187 : : }
188 : :
189 : :
190 : :
191 : :
192 : 7083 : sal_Int64 SAL_CALL ViewShellWrapper::getSomething (const Sequence<sal_Int8>& rId)
193 : : throw (RuntimeException)
194 : : {
195 : 7083 : sal_Int64 nResult = 0;
196 : :
197 [ + - + - ]: 14166 : if (rId.getLength() == 16
[ + - ]
198 : 7083 : && memcmp(getUnoTunnelId().getConstArray(), rId.getConstArray(), 16) == 0)
199 : : {
200 : 7083 : nResult = reinterpret_cast<sal_Int64>(this);
201 : : }
202 : :
203 : 7083 : return nResult;
204 : : }
205 : :
206 : :
207 : :
208 : :
209 : : //===== awt::XWindowListener ==================================================
210 : :
211 : 480 : void SAL_CALL ViewShellWrapper::windowResized (const awt::WindowEvent& rEvent)
212 : : throw (RuntimeException)
213 : : {
214 : : (void)rEvent;
215 : 480 : ViewShell* pViewShell (mpViewShell.get());
216 [ + - ]: 480 : if (pViewShell != NULL)
217 : 480 : pViewShell->Resize();
218 : 480 : }
219 : :
220 : :
221 : :
222 : :
223 : 484 : void SAL_CALL ViewShellWrapper::windowMoved (const awt::WindowEvent& rEvent)
224 : : throw (RuntimeException)
225 : : {
226 : : (void)rEvent;
227 : 484 : }
228 : :
229 : :
230 : :
231 : :
232 : 249 : void SAL_CALL ViewShellWrapper::windowShown (const lang::EventObject& rEvent)
233 : : throw (RuntimeException)
234 : : {
235 : : (void)rEvent;
236 : 249 : ViewShell* pViewShell (mpViewShell.get());
237 [ + - ]: 249 : if (pViewShell != NULL)
238 : 249 : pViewShell->Resize();
239 : 249 : }
240 : :
241 : :
242 : :
243 : :
244 : 0 : void SAL_CALL ViewShellWrapper::windowHidden (const lang::EventObject& rEvent)
245 : : throw (RuntimeException)
246 : : {
247 : : (void)rEvent;
248 : 0 : }
249 : :
250 : :
251 : :
252 : :
253 : : //===== XEventListener ========================================================
254 : :
255 : 156 : void SAL_CALL ViewShellWrapper::disposing (const lang::EventObject& rEvent)
256 : : throw (RuntimeException)
257 : : {
258 [ - + ]: 156 : if (rEvent.Source == mxWindow)
259 : 0 : mxWindow = NULL;
260 : 156 : }
261 : :
262 : :
263 : : } } // end of namespace sd::framework
264 : :
265 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|