Version 3.6.0.4, tag libreoffice-3.6.0.4
[LibreOffice.git] / svx / source / dialog / dlgctrl.cxx
blob7a84a7a0cffd1291119ff00fc0f1f6919d1fbec2
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
30 // include ---------------------------------------------------------------
31 #include <tools/shl.hxx>
32 #include <vcl/svapp.hxx>
34 #include <svx/xtable.hxx>
35 #include <svx/xpool.hxx>
37 #include <svx/dialogs.hrc>
38 #include "accessibility.hrc"
39 #include <svx/dlgctrl.hxx>
40 #include <svx/dialmgr.hxx>
41 #include <tools/poly.hxx>
42 #include <vcl/region.hxx>
43 #include <vcl/gradient.hxx>
44 #include <vcl/hatch.hxx>
45 #include <svtools/colorcfg.hxx>
47 #include "svxrectctaccessiblecontext.hxx"
48 #include <com/sun/star/lang/XUnoTunnel.hpp>
49 #include <basegfx/point/b2dpoint.hxx>
50 #include <basegfx/polygon/b2dpolygon.hxx>
51 #include <svx/svdorect.hxx>
53 #include <svx/svdmodel.hxx>
54 #include <svx/svdopath.hxx>
55 #include <svx/sdr/contact/objectcontactofobjlistpainter.hxx>
56 #include <svx/sdr/contact/displayinfo.hxx>
57 #include "linectrl.hrc"
59 #define OUTPUT_DRAWMODE_COLOR (DRAWMODE_DEFAULT)
60 #define OUTPUT_DRAWMODE_CONTRAST (DRAWMODE_SETTINGSLINE | DRAWMODE_SETTINGSFILL | DRAWMODE_SETTINGSTEXT | DRAWMODE_SETTINGSGRADIENT)
62 using namespace ::com::sun::star::uno;
63 using namespace ::com::sun::star::lang;
64 using namespace ::com::sun::star::accessibility;
66 // Control for display and selection of the corner points and
67 // mid point of an object
69 Bitmap& SvxRectCtl::GetRectBitmap( void )
71 if( !pBitmap )
72 InitRectBitmap();
74 return *pBitmap;
77 SvxRectCtl::SvxRectCtl( Window* pParent, const ResId& rResId, RECT_POINT eRpt,
78 sal_uInt16 nBorder, sal_uInt16 nCircle, CTL_STYLE eStyle ) :
80 Control( pParent, rResId ),
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)
91 SetMapMode( MAP_100TH_MM );
92 Resize_Impl();
95 // -----------------------------------------------------------------------
97 SvxRectCtl::~SvxRectCtl()
99 delete pBitmap;
101 if( pAccContext )
102 pAccContext->release();
105 // -----------------------------------------------------------------------
106 void SvxRectCtl::Resize()
108 Resize_Impl();
109 Control::Resize();
112 // -----------------------------------------------------------------------
114 void SvxRectCtl::Resize_Impl()
116 aSize = GetOutputSize();
118 switch( eCS )
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 );
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 );
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;
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 );
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 );
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;
150 Reset();
151 InitSettings( sal_True, sal_True );
153 // -----------------------------------------------------------------------
155 void SvxRectCtl::InitRectBitmap( void )
157 if( pBitmap )
158 delete pBitmap;
160 const StyleSettings& rStyles = Application::GetSettings().GetStyleSettings();
161 svtools::ColorConfig aColorConfig;
163 pBitmap = new Bitmap( SVX_RES( RID_SVXCTRL_RECTBTNS ) );
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();
183 #ifdef DBG_UTIL
184 static sal_Bool bModify = sal_False;
185 sal_Bool& rModify = bModify;
186 if( rModify )
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 );
198 #endif
200 pBitmap->Replace( aColorAry1, aColorAry2, 7, NULL );
203 // -----------------------------------------------------------------------
205 void SvxRectCtl::InitSettings( sal_Bool bForeground, sal_Bool bBackground )
207 const StyleSettings& rStyleSettings = Application::GetSettings().GetStyleSettings();
209 if( bForeground )
211 svtools::ColorConfig aColorConfig;
212 Color aTextColor( aColorConfig.GetColorValue( svtools::FONTCOLOR ).nColor );
214 if ( IsControlForeground() )
215 aTextColor = GetControlForeground();
216 SetTextColor( aTextColor );
219 if( bBackground )
221 if ( IsControlBackground() )
222 SetBackground( GetControlBackground() );
223 else
224 SetBackground( rStyleSettings.GetWindowColor() );
227 delete pBitmap;
228 pBitmap = NULL; // forces new creating of bitmap
230 Invalidate();
233 // The clicked rectangle (3 x 3) is determined and the parent (dialog)
234 // is notified that the item was changed
235 void SvxRectCtl::MouseButtonDown( const MouseEvent& rMEvt )
237 // CompletelyDisabled() added to have a disabled state for SvxRectCtl
238 if(!IsCompletelyDisabled())
240 Point aPtLast = aPtNew;
242 aPtNew = GetApproxLogPtFromPixPt( rMEvt.GetPosPixel() );
244 if( aPtNew == aPtMM && ( eCS == CS_SHADOW || eCS == CS_ANGLE ) )
246 aPtNew = aPtLast;
248 else
250 Invalidate( Rectangle( aPtLast - Point( nRadius, nRadius ),
251 aPtLast + Point( nRadius, nRadius ) ) );
252 Invalidate( Rectangle( aPtNew - Point( nRadius, nRadius ),
253 aPtNew + Point( nRadius, nRadius ) ) );
254 eRP = GetRPFromPoint( aPtNew );
256 SetActualRP( eRP );
258 if( WINDOW_TABPAGE == GetParent()->GetType() )
259 ( (SvxTabPage*) GetParent() )->PointChanged( this, eRP );
264 // -----------------------------------------------------------------------
266 void SvxRectCtl::KeyInput( const KeyEvent& rKeyEvt )
268 // CompletelyDisabled() added to have a disabled state for SvxRectCtl
269 if(!IsCompletelyDisabled())
271 RECT_POINT eNewRP = eRP;
272 sal_Bool bUseMM = (eCS != CS_SHADOW) && (eCS != CS_ANGLE);
274 switch( rKeyEvt.GetKeyCode().GetCode() )
276 case KEY_DOWN:
278 if( !(m_nState & CS_NOVERT) )
279 switch( eNewRP )
281 case RP_LT: eNewRP = RP_LM; break;
282 case RP_MT: eNewRP = bUseMM ? RP_MM : RP_MB; break;
283 case RP_RT: eNewRP = RP_RM; break;
284 case RP_LM: eNewRP = RP_LB; break;
285 case RP_MM: eNewRP = RP_MB; break;
286 case RP_RM: eNewRP = RP_RB; break;
287 default: ; //prevent warning
290 break;
291 case KEY_UP:
293 if( !(m_nState & CS_NOVERT) )
294 switch( eNewRP )
296 case RP_LM: eNewRP = RP_LT; break;
297 case RP_MM: eNewRP = RP_MT; break;
298 case RP_RM: eNewRP = RP_RT; break;
299 case RP_LB: eNewRP = RP_LM; break;
300 case RP_MB: eNewRP = bUseMM ? RP_MM : RP_MT; break;
301 case RP_RB: eNewRP = RP_RM; break;
302 default: ; //prevent warning
305 break;
306 case KEY_LEFT:
308 if( !(m_nState & CS_NOHORZ) )
309 switch( eNewRP )
311 case RP_MT: eNewRP = RP_LT; break;
312 case RP_RT: eNewRP = RP_MT; break;
313 case RP_MM: eNewRP = RP_LM; break;
314 case RP_RM: eNewRP = bUseMM ? RP_MM : RP_LM; break;
315 case RP_MB: eNewRP = RP_LB; break;
316 case RP_RB: eNewRP = RP_MB; break;
317 default: ; //prevent warning
320 break;
321 case KEY_RIGHT:
323 if( !(m_nState & CS_NOHORZ) )
324 switch( eNewRP )
326 case RP_LT: eNewRP = RP_MT; break;
327 case RP_MT: eNewRP = RP_RT; break;
328 case RP_LM: eNewRP = bUseMM ? RP_MM : RP_RM; break;
329 case RP_MM: eNewRP = RP_RM; break;
330 case RP_LB: eNewRP = RP_MB; break;
331 case RP_MB: eNewRP = RP_RB; break;
332 default: ; //prevent warning
335 break;
336 default:
337 Control::KeyInput( rKeyEvt );
338 return;
340 if( eNewRP != eRP )
342 SetActualRP( eNewRP );
344 if( WINDOW_TABPAGE == GetParent()->GetType() )
345 ( (SvxTabPage*) GetParent() )->PointChanged( this, eRP );
347 SetFocusRect();
352 // -----------------------------------------------------------------------
354 void SvxRectCtl::StateChanged( StateChangedType nType )
356 if ( nType == STATE_CHANGE_CONTROLFOREGROUND )
357 InitSettings( sal_True, sal_False );
358 else if ( nType == STATE_CHANGE_CONTROLBACKGROUND )
359 InitSettings( sal_False, sal_True );
361 Window::StateChanged( nType );
364 // -----------------------------------------------------------------------
366 void SvxRectCtl::DataChanged( const DataChangedEvent& rDCEvt )
368 if ( ( rDCEvt.GetType() == DATACHANGED_SETTINGS ) && ( rDCEvt.GetFlags() & SETTINGS_STYLE ) )
369 InitSettings( sal_True, sal_True );
370 else
371 Window::DataChanged( rDCEvt );
374 // the control (rectangle with 9 circles)
376 void SvxRectCtl::Paint( const Rectangle& )
378 Point aPtDiff( PixelToLogic( Point( 1, 1 ) ) );
380 const StyleSettings& rStyles = Application::GetSettings().GetStyleSettings();
382 SetLineColor( rStyles.GetDialogColor() );
383 SetFillColor( rStyles.GetDialogColor() );
384 DrawRect( Rectangle( Point(0,0), GetOutputSize() ) );
386 if( IsEnabled() )
387 SetLineColor( rStyles.GetLabelTextColor() );
388 else
389 SetLineColor( rStyles.GetShadowColor() );
391 SetFillColor();
393 switch( eCS )
396 case CS_RECT:
397 case CS_SHADOW:
398 if( !IsEnabled() )
400 Color aOldCol = GetLineColor();
401 SetLineColor( rStyles.GetLightColor() );
402 DrawRect( Rectangle( aPtLT + aPtDiff, aPtRB + aPtDiff ) );
403 SetLineColor( aOldCol );
405 DrawRect( Rectangle( aPtLT, aPtRB ) );
406 break;
408 case CS_LINE:
409 if( !IsEnabled() )
411 Color aOldCol = GetLineColor();
412 SetLineColor( rStyles.GetLightColor() );
413 DrawLine( aPtLM - Point( 2 * nBorderWidth, 0) + aPtDiff,
414 aPtRM + Point( 2 * nBorderWidth, 0 ) + aPtDiff );
415 SetLineColor( aOldCol );
417 DrawLine( aPtLM - Point( 2 * nBorderWidth, 0),
418 aPtRM + Point( 2 * nBorderWidth, 0 ) );
419 break;
421 case CS_ANGLE:
422 if( !IsEnabled() )
424 Color aOldCol = GetLineColor();
425 SetLineColor( rStyles.GetLightColor() );
426 DrawLine( aPtLT + aPtDiff, aPtRB + aPtDiff );
427 DrawLine( aPtLB + aPtDiff, aPtRT + aPtDiff );
428 DrawLine( aPtLM + aPtDiff, aPtRM + aPtDiff );
429 DrawLine( aPtMT + aPtDiff, aPtMB + aPtDiff );
430 SetLineColor( aOldCol );
432 DrawLine( aPtLT, aPtRB );
433 DrawLine( aPtLB, aPtRT );
434 DrawLine( aPtLM, aPtRM );
435 DrawLine( aPtMT, aPtMB );
436 break;
438 default:
439 break;
441 SetFillColor( GetBackground().GetColor() );
443 Size aBtnSize( 11, 11 );
444 Size aDstBtnSize( PixelToLogic( aBtnSize ) );
445 Point aToCenter( aDstBtnSize.Width() >> 1, aDstBtnSize.Height() >> 1);
446 Point aBtnPnt1( IsEnabled()?0:22,0 );
447 Point aBtnPnt2( 11,0 );
448 Point aBtnPnt3( 22,0 );
450 sal_Bool bNoHorz = (m_nState & CS_NOHORZ) != 0;
451 sal_Bool bNoVert = (m_nState & CS_NOVERT) != 0;
453 Bitmap& rBitmap = GetRectBitmap();
455 // CompletelyDisabled() added to have a disabled state for SvxRectCtl
456 if(IsCompletelyDisabled())
458 DrawBitmap( aPtLT - aToCenter, aDstBtnSize, aBtnPnt3, aBtnSize, rBitmap );
459 DrawBitmap( aPtMT - aToCenter, aDstBtnSize, aBtnPnt3, aBtnSize, rBitmap );
460 DrawBitmap( aPtRT - aToCenter, aDstBtnSize, aBtnPnt3, aBtnSize, rBitmap );
461 DrawBitmap( aPtLM - aToCenter, aDstBtnSize, aBtnPnt3, aBtnSize, rBitmap );
462 if( eCS == CS_RECT || eCS == CS_LINE )
463 DrawBitmap( aPtMM - aToCenter, aDstBtnSize, aBtnPnt3, aBtnSize, rBitmap );
464 DrawBitmap( aPtRM - aToCenter, aDstBtnSize, aBtnPnt3, aBtnSize, rBitmap );
465 DrawBitmap( aPtLB - aToCenter, aDstBtnSize, aBtnPnt3, aBtnSize, rBitmap );
466 DrawBitmap( aPtMB - aToCenter, aDstBtnSize, aBtnPnt3, aBtnSize, rBitmap );
467 DrawBitmap( aPtRB - aToCenter, aDstBtnSize, aBtnPnt3, aBtnSize, rBitmap );
469 else
471 DrawBitmap( aPtLT - aToCenter, aDstBtnSize, (bNoHorz | bNoVert)?aBtnPnt3:aBtnPnt1, aBtnSize, rBitmap );
472 DrawBitmap( aPtMT - aToCenter, aDstBtnSize, bNoVert?aBtnPnt3:aBtnPnt1, aBtnSize, rBitmap );
473 DrawBitmap( aPtRT - aToCenter, aDstBtnSize, (bNoHorz | bNoVert)?aBtnPnt3:aBtnPnt1, aBtnSize, rBitmap );
475 DrawBitmap( aPtLM - aToCenter, aDstBtnSize, bNoHorz?aBtnPnt3:aBtnPnt1, aBtnSize, rBitmap );
477 // Center for rectangle and line
478 if( eCS == CS_RECT || eCS == CS_LINE )
479 DrawBitmap( aPtMM - aToCenter, aDstBtnSize, aBtnPnt1, aBtnSize, rBitmap );
481 DrawBitmap( aPtRM - aToCenter, aDstBtnSize, bNoHorz?aBtnPnt3:aBtnPnt1, aBtnSize, rBitmap );
483 DrawBitmap( aPtLB - aToCenter, aDstBtnSize, (bNoHorz | bNoVert)?aBtnPnt3:aBtnPnt1, aBtnSize, rBitmap );
484 DrawBitmap( aPtMB - aToCenter, aDstBtnSize, bNoVert?aBtnPnt3:aBtnPnt1, aBtnSize, rBitmap );
485 DrawBitmap( aPtRB - aToCenter, aDstBtnSize, (bNoHorz | bNoVert)?aBtnPnt3:aBtnPnt1, aBtnSize, rBitmap );
488 // draw active button, avoid center pos for angle
489 // CompletelyDisabled() added to have a disabled state for SvxRectCtl
490 if(!IsCompletelyDisabled())
492 if( IsEnabled() && (eCS != CS_ANGLE || aPtNew != aPtMM) )
494 Point aCenterPt( aPtNew );
495 aCenterPt -= aToCenter;
497 DrawBitmap( aCenterPt, aDstBtnSize, aBtnPnt2, aBtnSize, rBitmap );
502 // Convert RECT_POINT Point
504 Point SvxRectCtl::GetPointFromRP( RECT_POINT _eRP) const
506 switch( _eRP )
508 case RP_LT: return aPtLT;
509 case RP_MT: return aPtMT;
510 case RP_RT: return aPtRT;
511 case RP_LM: return aPtLM;
512 case RP_MM: return aPtMM;
513 case RP_RM: return aPtRM;
514 case RP_LB: return aPtLB;
515 case RP_MB: return aPtMB;
516 case RP_RB: return aPtRB;
518 return( aPtMM ); // default
522 void SvxRectCtl::SetFocusRect( const Rectangle* pRect )
524 HideFocus();
526 if( pRect )
527 ShowFocus( *pRect );
528 else
529 ShowFocus( CalculateFocusRectangle() );
532 Point SvxRectCtl::SetActualRPWithoutInvalidate( RECT_POINT eNewRP )
534 Point aPtLast = aPtNew;
535 aPtNew = GetPointFromRP( eNewRP );
537 if( (m_nState & CS_NOHORZ) != 0 )
538 aPtNew.X() = aPtMM.X();
540 if( (m_nState & CS_NOVERT) != 0 )
541 aPtNew.Y() = aPtMM.Y();
543 eNewRP = GetRPFromPoint( aPtNew );
545 eDefRP = eNewRP;
546 eRP = eNewRP;
548 return aPtLast;
551 void SvxRectCtl::GetFocus()
553 SetFocusRect();
557 void SvxRectCtl::LoseFocus()
559 HideFocus();
563 Point SvxRectCtl::GetApproxLogPtFromPixPt( const Point& rPt ) const
565 Point aPt = PixelToLogic( rPt );
566 long x;
567 long y;
569 if( ( m_nState & CS_NOHORZ ) == 0 )
571 if( aPt.X() < aSize.Width() / 3 )
572 x = aPtLT.X();
573 else if( aPt.X() < aSize.Width() * 2 / 3 )
574 x = aPtMM.X();
575 else
576 x = aPtRB.X();
578 else
579 x = aPtMM.X();
581 if( ( m_nState & CS_NOVERT ) == 0 )
583 if( aPt.Y() < aSize.Height() / 3 )
584 y = aPtLT.Y();
585 else if( aPt.Y() < aSize.Height() * 2 / 3 )
586 y = aPtMM.Y();
587 else
588 y = aPtRB.Y();
590 else
591 y = aPtMM.Y();
593 return Point( x, y );
597 // Converts Point in RECT_POINT
599 RECT_POINT SvxRectCtl::GetRPFromPoint( Point aPt ) const
601 if ( aPt == aPtLT) return RP_LT;
602 else if( aPt == aPtMT) return RP_MT;
603 else if( aPt == aPtRT) return RP_RT;
604 else if( aPt == aPtLM) return RP_LM;
605 else if( aPt == aPtRM) return RP_RM;
606 else if( aPt == aPtLB) return RP_LB;
607 else if( aPt == aPtMB) return RP_MB;
608 else if( aPt == aPtRB) return RP_RB;
610 else
611 return RP_MM; // default
614 // Resets to the original state of the control
616 void SvxRectCtl::Reset()
618 aPtNew = GetPointFromRP( eDefRP );
619 eRP = eDefRP;
620 Invalidate();
623 // Returns the currently selected RECT_POINT
625 RECT_POINT SvxRectCtl::GetActualRP() const
627 return( eRP );
630 void SvxRectCtl::SetActualRP( RECT_POINT eNewRP )
632 Point aPtLast( SetActualRPWithoutInvalidate( eNewRP ) );
634 Invalidate( Rectangle( aPtLast - Point( nRadius, nRadius ), aPtLast + Point( nRadius, nRadius ) ) );
635 Invalidate( Rectangle( aPtNew - Point( nRadius, nRadius ), aPtNew + Point( nRadius, nRadius ) ) );
637 // notify accessibility object about change
638 if( pAccContext )
639 pAccContext->selectChild( eNewRP );
642 void SvxRectCtl::SetState( CTL_STATE nState )
644 m_nState = nState;
646 Point aPtLast( GetPointFromRP( eRP ) );
647 Point _aPtNew( aPtLast );
649 if( (m_nState & CS_NOHORZ) != 0 )
650 _aPtNew.X() = aPtMM.X();
652 if( (m_nState & CS_NOVERT) != 0 )
653 _aPtNew.Y() = aPtMM.Y();
655 eRP = GetRPFromPoint( _aPtNew );
656 Invalidate();
658 if( WINDOW_TABPAGE == GetParent()->GetType() )
659 ( (SvxTabPage*) GetParent() )->PointChanged( this, eRP );
662 sal_uInt8 SvxRectCtl::GetNumOfChildren( void ) const
664 return ( eCS == CS_ANGLE )? 8 : 9;
667 Rectangle SvxRectCtl::CalculateFocusRectangle( void ) const
669 Size aDstBtnSize( PixelToLogic( Size( 15, 15 ) ) );
670 return Rectangle( aPtNew - Point( aDstBtnSize.Width() >> 1, aDstBtnSize.Height() >> 1 ), aDstBtnSize );
673 Rectangle SvxRectCtl::CalculateFocusRectangle( RECT_POINT eRectPoint ) const
675 Rectangle aRet;
676 RECT_POINT eOldRectPoint = GetActualRP();
678 if( eOldRectPoint == eRectPoint )
679 aRet = CalculateFocusRectangle();
680 else
682 SvxRectCtl* pThis = const_cast< SvxRectCtl* >( this );
684 pThis->SetActualRPWithoutInvalidate( eRectPoint ); // no invalidation because it's only temporary!
685 aRet = CalculateFocusRectangle();
687 pThis->SetActualRPWithoutInvalidate( eOldRectPoint ); // no invalidation because nothing has changed!
690 return aRet;
693 Reference< XAccessible > SvxRectCtl::CreateAccessible()
695 Window* pParent = GetAccessibleParentWindow();
697 DBG_ASSERT( pParent, "-SvxRectCtl::CreateAccessible(): No Parent!" );
699 Reference< XAccessible > xAccParent = pParent->GetAccessible();
700 if( xAccParent.is() )
702 pAccContext = new SvxRectCtlAccessibleContext( xAccParent, *this );
703 pAccContext->acquire();
705 SetActualRP( GetActualRP() );
707 return pAccContext;
709 else
710 return Reference< XAccessible >();
713 RECT_POINT SvxRectCtl::GetApproxRPFromPixPt( const ::com::sun::star::awt::Point& r ) const
715 return GetRPFromPoint( GetApproxLogPtFromPixPt( Point( r.X, r.Y ) ) );
718 // CompletelyDisabled() added to have a disabled state for SvxRectCtl
719 void SvxRectCtl::DoCompletelyDisable(sal_Bool bNew)
721 mbCompleteDisable = bNew;
722 Invalidate();
725 // Control for editing bitmaps
727 SvxPixelCtl::SvxPixelCtl( Window* pParent, const ResId& rResId, sal_uInt16 nNumber ) :
728 Control ( pParent, rResId ),
729 nLines ( nNumber ),
730 bPaintable ( sal_True )
732 aRectSize = GetOutputSize();
734 SetPixelColor( Color( COL_BLACK ) );
735 SetBackgroundColor( Color( COL_WHITE ) );
736 SetLineColor( Application::GetSettings().GetStyleSettings().GetShadowColor() );
738 nSquares = nLines * nLines;
739 pPixel = new sal_uInt16[ nSquares ];
740 rtl_zeroMemory(pPixel, nSquares * sizeof(sal_uInt16));
743 // Destructor dealocating the dynamic array
745 SvxPixelCtl::~SvxPixelCtl( )
747 delete []pPixel;
750 // Changes the foreground or Background color
752 void SvxPixelCtl::ChangePixel( sal_uInt16 nPixel )
754 if( *( pPixel + nPixel) == 0 )
755 *( pPixel + nPixel) = 1; // could be extended to more colors
756 else
757 *( pPixel + nPixel) = 0;
760 // The clicked rectangle is identified, to change its color
762 void SvxPixelCtl::MouseButtonDown( const MouseEvent& rMEvt )
764 Point aPt = PixelToLogic( rMEvt.GetPosPixel() );
765 Point aPtTl, aPtBr;
766 sal_uInt16 nX, nY;
768 nX = (sal_uInt16) ( aPt.X() * nLines / aRectSize.Width() );
769 nY = (sal_uInt16) ( aPt.Y() * nLines / aRectSize.Height() );
771 ChangePixel( nX + nY * nLines );
773 aPtTl.X() = aRectSize.Width() * nX / nLines + 1;
774 aPtBr.X() = aRectSize.Width() * (nX + 1) / nLines - 1;
775 aPtTl.Y() = aRectSize.Height() * nY / nLines + 1;
776 aPtBr.Y() = aRectSize.Height() * (nY + 1) / nLines - 1;
778 Invalidate( Rectangle( aPtTl, aPtBr ) );
780 if( WINDOW_TABPAGE == GetParent()->GetType() )
781 ( (SvxTabPage*) GetParent() )->PointChanged( this, RP_MM ); // RectPoint is a dummy
784 // Draws the Control (Rectangle with nine circles)
786 void SvxPixelCtl::Paint( const Rectangle& )
788 sal_uInt16 i, j, nTmp;
789 Point aPtTl, aPtBr;
791 if( bPaintable )
793 // Draw lines
794 Control::SetLineColor( aLineColor );
795 for( i = 1; i < nLines; i++)
797 // horizontal
798 nTmp = (sal_uInt16) ( aRectSize.Height() * i / nLines );
799 DrawLine( Point( 0, nTmp ), Point( aRectSize.Width(), nTmp ) );
800 // vertically
801 nTmp = (sal_uInt16) ( aRectSize.Width() * i / nLines );
802 DrawLine( Point( nTmp, 0 ), Point( nTmp, aRectSize.Height() ) );
805 //Draw Rectangles (squares)
806 Control::SetLineColor();
807 sal_uInt16 nLastPixel = *pPixel ? 0 : 1;
809 for( i = 0; i < nLines; i++)
811 aPtTl.Y() = aRectSize.Height() * i / nLines + 1;
812 aPtBr.Y() = aRectSize.Height() * (i + 1) / nLines - 1;
814 for( j = 0; j < nLines; j++)
816 aPtTl.X() = aRectSize.Width() * j / nLines + 1;
817 aPtBr.X() = aRectSize.Width() * (j + 1) / nLines - 1;
819 if ( *( pPixel + i * nLines + j ) != nLastPixel )
821 nLastPixel = *( pPixel + i * nLines + j );
822 // Change color: 0 -> Background color
823 SetFillColor( nLastPixel ? aPixelColor : aBackgroundColor );
825 DrawRect( Rectangle( aPtTl, aPtBr ) );
828 } // bPaintable
829 else
831 SetBackground( Wallpaper( Color( COL_LIGHTGRAY ) ) );
832 Control::SetLineColor( Color( COL_LIGHTRED ) );
833 DrawLine( Point( 0, 0 ), Point( aRectSize.Width(), aRectSize.Height() ) );
834 DrawLine( Point( 0, aRectSize.Height() ), Point( aRectSize.Width(), 0 ) );
838 void SvxPixelCtl::SetXBitmap( const XOBitmap& rXBmp )
840 if( rXBmp.GetBitmapType() == XBITMAP_8X8 )
842 aPixelColor = rXBmp.GetPixelColor();
843 aBackgroundColor = rXBmp.GetBackgroundColor();
845 sal_uInt16* pArray = rXBmp.GetPixelArray();
847 for( sal_uInt16 i = 0; i < nSquares; i++ )
848 *( pPixel + i ) = *( pArray + i );
852 // Resets to the original state of the control
854 void SvxPixelCtl::Reset()
856 // clear pixel area
857 rtl_zeroMemory(pPixel, nSquares * sizeof(sal_uInt16));
858 Invalidate();
861 // Constructor: BitmapCtl for SvxPixelCtl
863 SvxBitmapCtl::SvxBitmapCtl( Window* /*pParent*/, const Size& rSize )
865 aSize = rSize;
868 SvxBitmapCtl::~SvxBitmapCtl()
872 // BitmapCtl: Returns the Bitmap
874 XOBitmap SvxBitmapCtl::GetXBitmap()
876 XOBitmap aXOBitmap( pBmpArray, aPixelColor, aBackgroundColor );
878 return( aXOBitmap );
881 // Fills the Listbox with color and strings
883 void ColorLB::Fill( const XColorListRef &pColorTab )
885 long nCount = pColorTab->Count();
886 XColorEntry* pEntry;
887 SetUpdateMode( sal_False );
889 for( long i = 0; i < nCount; i++ )
891 pEntry = pColorTab->GetColor( i );
892 InsertEntry( pEntry->GetColor(), pEntry->GetName() );
894 SetUpdateMode( sal_True );
897 /************************************************************************/
899 void ColorLB::Append( XColorEntry* pEntry, Bitmap* )
901 InsertEntry( pEntry->GetColor(), pEntry->GetName() );
904 /************************************************************************/
906 void ColorLB::Modify( XColorEntry* pEntry, sal_uInt16 nPos, Bitmap* )
908 RemoveEntry( nPos );
909 InsertEntry( pEntry->GetColor(), pEntry->GetName(), nPos );
912 // Fills the Listbox with color and strings
914 void FillAttrLB::Fill( const XColorListRef &pColorTab )
916 long nCount = pColorTab->Count();
917 XColorEntry* pEntry;
918 SetUpdateMode( sal_False );
920 for( long i = 0; i < nCount; i++ )
922 pEntry = pColorTab->GetColor( i );
923 InsertEntry( pEntry->GetColor(), pEntry->GetName() );
925 SetUpdateMode( sal_True );
928 // Fills the listbox (provisional) with strings
930 HatchingLB::HatchingLB( Window* pParent, ResId Id, sal_Bool bUserDraw /*= sal_True*/ )
931 : ListBox( pParent, Id ),
932 mpList ( NULL ),
933 mbUserDraw( bUserDraw )
935 EnableUserDraw( mbUserDraw );
938 void HatchingLB::Fill( const XHatchListRef &pList )
940 mpList = pList;
941 XHatchEntry* pEntry;
942 long nCount = pList->Count();
944 SetUpdateMode( sal_False );
946 if( mbUserDraw )
948 for( long i = 0; i < nCount; i++ )
949 InsertEntry( pList->GetHatch( i )->GetName() );
951 else
953 for( long i = 0; i < nCount; i++ )
955 pEntry = pList->GetHatch( i );
956 Bitmap* pBitmap = pList->GetBitmap( i );
957 if( pBitmap )
958 InsertEntry( pEntry->GetName(), *pBitmap );
959 else
960 InsertEntry( pEntry->GetName() );
964 SetUpdateMode( sal_True );
967 void HatchingLB::UserDraw( const UserDrawEvent& rUDEvt )
969 if( mpList != NULL )
971 // Draw gradient with borderrectangle
972 const Rectangle& rDrawRect = rUDEvt.GetRect();
973 Rectangle aRect( rDrawRect.nLeft+1, rDrawRect.nTop+1, rDrawRect.nLeft+33, rDrawRect.nBottom-1 );
975 sal_Int32 nId = rUDEvt.GetItemId();
976 if( nId >= 0 && nId <= mpList->Count() )
978 OutputDevice* pDevice = rUDEvt.GetDevice();
980 sal_uIntPtr nOldDrawMode = pDevice->GetDrawMode();
981 pDevice->SetDrawMode( GetSettings().GetStyleSettings().GetHighContrastMode() ? OUTPUT_DRAWMODE_CONTRAST : OUTPUT_DRAWMODE_COLOR );
983 XHatch& rXHatch = mpList->GetHatch( rUDEvt.GetItemId() )->GetHatch();
984 MapMode aMode( MAP_100TH_MM );
985 Hatch aHatch( (HatchStyle) rXHatch.GetHatchStyle(),
986 rXHatch.GetColor(),
987 rUDEvt.GetDevice()->LogicToPixel( Point( rXHatch.GetDistance(), 0 ), aMode ).X(),
988 (sal_uInt16)rXHatch.GetAngle() );
989 const Polygon aPolygon( aRect );
990 const PolyPolygon aPolypoly( aPolygon );
991 pDevice->DrawHatch( aPolypoly, aHatch );
993 pDevice->SetLineColor( COL_BLACK );
994 pDevice->SetFillColor();
995 pDevice->DrawRect( aRect );
997 pDevice->SetDrawMode( nOldDrawMode );
999 // Draw name
1000 pDevice->DrawText( Point( aRect.nRight+7, aRect.nTop-1 ), mpList->GetHatch( rUDEvt.GetItemId() )->GetName() );
1005 /************************************************************************/
1007 void HatchingLB::Append( XHatchEntry* pEntry, Bitmap* pBmp )
1009 if( pBmp )
1010 InsertEntry( pEntry->GetName(), *pBmp );
1011 else
1012 InsertEntry( pEntry->GetName() );
1015 /************************************************************************/
1017 void HatchingLB::Modify( XHatchEntry* pEntry, sal_uInt16 nPos, Bitmap* pBmp )
1019 RemoveEntry( nPos );
1021 if( pBmp )
1022 InsertEntry( pEntry->GetName(), *pBmp, nPos );
1023 else
1024 InsertEntry( pEntry->GetName(), nPos );
1027 // Fills the listbox (provisional) with strings
1029 void FillAttrLB::Fill( const XHatchListRef &pList )
1031 long nCount = pList->Count();
1032 XHatchEntry* pEntry;
1033 ListBox::SetUpdateMode( sal_False );
1035 for( long i = 0; i < nCount; i++ )
1037 pEntry = pList->GetHatch( i );
1038 Bitmap* pBitmap = pList->GetBitmap( i );
1039 if( pBitmap )
1040 ListBox::InsertEntry( pEntry->GetName(), *pBitmap );
1041 else
1042 InsertEntry( pEntry->GetName() );
1044 ListBox::SetUpdateMode( sal_True );
1047 // Fills the listbox (provisional) with strings
1049 GradientLB::GradientLB( Window* pParent, ResId Id, sal_Bool bUserDraw /*= sal_True*/ )
1050 : ListBox( pParent, Id ),
1051 mpList(NULL),
1052 mbUserDraw( bUserDraw )
1054 EnableUserDraw( mbUserDraw);
1057 void GradientLB::Fill( const XGradientListRef &pList )
1059 mpList = pList;
1060 XGradientEntry* pEntry;
1061 long nCount = pList->Count();
1063 SetUpdateMode( sal_False );
1065 if( mbUserDraw )
1067 for( long i = 0; i < nCount; i++ )
1068 InsertEntry( pList->GetGradient( i )->GetName() );
1070 else
1072 for( long i = 0; i < nCount; i++ )
1074 pEntry = pList->GetGradient( i );
1075 Bitmap* pBitmap = pList->GetBitmap( i );
1076 if( pBitmap )
1077 InsertEntry( pEntry->GetName(), *pBitmap );
1078 else
1079 InsertEntry( pEntry->GetName() );
1083 SetUpdateMode( sal_True );
1086 void GradientLB::UserDraw( const UserDrawEvent& rUDEvt )
1088 if( mpList != NULL )
1090 // Draw gradient with borderrectangle
1091 const Rectangle& rDrawRect = rUDEvt.GetRect();
1092 Rectangle aRect( rDrawRect.nLeft+1, rDrawRect.nTop+1, rDrawRect.nLeft+33, rDrawRect.nBottom-1 );
1094 sal_Int32 nId = rUDEvt.GetItemId();
1095 if( nId >= 0 && nId <= mpList->Count() )
1097 OutputDevice* pDevice = rUDEvt.GetDevice();
1099 XGradient& rXGrad = mpList->GetGradient( rUDEvt.GetItemId() )->GetGradient();
1100 Gradient aGradient( (GradientStyle) rXGrad.GetGradientStyle(), rXGrad.GetStartColor(), rXGrad.GetEndColor() );
1101 aGradient.SetAngle( (sal_uInt16)rXGrad.GetAngle() );
1102 aGradient.SetBorder( rXGrad.GetBorder() );
1103 aGradient.SetOfsX( rXGrad.GetXOffset() );
1104 aGradient.SetOfsY( rXGrad.GetYOffset() );
1105 aGradient.SetStartIntensity( rXGrad.GetStartIntens() );
1106 aGradient.SetEndIntensity( rXGrad.GetEndIntens() );
1107 aGradient.SetSteps( 255 );
1109 // #i76307# always paint the preview in LTR, because this is what the document does
1110 Window* pWin = dynamic_cast<Window*>(pDevice);
1111 if( pWin && pWin->IsRTLEnabled() && Application::GetSettings().GetLayoutRTL())
1113 long nWidth = pDevice->GetOutputSize().Width();
1115 pWin->EnableRTL( sal_False );
1117 Rectangle aMirrorRect( Point( nWidth - aRect.Left() - aRect.GetWidth(), aRect.Top() ),
1118 aRect.GetSize() );
1120 pDevice->DrawGradient( aMirrorRect, aGradient );
1122 pWin->EnableRTL( sal_True );
1124 else
1125 pDevice->DrawGradient( aRect, aGradient );
1127 pDevice->SetLineColor( COL_BLACK );
1128 pDevice->SetFillColor();
1129 pDevice->DrawRect( aRect );
1131 // Draw name
1132 pDevice->DrawText( Point( aRect.nRight+7, aRect.nTop-1 ), mpList->GetGradient( rUDEvt.GetItemId() )->GetName() );
1137 /************************************************************************/
1139 void GradientLB::Append( XGradientEntry* pEntry, Bitmap* pBmp )
1141 if( pBmp )
1142 InsertEntry( pEntry->GetName(), *pBmp );
1143 else
1144 InsertEntry( pEntry->GetName() );
1147 /************************************************************************/
1149 void GradientLB::Modify( XGradientEntry* pEntry, sal_uInt16 nPos, Bitmap* pBmp )
1151 RemoveEntry( nPos );
1153 if( pBmp )
1154 InsertEntry( pEntry->GetName(), *pBmp, nPos );
1155 else
1156 InsertEntry( pEntry->GetName(), nPos );
1159 /************************************************************************/
1161 void GradientLB::SelectEntryByList( const XGradientListRef &pList, const String& rStr,
1162 const XGradient& rGradient, sal_uInt16 nDist )
1164 long nCount = pList->Count();
1165 XGradientEntry* pEntry;
1166 sal_Bool bFound = sal_False;
1167 String aStr;
1169 long i;
1170 for( i = 0; i < nCount && !bFound; i++ )
1172 pEntry = pList->GetGradient( i );
1174 aStr = pEntry->GetName();
1176 if( rStr == aStr && rGradient == pEntry->GetGradient() )
1177 bFound = sal_True;
1179 if( bFound )
1180 SelectEntryPos( (sal_uInt16) ( i - 1 + nDist ) );
1183 // Fills the listbox (provisional) with strings
1185 void FillAttrLB::Fill( const XGradientListRef &pList )
1187 long nCount = pList->Count();
1188 XGradientEntry* pEntry;
1189 ListBox::SetUpdateMode( sal_False );
1191 for( long i = 0; i < nCount; i++ )
1193 pEntry = pList->GetGradient( i );
1194 Bitmap* pBitmap = pList->GetBitmap( i );
1195 if( pBitmap )
1196 ListBox::InsertEntry( pEntry->GetName(), *pBitmap );
1197 else
1198 InsertEntry( pEntry->GetName() );
1200 ListBox::SetUpdateMode( sal_True );
1203 // BitmapLB Constructor
1205 BitmapLB::BitmapLB( Window* pParent, ResId Id, sal_Bool bUserDraw /*= sal_True*/ )
1206 : ListBox( pParent, Id ),
1207 mpList( NULL ),
1208 mbUserDraw( bUserDraw )
1210 aVD.SetOutputSizePixel( Size( 32, 16 ) );
1211 EnableUserDraw( mbUserDraw );
1214 /************************************************************************/
1216 void BitmapLB::SetVirtualDevice()
1218 if( aBitmap.GetSizePixel().Width() > 8 ||
1219 aBitmap.GetSizePixel().Height() > 8 )
1221 aVD.DrawBitmap( Point( 0, 0 ), Size( 32, 16 ), aBitmap );
1223 else
1225 aVD.DrawBitmap( Point( 0, 0 ), aBitmap );
1226 aVD.DrawBitmap( Point( 8, 0 ), aBitmap );
1227 aVD.DrawBitmap( Point( 16, 0 ), aBitmap );
1228 aVD.DrawBitmap( Point( 24, 0 ), aBitmap );
1229 aVD.DrawBitmap( Point( 0, 8 ), aBitmap );
1230 aVD.DrawBitmap( Point( 8, 8 ), aBitmap );
1231 aVD.DrawBitmap( Point( 16, 8 ), aBitmap );
1232 aVD.DrawBitmap( Point( 24, 8 ), aBitmap );
1236 /************************************************************************/
1238 void BitmapLB::Fill( const XBitmapListRef &pList )
1240 mpList = pList;
1241 XBitmapEntry* pEntry;
1242 long nCount = pList->Count();
1244 SetUpdateMode( sal_False );
1246 if( mbUserDraw )
1248 for( long i = 0; i < nCount; i++ )
1249 InsertEntry( pList->GetBitmap( i )->GetName() );
1251 else
1253 for( long i = 0; i < nCount; i++ )
1255 pEntry = pList->GetBitmap( i );
1256 aBitmap = pEntry->GetXBitmap().GetBitmap();
1258 SetVirtualDevice();
1260 InsertEntry( pEntry->GetName(), aVD.GetBitmap( Point( 0, 2 ), Size( 32, 12 ) ) );
1264 SetUpdateMode( sal_True );
1267 void BitmapLB::UserDraw( const UserDrawEvent& rUDEvt )
1269 if( mpList != NULL )
1271 // Draw bitmap
1272 const Rectangle& rDrawRect = rUDEvt.GetRect();
1273 Rectangle aRect( rDrawRect.nLeft+1, rDrawRect.nTop+1, rDrawRect.nLeft+33, rDrawRect.nBottom-1 );
1275 sal_Int32 nId = rUDEvt.GetItemId();
1276 if( nId >= 0 && nId <= mpList->Count() )
1278 Rectangle aClipRect( rDrawRect.nLeft+1, rDrawRect.nTop+1, rDrawRect.nRight-1, rDrawRect.nBottom-1 );
1280 OutputDevice* pDevice = rUDEvt.GetDevice();
1281 pDevice->SetClipRegion( Region( aClipRect ) );
1283 aBitmap = mpList->GetBitmap( nId )->GetXBitmap().GetBitmap();
1285 long nPosBaseX = aRect.nLeft;
1286 long nPosBaseY = aRect.nTop;
1288 if( aBitmap.GetSizePixel().Width() > 8 ||
1289 aBitmap.GetSizePixel().Height() > 8 )
1291 pDevice->DrawBitmap( Point( nPosBaseX, nPosBaseY ), Size( 32, 16 ), aBitmap );
1293 else
1295 pDevice->DrawBitmap( Point( nPosBaseX+ 0, nPosBaseY+0 ), aBitmap );
1296 pDevice->DrawBitmap( Point( nPosBaseX+ 8, nPosBaseY+0 ), aBitmap );
1297 pDevice->DrawBitmap( Point( nPosBaseX+16, nPosBaseY+0 ), aBitmap );
1298 pDevice->DrawBitmap( Point( nPosBaseX+24, nPosBaseY+0 ), aBitmap );
1299 pDevice->DrawBitmap( Point( nPosBaseX+ 0, nPosBaseY+8 ), aBitmap );
1300 pDevice->DrawBitmap( Point( nPosBaseX+ 8, nPosBaseY+8 ), aBitmap );
1301 pDevice->DrawBitmap( Point( nPosBaseX+16, nPosBaseY+8 ), aBitmap );
1302 pDevice->DrawBitmap( Point( nPosBaseX+24, nPosBaseY+8 ), aBitmap );
1305 pDevice->SetClipRegion();
1307 // Draw name
1308 pDevice->DrawText( Point( aRect.nRight+7, aRect.nTop-1 ), mpList->GetBitmap( nId )->GetName() );
1313 /************************************************************************/
1315 void BitmapLB::Append( XBitmapEntry* pEntry, Bitmap* pBmp )
1317 if( pBmp )
1319 aBitmap = pEntry->GetXBitmap().GetBitmap();
1320 SetVirtualDevice();
1321 InsertEntry( pEntry->GetName(), aVD.GetBitmap( Point( 0, 2 ), Size( 32, 12 ) ) );
1323 else
1324 InsertEntry( pEntry->GetName() );
1327 /************************************************************************/
1329 void BitmapLB::Modify( XBitmapEntry* pEntry, sal_uInt16 nPos, Bitmap* pBmp )
1331 RemoveEntry( nPos );
1333 if( pBmp )
1335 aBitmap = pEntry->GetXBitmap().GetBitmap();
1336 SetVirtualDevice();
1338 InsertEntry( pEntry->GetName(), aVD.GetBitmap( Point( 0, 2 ), Size( 32, 12 ) ), nPos );
1340 else
1341 InsertEntry( pEntry->GetName() );
1344 // FillAttrLB Constructor
1346 FillAttrLB::FillAttrLB( Window* pParent, WinBits aWB ) :
1347 ColorListBox( pParent, aWB )
1349 aVD.SetOutputSizePixel( Size( 32, 16 ) );
1352 /************************************************************************/
1354 void FillAttrLB::SetVirtualDevice()
1356 if( aBitmap.GetSizePixel().Width() > 8 ||
1357 aBitmap.GetSizePixel().Height() > 8 )
1359 aVD.DrawBitmap( Point( 0, 0 ), Size( 32, 16 ), aBitmap );
1361 else
1363 aVD.DrawBitmap( Point( 0, 0 ), aBitmap );
1364 aVD.DrawBitmap( Point( 8, 0 ), aBitmap );
1365 aVD.DrawBitmap( Point( 16, 0 ), aBitmap );
1366 aVD.DrawBitmap( Point( 24, 0 ), aBitmap );
1367 aVD.DrawBitmap( Point( 0, 8 ), aBitmap );
1368 aVD.DrawBitmap( Point( 8, 8 ), aBitmap );
1369 aVD.DrawBitmap( Point( 16, 8 ), aBitmap );
1370 aVD.DrawBitmap( Point( 24, 8 ), aBitmap );
1374 /************************************************************************/
1376 void FillAttrLB::Fill( const XBitmapListRef &pList )
1378 long nCount = pList->Count();
1379 XBitmapEntry* pEntry;
1380 ListBox::SetUpdateMode( sal_False );
1382 for( long i = 0; i < nCount; i++ )
1384 pEntry = pList->GetBitmap( i );
1385 aBitmap = pEntry->GetXBitmap().GetBitmap();
1387 SetVirtualDevice();
1389 ListBox::InsertEntry( pEntry->GetName(), aVD.GetBitmap( Point( 0, 2 ), Size( 32, 12 ) ) );
1391 ListBox::SetUpdateMode( sal_True );
1394 // Fills the listbox (provisional) with strings
1396 void FillTypeLB::Fill()
1398 SetUpdateMode( sal_False );
1399 InsertEntry( String( SVX_RES( RID_SVXSTR_INVISIBLE ) ) );
1400 InsertEntry( String( SVX_RES( RID_SVXSTR_COLOR ) ) );
1401 InsertEntry( String( SVX_RES( RID_SVXSTR_GRADIENT ) ) );
1402 InsertEntry( String( SVX_RES( RID_SVXSTR_HATCH ) ) );
1403 InsertEntry( String( SVX_RES( RID_SVXSTR_BITMAP ) ) );
1404 SetUpdateMode( sal_True );
1407 // Fills the listbox (provisional) with strings
1409 void LineLB::Fill( const XDashListRef &pList )
1411 long nCount = pList->Count();
1412 XDashEntry* pEntry;
1413 SetUpdateMode( sal_False );
1415 for( long i = 0; i < nCount; i++ )
1417 pEntry = pList->GetDash( i );
1418 Bitmap* pBitmap = pList->CreateBitmapForUI( i );
1419 if( pBitmap )
1421 InsertEntry( pEntry->GetName(), *pBitmap );
1422 delete pBitmap;
1424 else
1425 InsertEntry( pEntry->GetName() );
1427 SetUpdateMode( sal_True );
1430 void LineLB::FillStyles()
1432 ResMgr& rMgr = DIALOG_MGR();
1434 // Line Styles
1435 Clear();
1436 InsertEntry( String( ResId( RID_SVXSTR_INVISIBLE, rMgr ) ) );
1438 const StyleSettings& rStyles = Application::GetSettings().GetStyleSettings();
1439 Bitmap aBitmap ( SVX_RES ( RID_SVXCTRL_LINECTRL ) );
1440 Color aSourceColors[2];
1441 Color aDestColors[2];
1443 aSourceColors[0] = Color( COL_WHITE );
1444 aSourceColors[1] = Color( COL_BLACK );
1446 aDestColors[0] = rStyles.GetFieldColor();
1447 aDestColors[1] = rStyles.GetFieldTextColor();
1449 aBitmap.Replace ( aSourceColors, aDestColors, 2 );
1450 Image aSolidLine ( aBitmap );
1451 InsertEntry( String( ResId( RID_SVXSTR_SOLID, rMgr ) ), aSolidLine );
1454 /************************************************************************/
1456 void LineLB::Append( XDashEntry* pEntry, Bitmap* pBmp )
1458 if( pBmp )
1459 InsertEntry( pEntry->GetName(), *pBmp );
1460 else
1461 InsertEntry( pEntry->GetName() );
1464 /************************************************************************/
1466 void LineLB::Modify( XDashEntry* pEntry, sal_uInt16 nPos, Bitmap* pBmp )
1468 RemoveEntry( nPos );
1470 if( pBmp )
1471 InsertEntry( pEntry->GetName(), *pBmp, nPos );
1472 else
1473 InsertEntry( pEntry->GetName(), nPos );
1476 // Fills the listbox (provisional) with strings
1478 void LineEndLB::Fill( const XLineEndListRef &pList, sal_Bool bStart )
1480 long nCount = pList->Count();
1481 XLineEndEntry* pEntry;
1482 VirtualDevice aVD;
1483 SetUpdateMode( sal_False );
1485 for( long i = 0; i < nCount; i++ )
1487 pEntry = pList->GetLineEnd( i );
1488 Bitmap* pBitmap = pList->CreateBitmapForUI( i );
1489 if( pBitmap )
1491 Size aBmpSize( pBitmap->GetSizePixel() );
1492 aVD.SetOutputSizePixel( aBmpSize, sal_False );
1493 aVD.DrawBitmap( Point(), *pBitmap );
1494 InsertEntry( pEntry->GetName(),
1495 aVD.GetBitmap( bStart ? Point() : Point( aBmpSize.Width() / 2, 0 ),
1496 Size( aBmpSize.Width() / 2, aBmpSize.Height() ) ) );
1498 delete pBitmap;
1500 else
1501 InsertEntry( pEntry->GetName() );
1503 SetUpdateMode( sal_True );
1506 /************************************************************************/
1508 void LineEndLB::Append( XLineEndEntry* pEntry, Bitmap* pBmp,
1509 sal_Bool bStart )
1511 if( pBmp )
1513 VirtualDevice aVD;
1514 Size aBmpSize( pBmp->GetSizePixel() );
1516 aVD.SetOutputSizePixel( aBmpSize, sal_False );
1517 aVD.DrawBitmap( Point(), *pBmp );
1518 InsertEntry( pEntry->GetName(),
1519 aVD.GetBitmap( bStart ? Point() : Point( aBmpSize.Width() / 2, 0 ),
1520 Size( aBmpSize.Width() / 2, aBmpSize.Height() ) ) );
1522 else
1523 InsertEntry( pEntry->GetName() );
1526 /************************************************************************/
1528 void LineEndLB::Modify( XLineEndEntry* pEntry, sal_uInt16 nPos, Bitmap* pBmp,
1529 sal_Bool bStart )
1531 RemoveEntry( nPos );
1533 if( pBmp )
1535 VirtualDevice aVD;
1536 Size aBmpSize( pBmp->GetSizePixel() );
1538 aVD.SetOutputSizePixel( aBmpSize, sal_False );
1539 aVD.DrawBitmap( Point(), *pBmp );
1540 InsertEntry( pEntry->GetName(),
1541 aVD.GetBitmap( bStart ? Point() : Point( aBmpSize.Width() / 2, 0 ),
1542 Size( aBmpSize.Width() / 2, aBmpSize.Height() ) ), nPos );
1544 else
1545 InsertEntry( pEntry->GetName(), nPos );
1548 //////////////////////////////////////////////////////////////////////////////
1550 void SvxPreviewBase::InitSettings(bool bForeground, bool bBackground)
1552 const StyleSettings& rStyleSettings = Application::GetSettings().GetStyleSettings();
1554 if(bForeground)
1556 svtools::ColorConfig aColorConfig;
1557 Color aTextColor(aColorConfig.GetColorValue(svtools::FONTCOLOR).nColor);
1559 if(IsControlForeground())
1561 aTextColor = GetControlForeground();
1564 getBufferDevice().SetTextColor(aTextColor);
1567 if(bBackground)
1569 if(IsControlBackground())
1571 getBufferDevice().SetBackground(GetControlBackground());
1573 else
1575 getBufferDevice().SetBackground(rStyleSettings.GetWindowColor());
1579 // do not paint background self, it gets painted buffered
1580 SetControlBackground();
1581 SetBackground();
1583 Invalidate();
1586 SvxPreviewBase::SvxPreviewBase( Window* pParent, const ResId& rResId )
1587 : Control( pParent, rResId ),
1588 mpModel( new SdrModel() ),
1589 mpBufferDevice( new VirtualDevice(*this) )
1591 // Draw the control's border as a flat thin black line.
1592 SetBorderStyle(WINDOW_BORDER_MONO);
1593 SetDrawMode( GetSettings().GetStyleSettings().GetHighContrastMode() ? OUTPUT_DRAWMODE_CONTRAST : OUTPUT_DRAWMODE_COLOR );
1594 SetMapMode(MAP_100TH_MM);
1596 // init model
1597 mpModel->GetItemPool().FreezeIdRanges();
1600 SvxPreviewBase::~SvxPreviewBase()
1602 delete mpModel;
1603 delete mpBufferDevice;
1606 void SvxPreviewBase::LocalPrePaint()
1608 // init BufferDevice
1609 if(mpBufferDevice->GetOutputSizePixel() != GetOutputSizePixel())
1611 mpBufferDevice->SetDrawMode(GetDrawMode());
1612 mpBufferDevice->SetSettings(GetSettings());
1613 mpBufferDevice->SetAntialiasing(GetAntialiasing());
1614 mpBufferDevice->SetOutputSizePixel(GetOutputSizePixel());
1615 mpBufferDevice->SetMapMode(GetMapMode());
1618 mpBufferDevice->Erase();
1621 void SvxPreviewBase::LocalPostPaint()
1623 // copy to front (in pixel mode)
1624 const bool bWasEnabledSrc(mpBufferDevice->IsMapModeEnabled());
1625 const bool bWasEnabledDst(IsMapModeEnabled());
1626 const Point aEmptyPoint;
1628 mpBufferDevice->EnableMapMode(false);
1629 EnableMapMode(false);
1631 DrawOutDev(
1632 aEmptyPoint, GetOutputSizePixel(),
1633 aEmptyPoint, GetOutputSizePixel(),
1634 *mpBufferDevice);
1636 mpBufferDevice->EnableMapMode(bWasEnabledSrc);
1637 EnableMapMode(bWasEnabledDst);
1640 void SvxPreviewBase::StateChanged(StateChangedType nType)
1642 Control::StateChanged(nType);
1644 if(STATE_CHANGE_CONTROLFOREGROUND == nType)
1646 InitSettings(true, false);
1648 else if(STATE_CHANGE_CONTROLBACKGROUND == nType)
1650 InitSettings(false, true);
1654 void SvxPreviewBase::DataChanged(const DataChangedEvent& rDCEvt)
1656 SetDrawMode(GetSettings().GetStyleSettings().GetHighContrastMode() ? OUTPUT_DRAWMODE_CONTRAST : OUTPUT_DRAWMODE_COLOR);
1658 if((DATACHANGED_SETTINGS == rDCEvt.GetType()) && (rDCEvt.GetFlags() & SETTINGS_STYLE))
1660 InitSettings(true, true);
1662 else
1664 Control::DataChanged(rDCEvt);
1668 SvxXLinePreview::SvxXLinePreview( Window* pParent, const ResId& rResId )
1669 : SvxPreviewBase( pParent, rResId ),
1670 mpLineObjA( 0L ),
1671 mpLineObjB( 0L ),
1672 mpLineObjC( 0L ),
1673 mpGraphic( 0L ),
1674 mbWithSymbol( sal_False )
1676 const Size aOutputSize(GetOutputSize());
1677 InitSettings( sal_True, sal_True );
1679 const sal_Int32 nDistance(500L);
1680 const sal_Int32 nAvailableLength(aOutputSize.Width() - (4 * nDistance));
1682 // create DrawObectA
1683 const sal_Int32 aYPosA(aOutputSize.Height() / 2);
1684 const basegfx::B2DPoint aPointA1( nDistance, aYPosA);
1685 const basegfx::B2DPoint aPointA2( aPointA1.getX() + ((nAvailableLength * 14) / 20), aYPosA );
1686 basegfx::B2DPolygon aPolygonA;
1687 aPolygonA.append(aPointA1);
1688 aPolygonA.append(aPointA2);
1689 mpLineObjA = new SdrPathObj(OBJ_LINE, basegfx::B2DPolyPolygon(aPolygonA));
1690 mpLineObjA->SetModel(&getModel());
1692 // create DrawObectB
1693 const sal_Int32 aYPosB1((aOutputSize.Height() * 3) / 4);
1694 const sal_Int32 aYPosB2((aOutputSize.Height() * 1) / 4);
1695 const basegfx::B2DPoint aPointB1( aPointA2.getX() + nDistance, aYPosB1);
1696 const basegfx::B2DPoint aPointB2( aPointB1.getX() + ((nAvailableLength * 2) / 20), aYPosB2 );
1697 const basegfx::B2DPoint aPointB3( aPointB2.getX() + ((nAvailableLength * 2) / 20), aYPosB1 );
1698 basegfx::B2DPolygon aPolygonB;
1699 aPolygonB.append(aPointB1);
1700 aPolygonB.append(aPointB2);
1701 aPolygonB.append(aPointB3);
1702 mpLineObjB = new SdrPathObj(OBJ_PLIN, basegfx::B2DPolyPolygon(aPolygonB));
1703 mpLineObjB->SetModel(&getModel());
1705 // create DrawObectC
1706 const basegfx::B2DPoint aPointC1( aPointB3.getX() + nDistance, aYPosB1);
1707 const basegfx::B2DPoint aPointC2( aPointC1.getX() + ((nAvailableLength * 1) / 20), aYPosB2 );
1708 const basegfx::B2DPoint aPointC3( aPointC2.getX() + ((nAvailableLength * 1) / 20), aYPosB1 );
1709 basegfx::B2DPolygon aPolygonC;
1710 aPolygonC.append(aPointC1);
1711 aPolygonC.append(aPointC2);
1712 aPolygonC.append(aPointC3);
1713 mpLineObjC = new SdrPathObj(OBJ_PLIN, basegfx::B2DPolyPolygon(aPolygonC));
1714 mpLineObjC->SetModel(&getModel());
1717 SvxXLinePreview::~SvxXLinePreview()
1719 SdrObject::Free( mpLineObjA );
1720 SdrObject::Free( mpLineObjB );
1721 SdrObject::Free( mpLineObjC );
1724 // -----------------------------------------------------------------------
1726 void SvxXLinePreview::SetSymbol(Graphic* p,const Size& s)
1728 mpGraphic = p;
1729 maSymbolSize = s;
1732 // -----------------------------------------------------------------------
1734 void SvxXLinePreview::ResizeSymbol(const Size& s)
1736 if ( s != maSymbolSize )
1738 maSymbolSize = s;
1739 Invalidate();
1743 // -----------------------------------------------------------------------
1745 void SvxXLinePreview::SetLineAttributes(const SfxItemSet& rItemSet)
1747 // Set ItemSet at objects
1748 mpLineObjA->SetMergedItemSet(rItemSet);
1750 // At line joints, do not use arrows
1751 SfxItemSet aTempSet(rItemSet);
1752 aTempSet.ClearItem(XATTR_LINESTART);
1753 aTempSet.ClearItem(XATTR_LINEEND);
1755 mpLineObjB->SetMergedItemSet(aTempSet);
1756 mpLineObjC->SetMergedItemSet(aTempSet);
1759 // -----------------------------------------------------------------------
1761 void SvxXLinePreview::Paint( const Rectangle& )
1763 LocalPrePaint();
1765 // paint objects to buffer device
1766 sdr::contact::SdrObjectVector aObjectVector;
1767 aObjectVector.push_back(mpLineObjA);
1768 aObjectVector.push_back(mpLineObjB);
1769 aObjectVector.push_back(mpLineObjC);
1771 sdr::contact::ObjectContactOfObjListPainter aPainter(getBufferDevice(), aObjectVector, 0);
1772 sdr::contact::DisplayInfo aDisplayInfo;
1774 // do processing
1775 aPainter.ProcessDisplay(aDisplayInfo);
1777 if ( mbWithSymbol && mpGraphic )
1779 const Size aOutputSize(GetOutputSize());
1780 Point aPos = Point( aOutputSize.Width() / 3, aOutputSize.Height() / 2 );
1781 aPos.X() -= maSymbolSize.Width() / 2;
1782 aPos.Y() -= maSymbolSize.Height() / 2;
1783 mpGraphic->Draw( &getBufferDevice(), aPos, maSymbolSize );
1786 LocalPostPaint();
1789 SvxXRectPreview::SvxXRectPreview( Window* pParent, const ResId& rResId )
1790 : SvxPreviewBase( pParent, rResId ),
1791 mpRectangleObject(0)
1793 InitSettings(true, true);
1795 // create RectangleObject
1796 const Rectangle aObjectSize(Point(), GetOutputSize());
1797 mpRectangleObject = new SdrRectObj(aObjectSize);
1798 mpRectangleObject->SetModel(&getModel());
1801 SvxXRectPreview::~SvxXRectPreview()
1803 SdrObject::Free(mpRectangleObject);
1806 void SvxXRectPreview::SetAttributes(const SfxItemSet& rItemSet)
1808 mpRectangleObject->SetMergedItemSet(rItemSet, true);
1809 mpRectangleObject->SetMergedItem(XLineStyleItem(XLINE_NONE));
1812 void SvxXRectPreview::Paint( const Rectangle& )
1814 LocalPrePaint();
1816 sdr::contact::SdrObjectVector aObjectVector;
1818 aObjectVector.push_back(mpRectangleObject);
1820 sdr::contact::ObjectContactOfObjListPainter aPainter(getBufferDevice(), aObjectVector, 0);
1821 sdr::contact::DisplayInfo aDisplayInfo;
1823 aPainter.ProcessDisplay(aDisplayInfo);
1825 LocalPostPaint();
1828 SvxXShadowPreview::SvxXShadowPreview( Window* pParent, const ResId& rResId )
1829 : SvxPreviewBase( pParent, rResId ),
1830 mpRectangleObject(0),
1831 mpRectangleShadow(0)
1833 InitSettings(true, true);
1835 // prepare size
1836 Size aSize = GetOutputSize();
1837 aSize.Width() = aSize.Width() / 3;
1838 aSize.Height() = aSize.Height() / 3;
1840 // create RectangleObject
1841 const Rectangle aObjectSize( Point( aSize.Width(), aSize.Height() ), aSize );
1842 mpRectangleObject = new SdrRectObj(aObjectSize);
1843 mpRectangleObject->SetModel(&getModel());
1845 // create ShadowObject
1846 const Rectangle aShadowSize( Point( aSize.Width(), aSize.Height() ), aSize );
1847 mpRectangleShadow = new SdrRectObj(aShadowSize);
1848 mpRectangleShadow->SetModel(&getModel());
1851 SvxXShadowPreview::~SvxXShadowPreview()
1853 SdrObject::Free(mpRectangleObject);
1854 SdrObject::Free(mpRectangleShadow);
1857 void SvxXShadowPreview::SetRectangleAttributes(const SfxItemSet& rItemSet)
1859 mpRectangleObject->SetMergedItemSet(rItemSet, true);
1860 mpRectangleObject->SetMergedItem(XLineStyleItem(XLINE_NONE));
1863 void SvxXShadowPreview::SetShadowAttributes(const SfxItemSet& rItemSet)
1865 mpRectangleShadow->SetMergedItemSet(rItemSet, true);
1866 mpRectangleShadow->SetMergedItem(XLineStyleItem(XLINE_NONE));
1869 void SvxXShadowPreview::SetShadowPosition(const Point& rPos)
1871 Rectangle aObjectPosition(mpRectangleObject->GetSnapRect());
1872 aObjectPosition.Move(rPos.X(), rPos.Y());
1873 mpRectangleShadow->SetSnapRect(aObjectPosition);
1876 void SvxXShadowPreview::Paint( const Rectangle& )
1878 LocalPrePaint();
1880 sdr::contact::SdrObjectVector aObjectVector;
1882 aObjectVector.push_back(mpRectangleShadow);
1883 aObjectVector.push_back(mpRectangleObject);
1885 sdr::contact::ObjectContactOfObjListPainter aPainter(getBufferDevice(), aObjectVector, 0);
1886 sdr::contact::DisplayInfo aDisplayInfo;
1888 aPainter.ProcessDisplay(aDisplayInfo);
1890 LocalPostPaint();
1893 // -----------------------------------------------------------------------
1894 // eof
1896 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */