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