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