1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 <osl/diagnose.h>
24 #include <vcl/svapp.hxx>
26 #include <com/sun/star/ui/ItemStyle.hpp>
27 #include <com/sun/star/ui/XStatusbarItem.hpp>
28 #include <com/sun/star/beans/XPropertySet.hpp>
29 #include <com/sun/star/awt/ImageDrawMode.hpp>
30 #include <com/sun/star/awt/XGraphics2.hpp>
31 #include <com/sun/star/graphic/GraphicType.hpp>
33 using namespace ::com::sun::star
;
34 using namespace ::com::sun::star::uno
;
35 using namespace ::com::sun::star::frame
;
40 GenericStatusbarController::GenericStatusbarController(
41 const Reference
< XComponentContext
>& rxContext
,
42 const Reference
< XFrame
>& rxFrame
,
43 const Reference
< ui::XStatusbarItem
>& rxItem
,
44 AddonStatusbarItemData
*pItemData
)
45 : svt::StatusbarController( rxContext
, rxFrame
, OUString(), 0 )
47 , m_bOwnerDraw( false )
48 , m_pItemData( pItemData
)
50 m_xStatusbarItem
= rxItem
;
51 if ( m_xStatusbarItem
.is() )
53 assert(m_aCommandURL
.pData
);
54 m_aCommandURL
= m_xStatusbarItem
->getCommand();
55 m_nID
= m_xStatusbarItem
->getItemId();
56 m_bOwnerDraw
= ( m_xStatusbarItem
->getStyle() & ui::ItemStyle::OWNER_DRAW
) == ui::ItemStyle::OWNER_DRAW
;
57 if ( !m_bOwnerDraw
&& m_pItemData
&& m_pItemData
->aLabel
.getLength() )
58 m_xStatusbarItem
->setText( m_pItemData
->aLabel
);
62 GenericStatusbarController::~GenericStatusbarController()
66 void SAL_CALL
GenericStatusbarController::dispose()
68 svt::StatusbarController::dispose();
70 SolarMutexGuard aGuard
;
71 m_pItemData
= nullptr;
73 m_xStatusbarItem
.clear();
77 void SAL_CALL
GenericStatusbarController::statusChanged(
78 const FeatureStateEvent
& rEvent
)
80 SolarMutexGuard aGuard
;
82 if ( m_bDisposed
|| !m_xStatusbarItem
.is() )
85 m_bEnabled
= rEvent
.IsEnabled
;
88 Reference
< graphic::XGraphic
> aGraphic
;
90 if ( rEvent
.State
>>= aStrValue
)
93 m_xStatusbarItem
->setText( aStrValue
);
96 if ( aStrValue
.getLength() )
98 m_xStatusbarItem
->setQuickHelpText( aStrValue
);
102 else if ( ( rEvent
.State
>>= aGraphic
) && m_bOwnerDraw
)
104 m_xGraphic
= std::move(aGraphic
);
107 // when the status is updated, and the controller is responsible for
108 // painting the statusbar item content, we must trigger a repaint
109 if ( m_bOwnerDraw
&& m_xStatusbarItem
->getVisible() )
111 m_xStatusbarItem
->repaint();
115 void SAL_CALL
GenericStatusbarController::paint(
116 const Reference
< awt::XGraphics
>& xGraphics
,
117 const awt::Rectangle
& rOutputRectangle
,
118 ::sal_Int32
/*nStyle*/ )
120 SolarMutexGuard aGuard
;
122 const Reference
< awt::XGraphics2
> xGraphics2(xGraphics
, UNO_QUERY
);
124 if ( !m_xStatusbarItem
.is() || !xGraphics2
.is() )
127 Reference
< beans::XPropertySet
> xGraphicProps( m_xGraphic
, UNO_QUERY
);
129 if ( xGraphicProps
.is() && m_xGraphic
->getType() != graphic::GraphicType::EMPTY
)
131 awt::Size aGraphicSize
;
132 xGraphicProps
->getPropertyValue( u
"SizePixel"_ustr
) >>= aGraphicSize
;
133 OSL_ENSURE( aGraphicSize
.Height
> 0 && aGraphicSize
.Width
> 0, "Empty status bar graphic!" );
135 sal_Int32 nOffset
= m_xStatusbarItem
->getOffset( );
137 aPos
.X
= ( rOutputRectangle
.Width
+ nOffset
) / 2 - aGraphicSize
.Width
/ 2;
138 aPos
.Y
= rOutputRectangle
.Height
/ 2 - aGraphicSize
.Height
/ 2;
140 xGraphics2
->drawImage( rOutputRectangle
.X
+ aPos
.X
,
141 rOutputRectangle
.Y
+ aPos
.Y
,
144 m_bEnabled
? awt::ImageDrawMode::NONE
: awt::ImageDrawMode::DISABLE
,
149 xGraphics2
->clear( rOutputRectangle
);
155 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */