15b190011SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
35b190011SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
45b190011SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
55b190011SAndrew Rist  * distributed with this work for additional information
65b190011SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
75b190011SAndrew Rist  * to you under the Apache License, Version 2.0 (the
85b190011SAndrew Rist  * "License"); you may not use this file except in compliance
95b190011SAndrew Rist  * with the License.  You may obtain a copy of the License at
105b190011SAndrew Rist  *
115b190011SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
125b190011SAndrew Rist  *
135b190011SAndrew Rist  * Unless required by applicable law or agreed to in writing,
145b190011SAndrew Rist  * software distributed under the License is distributed on an
155b190011SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
165b190011SAndrew Rist  * KIND, either express or implied.  See the License for the
175b190011SAndrew Rist  * specific language governing permissions and limitations
185b190011SAndrew Rist  * under the License.
195b190011SAndrew Rist  *
205b190011SAndrew Rist  *************************************************************/
215b190011SAndrew Rist 
225b190011SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir #include "precompiled_sd.hxx"
25cdf0e10cSrcweir 
26cdf0e10cSrcweir #include "framework/ViewShellWrapper.hxx"
27cdf0e10cSrcweir #include "framework/Pane.hxx"
28cdf0e10cSrcweir #include "ViewShell.hxx"
29cdf0e10cSrcweir #include "Window.hxx"
30cdf0e10cSrcweir 
31cdf0e10cSrcweir #include <com/sun/star/drawing/framework/XPane.hpp>
32cdf0e10cSrcweir #include <com/sun/star/lang/DisposedException.hpp>
33cdf0e10cSrcweir 
34cdf0e10cSrcweir #include <rtl/uuid.h>
35cdf0e10cSrcweir #include <toolkit/helper/vclunohelper.hxx>
36cdf0e10cSrcweir #include <comphelper/sequence.hxx>
37cdf0e10cSrcweir #include <cppuhelper/typeprovider.hxx>
38cdf0e10cSrcweir #include <vcl/svapp.hxx>
39cdf0e10cSrcweir #include <vos/mutex.hxx>
40cdf0e10cSrcweir #include <tools/diagnose_ex.h>
41cdf0e10cSrcweir 
42cdf0e10cSrcweir 
43cdf0e10cSrcweir using namespace ::com::sun::star;
44cdf0e10cSrcweir using namespace ::com::sun::star::uno;
45cdf0e10cSrcweir using namespace ::com::sun::star::drawing::framework;
46cdf0e10cSrcweir 
47cdf0e10cSrcweir using ::com::sun::star::awt::XWindow;
48cdf0e10cSrcweir using ::com::sun::star::rendering::XCanvas;
49cdf0e10cSrcweir using ::com::sun::star::lang::DisposedException;
50cdf0e10cSrcweir 
51cdf0e10cSrcweir using ::rtl::OUString;
52cdf0e10cSrcweir 
53cdf0e10cSrcweir namespace sd { namespace framework {
54cdf0e10cSrcweir 
ViewShellWrapper(::boost::shared_ptr<ViewShell> pViewShell,const Reference<XResourceId> & rxViewId,const Reference<awt::XWindow> & rxWindow)55cdf0e10cSrcweir ViewShellWrapper::ViewShellWrapper (
56cdf0e10cSrcweir     ::boost::shared_ptr<ViewShell> pViewShell,
57cdf0e10cSrcweir     const Reference<XResourceId>& rxViewId,
58cdf0e10cSrcweir     const Reference<awt::XWindow>& rxWindow)
59cdf0e10cSrcweir     : ViewShellWrapperInterfaceBase(MutexOwner::maMutex),
60cdf0e10cSrcweir       mpViewShell(pViewShell),
61cdf0e10cSrcweir       mxViewId(rxViewId),
62cdf0e10cSrcweir       mxWindow(rxWindow)
63cdf0e10cSrcweir {
64cdf0e10cSrcweir     if (rxWindow.is())
65cdf0e10cSrcweir     {
66cdf0e10cSrcweir         rxWindow->addWindowListener(this);
67*b862c97cSHerbert Dürr         if( bool(pViewShell) )
68cdf0e10cSrcweir         {
69cdf0e10cSrcweir             pViewShell->Resize();
70cdf0e10cSrcweir         }
71cdf0e10cSrcweir     }
72cdf0e10cSrcweir }
73cdf0e10cSrcweir 
74cdf0e10cSrcweir 
75cdf0e10cSrcweir 
76cdf0e10cSrcweir 
~ViewShellWrapper(void)77cdf0e10cSrcweir ViewShellWrapper::~ViewShellWrapper (void)
78cdf0e10cSrcweir {
79cdf0e10cSrcweir }
80cdf0e10cSrcweir 
81cdf0e10cSrcweir 
82cdf0e10cSrcweir 
83cdf0e10cSrcweir 
disposing(void)84cdf0e10cSrcweir void SAL_CALL ViewShellWrapper::disposing (void)
85cdf0e10cSrcweir {
86cdf0e10cSrcweir     ::osl::MutexGuard aGuard( maMutex );
87cdf0e10cSrcweir 
88cdf0e10cSrcweir     OSL_TRACE("disposing ViewShellWrapper %x", this);
89cdf0e10cSrcweir     Reference<awt::XWindow> xWindow (mxWindow);
90cdf0e10cSrcweir     if (xWindow.is())
91cdf0e10cSrcweir     {
92cdf0e10cSrcweir         OSL_TRACE("removing ViewShellWrapper %x from window listener at %x", this, mxWindow.get());
93cdf0e10cSrcweir         xWindow->removeWindowListener(this);
94cdf0e10cSrcweir     }
95cdf0e10cSrcweir 
96cdf0e10cSrcweir     mpViewShell.reset();
97cdf0e10cSrcweir }
98cdf0e10cSrcweir 
99cdf0e10cSrcweir 
100cdf0e10cSrcweir 
101cdf0e10cSrcweir 
GetViewShell(void)102cdf0e10cSrcweir ::boost::shared_ptr<ViewShell> ViewShellWrapper::GetViewShell (void)
103cdf0e10cSrcweir {
104cdf0e10cSrcweir     return mpViewShell;
105cdf0e10cSrcweir }
106cdf0e10cSrcweir 
107cdf0e10cSrcweir 
108cdf0e10cSrcweir 
109cdf0e10cSrcweir 
110cdf0e10cSrcweir //----- XResource -------------------------------------------------------------
111cdf0e10cSrcweir 
getResourceId(void)112cdf0e10cSrcweir Reference<XResourceId> SAL_CALL ViewShellWrapper::getResourceId (void)
113cdf0e10cSrcweir     throw (RuntimeException)
114cdf0e10cSrcweir {
115cdf0e10cSrcweir     return mxViewId;
116cdf0e10cSrcweir }
117cdf0e10cSrcweir 
118cdf0e10cSrcweir 
119cdf0e10cSrcweir 
120cdf0e10cSrcweir 
isAnchorOnly(void)121cdf0e10cSrcweir sal_Bool SAL_CALL ViewShellWrapper::isAnchorOnly (void)
122cdf0e10cSrcweir     throw (RuntimeException)
123cdf0e10cSrcweir {
124cdf0e10cSrcweir     return false;
125cdf0e10cSrcweir }
126cdf0e10cSrcweir 
127cdf0e10cSrcweir 
128cdf0e10cSrcweir 
129cdf0e10cSrcweir 
130cdf0e10cSrcweir //----- XRelocatableResource --------------------------------------------------
131cdf0e10cSrcweir 
relocateToAnchor(const Reference<XResource> & xResource)132cdf0e10cSrcweir sal_Bool SAL_CALL ViewShellWrapper::relocateToAnchor (
133cdf0e10cSrcweir     const Reference<XResource>& xResource)
134cdf0e10cSrcweir     throw (RuntimeException)
135cdf0e10cSrcweir {
136cdf0e10cSrcweir     sal_Bool bResult (false);
137cdf0e10cSrcweir 
138cdf0e10cSrcweir     Reference<XPane> xPane (xResource, UNO_QUERY);
139cdf0e10cSrcweir     if (xPane.is())
140cdf0e10cSrcweir     {
141cdf0e10cSrcweir         // Detach from the window of the old pane.
142cdf0e10cSrcweir         Reference<awt::XWindow> xWindow (mxWindow);
143cdf0e10cSrcweir         if (xWindow.is())
144cdf0e10cSrcweir             xWindow->removeWindowListener(this);
145cdf0e10cSrcweir         mxWindow = NULL;
146cdf0e10cSrcweir 
147cdf0e10cSrcweir         if (mpViewShell.get() != NULL)
148cdf0e10cSrcweir         {
149cdf0e10cSrcweir             ::Window* pWindow = VCLUnoHelper::GetWindow(xPane->getWindow());
150cdf0e10cSrcweir             if (pWindow != NULL && mpViewShell->RelocateToParentWindow(pWindow))
151cdf0e10cSrcweir             {
152cdf0e10cSrcweir                 bResult = sal_True;
153cdf0e10cSrcweir 
154cdf0e10cSrcweir                 // Attach to the window of the new pane.
155cdf0e10cSrcweir                 xWindow = Reference<awt::XWindow>(xPane->getWindow(), UNO_QUERY);
156cdf0e10cSrcweir                 if (xWindow.is())
157cdf0e10cSrcweir                 {
158cdf0e10cSrcweir                     xWindow->addWindowListener(this);
159cdf0e10cSrcweir                     mpViewShell->Resize();
160cdf0e10cSrcweir                 }
161cdf0e10cSrcweir             }
162cdf0e10cSrcweir         }
163cdf0e10cSrcweir     }
164cdf0e10cSrcweir 
165cdf0e10cSrcweir     return bResult;
166cdf0e10cSrcweir }
167cdf0e10cSrcweir 
168cdf0e10cSrcweir 
169cdf0e10cSrcweir 
170cdf0e10cSrcweir 
171cdf0e10cSrcweir //----- XUnoTunnel ------------------------------------------------------------
172cdf0e10cSrcweir 
getUnoTunnelId(void)173cdf0e10cSrcweir const Sequence<sal_Int8>& ViewShellWrapper::getUnoTunnelId (void)
174cdf0e10cSrcweir {
175cdf0e10cSrcweir 	static Sequence<sal_Int8>* pSequence = NULL;
176cdf0e10cSrcweir 	if (pSequence == NULL)
177cdf0e10cSrcweir 	{
178cdf0e10cSrcweir         const ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() );
179cdf0e10cSrcweir 		if (pSequence == NULL)
180cdf0e10cSrcweir 		{
181cdf0e10cSrcweir 			static ::com::sun::star::uno::Sequence<sal_Int8> aSequence (16);
182cdf0e10cSrcweir 			rtl_createUuid((sal_uInt8*)aSequence.getArray(), 0, sal_True);
183cdf0e10cSrcweir 			pSequence = &aSequence;
184cdf0e10cSrcweir 		}
185cdf0e10cSrcweir 	}
186cdf0e10cSrcweir 	return *pSequence;
187cdf0e10cSrcweir }
188cdf0e10cSrcweir 
189cdf0e10cSrcweir 
190cdf0e10cSrcweir 
191cdf0e10cSrcweir 
getSomething(const Sequence<sal_Int8> & rId)192cdf0e10cSrcweir sal_Int64 SAL_CALL ViewShellWrapper::getSomething (const Sequence<sal_Int8>& rId)
193cdf0e10cSrcweir     throw (RuntimeException)
194cdf0e10cSrcweir {
195cdf0e10cSrcweir     sal_Int64 nResult = 0;
196cdf0e10cSrcweir 
197cdf0e10cSrcweir     if (rId.getLength() == 16
198cdf0e10cSrcweir         && rtl_compareMemory(getUnoTunnelId().getConstArray(), rId.getConstArray(), 16) == 0)
199cdf0e10cSrcweir 	{
200cdf0e10cSrcweir 		nResult = reinterpret_cast<sal_Int64>(this);
201cdf0e10cSrcweir 	}
202cdf0e10cSrcweir 
203cdf0e10cSrcweir     return nResult;
204cdf0e10cSrcweir }
205cdf0e10cSrcweir 
206cdf0e10cSrcweir 
207cdf0e10cSrcweir 
208cdf0e10cSrcweir 
209cdf0e10cSrcweir //===== awt::XWindowListener ==================================================
210cdf0e10cSrcweir 
windowResized(const awt::WindowEvent & rEvent)211cdf0e10cSrcweir void SAL_CALL ViewShellWrapper::windowResized (const awt::WindowEvent& rEvent)
212cdf0e10cSrcweir     throw (RuntimeException)
213cdf0e10cSrcweir {
214cdf0e10cSrcweir     (void)rEvent;
215cdf0e10cSrcweir     ViewShell* pViewShell (mpViewShell.get());
216cdf0e10cSrcweir     if (pViewShell != NULL)
217cdf0e10cSrcweir         pViewShell->Resize();
218cdf0e10cSrcweir }
219cdf0e10cSrcweir 
220cdf0e10cSrcweir 
221cdf0e10cSrcweir 
222cdf0e10cSrcweir 
windowMoved(const awt::WindowEvent & rEvent)223cdf0e10cSrcweir void SAL_CALL ViewShellWrapper::windowMoved (const awt::WindowEvent& rEvent)
224cdf0e10cSrcweir     throw (RuntimeException)
225cdf0e10cSrcweir {
226cdf0e10cSrcweir     (void)rEvent;
227cdf0e10cSrcweir }
228cdf0e10cSrcweir 
229cdf0e10cSrcweir 
230cdf0e10cSrcweir 
231cdf0e10cSrcweir 
windowShown(const lang::EventObject & rEvent)232cdf0e10cSrcweir void SAL_CALL ViewShellWrapper::windowShown (const lang::EventObject& rEvent)
233cdf0e10cSrcweir     throw (RuntimeException)
234cdf0e10cSrcweir {
235cdf0e10cSrcweir     (void)rEvent;
236cdf0e10cSrcweir     ViewShell* pViewShell (mpViewShell.get());
237cdf0e10cSrcweir     if (pViewShell != NULL)
238cdf0e10cSrcweir         pViewShell->Resize();
239cdf0e10cSrcweir }
240cdf0e10cSrcweir 
241cdf0e10cSrcweir 
242cdf0e10cSrcweir 
243cdf0e10cSrcweir 
windowHidden(const lang::EventObject & rEvent)244cdf0e10cSrcweir void SAL_CALL ViewShellWrapper::windowHidden (const lang::EventObject& rEvent)
245cdf0e10cSrcweir     throw (RuntimeException)
246cdf0e10cSrcweir {
247cdf0e10cSrcweir     (void)rEvent;
248cdf0e10cSrcweir }
249cdf0e10cSrcweir 
250cdf0e10cSrcweir 
251cdf0e10cSrcweir 
252cdf0e10cSrcweir 
253cdf0e10cSrcweir //===== XEventListener ========================================================
254cdf0e10cSrcweir 
disposing(const lang::EventObject & rEvent)255cdf0e10cSrcweir void SAL_CALL ViewShellWrapper::disposing (const lang::EventObject& rEvent)
256cdf0e10cSrcweir     throw (RuntimeException)
257cdf0e10cSrcweir {
258cdf0e10cSrcweir     if (rEvent.Source == mxWindow)
259cdf0e10cSrcweir         mxWindow = NULL;
260cdf0e10cSrcweir }
261cdf0e10cSrcweir 
262cdf0e10cSrcweir 
263cdf0e10cSrcweir } } // end of namespace sd::framework
264