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