Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / framework / source / uielement / statusbaritem.cxx
blobbaf321fd61c803b92866bce15213448b1f9351cb
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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/statusbaritem.hxx>
21 #include <utility>
22 #include <vcl/status.hxx>
23 #include <vcl/svapp.hxx>
25 #include <com/sun/star/ui/ItemStyle.hpp>
27 using namespace com::sun::star::ui;
29 namespace framework
32 namespace
34 sal_uInt16 impl_convertItemBitsToItemStyle( StatusBarItemBits nItemBits )
36 sal_uInt16 nStyle( 0 );
38 if ( nItemBits & StatusBarItemBits::Right )
39 nStyle |= ItemStyle::ALIGN_RIGHT;
40 else if ( nItemBits & StatusBarItemBits::Left )
41 nStyle |= ItemStyle::ALIGN_LEFT;
42 else
43 nStyle |= ItemStyle::ALIGN_CENTER;
45 if ( nItemBits & StatusBarItemBits::Flat )
46 nStyle |= ItemStyle::DRAW_FLAT;
47 else if ( nItemBits & StatusBarItemBits::Out )
48 nStyle |= ItemStyle::DRAW_OUT3D;
49 else
50 nStyle |= ItemStyle::DRAW_IN3D;
52 if ( nItemBits & StatusBarItemBits::AutoSize )
53 nStyle |= ItemStyle::AUTO_SIZE;
55 if ( nItemBits & StatusBarItemBits::UserDraw )
56 nStyle |= ItemStyle::OWNER_DRAW;
58 return nStyle;
62 StatusbarItem::StatusbarItem(
63 StatusBar *pStatusBar,
64 sal_uInt16 nId,
65 OUString aCommand )
66 : m_pStatusBar( pStatusBar )
67 , m_nId( nId )
68 , m_nStyle( 0 )
69 , m_aCommand(std::move( aCommand ))
71 if ( m_pStatusBar )
72 m_nStyle = impl_convertItemBitsToItemStyle(
73 m_pStatusBar->GetItemBits( m_nId ) );
76 StatusbarItem::~StatusbarItem()
80 void StatusbarItem::disposing(std::unique_lock<std::mutex>&)
82 m_pStatusBar = nullptr;
85 OUString SAL_CALL StatusbarItem::getCommand()
87 std::unique_lock aGuard( m_aMutex );
88 return m_aCommand;
91 ::sal_uInt16 SAL_CALL StatusbarItem::getItemId()
93 std::unique_lock aGuard( m_aMutex );
94 return m_nId;
97 ::sal_uInt32 SAL_CALL StatusbarItem::getWidth()
99 SolarMutexGuard aGuard;
100 if ( m_pStatusBar )
101 return m_pStatusBar->GetItemWidth( m_nId );
103 return ::sal_uInt32(0);
106 ::sal_uInt16 SAL_CALL StatusbarItem::getStyle()
108 std::unique_lock aGuard( m_aMutex );
109 return m_nStyle;
112 ::sal_Int32 SAL_CALL StatusbarItem::getOffset()
114 SolarMutexGuard aGuard;
115 if ( m_pStatusBar )
116 return m_pStatusBar->GetItemOffset( m_nId );
118 return 0;
121 css::awt::Rectangle SAL_CALL StatusbarItem::getItemRect()
123 SolarMutexGuard aGuard;
124 css::awt::Rectangle aAWTRect;
125 if ( m_pStatusBar )
127 tools::Rectangle aRect = m_pStatusBar->GetItemRect( m_nId );
128 return css::awt::Rectangle( aRect.Left(),
129 aRect.Top(),
130 aRect.GetWidth(),
131 aRect.GetHeight() );
134 return aAWTRect;
137 OUString SAL_CALL StatusbarItem::getText()
139 SolarMutexGuard aGuard;
140 if ( m_pStatusBar )
141 return m_pStatusBar->GetItemText( m_nId );
143 return OUString();
146 void SAL_CALL StatusbarItem::setText( const OUString& rText )
148 SolarMutexGuard aGuard;
149 if ( m_pStatusBar )
150 m_pStatusBar->SetItemText( m_nId, rText );
153 OUString SAL_CALL StatusbarItem::getHelpText()
155 SolarMutexGuard aGuard;
156 if ( m_pStatusBar )
157 return m_pStatusBar->GetHelpText( m_nId );
159 return OUString();
162 void SAL_CALL StatusbarItem::setHelpText( const OUString& rHelpText )
164 SolarMutexGuard aGuard;
165 if ( m_pStatusBar )
166 m_pStatusBar->SetHelpText( m_nId, rHelpText );
169 OUString SAL_CALL StatusbarItem::getQuickHelpText()
171 SolarMutexGuard aGuard;
172 if ( m_pStatusBar )
173 return m_pStatusBar->GetHelpText( m_nId );
175 return OUString();
178 void SAL_CALL StatusbarItem::setQuickHelpText( const OUString& rQuickHelpText )
180 SolarMutexGuard aGuard;
181 if ( m_pStatusBar )
182 m_pStatusBar->SetQuickHelpText( m_nId, rQuickHelpText );
185 OUString SAL_CALL StatusbarItem::getAccessibleName()
187 SolarMutexGuard aGuard;
188 if ( m_pStatusBar )
189 return m_pStatusBar->GetAccessibleName( m_nId );
191 return OUString();
194 void SAL_CALL StatusbarItem::setAccessibleName( const OUString& rAccessibleName )
196 SolarMutexGuard aGuard;
197 if ( m_pStatusBar )
198 m_pStatusBar->SetAccessibleName( m_nId, rAccessibleName );
201 sal_Bool SAL_CALL StatusbarItem::getVisible()
203 SolarMutexGuard aGuard;
204 if ( m_pStatusBar )
205 return m_pStatusBar->IsItemVisible( m_nId );
207 return false;
210 void SAL_CALL StatusbarItem::setVisible( sal_Bool bVisible )
212 SolarMutexGuard aGuard;
213 if ( !m_pStatusBar )
214 return;
216 if ( bool(bVisible) != m_pStatusBar->IsItemVisible( m_nId ) )
218 if ( bVisible )
219 m_pStatusBar->ShowItem( m_nId );
220 else
221 m_pStatusBar->HideItem( m_nId );
225 void SAL_CALL StatusbarItem::repaint( )
227 SolarMutexGuard aGuard;
228 if ( m_pStatusBar )
230 m_pStatusBar->RedrawItem( m_nId );
236 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */