1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: svlbitm.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_svtools.hxx"
35 #include <svtools/svlbox.hxx>
36 #include <svtools/svlbitm.hxx>
37 #include <vcl/svapp.hxx>
38 #ifndef _SV_BUTTON_HXX
39 #include <vcl/button.hxx>
41 #include <vcl/decoview.hxx>
42 #include <vcl/sound.hxx>
43 #include <vcl/salnativewidgets.hxx>
45 #define TABOFFS_NOT_VALID -2000000
47 struct SvLBoxButtonData_Impl
51 BOOL bShowRadioButton
;
53 SvLBoxButtonData_Impl() : pEntry( NULL
), bDefaultImages( FALSE
), bShowRadioButton( FALSE
) {}
57 DBG_NAME(SvLBoxButtonData
)
59 void SvLBoxButtonData::InitData( BOOL bImagesFromDefault
, bool _bRadioBtn
, const Control
* pCtrl
)
61 pImpl
= new SvLBoxButtonData_Impl
;
64 eState
= SV_BUTTON_UNCHECKED
;
65 pImpl
->bDefaultImages
= bImagesFromDefault
;
66 pImpl
->bShowRadioButton
= ( _bRadioBtn
!= false );
68 if ( bImagesFromDefault
)
69 SetDefaultImages( pCtrl
);
72 SvLBoxButtonData::SvLBoxButtonData( const Control
* pControlForSettings
)
74 DBG_CTOR(SvLBoxButtonData
,0);
76 InitData( TRUE
, false, pControlForSettings
);
79 SvLBoxButtonData::SvLBoxButtonData( const Control
* pControlForSettings
, bool _bRadioBtn
)
81 DBG_CTOR(SvLBoxButtonData
,0);
83 InitData( TRUE
, _bRadioBtn
, pControlForSettings
);
86 SvLBoxButtonData::SvLBoxButtonData()
88 DBG_CTOR(SvLBoxButtonData
,0);
90 InitData( FALSE
, false );
93 SvLBoxButtonData::~SvLBoxButtonData()
95 DBG_DTOR(SvLBoxButtonData
,0);
103 void SvLBoxButtonData::CallLink()
105 DBG_CHKTHIS(SvLBoxButtonData
,0);
109 USHORT
SvLBoxButtonData::GetIndex( USHORT nItemState
)
111 DBG_CHKTHIS(SvLBoxButtonData
,0);
112 nItemState
&= 0x000F;
116 case SV_ITEMSTATE_UNCHECKED
:
117 nIdx
= SV_BMP_UNCHECKED
; break;
118 case SV_ITEMSTATE_CHECKED
:
119 nIdx
= SV_BMP_CHECKED
; break;
120 case SV_ITEMSTATE_TRISTATE
:
121 nIdx
= SV_BMP_TRISTATE
; break;
122 case SV_ITEMSTATE_UNCHECKED
| SV_ITEMSTATE_HILIGHTED
:
123 nIdx
= SV_BMP_HIUNCHECKED
; break;
124 case SV_ITEMSTATE_CHECKED
| SV_ITEMSTATE_HILIGHTED
:
125 nIdx
= SV_BMP_HICHECKED
; break;
126 case SV_ITEMSTATE_TRISTATE
| SV_ITEMSTATE_HILIGHTED
:
127 nIdx
= SV_BMP_HITRISTATE
; break;
129 nIdx
= SV_BMP_UNCHECKED
;
134 void SvLBoxButtonData::SetWidthAndHeight()
136 DBG_CHKTHIS(SvLBoxButtonData
,0);
137 Size aSize
= aBmps
[0].GetSizePixel();
138 nWidth
= aSize
.Width();
139 nHeight
= aSize
.Height();
144 void SvLBoxButtonData::StoreButtonState( SvLBoxEntry
* pActEntry
, USHORT nItemFlags
)
146 DBG_CHKTHIS(SvLBoxButtonData
,0);
147 pImpl
->pEntry
= pActEntry
;
148 eState
= ConvertToButtonState( nItemFlags
);
151 SvButtonState
SvLBoxButtonData::ConvertToButtonState( USHORT nItemFlags
) const
153 DBG_CHKTHIS(SvLBoxButtonData
,0);
154 nItemFlags
&= (SV_ITEMSTATE_UNCHECKED
|
155 SV_ITEMSTATE_CHECKED
|
156 SV_ITEMSTATE_TRISTATE
);
159 case SV_ITEMSTATE_UNCHECKED
:
160 return SV_BUTTON_UNCHECKED
;
162 case SV_ITEMSTATE_CHECKED
:
163 return SV_BUTTON_CHECKED
;
165 case SV_ITEMSTATE_TRISTATE
:
166 return SV_BUTTON_TRISTATE
;
168 return SV_BUTTON_UNCHECKED
;
172 SvLBoxEntry
* SvLBoxButtonData::GetActEntry() const
174 DBG_ASSERT( pImpl
, "-SvLBoxButtonData::GetActEntry(): don't use me that way!" );
175 return pImpl
->pEntry
;
178 void SvLBoxButtonData::SetDefaultImages( const Control
* pCtrl
)
180 const AllSettings
& rSettings
= pCtrl
? pCtrl
->GetSettings() : Application::GetSettings();
182 if ( pImpl
->bShowRadioButton
)
184 aBmps
[ SV_BMP_UNCHECKED
] = RadioButton::GetRadioImage( rSettings
, BUTTON_DRAW_DEFAULT
);
185 aBmps
[ SV_BMP_CHECKED
] = RadioButton::GetRadioImage( rSettings
, BUTTON_DRAW_CHECKED
);
186 aBmps
[ SV_BMP_HICHECKED
] = RadioButton::GetRadioImage( rSettings
, BUTTON_DRAW_CHECKED
| BUTTON_DRAW_PRESSED
);
187 aBmps
[ SV_BMP_HIUNCHECKED
] = RadioButton::GetRadioImage( rSettings
, BUTTON_DRAW_DEFAULT
| BUTTON_DRAW_PRESSED
);
188 aBmps
[ SV_BMP_TRISTATE
] = RadioButton::GetRadioImage( rSettings
, BUTTON_DRAW_DONTKNOW
);
189 aBmps
[ SV_BMP_HITRISTATE
] = RadioButton::GetRadioImage( rSettings
, BUTTON_DRAW_DONTKNOW
| BUTTON_DRAW_PRESSED
);
193 aBmps
[ SV_BMP_UNCHECKED
] = CheckBox::GetCheckImage( rSettings
, BUTTON_DRAW_DEFAULT
);
194 aBmps
[ SV_BMP_CHECKED
] = CheckBox::GetCheckImage( rSettings
, BUTTON_DRAW_CHECKED
);
195 aBmps
[ SV_BMP_HICHECKED
] = CheckBox::GetCheckImage( rSettings
, BUTTON_DRAW_CHECKED
| BUTTON_DRAW_PRESSED
);
196 aBmps
[ SV_BMP_HIUNCHECKED
] = CheckBox::GetCheckImage( rSettings
, BUTTON_DRAW_DEFAULT
| BUTTON_DRAW_PRESSED
);
197 aBmps
[ SV_BMP_TRISTATE
] = CheckBox::GetCheckImage( rSettings
, BUTTON_DRAW_DONTKNOW
);
198 aBmps
[ SV_BMP_HITRISTATE
] = CheckBox::GetCheckImage( rSettings
, BUTTON_DRAW_DONTKNOW
| BUTTON_DRAW_PRESSED
);
202 BOOL
SvLBoxButtonData::HasDefaultImages( void ) const
204 return pImpl
->bDefaultImages
;
207 BOOL
SvLBoxButtonData::IsRadio() {
208 return pImpl
->bShowRadioButton
;
211 // ***************************************************************
212 // class SvLBoxString
213 // ***************************************************************
215 DBG_NAME(SvLBoxString
);
217 SvLBoxString::SvLBoxString( SvLBoxEntry
* pEntry
,USHORT nFlags
,const XubString
& rStr
) :
218 SvLBoxItem( pEntry
, nFlags
)
220 DBG_CTOR(SvLBoxString
,0);
221 SetText( pEntry
, rStr
);
224 SvLBoxString::SvLBoxString() : SvLBoxItem()
226 DBG_CTOR(SvLBoxString
,0);
229 SvLBoxString::~SvLBoxString()
231 DBG_DTOR(SvLBoxString
,0);
234 USHORT
SvLBoxString::IsA()
236 DBG_CHKTHIS(SvLBoxString
,0);
237 return SV_ITEM_ID_LBOXSTRING
;
240 void SvLBoxString::Paint( const Point
& rPos
, SvLBox
& rDev
, USHORT
/* nFlags */,
241 SvLBoxEntry
* _pEntry
)
243 DBG_CHKTHIS(SvLBoxString
,0);
246 USHORT nStyle
= rDev
.IsEnabled() ? 0 : TEXT_DRAW_DISABLE
;
247 if ( rDev
.IsEntryMnemonicsEnabled() )
248 nStyle
|= TEXT_DRAW_MNEMONIC
;
249 rDev
.DrawText( Rectangle(rPos
,GetSize(&rDev
,_pEntry
)),aStr
,nStyle
);
252 rDev
.DrawText( rPos
, aStr
);
256 SvLBoxItem
* SvLBoxString::Create() const
258 DBG_CHKTHIS(SvLBoxString
,0);
259 return new SvLBoxString
;
262 void SvLBoxString::Clone( SvLBoxItem
* pSource
)
264 DBG_CHKTHIS(SvLBoxString
,0);
265 aStr
= ((SvLBoxString
*)pSource
)->aStr
;
268 void SvLBoxString::SetText( SvLBoxEntry
*, const XubString
& rStr
)
270 DBG_CHKTHIS(SvLBoxString
,0);
274 void SvLBoxString::InitViewData( SvLBox
* pView
,SvLBoxEntry
* pEntry
,
275 SvViewDataItem
* pViewData
)
277 DBG_CHKTHIS(SvLBoxString
,0);
279 pViewData
= pView
->GetViewDataItem( pEntry
, this );
280 pViewData
->aSize
= Size(pView
->GetTextWidth( aStr
), pView
->GetTextHeight());
283 // ***************************************************************
285 // ***************************************************************
289 SvLBoxBmp::SvLBoxBmp( SvLBoxEntry
* pEntry
, USHORT nFlags
, Image aBitmap
) :
290 SvLBoxItem( pEntry
, nFlags
)
292 DBG_CTOR(SvLBoxBmp
,0);
293 SetBitmap( pEntry
, aBitmap
);
296 SvLBoxBmp::SvLBoxBmp() : SvLBoxItem()
298 DBG_CTOR(SvLBoxBmp
,0);
301 SvLBoxBmp::~SvLBoxBmp()
303 DBG_DTOR(SvLBoxBmp
,0);
306 USHORT
SvLBoxBmp::IsA()
308 DBG_CHKTHIS(SvLBoxBmp
,0);
309 return SV_ITEM_ID_LBOXBMP
;
312 void SvLBoxBmp::SetBitmap( SvLBoxEntry
*, Image aBitmap
)
314 DBG_CHKTHIS(SvLBoxBmp
,0);
318 void SvLBoxBmp::InitViewData( SvLBox
* pView
,SvLBoxEntry
* pEntry
,
319 SvViewDataItem
* pViewData
)
321 DBG_CHKTHIS(SvLBoxBmp
,0);
323 pViewData
= pView
->GetViewDataItem( pEntry
, this );
324 pViewData
->aSize
= aBmp
.GetSizePixel();
327 void SvLBoxBmp::Paint( const Point
& rPos
, SvLBox
& rDev
, USHORT
/* nFlags */,
330 DBG_CHKTHIS(SvLBoxBmp
,0);
331 USHORT nStyle
= rDev
.IsEnabled() ? 0 : IMAGE_DRAW_DISABLE
;
332 rDev
.DrawImage( rPos
, aBmp
,nStyle
);
335 SvLBoxItem
* SvLBoxBmp::Create() const
337 DBG_CHKTHIS(SvLBoxBmp
,0);
338 return new SvLBoxBmp
;
341 void SvLBoxBmp::Clone( SvLBoxItem
* pSource
)
343 DBG_CHKTHIS(SvLBoxBmp
,0);
344 aBmp
= ((SvLBoxBmp
*)pSource
)->aBmp
;
347 // ***************************************************************
348 // class SvLBoxButton
349 // ***************************************************************
351 DBG_NAME(SvLBoxButton
);
353 SvLBoxButton::SvLBoxButton( SvLBoxEntry
* pEntry
, SvLBoxButtonKind eTheKind
,
354 USHORT nFlags
, SvLBoxButtonData
* pBData
)
355 : SvLBoxItem( pEntry
, nFlags
)
357 DBG_CTOR(SvLBoxButton
,0);
365 SvLBoxButton::SvLBoxButton() : SvLBoxItem()
367 DBG_CTOR(SvLBoxButton
,0);
368 eKind
= SvLBoxButtonKind_enabledCheckbox
;
373 SvLBoxButton::~SvLBoxButton()
375 DBG_DTOR(SvLBoxButton
,0);
378 USHORT
SvLBoxButton::IsA()
380 DBG_CHKTHIS(SvLBoxButton
,0);
381 return SV_ITEM_ID_LBOXBUTTON
;
384 void SvLBoxButton::Check(SvLBox
*, SvLBoxEntry
*, BOOL bOn
)
386 DBG_CHKTHIS(SvLBoxButton
,0);
387 if ( bOn
!= IsStateChecked() )
396 BOOL
SvLBoxButton::ClickHdl( SvLBox
*, SvLBoxEntry
* pEntry
)
398 DBG_CHKTHIS(SvLBoxButton
,0);
399 if ( CheckModification() )
401 if ( IsStateChecked() )
405 pData
->StoreButtonState( pEntry
, nItemFlags
);
411 void SvLBoxButton::Paint( const Point
& rPos
, SvLBox
& rDev
, USHORT
/* nFlags */,
414 DBG_CHKTHIS(SvLBoxButton
,0);
415 USHORT nIndex
= eKind
== SvLBoxButtonKind_staticImage
416 ? SV_BMP_STATICIMAGE
: pData
->GetIndex( nItemFlags
);
417 USHORT nStyle
= eKind
!= SvLBoxButtonKind_disabledCheckbox
&&
418 rDev
.IsEnabled() ? 0 : IMAGE_DRAW_DISABLE
;
423 BOOL bNativeOK
= FALSE
;
425 if( rDev
.GetOutDevType() == OUTDEV_WINDOW
)
426 pWin
= (Window
*) &rDev
;
428 if ( nIndex
!= SV_BMP_STATICIMAGE
&& pWin
&& pWin
->IsNativeControlSupported( (pData
->IsRadio())? CTRL_RADIOBUTTON
: CTRL_CHECKBOX
, PART_ENTIRE_CONTROL
) )
430 ImplControlValue aControlValue
;
431 Region
aCtrlRegion( Rectangle(rPos
, Size(pData
->Width(), pData
->Height())) );
432 ControlState nState
= 0;
434 //states CTRL_STATE_DEFAULT, CTRL_STATE_PRESSED and CTRL_STATE_ROLLOVER are not implemented
435 if ( IsStateHilighted() ) nState
|= CTRL_STATE_FOCUSED
;
436 if ( nStyle
!= IMAGE_DRAW_DISABLE
) nState
|= CTRL_STATE_ENABLED
;
438 if ( IsStateChecked() )
439 aControlValue
.setTristateVal( BUTTONVALUE_ON
);
440 else if ( IsStateUnchecked() )
441 aControlValue
.setTristateVal( BUTTONVALUE_OFF
);
442 else if ( IsStateTristate() )
443 aControlValue
.setTristateVal( BUTTONVALUE_MIXED
);
445 bNativeOK
= pWin
->DrawNativeControl( (pData
->IsRadio())? CTRL_RADIOBUTTON
: CTRL_CHECKBOX
, PART_ENTIRE_CONTROL
,
446 aCtrlRegion
, nState
, aControlValue
, rtl::OUString() );
450 rDev
.DrawImage( rPos
, pData
->aBmps
[nIndex
+ nBaseOffs
] ,nStyle
);
453 SvLBoxItem
* SvLBoxButton::Create() const
455 DBG_CHKTHIS(SvLBoxButton
,0);
456 return new SvLBoxButton
;
459 void SvLBoxButton::Clone( SvLBoxItem
* pSource
)
461 DBG_CHKTHIS(SvLBoxButton
,0);
462 pData
= ((SvLBoxButton
*)pSource
)->pData
;
465 void SvLBoxButton::InitViewData( SvLBox
* pView
,SvLBoxEntry
* pEntry
,
466 SvViewDataItem
* pViewData
)
468 DBG_CHKTHIS(SvLBoxButton
,0);
470 pViewData
= pView
->GetViewDataItem( pEntry
, this );
471 pViewData
->aSize
= Size( pData
->Width(), pData
->Height() );
474 bool SvLBoxButton::CheckModification() const
476 if( eKind
== SvLBoxButtonKind_disabledCheckbox
)
478 return eKind
== SvLBoxButtonKind_enabledCheckbox
;
481 // ***************************************************************
482 // class SvLBoxContextBmp
483 // ***************************************************************
485 struct SvLBoxContextBmp_Impl
493 USHORT m_nB2IndicatorFlags
;
496 // ***************************************************************
497 DBG_NAME(SvLBoxContextBmp
)
499 SvLBoxContextBmp::SvLBoxContextBmp( SvLBoxEntry
* pEntry
, USHORT nItemFlags
,
500 Image aBmp1
, Image aBmp2
, USHORT nEntryFlags
)
501 :SvLBoxItem( pEntry
, nItemFlags
)
502 ,m_pImpl( new SvLBoxContextBmp_Impl
)
504 DBG_CTOR(SvLBoxContextBmp
,0);
506 m_pImpl
->m_nB2IndicatorFlags
= nEntryFlags
;
507 SetModeImages( aBmp1
, aBmp2
);
510 SvLBoxContextBmp::SvLBoxContextBmp()
512 ,m_pImpl( new SvLBoxContextBmp_Impl
)
514 m_pImpl
->m_nB2IndicatorFlags
= 0;
515 DBG_CTOR(SvLBoxContextBmp
,0);
518 SvLBoxContextBmp::~SvLBoxContextBmp()
521 DBG_DTOR(SvLBoxContextBmp
,0);
524 USHORT
SvLBoxContextBmp::IsA()
526 DBG_CHKTHIS(SvLBoxContextBmp
,0);
527 return SV_ITEM_ID_LBOXCONTEXTBMP
;
530 BOOL
SvLBoxContextBmp::SetModeImages( const Image
& _rBitmap1
, const Image
& _rBitmap2
, BmpColorMode _eMode
)
532 DBG_CHKTHIS(SvLBoxContextBmp
,0);
534 sal_Bool bSuccess
= sal_True
;
537 case BMP_COLOR_NORMAL
:
538 m_pImpl
->m_aImage1
= _rBitmap1
;
539 m_pImpl
->m_aImage2
= _rBitmap2
;
542 case BMP_COLOR_HIGHCONTRAST
:
543 m_pImpl
->m_aImage1_hc
= _rBitmap1
;
544 m_pImpl
->m_aImage2_hc
= _rBitmap2
;
548 DBG_ERROR( "SvLBoxContextBmp::SetModeImages: unexpected mode!");
549 bSuccess
= sal_False
;
555 Image
& SvLBoxContextBmp::implGetImageStore( sal_Bool _bFirst
, BmpColorMode _eMode
)
557 DBG_CHKTHIS(SvLBoxContextBmp
,0);
561 case BMP_COLOR_NORMAL
:
562 return _bFirst
? m_pImpl
->m_aImage1
: m_pImpl
->m_aImage2
;
564 case BMP_COLOR_HIGHCONTRAST
:
565 return _bFirst
? m_pImpl
->m_aImage1_hc
: m_pImpl
->m_aImage2_hc
;
568 DBG_ERROR( "SvLBoxContextBmp::implGetImageStore: unexpected mode!");
571 // OJ: #i27071# wrong mode so we just return the normal images
572 return _bFirst
? m_pImpl
->m_aImage1
: m_pImpl
->m_aImage2
;
575 void SvLBoxContextBmp::InitViewData( SvLBox
* pView
,SvLBoxEntry
* pEntry
,
576 SvViewDataItem
* pViewData
)
578 DBG_CHKTHIS(SvLBoxContextBmp
,0);
580 pViewData
= pView
->GetViewDataItem( pEntry
, this );
581 pViewData
->aSize
= m_pImpl
->m_aImage1
.GetSizePixel();
584 void SvLBoxContextBmp::Paint( const Point
& _rPos
, SvLBox
& _rDev
,
585 USHORT _nViewDataEntryFlags
, SvLBoxEntry
* _pEntry
)
587 DBG_CHKTHIS(SvLBoxContextBmp
,0);
589 // determine the image set
590 BmpColorMode
eMode( BMP_COLOR_NORMAL
);
591 if ( !!m_pImpl
->m_aImage1_hc
)
592 { // we really have HC images
593 const Wallpaper
& rDeviceBackground
= _rDev
.GetDisplayBackground();
594 if ( rDeviceBackground
.GetColor().IsDark() )
595 eMode
= BMP_COLOR_HIGHCONTRAST
;
599 const Image
& rImage
= implGetImageStore( 0 == ( _nViewDataEntryFlags
& m_pImpl
->m_nB2IndicatorFlags
), eMode
);
601 sal_Bool _bSemiTransparent
= _pEntry
&& ( 0 != ( SV_ENTRYFLAG_SEMITRANSPARENT
& _pEntry
->GetFlags( ) ) );
603 USHORT nStyle
= _rDev
.IsEnabled() ? 0 : IMAGE_DRAW_DISABLE
;
604 if ( _bSemiTransparent
)
605 nStyle
|= IMAGE_DRAW_SEMITRANSPARENT
;
606 _rDev
.DrawImage( _rPos
, rImage
, nStyle
);
609 SvLBoxItem
* SvLBoxContextBmp::Create() const
611 DBG_CHKTHIS(SvLBoxContextBmp
,0);
612 return new SvLBoxContextBmp
;
615 void SvLBoxContextBmp::Clone( SvLBoxItem
* pSource
)
617 DBG_CHKTHIS(SvLBoxContextBmp
,0);
618 m_pImpl
->m_aImage1
= static_cast< SvLBoxContextBmp
* >( pSource
)->m_pImpl
->m_aImage1
;
619 m_pImpl
->m_aImage2
= static_cast< SvLBoxContextBmp
* >( pSource
)->m_pImpl
->m_aImage2
;
620 m_pImpl
->m_nB2IndicatorFlags
= static_cast< SvLBoxContextBmp
* >( pSource
)->m_pImpl
->m_nB2IndicatorFlags
;