xref: /aoo42x/main/svx/source/dialog/dlgctrl.cxx (revision 3e407bd8)
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( const XColorEntry& rEntry )
1116 {
1117     InsertEntry( rEntry.GetColor(), rEntry.GetName() );
1118     AdaptDropDownLineCountToMaximum();
1119 }
1120 
1121 /************************************************************************/
1122 
1123 void ColorLB::Modify( const XColorEntry& rEntry, sal_uInt16 nPos )
1124 {
1125     RemoveEntry( nPos );
1126     InsertEntry( rEntry.GetColor(), rEntry.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( const XHatchEntry& rEntry, const Bitmap& rBitmap )
1193 {
1194     if(!rBitmap.IsEmpty())
1195     {
1196         InsertEntry( rEntry.GetName(), rBitmap );
1197     }
1198     else
1199     {
1200         InsertEntry( rEntry.GetName() );
1201     }
1202 
1203     AdaptDropDownLineCountToMaximum();
1204 }
1205 
1206 /************************************************************************/
1207 
1208 void HatchingLB::Modify( const XHatchEntry& rEntry, sal_uInt16 nPos, const Bitmap& rBitmap )
1209 {
1210     RemoveEntry( nPos );
1211 
1212     if( !rBitmap.IsEmpty() )
1213     {
1214         InsertEntry( rEntry.GetName(), rBitmap, nPos );
1215     }
1216     else
1217     {
1218         InsertEntry( rEntry.GetName(), nPos );
1219     }
1220 }
1221 
1222 /************************************************************************/
1223 
1224 void HatchingLB::SelectEntryByList( const XHatchListSharedPtr aList, const String& rStr, const XHatch& rHatch, sal_uInt16 nDist )
1225 {
1226 	long nCount = aList.get() ? aList->Count() : 0;
1227 	XHatchEntry* pEntry;
1228 	sal_Bool bFound = sal_False;
1229 	String aStr;
1230 
1231 	long i;
1232 	for( i = 0; i < nCount && !bFound; i++ )
1233 	{
1234         pEntry = aList->GetHatch( i );
1235 
1236 		aStr = pEntry->GetName();
1237 
1238 		if( rStr == aStr && rHatch == pEntry->GetHatch() )
1239 			bFound = sal_True;
1240 	}
1241 	if( bFound )
1242 		SelectEntryPos( (sal_uInt16) ( i - 1 + nDist ) );
1243 }
1244 
1245 /*************************************************************************
1246 |*
1247 |*	Fuellt die Listbox (vorlaeufig) mit Strings
1248 |*
1249 \************************************************************************/
1250 
1251 void FillAttrLB::Fill( const XHatchListSharedPtr aList )
1252 {
1253 	long nCount = aList.get() ? aList->Count() : 0;
1254 	XHatchEntry* pEntry;
1255 	ListBox::SetUpdateMode( sal_False );
1256 
1257 	for( long i = 0; i < nCount; i++ )
1258 	{
1259         pEntry = aList->GetHatch( i );
1260 		const Bitmap aBitmap = aList->GetUiBitmap( i );
1261 		if( !aBitmap.IsEmpty() )
1262 			ListBox::InsertEntry( pEntry->GetName(), aBitmap );
1263 		else
1264 			InsertEntry( pEntry->GetName() );
1265 	}
1266 
1267     AdaptDropDownLineCountToMaximum();
1268 	ListBox::SetUpdateMode( sal_True );
1269 }
1270 
1271 /*************************************************************************
1272 |*
1273 |*	Fuellt die Listbox (vorlaeufig) mit Strings
1274 |*
1275 \************************************************************************/
1276 
1277 GradientLB::GradientLB( Window* pParent, ResId Id)
1278 : ListBox( pParent, Id )
1279 {
1280     SetEdgeBlending(true);
1281 }
1282 
1283 GradientLB::GradientLB( Window* pParent, WinBits aWB)
1284 : ListBox( pParent, aWB )
1285 {
1286     SetEdgeBlending(true);
1287 }
1288 
1289 void GradientLB::Fill( const XGradientListSharedPtr aList )
1290 {
1291 	XGradientEntry* pEntry;
1292 	long nCount = aList.get() ? aList->Count() : 0;
1293 
1294 	SetUpdateMode( sal_False );
1295 
1296 	for( long i = 0; i < nCount; i++ )
1297 	{
1298         pEntry = aList->GetGradient( i );
1299 		const Bitmap aBitmap = aList->GetUiBitmap( i );
1300 		if( !aBitmap.IsEmpty() )
1301 			InsertEntry( pEntry->GetName(), aBitmap );
1302 		else
1303 			InsertEntry( pEntry->GetName() );
1304 	}
1305 
1306     AdaptDropDownLineCountToMaximum();
1307 	SetUpdateMode( sal_True );
1308 }
1309 
1310 /************************************************************************/
1311 
1312 void GradientLB::Append( const XGradientEntry& rEntry, const Bitmap& rBitmap )
1313 {
1314     if(!rBitmap.IsEmpty())
1315     {
1316         InsertEntry( rEntry.GetName(), rBitmap );
1317     }
1318     else
1319     {
1320         InsertEntry( rEntry.GetName() );
1321     }
1322 
1323     AdaptDropDownLineCountToMaximum();
1324 }
1325 
1326 /************************************************************************/
1327 
1328 void GradientLB::Modify( const XGradientEntry& rEntry, sal_uInt16 nPos, const Bitmap& rBitmap )
1329 {
1330     RemoveEntry( nPos );
1331 
1332     if(!rBitmap.IsEmpty())
1333     {
1334         InsertEntry( rEntry.GetName(), rBitmap, nPos );
1335     }
1336     else
1337     {
1338         InsertEntry( rEntry.GetName(), nPos );
1339     }
1340 }
1341 
1342 /************************************************************************/
1343 
1344 void GradientLB::SelectEntryByList( const XGradientListSharedPtr aList, const String& rStr, const XGradient& rGradient, sal_uInt16 nDist )
1345 {
1346 	long nCount = aList.get() ? aList->Count() : 0;
1347 	XGradientEntry* pEntry;
1348 	sal_Bool bFound = sal_False;
1349 	String aStr;
1350 
1351 	long i;
1352 	for( i = 0; i < nCount && !bFound; i++ )
1353 	{
1354         pEntry = aList->GetGradient( i );
1355 
1356 		aStr = pEntry->GetName();
1357 
1358 		if( rStr == aStr && rGradient == pEntry->GetGradient() )
1359 			bFound = sal_True;
1360 	}
1361 	if( bFound )
1362 		SelectEntryPos( (sal_uInt16) ( i - 1 + nDist ) );
1363 }
1364 
1365 /*************************************************************************
1366 |*
1367 |*	Fuellt die Listbox (vorlaeufig) mit Strings
1368 |*
1369 \************************************************************************/
1370 
1371 void FillAttrLB::Fill( const XGradientListSharedPtr aList )
1372 {
1373 	long nCount = aList.get() ? aList->Count() : 0;
1374 	XGradientEntry* pEntry;
1375 	ListBox::SetUpdateMode( sal_False );
1376 
1377 	for( long i = 0; i < nCount; i++ )
1378 	{
1379         pEntry = aList->GetGradient( i );
1380 		const Bitmap aBitmap = aList->GetUiBitmap( i );
1381 		if( !aBitmap.IsEmpty() )
1382 			ListBox::InsertEntry( pEntry->GetName(), aBitmap );
1383 		else
1384 			InsertEntry( pEntry->GetName() );
1385 	}
1386 
1387     AdaptDropDownLineCountToMaximum();
1388 	ListBox::SetUpdateMode( sal_True );
1389 }
1390 
1391 /*************************************************************************
1392 |*
1393 |*	Konstruktor von BitmapLB
1394 |*
1395 \************************************************************************/
1396 
1397 BitmapLB::BitmapLB(Window* pParent, ResId Id)
1398 :   ListBox(pParent, Id),
1399     maBitmapEx()
1400 {
1401     SetEdgeBlending(true);
1402 }
1403 
1404 /************************************************************************/
1405 
1406 namespace
1407 {
1408     void formatBitmapExToSize(BitmapEx& rBitmapEx, const Size& rSize)
1409     {
1410         if(!rBitmapEx.IsEmpty() && rSize.Width() > 0 && rSize.Height() > 0)
1411         {
1412             VirtualDevice aVirtualDevice;
1413             aVirtualDevice.SetOutputSizePixel(rSize);
1414 
1415             if(rBitmapEx.IsTransparent())
1416             {
1417                 const StyleSettings& rStyleSettings = Application::GetSettings().GetStyleSettings();
1418 
1419                 if(rStyleSettings.GetUIPreviewUsesCheckeredBackground())
1420                 {
1421                     const Point aNull(0, 0);
1422                     static const sal_uInt32 nLen(8);
1423                     static const Color aW(COL_WHITE);
1424                     static const Color aG(0xef, 0xef, 0xef);
1425 
1426                     aVirtualDevice.DrawCheckered(aNull, rSize, nLen, aW, aG);
1427                 }
1428                 else
1429                 {
1430                     aVirtualDevice.SetBackground(rStyleSettings.GetFieldColor());
1431                     aVirtualDevice.Erase();
1432                 }
1433             }
1434 
1435             if(rBitmapEx.GetSizePixel().Width() >= rSize.Width() && rBitmapEx.GetSizePixel().Height() >= rSize.Height())
1436             {
1437                 static sal_uInt32 nScaleFlag(BMP_SCALE_FASTESTINTERPOLATE);
1438 
1439                 rBitmapEx.Scale(rSize, nScaleFlag);
1440                 aVirtualDevice.DrawBitmapEx(Point(0, 0), rBitmapEx);
1441             }
1442             else
1443             {
1444                 const Size aBitmapSize(rBitmapEx.GetSizePixel());
1445 
1446                 for(sal_Int32 y(0); y < rSize.Height(); y += aBitmapSize.Height())
1447                 {
1448                     for(sal_Int32 x(0); x < rSize.Width(); x += aBitmapSize.Width())
1449                     {
1450                         aVirtualDevice.DrawBitmapEx(
1451                             Point(x, y),
1452                             rBitmapEx);
1453                     }
1454                 }
1455             }
1456 
1457             rBitmapEx = aVirtualDevice.GetBitmap(Point(0, 0), rSize);
1458         }
1459     }
1460 } // end of anonymous namespace
1461 
1462 /************************************************************************/
1463 
1464 void BitmapLB::Fill(const XBitmapListSharedPtr aList)
1465 {
1466 	XBitmapEntry* pEntry;
1467 	const long nCount(aList.get() ? aList->Count() : 0);
1468     const StyleSettings& rStyleSettings = Application::GetSettings().GetStyleSettings();
1469     const Size aSize(rStyleSettings.GetListBoxPreviewDefaultPixelSize());
1470 
1471 	SetUpdateMode(false);
1472 
1473 	for(long i(0); i < nCount; i++)
1474 	{
1475         pEntry = aList->GetBitmap(i);
1476         maBitmapEx = pEntry->GetGraphicObject().GetGraphic().GetBitmapEx();
1477         formatBitmapExToSize(maBitmapEx, aSize);
1478         InsertEntry(pEntry->GetName(), maBitmapEx);
1479 	}
1480 
1481     AdaptDropDownLineCountToMaximum();
1482 	SetUpdateMode(true);
1483 }
1484 
1485 /************************************************************************/
1486 
1487 void BitmapLB::Append(const Size& rSize, const XBitmapEntry& rEntry)
1488 {
1489     maBitmapEx = rEntry.GetGraphicObject().GetGraphic().GetBitmapEx();
1490 
1491     if(!maBitmapEx.IsEmpty())
1492     {
1493         formatBitmapExToSize(maBitmapEx, rSize);
1494         InsertEntry(rEntry.GetName(), maBitmapEx);
1495     }
1496     else
1497     {
1498         InsertEntry(rEntry.GetName());
1499     }
1500 
1501     AdaptDropDownLineCountToMaximum();
1502 }
1503 
1504 /************************************************************************/
1505 
1506 void BitmapLB::Modify(const Size& rSize, const XBitmapEntry& rEntry, sal_uInt16 nPos)
1507 {
1508     RemoveEntry(nPos);
1509     maBitmapEx = rEntry.GetGraphicObject().GetGraphic().GetBitmapEx();
1510 
1511     if(!maBitmapEx.IsEmpty())
1512     {
1513         formatBitmapExToSize(maBitmapEx, rSize);
1514         InsertEntry(rEntry.GetName(), maBitmapEx, nPos);
1515     }
1516     else
1517     {
1518         InsertEntry(rEntry.GetName());
1519     }
1520 }
1521 
1522 /************************************************************************/
1523 
1524 void BitmapLB::SelectEntryByList(const XBitmapListSharedPtr aList, const String& rStr)
1525 {
1526 	const long nCount(aList.get() ? aList->Count() : 0);
1527 	XBitmapEntry* pEntry;
1528 	bool bFound(false);
1529     long i(0);
1530 
1531 	for(i = 0; i < nCount && !bFound; i++)
1532 	{
1533         pEntry = aList->GetBitmap(i);
1534 		const String aStr(pEntry->GetName());
1535 
1536 		if(rStr == aStr)
1537 		{
1538 			bFound = true;
1539 		}
1540 	}
1541 
1542     if(bFound)
1543     {
1544 		SelectEntryPos((sal_uInt16)(i - 1));
1545     }
1546 }
1547 
1548 /*************************************************************************
1549 |*
1550 |*	Konstruktor von FillAttrLB
1551 |*
1552 \************************************************************************/
1553 
1554 FillAttrLB::FillAttrLB( Window* pParent, ResId Id )
1555 :   ColorListBox(pParent, Id),
1556     maBitmapEx()
1557 {
1558 }
1559 
1560 /************************************************************************/
1561 
1562 FillAttrLB::FillAttrLB(Window* pParent, WinBits aWB)
1563 :   ColorListBox(pParent, aWB)
1564 {
1565 }
1566 
1567 /************************************************************************/
1568 
1569 void FillAttrLB::Fill(const XBitmapListSharedPtr aList)
1570 {
1571 	const long nCount(aList.get() ? aList->Count() : 0);
1572 	XBitmapEntry* pEntry;
1573     const StyleSettings& rStyleSettings = Application::GetSettings().GetStyleSettings();
1574     const Size aSize(rStyleSettings.GetListBoxPreviewDefaultPixelSize());
1575 
1576     ListBox::SetUpdateMode(false);
1577 
1578 	for(long i(0); i < nCount; i++)
1579 	{
1580         pEntry = aList->GetBitmap( i );
1581 		maBitmapEx = pEntry->GetGraphicObject().GetGraphic().GetBitmapEx();
1582         formatBitmapExToSize(maBitmapEx, aSize);
1583 		ListBox::InsertEntry(pEntry->GetName(), maBitmapEx);
1584 	}
1585 
1586     AdaptDropDownLineCountToMaximum();
1587     ListBox::SetUpdateMode(true);
1588 }
1589 
1590 /************************************************************************/
1591 
1592 void FillAttrLB::SelectEntryByList( const XBitmapListSharedPtr aList, const String& rStr)
1593 {
1594 	const long nCount(aList.get() ? aList->Count() : 0);
1595 	XBitmapEntry* pEntry;
1596 	bool bFound(false);
1597 	long i(0);
1598 
1599     for(i = 0; i < nCount && !bFound; i++)
1600 	{
1601         pEntry = aList->GetBitmap(i);
1602 		const String aStr(pEntry->GetName());
1603 
1604 		if(rStr == aStr)
1605 		{
1606 			bFound = true;
1607 		}
1608 	}
1609 
1610     if(bFound)
1611     {
1612 		SelectEntryPos((sal_uInt16)(i - 1));
1613     }
1614 }
1615 
1616 /*************************************************************************
1617 |*
1618 |*	Fuellt die Listbox (vorlaeufig) mit Strings
1619 |*
1620 \************************************************************************/
1621 
1622 void FillTypeLB::Fill()
1623 {
1624 	SetUpdateMode( sal_False );
1625 
1626     InsertEntry( String( SVX_RES( RID_SVXSTR_INVISIBLE ) ) );
1627 	InsertEntry( String( SVX_RES( RID_SVXSTR_COLOR ) ) );
1628 	InsertEntry( String( SVX_RES( RID_SVXSTR_GRADIENT ) ) );
1629 	InsertEntry( String( SVX_RES( RID_SVXSTR_HATCH ) ) );
1630 	InsertEntry( String( SVX_RES( RID_SVXSTR_BITMAP ) ) );
1631 
1632     AdaptDropDownLineCountToMaximum();
1633 	SetUpdateMode( sal_True );
1634 }
1635 
1636 /*************************************************************************
1637 |*
1638 |*	Fuellt die Listbox (vorlaeufig) mit Strings
1639 |*
1640 \************************************************************************/
1641 LineLB::LineLB(Window* pParent, ResId Id)
1642 :   ListBox(pParent, Id),
1643     mbAddStandardFields(true)
1644 {
1645     // No EdgeBlending for LineStyle/Dash SetEdgeBlending(true);
1646 }
1647 
1648 LineLB::LineLB(Window* pParent, WinBits aWB)
1649 :   ListBox(pParent, aWB),
1650     mbAddStandardFields(true)
1651 {
1652     // No EdgeBlending for LineStyle/Dash SetEdgeBlending(true);
1653 }
1654 
1655 LineLB::~LineLB()
1656 {
1657 }
1658 
1659 void LineLB::setAddStandardFields(bool bNew)
1660 {
1661     if(getAddStandardFields() != bNew)
1662     {
1663         mbAddStandardFields = bNew;
1664     }
1665 }
1666 
1667 void LineLB::Fill( const XDashListSharedPtr aList )
1668 {
1669 	Clear();
1670 
1671     if(getAddStandardFields() && aList.get())
1672     {
1673         // entry for 'none'
1674         InsertEntry(aList->GetStringForUiNoLine());
1675 
1676         // entry for solid line
1677         InsertEntry(aList->GetStringForUiSolidLine(), aList->GetBitmapForUISolidLine());
1678     }
1679 
1680     // entries for dashed lines
1681 	long nCount = aList.get() ? aList->Count() : 0;
1682 	XDashEntry* pEntry;
1683 	SetUpdateMode( sal_False );
1684 
1685 	for( long i = 0; i < nCount; i++ )
1686 	{
1687         pEntry = aList->GetDash( i );
1688 		const Bitmap aBitmap = aList->GetUiBitmap( i );
1689 		if( !aBitmap.IsEmpty() )
1690 		{
1691 			InsertEntry( pEntry->GetName(), aBitmap );
1692 			//delete pBitmap;
1693 		}
1694 		else
1695 			InsertEntry( pEntry->GetName() );
1696 	}
1697 
1698     AdaptDropDownLineCountToMaximum();
1699 	SetUpdateMode( sal_True );
1700 }
1701 
1702 /************************************************************************/
1703 
1704 void LineLB::Append( const XDashEntry& rEntry, const Bitmap& rBitmap )
1705 {
1706     if(!rBitmap.IsEmpty())
1707     {
1708         InsertEntry( rEntry.GetName(), rBitmap );
1709     }
1710     else
1711     {
1712         InsertEntry( rEntry.GetName() );
1713     }
1714 
1715     AdaptDropDownLineCountToMaximum();
1716 }
1717 
1718 /************************************************************************/
1719 
1720 void LineLB::Modify( const XDashEntry& rEntry, sal_uInt16 nPos, const Bitmap& rBitmap )
1721 {
1722     RemoveEntry( nPos );
1723 
1724     if(!rBitmap.IsEmpty())
1725     {
1726         InsertEntry( rEntry.GetName(), rBitmap, nPos );
1727     }
1728     else
1729     {
1730         InsertEntry( rEntry.GetName(), nPos );
1731     }
1732 }
1733 
1734 /************************************************************************/
1735 
1736 void LineLB::SelectEntryByList( const XDashListSharedPtr aList, const String& rStr, const XDash& rDash, sal_uInt16 nDist )
1737 {
1738 	long nCount = aList.get() ? aList->Count() : 0;
1739 	XDashEntry* pEntry;
1740 	sal_Bool bFound = sal_False;
1741 	String aStr;
1742 	XDash aDash;
1743 
1744 	long i;
1745 	for( i = 0; i < nCount && !bFound; i++ )
1746 	{
1747         pEntry = aList->GetDash( i );
1748 
1749 		aStr = pEntry->GetName();
1750 		aDash = pEntry->GetDash();
1751 
1752 		if( rStr == aStr && rDash == aDash )
1753 			bFound = sal_True;
1754 	}
1755 	if( bFound )
1756 		SelectEntryPos( (sal_uInt16) ( i - 1 + nDist ) );
1757 }
1758 
1759 /*************************************************************************
1760 |*
1761 |*	Fuellt die Listbox (vorlaeufig) mit Strings
1762 |*
1763 \************************************************************************/
1764 LineEndLB::LineEndLB( Window* pParent, ResId Id )
1765     : ListBox( pParent, Id )
1766 {
1767     // No EdgeBlending for LineEnds SetEdgeBlending(true);
1768 }
1769 
1770 LineEndLB::LineEndLB( Window* pParent, WinBits aWB )
1771     : ListBox( pParent, aWB )
1772 {
1773     // No EdgeBlending for LineEnds SetEdgeBlending(true);
1774 }
1775 
1776 LineEndLB::~LineEndLB(void)
1777 {
1778 }
1779 
1780 
1781 void LineEndLB::Fill( const XLineEndListSharedPtr aList, bool bStart )
1782 {
1783 	long nCount = aList.get() ? aList->Count() : 0;
1784 	XLineEndEntry* pEntry;
1785 	VirtualDevice aVD;
1786 	SetUpdateMode( sal_False );
1787 
1788 	for( long i = 0; i < nCount; i++ )
1789 	{
1790         pEntry = aList->GetLineEnd( i );
1791 		const Bitmap aBitmap = aList->GetUiBitmap( i );
1792 		if( !aBitmap.IsEmpty() )
1793 		{
1794 			Size aBmpSize( aBitmap.GetSizePixel() );
1795 			aVD.SetOutputSizePixel( aBmpSize, sal_False );
1796 			aVD.DrawBitmap( Point(), aBitmap );
1797 			InsertEntry( pEntry->GetName(),
1798 				aVD.GetBitmap( bStart ? Point() : Point( aBmpSize.Width() / 2, 0 ),
1799 					Size( aBmpSize.Width() / 2, aBmpSize.Height() ) ) );
1800 			//delete pBitmap;
1801 		}
1802 		else
1803 			InsertEntry( pEntry->GetName() );
1804 	}
1805 
1806     AdaptDropDownLineCountToMaximum();
1807 	SetUpdateMode( sal_True );
1808 }
1809 
1810 /************************************************************************/
1811 
1812 void LineEndLB::Append( const XLineEndEntry& rEntry, const Bitmap& rBitmap, bool bStart )
1813 {
1814     if(!rBitmap.IsEmpty())
1815     {
1816         VirtualDevice aVD;
1817         const Size aBmpSize(rBitmap.GetSizePixel());
1818 
1819         aVD.SetOutputSizePixel(aBmpSize, false);
1820         aVD.DrawBitmap(Point(), rBitmap);
1821         InsertEntry(
1822             rEntry.GetName(),
1823             aVD.GetBitmap(bStart ? Point() : Point(aBmpSize.Width() / 2, 0 ), Size(aBmpSize.Width() / 2, aBmpSize.Height())));
1824     }
1825     else
1826     {
1827         InsertEntry(rEntry.GetName());
1828     }
1829 
1830     AdaptDropDownLineCountToMaximum();
1831 }
1832 
1833 /************************************************************************/
1834 
1835 void LineEndLB::Modify( const XLineEndEntry& rEntry, sal_uInt16 nPos, const Bitmap& rBitmap, bool bStart )
1836 {
1837     RemoveEntry( nPos );
1838 
1839     if(!rBitmap.IsEmpty())
1840     {
1841         VirtualDevice aVD;
1842         const Size aBmpSize(rBitmap.GetSizePixel());
1843 
1844         aVD.SetOutputSizePixel(aBmpSize, false);
1845         aVD.DrawBitmap(Point(), rBitmap);
1846         InsertEntry(
1847             rEntry.GetName(),
1848             aVD.GetBitmap(bStart ? Point() : Point( aBmpSize.Width() / 2, 0 ), Size( aBmpSize.Width() / 2, aBmpSize.Height())),
1849             nPos);
1850     }
1851     else
1852     {
1853         InsertEntry(rEntry.GetName(), nPos);
1854     }
1855 }
1856 
1857 //////////////////////////////////////////////////////////////////////////////
1858 
1859 void SvxPreviewBase::InitSettings(bool bForeground, bool bBackground)
1860 {
1861 	const StyleSettings& rStyleSettings = Application::GetSettings().GetStyleSettings();
1862 
1863 	if(bForeground)
1864 	{
1865 		svtools::ColorConfig aColorConfig;
1866 		Color aTextColor(aColorConfig.GetColorValue(svtools::FONTCOLOR).nColor);
1867 
1868 		if(IsControlForeground())
1869         {
1870 			aTextColor = GetControlForeground();
1871         }
1872 
1873 		getBufferDevice().SetTextColor(aTextColor);
1874 	}
1875 
1876 	if(bBackground)
1877 	{
1878 		if(IsControlBackground())
1879         {
1880 			getBufferDevice().SetBackground(GetControlBackground());
1881         }
1882 		else
1883         {
1884 			getBufferDevice().SetBackground(rStyleSettings.GetWindowColor());
1885         }
1886 	}
1887 
1888     // do not paint background self, it gets painted buffered
1889 	SetControlBackground();
1890     SetBackground();
1891 
1892     Invalidate();
1893 }
1894 
1895 SvxPreviewBase::SvxPreviewBase( Window* pParent, const ResId& rResId )
1896 :	Control( pParent, rResId ),
1897 	mpModel( new SdrModel() ),
1898     mpBufferDevice( new VirtualDevice(*this) )
1899 {
1900 	//	Draw the control's border as a flat thin black line.
1901     SetBorderStyle(WINDOW_BORDER_MONO);
1902     SetDrawMode( GetSettings().GetStyleSettings().GetHighContrastMode() ? OUTPUT_DRAWMODE_CONTRAST : OUTPUT_DRAWMODE_COLOR );
1903     SetMapMode(MAP_100TH_MM);
1904 
1905     // init model
1906 	mpModel->GetItemPool().FreezeIdRanges();
1907 }
1908 
1909 SvxPreviewBase::~SvxPreviewBase()
1910 {
1911 	delete mpModel;
1912     delete mpBufferDevice;
1913 }
1914 
1915 void SvxPreviewBase::LocalPrePaint()
1916 {
1917     // init BufferDevice
1918     if(mpBufferDevice->GetOutputSizePixel() != GetOutputSizePixel())
1919     {
1920         mpBufferDevice->SetDrawMode(GetDrawMode());
1921         mpBufferDevice->SetSettings(GetSettings());
1922         mpBufferDevice->SetAntialiasing(GetAntialiasing());
1923         mpBufferDevice->SetOutputSizePixel(GetOutputSizePixel());
1924 	    mpBufferDevice->SetMapMode(GetMapMode());
1925     }
1926 
1927     mpBufferDevice->Erase();
1928 }
1929 
1930 void SvxPreviewBase::LocalPostPaint()
1931 {
1932     // copy to front (in pixel mode)
1933 	const bool bWasEnabledSrc(mpBufferDevice->IsMapModeEnabled());
1934 	const bool bWasEnabledDst(IsMapModeEnabled());
1935 	const Point aEmptyPoint;
1936 
1937     mpBufferDevice->EnableMapMode(false);
1938     EnableMapMode(false);
1939 
1940     DrawOutDev(
1941         aEmptyPoint, GetOutputSizePixel(),
1942         aEmptyPoint, GetOutputSizePixel(),
1943         *mpBufferDevice);
1944 
1945     mpBufferDevice->EnableMapMode(bWasEnabledSrc);
1946     EnableMapMode(bWasEnabledDst);
1947 }
1948 
1949 void SvxPreviewBase::StateChanged(StateChangedType nType)
1950 {
1951 	Control::StateChanged(nType);
1952 
1953     if(STATE_CHANGE_CONTROLFOREGROUND == nType)
1954     {
1955 		InitSettings(true, false);
1956     }
1957 	else if(STATE_CHANGE_CONTROLBACKGROUND == nType)
1958     {
1959 		InitSettings(false, true);
1960     }
1961 }
1962 
1963 void SvxPreviewBase::DataChanged(const DataChangedEvent& rDCEvt)
1964 {
1965     SetDrawMode(GetSettings().GetStyleSettings().GetHighContrastMode() ? OUTPUT_DRAWMODE_CONTRAST : OUTPUT_DRAWMODE_COLOR);
1966 
1967     if((DATACHANGED_SETTINGS == rDCEvt.GetType()) && (rDCEvt.GetFlags() & SETTINGS_STYLE))
1968     {
1969 		InitSettings(true, true);
1970     }
1971 	else
1972     {
1973 		Control::DataChanged(rDCEvt);
1974     }
1975 }
1976 
1977 /*************************************************************************
1978 |*
1979 |*    SvxXLinePreview::SvxXLinePreview()
1980 |*
1981 *************************************************************************/
1982 
1983 SvxXLinePreview::SvxXLinePreview( Window* pParent, const ResId& rResId )
1984 :	SvxPreviewBase( pParent, rResId ),
1985 	mpLineObjA( 0L ),
1986 	mpLineObjB( 0L ),
1987 	mpLineObjC( 0L ),
1988 	mpGraphic( 0L ),
1989 	mbWithSymbol( sal_False )
1990 {
1991 	const Size aOutputSize(GetOutputSize());
1992 	InitSettings( sal_True, sal_True );
1993 
1994 	const sal_Int32 nDistance(500L);
1995 	const sal_Int32 nAvailableLength(aOutputSize.Width() - (4 * nDistance));
1996 
1997 	// create DrawObectA
1998 	const sal_Int32 aYPosA(aOutputSize.Height() / 2);
1999 	const basegfx::B2DPoint aPointA1( nDistance,  aYPosA);
2000 	const basegfx::B2DPoint aPointA2( aPointA1.getX() + ((nAvailableLength * 14) / 20), aYPosA );
2001 	basegfx::B2DPolygon aPolygonA;
2002 	aPolygonA.append(aPointA1);
2003 	aPolygonA.append(aPointA2);
2004 	mpLineObjA = new SdrPathObj(OBJ_LINE, basegfx::B2DPolyPolygon(aPolygonA));
2005 	mpLineObjA->SetModel(&getModel());
2006 
2007 	// create DrawObectB
2008 	const sal_Int32 aYPosB1((aOutputSize.Height() * 3) / 4);
2009 	const sal_Int32 aYPosB2((aOutputSize.Height() * 1) / 4);
2010 	const basegfx::B2DPoint aPointB1( aPointA2.getX() + nDistance,  aYPosB1);
2011 	const basegfx::B2DPoint aPointB2( aPointB1.getX() + ((nAvailableLength * 2) / 20), aYPosB2 );
2012 	const basegfx::B2DPoint aPointB3( aPointB2.getX() + ((nAvailableLength * 2) / 20), aYPosB1 );
2013 	basegfx::B2DPolygon aPolygonB;
2014 	aPolygonB.append(aPointB1);
2015 	aPolygonB.append(aPointB2);
2016 	aPolygonB.append(aPointB3);
2017 	mpLineObjB = new SdrPathObj(OBJ_PLIN, basegfx::B2DPolyPolygon(aPolygonB));
2018 	mpLineObjB->SetModel(&getModel());
2019 
2020 	// create DrawObectC
2021 	const basegfx::B2DPoint aPointC1( aPointB3.getX() + nDistance,  aYPosB1);
2022 	const basegfx::B2DPoint aPointC2( aPointC1.getX() + ((nAvailableLength * 1) / 20), aYPosB2 );
2023 	const basegfx::B2DPoint aPointC3( aPointC2.getX() + ((nAvailableLength * 1) / 20), aYPosB1 );
2024 	basegfx::B2DPolygon aPolygonC;
2025 	aPolygonC.append(aPointC1);
2026 	aPolygonC.append(aPointC2);
2027 	aPolygonC.append(aPointC3);
2028 	mpLineObjC = new SdrPathObj(OBJ_PLIN, basegfx::B2DPolyPolygon(aPolygonC));
2029 	mpLineObjC->SetModel(&getModel());
2030 }
2031 
2032 SvxXLinePreview::~SvxXLinePreview()
2033 {
2034     SdrObject::Free( mpLineObjA );
2035     SdrObject::Free( mpLineObjB );
2036     SdrObject::Free( mpLineObjC );
2037 }
2038 
2039 // -----------------------------------------------------------------------
2040 
2041 void SvxXLinePreview::SetSymbol(Graphic* p,const Size& s)
2042 {
2043 	mpGraphic = p;
2044 	maSymbolSize = s;
2045 }
2046 
2047 // -----------------------------------------------------------------------
2048 
2049 void SvxXLinePreview::ResizeSymbol(const Size& s)
2050 {
2051 	if ( s != maSymbolSize )
2052 	{
2053 		maSymbolSize = s;
2054 		Invalidate();
2055 	}
2056 }
2057 
2058 // -----------------------------------------------------------------------
2059 
2060 void SvxXLinePreview::SetLineAttributes(const SfxItemSet& rItemSet)
2061 {
2062 	// Set ItemSet at objects
2063 	mpLineObjA->SetMergedItemSet(rItemSet);
2064 
2065 	// At line joints, do not use arrows
2066 	SfxItemSet aTempSet(rItemSet);
2067 	aTempSet.ClearItem(XATTR_LINESTART);
2068 	aTempSet.ClearItem(XATTR_LINEEND);
2069 
2070 	mpLineObjB->SetMergedItemSet(aTempSet);
2071 	mpLineObjC->SetMergedItemSet(aTempSet);
2072 }
2073 
2074 // -----------------------------------------------------------------------
2075 
2076 void SvxXLinePreview::Paint( const Rectangle& )
2077 {
2078 	LocalPrePaint();
2079 
2080 	// paint objects to buffer device
2081 	sdr::contact::SdrObjectVector aObjectVector;
2082 	aObjectVector.push_back(mpLineObjA);
2083 	aObjectVector.push_back(mpLineObjB);
2084 	aObjectVector.push_back(mpLineObjC);
2085 
2086 	sdr::contact::ObjectContactOfObjListPainter aPainter(getBufferDevice(), aObjectVector, 0);
2087 	sdr::contact::DisplayInfo aDisplayInfo;
2088 
2089 	// do processing
2090 	aPainter.ProcessDisplay(aDisplayInfo);
2091 
2092 	if ( mbWithSymbol && mpGraphic )
2093 	{
2094     	const Size aOutputSize(GetOutputSize());
2095 		Point aPos = Point( aOutputSize.Width() / 3, aOutputSize.Height() / 2 );
2096 		aPos.X() -= maSymbolSize.Width() / 2;
2097 		aPos.Y() -= maSymbolSize.Height() / 2;
2098 		mpGraphic->Draw( &getBufferDevice(), aPos, maSymbolSize );
2099 	}
2100 
2101 	LocalPostPaint();
2102 }
2103 
2104 /*************************************************************************
2105 |*
2106 |*    SvxXRectPreview::SvxXRectPreview()
2107 |*
2108 *************************************************************************/
2109 
2110 SvxXRectPreview::SvxXRectPreview( Window* pParent, const ResId& rResId )
2111 :	SvxPreviewBase( pParent, rResId ),
2112 	mpRectangleObject(0)
2113 {
2114 	InitSettings(true, true);
2115 
2116 	// create RectangleObject
2117     const Rectangle aObjectSize(Point(), GetOutputSize());
2118 	mpRectangleObject = new SdrRectObj(aObjectSize);
2119 	mpRectangleObject->SetModel(&getModel());
2120 }
2121 
2122 SvxXRectPreview::~SvxXRectPreview()
2123 {
2124     SdrObject::Free(mpRectangleObject);
2125 }
2126 
2127 void SvxXRectPreview::SetAttributes(const SfxItemSet& rItemSet)
2128 {
2129 	mpRectangleObject->SetMergedItemSet(rItemSet, true);
2130 	mpRectangleObject->SetMergedItem(XLineStyleItem(XLINE_NONE));
2131 }
2132 
2133 void SvxXRectPreview::Paint( const Rectangle& )
2134 {
2135 	LocalPrePaint();
2136 
2137     sdr::contact::SdrObjectVector aObjectVector;
2138 
2139     aObjectVector.push_back(mpRectangleObject);
2140 
2141     sdr::contact::ObjectContactOfObjListPainter aPainter(getBufferDevice(), aObjectVector, 0);
2142 	sdr::contact::DisplayInfo aDisplayInfo;
2143 
2144 	aPainter.ProcessDisplay(aDisplayInfo);
2145 
2146     LocalPostPaint();
2147 }
2148 
2149 /*************************************************************************
2150 |*
2151 |*    SvxXShadowPreview::SvxXShadowPreview()
2152 |*
2153 *************************************************************************/
2154 
2155 SvxXShadowPreview::SvxXShadowPreview( Window* pParent, const ResId& rResId )
2156 :	SvxPreviewBase( pParent, rResId ),
2157 	mpRectangleObject(0),
2158     mpRectangleShadow(0)
2159 {
2160 	InitSettings(true, true);
2161 
2162     // prepare size
2163 	Size aSize = GetOutputSize();
2164 	aSize.Width() = aSize.Width() / 3;
2165 	aSize.Height() = aSize.Height() / 3;
2166 
2167     // create RectangleObject
2168     const Rectangle aObjectSize( Point( aSize.Width(), aSize.Height() ), aSize );
2169 	mpRectangleObject = new SdrRectObj(aObjectSize);
2170 	mpRectangleObject->SetModel(&getModel());
2171 
2172     // create ShadowObject
2173     const Rectangle aShadowSize( Point( aSize.Width(), aSize.Height() ), aSize );
2174 	mpRectangleShadow = new SdrRectObj(aShadowSize);
2175 	mpRectangleShadow->SetModel(&getModel());
2176 }
2177 
2178 SvxXShadowPreview::~SvxXShadowPreview()
2179 {
2180     SdrObject::Free(mpRectangleObject);
2181     SdrObject::Free(mpRectangleShadow);
2182 }
2183 
2184 void SvxXShadowPreview::SetRectangleAttributes(const SfxItemSet& rItemSet)
2185 {
2186 	mpRectangleObject->SetMergedItemSet(rItemSet, true);
2187 	mpRectangleObject->SetMergedItem(XLineStyleItem(XLINE_NONE));
2188 }
2189 
2190 void SvxXShadowPreview::SetShadowAttributes(const SfxItemSet& rItemSet)
2191 {
2192 	mpRectangleShadow->SetMergedItemSet(rItemSet, true);
2193 	mpRectangleShadow->SetMergedItem(XLineStyleItem(XLINE_NONE));
2194 }
2195 
2196 void SvxXShadowPreview::SetShadowPosition(const Point& rPos)
2197 {
2198     Rectangle aObjectPosition(mpRectangleObject->GetSnapRect());
2199     aObjectPosition.Move(rPos.X(), rPos.Y());
2200     mpRectangleShadow->SetSnapRect(aObjectPosition);
2201 }
2202 
2203 void SvxXShadowPreview::Paint( const Rectangle& )
2204 {
2205 	LocalPrePaint();
2206 
2207     sdr::contact::SdrObjectVector aObjectVector;
2208 
2209     aObjectVector.push_back(mpRectangleShadow);
2210 	aObjectVector.push_back(mpRectangleObject);
2211 
2212     sdr::contact::ObjectContactOfObjListPainter aPainter(getBufferDevice(), aObjectVector, 0);
2213 	sdr::contact::DisplayInfo aDisplayInfo;
2214 
2215 	aPainter.ProcessDisplay(aDisplayInfo);
2216 
2217     LocalPostPaint();
2218 }
2219 
2220 // -----------------------------------------------------------------------
2221 // eof
2222