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