Bump version to 6.4.7.2.M8
[LibreOffice.git] / svx / source / dialog / dlgctrl.cxx
blob7a9b7186a25742478f191ffa3db2ec7cc52d891a
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <vcl/svapp.hxx>
21 #include <vcl/settings.hxx>
22 #include <vcl/virdev.hxx>
23 #include <vcl/event.hxx>
24 #include <sfx2/dialoghelper.hxx>
25 #include <svx/xlineit0.hxx>
26 #include <svx/xtable.hxx>
27 #include <svx/xpool.hxx>
28 #include <svx/strings.hrc>
29 #include <bitmaps.hlst>
30 #include <svx/dlgctrl.hxx>
31 #include <svx/dialmgr.hxx>
32 #include <tools/debug.hxx>
33 #include <tools/poly.hxx>
34 #include <vcl/region.hxx>
35 #include <vcl/gradient.hxx>
36 #include <vcl/hatch.hxx>
37 #include <com/sun/star/accessibility/AccessibleEventObject.hpp>
38 #include <com/sun/star/accessibility/AccessibleEventId.hpp>
39 #include <com/sun/star/accessibility/AccessibleStateType.hpp>
40 #include <svxpixelctlaccessiblecontext.hxx>
41 #include <svtools/colorcfg.hxx>
42 #include <svxrectctaccessiblecontext.hxx>
43 #include <com/sun/star/lang/XUnoTunnel.hpp>
44 #include <basegfx/point/b2dpoint.hxx>
45 #include <basegfx/polygon/b2dpolygon.hxx>
46 #include <svx/svdorect.hxx>
47 #include <svx/svdmodel.hxx>
48 #include <svx/svdopath.hxx>
49 #include <svx/sdr/contact/objectcontactofobjlistpainter.hxx>
50 #include <svx/sdr/contact/displayinfo.hxx>
51 #include <vcl/bitmapaccess.hxx>
52 #include <vcl/BitmapTools.hxx>
53 #include <svx/xbtmpit.hxx>
55 #define OUTPUT_DRAWMODE_COLOR (DrawModeFlags::Default)
56 #define OUTPUT_DRAWMODE_CONTRAST (DrawModeFlags::SettingsLine | DrawModeFlags::SettingsFill | DrawModeFlags::SettingsText | DrawModeFlags::SettingsGradient)
58 using namespace ::com::sun::star;
59 using namespace ::com::sun::star::uno;
60 using namespace ::com::sun::star::lang;
61 using namespace ::com::sun::star::accessibility;
63 // Control for display and selection of the corner points and
64 // mid point of an object
66 BitmapEx& SvxRectCtl::GetRectBitmap()
68 if( !pBitmap )
69 InitRectBitmap();
71 return *pBitmap;
74 SvxRectCtl::SvxRectCtl(SvxTabPage* pPage, RectPoint eRpt, sal_uInt16 nBorder)
75 : m_pPage(pPage)
76 , nBorderWidth(Application::GetDefaultDevice()->LogicToPixel(Size(nBorder, 0), MapMode(MapUnit::Map100thMM)).Width())
77 , eRP(eRpt)
78 , eDefRP(eRpt)
79 , m_nState(CTL_STATE::NONE)
80 , mbCompleteDisable(false)
84 void SvxRectCtl::SetDrawingArea(weld::DrawingArea* pDrawingArea)
86 CustomWidgetController::SetDrawingArea(pDrawingArea);
87 Size aSize(pDrawingArea->get_approximate_digit_width() * 25,
88 pDrawingArea->get_text_height() * 5);
89 pDrawingArea->set_size_request(aSize.Width(), aSize.Height());
90 Resize_Impl(aSize);
93 void SvxRectCtl::SetControlSettings(RectPoint eRpt, sal_uInt16 nBorder)
95 nBorderWidth = Application::GetDefaultDevice()->LogicToPixel(Size(nBorder, 0), MapMode(MapUnit::Map100thMM)).Width();
96 eDefRP = eRpt;
97 Resize();
100 SvxRectCtl::~SvxRectCtl()
102 pBitmap.reset();
103 pAccContext.clear();
106 void SvxRectCtl::Resize()
108 Resize_Impl(GetOutputSizePixel());
111 void SvxRectCtl::Resize_Impl(const Size &rSize)
113 aPtLT = Point( 0 + nBorderWidth, 0 + nBorderWidth );
114 aPtMT = Point( rSize.Width() / 2, 0 + nBorderWidth );
115 aPtRT = Point( rSize.Width() - nBorderWidth, 0 + nBorderWidth );
117 aPtLM = Point( 0 + nBorderWidth, rSize.Height() / 2 );
118 aPtMM = Point( rSize.Width() / 2, rSize.Height() / 2 );
119 aPtRM = Point( rSize.Width() - nBorderWidth, rSize.Height() / 2 );
121 aPtLB = Point( 0 + nBorderWidth, rSize.Height() - nBorderWidth );
122 aPtMB = Point( rSize.Width() / 2, rSize.Height() - nBorderWidth );
123 aPtRB = Point( rSize.Width() - nBorderWidth, rSize.Height() - nBorderWidth );
125 Reset();
126 StyleUpdated();
129 void SvxRectCtl::InitRectBitmap()
131 pBitmap.reset();
133 const StyleSettings& rStyles = Application::GetSettings().GetStyleSettings();
134 svtools::ColorConfig aColorConfig;
136 pBitmap.reset(new BitmapEx(RID_SVXCTRL_RECTBTNS));
138 // set bitmap-colors
139 Color aColorAry1[7];
140 Color aColorAry2[7];
141 aColorAry1[0] = Color( 0xC0, 0xC0, 0xC0 ); // light-gray
142 aColorAry1[1] = Color( 0xFF, 0xFF, 0x00 ); // yellow
143 aColorAry1[2] = Color( 0xFF, 0xFF, 0xFF ); // white
144 aColorAry1[3] = Color( 0x80, 0x80, 0x80 ); // dark-gray
145 aColorAry1[4] = Color( 0x00, 0x00, 0x00 ); // black
146 aColorAry1[5] = Color( 0x00, 0xFF, 0x00 ); // green
147 aColorAry1[6] = Color( 0x00, 0x00, 0xFF ); // blue
148 aColorAry2[0] = rStyles.GetDialogColor(); // background
149 aColorAry2[1] = rStyles.GetWindowColor();
150 aColorAry2[2] = rStyles.GetLightColor();
151 aColorAry2[3] = rStyles.GetShadowColor();
152 aColorAry2[4] = rStyles.GetDarkShadowColor();
153 aColorAry2[5] = aColorConfig.GetColorValue( svtools::FONTCOLOR ).nColor;
154 aColorAry2[6] = rStyles.GetDialogColor();
156 #ifdef DBG_UTIL
157 static bool bModify = false;
158 bool& rModify = bModify;
159 if( rModify )
161 static int n = 0;
162 static sal_uInt8 r = 0xFF;
163 static sal_uInt8 g = 0x00;
164 static sal_uInt8 b = 0xFF;
165 int& rn = n;
166 sal_uInt8& rr = r;
167 sal_uInt8& rg = g;
168 sal_uInt8& rb = b;
169 aColorAry2[ rn ] = Color( rr, rg, rb );
171 #endif
173 pBitmap->Replace( aColorAry1, aColorAry2, 7 );
176 void SvxRectCtl::StyleUpdated()
178 pBitmap.reset(); // forces new creating of bitmap
179 CustomWidgetController::StyleUpdated();
182 void SvxRectCtl::InitSettings(vcl::RenderContext& rRenderContext)
184 svtools::ColorConfig aColorConfig;
185 Color aTextColor(aColorConfig.GetColorValue(svtools::FONTCOLOR).nColor);
186 rRenderContext.SetTextColor(aTextColor);
187 const StyleSettings& rStyleSettings = Application::GetSettings().GetStyleSettings();
188 rRenderContext.SetBackground(rStyleSettings.GetWindowColor());
191 // The clicked rectangle (3 x 3) is determined and the parent (dialog)
192 // is notified that the item was changed
193 bool SvxRectCtl::MouseButtonDown(const MouseEvent& rMEvt)
195 // CompletelyDisabled() added to have a disabled state for SvxRectCtl
196 if(!IsCompletelyDisabled())
198 aPtNew = GetApproxLogPtFromPixPt( rMEvt.GetPosPixel() );
199 eRP = GetRPFromPoint( aPtNew );
200 SetActualRP( eRP );
202 if (m_pPage)
203 m_pPage->PointChanged(GetDrawingArea(), eRP);
205 return true;
208 bool SvxRectCtl::KeyInput(const KeyEvent& rKeyEvt)
210 // CompletelyDisabled() added to have a disabled state for SvxRectCtl
211 if (IsCompletelyDisabled())
212 return false;
214 RectPoint eNewRP = eRP;
216 switch( rKeyEvt.GetKeyCode().GetCode() )
218 case KEY_DOWN:
220 if( !(m_nState & CTL_STATE::NOVERT) )
221 switch( eNewRP )
223 case RectPoint::LT: eNewRP = RectPoint::LM; break;
224 case RectPoint::MT: eNewRP = RectPoint::MM; break;
225 case RectPoint::RT: eNewRP = RectPoint::RM; break;
226 case RectPoint::LM: eNewRP = RectPoint::LB; break;
227 case RectPoint::MM: eNewRP = RectPoint::MB; break;
228 case RectPoint::RM: eNewRP = RectPoint::RB; break;
229 default: ; //prevent warning
232 break;
233 case KEY_UP:
235 if( !(m_nState & CTL_STATE::NOVERT) )
236 switch( eNewRP )
238 case RectPoint::LM: eNewRP = RectPoint::LT; break;
239 case RectPoint::MM: eNewRP = RectPoint::MT; break;
240 case RectPoint::RM: eNewRP = RectPoint::RT; break;
241 case RectPoint::LB: eNewRP = RectPoint::LM; break;
242 case RectPoint::MB: eNewRP = RectPoint::MM; break;
243 case RectPoint::RB: eNewRP = RectPoint::RM; break;
244 default: ; //prevent warning
247 break;
248 case KEY_LEFT:
250 if( !(m_nState & CTL_STATE::NOHORZ) )
251 switch( eNewRP )
253 case RectPoint::MT: eNewRP = RectPoint::LT; break;
254 case RectPoint::RT: eNewRP = RectPoint::MT; break;
255 case RectPoint::MM: eNewRP = RectPoint::LM; break;
256 case RectPoint::RM: eNewRP = RectPoint::MM; break;
257 case RectPoint::MB: eNewRP = RectPoint::LB; break;
258 case RectPoint::RB: eNewRP = RectPoint::MB; break;
259 default: ; //prevent warning
262 break;
263 case KEY_RIGHT:
265 if( !(m_nState & CTL_STATE::NOHORZ) )
266 switch( eNewRP )
268 case RectPoint::LT: eNewRP = RectPoint::MT; break;
269 case RectPoint::MT: eNewRP = RectPoint::RT; break;
270 case RectPoint::LM: eNewRP = RectPoint::MM; break;
271 case RectPoint::MM: eNewRP = RectPoint::RM; break;
272 case RectPoint::LB: eNewRP = RectPoint::MB; break;
273 case RectPoint::MB: eNewRP = RectPoint::RB; break;
274 default: ; //prevent warning
277 break;
278 default:
279 return false;
281 if( eNewRP != eRP )
283 SetActualRP( eNewRP );
285 if (m_pPage)
286 m_pPage->PointChanged(GetDrawingArea(), eRP);
288 return true;
291 // the control (rectangle with 9 circles)
292 void SvxRectCtl::Paint(vcl::RenderContext& rRenderContext, const tools::Rectangle&)
294 InitSettings(rRenderContext);
296 Point aPtDiff(1, 1);
298 const StyleSettings& rStyles = Application::GetSettings().GetStyleSettings();
300 rRenderContext.SetLineColor(rStyles.GetDialogColor());
301 rRenderContext.SetFillColor(rStyles.GetDialogColor());
302 rRenderContext.DrawRect(tools::Rectangle(Point(0,0), rRenderContext.GetOutputSize()));
304 if (IsEnabled())
305 rRenderContext.SetLineColor(rStyles.GetLabelTextColor());
306 else
307 rRenderContext.SetLineColor(rStyles.GetShadowColor());
309 rRenderContext.SetFillColor();
311 if (!IsEnabled())
313 Color aOldCol = rRenderContext.GetLineColor();
314 rRenderContext.SetLineColor(rStyles.GetLightColor());
315 rRenderContext.DrawRect(tools::Rectangle(aPtLT + aPtDiff, aPtRB + aPtDiff));
316 rRenderContext.SetLineColor(aOldCol);
318 rRenderContext.DrawRect(tools::Rectangle(aPtLT, aPtRB));
320 rRenderContext.SetFillColor(rRenderContext.GetBackground().GetColor());
322 Size aBtnSize(11, 11);
323 Size aDstBtnSize(aBtnSize);
324 Point aToCenter(aDstBtnSize.Width() >> 1, aDstBtnSize.Height() >> 1);
325 Point aBtnPnt1(IsEnabled() ? 0 : 22, 0);
326 Point aBtnPnt2(11, 0);
327 Point aBtnPnt3(22, 0);
329 bool bNoHorz = bool(m_nState & CTL_STATE::NOHORZ);
330 bool bNoVert = bool(m_nState & CTL_STATE::NOVERT);
332 BitmapEx& rBitmap = GetRectBitmap();
334 // CompletelyDisabled() added to have a disabled state for SvxRectCtl
335 if (IsCompletelyDisabled())
337 rRenderContext.DrawBitmapEx(aPtLT - aToCenter, aDstBtnSize, aBtnPnt3, aBtnSize, rBitmap);
338 rRenderContext.DrawBitmapEx(aPtMT - aToCenter, aDstBtnSize, aBtnPnt3, aBtnSize, rBitmap);
339 rRenderContext.DrawBitmapEx(aPtRT - aToCenter, aDstBtnSize, aBtnPnt3, aBtnSize, rBitmap);
340 rRenderContext.DrawBitmapEx(aPtLM - aToCenter, aDstBtnSize, aBtnPnt3, aBtnSize, rBitmap);
341 rRenderContext.DrawBitmapEx(aPtMM - aToCenter, aDstBtnSize, aBtnPnt3, aBtnSize, rBitmap);
342 rRenderContext.DrawBitmapEx(aPtRM - aToCenter, aDstBtnSize, aBtnPnt3, aBtnSize, rBitmap);
343 rRenderContext.DrawBitmapEx(aPtLB - aToCenter, aDstBtnSize, aBtnPnt3, aBtnSize, rBitmap);
344 rRenderContext.DrawBitmapEx(aPtMB - aToCenter, aDstBtnSize, aBtnPnt3, aBtnSize, rBitmap);
345 rRenderContext.DrawBitmapEx(aPtRB - aToCenter, aDstBtnSize, aBtnPnt3, aBtnSize, rBitmap);
347 else
349 rRenderContext.DrawBitmapEx(aPtLT - aToCenter, aDstBtnSize, (bNoHorz || bNoVert)?aBtnPnt3:aBtnPnt1, aBtnSize, rBitmap);
350 rRenderContext.DrawBitmapEx(aPtMT - aToCenter, aDstBtnSize, bNoVert?aBtnPnt3:aBtnPnt1, aBtnSize, rBitmap);
351 rRenderContext.DrawBitmapEx(aPtRT - aToCenter, aDstBtnSize, (bNoHorz || bNoVert)?aBtnPnt3:aBtnPnt1, aBtnSize, rBitmap);
352 rRenderContext.DrawBitmapEx(aPtLM - aToCenter, aDstBtnSize, bNoHorz?aBtnPnt3:aBtnPnt1, aBtnSize, rBitmap);
354 // Center for rectangle and line
355 rRenderContext.DrawBitmapEx(aPtMM - aToCenter, aDstBtnSize, aBtnPnt1, aBtnSize, rBitmap);
357 rRenderContext.DrawBitmapEx(aPtRM - aToCenter, aDstBtnSize, bNoHorz?aBtnPnt3:aBtnPnt1, aBtnSize, rBitmap);
358 rRenderContext.DrawBitmapEx(aPtLB - aToCenter, aDstBtnSize, (bNoHorz || bNoVert)?aBtnPnt3:aBtnPnt1, aBtnSize, rBitmap);
359 rRenderContext.DrawBitmapEx(aPtMB - aToCenter, aDstBtnSize, bNoVert?aBtnPnt3:aBtnPnt1, aBtnSize, rBitmap);
360 rRenderContext.DrawBitmapEx(aPtRB - aToCenter, aDstBtnSize, (bNoHorz || bNoVert)?aBtnPnt3:aBtnPnt1, aBtnSize, rBitmap);
363 // draw active button, avoid center pos for angle
364 // CompletelyDisabled() added to have a disabled state for SvxRectCtl
365 if (!IsCompletelyDisabled())
367 if (IsEnabled())
369 Point aCenterPt(aPtNew);
370 aCenterPt -= aToCenter;
372 rRenderContext.DrawBitmapEx(aCenterPt, aDstBtnSize, aBtnPnt2, aBtnSize, rBitmap);
377 tools::Rectangle SvxRectCtl::GetFocusRect()
379 tools::Rectangle aRet;
380 if (HasFocus())
381 aRet = CalculateFocusRectangle();
382 return aRet;
385 // Convert RectPoint Point
387 const Point& SvxRectCtl::GetPointFromRP( RectPoint _eRP) const
389 switch( _eRP )
391 case RectPoint::LT: return aPtLT;
392 case RectPoint::MT: return aPtMT;
393 case RectPoint::RT: return aPtRT;
394 case RectPoint::LM: return aPtLM;
395 case RectPoint::MM: return aPtMM;
396 case RectPoint::RM: return aPtRM;
397 case RectPoint::LB: return aPtLB;
398 case RectPoint::MB: return aPtMB;
399 case RectPoint::RB: return aPtRB;
401 return aPtMM; // default
404 Point SvxRectCtl::SetActualRPWithoutInvalidate( RectPoint eNewRP )
406 Point aPtLast = aPtNew;
407 aPtNew = GetPointFromRP( eNewRP );
409 if( m_nState & CTL_STATE::NOHORZ )
410 aPtNew.setX( aPtMM.X() );
412 if( m_nState & CTL_STATE::NOVERT )
413 aPtNew.setY( aPtMM.Y() );
415 // fdo#74751 this fix reverse base point on RTL UI.
416 bool bRTL = AllSettings::GetLayoutRTL();
417 eNewRP = GetRPFromPoint( aPtNew, bRTL );
419 eDefRP = eNewRP;
420 eRP = eNewRP;
422 return aPtLast;
425 void SvxRectCtl::GetFocus()
427 Invalidate();
429 // Send accessibility event.
430 if (pAccContext.is())
432 pAccContext->FireChildFocus(GetActualRP());
436 void SvxRectCtl::LoseFocus()
438 Invalidate();
441 Point SvxRectCtl::GetApproxLogPtFromPixPt( const Point& rPt ) const
443 Point aPt = rPt;
444 long x;
445 long y;
447 Size aSize(GetOutputSizePixel());
449 if( !( m_nState & CTL_STATE::NOHORZ ) )
451 if( aPt.X() < aSize.Width() / 3 )
452 x = aPtLT.X();
453 else if( aPt.X() < aSize.Width() * 2 / 3 )
454 x = aPtMM.X();
455 else
456 x = aPtRB.X();
458 else
459 x = aPtMM.X();
461 if( !( m_nState & CTL_STATE::NOVERT ) )
463 if( aPt.Y() < aSize.Height() / 3 )
464 y = aPtLT.Y();
465 else if( aPt.Y() < aSize.Height() * 2 / 3 )
466 y = aPtMM.Y();
467 else
468 y = aPtRB.Y();
470 else
471 y = aPtMM.Y();
473 return Point( x, y );
477 // Converts Point in RectPoint
479 RectPoint SvxRectCtl::GetRPFromPoint( Point aPt, bool bRTL ) const
481 RectPoint rPoint = RectPoint::MM; // default
483 if (aPt == aPtLT) rPoint = bRTL ? RectPoint::RT : RectPoint::LT;
484 else if( aPt == aPtMT) rPoint = RectPoint::MT;
485 else if( aPt == aPtRT) rPoint = bRTL ? RectPoint::LT : RectPoint::RT;
486 else if( aPt == aPtLM) rPoint = bRTL ? RectPoint::RM : RectPoint::LM;
487 else if( aPt == aPtRM) rPoint = bRTL ? RectPoint::LM : RectPoint::RM;
488 else if( aPt == aPtLB) rPoint = bRTL ? RectPoint::RB : RectPoint::LB;
489 else if( aPt == aPtMB) rPoint = RectPoint::MB;
490 else if( aPt == aPtRB) rPoint = bRTL ? RectPoint::LB : RectPoint::RB;
492 return rPoint;
495 // Resets to the original state of the control
497 void SvxRectCtl::Reset()
499 aPtNew = GetPointFromRP( eDefRP );
500 eRP = eDefRP;
501 Invalidate();
504 // Returns the currently selected RectPoint
507 void SvxRectCtl::SetActualRP( RectPoint eNewRP )
509 SetActualRPWithoutInvalidate(eNewRP);
511 Invalidate();
513 // notify accessibility object about change
514 if (pAccContext.is())
515 pAccContext->selectChild( eNewRP /* MT, bFireFocus */ );
518 void SvxRectCtl::SetState( CTL_STATE nState )
520 m_nState = nState;
522 Point aPtLast( GetPointFromRP( eRP ) );
523 Point _aPtNew( aPtLast );
525 if( m_nState & CTL_STATE::NOHORZ )
526 _aPtNew.setX( aPtMM.X() );
528 if( m_nState & CTL_STATE::NOVERT)
529 _aPtNew.setY( aPtMM.Y() );
531 eRP = GetRPFromPoint( _aPtNew );
532 Invalidate();
534 if (m_pPage)
535 m_pPage->PointChanged(GetDrawingArea(), eRP);
538 tools::Rectangle SvxRectCtl::CalculateFocusRectangle() const
540 Size aDstBtnSize(15, 15);
541 return tools::Rectangle( aPtNew - Point( aDstBtnSize.Width() >> 1, aDstBtnSize.Height() >> 1 ), aDstBtnSize );
544 tools::Rectangle SvxRectCtl::CalculateFocusRectangle( RectPoint eRectPoint ) const
546 tools::Rectangle aRet;
547 RectPoint eOldRectPoint = GetActualRP();
549 if( eOldRectPoint == eRectPoint )
550 aRet = CalculateFocusRectangle();
551 else
553 SvxRectCtl* pThis = const_cast<SvxRectCtl*>(this);
555 pThis->SetActualRPWithoutInvalidate( eRectPoint ); // no invalidation because it's only temporary!
556 aRet = CalculateFocusRectangle();
558 pThis->SetActualRPWithoutInvalidate( eOldRectPoint ); // no invalidation because nothing has changed!
561 return aRet;
564 Reference< XAccessible > SvxRectCtl::CreateAccessible()
566 pAccContext = new SvxRectCtlAccessibleContext(this);
567 return pAccContext.get();
570 RectPoint SvxRectCtl::GetApproxRPFromPixPt( const css::awt::Point& r ) const
572 return GetRPFromPoint( GetApproxLogPtFromPixPt( Point( r.X, r.Y ) ) );
575 // CompletelyDisabled() added to have a disabled state for SvxRectCtl
576 void SvxRectCtl::DoCompletelyDisable(bool bNew)
578 mbCompleteDisable = bNew;
579 Invalidate();
582 // Control for editing bitmaps
584 css::uno::Reference< css::accessibility::XAccessible > SvxPixelCtl::CreateAccessible()
586 if (!m_xAccess.is())
587 m_xAccess = new SvxPixelCtlAccessible(this);
588 return m_xAccess.get();
591 long SvxPixelCtl::PointToIndex(const Point &aPt) const
593 long nX = aPt.X() * nLines / aRectSize.Width();
594 long nY = aPt.Y() * nLines / aRectSize.Height();
596 return nX + nY * nLines ;
599 Point SvxPixelCtl::IndexToPoint(long nIndex) const
601 DBG_ASSERT(nIndex >= 0 && nIndex < nSquares ," Check Index");
603 sal_Int32 nXIndex = nIndex % nLines;
604 sal_Int32 nYIndex = nIndex / nLines;
606 Point aPtTl;
607 aPtTl.setY( aRectSize.Height() * nYIndex / nLines + 1 );
608 aPtTl.setX( aRectSize.Width() * nXIndex / nLines + 1 );
610 return aPtTl;
613 long SvxPixelCtl::GetFocusPosIndex() const
615 return aFocusPosition.getX() + aFocusPosition.getY() * nLines ;
618 long SvxPixelCtl::ShowPosition( const Point &rPt)
620 sal_Int32 nX = rPt.X() * nLines / aRectSize.Width();
621 sal_Int32 nY = rPt.Y() * nLines / aRectSize.Height();
623 ChangePixel( nX + nY * nLines );
625 //Solution:Set new focus position and repaint
626 aFocusPosition.setX(nX);
627 aFocusPosition.setY(nY);
628 Invalidate(tools::Rectangle(Point(0,0),aRectSize));
630 if (m_pPage)
631 m_pPage->PointChanged(GetDrawingArea(), RectPoint::MM ); // RectPoint is dummy
633 return GetFocusPosIndex();
637 SvxPixelCtl::SvxPixelCtl(SvxTabPage* pPage)
638 : m_pPage(pPage)
639 , bPaintable(true)
640 , aFocusPosition(0,0)
642 maPixelData.fill(0);
645 void SvxPixelCtl::Resize()
647 CustomWidgetController::Resize();
648 aRectSize = GetOutputSizePixel();
651 void SvxPixelCtl::SetDrawingArea(weld::DrawingArea* pDrawingArea)
653 CustomWidgetController::SetDrawingArea(pDrawingArea);
654 pDrawingArea->set_size_request(pDrawingArea->get_approximate_digit_width() * 25,
655 pDrawingArea->get_text_height() * 10);
658 SvxPixelCtl::~SvxPixelCtl()
662 // Changes the foreground or Background color
664 void SvxPixelCtl::ChangePixel( sal_uInt16 nPixel )
666 if( maPixelData[nPixel] == 0 )
667 maPixelData[nPixel] = 1; // could be extended to more colors
668 else
669 maPixelData[nPixel] = 0;
672 // The clicked rectangle is identified, to change its color
674 bool SvxPixelCtl::MouseButtonDown( const MouseEvent& rMEvt )
676 if (!aRectSize.Width() || !aRectSize.Height())
677 return true;
679 //Grab focus when click in window
680 if (!HasFocus())
682 GrabFocus();
685 long nIndex = ShowPosition(rMEvt.GetPosPixel());
687 if(m_xAccess.is())
689 m_xAccess->NotifyChild(nIndex,true, true);
692 return true;
695 tools::Rectangle SvxPixelCtl::GetFocusRect()
697 tools::Rectangle aRet;
698 //Draw visual focus when has focus
699 if (HasFocus())
700 aRet = implCalFocusRect(aFocusPosition);
701 return aRet;
704 // Draws the Control (Rectangle with nine circles)
705 void SvxPixelCtl::Paint( vcl::RenderContext& rRenderContext, const tools::Rectangle& )
707 if (!aRectSize.Width() || !aRectSize.Height())
708 return;
710 sal_uInt16 i, j, nTmp;
711 Point aPtTl, aPtBr;
713 if (bPaintable)
715 // Draw lines
716 rRenderContext.SetLineColor(Color());
717 for (i = 1; i < nLines; i++)
719 // horizontal
720 nTmp = static_cast<sal_uInt16>(aRectSize.Height() * i / nLines);
721 rRenderContext.DrawLine(Point(0, nTmp), Point(aRectSize.Width(), nTmp));
722 // vertically
723 nTmp = static_cast<sal_uInt16>( aRectSize.Width() * i / nLines );
724 rRenderContext.DrawLine(Point(nTmp, 0), Point(nTmp, aRectSize.Height()));
727 //Draw Rectangles (squares)
728 rRenderContext.SetLineColor();
729 sal_uInt16 nLastPixel = maPixelData[0] ? 0 : 1;
731 for (i = 0; i < nLines; i++)
733 aPtTl.setY( aRectSize.Height() * i / nLines + 1 );
734 aPtBr.setY( aRectSize.Height() * (i + 1) / nLines - 1 );
736 for (j = 0; j < nLines; j++)
738 aPtTl.setX( aRectSize.Width() * j / nLines + 1 );
739 aPtBr.setX( aRectSize.Width() * (j + 1) / nLines - 1 );
741 if (maPixelData[i * nLines + j] != nLastPixel)
743 nLastPixel = maPixelData[i * nLines + j];
744 // Change color: 0 -> Background color
745 rRenderContext.SetFillColor(nLastPixel ? aPixelColor : aBackgroundColor);
747 rRenderContext.DrawRect(tools::Rectangle(aPtTl, aPtBr));
751 else
753 rRenderContext.SetBackground(Wallpaper(COL_LIGHTGRAY));
754 rRenderContext.SetLineColor(COL_LIGHTRED);
755 rRenderContext.DrawLine(Point(0, 0), Point(aRectSize.Width(), aRectSize.Height()));
756 rRenderContext.DrawLine(Point(0, aRectSize.Height()), Point(aRectSize.Width(), 0));
760 //Calculate visual focus rectangle via focus position
761 tools::Rectangle SvxPixelCtl::implCalFocusRect( const Point& aPosition )
763 long nLeft,nTop,nRight,nBottom;
764 long i,j;
765 i = aPosition.Y();
766 j = aPosition.X();
767 nLeft = aRectSize.Width() * j / nLines + 1;
768 nRight = aRectSize.Width() * (j + 1) / nLines - 1;
769 nTop = aRectSize.Height() * i / nLines + 1;
770 nBottom = aRectSize.Height() * (i + 1) / nLines - 1;
771 return tools::Rectangle(nLeft,nTop,nRight,nBottom);
774 //Solution:Keyboard function
775 bool SvxPixelCtl::KeyInput( const KeyEvent& rKEvt )
777 vcl::KeyCode aKeyCode = rKEvt.GetKeyCode();
778 sal_uInt16 nCode = aKeyCode.GetCode();
779 bool bIsMod = aKeyCode.IsShift() || aKeyCode.IsMod1() || aKeyCode.IsMod2();
781 if( !bIsMod )
783 Point aRepaintPoint( aRectSize.Width() *( aFocusPosition.getX() - 1)/ nLines - 1,
784 aRectSize.Height() *( aFocusPosition.getY() - 1)/ nLines -1
786 Size aRepaintSize( aRectSize.Width() *3/ nLines + 2,aRectSize.Height() *3/ nLines + 2);
787 tools::Rectangle aRepaintRect( aRepaintPoint, aRepaintSize );
788 bool bFocusPosChanged=false;
789 switch(nCode)
791 case KEY_LEFT:
792 if(aFocusPosition.getX() >= 1)
794 aFocusPosition.setX( aFocusPosition.getX() - 1 );
795 Invalidate(aRepaintRect);
796 bFocusPosChanged=true;
798 break;
799 case KEY_RIGHT:
800 if( aFocusPosition.getX() < (nLines - 1) )
802 aFocusPosition.setX( aFocusPosition.getX() + 1 );
803 Invalidate(aRepaintRect);
804 bFocusPosChanged=true;
806 break;
807 case KEY_UP:
808 if(aFocusPosition.getY() >= 1)
810 aFocusPosition.setY( aFocusPosition.getY() - 1 );
811 Invalidate(aRepaintRect);
812 bFocusPosChanged=true;
814 break;
815 case KEY_DOWN:
816 if( aFocusPosition.getY() < ( nLines - 1 ) )
818 aFocusPosition.setY( aFocusPosition.getY() + 1 );
819 Invalidate(aRepaintRect);
820 bFocusPosChanged=true;
822 break;
823 case KEY_SPACE:
824 ChangePixel( sal_uInt16(aFocusPosition.getX() + aFocusPosition.getY() * nLines) );
825 Invalidate( implCalFocusRect(aFocusPosition) );
826 break;
827 default:
828 return CustomWidgetController::KeyInput( rKEvt );
830 if(m_xAccess.is())
832 long nIndex = GetFocusPosIndex();
833 switch(nCode)
835 case KEY_LEFT:
836 case KEY_RIGHT:
837 case KEY_UP:
838 case KEY_DOWN:
839 if (bFocusPosChanged)
841 m_xAccess->NotifyChild(nIndex,false,false);
843 break;
844 case KEY_SPACE:
845 m_xAccess->NotifyChild(nIndex,false,true);
846 break;
847 default:
848 break;
851 return true;
853 else
855 return CustomWidgetController::KeyInput( rKEvt );
859 //Draw focus when get focus
860 void SvxPixelCtl::GetFocus()
862 Invalidate(implCalFocusRect(aFocusPosition));
864 if (m_xAccess.is())
866 m_xAccess->NotifyChild(GetFocusPosIndex(),true,false);
870 void SvxPixelCtl::LoseFocus()
872 Invalidate();
875 void SvxPixelCtl::SetXBitmap(const BitmapEx& rBitmapEx)
877 if (vcl::bitmap::isHistorical8x8(rBitmapEx, aBackgroundColor, aPixelColor))
879 for (sal_uInt16 i = 0; i < nSquares; i++)
881 Color aColor = rBitmapEx.GetPixelColor(i%8, i/8);
882 maPixelData[i] = (aColor == aBackgroundColor) ? 0 : 1;
887 // Returns a specific pixel
889 sal_uInt8 SvxPixelCtl::GetBitmapPixel( const sal_uInt16 nPixel ) const
891 return maPixelData[nPixel];
894 // Resets to the original state of the control
896 void SvxPixelCtl::Reset()
898 // clear pixel area
899 maPixelData.fill(0);
900 Invalidate();
903 void FillTypeLB::Fill()
905 SetUpdateMode( false );
907 InsertEntry( SvxResId(RID_SVXSTR_INVISIBLE) );
908 InsertEntry( SvxResId(RID_SVXSTR_COLOR) );
909 InsertEntry( SvxResId(RID_SVXSTR_GRADIENT) );
910 InsertEntry( SvxResId(RID_SVXSTR_HATCH) );
911 InsertEntry( SvxResId(RID_SVXSTR_BITMAP) );
912 InsertEntry( SvxResId(RID_SVXSTR_PATTERN) );
914 AdaptDropDownLineCountToMaximum();
915 SetUpdateMode( true );
918 SvxLineLB::SvxLineLB(std::unique_ptr<weld::ComboBox> pControl)
919 : m_xControl(std::move(pControl))
920 , mbAddStandardFields(true)
924 void SvxLineLB::setAddStandardFields(bool bNew)
926 if(getAddStandardFields() != bNew)
928 mbAddStandardFields = bNew;
932 // Fills the listbox (provisional) with strings
934 void SvxLineLB::Fill( const XDashListRef &pList )
936 m_xControl->clear();
938 if( !pList.is() )
939 return;
941 ScopedVclPtrInstance< VirtualDevice > pVD;
943 if(getAddStandardFields())
945 // entry for 'none'
946 m_xControl->append_text(pList->GetStringForUiNoLine());
948 // entry for solid line
949 const BitmapEx aBitmap = pList->GetBitmapForUISolidLine();
950 const Size aBmpSize(aBitmap.GetSizePixel());
951 pVD->SetOutputSizePixel(aBmpSize, false);
952 pVD->DrawBitmapEx(Point(), aBitmap);
953 m_xControl->append("", pList->GetStringForUiSolidLine(), *pVD);
956 // entries for dashed lines
958 long nCount = pList->Count();
959 m_xControl->freeze();
961 for( long i = 0; i < nCount; i++ )
963 const XDashEntry* pEntry = pList->GetDash(i);
964 const BitmapEx aBitmap = pList->GetUiBitmap( i );
965 if( !aBitmap.IsEmpty() )
967 const Size aBmpSize(aBitmap.GetSizePixel());
968 pVD->SetOutputSizePixel(aBmpSize, false);
969 pVD->DrawBitmapEx(Point(), aBitmap);
970 m_xControl->append("", pEntry->GetName(), *pVD);
972 else
974 m_xControl->append_text(pEntry->GetName());
978 m_xControl->thaw();
981 void SvxLineLB::Append( const XDashEntry& rEntry, const BitmapEx& rBitmap )
983 if (!rBitmap.IsEmpty())
985 ScopedVclPtrInstance< VirtualDevice > pVD;
987 const Size aBmpSize(rBitmap.GetSizePixel());
988 pVD->SetOutputSizePixel(aBmpSize, false);
989 pVD->DrawBitmapEx(Point(), rBitmap);
990 m_xControl->append("", rEntry.GetName(), *pVD);
992 else
994 m_xControl->append_text(rEntry.GetName());
998 void SvxLineLB::Modify(const XDashEntry& rEntry, sal_Int32 nPos, const BitmapEx& rBitmap)
1000 m_xControl->remove(nPos);
1002 if (!rBitmap.IsEmpty())
1004 ScopedVclPtrInstance< VirtualDevice > pVD;
1006 const Size aBmpSize(rBitmap.GetSizePixel());
1007 pVD->SetOutputSizePixel(aBmpSize, false);
1008 pVD->DrawBitmapEx(Point(), rBitmap);
1009 m_xControl->insert(nPos, rEntry.GetName(), nullptr, nullptr, pVD);
1011 else
1013 m_xControl->insert_text(nPos, rEntry.GetName());
1017 SvxLineEndLB::SvxLineEndLB(std::unique_ptr<weld::ComboBox> pControl)
1018 : m_xControl(std::move(pControl))
1022 void SvxLineEndLB::Fill( const XLineEndListRef &pList, bool bStart )
1024 if( !pList.is() )
1025 return;
1027 long nCount = pList->Count();
1028 ScopedVclPtrInstance< VirtualDevice > pVD;
1029 m_xControl->freeze();
1031 for( long i = 0; i < nCount; i++ )
1033 const XLineEndEntry* pEntry = pList->GetLineEnd(i);
1034 const BitmapEx aBitmap = pList->GetUiBitmap( i );
1035 if( !aBitmap.IsEmpty() )
1037 const Size aBmpSize(aBitmap.GetSizePixel());
1038 pVD->SetOutputSizePixel(Size(aBmpSize.Width() / 2, aBmpSize.Height()), false);
1039 pVD->DrawBitmapEx(bStart ? Point() : Point(-aBmpSize.Width() / 2, 0), aBitmap);
1040 m_xControl->append("", pEntry->GetName(), *pVD);
1042 else
1043 m_xControl->append_text(pEntry->GetName());
1046 m_xControl->thaw();
1049 void SvxLineEndLB::Append( const XLineEndEntry& rEntry, const BitmapEx& rBitmap )
1051 if(!rBitmap.IsEmpty())
1053 ScopedVclPtrInstance< VirtualDevice > pVD;
1055 const Size aBmpSize(rBitmap.GetSizePixel());
1056 pVD->SetOutputSizePixel(Size(aBmpSize.Width() / 2, aBmpSize.Height()), false);
1057 pVD->DrawBitmapEx(Point(-aBmpSize.Width() / 2, 0), rBitmap);
1058 m_xControl->append("", rEntry.GetName(), *pVD);
1060 else
1062 m_xControl->append_text(rEntry.GetName());
1066 void SvxLineEndLB::Modify( const XLineEndEntry& rEntry, sal_Int32 nPos, const BitmapEx& rBitmap )
1068 m_xControl->remove(nPos);
1070 if(!rBitmap.IsEmpty())
1072 ScopedVclPtrInstance< VirtualDevice > pVD;
1074 const Size aBmpSize(rBitmap.GetSizePixel());
1075 pVD->SetOutputSizePixel(Size(aBmpSize.Width() / 2, aBmpSize.Height()), false);
1076 pVD->DrawBitmapEx(Point(-aBmpSize.Width() / 2, 0), rBitmap);
1077 m_xControl->insert(nPos, rEntry.GetName(), nullptr, nullptr, pVD);
1079 else
1081 m_xControl->insert_text(nPos, rEntry.GetName());
1085 void SvxXLinePreview::Resize()
1087 SvxPreviewBase::Resize();
1089 const Size aOutputSize(GetOutputSize());
1090 const sal_Int32 nDistance(500);
1091 const sal_Int32 nAvailableLength(aOutputSize.Width() - (4 * nDistance));
1093 // create DrawObectA
1094 const sal_Int32 aYPosA(aOutputSize.Height() / 2);
1095 const basegfx::B2DPoint aPointA1( nDistance, aYPosA);
1096 const basegfx::B2DPoint aPointA2( aPointA1.getX() + ((nAvailableLength * 14) / 20), aYPosA );
1097 basegfx::B2DPolygon aPolygonA;
1098 aPolygonA.append(aPointA1);
1099 aPolygonA.append(aPointA2);
1100 mpLineObjA->SetPathPoly(basegfx::B2DPolyPolygon(aPolygonA));
1102 // create DrawObectB
1103 const sal_Int32 aYPosB1((aOutputSize.Height() * 3) / 4);
1104 const sal_Int32 aYPosB2((aOutputSize.Height() * 1) / 4);
1105 const basegfx::B2DPoint aPointB1( aPointA2.getX() + nDistance, aYPosB1);
1106 const basegfx::B2DPoint aPointB2( aPointB1.getX() + ((nAvailableLength * 2) / 20), aYPosB2 );
1107 const basegfx::B2DPoint aPointB3( aPointB2.getX() + ((nAvailableLength * 2) / 20), aYPosB1 );
1108 basegfx::B2DPolygon aPolygonB;
1109 aPolygonB.append(aPointB1);
1110 aPolygonB.append(aPointB2);
1111 aPolygonB.append(aPointB3);
1112 mpLineObjB->SetPathPoly(basegfx::B2DPolyPolygon(aPolygonB));
1114 // create DrawObectC
1115 basegfx::B2DPolygon aPolygonC;
1116 const basegfx::B2DPoint aPointC1( aPointB3.getX() + nDistance, aYPosB1);
1117 const basegfx::B2DPoint aPointC2( aPointC1.getX() + ((nAvailableLength * 1) / 20), aYPosB2 );
1118 const basegfx::B2DPoint aPointC3( aPointC2.getX() + ((nAvailableLength * 1) / 20), aYPosB1 );
1119 aPolygonC.append(aPointC1);
1120 aPolygonC.append(aPointC2);
1121 aPolygonC.append(aPointC3);
1122 mpLineObjC->SetPathPoly(basegfx::B2DPolyPolygon(aPolygonC));
1125 SvxXLinePreview::SvxXLinePreview()
1126 : mpLineObjA(nullptr)
1127 , mpLineObjB(nullptr)
1128 , mpLineObjC(nullptr)
1129 , mpGraphic(nullptr)
1130 , mbWithSymbol(false)
1134 void SvxXLinePreview::SetDrawingArea(weld::DrawingArea* pDrawingArea)
1136 SvxPreviewBase::SetDrawingArea(pDrawingArea);
1138 mpLineObjA = new SdrPathObj(getModel(), OBJ_LINE);
1139 mpLineObjB = new SdrPathObj(getModel(), OBJ_PLIN);
1140 mpLineObjC = new SdrPathObj(getModel(), OBJ_PLIN);
1142 Resize();
1143 Invalidate();
1146 SvxXLinePreview::~SvxXLinePreview()
1148 SdrObject *pFoo = mpLineObjA;
1149 SdrObject::Free( pFoo );
1150 pFoo = mpLineObjB;
1151 SdrObject::Free( pFoo );
1152 pFoo = mpLineObjC;
1153 SdrObject::Free( pFoo );
1156 void SvxXLinePreview::SetSymbol(Graphic* p,const Size& s)
1158 mpGraphic = p;
1159 maSymbolSize = s;
1162 void SvxXLinePreview::ResizeSymbol(const Size& s)
1164 if ( s != maSymbolSize )
1166 maSymbolSize = s;
1167 Invalidate();
1171 void SvxXLinePreview::SetLineAttributes(const SfxItemSet& rItemSet)
1173 // Set ItemSet at objects
1174 mpLineObjA->SetMergedItemSet(rItemSet);
1176 // At line joints, do not use arrows
1177 SfxItemSet aTempSet(rItemSet);
1178 aTempSet.ClearItem(XATTR_LINESTART);
1179 aTempSet.ClearItem(XATTR_LINEEND);
1181 mpLineObjB->SetMergedItemSet(aTempSet);
1182 mpLineObjC->SetMergedItemSet(aTempSet);
1185 void SvxXLinePreview::Paint(vcl::RenderContext& rRenderContext, const tools::Rectangle&)
1187 LocalPrePaint(rRenderContext);
1189 // paint objects to buffer device
1190 sdr::contact::SdrObjectVector aObjectVector;
1191 aObjectVector.push_back(mpLineObjA);
1192 aObjectVector.push_back(mpLineObjB);
1193 aObjectVector.push_back(mpLineObjC);
1195 sdr::contact::ObjectContactOfObjListPainter aPainter(getBufferDevice(), aObjectVector, nullptr);
1196 sdr::contact::DisplayInfo aDisplayInfo;
1198 // do processing
1199 aPainter.ProcessDisplay(aDisplayInfo);
1201 if ( mbWithSymbol && mpGraphic )
1203 const Size aOutputSize(GetOutputSize());
1204 Point aPos( aOutputSize.Width() / 3, aOutputSize.Height() / 2 );
1205 aPos.AdjustX( -(maSymbolSize.Width() / 2) );
1206 aPos.AdjustY( -(maSymbolSize.Height() / 2) );
1207 mpGraphic->Draw(&getBufferDevice(), aPos, maSymbolSize);
1210 LocalPostPaint(rRenderContext);
1213 SvxXShadowPreview::SvxXShadowPreview()
1214 : mpRectangleObject(nullptr)
1215 , mpRectangleShadow(nullptr)
1219 void SvxXShadowPreview::SetDrawingArea(weld::DrawingArea* pDrawingArea)
1221 SvxPreviewBase::SetDrawingArea(pDrawingArea);
1222 InitSettings();
1224 // prepare size
1225 Size aSize = GetPreviewSize().GetSize();
1226 aSize.setWidth( aSize.Width() / 3 );
1227 aSize.setHeight( aSize.Height() / 3 );
1229 // create RectangleObject
1230 const tools::Rectangle aObjectSize( Point( aSize.Width(), aSize.Height() ), aSize );
1231 mpRectangleObject = new SdrRectObj(
1232 getModel(),
1233 aObjectSize);
1235 // create ShadowObject
1236 const tools::Rectangle aShadowSize( Point( aSize.Width(), aSize.Height() ), aSize );
1237 mpRectangleShadow = new SdrRectObj(
1238 getModel(),
1239 aShadowSize);
1242 SvxXShadowPreview::~SvxXShadowPreview()
1244 SdrObject::Free(mpRectangleObject);
1245 SdrObject::Free(mpRectangleShadow);
1248 void SvxXShadowPreview::SetRectangleAttributes(const SfxItemSet& rItemSet)
1250 mpRectangleObject->SetMergedItemSet(rItemSet, true);
1251 mpRectangleObject->SetMergedItem(XLineStyleItem(drawing::LineStyle_NONE));
1254 void SvxXShadowPreview::SetShadowAttributes(const SfxItemSet& rItemSet)
1256 mpRectangleShadow->SetMergedItemSet(rItemSet, true);
1257 mpRectangleShadow->SetMergedItem(XLineStyleItem(drawing::LineStyle_NONE));
1260 void SvxXShadowPreview::SetShadowPosition(const Point& rPos)
1262 maShadowOffset = rPos;
1265 void SvxXShadowPreview::Paint(vcl::RenderContext& rRenderContext, const tools::Rectangle&)
1267 rRenderContext.Push(PushFlags::MAPMODE);
1268 rRenderContext.SetMapMode(MapMode(MapUnit::Map100thMM));
1270 LocalPrePaint(rRenderContext);
1272 // prepare size
1273 Size aSize = rRenderContext.GetOutputSize();
1274 aSize.setWidth( aSize.Width() / 3 );
1275 aSize.setHeight( aSize.Height() / 3 );
1277 tools::Rectangle aObjectRect(Point(aSize.Width(), aSize.Height()), aSize);
1278 mpRectangleObject->SetSnapRect(aObjectRect);
1279 aObjectRect.Move(maShadowOffset.X(), maShadowOffset.Y());
1280 mpRectangleShadow->SetSnapRect(aObjectRect);
1282 sdr::contact::SdrObjectVector aObjectVector;
1284 aObjectVector.push_back(mpRectangleShadow);
1285 aObjectVector.push_back(mpRectangleObject);
1287 sdr::contact::ObjectContactOfObjListPainter aPainter(getBufferDevice(), aObjectVector, nullptr);
1288 sdr::contact::DisplayInfo aDisplayInfo;
1290 aPainter.ProcessDisplay(aDisplayInfo);
1292 LocalPostPaint(rRenderContext);
1294 rRenderContext.Pop();
1297 void SvxPreviewBase::InitSettings()
1299 const StyleSettings& rStyleSettings = Application::GetSettings().GetStyleSettings();
1301 svtools::ColorConfig aColorConfig;
1302 Color aTextColor(aColorConfig.GetColorValue(svtools::FONTCOLOR).nColor);
1303 getBufferDevice().SetTextColor(aTextColor);
1305 getBufferDevice().SetBackground(rStyleSettings.GetWindowColor());
1307 getBufferDevice().SetDrawMode(rStyleSettings.GetHighContrastMode() ? OUTPUT_DRAWMODE_CONTRAST : OUTPUT_DRAWMODE_COLOR);
1309 Invalidate();
1312 SvxPreviewBase::SvxPreviewBase()
1313 : mpModel(new SdrModel(nullptr, nullptr, true))
1315 // init model
1316 mpModel->GetItemPool().FreezeIdRanges();
1319 void SvxPreviewBase::SetDrawingArea(weld::DrawingArea* pDrawingArea)
1321 CustomWidgetController::SetDrawingArea(pDrawingArea);
1322 Size aSize(getPreviewStripSize(pDrawingArea->get_ref_device()));
1323 pDrawingArea->set_size_request(aSize.Width(), aSize.Height());
1324 SetOutputSizePixel(aSize);
1326 mpBufferDevice = VclPtr<VirtualDevice>::Create(pDrawingArea->get_ref_device());
1327 mpBufferDevice->SetMapMode(MapMode(MapUnit::Map100thMM));
1330 SvxPreviewBase::~SvxPreviewBase()
1332 mpModel.reset();
1333 mpBufferDevice.disposeAndClear();
1336 void SvxPreviewBase::LocalPrePaint(vcl::RenderContext const & rRenderContext)
1338 // init BufferDevice
1339 if (mpBufferDevice->GetOutputSizePixel() != GetOutputSizePixel())
1340 mpBufferDevice->SetOutputSizePixel(GetOutputSizePixel());
1341 mpBufferDevice->SetAntialiasing(rRenderContext.GetAntialiasing());
1343 const StyleSettings& rStyleSettings = Application::GetSettings().GetStyleSettings();
1345 if (rStyleSettings.GetPreviewUsesCheckeredBackground())
1347 const Point aNull(0, 0);
1348 static const sal_uInt32 nLen(8);
1349 static const Color aW(COL_WHITE);
1350 static const Color aG(0xef, 0xef, 0xef);
1351 const bool bWasEnabled(mpBufferDevice->IsMapModeEnabled());
1353 mpBufferDevice->EnableMapMode(false);
1354 mpBufferDevice->DrawCheckered(aNull, mpBufferDevice->GetOutputSizePixel(), nLen, aW, aG);
1355 mpBufferDevice->EnableMapMode(bWasEnabled);
1357 else
1359 mpBufferDevice->Erase();
1363 void SvxPreviewBase::LocalPostPaint(vcl::RenderContext& rRenderContext)
1365 // copy to front (in pixel mode)
1366 const bool bWasEnabledSrc(mpBufferDevice->IsMapModeEnabled());
1367 const bool bWasEnabledDst(rRenderContext.IsMapModeEnabled());
1368 const Point aEmptyPoint;
1370 mpBufferDevice->EnableMapMode(false);
1371 rRenderContext.EnableMapMode(false);
1373 rRenderContext.DrawOutDev(aEmptyPoint, GetOutputSizePixel(),
1374 aEmptyPoint, GetOutputSizePixel(),
1375 *mpBufferDevice);
1377 mpBufferDevice->EnableMapMode(bWasEnabledSrc);
1378 rRenderContext.EnableMapMode(bWasEnabledDst);
1381 void SvxPreviewBase::StyleUpdated()
1383 InitSettings();
1384 CustomWidgetController::StyleUpdated();
1387 SvxXRectPreview::SvxXRectPreview()
1388 : mpRectangleObject(nullptr)
1392 tools::Rectangle SvxPreviewBase::GetPreviewSize() const
1394 tools::Rectangle aObjectSize(Point(), getBufferDevice().PixelToLogic(GetOutputSizePixel()));
1395 return aObjectSize;
1398 void SvxXRectPreview::SetDrawingArea(weld::DrawingArea* pDrawingArea)
1400 SvxPreviewBase::SetDrawingArea(pDrawingArea);
1401 InitSettings();
1403 // create RectangleObject
1404 mpRectangleObject = new SdrRectObj(getModel(), GetPreviewSize());
1407 void SvxXRectPreview::Resize()
1409 SdrObject *pOrigObject = mpRectangleObject;
1410 if (pOrigObject)
1412 mpRectangleObject = new SdrRectObj(getModel(), GetPreviewSize());
1413 SetAttributes(pOrigObject->GetMergedItemSet());
1414 SdrObject::Free(pOrigObject);
1416 SvxPreviewBase::Resize();
1419 SvxXRectPreview::~SvxXRectPreview()
1421 SdrObject::Free(mpRectangleObject);
1424 void SvxXRectPreview::SetAttributes(const SfxItemSet& rItemSet)
1426 mpRectangleObject->SetMergedItemSet(rItemSet, true);
1427 mpRectangleObject->SetMergedItem(XLineStyleItem(drawing::LineStyle_NONE));
1430 void SvxXRectPreview::Paint(vcl::RenderContext& rRenderContext, const tools::Rectangle&)
1432 rRenderContext.Push(PushFlags::MAPMODE);
1433 rRenderContext.SetMapMode(MapMode(MapUnit::Map100thMM));
1434 LocalPrePaint(rRenderContext);
1436 sdr::contact::SdrObjectVector aObjectVector;
1438 aObjectVector.push_back(mpRectangleObject);
1440 sdr::contact::ObjectContactOfObjListPainter aPainter(getBufferDevice(), aObjectVector, nullptr);
1441 sdr::contact::DisplayInfo aDisplayInfo;
1443 aPainter.ProcessDisplay(aDisplayInfo);
1445 LocalPostPaint(rRenderContext);
1446 rRenderContext.Pop();
1449 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */