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