1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 <svtools/treelistbox.hxx>
21 #include <svtools/svlbitm.hxx>
22 #include "svtools/treelistentry.hxx"
23 #include "svtools/viewdataentry.hxx"
24 #include <vcl/svapp.hxx>
25 #include <vcl/button.hxx>
26 #include <vcl/decoview.hxx>
27 #include <vcl/salnativewidgets.hxx>
29 struct SvLBoxButtonData_Impl
31 SvTreeListEntry
* pEntry
;
32 sal_Bool bDefaultImages
;
33 sal_Bool bShowRadioButton
;
35 SvLBoxButtonData_Impl() : pEntry( NULL
), bDefaultImages( sal_False
), bShowRadioButton( sal_False
) {}
39 DBG_NAME(SvLBoxButtonData
)
41 void SvLBoxButtonData::InitData( sal_Bool bImagesFromDefault
, bool _bRadioBtn
, const Control
* pCtrl
)
43 pImpl
= new SvLBoxButtonData_Impl
;
46 eState
= SV_BUTTON_UNCHECKED
;
47 pImpl
->bDefaultImages
= bImagesFromDefault
;
48 pImpl
->bShowRadioButton
= ( _bRadioBtn
!= false );
50 if ( bImagesFromDefault
)
51 SetDefaultImages( pCtrl
);
54 SvLBoxButtonData::SvLBoxButtonData( const Control
* pControlForSettings
)
56 DBG_CTOR(SvLBoxButtonData
,0);
58 InitData( sal_True
, false, pControlForSettings
);
61 SvLBoxButtonData::SvLBoxButtonData( const Control
* pControlForSettings
, bool _bRadioBtn
)
63 DBG_CTOR(SvLBoxButtonData
,0);
65 InitData( sal_True
, _bRadioBtn
, pControlForSettings
);
68 SvLBoxButtonData::~SvLBoxButtonData()
70 DBG_DTOR(SvLBoxButtonData
,0);
78 void SvLBoxButtonData::CallLink()
80 DBG_CHKTHIS(SvLBoxButtonData
,0);
84 sal_uInt16
SvLBoxButtonData::GetIndex( sal_uInt16 nItemState
)
86 DBG_CHKTHIS(SvLBoxButtonData
,0);
91 case SV_ITEMSTATE_UNCHECKED
:
92 nIdx
= SV_BMP_UNCHECKED
; break;
93 case SV_ITEMSTATE_CHECKED
:
94 nIdx
= SV_BMP_CHECKED
; break;
95 case SV_ITEMSTATE_TRISTATE
:
96 nIdx
= SV_BMP_TRISTATE
; break;
97 case SV_ITEMSTATE_UNCHECKED
| SV_ITEMSTATE_HILIGHTED
:
98 nIdx
= SV_BMP_HIUNCHECKED
; break;
99 case SV_ITEMSTATE_CHECKED
| SV_ITEMSTATE_HILIGHTED
:
100 nIdx
= SV_BMP_HICHECKED
; break;
101 case SV_ITEMSTATE_TRISTATE
| SV_ITEMSTATE_HILIGHTED
:
102 nIdx
= SV_BMP_HITRISTATE
; break;
104 nIdx
= SV_BMP_UNCHECKED
;
109 void SvLBoxButtonData::SetWidthAndHeight()
111 DBG_CHKTHIS(SvLBoxButtonData
,0);
112 Size aSize
= aBmps
[0].GetSizePixel();
113 nWidth
= aSize
.Width();
114 nHeight
= aSize
.Height();
119 void SvLBoxButtonData::StoreButtonState( SvTreeListEntry
* pActEntry
, sal_uInt16 nItemFlags
)
121 DBG_CHKTHIS(SvLBoxButtonData
,0);
122 pImpl
->pEntry
= pActEntry
;
123 eState
= ConvertToButtonState( nItemFlags
);
126 SvButtonState
SvLBoxButtonData::ConvertToButtonState( sal_uInt16 nItemFlags
) const
128 DBG_CHKTHIS(SvLBoxButtonData
,0);
129 nItemFlags
&= (SV_ITEMSTATE_UNCHECKED
|
130 SV_ITEMSTATE_CHECKED
|
131 SV_ITEMSTATE_TRISTATE
);
134 case SV_ITEMSTATE_UNCHECKED
:
135 return SV_BUTTON_UNCHECKED
;
137 case SV_ITEMSTATE_CHECKED
:
138 return SV_BUTTON_CHECKED
;
140 case SV_ITEMSTATE_TRISTATE
:
141 return SV_BUTTON_TRISTATE
;
143 return SV_BUTTON_UNCHECKED
;
147 SvTreeListEntry
* SvLBoxButtonData::GetActEntry() const
149 DBG_ASSERT( pImpl
, "-SvLBoxButtonData::GetActEntry(): don't use me that way!" );
150 return pImpl
->pEntry
;
153 void SvLBoxButtonData::SetDefaultImages( const Control
* pCtrl
)
155 const AllSettings
& rSettings
= pCtrl
? pCtrl
->GetSettings() : Application::GetSettings();
157 if ( pImpl
->bShowRadioButton
)
159 aBmps
[ SV_BMP_UNCHECKED
] = RadioButton::GetRadioImage( rSettings
, BUTTON_DRAW_DEFAULT
);
160 aBmps
[ SV_BMP_CHECKED
] = RadioButton::GetRadioImage( rSettings
, BUTTON_DRAW_CHECKED
);
161 aBmps
[ SV_BMP_HICHECKED
] = RadioButton::GetRadioImage( rSettings
, BUTTON_DRAW_CHECKED
| BUTTON_DRAW_PRESSED
);
162 aBmps
[ SV_BMP_HIUNCHECKED
] = RadioButton::GetRadioImage( rSettings
, BUTTON_DRAW_DEFAULT
| BUTTON_DRAW_PRESSED
);
163 aBmps
[ SV_BMP_TRISTATE
] = RadioButton::GetRadioImage( rSettings
, BUTTON_DRAW_DONTKNOW
);
164 aBmps
[ SV_BMP_HITRISTATE
] = RadioButton::GetRadioImage( rSettings
, BUTTON_DRAW_DONTKNOW
| BUTTON_DRAW_PRESSED
);
168 aBmps
[ SV_BMP_UNCHECKED
] = CheckBox::GetCheckImage( rSettings
, BUTTON_DRAW_DEFAULT
);
169 aBmps
[ SV_BMP_CHECKED
] = CheckBox::GetCheckImage( rSettings
, BUTTON_DRAW_CHECKED
);
170 aBmps
[ SV_BMP_HICHECKED
] = CheckBox::GetCheckImage( rSettings
, BUTTON_DRAW_CHECKED
| BUTTON_DRAW_PRESSED
);
171 aBmps
[ SV_BMP_HIUNCHECKED
] = CheckBox::GetCheckImage( rSettings
, BUTTON_DRAW_DEFAULT
| BUTTON_DRAW_PRESSED
);
172 aBmps
[ SV_BMP_TRISTATE
] = CheckBox::GetCheckImage( rSettings
, BUTTON_DRAW_DONTKNOW
);
173 aBmps
[ SV_BMP_HITRISTATE
] = CheckBox::GetCheckImage( rSettings
, BUTTON_DRAW_DONTKNOW
| BUTTON_DRAW_PRESSED
);
177 sal_Bool
SvLBoxButtonData::HasDefaultImages( void ) const
179 return pImpl
->bDefaultImages
;
182 sal_Bool
SvLBoxButtonData::IsRadio() {
183 return pImpl
->bShowRadioButton
;
186 // ***************************************************************
187 // class SvLBoxString
188 // ***************************************************************
190 DBG_NAME(SvLBoxString
);
192 SvLBoxString::SvLBoxString(SvTreeListEntry
* pEntry
, sal_uInt16 nFlags
, const OUString
& rStr
)
193 : SvLBoxItem(pEntry
, nFlags
)
195 DBG_CTOR(SvLBoxString
,0);
199 SvLBoxString::SvLBoxString() : SvLBoxItem()
201 DBG_CTOR(SvLBoxString
,0);
204 SvLBoxString::~SvLBoxString()
206 DBG_DTOR(SvLBoxString
,0);
209 sal_uInt16
SvLBoxString::GetType() const
211 DBG_CHKTHIS(SvLBoxString
,0);
212 return SV_ITEM_ID_LBOXSTRING
;
215 void SvLBoxString::Paint(
216 const Point
& rPos
, SvTreeListBox
& rDev
, const SvViewDataEntry
* /*pView*/,
217 const SvTreeListEntry
* pEntry
)
219 DBG_CHKTHIS(SvLBoxString
,0);
222 sal_uInt16 nStyle
= rDev
.IsEnabled() ? 0 : TEXT_DRAW_DISABLE
;
223 if ( rDev
.IsEntryMnemonicsEnabled() )
224 nStyle
|= TEXT_DRAW_MNEMONIC
;
225 rDev
.DrawText(Rectangle(rPos
, GetSize(&rDev
, pEntry
)), maText
, nStyle
);
228 rDev
.DrawText(rPos
, maText
);
232 SvLBoxItem
* SvLBoxString::Create() const
234 DBG_CHKTHIS(SvLBoxString
,0);
235 return new SvLBoxString
;
238 void SvLBoxString::Clone( SvLBoxItem
* pSource
)
240 DBG_CHKTHIS(SvLBoxString
,0);
241 maText
= ((SvLBoxString
*)pSource
)->maText
;
244 void SvLBoxString::InitViewData(
245 SvTreeListBox
* pView
, SvTreeListEntry
* pEntry
, SvViewDataItem
* pViewData
)
247 DBG_CHKTHIS(SvLBoxString
,0);
249 pViewData
= pView
->GetViewDataItem( pEntry
, this );
250 pViewData
->maSize
= Size(pView
->GetTextWidth(maText
), pView
->GetTextHeight());
253 // ***************************************************************
255 // ***************************************************************
259 SvLBoxBmp::SvLBoxBmp() : SvLBoxItem()
261 DBG_CTOR(SvLBoxBmp
,0);
264 SvLBoxBmp::~SvLBoxBmp()
266 DBG_DTOR(SvLBoxBmp
,0);
269 sal_uInt16
SvLBoxBmp::GetType() const
271 DBG_CHKTHIS(SvLBoxBmp
,0);
272 return SV_ITEM_ID_LBOXBMP
;
275 void SvLBoxBmp::InitViewData( SvTreeListBox
* pView
,SvTreeListEntry
* pEntry
,
276 SvViewDataItem
* pViewData
)
278 DBG_CHKTHIS(SvLBoxBmp
,0);
280 pViewData
= pView
->GetViewDataItem( pEntry
, this );
281 pViewData
->maSize
= aBmp
.GetSizePixel();
284 void SvLBoxBmp::Paint(
285 const Point
& rPos
, SvTreeListBox
& rDev
, const SvViewDataEntry
* /*pView*/,
286 const SvTreeListEntry
* /*pEntry*/)
288 DBG_CHKTHIS(SvLBoxBmp
,0);
289 sal_uInt16 nStyle
= rDev
.IsEnabled() ? 0 : IMAGE_DRAW_DISABLE
;
290 rDev
.DrawImage( rPos
, aBmp
,nStyle
);
293 SvLBoxItem
* SvLBoxBmp::Create() const
295 DBG_CHKTHIS(SvLBoxBmp
,0);
296 return new SvLBoxBmp
;
299 void SvLBoxBmp::Clone( SvLBoxItem
* pSource
)
301 DBG_CHKTHIS(SvLBoxBmp
,0);
302 aBmp
= ((SvLBoxBmp
*)pSource
)->aBmp
;
305 // ***************************************************************
306 // class SvLBoxButton
307 // ***************************************************************
309 DBG_NAME(SvLBoxButton
);
311 SvLBoxButton::SvLBoxButton( SvTreeListEntry
* pEntry
, SvLBoxButtonKind eTheKind
,
312 sal_uInt16 nFlags
, SvLBoxButtonData
* pBData
)
313 : SvLBoxItem( pEntry
, nFlags
)
315 DBG_CTOR(SvLBoxButton
,0);
323 SvLBoxButton::SvLBoxButton() : SvLBoxItem()
325 DBG_CTOR(SvLBoxButton
,0);
326 eKind
= SvLBoxButtonKind_enabledCheckbox
;
331 SvLBoxButton::~SvLBoxButton()
333 DBG_DTOR(SvLBoxButton
,0);
336 sal_uInt16
SvLBoxButton::GetType() const
338 DBG_CHKTHIS(SvLBoxButton
,0);
339 return SV_ITEM_ID_LBOXBUTTON
;
342 sal_Bool
SvLBoxButton::ClickHdl( SvTreeListBox
*, SvTreeListEntry
* pEntry
)
344 DBG_CHKTHIS(SvLBoxButton
,0);
345 if ( CheckModification() )
347 if ( IsStateChecked() )
351 pData
->StoreButtonState( pEntry
, nItemFlags
);
357 void SvLBoxButton::Paint(
358 const Point
& rPos
, SvTreeListBox
& rDev
, const SvViewDataEntry
* /*pView*/,
359 const SvTreeListEntry
* /*pEntry*/)
361 DBG_CHKTHIS(SvLBoxButton
,0);
362 sal_uInt16 nIndex
= eKind
== SvLBoxButtonKind_staticImage
363 ? SV_BMP_STATICIMAGE
: pData
->GetIndex( nItemFlags
);
364 sal_uInt16 nStyle
= eKind
!= SvLBoxButtonKind_disabledCheckbox
&&
365 rDev
.IsEnabled() ? 0 : IMAGE_DRAW_DISABLE
;
370 sal_Bool bNativeOK
= sal_False
;
371 ControlType eCtrlType
= (pData
->IsRadio())? CTRL_RADIOBUTTON
: CTRL_CHECKBOX
;
372 if ( nIndex
!= SV_BMP_STATICIMAGE
&& rDev
.IsNativeControlSupported( eCtrlType
, PART_ENTIRE_CONTROL
) )
375 Size
aSize(pData
->Width(), pData
->Height());
376 ImplAdjustBoxSize( aSize
, eCtrlType
, &rDev
);
377 ImplControlValue aControlValue
;
378 Rectangle
aCtrlRegion( rPos
, aSize
);
379 ControlState nState
= 0;
381 //states CTRL_STATE_DEFAULT, CTRL_STATE_PRESSED and CTRL_STATE_ROLLOVER are not implemented
382 if ( IsStateHilighted() ) nState
|= CTRL_STATE_FOCUSED
;
383 if ( nStyle
!= IMAGE_DRAW_DISABLE
) nState
|= CTRL_STATE_ENABLED
;
385 if ( IsStateChecked() )
386 aControlValue
.setTristateVal( BUTTONVALUE_ON
);
387 else if ( IsStateUnchecked() )
388 aControlValue
.setTristateVal( BUTTONVALUE_OFF
);
389 else if ( IsStateTristate() )
390 aControlValue
.setTristateVal( BUTTONVALUE_MIXED
);
392 bNativeOK
= rDev
.DrawNativeControl( eCtrlType
, PART_ENTIRE_CONTROL
,
393 aCtrlRegion
, nState
, aControlValue
, OUString() );
397 rDev
.DrawImage( rPos
, pData
->aBmps
[nIndex
+ nBaseOffs
] ,nStyle
);
400 SvLBoxItem
* SvLBoxButton::Create() const
402 DBG_CHKTHIS(SvLBoxButton
,0);
403 return new SvLBoxButton
;
406 void SvLBoxButton::Clone( SvLBoxItem
* pSource
)
408 DBG_CHKTHIS(SvLBoxButton
,0);
409 pData
= ((SvLBoxButton
*)pSource
)->pData
;
412 void SvLBoxButton::ImplAdjustBoxSize( Size
& io_rSize
, ControlType i_eType
, Window
* i_pParent
)
414 if ( i_pParent
->IsNativeControlSupported( i_eType
, PART_ENTIRE_CONTROL
) )
416 ImplControlValue aControlValue
;
417 Rectangle
aCtrlRegion( Point( 0, 0 ), io_rSize
);
418 ControlState nState
= CTRL_STATE_ENABLED
;
420 aControlValue
.setTristateVal( BUTTONVALUE_ON
);
422 Rectangle aNativeBounds
, aNativeContent
;
423 bool bNativeOK
= i_pParent
->GetNativeControlRegion( i_eType
,
433 Size
aContentSize( aNativeContent
.GetSize() );
434 // leave a little space around the box image (looks better)
435 if( aContentSize
.Height() + 2 > io_rSize
.Height() )
436 io_rSize
.Height() = aContentSize
.Height() + 2;
437 if( aContentSize
.Width() + 2 > io_rSize
.Width() )
438 io_rSize
.Width() = aContentSize
.Width() + 2;
443 void SvLBoxButton::InitViewData( SvTreeListBox
* pView
,SvTreeListEntry
* pEntry
,
444 SvViewDataItem
* pViewData
)
446 DBG_CHKTHIS(SvLBoxButton
,0);
448 pViewData
= pView
->GetViewDataItem( pEntry
, this );
449 Size
aSize( pData
->Width(), pData
->Height() );
451 ControlType eCtrlType
= (pData
->IsRadio())? CTRL_RADIOBUTTON
: CTRL_CHECKBOX
;
452 if ( eKind
!= SvLBoxButtonKind_staticImage
&& pView
)
453 ImplAdjustBoxSize( aSize
, eCtrlType
, pView
);
454 pViewData
->maSize
= aSize
;
457 bool SvLBoxButton::CheckModification() const
459 return eKind
== SvLBoxButtonKind_enabledCheckbox
;
462 // ***************************************************************
463 // class SvLBoxContextBmp
464 // ***************************************************************
466 struct SvLBoxContextBmp_Impl
474 // ***************************************************************
475 DBG_NAME(SvLBoxContextBmp
)
477 SvLBoxContextBmp::SvLBoxContextBmp(
478 SvTreeListEntry
* pEntry
, sal_uInt16 nItemFlags
, Image aBmp1
, Image aBmp2
,
480 :SvLBoxItem( pEntry
, nItemFlags
)
481 ,m_pImpl( new SvLBoxContextBmp_Impl
)
483 DBG_CTOR(SvLBoxContextBmp
,0);
485 m_pImpl
->m_bExpanded
= bExpanded
;
486 SetModeImages( aBmp1
, aBmp2
);
489 SvLBoxContextBmp::SvLBoxContextBmp()
491 ,m_pImpl( new SvLBoxContextBmp_Impl
)
493 m_pImpl
->m_bExpanded
= false;
494 DBG_CTOR(SvLBoxContextBmp
,0);
497 SvLBoxContextBmp::~SvLBoxContextBmp()
500 DBG_DTOR(SvLBoxContextBmp
,0);
503 sal_uInt16
SvLBoxContextBmp::GetType() const
505 DBG_CHKTHIS(SvLBoxContextBmp
,0);
506 return SV_ITEM_ID_LBOXCONTEXTBMP
;
509 sal_Bool
SvLBoxContextBmp::SetModeImages( const Image
& _rBitmap1
, const Image
& _rBitmap2
)
511 DBG_CHKTHIS(SvLBoxContextBmp
,0);
513 sal_Bool bSuccess
= sal_True
;
514 m_pImpl
->m_aImage1
= _rBitmap1
;
515 m_pImpl
->m_aImage2
= _rBitmap2
;
519 Image
& SvLBoxContextBmp::implGetImageStore( sal_Bool _bFirst
)
521 DBG_CHKTHIS(SvLBoxContextBmp
,0);
523 // OJ: #i27071# wrong mode so we just return the normal images
524 return _bFirst
? m_pImpl
->m_aImage1
: m_pImpl
->m_aImage2
;
527 void SvLBoxContextBmp::InitViewData( SvTreeListBox
* pView
,SvTreeListEntry
* pEntry
,
528 SvViewDataItem
* pViewData
)
530 DBG_CHKTHIS(SvLBoxContextBmp
,0);
532 pViewData
= pView
->GetViewDataItem( pEntry
, this );
533 pViewData
->maSize
= m_pImpl
->m_aImage1
.GetSizePixel();
536 void SvLBoxContextBmp::Paint(
537 const Point
& _rPos
, SvTreeListBox
& _rDev
,
538 const SvViewDataEntry
* pView
, const SvTreeListEntry
* pEntry
)
540 DBG_CHKTHIS(SvLBoxContextBmp
,0);
543 const Image
& rImage
= implGetImageStore(pView
->IsExpanded() != m_pImpl
->m_bExpanded
);
545 sal_Bool _bSemiTransparent
= pEntry
&& ( 0 != ( SV_ENTRYFLAG_SEMITRANSPARENT
& pEntry
->GetFlags( ) ) );
547 sal_uInt16 nStyle
= _rDev
.IsEnabled() ? 0 : IMAGE_DRAW_DISABLE
;
548 if ( _bSemiTransparent
)
549 nStyle
|= IMAGE_DRAW_SEMITRANSPARENT
;
550 _rDev
.DrawImage( _rPos
, rImage
, nStyle
);
553 SvLBoxItem
* SvLBoxContextBmp::Create() const
555 DBG_CHKTHIS(SvLBoxContextBmp
,0);
556 return new SvLBoxContextBmp
;
559 void SvLBoxContextBmp::Clone( SvLBoxItem
* pSource
)
561 DBG_CHKTHIS(SvLBoxContextBmp
,0);
562 m_pImpl
->m_aImage1
= static_cast< SvLBoxContextBmp
* >( pSource
)->m_pImpl
->m_aImage1
;
563 m_pImpl
->m_aImage2
= static_cast< SvLBoxContextBmp
* >( pSource
)->m_pImpl
->m_aImage2
;
564 m_pImpl
->m_bExpanded
= static_cast<SvLBoxContextBmp
*>(pSource
)->m_pImpl
->m_bExpanded
;
567 long SvLBoxButtonData::Width()
574 long SvLBoxButtonData::Height()
581 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */