fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / framework / source / uielement / genericstatusbarcontroller.cxx
blob982ab0a283fce4dbfb87d91821e8c2f4c88da709
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <uielement/genericstatusbarcontroller.hxx>
21 #include <uielement/statusbarmerger.hxx>
23 #include <vcl/svapp.hxx>
24 #include <vcl/status.hxx>
25 #include <vcl/image.hxx>
26 #include <toolkit/helper/vclunohelper.hxx>
27 #include <toolkit/helper/convert.hxx>
29 #include <com/sun/star/ui/ItemStyle.hpp>
30 #include <com/sun/star/beans/XPropertySet.hpp>
31 #include <com/sun/star/awt/ImageDrawMode.hpp>
32 #include <com/sun/star/awt/XGraphics2.hpp>
33 #include <com/sun/star/graphic/GraphicType.hpp>
35 using ::rtl::OUString;
37 using namespace ::cppu;
38 using namespace ::com::sun::star;
39 using namespace ::com::sun::star::uno;
40 using namespace ::com::sun::star::lang;
41 using namespace ::com::sun::star::frame;
43 namespace framework
46 GenericStatusbarController::GenericStatusbarController(
47 const Reference< XComponentContext >& rxContext,
48 const Reference< XFrame >& rxFrame,
49 const Reference< ui::XStatusbarItem >& rxItem,
50 AddonStatusbarItemData *pItemData )
51 : svt::StatusbarController( rxContext, rxFrame, OUString(), 0 )
52 , m_bEnabled( false )
53 , m_bOwnerDraw( false )
54 , m_pItemData( pItemData )
55 , m_xGraphic()
57 m_xStatusbarItem = rxItem;
58 if ( m_xStatusbarItem.is() )
60 m_aCommandURL = m_xStatusbarItem->getCommand();
61 m_nID = m_xStatusbarItem->getItemId();
62 m_bOwnerDraw = ( m_xStatusbarItem->getStyle() & ui::ItemStyle::OWNER_DRAW ) == ui::ItemStyle::OWNER_DRAW;
63 if ( !m_bOwnerDraw && m_pItemData && m_pItemData->aLabel.getLength() )
64 m_xStatusbarItem->setText( m_pItemData->aLabel );
68 GenericStatusbarController::~GenericStatusbarController()
72 void SAL_CALL GenericStatusbarController::dispose()
73 throw ( RuntimeException, std::exception )
75 svt::StatusbarController::dispose();
77 SolarMutexGuard aGuard;
78 m_pItemData = NULL;
79 m_xGraphic.clear();
80 m_xStatusbarItem.clear();
84 void SAL_CALL GenericStatusbarController::statusChanged(
85 const FeatureStateEvent& rEvent)
86 throw ( RuntimeException, std::exception )
88 SolarMutexGuard aGuard;
90 if ( m_bDisposed || !m_xStatusbarItem.is() )
91 return;
93 m_bEnabled = rEvent.IsEnabled;
95 rtl::OUString aStrValue;
96 Reference< graphic::XGraphic > aGraphic;
98 if ( rEvent.State >>= aStrValue )
100 if ( !m_bOwnerDraw )
101 m_xStatusbarItem->setText( aStrValue );
102 else
104 if ( aStrValue.getLength() )
106 m_xStatusbarItem->setQuickHelpText( aStrValue );
110 else if ( ( rEvent.State >>= aGraphic ) && m_bOwnerDraw )
112 m_xGraphic = aGraphic;
115 // when the status is updated, and the controller is responsible for
116 // painting the statusbar item content, we must trigger a repaint
117 if ( m_bOwnerDraw && m_xStatusbarItem->getVisible() )
119 m_xStatusbarItem->repaint();
123 void SAL_CALL GenericStatusbarController::paint(
124 const Reference< awt::XGraphics >& xGraphics,
125 const awt::Rectangle& rOutputRectangle,
126 ::sal_Int32 /*nStyle*/ )
127 throw ( RuntimeException, std::exception )
129 OSL_TRACE("framework::GenericStatusbarController::paint");
130 SolarMutexGuard aGuard;
132 const Reference< awt::XGraphics2 > xGraphics2(xGraphics, UNO_QUERY);
134 if ( !m_xStatusbarItem.is() || !xGraphics2.is() )
135 return;
137 Reference< beans::XPropertySet > xGraphicProps( m_xGraphic, UNO_QUERY );
139 if ( xGraphicProps.is() && m_xGraphic->getType() != graphic::GraphicType::EMPTY )
141 awt::Size aGraphicSize;
142 xGraphicProps->getPropertyValue( OUString( "SizePixel" ) ) >>= aGraphicSize;
143 OSL_ENSURE( aGraphicSize.Height > 0 && aGraphicSize.Width > 0, "Empty status bar graphic!" );
145 sal_Int32 nOffset = m_xStatusbarItem->getOffset( );
146 awt::Point aPos;
147 aPos.X = ( rOutputRectangle.Width + nOffset ) / 2 - aGraphicSize.Width / 2;
148 aPos.Y = rOutputRectangle.Height / 2 - aGraphicSize.Height / 2;
150 xGraphics2->drawImage( rOutputRectangle.X + aPos.X,
151 rOutputRectangle.Y + aPos.Y,
152 aGraphicSize.Width,
153 aGraphicSize.Height,
154 m_bEnabled ? awt::ImageDrawMode::NONE : awt::ImageDrawMode::DISABLE,
155 m_xGraphic );
157 else
159 xGraphics2->clear( rOutputRectangle );
165 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */