xref: /core/svx/source/dialog/dlgctrl.cxx (revision 2c03412a023d2f2aa569eb97b21f4006ee9a52dd)
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
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/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
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 .
18  */
19 
20 #include <config_wasm_strip.h>
21 
22 #include <vcl/svapp.hxx>
23 #include <vcl/settings.hxx>
24 #include <vcl/virdev.hxx>
25 #include <vcl/event.hxx>
26 #include <sfx2/dialoghelper.hxx>
27 #include <sfx2/weldutils.hxx>
28 #include <svx/relfld.hxx>
29 #include <svx/xlineit0.hxx>
30 #include <svx/xtable.hxx>
31 #include <bitmaps.hlst>
32 #include <svx/dlgctrl.hxx>
33 #include <tools/debug.hxx>
34 #include <svxpixelctlaccessiblecontext.hxx>
35 #include <svtools/colorcfg.hxx>
36 #include <svxrectctaccessiblecontext.hxx>
37 #include <basegfx/point/b2dpoint.hxx>
38 #include <basegfx/polygon/b2dpolygon.hxx>
39 #include <svx/svdorect.hxx>
40 #include <svx/svdmodel.hxx>
41 #include <svx/svdopath.hxx>
42 #include <sdr/contact/objectcontactofobjlistpainter.hxx>
43 #include <svx/sdr/contact/displayinfo.hxx>
44 #include <vcl/BitmapTools.hxx>
45 
46 #define OUTPUT_DRAWMODE_COLOR       (DrawModeFlags::Default)
47 #define OUTPUT_DRAWMODE_CONTRAST    (DrawModeFlags::SettingsLine | DrawModeFlags::SettingsFill | DrawModeFlags::SettingsText | DrawModeFlags::SettingsGradient)
48 
49 using namespace ::com::sun::star;
50 using namespace ::com::sun::star::uno;
51 using namespace ::com::sun::star::accessibility;
52 
53 // Control for display and selection of the corner points and
54 // mid point of an object
55 
GetRectBitmap()56 Bitmap& SvxRectCtl::GetRectBitmap()
57 {
58     if( maBitmap.IsEmpty() )
59         InitRectBitmap();
60 
61     return maBitmap;
62 }
63 
SvxRectCtl(SvxTabPage * pPage)64 SvxRectCtl::SvxRectCtl(SvxTabPage* pPage)
65     : m_pPage(pPage)
66     , m_nBorderWidth(Application::GetDefaultDevice()->LogicToPixel(Size(200, 0), MapMode(MapUnit::Map100thMM)).Width())
67     , m_eRP(RectPoint::MM)
68     , m_eDefRP(RectPoint::MM)
69     , m_nState(CTL_STATE::NONE)
70     , mbCompleteDisable(false)
71 {
72 }
73 
SetDrawingArea(weld::DrawingArea * pDrawingArea)74 void SvxRectCtl::SetDrawingArea(weld::DrawingArea* pDrawingArea)
75 {
76     CustomWidgetController::SetDrawingArea(pDrawingArea);
77     Size aSize(pDrawingArea->get_approximate_digit_width() * 25,
78                pDrawingArea->get_text_height() * 5);
79     pDrawingArea->set_size_request(aSize.Width(), aSize.Height());
80     Resize_Impl(aSize);
81 }
82 
SetControlSettings(RectPoint eRpt,sal_uInt16 nBorder)83 void SvxRectCtl::SetControlSettings(RectPoint eRpt, sal_uInt16 nBorder)
84 {
85     m_nBorderWidth = Application::GetDefaultDevice()->LogicToPixel(Size(nBorder, 0), MapMode(MapUnit::Map100thMM)).Width();
86     m_eDefRP = eRpt;
87     Resize();
88 }
89 
~SvxRectCtl()90 SvxRectCtl::~SvxRectCtl()
91 {
92 #if !ENABLE_WASM_STRIP_ACCESSIBILITY
93     m_pAccContext.clear();
94 #endif
95 }
96 
Resize()97 void SvxRectCtl::Resize()
98 {
99     Resize_Impl(GetOutputSizePixel());
100 }
101 
Resize_Impl(const Size & rSize)102 void SvxRectCtl::Resize_Impl(const Size &rSize)
103 {
104     m_aPtLT = Point( 0 + m_nBorderWidth,  0 + m_nBorderWidth );
105     m_aPtMT = Point( rSize.Width() / 2, 0 + m_nBorderWidth );
106     m_aPtRT = Point( rSize.Width() - m_nBorderWidth, 0 + m_nBorderWidth );
107 
108     m_aPtLM = Point( 0 + m_nBorderWidth,  rSize.Height() / 2 );
109     m_aPtMM = Point( rSize.Width() / 2, rSize.Height() / 2 );
110     m_aPtRM = Point( rSize.Width() - m_nBorderWidth, rSize.Height() / 2 );
111 
112     m_aPtLB = Point( 0 + m_nBorderWidth,    rSize.Height() - m_nBorderWidth );
113     m_aPtMB = Point( rSize.Width() / 2,   rSize.Height() - m_nBorderWidth );
114     m_aPtRB = Point( rSize.Width() - m_nBorderWidth, rSize.Height() - m_nBorderWidth );
115 
116     Reset();
117     StyleUpdated();
118 }
119 
InitRectBitmap()120 void SvxRectCtl::InitRectBitmap()
121 {
122     const StyleSettings& rStyles = Application::GetSettings().GetStyleSettings();
123     svtools::ColorConfig aColorConfig;
124 
125     maBitmap = Bitmap(RID_SVXCTRL_RECTBTNS);
126 
127     // set bitmap-colors
128     Color aColorAry1[7];
129     Color aColorAry2[7];
130     aColorAry1[0] = Color( 0xC0, 0xC0, 0xC0 );  // light-gray
131     aColorAry1[1] = Color( 0xFF, 0xFF, 0x00 );  // yellow
132     aColorAry1[2] = Color( 0xFF, 0xFF, 0xFF );  // white
133     aColorAry1[3] = Color( 0x80, 0x80, 0x80 );  // dark-gray
134     aColorAry1[4] = Color( 0x00, 0x00, 0x00 );  // black
135     aColorAry1[5] = Color( 0x00, 0xFF, 0x00 );  // green
136     aColorAry1[6] = Color( 0x00, 0x00, 0xFF );  // blue
137     aColorAry2[0] = rStyles.GetDialogColor();       // background
138     aColorAry2[1] = rStyles.GetWindowColor();
139     aColorAry2[2] = rStyles.GetLightColor();
140     aColorAry2[3] = rStyles.GetShadowColor();
141     aColorAry2[4] = rStyles.GetDarkShadowColor();
142     aColorAry2[5] = aColorConfig.GetColorValue( svtools::FONTCOLOR ).nColor;
143     aColorAry2[6] = rStyles.GetDialogColor();
144 
145 #ifdef DBG_UTIL
146     static bool     bModify = false;
147     bool&           rModify = bModify;
148     if( rModify )
149     {
150         static int      n = 0;
151         static sal_uInt8    r = 0xFF;
152         static sal_uInt8    g = 0x00;
153         static sal_uInt8    b = 0xFF;
154         int&            rn = n;
155         sal_uInt8&          rr = r;
156         sal_uInt8&          rg = g;
157         sal_uInt8&          rb = b;
158         aColorAry2[ rn ] = Color( rr, rg, rb );
159     }
160 #endif
161 
162     maBitmap.Replace( aColorAry1, aColorAry2, 7, nullptr );
163 }
164 
StyleUpdated()165 void SvxRectCtl::StyleUpdated()
166 {
167     maBitmap.SetEmpty(); // forces new creating of bitmap
168     CustomWidgetController::StyleUpdated();
169 }
170 
InitSettings(vcl::RenderContext & rRenderContext)171 void SvxRectCtl::InitSettings(vcl::RenderContext& rRenderContext)
172 {
173     svtools::ColorConfig aColorConfig;
174     Color aTextColor(aColorConfig.GetColorValue(svtools::FONTCOLOR).nColor);
175     rRenderContext.SetTextColor(aTextColor);
176     const StyleSettings& rStyleSettings = Application::GetSettings().GetStyleSettings();
177     rRenderContext.SetBackground(rStyleSettings.GetWindowColor());
178 }
179 
180 // The clicked rectangle (3 x 3) is determined and the parent (dialog)
181 // is notified that the item was changed
MouseButtonDown(const MouseEvent & rMEvt)182 bool SvxRectCtl::MouseButtonDown(const MouseEvent& rMEvt)
183 {
184     // CompletelyDisabled() added to have a disabled state for SvxRectCtl
185     if(!IsCompletelyDisabled())
186     {
187         m_aPtNew = GetApproxLogPtFromPixPt( rMEvt.GetPosPixel() );
188         m_eRP = GetRPFromPoint( m_aPtNew );
189         SetActualRP( m_eRP );
190 
191         if (m_pPage)
192             m_pPage->PointChanged(GetDrawingArea(), m_eRP);
193     }
194     return true;
195 }
196 
KeyInput(const KeyEvent & rKeyEvt)197 bool SvxRectCtl::KeyInput(const KeyEvent& rKeyEvt)
198 {
199     // CompletelyDisabled() added to have a disabled state for SvxRectCtl
200     if (IsCompletelyDisabled())
201         return false;
202 
203     RectPoint eNewRP = m_eRP;
204 
205     switch( rKeyEvt.GetKeyCode().GetCode() )
206     {
207         case KEY_DOWN:
208         {
209             if( !(m_nState & CTL_STATE::NOVERT) )
210                 switch( eNewRP )
211                 {
212                     case RectPoint::LT: eNewRP = RectPoint::LM; break;
213                     case RectPoint::MT: eNewRP = RectPoint::MM; break;
214                     case RectPoint::RT: eNewRP = RectPoint::RM; break;
215                     case RectPoint::LM: eNewRP = RectPoint::LB; break;
216                     case RectPoint::MM: eNewRP = RectPoint::MB; break;
217                     case RectPoint::RM: eNewRP = RectPoint::RB; break;
218                     default: ; //prevent warning
219                 }
220         }
221         break;
222         case KEY_UP:
223         {
224             if( !(m_nState & CTL_STATE::NOVERT) )
225                 switch( eNewRP )
226                 {
227                     case RectPoint::LM: eNewRP = RectPoint::LT; break;
228                     case RectPoint::MM: eNewRP = RectPoint::MT; break;
229                     case RectPoint::RM: eNewRP = RectPoint::RT; break;
230                     case RectPoint::LB: eNewRP = RectPoint::LM; break;
231                     case RectPoint::MB: eNewRP = RectPoint::MM; break;
232                     case RectPoint::RB: eNewRP = RectPoint::RM; break;
233                     default: ; //prevent warning
234                 }
235         }
236         break;
237         case KEY_LEFT:
238         {
239             if( !(m_nState & CTL_STATE::NOHORZ) )
240                 switch( eNewRP )
241                 {
242                     case RectPoint::MT: eNewRP = RectPoint::LT; break;
243                     case RectPoint::RT: eNewRP = RectPoint::MT; break;
244                     case RectPoint::MM: eNewRP = RectPoint::LM; break;
245                     case RectPoint::RM: eNewRP = RectPoint::MM; break;
246                     case RectPoint::MB: eNewRP = RectPoint::LB; break;
247                     case RectPoint::RB: eNewRP = RectPoint::MB; break;
248                     default: ; //prevent warning
249                 }
250         }
251         break;
252         case KEY_RIGHT:
253         {
254             if( !(m_nState & CTL_STATE::NOHORZ) )
255                 switch( eNewRP )
256                 {
257                     case RectPoint::LT: eNewRP = RectPoint::MT; break;
258                     case RectPoint::MT: eNewRP = RectPoint::RT; break;
259                     case RectPoint::LM: eNewRP = RectPoint::MM; break;
260                     case RectPoint::MM: eNewRP = RectPoint::RM; break;
261                     case RectPoint::LB: eNewRP = RectPoint::MB; break;
262                     case RectPoint::MB: eNewRP = RectPoint::RB; break;
263                     default: ; //prevent warning
264                 }
265         }
266         break;
267         default:
268             return false;
269     }
270     if( eNewRP != m_eRP )
271     {
272         SetActualRP( eNewRP );
273 
274         if (m_pPage)
275             m_pPage->PointChanged(GetDrawingArea(), m_eRP);
276     }
277     return true;
278 }
279 
280 // the control (rectangle with 9 circles)
Paint(vcl::RenderContext & rRenderContext,const tools::Rectangle &)281 void SvxRectCtl::Paint(vcl::RenderContext& rRenderContext, const tools::Rectangle&)
282 {
283     InitSettings(rRenderContext);
284 
285     Point aPtDiff(1, 1);
286 
287     const StyleSettings& rStyles = Application::GetSettings().GetStyleSettings();
288 
289     rRenderContext.SetLineColor(rStyles.GetDialogColor());
290     rRenderContext.SetFillColor(rStyles.GetDialogColor());
291     rRenderContext.DrawRect(tools::Rectangle(Point(0,0), rRenderContext.GetOutputSize()));
292 
293     if (IsEnabled())
294         rRenderContext.SetLineColor(rStyles.GetLabelTextColor());
295     else
296         rRenderContext.SetLineColor(rStyles.GetShadowColor());
297 
298     rRenderContext.SetFillColor();
299 
300     if (!IsEnabled())
301     {
302         Color aOldCol = rRenderContext.GetLineColor();
303         rRenderContext.SetLineColor(rStyles.GetLightColor());
304         rRenderContext.DrawRect(tools::Rectangle(m_aPtLT + aPtDiff, m_aPtRB + aPtDiff));
305         rRenderContext.SetLineColor(aOldCol);
306     }
307     rRenderContext.DrawRect(tools::Rectangle(m_aPtLT, m_aPtRB));
308 
309     rRenderContext.SetFillColor(rRenderContext.GetBackground().GetColor());
310 
311     Size aBtnSize(11, 11);
312     Size aDstBtnSize(aBtnSize);
313     Point aToCenter(aDstBtnSize.Width() >> 1, aDstBtnSize.Height() >> 1);
314     Point aBtnPnt1(IsEnabled() ? 0 : 22, 0);
315     Point aBtnPnt2(11, 0);
316     Point aBtnPnt3(22, 0);
317 
318     bool bNoHorz = bool(m_nState & CTL_STATE::NOHORZ);
319     bool bNoVert = bool(m_nState & CTL_STATE::NOVERT);
320 
321     Bitmap& rBitmap = GetRectBitmap();
322 
323     // CompletelyDisabled() added to have a disabled state for SvxRectCtl
324     if (IsCompletelyDisabled())
325     {
326         rRenderContext.DrawBitmapEx(m_aPtLT - aToCenter, aDstBtnSize, aBtnPnt3, aBtnSize, rBitmap);
327         rRenderContext.DrawBitmapEx(m_aPtMT - aToCenter, aDstBtnSize, aBtnPnt3, aBtnSize, rBitmap);
328         rRenderContext.DrawBitmapEx(m_aPtRT - aToCenter, aDstBtnSize, aBtnPnt3, aBtnSize, rBitmap);
329         rRenderContext.DrawBitmapEx(m_aPtLM - aToCenter, aDstBtnSize, aBtnPnt3, aBtnSize, rBitmap);
330         rRenderContext.DrawBitmapEx(m_aPtMM - aToCenter, aDstBtnSize, aBtnPnt3, aBtnSize, rBitmap);
331         rRenderContext.DrawBitmapEx(m_aPtRM - aToCenter, aDstBtnSize, aBtnPnt3, aBtnSize, rBitmap);
332         rRenderContext.DrawBitmapEx(m_aPtLB - aToCenter, aDstBtnSize, aBtnPnt3, aBtnSize, rBitmap);
333         rRenderContext.DrawBitmapEx(m_aPtMB - aToCenter, aDstBtnSize, aBtnPnt3, aBtnSize, rBitmap);
334         rRenderContext.DrawBitmapEx(m_aPtRB - aToCenter, aDstBtnSize, aBtnPnt3, aBtnSize, rBitmap);
335     }
336     else
337     {
338         rRenderContext.DrawBitmapEx(m_aPtLT - aToCenter, aDstBtnSize, (bNoHorz || bNoVert)?aBtnPnt3:aBtnPnt1, aBtnSize, rBitmap);
339         rRenderContext.DrawBitmapEx(m_aPtMT - aToCenter, aDstBtnSize, bNoVert?aBtnPnt3:aBtnPnt1, aBtnSize, rBitmap);
340         rRenderContext.DrawBitmapEx(m_aPtRT - aToCenter, aDstBtnSize, (bNoHorz || bNoVert)?aBtnPnt3:aBtnPnt1, aBtnSize, rBitmap);
341         rRenderContext.DrawBitmapEx(m_aPtLM - aToCenter, aDstBtnSize, bNoHorz?aBtnPnt3:aBtnPnt1, aBtnSize, rBitmap);
342 
343         // Center for rectangle and line
344         rRenderContext.DrawBitmapEx(m_aPtMM - aToCenter, aDstBtnSize, aBtnPnt1, aBtnSize, rBitmap);
345 
346         rRenderContext.DrawBitmapEx(m_aPtRM - aToCenter, aDstBtnSize, bNoHorz?aBtnPnt3:aBtnPnt1, aBtnSize, rBitmap);
347         rRenderContext.DrawBitmapEx(m_aPtLB - aToCenter, aDstBtnSize, (bNoHorz || bNoVert)?aBtnPnt3:aBtnPnt1, aBtnSize, rBitmap);
348         rRenderContext.DrawBitmapEx(m_aPtMB - aToCenter, aDstBtnSize, bNoVert?aBtnPnt3:aBtnPnt1, aBtnSize, rBitmap);
349         rRenderContext.DrawBitmapEx(m_aPtRB - aToCenter, aDstBtnSize, (bNoHorz || bNoVert)?aBtnPnt3:aBtnPnt1, aBtnSize, rBitmap);
350     }
351 
352     // draw active button, avoid center pos for angle
353     // CompletelyDisabled() added to have a disabled state for SvxRectCtl
354     if (!IsCompletelyDisabled())
355     {
356         if (IsEnabled())
357         {
358             Point aCenterPt(m_aPtNew);
359             aCenterPt -= aToCenter;
360 
361             rRenderContext.DrawBitmapEx(aCenterPt, aDstBtnSize, aBtnPnt2, aBtnSize, rBitmap);
362         }
363     }
364 }
365 
GetFocusRect()366 tools::Rectangle SvxRectCtl::GetFocusRect()
367 {
368     tools::Rectangle aRet;
369     if (HasFocus())
370         aRet = CalculateFocusRectangle();
371     return aRet;
372 }
373 
374 // Convert RectPoint Point
375 
GetPointFromRP(RectPoint _eRP) const376 const Point& SvxRectCtl::GetPointFromRP( RectPoint _eRP) const
377 {
378     switch( _eRP )
379     {
380         case RectPoint::LT: return m_aPtLT;
381         case RectPoint::MT: return m_aPtMT;
382         case RectPoint::RT: return m_aPtRT;
383         case RectPoint::LM: return m_aPtLM;
384         case RectPoint::MM: return m_aPtMM;
385         case RectPoint::RM: return m_aPtRM;
386         case RectPoint::LB: return m_aPtLB;
387         case RectPoint::MB: return m_aPtMB;
388         case RectPoint::RB: return m_aPtRB;
389     }
390     return m_aPtMM; // default
391 }
392 
SetActualRPWithoutInvalidate(RectPoint eNewRP)393 Point SvxRectCtl::SetActualRPWithoutInvalidate( RectPoint eNewRP )
394 {
395     Point aPtLast = m_aPtNew;
396     m_aPtNew = GetPointFromRP( eNewRP );
397 
398     if( m_nState & CTL_STATE::NOHORZ )
399         m_aPtNew.setX( m_aPtMM.X() );
400 
401     if( m_nState & CTL_STATE::NOVERT )
402         m_aPtNew.setY( m_aPtMM.Y() );
403 
404     // fdo#74751 this fix reverse base point on RTL UI.
405     bool bRTL = AllSettings::GetLayoutRTL();
406     eNewRP = GetRPFromPoint( m_aPtNew, bRTL );
407 
408     m_eDefRP = eNewRP;
409     m_eRP = eNewRP;
410 
411     return aPtLast;
412 }
413 
GetFocus()414 void SvxRectCtl::GetFocus()
415 {
416     Invalidate();
417 
418 #if !ENABLE_WASM_STRIP_ACCESSIBILITY
419     // Send accessibility event.
420     if (m_pAccContext.is())
421     {
422         m_pAccContext->FireChildFocus(GetActualRP());
423     }
424 #endif
425 }
426 
LoseFocus()427 void SvxRectCtl::LoseFocus()
428 {
429     Invalidate();
430 }
431 
GetApproxLogPtFromPixPt(const Point & rPt) const432 Point SvxRectCtl::GetApproxLogPtFromPixPt( const Point& rPt ) const
433 {
434     Point   aPt = rPt;
435     tools::Long    x;
436     tools::Long    y;
437 
438     Size aSize(GetOutputSizePixel());
439 
440     if( !( m_nState & CTL_STATE::NOHORZ ) )
441     {
442         if( aPt.X() < aSize.Width() / 3 )
443             x = m_aPtLT.X();
444         else if( aPt.X() < aSize.Width() * 2 / 3 )
445             x = m_aPtMM.X();
446         else
447             x = m_aPtRB.X();
448     }
449     else
450         x = m_aPtMM.X();
451 
452     if( !( m_nState & CTL_STATE::NOVERT ) )
453     {
454         if( aPt.Y() < aSize.Height() / 3 )
455             y = m_aPtLT.Y();
456         else if( aPt.Y() < aSize.Height() * 2 / 3 )
457             y = m_aPtMM.Y();
458         else
459             y = m_aPtRB.Y();
460     }
461     else
462             y = m_aPtMM.Y();
463 
464     return Point( x, y );
465 }
466 
467 
468 // Converts Point in RectPoint
469 
GetRPFromPoint(Point aPt,bool bRTL) const470 RectPoint SvxRectCtl::GetRPFromPoint( Point aPt, bool bRTL ) const
471 {
472     RectPoint rPoint = RectPoint::MM;  // default
473 
474     if (aPt == m_aPtLT) rPoint = bRTL ? RectPoint::RT : RectPoint::LT;
475     else if( aPt == m_aPtMT) rPoint = RectPoint::MT;
476     else if( aPt == m_aPtRT) rPoint = bRTL ? RectPoint::LT : RectPoint::RT;
477     else if( aPt == m_aPtLM) rPoint = bRTL ? RectPoint::RM : RectPoint::LM;
478     else if( aPt == m_aPtRM) rPoint = bRTL ? RectPoint::LM : RectPoint::RM;
479     else if( aPt == m_aPtLB) rPoint = bRTL ? RectPoint::RB : RectPoint::LB;
480     else if( aPt == m_aPtMB) rPoint = RectPoint::MB;
481     else if( aPt == m_aPtRB) rPoint = bRTL ? RectPoint::LB : RectPoint::RB;
482 
483     return rPoint;
484 }
485 
486 // Resets to the original state of the control
487 
Reset()488 void SvxRectCtl::Reset()
489 {
490     m_aPtNew = GetPointFromRP( m_eDefRP );
491     m_eRP = m_eDefRP;
492     Invalidate();
493 }
494 
495 // Returns the currently selected RectPoint
496 
497 
SetActualRP(RectPoint eNewRP)498 void SvxRectCtl::SetActualRP( RectPoint eNewRP )
499 {
500     SetActualRPWithoutInvalidate(eNewRP);
501 
502     Invalidate();
503 
504 #if !ENABLE_WASM_STRIP_ACCESSIBILITY
505     // notify accessibility object about change
506     if (m_pAccContext.is())
507         m_pAccContext->selectChild( eNewRP /* MT, bFireFocus */ );
508 #endif
509 }
510 
SetState(CTL_STATE nState)511 void SvxRectCtl::SetState( CTL_STATE nState )
512 {
513     m_nState = nState;
514 
515     Point aPtLast( GetPointFromRP( m_eRP ) );
516     Point _aPtNew( aPtLast );
517 
518     if( m_nState & CTL_STATE::NOHORZ )
519         _aPtNew.setX( m_aPtMM.X() );
520 
521     if( m_nState & CTL_STATE::NOVERT)
522         _aPtNew.setY( m_aPtMM.Y() );
523 
524     m_eRP = GetRPFromPoint( _aPtNew );
525     Invalidate();
526 
527     if (m_pPage)
528         m_pPage->PointChanged(GetDrawingArea(), m_eRP);
529 }
530 
CalculateFocusRectangle() const531 tools::Rectangle SvxRectCtl::CalculateFocusRectangle() const
532 {
533     Size        aDstBtnSize(15, 15);
534     return tools::Rectangle( m_aPtNew - Point( aDstBtnSize.Width() >> 1, aDstBtnSize.Height() >> 1 ), aDstBtnSize );
535 }
536 
CalculateFocusRectangle(RectPoint eRectPoint) const537 tools::Rectangle SvxRectCtl::CalculateFocusRectangle( RectPoint eRectPoint ) const
538 {
539     tools::Rectangle   aRet;
540     RectPoint  eOldRectPoint = GetActualRP();
541 
542     if( eOldRectPoint == eRectPoint )
543         aRet = CalculateFocusRectangle();
544     else
545     {
546         SvxRectCtl* pThis = const_cast<SvxRectCtl*>(this);
547 
548         pThis->SetActualRPWithoutInvalidate( eRectPoint );      // no invalidation because it's only temporary!
549         aRet = CalculateFocusRectangle();
550 
551         pThis->SetActualRPWithoutInvalidate( eOldRectPoint );   // no invalidation because nothing has changed!
552     }
553 
554     return aRet;
555 }
556 
CreateAccessible()557 rtl::Reference<comphelper::OAccessible> SvxRectCtl::CreateAccessible()
558 {
559 #if !ENABLE_WASM_STRIP_ACCESSIBILITY
560     m_pAccContext = new SvxRectCtlAccessibleContext(this);
561 #endif
562     return m_pAccContext;
563 }
564 
GetApproxRPFromPixPt(const css::awt::Point & r) const565 RectPoint SvxRectCtl::GetApproxRPFromPixPt( const css::awt::Point& r ) const
566 {
567     return GetRPFromPoint( GetApproxLogPtFromPixPt( Point( r.X, r.Y ) ) );
568 }
569 
570 // CompletelyDisabled() added to have a disabled state for SvxRectCtl
DoCompletelyDisable(bool bNew)571 void SvxRectCtl::DoCompletelyDisable(bool bNew)
572 {
573     mbCompleteDisable = bNew;
574     Invalidate();
575 }
576 
577 // Control for editing bitmaps
578 
CreateAccessible()579 rtl::Reference<comphelper::OAccessible> SvxPixelCtl::CreateAccessible()
580 {
581 #if !ENABLE_WASM_STRIP_ACCESSIBILITY
582     if (!m_xAccess.is())
583         m_xAccess = new SvxPixelCtlAccessible(this);
584 #endif
585     return m_xAccess;
586 }
587 
PointToIndex(const Point & aPt) const588 tools::Long SvxPixelCtl::PointToIndex(const Point &aPt) const
589 {
590     tools::Long nX = aPt.X() * nLines / m_aRectSize.Width();
591     tools::Long nY = aPt.Y() * nLines / m_aRectSize.Height();
592 
593     return nX + nY * nLines ;
594 }
595 
IndexToPoint(tools::Long nIndex) const596 Point SvxPixelCtl::IndexToPoint(tools::Long nIndex) const
597 {
598     DBG_ASSERT(nIndex >= 0 && nIndex < nSquares ," Check Index");
599 
600     sal_Int32 nXIndex = nIndex % nLines;
601     sal_Int32 nYIndex = nIndex / nLines;
602 
603     Point aPtTl;
604     aPtTl.setY( m_aRectSize.Height() * nYIndex / nLines + 1 );
605     aPtTl.setX( m_aRectSize.Width() * nXIndex / nLines + 1 );
606 
607     return aPtTl;
608 }
609 
GetFocusPosIndex() const610 tools::Long SvxPixelCtl::GetFocusPosIndex() const
611 {
612     return m_aFocusPosition.getX() + m_aFocusPosition.getY() * nLines ;
613 }
614 
ShowPosition(const Point & rPt)615 tools::Long SvxPixelCtl::ShowPosition( const Point &rPt)
616 {
617     sal_Int32 nX = rPt.X() * nLines / m_aRectSize.Width();
618     sal_Int32 nY = rPt.Y() * nLines / m_aRectSize.Height();
619 
620     ChangePixel( nX + nY * nLines );
621 
622     //Solution:Set new focus position and repaint
623     m_aFocusPosition.setX(nX);
624     m_aFocusPosition.setY(nY);
625     Invalidate(tools::Rectangle(Point(0,0),m_aRectSize));
626 
627     if (m_pPage)
628         m_pPage->PointChanged(GetDrawingArea(), RectPoint::MM ); // RectPoint is dummy
629 
630     return GetFocusPosIndex();
631 
632 }
633 
SvxPixelCtl(SvxTabPage * pPage)634 SvxPixelCtl::SvxPixelCtl(SvxTabPage* pPage)
635     : m_pPage(pPage)
636     , m_bPaintable(true)
637     , m_aFocusPosition(0,0)
638 {
639     maPixelData.fill(0);
640 }
641 
Resize()642 void SvxPixelCtl::Resize()
643 {
644     CustomWidgetController::Resize();
645     m_aRectSize = GetOutputSizePixel();
646 }
647 
SetDrawingArea(weld::DrawingArea * pDrawingArea)648 void SvxPixelCtl::SetDrawingArea(weld::DrawingArea* pDrawingArea)
649 {
650     CustomWidgetController::SetDrawingArea(pDrawingArea);
651     pDrawingArea->set_size_request(pDrawingArea->get_approximate_digit_width() * 25,
652                                    pDrawingArea->get_text_height() * 10);
653 }
654 
~SvxPixelCtl()655 SvxPixelCtl::~SvxPixelCtl()
656 {
657 }
658 
659 // Changes the foreground or Background color
660 
ChangePixel(sal_uInt16 nPixel)661 void SvxPixelCtl::ChangePixel( sal_uInt16 nPixel )
662 {
663     if( maPixelData[nPixel] == 0 )
664         maPixelData[nPixel] = 1; //  could be extended to more colors
665     else
666         maPixelData[nPixel] = 0;
667 }
668 
669 // The clicked rectangle is identified, to change its color
670 
MouseButtonDown(const MouseEvent & rMEvt)671 bool SvxPixelCtl::MouseButtonDown( const MouseEvent& rMEvt )
672 {
673     if (!m_aRectSize.Width() || !m_aRectSize.Height())
674         return true;
675 
676     //Grab focus when click in window
677     if (!HasFocus())
678     {
679         GrabFocus();
680     }
681 
682     tools::Long nIndex = ShowPosition(rMEvt.GetPosPixel());
683 
684 #if !ENABLE_WASM_STRIP_ACCESSIBILITY
685     if(m_xAccess.is())
686     {
687         m_xAccess->NotifyChild(nIndex,true, true);
688     }
689 #else
690     (void)nIndex;
691 #endif
692 
693     return true;
694 }
695 
GetFocusRect()696 tools::Rectangle SvxPixelCtl::GetFocusRect()
697 {
698     tools::Rectangle aRet;
699     //Draw visual focus when has focus
700     if (HasFocus())
701         aRet = implCalFocusRect(m_aFocusPosition);
702     return aRet;
703 }
704 
705 // Draws the Control (Rectangle with nine circles)
Paint(vcl::RenderContext & rRenderContext,const tools::Rectangle &)706 void SvxPixelCtl::Paint( vcl::RenderContext& rRenderContext, const tools::Rectangle& )
707 {
708     if (!m_aRectSize.Width() || !m_aRectSize.Height())
709         return;
710 
711     sal_uInt16 i, j, nTmp;
712     Point aPtTl, aPtBr;
713 
714     if (m_bPaintable)
715     {
716         // Draw lines
717         rRenderContext.SetLineColor(Color());
718         for (i = 1; i < nLines; i++)
719         {
720             // horizontal
721             nTmp = static_cast<sal_uInt16>(m_aRectSize.Height() * i / nLines);
722             rRenderContext.DrawLine(Point(0, nTmp), Point(m_aRectSize.Width(), nTmp));
723             // vertically
724             nTmp = static_cast<sal_uInt16>( m_aRectSize.Width() * i / nLines );
725             rRenderContext.DrawLine(Point(nTmp, 0), Point(nTmp, m_aRectSize.Height()));
726         }
727 
728         //Draw Rectangles (squares)
729         rRenderContext.SetLineColor();
730         sal_uInt16 nLastPixel = maPixelData[0] ? 0 : 1;
731 
732         for (i = 0; i < nLines; i++)
733         {
734             aPtTl.setY( m_aRectSize.Height() * i / nLines + 1 );
735             aPtBr.setY( m_aRectSize.Height() * (i + 1) / nLines - 1 );
736 
737             for (j = 0; j < nLines; j++)
738             {
739                 aPtTl.setX( m_aRectSize.Width() * j / nLines + 1 );
740                 aPtBr.setX( m_aRectSize.Width() * (j + 1) / nLines - 1 );
741 
742                 if (maPixelData[i * nLines + j] != nLastPixel)
743                 {
744                     nLastPixel = maPixelData[i * nLines + j];
745                     // Change color: 0 -> Background color
746                     rRenderContext.SetFillColor(nLastPixel ? m_aPixelColor : m_aBackgroundColor);
747                 }
748                 rRenderContext.DrawRect(tools::Rectangle(aPtTl, aPtBr));
749             }
750         }
751     }
752     else
753     {
754         rRenderContext.SetBackground(Wallpaper(COL_LIGHTGRAY));
755         rRenderContext.SetLineColor(COL_LIGHTRED);
756         rRenderContext.DrawLine(Point(0, 0), Point(m_aRectSize.Width(), m_aRectSize.Height()));
757         rRenderContext.DrawLine(Point(0, m_aRectSize.Height()), Point(m_aRectSize.Width(), 0));
758     }
759 }
760 
761 //Calculate visual focus rectangle via focus position
implCalFocusRect(const Point & aPosition)762 tools::Rectangle SvxPixelCtl::implCalFocusRect( const Point& aPosition )
763 {
764     tools::Long nLeft,nTop,nRight,nBottom;
765     tools::Long i,j;
766     i = aPosition.Y();
767     j = aPosition.X();
768     nLeft = m_aRectSize.Width() * j / nLines + 1;
769     nRight = m_aRectSize.Width() * (j + 1) / nLines - 1;
770     nTop = m_aRectSize.Height() * i / nLines + 1;
771     nBottom = m_aRectSize.Height() * (i + 1) / nLines - 1;
772     return tools::Rectangle(nLeft,nTop,nRight,nBottom);
773 }
774 
775 //Solution:Keyboard function
KeyInput(const KeyEvent & rKEvt)776 bool SvxPixelCtl::KeyInput( const KeyEvent& rKEvt )
777 {
778     vcl::KeyCode aKeyCode = rKEvt.GetKeyCode();
779     sal_uInt16 nCode = aKeyCode.GetCode();
780     bool bIsMod = aKeyCode.IsShift() || aKeyCode.IsMod1() || aKeyCode.IsMod2();
781 
782     if( !bIsMod )
783     {
784         Point aRepaintPoint( m_aRectSize.Width() *( m_aFocusPosition.getX() - 1)/ nLines - 1,
785                              m_aRectSize.Height() *( m_aFocusPosition.getY() - 1)/ nLines -1
786                             );
787         Size  aRepaintSize( m_aRectSize.Width() *3/ nLines + 2,m_aRectSize.Height() *3/ nLines + 2);
788         tools::Rectangle aRepaintRect( aRepaintPoint, aRepaintSize );
789         bool bFocusPosChanged=false;
790         switch(nCode)
791         {
792             case KEY_LEFT:
793                 if(m_aFocusPosition.getX() >= 1)
794                 {
795                     m_aFocusPosition.setX( m_aFocusPosition.getX() - 1 );
796                     Invalidate(aRepaintRect);
797                     bFocusPosChanged=true;
798                 }
799                 break;
800             case KEY_RIGHT:
801                 if( m_aFocusPosition.getX() < (nLines - 1) )
802                 {
803                     m_aFocusPosition.setX( m_aFocusPosition.getX() + 1 );
804                     Invalidate(aRepaintRect);
805                     bFocusPosChanged=true;
806                 }
807                 break;
808             case KEY_UP:
809                 if(m_aFocusPosition.getY() >= 1)
810                 {
811                     m_aFocusPosition.setY( m_aFocusPosition.getY() - 1 );
812                     Invalidate(aRepaintRect);
813                     bFocusPosChanged=true;
814                 }
815                 break;
816             case KEY_DOWN:
817                 if( m_aFocusPosition.getY() < ( nLines - 1 ) )
818                 {
819                     m_aFocusPosition.setY( m_aFocusPosition.getY() + 1 );
820                     Invalidate(aRepaintRect);
821                     bFocusPosChanged=true;
822                 }
823                 break;
824             case KEY_SPACE:
825                 ChangePixel( sal_uInt16(m_aFocusPosition.getX() + m_aFocusPosition.getY() * nLines) );
826                 Invalidate( implCalFocusRect(m_aFocusPosition) );
827                 break;
828             default:
829                 return CustomWidgetController::KeyInput( rKEvt );
830         }
831 #if !ENABLE_WASM_STRIP_ACCESSIBILITY
832         if(m_xAccess.is())
833         {
834             tools::Long nIndex = GetFocusPosIndex();
835             switch(nCode)
836             {
837             case KEY_LEFT:
838             case KEY_RIGHT:
839             case KEY_UP:
840             case KEY_DOWN:
841                 if (bFocusPosChanged)
842                 {
843                     m_xAccess->NotifyChild(nIndex,false,false);
844                 }
845                 break;
846             case KEY_SPACE:
847                 m_xAccess->NotifyChild(nIndex,false,true);
848                 break;
849             default:
850                 break;
851             }
852         }
853 #else
854         (void)bFocusPosChanged;
855 #endif
856         return true;
857     }
858     else
859     {
860         return CustomWidgetController::KeyInput( rKEvt );
861     }
862 }
863 
864 //Draw focus when get focus
GetFocus()865 void SvxPixelCtl::GetFocus()
866 {
867     Invalidate(implCalFocusRect(m_aFocusPosition));
868 
869 #if !ENABLE_WASM_STRIP_ACCESSIBILITY
870     if (m_xAccess.is())
871     {
872         m_xAccess->NotifyChild(GetFocusPosIndex(),true,false);
873     }
874 #endif
875 }
876 
LoseFocus()877 void SvxPixelCtl::LoseFocus()
878 {
879     Invalidate();
880 }
881 
SetXBitmap(const Bitmap & rBitmap)882 void SvxPixelCtl::SetXBitmap(const Bitmap& rBitmap)
883 {
884     if (vcl::bitmap::isHistorical8x8(rBitmap, m_aBackgroundColor, m_aPixelColor))
885     {
886         for (sal_uInt16 i = 0; i < nSquares; i++)
887         {
888             Color aColor = rBitmap.GetPixelColor(i%8, i/8);
889             maPixelData[i] = (aColor == m_aBackgroundColor) ? 0 : 1;
890         }
891     }
892 }
893 
894 // Returns a specific pixel
895 
GetBitmapPixel(const sal_uInt16 nPixel) const896 sal_uInt8 SvxPixelCtl::GetBitmapPixel( const sal_uInt16 nPixel ) const
897 {
898     return maPixelData[nPixel];
899 }
900 
901 // Resets to the original state of the control
902 
Reset()903 void SvxPixelCtl::Reset()
904 {
905     // clear pixel area
906     maPixelData.fill(0);
907     Invalidate();
908 }
909 
SvxLineLB(std::unique_ptr<weld::ComboBox> pControl)910 SvxLineLB::SvxLineLB(std::unique_ptr<weld::ComboBox> pControl)
911     : m_xControl(std::move(pControl))
912     , mbAddStandardFields(true)
913 {
914 }
915 
setAddStandardFields(bool bNew)916 void SvxLineLB::setAddStandardFields(bool bNew)
917 {
918     if(getAddStandardFields() != bNew)
919     {
920         mbAddStandardFields = bNew;
921     }
922 }
923 
924 // Fills the listbox (provisional) with strings
925 
Fill(const XDashListRef & pList)926 void SvxLineLB::Fill( const XDashListRef &pList )
927 {
928     m_xControl->clear();
929 
930     if( !pList.is() )
931         return;
932 
933     ScopedVclPtrInstance< VirtualDevice > pVD;
934 
935     if(getAddStandardFields())
936     {
937         // entry for 'none'
938         m_xControl->append_text(pList->GetStringForUiNoLine());
939 
940         // entry for solid line
941         const Bitmap aBitmap = pList->GetBitmapForUISolidLine();
942         const Size aBmpSize(aBitmap.GetSizePixel());
943         pVD->SetOutputSizePixel(aBmpSize, false);
944         pVD->DrawBitmapEx(Point(), aBitmap);
945         m_xControl->append(u""_ustr, pList->GetStringForUiSolidLine(), *pVD);
946     }
947 
948     // entries for dashed lines
949 
950     tools::Long nCount = pList->Count();
951     m_xControl->freeze();
952 
953     for( tools::Long i = 0; i < nCount; i++ )
954     {
955         const XDashEntry* pEntry = pList->GetDash(i);
956         const Bitmap aBitmap = pList->GetUiBitmap( i );
957         if( !aBitmap.IsEmpty() )
958         {
959             const Size aBmpSize(aBitmap.GetSizePixel());
960             pVD->SetOutputSizePixel(aBmpSize, false);
961             pVD->DrawBitmapEx(Point(), aBitmap);
962             m_xControl->append(u""_ustr, pEntry->GetName(), *pVD);
963         }
964         else
965         {
966             m_xControl->append_text(pEntry->GetName());
967         }
968     }
969 
970     m_xControl->thaw();
971 }
972 
Append(const XDashEntry & rEntry,const Bitmap & rBitmap)973 void SvxLineLB::Append( const XDashEntry& rEntry, const Bitmap& rBitmap )
974 {
975     if (!rBitmap.IsEmpty())
976     {
977         ScopedVclPtrInstance< VirtualDevice > pVD;
978 
979         const Size aBmpSize(rBitmap.GetSizePixel());
980         pVD->SetOutputSizePixel(aBmpSize, false);
981         pVD->DrawBitmapEx(Point(), rBitmap);
982         m_xControl->append(u""_ustr, rEntry.GetName(), *pVD);
983     }
984     else
985     {
986         m_xControl->append_text(rEntry.GetName());
987     }
988 }
989 
Modify(const XDashEntry & rEntry,sal_Int32 nPos,const Bitmap & rBitmap)990 void SvxLineLB::Modify(const XDashEntry& rEntry, sal_Int32 nPos, const Bitmap& rBitmap)
991 {
992     m_xControl->remove(nPos);
993 
994     if (!rBitmap.IsEmpty())
995     {
996         ScopedVclPtrInstance< VirtualDevice > pVD;
997 
998         const Size aBmpSize(rBitmap.GetSizePixel());
999         pVD->SetOutputSizePixel(aBmpSize, false);
1000         pVD->DrawBitmapEx(Point(), rBitmap);
1001         m_xControl->insert(nPos, rEntry.GetName(), nullptr, nullptr, pVD);
1002     }
1003     else
1004     {
1005         m_xControl->insert_text(nPos, rEntry.GetName());
1006     }
1007 }
1008 
SvxLineEndLB(std::unique_ptr<weld::ComboBox> pControl)1009 SvxLineEndLB::SvxLineEndLB(std::unique_ptr<weld::ComboBox> pControl)
1010     : m_xControl(std::move(pControl))
1011 {
1012 }
1013 
Fill(const XLineEndListRef & pList,bool bStart)1014 void SvxLineEndLB::Fill( const XLineEndListRef &pList, bool bStart )
1015 {
1016     if( !pList.is() )
1017         return;
1018 
1019     tools::Long nCount = pList->Count();
1020     ScopedVclPtrInstance< VirtualDevice > pVD;
1021     m_xControl->freeze();
1022 
1023     for( tools::Long i = 0; i < nCount; i++ )
1024     {
1025         const XLineEndEntry* pEntry = pList->GetLineEnd(i);
1026         const Bitmap aBitmap = pList->GetUiBitmap( i );
1027         if( !aBitmap.IsEmpty() )
1028         {
1029             const Size aBmpSize(aBitmap.GetSizePixel());
1030             pVD->SetOutputSizePixel(Size(aBmpSize.Width() / 2, aBmpSize.Height()), false);
1031             pVD->DrawBitmapEx(bStart ? Point() : Point(-aBmpSize.Width() / 2, 0), aBitmap);
1032             m_xControl->append(u""_ustr, pEntry->GetName(), *pVD);
1033         }
1034         else
1035             m_xControl->append_text(pEntry->GetName());
1036     }
1037 
1038     m_xControl->thaw();
1039 }
1040 
Append(const XLineEndEntry & rEntry,const Bitmap & rBitmap)1041 void SvxLineEndLB::Append( const XLineEndEntry& rEntry, const Bitmap& rBitmap )
1042 {
1043     if(!rBitmap.IsEmpty())
1044     {
1045         ScopedVclPtrInstance< VirtualDevice > pVD;
1046 
1047         const Size aBmpSize(rBitmap.GetSizePixel());
1048         pVD->SetOutputSizePixel(Size(aBmpSize.Width() / 2, aBmpSize.Height()), false);
1049         pVD->DrawBitmapEx(Point(-aBmpSize.Width() / 2, 0), rBitmap);
1050         m_xControl->append(u""_ustr, rEntry.GetName(), *pVD);
1051     }
1052     else
1053     {
1054         m_xControl->append_text(rEntry.GetName());
1055     }
1056 }
1057 
Modify(const XLineEndEntry & rEntry,sal_Int32 nPos,const Bitmap & rBitmap)1058 void SvxLineEndLB::Modify( const XLineEndEntry& rEntry, sal_Int32 nPos, const Bitmap& rBitmap )
1059 {
1060     m_xControl->remove(nPos);
1061 
1062     if(!rBitmap.IsEmpty())
1063     {
1064         ScopedVclPtrInstance< VirtualDevice > pVD;
1065 
1066         const Size aBmpSize(rBitmap.GetSizePixel());
1067         pVD->SetOutputSizePixel(Size(aBmpSize.Width() / 2, aBmpSize.Height()), false);
1068         pVD->DrawBitmapEx(Point(-aBmpSize.Width() / 2, 0), rBitmap);
1069         m_xControl->insert(nPos, rEntry.GetName(), nullptr, nullptr, pVD);
1070     }
1071     else
1072     {
1073         m_xControl->insert_text(nPos, rEntry.GetName());
1074     }
1075 }
1076 
Resize()1077 void SvxXLinePreview::Resize()
1078 {
1079     SvxPreviewBase::Resize();
1080 
1081     const Size aOutputSize(GetOutputSize());
1082     const sal_Int32 nDistance(500);
1083     const sal_Int32 nAvailableLength(aOutputSize.Width() - (4 * nDistance));
1084 
1085     // create DrawObjectA
1086     const sal_Int32 aYPosA(aOutputSize.Height() / 2);
1087     const basegfx::B2DPoint aPointA1( nDistance,  aYPosA);
1088     const basegfx::B2DPoint aPointA2( aPointA1.getX() + ((nAvailableLength * 14) / 20), aYPosA );
1089     basegfx::B2DPolygon aPolygonA;
1090     aPolygonA.append(aPointA1);
1091     aPolygonA.append(aPointA2);
1092     mpLineObjA->SetPathPoly(basegfx::B2DPolyPolygon(aPolygonA));
1093 
1094     // create DrawObjectB
1095     const sal_Int32 aYPosB1((aOutputSize.Height() * 3) / 4);
1096     const sal_Int32 aYPosB2((aOutputSize.Height() * 1) / 4);
1097     const basegfx::B2DPoint aPointB1( aPointA2.getX() + nDistance,  aYPosB1);
1098     const basegfx::B2DPoint aPointB2( aPointB1.getX() + ((nAvailableLength * 2) / 20), aYPosB2 );
1099     const basegfx::B2DPoint aPointB3( aPointB2.getX() + ((nAvailableLength * 2) / 20), aYPosB1 );
1100     basegfx::B2DPolygon aPolygonB;
1101     aPolygonB.append(aPointB1);
1102     aPolygonB.append(aPointB2);
1103     aPolygonB.append(aPointB3);
1104     mpLineObjB->SetPathPoly(basegfx::B2DPolyPolygon(aPolygonB));
1105 
1106     // create DrawObjectC
1107     basegfx::B2DPolygon aPolygonC;
1108     const basegfx::B2DPoint aPointC1( aPointB3.getX() + nDistance,  aYPosB1);
1109     const basegfx::B2DPoint aPointC2( aPointC1.getX() + ((nAvailableLength * 1) / 20), aYPosB2 );
1110     const basegfx::B2DPoint aPointC3( aPointC2.getX() + ((nAvailableLength * 1) / 20), aYPosB1 );
1111     aPolygonC.append(aPointC1);
1112     aPolygonC.append(aPointC2);
1113     aPolygonC.append(aPointC3);
1114     mpLineObjC->SetPathPoly(basegfx::B2DPolyPolygon(aPolygonC));
1115 }
1116 
SvxXLinePreview()1117 SvxXLinePreview::SvxXLinePreview()
1118     : mpGraphic(nullptr)
1119     , mbWithSymbol(false)
1120 {
1121 }
1122 
SetDrawingArea(weld::DrawingArea * pDrawingArea)1123 void SvxXLinePreview::SetDrawingArea(weld::DrawingArea* pDrawingArea)
1124 {
1125     SvxPreviewBase::SetDrawingArea(pDrawingArea);
1126 
1127     mpLineObjA = new SdrPathObj(getModel(), SdrObjKind::Line);
1128     mpLineObjB = new SdrPathObj(getModel(), SdrObjKind::PolyLine);
1129     mpLineObjC = new SdrPathObj(getModel(), SdrObjKind::PolyLine);
1130 
1131     Resize();
1132     Invalidate();
1133 }
1134 
~SvxXLinePreview()1135 SvxXLinePreview::~SvxXLinePreview()
1136 {
1137 }
1138 
SetSymbol(Graphic * p,const Size & s)1139 void SvxXLinePreview::SetSymbol(Graphic* p,const Size& s)
1140 {
1141     mpGraphic = p;
1142     maSymbolSize = s;
1143 }
1144 
ResizeSymbol(const Size & s)1145 void SvxXLinePreview::ResizeSymbol(const Size& s)
1146 {
1147     if ( s != maSymbolSize )
1148     {
1149         maSymbolSize = s;
1150         Invalidate();
1151     }
1152 }
1153 
SetLineAttributes(const SfxItemSet & rItemSet)1154 void SvxXLinePreview::SetLineAttributes(const SfxItemSet& rItemSet)
1155 {
1156     // Set ItemSet at objects
1157     mpLineObjA->SetMergedItemSet(rItemSet);
1158 
1159     // At line joints, do not use arrows
1160     SfxItemSet aTempSet(rItemSet);
1161     aTempSet.ClearItem(XATTR_LINESTART);
1162     aTempSet.ClearItem(XATTR_LINEEND);
1163 
1164     mpLineObjB->SetMergedItemSet(aTempSet);
1165     mpLineObjC->SetMergedItemSet(aTempSet);
1166 }
1167 
Paint(vcl::RenderContext & rRenderContext,const tools::Rectangle &)1168 void SvxXLinePreview::Paint(vcl::RenderContext& rRenderContext, const tools::Rectangle&)
1169 {
1170     LocalPrePaint(rRenderContext);
1171 
1172     // paint objects to buffer device
1173     sdr::contact::SdrObjectVector aObjectVector;
1174     aObjectVector.push_back(mpLineObjA.get());
1175     aObjectVector.push_back(mpLineObjB.get());
1176     aObjectVector.push_back(mpLineObjC.get());
1177 
1178     sdr::contact::ObjectContactOfObjListPainter aPainter(getBufferDevice(), std::move(aObjectVector), nullptr);
1179     sdr::contact::DisplayInfo aDisplayInfo;
1180 
1181     // do processing
1182     aPainter.ProcessDisplay(aDisplayInfo);
1183 
1184     if ( mbWithSymbol && mpGraphic )
1185     {
1186         const Size aOutputSize(GetOutputSize());
1187         Point aPos( aOutputSize.Width() / 3, aOutputSize.Height() / 2 );
1188         aPos.AdjustX( -(maSymbolSize.Width() / 2) );
1189         aPos.AdjustY( -(maSymbolSize.Height() / 2) );
1190         mpGraphic->Draw(getBufferDevice(), aPos, maSymbolSize);
1191     }
1192 
1193     LocalPostPaint(rRenderContext);
1194 }
1195 
SvxXShadowPreview()1196 SvxXShadowPreview::SvxXShadowPreview()
1197 {
1198 }
1199 
SetDrawingArea(weld::DrawingArea * pDrawingArea)1200 void SvxXShadowPreview::SetDrawingArea(weld::DrawingArea* pDrawingArea)
1201 {
1202     SvxPreviewBase::SetDrawingArea(pDrawingArea);
1203     InitSettings();
1204 
1205     // prepare size
1206     Size aSize = GetPreviewSize().GetSize();
1207     aSize.setWidth( aSize.Width() / 3 );
1208     aSize.setHeight( aSize.Height() / 3 );
1209 
1210     // create RectangleObject
1211     const tools::Rectangle aObjectSize( Point( aSize.Width(), aSize.Height() ), aSize );
1212     mpRectangleObject = new SdrRectObj(
1213         getModel(),
1214         aObjectSize);
1215 
1216     // create ShadowObject
1217     const tools::Rectangle aShadowSize( Point( aSize.Width(), aSize.Height() ), aSize );
1218     mpRectangleShadow = new SdrRectObj(
1219         getModel(),
1220         aShadowSize);
1221 }
1222 
~SvxXShadowPreview()1223 SvxXShadowPreview::~SvxXShadowPreview()
1224 {
1225 }
1226 
SetRectangleAttributes(const SfxItemSet & rItemSet)1227 void SvxXShadowPreview::SetRectangleAttributes(const SfxItemSet& rItemSet)
1228 {
1229     mpRectangleObject->SetMergedItemSet(rItemSet, true);
1230     mpRectangleObject->SetMergedItem(XLineStyleItem(drawing::LineStyle_NONE));
1231 }
1232 
SetShadowAttributes(const SfxItemSet & rItemSet)1233 void SvxXShadowPreview::SetShadowAttributes(const SfxItemSet& rItemSet)
1234 {
1235     mpRectangleShadow->SetMergedItemSet(rItemSet, true);
1236     mpRectangleShadow->SetMergedItem(XLineStyleItem(drawing::LineStyle_NONE));
1237 }
1238 
SetShadowPosition(const Point & rPos)1239 void SvxXShadowPreview::SetShadowPosition(const Point& rPos)
1240 {
1241     maShadowOffset = rPos;
1242 }
1243 
Paint(vcl::RenderContext & rRenderContext,const tools::Rectangle &)1244 void SvxXShadowPreview::Paint(vcl::RenderContext& rRenderContext, const tools::Rectangle&)
1245 {
1246     auto popIt = rRenderContext.ScopedPush(vcl::PushFlags::MAPMODE);
1247     rRenderContext.SetMapMode(MapMode(MapUnit::Map100thMM));
1248 
1249     LocalPrePaint(rRenderContext);
1250 
1251     // prepare size
1252     Size aSize = rRenderContext.GetOutputSize();
1253     aSize.setWidth( aSize.Width() / 3 );
1254     aSize.setHeight( aSize.Height() / 3 );
1255 
1256     tools::Rectangle aObjectRect(Point(aSize.Width(), aSize.Height()), aSize);
1257     mpRectangleObject->SetSnapRect(aObjectRect);
1258     aObjectRect.Move(maShadowOffset.X(), maShadowOffset.Y());
1259     mpRectangleShadow->SetSnapRect(aObjectRect);
1260 
1261     sdr::contact::SdrObjectVector aObjectVector;
1262 
1263     aObjectVector.push_back(mpRectangleShadow.get());
1264     aObjectVector.push_back(mpRectangleObject.get());
1265 
1266     sdr::contact::ObjectContactOfObjListPainter aPainter(getBufferDevice(), std::move(aObjectVector), nullptr);
1267     sdr::contact::DisplayInfo aDisplayInfo;
1268 
1269     aPainter.ProcessDisplay(aDisplayInfo);
1270 
1271     LocalPostPaint(rRenderContext);
1272 }
1273 
InitSettings()1274 void SvxPreviewBase::InitSettings()
1275 {
1276     const StyleSettings& rStyleSettings = Application::GetSettings().GetStyleSettings();
1277 
1278     svtools::ColorConfig aColorConfig;
1279     Color aTextColor(aColorConfig.GetColorValue(svtools::FONTCOLOR).nColor);
1280     getBufferDevice().SetTextColor(aTextColor);
1281 
1282     getBufferDevice().SetBackground(rStyleSettings.GetWindowColor());
1283 
1284     getBufferDevice().SetDrawMode(rStyleSettings.GetHighContrastMode() ? OUTPUT_DRAWMODE_CONTRAST : OUTPUT_DRAWMODE_COLOR);
1285 
1286     Invalidate();
1287 }
1288 
SvxPreviewBase()1289 SvxPreviewBase::SvxPreviewBase()
1290     : mpModel(new SdrModel(nullptr, nullptr, true))
1291 {
1292 }
1293 
SetDrawingArea(weld::DrawingArea * pDrawingArea)1294 void SvxPreviewBase::SetDrawingArea(weld::DrawingArea* pDrawingArea)
1295 {
1296     CustomWidgetController::SetDrawingArea(pDrawingArea);
1297     Size aSize(getPreviewStripSize(pDrawingArea->get_ref_device()));
1298     pDrawingArea->set_size_request(aSize.Width(), aSize.Height());
1299     SetOutputSizePixel(aSize);
1300 
1301     mpBufferDevice = VclPtr<VirtualDevice>::Create(pDrawingArea->get_ref_device());
1302     mpBufferDevice->SetMapMode(MapMode(MapUnit::Map100thMM));
1303 }
1304 
~SvxPreviewBase()1305 SvxPreviewBase::~SvxPreviewBase()
1306 {
1307     mpModel.reset();
1308     mpBufferDevice.disposeAndClear();
1309 }
1310 
LocalPrePaint(vcl::RenderContext const & rRenderContext)1311 void SvxPreviewBase::LocalPrePaint(vcl::RenderContext const & rRenderContext)
1312 {
1313     // init BufferDevice
1314     if (mpBufferDevice->GetOutputSizePixel() != GetOutputSizePixel())
1315         mpBufferDevice->SetOutputSizePixel(GetOutputSizePixel());
1316     mpBufferDevice->SetAntialiasing(rRenderContext.GetAntialiasing());
1317 
1318     const StyleSettings& rStyleSettings = Application::GetSettings().GetStyleSettings();
1319 
1320     if (rStyleSettings.GetPreviewUsesCheckeredBackground())
1321     {
1322         const Point aNull(0, 0);
1323         static const sal_uInt32 nLen(8);
1324         static const Color aW(COL_WHITE);
1325         static const Color aG(0xef, 0xef, 0xef);
1326         const bool bWasEnabled(mpBufferDevice->IsMapModeEnabled());
1327 
1328         mpBufferDevice->EnableMapMode(false);
1329         mpBufferDevice->DrawCheckered(aNull, mpBufferDevice->GetOutputSizePixel(), nLen, aW, aG);
1330         mpBufferDevice->EnableMapMode(bWasEnabled);
1331     }
1332     else
1333     {
1334         mpBufferDevice->Erase();
1335     }
1336 }
1337 
LocalPostPaint(vcl::RenderContext & rRenderContext)1338 void SvxPreviewBase::LocalPostPaint(vcl::RenderContext& rRenderContext)
1339 {
1340     // copy to front (in pixel mode)
1341     const bool bWasEnabledSrc(mpBufferDevice->IsMapModeEnabled());
1342     const bool bWasEnabledDst(rRenderContext.IsMapModeEnabled());
1343     const Point aEmptyPoint;
1344 
1345     mpBufferDevice->EnableMapMode(false);
1346     rRenderContext.EnableMapMode(false);
1347 
1348     rRenderContext.DrawOutDev(aEmptyPoint, GetOutputSizePixel(),
1349                               aEmptyPoint, GetOutputSizePixel(),
1350                               *mpBufferDevice);
1351 
1352     mpBufferDevice->EnableMapMode(bWasEnabledSrc);
1353     rRenderContext.EnableMapMode(bWasEnabledDst);
1354 }
1355 
StyleUpdated()1356 void SvxPreviewBase::StyleUpdated()
1357 {
1358     InitSettings();
1359     CustomWidgetController::StyleUpdated();
1360 }
1361 
SvxXRectPreview()1362 SvxXRectPreview::SvxXRectPreview()
1363 {
1364 }
1365 
GetPreviewSize() const1366 tools::Rectangle SvxPreviewBase::GetPreviewSize() const
1367 {
1368     tools::Rectangle aObjectSize(Point(), getBufferDevice().PixelToLogic(GetOutputSizePixel()));
1369     return aObjectSize;
1370 }
1371 
SetDrawingArea(weld::DrawingArea * pDrawingArea)1372 void SvxXRectPreview::SetDrawingArea(weld::DrawingArea* pDrawingArea)
1373 {
1374     SvxPreviewBase::SetDrawingArea(pDrawingArea);
1375     InitSettings();
1376 
1377     // create RectangleObject
1378     mpRectangleObject = new SdrRectObj(getModel(), GetPreviewSize());
1379 }
1380 
Resize()1381 void SvxXRectPreview::Resize()
1382 {
1383     rtl::Reference<SdrObject> pOrigObject = mpRectangleObject;
1384     if (pOrigObject)
1385     {
1386         mpRectangleObject = new SdrRectObj(getModel(), GetPreviewSize());
1387         SetAttributes(pOrigObject->GetMergedItemSet());
1388         pOrigObject.clear();
1389     }
1390     SvxPreviewBase::Resize();
1391 }
1392 
~SvxXRectPreview()1393 SvxXRectPreview::~SvxXRectPreview()
1394 {
1395 }
1396 
SetAttributes(const SfxItemSet & rItemSet)1397 void SvxXRectPreview::SetAttributes(const SfxItemSet& rItemSet)
1398 {
1399     mpRectangleObject->SetMergedItemSet(rItemSet, true);
1400     mpRectangleObject->SetMergedItem(XLineStyleItem(drawing::LineStyle_NONE));
1401 }
1402 
Paint(vcl::RenderContext & rRenderContext,const tools::Rectangle &)1403 void SvxXRectPreview::Paint(vcl::RenderContext& rRenderContext, const tools::Rectangle&)
1404 {
1405     auto popIt = rRenderContext.ScopedPush(vcl::PushFlags::MAPMODE);
1406     rRenderContext.SetMapMode(MapMode(MapUnit::Map100thMM));
1407     LocalPrePaint(rRenderContext);
1408 
1409     sdr::contact::SdrObjectVector aObjectVector;
1410 
1411     aObjectVector.push_back(mpRectangleObject.get());
1412 
1413     sdr::contact::ObjectContactOfObjListPainter aPainter(getBufferDevice(), std::move(aObjectVector), nullptr);
1414     sdr::contact::DisplayInfo aDisplayInfo;
1415 
1416     aPainter.ProcessDisplay(aDisplayInfo);
1417 
1418     LocalPostPaint(rRenderContext);
1419 }
1420 
limitWidthForSidebar(weld::SpinButton & rSpinButton)1421 void limitWidthForSidebar(weld::SpinButton& rSpinButton)
1422 {
1423     // space is limited in the sidebar, so limit MetricSpinButtons to a width of 4 digits
1424     const int nMaxDigits = 4;
1425     rSpinButton.set_width_chars(std::min(rSpinButton.get_width_chars(), nMaxDigits));
1426 }
1427 
limitWidthForSidebar(SvxRelativeField & rMetricSpinButton)1428 void limitWidthForSidebar(SvxRelativeField& rMetricSpinButton)
1429 {
1430     weld::SpinButton& rSpinButton = rMetricSpinButton.get_widget();
1431     limitWidthForSidebar(rSpinButton);
1432 }
1433 
padWidthForSidebar(weld::Toolbar & rToolbar,const css::uno::Reference<css::frame::XFrame> & rFrame)1434 void padWidthForSidebar(weld::Toolbar& rToolbar, const css::uno::Reference<css::frame::XFrame>& rFrame)
1435 {
1436     static int nColumnWidth = -1;
1437     static vcl::ImageType eSize;
1438     if (nColumnWidth != -1 && eSize != rToolbar.get_icon_size())
1439         nColumnWidth = -1;
1440     if (nColumnWidth == -1)
1441     {
1442         // use the, filled-in by dispatcher, width of measurewidth as the width
1443         // of a "standard" column in a two column panel
1444         std::unique_ptr<weld::Builder> xBuilder(Application::CreateBuilder(&rToolbar, u"svx/ui/measurewidthbar.ui"_ustr));
1445         std::unique_ptr<weld::Toolbar> xToolbar1(xBuilder->weld_toolbar(u"measurewidth1"_ustr));
1446         ToolbarUnoDispatcher aDispatcher1(*xToolbar1, *xBuilder, rFrame);
1447         std::unique_ptr<weld::Toolbar> xToolbar2(xBuilder->weld_toolbar(u"measurewidth2"_ustr));
1448         ToolbarUnoDispatcher aDispatcher2(*xToolbar2, *xBuilder, rFrame);
1449         nColumnWidth = std::max(xToolbar1->get_preferred_size().Width(), xToolbar2->get_preferred_size().Width());
1450         eSize = rToolbar.get_icon_size();
1451     }
1452     rToolbar.set_size_request(nColumnWidth, -1);
1453 }
1454 
1455 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
1456