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