File: | home/maarten/src/libreoffice/core/svtools/source/control/valueset.cxx |
Warning: | line 395, column 40 Division by zero |
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 <sal/config.h> | |||
21 | ||||
22 | #include <o3tl/safeint.hxx> | |||
23 | #include <tools/debug.hxx> | |||
24 | #include <tools/stream.hxx> | |||
25 | #include <comphelper/base64.hxx> | |||
26 | #include <vcl/decoview.hxx> | |||
27 | #include <vcl/event.hxx> | |||
28 | #include <vcl/graph.hxx> | |||
29 | #include <vcl/svapp.hxx> | |||
30 | #include <vcl/cvtgrf.hxx> | |||
31 | #include <vcl/help.hxx> | |||
32 | #include <vcl/settings.hxx> | |||
33 | #include <vcl/commandevent.hxx> | |||
34 | #include <vcl/virdev.hxx> | |||
35 | ||||
36 | #include <com/sun/star/accessibility/AccessibleEventId.hpp> | |||
37 | #include <com/sun/star/lang/XComponent.hpp> | |||
38 | #include <rtl/ustring.hxx> | |||
39 | #include <sal/log.hxx> | |||
40 | #include "valueimp.hxx" | |||
41 | ||||
42 | #include <svtools/valueset.hxx> | |||
43 | #include <boost/property_tree/ptree.hpp> | |||
44 | ||||
45 | #include <uiobject.hxx> | |||
46 | #include <vcl/uitest/logger.hxx> | |||
47 | #include <vcl/uitest/eventdescription.hxx> | |||
48 | ||||
49 | using namespace css::uno; | |||
50 | using namespace css::lang; | |||
51 | using namespace css::accessibility; | |||
52 | ||||
53 | namespace | |||
54 | { | |||
55 | void collectUIInformation( const OUString& aID , const OUString& aParentID , const OUString& aPos ) | |||
56 | { | |||
57 | EventDescription aDescription; | |||
58 | aDescription.aID = aID ; | |||
59 | aDescription.aParameters = {{"POS", aPos }}; | |||
60 | aDescription.aAction = "SELECT"; | |||
61 | aDescription.aKeyWord = "ValueSet"; | |||
62 | aDescription.aParent = aParentID; | |||
63 | UITestLogger::getInstance().logEvent(aDescription); | |||
64 | } | |||
65 | ||||
66 | enum | |||
67 | { | |||
68 | ITEM_OFFSET = 4, | |||
69 | ITEM_OFFSET_DOUBLE = 6, | |||
70 | NAME_LINE_OFF_X = 2, | |||
71 | NAME_LINE_OFF_Y = 2, | |||
72 | NAME_LINE_HEIGHT = 2, | |||
73 | NAME_OFFSET = 2, | |||
74 | }; | |||
75 | ||||
76 | } | |||
77 | ||||
78 | ValueSet::ValueSet(std::unique_ptr<weld::ScrolledWindow> pScrolledWindow) | |||
79 | : maVirDev( VclPtr<VirtualDevice>::Create()) | |||
80 | , mxScrolledWindow(std::move(pScrolledWindow)) | |||
81 | , mnHighItemId(0) | |||
82 | , maColor(COL_TRANSPARENT) | |||
83 | , mnStyle(0) | |||
84 | , mbFormat(true) | |||
85 | , mbHighlight(false) | |||
86 | { | |||
87 | maVirDev->SetBackground(Application::GetSettings().GetStyleSettings().GetFaceColor()); | |||
88 | ||||
89 | mnItemWidth = 0; | |||
90 | mnItemHeight = 0; | |||
91 | mnTextOffset = 0; | |||
92 | mnVisLines = 0; | |||
93 | mnLines = 0; | |||
94 | mnUserItemWidth = 0; | |||
95 | mnUserItemHeight = 0; | |||
96 | mnFirstLine = 0; | |||
97 | mnSelItemId = 0; | |||
98 | mnSavedItemId = -1; | |||
99 | mnCols = 0; | |||
100 | mnCurCol = 0; | |||
101 | mnUserCols = 0; | |||
102 | mnUserVisLines = 0; | |||
103 | mnSpacing = 0; | |||
104 | mnFrameStyle = DrawFrameStyle::NONE; | |||
105 | mbNoSelection = true; | |||
106 | mbDrawSelection = true; | |||
107 | mbBlackSel = false; | |||
108 | mbDoubleSel = false; | |||
109 | mbScroll = false; | |||
110 | mbFullMode = true; | |||
111 | mbEdgeBlending = false; | |||
112 | mbHasVisibleItems = false; | |||
113 | ||||
114 | if (mxScrolledWindow) | |||
115 | mxScrolledWindow->connect_vadjustment_changed(LINK(this, ValueSet, ImplScrollHdl)::tools::detail::makeLink( ::tools::detail::castTo<ValueSet *>(this), &ValueSet::LinkStubImplScrollHdl)); | |||
116 | } | |||
117 | ||||
118 | void ValueSet::SetDrawingArea(weld::DrawingArea* pDrawingArea) | |||
119 | { | |||
120 | CustomWidgetController::SetDrawingArea(pDrawingArea); | |||
121 | // #106446#, #106601# force mirroring of virtual device | |||
122 | maVirDev->EnableRTL(pDrawingArea->get_direction()); | |||
123 | } | |||
124 | ||||
125 | Reference<XAccessible> ValueSet::CreateAccessible() | |||
126 | { | |||
127 | if (!mxAccessible) | |||
128 | mxAccessible.set(new ValueSetAcc(this)); | |||
129 | return mxAccessible; | |||
130 | } | |||
131 | ||||
132 | ValueSet::~ValueSet() | |||
133 | { | |||
134 | Reference<XComponent> xComponent(mxAccessible, UNO_QUERY); | |||
135 | if (xComponent.is()) | |||
136 | xComponent->dispose(); | |||
137 | ||||
138 | ImplDeleteItems(); | |||
139 | } | |||
140 | ||||
141 | void ValueSet::ImplDeleteItems() | |||
142 | { | |||
143 | const size_t n = mItemList.size(); | |||
144 | ||||
145 | for ( size_t i = 0; i < n; ++i ) | |||
146 | { | |||
147 | ValueSetItem* pItem = mItemList[i].get(); | |||
148 | if ( pItem->mbVisible && ImplHasAccessibleListeners() ) | |||
149 | { | |||
150 | Any aOldAny; | |||
151 | Any aNewAny; | |||
152 | ||||
153 | aOldAny <<= pItem->GetAccessible( false/*bIsTransientChildrenDisabled*/ ); | |||
154 | ImplFireAccessibleEvent(AccessibleEventId::CHILD, aOldAny, aNewAny); | |||
155 | } | |||
156 | ||||
157 | mItemList[i].reset(); | |||
158 | } | |||
159 | ||||
160 | mItemList.clear(); | |||
161 | } | |||
162 | ||||
163 | void ValueSet::Select() | |||
164 | { | |||
165 | collectUIInformation(OStringToOUString(GetDrawingArea()->get_buildable_name(),RTL_TEXTENCODING_UTF8(((rtl_TextEncoding) 76))) , OStringToOUString(GetDrawingArea()->get_help_id(),RTL_TEXTENCODING_UTF8(((rtl_TextEncoding) 76))) , OUString::number(GetSelectedItemId())); | |||
166 | maSelectHdl.Call( this ); | |||
167 | } | |||
168 | ||||
169 | void ValueSet::UserDraw( const UserDrawEvent& ) | |||
170 | { | |||
171 | } | |||
172 | ||||
173 | size_t ValueSet::ImplGetItem( const Point& rPos ) const | |||
174 | { | |||
175 | if (!mbHasVisibleItems) | |||
176 | { | |||
177 | return VALUESET_ITEM_NOTFOUND(size_t(-1)); | |||
178 | } | |||
179 | ||||
180 | if (mpNoneItem && maNoneItemRect.IsInside(rPos)) | |||
181 | { | |||
182 | return VALUESET_ITEM_NONEITEM0xFFFE; | |||
183 | } | |||
184 | ||||
185 | if (maItemListRect.IsInside(rPos)) | |||
186 | { | |||
187 | const int xc = rPos.X() - maItemListRect.Left(); | |||
188 | const int yc = rPos.Y() - maItemListRect.Top(); | |||
189 | // The point is inside the area of item list, | |||
190 | // let's find the containing item. | |||
191 | const int col = xc / (mnItemWidth + mnSpacing); | |||
192 | const int x = xc % (mnItemWidth + mnSpacing); | |||
193 | const int row = yc / (mnItemHeight + mnSpacing); | |||
194 | const int y = yc % (mnItemHeight + mnSpacing); | |||
195 | ||||
196 | if (x < mnItemWidth && y < mnItemHeight) | |||
197 | { | |||
198 | // the point is inside item rect and not inside spacing | |||
199 | const size_t item = (mnFirstLine + row) * static_cast<size_t>(mnCols) + col; | |||
200 | if (item < mItemList.size()) | |||
201 | { | |||
202 | return item; | |||
203 | } | |||
204 | } | |||
205 | } | |||
206 | ||||
207 | return VALUESET_ITEM_NOTFOUND(size_t(-1)); | |||
208 | } | |||
209 | ||||
210 | ValueSetItem* ValueSet::ImplGetItem( size_t nPos ) | |||
211 | { | |||
212 | if (nPos == VALUESET_ITEM_NONEITEM0xFFFE) | |||
213 | return mpNoneItem.get(); | |||
214 | else | |||
215 | return (nPos < mItemList.size()) ? mItemList[nPos].get() : nullptr; | |||
216 | } | |||
217 | ||||
218 | ValueSetItem* ValueSet::ImplGetFirstItem() | |||
219 | { | |||
220 | return !mItemList.empty() ? mItemList[0].get() : nullptr; | |||
221 | } | |||
222 | ||||
223 | sal_uInt16 ValueSet::ImplGetVisibleItemCount() const | |||
224 | { | |||
225 | sal_uInt16 nRet = 0; | |||
226 | const size_t nItemCount = mItemList.size(); | |||
227 | ||||
228 | for ( size_t n = 0; n < nItemCount; ++n ) | |||
229 | { | |||
230 | if ( mItemList[n]->mbVisible ) | |||
231 | ++nRet; | |||
232 | } | |||
233 | ||||
234 | return nRet; | |||
235 | } | |||
236 | ||||
237 | void ValueSet::ImplFireAccessibleEvent( short nEventId, const Any& rOldValue, const Any& rNewValue ) | |||
238 | { | |||
239 | ValueSetAcc* pAcc = ValueSetAcc::getImplementation(mxAccessible); | |||
240 | ||||
241 | if( pAcc ) | |||
242 | pAcc->FireAccessibleEvent( nEventId, rOldValue, rNewValue ); | |||
243 | } | |||
244 | ||||
245 | bool ValueSet::ImplHasAccessibleListeners() | |||
246 | { | |||
247 | ValueSetAcc* pAcc = ValueSetAcc::getImplementation(mxAccessible); | |||
248 | return( pAcc && pAcc->HasAccessibleListeners() ); | |||
249 | } | |||
250 | ||||
251 | IMPL_LINK(ValueSet, ImplScrollHdl, weld::ScrolledWindow&, rScrollWin, void)void ValueSet::LinkStubImplScrollHdl(void * instance, weld::ScrolledWindow & data) { return static_cast<ValueSet *>(instance)-> ImplScrollHdl(data); } void ValueSet::ImplScrollHdl(weld::ScrolledWindow & rScrollWin) | |||
252 | { | |||
253 | auto nNewFirstLine = rScrollWin.vadjustment_get_value(); | |||
254 | if ( nNewFirstLine != mnFirstLine ) | |||
255 | { | |||
256 | mnFirstLine = nNewFirstLine; | |||
257 | mbFormat = true; | |||
258 | Invalidate(); | |||
259 | } | |||
260 | } | |||
261 | ||||
262 | void ValueSet::Paint(vcl::RenderContext& rRenderContext, const tools::Rectangle&) | |||
263 | { | |||
264 | if (GetStyle() & WB_FLATVALUESET(WinBits(0x02000000))) | |||
265 | { | |||
266 | const StyleSettings& rStyleSettings = rRenderContext.GetSettings().GetStyleSettings(); | |||
267 | rRenderContext.SetLineColor(); | |||
268 | rRenderContext.SetFillColor(rStyleSettings.GetFaceColor()); | |||
269 | long nOffY = maVirDev->GetOutputSizePixel().Height(); | |||
270 | Size aWinSize(GetOutputSizePixel()); | |||
271 | rRenderContext.DrawRect(tools::Rectangle(Point(0, nOffY ), Point( aWinSize.Width(), aWinSize.Height()))); | |||
272 | } | |||
273 | ||||
274 | ImplDraw(rRenderContext); | |||
275 | } | |||
276 | ||||
277 | void ValueSet::GetFocus() | |||
278 | { | |||
279 | SAL_INFO("svtools", "value set getting focus")do { if (true) { switch (sal_detail_log_report(::SAL_DETAIL_LOG_LEVEL_INFO , "svtools")) { case SAL_DETAIL_LOG_ACTION_IGNORE: break; case SAL_DETAIL_LOG_ACTION_LOG: if (sizeof ::sal::detail::getResult ( ::sal::detail::StreamStart() << "value set getting focus" ) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_INFO), ("svtools" ), ("/home/maarten/src/libreoffice/core/svtools/source/control/valueset.cxx" ":" "279" ": "), ::sal::detail::unwrapStream( ::sal::detail:: StreamStart() << "value set getting focus"), 0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream << "value set getting focus"; ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_INFO ), ("svtools"), ("/home/maarten/src/libreoffice/core/svtools/source/control/valueset.cxx" ":" "279" ": "), sal_detail_stream, 0); }; break; case SAL_DETAIL_LOG_ACTION_FATAL : if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart () << "value set getting focus") == 1) { ::sal_detail_log ( (::SAL_DETAIL_LOG_LEVEL_INFO), ("svtools"), ("/home/maarten/src/libreoffice/core/svtools/source/control/valueset.cxx" ":" "279" ": "), ::sal::detail::unwrapStream( ::sal::detail:: StreamStart() << "value set getting focus"), 0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream << "value set getting focus"; ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_INFO ), ("svtools"), ("/home/maarten/src/libreoffice/core/svtools/source/control/valueset.cxx" ":" "279" ": "), sal_detail_stream, 0); }; std::abort(); break ; } } } while (false); | |||
280 | Invalidate(); | |||
281 | CustomWidgetController::GetFocus(); | |||
282 | ||||
283 | // Tell the accessible object that we got the focus. | |||
284 | ValueSetAcc* pAcc = ValueSetAcc::getImplementation(mxAccessible); | |||
285 | if (pAcc) | |||
286 | pAcc->GetFocus(); | |||
287 | } | |||
288 | ||||
289 | void ValueSet::LoseFocus() | |||
290 | { | |||
291 | SAL_INFO("svtools", "value set losing focus")do { if (true) { switch (sal_detail_log_report(::SAL_DETAIL_LOG_LEVEL_INFO , "svtools")) { case SAL_DETAIL_LOG_ACTION_IGNORE: break; case SAL_DETAIL_LOG_ACTION_LOG: if (sizeof ::sal::detail::getResult ( ::sal::detail::StreamStart() << "value set losing focus" ) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_INFO), ("svtools" ), ("/home/maarten/src/libreoffice/core/svtools/source/control/valueset.cxx" ":" "291" ": "), ::sal::detail::unwrapStream( ::sal::detail:: StreamStart() << "value set losing focus"), 0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream << "value set losing focus"; ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_INFO ), ("svtools"), ("/home/maarten/src/libreoffice/core/svtools/source/control/valueset.cxx" ":" "291" ": "), sal_detail_stream, 0); }; break; case SAL_DETAIL_LOG_ACTION_FATAL : if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart () << "value set losing focus") == 1) { ::sal_detail_log ( (::SAL_DETAIL_LOG_LEVEL_INFO), ("svtools"), ("/home/maarten/src/libreoffice/core/svtools/source/control/valueset.cxx" ":" "291" ": "), ::sal::detail::unwrapStream( ::sal::detail:: StreamStart() << "value set losing focus"), 0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream << "value set losing focus"; ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_INFO ), ("svtools"), ("/home/maarten/src/libreoffice/core/svtools/source/control/valueset.cxx" ":" "291" ": "), sal_detail_stream, 0); }; std::abort(); break ; } } } while (false); | |||
292 | Invalidate(); | |||
293 | CustomWidgetController::LoseFocus(); | |||
294 | ||||
295 | // Tell the accessible object that we lost the focus. | |||
296 | ValueSetAcc* pAcc = ValueSetAcc::getImplementation(mxAccessible); | |||
297 | if( pAcc ) | |||
298 | pAcc->LoseFocus(); | |||
299 | } | |||
300 | ||||
301 | void ValueSet::Resize() | |||
302 | { | |||
303 | mbFormat = true; | |||
304 | if ( IsReallyVisible() && IsUpdateMode() ) | |||
305 | Invalidate(); | |||
306 | CustomWidgetController::Resize(); | |||
307 | } | |||
308 | ||||
309 | bool ValueSet::KeyInput( const KeyEvent& rKeyEvent ) | |||
310 | { | |||
311 | size_t nLastItem = mItemList.size(); | |||
312 | ||||
313 | if ( !nLastItem || !ImplGetFirstItem() ) | |||
| ||||
314 | return CustomWidgetController::KeyInput(rKeyEvent); | |||
315 | ||||
316 | if (mbFormat) | |||
317 | Invalidate(); | |||
318 | ||||
319 | --nLastItem; | |||
320 | ||||
321 | const size_t nCurPos | |||
322 | = mnSelItemId ? GetItemPos(mnSelItemId) : (mpNoneItem ? VALUESET_ITEM_NONEITEM0xFFFE : 0); | |||
323 | size_t nItemPos = VALUESET_ITEM_NOTFOUND(size_t(-1)); | |||
324 | size_t nVStep = mnCols; | |||
325 | ||||
326 | switch (rKeyEvent.GetKeyCode().GetCode()) | |||
327 | { | |||
328 | case KEY_HOME: | |||
329 | nItemPos = mpNoneItem ? VALUESET_ITEM_NONEITEM0xFFFE : 0; | |||
330 | break; | |||
331 | ||||
332 | case KEY_END: | |||
333 | nItemPos = nLastItem; | |||
334 | break; | |||
335 | ||||
336 | case KEY_LEFT: | |||
337 | if (nCurPos != VALUESET_ITEM_NONEITEM0xFFFE) | |||
338 | { | |||
339 | if (nCurPos) | |||
340 | { | |||
341 | nItemPos = nCurPos-1; | |||
342 | } | |||
343 | else if (mpNoneItem) | |||
344 | { | |||
345 | nItemPos = VALUESET_ITEM_NONEITEM0xFFFE; | |||
346 | } | |||
347 | } | |||
348 | break; | |||
349 | ||||
350 | case KEY_RIGHT: | |||
351 | if (nCurPos < nLastItem) | |||
352 | { | |||
353 | if (nCurPos == VALUESET_ITEM_NONEITEM0xFFFE) | |||
354 | { | |||
355 | nItemPos = 0; | |||
356 | } | |||
357 | else | |||
358 | { | |||
359 | nItemPos = nCurPos+1; | |||
360 | } | |||
361 | } | |||
362 | break; | |||
363 | ||||
364 | case KEY_PAGEUP: | |||
365 | if (rKeyEvent.GetKeyCode().IsShift() || rKeyEvent.GetKeyCode().IsMod1() || rKeyEvent.GetKeyCode().IsMod2()) | |||
366 | { | |||
367 | return CustomWidgetController::KeyInput(rKeyEvent); | |||
368 | } | |||
369 | nVStep *= mnVisLines; | |||
370 | [[fallthrough]]; | |||
371 | case KEY_UP: | |||
372 | if (nCurPos != VALUESET_ITEM_NONEITEM0xFFFE) | |||
373 | { | |||
374 | if (nCurPos == nLastItem) | |||
375 | { | |||
376 | const size_t nCol = mnCols ? nLastItem % mnCols : 0; | |||
377 | if (nCol < mnCurCol) | |||
378 | { | |||
379 | // Move to previous row/page, keeping the old column | |||
380 | nVStep -= mnCurCol - nCol; | |||
381 | } | |||
382 | } | |||
383 | if (nCurPos >= nVStep) | |||
384 | { | |||
385 | // Go up of a whole page | |||
386 | nItemPos = nCurPos-nVStep; | |||
387 | } | |||
388 | else if (mpNoneItem) | |||
389 | { | |||
390 | nItemPos = VALUESET_ITEM_NONEITEM0xFFFE; | |||
391 | } | |||
392 | else if (nCurPos > mnCols) | |||
393 | { | |||
394 | // Go to same column in first row | |||
395 | nItemPos = nCurPos % mnCols; | |||
| ||||
396 | } | |||
397 | } | |||
398 | break; | |||
399 | ||||
400 | case KEY_PAGEDOWN: | |||
401 | if (rKeyEvent.GetKeyCode().IsShift() || rKeyEvent.GetKeyCode().IsMod1() || rKeyEvent.GetKeyCode().IsMod2()) | |||
402 | { | |||
403 | return CustomWidgetController::KeyInput(rKeyEvent); | |||
404 | } | |||
405 | nVStep *= mnVisLines; | |||
406 | [[fallthrough]]; | |||
407 | case KEY_DOWN: | |||
408 | if (nCurPos != nLastItem) | |||
409 | { | |||
410 | if (nCurPos == VALUESET_ITEM_NONEITEM0xFFFE) | |||
411 | { | |||
412 | nItemPos = nVStep-mnCols+mnCurCol; | |||
413 | } | |||
414 | else | |||
415 | { | |||
416 | nItemPos = nCurPos+nVStep; | |||
417 | } | |||
418 | if (nItemPos > nLastItem) | |||
419 | { | |||
420 | nItemPos = nLastItem; | |||
421 | } | |||
422 | } | |||
423 | break; | |||
424 | ||||
425 | case KEY_RETURN: | |||
426 | if (GetStyle() & WB_NO_DIRECTSELECT(WinBits(0x04000000))) | |||
427 | { | |||
428 | Select(); | |||
429 | break; | |||
430 | } | |||
431 | [[fallthrough]]; | |||
432 | default: | |||
433 | return CustomWidgetController::KeyInput(rKeyEvent); | |||
434 | } | |||
435 | ||||
436 | if ( nItemPos == VALUESET_ITEM_NOTFOUND(size_t(-1)) ) | |||
437 | return true; | |||
438 | ||||
439 | if ( nItemPos!=VALUESET_ITEM_NONEITEM0xFFFE && nItemPos<nLastItem ) | |||
440 | { | |||
441 | // update current column only in case of a new position | |||
442 | // which is also not a "specially" handled one. | |||
443 | mnCurCol = mnCols ? nItemPos % mnCols : 0; | |||
444 | } | |||
445 | const sal_uInt16 nItemId = (nItemPos != VALUESET_ITEM_NONEITEM0xFFFE) ? GetItemId( nItemPos ) : 0; | |||
446 | if ( nItemId != mnSelItemId ) | |||
447 | { | |||
448 | SelectItem( nItemId ); | |||
449 | if (!(GetStyle() & WB_NO_DIRECTSELECT(WinBits(0x04000000)))) | |||
450 | { | |||
451 | // select only if WB_NO_DIRECTSELECT is not set | |||
452 | Select(); | |||
453 | } | |||
454 | } | |||
455 | ||||
456 | return true; | |||
457 | } | |||
458 | ||||
459 | void ValueSet::ImplTracking(const Point& rPos) | |||
460 | { | |||
461 | ValueSetItem* pItem = ImplGetItem( ImplGetItem( rPos ) ); | |||
462 | if ( pItem ) | |||
463 | { | |||
464 | if( GetStyle() & WB_MENUSTYLEVALUESET(WinBits(0x08000000)) || GetStyle() & WB_FLATVALUESET(WinBits(0x02000000)) ) | |||
465 | mbHighlight = true; | |||
466 | ||||
467 | ImplHighlightItem( pItem->mnId ); | |||
468 | } | |||
469 | else | |||
470 | { | |||
471 | if( GetStyle() & WB_MENUSTYLEVALUESET(WinBits(0x08000000)) || GetStyle() & WB_FLATVALUESET(WinBits(0x02000000)) ) | |||
472 | mbHighlight = true; | |||
473 | ||||
474 | ImplHighlightItem( mnSelItemId, false ); | |||
475 | } | |||
476 | } | |||
477 | ||||
478 | bool ValueSet::MouseButtonDown( const MouseEvent& rMouseEvent ) | |||
479 | { | |||
480 | if ( rMouseEvent.IsLeft() ) | |||
481 | { | |||
482 | ValueSetItem* pItem = ImplGetItem( ImplGetItem( rMouseEvent.GetPosPixel() ) ); | |||
483 | if (pItem && !rMouseEvent.IsMod2()) | |||
484 | { | |||
485 | if (rMouseEvent.GetClicks() == 1) | |||
486 | { | |||
487 | SelectItem( pItem->mnId ); | |||
488 | if (!(GetStyle() & WB_NOPOINTERFOCUS)) | |||
489 | GrabFocus(); | |||
490 | } | |||
491 | else if ( rMouseEvent.GetClicks() == 2 ) | |||
492 | maDoubleClickHdl.Call( this ); | |||
493 | ||||
494 | return true; | |||
495 | } | |||
496 | } | |||
497 | ||||
498 | return CustomWidgetController::MouseButtonDown( rMouseEvent ); | |||
499 | } | |||
500 | ||||
501 | bool ValueSet::MouseButtonUp( const MouseEvent& rMouseEvent ) | |||
502 | { | |||
503 | if (rMouseEvent.IsLeft() && !rMouseEvent.IsMod2()) | |||
504 | { | |||
505 | Select(); | |||
506 | return true; | |||
507 | } | |||
508 | ||||
509 | return CustomWidgetController::MouseButtonUp( rMouseEvent ); | |||
510 | } | |||
511 | ||||
512 | bool ValueSet::MouseMove(const MouseEvent& rMouseEvent) | |||
513 | { | |||
514 | // because of SelectionMode | |||
515 | if ((GetStyle() & WB_MENUSTYLEVALUESET(WinBits(0x08000000))) || (GetStyle() & WB_FLATVALUESET(WinBits(0x02000000)))) | |||
516 | ImplTracking(rMouseEvent.GetPosPixel()); | |||
517 | return CustomWidgetController::MouseMove(rMouseEvent); | |||
518 | } | |||
519 | ||||
520 | void ValueSet::QueueReformat() | |||
521 | { | |||
522 | queue_resize(); | |||
523 | RecalcScrollBar(); | |||
524 | mbFormat = true; | |||
525 | if ( IsReallyVisible() && IsUpdateMode() ) | |||
526 | Invalidate(); | |||
527 | } | |||
528 | ||||
529 | void ValueSet::RemoveItem( sal_uInt16 nItemId ) | |||
530 | { | |||
531 | size_t nPos = GetItemPos( nItemId ); | |||
532 | ||||
533 | if ( nPos == VALUESET_ITEM_NOTFOUND(size_t(-1)) ) | |||
534 | return; | |||
535 | ||||
536 | if ( nPos < mItemList.size() ) { | |||
537 | mItemList.erase( mItemList.begin() + nPos ); | |||
538 | } | |||
539 | ||||
540 | // reset variables | |||
541 | if (mnHighItemId == nItemId || mnSelItemId == nItemId) | |||
542 | { | |||
543 | mnCurCol = 0; | |||
544 | mnHighItemId = 0; | |||
545 | mnSelItemId = 0; | |||
546 | mbNoSelection = true; | |||
547 | } | |||
548 | ||||
549 | QueueReformat(); | |||
550 | } | |||
551 | ||||
552 | void ValueSet::TurnOffScrollBar() | |||
553 | { | |||
554 | if (mxScrolledWindow->get_vpolicy() == VclPolicyType::NEVER) | |||
555 | return; | |||
556 | mxScrolledWindow->set_vpolicy(VclPolicyType::NEVER); | |||
557 | weld::DrawingArea* pDrawingArea = GetDrawingArea(); | |||
558 | Size aPrefSize(pDrawingArea->get_preferred_size()); | |||
559 | pDrawingArea->set_size_request(aPrefSize.Width() + GetScrollWidth(), aPrefSize.Height()); | |||
560 | } | |||
561 | ||||
562 | void ValueSet::TurnOnScrollBar() | |||
563 | { | |||
564 | if (mxScrolledWindow->get_vpolicy() == VclPolicyType::ALWAYS) | |||
565 | return; | |||
566 | mxScrolledWindow->set_vpolicy(VclPolicyType::ALWAYS); | |||
567 | weld::DrawingArea* pDrawingArea = GetDrawingArea(); | |||
568 | Size aPrefSize(pDrawingArea->get_preferred_size()); | |||
569 | pDrawingArea->set_size_request(aPrefSize.Width() - GetScrollWidth(), aPrefSize.Height()); | |||
570 | } | |||
571 | ||||
572 | void ValueSet::RecalcScrollBar() | |||
573 | { | |||
574 | // reset scrolled window state to initial value | |||
575 | // so it will get configured to the right adjustment | |||
576 | WinBits nStyle = GetStyle(); | |||
577 | if (mxScrolledWindow && (nStyle & WB_VSCROLL)) | |||
578 | TurnOffScrollBar(); | |||
579 | } | |||
580 | ||||
581 | void ValueSet::Clear() | |||
582 | { | |||
583 | ImplDeleteItems(); | |||
584 | ||||
585 | // reset variables | |||
586 | mnFirstLine = 0; | |||
587 | mnCurCol = 0; | |||
588 | mnHighItemId = 0; | |||
589 | mnSelItemId = 0; | |||
590 | mbNoSelection = true; | |||
591 | ||||
592 | RecalcScrollBar(); | |||
593 | ||||
594 | mbFormat = true; | |||
595 | if ( IsReallyVisible() && IsUpdateMode() ) | |||
596 | Invalidate(); | |||
597 | } | |||
598 | ||||
599 | size_t ValueSet::GetItemCount() const | |||
600 | { | |||
601 | return mItemList.size(); | |||
602 | } | |||
603 | ||||
604 | size_t ValueSet::GetItemPos( sal_uInt16 nItemId ) const | |||
605 | { | |||
606 | for ( size_t i = 0, n = mItemList.size(); i < n; ++i ) { | |||
607 | if ( mItemList[i]->mnId == nItemId ) { | |||
608 | return i; | |||
609 | } | |||
610 | } | |||
611 | return VALUESET_ITEM_NOTFOUND(size_t(-1)); | |||
612 | } | |||
613 | ||||
614 | sal_uInt16 ValueSet::GetItemId( size_t nPos ) const | |||
615 | { | |||
616 | return ( nPos < mItemList.size() ) ? mItemList[nPos]->mnId : 0 ; | |||
617 | } | |||
618 | ||||
619 | sal_uInt16 ValueSet::GetItemId( const Point& rPos ) const | |||
620 | { | |||
621 | size_t nItemPos = ImplGetItem( rPos ); | |||
622 | if ( nItemPos != VALUESET_ITEM_NOTFOUND(size_t(-1)) ) | |||
623 | return GetItemId( nItemPos ); | |||
624 | ||||
625 | return 0; | |||
626 | } | |||
627 | ||||
628 | tools::Rectangle ValueSet::GetItemRect( sal_uInt16 nItemId ) const | |||
629 | { | |||
630 | const size_t nPos = GetItemPos( nItemId ); | |||
631 | ||||
632 | if ( nPos!=VALUESET_ITEM_NOTFOUND(size_t(-1)) && mItemList[nPos]->mbVisible ) | |||
633 | return ImplGetItemRect( nPos ); | |||
634 | ||||
635 | return tools::Rectangle(); | |||
636 | } | |||
637 | ||||
638 | tools::Rectangle ValueSet::ImplGetItemRect( size_t nPos ) const | |||
639 | { | |||
640 | const size_t nVisibleBegin = static_cast<size_t>(mnFirstLine)*mnCols; | |||
641 | const size_t nVisibleEnd = nVisibleBegin + static_cast<size_t>(mnVisLines)*mnCols; | |||
642 | ||||
643 | // Check if the item is inside the range of the displayed ones, | |||
644 | // taking into account that last row could be incomplete | |||
645 | if ( nPos<nVisibleBegin || nPos>=nVisibleEnd || nPos>=mItemList.size() ) | |||
646 | return tools::Rectangle(); | |||
647 | ||||
648 | nPos -= nVisibleBegin; | |||
649 | ||||
650 | const size_t row = mnCols ? nPos/mnCols : 0; | |||
651 | const size_t col = mnCols ? nPos%mnCols : 0; | |||
652 | const long x = maItemListRect.Left()+col*(mnItemWidth+mnSpacing); | |||
653 | const long y = maItemListRect.Top()+row*(mnItemHeight+mnSpacing); | |||
654 | ||||
655 | return tools::Rectangle( Point(x, y), Size(mnItemWidth, mnItemHeight) ); | |||
656 | } | |||
657 | ||||
658 | void ValueSet::ImplHighlightItem( sal_uInt16 nItemId, bool bIsSelection ) | |||
659 | { | |||
660 | if ( mnHighItemId == nItemId ) | |||
661 | return; | |||
662 | ||||
663 | // remember the old item to delete the previous selection | |||
664 | mnHighItemId = nItemId; | |||
665 | ||||
666 | // don't draw the selection if nothing is selected | |||
667 | if ( !bIsSelection && mbNoSelection ) | |||
668 | mbDrawSelection = false; | |||
669 | ||||
670 | // remove the old selection and draw the new one | |||
671 | Invalidate(); | |||
672 | mbDrawSelection = true; | |||
673 | } | |||
674 | ||||
675 | void ValueSet::ImplDraw(vcl::RenderContext& rRenderContext) | |||
676 | { | |||
677 | if (mbFormat) | |||
678 | Format(rRenderContext); | |||
679 | ||||
680 | Point aDefPos; | |||
681 | Size aSize = maVirDev->GetOutputSizePixel(); | |||
682 | ||||
683 | rRenderContext.DrawOutDev(aDefPos, aSize, aDefPos, aSize, *maVirDev); | |||
684 | ||||
685 | // draw parting line to the Namefield | |||
686 | if (GetStyle() & WB_NAMEFIELD(WinBits(0x00040000))) | |||
687 | { | |||
688 | if (!(GetStyle() & WB_FLATVALUESET(WinBits(0x02000000)))) | |||
689 | { | |||
690 | const StyleSettings& rStyleSettings = rRenderContext.GetSettings().GetStyleSettings(); | |||
691 | Size aWinSize(GetOutputSizePixel()); | |||
692 | Point aPos1(NAME_LINE_OFF_X, mnTextOffset + NAME_LINE_OFF_Y); | |||
693 | Point aPos2(aWinSize.Width() - (NAME_LINE_OFF_X * 2), mnTextOffset + NAME_LINE_OFF_Y); | |||
694 | if (!(rStyleSettings.GetOptions() & StyleSettingsOptions::Mono)) | |||
695 | { | |||
696 | rRenderContext.SetLineColor(rStyleSettings.GetShadowColor()); | |||
697 | rRenderContext.DrawLine(aPos1, aPos2); | |||
698 | aPos1.AdjustY( 1 ); | |||
699 | aPos2.AdjustY( 1 ); | |||
700 | rRenderContext.SetLineColor(rStyleSettings.GetLightColor()); | |||
701 | } | |||
702 | else | |||
703 | rRenderContext.SetLineColor(rStyleSettings.GetWindowTextColor()); | |||
704 | rRenderContext.DrawLine(aPos1, aPos2); | |||
705 | } | |||
706 | } | |||
707 | ||||
708 | ImplDrawSelect(rRenderContext); | |||
709 | } | |||
710 | ||||
711 | /** | |||
712 | * An inelegant method; sets the item width & height such that | |||
713 | * all of the included items and their labels fit; if we can | |||
714 | * calculate that. | |||
715 | */ | |||
716 | void ValueSet::RecalculateItemSizes() | |||
717 | { | |||
718 | Size aLargestItem = GetLargestItemSize(); | |||
719 | ||||
720 | if ( mnUserItemWidth != aLargestItem.Width() || | |||
721 | mnUserItemHeight != aLargestItem.Height() ) | |||
722 | { | |||
723 | mnUserItemWidth = aLargestItem.Width(); | |||
724 | mnUserItemHeight = aLargestItem.Height(); | |||
725 | QueueReformat(); | |||
726 | } | |||
727 | } | |||
728 | ||||
729 | void ValueSet::SetFirstLine(sal_uInt16 nNewFirstLine) | |||
730 | { | |||
731 | if (nNewFirstLine != mnFirstLine) | |||
732 | { | |||
733 | mnFirstLine = nNewFirstLine; | |||
734 | if (mxScrolledWindow) | |||
735 | mxScrolledWindow->vadjustment_set_value(mnFirstLine); | |||
736 | } | |||
737 | } | |||
738 | ||||
739 | void ValueSet::SelectItem( sal_uInt16 nItemId ) | |||
740 | { | |||
741 | size_t nItemPos = 0; | |||
742 | ||||
743 | if ( nItemId ) | |||
744 | { | |||
745 | nItemPos = GetItemPos( nItemId ); | |||
746 | if ( nItemPos == VALUESET_ITEM_NOTFOUND(size_t(-1)) ) | |||
747 | return; | |||
748 | } | |||
749 | ||||
750 | if ( !((mnSelItemId != nItemId) || mbNoSelection) ) | |||
751 | return; | |||
752 | ||||
753 | const sal_uInt16 nOldItem = mnSelItemId; | |||
754 | mnSelItemId = nItemId; | |||
755 | mbNoSelection = false; | |||
756 | ||||
757 | bool bNewOut = !mbFormat && IsReallyVisible() && IsUpdateMode(); | |||
758 | bool bNewLine = false; | |||
759 | ||||
760 | if (weld::DrawingArea* pNeedsFormatToScroll = !mnCols ? GetDrawingArea() : nullptr) | |||
761 | { | |||
762 | Format(pNeedsFormatToScroll->get_ref_device()); | |||
763 | // reset scrollbar so its set to the later calculated mnFirstLine on | |||
764 | // the next Format | |||
765 | RecalcScrollBar(); // reset scrollbar so its set to the later calculated | |||
766 | } | |||
767 | ||||
768 | // if necessary scroll to the visible area | |||
769 | if (mbScroll && nItemId && mnCols) | |||
770 | { | |||
771 | sal_uInt16 nNewLine = static_cast<sal_uInt16>(nItemPos / mnCols); | |||
772 | if ( nNewLine < mnFirstLine ) | |||
773 | { | |||
774 | SetFirstLine(nNewLine); | |||
775 | bNewLine = true; | |||
776 | } | |||
777 | else if ( nNewLine > o3tl::make_unsigned(mnFirstLine+mnVisLines-1) ) | |||
778 | { | |||
779 | SetFirstLine(static_cast<sal_uInt16>(nNewLine-mnVisLines+1)); | |||
780 | bNewLine = true; | |||
781 | } | |||
782 | } | |||
783 | ||||
784 | if ( bNewOut ) | |||
785 | { | |||
786 | if ( bNewLine ) | |||
787 | { | |||
788 | // redraw everything if the visible area has changed | |||
789 | mbFormat = true; | |||
790 | } | |||
791 | Invalidate(); | |||
792 | } | |||
793 | ||||
794 | if( !ImplHasAccessibleListeners() ) | |||
795 | return; | |||
796 | ||||
797 | // focus event (deselect) | |||
798 | if( nOldItem ) | |||
799 | { | |||
800 | const size_t nPos = GetItemPos( nItemId ); | |||
801 | ||||
802 | if( nPos != VALUESET_ITEM_NOTFOUND(size_t(-1)) ) | |||
803 | { | |||
804 | ValueItemAcc* pItemAcc = ValueItemAcc::getImplementation( | |||
805 | mItemList[nPos]->GetAccessible( false/*bIsTransientChildrenDisabled*/ ) ); | |||
806 | ||||
807 | if( pItemAcc ) | |||
808 | { | |||
809 | Any aOldAny; | |||
810 | Any aNewAny; | |||
811 | aOldAny <<= Reference<XInterface>(static_cast<cppu::OWeakObject*>(pItemAcc)); | |||
812 | ImplFireAccessibleEvent(AccessibleEventId::ACTIVE_DESCENDANT_CHANGED, aOldAny, aNewAny ); | |||
813 | } | |||
814 | } | |||
815 | } | |||
816 | ||||
817 | // focus event (select) | |||
818 | const size_t nPos = GetItemPos( mnSelItemId ); | |||
819 | ||||
820 | ValueSetItem* pItem; | |||
821 | if( nPos != VALUESET_ITEM_NOTFOUND(size_t(-1)) ) | |||
822 | pItem = mItemList[nPos].get(); | |||
823 | else | |||
824 | pItem = mpNoneItem.get(); | |||
825 | ||||
826 | ValueItemAcc* pItemAcc = nullptr; | |||
827 | if (pItem != nullptr) | |||
828 | pItemAcc = ValueItemAcc::getImplementation( pItem->GetAccessible( false/*bIsTransientChildrenDisabled*/ ) ); | |||
829 | ||||
830 | if( pItemAcc ) | |||
831 | { | |||
832 | Any aOldAny; | |||
833 | Any aNewAny; | |||
834 | aNewAny <<= Reference<XInterface>(static_cast<cppu::OWeakObject*>(pItemAcc)); | |||
835 | ImplFireAccessibleEvent(AccessibleEventId::ACTIVE_DESCENDANT_CHANGED, aOldAny, aNewAny); | |||
836 | } | |||
837 | ||||
838 | // selection event | |||
839 | Any aOldAny; | |||
840 | Any aNewAny; | |||
841 | ImplFireAccessibleEvent(AccessibleEventId::SELECTION_CHANGED, aOldAny, aNewAny); | |||
842 | } | |||
843 | ||||
844 | void ValueSet::SetNoSelection() | |||
845 | { | |||
846 | mbNoSelection = true; | |||
847 | mbHighlight = false; | |||
848 | ||||
849 | if (IsReallyVisible() && IsUpdateMode()) | |||
850 | Invalidate(); | |||
851 | } | |||
852 | ||||
853 | void ValueSet::SetStyle(WinBits nStyle) | |||
854 | { | |||
855 | if (nStyle != mnStyle) | |||
856 | { | |||
857 | mnStyle = nStyle; | |||
858 | mbFormat = true; | |||
859 | Invalidate(); | |||
860 | } | |||
861 | } | |||
862 | ||||
863 | void ValueSet::Format(vcl::RenderContext const & rRenderContext) | |||
864 | { | |||
865 | Size aWinSize(GetOutputSizePixel()); | |||
866 | size_t nItemCount = mItemList.size(); | |||
867 | WinBits nStyle = GetStyle(); | |||
868 | long nTxtHeight = rRenderContext.GetTextHeight(); | |||
869 | long nOff; | |||
870 | long nNoneHeight; | |||
871 | long nNoneSpace; | |||
872 | ||||
873 | if (mxScrolledWindow && !(nStyle & WB_VSCROLL) && mxScrolledWindow->get_vpolicy() != VclPolicyType::NEVER) | |||
874 | TurnOffScrollBar(); | |||
875 | ||||
876 | // calculate item offset | |||
877 | if (nStyle & WB_ITEMBORDER(WinBits(0x00010000))) | |||
878 | { | |||
879 | if (nStyle & WB_DOUBLEBORDER(WinBits(0x00020000))) | |||
880 | nOff = ITEM_OFFSET_DOUBLE; | |||
881 | else | |||
882 | nOff = ITEM_OFFSET; | |||
883 | } | |||
884 | else | |||
885 | nOff = 0; | |||
886 | ||||
887 | // consider size, if NameField does exist | |||
888 | if (nStyle & WB_NAMEFIELD(WinBits(0x00040000))) | |||
889 | { | |||
890 | mnTextOffset = aWinSize.Height() - nTxtHeight - NAME_OFFSET; | |||
891 | aWinSize.AdjustHeight( -(nTxtHeight + NAME_OFFSET) ); | |||
892 | ||||
893 | if (!(nStyle & WB_FLATVALUESET(WinBits(0x02000000)))) | |||
894 | { | |||
895 | mnTextOffset -= NAME_LINE_HEIGHT + NAME_LINE_OFF_Y; | |||
896 | aWinSize.AdjustHeight( -(NAME_LINE_HEIGHT + NAME_LINE_OFF_Y) ); | |||
897 | } | |||
898 | } | |||
899 | else | |||
900 | mnTextOffset = 0; | |||
901 | ||||
902 | // consider offset and size, if NoneField does exist | |||
903 | if (nStyle & WB_NONEFIELD(WinBits(0x00080000))) | |||
904 | { | |||
905 | nNoneHeight = nTxtHeight + nOff; | |||
906 | nNoneSpace = mnSpacing; | |||
907 | } | |||
908 | else | |||
909 | { | |||
910 | nNoneHeight = 0; | |||
911 | nNoneSpace = 0; | |||
912 | mpNoneItem.reset(); | |||
913 | } | |||
914 | ||||
915 | // calculate number of columns | |||
916 | if (!mnUserCols) | |||
917 | { | |||
918 | if (mnUserItemWidth) | |||
919 | { | |||
920 | mnCols = static_cast<sal_uInt16>((aWinSize.Width() - mnSpacing) / (mnUserItemWidth + mnSpacing)); | |||
921 | if (mnCols <= 0) | |||
922 | mnCols = 1; | |||
923 | } | |||
924 | else | |||
925 | { | |||
926 | mnCols = 1; | |||
927 | } | |||
928 | } | |||
929 | else | |||
930 | { | |||
931 | mnCols = mnUserCols; | |||
932 | } | |||
933 | ||||
934 | // calculate number of rows | |||
935 | mbScroll = false; | |||
936 | ||||
937 | auto nOldLines = mnLines; | |||
938 | // Floor( (M+N-1)/N )==Ceiling( M/N ) | |||
939 | mnLines = (static_cast<long>(nItemCount) + mnCols - 1) / mnCols; | |||
940 | if (mnLines <= 0) | |||
941 | mnLines = 1; | |||
942 | ||||
943 | bool bAdjustmentOutOfDate = nOldLines != mnLines; | |||
944 | ||||
945 | auto nOldVisLines = mnVisLines; | |||
946 | ||||
947 | long nCalcHeight = aWinSize.Height() - nNoneHeight; | |||
948 | if (mnUserVisLines) | |||
949 | { | |||
950 | mnVisLines = mnUserVisLines; | |||
951 | } | |||
952 | else if (mnUserItemHeight) | |||
953 | { | |||
954 | mnVisLines = (nCalcHeight - nNoneSpace + mnSpacing) / (mnUserItemHeight + mnSpacing); | |||
955 | if (!mnVisLines) | |||
956 | mnVisLines = 1; | |||
957 | } | |||
958 | else | |||
959 | { | |||
960 | mnVisLines = mnLines; | |||
961 | } | |||
962 | ||||
963 | bAdjustmentOutOfDate |= nOldVisLines != mnVisLines; | |||
964 | ||||
965 | if (mnLines > mnVisLines) | |||
966 | mbScroll = true; | |||
967 | ||||
968 | if (mnLines <= mnVisLines) | |||
969 | { | |||
970 | SetFirstLine(0); | |||
971 | } | |||
972 | else | |||
973 | { | |||
974 | if (mnFirstLine > o3tl::make_unsigned(mnLines - mnVisLines)) | |||
975 | SetFirstLine(static_cast<sal_uInt16>(mnLines - mnVisLines)); | |||
976 | } | |||
977 | ||||
978 | // calculate item size | |||
979 | const long nColSpace = (mnCols - 1) * static_cast<long>(mnSpacing); | |||
980 | const long nLineSpace = ((mnVisLines - 1) * mnSpacing) + nNoneSpace; | |||
981 | if (mnUserItemWidth && !mnUserCols) | |||
982 | { | |||
983 | mnItemWidth = mnUserItemWidth; | |||
984 | if (mnItemWidth > aWinSize.Width() - nColSpace) | |||
985 | mnItemWidth = aWinSize.Width() - nColSpace; | |||
986 | } | |||
987 | else | |||
988 | mnItemWidth = (aWinSize.Width() - nColSpace) / mnCols; | |||
989 | if (mnUserItemHeight && !mnUserVisLines) | |||
990 | { | |||
991 | mnItemHeight = mnUserItemHeight; | |||
992 | if (mnItemHeight > nCalcHeight - nNoneSpace) | |||
993 | mnItemHeight = nCalcHeight - nNoneSpace; | |||
994 | } | |||
995 | else | |||
996 | { | |||
997 | nCalcHeight -= nLineSpace; | |||
998 | mnItemHeight = nCalcHeight / mnVisLines; | |||
999 | } | |||
1000 | ||||
1001 | // Init VirDev | |||
1002 | maVirDev->SetSettings(rRenderContext.GetSettings()); | |||
1003 | maVirDev->SetOutputSizePixel(aWinSize); | |||
1004 | ||||
1005 | // nothing is changed in case of too small items | |||
1006 | if ((mnItemWidth <= 0) || | |||
1007 | (mnItemHeight <= ((nStyle & WB_ITEMBORDER(WinBits(0x00010000))) ? 4 : 2)) || | |||
1008 | !nItemCount) | |||
1009 | { | |||
1010 | mbHasVisibleItems = false; | |||
1011 | ||||
1012 | if ((nStyle & WB_NONEFIELD(WinBits(0x00080000))) && mpNoneItem) | |||
1013 | { | |||
1014 | mpNoneItem->mbVisible = false; | |||
1015 | mpNoneItem->maText = GetText(); | |||
1016 | } | |||
1017 | ||||
1018 | for (size_t i = 0; i < nItemCount; i++) | |||
1019 | { | |||
1020 | mItemList[i]->mbVisible = false; | |||
1021 | } | |||
1022 | ||||
1023 | if (mxScrolledWindow && mxScrolledWindow->get_vpolicy() != VclPolicyType::NEVER) | |||
1024 | TurnOffScrollBar(); | |||
1025 | } | |||
1026 | else | |||
1027 | { | |||
1028 | mbHasVisibleItems = true; | |||
1029 | ||||
1030 | // determine Frame-Style | |||
1031 | if (nStyle & WB_DOUBLEBORDER(WinBits(0x00020000))) | |||
1032 | mnFrameStyle = DrawFrameStyle::DoubleIn; | |||
1033 | else | |||
1034 | mnFrameStyle = DrawFrameStyle::In; | |||
1035 | ||||
1036 | // determine selected color and width | |||
1037 | // if necessary change the colors, to make the selection | |||
1038 | // better detectable | |||
1039 | const StyleSettings& rStyleSettings = rRenderContext.GetSettings().GetStyleSettings(); | |||
1040 | Color aHighColor(rStyleSettings.GetHighlightColor()); | |||
1041 | if (((aHighColor.GetRed() > 0x80) || (aHighColor.GetGreen() > 0x80) || | |||
1042 | (aHighColor.GetBlue() > 0x80)) || | |||
1043 | ((aHighColor.GetRed() == 0x80) && (aHighColor.GetGreen() == 0x80) && | |||
1044 | (aHighColor.GetBlue() == 0x80))) | |||
1045 | { | |||
1046 | mbBlackSel = true; | |||
1047 | } | |||
1048 | else | |||
1049 | { | |||
1050 | mbBlackSel = false; | |||
1051 | } | |||
1052 | // draw the selection with double width if the items are bigger | |||
1053 | if ((nStyle & WB_DOUBLEBORDER(WinBits(0x00020000))) && | |||
1054 | ((mnItemWidth >= 25) && (mnItemHeight >= 20))) | |||
1055 | { | |||
1056 | mbDoubleSel = true; | |||
1057 | } | |||
1058 | else | |||
1059 | { | |||
1060 | mbDoubleSel = false; | |||
1061 | } | |||
1062 | ||||
1063 | // calculate offsets | |||
1064 | long nStartX; | |||
1065 | long nStartY; | |||
1066 | if (mbFullMode) | |||
1067 | { | |||
1068 | long nAllItemWidth = (mnItemWidth * mnCols) + nColSpace; | |||
1069 | long nAllItemHeight = (mnItemHeight * mnVisLines) + nNoneHeight + nLineSpace; | |||
1070 | nStartX = (aWinSize.Width() - nAllItemWidth) / 2; | |||
1071 | nStartY = (aWinSize.Height() - nAllItemHeight) / 2; | |||
1072 | } | |||
1073 | else | |||
1074 | { | |||
1075 | nStartX = 0; | |||
1076 | nStartY = 0; | |||
1077 | } | |||
1078 | ||||
1079 | // calculate and draw items | |||
1080 | maVirDev->SetLineColor(); | |||
1081 | long x = nStartX; | |||
1082 | long y = nStartY; | |||
1083 | ||||
1084 | // create NoSelection field and show it | |||
1085 | if (nStyle & WB_NONEFIELD(WinBits(0x00080000))) | |||
1086 | { | |||
1087 | if (!mpNoneItem) | |||
1088 | mpNoneItem.reset(new ValueSetItem(*this)); | |||
1089 | ||||
1090 | mpNoneItem->mnId = 0; | |||
1091 | mpNoneItem->meType = VALUESETITEM_NONE; | |||
1092 | mpNoneItem->mbVisible = true; | |||
1093 | maNoneItemRect.SetLeft( x ); | |||
1094 | maNoneItemRect.SetTop( y ); | |||
1095 | maNoneItemRect.SetRight( maNoneItemRect.Left() + aWinSize.Width() - x - 1 ); | |||
1096 | maNoneItemRect.SetBottom( y + nNoneHeight - 1 ); | |||
1097 | ||||
1098 | ImplFormatItem(rRenderContext, mpNoneItem.get(), maNoneItemRect); | |||
1099 | ||||
1100 | y += nNoneHeight + nNoneSpace; | |||
1101 | } | |||
1102 | ||||
1103 | // draw items | |||
1104 | sal_uLong nFirstItem = static_cast<sal_uLong>(mnFirstLine) * mnCols; | |||
1105 | sal_uLong nLastItem = nFirstItem + (mnVisLines * mnCols); | |||
1106 | ||||
1107 | maItemListRect.SetLeft( x ); | |||
1108 | maItemListRect.SetTop( y ); | |||
1109 | maItemListRect.SetRight( x + mnCols * (mnItemWidth + mnSpacing) - mnSpacing - 1 ); | |||
1110 | maItemListRect.SetBottom( y + mnVisLines * (mnItemHeight + mnSpacing) - mnSpacing - 1 ); | |||
1111 | ||||
1112 | if (!mbFullMode) | |||
1113 | { | |||
1114 | // If want also draw parts of items in the last line, | |||
1115 | // then we add one more line if parts of these line are | |||
1116 | // visible | |||
1117 | if (y + (mnVisLines * (mnItemHeight + mnSpacing)) < aWinSize.Height()) | |||
1118 | nLastItem += mnCols; | |||
1119 | maItemListRect.SetBottom( aWinSize.Height() - y ); | |||
1120 | } | |||
1121 | for (size_t i = 0; i < nItemCount; i++) | |||
1122 | { | |||
1123 | ValueSetItem* pItem = mItemList[i].get(); | |||
1124 | ||||
1125 | if (i >= nFirstItem && i < nLastItem) | |||
1126 | { | |||
1127 | if (!pItem->mbVisible && ImplHasAccessibleListeners()) | |||
1128 | { | |||
1129 | Any aOldAny; | |||
1130 | Any aNewAny; | |||
1131 | ||||
1132 | aNewAny <<= pItem->GetAccessible(false/*bIsTransientChildrenDisabled*/); | |||
1133 | ImplFireAccessibleEvent(AccessibleEventId::CHILD, aOldAny, aNewAny); | |||
1134 | } | |||
1135 | ||||
1136 | pItem->mbVisible = true; | |||
1137 | ImplFormatItem(rRenderContext, pItem, tools::Rectangle(Point(x, y), Size(mnItemWidth, mnItemHeight))); | |||
1138 | ||||
1139 | if (!((i + 1) % mnCols)) | |||
1140 | { | |||
1141 | x = nStartX; | |||
1142 | y += mnItemHeight + mnSpacing; | |||
1143 | } | |||
1144 | else | |||
1145 | x += mnItemWidth + mnSpacing; | |||
1146 | } | |||
1147 | else | |||
1148 | { | |||
1149 | if (pItem->mbVisible && ImplHasAccessibleListeners()) | |||
1150 | { | |||
1151 | Any aOldAny; | |||
1152 | Any aNewAny; | |||
1153 | ||||
1154 | aOldAny <<= pItem->GetAccessible(false/*bIsTransientChildrenDisabled*/); | |||
1155 | ImplFireAccessibleEvent(AccessibleEventId::CHILD, aOldAny, aNewAny); | |||
1156 | } | |||
1157 | ||||
1158 | pItem->mbVisible = false; | |||
1159 | } | |||
1160 | } | |||
1161 | ||||
1162 | // arrange ScrollBar, set values and show it | |||
1163 | if (mxScrolledWindow && (nStyle & WB_VSCROLL)) | |||
1164 | { | |||
1165 | bool bTurnScrollbarOn = mxScrolledWindow->get_vpolicy() != VclPolicyType::ALWAYS; | |||
1166 | if (bAdjustmentOutOfDate || bTurnScrollbarOn) | |||
1167 | { | |||
1168 | long nPageSize = mnVisLines; | |||
1169 | if (nPageSize < 1) | |||
1170 | nPageSize = 1; | |||
1171 | mxScrolledWindow->vadjustment_configure(mnFirstLine, 0, mnLines, 1, | |||
1172 | mnVisLines, nPageSize); | |||
1173 | } | |||
1174 | ||||
1175 | if (bTurnScrollbarOn) | |||
1176 | TurnOnScrollBar(); | |||
1177 | } | |||
1178 | } | |||
1179 | ||||
1180 | // waiting for the next since the formatting is finished | |||
1181 | mbFormat = false; | |||
1182 | } | |||
1183 | ||||
1184 | void ValueSet::ImplDrawSelect(vcl::RenderContext& rRenderContext) | |||
1185 | { | |||
1186 | if (!IsReallyVisible()) | |||
1187 | return; | |||
1188 | ||||
1189 | const bool bFocus = HasFocus(); | |||
1190 | const bool bDrawSel = !((mbNoSelection && !mbHighlight) || (!mbDrawSelection && mbHighlight)); | |||
1191 | ||||
1192 | if (!bFocus && !bDrawSel) | |||
1193 | { | |||
1194 | ImplDrawItemText(rRenderContext, OUString()); | |||
1195 | return; | |||
1196 | } | |||
1197 | ||||
1198 | ImplDrawSelect(rRenderContext, mnSelItemId, bFocus, bDrawSel); | |||
1199 | if (mbHighlight) | |||
1200 | { | |||
1201 | ImplDrawSelect(rRenderContext, mnHighItemId, bFocus, bDrawSel); | |||
1202 | } | |||
1203 | } | |||
1204 | ||||
1205 | void ValueSet::ImplDrawSelect(vcl::RenderContext& rRenderContext, sal_uInt16 nItemId, const bool bFocus, const bool bDrawSel ) | |||
1206 | { | |||
1207 | ValueSetItem* pItem; | |||
1208 | tools::Rectangle aRect; | |||
1209 | if (nItemId) | |||
1210 | { | |||
1211 | const size_t nPos = GetItemPos( nItemId ); | |||
1212 | pItem = mItemList[ nPos ].get(); | |||
1213 | aRect = ImplGetItemRect( nPos ); | |||
1214 | } | |||
1215 | else if (mpNoneItem) | |||
1216 | { | |||
1217 | pItem = mpNoneItem.get(); | |||
1218 | aRect = maNoneItemRect; | |||
1219 | } | |||
1220 | else if (bFocus && (pItem = ImplGetFirstItem())) | |||
1221 | { | |||
1222 | aRect = ImplGetItemRect(0); | |||
1223 | } | |||
1224 | else | |||
1225 | { | |||
1226 | return; | |||
1227 | } | |||
1228 | ||||
1229 | if (!pItem->mbVisible) | |||
1230 | return; | |||
1231 | ||||
1232 | // draw selection | |||
1233 | const StyleSettings& rStyleSettings = rRenderContext.GetSettings().GetStyleSettings(); | |||
1234 | rRenderContext.SetFillColor(); | |||
1235 | ||||
1236 | Color aDoubleColor(rStyleSettings.GetHighlightColor()); | |||
1237 | Color aSingleColor(rStyleSettings.GetHighlightTextColor()); | |||
1238 | if (!mbDoubleSel) | |||
1239 | { | |||
1240 | /* | |||
1241 | * #99777# contrast enhancement for thin mode | |||
1242 | */ | |||
1243 | const Wallpaper& rWall = maVirDev->GetBackground(); | |||
1244 | if (!rWall.IsBitmap() && ! rWall.IsGradient()) | |||
1245 | { | |||
1246 | const Color& rBack = rWall.GetColor(); | |||
1247 | if (rBack.IsDark() && ! aDoubleColor.IsBright()) | |||
1248 | { | |||
1249 | aDoubleColor = COL_WHITE; | |||
1250 | aSingleColor = COL_BLACK; | |||
1251 | } | |||
1252 | else if (rBack.IsBright() && !aDoubleColor.IsDark()) | |||
1253 | { | |||
1254 | aDoubleColor = COL_BLACK; | |||
1255 | aSingleColor = COL_WHITE; | |||
1256 | } | |||
1257 | } | |||
1258 | } | |||
1259 | ||||
1260 | // specify selection output | |||
1261 | WinBits nStyle = GetStyle(); | |||
1262 | if (nStyle & WB_MENUSTYLEVALUESET(WinBits(0x08000000))) | |||
1263 | { | |||
1264 | if (bFocus) | |||
1265 | DrawFocusRect(rRenderContext, aRect); | |||
1266 | if (bDrawSel) | |||
1267 | { | |||
1268 | rRenderContext.SetLineColor(mbBlackSel ? COL_BLACK : aDoubleColor); | |||
1269 | rRenderContext.DrawRect(aRect); | |||
1270 | } | |||
1271 | } | |||
1272 | else | |||
1273 | { | |||
1274 | if (bDrawSel) | |||
1275 | { | |||
1276 | rRenderContext.SetLineColor(mbBlackSel ? COL_BLACK : aDoubleColor); | |||
1277 | rRenderContext.DrawRect(aRect); | |||
1278 | } | |||
1279 | if (mbDoubleSel) | |||
1280 | { | |||
1281 | aRect.AdjustLeft( 1 ); | |||
1282 | aRect.AdjustTop( 1 ); | |||
1283 | aRect.AdjustRight( -1 ); | |||
1284 | aRect.AdjustBottom( -1 ); | |||
1285 | if (bDrawSel) | |||
1286 | rRenderContext.DrawRect(aRect); | |||
1287 | } | |||
1288 | aRect.AdjustLeft( 1 ); | |||
1289 | aRect.AdjustTop( 1 ); | |||
1290 | aRect.AdjustRight( -1 ); | |||
1291 | aRect.AdjustBottom( -1 ); | |||
1292 | tools::Rectangle aRect2 = aRect; | |||
1293 | aRect.AdjustLeft( 1 ); | |||
1294 | aRect.AdjustTop( 1 ); | |||
1295 | aRect.AdjustRight( -1 ); | |||
1296 | aRect.AdjustBottom( -1 ); | |||
1297 | if (bDrawSel) | |||
1298 | rRenderContext.DrawRect(aRect); | |||
1299 | if (mbDoubleSel) | |||
1300 | { | |||
1301 | aRect.AdjustLeft( 1 ); | |||
1302 | aRect.AdjustTop( 1 ); | |||
1303 | aRect.AdjustRight( -1 ); | |||
1304 | aRect.AdjustBottom( -1 ); | |||
1305 | if (bDrawSel) | |||
1306 | rRenderContext.DrawRect(aRect); | |||
1307 | } | |||
1308 | ||||
1309 | if (bDrawSel) | |||
1310 | { | |||
1311 | rRenderContext.SetLineColor(mbBlackSel ? COL_WHITE : aSingleColor); | |||
1312 | } | |||
1313 | else | |||
1314 | { | |||
1315 | rRenderContext.SetLineColor(COL_LIGHTGRAY); | |||
1316 | } | |||
1317 | rRenderContext.DrawRect(aRect2); | |||
1318 | if (bFocus) | |||
1319 | DrawFocusRect(rRenderContext, aRect2); | |||
1320 | } | |||
1321 | ||||
1322 | ImplDrawItemText(rRenderContext, pItem->maText); | |||
1323 | } | |||
1324 | ||||
1325 | void ValueSet::ImplFormatItem(vcl::RenderContext const & rRenderContext, ValueSetItem* pItem, tools::Rectangle aRect) | |||
1326 | { | |||
1327 | WinBits nStyle = GetStyle(); | |||
1328 | if (nStyle & WB_ITEMBORDER(WinBits(0x00010000))) | |||
1329 | { | |||
1330 | aRect.AdjustLeft(1 ); | |||
1331 | aRect.AdjustTop(1 ); | |||
1332 | aRect.AdjustRight( -1 ); | |||
1333 | aRect.AdjustBottom( -1 ); | |||
1334 | ||||
1335 | if (nStyle & WB_FLATVALUESET(WinBits(0x02000000))) | |||
1336 | { | |||
1337 | sal_Int32 nBorder = (nStyle & WB_DOUBLEBORDER(WinBits(0x00020000))) ? 2 : 1; | |||
1338 | ||||
1339 | aRect.AdjustLeft(nBorder ); | |||
1340 | aRect.AdjustTop(nBorder ); | |||
1341 | aRect.AdjustRight( -nBorder ); | |||
1342 | aRect.AdjustBottom( -nBorder ); | |||
1343 | } | |||
1344 | else | |||
1345 | { | |||
1346 | DecorationView aView(maVirDev.get()); | |||
1347 | aRect = aView.DrawFrame(aRect, mnFrameStyle); | |||
1348 | } | |||
1349 | } | |||
1350 | ||||
1351 | if (pItem == mpNoneItem.get()) | |||
1352 | pItem->maText = GetText(); | |||
1353 | ||||
1354 | if ((aRect.GetHeight() <= 0) || (aRect.GetWidth() <= 0)) | |||
1355 | return; | |||
1356 | ||||
1357 | const StyleSettings& rStyleSettings = rRenderContext.GetSettings().GetStyleSettings(); | |||
1358 | ||||
1359 | if (pItem == mpNoneItem.get()) | |||
1360 | { | |||
1361 | maVirDev->SetFont(rRenderContext.GetFont()); | |||
1362 | maVirDev->SetTextColor((nStyle & WB_MENUSTYLEVALUESET(WinBits(0x08000000))) ? rStyleSettings.GetMenuTextColor() : rStyleSettings.GetWindowTextColor()); | |||
1363 | maVirDev->SetTextFillColor(); | |||
1364 | maVirDev->SetFillColor((nStyle & WB_MENUSTYLEVALUESET(WinBits(0x08000000))) ? rStyleSettings.GetMenuColor() : rStyleSettings.GetWindowColor()); | |||
1365 | maVirDev->DrawRect(aRect); | |||
1366 | Point aTxtPos(aRect.Left() + 2, aRect.Top()); | |||
1367 | long nTxtWidth = rRenderContext.GetTextWidth(pItem->maText); | |||
1368 | if ((aTxtPos.X() + nTxtWidth) > aRect.Right()) | |||
1369 | { | |||
1370 | maVirDev->SetClipRegion(vcl::Region(aRect)); | |||
1371 | maVirDev->DrawText(aTxtPos, pItem->maText); | |||
1372 | maVirDev->SetClipRegion(); | |||
1373 | } | |||
1374 | else | |||
1375 | maVirDev->DrawText(aTxtPos, pItem->maText); | |||
1376 | } | |||
1377 | else if (pItem->meType == VALUESETITEM_COLOR) | |||
1378 | { | |||
1379 | maVirDev->SetFillColor(pItem->maColor); | |||
1380 | maVirDev->DrawRect(aRect); | |||
1381 | } | |||
1382 | else | |||
1383 | { | |||
1384 | if (IsColor()) | |||
1385 | maVirDev->SetFillColor(maColor); | |||
1386 | else if (nStyle & WB_MENUSTYLEVALUESET(WinBits(0x08000000))) | |||
1387 | maVirDev->SetFillColor(rStyleSettings.GetMenuColor()); | |||
1388 | else if (IsEnabled()) | |||
1389 | maVirDev->SetFillColor(rStyleSettings.GetWindowColor()); | |||
1390 | else | |||
1391 | maVirDev->SetFillColor(rStyleSettings.GetFaceColor()); | |||
1392 | maVirDev->DrawRect(aRect); | |||
1393 | ||||
1394 | if (pItem->meType == VALUESETITEM_USERDRAW) | |||
1395 | { | |||
1396 | UserDrawEvent aUDEvt(nullptr, maVirDev.get(), aRect, pItem->mnId); | |||
1397 | UserDraw(aUDEvt); | |||
1398 | } | |||
1399 | else | |||
1400 | { | |||
1401 | Size aImageSize = pItem->maImage.GetSizePixel(); | |||
1402 | Size aRectSize = aRect.GetSize(); | |||
1403 | Point aPos(aRect.Left(), aRect.Top()); | |||
1404 | aPos.AdjustX((aRectSize.Width() - aImageSize.Width()) / 2 ); | |||
1405 | ||||
1406 | if (pItem->meType != VALUESETITEM_IMAGE_AND_TEXT) | |||
1407 | aPos.AdjustY((aRectSize.Height() - aImageSize.Height()) / 2 ); | |||
1408 | ||||
1409 | DrawImageFlags nImageStyle = DrawImageFlags::NONE; | |||
1410 | if (!IsEnabled()) | |||
1411 | nImageStyle |= DrawImageFlags::Disable; | |||
1412 | ||||
1413 | if (aImageSize.Width() > aRectSize.Width() || | |||
1414 | aImageSize.Height() > aRectSize.Height()) | |||
1415 | { | |||
1416 | maVirDev->SetClipRegion(vcl::Region(aRect)); | |||
1417 | maVirDev->DrawImage(aPos, pItem->maImage, nImageStyle); | |||
1418 | maVirDev->SetClipRegion(); | |||
1419 | } | |||
1420 | else | |||
1421 | maVirDev->DrawImage(aPos, pItem->maImage, nImageStyle); | |||
1422 | ||||
1423 | if (pItem->meType == VALUESETITEM_IMAGE_AND_TEXT) | |||
1424 | { | |||
1425 | maVirDev->SetFont(rRenderContext.GetFont()); | |||
1426 | maVirDev->SetTextColor((nStyle & WB_MENUSTYLEVALUESET(WinBits(0x08000000))) ? rStyleSettings.GetMenuTextColor() : rStyleSettings.GetWindowTextColor()); | |||
1427 | maVirDev->SetTextFillColor(); | |||
1428 | ||||
1429 | long nTxtWidth = maVirDev->GetTextWidth(pItem->maText); | |||
1430 | ||||
1431 | if (nTxtWidth > aRect.GetWidth()) | |||
1432 | maVirDev->SetClipRegion(vcl::Region(aRect)); | |||
1433 | ||||
1434 | maVirDev->DrawText(Point(aRect.Left() + | |||
1435 | (aRect.GetWidth() - nTxtWidth) / 2, | |||
1436 | aRect.Bottom() - maVirDev->GetTextHeight()), | |||
1437 | pItem->maText); | |||
1438 | ||||
1439 | if (nTxtWidth > aRect.GetWidth()) | |||
1440 | maVirDev->SetClipRegion(); | |||
1441 | } | |||
1442 | } | |||
1443 | } | |||
1444 | ||||
1445 | const sal_uInt16 nEdgeBlendingPercent(GetEdgeBlending() ? rStyleSettings.GetEdgeBlending() : 0); | |||
1446 | ||||
1447 | if (nEdgeBlendingPercent) | |||
1448 | { | |||
1449 | const Color& rTopLeft(rStyleSettings.GetEdgeBlendingTopLeftColor()); | |||
1450 | const Color& rBottomRight(rStyleSettings.GetEdgeBlendingBottomRightColor()); | |||
1451 | const sal_uInt8 nAlpha((nEdgeBlendingPercent * 255) / 100); | |||
1452 | const BitmapEx aBlendFrame(createBlendFrame(aRect.GetSize(), nAlpha, rTopLeft, rBottomRight)); | |||
1453 | ||||
1454 | if (!aBlendFrame.IsEmpty()) | |||
1455 | { | |||
1456 | maVirDev->DrawBitmapEx(aRect.TopLeft(), aBlendFrame); | |||
1457 | } | |||
1458 | } | |||
1459 | } | |||
1460 | ||||
1461 | void ValueSet::ImplDrawItemText(vcl::RenderContext& rRenderContext, const OUString& rText) | |||
1462 | { | |||
1463 | if (!(GetStyle() & WB_NAMEFIELD(WinBits(0x00040000)))) | |||
1464 | return; | |||
1465 | ||||
1466 | Size aWinSize(GetOutputSizePixel()); | |||
1467 | long nTxtWidth = rRenderContext.GetTextWidth(rText); | |||
1468 | long nTxtOffset = mnTextOffset; | |||
1469 | ||||
1470 | // delete rectangle and show text | |||
1471 | if (GetStyle() & WB_FLATVALUESET(WinBits(0x02000000))) | |||
1472 | { | |||
1473 | const StyleSettings& rStyleSettings = rRenderContext.GetSettings().GetStyleSettings(); | |||
1474 | rRenderContext.SetLineColor(); | |||
1475 | rRenderContext.SetFillColor(rStyleSettings.GetFaceColor()); | |||
1476 | rRenderContext.DrawRect(tools::Rectangle(Point(0, nTxtOffset), Point(aWinSize.Width(), aWinSize.Height()))); | |||
1477 | rRenderContext.SetTextColor(rStyleSettings.GetButtonTextColor()); | |||
1478 | } | |||
1479 | else | |||
1480 | { | |||
1481 | nTxtOffset += NAME_LINE_HEIGHT+NAME_LINE_OFF_Y; | |||
1482 | rRenderContext.SetBackground(Application::GetSettings().GetStyleSettings().GetFaceColor()); | |||
1483 | rRenderContext.Erase(tools::Rectangle(Point(0, nTxtOffset), Point(aWinSize.Width(), aWinSize.Height()))); | |||
1484 | } | |||
1485 | rRenderContext.DrawText(Point((aWinSize.Width() - nTxtWidth) / 2, nTxtOffset + (NAME_OFFSET / 2)), rText); | |||
1486 | } | |||
1487 | ||||
1488 | void ValueSet::StyleUpdated() | |||
1489 | { | |||
1490 | mbFormat = true; | |||
1491 | CustomWidgetController::StyleUpdated(); | |||
1492 | } | |||
1493 | ||||
1494 | void ValueSet::EnableFullItemMode( bool bFullMode ) | |||
1495 | { | |||
1496 | mbFullMode = bFullMode; | |||
1497 | } | |||
1498 | ||||
1499 | void ValueSet::SetColCount( sal_uInt16 nNewCols ) | |||
1500 | { | |||
1501 | if ( mnUserCols != nNewCols ) | |||
1502 | { | |||
1503 | mnUserCols = nNewCols; | |||
1504 | QueueReformat(); | |||
1505 | } | |||
1506 | } | |||
1507 | ||||
1508 | void ValueSet::SetItemImage( sal_uInt16 nItemId, const Image& rImage ) | |||
1509 | { | |||
1510 | size_t nPos = GetItemPos( nItemId ); | |||
1511 | ||||
1512 | if ( nPos == VALUESET_ITEM_NOTFOUND(size_t(-1)) ) | |||
1513 | return; | |||
1514 | ||||
1515 | ValueSetItem* pItem = mItemList[nPos].get(); | |||
1516 | pItem->meType = VALUESETITEM_IMAGE; | |||
1517 | pItem->maImage = rImage; | |||
1518 | ||||
1519 | if ( !mbFormat && IsReallyVisible() && IsUpdateMode() ) | |||
1520 | { | |||
1521 | const tools::Rectangle aRect = ImplGetItemRect(nPos); | |||
1522 | Invalidate(aRect); | |||
1523 | } | |||
1524 | else | |||
1525 | mbFormat = true; | |||
1526 | } | |||
1527 | ||||
1528 | void ValueSet::SetItemColor( sal_uInt16 nItemId, const Color& rColor ) | |||
1529 | { | |||
1530 | size_t nPos = GetItemPos( nItemId ); | |||
1531 | ||||
1532 | if ( nPos == VALUESET_ITEM_NOTFOUND(size_t(-1)) ) | |||
1533 | return; | |||
1534 | ||||
1535 | ValueSetItem* pItem = mItemList[nPos].get(); | |||
1536 | pItem->meType = VALUESETITEM_COLOR; | |||
1537 | pItem->maColor = rColor; | |||
1538 | ||||
1539 | if ( !mbFormat && IsReallyVisible() && IsUpdateMode() ) | |||
1540 | { | |||
1541 | const tools::Rectangle aRect = ImplGetItemRect(nPos); | |||
1542 | Invalidate( aRect ); | |||
1543 | } | |||
1544 | else | |||
1545 | mbFormat = true; | |||
1546 | } | |||
1547 | ||||
1548 | Color ValueSet::GetItemColor( sal_uInt16 nItemId ) const | |||
1549 | { | |||
1550 | size_t nPos = GetItemPos( nItemId ); | |||
1551 | ||||
1552 | if ( nPos != VALUESET_ITEM_NOTFOUND(size_t(-1)) ) | |||
1553 | return mItemList[nPos]->maColor; | |||
1554 | else | |||
1555 | return Color(); | |||
1556 | } | |||
1557 | ||||
1558 | Size ValueSet::CalcWindowSizePixel( const Size& rItemSize, sal_uInt16 nDesireCols, | |||
1559 | sal_uInt16 nDesireLines ) const | |||
1560 | { | |||
1561 | size_t nCalcCols = nDesireCols; | |||
1562 | size_t nCalcLines = nDesireLines; | |||
1563 | ||||
1564 | if ( !nCalcCols ) | |||
1565 | { | |||
1566 | if ( mnUserCols ) | |||
1567 | nCalcCols = mnUserCols; | |||
1568 | else | |||
1569 | nCalcCols = 1; | |||
1570 | } | |||
1571 | ||||
1572 | if ( !nCalcLines ) | |||
1573 | { | |||
1574 | nCalcLines = mnVisLines; | |||
1575 | ||||
1576 | if ( mbFormat ) | |||
1577 | { | |||
1578 | if ( mnUserVisLines ) | |||
1579 | nCalcLines = mnUserVisLines; | |||
1580 | else | |||
1581 | { | |||
1582 | // Floor( (M+N-1)/N )==Ceiling( M/N ) | |||
1583 | nCalcLines = (mItemList.size()+nCalcCols-1) / nCalcCols; | |||
1584 | if ( !nCalcLines ) | |||
1585 | nCalcLines = 1; | |||
1586 | } | |||
1587 | } | |||
1588 | } | |||
1589 | ||||
1590 | Size aSize( rItemSize.Width() * nCalcCols, rItemSize.Height() * nCalcLines ); | |||
1591 | WinBits nStyle = GetStyle(); | |||
1592 | long nTxtHeight = GetTextHeight(); | |||
1593 | long n; | |||
1594 | ||||
1595 | if ( nStyle & WB_ITEMBORDER(WinBits(0x00010000)) ) | |||
1596 | { | |||
1597 | if ( nStyle & WB_DOUBLEBORDER(WinBits(0x00020000)) ) | |||
1598 | n = ITEM_OFFSET_DOUBLE; | |||
1599 | else | |||
1600 | n = ITEM_OFFSET; | |||
1601 | ||||
1602 | aSize.AdjustWidth(n * nCalcCols ); | |||
1603 | aSize.AdjustHeight(n * nCalcLines ); | |||
1604 | } | |||
1605 | else | |||
1606 | n = 0; | |||
1607 | ||||
1608 | if ( mnSpacing ) | |||
1609 | { | |||
1610 | aSize.AdjustWidth(mnSpacing * (nCalcCols - 1) ); | |||
1611 | aSize.AdjustHeight(mnSpacing * (nCalcLines - 1) ); | |||
1612 | } | |||
1613 | ||||
1614 | if ( nStyle & WB_NAMEFIELD(WinBits(0x00040000)) ) | |||
1615 | { | |||
1616 | aSize.AdjustHeight(nTxtHeight + NAME_OFFSET ); | |||
1617 | if ( !(nStyle & WB_FLATVALUESET(WinBits(0x02000000))) ) | |||
1618 | aSize.AdjustHeight(NAME_LINE_HEIGHT + NAME_LINE_OFF_Y ); | |||
1619 | } | |||
1620 | ||||
1621 | if ( nStyle & WB_NONEFIELD(WinBits(0x00080000)) ) | |||
1622 | { | |||
1623 | aSize.AdjustHeight(nTxtHeight + n + mnSpacing ); | |||
1624 | } | |||
1625 | ||||
1626 | return aSize; | |||
1627 | } | |||
1628 | ||||
1629 | void ValueSet::InsertItem( sal_uInt16 nItemId, const Image& rImage ) | |||
1630 | { | |||
1631 | std::unique_ptr<ValueSetItem> pItem(new ValueSetItem( *this )); | |||
1632 | pItem->mnId = nItemId; | |||
1633 | pItem->meType = VALUESETITEM_IMAGE; | |||
1634 | pItem->maImage = rImage; | |||
1635 | ImplInsertItem( std::move(pItem), VALUESET_APPEND(size_t(-1)) ); | |||
1636 | } | |||
1637 | ||||
1638 | void ValueSet::InsertItem( sal_uInt16 nItemId, const Image& rImage, | |||
1639 | const OUString& rText, size_t nPos, | |||
1640 | bool bShowLegend ) | |||
1641 | { | |||
1642 | std::unique_ptr<ValueSetItem> pItem(new ValueSetItem( *this )); | |||
1643 | pItem->mnId = nItemId; | |||
1644 | pItem->meType = bShowLegend ? VALUESETITEM_IMAGE_AND_TEXT : VALUESETITEM_IMAGE; | |||
1645 | pItem->maImage = rImage; | |||
1646 | pItem->maText = rText; | |||
1647 | ImplInsertItem( std::move(pItem), nPos ); | |||
1648 | } | |||
1649 | ||||
1650 | void ValueSet::InsertItem( sal_uInt16 nItemId, size_t nPos ) | |||
1651 | { | |||
1652 | std::unique_ptr<ValueSetItem> pItem(new ValueSetItem( *this )); | |||
1653 | pItem->mnId = nItemId; | |||
1654 | pItem->meType = VALUESETITEM_USERDRAW; | |||
1655 | ImplInsertItem( std::move(pItem), nPos ); | |||
1656 | } | |||
1657 | ||||
1658 | void ValueSet::InsertItem( sal_uInt16 nItemId, const Color& rColor, | |||
1659 | const OUString& rText ) | |||
1660 | { | |||
1661 | std::unique_ptr<ValueSetItem> pItem(new ValueSetItem( *this )); | |||
1662 | pItem->mnId = nItemId; | |||
1663 | pItem->meType = VALUESETITEM_COLOR; | |||
1664 | pItem->maColor = rColor; | |||
1665 | pItem->maText = rText; | |||
1666 | ImplInsertItem( std::move(pItem), VALUESET_APPEND(size_t(-1)) ); | |||
1667 | } | |||
1668 | ||||
1669 | void ValueSet::ImplInsertItem( std::unique_ptr<ValueSetItem> pItem, const size_t nPos ) | |||
1670 | { | |||
1671 | DBG_ASSERT( pItem->mnId, "ValueSet::InsertItem(): ItemId == 0" )do { if (true && (!(pItem->mnId))) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.tools"), ("/home/maarten/src/libreoffice/core/svtools/source/control/valueset.cxx" ":" "1671" ": "), "%s", "ValueSet::InsertItem(): ItemId == 0" ); } } while (false); | |||
1672 | DBG_ASSERT( GetItemPos( pItem->mnId ) == VALUESET_ITEM_NOTFOUND,do { if (true && (!(GetItemPos( pItem->mnId ) == ( size_t(-1))))) { sal_detail_logFormat((SAL_DETAIL_LOG_LEVEL_WARN ), ("legacy.tools"), ("/home/maarten/src/libreoffice/core/svtools/source/control/valueset.cxx" ":" "1673" ": "), "%s", "ValueSet::InsertItem(): ItemId already exists" ); } } while (false) | |||
1673 | "ValueSet::InsertItem(): ItemId already exists" )do { if (true && (!(GetItemPos( pItem->mnId ) == ( size_t(-1))))) { sal_detail_logFormat((SAL_DETAIL_LOG_LEVEL_WARN ), ("legacy.tools"), ("/home/maarten/src/libreoffice/core/svtools/source/control/valueset.cxx" ":" "1673" ": "), "%s", "ValueSet::InsertItem(): ItemId already exists" ); } } while (false); | |||
1674 | ||||
1675 | if ( nPos < mItemList.size() ) { | |||
1676 | mItemList.insert( mItemList.begin() + nPos, std::move(pItem) ); | |||
1677 | } else { | |||
1678 | mItemList.push_back( std::move(pItem) ); | |||
1679 | } | |||
1680 | ||||
1681 | QueueReformat(); | |||
1682 | } | |||
1683 | ||||
1684 | int ValueSet::GetScrollWidth() const | |||
1685 | { | |||
1686 | if (mxScrolledWindow) | |||
1687 | return mxScrolledWindow->get_vscroll_width(); | |||
1688 | return 0; | |||
1689 | } | |||
1690 | ||||
1691 | void ValueSet::SetEdgeBlending(bool bNew) | |||
1692 | { | |||
1693 | if(mbEdgeBlending != bNew) | |||
1694 | { | |||
1695 | mbEdgeBlending = bNew; | |||
1696 | mbFormat = true; | |||
1697 | ||||
1698 | if (GetDrawingArea() && IsReallyVisible() && IsUpdateMode()) | |||
1699 | { | |||
1700 | Invalidate(); | |||
1701 | } | |||
1702 | } | |||
1703 | } | |||
1704 | ||||
1705 | Size ValueSet::CalcItemSizePixel( const Size& rItemSize) const | |||
1706 | { | |||
1707 | Size aSize = rItemSize; | |||
1708 | ||||
1709 | WinBits nStyle = GetStyle(); | |||
1710 | if ( nStyle & WB_ITEMBORDER(WinBits(0x00010000)) ) | |||
1711 | { | |||
1712 | long n; | |||
1713 | ||||
1714 | if ( nStyle & WB_DOUBLEBORDER(WinBits(0x00020000)) ) | |||
1715 | n = ITEM_OFFSET_DOUBLE; | |||
1716 | else | |||
1717 | n = ITEM_OFFSET; | |||
1718 | ||||
1719 | aSize.AdjustWidth(n ); | |||
1720 | aSize.AdjustHeight(n ); | |||
1721 | } | |||
1722 | ||||
1723 | return aSize; | |||
1724 | } | |||
1725 | ||||
1726 | void ValueSet::SetLineCount( sal_uInt16 nNewLines ) | |||
1727 | { | |||
1728 | if ( mnUserVisLines != nNewLines ) | |||
1729 | { | |||
1730 | mnUserVisLines = nNewLines; | |||
1731 | QueueReformat(); | |||
1732 | } | |||
1733 | } | |||
1734 | ||||
1735 | void ValueSet::SetItemWidth( long nNewItemWidth ) | |||
1736 | { | |||
1737 | if ( mnUserItemWidth != nNewItemWidth ) | |||
1738 | { | |||
1739 | mnUserItemWidth = nNewItemWidth; | |||
1740 | QueueReformat(); | |||
1741 | } | |||
1742 | } | |||
1743 | ||||
1744 | //method to set accessible when the style is user draw. | |||
1745 | void ValueSet::InsertItem( sal_uInt16 nItemId, const OUString& rText, size_t nPos ) | |||
1746 | { | |||
1747 | DBG_ASSERT( nItemId, "ValueSet::InsertItem(): ItemId == 0" )do { if (true && (!(nItemId))) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.tools"), ("/home/maarten/src/libreoffice/core/svtools/source/control/valueset.cxx" ":" "1747" ": "), "%s", "ValueSet::InsertItem(): ItemId == 0" ); } } while (false); | |||
1748 | DBG_ASSERT( GetItemPos( nItemId ) == VALUESET_ITEM_NOTFOUND,do { if (true && (!(GetItemPos( nItemId ) == (size_t( -1))))) { sal_detail_logFormat((SAL_DETAIL_LOG_LEVEL_WARN), ( "legacy.tools"), ("/home/maarten/src/libreoffice/core/svtools/source/control/valueset.cxx" ":" "1749" ": "), "%s", "ValueSet::InsertItem(): ItemId already exists" ); } } while (false) | |||
1749 | "ValueSet::InsertItem(): ItemId already exists" )do { if (true && (!(GetItemPos( nItemId ) == (size_t( -1))))) { sal_detail_logFormat((SAL_DETAIL_LOG_LEVEL_WARN), ( "legacy.tools"), ("/home/maarten/src/libreoffice/core/svtools/source/control/valueset.cxx" ":" "1749" ": "), "%s", "ValueSet::InsertItem(): ItemId already exists" ); } } while (false); | |||
1750 | std::unique_ptr<ValueSetItem> pItem(new ValueSetItem( *this )); | |||
1751 | pItem->mnId = nItemId; | |||
1752 | pItem->meType = VALUESETITEM_USERDRAW; | |||
1753 | pItem->maText = rText; | |||
1754 | ImplInsertItem( std::move(pItem), nPos ); | |||
1755 | } | |||
1756 | ||||
1757 | void ValueSet::SetItemHeight( long nNewItemHeight ) | |||
1758 | { | |||
1759 | if ( mnUserItemHeight != nNewItemHeight ) | |||
1760 | { | |||
1761 | mnUserItemHeight = nNewItemHeight; | |||
1762 | QueueReformat(); | |||
1763 | } | |||
1764 | } | |||
1765 | ||||
1766 | OUString ValueSet::RequestHelp(tools::Rectangle& rHelpRect) | |||
1767 | { | |||
1768 | Point aPos = rHelpRect.TopLeft(); | |||
1769 | const size_t nItemPos = ImplGetItem( aPos ); | |||
1770 | OUString sRet; | |||
1771 | if (nItemPos != VALUESET_ITEM_NOTFOUND(size_t(-1))) | |||
1772 | { | |||
1773 | rHelpRect = ImplGetItemRect(nItemPos); | |||
1774 | sRet = GetItemText(ImplGetItem(nItemPos)->mnId); | |||
1775 | } | |||
1776 | return sRet; | |||
1777 | } | |||
1778 | ||||
1779 | OUString ValueSet::GetItemText(sal_uInt16 nItemId) const | |||
1780 | { | |||
1781 | const size_t nPos = GetItemPos(nItemId); | |||
1782 | ||||
1783 | if ( nPos != VALUESET_ITEM_NOTFOUND(size_t(-1)) ) | |||
1784 | return mItemList[nPos]->maText; | |||
1785 | ||||
1786 | return OUString(); | |||
1787 | } | |||
1788 | ||||
1789 | void ValueSet::SetExtraSpacing( sal_uInt16 nNewSpacing ) | |||
1790 | { | |||
1791 | if ( GetStyle() & WB_ITEMBORDER(WinBits(0x00010000)) ) | |||
1792 | { | |||
1793 | mnSpacing = nNewSpacing; | |||
1794 | QueueReformat(); | |||
1795 | } | |||
1796 | } | |||
1797 | ||||
1798 | void ValueSet::SetFormat() | |||
1799 | { | |||
1800 | mbFormat = true; | |||
1801 | } | |||
1802 | ||||
1803 | void ValueSet::SetItemData( sal_uInt16 nItemId, void* pData ) | |||
1804 | { | |||
1805 | size_t nPos = GetItemPos( nItemId ); | |||
1806 | ||||
1807 | if ( nPos == VALUESET_ITEM_NOTFOUND(size_t(-1)) ) | |||
1808 | return; | |||
1809 | ||||
1810 | ValueSetItem* pItem = mItemList[nPos].get(); | |||
1811 | pItem->mpData = pData; | |||
1812 | ||||
1813 | if ( pItem->meType == VALUESETITEM_USERDRAW ) | |||
1814 | { | |||
1815 | if ( !mbFormat && IsReallyVisible() && IsUpdateMode() ) | |||
1816 | { | |||
1817 | const tools::Rectangle aRect = ImplGetItemRect(nPos); | |||
1818 | Invalidate(aRect); | |||
1819 | } | |||
1820 | else | |||
1821 | mbFormat = true; | |||
1822 | } | |||
1823 | } | |||
1824 | ||||
1825 | void* ValueSet::GetItemData( sal_uInt16 nItemId ) const | |||
1826 | { | |||
1827 | size_t nPos = GetItemPos( nItemId ); | |||
1828 | ||||
1829 | if ( nPos != VALUESET_ITEM_NOTFOUND(size_t(-1)) ) | |||
1830 | return mItemList[nPos]->mpData; | |||
1831 | else | |||
1832 | return nullptr; | |||
1833 | } | |||
1834 | ||||
1835 | void ValueSet::SetItemText(sal_uInt16 nItemId, const OUString& rText) | |||
1836 | { | |||
1837 | size_t nPos = GetItemPos( nItemId ); | |||
1838 | ||||
1839 | if ( nPos == VALUESET_ITEM_NOTFOUND(size_t(-1)) ) | |||
1840 | return; | |||
1841 | ||||
1842 | ValueSetItem* pItem = mItemList[nPos].get(); | |||
1843 | ||||
1844 | // Remember old and new name for accessibility event. | |||
1845 | Any aOldName; | |||
1846 | Any aNewName; | |||
1847 | OUString sString (pItem->maText); | |||
1848 | aOldName <<= sString; | |||
1849 | sString = rText; | |||
1850 | aNewName <<= sString; | |||
1851 | ||||
1852 | pItem->maText = rText; | |||
1853 | ||||
1854 | if (!mbFormat && IsReallyVisible() && IsUpdateMode()) | |||
1855 | { | |||
1856 | sal_uInt16 nTempId = mnSelItemId; | |||
1857 | ||||
1858 | if (mbHighlight) | |||
1859 | nTempId = mnHighItemId; | |||
1860 | ||||
1861 | if (nTempId == nItemId) | |||
1862 | Invalidate(); | |||
1863 | } | |||
1864 | ||||
1865 | if (ImplHasAccessibleListeners()) | |||
1866 | { | |||
1867 | Reference<XAccessible> xAccessible(pItem->GetAccessible( false/*bIsTransientChildrenDisabled*/)); | |||
1868 | ValueItemAcc* pValueItemAcc = static_cast<ValueItemAcc*>(xAccessible.get()); | |||
1869 | pValueItemAcc->FireAccessibleEvent(AccessibleEventId::NAME_CHANGED, aOldName, aNewName); | |||
1870 | } | |||
1871 | } | |||
1872 | ||||
1873 | Size ValueSet::GetLargestItemSize() | |||
1874 | { | |||
1875 | Size aLargestItem; | |||
1876 | ||||
1877 | for (const std::unique_ptr<ValueSetItem>& pItem : mItemList) | |||
1878 | { | |||
1879 | if (!pItem->mbVisible) | |||
1880 | continue; | |||
1881 | ||||
1882 | if (pItem->meType != VALUESETITEM_IMAGE && | |||
1883 | pItem->meType != VALUESETITEM_IMAGE_AND_TEXT) | |||
1884 | { | |||
1885 | // handle determining an optimal size for this case | |||
1886 | continue; | |||
1887 | } | |||
1888 | ||||
1889 | Size aSize = pItem->maImage.GetSizePixel(); | |||
1890 | if (pItem->meType == VALUESETITEM_IMAGE_AND_TEXT) | |||
1891 | { | |||
1892 | aSize.AdjustHeight(3 * NAME_LINE_HEIGHT + | |||
1893 | maVirDev->GetTextHeight() ); | |||
1894 | aSize.setWidth( std::max(aSize.Width(), | |||
1895 | maVirDev->GetTextWidth(pItem->maText) + NAME_OFFSET) ); | |||
1896 | } | |||
1897 | ||||
1898 | aLargestItem.setWidth( std::max(aLargestItem.Width(), aSize.Width()) ); | |||
1899 | aLargestItem.setHeight( std::max(aLargestItem.Height(), aSize.Height()) ); | |||
1900 | } | |||
1901 | ||||
1902 | return aLargestItem; | |||
1903 | } | |||
1904 | ||||
1905 | void ValueSet::SetOptimalSize() | |||
1906 | { | |||
1907 | Size aLargestSize(GetLargestItemSize()); | |||
1908 | aLargestSize.setWidth(std::max(aLargestSize.Width(), mnUserItemWidth)); | |||
1909 | aLargestSize.setHeight(std::max(aLargestSize.Height(), mnUserItemHeight)); | |||
1910 | Size aPrefSize(CalcWindowSizePixel(aLargestSize)); | |||
1911 | GetDrawingArea()->set_size_request(aPrefSize.Width(), aPrefSize.Height()); | |||
1912 | } | |||
1913 | ||||
1914 | Image ValueSet::GetItemImage(sal_uInt16 nItemId) const | |||
1915 | { | |||
1916 | size_t nPos = GetItemPos( nItemId ); | |||
1917 | ||||
1918 | if ( nPos != VALUESET_ITEM_NOTFOUND(size_t(-1)) ) | |||
1919 | return mItemList[nPos]->maImage; | |||
1920 | else | |||
1921 | return Image(); | |||
1922 | } | |||
1923 | ||||
1924 | void ValueSet::SetColor(const Color& rColor) | |||
1925 | { | |||
1926 | maColor = rColor; | |||
1927 | mbFormat = true; | |||
1928 | if (IsReallyVisible() && IsUpdateMode()) | |||
1929 | Invalidate(); | |||
1930 | } | |||
1931 | ||||
1932 | void ValueSet::Show() | |||
1933 | { | |||
1934 | if (mxScrolledWindow) | |||
1935 | mxScrolledWindow->show(); | |||
1936 | CustomWidgetController::Show(); | |||
1937 | } | |||
1938 | ||||
1939 | void ValueSet::Hide() | |||
1940 | { | |||
1941 | CustomWidgetController::Hide(); | |||
1942 | if (mxScrolledWindow) | |||
1943 | mxScrolledWindow->hide(); | |||
1944 | } | |||
1945 | ||||
1946 | FactoryFunction ValueSet::GetUITestFactory() const | |||
1947 | { | |||
1948 | return ValueSetUIObject::create; | |||
1949 | } | |||
1950 | ||||
1951 | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |
1 | // unique_ptr implementation -*- C++ -*- |
2 | |
3 | // Copyright (C) 2008-2020 Free Software Foundation, Inc. |
4 | // |
5 | // This file is part of the GNU ISO C++ Library. This library is free |
6 | // software; you can redistribute it and/or modify it under the |
7 | // terms of the GNU General Public License as published by the |
8 | // Free Software Foundation; either version 3, or (at your option) |
9 | // any later version. |
10 | |
11 | // This library is distributed in the hope that it will be useful, |
12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 | // GNU General Public License for more details. |
15 | |
16 | // Under Section 7 of GPL version 3, you are granted additional |
17 | // permissions described in the GCC Runtime Library Exception, version |
18 | // 3.1, as published by the Free Software Foundation. |
19 | |
20 | // You should have received a copy of the GNU General Public License and |
21 | // a copy of the GCC Runtime Library Exception along with this program; |
22 | // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see |
23 | // <http://www.gnu.org/licenses/>. |
24 | |
25 | /** @file bits/unique_ptr.h |
26 | * This is an internal header file, included by other library headers. |
27 | * Do not attempt to use it directly. @headername{memory} |
28 | */ |
29 | |
30 | #ifndef _UNIQUE_PTR_H1 |
31 | #define _UNIQUE_PTR_H1 1 |
32 | |
33 | #include <bits/c++config.h> |
34 | #include <debug/assertions.h> |
35 | #include <type_traits> |
36 | #include <utility> |
37 | #include <tuple> |
38 | #include <bits/stl_function.h> |
39 | #include <bits/functional_hash.h> |
40 | #if __cplusplus201703L > 201703L |
41 | # include <compare> |
42 | # include <ostream> |
43 | #endif |
44 | |
45 | namespace std _GLIBCXX_VISIBILITY(default)__attribute__ ((__visibility__ ("default"))) |
46 | { |
47 | _GLIBCXX_BEGIN_NAMESPACE_VERSION |
48 | |
49 | /** |
50 | * @addtogroup pointer_abstractions |
51 | * @{ |
52 | */ |
53 | |
54 | #if _GLIBCXX_USE_DEPRECATED1 |
55 | #pragma GCC diagnostic push |
56 | #pragma GCC diagnostic ignored "-Wdeprecated-declarations" |
57 | template<typename> class auto_ptr; |
58 | #pragma GCC diagnostic pop |
59 | #endif |
60 | |
61 | /// Primary template of default_delete, used by unique_ptr for single objects |
62 | template<typename _Tp> |
63 | struct default_delete |
64 | { |
65 | /// Default constructor |
66 | constexpr default_delete() noexcept = default; |
67 | |
68 | /** @brief Converting constructor. |
69 | * |
70 | * Allows conversion from a deleter for objects of another type, `_Up`, |
71 | * only if `_Up*` is convertible to `_Tp*`. |
72 | */ |
73 | template<typename _Up, |
74 | typename = _Require<is_convertible<_Up*, _Tp*>>> |
75 | default_delete(const default_delete<_Up>&) noexcept { } |
76 | |
77 | /// Calls `delete __ptr` |
78 | void |
79 | operator()(_Tp* __ptr) const |
80 | { |
81 | static_assert(!is_void<_Tp>::value, |
82 | "can't delete pointer to incomplete type"); |
83 | static_assert(sizeof(_Tp)>0, |
84 | "can't delete pointer to incomplete type"); |
85 | delete __ptr; |
86 | } |
87 | }; |
88 | |
89 | // _GLIBCXX_RESOLVE_LIB_DEFECTS |
90 | // DR 740 - omit specialization for array objects with a compile time length |
91 | |
92 | /// Specialization of default_delete for arrays, used by `unique_ptr<T[]>` |
93 | template<typename _Tp> |
94 | struct default_delete<_Tp[]> |
95 | { |
96 | public: |
97 | /// Default constructor |
98 | constexpr default_delete() noexcept = default; |
99 | |
100 | /** @brief Converting constructor. |
101 | * |
102 | * Allows conversion from a deleter for arrays of another type, such as |
103 | * a const-qualified version of `_Tp`. |
104 | * |
105 | * Conversions from types derived from `_Tp` are not allowed because |
106 | * it is undefined to `delete[]` an array of derived types through a |
107 | * pointer to the base type. |
108 | */ |
109 | template<typename _Up, |
110 | typename = _Require<is_convertible<_Up(*)[], _Tp(*)[]>>> |
111 | default_delete(const default_delete<_Up[]>&) noexcept { } |
112 | |
113 | /// Calls `delete[] __ptr` |
114 | template<typename _Up> |
115 | typename enable_if<is_convertible<_Up(*)[], _Tp(*)[]>::value>::type |
116 | operator()(_Up* __ptr) const |
117 | { |
118 | static_assert(sizeof(_Tp)>0, |
119 | "can't delete pointer to incomplete type"); |
120 | delete [] __ptr; |
121 | } |
122 | }; |
123 | |
124 | /// @cond undocumented |
125 | |
126 | // Manages the pointer and deleter of a unique_ptr |
127 | template <typename _Tp, typename _Dp> |
128 | class __uniq_ptr_impl |
129 | { |
130 | template <typename _Up, typename _Ep, typename = void> |
131 | struct _Ptr |
132 | { |
133 | using type = _Up*; |
134 | }; |
135 | |
136 | template <typename _Up, typename _Ep> |
137 | struct |
138 | _Ptr<_Up, _Ep, __void_t<typename remove_reference<_Ep>::type::pointer>> |
139 | { |
140 | using type = typename remove_reference<_Ep>::type::pointer; |
141 | }; |
142 | |
143 | public: |
144 | using _DeleterConstraint = enable_if< |
145 | __and_<__not_<is_pointer<_Dp>>, |
146 | is_default_constructible<_Dp>>::value>; |
147 | |
148 | using pointer = typename _Ptr<_Tp, _Dp>::type; |
149 | |
150 | static_assert( !is_rvalue_reference<_Dp>::value, |
151 | "unique_ptr's deleter type must be a function object type" |
152 | " or an lvalue reference type" ); |
153 | |
154 | __uniq_ptr_impl() = default; |
155 | __uniq_ptr_impl(pointer __p) : _M_t() { _M_ptr() = __p; } |
156 | |
157 | template<typename _Del> |
158 | __uniq_ptr_impl(pointer __p, _Del&& __d) |
159 | : _M_t(__p, std::forward<_Del>(__d)) { } |
160 | |
161 | __uniq_ptr_impl(__uniq_ptr_impl&& __u) noexcept |
162 | : _M_t(std::move(__u._M_t)) |
163 | { __u._M_ptr() = nullptr; } |
164 | |
165 | __uniq_ptr_impl& operator=(__uniq_ptr_impl&& __u) noexcept |
166 | { |
167 | reset(__u.release()); |
168 | _M_deleter() = std::forward<_Dp>(__u._M_deleter()); |
169 | return *this; |
170 | } |
171 | |
172 | pointer& _M_ptr() { return std::get<0>(_M_t); } |
173 | pointer _M_ptr() const { return std::get<0>(_M_t); } |
174 | _Dp& _M_deleter() { return std::get<1>(_M_t); } |
175 | const _Dp& _M_deleter() const { return std::get<1>(_M_t); } |
176 | |
177 | void reset(pointer __p) noexcept |
178 | { |
179 | const pointer __old_p = _M_ptr(); |
180 | _M_ptr() = __p; |
181 | if (__old_p) |
182 | _M_deleter()(__old_p); |
183 | } |
184 | |
185 | pointer release() noexcept |
186 | { |
187 | pointer __p = _M_ptr(); |
188 | _M_ptr() = nullptr; |
189 | return __p; |
190 | } |
191 | |
192 | void |
193 | swap(__uniq_ptr_impl& __rhs) noexcept |
194 | { |
195 | using std::swap; |
196 | swap(this->_M_ptr(), __rhs._M_ptr()); |
197 | swap(this->_M_deleter(), __rhs._M_deleter()); |
198 | } |
199 | |
200 | private: |
201 | tuple<pointer, _Dp> _M_t; |
202 | }; |
203 | |
204 | // Defines move construction + assignment as either defaulted or deleted. |
205 | template <typename _Tp, typename _Dp, |
206 | bool = is_move_constructible<_Dp>::value, |
207 | bool = is_move_assignable<_Dp>::value> |
208 | struct __uniq_ptr_data : __uniq_ptr_impl<_Tp, _Dp> |
209 | { |
210 | using __uniq_ptr_impl<_Tp, _Dp>::__uniq_ptr_impl; |
211 | __uniq_ptr_data(__uniq_ptr_data&&) = default; |
212 | __uniq_ptr_data& operator=(__uniq_ptr_data&&) = default; |
213 | }; |
214 | |
215 | template <typename _Tp, typename _Dp> |
216 | struct __uniq_ptr_data<_Tp, _Dp, true, false> : __uniq_ptr_impl<_Tp, _Dp> |
217 | { |
218 | using __uniq_ptr_impl<_Tp, _Dp>::__uniq_ptr_impl; |
219 | __uniq_ptr_data(__uniq_ptr_data&&) = default; |
220 | __uniq_ptr_data& operator=(__uniq_ptr_data&&) = delete; |
221 | }; |
222 | |
223 | template <typename _Tp, typename _Dp> |
224 | struct __uniq_ptr_data<_Tp, _Dp, false, true> : __uniq_ptr_impl<_Tp, _Dp> |
225 | { |
226 | using __uniq_ptr_impl<_Tp, _Dp>::__uniq_ptr_impl; |
227 | __uniq_ptr_data(__uniq_ptr_data&&) = delete; |
228 | __uniq_ptr_data& operator=(__uniq_ptr_data&&) = default; |
229 | }; |
230 | |
231 | template <typename _Tp, typename _Dp> |
232 | struct __uniq_ptr_data<_Tp, _Dp, false, false> : __uniq_ptr_impl<_Tp, _Dp> |
233 | { |
234 | using __uniq_ptr_impl<_Tp, _Dp>::__uniq_ptr_impl; |
235 | __uniq_ptr_data(__uniq_ptr_data&&) = delete; |
236 | __uniq_ptr_data& operator=(__uniq_ptr_data&&) = delete; |
237 | }; |
238 | /// @endcond |
239 | |
240 | /// 20.7.1.2 unique_ptr for single objects. |
241 | template <typename _Tp, typename _Dp = default_delete<_Tp>> |
242 | class unique_ptr |
243 | { |
244 | template <typename _Up> |
245 | using _DeleterConstraint = |
246 | typename __uniq_ptr_impl<_Tp, _Up>::_DeleterConstraint::type; |
247 | |
248 | __uniq_ptr_data<_Tp, _Dp> _M_t; |
249 | |
250 | public: |
251 | using pointer = typename __uniq_ptr_impl<_Tp, _Dp>::pointer; |
252 | using element_type = _Tp; |
253 | using deleter_type = _Dp; |
254 | |
255 | private: |
256 | // helper template for detecting a safe conversion from another |
257 | // unique_ptr |
258 | template<typename _Up, typename _Ep> |
259 | using __safe_conversion_up = __and_< |
260 | is_convertible<typename unique_ptr<_Up, _Ep>::pointer, pointer>, |
261 | __not_<is_array<_Up>> |
262 | >; |
263 | |
264 | public: |
265 | // Constructors. |
266 | |
267 | /// Default constructor, creates a unique_ptr that owns nothing. |
268 | template<typename _Del = _Dp, typename = _DeleterConstraint<_Del>> |
269 | constexpr unique_ptr() noexcept |
270 | : _M_t() |
271 | { } |
272 | |
273 | /** Takes ownership of a pointer. |
274 | * |
275 | * @param __p A pointer to an object of @c element_type |
276 | * |
277 | * The deleter will be value-initialized. |
278 | */ |
279 | template<typename _Del = _Dp, typename = _DeleterConstraint<_Del>> |
280 | explicit |
281 | unique_ptr(pointer __p) noexcept |
282 | : _M_t(__p) |
283 | { } |
284 | |
285 | /** Takes ownership of a pointer. |
286 | * |
287 | * @param __p A pointer to an object of @c element_type |
288 | * @param __d A reference to a deleter. |
289 | * |
290 | * The deleter will be initialized with @p __d |
291 | */ |
292 | template<typename _Del = deleter_type, |
293 | typename = _Require<is_copy_constructible<_Del>>> |
294 | unique_ptr(pointer __p, const deleter_type& __d) noexcept |
295 | : _M_t(__p, __d) { } |
296 | |
297 | /** Takes ownership of a pointer. |
298 | * |
299 | * @param __p A pointer to an object of @c element_type |
300 | * @param __d An rvalue reference to a (non-reference) deleter. |
301 | * |
302 | * The deleter will be initialized with @p std::move(__d) |
303 | */ |
304 | template<typename _Del = deleter_type, |
305 | typename = _Require<is_move_constructible<_Del>>> |
306 | unique_ptr(pointer __p, |
307 | __enable_if_t<!is_lvalue_reference<_Del>::value, |
308 | _Del&&> __d) noexcept |
309 | : _M_t(__p, std::move(__d)) |
310 | { } |
311 | |
312 | template<typename _Del = deleter_type, |
313 | typename _DelUnref = typename remove_reference<_Del>::type> |
314 | unique_ptr(pointer, |
315 | __enable_if_t<is_lvalue_reference<_Del>::value, |
316 | _DelUnref&&>) = delete; |
317 | |
318 | /// Creates a unique_ptr that owns nothing. |
319 | template<typename _Del = _Dp, typename = _DeleterConstraint<_Del>> |
320 | constexpr unique_ptr(nullptr_t) noexcept |
321 | : _M_t() |
322 | { } |
323 | |
324 | // Move constructors. |
325 | |
326 | /// Move constructor. |
327 | unique_ptr(unique_ptr&&) = default; |
328 | |
329 | /** @brief Converting constructor from another type |
330 | * |
331 | * Requires that the pointer owned by @p __u is convertible to the |
332 | * type of pointer owned by this object, @p __u does not own an array, |
333 | * and @p __u has a compatible deleter type. |
334 | */ |
335 | template<typename _Up, typename _Ep, typename = _Require< |
336 | __safe_conversion_up<_Up, _Ep>, |
337 | typename conditional<is_reference<_Dp>::value, |
338 | is_same<_Ep, _Dp>, |
339 | is_convertible<_Ep, _Dp>>::type>> |
340 | unique_ptr(unique_ptr<_Up, _Ep>&& __u) noexcept |
341 | : _M_t(__u.release(), std::forward<_Ep>(__u.get_deleter())) |
342 | { } |
343 | |
344 | #if _GLIBCXX_USE_DEPRECATED1 |
345 | #pragma GCC diagnostic push |
346 | #pragma GCC diagnostic ignored "-Wdeprecated-declarations" |
347 | /// Converting constructor from @c auto_ptr |
348 | template<typename _Up, typename = _Require< |
349 | is_convertible<_Up*, _Tp*>, is_same<_Dp, default_delete<_Tp>>>> |
350 | unique_ptr(auto_ptr<_Up>&& __u) noexcept; |
351 | #pragma GCC diagnostic pop |
352 | #endif |
353 | |
354 | /// Destructor, invokes the deleter if the stored pointer is not null. |
355 | ~unique_ptr() noexcept |
356 | { |
357 | static_assert(__is_invocable<deleter_type&, pointer>::value, |
358 | "unique_ptr's deleter must be invocable with a pointer"); |
359 | auto& __ptr = _M_t._M_ptr(); |
360 | if (__ptr != nullptr) |
361 | get_deleter()(std::move(__ptr)); |
362 | __ptr = pointer(); |
363 | } |
364 | |
365 | // Assignment. |
366 | |
367 | /** @brief Move assignment operator. |
368 | * |
369 | * Invokes the deleter if this object owns a pointer. |
370 | */ |
371 | unique_ptr& operator=(unique_ptr&&) = default; |
372 | |
373 | /** @brief Assignment from another type. |
374 | * |
375 | * @param __u The object to transfer ownership from, which owns a |
376 | * convertible pointer to a non-array object. |
377 | * |
378 | * Invokes the deleter if this object owns a pointer. |
379 | */ |
380 | template<typename _Up, typename _Ep> |
381 | typename enable_if< __and_< |
382 | __safe_conversion_up<_Up, _Ep>, |
383 | is_assignable<deleter_type&, _Ep&&> |
384 | >::value, |
385 | unique_ptr&>::type |
386 | operator=(unique_ptr<_Up, _Ep>&& __u) noexcept |
387 | { |
388 | reset(__u.release()); |
389 | get_deleter() = std::forward<_Ep>(__u.get_deleter()); |
390 | return *this; |
391 | } |
392 | |
393 | /// Reset the %unique_ptr to empty, invoking the deleter if necessary. |
394 | unique_ptr& |
395 | operator=(nullptr_t) noexcept |
396 | { |
397 | reset(); |
398 | return *this; |
399 | } |
400 | |
401 | // Observers. |
402 | |
403 | /// Dereference the stored pointer. |
404 | typename add_lvalue_reference<element_type>::type |
405 | operator*() const |
406 | { |
407 | __glibcxx_assert(get() != pointer()); |
408 | return *get(); |
409 | } |
410 | |
411 | /// Return the stored pointer. |
412 | pointer |
413 | operator->() const noexcept |
414 | { |
415 | _GLIBCXX_DEBUG_PEDASSERT(get() != pointer()); |
416 | return get(); |
417 | } |
418 | |
419 | /// Return the stored pointer. |
420 | pointer |
421 | get() const noexcept |
422 | { return _M_t._M_ptr(); } |
423 | |
424 | /// Return a reference to the stored deleter. |
425 | deleter_type& |
426 | get_deleter() noexcept |
427 | { return _M_t._M_deleter(); } |
428 | |
429 | /// Return a reference to the stored deleter. |
430 | const deleter_type& |
431 | get_deleter() const noexcept |
432 | { return _M_t._M_deleter(); } |
433 | |
434 | /// Return @c true if the stored pointer is not null. |
435 | explicit operator bool() const noexcept |
436 | { return get() == pointer() ? false : true; } |
437 | |
438 | // Modifiers. |
439 | |
440 | /// Release ownership of any stored pointer. |
441 | pointer |
442 | release() noexcept |
443 | { return _M_t.release(); } |
444 | |
445 | /** @brief Replace the stored pointer. |
446 | * |
447 | * @param __p The new pointer to store. |
448 | * |
449 | * The deleter will be invoked if a pointer is already owned. |
450 | */ |
451 | void |
452 | reset(pointer __p = pointer()) noexcept |
453 | { |
454 | static_assert(__is_invocable<deleter_type&, pointer>::value, |
455 | "unique_ptr's deleter must be invocable with a pointer"); |
456 | _M_t.reset(std::move(__p)); |
457 | } |
458 | |
459 | /// Exchange the pointer and deleter with another object. |
460 | void |
461 | swap(unique_ptr& __u) noexcept |
462 | { |
463 | static_assert(__is_swappable<_Dp>::value, "deleter must be swappable"); |
464 | _M_t.swap(__u._M_t); |
465 | } |
466 | |
467 | // Disable copy from lvalue. |
468 | unique_ptr(const unique_ptr&) = delete; |
469 | unique_ptr& operator=(const unique_ptr&) = delete; |
470 | }; |
471 | |
472 | /// 20.7.1.3 unique_ptr for array objects with a runtime length |
473 | // [unique.ptr.runtime] |
474 | // _GLIBCXX_RESOLVE_LIB_DEFECTS |
475 | // DR 740 - omit specialization for array objects with a compile time length |
476 | template<typename _Tp, typename _Dp> |
477 | class unique_ptr<_Tp[], _Dp> |
478 | { |
479 | template <typename _Up> |
480 | using _DeleterConstraint = |
481 | typename __uniq_ptr_impl<_Tp, _Up>::_DeleterConstraint::type; |
482 | |
483 | __uniq_ptr_data<_Tp, _Dp> _M_t; |
484 | |
485 | template<typename _Up> |
486 | using __remove_cv = typename remove_cv<_Up>::type; |
487 | |
488 | // like is_base_of<_Tp, _Up> but false if unqualified types are the same |
489 | template<typename _Up> |
490 | using __is_derived_Tp |
491 | = __and_< is_base_of<_Tp, _Up>, |
492 | __not_<is_same<__remove_cv<_Tp>, __remove_cv<_Up>>> >; |
493 | |
494 | public: |
495 | using pointer = typename __uniq_ptr_impl<_Tp, _Dp>::pointer; |
496 | using element_type = _Tp; |
497 | using deleter_type = _Dp; |
498 | |
499 | // helper template for detecting a safe conversion from another |
500 | // unique_ptr |
501 | template<typename _Up, typename _Ep, |
502 | typename _UPtr = unique_ptr<_Up, _Ep>, |
503 | typename _UP_pointer = typename _UPtr::pointer, |
504 | typename _UP_element_type = typename _UPtr::element_type> |
505 | using __safe_conversion_up = __and_< |
506 | is_array<_Up>, |
507 | is_same<pointer, element_type*>, |
508 | is_same<_UP_pointer, _UP_element_type*>, |
509 | is_convertible<_UP_element_type(*)[], element_type(*)[]> |
510 | >; |
511 | |
512 | // helper template for detecting a safe conversion from a raw pointer |
513 | template<typename _Up> |
514 | using __safe_conversion_raw = __and_< |
515 | __or_<__or_<is_same<_Up, pointer>, |
516 | is_same<_Up, nullptr_t>>, |
517 | __and_<is_pointer<_Up>, |
518 | is_same<pointer, element_type*>, |
519 | is_convertible< |
520 | typename remove_pointer<_Up>::type(*)[], |
521 | element_type(*)[]> |
522 | > |
523 | > |
524 | >; |
525 | |
526 | // Constructors. |
527 | |
528 | /// Default constructor, creates a unique_ptr that owns nothing. |
529 | template<typename _Del = _Dp, typename = _DeleterConstraint<_Del>> |
530 | constexpr unique_ptr() noexcept |
531 | : _M_t() |
532 | { } |
533 | |
534 | /** Takes ownership of a pointer. |
535 | * |
536 | * @param __p A pointer to an array of a type safely convertible |
537 | * to an array of @c element_type |
538 | * |
539 | * The deleter will be value-initialized. |
540 | */ |
541 | template<typename _Up, |
542 | typename _Vp = _Dp, |
543 | typename = _DeleterConstraint<_Vp>, |
544 | typename = typename enable_if< |
545 | __safe_conversion_raw<_Up>::value, bool>::type> |
546 | explicit |
547 | unique_ptr(_Up __p) noexcept |
548 | : _M_t(__p) |
549 | { } |
550 | |
551 | /** Takes ownership of a pointer. |
552 | * |
553 | * @param __p A pointer to an array of a type safely convertible |
554 | * to an array of @c element_type |
555 | * @param __d A reference to a deleter. |
556 | * |
557 | * The deleter will be initialized with @p __d |
558 | */ |
559 | template<typename _Up, typename _Del = deleter_type, |
560 | typename = _Require<__safe_conversion_raw<_Up>, |
561 | is_copy_constructible<_Del>>> |
562 | unique_ptr(_Up __p, const deleter_type& __d) noexcept |
563 | : _M_t(__p, __d) { } |
564 | |
565 | /** Takes ownership of a pointer. |
566 | * |
567 | * @param __p A pointer to an array of a type safely convertible |
568 | * to an array of @c element_type |
569 | * @param __d A reference to a deleter. |
570 | * |
571 | * The deleter will be initialized with @p std::move(__d) |
572 | */ |
573 | template<typename _Up, typename _Del = deleter_type, |
574 | typename = _Require<__safe_conversion_raw<_Up>, |
575 | is_move_constructible<_Del>>> |
576 | unique_ptr(_Up __p, |
577 | __enable_if_t<!is_lvalue_reference<_Del>::value, |
578 | _Del&&> __d) noexcept |
579 | : _M_t(std::move(__p), std::move(__d)) |
580 | { } |
581 | |
582 | template<typename _Up, typename _Del = deleter_type, |
583 | typename _DelUnref = typename remove_reference<_Del>::type, |
584 | typename = _Require<__safe_conversion_raw<_Up>>> |
585 | unique_ptr(_Up, |
586 | __enable_if_t<is_lvalue_reference<_Del>::value, |
587 | _DelUnref&&>) = delete; |
588 | |
589 | /// Move constructor. |
590 | unique_ptr(unique_ptr&&) = default; |
591 | |
592 | /// Creates a unique_ptr that owns nothing. |
593 | template<typename _Del = _Dp, typename = _DeleterConstraint<_Del>> |
594 | constexpr unique_ptr(nullptr_t) noexcept |
595 | : _M_t() |
596 | { } |
597 | |
598 | template<typename _Up, typename _Ep, typename = _Require< |
599 | __safe_conversion_up<_Up, _Ep>, |
600 | typename conditional<is_reference<_Dp>::value, |
601 | is_same<_Ep, _Dp>, |
602 | is_convertible<_Ep, _Dp>>::type>> |
603 | unique_ptr(unique_ptr<_Up, _Ep>&& __u) noexcept |
604 | : _M_t(__u.release(), std::forward<_Ep>(__u.get_deleter())) |
605 | { } |
606 | |
607 | /// Destructor, invokes the deleter if the stored pointer is not null. |
608 | ~unique_ptr() |
609 | { |
610 | auto& __ptr = _M_t._M_ptr(); |
611 | if (__ptr != nullptr) |
612 | get_deleter()(__ptr); |
613 | __ptr = pointer(); |
614 | } |
615 | |
616 | // Assignment. |
617 | |
618 | /** @brief Move assignment operator. |
619 | * |
620 | * Invokes the deleter if this object owns a pointer. |
621 | */ |
622 | unique_ptr& |
623 | operator=(unique_ptr&&) = default; |
624 | |
625 | /** @brief Assignment from another type. |
626 | * |
627 | * @param __u The object to transfer ownership from, which owns a |
628 | * convertible pointer to an array object. |
629 | * |
630 | * Invokes the deleter if this object owns a pointer. |
631 | */ |
632 | template<typename _Up, typename _Ep> |
633 | typename |
634 | enable_if<__and_<__safe_conversion_up<_Up, _Ep>, |
635 | is_assignable<deleter_type&, _Ep&&> |
636 | >::value, |
637 | unique_ptr&>::type |
638 | operator=(unique_ptr<_Up, _Ep>&& __u) noexcept |
639 | { |
640 | reset(__u.release()); |
641 | get_deleter() = std::forward<_Ep>(__u.get_deleter()); |
642 | return *this; |
643 | } |
644 | |
645 | /// Reset the %unique_ptr to empty, invoking the deleter if necessary. |
646 | unique_ptr& |
647 | operator=(nullptr_t) noexcept |
648 | { |
649 | reset(); |
650 | return *this; |
651 | } |
652 | |
653 | // Observers. |
654 | |
655 | /// Access an element of owned array. |
656 | typename std::add_lvalue_reference<element_type>::type |
657 | operator[](size_t __i) const |
658 | { |
659 | __glibcxx_assert(get() != pointer()); |
660 | return get()[__i]; |
661 | } |
662 | |
663 | /// Return the stored pointer. |
664 | pointer |
665 | get() const noexcept |
666 | { return _M_t._M_ptr(); } |
667 | |
668 | /// Return a reference to the stored deleter. |
669 | deleter_type& |
670 | get_deleter() noexcept |
671 | { return _M_t._M_deleter(); } |
672 | |
673 | /// Return a reference to the stored deleter. |
674 | const deleter_type& |
675 | get_deleter() const noexcept |
676 | { return _M_t._M_deleter(); } |
677 | |
678 | /// Return @c true if the stored pointer is not null. |
679 | explicit operator bool() const noexcept |
680 | { return get() == pointer() ? false : true; } |
681 | |
682 | // Modifiers. |
683 | |
684 | /// Release ownership of any stored pointer. |
685 | pointer |
686 | release() noexcept |
687 | { return _M_t.release(); } |
688 | |
689 | /** @brief Replace the stored pointer. |
690 | * |
691 | * @param __p The new pointer to store. |
692 | * |
693 | * The deleter will be invoked if a pointer is already owned. |
694 | */ |
695 | template <typename _Up, |
696 | typename = _Require< |
697 | __or_<is_same<_Up, pointer>, |
698 | __and_<is_same<pointer, element_type*>, |
699 | is_pointer<_Up>, |
700 | is_convertible< |
701 | typename remove_pointer<_Up>::type(*)[], |
702 | element_type(*)[] |
703 | > |
704 | > |
705 | > |
706 | >> |
707 | void |
708 | reset(_Up __p) noexcept |
709 | { _M_t.reset(std::move(__p)); } |
710 | |
711 | void reset(nullptr_t = nullptr) noexcept |
712 | { reset(pointer()); } |
713 | |
714 | /// Exchange the pointer and deleter with another object. |
715 | void |
716 | swap(unique_ptr& __u) noexcept |
717 | { |
718 | static_assert(__is_swappable<_Dp>::value, "deleter must be swappable"); |
719 | _M_t.swap(__u._M_t); |
720 | } |
721 | |
722 | // Disable copy from lvalue. |
723 | unique_ptr(const unique_ptr&) = delete; |
724 | unique_ptr& operator=(const unique_ptr&) = delete; |
725 | }; |
726 | |
727 | /// @relates unique_ptr @{ |
728 | |
729 | /// Swap overload for unique_ptr |
730 | template<typename _Tp, typename _Dp> |
731 | inline |
732 | #if __cplusplus201703L > 201402L || !defined(__STRICT_ANSI__1) // c++1z or gnu++11 |
733 | // Constrained free swap overload, see p0185r1 |
734 | typename enable_if<__is_swappable<_Dp>::value>::type |
735 | #else |
736 | void |
737 | #endif |
738 | swap(unique_ptr<_Tp, _Dp>& __x, |
739 | unique_ptr<_Tp, _Dp>& __y) noexcept |
740 | { __x.swap(__y); } |
741 | |
742 | #if __cplusplus201703L > 201402L || !defined(__STRICT_ANSI__1) // c++1z or gnu++11 |
743 | template<typename _Tp, typename _Dp> |
744 | typename enable_if<!__is_swappable<_Dp>::value>::type |
745 | swap(unique_ptr<_Tp, _Dp>&, |
746 | unique_ptr<_Tp, _Dp>&) = delete; |
747 | #endif |
748 | |
749 | /// Equality operator for unique_ptr objects, compares the owned pointers |
750 | template<typename _Tp, typename _Dp, |
751 | typename _Up, typename _Ep> |
752 | _GLIBCXX_NODISCARD[[__nodiscard__]] inline bool |
753 | operator==(const unique_ptr<_Tp, _Dp>& __x, |
754 | const unique_ptr<_Up, _Ep>& __y) |
755 | { return __x.get() == __y.get(); } |
756 | |
757 | /// unique_ptr comparison with nullptr |
758 | template<typename _Tp, typename _Dp> |
759 | _GLIBCXX_NODISCARD[[__nodiscard__]] inline bool |
760 | operator==(const unique_ptr<_Tp, _Dp>& __x, nullptr_t) noexcept |
761 | { return !__x; } |
762 | |
763 | #ifndef __cpp_lib_three_way_comparison |
764 | /// unique_ptr comparison with nullptr |
765 | template<typename _Tp, typename _Dp> |
766 | _GLIBCXX_NODISCARD[[__nodiscard__]] inline bool |
767 | operator==(nullptr_t, const unique_ptr<_Tp, _Dp>& __x) noexcept |
768 | { return !__x; } |
769 | |
770 | /// Inequality operator for unique_ptr objects, compares the owned pointers |
771 | template<typename _Tp, typename _Dp, |
772 | typename _Up, typename _Ep> |
773 | _GLIBCXX_NODISCARD[[__nodiscard__]] inline bool |
774 | operator!=(const unique_ptr<_Tp, _Dp>& __x, |
775 | const unique_ptr<_Up, _Ep>& __y) |
776 | { return __x.get() != __y.get(); } |
777 | |
778 | /// unique_ptr comparison with nullptr |
779 | template<typename _Tp, typename _Dp> |
780 | _GLIBCXX_NODISCARD[[__nodiscard__]] inline bool |
781 | operator!=(const unique_ptr<_Tp, _Dp>& __x, nullptr_t) noexcept |
782 | { return (bool)__x; } |
783 | |
784 | /// unique_ptr comparison with nullptr |
785 | template<typename _Tp, typename _Dp> |
786 | _GLIBCXX_NODISCARD[[__nodiscard__]] inline bool |
787 | operator!=(nullptr_t, const unique_ptr<_Tp, _Dp>& __x) noexcept |
788 | { return (bool)__x; } |
789 | #endif // three way comparison |
790 | |
791 | /// Relational operator for unique_ptr objects, compares the owned pointers |
792 | template<typename _Tp, typename _Dp, |
793 | typename _Up, typename _Ep> |
794 | _GLIBCXX_NODISCARD[[__nodiscard__]] inline bool |
795 | operator<(const unique_ptr<_Tp, _Dp>& __x, |
796 | const unique_ptr<_Up, _Ep>& __y) |
797 | { |
798 | typedef typename |
799 | std::common_type<typename unique_ptr<_Tp, _Dp>::pointer, |
800 | typename unique_ptr<_Up, _Ep>::pointer>::type _CT; |
801 | return std::less<_CT>()(__x.get(), __y.get()); |
802 | } |
803 | |
804 | /// unique_ptr comparison with nullptr |
805 | template<typename _Tp, typename _Dp> |
806 | _GLIBCXX_NODISCARD[[__nodiscard__]] inline bool |
807 | operator<(const unique_ptr<_Tp, _Dp>& __x, nullptr_t) |
808 | { |
809 | return std::less<typename unique_ptr<_Tp, _Dp>::pointer>()(__x.get(), |
810 | nullptr); |
811 | } |
812 | |
813 | /// unique_ptr comparison with nullptr |
814 | template<typename _Tp, typename _Dp> |
815 | _GLIBCXX_NODISCARD[[__nodiscard__]] inline bool |
816 | operator<(nullptr_t, const unique_ptr<_Tp, _Dp>& __x) |
817 | { |
818 | return std::less<typename unique_ptr<_Tp, _Dp>::pointer>()(nullptr, |
819 | __x.get()); |
820 | } |
821 | |
822 | /// Relational operator for unique_ptr objects, compares the owned pointers |
823 | template<typename _Tp, typename _Dp, |
824 | typename _Up, typename _Ep> |
825 | _GLIBCXX_NODISCARD[[__nodiscard__]] inline bool |
826 | operator<=(const unique_ptr<_Tp, _Dp>& __x, |
827 | const unique_ptr<_Up, _Ep>& __y) |
828 | { return !(__y < __x); } |
829 | |
830 | /// unique_ptr comparison with nullptr |
831 | template<typename _Tp, typename _Dp> |
832 | _GLIBCXX_NODISCARD[[__nodiscard__]] inline bool |
833 | operator<=(const unique_ptr<_Tp, _Dp>& __x, nullptr_t) |
834 | { return !(nullptr < __x); } |
835 | |
836 | /// unique_ptr comparison with nullptr |
837 | template<typename _Tp, typename _Dp> |
838 | _GLIBCXX_NODISCARD[[__nodiscard__]] inline bool |
839 | operator<=(nullptr_t, const unique_ptr<_Tp, _Dp>& __x) |
840 | { return !(__x < nullptr); } |
841 | |
842 | /// Relational operator for unique_ptr objects, compares the owned pointers |
843 | template<typename _Tp, typename _Dp, |
844 | typename _Up, typename _Ep> |
845 | _GLIBCXX_NODISCARD[[__nodiscard__]] inline bool |
846 | operator>(const unique_ptr<_Tp, _Dp>& __x, |
847 | const unique_ptr<_Up, _Ep>& __y) |
848 | { return (__y < __x); } |
849 | |
850 | /// unique_ptr comparison with nullptr |
851 | template<typename _Tp, typename _Dp> |
852 | _GLIBCXX_NODISCARD[[__nodiscard__]] inline bool |
853 | operator>(const unique_ptr<_Tp, _Dp>& __x, nullptr_t) |
854 | { |
855 | return std::less<typename unique_ptr<_Tp, _Dp>::pointer>()(nullptr, |
856 | __x.get()); |
857 | } |
858 | |
859 | /// unique_ptr comparison with nullptr |
860 | template<typename _Tp, typename _Dp> |
861 | _GLIBCXX_NODISCARD[[__nodiscard__]] inline bool |
862 | operator>(nullptr_t, const unique_ptr<_Tp, _Dp>& __x) |
863 | { |
864 | return std::less<typename unique_ptr<_Tp, _Dp>::pointer>()(__x.get(), |
865 | nullptr); |
866 | } |
867 | |
868 | /// Relational operator for unique_ptr objects, compares the owned pointers |
869 | template<typename _Tp, typename _Dp, |
870 | typename _Up, typename _Ep> |
871 | _GLIBCXX_NODISCARD[[__nodiscard__]] inline bool |
872 | operator>=(const unique_ptr<_Tp, _Dp>& __x, |
873 | const unique_ptr<_Up, _Ep>& __y) |
874 | { return !(__x < __y); } |
875 | |
876 | /// unique_ptr comparison with nullptr |
877 | template<typename _Tp, typename _Dp> |
878 | _GLIBCXX_NODISCARD[[__nodiscard__]] inline bool |
879 | operator>=(const unique_ptr<_Tp, _Dp>& __x, nullptr_t) |
880 | { return !(__x < nullptr); } |
881 | |
882 | /// unique_ptr comparison with nullptr |
883 | template<typename _Tp, typename _Dp> |
884 | _GLIBCXX_NODISCARD[[__nodiscard__]] inline bool |
885 | operator>=(nullptr_t, const unique_ptr<_Tp, _Dp>& __x) |
886 | { return !(nullptr < __x); } |
887 | |
888 | #ifdef __cpp_lib_three_way_comparison |
889 | template<typename _Tp, typename _Dp, typename _Up, typename _Ep> |
890 | requires three_way_comparable_with<typename unique_ptr<_Tp, _Dp>::pointer, |
891 | typename unique_ptr<_Up, _Ep>::pointer> |
892 | inline |
893 | compare_three_way_result_t<typename unique_ptr<_Tp, _Dp>::pointer, |
894 | typename unique_ptr<_Up, _Ep>::pointer> |
895 | operator<=>(const unique_ptr<_Tp, _Dp>& __x, |
896 | const unique_ptr<_Up, _Ep>& __y) |
897 | { return compare_three_way()(__x.get(), __y.get()); } |
898 | |
899 | template<typename _Tp, typename _Dp> |
900 | requires three_way_comparable<typename unique_ptr<_Tp, _Dp>::pointer> |
901 | inline |
902 | compare_three_way_result_t<typename unique_ptr<_Tp, _Dp>::pointer> |
903 | operator<=>(const unique_ptr<_Tp, _Dp>& __x, nullptr_t) |
904 | { |
905 | using pointer = typename unique_ptr<_Tp, _Dp>::pointer; |
906 | return compare_three_way()(__x.get(), static_cast<pointer>(nullptr)); |
907 | } |
908 | #endif |
909 | // @} relates unique_ptr |
910 | |
911 | /// @cond undocumented |
912 | template<typename _Up, typename _Ptr = typename _Up::pointer, |
913 | bool = __poison_hash<_Ptr>::__enable_hash_call> |
914 | struct __uniq_ptr_hash |
915 | #if ! _GLIBCXX_INLINE_VERSION0 |
916 | : private __poison_hash<_Ptr> |
917 | #endif |
918 | { |
919 | size_t |
920 | operator()(const _Up& __u) const |
921 | noexcept(noexcept(std::declval<hash<_Ptr>>()(std::declval<_Ptr>()))) |
922 | { return hash<_Ptr>()(__u.get()); } |
923 | }; |
924 | |
925 | template<typename _Up, typename _Ptr> |
926 | struct __uniq_ptr_hash<_Up, _Ptr, false> |
927 | : private __poison_hash<_Ptr> |
928 | { }; |
929 | /// @endcond |
930 | |
931 | /// std::hash specialization for unique_ptr. |
932 | template<typename _Tp, typename _Dp> |
933 | struct hash<unique_ptr<_Tp, _Dp>> |
934 | : public __hash_base<size_t, unique_ptr<_Tp, _Dp>>, |
935 | public __uniq_ptr_hash<unique_ptr<_Tp, _Dp>> |
936 | { }; |
937 | |
938 | #if __cplusplus201703L >= 201402L |
939 | /// @relates unique_ptr @{ |
940 | #define __cpp_lib_make_unique201304 201304 |
941 | |
942 | /// @cond undocumented |
943 | |
944 | template<typename _Tp> |
945 | struct _MakeUniq |
946 | { typedef unique_ptr<_Tp> __single_object; }; |
947 | |
948 | template<typename _Tp> |
949 | struct _MakeUniq<_Tp[]> |
950 | { typedef unique_ptr<_Tp[]> __array; }; |
951 | |
952 | template<typename _Tp, size_t _Bound> |
953 | struct _MakeUniq<_Tp[_Bound]> |
954 | { struct __invalid_type { }; }; |
955 | |
956 | /// @endcond |
957 | |
958 | /// std::make_unique for single objects |
959 | template<typename _Tp, typename... _Args> |
960 | inline typename _MakeUniq<_Tp>::__single_object |
961 | make_unique(_Args&&... __args) |
962 | { return unique_ptr<_Tp>(new _Tp(std::forward<_Args>(__args)...)); } |
963 | |
964 | /// std::make_unique for arrays of unknown bound |
965 | template<typename _Tp> |
966 | inline typename _MakeUniq<_Tp>::__array |
967 | make_unique(size_t __num) |
968 | { return unique_ptr<_Tp>(new remove_extent_t<_Tp>[__num]()); } |
969 | |
970 | /// Disable std::make_unique for arrays of known bound |
971 | template<typename _Tp, typename... _Args> |
972 | inline typename _MakeUniq<_Tp>::__invalid_type |
973 | make_unique(_Args&&...) = delete; |
974 | // @} relates unique_ptr |
975 | #endif // C++14 |
976 | |
977 | #if __cplusplus201703L > 201703L && __cpp_concepts |
978 | // _GLIBCXX_RESOLVE_LIB_DEFECTS |
979 | // 2948. unique_ptr does not define operator<< for stream output |
980 | /// Stream output operator for unique_ptr |
981 | template<typename _CharT, typename _Traits, typename _Tp, typename _Dp> |
982 | inline basic_ostream<_CharT, _Traits>& |
983 | operator<<(basic_ostream<_CharT, _Traits>& __os, |
984 | const unique_ptr<_Tp, _Dp>& __p) |
985 | requires requires { __os << __p.get(); } |
986 | { |
987 | __os << __p.get(); |
988 | return __os; |
989 | } |
990 | #endif // C++20 |
991 | |
992 | // @} group pointer_abstractions |
993 | |
994 | #if __cplusplus201703L >= 201703L |
995 | namespace __detail::__variant |
996 | { |
997 | template<typename> struct _Never_valueless_alt; // see <variant> |
998 | |
999 | // Provide the strong exception-safety guarantee when emplacing a |
1000 | // unique_ptr into a variant. |
1001 | template<typename _Tp, typename _Del> |
1002 | struct _Never_valueless_alt<std::unique_ptr<_Tp, _Del>> |
1003 | : std::true_type |
1004 | { }; |
1005 | } // namespace __detail::__variant |
1006 | #endif // C++17 |
1007 | |
1008 | _GLIBCXX_END_NAMESPACE_VERSION |
1009 | } // namespace |
1010 | |
1011 | #endif /* _UNIQUE_PTR_H */ |