LibreOffice Module framework (master) 1
genericstatusbarcontroller.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
22
23#include <osl/diagnose.h>
24#include <vcl/svapp.hxx>
25
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>
32
33using namespace ::cppu;
34using namespace ::com::sun::star;
35using namespace ::com::sun::star::uno;
36using namespace ::com::sun::star::lang;
37using namespace ::com::sun::star::frame;
38
39namespace framework
40{
41
43 const Reference< XComponentContext >& rxContext,
44 const Reference< XFrame >& rxFrame,
45 const Reference< ui::XStatusbarItem >& rxItem,
46 AddonStatusbarItemData *pItemData )
47 : svt::StatusbarController( rxContext, rxFrame, OUString(), 0 )
48 , m_bEnabled( false )
49 , m_bOwnerDraw( false )
50 , m_pItemData( pItemData )
51{
52 m_xStatusbarItem = rxItem;
53 if ( m_xStatusbarItem.is() )
54 {
55 assert(m_aCommandURL.pData);
56 m_aCommandURL = m_xStatusbarItem->getCommand();
57 m_nID = m_xStatusbarItem->getItemId();
58 m_bOwnerDraw = ( m_xStatusbarItem->getStyle() & ui::ItemStyle::OWNER_DRAW ) == ui::ItemStyle::OWNER_DRAW;
59 if ( !m_bOwnerDraw && m_pItemData && m_pItemData->aLabel.getLength() )
61 }
62}
63
65{
66}
67
69{
71
72 SolarMutexGuard aGuard;
73 m_pItemData = nullptr;
74 m_xGraphic.clear();
75 m_xStatusbarItem.clear();
76
77}
78
80 const FeatureStateEvent& rEvent)
81{
82 SolarMutexGuard aGuard;
83
84 if ( m_bDisposed || !m_xStatusbarItem.is() )
85 return;
86
87 m_bEnabled = rEvent.IsEnabled;
88
89 OUString aStrValue;
90 Reference< graphic::XGraphic > aGraphic;
91
92 if ( rEvent.State >>= aStrValue )
93 {
94 if ( !m_bOwnerDraw )
95 m_xStatusbarItem->setText( aStrValue );
96 else
97 {
98 if ( aStrValue.getLength() )
99 {
100 m_xStatusbarItem->setQuickHelpText( aStrValue );
101 }
102 }
103 }
104 else if ( ( rEvent.State >>= aGraphic ) && m_bOwnerDraw )
105 {
106 m_xGraphic = aGraphic;
107 }
108
109 // when the status is updated, and the controller is responsible for
110 // painting the statusbar item content, we must trigger a repaint
111 if ( m_bOwnerDraw && m_xStatusbarItem->getVisible() )
112 {
113 m_xStatusbarItem->repaint();
114 }
115}
116
118 const Reference< awt::XGraphics >& xGraphics,
119 const awt::Rectangle& rOutputRectangle,
120 ::sal_Int32 /*nStyle*/ )
121{
122 SolarMutexGuard aGuard;
123
124 const Reference< awt::XGraphics2 > xGraphics2(xGraphics, UNO_QUERY);
125
126 if ( !m_xStatusbarItem.is() || !xGraphics2.is() )
127 return;
128
129 Reference< beans::XPropertySet > xGraphicProps( m_xGraphic, UNO_QUERY );
130
131 if ( xGraphicProps.is() && m_xGraphic->getType() != graphic::GraphicType::EMPTY )
132 {
133 awt::Size aGraphicSize;
134 xGraphicProps->getPropertyValue( "SizePixel" ) >>= aGraphicSize;
135 OSL_ENSURE( aGraphicSize.Height > 0 && aGraphicSize.Width > 0, "Empty status bar graphic!" );
136
137 sal_Int32 nOffset = m_xStatusbarItem->getOffset( );
138 awt::Point aPos;
139 aPos.X = ( rOutputRectangle.Width + nOffset ) / 2 - aGraphicSize.Width / 2;
140 aPos.Y = rOutputRectangle.Height / 2 - aGraphicSize.Height / 2;
141
142 xGraphics2->drawImage( rOutputRectangle.X + aPos.X,
143 rOutputRectangle.Y + aPos.Y,
144 aGraphicSize.Width,
145 aGraphicSize.Height,
146 m_bEnabled ? awt::ImageDrawMode::NONE : awt::ImageDrawMode::DISABLE,
147 m_xGraphic );
148 }
149 else
150 {
151 xGraphics2->clear( rOutputRectangle );
152 }
153}
154
155}
156
157/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual void SAL_CALL statusChanged(const css::frame::FeatureStateEvent &Event) override
css::uno::Reference< css::graphic::XGraphic > m_xGraphic
virtual void SAL_CALL paint(const css::uno::Reference< css::awt::XGraphics > &xGraphics, const css::awt::Rectangle &rOutputRectangle, ::sal_Int32 nStyle) override
GenericStatusbarController(const css::uno::Reference< css::uno::XComponentContext > &rxContext, const css::uno::Reference< css::frame::XFrame > &rFrame, const css::uno::Reference< css::ui::XStatusbarItem > &rxItem, AddonStatusbarItemData *pItemData)
css::uno::Reference< css::ui::XStatusbarItem > m_xStatusbarItem
virtual void SAL_CALL dispose() override