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