LibreOffice Module framework (master) 1
statusbaritem.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
21#include <utility>
22#include <vcl/status.hxx>
23#include <vcl/svapp.hxx>
24
25#include <com/sun/star/ui/ItemStyle.hpp>
26
27using namespace com::sun::star::ui;
28
29namespace framework
30{
31
32namespace
33{
34sal_uInt16 impl_convertItemBitsToItemStyle( StatusBarItemBits nItemBits )
35{
36 sal_uInt16 nStyle( 0 );
37
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;
44
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;
51
52 if ( nItemBits & StatusBarItemBits::AutoSize )
53 nStyle |= ItemStyle::AUTO_SIZE;
54
55 if ( nItemBits & StatusBarItemBits::UserDraw )
56 nStyle |= ItemStyle::OWNER_DRAW;
57
58 return nStyle;
59}
60}
61
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 ))
70{
71 if ( m_pStatusBar )
72 m_nStyle = impl_convertItemBitsToItemStyle(
73 m_pStatusBar->GetItemBits( m_nId ) );
74}
75
77{
78}
79
80void StatusbarItem::disposing(std::unique_lock<std::mutex>&)
81{
82 m_pStatusBar = nullptr;
83}
84
85OUString SAL_CALL StatusbarItem::getCommand()
86{
87 std::unique_lock aGuard( m_aMutex );
88 return m_aCommand;
89}
90
91::sal_uInt16 SAL_CALL StatusbarItem::getItemId()
92{
93 std::unique_lock aGuard( m_aMutex );
94 return m_nId;
95}
96
97::sal_uInt32 SAL_CALL StatusbarItem::getWidth()
98{
99 SolarMutexGuard aGuard;
100 if ( m_pStatusBar )
101 return m_pStatusBar->GetItemWidth( m_nId );
102
103 return ::sal_uInt32(0);
104}
105
106::sal_uInt16 SAL_CALL StatusbarItem::getStyle()
107{
108 std::unique_lock aGuard( m_aMutex );
109 return m_nStyle;
110}
111
112::sal_Int32 SAL_CALL StatusbarItem::getOffset()
113{
114 SolarMutexGuard aGuard;
115 if ( m_pStatusBar )
116 return m_pStatusBar->GetItemOffset( m_nId );
117
118 return 0;
119}
120
121css::awt::Rectangle SAL_CALL StatusbarItem::getItemRect()
122{
123 SolarMutexGuard aGuard;
124 css::awt::Rectangle aAWTRect;
125 if ( m_pStatusBar )
126 {
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() );
132 }
133
134 return aAWTRect;
135}
136
137OUString SAL_CALL StatusbarItem::getText()
138{
139 SolarMutexGuard aGuard;
140 if ( m_pStatusBar )
141 return m_pStatusBar->GetItemText( m_nId );
142
143 return OUString();
144}
145
146void SAL_CALL StatusbarItem::setText( const OUString& rText )
147{
148 SolarMutexGuard aGuard;
149 if ( m_pStatusBar )
150 m_pStatusBar->SetItemText( m_nId, rText );
151}
152
153OUString SAL_CALL StatusbarItem::getHelpText()
154{
155 SolarMutexGuard aGuard;
156 if ( m_pStatusBar )
157 return m_pStatusBar->GetHelpText( m_nId );
158
159 return OUString();
160}
161
162void SAL_CALL StatusbarItem::setHelpText( const OUString& rHelpText )
163{
164 SolarMutexGuard aGuard;
165 if ( m_pStatusBar )
166 m_pStatusBar->SetHelpText( m_nId, rHelpText );
167}
168
170{
171 SolarMutexGuard aGuard;
172 if ( m_pStatusBar )
173 return m_pStatusBar->GetHelpText( m_nId );
174
175 return OUString();
176}
177
178void SAL_CALL StatusbarItem::setQuickHelpText( const OUString& rQuickHelpText )
179{
180 SolarMutexGuard aGuard;
181 if ( m_pStatusBar )
182 m_pStatusBar->SetQuickHelpText( m_nId, rQuickHelpText );
183}
184
186{
187 SolarMutexGuard aGuard;
188 if ( m_pStatusBar )
189 return m_pStatusBar->GetAccessibleName( m_nId );
190
191 return OUString();
192}
193
194void SAL_CALL StatusbarItem::setAccessibleName( const OUString& rAccessibleName )
195{
196 SolarMutexGuard aGuard;
197 if ( m_pStatusBar )
198 m_pStatusBar->SetAccessibleName( m_nId, rAccessibleName );
199}
200
202{
203 SolarMutexGuard aGuard;
204 if ( m_pStatusBar )
205 return m_pStatusBar->IsItemVisible( m_nId );
206
207 return false;
208}
209
211{
212 SolarMutexGuard aGuard;
213 if ( !m_pStatusBar )
214 return;
215
216 if ( bool(bVisible) != m_pStatusBar->IsItemVisible( m_nId ) )
217 {
218 if ( bVisible )
219 m_pStatusBar->ShowItem( m_nId );
220 else
221 m_pStatusBar->HideItem( m_nId );
222 }
223}
224
226{
227 SolarMutexGuard aGuard;
228 if ( m_pStatusBar )
229 {
230 m_pStatusBar->RedrawItem( m_nId );
231 }
232}
233
234}
235
236/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual sal_Bool SAL_CALL getVisible() override
virtual ::sal_uInt16 SAL_CALL getStyle() override
virtual ~StatusbarItem() override
virtual void SAL_CALL setVisible(sal_Bool bVisible) override
virtual void SAL_CALL setQuickHelpText(const OUString &rQuickHelpText) override
virtual void SAL_CALL repaint() override
virtual void SAL_CALL setAccessibleName(const OUString &rAccessibleName) override
void disposing(std::unique_lock< std::mutex > &) override
virtual OUString SAL_CALL getQuickHelpText() override
virtual OUString SAL_CALL getCommand() override
virtual OUString SAL_CALL getAccessibleName() override
virtual OUString SAL_CALL getHelpText() override
virtual ::sal_Int32 SAL_CALL getOffset() override
virtual css::awt::Rectangle SAL_CALL getItemRect() override
StatusbarItem(StatusBar *pStatusBar, sal_uInt16 nId, OUString aCommand)
virtual void SAL_CALL setText(const OUString &rText) override
virtual OUString SAL_CALL getText() override
virtual ::sal_uInt16 SAL_CALL getItemId() override
VclPtr< StatusBar > m_pStatusBar
virtual void SAL_CALL setHelpText(const OUString &rHelpText) override
virtual ::sal_uInt32 SAL_CALL getWidth() override
constexpr tools::Long GetWidth() const
constexpr tools::Long Top() const
constexpr tools::Long GetHeight() const
constexpr tools::Long Left() const
sal_Int16 nId
StatusBarItemBits
bool bVisible
OUString aCommand
unsigned char sal_Bool