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 #include "PresenterButton.hxx"
28cdf0e10cSrcweir #include "PresenterCanvasHelper.hxx"
29cdf0e10cSrcweir #include "PresenterController.hxx"
30cdf0e10cSrcweir #include "PresenterGeometryHelper.hxx"
31cdf0e10cSrcweir #include "PresenterPaintManager.hxx"
32cdf0e10cSrcweir #include "PresenterUIPainter.hxx"
33cdf0e10cSrcweir #include <com/sun/star/awt/PosSize.hpp>
34cdf0e10cSrcweir #include <com/sun/star/awt/XWindowPeer.hpp>
35cdf0e10cSrcweir #include <com/sun/star/drawing/XPresenterHelper.hpp>
36cdf0e10cSrcweir #include <com/sun/star/rendering/CompositeOperation.hpp>
37cdf0e10cSrcweir #include <com/sun/star/rendering/TextDirection.hpp>
38cdf0e10cSrcweir #include <boost/bind.hpp>
39cdf0e10cSrcweir
40cdf0e10cSrcweir using namespace ::com::sun::star;
41cdf0e10cSrcweir using namespace ::com::sun::star::uno;
42cdf0e10cSrcweir using ::rtl::OUString;
43cdf0e10cSrcweir
44cdf0e10cSrcweir #define A2S(pString) (::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(pString)))
45cdf0e10cSrcweir
46cdf0e10cSrcweir namespace sdext { namespace presenter {
47cdf0e10cSrcweir
48cdf0e10cSrcweir const static double gnHorizontalBorder (15);
49cdf0e10cSrcweir const static double gnVerticalBorder (5);
50cdf0e10cSrcweir
51cdf0e10cSrcweir
52cdf0e10cSrcweir
Create(const css::uno::Reference<css::uno::XComponentContext> & rxComponentContext,const::rtl::Reference<PresenterController> & rpPresenterController,const::boost::shared_ptr<PresenterTheme> & rpTheme,const css::uno::Reference<css::awt::XWindow> & rxParentWindow,const css::uno::Reference<css::rendering::XCanvas> & rxParentCanvas,const OUString & rsConfigurationName)53cdf0e10cSrcweir ::rtl::Reference<PresenterButton> PresenterButton::Create (
54cdf0e10cSrcweir const css::uno::Reference<css::uno::XComponentContext>& rxComponentContext,
55cdf0e10cSrcweir const ::rtl::Reference<PresenterController>& rpPresenterController,
56cdf0e10cSrcweir const ::boost::shared_ptr<PresenterTheme>& rpTheme,
57cdf0e10cSrcweir const css::uno::Reference<css::awt::XWindow>& rxParentWindow,
58cdf0e10cSrcweir const css::uno::Reference<css::rendering::XCanvas>& rxParentCanvas,
59cdf0e10cSrcweir const OUString& rsConfigurationName)
60cdf0e10cSrcweir {
61cdf0e10cSrcweir Reference<beans::XPropertySet> xProperties (GetConfigurationProperties(
62cdf0e10cSrcweir rxComponentContext,
63cdf0e10cSrcweir rsConfigurationName));
64cdf0e10cSrcweir if (xProperties.is())
65cdf0e10cSrcweir {
66cdf0e10cSrcweir OUString sText;
67cdf0e10cSrcweir OUString sAction;
68cdf0e10cSrcweir PresenterConfigurationAccess::GetProperty(xProperties, A2S("Text")) >>= sText;
69cdf0e10cSrcweir PresenterConfigurationAccess::GetProperty(xProperties, A2S("Action")) >>= sAction;
70cdf0e10cSrcweir
71cdf0e10cSrcweir PresenterTheme::SharedFontDescriptor pFont;
72cdf0e10cSrcweir if (rpTheme.get() != NULL)
73cdf0e10cSrcweir pFont = rpTheme->GetFont(A2S("ButtonFont"));
74cdf0e10cSrcweir
75cdf0e10cSrcweir PresenterTheme::SharedFontDescriptor pMouseOverFont;
76cdf0e10cSrcweir if (rpTheme.get() != NULL)
77cdf0e10cSrcweir pMouseOverFont = rpTheme->GetFont(A2S("ButtonMouseOverFont"));
78cdf0e10cSrcweir
79cdf0e10cSrcweir rtl::Reference<PresenterButton> pButton (
80cdf0e10cSrcweir new PresenterButton(
81cdf0e10cSrcweir rxComponentContext,
82cdf0e10cSrcweir rpPresenterController,
83cdf0e10cSrcweir rpTheme,
84cdf0e10cSrcweir rxParentWindow,
85cdf0e10cSrcweir pFont,
86cdf0e10cSrcweir pMouseOverFont,
87cdf0e10cSrcweir sText,
88cdf0e10cSrcweir sAction));
89cdf0e10cSrcweir pButton->SetCanvas(rxParentCanvas, rxParentWindow);
90cdf0e10cSrcweir return pButton;
91cdf0e10cSrcweir }
92cdf0e10cSrcweir else
93cdf0e10cSrcweir return NULL;
94cdf0e10cSrcweir }
95cdf0e10cSrcweir
96cdf0e10cSrcweir
97cdf0e10cSrcweir
98cdf0e10cSrcweir
PresenterButton(const css::uno::Reference<css::uno::XComponentContext> & rxComponentContext,const::rtl::Reference<PresenterController> & rpPresenterController,const::boost::shared_ptr<PresenterTheme> & rpTheme,const css::uno::Reference<css::awt::XWindow> & rxParentWindow,const PresenterTheme::SharedFontDescriptor & rpFont,const PresenterTheme::SharedFontDescriptor & rpMouseOverFont,const OUString & rsText,const OUString & rsAction)99cdf0e10cSrcweir PresenterButton::PresenterButton (
100cdf0e10cSrcweir const css::uno::Reference<css::uno::XComponentContext>& rxComponentContext,
101cdf0e10cSrcweir const ::rtl::Reference<PresenterController>& rpPresenterController,
102cdf0e10cSrcweir const ::boost::shared_ptr<PresenterTheme>& rpTheme,
103cdf0e10cSrcweir const css::uno::Reference<css::awt::XWindow>& rxParentWindow,
104cdf0e10cSrcweir const PresenterTheme::SharedFontDescriptor& rpFont,
105cdf0e10cSrcweir const PresenterTheme::SharedFontDescriptor& rpMouseOverFont,
106cdf0e10cSrcweir const OUString& rsText,
107cdf0e10cSrcweir const OUString& rsAction)
108cdf0e10cSrcweir : PresenterButtonInterfaceBase(m_aMutex),
109cdf0e10cSrcweir mpPresenterController(rpPresenterController),
110cdf0e10cSrcweir mpTheme(rpTheme),
111cdf0e10cSrcweir mxWindow(),
112cdf0e10cSrcweir mxCanvas(),
113cdf0e10cSrcweir mxPresenterHelper(),
114cdf0e10cSrcweir msText(rsText),
115cdf0e10cSrcweir mpFont(rpFont),
116cdf0e10cSrcweir mpMouseOverFont(rpMouseOverFont),
117cdf0e10cSrcweir msAction(rsAction),
118cdf0e10cSrcweir maCenter(),
119cdf0e10cSrcweir maButtonSize(-1,-1),
120cdf0e10cSrcweir meState(PresenterBitmapDescriptor::Normal),
121cdf0e10cSrcweir mxNormalBitmap(),
122cdf0e10cSrcweir mxMouseOverBitmap()
123cdf0e10cSrcweir {
124cdf0e10cSrcweir try
125cdf0e10cSrcweir {
126cdf0e10cSrcweir Reference<lang::XMultiComponentFactory> xFactory (rxComponentContext->getServiceManager());
127cdf0e10cSrcweir if ( ! xFactory.is())
128cdf0e10cSrcweir throw RuntimeException();
129cdf0e10cSrcweir
130cdf0e10cSrcweir mxPresenterHelper = Reference<drawing::XPresenterHelper>(
131cdf0e10cSrcweir xFactory->createInstanceWithContext(
132cdf0e10cSrcweir OUString::createFromAscii("com.sun.star.comp.Draw.PresenterHelper"),
133cdf0e10cSrcweir rxComponentContext),
134cdf0e10cSrcweir UNO_QUERY_THROW);
135cdf0e10cSrcweir
136cdf0e10cSrcweir if (mxPresenterHelper.is())
137cdf0e10cSrcweir mxWindow = mxPresenterHelper->createWindow(rxParentWindow,
138cdf0e10cSrcweir sal_False,
139cdf0e10cSrcweir sal_False,
140cdf0e10cSrcweir sal_False,
141cdf0e10cSrcweir sal_False);
142cdf0e10cSrcweir
143cdf0e10cSrcweir // Make the background transparent.
144cdf0e10cSrcweir Reference<awt::XWindowPeer> xPeer (mxWindow, UNO_QUERY_THROW);
145cdf0e10cSrcweir if (xPeer.is())
146cdf0e10cSrcweir {
147cdf0e10cSrcweir xPeer->setBackground(0xff000000);
148cdf0e10cSrcweir }
149cdf0e10cSrcweir
150cdf0e10cSrcweir mxWindow->setVisible(sal_True);
151cdf0e10cSrcweir mxWindow->addWindowListener(this);
152cdf0e10cSrcweir mxWindow->addPaintListener(this);
153cdf0e10cSrcweir mxWindow->addMouseListener(this);
154cdf0e10cSrcweir mxWindow->addMouseMotionListener(this);
155cdf0e10cSrcweir }
156cdf0e10cSrcweir catch (RuntimeException&)
157cdf0e10cSrcweir {
158cdf0e10cSrcweir }
159cdf0e10cSrcweir }
160cdf0e10cSrcweir
161cdf0e10cSrcweir
162cdf0e10cSrcweir
163cdf0e10cSrcweir
~PresenterButton(void)164cdf0e10cSrcweir PresenterButton::~PresenterButton (void)
165cdf0e10cSrcweir {
166cdf0e10cSrcweir }
167cdf0e10cSrcweir
168cdf0e10cSrcweir
169cdf0e10cSrcweir
170cdf0e10cSrcweir
disposing(void)171cdf0e10cSrcweir void SAL_CALL PresenterButton::disposing (void)
172cdf0e10cSrcweir {
173cdf0e10cSrcweir if (mxCanvas.is())
174cdf0e10cSrcweir {
175cdf0e10cSrcweir Reference<lang::XComponent> xComponent (mxCanvas, UNO_QUERY);
176cdf0e10cSrcweir mxCanvas = NULL;
177cdf0e10cSrcweir if (xComponent.is())
178cdf0e10cSrcweir xComponent->dispose();
179cdf0e10cSrcweir }
180cdf0e10cSrcweir
181cdf0e10cSrcweir if (mxWindow.is())
182cdf0e10cSrcweir {
183cdf0e10cSrcweir mxWindow->removeWindowListener(this);
184cdf0e10cSrcweir mxWindow->removePaintListener(this);
185cdf0e10cSrcweir mxWindow->removeMouseListener(this);
186cdf0e10cSrcweir mxWindow->removeMouseMotionListener(this);
187cdf0e10cSrcweir Reference<lang::XComponent> xComponent (mxWindow, UNO_QUERY);
188cdf0e10cSrcweir mxWindow = NULL;
189cdf0e10cSrcweir if (xComponent.is())
190cdf0e10cSrcweir xComponent->dispose();
191cdf0e10cSrcweir }
192cdf0e10cSrcweir }
193cdf0e10cSrcweir
194cdf0e10cSrcweir
195cdf0e10cSrcweir
196cdf0e10cSrcweir
SetCenter(const css::geometry::RealPoint2D & rLocation)197cdf0e10cSrcweir void PresenterButton::SetCenter (const css::geometry::RealPoint2D& rLocation)
198cdf0e10cSrcweir {
199cdf0e10cSrcweir if (mxCanvas.is())
200cdf0e10cSrcweir {
201cdf0e10cSrcweir Invalidate();
202cdf0e10cSrcweir
203cdf0e10cSrcweir maCenter = rLocation;
204cdf0e10cSrcweir mxWindow->setPosSize(
205cdf0e10cSrcweir sal_Int32(0.5 + maCenter.X - maButtonSize.Width/2),
206cdf0e10cSrcweir sal_Int32(0.5 + maCenter.Y - maButtonSize.Height/2),
207cdf0e10cSrcweir maButtonSize.Width,
208cdf0e10cSrcweir maButtonSize.Height,
209cdf0e10cSrcweir awt::PosSize::POSSIZE);
210cdf0e10cSrcweir
211cdf0e10cSrcweir Invalidate();
212cdf0e10cSrcweir }
213cdf0e10cSrcweir else
214cdf0e10cSrcweir {
215cdf0e10cSrcweir // The button can not be painted but we can at least store the new center.
216cdf0e10cSrcweir maCenter = rLocation;
217cdf0e10cSrcweir }
218cdf0e10cSrcweir }
219cdf0e10cSrcweir
220cdf0e10cSrcweir
221cdf0e10cSrcweir
222cdf0e10cSrcweir
SetCanvas(const css::uno::Reference<css::rendering::XCanvas> & rxParentCanvas,const css::uno::Reference<css::awt::XWindow> & rxParentWindow)223cdf0e10cSrcweir void PresenterButton::SetCanvas (
224cdf0e10cSrcweir const css::uno::Reference<css::rendering::XCanvas>& rxParentCanvas,
225cdf0e10cSrcweir const css::uno::Reference<css::awt::XWindow>& rxParentWindow)
226cdf0e10cSrcweir {
227cdf0e10cSrcweir if (mxCanvas.is())
228cdf0e10cSrcweir {
229cdf0e10cSrcweir Reference<lang::XComponent> xComponent (mxCanvas, UNO_QUERY);
230cdf0e10cSrcweir mxCanvas = NULL;
231cdf0e10cSrcweir if (xComponent.is())
232cdf0e10cSrcweir xComponent->dispose();
233cdf0e10cSrcweir }
234cdf0e10cSrcweir
235cdf0e10cSrcweir if (mxPresenterHelper.is() && rxParentCanvas.is() && rxParentWindow.is())
236cdf0e10cSrcweir {
237cdf0e10cSrcweir mxCanvas = mxPresenterHelper->createSharedCanvas (
238cdf0e10cSrcweir Reference<rendering::XSpriteCanvas>(rxParentCanvas, UNO_QUERY),
239cdf0e10cSrcweir rxParentWindow,
240cdf0e10cSrcweir rxParentCanvas,
241cdf0e10cSrcweir rxParentWindow,
242cdf0e10cSrcweir mxWindow);
243cdf0e10cSrcweir if (mxCanvas.is())
244cdf0e10cSrcweir {
245cdf0e10cSrcweir SetupButtonBitmaps();
246cdf0e10cSrcweir SetCenter(maCenter);
247cdf0e10cSrcweir }
248cdf0e10cSrcweir }
249cdf0e10cSrcweir }
250cdf0e10cSrcweir
251cdf0e10cSrcweir
252cdf0e10cSrcweir
253cdf0e10cSrcweir
GetSize(void)254cdf0e10cSrcweir css::geometry::IntegerSize2D PresenterButton::GetSize (void)
255cdf0e10cSrcweir {
256cdf0e10cSrcweir if (maButtonSize.Width < 0)
257cdf0e10cSrcweir CalculateButtonSize();
258cdf0e10cSrcweir return maButtonSize;
259cdf0e10cSrcweir }
260cdf0e10cSrcweir
261cdf0e10cSrcweir
262cdf0e10cSrcweir
263cdf0e10cSrcweir
264cdf0e10cSrcweir //----- XWindowListener -------------------------------------------------------
265cdf0e10cSrcweir
windowResized(const css::awt::WindowEvent & rEvent)266cdf0e10cSrcweir void SAL_CALL PresenterButton::windowResized (const css::awt::WindowEvent& rEvent)
267cdf0e10cSrcweir throw (css::uno::RuntimeException)
268cdf0e10cSrcweir {
269cdf0e10cSrcweir (void)rEvent;
270cdf0e10cSrcweir ThrowIfDisposed();
271cdf0e10cSrcweir }
272cdf0e10cSrcweir
273cdf0e10cSrcweir
274cdf0e10cSrcweir
275cdf0e10cSrcweir
276cdf0e10cSrcweir
windowMoved(const css::awt::WindowEvent & rEvent)277cdf0e10cSrcweir void SAL_CALL PresenterButton::windowMoved (const css::awt::WindowEvent& rEvent)
278cdf0e10cSrcweir throw (css::uno::RuntimeException)
279cdf0e10cSrcweir {
280cdf0e10cSrcweir (void)rEvent;
281cdf0e10cSrcweir ThrowIfDisposed();
282cdf0e10cSrcweir }
283cdf0e10cSrcweir
284cdf0e10cSrcweir
285cdf0e10cSrcweir
286cdf0e10cSrcweir
windowShown(const css::lang::EventObject & rEvent)287cdf0e10cSrcweir void SAL_CALL PresenterButton::windowShown (const css::lang::EventObject& rEvent)
288cdf0e10cSrcweir throw (css::uno::RuntimeException)
289cdf0e10cSrcweir {
290cdf0e10cSrcweir (void)rEvent;
291cdf0e10cSrcweir ThrowIfDisposed();
292cdf0e10cSrcweir }
293cdf0e10cSrcweir
294cdf0e10cSrcweir
295cdf0e10cSrcweir
296cdf0e10cSrcweir
windowHidden(const css::lang::EventObject & rEvent)297cdf0e10cSrcweir void SAL_CALL PresenterButton::windowHidden (const css::lang::EventObject& rEvent)
298cdf0e10cSrcweir throw (css::uno::RuntimeException)
299cdf0e10cSrcweir {
300cdf0e10cSrcweir (void)rEvent;
301cdf0e10cSrcweir ThrowIfDisposed();
302cdf0e10cSrcweir }
303cdf0e10cSrcweir
304cdf0e10cSrcweir
305cdf0e10cSrcweir
306cdf0e10cSrcweir
307cdf0e10cSrcweir //----- XPaintListener --------------------------------------------------------
308cdf0e10cSrcweir
windowPaint(const css::awt::PaintEvent & rEvent)309cdf0e10cSrcweir void SAL_CALL PresenterButton::windowPaint (const css::awt::PaintEvent& rEvent)
310cdf0e10cSrcweir throw (css::uno::RuntimeException)
311cdf0e10cSrcweir {
312cdf0e10cSrcweir ThrowIfDisposed();
313cdf0e10cSrcweir if (mxWindow.is() && mxCanvas.is())
314cdf0e10cSrcweir {
315cdf0e10cSrcweir Reference<rendering::XBitmap> xBitmap;
316cdf0e10cSrcweir if (meState == PresenterBitmapDescriptor::MouseOver)
317cdf0e10cSrcweir xBitmap = mxMouseOverBitmap;
318cdf0e10cSrcweir else
319cdf0e10cSrcweir xBitmap = mxNormalBitmap;
320cdf0e10cSrcweir if ( ! xBitmap.is())
321cdf0e10cSrcweir return;
322cdf0e10cSrcweir
323cdf0e10cSrcweir rendering::ViewState aViewState(
324cdf0e10cSrcweir geometry::AffineMatrix2D(1,0,0, 0,1,0),
325cdf0e10cSrcweir NULL);
326cdf0e10cSrcweir rendering::RenderState aRenderState(
327cdf0e10cSrcweir geometry::AffineMatrix2D(1,0,0, 0,1,0),
328cdf0e10cSrcweir PresenterGeometryHelper::CreatePolygon(rEvent.UpdateRect, mxCanvas->getDevice()),
329cdf0e10cSrcweir Sequence<double>(4),
330cdf0e10cSrcweir rendering::CompositeOperation::SOURCE);
331cdf0e10cSrcweir
332cdf0e10cSrcweir mxCanvas->drawBitmap(xBitmap, aViewState, aRenderState);
333cdf0e10cSrcweir
334cdf0e10cSrcweir Reference<rendering::XSpriteCanvas> xSpriteCanvas (mxCanvas, UNO_QUERY);
335cdf0e10cSrcweir if (xSpriteCanvas.is())
336cdf0e10cSrcweir xSpriteCanvas->updateScreen(sal_False);
337cdf0e10cSrcweir }
338cdf0e10cSrcweir }
339cdf0e10cSrcweir
340cdf0e10cSrcweir
341cdf0e10cSrcweir
342cdf0e10cSrcweir
343cdf0e10cSrcweir //----- XMouseListener --------------------------------------------------------
344cdf0e10cSrcweir
mousePressed(const css::awt::MouseEvent & rEvent)345cdf0e10cSrcweir void SAL_CALL PresenterButton::mousePressed (const css::awt::MouseEvent& rEvent)
346cdf0e10cSrcweir throw(css::uno::RuntimeException)
347cdf0e10cSrcweir {
348cdf0e10cSrcweir (void)rEvent;
349cdf0e10cSrcweir ThrowIfDisposed();
350cdf0e10cSrcweir
351cdf0e10cSrcweir meState = PresenterBitmapDescriptor::ButtonDown;
352cdf0e10cSrcweir }
353cdf0e10cSrcweir
354cdf0e10cSrcweir
355cdf0e10cSrcweir
356cdf0e10cSrcweir
mouseReleased(const css::awt::MouseEvent & rEvent)357cdf0e10cSrcweir void SAL_CALL PresenterButton::mouseReleased (const css::awt::MouseEvent& rEvent)
358cdf0e10cSrcweir throw(css::uno::RuntimeException)
359cdf0e10cSrcweir {
360cdf0e10cSrcweir (void)rEvent;
361cdf0e10cSrcweir ThrowIfDisposed();
362cdf0e10cSrcweir
363cdf0e10cSrcweir if (meState == PresenterBitmapDescriptor::ButtonDown)
364cdf0e10cSrcweir {
365cdf0e10cSrcweir OSL_ASSERT(mpPresenterController.get()!=NULL);
366cdf0e10cSrcweir mpPresenterController->DispatchUnoCommand(msAction);
367cdf0e10cSrcweir
368cdf0e10cSrcweir meState = PresenterBitmapDescriptor::Normal;
369cdf0e10cSrcweir Invalidate();
370cdf0e10cSrcweir }
371cdf0e10cSrcweir }
372cdf0e10cSrcweir
373cdf0e10cSrcweir
374cdf0e10cSrcweir
375cdf0e10cSrcweir
mouseEntered(const css::awt::MouseEvent & rEvent)376cdf0e10cSrcweir void SAL_CALL PresenterButton::mouseEntered (const css::awt::MouseEvent& rEvent)
377cdf0e10cSrcweir throw(css::uno::RuntimeException)
378cdf0e10cSrcweir {
379cdf0e10cSrcweir (void)rEvent;
380cdf0e10cSrcweir ThrowIfDisposed();
381cdf0e10cSrcweir meState = PresenterBitmapDescriptor::MouseOver;
382cdf0e10cSrcweir Invalidate();
383cdf0e10cSrcweir }
384cdf0e10cSrcweir
385cdf0e10cSrcweir
386cdf0e10cSrcweir
387cdf0e10cSrcweir
mouseExited(const css::awt::MouseEvent & rEvent)388cdf0e10cSrcweir void SAL_CALL PresenterButton::mouseExited (const css::awt::MouseEvent& rEvent)
389cdf0e10cSrcweir throw(css::uno::RuntimeException)
390cdf0e10cSrcweir {
391cdf0e10cSrcweir (void)rEvent;
392cdf0e10cSrcweir ThrowIfDisposed();
393cdf0e10cSrcweir meState = PresenterBitmapDescriptor::Normal;
394cdf0e10cSrcweir Invalidate();
395cdf0e10cSrcweir }
396cdf0e10cSrcweir
397cdf0e10cSrcweir
398cdf0e10cSrcweir
399cdf0e10cSrcweir
400cdf0e10cSrcweir
401cdf0e10cSrcweir //----- XMouseMotionListener --------------------------------------------------
402cdf0e10cSrcweir
mouseMoved(const css::awt::MouseEvent & rEvent)403cdf0e10cSrcweir void SAL_CALL PresenterButton::mouseMoved (const css::awt::MouseEvent& rEvent)
404cdf0e10cSrcweir throw (css::uno::RuntimeException)
405cdf0e10cSrcweir {
406cdf0e10cSrcweir (void)rEvent;
407cdf0e10cSrcweir ThrowIfDisposed();
408cdf0e10cSrcweir }
409cdf0e10cSrcweir
410cdf0e10cSrcweir
411cdf0e10cSrcweir
412cdf0e10cSrcweir
mouseDragged(const css::awt::MouseEvent & rEvent)413cdf0e10cSrcweir void SAL_CALL PresenterButton::mouseDragged (const css::awt::MouseEvent& rEvent)
414cdf0e10cSrcweir throw (css::uno::RuntimeException)
415cdf0e10cSrcweir {
416cdf0e10cSrcweir (void)rEvent;
417cdf0e10cSrcweir ThrowIfDisposed();
418cdf0e10cSrcweir }
419cdf0e10cSrcweir
420cdf0e10cSrcweir
421cdf0e10cSrcweir
422cdf0e10cSrcweir
423cdf0e10cSrcweir //----- lang::XEventListener --------------------------------------------------
424cdf0e10cSrcweir
disposing(const css::lang::EventObject & rEvent)425cdf0e10cSrcweir void SAL_CALL PresenterButton::disposing (const css::lang::EventObject& rEvent)
426cdf0e10cSrcweir throw (css::uno::RuntimeException)
427cdf0e10cSrcweir {
428cdf0e10cSrcweir if (rEvent.Source == mxWindow)
429cdf0e10cSrcweir mxWindow = NULL;
430cdf0e10cSrcweir }
431cdf0e10cSrcweir
432cdf0e10cSrcweir
433cdf0e10cSrcweir
434cdf0e10cSrcweir
435cdf0e10cSrcweir //-----------------------------------------------------------------------------
436cdf0e10cSrcweir
CalculateButtonSize(void)437cdf0e10cSrcweir css::geometry::IntegerSize2D PresenterButton::CalculateButtonSize (void)
438cdf0e10cSrcweir {
439cdf0e10cSrcweir if (mpFont.get()!=NULL && !mpFont->mxFont.is() && mxCanvas.is())
440cdf0e10cSrcweir mpFont->PrepareFont(mxCanvas);
441cdf0e10cSrcweir if (mpFont.get()==NULL || !mpFont->mxFont.is())
442cdf0e10cSrcweir return geometry::IntegerSize2D(-1,-1);
443cdf0e10cSrcweir
444cdf0e10cSrcweir geometry::RealSize2D aTextSize (PresenterCanvasHelper::GetTextSize(mpFont->mxFont,msText));
445cdf0e10cSrcweir
446cdf0e10cSrcweir return geometry::IntegerSize2D (
447cdf0e10cSrcweir sal_Int32(0.5 + aTextSize.Width + 2*gnHorizontalBorder),
448cdf0e10cSrcweir sal_Int32(0.5 + aTextSize.Height + 2*gnVerticalBorder));
449cdf0e10cSrcweir }
450cdf0e10cSrcweir
451cdf0e10cSrcweir
452cdf0e10cSrcweir
453cdf0e10cSrcweir
RenderButton(const Reference<rendering::XCanvas> & rxCanvas,const geometry::IntegerSize2D & rSize,const PresenterTheme::SharedFontDescriptor & rpFont,const PresenterBitmapDescriptor::Mode eMode,const SharedBitmapDescriptor & rpLeft,const SharedBitmapDescriptor & rpCenter,const SharedBitmapDescriptor & rpRight)454cdf0e10cSrcweir void PresenterButton::RenderButton (
455cdf0e10cSrcweir const Reference<rendering::XCanvas>& rxCanvas,
456cdf0e10cSrcweir const geometry::IntegerSize2D& rSize,
457cdf0e10cSrcweir const PresenterTheme::SharedFontDescriptor& rpFont,
458cdf0e10cSrcweir const PresenterBitmapDescriptor::Mode eMode,
459cdf0e10cSrcweir const SharedBitmapDescriptor& rpLeft,
460cdf0e10cSrcweir const SharedBitmapDescriptor& rpCenter,
461cdf0e10cSrcweir const SharedBitmapDescriptor& rpRight)
462cdf0e10cSrcweir {
463cdf0e10cSrcweir if ( ! rxCanvas.is())
464cdf0e10cSrcweir return;
465cdf0e10cSrcweir
466cdf0e10cSrcweir const awt::Rectangle aBox(0,0, rSize.Width, rSize.Height);
467cdf0e10cSrcweir
468cdf0e10cSrcweir PresenterUIPainter::PaintHorizontalBitmapComposite (
469cdf0e10cSrcweir rxCanvas,
470cdf0e10cSrcweir aBox,
471cdf0e10cSrcweir aBox,
472cdf0e10cSrcweir GetBitmap(rpLeft, eMode),
473cdf0e10cSrcweir GetBitmap(rpCenter, eMode),
474cdf0e10cSrcweir GetBitmap(rpRight, eMode));
475cdf0e10cSrcweir
476cdf0e10cSrcweir if (rpFont.get()==NULL || ! rpFont->mxFont.is())
477cdf0e10cSrcweir return;
478cdf0e10cSrcweir
479cdf0e10cSrcweir const rendering::StringContext aContext (msText, 0, msText.getLength());
480cdf0e10cSrcweir const Reference<rendering::XTextLayout> xLayout (
481cdf0e10cSrcweir rpFont->mxFont->createTextLayout(aContext,rendering::TextDirection::WEAK_LEFT_TO_RIGHT,0));
482cdf0e10cSrcweir const geometry::RealRectangle2D aTextBBox (xLayout->queryTextBounds());
483cdf0e10cSrcweir
484cdf0e10cSrcweir rendering::RenderState aRenderState (geometry::AffineMatrix2D(1,0,0, 0,1,0), NULL,
485cdf0e10cSrcweir Sequence<double>(4), rendering::CompositeOperation::SOURCE);
486cdf0e10cSrcweir PresenterCanvasHelper::SetDeviceColor(aRenderState, rpFont->mnColor);
487cdf0e10cSrcweir aRenderState.AffineTransform.m02 = (rSize.Width - aTextBBox.X2 + aTextBBox.X1)/2;
488cdf0e10cSrcweir aRenderState.AffineTransform.m12 = (rSize.Height - aTextBBox.Y2 + aTextBBox.Y1)/2 - aTextBBox.Y1;
489cdf0e10cSrcweir
490cdf0e10cSrcweir rxCanvas->drawText(
491cdf0e10cSrcweir aContext,
492cdf0e10cSrcweir rpFont->mxFont,
493cdf0e10cSrcweir rendering::ViewState(geometry::AffineMatrix2D(1,0,0, 0,1,0), NULL),
494cdf0e10cSrcweir aRenderState,
495cdf0e10cSrcweir rendering::TextDirection::WEAK_LEFT_TO_RIGHT);
496cdf0e10cSrcweir }
497cdf0e10cSrcweir
498cdf0e10cSrcweir
499cdf0e10cSrcweir
500cdf0e10cSrcweir
Invalidate(void)501cdf0e10cSrcweir void PresenterButton::Invalidate (void)
502cdf0e10cSrcweir {
503cdf0e10cSrcweir mpPresenterController->GetPaintManager()->Invalidate(mxWindow);
504cdf0e10cSrcweir }
505cdf0e10cSrcweir
506cdf0e10cSrcweir
507cdf0e10cSrcweir
508cdf0e10cSrcweir
GetBitmap(const SharedBitmapDescriptor & mpIcon,const PresenterBitmapDescriptor::Mode eMode)509cdf0e10cSrcweir Reference<rendering::XBitmap> PresenterButton::GetBitmap (
510cdf0e10cSrcweir const SharedBitmapDescriptor& mpIcon,
511cdf0e10cSrcweir const PresenterBitmapDescriptor::Mode eMode)
512cdf0e10cSrcweir {
513cdf0e10cSrcweir if (mpIcon.get() != NULL)
514cdf0e10cSrcweir return mpIcon->GetBitmap(eMode);
515cdf0e10cSrcweir else
516cdf0e10cSrcweir {
517cdf0e10cSrcweir OSL_ASSERT(mpIcon.get()!=NULL);
518cdf0e10cSrcweir return NULL;
519cdf0e10cSrcweir }
520cdf0e10cSrcweir }
521cdf0e10cSrcweir
522cdf0e10cSrcweir
523cdf0e10cSrcweir
524cdf0e10cSrcweir
SetupButtonBitmaps(void)525cdf0e10cSrcweir void PresenterButton::SetupButtonBitmaps (void)
526cdf0e10cSrcweir {
527cdf0e10cSrcweir if ( ! mxCanvas.is())
528cdf0e10cSrcweir return;
529cdf0e10cSrcweir if ( ! mxCanvas->getDevice().is())
530cdf0e10cSrcweir return;
531cdf0e10cSrcweir
532cdf0e10cSrcweir // Get the bitmaps for the button border.
533cdf0e10cSrcweir SharedBitmapDescriptor pLeftBitmap (mpTheme->GetBitmap(A2S("ButtonFrameLeft")));
534cdf0e10cSrcweir SharedBitmapDescriptor pCenterBitmap(mpTheme->GetBitmap(A2S("ButtonFrameCenter")));
535cdf0e10cSrcweir SharedBitmapDescriptor pRightBitmap(mpTheme->GetBitmap(A2S("ButtonFrameRight")));
536cdf0e10cSrcweir
537cdf0e10cSrcweir maButtonSize = CalculateButtonSize();
538cdf0e10cSrcweir
539cdf0e10cSrcweir if (maButtonSize.Height<=0 && maButtonSize.Width<= 0)
540cdf0e10cSrcweir return;
541cdf0e10cSrcweir
542cdf0e10cSrcweir mxNormalBitmap = mxCanvas->getDevice()->createCompatibleAlphaBitmap(maButtonSize);
543cdf0e10cSrcweir Reference<rendering::XCanvas> xCanvas (mxNormalBitmap, UNO_QUERY);
544cdf0e10cSrcweir if (xCanvas.is())
545cdf0e10cSrcweir RenderButton(
546cdf0e10cSrcweir xCanvas,
547cdf0e10cSrcweir maButtonSize,
548cdf0e10cSrcweir mpFont,
549cdf0e10cSrcweir PresenterBitmapDescriptor::Normal,
550cdf0e10cSrcweir pLeftBitmap,
551cdf0e10cSrcweir pCenterBitmap,
552cdf0e10cSrcweir pRightBitmap);
553cdf0e10cSrcweir
554cdf0e10cSrcweir mxMouseOverBitmap = mxCanvas->getDevice()->createCompatibleAlphaBitmap(maButtonSize);
555cdf0e10cSrcweir xCanvas = Reference<rendering::XCanvas>(mxMouseOverBitmap, UNO_QUERY);
556cdf0e10cSrcweir if (mpMouseOverFont.get()!=NULL && !mpMouseOverFont->mxFont.is() && mxCanvas.is())
557cdf0e10cSrcweir mpMouseOverFont->PrepareFont(mxCanvas);
558cdf0e10cSrcweir if (xCanvas.is())
559cdf0e10cSrcweir RenderButton(
560cdf0e10cSrcweir xCanvas,
561cdf0e10cSrcweir maButtonSize,
562cdf0e10cSrcweir mpMouseOverFont,
563cdf0e10cSrcweir PresenterBitmapDescriptor::MouseOver,
564cdf0e10cSrcweir pLeftBitmap,
565cdf0e10cSrcweir pCenterBitmap,
566cdf0e10cSrcweir pRightBitmap);
567cdf0e10cSrcweir }
568cdf0e10cSrcweir
569cdf0e10cSrcweir
570cdf0e10cSrcweir
571cdf0e10cSrcweir
GetConfigurationProperties(const css::uno::Reference<css::uno::XComponentContext> & rxComponentContext,const OUString & rsConfgurationName)572cdf0e10cSrcweir Reference<beans::XPropertySet> PresenterButton::GetConfigurationProperties (
573cdf0e10cSrcweir const css::uno::Reference<css::uno::XComponentContext>& rxComponentContext,
574cdf0e10cSrcweir const OUString& rsConfgurationName)
575cdf0e10cSrcweir {
576cdf0e10cSrcweir PresenterConfigurationAccess aConfiguration (
577cdf0e10cSrcweir rxComponentContext,
578cdf0e10cSrcweir PresenterConfigurationAccess::msPresenterScreenRootName,
579cdf0e10cSrcweir PresenterConfigurationAccess::READ_ONLY);
580cdf0e10cSrcweir return Reference<beans::XPropertySet>(
581cdf0e10cSrcweir PresenterConfigurationAccess::Find (
582cdf0e10cSrcweir Reference<container::XNameAccess>(
583cdf0e10cSrcweir aConfiguration.GetConfigurationNode(A2S("PresenterScreenSettings/Buttons")),
584cdf0e10cSrcweir UNO_QUERY),
585cdf0e10cSrcweir ::boost::bind(&PresenterConfigurationAccess::IsStringPropertyEqual,
586cdf0e10cSrcweir rsConfgurationName,
587cdf0e10cSrcweir A2S("Name"),
588cdf0e10cSrcweir _2)),
589cdf0e10cSrcweir UNO_QUERY);
590cdf0e10cSrcweir }
591cdf0e10cSrcweir
592cdf0e10cSrcweir
593cdf0e10cSrcweir
594cdf0e10cSrcweir
ThrowIfDisposed(void) const595cdf0e10cSrcweir void PresenterButton::ThrowIfDisposed (void) const
596cdf0e10cSrcweir throw (::com::sun::star::lang::DisposedException)
597cdf0e10cSrcweir {
598cdf0e10cSrcweir if (rBHelper.bDisposed || rBHelper.bInDispose)
599cdf0e10cSrcweir {
600cdf0e10cSrcweir throw lang::DisposedException (
601cdf0e10cSrcweir OUString(RTL_CONSTASCII_USTRINGPARAM(
602cdf0e10cSrcweir "PresenterButton object has already been disposed")),
603cdf0e10cSrcweir const_cast<uno::XWeak*>(static_cast<const uno::XWeak*>(this)));
604cdf0e10cSrcweir }
605cdf0e10cSrcweir }
606cdf0e10cSrcweir
607cdf0e10cSrcweir
608cdf0e10cSrcweir } } // end of namespace sdext::presenter
609