1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 // MARKER(update_precomp.py): autogen include statement, do not remove 23 #include "precompiled_framework.hxx" 24 25 #include <uielement/statusbaritem.hxx> 26 #include <vcl/status.hxx> 27 #include <vcl/svapp.hxx> 28 #include <vos/mutex.hxx> 29 30 #include <com/sun/star/ui/ItemStyle.hpp> 31 32 using namespace com::sun::star::ui; 33 34 using rtl::OUString; 35 using com::sun::star::uno::RuntimeException; 36 37 namespace framework 38 { 39 40 namespace 41 { 42 static sal_uInt16 impl_convertItemBitsToItemStyle( sal_Int16 nItemBits ) 43 { 44 sal_uInt16 nStyle( 0 ); 45 46 if ( ( nItemBits & SIB_RIGHT ) == SIB_RIGHT ) 47 nStyle |= ItemStyle::ALIGN_RIGHT; 48 else if ( ( nItemBits & SIB_LEFT ) == SIB_LEFT ) 49 nStyle |= ItemStyle::ALIGN_LEFT; 50 else 51 nStyle |= ItemStyle::ALIGN_CENTER; 52 53 if ( ( nItemBits & SIB_FLAT ) == SIB_FLAT ) 54 nStyle |= ItemStyle::DRAW_FLAT; 55 else if ( ( nItemBits & SIB_OUT ) == SIB_OUT ) 56 nStyle |= ItemStyle::DRAW_OUT3D; 57 else 58 nStyle |= ItemStyle::DRAW_IN3D; 59 60 if ( ( nItemBits & SIB_AUTOSIZE ) == SIB_AUTOSIZE ) 61 nStyle |= ItemStyle::AUTO_SIZE; 62 63 if ( ( nItemBits & SIB_USERDRAW ) == SIB_USERDRAW ) 64 nStyle |= ItemStyle::OWNER_DRAW; 65 66 return nStyle; 67 } 68 } 69 70 StatusbarItem::StatusbarItem( 71 StatusBar *pStatusBar, 72 AddonStatusbarItemData *pItemData, 73 sal_uInt16 nId, 74 const rtl::OUString& aCommand ) 75 : StatusbarItem_Base( m_aMutex ) 76 , m_pStatusBar( pStatusBar ) 77 , m_pItemData( pItemData ) 78 , m_nId( nId ) 79 , m_nStyle( 0 ) 80 , m_aCommand( aCommand ) 81 { 82 if ( m_pStatusBar ) 83 m_nStyle = impl_convertItemBitsToItemStyle( 84 m_pStatusBar->GetItemBits( m_nId ) ); 85 } 86 87 StatusbarItem::~StatusbarItem() 88 { 89 } 90 91 void SAL_CALL StatusbarItem::disposing() 92 { 93 osl::MutexGuard aGuard( m_aMutex ); 94 m_pItemData = 0; 95 m_pStatusBar = 0; 96 } 97 98 OUString SAL_CALL StatusbarItem::getCommand() 99 throw (RuntimeException) 100 { 101 osl::MutexGuard aGuard( m_aMutex ); 102 return m_aCommand; 103 } 104 105 ::sal_uInt16 SAL_CALL StatusbarItem::getItemId() 106 throw (RuntimeException) 107 { 108 osl::MutexGuard aGuard( m_aMutex ); 109 return m_nId; 110 } 111 112 ::sal_uInt32 SAL_CALL StatusbarItem::getWidth() 113 throw (RuntimeException) 114 { 115 vos::OGuard aSolarGuard( Application::GetSolarMutex() ); 116 osl::MutexGuard aGuard( m_aMutex ); 117 if ( m_pStatusBar ) 118 return m_pStatusBar->GetItemWidth( m_nId ); 119 120 return ::sal_uInt32(0); 121 } 122 123 ::sal_uInt16 SAL_CALL StatusbarItem::getStyle() 124 throw (RuntimeException) 125 { 126 osl::MutexGuard aGuard( m_aMutex ); 127 return m_nStyle; 128 } 129 130 ::sal_Int32 SAL_CALL StatusbarItem::getOffset() 131 throw (RuntimeException) 132 { 133 vos::OGuard aSolarGuard( Application::GetSolarMutex() ); 134 osl::MutexGuard aGuard( m_aMutex ); 135 if ( m_pStatusBar ) 136 return m_pStatusBar->GetItemOffset( m_nId ); 137 138 return ::sal_Int32(0); 139 } 140 141 ::com::sun::star::awt::Rectangle SAL_CALL StatusbarItem::getItemRect() 142 throw (RuntimeException) 143 { 144 vos::OGuard aSolarGuard( Application::GetSolarMutex() ); 145 osl::MutexGuard aGuard( m_aMutex ); 146 ::com::sun::star::awt::Rectangle aAWTRect; 147 if ( m_pStatusBar ) 148 { 149 Rectangle aRect = m_pStatusBar->GetItemRect( m_nId ); 150 return ::com::sun::star::awt::Rectangle( aRect.Left(), 151 aRect.Top(), 152 aRect.GetWidth(), 153 aRect.GetHeight() ); 154 } 155 156 return aAWTRect; 157 } 158 159 OUString SAL_CALL StatusbarItem::getText() 160 throw (RuntimeException) 161 { 162 vos::OGuard aSolarGuard( Application::GetSolarMutex() ); 163 osl::MutexGuard aGuard( m_aMutex ); 164 if ( m_pStatusBar ) 165 return m_pStatusBar->GetItemText( m_nId ); 166 167 return OUString(); 168 } 169 170 void SAL_CALL StatusbarItem::setText( const OUString& rText ) 171 throw (RuntimeException) 172 { 173 vos::OGuard aSolarGuard( Application::GetSolarMutex() ); 174 osl::MutexGuard aGuard( m_aMutex ); 175 if ( m_pStatusBar ) 176 m_pStatusBar->SetItemText( m_nId, rText );; 177 } 178 179 OUString SAL_CALL StatusbarItem::getHelpText() 180 throw (RuntimeException) 181 { 182 vos::OGuard aSolarGuard( Application::GetSolarMutex() ); 183 osl::MutexGuard aGuard( m_aMutex ); 184 if ( m_pStatusBar ) 185 return m_pStatusBar->GetHelpText( m_nId ); 186 187 return OUString(); 188 } 189 190 void SAL_CALL StatusbarItem::setHelpText( const OUString& rHelpText ) 191 throw (RuntimeException) 192 { 193 vos::OGuard aSolarGuard( Application::GetSolarMutex() ); 194 osl::MutexGuard aGuard( m_aMutex ); 195 if ( m_pStatusBar ) 196 m_pStatusBar->SetHelpText( m_nId, rHelpText );; 197 } 198 199 OUString SAL_CALL StatusbarItem::getQuickHelpText() 200 throw (RuntimeException) 201 { 202 vos::OGuard aSolarGuard( Application::GetSolarMutex() ); 203 osl::MutexGuard aGuard( m_aMutex ); 204 if ( m_pStatusBar ) 205 return m_pStatusBar->GetHelpText( m_nId ); 206 207 return OUString(); 208 } 209 210 void SAL_CALL StatusbarItem::setQuickHelpText( const OUString& rQuickHelpText ) 211 throw (RuntimeException) 212 { 213 vos::OGuard aSolarGuard( Application::GetSolarMutex() ); 214 osl::MutexGuard aGuard( m_aMutex ); 215 if ( m_pStatusBar ) 216 m_pStatusBar->SetQuickHelpText( m_nId, rQuickHelpText ); 217 } 218 219 OUString SAL_CALL StatusbarItem::getAccessibleName() 220 throw (RuntimeException) 221 { 222 vos::OGuard aSolarGuard( Application::GetSolarMutex() ); 223 osl::MutexGuard aGuard( m_aMutex ); 224 if ( m_pStatusBar ) 225 return m_pStatusBar->GetAccessibleName( m_nId ); 226 227 return OUString(); 228 } 229 230 void SAL_CALL StatusbarItem::setAccessibleName( const OUString& rAccessibleName ) 231 throw (RuntimeException) 232 { 233 vos::OGuard aSolarGuard( Application::GetSolarMutex() ); 234 osl::MutexGuard aGuard( m_aMutex ); 235 if ( m_pStatusBar ) 236 m_pStatusBar->SetAccessibleName( m_nId, rAccessibleName ); 237 } 238 239 ::sal_Bool SAL_CALL StatusbarItem::getVisible() 240 throw (RuntimeException) 241 { 242 vos::OGuard aSolarGuard( Application::GetSolarMutex() ); 243 osl::MutexGuard aGuard( m_aMutex ); 244 if ( m_pStatusBar ) 245 return m_pStatusBar->IsItemVisible( m_nId ); 246 247 return sal_False; 248 } 249 250 void SAL_CALL StatusbarItem::setVisible( ::sal_Bool bVisible ) 251 throw (RuntimeException) 252 { 253 vos::OGuard aSolarGuard( Application::GetSolarMutex() ); 254 osl::MutexGuard aGuard( m_aMutex ); 255 if ( !m_pStatusBar ) 256 return; 257 258 if ( bVisible != m_pStatusBar->IsItemVisible( m_nId ) ) 259 { 260 if ( bVisible ) 261 m_pStatusBar->ShowItem( m_nId ); 262 else 263 m_pStatusBar->HideItem( m_nId ); 264 } 265 } 266 267 void SAL_CALL StatusbarItem::repaint( ) 268 throw (RuntimeException) 269 { 270 vos::OGuard aSolarGuard( Application::GetSolarMutex() ); 271 osl::MutexGuard aGuard( m_aMutex ); 272 if ( m_pStatusBar ) 273 { 274 m_pStatusBar->RedrawItem( m_nId ); 275 } 276 } 277 278 } 279