1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 // MARKER(update_precomp.py): autogen include statement, do not remove 23 #include "precompiled_framework.hxx" 24 25 #include <uielement/genericstatusbarcontroller.hxx> 26 #include <uielement/statusbarmerger.hxx> 27 28 #include <vos/mutex.hxx> 29 #include <vcl/svapp.hxx> 30 #include <vcl/status.hxx> 31 #include <vcl/image.hxx> 32 #include <toolkit/helper/vclunohelper.hxx> 33 #include <toolkit/helper/convert.hxx> 34 35 #include <com/sun/star/ui/ItemStyle.hpp> 36 #include <com/sun/star/beans/XPropertySet.hpp> 37 #include <com/sun/star/awt/ImageDrawMode.hpp> 38 #include <com/sun/star/graphic/GraphicType.hpp> 39 40 using ::rtl::OUString; 41 42 using namespace ::cppu; 43 using namespace ::com::sun::star; 44 using namespace ::com::sun::star::uno; 45 using namespace ::com::sun::star::lang; 46 using namespace ::com::sun::star::frame; 47 48 namespace framework 49 { 50 51 GenericStatusbarController::GenericStatusbarController( 52 const Reference< XMultiServiceFactory >& rxServiceManager, 53 const Reference< XFrame >& rxFrame, 54 const Reference< ui::XStatusbarItem >& rxItem, 55 AddonStatusbarItemData *pItemData ) 56 : svt::StatusbarController( rxServiceManager, rxFrame, OUString(), 0 ) 57 , m_bEnabled( sal_False ) 58 , m_bOwnerDraw( sal_False ) 59 , m_pItemData( pItemData ) 60 , m_xGraphic() 61 { 62 m_xStatusbarItem = rxItem; 63 if ( m_xStatusbarItem.is() ) 64 { 65 m_aCommandURL = m_xStatusbarItem->getCommand(); 66 m_nID = m_xStatusbarItem->getItemId(); 67 m_bOwnerDraw = ( m_xStatusbarItem->getStyle() & ui::ItemStyle::OWNER_DRAW ) == ui::ItemStyle::OWNER_DRAW; 68 if ( !m_bOwnerDraw && m_pItemData && m_pItemData->aLabel.getLength() ) 69 m_xStatusbarItem->setText( m_pItemData->aLabel ); 70 } 71 } 72 73 GenericStatusbarController::~GenericStatusbarController() 74 { 75 } 76 77 void SAL_CALL GenericStatusbarController::dispose() 78 { 79 svt::StatusbarController::dispose(); 80 81 vos::OGuard aSolarMutexGuard( Application::GetSolarMutex() ); 82 m_pItemData = NULL; 83 m_xGraphic.clear(); 84 m_xStatusbarItem.clear(); 85 86 } 87 88 void SAL_CALL GenericStatusbarController::statusChanged( 89 const FeatureStateEvent& rEvent) 90 { 91 vos::OGuard aSolarMutexGuard( Application::GetSolarMutex() ); 92 93 if ( m_bDisposed || !m_xStatusbarItem.is() ) 94 return; 95 96 m_bEnabled = rEvent.IsEnabled; 97 98 rtl::OUString aStrValue; 99 Reference< graphic::XGraphic > aGraphic; 100 101 if ( rEvent.State >>= aStrValue ) 102 { 103 if ( !m_bOwnerDraw ) 104 m_xStatusbarItem->setText( aStrValue ); 105 else 106 { 107 if ( aStrValue.getLength() ) 108 { 109 m_xStatusbarItem->setQuickHelpText( aStrValue ); 110 } 111 } 112 } 113 else if ( ( rEvent.State >>= aGraphic ) && m_bOwnerDraw ) 114 { 115 m_xGraphic = aGraphic; 116 } 117 118 // when the status is updated, and the controller is responsible for 119 // painting the statusbar item content, we must trigger a repaint 120 if ( m_bOwnerDraw && m_xStatusbarItem->getVisible() ) 121 { 122 m_xStatusbarItem->repaint(); 123 } 124 } 125 126 void SAL_CALL GenericStatusbarController::paint( 127 const Reference< awt::XGraphics >& xGraphics, 128 const awt::Rectangle& rOutputRectangle, 129 ::sal_Int32 /*nStyle*/ ) 130 { 131 OSL_TRACE("framework::GenericStatusbarController::paint"); 132 ::vos::OGuard aGuard( Application::GetSolarMutex() ); 133 134 if ( !m_xStatusbarItem.is() || !xGraphics.is() ) 135 return; 136 137 Reference< beans::XPropertySet > xGraphicProps( m_xGraphic, UNO_QUERY ); 138 139 if ( xGraphicProps.is() && m_xGraphic->getType() != graphic::GraphicType::EMPTY ) 140 { 141 awt::Size aGraphicSize; 142 xGraphicProps->getPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM("SizePixel") ) ) >>= aGraphicSize; 143 OSL_ENSURE( aGraphicSize.Height > 0 && aGraphicSize.Width > 0, "Empty status bar graphic!" ); 144 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; 149 150 xGraphics->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 ); 156 } 157 else 158 { 159 xGraphics->clear( rOutputRectangle ); 160 } 161 } 162 163 164 } 165