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 throw ( RuntimeException ) 79 { 80 svt::StatusbarController::dispose(); 81 82 vos::OGuard aSolarMutexGuard( Application::GetSolarMutex() ); 83 m_pItemData = NULL; 84 m_xGraphic.clear(); 85 m_xStatusbarItem.clear(); 86 87 } 88 89 void SAL_CALL GenericStatusbarController::statusChanged( 90 const FeatureStateEvent& rEvent) 91 throw ( RuntimeException ) 92 { 93 vos::OGuard aSolarMutexGuard( Application::GetSolarMutex() ); 94 95 if ( m_bDisposed || !m_xStatusbarItem.is() ) 96 return; 97 98 m_bEnabled = rEvent.IsEnabled; 99 100 rtl::OUString aStrValue; 101 Reference< graphic::XGraphic > aGraphic; 102 103 if ( rEvent.State >>= aStrValue ) 104 { 105 if ( !m_bOwnerDraw ) 106 m_xStatusbarItem->setText( aStrValue ); 107 else 108 { 109 if ( aStrValue.getLength() ) 110 { 111 m_xStatusbarItem->setQuickHelpText( aStrValue ); 112 } 113 } 114 } 115 else if ( ( rEvent.State >>= aGraphic ) && m_bOwnerDraw ) 116 { 117 m_xGraphic = aGraphic; 118 } 119 120 // when the status is updated, and the controller is responsible for 121 // painting the statusbar item content, we must trigger a repaint 122 if ( m_bOwnerDraw && m_xStatusbarItem->getVisible() ) 123 { 124 m_xStatusbarItem->repaint(); 125 } 126 } 127 128 void SAL_CALL GenericStatusbarController::paint( 129 const Reference< awt::XGraphics >& xGraphics, 130 const awt::Rectangle& rOutputRectangle, 131 ::sal_Int32 /*nStyle*/ ) 132 throw ( RuntimeException ) 133 { 134 OSL_TRACE("framework::GenericStatusbarController::paint"); 135 ::vos::OGuard aGuard( Application::GetSolarMutex() ); 136 137 if ( !m_xStatusbarItem.is() || !xGraphics.is() ) 138 return; 139 140 Reference< beans::XPropertySet > xGraphicProps( m_xGraphic, UNO_QUERY ); 141 142 if ( xGraphicProps.is() && m_xGraphic->getType() != graphic::GraphicType::EMPTY ) 143 { 144 awt::Size aGraphicSize; 145 xGraphicProps->getPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM("SizePixel") ) ) >>= aGraphicSize; 146 OSL_ENSURE( aGraphicSize.Height > 0 && aGraphicSize.Width > 0, "Empty status bar graphic!" ); 147 148 sal_Int32 nOffset = m_xStatusbarItem->getOffset( ); 149 awt::Point aPos; 150 aPos.X = ( rOutputRectangle.Width + nOffset ) / 2 - aGraphicSize.Width / 2; 151 aPos.Y = rOutputRectangle.Height / 2 - aGraphicSize.Height / 2; 152 153 xGraphics->drawImage( rOutputRectangle.X + aPos.X, 154 rOutputRectangle.Y + aPos.Y, 155 aGraphicSize.Width, 156 aGraphicSize.Height, 157 m_bEnabled ? awt::ImageDrawMode::NONE : awt::ImageDrawMode::DISABLE, 158 m_xGraphic ); 159 } 160 else 161 { 162 xGraphics->clear( rOutputRectangle ); 163 } 164 } 165 166 167 } 168