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