xref: /AOO41X/main/sdext/source/presenter/PresenterPaneBorderManager.cxx (revision c142477ce2bdb32de904d9995ebf0add7aef9609)
1*c142477cSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*c142477cSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*c142477cSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*c142477cSAndrew Rist  * distributed with this work for additional information
6*c142477cSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*c142477cSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*c142477cSAndrew Rist  * "License"); you may not use this file except in compliance
9*c142477cSAndrew Rist  * with the License.  You may obtain a copy of the License at
10cdf0e10cSrcweir  *
11*c142477cSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
13*c142477cSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*c142477cSAndrew Rist  * software distributed under the License is distributed on an
15*c142477cSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*c142477cSAndrew Rist  * KIND, either express or implied.  See the License for the
17*c142477cSAndrew Rist  * specific language governing permissions and limitations
18*c142477cSAndrew Rist  * under the License.
19cdf0e10cSrcweir  *
20*c142477cSAndrew Rist  *************************************************************/
21*c142477cSAndrew Rist 
22*c142477cSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_sdext.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir // The body of this file is only used when PresenterWindowManager defines
28cdf0e10cSrcweir // the preprocessor symbol ENABLE_PANE_RESIZING, which by default is not the
29cdf0e10cSrcweir // case.
30cdf0e10cSrcweir #ifdef ENABLE_PANE_RESIZING
31cdf0e10cSrcweir 
32cdf0e10cSrcweir #include "PresenterPaneBorderManager.hxx"
33cdf0e10cSrcweir #include "PresenterController.hxx"
34cdf0e10cSrcweir #include "PresenterPaintManager.hxx"
35cdf0e10cSrcweir #include <com/sun/star/awt/PosSize.hpp>
36cdf0e10cSrcweir #include <com/sun/star/awt/SystemPointer.hpp>
37cdf0e10cSrcweir #include <com/sun/star/awt/WindowAttribute.hpp>
38cdf0e10cSrcweir #include <com/sun/star/awt/WindowDescriptor.hpp>
39cdf0e10cSrcweir #include <com/sun/star/awt/WindowClass.hpp>
40cdf0e10cSrcweir #include <com/sun/star/awt/XWindow2.hpp>
41cdf0e10cSrcweir #include <com/sun/star/awt/XWindowPeer.hpp>
42cdf0e10cSrcweir #include <com/sun/star/lang/XMultiComponentFactory.hpp>
43cdf0e10cSrcweir #include <cppuhelper/compbase1.hxx>
44cdf0e10cSrcweir #include <osl/mutex.hxx>
45cdf0e10cSrcweir #include <boost/weak_ptr.hpp>
46cdf0e10cSrcweir 
47cdf0e10cSrcweir using namespace ::com::sun::star;
48cdf0e10cSrcweir using namespace ::com::sun::star::uno;
49cdf0e10cSrcweir using ::rtl::OUString;
50cdf0e10cSrcweir 
51cdf0e10cSrcweir namespace sdext { namespace presenter {
52cdf0e10cSrcweir 
53cdf0e10cSrcweir //===== Service ===============================================================
54cdf0e10cSrcweir 
55cdf0e10cSrcweir 
getImplementationName_static(void)56cdf0e10cSrcweir OUString PresenterPaneBorderManager::getImplementationName_static (void)
57cdf0e10cSrcweir {
58cdf0e10cSrcweir     return OUString::createFromAscii("com.sun.star.comp.Draw.PresenterPaneBorderManager");
59cdf0e10cSrcweir }
60cdf0e10cSrcweir 
61cdf0e10cSrcweir 
62cdf0e10cSrcweir 
63cdf0e10cSrcweir 
getSupportedServiceNames_static(void)64cdf0e10cSrcweir Sequence<OUString> PresenterPaneBorderManager::getSupportedServiceNames_static (void)
65cdf0e10cSrcweir {
66cdf0e10cSrcweir 	static const ::rtl::OUString sServiceName(
67cdf0e10cSrcweir         ::rtl::OUString::createFromAscii("com.sun.star.drawing.PresenterPaneBorderManager"));
68cdf0e10cSrcweir 	return Sequence<rtl::OUString>(&sServiceName, 1);
69cdf0e10cSrcweir }
70cdf0e10cSrcweir 
71cdf0e10cSrcweir 
72cdf0e10cSrcweir 
73cdf0e10cSrcweir 
Create(const Reference<uno::XComponentContext> & rxContext)74cdf0e10cSrcweir Reference<XInterface> PresenterPaneBorderManager::Create (const Reference<uno::XComponentContext>& rxContext)
75cdf0e10cSrcweir     SAL_THROW((css::uno::Exception))
76cdf0e10cSrcweir {
77cdf0e10cSrcweir     return Reference<XInterface>(static_cast<XWeak*>(
78cdf0e10cSrcweir         new PresenterPaneBorderManager(rxContext, NULL)));
79cdf0e10cSrcweir }
80cdf0e10cSrcweir 
81cdf0e10cSrcweir 
82cdf0e10cSrcweir 
83cdf0e10cSrcweir 
84cdf0e10cSrcweir //===== PresenterPaneBorderManager ============================================
85cdf0e10cSrcweir 
PresenterPaneBorderManager(const Reference<XComponentContext> & rxContext,const::rtl::Reference<PresenterController> & rpPresenterController)86cdf0e10cSrcweir PresenterPaneBorderManager::PresenterPaneBorderManager (
87cdf0e10cSrcweir     const Reference<XComponentContext>& rxContext,
88cdf0e10cSrcweir     const ::rtl::Reference<PresenterController>& rpPresenterController)
89cdf0e10cSrcweir     : PresenterPaneBorderManagerInterfaceBase(m_aMutex),
90cdf0e10cSrcweir       mpPresenterController(rpPresenterController),
91cdf0e10cSrcweir       mxComponentContext(rxContext),
92cdf0e10cSrcweir       mxPresenterHelper(),
93cdf0e10cSrcweir       maWindowList(),
94cdf0e10cSrcweir       mnPointerType(),
95cdf0e10cSrcweir       maDragAnchor(),
96cdf0e10cSrcweir       meDragType(Outside),
97cdf0e10cSrcweir       mxOuterDragWindow(),
98cdf0e10cSrcweir       mxInnerDragWindow(),
99cdf0e10cSrcweir       mxPointer()
100cdf0e10cSrcweir {
101cdf0e10cSrcweir     Reference<lang::XMultiComponentFactory> xFactory (rxContext->getServiceManager());
102cdf0e10cSrcweir     if (xFactory.is())
103cdf0e10cSrcweir     {
104cdf0e10cSrcweir         mxPointer = Reference<awt::XPointer>(
105cdf0e10cSrcweir             xFactory->createInstanceWithContext(
106cdf0e10cSrcweir                 OUString::createFromAscii("com.sun.star.awt.Pointer"),
107cdf0e10cSrcweir                 rxContext),
108cdf0e10cSrcweir             UNO_QUERY_THROW);
109cdf0e10cSrcweir 
110cdf0e10cSrcweir         mxPresenterHelper = Reference<drawing::XPresenterHelper>(
111cdf0e10cSrcweir             xFactory->createInstanceWithContext(
112cdf0e10cSrcweir                 OUString::createFromAscii("com.sun.star.comp.Draw.PresenterHelper"),
113cdf0e10cSrcweir                 rxContext),
114cdf0e10cSrcweir             UNO_QUERY_THROW);
115cdf0e10cSrcweir     }
116cdf0e10cSrcweir }
117cdf0e10cSrcweir 
118cdf0e10cSrcweir 
119cdf0e10cSrcweir 
120cdf0e10cSrcweir 
~PresenterPaneBorderManager(void)121cdf0e10cSrcweir PresenterPaneBorderManager::~PresenterPaneBorderManager (void)
122cdf0e10cSrcweir {
123cdf0e10cSrcweir }
124cdf0e10cSrcweir 
125cdf0e10cSrcweir 
126cdf0e10cSrcweir 
127cdf0e10cSrcweir 
disposing(void)128cdf0e10cSrcweir void PresenterPaneBorderManager::disposing (void)
129cdf0e10cSrcweir {
130cdf0e10cSrcweir     WindowList::const_iterator iDescriptor;
131cdf0e10cSrcweir     for (iDescriptor=maWindowList.begin(); iDescriptor!=maWindowList.end(); ++iDescriptor)
132cdf0e10cSrcweir     {
133cdf0e10cSrcweir         iDescriptor->first->removeMouseListener(this);
134cdf0e10cSrcweir         iDescriptor->first->removeMouseMotionListener(this);
135cdf0e10cSrcweir     }
136cdf0e10cSrcweir     maWindowList.clear();
137cdf0e10cSrcweir }
138cdf0e10cSrcweir 
139cdf0e10cSrcweir 
140cdf0e10cSrcweir 
141cdf0e10cSrcweir 
142cdf0e10cSrcweir namespace {
143cdf0e10cSrcweir const static sal_Int32 mnOutside = 0;
144cdf0e10cSrcweir const static sal_Int32 mnLeft = 0x01;
145cdf0e10cSrcweir const static sal_Int32 mnHorizontalCenter = 0x02;
146cdf0e10cSrcweir const static sal_Int32 mnRight = 0x04;
147cdf0e10cSrcweir const static sal_Int32 mnTop = 0x10;
148cdf0e10cSrcweir const static sal_Int32 mnVerticalCenter = 0x20;
149cdf0e10cSrcweir const static sal_Int32 mnBottom = 0x40;
150cdf0e10cSrcweir }
151cdf0e10cSrcweir 
152cdf0e10cSrcweir PresenterPaneBorderManager::BorderElement
ClassifyBorderElementUnderMouse(const Reference<awt::XWindow> & rxOuterWindow,const Reference<awt::XWindow> & rxInnerWindow,const awt::Point aPosition) const153cdf0e10cSrcweir     PresenterPaneBorderManager::ClassifyBorderElementUnderMouse (
154cdf0e10cSrcweir         const Reference<awt::XWindow>& rxOuterWindow,
155cdf0e10cSrcweir         const Reference<awt::XWindow>& rxInnerWindow,
156cdf0e10cSrcweir         const awt::Point aPosition) const
157cdf0e10cSrcweir {
158cdf0e10cSrcweir     OSL_ASSERT(rxOuterWindow.is());
159cdf0e10cSrcweir     OSL_ASSERT(rxInnerWindow.is());
160cdf0e10cSrcweir 
161cdf0e10cSrcweir     awt::Rectangle aOuterBox (rxOuterWindow->getPosSize());
162cdf0e10cSrcweir     const awt::Rectangle aInnerBox (rxInnerWindow->getPosSize());
163cdf0e10cSrcweir 
164cdf0e10cSrcweir     // Coordinates of the pointer position are given in the window
165cdf0e10cSrcweir     // coordinate system.  Therefore the upper left corner of the outer box
166cdf0e10cSrcweir     // is the origin.
167cdf0e10cSrcweir     aOuterBox.X = 0;
168cdf0e10cSrcweir     aOuterBox.Y = 0;
169cdf0e10cSrcweir 
170cdf0e10cSrcweir     sal_Int32 nCode = 0;
171cdf0e10cSrcweir 
172cdf0e10cSrcweir     // Add horizontal classification to nCode.
173cdf0e10cSrcweir     if (aPosition.X < aInnerBox.X)
174cdf0e10cSrcweir         if (aPosition.X < aOuterBox.X)
175cdf0e10cSrcweir             nCode = mnOutside;
176cdf0e10cSrcweir         else
177cdf0e10cSrcweir             nCode = mnLeft;
178cdf0e10cSrcweir     else if (aPosition.X >= aInnerBox.X+aInnerBox.Width)
179cdf0e10cSrcweir         if (aPosition.X >= aOuterBox.X+aOuterBox.Width)
180cdf0e10cSrcweir             nCode = mnOutside;
181cdf0e10cSrcweir         else
182cdf0e10cSrcweir             nCode = mnRight;
183cdf0e10cSrcweir     else
184cdf0e10cSrcweir         nCode = mnHorizontalCenter;
185cdf0e10cSrcweir 
186cdf0e10cSrcweir     // Add vertical classification to nCode.
187cdf0e10cSrcweir     if (aPosition.Y < aInnerBox.Y)
188cdf0e10cSrcweir         if (aPosition.Y < aOuterBox.Y)
189cdf0e10cSrcweir             nCode |= mnOutside;
190cdf0e10cSrcweir         else
191cdf0e10cSrcweir             nCode |= mnTop;
192cdf0e10cSrcweir     else if (aPosition.Y >= aInnerBox.Y+aInnerBox.Height)
193cdf0e10cSrcweir         if (aPosition.Y >= aOuterBox.Y+aOuterBox.Height)
194cdf0e10cSrcweir             nCode |= mnOutside;
195cdf0e10cSrcweir         else
196cdf0e10cSrcweir             nCode |= mnBottom;
197cdf0e10cSrcweir     else
198cdf0e10cSrcweir         nCode |= mnVerticalCenter;
199cdf0e10cSrcweir 
200cdf0e10cSrcweir     // Translate bits in nCode into BorderElement value.
201cdf0e10cSrcweir     switch (nCode)
202cdf0e10cSrcweir     {
203cdf0e10cSrcweir         case mnOutside | mnOutside:
204cdf0e10cSrcweir         case mnOutside | mnLeft:
205cdf0e10cSrcweir         case mnOutside | mnRight:
206cdf0e10cSrcweir         case mnOutside | mnHorizontalCenter:
207cdf0e10cSrcweir         case mnTop | mnOutside:
208cdf0e10cSrcweir         case mnBottom | mnOutside:
209cdf0e10cSrcweir         case mnVerticalCenter | mnOutside:
210cdf0e10cSrcweir         default:
211cdf0e10cSrcweir             return Outside;
212cdf0e10cSrcweir 
213cdf0e10cSrcweir         case mnVerticalCenter | mnHorizontalCenter:
214cdf0e10cSrcweir             return Content;
215cdf0e10cSrcweir 
216cdf0e10cSrcweir         case mnTop | mnLeft:
217cdf0e10cSrcweir             return TopLeft;
218cdf0e10cSrcweir 
219cdf0e10cSrcweir         case mnTop | mnRight:
220cdf0e10cSrcweir             return TopRight;
221cdf0e10cSrcweir 
222cdf0e10cSrcweir         case mnTop | mnHorizontalCenter:
223cdf0e10cSrcweir             return Top;
224cdf0e10cSrcweir 
225cdf0e10cSrcweir         case mnBottom | mnLeft:
226cdf0e10cSrcweir             return BottomLeft;
227cdf0e10cSrcweir 
228cdf0e10cSrcweir         case mnBottom | mnRight:
229cdf0e10cSrcweir             return BottomRight;
230cdf0e10cSrcweir 
231cdf0e10cSrcweir         case mnBottom | mnHorizontalCenter:
232cdf0e10cSrcweir             return Bottom;
233cdf0e10cSrcweir 
234cdf0e10cSrcweir         case mnVerticalCenter | mnLeft:
235cdf0e10cSrcweir             return Left;
236cdf0e10cSrcweir 
237cdf0e10cSrcweir         case mnVerticalCenter | mnRight:
238cdf0e10cSrcweir             return Right;
239cdf0e10cSrcweir     }
240cdf0e10cSrcweir }
241cdf0e10cSrcweir 
242cdf0e10cSrcweir 
243cdf0e10cSrcweir 
244cdf0e10cSrcweir 
245cdf0e10cSrcweir //----- XInitialization -------------------------------------------------------
246cdf0e10cSrcweir 
initialize(const Sequence<Any> & rArguments)247cdf0e10cSrcweir void SAL_CALL PresenterPaneBorderManager::initialize (const Sequence<Any>& rArguments)
248cdf0e10cSrcweir     throw (Exception, RuntimeException)
249cdf0e10cSrcweir {
250cdf0e10cSrcweir     ThrowIfDisposed();
251cdf0e10cSrcweir 
252cdf0e10cSrcweir     if (rArguments.getLength()%2 == 1 && mxComponentContext.is())
253cdf0e10cSrcweir     {
254cdf0e10cSrcweir         try
255cdf0e10cSrcweir         {
256cdf0e10cSrcweir             mxParentWindow = Reference<awt::XWindow>(rArguments[0], UNO_QUERY_THROW);
257cdf0e10cSrcweir 
258cdf0e10cSrcweir             // Get the outer and inner windows from the argument list and
259cdf0e10cSrcweir             // build a window list of it.
260cdf0e10cSrcweir             for (sal_Int32 nIndex=1; nIndex<rArguments.getLength(); nIndex+=2)
261cdf0e10cSrcweir             {
262cdf0e10cSrcweir                 Reference<awt::XWindow> xOuterWindow (rArguments[nIndex], UNO_QUERY_THROW);
263cdf0e10cSrcweir                 Reference<awt::XWindow> xInnerWindow (rArguments[nIndex+1], UNO_QUERY_THROW);
264cdf0e10cSrcweir 
265cdf0e10cSrcweir                 maWindowList.push_back(WindowDescriptor(xOuterWindow,xInnerWindow));
266cdf0e10cSrcweir 
267cdf0e10cSrcweir                 xOuterWindow->addMouseListener(this);
268cdf0e10cSrcweir                 xOuterWindow->addMouseMotionListener(this);
269cdf0e10cSrcweir             }
270cdf0e10cSrcweir         }
271cdf0e10cSrcweir         catch (RuntimeException&)
272cdf0e10cSrcweir         {
273cdf0e10cSrcweir             PresenterPaneBorderManager::disposing();
274cdf0e10cSrcweir             throw;
275cdf0e10cSrcweir         }
276cdf0e10cSrcweir     }
277cdf0e10cSrcweir     else
278cdf0e10cSrcweir     {
279cdf0e10cSrcweir         throw RuntimeException(
280cdf0e10cSrcweir             OUString::createFromAscii("PresenterPane: invalid number of arguments"),
281cdf0e10cSrcweir                 static_cast<XWeak*>(this));
282cdf0e10cSrcweir     }
283cdf0e10cSrcweir }
284cdf0e10cSrcweir 
285cdf0e10cSrcweir 
286cdf0e10cSrcweir 
287cdf0e10cSrcweir 
288cdf0e10cSrcweir //----- XMouseListener --------------------------------------------------------
289cdf0e10cSrcweir 
mousePressed(const css::awt::MouseEvent & rEvent)290cdf0e10cSrcweir void SAL_CALL PresenterPaneBorderManager::mousePressed (const css::awt::MouseEvent& rEvent)
291cdf0e10cSrcweir     throw (css::uno::RuntimeException)
292cdf0e10cSrcweir {
293cdf0e10cSrcweir     ThrowIfDisposed();
294cdf0e10cSrcweir 	::osl::MutexGuard aGuard (::osl::Mutex::getGlobalMutex());
295cdf0e10cSrcweir 
296cdf0e10cSrcweir     // Find window descriptor of the window that has been clicked.
297cdf0e10cSrcweir     WindowList::const_iterator iDescriptor;
298cdf0e10cSrcweir     for (iDescriptor=maWindowList.begin(); iDescriptor!=maWindowList.end(); ++iDescriptor)
299cdf0e10cSrcweir         if (iDescriptor->first == rEvent.Source)
300cdf0e10cSrcweir             break;
301cdf0e10cSrcweir 
302cdf0e10cSrcweir     if (iDescriptor != maWindowList.end())
303cdf0e10cSrcweir     {
304cdf0e10cSrcweir         // Prepare dragging.
305cdf0e10cSrcweir         mxOuterDragWindow = iDescriptor->first;
306cdf0e10cSrcweir         mxInnerDragWindow = iDescriptor->second;
307cdf0e10cSrcweir         OSL_ASSERT(mxOuterDragWindow.is() && mxInnerDragWindow.is());
308cdf0e10cSrcweir         const awt::Rectangle aOuterBox (mxOuterDragWindow->getPosSize());
309cdf0e10cSrcweir         maDragAnchor.X = rEvent.X + aOuterBox.X;
310cdf0e10cSrcweir         maDragAnchor.Y = rEvent.Y + aOuterBox.Y;
311cdf0e10cSrcweir         meDragType = ClassifyBorderElementUnderMouse(
312cdf0e10cSrcweir             mxOuterDragWindow,
313cdf0e10cSrcweir             mxInnerDragWindow,
314cdf0e10cSrcweir             awt::Point(rEvent.X, rEvent.Y));
315cdf0e10cSrcweir     }
316cdf0e10cSrcweir }
317cdf0e10cSrcweir 
318cdf0e10cSrcweir 
319cdf0e10cSrcweir 
320cdf0e10cSrcweir 
mouseReleased(const css::awt::MouseEvent & rEvent)321cdf0e10cSrcweir void SAL_CALL PresenterPaneBorderManager::mouseReleased (const css::awt::MouseEvent& rEvent)
322cdf0e10cSrcweir     throw (css::uno::RuntimeException)
323cdf0e10cSrcweir {
324cdf0e10cSrcweir     (void)rEvent;
325cdf0e10cSrcweir     ThrowIfDisposed();
326cdf0e10cSrcweir 	::osl::MutexGuard aGuard (::osl::Mutex::getGlobalMutex());
327cdf0e10cSrcweir 
328cdf0e10cSrcweir     ReleaseMouse(mxOuterDragWindow);
329cdf0e10cSrcweir     meDragType = PresenterPaneBorderManager::Outside;
330cdf0e10cSrcweir     mxOuterDragWindow = NULL;
331cdf0e10cSrcweir     mxInnerDragWindow = NULL;
332cdf0e10cSrcweir }
333cdf0e10cSrcweir 
334cdf0e10cSrcweir 
335cdf0e10cSrcweir 
336cdf0e10cSrcweir 
mouseEntered(const css::awt::MouseEvent & rEvent)337cdf0e10cSrcweir void SAL_CALL PresenterPaneBorderManager::mouseEntered (const css::awt::MouseEvent& rEvent)
338cdf0e10cSrcweir     throw (css::uno::RuntimeException)
339cdf0e10cSrcweir {
340cdf0e10cSrcweir     (void)rEvent;
341cdf0e10cSrcweir }
342cdf0e10cSrcweir 
343cdf0e10cSrcweir 
344cdf0e10cSrcweir 
345cdf0e10cSrcweir 
mouseExited(const css::awt::MouseEvent & rEvent)346cdf0e10cSrcweir void SAL_CALL PresenterPaneBorderManager::mouseExited (const css::awt::MouseEvent& rEvent)
347cdf0e10cSrcweir     throw (css::uno::RuntimeException)
348cdf0e10cSrcweir {
349cdf0e10cSrcweir     (void)rEvent;
350cdf0e10cSrcweir     ThrowIfDisposed();
351cdf0e10cSrcweir 	::osl::MutexGuard aGuard (::osl::Mutex::getGlobalMutex());
352cdf0e10cSrcweir 
353cdf0e10cSrcweir     ReleaseMouse(mxOuterDragWindow);
354cdf0e10cSrcweir     meDragType = PresenterPaneBorderManager::Outside;
355cdf0e10cSrcweir     mxOuterDragWindow = NULL;
356cdf0e10cSrcweir     mxInnerDragWindow = NULL;
357cdf0e10cSrcweir }
358cdf0e10cSrcweir 
359cdf0e10cSrcweir 
360cdf0e10cSrcweir 
361cdf0e10cSrcweir 
362cdf0e10cSrcweir //----- XMouseMotionListener --------------------------------------------------
363cdf0e10cSrcweir 
mouseMoved(const css::awt::MouseEvent & rEvent)364cdf0e10cSrcweir void SAL_CALL PresenterPaneBorderManager::mouseMoved (const css::awt::MouseEvent& rEvent)
365cdf0e10cSrcweir     throw (css::uno::RuntimeException)
366cdf0e10cSrcweir {
367cdf0e10cSrcweir     ThrowIfDisposed();
368cdf0e10cSrcweir 	::osl::MutexGuard aGuard (::osl::Mutex::getGlobalMutex());
369cdf0e10cSrcweir 
370cdf0e10cSrcweir     WindowList::const_iterator iDescriptor;
371cdf0e10cSrcweir     for (iDescriptor=maWindowList.begin(); iDescriptor!=maWindowList.end(); ++iDescriptor)
372cdf0e10cSrcweir         if (iDescriptor->first == rEvent.Source)
373cdf0e10cSrcweir             break;
374cdf0e10cSrcweir     if (iDescriptor != maWindowList.end())
375cdf0e10cSrcweir     {
376cdf0e10cSrcweir         // Choose pointer shape according to position in the window border.
377cdf0e10cSrcweir         switch (ClassifyBorderElementUnderMouse(
378cdf0e10cSrcweir             iDescriptor->first,
379cdf0e10cSrcweir             iDescriptor->second,
380cdf0e10cSrcweir             awt::Point(rEvent.X,rEvent.Y)))
381cdf0e10cSrcweir         {
382cdf0e10cSrcweir             case PresenterPaneBorderManager::Top:
383cdf0e10cSrcweir                 mnPointerType = awt::SystemPointer::MOVE;
384cdf0e10cSrcweir                 break;
385cdf0e10cSrcweir             case PresenterPaneBorderManager::TopLeft:
386cdf0e10cSrcweir                 mnPointerType = awt::SystemPointer::WINDOW_NWSIZE;
387cdf0e10cSrcweir                 break;
388cdf0e10cSrcweir             case PresenterPaneBorderManager::TopRight:
389cdf0e10cSrcweir                 mnPointerType = awt::SystemPointer::WINDOW_NESIZE;
390cdf0e10cSrcweir                 break;
391cdf0e10cSrcweir             case PresenterPaneBorderManager::Left:
392cdf0e10cSrcweir                 mnPointerType = awt::SystemPointer::WINDOW_WSIZE;
393cdf0e10cSrcweir                 break;
394cdf0e10cSrcweir             case PresenterPaneBorderManager::Right:
395cdf0e10cSrcweir                 mnPointerType = awt::SystemPointer::WINDOW_ESIZE;
396cdf0e10cSrcweir                 break;
397cdf0e10cSrcweir             case PresenterPaneBorderManager::BottomLeft:
398cdf0e10cSrcweir                 mnPointerType = awt::SystemPointer::WINDOW_SWSIZE;
399cdf0e10cSrcweir                 break;
400cdf0e10cSrcweir             case PresenterPaneBorderManager::BottomRight:
401cdf0e10cSrcweir                 mnPointerType = awt::SystemPointer::WINDOW_SESIZE;
402cdf0e10cSrcweir                 break;
403cdf0e10cSrcweir             case PresenterPaneBorderManager::Bottom:
404cdf0e10cSrcweir                 mnPointerType = awt::SystemPointer::WINDOW_SSIZE;
405cdf0e10cSrcweir                 break;
406cdf0e10cSrcweir 
407cdf0e10cSrcweir             case PresenterPaneBorderManager::Content:
408cdf0e10cSrcweir             case PresenterPaneBorderManager::Outside:
409cdf0e10cSrcweir             default:
410cdf0e10cSrcweir                 mnPointerType = awt::SystemPointer::ARROW;
411cdf0e10cSrcweir                 break;
412cdf0e10cSrcweir         }
413cdf0e10cSrcweir 
414cdf0e10cSrcweir         // Make the pointer shape visible.
415cdf0e10cSrcweir         Reference<awt::XWindowPeer> xPeer (iDescriptor->first, UNO_QUERY);
416cdf0e10cSrcweir         if (xPeer.is())
417cdf0e10cSrcweir         {
418cdf0e10cSrcweir             if (mxPointer.is())
419cdf0e10cSrcweir                 mxPointer->setType(mnPointerType);
420cdf0e10cSrcweir             xPeer->setPointer(mxPointer);
421cdf0e10cSrcweir         }
422cdf0e10cSrcweir     }
423cdf0e10cSrcweir }
424cdf0e10cSrcweir 
425cdf0e10cSrcweir 
426cdf0e10cSrcweir 
427cdf0e10cSrcweir 
mouseDragged(const css::awt::MouseEvent & rEvent)428cdf0e10cSrcweir void SAL_CALL PresenterPaneBorderManager::mouseDragged (const css::awt::MouseEvent& rEvent)
429cdf0e10cSrcweir     throw (css::uno::RuntimeException)
430cdf0e10cSrcweir {
431cdf0e10cSrcweir     ThrowIfDisposed();
432cdf0e10cSrcweir 	::osl::MutexGuard aGuard (::osl::Mutex::getGlobalMutex());
433cdf0e10cSrcweir 
434cdf0e10cSrcweir     if ( ! mxOuterDragWindow.is())
435cdf0e10cSrcweir         return;
436cdf0e10cSrcweir 
437cdf0e10cSrcweir     CaptureMouse(mxOuterDragWindow);
438cdf0e10cSrcweir 
439cdf0e10cSrcweir     const awt::Rectangle aOldBox (mxOuterDragWindow->getPosSize());
440cdf0e10cSrcweir     const sal_Int32 nX = rEvent.X + aOldBox.X;
441cdf0e10cSrcweir     const sal_Int32 nY = rEvent.Y + aOldBox.Y;
442cdf0e10cSrcweir     const sal_Int32 nDiffX = nX - maDragAnchor.X;
443cdf0e10cSrcweir     const sal_Int32 nDiffY = nY - maDragAnchor.Y;
444cdf0e10cSrcweir     maDragAnchor.X = nX;
445cdf0e10cSrcweir     maDragAnchor.Y = nY;
446cdf0e10cSrcweir 
447cdf0e10cSrcweir     const sal_Int32 nOldRight = aOldBox.X + aOldBox.Width;
448cdf0e10cSrcweir     const sal_Int32 nOldBottom = aOldBox.Y + aOldBox.Height;
449cdf0e10cSrcweir 
450cdf0e10cSrcweir     awt::Rectangle aBox (aOldBox);
451cdf0e10cSrcweir     sal_Int32 nRight = aBox.X + aBox.Width;
452cdf0e10cSrcweir     sal_Int32 nBottom = aBox.Y + aBox.Height;
453cdf0e10cSrcweir 
454cdf0e10cSrcweir     // Update position and/or size according to initial pointer position
455cdf0e10cSrcweir     // inside the window border.
456cdf0e10cSrcweir     switch (meDragType)
457cdf0e10cSrcweir     {
458cdf0e10cSrcweir         case PresenterPaneBorderManager::Top:
459cdf0e10cSrcweir             aBox.X += nDiffX; aBox.Y += nDiffY;
460cdf0e10cSrcweir             nRight += nDiffX; nBottom += nDiffY;
461cdf0e10cSrcweir             break;
462cdf0e10cSrcweir         case PresenterPaneBorderManager::TopLeft:
463cdf0e10cSrcweir             aBox.X += nDiffX; aBox.Y += nDiffY;
464cdf0e10cSrcweir             break;
465cdf0e10cSrcweir         case PresenterPaneBorderManager::TopRight:
466cdf0e10cSrcweir             nRight += nDiffX; aBox.Y += nDiffY;
467cdf0e10cSrcweir             break;
468cdf0e10cSrcweir         case PresenterPaneBorderManager::Left:
469cdf0e10cSrcweir             aBox.X += nDiffX;
470cdf0e10cSrcweir             break;
471cdf0e10cSrcweir         case PresenterPaneBorderManager::Right:
472cdf0e10cSrcweir             nRight += nDiffX;
473cdf0e10cSrcweir             break;
474cdf0e10cSrcweir         case PresenterPaneBorderManager::BottomLeft:
475cdf0e10cSrcweir             aBox.X += nDiffX; nBottom += nDiffY;
476cdf0e10cSrcweir             break;
477cdf0e10cSrcweir         case PresenterPaneBorderManager::BottomRight:
478cdf0e10cSrcweir             nRight += nDiffX; nBottom += nDiffY;
479cdf0e10cSrcweir             break;
480cdf0e10cSrcweir         case PresenterPaneBorderManager::Bottom:
481cdf0e10cSrcweir             nBottom += nDiffY;
482cdf0e10cSrcweir             break;
483cdf0e10cSrcweir         default: break;
484cdf0e10cSrcweir     }
485cdf0e10cSrcweir 
486cdf0e10cSrcweir     aBox.Width = nRight - aBox.X;
487cdf0e10cSrcweir     aBox.Height = nBottom - aBox.Y;
488cdf0e10cSrcweir     if (aBox.Width > 20
489cdf0e10cSrcweir         && aBox.Height > 20)
490cdf0e10cSrcweir     {
491cdf0e10cSrcweir         // Set position and/or size of the border window to the new values.
492cdf0e10cSrcweir         sal_Int16 nFlags (0);
493cdf0e10cSrcweir         if (aBox.X != aOldBox.X)
494cdf0e10cSrcweir             nFlags |= awt::PosSize::X;
495cdf0e10cSrcweir         if (aBox.Y != aOldBox.Y)
496cdf0e10cSrcweir             nFlags |= awt::PosSize::Y;
497cdf0e10cSrcweir         if (aBox.Width != aOldBox.Width)
498cdf0e10cSrcweir             nFlags |= awt::PosSize::WIDTH;
499cdf0e10cSrcweir         if (aBox.Height != aOldBox.Height)
500cdf0e10cSrcweir             nFlags |= awt::PosSize::HEIGHT;
501cdf0e10cSrcweir         mxOuterDragWindow->setPosSize(aBox.X, aBox.Y, aBox.Width, aBox.Height, nFlags);
502cdf0e10cSrcweir 
503cdf0e10cSrcweir         // Invalidate that is or was covered by the border window before and
504cdf0e10cSrcweir         // after the move/resize.
505cdf0e10cSrcweir         if (mpPresenterController.get() != NULL)
506cdf0e10cSrcweir         {
507cdf0e10cSrcweir             const sal_Int32 nLeft = ::std::min(aOldBox.X,aBox.X);
508cdf0e10cSrcweir             const sal_Int32 nTop = ::std::min(aOldBox.Y,aBox.Y);
509cdf0e10cSrcweir             const sal_Int32 nWidth = ::std::max(nOldRight,nRight) - nLeft;
510cdf0e10cSrcweir             const sal_Int32 nHeight = ::std::max(nOldBottom,nBottom) - nTop;
511cdf0e10cSrcweir 
512cdf0e10cSrcweir             OSL_ASSERT(mpPresenterController->GetPaintManager().get()!=NULL);
513cdf0e10cSrcweir             mpPresenterController->GetPaintManager()->Invalidate(
514cdf0e10cSrcweir                 mxParentWindow,
515cdf0e10cSrcweir                 ::awt::Rectangle(nLeft,nTop,nWidth-1,nHeight-1));
516cdf0e10cSrcweir         }
517cdf0e10cSrcweir     }
518cdf0e10cSrcweir }
519cdf0e10cSrcweir 
520cdf0e10cSrcweir 
521cdf0e10cSrcweir 
522cdf0e10cSrcweir 
523cdf0e10cSrcweir //----- lang::XEventListener --------------------------------------------------
524cdf0e10cSrcweir 
disposing(const lang::EventObject & rEvent)525cdf0e10cSrcweir void SAL_CALL PresenterPaneBorderManager::disposing (const lang::EventObject& rEvent)
526cdf0e10cSrcweir     throw (RuntimeException)
527cdf0e10cSrcweir {
528cdf0e10cSrcweir     WindowList::iterator iDescriptor;
529cdf0e10cSrcweir     for (iDescriptor=maWindowList.begin(); iDescriptor!=maWindowList.end(); ++iDescriptor)
530cdf0e10cSrcweir         if (iDescriptor->first == rEvent.Source)
531cdf0e10cSrcweir         {
532cdf0e10cSrcweir             maWindowList.erase(iDescriptor);
533cdf0e10cSrcweir             break;
534cdf0e10cSrcweir         }
535cdf0e10cSrcweir }
536cdf0e10cSrcweir 
537cdf0e10cSrcweir 
538cdf0e10cSrcweir 
539cdf0e10cSrcweir 
540cdf0e10cSrcweir //-----------------------------------------------------------------------------
541cdf0e10cSrcweir 
542cdf0e10cSrcweir 
CaptureMouse(const Reference<awt::XWindow> & rxWindow)543cdf0e10cSrcweir void PresenterPaneBorderManager::CaptureMouse (const Reference<awt::XWindow>& rxWindow)
544cdf0e10cSrcweir {
545cdf0e10cSrcweir     if (mxPresenterHelper.is())
546cdf0e10cSrcweir         mxPresenterHelper->captureMouse(rxWindow);
547cdf0e10cSrcweir }
548cdf0e10cSrcweir 
549cdf0e10cSrcweir 
550cdf0e10cSrcweir 
551cdf0e10cSrcweir 
ReleaseMouse(const Reference<awt::XWindow> & rxWindow)552cdf0e10cSrcweir void PresenterPaneBorderManager::ReleaseMouse (const Reference<awt::XWindow>& rxWindow)
553cdf0e10cSrcweir {
554cdf0e10cSrcweir     if (mxPresenterHelper.is())
555cdf0e10cSrcweir         mxPresenterHelper->releaseMouse(rxWindow);
556cdf0e10cSrcweir }
557cdf0e10cSrcweir 
558cdf0e10cSrcweir 
559cdf0e10cSrcweir 
560cdf0e10cSrcweir 
ThrowIfDisposed(void)561cdf0e10cSrcweir void PresenterPaneBorderManager::ThrowIfDisposed (void)
562cdf0e10cSrcweir     throw (::com::sun::star::lang::DisposedException)
563cdf0e10cSrcweir {
564cdf0e10cSrcweir 	if (rBHelper.bDisposed || rBHelper.bInDispose)
565cdf0e10cSrcweir 	{
566cdf0e10cSrcweir         throw lang::DisposedException (
567cdf0e10cSrcweir             ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
568cdf0e10cSrcweir                 "PresenterPaneBorderManager object has already been disposed")),
569cdf0e10cSrcweir             static_cast<uno::XWeak*>(this));
570cdf0e10cSrcweir     }
571cdf0e10cSrcweir }
572cdf0e10cSrcweir 
573cdf0e10cSrcweir 
574cdf0e10cSrcweir 
575cdf0e10cSrcweir 
576cdf0e10cSrcweir } } // end of namespace ::sd::presenter
577cdf0e10cSrcweir 
578cdf0e10cSrcweir #endif // ENABLE_PANE_RESIZING
579