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