1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir 28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 29*cdf0e10cSrcweir #include "precompiled_svtools.hxx" 30*cdf0e10cSrcweir 31*cdf0e10cSrcweir 32*cdf0e10cSrcweir #include <svtools/svlbox.hxx> 33*cdf0e10cSrcweir #include <svtools/svlbitm.hxx> 34*cdf0e10cSrcweir #include <vcl/svapp.hxx> 35*cdf0e10cSrcweir #ifndef _SV_BUTTON_HXX 36*cdf0e10cSrcweir #include <vcl/button.hxx> 37*cdf0e10cSrcweir #endif 38*cdf0e10cSrcweir #include <vcl/decoview.hxx> 39*cdf0e10cSrcweir #include <vcl/sound.hxx> 40*cdf0e10cSrcweir #include <vcl/salnativewidgets.hxx> 41*cdf0e10cSrcweir 42*cdf0e10cSrcweir #define TABOFFS_NOT_VALID -2000000 43*cdf0e10cSrcweir 44*cdf0e10cSrcweir struct SvLBoxButtonData_Impl 45*cdf0e10cSrcweir { 46*cdf0e10cSrcweir SvLBoxEntry* pEntry; 47*cdf0e10cSrcweir sal_Bool bDefaultImages; 48*cdf0e10cSrcweir sal_Bool bShowRadioButton; 49*cdf0e10cSrcweir 50*cdf0e10cSrcweir SvLBoxButtonData_Impl() : pEntry( NULL ), bDefaultImages( sal_False ), bShowRadioButton( sal_False ) {} 51*cdf0e10cSrcweir }; 52*cdf0e10cSrcweir 53*cdf0e10cSrcweir 54*cdf0e10cSrcweir DBG_NAME(SvLBoxButtonData) 55*cdf0e10cSrcweir 56*cdf0e10cSrcweir void SvLBoxButtonData::InitData( sal_Bool bImagesFromDefault, bool _bRadioBtn, const Control* pCtrl ) 57*cdf0e10cSrcweir { 58*cdf0e10cSrcweir pImpl = new SvLBoxButtonData_Impl; 59*cdf0e10cSrcweir 60*cdf0e10cSrcweir bDataOk = sal_False; 61*cdf0e10cSrcweir eState = SV_BUTTON_UNCHECKED; 62*cdf0e10cSrcweir pImpl->bDefaultImages = bImagesFromDefault; 63*cdf0e10cSrcweir pImpl->bShowRadioButton = ( _bRadioBtn != false ); 64*cdf0e10cSrcweir 65*cdf0e10cSrcweir if ( bImagesFromDefault ) 66*cdf0e10cSrcweir SetDefaultImages( pCtrl ); 67*cdf0e10cSrcweir } 68*cdf0e10cSrcweir 69*cdf0e10cSrcweir SvLBoxButtonData::SvLBoxButtonData( const Control* pControlForSettings ) 70*cdf0e10cSrcweir { 71*cdf0e10cSrcweir DBG_CTOR(SvLBoxButtonData,0); 72*cdf0e10cSrcweir 73*cdf0e10cSrcweir InitData( sal_True, false, pControlForSettings ); 74*cdf0e10cSrcweir } 75*cdf0e10cSrcweir 76*cdf0e10cSrcweir SvLBoxButtonData::SvLBoxButtonData( const Control* pControlForSettings, bool _bRadioBtn ) 77*cdf0e10cSrcweir { 78*cdf0e10cSrcweir DBG_CTOR(SvLBoxButtonData,0); 79*cdf0e10cSrcweir 80*cdf0e10cSrcweir InitData( sal_True, _bRadioBtn, pControlForSettings ); 81*cdf0e10cSrcweir } 82*cdf0e10cSrcweir 83*cdf0e10cSrcweir SvLBoxButtonData::SvLBoxButtonData() 84*cdf0e10cSrcweir { 85*cdf0e10cSrcweir DBG_CTOR(SvLBoxButtonData,0); 86*cdf0e10cSrcweir 87*cdf0e10cSrcweir InitData( sal_False, false ); 88*cdf0e10cSrcweir } 89*cdf0e10cSrcweir 90*cdf0e10cSrcweir SvLBoxButtonData::~SvLBoxButtonData() 91*cdf0e10cSrcweir { 92*cdf0e10cSrcweir DBG_DTOR(SvLBoxButtonData,0); 93*cdf0e10cSrcweir 94*cdf0e10cSrcweir delete pImpl; 95*cdf0e10cSrcweir #ifdef DBG_UTIL 96*cdf0e10cSrcweir pImpl = NULL; 97*cdf0e10cSrcweir #endif 98*cdf0e10cSrcweir } 99*cdf0e10cSrcweir 100*cdf0e10cSrcweir void SvLBoxButtonData::CallLink() 101*cdf0e10cSrcweir { 102*cdf0e10cSrcweir DBG_CHKTHIS(SvLBoxButtonData,0); 103*cdf0e10cSrcweir aLink.Call( this ); 104*cdf0e10cSrcweir } 105*cdf0e10cSrcweir 106*cdf0e10cSrcweir sal_uInt16 SvLBoxButtonData::GetIndex( sal_uInt16 nItemState ) 107*cdf0e10cSrcweir { 108*cdf0e10cSrcweir DBG_CHKTHIS(SvLBoxButtonData,0); 109*cdf0e10cSrcweir nItemState &= 0x000F; 110*cdf0e10cSrcweir sal_uInt16 nIdx; 111*cdf0e10cSrcweir switch( nItemState ) 112*cdf0e10cSrcweir { 113*cdf0e10cSrcweir case SV_ITEMSTATE_UNCHECKED: 114*cdf0e10cSrcweir nIdx = SV_BMP_UNCHECKED; break; 115*cdf0e10cSrcweir case SV_ITEMSTATE_CHECKED: 116*cdf0e10cSrcweir nIdx = SV_BMP_CHECKED; break; 117*cdf0e10cSrcweir case SV_ITEMSTATE_TRISTATE: 118*cdf0e10cSrcweir nIdx = SV_BMP_TRISTATE; break; 119*cdf0e10cSrcweir case SV_ITEMSTATE_UNCHECKED | SV_ITEMSTATE_HILIGHTED: 120*cdf0e10cSrcweir nIdx = SV_BMP_HIUNCHECKED; break; 121*cdf0e10cSrcweir case SV_ITEMSTATE_CHECKED | SV_ITEMSTATE_HILIGHTED: 122*cdf0e10cSrcweir nIdx = SV_BMP_HICHECKED; break; 123*cdf0e10cSrcweir case SV_ITEMSTATE_TRISTATE | SV_ITEMSTATE_HILIGHTED: 124*cdf0e10cSrcweir nIdx = SV_BMP_HITRISTATE; break; 125*cdf0e10cSrcweir default: 126*cdf0e10cSrcweir nIdx = SV_BMP_UNCHECKED; 127*cdf0e10cSrcweir } 128*cdf0e10cSrcweir return nIdx; 129*cdf0e10cSrcweir } 130*cdf0e10cSrcweir 131*cdf0e10cSrcweir void SvLBoxButtonData::SetWidthAndHeight() 132*cdf0e10cSrcweir { 133*cdf0e10cSrcweir DBG_CHKTHIS(SvLBoxButtonData,0); 134*cdf0e10cSrcweir Size aSize = aBmps[0].GetSizePixel(); 135*cdf0e10cSrcweir nWidth = aSize.Width(); 136*cdf0e10cSrcweir nHeight = aSize.Height(); 137*cdf0e10cSrcweir bDataOk = sal_True; 138*cdf0e10cSrcweir } 139*cdf0e10cSrcweir 140*cdf0e10cSrcweir 141*cdf0e10cSrcweir void SvLBoxButtonData::StoreButtonState( SvLBoxEntry* pActEntry, sal_uInt16 nItemFlags ) 142*cdf0e10cSrcweir { 143*cdf0e10cSrcweir DBG_CHKTHIS(SvLBoxButtonData,0); 144*cdf0e10cSrcweir pImpl->pEntry = pActEntry; 145*cdf0e10cSrcweir eState = ConvertToButtonState( nItemFlags ); 146*cdf0e10cSrcweir } 147*cdf0e10cSrcweir 148*cdf0e10cSrcweir SvButtonState SvLBoxButtonData::ConvertToButtonState( sal_uInt16 nItemFlags ) const 149*cdf0e10cSrcweir { 150*cdf0e10cSrcweir DBG_CHKTHIS(SvLBoxButtonData,0); 151*cdf0e10cSrcweir nItemFlags &= (SV_ITEMSTATE_UNCHECKED | 152*cdf0e10cSrcweir SV_ITEMSTATE_CHECKED | 153*cdf0e10cSrcweir SV_ITEMSTATE_TRISTATE); 154*cdf0e10cSrcweir switch( nItemFlags ) 155*cdf0e10cSrcweir { 156*cdf0e10cSrcweir case SV_ITEMSTATE_UNCHECKED: 157*cdf0e10cSrcweir return SV_BUTTON_UNCHECKED; 158*cdf0e10cSrcweir 159*cdf0e10cSrcweir case SV_ITEMSTATE_CHECKED: 160*cdf0e10cSrcweir return SV_BUTTON_CHECKED; 161*cdf0e10cSrcweir 162*cdf0e10cSrcweir case SV_ITEMSTATE_TRISTATE: 163*cdf0e10cSrcweir return SV_BUTTON_TRISTATE; 164*cdf0e10cSrcweir default: 165*cdf0e10cSrcweir return SV_BUTTON_UNCHECKED; 166*cdf0e10cSrcweir } 167*cdf0e10cSrcweir } 168*cdf0e10cSrcweir 169*cdf0e10cSrcweir SvLBoxEntry* SvLBoxButtonData::GetActEntry() const 170*cdf0e10cSrcweir { 171*cdf0e10cSrcweir DBG_ASSERT( pImpl, "-SvLBoxButtonData::GetActEntry(): don't use me that way!" ); 172*cdf0e10cSrcweir return pImpl->pEntry; 173*cdf0e10cSrcweir } 174*cdf0e10cSrcweir 175*cdf0e10cSrcweir void SvLBoxButtonData::SetDefaultImages( const Control* pCtrl ) 176*cdf0e10cSrcweir { 177*cdf0e10cSrcweir const AllSettings& rSettings = pCtrl? pCtrl->GetSettings() : Application::GetSettings(); 178*cdf0e10cSrcweir 179*cdf0e10cSrcweir if ( pImpl->bShowRadioButton ) 180*cdf0e10cSrcweir { 181*cdf0e10cSrcweir aBmps[ SV_BMP_UNCHECKED ] = RadioButton::GetRadioImage( rSettings, BUTTON_DRAW_DEFAULT ); 182*cdf0e10cSrcweir aBmps[ SV_BMP_CHECKED ] = RadioButton::GetRadioImage( rSettings, BUTTON_DRAW_CHECKED ); 183*cdf0e10cSrcweir aBmps[ SV_BMP_HICHECKED ] = RadioButton::GetRadioImage( rSettings, BUTTON_DRAW_CHECKED | BUTTON_DRAW_PRESSED ); 184*cdf0e10cSrcweir aBmps[ SV_BMP_HIUNCHECKED ] = RadioButton::GetRadioImage( rSettings, BUTTON_DRAW_DEFAULT | BUTTON_DRAW_PRESSED ); 185*cdf0e10cSrcweir aBmps[ SV_BMP_TRISTATE ] = RadioButton::GetRadioImage( rSettings, BUTTON_DRAW_DONTKNOW ); 186*cdf0e10cSrcweir aBmps[ SV_BMP_HITRISTATE ] = RadioButton::GetRadioImage( rSettings, BUTTON_DRAW_DONTKNOW | BUTTON_DRAW_PRESSED ); 187*cdf0e10cSrcweir } 188*cdf0e10cSrcweir else 189*cdf0e10cSrcweir { 190*cdf0e10cSrcweir aBmps[ SV_BMP_UNCHECKED ] = CheckBox::GetCheckImage( rSettings, BUTTON_DRAW_DEFAULT ); 191*cdf0e10cSrcweir aBmps[ SV_BMP_CHECKED ] = CheckBox::GetCheckImage( rSettings, BUTTON_DRAW_CHECKED ); 192*cdf0e10cSrcweir aBmps[ SV_BMP_HICHECKED ] = CheckBox::GetCheckImage( rSettings, BUTTON_DRAW_CHECKED | BUTTON_DRAW_PRESSED ); 193*cdf0e10cSrcweir aBmps[ SV_BMP_HIUNCHECKED ] = CheckBox::GetCheckImage( rSettings, BUTTON_DRAW_DEFAULT | BUTTON_DRAW_PRESSED ); 194*cdf0e10cSrcweir aBmps[ SV_BMP_TRISTATE ] = CheckBox::GetCheckImage( rSettings, BUTTON_DRAW_DONTKNOW ); 195*cdf0e10cSrcweir aBmps[ SV_BMP_HITRISTATE ] = CheckBox::GetCheckImage( rSettings, BUTTON_DRAW_DONTKNOW | BUTTON_DRAW_PRESSED ); 196*cdf0e10cSrcweir } 197*cdf0e10cSrcweir } 198*cdf0e10cSrcweir 199*cdf0e10cSrcweir sal_Bool SvLBoxButtonData::HasDefaultImages( void ) const 200*cdf0e10cSrcweir { 201*cdf0e10cSrcweir return pImpl->bDefaultImages; 202*cdf0e10cSrcweir } 203*cdf0e10cSrcweir 204*cdf0e10cSrcweir sal_Bool SvLBoxButtonData::IsRadio() { 205*cdf0e10cSrcweir return pImpl->bShowRadioButton; 206*cdf0e10cSrcweir } 207*cdf0e10cSrcweir 208*cdf0e10cSrcweir // *************************************************************** 209*cdf0e10cSrcweir // class SvLBoxString 210*cdf0e10cSrcweir // *************************************************************** 211*cdf0e10cSrcweir 212*cdf0e10cSrcweir DBG_NAME(SvLBoxString); 213*cdf0e10cSrcweir 214*cdf0e10cSrcweir SvLBoxString::SvLBoxString( SvLBoxEntry* pEntry,sal_uInt16 nFlags,const XubString& rStr) : 215*cdf0e10cSrcweir SvLBoxItem( pEntry, nFlags ) 216*cdf0e10cSrcweir { 217*cdf0e10cSrcweir DBG_CTOR(SvLBoxString,0); 218*cdf0e10cSrcweir SetText( pEntry, rStr ); 219*cdf0e10cSrcweir } 220*cdf0e10cSrcweir 221*cdf0e10cSrcweir SvLBoxString::SvLBoxString() : SvLBoxItem() 222*cdf0e10cSrcweir { 223*cdf0e10cSrcweir DBG_CTOR(SvLBoxString,0); 224*cdf0e10cSrcweir } 225*cdf0e10cSrcweir 226*cdf0e10cSrcweir SvLBoxString::~SvLBoxString() 227*cdf0e10cSrcweir { 228*cdf0e10cSrcweir DBG_DTOR(SvLBoxString,0); 229*cdf0e10cSrcweir } 230*cdf0e10cSrcweir 231*cdf0e10cSrcweir sal_uInt16 SvLBoxString::IsA() 232*cdf0e10cSrcweir { 233*cdf0e10cSrcweir DBG_CHKTHIS(SvLBoxString,0); 234*cdf0e10cSrcweir return SV_ITEM_ID_LBOXSTRING; 235*cdf0e10cSrcweir } 236*cdf0e10cSrcweir 237*cdf0e10cSrcweir void SvLBoxString::Paint( const Point& rPos, SvLBox& rDev, sal_uInt16 /* nFlags */, 238*cdf0e10cSrcweir SvLBoxEntry* _pEntry) 239*cdf0e10cSrcweir { 240*cdf0e10cSrcweir DBG_CHKTHIS(SvLBoxString,0); 241*cdf0e10cSrcweir if ( _pEntry ) 242*cdf0e10cSrcweir { 243*cdf0e10cSrcweir sal_uInt16 nStyle = rDev.IsEnabled() ? 0 : TEXT_DRAW_DISABLE; 244*cdf0e10cSrcweir if ( rDev.IsEntryMnemonicsEnabled() ) 245*cdf0e10cSrcweir nStyle |= TEXT_DRAW_MNEMONIC; 246*cdf0e10cSrcweir rDev.DrawText( Rectangle(rPos,GetSize(&rDev,_pEntry)),aStr,nStyle); 247*cdf0e10cSrcweir } 248*cdf0e10cSrcweir else 249*cdf0e10cSrcweir rDev.DrawText( rPos, aStr); 250*cdf0e10cSrcweir 251*cdf0e10cSrcweir } 252*cdf0e10cSrcweir 253*cdf0e10cSrcweir SvLBoxItem* SvLBoxString::Create() const 254*cdf0e10cSrcweir { 255*cdf0e10cSrcweir DBG_CHKTHIS(SvLBoxString,0); 256*cdf0e10cSrcweir return new SvLBoxString; 257*cdf0e10cSrcweir } 258*cdf0e10cSrcweir 259*cdf0e10cSrcweir void SvLBoxString::Clone( SvLBoxItem* pSource ) 260*cdf0e10cSrcweir { 261*cdf0e10cSrcweir DBG_CHKTHIS(SvLBoxString,0); 262*cdf0e10cSrcweir aStr = ((SvLBoxString*)pSource)->aStr; 263*cdf0e10cSrcweir } 264*cdf0e10cSrcweir 265*cdf0e10cSrcweir void SvLBoxString::SetText( SvLBoxEntry*, const XubString& rStr ) 266*cdf0e10cSrcweir { 267*cdf0e10cSrcweir DBG_CHKTHIS(SvLBoxString,0); 268*cdf0e10cSrcweir aStr = rStr; 269*cdf0e10cSrcweir } 270*cdf0e10cSrcweir 271*cdf0e10cSrcweir void SvLBoxString::InitViewData( SvLBox* pView,SvLBoxEntry* pEntry, 272*cdf0e10cSrcweir SvViewDataItem* pViewData) 273*cdf0e10cSrcweir { 274*cdf0e10cSrcweir DBG_CHKTHIS(SvLBoxString,0); 275*cdf0e10cSrcweir if( !pViewData ) 276*cdf0e10cSrcweir pViewData = pView->GetViewDataItem( pEntry, this ); 277*cdf0e10cSrcweir pViewData->aSize = Size(pView->GetTextWidth( aStr ), pView->GetTextHeight()); 278*cdf0e10cSrcweir } 279*cdf0e10cSrcweir 280*cdf0e10cSrcweir // *************************************************************** 281*cdf0e10cSrcweir // class SvLBoxBmp 282*cdf0e10cSrcweir // *************************************************************** 283*cdf0e10cSrcweir 284*cdf0e10cSrcweir DBG_NAME(SvLBoxBmp); 285*cdf0e10cSrcweir 286*cdf0e10cSrcweir SvLBoxBmp::SvLBoxBmp( SvLBoxEntry* pEntry, sal_uInt16 nFlags, Image aBitmap ) : 287*cdf0e10cSrcweir SvLBoxItem( pEntry, nFlags ) 288*cdf0e10cSrcweir { 289*cdf0e10cSrcweir DBG_CTOR(SvLBoxBmp,0); 290*cdf0e10cSrcweir SetBitmap( pEntry, aBitmap); 291*cdf0e10cSrcweir } 292*cdf0e10cSrcweir 293*cdf0e10cSrcweir SvLBoxBmp::SvLBoxBmp() : SvLBoxItem() 294*cdf0e10cSrcweir { 295*cdf0e10cSrcweir DBG_CTOR(SvLBoxBmp,0); 296*cdf0e10cSrcweir } 297*cdf0e10cSrcweir 298*cdf0e10cSrcweir SvLBoxBmp::~SvLBoxBmp() 299*cdf0e10cSrcweir { 300*cdf0e10cSrcweir DBG_DTOR(SvLBoxBmp,0); 301*cdf0e10cSrcweir } 302*cdf0e10cSrcweir 303*cdf0e10cSrcweir sal_uInt16 SvLBoxBmp::IsA() 304*cdf0e10cSrcweir { 305*cdf0e10cSrcweir DBG_CHKTHIS(SvLBoxBmp,0); 306*cdf0e10cSrcweir return SV_ITEM_ID_LBOXBMP; 307*cdf0e10cSrcweir } 308*cdf0e10cSrcweir 309*cdf0e10cSrcweir void SvLBoxBmp::SetBitmap( SvLBoxEntry*, Image aBitmap) 310*cdf0e10cSrcweir { 311*cdf0e10cSrcweir DBG_CHKTHIS(SvLBoxBmp,0); 312*cdf0e10cSrcweir aBmp = aBitmap; 313*cdf0e10cSrcweir } 314*cdf0e10cSrcweir 315*cdf0e10cSrcweir void SvLBoxBmp::InitViewData( SvLBox* pView,SvLBoxEntry* pEntry, 316*cdf0e10cSrcweir SvViewDataItem* pViewData) 317*cdf0e10cSrcweir { 318*cdf0e10cSrcweir DBG_CHKTHIS(SvLBoxBmp,0); 319*cdf0e10cSrcweir if( !pViewData ) 320*cdf0e10cSrcweir pViewData = pView->GetViewDataItem( pEntry, this ); 321*cdf0e10cSrcweir pViewData->aSize = aBmp.GetSizePixel(); 322*cdf0e10cSrcweir } 323*cdf0e10cSrcweir 324*cdf0e10cSrcweir void SvLBoxBmp::Paint( const Point& rPos, SvLBox& rDev, sal_uInt16 /* nFlags */, 325*cdf0e10cSrcweir SvLBoxEntry* ) 326*cdf0e10cSrcweir { 327*cdf0e10cSrcweir DBG_CHKTHIS(SvLBoxBmp,0); 328*cdf0e10cSrcweir sal_uInt16 nStyle = rDev.IsEnabled() ? 0 : IMAGE_DRAW_DISABLE; 329*cdf0e10cSrcweir rDev.DrawImage( rPos, aBmp ,nStyle); 330*cdf0e10cSrcweir } 331*cdf0e10cSrcweir 332*cdf0e10cSrcweir SvLBoxItem* SvLBoxBmp::Create() const 333*cdf0e10cSrcweir { 334*cdf0e10cSrcweir DBG_CHKTHIS(SvLBoxBmp,0); 335*cdf0e10cSrcweir return new SvLBoxBmp; 336*cdf0e10cSrcweir } 337*cdf0e10cSrcweir 338*cdf0e10cSrcweir void SvLBoxBmp::Clone( SvLBoxItem* pSource ) 339*cdf0e10cSrcweir { 340*cdf0e10cSrcweir DBG_CHKTHIS(SvLBoxBmp,0); 341*cdf0e10cSrcweir aBmp = ((SvLBoxBmp*)pSource)->aBmp; 342*cdf0e10cSrcweir } 343*cdf0e10cSrcweir 344*cdf0e10cSrcweir // *************************************************************** 345*cdf0e10cSrcweir // class SvLBoxButton 346*cdf0e10cSrcweir // *************************************************************** 347*cdf0e10cSrcweir 348*cdf0e10cSrcweir DBG_NAME(SvLBoxButton); 349*cdf0e10cSrcweir 350*cdf0e10cSrcweir SvLBoxButton::SvLBoxButton( SvLBoxEntry* pEntry, SvLBoxButtonKind eTheKind, 351*cdf0e10cSrcweir sal_uInt16 nFlags, SvLBoxButtonData* pBData ) 352*cdf0e10cSrcweir : SvLBoxItem( pEntry, nFlags ) 353*cdf0e10cSrcweir { 354*cdf0e10cSrcweir DBG_CTOR(SvLBoxButton,0); 355*cdf0e10cSrcweir eKind = eTheKind; 356*cdf0e10cSrcweir nBaseOffs = 0; 357*cdf0e10cSrcweir nItemFlags = 0; 358*cdf0e10cSrcweir SetStateUnchecked(); 359*cdf0e10cSrcweir pData = pBData; 360*cdf0e10cSrcweir } 361*cdf0e10cSrcweir 362*cdf0e10cSrcweir SvLBoxButton::SvLBoxButton() : SvLBoxItem() 363*cdf0e10cSrcweir { 364*cdf0e10cSrcweir DBG_CTOR(SvLBoxButton,0); 365*cdf0e10cSrcweir eKind = SvLBoxButtonKind_enabledCheckbox; 366*cdf0e10cSrcweir nItemFlags = 0; 367*cdf0e10cSrcweir SetStateUnchecked(); 368*cdf0e10cSrcweir } 369*cdf0e10cSrcweir 370*cdf0e10cSrcweir SvLBoxButton::~SvLBoxButton() 371*cdf0e10cSrcweir { 372*cdf0e10cSrcweir DBG_DTOR(SvLBoxButton,0); 373*cdf0e10cSrcweir } 374*cdf0e10cSrcweir 375*cdf0e10cSrcweir sal_uInt16 SvLBoxButton::IsA() 376*cdf0e10cSrcweir { 377*cdf0e10cSrcweir DBG_CHKTHIS(SvLBoxButton,0); 378*cdf0e10cSrcweir return SV_ITEM_ID_LBOXBUTTON; 379*cdf0e10cSrcweir } 380*cdf0e10cSrcweir 381*cdf0e10cSrcweir void SvLBoxButton::Check(SvLBox*, SvLBoxEntry*, sal_Bool bOn) 382*cdf0e10cSrcweir { 383*cdf0e10cSrcweir DBG_CHKTHIS(SvLBoxButton,0); 384*cdf0e10cSrcweir if ( bOn != IsStateChecked() ) 385*cdf0e10cSrcweir { 386*cdf0e10cSrcweir if ( bOn ) 387*cdf0e10cSrcweir SetStateChecked(); 388*cdf0e10cSrcweir else 389*cdf0e10cSrcweir SetStateUnchecked(); 390*cdf0e10cSrcweir } 391*cdf0e10cSrcweir } 392*cdf0e10cSrcweir 393*cdf0e10cSrcweir sal_Bool SvLBoxButton::ClickHdl( SvLBox*, SvLBoxEntry* pEntry ) 394*cdf0e10cSrcweir { 395*cdf0e10cSrcweir DBG_CHKTHIS(SvLBoxButton,0); 396*cdf0e10cSrcweir if ( CheckModification() ) 397*cdf0e10cSrcweir { 398*cdf0e10cSrcweir if ( IsStateChecked() ) 399*cdf0e10cSrcweir SetStateUnchecked(); 400*cdf0e10cSrcweir else 401*cdf0e10cSrcweir SetStateChecked(); 402*cdf0e10cSrcweir pData->StoreButtonState( pEntry, nItemFlags ); 403*cdf0e10cSrcweir pData->CallLink(); 404*cdf0e10cSrcweir } 405*cdf0e10cSrcweir return sal_False; 406*cdf0e10cSrcweir } 407*cdf0e10cSrcweir 408*cdf0e10cSrcweir void SvLBoxButton::Paint( const Point& rPos, SvLBox& rDev, sal_uInt16 /* nFlags */, 409*cdf0e10cSrcweir SvLBoxEntry* /*pEntry*/ ) 410*cdf0e10cSrcweir { 411*cdf0e10cSrcweir DBG_CHKTHIS(SvLBoxButton,0); 412*cdf0e10cSrcweir sal_uInt16 nIndex = eKind == SvLBoxButtonKind_staticImage 413*cdf0e10cSrcweir ? SV_BMP_STATICIMAGE : pData->GetIndex( nItemFlags ); 414*cdf0e10cSrcweir sal_uInt16 nStyle = eKind != SvLBoxButtonKind_disabledCheckbox && 415*cdf0e10cSrcweir rDev.IsEnabled() ? 0 : IMAGE_DRAW_DISABLE; 416*cdf0e10cSrcweir 417*cdf0e10cSrcweir /// 418*cdf0e10cSrcweir //Native drawing 419*cdf0e10cSrcweir /// 420*cdf0e10cSrcweir sal_Bool bNativeOK = sal_False; 421*cdf0e10cSrcweir ControlType eCtrlType = (pData->IsRadio())? CTRL_RADIOBUTTON : CTRL_CHECKBOX; 422*cdf0e10cSrcweir if ( nIndex != SV_BMP_STATICIMAGE && rDev.IsNativeControlSupported( eCtrlType, PART_ENTIRE_CONTROL) ) 423*cdf0e10cSrcweir { 424*cdf0e10cSrcweir Size aSize(pData->Width(), pData->Height()); 425*cdf0e10cSrcweir ImplAdjustBoxSize( aSize, eCtrlType, &rDev ); 426*cdf0e10cSrcweir ImplControlValue aControlValue; 427*cdf0e10cSrcweir Rectangle aCtrlRegion( rPos, aSize ); 428*cdf0e10cSrcweir ControlState nState = 0; 429*cdf0e10cSrcweir 430*cdf0e10cSrcweir //states CTRL_STATE_DEFAULT, CTRL_STATE_PRESSED and CTRL_STATE_ROLLOVER are not implemented 431*cdf0e10cSrcweir if ( IsStateHilighted() ) nState |= CTRL_STATE_FOCUSED; 432*cdf0e10cSrcweir if ( nStyle != IMAGE_DRAW_DISABLE ) nState |= CTRL_STATE_ENABLED; 433*cdf0e10cSrcweir 434*cdf0e10cSrcweir if ( IsStateChecked() ) 435*cdf0e10cSrcweir aControlValue.setTristateVal( BUTTONVALUE_ON ); 436*cdf0e10cSrcweir else if ( IsStateUnchecked() ) 437*cdf0e10cSrcweir aControlValue.setTristateVal( BUTTONVALUE_OFF ); 438*cdf0e10cSrcweir else if ( IsStateTristate() ) 439*cdf0e10cSrcweir aControlValue.setTristateVal( BUTTONVALUE_MIXED ); 440*cdf0e10cSrcweir 441*cdf0e10cSrcweir bNativeOK = rDev.DrawNativeControl( eCtrlType, PART_ENTIRE_CONTROL, 442*cdf0e10cSrcweir aCtrlRegion, nState, aControlValue, rtl::OUString() ); 443*cdf0e10cSrcweir } 444*cdf0e10cSrcweir 445*cdf0e10cSrcweir if( !bNativeOK) 446*cdf0e10cSrcweir rDev.DrawImage( rPos, pData->aBmps[nIndex + nBaseOffs] ,nStyle); 447*cdf0e10cSrcweir } 448*cdf0e10cSrcweir 449*cdf0e10cSrcweir SvLBoxItem* SvLBoxButton::Create() const 450*cdf0e10cSrcweir { 451*cdf0e10cSrcweir DBG_CHKTHIS(SvLBoxButton,0); 452*cdf0e10cSrcweir return new SvLBoxButton; 453*cdf0e10cSrcweir } 454*cdf0e10cSrcweir 455*cdf0e10cSrcweir void SvLBoxButton::Clone( SvLBoxItem* pSource ) 456*cdf0e10cSrcweir { 457*cdf0e10cSrcweir DBG_CHKTHIS(SvLBoxButton,0); 458*cdf0e10cSrcweir pData = ((SvLBoxButton*)pSource)->pData; 459*cdf0e10cSrcweir } 460*cdf0e10cSrcweir 461*cdf0e10cSrcweir void SvLBoxButton::ImplAdjustBoxSize( Size& io_rSize, ControlType i_eType, Window* i_pParent ) 462*cdf0e10cSrcweir { 463*cdf0e10cSrcweir if ( i_pParent->IsNativeControlSupported( i_eType, PART_ENTIRE_CONTROL) ) 464*cdf0e10cSrcweir { 465*cdf0e10cSrcweir ImplControlValue aControlValue; 466*cdf0e10cSrcweir Rectangle aCtrlRegion( Point( 0, 0 ), io_rSize ); 467*cdf0e10cSrcweir ControlState nState = CTRL_STATE_ENABLED; 468*cdf0e10cSrcweir 469*cdf0e10cSrcweir aControlValue.setTristateVal( BUTTONVALUE_ON ); 470*cdf0e10cSrcweir 471*cdf0e10cSrcweir Rectangle aNativeBounds, aNativeContent; 472*cdf0e10cSrcweir bool bNativeOK = i_pParent->GetNativeControlRegion( i_eType, 473*cdf0e10cSrcweir PART_ENTIRE_CONTROL, 474*cdf0e10cSrcweir aCtrlRegion, 475*cdf0e10cSrcweir nState, 476*cdf0e10cSrcweir aControlValue, 477*cdf0e10cSrcweir rtl::OUString(), 478*cdf0e10cSrcweir aNativeBounds, 479*cdf0e10cSrcweir aNativeContent ); 480*cdf0e10cSrcweir if( bNativeOK ) 481*cdf0e10cSrcweir { 482*cdf0e10cSrcweir Size aContentSize( aNativeContent.GetSize() ); 483*cdf0e10cSrcweir // leave a little space around the box image (looks better 484*cdf0e10cSrcweir if( aContentSize.Height() + 2 > io_rSize.Height() ) 485*cdf0e10cSrcweir io_rSize.Height() = aContentSize.Height() + 2; 486*cdf0e10cSrcweir } 487*cdf0e10cSrcweir } 488*cdf0e10cSrcweir } 489*cdf0e10cSrcweir 490*cdf0e10cSrcweir void SvLBoxButton::InitViewData( SvLBox* pView,SvLBoxEntry* pEntry, 491*cdf0e10cSrcweir SvViewDataItem* pViewData ) 492*cdf0e10cSrcweir { 493*cdf0e10cSrcweir DBG_CHKTHIS(SvLBoxButton,0); 494*cdf0e10cSrcweir if( !pViewData ) 495*cdf0e10cSrcweir pViewData = pView->GetViewDataItem( pEntry, this ); 496*cdf0e10cSrcweir Size aSize( pData->Width(), pData->Height() ); 497*cdf0e10cSrcweir 498*cdf0e10cSrcweir ControlType eCtrlType = (pData->IsRadio())? CTRL_RADIOBUTTON : CTRL_CHECKBOX; 499*cdf0e10cSrcweir if ( eKind != SvLBoxButtonKind_staticImage && pView ) 500*cdf0e10cSrcweir ImplAdjustBoxSize( aSize, eCtrlType, pView ); 501*cdf0e10cSrcweir pViewData->aSize = aSize; 502*cdf0e10cSrcweir } 503*cdf0e10cSrcweir 504*cdf0e10cSrcweir bool SvLBoxButton::CheckModification() const 505*cdf0e10cSrcweir { 506*cdf0e10cSrcweir if( eKind == SvLBoxButtonKind_disabledCheckbox ) 507*cdf0e10cSrcweir Sound::Beep(); 508*cdf0e10cSrcweir return eKind == SvLBoxButtonKind_enabledCheckbox; 509*cdf0e10cSrcweir } 510*cdf0e10cSrcweir 511*cdf0e10cSrcweir // *************************************************************** 512*cdf0e10cSrcweir // class SvLBoxContextBmp 513*cdf0e10cSrcweir // *************************************************************** 514*cdf0e10cSrcweir 515*cdf0e10cSrcweir struct SvLBoxContextBmp_Impl 516*cdf0e10cSrcweir { 517*cdf0e10cSrcweir Image m_aImage1; 518*cdf0e10cSrcweir Image m_aImage2; 519*cdf0e10cSrcweir 520*cdf0e10cSrcweir Image m_aImage1_hc; 521*cdf0e10cSrcweir Image m_aImage2_hc; 522*cdf0e10cSrcweir 523*cdf0e10cSrcweir sal_uInt16 m_nB2IndicatorFlags; 524*cdf0e10cSrcweir }; 525*cdf0e10cSrcweir 526*cdf0e10cSrcweir // *************************************************************** 527*cdf0e10cSrcweir DBG_NAME(SvLBoxContextBmp) 528*cdf0e10cSrcweir 529*cdf0e10cSrcweir SvLBoxContextBmp::SvLBoxContextBmp( SvLBoxEntry* pEntry, sal_uInt16 nItemFlags, 530*cdf0e10cSrcweir Image aBmp1, Image aBmp2, sal_uInt16 nEntryFlags ) 531*cdf0e10cSrcweir :SvLBoxItem( pEntry, nItemFlags ) 532*cdf0e10cSrcweir ,m_pImpl( new SvLBoxContextBmp_Impl ) 533*cdf0e10cSrcweir { 534*cdf0e10cSrcweir DBG_CTOR(SvLBoxContextBmp,0); 535*cdf0e10cSrcweir 536*cdf0e10cSrcweir m_pImpl->m_nB2IndicatorFlags = nEntryFlags; 537*cdf0e10cSrcweir SetModeImages( aBmp1, aBmp2 ); 538*cdf0e10cSrcweir } 539*cdf0e10cSrcweir 540*cdf0e10cSrcweir SvLBoxContextBmp::SvLBoxContextBmp() 541*cdf0e10cSrcweir :SvLBoxItem( ) 542*cdf0e10cSrcweir ,m_pImpl( new SvLBoxContextBmp_Impl ) 543*cdf0e10cSrcweir { 544*cdf0e10cSrcweir m_pImpl->m_nB2IndicatorFlags = 0; 545*cdf0e10cSrcweir DBG_CTOR(SvLBoxContextBmp,0); 546*cdf0e10cSrcweir } 547*cdf0e10cSrcweir 548*cdf0e10cSrcweir SvLBoxContextBmp::~SvLBoxContextBmp() 549*cdf0e10cSrcweir { 550*cdf0e10cSrcweir delete m_pImpl; 551*cdf0e10cSrcweir DBG_DTOR(SvLBoxContextBmp,0); 552*cdf0e10cSrcweir } 553*cdf0e10cSrcweir 554*cdf0e10cSrcweir sal_uInt16 SvLBoxContextBmp::IsA() 555*cdf0e10cSrcweir { 556*cdf0e10cSrcweir DBG_CHKTHIS(SvLBoxContextBmp,0); 557*cdf0e10cSrcweir return SV_ITEM_ID_LBOXCONTEXTBMP; 558*cdf0e10cSrcweir } 559*cdf0e10cSrcweir 560*cdf0e10cSrcweir sal_Bool SvLBoxContextBmp::SetModeImages( const Image& _rBitmap1, const Image& _rBitmap2, BmpColorMode _eMode ) 561*cdf0e10cSrcweir { 562*cdf0e10cSrcweir DBG_CHKTHIS(SvLBoxContextBmp,0); 563*cdf0e10cSrcweir 564*cdf0e10cSrcweir sal_Bool bSuccess = sal_True; 565*cdf0e10cSrcweir switch ( _eMode ) 566*cdf0e10cSrcweir { 567*cdf0e10cSrcweir case BMP_COLOR_NORMAL: 568*cdf0e10cSrcweir m_pImpl->m_aImage1 = _rBitmap1; 569*cdf0e10cSrcweir m_pImpl->m_aImage2 = _rBitmap2; 570*cdf0e10cSrcweir break; 571*cdf0e10cSrcweir 572*cdf0e10cSrcweir case BMP_COLOR_HIGHCONTRAST: 573*cdf0e10cSrcweir m_pImpl->m_aImage1_hc = _rBitmap1; 574*cdf0e10cSrcweir m_pImpl->m_aImage2_hc = _rBitmap2; 575*cdf0e10cSrcweir break; 576*cdf0e10cSrcweir 577*cdf0e10cSrcweir default: 578*cdf0e10cSrcweir DBG_ERROR( "SvLBoxContextBmp::SetModeImages: unexpected mode!"); 579*cdf0e10cSrcweir bSuccess = sal_False; 580*cdf0e10cSrcweir break; 581*cdf0e10cSrcweir } 582*cdf0e10cSrcweir return bSuccess; 583*cdf0e10cSrcweir } 584*cdf0e10cSrcweir 585*cdf0e10cSrcweir Image& SvLBoxContextBmp::implGetImageStore( sal_Bool _bFirst, BmpColorMode _eMode ) 586*cdf0e10cSrcweir { 587*cdf0e10cSrcweir DBG_CHKTHIS(SvLBoxContextBmp,0); 588*cdf0e10cSrcweir 589*cdf0e10cSrcweir switch ( _eMode ) 590*cdf0e10cSrcweir { 591*cdf0e10cSrcweir case BMP_COLOR_NORMAL: 592*cdf0e10cSrcweir return _bFirst ? m_pImpl->m_aImage1 : m_pImpl->m_aImage2; 593*cdf0e10cSrcweir 594*cdf0e10cSrcweir case BMP_COLOR_HIGHCONTRAST: 595*cdf0e10cSrcweir return _bFirst ? m_pImpl->m_aImage1_hc : m_pImpl->m_aImage2_hc; 596*cdf0e10cSrcweir 597*cdf0e10cSrcweir default: 598*cdf0e10cSrcweir DBG_ERROR( "SvLBoxContextBmp::implGetImageStore: unexpected mode!"); 599*cdf0e10cSrcweir } 600*cdf0e10cSrcweir 601*cdf0e10cSrcweir // OJ: #i27071# wrong mode so we just return the normal images 602*cdf0e10cSrcweir return _bFirst ? m_pImpl->m_aImage1 : m_pImpl->m_aImage2; 603*cdf0e10cSrcweir } 604*cdf0e10cSrcweir 605*cdf0e10cSrcweir void SvLBoxContextBmp::InitViewData( SvLBox* pView,SvLBoxEntry* pEntry, 606*cdf0e10cSrcweir SvViewDataItem* pViewData) 607*cdf0e10cSrcweir { 608*cdf0e10cSrcweir DBG_CHKTHIS(SvLBoxContextBmp,0); 609*cdf0e10cSrcweir if( !pViewData ) 610*cdf0e10cSrcweir pViewData = pView->GetViewDataItem( pEntry, this ); 611*cdf0e10cSrcweir pViewData->aSize = m_pImpl->m_aImage1.GetSizePixel(); 612*cdf0e10cSrcweir } 613*cdf0e10cSrcweir 614*cdf0e10cSrcweir void SvLBoxContextBmp::Paint( const Point& _rPos, SvLBox& _rDev, 615*cdf0e10cSrcweir sal_uInt16 _nViewDataEntryFlags, SvLBoxEntry* _pEntry ) 616*cdf0e10cSrcweir { 617*cdf0e10cSrcweir DBG_CHKTHIS(SvLBoxContextBmp,0); 618*cdf0e10cSrcweir 619*cdf0e10cSrcweir // determine the image set 620*cdf0e10cSrcweir BmpColorMode eMode( BMP_COLOR_NORMAL ); 621*cdf0e10cSrcweir if ( !!m_pImpl->m_aImage1_hc ) 622*cdf0e10cSrcweir { // we really have HC images 623*cdf0e10cSrcweir if ( _rDev.GetSettings().GetStyleSettings().GetHighContrastMode() ) 624*cdf0e10cSrcweir eMode = BMP_COLOR_HIGHCONTRAST; 625*cdf0e10cSrcweir } 626*cdf0e10cSrcweir 627*cdf0e10cSrcweir // get the image 628*cdf0e10cSrcweir const Image& rImage = implGetImageStore( 0 == ( _nViewDataEntryFlags & m_pImpl->m_nB2IndicatorFlags ), eMode ); 629*cdf0e10cSrcweir 630*cdf0e10cSrcweir sal_Bool _bSemiTransparent = _pEntry && ( 0 != ( SV_ENTRYFLAG_SEMITRANSPARENT & _pEntry->GetFlags( ) ) ); 631*cdf0e10cSrcweir // draw 632*cdf0e10cSrcweir sal_uInt16 nStyle = _rDev.IsEnabled() ? 0 : IMAGE_DRAW_DISABLE; 633*cdf0e10cSrcweir if ( _bSemiTransparent ) 634*cdf0e10cSrcweir nStyle |= IMAGE_DRAW_SEMITRANSPARENT; 635*cdf0e10cSrcweir _rDev.DrawImage( _rPos, rImage, nStyle); 636*cdf0e10cSrcweir } 637*cdf0e10cSrcweir 638*cdf0e10cSrcweir SvLBoxItem* SvLBoxContextBmp::Create() const 639*cdf0e10cSrcweir { 640*cdf0e10cSrcweir DBG_CHKTHIS(SvLBoxContextBmp,0); 641*cdf0e10cSrcweir return new SvLBoxContextBmp; 642*cdf0e10cSrcweir } 643*cdf0e10cSrcweir 644*cdf0e10cSrcweir void SvLBoxContextBmp::Clone( SvLBoxItem* pSource ) 645*cdf0e10cSrcweir { 646*cdf0e10cSrcweir DBG_CHKTHIS(SvLBoxContextBmp,0); 647*cdf0e10cSrcweir m_pImpl->m_aImage1 = static_cast< SvLBoxContextBmp* >( pSource )->m_pImpl->m_aImage1; 648*cdf0e10cSrcweir m_pImpl->m_aImage2 = static_cast< SvLBoxContextBmp* >( pSource )->m_pImpl->m_aImage2; 649*cdf0e10cSrcweir m_pImpl->m_nB2IndicatorFlags = static_cast< SvLBoxContextBmp* >( pSource )->m_pImpl->m_nB2IndicatorFlags; 650*cdf0e10cSrcweir } 651*cdf0e10cSrcweir 652