xref: /aoo41x/main/svx/source/dialog/dlgctrl.cxx (revision c7be74b1)
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_svx.hxx"
26 
27 // include ---------------------------------------------------------------
28 #include <tools/shl.hxx>
29 #include <vcl/svapp.hxx>
30 #include <svx/xtable.hxx>
31 #include <svx/xpool.hxx>
32 #include <svx/dialogs.hrc>
33 #include <accessibility.hrc>
34 #include <svx/dlgctrl.hxx>
35 #include <svx/dialmgr.hxx>
36 #include <tools/poly.hxx>
37 #include <vcl/region.hxx>
38 #include <vcl/gradient.hxx>
39 #include <vcl/hatch.hxx>
40 #include <svtools/colorcfg.hxx>
41 #include <svxrectctaccessiblecontext.hxx>
42 #include <com/sun/star/lang/XUnoTunnel.hpp>
43 #include <basegfx/point/b2dpoint.hxx>
44 #include <basegfx/polygon/b2dpolygon.hxx>
45 #include <svx/svdorect.hxx>
46 #include <svx/svdmodel.hxx>
47 #include <svx/svdopath.hxx>
48 #include <svx/sdr/contact/objectcontactofobjlistpainter.hxx>
49 #include <svx/sdr/contact/displayinfo.hxx>
50 #include <vcl/bmpacc.hxx>
51 #include <svx/xbtmpit.hxx>
52 
53 #define OUTPUT_DRAWMODE_COLOR		(DRAWMODE_DEFAULT)
54 #define OUTPUT_DRAWMODE_CONTRAST	(DRAWMODE_SETTINGSLINE | DRAWMODE_SETTINGSFILL | DRAWMODE_SETTINGSTEXT | DRAWMODE_SETTINGSGRADIENT)
55 
56 using namespace ::com::sun::star::uno;
57 using namespace ::com::sun::star::lang;
58 using namespace ::com::sun::star::accessibility;
59 
60 
61 /*************************************************************************
62 |*
63 |*	Control zur Darstellung und Auswahl der Eckpunkte (und Mittelpunkt)
64 |*	eines Objekts
65 |*
66 \************************************************************************/
67 
68 Bitmap& SvxRectCtl::GetRectBitmap( void )
69 {
70 	if( !pBitmap )
71 		InitRectBitmap();
72 
73 	return *pBitmap;
74 }
75 
76 SvxRectCtl::SvxRectCtl( Window* pParent, const ResId& rResId, RECT_POINT eRpt,
77 						sal_uInt16 nBorder, sal_uInt16 nCircle, CTL_STYLE eStyle ) :
78 
79 	Control( pParent, rResId ),
80 
81 	pAccContext	( NULL ),
82     nBorderWidth( nBorder ),
83     nRadius     ( nCircle),
84     eDefRP      ( eRpt ),
85     eCS         ( eStyle ),
86 	pBitmap		( NULL ),
87     m_nState    ( 0 ),
88     mbCompleteDisable(sal_False)
89 {
90 	SetMapMode( MAP_100TH_MM );
91     Resize_Impl();
92 }
93 
94 // -----------------------------------------------------------------------
95 
96 SvxRectCtl::~SvxRectCtl()
97 {
98 	delete pBitmap;
99 
100 	if( pAccContext )
101 		pAccContext->release();
102 }
103 
104 // -----------------------------------------------------------------------
105 void SvxRectCtl::Resize()
106 {
107     Resize_Impl();
108     Control::Resize();
109 }
110 
111 // -----------------------------------------------------------------------
112 
113 void SvxRectCtl::Resize_Impl()
114 {
115     aSize = GetOutputSize();
116 
117 	switch( eCS )
118 	{
119 		case CS_RECT:
120 		case CS_ANGLE:
121 		case CS_SHADOW:
122 			aPtLT = Point( 0 + nBorderWidth,  0 + nBorderWidth );
123 			aPtMT = Point( aSize.Width() / 2, 0 + nBorderWidth );
124 			aPtRT = Point( aSize.Width() - nBorderWidth, 0 + nBorderWidth );
125 
126 			aPtLM = Point( 0 + nBorderWidth,  aSize.Height() / 2 );
127 			aPtMM = Point( aSize.Width() / 2, aSize.Height() / 2 );
128 			aPtRM = Point( aSize.Width() - nBorderWidth, aSize.Height() / 2 );
129 
130 			aPtLB = Point( 0 + nBorderWidth,	aSize.Height() - nBorderWidth );
131 			aPtMB = Point( aSize.Width() / 2,	aSize.Height() - nBorderWidth );
132 			aPtRB = Point( aSize.Width() - nBorderWidth, aSize.Height() - nBorderWidth );
133 		break;
134 
135 		case CS_LINE:
136 			aPtLT = Point( 0 + 3 * nBorderWidth,  0 + nBorderWidth );
137 			aPtMT = Point( aSize.Width() / 2, 0 + nBorderWidth );
138 			aPtRT = Point( aSize.Width() - 3 * nBorderWidth, 0 + nBorderWidth );
139 
140 			aPtLM = Point( 0 + 3 * nBorderWidth,  aSize.Height() / 2 );
141 			aPtMM = Point( aSize.Width() / 2, aSize.Height() / 2 );
142 			aPtRM = Point( aSize.Width() - 3 * nBorderWidth, aSize.Height() / 2 );
143 
144 			aPtLB = Point( 0 + 3 * nBorderWidth,	aSize.Height() - nBorderWidth );
145 			aPtMB = Point( aSize.Width() / 2,	aSize.Height() - nBorderWidth );
146 			aPtRB = Point( aSize.Width() - 3 * nBorderWidth, aSize.Height() - nBorderWidth );
147 		break;
148 	}
149 	Reset();
150 	InitSettings( sal_True, sal_True );
151 }
152 // -----------------------------------------------------------------------
153 
154 void SvxRectCtl::InitRectBitmap( void )
155 {
156 	if( pBitmap )
157 		delete pBitmap;
158 
159 	const StyleSettings&	rStyles = Application::GetSettings().GetStyleSettings();
160 	svtools::ColorConfig aColorConfig;
161 
162 	pBitmap = new Bitmap( SVX_RES( RID_SVXCTRL_RECTBTNS ) );
163 
164 	// set bitmap-colors
165 	Color	aColorAry1[7];
166 	Color	aColorAry2[7];
167 	aColorAry1[0] = Color( 0xC0, 0xC0, 0xC0 );	// light-gray
168 	aColorAry1[1] = Color( 0xFF, 0xFF, 0x00 );	// yellow
169 	aColorAry1[2] = Color( 0xFF, 0xFF, 0xFF );	// white
170 	aColorAry1[3] = Color( 0x80, 0x80, 0x80 );	// dark-gray
171 	aColorAry1[4] = Color( 0x00, 0x00, 0x00 );  // black
172 	aColorAry1[5] = Color( 0x00, 0xFF, 0x00 );	// green
173 	aColorAry1[6] = Color( 0x00, 0x00, 0xFF );	// blue
174 	aColorAry2[0] = rStyles.GetDialogColor();		// background
175 	aColorAry2[1] = rStyles.GetWindowColor();
176 	aColorAry2[2] = rStyles.GetLightColor();
177 	aColorAry2[3] = rStyles.GetShadowColor();
178 	aColorAry2[4] = rStyles.GetDarkShadowColor();
179 	aColorAry2[5] = Color( aColorConfig.GetColorValue( svtools::FONTCOLOR ).nColor );
180 	aColorAry2[6] = rStyles.GetDialogColor();
181 
182 #ifdef DBG_UTIL
183 	static sal_Bool		bModify = sal_False;
184 	sal_Bool&			rModify = bModify;
185 	if( rModify )
186 	{
187 		static int		n = 0;
188 		static sal_uInt8	r = 0xFF;
189 		static sal_uInt8	g = 0x00;
190 		static sal_uInt8	b = 0xFF;
191 		int&			rn = n;
192 		sal_uInt8&			rr = r;
193 		sal_uInt8&			rg = g;
194 		sal_uInt8&			rb = b;
195 		aColorAry2[ rn ] = Color( rr, rg, rb );
196 	}
197 #endif
198 
199 	pBitmap->Replace( aColorAry1, aColorAry2, 7, NULL );
200 }
201 
202 // -----------------------------------------------------------------------
203 
204 void SvxRectCtl::InitSettings( sal_Bool bForeground, sal_Bool bBackground )
205 {
206 	const StyleSettings& rStyleSettings = Application::GetSettings().GetStyleSettings();
207 
208 	if( bForeground )
209 	{
210 		svtools::ColorConfig aColorConfig;
211 		Color aTextColor( aColorConfig.GetColorValue( svtools::FONTCOLOR ).nColor );
212 
213 		if ( IsControlForeground() )
214 			aTextColor = GetControlForeground();
215 		SetTextColor( aTextColor );
216 	}
217 
218 	if( bBackground )
219 	{
220 		if ( IsControlBackground() )
221 			SetBackground( GetControlBackground() );
222 		else
223 			SetBackground( rStyleSettings.GetWindowColor() );
224 	}
225 
226 	delete pBitmap;
227 	pBitmap = NULL;		// forces new creating of bitmap
228 
229 	Invalidate();
230 }
231 
232 /*************************************************************************
233 |*
234 |*	Das angeklickte Rechteck (3 x 3) wird ermittelt und der Parent (Dialog)
235 |*	wird benachrichtigt, dass der Punkt geaendert wurde
236 |*
237 \************************************************************************/
238 
239 void SvxRectCtl::MouseButtonDown( const MouseEvent& rMEvt )
240 {
241 	// #103516# CompletelyDisabled() added to have a disabled state for SvxRectCtl
242 	if(!IsCompletelyDisabled())
243 	{
244 		Point aPtLast = aPtNew;
245 
246 		aPtNew = GetApproxLogPtFromPixPt( rMEvt.GetPosPixel() );
247 
248 		if( aPtNew == aPtMM && ( eCS == CS_SHADOW || eCS == CS_ANGLE ) )
249 		{
250 			aPtNew = aPtLast;
251 		}
252 		else
253 		{
254 			Invalidate( Rectangle( aPtLast - Point( nRadius, nRadius ),
255 								   aPtLast + Point( nRadius, nRadius ) ) );
256 			Invalidate( Rectangle( aPtNew - Point( nRadius, nRadius ),
257 								   aPtNew + Point( nRadius, nRadius ) ) );
258 			eRP = GetRPFromPoint( aPtNew );
259 
260 			SetActualRP( eRP );
261 
262 			if( WINDOW_TABPAGE == GetParent()->GetType() )
263 				( (SvxTabPage*) GetParent() )->PointChanged( this, eRP );
264 		}
265 	}
266 }
267 
268 // -----------------------------------------------------------------------
269 
270 void SvxRectCtl::KeyInput( const KeyEvent& rKeyEvt )
271 {
272 	// #103516# CompletelyDisabled() added to have a disabled state for SvxRectCtl
273 	if(!IsCompletelyDisabled())
274 	{
275 		RECT_POINT eNewRP = eRP;
276 		sal_Bool bUseMM = (eCS != CS_SHADOW) && (eCS != CS_ANGLE);
277 
278 		switch( rKeyEvt.GetKeyCode().GetCode() )
279 		{
280 			case KEY_DOWN:
281 			{
282 				if( !(m_nState & CS_NOVERT) )
283 					switch( eNewRP )
284 					{
285 						case RP_LT: eNewRP = RP_LM; break;
286 						case RP_MT: eNewRP = bUseMM ? RP_MM : RP_MB; break;
287 						case RP_RT: eNewRP = RP_RM; break;
288 						case RP_LM: eNewRP = RP_LB; break;
289 						case RP_MM: eNewRP = RP_MB; break;
290 						case RP_RM: eNewRP = RP_RB; break;
291                         default: ; //prevent warning
292                     }
293 			}
294 			break;
295 			case KEY_UP:
296 			{
297 				if( !(m_nState & CS_NOVERT) )
298 					switch( eNewRP )
299 					{
300 						case RP_LM: eNewRP = RP_LT; break;
301 						case RP_MM: eNewRP = RP_MT; break;
302 						case RP_RM: eNewRP = RP_RT; break;
303 						case RP_LB: eNewRP = RP_LM; break;
304 						case RP_MB: eNewRP = bUseMM ? RP_MM : RP_MT; break;
305 						case RP_RB: eNewRP = RP_RM; break;
306                         default: ; //prevent warning
307                     }
308 			}
309 			break;
310 			case KEY_LEFT:
311 			{
312 				if( !(m_nState & CS_NOHORZ) )
313 					switch( eNewRP )
314 					{
315 						case RP_MT: eNewRP = RP_LT; break;
316 						case RP_RT: eNewRP = RP_MT; break;
317 						case RP_MM: eNewRP = RP_LM; break;
318 						case RP_RM: eNewRP = bUseMM ? RP_MM : RP_LM; break;
319 						case RP_MB: eNewRP = RP_LB; break;
320 						case RP_RB: eNewRP = RP_MB; break;
321                         default: ; //prevent warning
322                     }
323 			}
324 			break;
325 			case KEY_RIGHT:
326 			{
327 				if( !(m_nState & CS_NOHORZ) )
328 					switch( eNewRP )
329 					{
330 						case RP_LT: eNewRP = RP_MT; break;
331 						case RP_MT: eNewRP = RP_RT; break;
332 						case RP_LM: eNewRP = bUseMM ? RP_MM : RP_RM; break;
333 						case RP_MM: eNewRP = RP_RM; break;
334 						case RP_LB: eNewRP = RP_MB; break;
335 						case RP_MB: eNewRP = RP_RB; break;
336                         default: ; //prevent warning
337                     }
338 			}
339 			break;
340 			default:
341 				Control::KeyInput( rKeyEvt );
342 				return;
343 		}
344 		if( eNewRP != eRP )
345 		{
346 			SetActualRP( eNewRP );
347 
348 			if( WINDOW_TABPAGE == GetParent()->GetType() )
349 				( (SvxTabPage*) GetParent() )->PointChanged( this, eRP );
350 
351 			SetFocusRect();
352 		}
353 	}
354 }
355 
356 // -----------------------------------------------------------------------
357 
358 void SvxRectCtl::StateChanged( StateChangedType nType )
359 {
360 	if ( nType == STATE_CHANGE_CONTROLFOREGROUND )
361 		InitSettings( sal_True, sal_False );
362 	else if ( nType == STATE_CHANGE_CONTROLBACKGROUND )
363 		InitSettings( sal_False, sal_True );
364 
365 	Window::StateChanged( nType );
366 }
367 
368 // -----------------------------------------------------------------------
369 
370 void SvxRectCtl::DataChanged( const DataChangedEvent& rDCEvt )
371 {
372 	if ( ( rDCEvt.GetType() == DATACHANGED_SETTINGS ) && ( rDCEvt.GetFlags() & SETTINGS_STYLE ) )
373 		InitSettings( sal_True, sal_True );
374 	else
375 		Window::DataChanged( rDCEvt );
376 }
377 
378 /*************************************************************************
379 |*
380 |*	Zeichnet das Control (Rechteck mit 9 Kreisen)
381 |*
382 \************************************************************************/
383 
384 void SvxRectCtl::Paint( const Rectangle& )
385 {
386 	Point	aPtDiff( PixelToLogic( Point( 1, 1 ) ) );
387 
388 	const StyleSettings& rStyles = Application::GetSettings().GetStyleSettings();
389 
390 	SetLineColor( rStyles.GetDialogColor() );
391 	SetFillColor( rStyles.GetDialogColor() );
392 	DrawRect( Rectangle( Point(0,0), GetOutputSize() ) );
393 
394 	if( IsEnabled() )
395 		SetLineColor( rStyles.GetLabelTextColor() );
396 	else
397 		SetLineColor( rStyles.GetShadowColor() );
398 
399 	SetFillColor();
400 
401 	switch( eCS )
402 	{
403 
404 		case CS_RECT:
405 		case CS_SHADOW:
406 			if( !IsEnabled() )
407 			{
408 				Color aOldCol = GetLineColor();
409 				SetLineColor( rStyles.GetLightColor() );
410 				DrawRect( Rectangle( aPtLT + aPtDiff, aPtRB + aPtDiff ) );
411 				SetLineColor( aOldCol );
412 			}
413 			DrawRect( Rectangle( aPtLT, aPtRB ) );
414 		break;
415 
416 		case CS_LINE:
417 			if( !IsEnabled() )
418 			{
419 				Color aOldCol = GetLineColor();
420 				SetLineColor( rStyles.GetLightColor() );
421 				DrawLine( aPtLM - Point( 2 * nBorderWidth, 0) + aPtDiff,
422 						  aPtRM + Point( 2 * nBorderWidth, 0 ) + aPtDiff );
423 				SetLineColor( aOldCol );
424 			}
425 			DrawLine( aPtLM - Point( 2 * nBorderWidth, 0),
426 					  aPtRM + Point( 2 * nBorderWidth, 0 ) );
427 		break;
428 
429 		case CS_ANGLE:
430 			if( !IsEnabled() )
431 			{
432 				Color aOldCol = GetLineColor();
433 				SetLineColor( rStyles.GetLightColor() );
434 				DrawLine( aPtLT + aPtDiff, aPtRB + aPtDiff );
435 				DrawLine( aPtLB + aPtDiff, aPtRT + aPtDiff );
436 				DrawLine( aPtLM + aPtDiff, aPtRM + aPtDiff );
437 				DrawLine( aPtMT + aPtDiff, aPtMB + aPtDiff );
438 				SetLineColor( aOldCol );
439 			}
440 			DrawLine( aPtLT, aPtRB );
441 			DrawLine( aPtLB, aPtRT );
442 			DrawLine( aPtLM, aPtRM );
443 			DrawLine( aPtMT, aPtMB );
444 		break;
445 
446 		default:
447 			break;
448 	}
449 	SetFillColor( GetBackground().GetColor() );
450 
451 	Size aBtnSize( 11, 11 );
452 	Size aDstBtnSize(  PixelToLogic( aBtnSize ) );
453 	Point aToCenter( aDstBtnSize.Width() >> 1, aDstBtnSize.Height() >> 1);
454 	Point aBtnPnt1( IsEnabled()?0:22,0 );
455 	Point aBtnPnt2( 11,0 );
456 	Point aBtnPnt3( 22,0 );
457 
458 	sal_Bool bNoHorz = (m_nState & CS_NOHORZ) != 0;
459 	sal_Bool bNoVert = (m_nState & CS_NOVERT) != 0;
460 
461 	Bitmap&			rBitmap = GetRectBitmap();
462 
463 	// #103516# CompletelyDisabled() added to have a disabled state for SvxRectCtl
464 	if(IsCompletelyDisabled())
465 	{
466 		DrawBitmap( aPtLT - aToCenter, aDstBtnSize, aBtnPnt3, aBtnSize, rBitmap );
467 		DrawBitmap( aPtMT - aToCenter, aDstBtnSize, aBtnPnt3, aBtnSize, rBitmap );
468 		DrawBitmap( aPtRT - aToCenter, aDstBtnSize, aBtnPnt3, aBtnSize, rBitmap );
469 		DrawBitmap( aPtLM - aToCenter, aDstBtnSize, aBtnPnt3, aBtnSize, rBitmap );
470 		if( eCS == CS_RECT || eCS == CS_LINE )
471 			DrawBitmap( aPtMM - aToCenter, aDstBtnSize, aBtnPnt3, aBtnSize, rBitmap );
472 		DrawBitmap( aPtRM - aToCenter, aDstBtnSize, aBtnPnt3, aBtnSize, rBitmap );
473 		DrawBitmap( aPtLB - aToCenter, aDstBtnSize, aBtnPnt3, aBtnSize, rBitmap );
474 		DrawBitmap( aPtMB - aToCenter, aDstBtnSize, aBtnPnt3, aBtnSize, rBitmap );
475 		DrawBitmap( aPtRB - aToCenter, aDstBtnSize, aBtnPnt3, aBtnSize, rBitmap );
476 	}
477 	else
478 	{
479 		DrawBitmap( aPtLT - aToCenter, aDstBtnSize, (bNoHorz | bNoVert)?aBtnPnt3:aBtnPnt1, aBtnSize, rBitmap );
480 		DrawBitmap( aPtMT - aToCenter, aDstBtnSize, bNoVert?aBtnPnt3:aBtnPnt1, aBtnSize, rBitmap );
481 		DrawBitmap( aPtRT - aToCenter, aDstBtnSize, (bNoHorz | bNoVert)?aBtnPnt3:aBtnPnt1, aBtnSize, rBitmap );
482 
483 		DrawBitmap( aPtLM - aToCenter, aDstBtnSize, bNoHorz?aBtnPnt3:aBtnPnt1, aBtnSize, rBitmap );
484 
485 		// Mittelpunkt bei Rechteck und Linie
486 		if( eCS == CS_RECT || eCS == CS_LINE )
487 			DrawBitmap( aPtMM - aToCenter, aDstBtnSize, aBtnPnt1, aBtnSize, rBitmap );
488 
489 		DrawBitmap( aPtRM - aToCenter, aDstBtnSize, bNoHorz?aBtnPnt3:aBtnPnt1, aBtnSize, rBitmap );
490 
491 		DrawBitmap( aPtLB - aToCenter, aDstBtnSize, (bNoHorz | bNoVert)?aBtnPnt3:aBtnPnt1, aBtnSize, rBitmap );
492 		DrawBitmap( aPtMB - aToCenter, aDstBtnSize, bNoVert?aBtnPnt3:aBtnPnt1, aBtnSize, rBitmap );
493 		DrawBitmap( aPtRB - aToCenter, aDstBtnSize, (bNoHorz | bNoVert)?aBtnPnt3:aBtnPnt1, aBtnSize, rBitmap );
494 	}
495 
496 	// draw active button, avoid center pos for angle
497 	// #103516# CompletelyDisabled() added to have a disabled state for SvxRectCtl
498 	if(!IsCompletelyDisabled())
499 	{
500 		if( IsEnabled() && (eCS != CS_ANGLE || aPtNew != aPtMM) )
501 		{
502 			Point		aCenterPt( aPtNew );
503 			aCenterPt -= aToCenter;
504 
505 			DrawBitmap( aCenterPt, aDstBtnSize, aBtnPnt2, aBtnSize, rBitmap );
506 		}
507 	}
508 }
509 
510 /*************************************************************************
511 |*
512 |*	Konvertiert RECT_POINT in Point
513 |*
514 \************************************************************************/
515 
516 Point SvxRectCtl::GetPointFromRP( RECT_POINT _eRP) const
517 {
518     switch( _eRP )
519 	{
520 		case RP_LT: return aPtLT;
521 		case RP_MT: return aPtMT;
522 		case RP_RT: return aPtRT;
523 		case RP_LM: return aPtLM;
524 		case RP_MM: return aPtMM;
525 		case RP_RM: return aPtRM;
526 		case RP_LB: return aPtLB;
527 		case RP_MB: return aPtMB;
528 		case RP_RB: return aPtRB;
529 	}
530 	return( aPtMM ); // default
531 }
532 
533 
534 void SvxRectCtl::SetFocusRect( const Rectangle* pRect )
535 {
536 	HideFocus();
537 
538 	if( pRect )
539 		ShowFocus( *pRect );
540 	else
541 		ShowFocus( CalculateFocusRectangle() );
542 }
543 
544 Point SvxRectCtl::SetActualRPWithoutInvalidate( RECT_POINT eNewRP )
545 {
546 	Point aPtLast = aPtNew;
547 	aPtNew = GetPointFromRP( eNewRP );
548 
549 	if( (m_nState & CS_NOHORZ) != 0 )
550 		aPtNew.X() = aPtMM.X();
551 
552 	if( (m_nState & CS_NOVERT) != 0 )
553 		aPtNew.Y() = aPtMM.Y();
554 
555 	eNewRP = GetRPFromPoint( aPtNew );
556 
557 	eDefRP = eNewRP;
558 	eRP = eNewRP;
559 
560 	return aPtLast;
561 }
562 
563 void SvxRectCtl::GetFocus()
564 {
565 	SetFocusRect();
566 }
567 
568 
569 void SvxRectCtl::LoseFocus()
570 {
571 	HideFocus();
572 }
573 
574 
575 Point SvxRectCtl::GetApproxLogPtFromPixPt( const Point& rPt ) const
576 {
577 	Point	aPt = PixelToLogic( rPt );
578 	long	x;
579 	long	y;
580 
581 	if( ( m_nState & CS_NOHORZ ) == 0 )
582 	{
583 		if( aPt.X() < aSize.Width() / 3 )
584 			x = aPtLT.X();
585 		else if( aPt.X() < aSize.Width() * 2 / 3 )
586 			x = aPtMM.X();
587 		else
588 			x = aPtRB.X();
589 	}
590 	else
591 		x = aPtMM.X();
592 
593 	if( ( m_nState & CS_NOVERT ) == 0 )
594 	{
595 		if( aPt.Y() < aSize.Height() / 3 )
596 			y = aPtLT.Y();
597 		else if( aPt.Y() < aSize.Height() * 2 / 3 )
598 			y = aPtMM.Y();
599 		else
600 			y = aPtRB.Y();
601 	}
602 	else
603 			y = aPtMM.Y();
604 
605 	return Point( x, y );
606 }
607 
608 
609 /*************************************************************************
610 |*
611 |*	Konvertiert Point in RECT_POINT
612 |*
613 \************************************************************************/
614 
615 RECT_POINT SvxRectCtl::GetRPFromPoint( Point aPt ) const
616 {
617 	if	   ( aPt == aPtLT) return RP_LT;
618 	else if( aPt == aPtMT) return RP_MT;
619 	else if( aPt == aPtRT) return RP_RT;
620 	else if( aPt == aPtLM) return RP_LM;
621 	else if( aPt == aPtRM) return RP_RM;
622 	else if( aPt == aPtLB) return RP_LB;
623 	else if( aPt == aPtMB) return RP_MB;
624 	else if( aPt == aPtRB) return RP_RB;
625 
626 	else
627 		return RP_MM; // default
628 }
629 
630 /*************************************************************************
631 |*
632 |*	Bewirkt den Ursprungszustand des Controls
633 |*
634 \************************************************************************/
635 
636 void SvxRectCtl::Reset()
637 {
638 	aPtNew = GetPointFromRP( eDefRP );
639 	eRP = eDefRP;
640 	Invalidate();
641 }
642 
643 /*************************************************************************
644 |*
645 |*	Gibt den aktuell ausgewaehlten RECT_POINT zur�ck
646 |*
647 \************************************************************************/
648 
649 RECT_POINT SvxRectCtl::GetActualRP() const
650 {
651 	return( eRP );
652 }
653 
654 /*************************************************************************
655 |*
656 |*	Gibt den aktuell ausgewaehlten RECT_POINT zur�ck
657 |*
658 \************************************************************************/
659 
660 void SvxRectCtl::SetActualRP( RECT_POINT eNewRP )
661 {
662 	Point aPtLast( SetActualRPWithoutInvalidate( eNewRP ) );
663 
664 	Invalidate( Rectangle( aPtLast - Point( nRadius, nRadius ), aPtLast + Point( nRadius, nRadius ) ) );
665 	Invalidate( Rectangle( aPtNew - Point( nRadius, nRadius ), aPtNew + Point( nRadius, nRadius ) ) );
666 
667 	// notify accessibility object about change
668 	if( pAccContext )
669 		pAccContext->selectChild( eNewRP );
670 }
671 
672 void SvxRectCtl::SetState( CTL_STATE nState )
673 {
674 	m_nState = nState;
675 
676 	Point aPtLast( GetPointFromRP( eRP ) );
677     Point _aPtNew( aPtLast );
678 
679 	if( (m_nState & CS_NOHORZ) != 0 )
680         _aPtNew.X() = aPtMM.X();
681 
682 	if( (m_nState & CS_NOVERT) != 0 )
683         _aPtNew.Y() = aPtMM.Y();
684 
685     eRP = GetRPFromPoint( _aPtNew );
686 	Invalidate();
687 
688 	if( WINDOW_TABPAGE == GetParent()->GetType() )
689 		( (SvxTabPage*) GetParent() )->PointChanged( this, eRP );
690 }
691 
692 sal_uInt8 SvxRectCtl::GetNumOfChilds( void ) const
693 {
694 	return ( eCS == CS_ANGLE )? 8 : 9;
695 }
696 
697 Rectangle SvxRectCtl::CalculateFocusRectangle( void ) const
698 {
699 	Size		aDstBtnSize( PixelToLogic( Size( 15, 15 ) ) );
700 	return Rectangle( aPtNew - Point( aDstBtnSize.Width() >> 1, aDstBtnSize.Height() >> 1 ), aDstBtnSize );
701 }
702 
703 Rectangle SvxRectCtl::CalculateFocusRectangle( RECT_POINT eRectPoint ) const
704 {
705 	Rectangle	aRet;
706 	RECT_POINT	eOldRectPoint = GetActualRP();
707 
708 	if( eOldRectPoint == eRectPoint )
709 		aRet = CalculateFocusRectangle();
710 	else
711 	{
712 		SvxRectCtl*	pThis = const_cast< SvxRectCtl* >( this );
713 
714 		pThis->SetActualRPWithoutInvalidate( eRectPoint );		// no invalidation because it's only temporary!
715 		aRet = CalculateFocusRectangle();
716 
717 		pThis->SetActualRPWithoutInvalidate( eOldRectPoint );	// no invalidation because nothing has changed!
718 	}
719 
720 	return aRet;
721 }
722 
723 Reference< XAccessible > SvxRectCtl::CreateAccessible()
724 {
725 	Window*						pParent = GetAccessibleParentWindow();
726 
727 	DBG_ASSERT( pParent, "-SvxRectCtl::CreateAccessible(): No Parent!" );
728 
729 	Reference< XAccessible >	xAccParent  = pParent->GetAccessible();
730 	if( xAccParent.is() )
731 	{
732 		pAccContext = new SvxRectCtlAccessibleContext( xAccParent, *this );
733 		pAccContext->acquire();
734 
735         SetActualRP( GetActualRP() );
736 
737 		return pAccContext;
738 	}
739 	else
740 		return Reference< XAccessible >();
741 }
742 
743 RECT_POINT SvxRectCtl::GetApproxRPFromPixPt( const ::com::sun::star::awt::Point& r ) const
744 {
745 	return GetRPFromPoint( GetApproxLogPtFromPixPt( Point( r.X, r.Y ) ) );
746 }
747 
748 // #103516# CompletelyDisabled() added to have a disabled state for SvxRectCtl
749 void SvxRectCtl::DoCompletelyDisable(sal_Bool bNew)
750 {
751 	mbCompleteDisable = bNew;
752 	Invalidate();
753 }
754 
755 /*************************************************************************
756 |*
757 |* Konstruktor ohne Size-Parameter
758 |*
759 \************************************************************************/
760 
761 SvxAngleCtl::SvxAngleCtl( Window* pParent, const ResId& rResId ) :
762 
763 	SvxRectCtl( pParent, rResId ),
764 
765 	aFont( Application::GetSettings().GetStyleSettings().GetAppFont() )
766 {
767 	aFontSize = Size( 250, 400 );
768 	Initialize();
769 }
770 
771 /*************************************************************************
772 |*
773 |* Konstruktor mit Size-Parameter
774 |*
775 \************************************************************************/
776 
777 SvxAngleCtl::SvxAngleCtl( Window* pParent, const ResId& rResId, Size _aSize ) :
778 
779 	SvxRectCtl( pParent, rResId ),
780 
781 	aFont( Application::GetSettings().GetStyleSettings().GetAppFont() )
782 {
783     aFontSize = _aSize;
784 	Initialize();
785 }
786 
787 /*************************************************************************
788 |*
789 |* Initialisierung
790 |*
791 \************************************************************************/
792 
793 void SvxAngleCtl::Initialize()
794 {
795 	bPositive = sal_True;
796 
797 	// aFont.SetName( "Helvetica" );
798 	aFont.SetSize( aFontSize );
799 	aFont.SetWeight( WEIGHT_NORMAL );
800 	aFont.SetTransparent( sal_False );
801 
802 	SetFont( aFont );
803 }
804 
805 /*************************************************************************
806 |*
807 |*	Zeichnet das (Mini-)Koordinatensystem
808 |*
809 \************************************************************************/
810 
811 void SvxAngleCtl::Paint( const Rectangle& )
812 {
813 	SetLineColor( Color( COL_BLACK ) ); 	// PEN_DOT ???
814 	DrawLine( aPtLT - Point( 0, 0), aPtRB + Point( 0, 0 ) );
815 	DrawLine( aPtLB - Point( 0, 0), aPtRT + Point( 0, 0 ) );
816 
817 	SetLineColor( Color( COL_BLACK ) );
818 	DrawLine( aPtLM - Point( 0, 0), aPtRM + Point( 0, 0 ) );
819 	DrawLine( aPtMT - Point( 0, 0), aPtMB + Point( 0, 0 ) );
820 
821 	Point aDiff(aFontSize.Width() / 2, aFontSize.Height() / 2);
822 
823 	DrawText( aPtLT - aDiff, UniString::CreateFromAscii(
824 		                     RTL_CONSTASCII_STRINGPARAM( "135" ) ) );
825 	DrawText( aPtLM - aDiff, UniString::CreateFromAscii(
826 		                     RTL_CONSTASCII_STRINGPARAM( "180" ) ) );
827 
828 	if ( bPositive )
829 		DrawText( aPtLB - aDiff, UniString::CreateFromAscii(
830 		                         RTL_CONSTASCII_STRINGPARAM( "225" ) ) );
831 	else
832 		DrawText( aPtLB - aDiff, UniString::CreateFromAscii(
833 		                         RTL_CONSTASCII_STRINGPARAM( "-135" ) ) );
834 
835 	aDiff.X() = aFontSize.Width();
836 	DrawText( aPtMT - aDiff, UniString::CreateFromAscii(
837 		                     RTL_CONSTASCII_STRINGPARAM( "90" ) ) );
838 	DrawText( aPtRT - aDiff, UniString::CreateFromAscii(
839 		                     RTL_CONSTASCII_STRINGPARAM( "45" ) ) );
840 	aDiff.X() = aDiff .X() * 3 / 2;
841 
842 	if ( bPositive )
843 		DrawText( aPtMB - aDiff, UniString::CreateFromAscii(
844 		                         RTL_CONSTASCII_STRINGPARAM( "270" ) ) );
845 	else
846 		DrawText( aPtMB - aDiff, UniString::CreateFromAscii(
847 		                         RTL_CONSTASCII_STRINGPARAM( "-90" ) ) );
848 
849 	DrawText( aPtRM - Point( 0, aDiff.Y() ), UniString::CreateFromAscii(
850 		                                     RTL_CONSTASCII_STRINGPARAM( "0" ) ) );
851 	aDiff.X() = aFontSize.Width() * 2;
852 
853 	if ( bPositive )
854 		DrawText( aPtRB - aDiff, UniString::CreateFromAscii(
855 		                         RTL_CONSTASCII_STRINGPARAM( "315" ) ) );
856 	else
857 		DrawText( aPtRB - aDiff, UniString::CreateFromAscii(
858 		                         RTL_CONSTASCII_STRINGPARAM( "-45" ) ) );
859 }
860 
861 /*************************************************************************
862 |*
863 |*	Control zum Editieren von Bitmaps
864 |*
865 \************************************************************************/
866 
867 SvxPixelCtl::SvxPixelCtl( Window* pParent, const ResId& rResId, sal_uInt16 nNumber ) :
868 						Control		( pParent, rResId ),
869 						nLines		( nNumber ),
870 						bPaintable	( sal_True )
871 {
872 	// SetMapMode( MAP_100TH_MM );
873 	aRectSize = GetOutputSize();
874 
875 	SetPixelColor( Color( COL_BLACK ) );
876 	SetBackgroundColor( Color( COL_WHITE ) );
877 	SetLineColor( Application::GetSettings().GetStyleSettings().GetShadowColor() );
878 
879 	nSquares = nLines * nLines;
880 	pPixel = new sal_uInt16[ nSquares ];
881 	rtl_zeroMemory(pPixel, nSquares * sizeof(sal_uInt16));
882 }
883 
884 /*************************************************************************
885 |*
886 |*	Destruktor dealociert dyn. Array
887 |*
888 \************************************************************************/
889 
890 SvxPixelCtl::~SvxPixelCtl( )
891 {
892 	delete []pPixel;
893 }
894 
895 /*************************************************************************
896 |*
897 |*	Wechselt die Vordergrund- ,bzw. Hintergrundfarbe
898 |*
899 \************************************************************************/
900 
901 void SvxPixelCtl::ChangePixel( sal_uInt16 nPixel )
902 {
903 	if( *( pPixel + nPixel) == 0 )
904 		*( pPixel + nPixel) = 1; // koennte erweitert werden auf mehrere Farben
905 	else
906 		*( pPixel + nPixel) = 0;
907 }
908 
909 /*************************************************************************
910 |*
911 |*	Das angeklickte Rechteck wird ermittelt um die Farbe zu wechseln
912 |*
913 \************************************************************************/
914 
915 void SvxPixelCtl::MouseButtonDown( const MouseEvent& rMEvt )
916 {
917 	Point aPt = PixelToLogic( rMEvt.GetPosPixel() );
918 	Point aPtTl, aPtBr;
919 	sal_uInt16	nX, nY;
920 
921 	nX = (sal_uInt16) ( aPt.X() * nLines / aRectSize.Width() );
922 	nY = (sal_uInt16) ( aPt.Y() * nLines / aRectSize.Height() );
923 
924 	ChangePixel( nX + nY * nLines );
925 
926 	aPtTl.X() = aRectSize.Width() * nX / nLines + 1;
927 	aPtBr.X() = aRectSize.Width() * (nX + 1) / nLines - 1;
928 	aPtTl.Y() = aRectSize.Height() * nY / nLines + 1;
929 	aPtBr.Y() = aRectSize.Height() * (nY + 1) / nLines - 1;
930 
931 	Invalidate( Rectangle( aPtTl, aPtBr ) );
932 
933 	if( WINDOW_TABPAGE == GetParent()->GetType() )
934 		( (SvxTabPage*) GetParent() )->PointChanged( this, RP_MM ); // RectPoint ist dummy
935 }
936 
937 /*************************************************************************
938 |*
939 |*	Zeichnet das Control (Rechteck mit 9 Kreisen)
940 |*
941 \************************************************************************/
942 
943 void SvxPixelCtl::Paint( const Rectangle& )
944 {
945 	sal_uInt16	i, j, nTmp;
946 	Point	aPtTl, aPtBr;
947 
948 	if( bPaintable )
949 	{
950 		// Linien Zeichnen
951 		Control::SetLineColor( aLineColor );
952 		for( i = 1; i < nLines; i++)
953 		{
954 			// horizontal
955 			nTmp = (sal_uInt16) ( aRectSize.Height() * i / nLines );
956 			DrawLine( Point( 0, nTmp ), Point( aRectSize.Width(), nTmp ) );
957 			// vertikal
958 			nTmp = (sal_uInt16) ( aRectSize.Width() * i / nLines );
959 			DrawLine( Point( nTmp, 0 ), Point( nTmp, aRectSize.Height() ) );
960 		}
961 
962 		// Rechtecke (Quadrate) zeichnen
963 		Control::SetLineColor();
964 		sal_uInt16 nLastPixel = *pPixel ? 0 : 1;
965 
966 		for( i = 0; i < nLines; i++)
967 		{
968 			aPtTl.Y() = aRectSize.Height() * i / nLines + 1;
969 			aPtBr.Y() = aRectSize.Height() * (i + 1) / nLines - 1;
970 
971 			for( j = 0; j < nLines; j++)
972 			{
973 				aPtTl.X() = aRectSize.Width() * j / nLines + 1;
974 				aPtBr.X() = aRectSize.Width() * (j + 1) / nLines - 1;
975 
976 				if ( *( pPixel + i * nLines + j ) != nLastPixel )
977 				{
978 					nLastPixel = *( pPixel + i * nLines + j );
979 					// Farbe wechseln: 0 -> Hintergrundfarbe
980 					SetFillColor( nLastPixel ? aPixelColor : aBackgroundColor );
981 				}
982 				DrawRect( Rectangle( aPtTl, aPtBr ) );
983 			}
984 		}
985 	} // bPaintable
986 	else
987 	{
988 		SetBackground( Wallpaper( Color( COL_LIGHTGRAY ) ) );
989 		Control::SetLineColor( Color( COL_LIGHTRED ) );
990 		DrawLine( Point( 0, 0 ), Point( aRectSize.Width(), aRectSize.Height() ) );
991 		DrawLine( Point( 0, aRectSize.Height() ), Point( aRectSize.Width(), 0 ) );
992 	}
993 }
994 
995 /*************************************************************************
996 |*
997 |*
998 |*
999 \************************************************************************/
1000 
1001 void SvxPixelCtl::SetXBitmap( const BitmapEx& rBitmapEx )
1002 {
1003     BitmapColor aBack;
1004     BitmapColor aFront;
1005 
1006     if(isHistorical8x8(rBitmapEx, aBack, aFront))
1007     {
1008         Bitmap aBitmap(rBitmapEx.GetBitmap());
1009         BitmapReadAccess* pRead = aBitmap.AcquireReadAccess();
1010 
1011         aBackgroundColor = aBack;
1012         aPixelColor = aFront;
1013 
1014         for(sal_uInt16 i(0); i < nSquares; i++)
1015         {
1016             const BitmapColor aColor(pRead->GetColor(i/8, i%8));
1017 
1018             if(aColor == aBack)
1019             {
1020                 *( pPixel + i ) = 0;
1021             }
1022             else
1023             {
1024                 *( pPixel + i ) = 1;
1025             }
1026         }
1027 
1028         aBitmap.ReleaseAccess(pRead);
1029     }
1030 }
1031 
1032 /*************************************************************************
1033 |*
1034 |*	Gibt ein bestimmtes Pixel zurueck
1035 |*
1036 \************************************************************************/
1037 
1038 sal_uInt16 SvxPixelCtl::GetBitmapPixel( const sal_uInt16 nPixel )
1039 {
1040 	return( *( pPixel + nPixel ) );
1041 }
1042 
1043 /*************************************************************************
1044 |*
1045 |*	Bewirkt den Ursprungszustand des Controls
1046 |*
1047 \************************************************************************/
1048 
1049 void SvxPixelCtl::Reset()
1050 {
1051 	// clear pixel area
1052 	rtl_zeroMemory(pPixel, nSquares * sizeof(sal_uInt16));
1053 	Invalidate();
1054 }
1055 
1056 /*************************************************************************
1057 |*
1058 |*	Ctor: BitmapCtl fuer SvxPixelCtl
1059 |*
1060 \************************************************************************/
1061 
1062 SvxBitmapCtl::SvxBitmapCtl( Window* /*pParent*/, const Size& rSize )
1063 {
1064 	aSize = rSize;
1065 	// aVD.SetOutputSizePixel( aSize );
1066 }
1067 
1068 /*************************************************************************
1069 |*
1070 |*	Dtor
1071 |*
1072 \************************************************************************/
1073 
1074 SvxBitmapCtl::~SvxBitmapCtl()
1075 {
1076 }
1077 
1078 /*************************************************************************
1079 |*
1080 |*	BitmapCtl:	Gibt die Bitmap zurueck
1081 |*
1082 \************************************************************************/
1083 
1084 BitmapEx SvxBitmapCtl::GetBitmapEx()
1085 {
1086     const Bitmap aRetval(createHistorical8x8FromArray(pBmpArray, aPixelColor, aBackgroundColor));
1087 
1088 	return BitmapEx(aRetval);
1089 }
1090 
1091 /*************************************************************************
1092 |*
1093 |*	Fuellt die Listbox mit Farben und Strings
1094 |*
1095 \************************************************************************/
1096 
1097 void ColorLB::Fill( const XColorListSharedPtr aColorTab )
1098 {
1099 	long nCount = aColorTab->Count();
1100 	XColorEntry* pEntry;
1101 	SetUpdateMode( sal_False );
1102 
1103 	for( long i = 0; i < nCount; i++ )
1104 	{
1105         pEntry = aColorTab->GetColor( i );
1106 		InsertEntry( pEntry->GetColor(), pEntry->GetName() );
1107 	}
1108 
1109     AdaptDropDownLineCountToMaximum();
1110 	SetUpdateMode( sal_True );
1111 }
1112 
1113 /************************************************************************/
1114 
1115 void ColorLB::Append( XColorEntry* pEntry, Bitmap* )
1116 {
1117 	InsertEntry( pEntry->GetColor(), pEntry->GetName() );
1118     AdaptDropDownLineCountToMaximum();
1119 }
1120 
1121 /************************************************************************/
1122 
1123 void ColorLB::Modify( XColorEntry* pEntry, sal_uInt16 nPos, Bitmap*  )
1124 {
1125 	RemoveEntry( nPos );
1126 	InsertEntry( pEntry->GetColor(), pEntry->GetName(), nPos );
1127 }
1128 
1129 /*************************************************************************
1130 |*
1131 |*	Fuellt die Listbox mit Farben und Strings
1132 |*
1133 \************************************************************************/
1134 
1135 void FillAttrLB::Fill( const XColorListSharedPtr aColorTab )
1136 {
1137 	long nCount = aColorTab->Count();
1138 	XColorEntry* pEntry;
1139 	SetUpdateMode( sal_False );
1140 
1141 	for( long i = 0; i < nCount; i++ )
1142 	{
1143         pEntry = aColorTab->GetColor( i );
1144 		InsertEntry( pEntry->GetColor(), pEntry->GetName() );
1145 	}
1146 
1147     AdaptDropDownLineCountToMaximum();
1148     SetUpdateMode( sal_True );
1149 }
1150 
1151 /*************************************************************************
1152 |*
1153 |*	Fuellt die Listbox (vorlaeufig) mit Strings
1154 |*
1155 \************************************************************************/
1156 
1157 HatchingLB::HatchingLB( Window* pParent, ResId Id)
1158 : ListBox( pParent, Id )
1159 {
1160     SetEdgeBlending(true);
1161 }
1162 
1163 HatchingLB::HatchingLB( Window* pParent, WinBits aWB)
1164 : ListBox( pParent, aWB )
1165 {
1166     SetEdgeBlending(true);
1167 }
1168 
1169 void HatchingLB::Fill( const XHatchListSharedPtr aList )
1170 {
1171 	XHatchEntry* pEntry;
1172 	long nCount = aList.get() ? aList->Count() : 0;
1173 
1174 	SetUpdateMode( sal_False );
1175 
1176 	for( long i = 0; i < nCount; i++ )
1177 	{
1178         pEntry = aList->GetHatch( i );
1179 		const Bitmap aBitmap = aList->GetUiBitmap( i );
1180 		if( !aBitmap.IsEmpty() )
1181 			InsertEntry( pEntry->GetName(), aBitmap );
1182 		else
1183 			InsertEntry( pEntry->GetName() );
1184 	}
1185 
1186     AdaptDropDownLineCountToMaximum();
1187 	SetUpdateMode( sal_True );
1188 }
1189 
1190 /************************************************************************/
1191 
1192 void HatchingLB::Append( XHatchEntry* pEntry, Bitmap* pBmp )
1193 {
1194 	if( pBmp )
1195 		InsertEntry( pEntry->GetName(), *pBmp );
1196 	else
1197 		InsertEntry( pEntry->GetName() );
1198     AdaptDropDownLineCountToMaximum();
1199 }
1200 
1201 /************************************************************************/
1202 
1203 void HatchingLB::Modify( XHatchEntry* pEntry, sal_uInt16 nPos, Bitmap* pBmp )
1204 {
1205 	RemoveEntry( nPos );
1206 
1207 	if( pBmp )
1208 		InsertEntry( pEntry->GetName(), *pBmp, nPos );
1209 	else
1210 		InsertEntry( pEntry->GetName(), nPos );
1211 }
1212 
1213 /************************************************************************/
1214 
1215 void HatchingLB::SelectEntryByList( const XHatchListSharedPtr aList, const String& rStr, const XHatch& rHatch, sal_uInt16 nDist )
1216 {
1217 	long nCount = aList.get() ? aList->Count() : 0;
1218 	XHatchEntry* pEntry;
1219 	sal_Bool bFound = sal_False;
1220 	String aStr;
1221 
1222 	long i;
1223 	for( i = 0; i < nCount && !bFound; i++ )
1224 	{
1225         pEntry = aList->GetHatch( i );
1226 
1227 		aStr = pEntry->GetName();
1228 
1229 		if( rStr == aStr && rHatch == pEntry->GetHatch() )
1230 			bFound = sal_True;
1231 	}
1232 	if( bFound )
1233 		SelectEntryPos( (sal_uInt16) ( i - 1 + nDist ) );
1234 }
1235 
1236 /*************************************************************************
1237 |*
1238 |*	Fuellt die Listbox (vorlaeufig) mit Strings
1239 |*
1240 \************************************************************************/
1241 
1242 void FillAttrLB::Fill( const XHatchListSharedPtr aList )
1243 {
1244 	long nCount = aList.get() ? aList->Count() : 0;
1245 	XHatchEntry* pEntry;
1246 	ListBox::SetUpdateMode( sal_False );
1247 
1248 	for( long i = 0; i < nCount; i++ )
1249 	{
1250         pEntry = aList->GetHatch( i );
1251 		const Bitmap aBitmap = aList->GetUiBitmap( i );
1252 		if( !aBitmap.IsEmpty() )
1253 			ListBox::InsertEntry( pEntry->GetName(), aBitmap );
1254 		else
1255 			InsertEntry( pEntry->GetName() );
1256 	}
1257 
1258     AdaptDropDownLineCountToMaximum();
1259 	ListBox::SetUpdateMode( sal_True );
1260 }
1261 
1262 /*************************************************************************
1263 |*
1264 |*	Fuellt die Listbox (vorlaeufig) mit Strings
1265 |*
1266 \************************************************************************/
1267 
1268 GradientLB::GradientLB( Window* pParent, ResId Id)
1269 : ListBox( pParent, Id )
1270 {
1271     SetEdgeBlending(true);
1272 }
1273 
1274 GradientLB::GradientLB( Window* pParent, WinBits aWB)
1275 : ListBox( pParent, aWB )
1276 {
1277     SetEdgeBlending(true);
1278 }
1279 
1280 void GradientLB::Fill( const XGradientListSharedPtr aList )
1281 {
1282 	XGradientEntry* pEntry;
1283 	long nCount = aList.get() ? aList->Count() : 0;
1284 
1285 	SetUpdateMode( sal_False );
1286 
1287 	for( long i = 0; i < nCount; i++ )
1288 	{
1289         pEntry = aList->GetGradient( i );
1290 		const Bitmap aBitmap = aList->GetUiBitmap( i );
1291 		if( !aBitmap.IsEmpty() )
1292 			InsertEntry( pEntry->GetName(), aBitmap );
1293 		else
1294 			InsertEntry( pEntry->GetName() );
1295 	}
1296 
1297     AdaptDropDownLineCountToMaximum();
1298 	SetUpdateMode( sal_True );
1299 }
1300 
1301 /************************************************************************/
1302 
1303 void GradientLB::Append( XGradientEntry* pEntry, Bitmap* pBmp )
1304 {
1305 	if( pBmp )
1306 		InsertEntry( pEntry->GetName(), *pBmp );
1307 	else
1308 		InsertEntry( pEntry->GetName() );
1309     AdaptDropDownLineCountToMaximum();
1310 }
1311 
1312 /************************************************************************/
1313 
1314 void GradientLB::Modify( XGradientEntry* pEntry, sal_uInt16 nPos, Bitmap* pBmp )
1315 {
1316 	RemoveEntry( nPos );
1317 
1318 	if( pBmp )
1319 		InsertEntry( pEntry->GetName(), *pBmp, nPos );
1320 	else
1321 		InsertEntry( pEntry->GetName(), nPos );
1322 }
1323 
1324 /************************************************************************/
1325 
1326 void GradientLB::SelectEntryByList( const XGradientListSharedPtr aList, const String& rStr, const XGradient& rGradient, sal_uInt16 nDist )
1327 {
1328 	long nCount = aList.get() ? aList->Count() : 0;
1329 	XGradientEntry* pEntry;
1330 	sal_Bool bFound = sal_False;
1331 	String aStr;
1332 
1333 	long i;
1334 	for( i = 0; i < nCount && !bFound; i++ )
1335 	{
1336         pEntry = aList->GetGradient( i );
1337 
1338 		aStr = pEntry->GetName();
1339 
1340 		if( rStr == aStr && rGradient == pEntry->GetGradient() )
1341 			bFound = sal_True;
1342 	}
1343 	if( bFound )
1344 		SelectEntryPos( (sal_uInt16) ( i - 1 + nDist ) );
1345 }
1346 
1347 /*************************************************************************
1348 |*
1349 |*	Fuellt die Listbox (vorlaeufig) mit Strings
1350 |*
1351 \************************************************************************/
1352 
1353 void FillAttrLB::Fill( const XGradientListSharedPtr aList )
1354 {
1355 	long nCount = aList.get() ? aList->Count() : 0;
1356 	XGradientEntry* pEntry;
1357 	ListBox::SetUpdateMode( sal_False );
1358 
1359 	for( long i = 0; i < nCount; i++ )
1360 	{
1361         pEntry = aList->GetGradient( i );
1362 		const Bitmap aBitmap = aList->GetUiBitmap( i );
1363 		if( !aBitmap.IsEmpty() )
1364 			ListBox::InsertEntry( pEntry->GetName(), aBitmap );
1365 		else
1366 			InsertEntry( pEntry->GetName() );
1367 	}
1368 
1369     AdaptDropDownLineCountToMaximum();
1370 	ListBox::SetUpdateMode( sal_True );
1371 }
1372 
1373 /*************************************************************************
1374 |*
1375 |*	Konstruktor von BitmapLB
1376 |*
1377 \************************************************************************/
1378 
1379 BitmapLB::BitmapLB(Window* pParent, ResId Id)
1380 :   ListBox(pParent, Id),
1381     maBitmapEx()
1382 {
1383     SetEdgeBlending(true);
1384 }
1385 
1386 /************************************************************************/
1387 
1388 namespace
1389 {
1390     void formatBitmapExToSize(BitmapEx& rBitmapEx, const Size& rSize)
1391     {
1392         if(!rBitmapEx.IsEmpty() && rSize.Width() > 0 && rSize.Height() > 0)
1393         {
1394             VirtualDevice aVirtualDevice;
1395             aVirtualDevice.SetOutputSizePixel(rSize);
1396 
1397             if(rBitmapEx.IsTransparent())
1398             {
1399                 const Point aNull(0, 0);
1400                 static const sal_uInt32 nLen(8);
1401                 static const Color aW(COL_WHITE);
1402                 static const Color aG(0xef, 0xef, 0xef);
1403 
1404                 aVirtualDevice.DrawCheckered(aNull, rSize, nLen, aW, aG);
1405             }
1406 
1407             if(rBitmapEx.GetSizePixel().Width() >= rSize.Width() && rBitmapEx.GetSizePixel().Height() >= rSize.Height())
1408             {
1409                 static sal_uInt32 nScaleFlag(BMP_SCALE_FASTESTINTERPOLATE);
1410 
1411                 rBitmapEx.Scale(rSize, nScaleFlag);
1412                 aVirtualDevice.DrawBitmapEx(Point(0, 0), rBitmapEx);
1413             }
1414             else
1415             {
1416                 const Size aBitmapSize(rBitmapEx.GetSizePixel());
1417 
1418                 for(sal_Int32 y(0); y < rSize.Height(); y += aBitmapSize.Height())
1419                 {
1420                     for(sal_Int32 x(0); x < rSize.Width(); x += aBitmapSize.Width())
1421                     {
1422                         aVirtualDevice.DrawBitmapEx(
1423                             Point(x, y),
1424                             rBitmapEx);
1425                     }
1426                 }
1427             }
1428 
1429             rBitmapEx = aVirtualDevice.GetBitmap(Point(0, 0), rSize);
1430         }
1431     }
1432 } // end of anonymous namespace
1433 
1434 /************************************************************************/
1435 
1436 void BitmapLB::Fill(const XBitmapListSharedPtr aList)
1437 {
1438 	XBitmapEntry* pEntry;
1439 	const long nCount(aList.get() ? aList->Count() : 0);
1440     const StyleSettings& rStyleSettings = Application::GetSettings().GetStyleSettings();
1441     const Size aSize(rStyleSettings.GetListBoxPreviewDefaultPixelSize());
1442 
1443 	SetUpdateMode(false);
1444 
1445 	for(long i(0); i < nCount; i++)
1446 	{
1447         pEntry = aList->GetBitmap(i);
1448         maBitmapEx = pEntry->GetGraphicObject().GetGraphic().GetBitmapEx();
1449         formatBitmapExToSize(maBitmapEx, aSize);
1450         InsertEntry(pEntry->GetName(), maBitmapEx);
1451 	}
1452 
1453     AdaptDropDownLineCountToMaximum();
1454 	SetUpdateMode(true);
1455 }
1456 
1457 /************************************************************************/
1458 
1459 void BitmapLB::Append(const Size& rSize, const XBitmapEntry& rEntry, BitmapEx* pBmpEx)
1460 {
1461 	if(pBmpEx)
1462 	{
1463 		maBitmapEx = rEntry.GetGraphicObject().GetGraphic().GetBitmapEx();
1464         formatBitmapExToSize(maBitmapEx, rSize);
1465 		InsertEntry(rEntry.GetName(), maBitmapEx);
1466 	}
1467 	else
1468     {
1469 		InsertEntry(rEntry.GetName());
1470     }
1471 
1472     AdaptDropDownLineCountToMaximum();
1473 }
1474 
1475 /************************************************************************/
1476 
1477 void BitmapLB::Modify(const Size& rSize, const XBitmapEntry& rEntry, sal_uInt16 nPos, BitmapEx* pBmpEx)
1478 {
1479 	RemoveEntry(nPos);
1480 
1481 	if(pBmpEx)
1482 	{
1483 		maBitmapEx = rEntry.GetGraphicObject().GetGraphic().GetBitmapEx();
1484         formatBitmapExToSize(maBitmapEx, rSize);
1485 		InsertEntry(rEntry.GetName(), maBitmapEx, nPos);
1486 	}
1487 	else
1488     {
1489 		InsertEntry(rEntry.GetName());
1490     }
1491 }
1492 
1493 /************************************************************************/
1494 
1495 void BitmapLB::SelectEntryByList(const XBitmapListSharedPtr aList, const String& rStr)
1496 {
1497 	const long nCount(aList.get() ? aList->Count() : 0);
1498 	XBitmapEntry* pEntry;
1499 	bool bFound(false);
1500     long i(0);
1501 
1502 	for(i = 0; i < nCount && !bFound; i++)
1503 	{
1504         pEntry = aList->GetBitmap(i);
1505 		const String aStr(pEntry->GetName());
1506 
1507 		if(rStr == aStr)
1508 		{
1509 			bFound = true;
1510 		}
1511 	}
1512 
1513     if(bFound)
1514     {
1515 		SelectEntryPos((sal_uInt16)(i - 1));
1516     }
1517 }
1518 
1519 /*************************************************************************
1520 |*
1521 |*	Konstruktor von FillAttrLB
1522 |*
1523 \************************************************************************/
1524 
1525 FillAttrLB::FillAttrLB( Window* pParent, ResId Id )
1526 :   ColorListBox(pParent, Id),
1527     maBitmapEx()
1528 {
1529 }
1530 
1531 /************************************************************************/
1532 
1533 FillAttrLB::FillAttrLB(Window* pParent, WinBits aWB)
1534 :   ColorListBox(pParent, aWB)
1535 {
1536 }
1537 
1538 /************************************************************************/
1539 
1540 void FillAttrLB::Fill(const XBitmapListSharedPtr aList)
1541 {
1542 	const long nCount(aList.get() ? aList->Count() : 0);
1543 	XBitmapEntry* pEntry;
1544     const StyleSettings& rStyleSettings = Application::GetSettings().GetStyleSettings();
1545     const Size aSize(rStyleSettings.GetListBoxPreviewDefaultPixelSize());
1546 
1547     ListBox::SetUpdateMode(false);
1548 
1549 	for(long i(0); i < nCount; i++)
1550 	{
1551         pEntry = aList->GetBitmap( i );
1552 		maBitmapEx = pEntry->GetGraphicObject().GetGraphic().GetBitmapEx();
1553         formatBitmapExToSize(maBitmapEx, aSize);
1554 		ListBox::InsertEntry(pEntry->GetName(), maBitmapEx);
1555 	}
1556 
1557     AdaptDropDownLineCountToMaximum();
1558     ListBox::SetUpdateMode(true);
1559 }
1560 
1561 /************************************************************************/
1562 
1563 void FillAttrLB::SelectEntryByList( const XBitmapListSharedPtr aList, const String& rStr)
1564 {
1565 	const long nCount(aList.get() ? aList->Count() : 0);
1566 	XBitmapEntry* pEntry;
1567 	bool bFound(false);
1568 	long i(0);
1569 
1570     for(i = 0; i < nCount && !bFound; i++)
1571 	{
1572         pEntry = aList->GetBitmap(i);
1573 		const String aStr(pEntry->GetName());
1574 
1575 		if(rStr == aStr)
1576 		{
1577 			bFound = true;
1578 		}
1579 	}
1580 
1581     if(bFound)
1582     {
1583 		SelectEntryPos((sal_uInt16)(i - 1));
1584     }
1585 }
1586 
1587 /*************************************************************************
1588 |*
1589 |*	Fuellt die Listbox (vorlaeufig) mit Strings
1590 |*
1591 \************************************************************************/
1592 
1593 void FillTypeLB::Fill()
1594 {
1595 	SetUpdateMode( sal_False );
1596 
1597     InsertEntry( String( SVX_RES( RID_SVXSTR_INVISIBLE ) ) );
1598 	InsertEntry( String( SVX_RES( RID_SVXSTR_COLOR ) ) );
1599 	InsertEntry( String( SVX_RES( RID_SVXSTR_GRADIENT ) ) );
1600 	InsertEntry( String( SVX_RES( RID_SVXSTR_HATCH ) ) );
1601 	InsertEntry( String( SVX_RES( RID_SVXSTR_BITMAP ) ) );
1602 
1603     AdaptDropDownLineCountToMaximum();
1604 	SetUpdateMode( sal_True );
1605 }
1606 
1607 /*************************************************************************
1608 |*
1609 |*	Fuellt die Listbox (vorlaeufig) mit Strings
1610 |*
1611 \************************************************************************/
1612 LineLB::LineLB(Window* pParent, ResId Id)
1613 :   ListBox(pParent, Id),
1614     mbAddStandardFields(true)
1615 {
1616     // No EdgeBlending for LineStyle/Dash SetEdgeBlending(true);
1617 }
1618 
1619 LineLB::LineLB(Window* pParent, WinBits aWB)
1620 :   ListBox(pParent, aWB),
1621     mbAddStandardFields(true)
1622 {
1623     // No EdgeBlending for LineStyle/Dash SetEdgeBlending(true);
1624 }
1625 
1626 LineLB::~LineLB()
1627 {
1628 }
1629 
1630 void LineLB::setAddStandardFields(bool bNew)
1631 {
1632     if(getAddStandardFields() != bNew)
1633     {
1634         mbAddStandardFields = bNew;
1635     }
1636 }
1637 
1638 void LineLB::Fill( const XDashListSharedPtr aList )
1639 {
1640 	Clear();
1641 
1642     if(getAddStandardFields() && aList.get())
1643     {
1644         // entry for 'none'
1645         InsertEntry(aList->GetStringForUiNoLine());
1646 
1647         // entry for solid line
1648         InsertEntry(aList->GetStringForUiSolidLine(), aList->GetBitmapForUISolidLine());
1649     }
1650 
1651     // entries for dashed lines
1652 	long nCount = aList.get() ? aList->Count() : 0;
1653 	XDashEntry* pEntry;
1654 	SetUpdateMode( sal_False );
1655 
1656 	for( long i = 0; i < nCount; i++ )
1657 	{
1658         pEntry = aList->GetDash( i );
1659 		const Bitmap aBitmap = aList->GetUiBitmap( i );
1660 		if( !aBitmap.IsEmpty() )
1661 		{
1662 			InsertEntry( pEntry->GetName(), aBitmap );
1663 			//delete pBitmap;
1664 		}
1665 		else
1666 			InsertEntry( pEntry->GetName() );
1667 	}
1668 
1669     AdaptDropDownLineCountToMaximum();
1670 	SetUpdateMode( sal_True );
1671 }
1672 
1673 /************************************************************************/
1674 
1675 void LineLB::Append( XDashEntry* pEntry, const Bitmap* pBmp )
1676 {
1677 	if( pBmp )
1678 		InsertEntry( pEntry->GetName(), *pBmp );
1679 	else
1680 		InsertEntry( pEntry->GetName() );
1681     AdaptDropDownLineCountToMaximum();
1682 }
1683 
1684 /************************************************************************/
1685 
1686 void LineLB::Modify( XDashEntry* pEntry, sal_uInt16 nPos, const Bitmap* pBmp )
1687 {
1688 	RemoveEntry( nPos );
1689 
1690 	if( pBmp )
1691 		InsertEntry( pEntry->GetName(), *pBmp, nPos );
1692 	else
1693 		InsertEntry( pEntry->GetName(), nPos );
1694 }
1695 
1696 /************************************************************************/
1697 
1698 void LineLB::SelectEntryByList( const XDashListSharedPtr aList, const String& rStr, const XDash& rDash, sal_uInt16 nDist )
1699 {
1700 	long nCount = aList.get() ? aList->Count() : 0;
1701 	XDashEntry* pEntry;
1702 	sal_Bool bFound = sal_False;
1703 	String aStr;
1704 	XDash aDash;
1705 
1706 	long i;
1707 	for( i = 0; i < nCount && !bFound; i++ )
1708 	{
1709         pEntry = aList->GetDash( i );
1710 
1711 		aStr = pEntry->GetName();
1712 		aDash = pEntry->GetDash();
1713 
1714 		if( rStr == aStr && rDash == aDash )
1715 			bFound = sal_True;
1716 	}
1717 	if( bFound )
1718 		SelectEntryPos( (sal_uInt16) ( i - 1 + nDist ) );
1719 }
1720 
1721 /*************************************************************************
1722 |*
1723 |*	Fuellt die Listbox (vorlaeufig) mit Strings
1724 |*
1725 \************************************************************************/
1726 LineEndLB::LineEndLB( Window* pParent, ResId Id )
1727     : ListBox( pParent, Id )
1728 {
1729     // No EdgeBlending for LineEnds SetEdgeBlending(true);
1730 }
1731 
1732 LineEndLB::LineEndLB( Window* pParent, WinBits aWB )
1733     : ListBox( pParent, aWB )
1734 {
1735     // No EdgeBlending for LineEnds SetEdgeBlending(true);
1736 }
1737 
1738 LineEndLB::~LineEndLB(void)
1739 {
1740 }
1741 
1742 
1743 void LineEndLB::Fill( const XLineEndListSharedPtr aList, sal_Bool bStart )
1744 {
1745 	long nCount = aList.get() ? aList->Count() : 0;
1746 	XLineEndEntry* pEntry;
1747 	VirtualDevice aVD;
1748 	SetUpdateMode( sal_False );
1749 
1750 	for( long i = 0; i < nCount; i++ )
1751 	{
1752         pEntry = aList->GetLineEnd( i );
1753 		const Bitmap aBitmap = aList->GetUiBitmap( i );
1754 		if( !aBitmap.IsEmpty() )
1755 		{
1756 			Size aBmpSize( aBitmap.GetSizePixel() );
1757 			aVD.SetOutputSizePixel( aBmpSize, sal_False );
1758 			aVD.DrawBitmap( Point(), aBitmap );
1759 			InsertEntry( pEntry->GetName(),
1760 				aVD.GetBitmap( bStart ? Point() : Point( aBmpSize.Width() / 2, 0 ),
1761 					Size( aBmpSize.Width() / 2, aBmpSize.Height() ) ) );
1762 			//delete pBitmap;
1763 		}
1764 		else
1765 			InsertEntry( pEntry->GetName() );
1766 	}
1767 
1768     AdaptDropDownLineCountToMaximum();
1769 	SetUpdateMode( sal_True );
1770 }
1771 
1772 /************************************************************************/
1773 
1774 void LineEndLB::Append( XLineEndEntry* pEntry, const Bitmap* pBmp, sal_Bool bStart )
1775 {
1776 	if( pBmp )
1777 	{
1778 		VirtualDevice aVD;
1779 		Size aBmpSize( pBmp->GetSizePixel() );
1780 
1781 		aVD.SetOutputSizePixel( aBmpSize, sal_False );
1782 		aVD.DrawBitmap( Point(), *pBmp );
1783 		InsertEntry( pEntry->GetName(),
1784 			aVD.GetBitmap( bStart ? Point() : Point( aBmpSize.Width() / 2, 0 ),
1785 				Size( aBmpSize.Width() / 2, aBmpSize.Height() ) ) );
1786 	}
1787 	else
1788 		InsertEntry( pEntry->GetName() );
1789     AdaptDropDownLineCountToMaximum();
1790 }
1791 
1792 /************************************************************************/
1793 
1794 void LineEndLB::Modify( XLineEndEntry* pEntry, sal_uInt16 nPos, const Bitmap* pBmp, sal_Bool bStart )
1795 {
1796 	RemoveEntry( nPos );
1797 
1798 	if( pBmp )
1799 	{
1800 		VirtualDevice aVD;
1801 		Size aBmpSize( pBmp->GetSizePixel() );
1802 
1803 		aVD.SetOutputSizePixel( aBmpSize, sal_False );
1804 		aVD.DrawBitmap( Point(), *pBmp );
1805 		InsertEntry( pEntry->GetName(),
1806 			aVD.GetBitmap( bStart ? Point() : Point( aBmpSize.Width() / 2, 0 ),
1807 				Size( aBmpSize.Width() / 2, aBmpSize.Height() ) ), nPos );
1808 	}
1809 	else
1810 		InsertEntry( pEntry->GetName(), nPos );
1811 }
1812 
1813 //////////////////////////////////////////////////////////////////////////////
1814 
1815 void SvxPreviewBase::InitSettings(bool bForeground, bool bBackground)
1816 {
1817 	const StyleSettings& rStyleSettings = Application::GetSettings().GetStyleSettings();
1818 
1819 	if(bForeground)
1820 	{
1821 		svtools::ColorConfig aColorConfig;
1822 		Color aTextColor(aColorConfig.GetColorValue(svtools::FONTCOLOR).nColor);
1823 
1824 		if(IsControlForeground())
1825         {
1826 			aTextColor = GetControlForeground();
1827         }
1828 
1829 		getBufferDevice().SetTextColor(aTextColor);
1830 	}
1831 
1832 	if(bBackground)
1833 	{
1834 		if(IsControlBackground())
1835         {
1836 			getBufferDevice().SetBackground(GetControlBackground());
1837         }
1838 		else
1839         {
1840 			getBufferDevice().SetBackground(rStyleSettings.GetWindowColor());
1841         }
1842 	}
1843 
1844     // do not paint background self, it gets painted buffered
1845 	SetControlBackground();
1846     SetBackground();
1847 
1848     Invalidate();
1849 }
1850 
1851 SvxPreviewBase::SvxPreviewBase( Window* pParent, const ResId& rResId )
1852 :	Control( pParent, rResId ),
1853 	mpModel( new SdrModel() ),
1854     mpBufferDevice( new VirtualDevice(*this) )
1855 {
1856 	//	Draw the control's border as a flat thin black line.
1857     SetBorderStyle(WINDOW_BORDER_MONO);
1858     SetDrawMode( GetSettings().GetStyleSettings().GetHighContrastMode() ? OUTPUT_DRAWMODE_CONTRAST : OUTPUT_DRAWMODE_COLOR );
1859     SetMapMode(MAP_100TH_MM);
1860 
1861     // init model
1862 	mpModel->GetItemPool().FreezeIdRanges();
1863 }
1864 
1865 SvxPreviewBase::~SvxPreviewBase()
1866 {
1867 	delete mpModel;
1868     delete mpBufferDevice;
1869 }
1870 
1871 void SvxPreviewBase::LocalPrePaint()
1872 {
1873     // init BufferDevice
1874     if(mpBufferDevice->GetOutputSizePixel() != GetOutputSizePixel())
1875     {
1876         mpBufferDevice->SetDrawMode(GetDrawMode());
1877         mpBufferDevice->SetSettings(GetSettings());
1878         mpBufferDevice->SetAntialiasing(GetAntialiasing());
1879         mpBufferDevice->SetOutputSizePixel(GetOutputSizePixel());
1880 	    mpBufferDevice->SetMapMode(GetMapMode());
1881     }
1882 
1883     mpBufferDevice->Erase();
1884 }
1885 
1886 void SvxPreviewBase::LocalPostPaint()
1887 {
1888     // copy to front (in pixel mode)
1889 	const bool bWasEnabledSrc(mpBufferDevice->IsMapModeEnabled());
1890 	const bool bWasEnabledDst(IsMapModeEnabled());
1891 	const Point aEmptyPoint;
1892 
1893     mpBufferDevice->EnableMapMode(false);
1894     EnableMapMode(false);
1895 
1896     DrawOutDev(
1897         aEmptyPoint, GetOutputSizePixel(),
1898         aEmptyPoint, GetOutputSizePixel(),
1899         *mpBufferDevice);
1900 
1901     mpBufferDevice->EnableMapMode(bWasEnabledSrc);
1902     EnableMapMode(bWasEnabledDst);
1903 }
1904 
1905 void SvxPreviewBase::StateChanged(StateChangedType nType)
1906 {
1907 	Control::StateChanged(nType);
1908 
1909     if(STATE_CHANGE_CONTROLFOREGROUND == nType)
1910     {
1911 		InitSettings(true, false);
1912     }
1913 	else if(STATE_CHANGE_CONTROLBACKGROUND == nType)
1914     {
1915 		InitSettings(false, true);
1916     }
1917 }
1918 
1919 void SvxPreviewBase::DataChanged(const DataChangedEvent& rDCEvt)
1920 {
1921     SetDrawMode(GetSettings().GetStyleSettings().GetHighContrastMode() ? OUTPUT_DRAWMODE_CONTRAST : OUTPUT_DRAWMODE_COLOR);
1922 
1923     if((DATACHANGED_SETTINGS == rDCEvt.GetType()) && (rDCEvt.GetFlags() & SETTINGS_STYLE))
1924     {
1925 		InitSettings(true, true);
1926     }
1927 	else
1928     {
1929 		Control::DataChanged(rDCEvt);
1930     }
1931 }
1932 
1933 /*************************************************************************
1934 |*
1935 |*    SvxXLinePreview::SvxXLinePreview()
1936 |*
1937 *************************************************************************/
1938 
1939 SvxXLinePreview::SvxXLinePreview( Window* pParent, const ResId& rResId )
1940 :	SvxPreviewBase( pParent, rResId ),
1941 	mpLineObjA( 0L ),
1942 	mpLineObjB( 0L ),
1943 	mpLineObjC( 0L ),
1944 	mpGraphic( 0L ),
1945 	mbWithSymbol( sal_False )
1946 {
1947 	const Size aOutputSize(GetOutputSize());
1948 	InitSettings( sal_True, sal_True );
1949 
1950 	const sal_Int32 nDistance(500L);
1951 	const sal_Int32 nAvailableLength(aOutputSize.Width() - (4 * nDistance));
1952 
1953 	// create DrawObectA
1954 	const sal_Int32 aYPosA(aOutputSize.Height() / 2);
1955 	const basegfx::B2DPoint aPointA1( nDistance,  aYPosA);
1956 	const basegfx::B2DPoint aPointA2( aPointA1.getX() + ((nAvailableLength * 14) / 20), aYPosA );
1957 	basegfx::B2DPolygon aPolygonA;
1958 	aPolygonA.append(aPointA1);
1959 	aPolygonA.append(aPointA2);
1960 	mpLineObjA = new SdrPathObj(OBJ_LINE, basegfx::B2DPolyPolygon(aPolygonA));
1961 	mpLineObjA->SetModel(&getModel());
1962 
1963 	// create DrawObectB
1964 	const sal_Int32 aYPosB1((aOutputSize.Height() * 3) / 4);
1965 	const sal_Int32 aYPosB2((aOutputSize.Height() * 1) / 4);
1966 	const basegfx::B2DPoint aPointB1( aPointA2.getX() + nDistance,  aYPosB1);
1967 	const basegfx::B2DPoint aPointB2( aPointB1.getX() + ((nAvailableLength * 2) / 20), aYPosB2 );
1968 	const basegfx::B2DPoint aPointB3( aPointB2.getX() + ((nAvailableLength * 2) / 20), aYPosB1 );
1969 	basegfx::B2DPolygon aPolygonB;
1970 	aPolygonB.append(aPointB1);
1971 	aPolygonB.append(aPointB2);
1972 	aPolygonB.append(aPointB3);
1973 	mpLineObjB = new SdrPathObj(OBJ_PLIN, basegfx::B2DPolyPolygon(aPolygonB));
1974 	mpLineObjB->SetModel(&getModel());
1975 
1976 	// create DrawObectC
1977 	const basegfx::B2DPoint aPointC1( aPointB3.getX() + nDistance,  aYPosB1);
1978 	const basegfx::B2DPoint aPointC2( aPointC1.getX() + ((nAvailableLength * 1) / 20), aYPosB2 );
1979 	const basegfx::B2DPoint aPointC3( aPointC2.getX() + ((nAvailableLength * 1) / 20), aYPosB1 );
1980 	basegfx::B2DPolygon aPolygonC;
1981 	aPolygonC.append(aPointC1);
1982 	aPolygonC.append(aPointC2);
1983 	aPolygonC.append(aPointC3);
1984 	mpLineObjC = new SdrPathObj(OBJ_PLIN, basegfx::B2DPolyPolygon(aPolygonC));
1985 	mpLineObjC->SetModel(&getModel());
1986 }
1987 
1988 SvxXLinePreview::~SvxXLinePreview()
1989 {
1990     SdrObject::Free( mpLineObjA );
1991     SdrObject::Free( mpLineObjB );
1992     SdrObject::Free( mpLineObjC );
1993 }
1994 
1995 // -----------------------------------------------------------------------
1996 
1997 void SvxXLinePreview::SetSymbol(Graphic* p,const Size& s)
1998 {
1999 	mpGraphic = p;
2000 	maSymbolSize = s;
2001 }
2002 
2003 // -----------------------------------------------------------------------
2004 
2005 void SvxXLinePreview::ResizeSymbol(const Size& s)
2006 {
2007 	if ( s != maSymbolSize )
2008 	{
2009 		maSymbolSize = s;
2010 		Invalidate();
2011 	}
2012 }
2013 
2014 // -----------------------------------------------------------------------
2015 
2016 void SvxXLinePreview::SetLineAttributes(const SfxItemSet& rItemSet)
2017 {
2018 	// Set ItemSet at objects
2019 	mpLineObjA->SetMergedItemSet(rItemSet);
2020 
2021 	// At line joints, do not use arrows
2022 	SfxItemSet aTempSet(rItemSet);
2023 	aTempSet.ClearItem(XATTR_LINESTART);
2024 	aTempSet.ClearItem(XATTR_LINEEND);
2025 
2026 	mpLineObjB->SetMergedItemSet(aTempSet);
2027 	mpLineObjC->SetMergedItemSet(aTempSet);
2028 }
2029 
2030 // -----------------------------------------------------------------------
2031 
2032 void SvxXLinePreview::Paint( const Rectangle& )
2033 {
2034 	LocalPrePaint();
2035 
2036 	// paint objects to buffer device
2037 	sdr::contact::SdrObjectVector aObjectVector;
2038 	aObjectVector.push_back(mpLineObjA);
2039 	aObjectVector.push_back(mpLineObjB);
2040 	aObjectVector.push_back(mpLineObjC);
2041 
2042 	sdr::contact::ObjectContactOfObjListPainter aPainter(getBufferDevice(), aObjectVector, 0);
2043 	sdr::contact::DisplayInfo aDisplayInfo;
2044 
2045 	// do processing
2046 	aPainter.ProcessDisplay(aDisplayInfo);
2047 
2048 	if ( mbWithSymbol && mpGraphic )
2049 	{
2050     	const Size aOutputSize(GetOutputSize());
2051 		Point aPos = Point( aOutputSize.Width() / 3, aOutputSize.Height() / 2 );
2052 		aPos.X() -= maSymbolSize.Width() / 2;
2053 		aPos.Y() -= maSymbolSize.Height() / 2;
2054 		mpGraphic->Draw( &getBufferDevice(), aPos, maSymbolSize );
2055 	}
2056 
2057 	LocalPostPaint();
2058 }
2059 
2060 /*************************************************************************
2061 |*
2062 |*    SvxXRectPreview::SvxXRectPreview()
2063 |*
2064 *************************************************************************/
2065 
2066 SvxXRectPreview::SvxXRectPreview( Window* pParent, const ResId& rResId )
2067 :	SvxPreviewBase( pParent, rResId ),
2068 	mpRectangleObject(0)
2069 {
2070 	InitSettings(true, true);
2071 
2072 	// create RectangleObject
2073     const Rectangle aObjectSize(Point(), GetOutputSize());
2074 	mpRectangleObject = new SdrRectObj(aObjectSize);
2075 	mpRectangleObject->SetModel(&getModel());
2076 }
2077 
2078 SvxXRectPreview::~SvxXRectPreview()
2079 {
2080     SdrObject::Free(mpRectangleObject);
2081 }
2082 
2083 void SvxXRectPreview::SetAttributes(const SfxItemSet& rItemSet)
2084 {
2085 	mpRectangleObject->SetMergedItemSet(rItemSet, true);
2086 	mpRectangleObject->SetMergedItem(XLineStyleItem(XLINE_NONE));
2087 }
2088 
2089 void SvxXRectPreview::Paint( const Rectangle& )
2090 {
2091 	LocalPrePaint();
2092 
2093     sdr::contact::SdrObjectVector aObjectVector;
2094 
2095     aObjectVector.push_back(mpRectangleObject);
2096 
2097     sdr::contact::ObjectContactOfObjListPainter aPainter(getBufferDevice(), aObjectVector, 0);
2098 	sdr::contact::DisplayInfo aDisplayInfo;
2099 
2100 	aPainter.ProcessDisplay(aDisplayInfo);
2101 
2102     LocalPostPaint();
2103 }
2104 
2105 /*************************************************************************
2106 |*
2107 |*    SvxXShadowPreview::SvxXShadowPreview()
2108 |*
2109 *************************************************************************/
2110 
2111 SvxXShadowPreview::SvxXShadowPreview( Window* pParent, const ResId& rResId )
2112 :	SvxPreviewBase( pParent, rResId ),
2113 	mpRectangleObject(0),
2114     mpRectangleShadow(0)
2115 {
2116 	InitSettings(true, true);
2117 
2118     // prepare size
2119 	Size aSize = GetOutputSize();
2120 	aSize.Width() = aSize.Width() / 3;
2121 	aSize.Height() = aSize.Height() / 3;
2122 
2123     // create RectangleObject
2124     const Rectangle aObjectSize( Point( aSize.Width(), aSize.Height() ), aSize );
2125 	mpRectangleObject = new SdrRectObj(aObjectSize);
2126 	mpRectangleObject->SetModel(&getModel());
2127 
2128     // create ShadowObject
2129     const Rectangle aShadowSize( Point( aSize.Width(), aSize.Height() ), aSize );
2130 	mpRectangleShadow = new SdrRectObj(aShadowSize);
2131 	mpRectangleShadow->SetModel(&getModel());
2132 }
2133 
2134 SvxXShadowPreview::~SvxXShadowPreview()
2135 {
2136     SdrObject::Free(mpRectangleObject);
2137     SdrObject::Free(mpRectangleShadow);
2138 }
2139 
2140 void SvxXShadowPreview::SetRectangleAttributes(const SfxItemSet& rItemSet)
2141 {
2142 	mpRectangleObject->SetMergedItemSet(rItemSet, true);
2143 	mpRectangleObject->SetMergedItem(XLineStyleItem(XLINE_NONE));
2144 }
2145 
2146 void SvxXShadowPreview::SetShadowAttributes(const SfxItemSet& rItemSet)
2147 {
2148 	mpRectangleShadow->SetMergedItemSet(rItemSet, true);
2149 	mpRectangleShadow->SetMergedItem(XLineStyleItem(XLINE_NONE));
2150 }
2151 
2152 void SvxXShadowPreview::SetShadowPosition(const Point& rPos)
2153 {
2154     Rectangle aObjectPosition(mpRectangleObject->GetSnapRect());
2155     aObjectPosition.Move(rPos.X(), rPos.Y());
2156     mpRectangleShadow->SetSnapRect(aObjectPosition);
2157 }
2158 
2159 void SvxXShadowPreview::Paint( const Rectangle& )
2160 {
2161 	LocalPrePaint();
2162 
2163     sdr::contact::SdrObjectVector aObjectVector;
2164 
2165     aObjectVector.push_back(mpRectangleShadow);
2166 	aObjectVector.push_back(mpRectangleObject);
2167 
2168     sdr::contact::ObjectContactOfObjListPainter aPainter(getBufferDevice(), aObjectVector, 0);
2169 	sdr::contact::DisplayInfo aDisplayInfo;
2170 
2171 	aPainter.ProcessDisplay(aDisplayInfo);
2172 
2173     LocalPostPaint();
2174 }
2175 
2176 // -----------------------------------------------------------------------
2177 // eof
2178