Bug Summary

File:home/maarten/src/libreoffice/core/include/rtl/ref.hxx
Warning:line 192, column 9
Use of memory after it is freed

Annotated Source Code

Press '?' to see keyboard shortcuts

clang -cc1 -cc1 -triple x86_64-unknown-linux-gnu -analyze -disable-free -disable-llvm-verifier -discard-value-names -main-file-name brwbox2.cxx -analyzer-store=region -analyzer-opt-analyze-nested-blocks -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=cplusplus -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -setup-static-analyzer -mrelocation-model pic -pic-level 2 -mframe-pointer=all -fmath-errno -fno-rounding-math -mconstructor-aliases -munwind-tables -target-cpu x86-64 -fno-split-dwarf-inlining -debugger-tuning=gdb -resource-dir /usr/lib64/clang/11.0.0 -D BOOST_ERROR_CODE_HEADER_ONLY -D BOOST_SYSTEM_NO_DEPRECATED -D CPPU_ENV=gcc3 -D LINUX -D OSL_DEBUG_LEVEL=1 -D SAL_LOG_INFO -D SAL_LOG_WARN -D UNIX -D UNX -D X86_64 -D _PTHREADS -D _REENTRANT -D SVT_DLLIMPLEMENTATION -D EXCEPTIONS_ON -D LIBO_INTERNAL_ONLY -I /home/maarten/src/libreoffice/core/workdir/UnpackedTarball/icu/source -I /home/maarten/src/libreoffice/core/workdir/UnpackedTarball/icu/source/i18n -I /home/maarten/src/libreoffice/core/workdir/UnpackedTarball/icu/source/common -I /home/maarten/src/libreoffice/core/external/boost/include -I /home/maarten/src/libreoffice/core/workdir/UnpackedTarball/boost -I /home/maarten/src/libreoffice/core/include -I /usr/lib/jvm/java-11-openjdk-11.0.9.10-0.0.ea.fc33.x86_64/include -I /usr/lib/jvm/java-11-openjdk-11.0.9.10-0.0.ea.fc33.x86_64/include/linux -I /home/maarten/src/libreoffice/core/config_host -I /home/maarten/src/libreoffice/core/workdir/CustomTarget/officecfg/registry -I /home/maarten/src/libreoffice/core/workdir/UnoApiHeadersTarget/udkapi/normal -I /home/maarten/src/libreoffice/core/workdir/UnoApiHeadersTarget/offapi/normal -I /home/maarten/src/libreoffice/core/svtools/source/inc -I /home/maarten/src/libreoffice/core/svtools/inc -internal-isystem /usr/bin/../lib/gcc/x86_64-redhat-linux/10/../../../../include/c++/10 -internal-isystem /usr/bin/../lib/gcc/x86_64-redhat-linux/10/../../../../include/c++/10/x86_64-redhat-linux -internal-isystem /usr/bin/../lib/gcc/x86_64-redhat-linux/10/../../../../include/c++/10/backward -internal-isystem /usr/local/include -internal-isystem /usr/lib64/clang/11.0.0/include -internal-externc-isystem /include -internal-externc-isystem /usr/include -O0 -Wno-missing-braces -std=c++17 -fdeprecated-macro -fdebug-compilation-dir /home/maarten/src/libreoffice/core -ferror-limit 19 -fvisibility hidden -fvisibility-inlines-hidden -stack-protector 2 -fgnuc-version=4.2.1 -fcxx-exceptions -fexceptions -debug-info-kind=constructor -analyzer-output=html -faddrsig -o /home/maarten/tmp/wis/scan-build-libreoffice/output/report/2020-10-07-141433-9725-1 -x c++ /home/maarten/src/libreoffice/core/svtools/source/brwbox/brwbox2.cxx

/home/maarten/src/libreoffice/core/svtools/source/brwbox/brwbox2.cxx

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/log.hxx>
21#include <o3tl/safeint.hxx>
22#include <osl/diagnose.h>
23#include <tools/debug.hxx>
24#include <svtools/brwbox.hxx>
25#include <svtools/recorditemwindow.hxx>
26#include "datwin.hxx"
27#include <svtools/colorcfg.hxx>
28#include <vcl/commandevent.hxx>
29#include <vcl/ptrstyle.hxx>
30#include <vcl/scrbar.hxx>
31#include <vcl/settings.hxx>
32
33#include <tools/multisel.hxx>
34#include <tools/fract.hxx>
35#include <algorithm>
36#include <memory>
37
38using namespace ::com::sun::star::datatransfer;
39
40
41void BrowseBox::StartDrag( sal_Int8 /* _nAction */, const Point& /* _rPosPixel */ )
42{
43 // not interested in this event
44}
45
46
47sal_Int8 BrowseBox::AcceptDrop( const AcceptDropEvent& _rEvt )
48{
49 AcceptDropEvent aTransformed( _rEvt );
50 aTransformed.maPosPixel = pDataWin->ScreenToOutputPixel( OutputToScreenPixel( _rEvt.maPosPixel ) );
51 return pDataWin->AcceptDrop( aTransformed );
52}
53
54
55sal_Int8 BrowseBox::ExecuteDrop( const ExecuteDropEvent& _rEvt )
56{
57 ExecuteDropEvent aTransformed( _rEvt );
58 aTransformed.maPosPixel = pDataWin->ScreenToOutputPixel( OutputToScreenPixel( _rEvt.maPosPixel ) );
59 return pDataWin->ExecuteDrop( aTransformed );
60}
61
62
63sal_Int8 BrowseBox::AcceptDrop( const BrowserAcceptDropEvent& )
64{
65 // not interested in this event
66 return DND_ACTION_NONEcss::datatransfer::dnd::DNDConstants::ACTION_NONE;
67}
68
69
70sal_Int8 BrowseBox::ExecuteDrop( const BrowserExecuteDropEvent& )
71{
72 // not interested in this event
73 return DND_ACTION_NONEcss::datatransfer::dnd::DNDConstants::ACTION_NONE;
74}
75
76
77const DataFlavorExVector& BrowseBox::GetDataFlavors() const
78{
79 if (pDataWin->bCallingDropCallback)
80 return pDataWin->GetDataFlavorExVector();
81 return GetDataFlavorExVector();
82}
83
84
85bool BrowseBox::IsDropFormatSupported( SotClipboardFormatId _nFormat )
86{
87 if ( pDataWin->bCallingDropCallback )
88 return pDataWin->IsDropFormatSupported( _nFormat );
89
90 return DropTargetHelper::IsDropFormatSupported( _nFormat );
91}
92
93
94void BrowseBox::Command( const CommandEvent& rEvt )
95{
96 if ( !pDataWin->bInCommand )
97 Control::Command( rEvt );
98}
99
100
101void BrowseBox::StateChanged( StateChangedType nStateChange )
102{
103 Control::StateChanged( nStateChange );
104
105 if ( StateChangedType::Mirroring == nStateChange )
106 {
107 pDataWin->EnableRTL( IsRTLEnabled() );
108
109 HeaderBar* pHeaderBar = pDataWin->pHeaderBar;
110 if ( pHeaderBar )
111 pHeaderBar->EnableRTL( IsRTLEnabled() );
112 aHScroll->EnableRTL( IsRTLEnabled() );
113 if( pVScroll )
114 pVScroll->EnableRTL( IsRTLEnabled() );
115 Resize();
116 }
117 else if ( StateChangedType::InitShow == nStateChange )
118 {
119 bBootstrapped = true; // must be set first!
120
121 Resize();
122 if ( bMultiSelection )
123 uRow.pSel->SetTotalRange( Range( 0, nRowCount - 1 ) );
124 if ( nRowCount == 0 )
125 nCurRow = BROWSER_ENDOFSELECTION(static_cast<long>((-1)));
126 else if ( nCurRow == BROWSER_ENDOFSELECTION(static_cast<long>((-1))) )
127 nCurRow = 0;
128
129
130 if ( HasFocus() )
131 {
132 bSelectionIsVisible = true;
133 bHasFocus = true;
134 }
135 UpdateScrollbars();
136 AutoSizeLastColumn();
137 CursorMoved();
138 }
139 else if (StateChangedType::Zoom == nStateChange)
140 {
141 pDataWin->SetZoom(GetZoom());
142 HeaderBar* pHeaderBar = pDataWin->pHeaderBar;
143 if (pHeaderBar)
144 pHeaderBar->SetZoom(GetZoom());
145
146 // let the columns calculate their new widths and adjust the header bar
147 for (auto & pCol : mvCols)
148 {
149 pCol->ZoomChanged(GetZoom());
150 if ( pHeaderBar )
151 pHeaderBar->SetItemSize( pCol->GetId(), pCol->Width() );
152 }
153
154 // all our controls have to be repositioned
155 Resize();
156 }
157 else if (StateChangedType::Enable == nStateChange)
158 {
159 // do we have a handle column?
160 bool bHandleCol = !mvCols.empty() && (0 == mvCols[ 0 ]->GetId());
161 // do we have a header bar?
162 bool bHeaderBar(pDataWin->pHeaderBar);
163
164 if ( nTitleLines
165 && ( !bHeaderBar
166 || bHandleCol
167 )
168 )
169 // we draw the text in our header bar in a color dependent on the enabled state. So if this state changed
170 // -> redraw
171 Invalidate(tools::Rectangle(Point(0, 0), Size(GetOutputSizePixel().Width(), GetTitleHeight() - 1)));
172 }
173}
174
175
176void BrowseBox::Select()
177{
178}
179
180
181void BrowseBox::DoubleClick( const BrowserMouseEvent & )
182{
183}
184
185
186long BrowseBox::QueryMinimumRowHeight()
187{
188 return CalcZoom( 5 );
189}
190
191
192void BrowseBox::ImplStartTracking()
193{
194}
195
196
197void BrowseBox::ImplEndTracking()
198{
199}
200
201
202void BrowseBox::RowHeightChanged()
203{
204}
205
206
207void BrowseBox::ColumnResized( sal_uInt16 )
208{
209}
210
211
212void BrowseBox::ColumnMoved( sal_uInt16 )
213{
214}
215
216
217void BrowseBox::StartScroll()
218{
219 DoHideCursor( "StartScroll" );
220}
221
222
223void BrowseBox::EndScroll()
224{
225 UpdateScrollbars();
226 AutoSizeLastColumn();
227 DoShowCursor( "EndScroll" );
228}
229
230
231void BrowseBox::ToggleSelection()
232{
233
234 // selection highlight-toggling allowed?
235 if ( bHideSelect )
236 return;
237 if ( bNotToggleSel || !IsUpdateMode() || !bSelectionIsVisible )
238 return;
239
240 // only highlight painted areas!
241 bNotToggleSel = true;
242
243 // accumulate areas of rows to highlight
244 std::vector<tools::Rectangle> aHighlightList;
245 long nLastRowInRect = 0; // for the CFront
246
247 // don't highlight handle column
248 BrowserColumn *pFirstCol = mvCols.empty() ? nullptr : mvCols[ 0 ].get();
249 long nOfsX = (!pFirstCol || pFirstCol->GetId()) ? 0 : pFirstCol->Width();
250
251 // accumulate old row selection
252 long nBottomRow = nTopRow +
253 pDataWin->GetOutputSizePixel().Height() / GetDataRowHeight();
254 if ( nBottomRow > GetRowCount() && GetRowCount() )
255 nBottomRow = GetRowCount();
256 for ( long nRow = bMultiSelection ? uRow.pSel->FirstSelected() : uRow.nSel;
257 nRow != BROWSER_ENDOFSELECTION(static_cast<long>((-1))) && nRow <= nBottomRow;
258 nRow = bMultiSelection ? uRow.pSel->NextSelected() : BROWSER_ENDOFSELECTION(static_cast<long>((-1))) )
259 {
260 if ( nRow < nTopRow )
261 continue;
262
263 tools::Rectangle aAddRect(
264 Point( nOfsX, (nRow-nTopRow)*GetDataRowHeight() ),
265 Size( pDataWin->GetSizePixel().Width(), GetDataRowHeight() ) );
266 if ( !aHighlightList.empty() && nLastRowInRect == ( nRow - 1 ) )
267 aHighlightList[ 0 ].Union( aAddRect );
268 else
269 aHighlightList.emplace( aHighlightList.begin(), aAddRect );
270 nLastRowInRect = nRow;
271 }
272
273 // unhighlight the old selection (if any)
274 while ( !aHighlightList.empty() )
275 {
276 pDataWin->Invalidate( aHighlightList.back() );
277 aHighlightList.pop_back();
278 }
279
280 // unhighlight old column selection (if any)
281 for ( long nColId = pColSel ? pColSel->FirstSelected() : BROWSER_ENDOFSELECTION(static_cast<long>((-1)));
282 nColId != BROWSER_ENDOFSELECTION(static_cast<long>((-1)));
283 nColId = pColSel->NextSelected() )
284 {
285 tools::Rectangle aRect( GetFieldRectPixel(nCurRow,
286 mvCols[ nColId ]->GetId(),
287 false ) );
288 aRect.AdjustLeft( -(MIN_COLUMNWIDTH2) );
289 aRect.AdjustRight(MIN_COLUMNWIDTH2 );
290 aRect.SetTop( 0 );
291 aRect.SetBottom( pDataWin->GetOutputSizePixel().Height() );
292 pDataWin->Invalidate( aRect );
293 }
294
295 bNotToggleSel = false;
296}
297
298
299void BrowseBox::DrawCursor()
300{
301 bool bReallyHide = false;
302 if ( bHideCursor == TRISTATE_INDET )
303 {
304 if ( !GetSelectRowCount() && !GetSelectColumnCount() )
305 bReallyHide = true;
306 }
307 else if ( bHideCursor == TRISTATE_TRUE )
308 {
309 bReallyHide = true;
310 }
311
312 bReallyHide |= !bSelectionIsVisible || !IsUpdateMode() || bScrolling || nCurRow < 0;
313
314 if (PaintCursorIfHiddenOnce())
315 bReallyHide |= ( GetCursorHideCount() > 1 );
316 else
317 bReallyHide |= ( GetCursorHideCount() > 0 );
318
319 // no cursor on handle column
320 if ( nCurColId == HandleColumnId )
321 nCurColId = GetColumnId(1);
322
323 // calculate cursor rectangle
324 tools::Rectangle aCursor;
325 if ( bColumnCursor )
326 {
327 aCursor = GetFieldRectPixel( nCurRow, nCurColId, false );
328 aCursor.AdjustLeft( -(MIN_COLUMNWIDTH2) );
329 aCursor.AdjustRight(1 );
330 aCursor.AdjustBottom(1 );
331 }
332 else
333 aCursor = tools::Rectangle(
334 Point( ( !mvCols.empty() && mvCols[ 0 ]->GetId() == 0 ) ?
335 mvCols[ 0 ]->Width() : 0,
336 (nCurRow - nTopRow) * GetDataRowHeight() + 1 ),
337 Size( pDataWin->GetOutputSizePixel().Width() + 1,
338 GetDataRowHeight() - 2 ) );
339 if ( bHLines )
340 {
341 if ( !bMultiSelection )
342 aCursor.AdjustTop( -1 );
343 aCursor.AdjustBottom( -1 );
344 }
345
346 if (m_aCursorColor == COL_TRANSPARENT)
347 {
348 // on these platforms, the StarView focus works correctly
349 if ( bReallyHide )
350 static_cast<Control*>(pDataWin.get())->HideFocus();
351 else
352 static_cast<Control*>(pDataWin.get())->ShowFocus( aCursor );
353 }
354 else
355 {
356 Color rCol = bReallyHide ? pDataWin->GetFillColor() : m_aCursorColor;
357 Color aOldFillColor = pDataWin->GetFillColor();
358 Color aOldLineColor = pDataWin->GetLineColor();
359 pDataWin->SetFillColor();
360 pDataWin->SetLineColor( rCol );
361 pDataWin->DrawRect( aCursor );
362 pDataWin->SetLineColor( aOldLineColor );
363 pDataWin->SetFillColor( aOldFillColor );
364 }
365}
366
367
368sal_uLong BrowseBox::GetColumnWidth( sal_uInt16 nId ) const
369{
370
371 sal_uInt16 nItemPos = GetColumnPos( nId );
372 if ( nItemPos >= mvCols.size() )
373 return 0;
374 return mvCols[ nItemPos ]->Width();
375}
376
377
378sal_uInt16 BrowseBox::GetColumnId( sal_uInt16 nPos ) const
379{
380
381 if ( nPos >= mvCols.size() )
382 return BROWSER_INVALIDID((sal_uInt16) 0xFFFF);
383 return mvCols[ nPos ]->GetId();
384}
385
386
387sal_uInt16 BrowseBox::GetColumnPos( sal_uInt16 nId ) const
388{
389 for ( size_t nPos = 0; nPos < mvCols.size(); ++nPos )
390 if ( mvCols[ nPos ]->GetId() == nId )
391 return nPos;
392 return BROWSER_INVALIDID((sal_uInt16) 0xFFFF);
393}
394
395
396bool BrowseBox::IsFrozen( sal_uInt16 nColumnId ) const
397{
398 for (auto const & pCol : mvCols)
399 if ( pCol->GetId() == nColumnId )
400 return pCol->IsFrozen();
401 return false;
402}
403
404
405void BrowseBox::ExpandRowSelection( const BrowserMouseEvent& rEvt )
406{
407
408 DoHideCursor( "ExpandRowSelection" );
409
410 // expand the last selection
411 if ( bMultiSelection )
412 {
413 Range aJustifiedRange( aSelRange );
414 aJustifiedRange.Justify();
415
416 bool bSelectThis = ( bSelect != aJustifiedRange.IsInside( rEvt.GetRow() ) );
417
418 if ( aJustifiedRange.IsInside( rEvt.GetRow() ) )
419 {
420 // down and up
421 while ( rEvt.GetRow() < aSelRange.Max() )
422 { // ZTC/Mac bug - don't put these statements together!
423 SelectRow( aSelRange.Max(), bSelectThis );
424 --aSelRange.Max();
425 }
426 while ( rEvt.GetRow() > aSelRange.Max() )
427 { // ZTC/Mac bug - don't put these statements together!
428 SelectRow( aSelRange.Max(), bSelectThis );
429 ++aSelRange.Max();
430 }
431 }
432 else
433 {
434 // up and down
435 bool bOldSelecting = bSelecting;
436 bSelecting = true;
437 while ( rEvt.GetRow() < aSelRange.Max() )
438 { // ZTC/Mac bug - don't put these statements together!
439 --aSelRange.Max();
440 if ( !IsRowSelected( aSelRange.Max() ) )
441 {
442 SelectRow( aSelRange.Max(), bSelectThis );
443 bSelect = true;
444 }
445 }
446 while ( rEvt.GetRow() > aSelRange.Max() )
447 { // ZTC/Mac bug - don't put these statements together!
448 ++aSelRange.Max();
449 if ( !IsRowSelected( aSelRange.Max() ) )
450 {
451 SelectRow( aSelRange.Max(), bSelectThis );
452 bSelect = true;
453 }
454 }
455 bSelecting = bOldSelecting;
456 if ( bSelect )
457 Select();
458 }
459 }
460 else
461 if (!IsRowSelected(rEvt.GetRow()))
462 SelectRow( rEvt.GetRow() );
463
464 GoToRow( rEvt.GetRow(), false );
465 DoShowCursor( "ExpandRowSelection" );
466}
467
468
469void BrowseBox::Resize()
470{
471 if ( !bBootstrapped && IsReallyVisible() )
472 BrowseBox::StateChanged( StateChangedType::InitShow );
473 if ( mvCols.empty() )
474 {
475 pDataWin->bResizeOnPaint = true;
476 return;
477 }
478 pDataWin->bResizeOnPaint = false;
479
480 // calc the size of the scrollbars
481 sal_uLong nSBSize = GetBarHeight();
482 if (IsZoom())
483 nSBSize = static_cast<sal_uLong>(nSBSize * static_cast<double>(GetZoom()));
484
485 DoHideCursor( "Resize" );
486 sal_uInt16 nOldVisibleRows = 0;
487 //fdo#42694, post #i111125# GetDataRowHeight() can be 0
488 if (GetDataRowHeight())
489 nOldVisibleRows = static_cast<sal_uInt16>(pDataWin->GetOutputSizePixel().Height() / GetDataRowHeight() + 1);
490
491 // did we need a horizontal scroll bar or is there a Control Area?
492 if ( !pDataWin->bNoHScroll &&
493 ( ( mvCols.size() - FrozenColCount() ) > 1 ) )
494 aHScroll->Show();
495 else
496 aHScroll->Hide();
497
498 // calculate the size of the data window
499 long nDataHeight = GetOutputSizePixel().Height() - GetTitleHeight();
500 if ( aHScroll->IsVisible() || ( nControlAreaWidth != USHRT_MAX(32767 *2 +1) ) )
501 nDataHeight -= nSBSize;
502
503 long nDataWidth = GetOutputSizePixel().Width();
504 if ( pVScroll->IsVisible() )
505 nDataWidth -= nSBSize;
506
507 // adjust position and size of data window
508 pDataWin->SetPosSizePixel(
509 Point( 0, GetTitleHeight() ),
510 Size( nDataWidth, nDataHeight ) );
511
512 sal_uInt16 nVisibleRows = 0;
513
514 if (GetDataRowHeight())
515 nVisibleRows = static_cast<sal_uInt16>(pDataWin->GetOutputSizePixel().Height() / GetDataRowHeight() + 1);
516
517 // TopRow is unchanged, but the number of visible lines has changed.
518 if ( nVisibleRows != nOldVisibleRows )
519 VisibleRowsChanged(nTopRow, nVisibleRows);
520
521 UpdateScrollbars();
522
523 // Control-Area
524 tools::Rectangle aInvalidArea( GetControlArea() );
525 aInvalidArea.SetRight( GetOutputSizePixel().Width() );
526 aInvalidArea.SetLeft( 0 );
527 Invalidate( aInvalidArea );
528
529 // external header-bar
530 HeaderBar* pHeaderBar = pDataWin->pHeaderBar;
531 if ( pHeaderBar )
532 {
533 // take the handle column into account
534 BrowserColumn *pFirstCol = mvCols[ 0 ].get();
535 long nOfsX = pFirstCol->GetId() ? 0 : pFirstCol->Width();
536 pHeaderBar->SetPosSizePixel( Point( nOfsX, 0 ), Size( GetOutputSizePixel().Width() - nOfsX, GetTitleHeight() ) );
537 }
538
539 AutoSizeLastColumn(); // adjust last column width
540 DoShowCursor( "Resize" );
541}
542
543
544void BrowseBox::Paint(vcl::RenderContext& rRenderContext, const tools::Rectangle& rRect)
545{
546
547 // initializations
548 if (!bBootstrapped && IsReallyVisible())
549 BrowseBox::StateChanged(StateChangedType::InitShow);
550 if (mvCols.empty())
551 return;
552
553 BrowserColumn *pFirstCol = mvCols[ 0 ].get();
554 bool bHandleCol = pFirstCol && pFirstCol->GetId() == 0;
555 bool bHeaderBar(pDataWin->pHeaderBar);
556
557 // draw delimitational lines
558 if (!pDataWin->bNoHScroll)
559 rRenderContext.DrawLine(Point(0, aHScroll->GetPosPixel().Y()),
560 Point(GetOutputSizePixel().Width(),
561 aHScroll->GetPosPixel().Y()));
562
563 if (nTitleLines)
564 {
565 if (!bHeaderBar)
566 {
567 rRenderContext.DrawLine(Point(0, GetTitleHeight() - 1),
568 Point(GetOutputSizePixel().Width(), GetTitleHeight() - 1));
569 }
570 else if (bHandleCol)
571 {
572 rRenderContext.DrawLine(Point(0, GetTitleHeight() - 1),
573 Point(pFirstCol->Width(), GetTitleHeight() - 1));
574 }
575 }
576
577 // Title Bar
578 // If there is a handle column and if the header bar is available, only
579 // take the HandleColumn into account
580 if (!(nTitleLines && (!bHeaderBar || bHandleCol)))
581 return;
582
583 // iterate through columns to redraw
584 long nX = 0;
585 size_t nCol;
586 for (nCol = 0; nCol < mvCols.size() && nX < rRect.Right(); ++nCol)
587 {
588 // skip invisible columns between frozen and scrollable area
589 if (nCol < nFirstCol && !mvCols[nCol]->IsFrozen())
590 nCol = nFirstCol;
591
592 // only the handle column?
593 if (bHeaderBar && bHandleCol && nCol > 0)
594 break;
595
596 BrowserColumn* pCol = mvCols[nCol].get();
597
598 // draw the column and increment position
599 if ( pCol->Width() > 4 )
600 {
601 ButtonFrame aButtonFrame( Point( nX, 0 ),
602 Size( pCol->Width()-1, GetTitleHeight()-1 ),
603 pCol->Title(), !IsEnabled());
604 aButtonFrame.Draw(rRenderContext);
605 rRenderContext.DrawLine(Point(nX + pCol->Width() - 1, 0),
606 Point(nX + pCol->Width() - 1, GetTitleHeight() - 1));
607 }
608 else
609 {
610 rRenderContext.Push(PushFlags::FILLCOLOR);
611 rRenderContext.SetFillColor(COL_BLACK);
612 rRenderContext.DrawRect(tools::Rectangle(Point(nX, 0), Size(pCol->Width(), GetTitleHeight() - 1)));
613 rRenderContext.Pop();
614 }
615
616 // skip column
617 nX += pCol->Width();
618 }
619
620 // retouching
621 if ( !bHeaderBar && nCol == mvCols.size() )
622 {
623 const StyleSettings &rSettings = rRenderContext.GetSettings().GetStyleSettings();
624 Color aColFace(rSettings.GetFaceColor());
625 rRenderContext.Push(PushFlags::FILLCOLOR | PushFlags::LINECOLOR);
626 rRenderContext.SetFillColor(aColFace);
627 rRenderContext.SetLineColor(aColFace);
628 rRenderContext.DrawRect(tools::Rectangle(Point(nX, 0),
629 Point(rRect.Right(), GetTitleHeight() - 2 )));
630 rRenderContext.Pop();
631 }
632}
633
634void BrowseBox::Draw( OutputDevice* pDev, const Point& rPos, DrawFlags nFlags )
635{
636 // we need pixel coordinates
637 Size aRealSize = GetSizePixel();
638 Point aRealPos = pDev->LogicToPixel(rPos);
639
640 if ((aRealSize.Width() < 3) || (aRealSize.Height() < 3))
641 // we want to have two pixels frame ...
642 return;
643
644 vcl::Font aFont = pDataWin->GetDrawPixelFont( pDev );
645 // the 'normal' painting uses always the data window as device to output to, so we have to calc the new font
646 // relative to the data wins current settings
647
648 pDev->Push();
649 pDev->SetMapMode();
650 pDev->SetFont( aFont );
651
652 // draw a frame
653 const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings();
654 pDev->SetLineColor(rStyleSettings.GetDarkShadowColor());
655 pDev->DrawLine(Point(aRealPos.X(), aRealPos.Y()),
656 Point(aRealPos.X(), aRealPos.Y() + aRealSize.Height() - 1));
657 pDev->DrawLine(Point(aRealPos.X(), aRealPos.Y()),
658 Point(aRealPos.X() + aRealSize.Width() - 1, aRealPos.Y()));
659 pDev->SetLineColor(rStyleSettings.GetShadowColor());
660 pDev->DrawLine(Point(aRealPos.X() + aRealSize.Width() - 1, aRealPos.Y() + 1),
661 Point(aRealPos.X() + aRealSize.Width() - 1, aRealPos.Y() + aRealSize.Height() - 1));
662 pDev->DrawLine(Point(aRealPos.X() + aRealSize.Width() - 1, aRealPos.Y() + aRealSize.Height() - 1),
663 Point(aRealPos.X() + 1, aRealPos.Y() + aRealSize.Height() - 1));
664
665 HeaderBar* pBar = pDataWin->pHeaderBar;
666
667 // we're drawing onto a foreign device, so we have to fake the DataRowHeight for the subsequent ImplPaintData
668 // (as it is based on the settings of our data window, not the foreign device)
669 if (!nDataRowHeight)
670 ImpGetDataRowHeight();
671 long nHeightLogic = PixelToLogic(Size(0, nDataRowHeight), MapMode(MapUnit::Map10thMM)).Height();
672 long nForeignHeightPixel = pDev->LogicToPixel(Size(0, nHeightLogic), MapMode(MapUnit::Map10thMM)).Height();
673
674 long nOriginalHeight = nDataRowHeight;
675 nDataRowHeight = nForeignHeightPixel;
676
677 // this counts for the column widths, too
678 size_t nPos;
679 for ( nPos = 0; nPos < mvCols.size(); ++nPos )
680 {
681 BrowserColumn* pCurrent = mvCols[ nPos ].get();
682
683 long nWidthLogic = PixelToLogic(Size(pCurrent->Width(), 0), MapMode(MapUnit::Map10thMM)).Width();
684 long nForeignWidthPixel = pDev->LogicToPixel(Size(nWidthLogic, 0), MapMode(MapUnit::Map10thMM)).Width();
685
686 pCurrent->SetWidth(nForeignWidthPixel, GetZoom());
687 if ( pBar )
688 pBar->SetItemSize( pCurrent->GetId(), pCurrent->Width() );
689 }
690
691 // a smaller area for the content
692 aRealPos.AdjustX( 1 );
693 aRealPos.AdjustY( 1 );
694 aRealSize.AdjustWidth( -2 );
695 aRealSize.AdjustHeight( -2 );
696
697 // let the header bar draw itself
698 if ( pBar )
699 {
700 // the title height with respect to the font set for the given device
701 long nTitleHeight = PixelToLogic(Size(0, GetTitleHeight()), MapMode(MapUnit::Map10thMM)).Height();
702 nTitleHeight = pDev->LogicToPixel(Size(0, nTitleHeight), MapMode(MapUnit::Map10thMM)).Height();
703
704 BrowserColumn* pFirstCol = !mvCols.empty() ? mvCols[ 0 ].get() : nullptr;
705
706 Point aHeaderPos(pFirstCol && (pFirstCol->GetId() == 0) ? pFirstCol->Width() : 0, 0);
707 Size aHeaderSize(aRealSize.Width() - aHeaderPos.X(), nTitleHeight);
708
709 aHeaderPos += aRealPos;
710 // do this before converting to logics !
711
712 // the header's draw expects logic coordinates, again
713 aHeaderPos = pDev->PixelToLogic(aHeaderPos);
714
715 Size aOrigSize(pBar->GetSizePixel());
716 pBar->SetSizePixel(aHeaderSize);
717 pBar->Draw(pDev, aHeaderPos, nFlags);
718 pBar->SetSizePixel(aOrigSize);
719
720 // draw the "upper left cell" (the intersection between the header bar and the handle column)
721 if (pFirstCol && (pFirstCol->GetId() == 0) && (pFirstCol->Width() > 4))
722 {
723 ButtonFrame aButtonFrame( aRealPos,
724 Size( pFirstCol->Width()-1, nTitleHeight-1 ),
725 pFirstCol->Title(), !IsEnabled());
726 aButtonFrame.Draw( *pDev );
727
728 pDev->Push( PushFlags::LINECOLOR );
729 pDev->SetLineColor( COL_BLACK );
730
731 pDev->DrawLine( Point( aRealPos.X(), aRealPos.Y() + nTitleHeight-1 ),
732 Point( aRealPos.X() + pFirstCol->Width() - 1, aRealPos.Y() + nTitleHeight-1 ) );
733 pDev->DrawLine( Point( aRealPos.X() + pFirstCol->Width() - 1, aRealPos.Y() ),
734 Point( aRealPos.X() + pFirstCol->Width() - 1, aRealPos.Y() + nTitleHeight-1 ) );
735
736 pDev->Pop();
737 }
738
739 aRealPos.AdjustY(aHeaderSize.Height() );
740 aRealSize.AdjustHeight( -(aHeaderSize.Height()) );
741 }
742
743 // draw our own content (with clipping)
744 vcl::Region aRegion(tools::Rectangle(aRealPos, aRealSize));
745 pDev->SetClipRegion( pDev->PixelToLogic( aRegion ) );
746
747 // do we have to paint the background
748 bool bBackground = pDataWin->IsControlBackground();
749 if ( bBackground )
750 {
751 tools::Rectangle aRect( aRealPos, aRealSize );
752 pDev->SetFillColor( pDataWin->GetControlBackground() );
753 pDev->DrawRect( aRect );
754 }
755
756 ImplPaintData( *pDev, tools::Rectangle( aRealPos, aRealSize ), true );
757
758 // restore the column widths/data row height
759 nDataRowHeight = nOriginalHeight;
760 for ( nPos = 0; nPos < mvCols.size(); ++nPos )
761 {
762 BrowserColumn* pCurrent = mvCols[ nPos ].get();
763
764 long nForeignWidthLogic = pDev->PixelToLogic(Size(pCurrent->Width(), 0), MapMode(MapUnit::Map10thMM)).Width();
765 long nWidthPixel = LogicToPixel(Size(nForeignWidthLogic, 0), MapMode(MapUnit::Map10thMM)).Width();
766
767 pCurrent->SetWidth(nWidthPixel, GetZoom());
768 if ( pBar )
769 pBar->SetItemSize( pCurrent->GetId(), pCurrent->Width() );
770 }
771
772 pDev->Pop();
773}
774
775void BrowseBox::ImplPaintData(OutputDevice& _rOut, const tools::Rectangle& _rRect, bool _bForeignDevice)
776{
777 Point aOverallAreaPos = _bForeignDevice ? _rRect.TopLeft() : Point(0,0);
778 Size aOverallAreaSize = _bForeignDevice ? _rRect.GetSize() : pDataWin->GetOutputSizePixel();
779 Point aOverallAreaBRPos = _bForeignDevice ? _rRect.BottomRight() : Point( aOverallAreaSize.Width(), aOverallAreaSize.Height() );
780
781 long nDataRowHeigt = GetDataRowHeight();
782
783 // compute relative rows to redraw
784 sal_uLong nRelTopRow = 0;
785 sal_uLong nRelBottomRow = aOverallAreaSize.Height();
786 if (!_bForeignDevice && nDataRowHeigt)
787 {
788 nRelTopRow = (static_cast<sal_uLong>(_rRect.Top()) / nDataRowHeigt);
789 nRelBottomRow = static_cast<sal_uLong>(_rRect.Bottom()) / nDataRowHeigt;
790 }
791
792 // cache frequently used values
793 Point aPos( aOverallAreaPos.X(), nRelTopRow * nDataRowHeigt + aOverallAreaPos.Y() );
794 _rOut.SetLineColor( COL_WHITE );
795 const AllSettings& rAllSets = _rOut.GetSettings();
796 const StyleSettings &rSettings = rAllSets.GetStyleSettings();
797 const Color &rHighlightTextColor = rSettings.GetHighlightTextColor();
798 const Color &rHighlightFillColor = rSettings.GetHighlightColor();
799 Color aOldTextColor = _rOut.GetTextColor();
800 Color aOldFillColor = _rOut.GetFillColor();
801 Color aOldLineColor = _rOut.GetLineColor();
802 long nHLineX = 0 == mvCols[ 0 ]->GetId() ? mvCols[ 0 ]->Width() : 0;
803 nHLineX += aOverallAreaPos.X();
804
805 Color aDelimiterLineColor( ::svtools::ColorConfig().GetColorValue( ::svtools::CALCGRID ).nColor );
806
807 // redraw the invalid fields
808 for ( sal_uLong nRelRow = nRelTopRow;
809 nRelRow <= nRelBottomRow && static_cast<sal_uLong>(nTopRow)+nRelRow < o3tl::make_unsigned(nRowCount);
810 ++nRelRow, aPos.AdjustY(nDataRowHeigt ) )
811 {
812 // get row
813 // check valid area, to be on the safe side:
814 DBG_ASSERT( static_cast<sal_uInt16>(nTopRow+nRelRow) < nRowCount, "BrowseBox::ImplPaintData: invalid seek" )do { if (true && (!(static_cast<sal_uInt16>(nTopRow
+nRelRow) < nRowCount))) { sal_detail_logFormat((SAL_DETAIL_LOG_LEVEL_WARN
), ("legacy.tools"), ("/home/maarten/src/libreoffice/core/svtools/source/brwbox/brwbox2.cxx"
":" "814" ": "), "%s", "BrowseBox::ImplPaintData: invalid seek"
); } } while (false)
;
815 if ( (nTopRow+long(nRelRow)) < 0 || static_cast<sal_uInt16>(nTopRow+nRelRow) >= nRowCount )
816 continue;
817
818 // prepare row
819 sal_uLong nRow = nTopRow+nRelRow;
820 if ( !SeekRow( nRow) ) {
821 OSL_FAIL("BrowseBox::ImplPaintData: SeekRow failed")do { if (true && (((sal_Bool)1))) { sal_detail_logFormat
((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/svtools/source/brwbox/brwbox2.cxx"
":" "821" ": "), "%s", "BrowseBox::ImplPaintData: SeekRow failed"
); } } while (false)
;
822 }
823 _rOut.SetClipRegion();
824 aPos.setX( aOverallAreaPos.X() );
825
826
827 // #73325# don't paint the row outside the painting rectangle (DG)
828 // prepare auto-highlight
829 tools::Rectangle aRowRect( Point( _rRect.TopLeft().X(), aPos.Y() ),
830 Size( _rRect.GetSize().Width(), nDataRowHeigt ) );
831
832 bool bRowSelected = !bHideSelect
833 && IsRowSelected( nRow );
834 if ( bRowSelected )
835 {
836 _rOut.SetTextColor( rHighlightTextColor );
837 _rOut.SetFillColor( rHighlightFillColor );
838 _rOut.SetLineColor();
839 _rOut.DrawRect( aRowRect );
840 }
841
842 // iterate through columns to redraw
843 size_t nCol;
844 for ( nCol = 0; nCol < mvCols.size(); ++nCol )
845 {
846 // get column
847 BrowserColumn *pCol = mvCols[ nCol ].get();
848
849 // at end of invalid area
850 if ( aPos.X() >= _rRect.Right() )
851 break;
852
853 // skip invisible columns between frozen and scrollable area
854 if ( nCol < nFirstCol && !pCol->IsFrozen() )
855 {
856 nCol = nFirstCol;
857 pCol = (nCol < mvCols.size() ) ? mvCols[ nCol ].get() : nullptr;
858 if (!pCol)
859 { // FS - 21.05.99 - 66325
860 // actually this has been fixed elsewhere (in the right place),
861 // but let's make sure...
862 OSL_FAIL("BrowseBox::PaintData : nFirstCol is probably invalid !")do { if (true && (((sal_Bool)1))) { sal_detail_logFormat
((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/svtools/source/brwbox/brwbox2.cxx"
":" "862" ": "), "%s", "BrowseBox::PaintData : nFirstCol is probably invalid !"
); } } while (false)
;
863 break;
864 }
865 }
866
867 // prepare Column-AutoHighlight
868 bool bColAutoHighlight = bColumnCursor
869 && IsColumnSelected( pCol->GetId() );
870 if ( bColAutoHighlight )
871 {
872 _rOut.SetClipRegion();
873 _rOut.SetTextColor( rHighlightTextColor );
874 _rOut.SetFillColor( rHighlightFillColor );
875 _rOut.SetLineColor();
876 tools::Rectangle aFieldRect( aPos,
877 Size( pCol->Width(), nDataRowHeigt ) );
878 _rOut.DrawRect( aFieldRect );
879 }
880
881 if (!m_bFocusOnlyCursor && (pCol->GetId() == GetCurColumnId()) && (nRow == static_cast<sal_uLong>(GetCurRow())))
882 DrawCursor();
883
884 // draw a single field.
885 // else something is drawn to, e.g. handle column
886 if (pCol->Width())
887 {
888 // clip the column's output to the field area
889 if (_bForeignDevice)
890 { // (not necessary if painting onto the data window)
891 Size aFieldSize(pCol->Width(), nDataRowHeigt);
892
893 if (aPos.X() + aFieldSize.Width() > aOverallAreaBRPos.X())
894 aFieldSize.setWidth( aOverallAreaBRPos.X() - aPos.X() );
895
896 if (aPos.Y() + aFieldSize.Height() > aOverallAreaBRPos.Y() + 1)
897 {
898 // for non-handle cols we don't clip vertically : we just don't draw the cell if the line isn't completely visible
899 if (pCol->GetId() != 0)
900 continue;
901 aFieldSize.setHeight( aOverallAreaBRPos.Y() + 1 - aPos.Y() );
902 }
903
904 vcl::Region aClipToField(tools::Rectangle(aPos, aFieldSize));
905 _rOut.SetClipRegion(aClipToField);
906 }
907 pCol->Draw( *this, _rOut, aPos );
908 if (_bForeignDevice)
909 _rOut.SetClipRegion();
910 }
911
912 // reset Column-auto-highlight
913 if ( bColAutoHighlight )
914 {
915 _rOut.SetTextColor( aOldTextColor );
916 _rOut.SetFillColor( aOldFillColor );
917 _rOut.SetLineColor( aOldLineColor );
918 }
919
920 // skip column
921 aPos.AdjustX(pCol->Width() );
922 }
923
924 // reset auto-highlight
925 if ( bRowSelected )
926 {
927 _rOut.SetTextColor( aOldTextColor );
928 _rOut.SetFillColor( aOldFillColor );
929 _rOut.SetLineColor( aOldLineColor );
930 }
931
932 if ( bHLines )
933 {
934 // draw horizontal delimitation lines
935 _rOut.SetClipRegion();
936 _rOut.Push( PushFlags::LINECOLOR );
937 _rOut.SetLineColor( aDelimiterLineColor );
938 long nY = aPos.Y() + nDataRowHeigt - 1;
939 if (nY <= aOverallAreaBRPos.Y())
940 _rOut.DrawLine( Point( nHLineX, nY ),
941 Point( bVLines
942 ? std::min(long(aPos.X() - 1), aOverallAreaBRPos.X())
943 : aOverallAreaBRPos.X(),
944 nY ) );
945 _rOut.Pop();
946 }
947 }
948
949 if (aPos.Y() > aOverallAreaBRPos.Y() + 1)
950 aPos.setY( aOverallAreaBRPos.Y() + 1 );
951 // needed for some of the following drawing
952
953 // retouching
954 _rOut.SetClipRegion();
955 aOldLineColor = _rOut.GetLineColor();
956 aOldFillColor = _rOut.GetFillColor();
957 _rOut.SetFillColor( rSettings.GetFaceColor() );
958 if ( !mvCols.empty() && ( mvCols[ 0 ]->GetId() == 0 ) && ( aPos.Y() <= _rRect.Bottom() ) )
959 {
960 // fill rectangle gray below handle column
961 // DG: fill it only until the end of the drawing rect and not to the end, as this may overpaint handle columns
962 _rOut.SetLineColor( COL_BLACK );
963 _rOut.DrawRect( tools::Rectangle(
964 Point( aOverallAreaPos.X() - 1, aPos.Y() - 1 ),
965 Point( aOverallAreaPos.X() + mvCols[ 0 ]->Width() - 1,
966 _rRect.Bottom() + 1) ) );
967 }
968 _rOut.SetFillColor( aOldFillColor );
969
970 // draw vertical delimitational line between frozen and scrollable cols
971 _rOut.SetLineColor( COL_BLACK );
972 long nFrozenWidth = GetFrozenWidth()-1;
973 _rOut.DrawLine( Point( aOverallAreaPos.X() + nFrozenWidth, aPos.Y() ),
974 Point( aOverallAreaPos.X() + nFrozenWidth, bHLines
975 ? aPos.Y() - 1
976 : aOverallAreaBRPos.Y() ) );
977
978 // draw vertical delimitational lines?
979 if ( bVLines )
980 {
981 _rOut.SetLineColor( aDelimiterLineColor );
982 Point aVertPos( aOverallAreaPos.X() - 1, aOverallAreaPos.Y() );
983 long nDeltaY = aOverallAreaBRPos.Y();
984 for ( size_t nCol = 0; nCol < mvCols.size(); ++nCol )
985 {
986 // get column
987 BrowserColumn *pCol = mvCols[ nCol ].get();
988
989 // skip invisible columns between frozen and scrollable area
990 if ( nCol < nFirstCol && !pCol->IsFrozen() )
991 {
992 nCol = nFirstCol;
993 pCol = mvCols[ nCol ].get();
994 }
995
996 // skip column
997 aVertPos.AdjustX(pCol->Width() );
998
999 // at end of invalid area
1000 // invalid area is first reached when X > Right
1001 // and not >=
1002 if ( aVertPos.X() > _rRect.Right() )
1003 break;
1004
1005 // draw a single line
1006 if ( pCol->GetId() != 0 )
1007 _rOut.DrawLine( aVertPos, Point( aVertPos.X(),
1008 bHLines
1009 ? aPos.Y() - 1
1010 : aPos.Y() + nDeltaY ) );
1011 }
1012 }
1013
1014 _rOut.SetLineColor( aOldLineColor );
1015}
1016
1017void BrowseBox::PaintData( vcl::Window const & rWin, vcl::RenderContext& rRenderContext, const tools::Rectangle& rRect )
1018{
1019 if (!bBootstrapped && IsReallyVisible())
1020 BrowseBox::StateChanged(StateChangedType::InitShow);
1021
1022 // initializations
1023 if (mvCols.empty() || !rWin.IsUpdateMode())
1024 return;
1025 if (pDataWin->bResizeOnPaint)
1026 Resize();
1027 // MI: who was that? Window::Update();
1028
1029 ImplPaintData(rRenderContext, rRect, false);
1030}
1031
1032void BrowseBox::UpdateScrollbars()
1033{
1034
1035 if ( !bBootstrapped || !IsUpdateMode() )
3
Assuming field 'bBootstrapped' is true
4
Assuming the condition is false
5
Taking false branch
1036 return;
1037
1038 // protect against recursion
1039 if ( pDataWin->bInUpdateScrollbars )
6
Assuming field 'bInUpdateScrollbars' is false
7
Taking false branch
1040 {
1041 pDataWin->bHadRecursion = true;
1042 return;
1043 }
1044 pDataWin->bInUpdateScrollbars = true;
1045
1046 // the size of the corner window (and the width of the VSB/height of the HSB)
1047 sal_uLong nCornerSize = GetBarHeight();
1048 if (IsZoom())
8
Assuming the condition is false
9
Taking false branch
1049 nCornerSize = static_cast<sal_uLong>(nCornerSize * static_cast<double>(GetZoom()));
1050
1051 bool bNeedsVScroll = false;
1052 long nMaxRows = 0;
1053 if (GetDataRowHeight())
10
Assuming the condition is false
11
Taking false branch
1054 {
1055 // needs VScroll?
1056 nMaxRows = (pDataWin->GetSizePixel().Height()) / GetDataRowHeight();
1057 bNeedsVScroll = pDataWin->bAutoVScroll
1058 ? nTopRow || ( nRowCount > nMaxRows )
1059 : !pDataWin->bNoVScroll;
1060 }
1061 Size aDataWinSize = pDataWin->GetSizePixel();
1062 if ( !bNeedsVScroll
11.1
'bNeedsVScroll' is false
11.1
'bNeedsVScroll' is false
11.1
'bNeedsVScroll' is false
11.1
'bNeedsVScroll' is false
)
12
Taking true branch
1063 {
1064 if ( pVScroll->IsVisible() )
13
Assuming the condition is false
14
Taking false branch
1065 {
1066 pVScroll->Hide();
1067 Size aNewSize( aDataWinSize );
1068 aNewSize.setWidth( GetOutputSizePixel().Width() );
1069 aDataWinSize = aNewSize;
1070 }
1071 }
1072 else if ( !pVScroll->IsVisible() )
1073 {
1074 Size aNewSize( aDataWinSize );
1075 aNewSize.setWidth( GetOutputSizePixel().Width() - nCornerSize );
1076 aDataWinSize = aNewSize;
1077 }
1078
1079 // needs HScroll?
1080 sal_uLong nLastCol = GetColumnAtXPosPixel( aDataWinSize.Width() - 1 );
1081
1082 sal_uInt16 nFrozenCols = FrozenColCount();
1083 bool bNeedsHScroll = pDataWin->bAutoHScroll
15
Assuming field 'bAutoHScroll' is true
16
'?' condition is true
1084 ? ( nFirstCol > nFrozenCols ) || ( nLastCol <= mvCols.size() )
17
Assuming 'nFrozenCols' is >= field 'nFirstCol'
18
Assuming the condition is false
1085 : !pDataWin->bNoHScroll;
1086 if ( !bNeedsHScroll
18.1
'bNeedsHScroll' is false
18.1
'bNeedsHScroll' is false
18.1
'bNeedsHScroll' is false
18.1
'bNeedsHScroll' is false
)
19
Taking true branch
1087 {
1088 if ( aHScroll->IsVisible() )
20
Assuming the condition is false
21
Taking false branch
1089 {
1090 aHScroll->Hide();
1091 }
1092 aDataWinSize.setHeight( GetOutputSizePixel().Height() - GetTitleHeight() );
1093 if ( nControlAreaWidth != USHRT_MAX(32767 *2 +1) )
22
Assuming the condition is false
23
Taking false branch
1094 aDataWinSize.AdjustHeight( -sal_Int32(nCornerSize) );
1095 }
1096 else if ( !aHScroll->IsVisible() )
1097 {
1098 Size aNewSize( aDataWinSize );
1099 aNewSize.setHeight( GetOutputSizePixel().Height() - GetTitleHeight() - nCornerSize );
1100 aDataWinSize = aNewSize;
1101 }
1102
1103 // adjust position and Width of horizontal scrollbar
1104 sal_uLong nHScrX = nControlAreaWidth == USHRT_MAX(32767 *2 +1)
24
'?' condition is true
1105 ? 0
1106 : nControlAreaWidth;
1107
1108 aHScroll->SetPosSizePixel(
1109 Point( nHScrX, GetOutputSizePixel().Height() - nCornerSize ),
1110 Size( aDataWinSize.Width() - nHScrX, nCornerSize ) );
1111
1112 // total scrollable columns
1113 short nScrollCols = short(mvCols.size()) - static_cast<short>(nFrozenCols);
1114
1115 // visible columns
1116 short nVisibleHSize = nLastCol == BROWSER_INVALIDID((sal_uInt16) 0xFFFF)
25
Assuming 'nLastCol' is not equal to BROWSER_INVALIDID
26
'?' condition is false
1117 ? static_cast<short>( mvCols.size() - nFirstCol )
1118 : static_cast<short>( nLastCol - nFirstCol );
1119
1120 short nRange = std::max( nScrollCols, short(0) );
1121 aHScroll->SetVisibleSize( nVisibleHSize );
1122 aHScroll->SetRange( Range( 0, nRange ));
1123 if ( bNeedsHScroll
26.1
'bNeedsHScroll' is false
26.1
'bNeedsHScroll' is false
26.1
'bNeedsHScroll' is false
26.1
'bNeedsHScroll' is false
&& !aHScroll->IsVisible() )
1124 aHScroll->Show();
1125
1126 // adjust position and height of vertical scrollbar
1127 pVScroll->SetPageSize( nMaxRows );
1128
1129 if ( nTopRow > nRowCount )
27
Assuming field 'nTopRow' is <= field 'nRowCount'
28
Taking false branch
1130 {
1131 nTopRow = nRowCount - 1;
1132 OSL_FAIL("BrowseBox: nTopRow > nRowCount")do { if (true && (((sal_Bool)1))) { sal_detail_logFormat
((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/svtools/source/brwbox/brwbox2.cxx"
":" "1132" ": "), "%s", "BrowseBox: nTopRow > nRowCount")
; } } while (false)
;
1133 }
1134
1135 if ( pVScroll->GetThumbPos() != nTopRow )
29
Assuming the condition is false
30
Taking false branch
1136 pVScroll->SetThumbPos( nTopRow );
1137 long nVisibleSize = std::min( std::min( nRowCount, nMaxRows ), long(nRowCount-nTopRow) );
1138 pVScroll->SetVisibleSize( nVisibleSize
30.1
'nVisibleSize' is 0
30.1
'nVisibleSize' is 0
30.1
'nVisibleSize' is 0
30.1
'nVisibleSize' is 0
? nVisibleSize : 1 );
31
'?' condition is false
1139 pVScroll->SetRange( Range( 0, nRowCount ) );
1140 pVScroll->SetPosSizePixel(
1141 Point( aDataWinSize.Width(), GetTitleHeight() ),
1142 Size( nCornerSize, aDataWinSize.Height()) );
1143 long nLclDataRowHeight = GetDataRowHeight();
1144 if ( nLclDataRowHeight > 0 && nRowCount < long( aDataWinSize.Height() / nLclDataRowHeight ) )
32
Assuming 'nLclDataRowHeight' is <= 0
1145 ScrollRows( -nTopRow );
1146 if ( bNeedsVScroll
32.1
'bNeedsVScroll' is false
32.1
'bNeedsVScroll' is false
32.1
'bNeedsVScroll' is false
32.1
'bNeedsVScroll' is false
&& !pVScroll->IsVisible() )
1147 pVScroll->Show();
1148
1149 pDataWin->SetPosSizePixel(
1150 Point( 0, GetTitleHeight() ),
1151 aDataWinSize );
1152
1153 // needs corner-window?
1154 // (do that AFTER positioning BOTH scrollbars)
1155 sal_uLong nActualCorderWidth = 0;
1156 if (aHScroll->IsVisible() && pVScroll && pVScroll->IsVisible() )
33
Assuming the condition is false
1157 {
1158 // if we have both scrollbars, the corner window fills the point of intersection of these two
1159 nActualCorderWidth = nCornerSize;
1160 }
1161 else if ( !aHScroll->IsVisible() && ( nControlAreaWidth != USHRT_MAX(32767 *2 +1) ) )
34
Assuming the condition is false
1162 {
1163 // if we have no horizontal scrollbar, but a control area, we need the corner window to
1164 // fill the space between the control are and the right border
1165 nActualCorderWidth = GetOutputSizePixel().Width() - nControlAreaWidth;
1166 }
1167 if ( nActualCorderWidth
34.1
'nActualCorderWidth' is 0
34.1
'nActualCorderWidth' is 0
34.1
'nActualCorderWidth' is 0
34.1
'nActualCorderWidth' is 0
)
35
Taking false branch
1168 {
1169 if ( !pDataWin->pCornerWin )
1170 pDataWin->pCornerWin = VclPtr<ScrollBarBox>::Create( this, 0 );
1171 pDataWin->pCornerWin->SetPosSizePixel(
1172 Point( GetOutputSizePixel().Width() - nActualCorderWidth, aHScroll->GetPosPixel().Y() ),
1173 Size( nActualCorderWidth, nCornerSize ) );
1174 pDataWin->pCornerWin->Show();
1175 }
1176 else
1177 pDataWin->pCornerWin.disposeAndClear();
36
Calling 'VclPtr::disposeAndClear'
1178
1179 // scroll headerbar, if necessary
1180 if ( pDataWin->pHeaderBar )
1181 {
1182 long nWidth = 0;
1183 for ( size_t nCol = 0;
1184 nCol < mvCols.size() && nCol < nFirstCol;
1185 ++nCol )
1186 {
1187 // not the handle column
1188 if ( mvCols[ nCol ]->GetId() )
1189 nWidth += mvCols[ nCol ]->Width();
1190 }
1191
1192 pDataWin->pHeaderBar->SetOffset( nWidth );
1193 }
1194
1195 pDataWin->bInUpdateScrollbars = false;
1196 if ( pDataWin->bHadRecursion )
1197 {
1198 pDataWin->bHadRecursion = false;
1199 UpdateScrollbars();
1200 }
1201}
1202
1203
1204void BrowseBox::SetUpdateMode( bool bUpdate )
1205{
1206
1207 bool bWasUpdate = IsUpdateMode();
1208 if ( bWasUpdate == bUpdate )
1209 return;
1210
1211 Control::SetUpdateMode( bUpdate );
1212 // If WB_CLIPCHILDREN is st at the BrowseBox (to minimize flicker),
1213 // the data window is not invalidated by SetUpdateMode.
1214 if( bUpdate )
1215 pDataWin->Invalidate();
1216 pDataWin->SetUpdateMode( bUpdate );
1217
1218
1219 if ( bUpdate )
1220 {
1221 if ( bBootstrapped )
1222 {
1223 UpdateScrollbars();
1224 AutoSizeLastColumn();
1225 }
1226 DoShowCursor( "SetUpdateMode" );
1227 }
1228 else
1229 DoHideCursor( "SetUpdateMode" );
1230}
1231
1232
1233bool BrowseBox::GetUpdateMode() const
1234{
1235
1236 return pDataWin->IsUpdateMode();
1237}
1238
1239
1240long BrowseBox::GetFrozenWidth() const
1241{
1242
1243 long nWidth = 0;
1244 for ( size_t nCol = 0;
1245 nCol < mvCols.size() && mvCols[ nCol ]->IsFrozen();
1246 ++nCol )
1247 nWidth += mvCols[ nCol ]->Width();
1248 return nWidth;
1249}
1250
1251
1252void BrowseBox::ColumnInserted( sal_uInt16 nPos )
1253{
1254 if ( pColSel )
1
Taking true branch
1255 pColSel->Insert( nPos );
1256 UpdateScrollbars();
2
Calling 'BrowseBox::UpdateScrollbars'
1257}
1258
1259
1260sal_uInt16 BrowseBox::FrozenColCount() const
1261{
1262 std::size_t nCol;
1263 for ( nCol = 0;
1264 nCol < mvCols.size() && mvCols[ nCol ]->IsFrozen();
1265 ++nCol )
1266 /* empty loop */;
1267 return nCol; //TODO: BrowserColumns::size_type -> sal_uInt16!
1268}
1269
1270
1271IMPL_LINK(BrowseBox, ScrollHdl, ScrollBar*, pBar, void)void BrowseBox::LinkStubScrollHdl(void * instance, ScrollBar*
data) { return static_cast<BrowseBox *>(instance)->
ScrollHdl(data); } void BrowseBox::ScrollHdl(ScrollBar* pBar)
1272{
1273 if ( pBar->GetDelta() == 0 )
1274 return;
1275
1276 if ( pBar == aHScroll.get() )
1277 ScrollColumns( aHScroll->GetDelta() );
1278 if ( pBar == pVScroll )
1279 ScrollRows( pVScroll->GetDelta() );
1280}
1281
1282
1283IMPL_LINK( BrowseBox, StartDragHdl, HeaderBar*, pBar, void )void BrowseBox::LinkStubStartDragHdl(void * instance, HeaderBar
* data) { return static_cast<BrowseBox *>(instance)->
StartDragHdl(data); } void BrowseBox::StartDragHdl(HeaderBar*
pBar)
1284{
1285 pBar->SetDragSize( pDataWin->GetOutputSizePixel().Height() );
1286}
1287
1288
1289// usually only the first column was resized
1290
1291void BrowseBox::MouseButtonDown( const MouseEvent& rEvt )
1292{
1293
1294 GrabFocus();
1295
1296 // only mouse events in the title-line are supported
1297 const Point &rEvtPos = rEvt.GetPosPixel();
1298 if ( rEvtPos.Y() >= GetTitleHeight() )
1299 return;
1300
1301 long nX = 0;
1302 long nWidth = GetOutputSizePixel().Width();
1303 for ( size_t nCol = 0; nCol < mvCols.size() && nX < nWidth; ++nCol )
1304 {
1305 // is this column visible?
1306 BrowserColumn *pCol = mvCols[ nCol ].get();
1307 if ( pCol->IsFrozen() || nCol >= nFirstCol )
1308 {
1309 // compute right end of column
1310 long nR = nX + pCol->Width() - 1;
1311
1312 // at the end of a column (and not handle column)?
1313 if ( pCol->GetId() && std::abs( nR - rEvtPos.X() ) < 2 )
1314 {
1315 // start resizing the column
1316 bResizing = true;
1317 nResizeCol = nCol;
1318 nDragX = nResizeX = rEvtPos.X();
1319 SetPointer( PointerStyle::HSplit );
1320 CaptureMouse();
1321 pDataWin->DrawLine( Point( nDragX, 0 ),
1322 Point( nDragX, pDataWin->GetSizePixel().Height() ) );
1323 nMinResizeX = nX + MIN_COLUMNWIDTH2;
1324 return;
1325 }
1326 else if ( nX < rEvtPos.X() && nR > rEvtPos.X() )
1327 {
1328 MouseButtonDown( BrowserMouseEvent(
1329 this, rEvt, -1, nCol, pCol->GetId(), tools::Rectangle() ) );
1330 return;
1331 }
1332 nX = nR + 1;
1333 }
1334 }
1335
1336 // event occurred out of data area
1337 if ( rEvt.IsRight() )
1338 pDataWin->Command(
1339 CommandEvent( Point( 1, LONG_MAX9223372036854775807L ), CommandEventId::ContextMenu, true ) );
1340 else
1341 SetNoSelection();
1342}
1343
1344
1345void BrowseBox::MouseMove( const MouseEvent& rEvt )
1346{
1347 SAL_INFO("svtools", "BrowseBox::MouseMove( MouseEvent )" )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() << "BrowseBox::MouseMove( MouseEvent )"
) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_INFO), ("svtools"
), ("/home/maarten/src/libreoffice/core/svtools/source/brwbox/brwbox2.cxx"
":" "1347" ": "), ::sal::detail::unwrapStream( ::sal::detail
::StreamStart() << "BrowseBox::MouseMove( MouseEvent )"
), 0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream
<< "BrowseBox::MouseMove( MouseEvent )"; ::sal::detail
::log( (::SAL_DETAIL_LOG_LEVEL_INFO), ("svtools"), ("/home/maarten/src/libreoffice/core/svtools/source/brwbox/brwbox2.cxx"
":" "1347" ": "), sal_detail_stream, 0); }; break; case SAL_DETAIL_LOG_ACTION_FATAL
: if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart
() << "BrowseBox::MouseMove( MouseEvent )") == 1) { ::sal_detail_log
( (::SAL_DETAIL_LOG_LEVEL_INFO), ("svtools"), ("/home/maarten/src/libreoffice/core/svtools/source/brwbox/brwbox2.cxx"
":" "1347" ": "), ::sal::detail::unwrapStream( ::sal::detail
::StreamStart() << "BrowseBox::MouseMove( MouseEvent )"
), 0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream
<< "BrowseBox::MouseMove( MouseEvent )"; ::sal::detail
::log( (::SAL_DETAIL_LOG_LEVEL_INFO), ("svtools"), ("/home/maarten/src/libreoffice/core/svtools/source/brwbox/brwbox2.cxx"
":" "1347" ": "), sal_detail_stream, 0); }; std::abort(); break
; } } } while (false)
;
1348
1349 PointerStyle aNewPointer = PointerStyle::Arrow;
1350
1351 sal_uInt16 nX = 0;
1352 for ( size_t nCol = 0;
1353 nCol < mvCols.size() &&
1354 ( nX + mvCols[ nCol ]->Width() ) < o3tl::make_unsigned(GetOutputSizePixel().Width());
1355 ++nCol )
1356 // is this column visible?
1357 if ( mvCols[ nCol ]->IsFrozen() || nCol >= nFirstCol )
1358 {
1359 // compute right end of column
1360 BrowserColumn *pCol = mvCols[ nCol ].get();
1361 sal_uInt16 nR = static_cast<sal_uInt16>(nX + pCol->Width() - 1);
1362
1363 // show resize-pointer?
1364 if ( bResizing || ( pCol->GetId() &&
1365 std::abs( static_cast<long>(nR) - rEvt.GetPosPixel().X() ) < MIN_COLUMNWIDTH2 ) )
1366 {
1367 aNewPointer = PointerStyle::HSplit;
1368 if ( bResizing )
1369 {
1370 // delete old auxiliary line
1371 pDataWin->HideTracking() ;
1372
1373 // check allowed width and new delta
1374 nDragX = std::max( rEvt.GetPosPixel().X(), nMinResizeX );
1375 long nDeltaX = nDragX - nResizeX;
1376 sal_uInt16 nId = GetColumnId(nResizeCol);
1377 sal_uLong nOldWidth = GetColumnWidth(nId);
1378 nDragX = nOldWidth + nDeltaX + nResizeX - nOldWidth;
1379
1380 // draw new auxiliary line
1381 pDataWin->ShowTracking( tools::Rectangle( Point( nDragX, 0 ),
1382 Size( 1, pDataWin->GetSizePixel().Height() ) ),
1383 ShowTrackFlags::Split|ShowTrackFlags::TrackWindow );
1384 }
1385
1386 }
1387
1388 nX = nR + 1;
1389 }
1390
1391 SetPointer( aNewPointer );
1392}
1393
1394
1395void BrowseBox::MouseButtonUp( const MouseEvent & rEvt )
1396{
1397
1398 if ( bResizing )
1399 {
1400 // delete auxiliary line
1401 pDataWin->HideTracking();
1402
1403 // width changed?
1404 nDragX = std::max( rEvt.GetPosPixel().X(), nMinResizeX );
1405 if ( (nDragX - nResizeX) != static_cast<long>(mvCols[ nResizeCol ]->Width()) )
1406 {
1407 // resize column
1408 long nMaxX = pDataWin->GetSizePixel().Width();
1409 nDragX = std::min( nDragX, nMaxX );
1410 long nDeltaX = nDragX - nResizeX;
1411 sal_uInt16 nId = GetColumnId(nResizeCol);
1412 SetColumnWidth( GetColumnId(nResizeCol), GetColumnWidth(nId) + nDeltaX );
1413 ColumnResized( nId );
1414 }
1415
1416 // end action
1417 SetPointer( PointerStyle::Arrow );
1418 ReleaseMouse();
1419 bResizing = false;
1420 }
1421 else
1422 MouseButtonUp( BrowserMouseEvent( pDataWin,
1423 MouseEvent( Point( rEvt.GetPosPixel().X(),
1424 rEvt.GetPosPixel().Y() - pDataWin->GetPosPixel().Y() ),
1425 rEvt.GetClicks(), rEvt.GetMode(), rEvt.GetButtons(),
1426 rEvt.GetModifier() ) ) );
1427}
1428
1429
1430static bool bExtendedMode = false;
1431static bool bFieldMode = false;
1432
1433void BrowseBox::MouseButtonDown( const BrowserMouseEvent& rEvt )
1434{
1435
1436 GrabFocus();
1437
1438 // adjust selection while and after double-click
1439 if ( rEvt.GetClicks() == 2 )
1440 {
1441 SetNoSelection();
1442 if ( rEvt.GetRow() >= 0 )
1443 {
1444 GoToRow( rEvt.GetRow() );
1445 SelectRow( rEvt.GetRow(), true, false );
1446 }
1447 else
1448 {
1449 if ( bColumnCursor && rEvt.GetColumn() != 0 )
1450 {
1451 if ( rEvt.GetColumn() < mvCols.size() )
1452 SelectColumnPos( rEvt.GetColumn(), true, false);
1453 }
1454 }
1455 DoubleClick( rEvt );
1456 }
1457 // selections
1458 else if ( ( rEvt.GetMode() & ( MouseEventModifiers::SELECT | MouseEventModifiers::SIMPLECLICK ) ) &&
1459 ( bColumnCursor || rEvt.GetRow() >= 0 ) )
1460 {
1461 if ( rEvt.GetClicks() == 1 )
1462 {
1463 // initialise flags
1464 bHit = false;
1465
1466 // selection out of range?
1467 if ( rEvt.GetRow() >= nRowCount ||
1468 rEvt.GetColumnId() == BROWSER_INVALIDID((sal_uInt16) 0xFFFF) )
1469 {
1470 SetNoSelection();
1471 return;
1472 }
1473
1474 // while selecting, no cursor
1475 bSelecting = true;
1476 DoHideCursor( "MouseButtonDown" );
1477
1478 // DataRow?
1479 if ( rEvt.GetRow() >= 0 )
1480 {
1481 // line selection?
1482 if ( rEvt.GetColumnId() == HandleColumnId || !bColumnCursor )
1483 {
1484 if ( bMultiSelection )
1485 {
1486 // remove column-selection, if exists
1487 if ( pColSel && pColSel->GetSelectCount() )
1488 {
1489 ToggleSelection();
1490 if ( bMultiSelection )
1491 uRow.pSel->SelectAll(false);
1492 else
1493 uRow.nSel = BROWSER_ENDOFSELECTION(static_cast<long>((-1)));
1494 if ( pColSel )
1495 pColSel->SelectAll(false);
1496 bSelect = true;
1497 }
1498
1499 // expanding mode?
1500 if ( rEvt.GetMode() & MouseEventModifiers::RANGESELECT )
1501 {
1502 // select the further touched rows too
1503 bSelect = true;
1504 ExpandRowSelection( rEvt );
1505 return;
1506 }
1507
1508 // click in the selected area?
1509 else if ( IsRowSelected( rEvt.GetRow() ) )
1510 {
1511 // wait for Drag&Drop
1512 bHit = true;
1513 bExtendedMode = bool( rEvt.GetMode() & MouseEventModifiers::MULTISELECT );
1514 return;
1515 }
1516
1517 // extension mode?
1518 else if ( rEvt.GetMode() & MouseEventModifiers::MULTISELECT )
1519 {
1520 // determine the new selection range
1521 // and selection/deselection
1522 aSelRange = Range( rEvt.GetRow(), rEvt.GetRow() );
1523 SelectRow( rEvt.GetRow(),
1524 !uRow.pSel->IsSelected( rEvt.GetRow() ) );
1525 bSelect = true;
1526 return;
1527 }
1528 }
1529
1530 // select directly
1531 SetNoSelection();
1532 GoToRow( rEvt.GetRow() );
1533 SelectRow( rEvt.GetRow() );
1534 aSelRange = Range( rEvt.GetRow(), rEvt.GetRow() );
1535 bSelect = true;
1536 }
1537 else // Column/Field-Selection
1538 {
1539 // click in selected column
1540 if ( IsColumnSelected( rEvt.GetColumn() ) ||
1541 IsRowSelected( rEvt.GetRow() ) )
1542 {
1543 bHit = true;
1544 bFieldMode = true;
1545 return;
1546 }
1547
1548 SetNoSelection();
1549 GoToRowColumnId( rEvt.GetRow(), rEvt.GetColumnId() );
1550 bSelect = true;
1551 }
1552 }
1553 else
1554 {
1555 if ( bMultiSelection && rEvt.GetColumnId() == HandleColumnId )
1556 {
1557 // toggle all-selection
1558 if ( uRow.pSel->GetSelectCount() > ( GetRowCount() / 2 ) )
1559 SetNoSelection();
1560 else
1561 SelectAll();
1562 }
1563 else
1564 SelectColumnPos( GetColumnPos(rEvt.GetColumnId()), true, false);
1565 }
1566
1567 // turn cursor on again, if necessary
1568 bSelecting = false;
1569 DoShowCursor( "MouseButtonDown" );
1570 if ( bSelect )
1571 Select();
1572 }
1573 }
1574}
1575
1576
1577void BrowseBox::MouseButtonUp( const BrowserMouseEvent &rEvt )
1578{
1579
1580 // D&D was possible, but did not occur
1581 if ( bHit )
1582 {
1583 aSelRange = Range( rEvt.GetRow(), rEvt.GetRow() );
1584 if ( bExtendedMode )
1585 SelectRow( rEvt.GetRow(), false );
1586 else
1587 {
1588 SetNoSelection();
1589 if ( bFieldMode )
1590 GoToRowColumnId( rEvt.GetRow(), rEvt.GetColumnId() );
1591 else
1592 {
1593 GoToRow( rEvt.GetRow() );
1594 SelectRow( rEvt.GetRow() );
1595 }
1596 }
1597 bSelect = true;
1598 bExtendedMode = false;
1599 bFieldMode = false;
1600 bHit = false;
1601 }
1602
1603 // activate cursor
1604 if ( bSelecting )
1605 {
1606 bSelecting = false;
1607 DoShowCursor( "MouseButtonUp" );
1608 if ( bSelect )
1609 Select();
1610 }
1611}
1612
1613
1614void BrowseBox::KeyInput( const KeyEvent& rEvt )
1615{
1616 if ( !ProcessKey( rEvt ) )
1617 Control::KeyInput( rEvt );
1618}
1619
1620
1621bool BrowseBox::ProcessKey( const KeyEvent& rEvt )
1622{
1623
1624 sal_uInt16 nCode = rEvt.GetKeyCode().GetCode();
1625 bool bShift = rEvt.GetKeyCode().IsShift();
1626 bool bCtrl = rEvt.GetKeyCode().IsMod1();
1627 bool bAlt = rEvt.GetKeyCode().IsMod2();
1628
1629 sal_uInt16 nId = BROWSER_NONE0;
1630
1631 if ( !bAlt && !bCtrl && !bShift )
1632 {
1633 switch ( nCode )
1634 {
1635 case KEY_DOWN: nId = BROWSER_CURSORDOWN731; break;
1636 case KEY_UP: nId = BROWSER_CURSORUP732; break;
1637 case KEY_HOME: nId = BROWSER_CURSORHOME745; break;
1638 case KEY_END: nId = BROWSER_CURSOREND746; break;
1639 case KEY_TAB:
1640 if ( !bColumnCursor )
1641 break;
1642 [[fallthrough]];
1643 case KEY_RIGHT: nId = BROWSER_CURSORRIGHT734; break;
1644 case KEY_LEFT: nId = BROWSER_CURSORLEFT733; break;
1645 case KEY_SPACE: nId = BROWSER_SELECT720; break;
1646 }
1647 if ( BROWSER_NONE0 != nId )
1648 SetNoSelection();
1649
1650 switch ( nCode )
1651 {
1652 case KEY_PAGEDOWN: nId = BROWSER_CURSORPAGEDOWN735; break;
1653 case KEY_PAGEUP: nId = BROWSER_CURSORPAGEUP736; break;
1654 }
1655 }
1656
1657 if ( !bAlt && !bCtrl && bShift )
1658 switch ( nCode )
1659 {
1660 case KEY_DOWN: nId = BROWSER_SELECTDOWN724; break;
1661 case KEY_UP: nId = BROWSER_SELECTUP725; break;
1662 case KEY_TAB:
1663 if ( !bColumnCursor )
1664 break;
1665 nId = BROWSER_CURSORLEFT733; break;
1666 case KEY_HOME: nId = BROWSER_SELECTHOME753; break;
1667 case KEY_END: nId = BROWSER_SELECTEND754; break;
1668 }
1669
1670
1671 if ( !bAlt && bCtrl && !bShift )
1672 switch ( nCode )
1673 {
1674 case KEY_DOWN: nId = BROWSER_CURSORDOWN731; break;
1675 case KEY_UP: nId = BROWSER_CURSORUP732; break;
1676 case KEY_PAGEDOWN: nId = BROWSER_CURSORENDOFFILE741; break;
1677 case KEY_PAGEUP: nId = BROWSER_CURSORTOPOFFILE742; break;
1678 case KEY_HOME: nId = BROWSER_CURSORTOPOFSCREEN744; break;
1679 case KEY_END: nId = BROWSER_CURSORENDOFSCREEN743; break;
1680 case KEY_SPACE: nId = BROWSER_ENHANCESELECTION722; break;
1681 case KEY_LEFT: nId = BROWSER_MOVECOLUMNLEFT756; break;
1682 case KEY_RIGHT: nId = BROWSER_MOVECOLUMNRIGHT757; break;
1683 }
1684
1685 if ( nId != BROWSER_NONE0 )
1686 Dispatch( nId );
1687 return nId != BROWSER_NONE0;
1688}
1689
1690
1691void BrowseBox::Dispatch( sal_uInt16 nId )
1692{
1693
1694 long nRowsOnPage = pDataWin->GetSizePixel().Height() / GetDataRowHeight();
1695
1696 switch ( nId )
1697 {
1698 case BROWSER_SELECTCOLUMN755:
1699 if ( ColCount() )
1700 SelectColumnId( GetCurColumnId() );
1701 break;
1702
1703 case BROWSER_CURSORDOWN731:
1704 if ( ( GetCurRow() + 1 ) < nRowCount )
1705 GoToRow( GetCurRow() + 1, false );
1706 break;
1707 case BROWSER_CURSORUP732:
1708 if ( GetCurRow() > 0 )
1709 GoToRow( GetCurRow() - 1, false );
1710 break;
1711 case BROWSER_SELECTHOME753:
1712 if ( GetRowCount() )
1713 {
1714 DoHideCursor( "BROWSER_SELECTHOME" );
1715 for ( long nRow = GetCurRow(); nRow >= 0; --nRow )
1716 SelectRow( nRow );
1717 GoToRow( 0, true );
1718 DoShowCursor( "BROWSER_SELECTHOME" );
1719 }
1720 break;
1721 case BROWSER_SELECTEND754:
1722 if ( GetRowCount() )
1723 {
1724 DoHideCursor( "BROWSER_SELECTEND" );
1725 long nRows = GetRowCount();
1726 for ( long nRow = GetCurRow(); nRow < nRows; ++nRow )
1727 SelectRow( nRow );
1728 GoToRow( GetRowCount() - 1, true );
1729 DoShowCursor( "BROWSER_SELECTEND" );
1730 }
1731 break;
1732 case BROWSER_SELECTDOWN724:
1733 {
1734 if ( GetRowCount() && ( GetCurRow() + 1 ) < nRowCount )
1735 {
1736 // deselect the current row, if it isn't the first
1737 // and there is no other selected row above
1738 long nRow = GetCurRow();
1739 bool bLocalSelect = ( !IsRowSelected( nRow ) ||
1740 GetSelectRowCount() == 1 || IsRowSelected( nRow - 1 ) );
1741 SelectRow( nRow, bLocalSelect );
1742 bool bDone = GoToRow( GetCurRow() + 1, false );
1743 if ( bDone )
1744 SelectRow( GetCurRow() );
1745 }
1746 else
1747 ScrollRows( 1 );
1748 break;
1749 }
1750 case BROWSER_SELECTUP725:
1751 if ( GetRowCount() )
1752 {
1753 // deselect the current row, if it isn't the first
1754 // and there is no other selected row under
1755 long nRow = GetCurRow();
1756 bool bLocalSelect = ( !IsRowSelected( nRow ) ||
1757 GetSelectRowCount() == 1 || IsRowSelected( nRow + 1 ) );
1758 SelectRow( nCurRow, bLocalSelect );
1759 bool bDone = GoToRow( nRow - 1, false );
1760 if ( bDone )
1761 SelectRow( GetCurRow() );
1762 }
1763 break;
1764 case BROWSER_CURSORPAGEDOWN735:
1765 ScrollRows( nRowsOnPage );
1766 break;
1767 case BROWSER_CURSORPAGEUP736:
1768 ScrollRows( -nRowsOnPage );
1769 break;
1770 case BROWSER_CURSOREND746:
1771 if ( bColumnCursor )
1772 {
1773 sal_uInt16 nNewId = GetColumnId(ColCount() -1);
1774 nNewId != HandleColumnId && GoToColumnId( nNewId );
1775 break;
1776 }
1777 [[fallthrough]];
1778 case BROWSER_CURSORENDOFFILE741:
1779 GoToRow( nRowCount - 1, false );
1780 break;
1781 case BROWSER_CURSORRIGHT734:
1782 if ( bColumnCursor )
1783 {
1784 sal_uInt16 nNewPos = GetColumnPos( GetCurColumnId() ) + 1;
1785 sal_uInt16 nNewId = GetColumnId( nNewPos );
1786 if (nNewId != BROWSER_INVALIDID((sal_uInt16) 0xFFFF)) // At end of row ?
1787 GoToColumnId( nNewId );
1788 else
1789 {
1790 sal_uInt16 nColId = GetColumnId(0);
1791 if ( nColId == BROWSER_INVALIDID((sal_uInt16) 0xFFFF) || nColId == HandleColumnId )
1792 nColId = GetColumnId(1);
1793 if ( GetRowCount() )
1794 {
1795 if ( nCurRow < GetRowCount() - 1 )
1796 {
1797 GoToRowColumnId( nCurRow + 1, nColId );
1798 }
1799 }
1800 else if ( ColCount() )
1801 GoToColumnId( nColId );
1802 }
1803 }
1804 else
1805 ScrollColumns( 1 );
1806 break;
1807 case BROWSER_CURSORHOME745:
1808 if ( bColumnCursor )
1809 {
1810 sal_uInt16 nNewId = GetColumnId(1);
1811 if (nNewId != HandleColumnId)
1812 {
1813 GoToColumnId( nNewId );
1814 }
1815 break;
1816 }
1817 [[fallthrough]];
1818 case BROWSER_CURSORTOPOFFILE742:
1819 GoToRow( 0, false );
1820 break;
1821 case BROWSER_CURSORLEFT733:
1822 if ( bColumnCursor )
1823 {
1824 sal_uInt16 nNewPos = GetColumnPos( GetCurColumnId() ) - 1;
1825 sal_uInt16 nNewId = GetColumnId( nNewPos );
1826 if (nNewId != HandleColumnId)
1827 GoToColumnId( nNewId );
1828 else
1829 {
1830 if ( GetRowCount() )
1831 {
1832 if (nCurRow > 0)
1833 {
1834 GoToRowColumnId(nCurRow - 1, GetColumnId(ColCount() -1));
1835 }
1836 }
1837 else if ( ColCount() )
1838 GoToColumnId( GetColumnId(ColCount() -1) );
1839 }
1840 }
1841 else
1842 ScrollColumns( -1 );
1843 break;
1844 case BROWSER_ENHANCESELECTION722:
1845 if ( GetRowCount() )
1846 SelectRow( GetCurRow(), !IsRowSelected( GetCurRow() ) );
1847 break;
1848 case BROWSER_SELECT720:
1849 if ( GetRowCount() )
1850 SelectRow( GetCurRow(), !IsRowSelected( GetCurRow() ), false );
1851 break;
1852 case BROWSER_MOVECOLUMNLEFT756:
1853 case BROWSER_MOVECOLUMNRIGHT757:
1854 { // check if column moving is allowed
1855 BrowserHeader* pHeaderBar = pDataWin->pHeaderBar;
1856 if ( pHeaderBar && pHeaderBar->IsDragable() )
1857 {
1858 sal_uInt16 nColId = GetCurColumnId();
1859 bool bColumnSelected = IsColumnSelected(nColId);
1860 sal_uInt16 nNewPos = GetColumnPos(nColId);
1861 bool bMoveAllowed = false;
1862 if ( BROWSER_MOVECOLUMNLEFT756 == nId && nNewPos > 1 )
1863 {
1864 --nNewPos;
1865 bMoveAllowed = true;
1866 }
1867 else if ( BROWSER_MOVECOLUMNRIGHT757 == nId && nNewPos < (ColCount()-1) )
1868 {
1869 ++nNewPos;
1870 bMoveAllowed = true;
1871 }
1872
1873 if ( bMoveAllowed )
1874 {
1875 SetColumnPos( nColId, nNewPos );
1876 ColumnMoved( nColId );
1877 MakeFieldVisible(GetCurRow(), nColId);
1878 if ( bColumnSelected )
1879 SelectColumnId(nColId);
1880 }
1881 }
1882 }
1883 break;
1884 }
1885}
1886
1887
1888void BrowseBox::SetCursorColor(const Color& _rCol)
1889{
1890 if (_rCol == m_aCursorColor)
1891 return;
1892
1893 // ensure the cursor is hidden
1894 DoHideCursor("SetCursorColor");
1895 if (!m_bFocusOnlyCursor)
1896 DoHideCursor("SetCursorColor - force");
1897
1898 m_aCursorColor = _rCol;
1899
1900 if (!m_bFocusOnlyCursor)
1901 DoShowCursor("SetCursorColor - force");
1902 DoShowCursor("SetCursorColor");
1903}
1904
1905tools::Rectangle BrowseBox::calcHeaderRect(bool _bIsColumnBar, bool _bOnScreen)
1906{
1907 vcl::Window* pParent = nullptr;
1908 if ( !_bOnScreen )
1909 pParent = GetAccessibleParentWindow();
1910
1911 Point aTopLeft;
1912 long nWidth;
1913 long nHeight;
1914 if ( _bIsColumnBar )
1915 {
1916 nWidth = pDataWin->GetOutputSizePixel().Width();
1917 nHeight = GetDataRowHeight();
1918 }
1919 else
1920 {
1921 aTopLeft.setY( GetDataRowHeight() );
1922 nWidth = GetColumnWidth(0);
1923 nHeight = GetWindowExtentsRelative( pParent ).GetHeight() - aTopLeft.Y() - GetControlArea().GetSize().Height();
1924 }
1925 aTopLeft += GetWindowExtentsRelative( pParent ).TopLeft();
1926 return tools::Rectangle(aTopLeft,Size(nWidth,nHeight));
1927}
1928
1929tools::Rectangle BrowseBox::calcTableRect(bool _bOnScreen)
1930{
1931 vcl::Window* pParent = nullptr;
1932 if ( !_bOnScreen )
1933 pParent = GetAccessibleParentWindow();
1934
1935 tools::Rectangle aRect( GetWindowExtentsRelative( pParent ) );
1936 tools::Rectangle aRowBar = calcHeaderRect(false, pParent == nullptr);
1937
1938 long nX = aRowBar.Right() - aRect.Left();
1939 long nY = aRowBar.Top() - aRect.Top();
1940 Size aSize(aRect.GetSize());
1941
1942 return tools::Rectangle(aRowBar.TopRight(), Size(aSize.Width() - nX, aSize.Height() - nY - GetBarHeight()) );
1943}
1944
1945tools::Rectangle BrowseBox::GetFieldRectPixelAbs( sal_Int32 _nRowId, sal_uInt16 _nColId, bool /*_bIsHeader*/, bool _bOnScreen )
1946{
1947 vcl::Window* pParent = nullptr;
1948 if ( !_bOnScreen )
1949 pParent = GetAccessibleParentWindow();
1950
1951 tools::Rectangle aRect = GetFieldRectPixel(_nRowId,_nColId,_bOnScreen);
1952
1953 Point aTopLeft = aRect.TopLeft();
1954 aTopLeft += GetWindowExtentsRelative( pParent ).TopLeft();
1955
1956 return tools::Rectangle(aTopLeft,aRect.GetSize());
1957}
1958
1959// ------------------------------------------------------------------------- EOF
1960
1961/* vim:set shiftwidth=4 softtabstop=4 expandtab: */

/home/maarten/src/libreoffice/core/include/vcl/vclptr.hxx

1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 */
19
20#ifndef INCLUDED_VCL_PTR_HXX
21#define INCLUDED_VCL_PTR_HXX
22
23#include <sal/config.h>
24
25#include <rtl/ref.hxx>
26
27#include <utility>
28#include <type_traits>
29
30#ifdef DBG_UTIL
31#ifndef _WIN32
32#include <vcl/vclmain.hxx>
33#endif
34#endif
35
36class VclReferenceBase;
37
38namespace vcl::detail {
39
40template<typename>
41constexpr bool isIncompleteOrDerivedFromVclReferenceBase(...) { return true; }
42
43template<typename T> constexpr bool isIncompleteOrDerivedFromVclReferenceBase(
44 int (*)[sizeof(T)])
45{ return std::is_base_of<VclReferenceBase, T>::value; }
46
47} // namespace vcl::detail
48
49/**
50 * A thin wrapper around rtl::Reference to implement the acquire and dispose semantics we want for references to vcl::Window subclasses.
51 *
52 * For more details on the design please see vcl/README.lifecycle
53 *
54 * @param reference_type must be a subclass of vcl::Window
55 */
56template <class reference_type>
57class VclPtr
58{
59 static_assert(
60 vcl::detail::isIncompleteOrDerivedFromVclReferenceBase<reference_type>(
61 nullptr),
62 "template argument type must be derived from VclReferenceBase");
63
64 ::rtl::Reference<reference_type> m_rInnerRef;
65
66public:
67 /** Constructor...
68 */
69 VclPtr()
70 : m_rInnerRef()
71 {}
72
73 /** Constructor...
74 */
75 VclPtr (reference_type * pBody)
76 : m_rInnerRef(pBody)
77 {}
78
79 /** Constructor... that doesn't take a ref.
80 */
81 VclPtr (reference_type * pBody, __sal_NoAcquire)
82 : m_rInnerRef(pBody, SAL_NO_ACQUIRE)
83 {}
84
85 /** Up-casting conversion constructor: Copies interface reference.
86
87 Does not work for up-casts to ambiguous bases. For the special case of
88 up-casting to Reference< XInterface >, see the corresponding conversion
89 operator.
90
91 @param rRef another reference
92 */
93 template< class derived_type >
94 VclPtr(
95 const VclPtr< derived_type > & rRef,
96 typename std::enable_if<
97 std::is_base_of<reference_type, derived_type>::value, int>::type
98 = 0 )
99 : m_rInnerRef( static_cast<reference_type*>(rRef) )
100 {
101 }
102
103#if defined(DBG_UTIL) && !defined(_WIN32)
104 virtual ~VclPtr()
105 {
106 assert(m_rInnerRef.get() == nullptr || vclmain::isAlive())(static_cast <bool> (m_rInnerRef.get() == nullptr || vclmain
::isAlive()) ? void (0) : __assert_fail ("m_rInnerRef.get() == nullptr || vclmain::isAlive()"
, "/home/maarten/src/libreoffice/core/include/vcl/vclptr.hxx"
, 106, __extension__ __PRETTY_FUNCTION__))
;
107 // We can be one of the intermediate counts, but if we are the last
108 // VclPtr keeping this object alive, then something forgot to call dispose().
109 assert((!m_rInnerRef.get() || m_rInnerRef->isDisposed() || m_rInnerRef->getRefCount() > 1)(static_cast <bool> ((!m_rInnerRef.get() || m_rInnerRef
->isDisposed() || m_rInnerRef->getRefCount() > 1) &&
"someone forgot to call dispose()") ? void (0) : __assert_fail
("(!m_rInnerRef.get() || m_rInnerRef->isDisposed() || m_rInnerRef->getRefCount() > 1) && \"someone forgot to call dispose()\""
, "/home/maarten/src/libreoffice/core/include/vcl/vclptr.hxx"
, 110, __extension__ __PRETTY_FUNCTION__))
110 && "someone forgot to call dispose()")(static_cast <bool> ((!m_rInnerRef.get() || m_rInnerRef
->isDisposed() || m_rInnerRef->getRefCount() > 1) &&
"someone forgot to call dispose()") ? void (0) : __assert_fail
("(!m_rInnerRef.get() || m_rInnerRef->isDisposed() || m_rInnerRef->getRefCount() > 1) && \"someone forgot to call dispose()\""
, "/home/maarten/src/libreoffice/core/include/vcl/vclptr.hxx"
, 110, __extension__ __PRETTY_FUNCTION__))
;
111 }
112 VclPtr(VclPtr const &) = default;
113 VclPtr(VclPtr &&) = default;
114 VclPtr & operator =(VclPtr const &) = default;
115 VclPtr & operator =(VclPtr &&) = default;
116#endif
117
118 /**
119 * A construction helper for VclPtr. Since VclPtr types are created
120 * with a reference-count of one - to help fit into the existing
121 * code-flow; this helps us to construct them easily.
122 *
123 * For more details on the design please see vcl/README.lifecycle
124 *
125 * @tparam reference_type must be a subclass of vcl::Window
126 */
127 template<typename... Arg> [[nodiscard]] static VclPtr< reference_type > Create(Arg &&... arg)
128 {
129 return VclPtr< reference_type >( new reference_type(std::forward<Arg>(arg)...), SAL_NO_ACQUIRE );
130 }
131
132 /** Probably most common used: handle->someBodyOp().
133 */
134 reference_type * operator->() const
135 {
136 return m_rInnerRef.get();
137 }
138
139 /** Get the body. Can be used instead of operator->().
140 I.e. handle->someBodyOp() and handle.get()->someBodyOp()
141 are the same.
142 */
143 reference_type * get() const
144 {
145 return m_rInnerRef.get();
146 }
147
148 void set(reference_type *pBody)
149 {
150 m_rInnerRef.set(pBody);
151 }
152
153 void reset(reference_type *pBody)
154 {
155 m_rInnerRef.set(pBody);
156 }
157
158 /** Up-casting copy assignment operator.
159
160 Does not work for up-casts to ambiguous bases.
161
162 @param rRef another reference
163 */
164 template<typename derived_type>
165 typename std::enable_if<
166 std::is_base_of<reference_type, derived_type>::value,
167 VclPtr &>::type
168 operator =(VclPtr<derived_type> const & rRef)
169 {
170 m_rInnerRef.set(rRef.get());
171 return *this;
172 }
173
174 VclPtr & operator =(reference_type * pBody)
175 {
176 m_rInnerRef.set(pBody);
177 return *this;
178 }
179
180 operator reference_type * () const
181 {
182 return m_rInnerRef.get();
183 }
184
185 explicit operator bool () const
186 {
187 return m_rInnerRef.get() != nullptr;
188 }
189
190 void clear()
191 {
192 m_rInnerRef.clear();
193 }
194
195 void reset()
196 {
197 m_rInnerRef.clear();
198 }
199
200 void disposeAndClear()
201 {
202 // hold it alive for the lifetime of this method
203 ::rtl::Reference<reference_type> aTmp(m_rInnerRef);
37
Calling copy constructor for 'Reference<ScrollBarBox>'
40
Returning from copy constructor for 'Reference<ScrollBarBox>'
204 m_rInnerRef.clear(); // we should use some 'swap' method ideally ;-)
41
Calling 'Reference::clear'
48
Returning; memory was released
205 if (aTmp.get()) {
49
Calling 'Reference::get'
206 aTmp->disposeOnce();
207 }
208 }
209
210 /** Needed to place VclPtr's into STL collection.
211 */
212 bool operator< (const VclPtr<reference_type> & handle) const
213 {
214 return (m_rInnerRef < handle.m_rInnerRef);
215 }
216}; // class VclPtr
217
218template<typename T1, typename T2>
219inline bool operator ==(VclPtr<T1> const & p1, VclPtr<T2> const & p2) {
220 return p1.get() == p2.get();
221}
222
223template<typename T> inline bool operator ==(VclPtr<T> const & p1, T const * p2)
224{
225 return p1.get() == p2;
226}
227
228template<typename T> inline bool operator ==(VclPtr<T> const & p1, T * p2) {
229 return p1.get() == p2;
230}
231
232template<typename T> inline bool operator ==(T const * p1, VclPtr<T> const & p2)
233{
234 return p1 == p2.get();
235}
236
237template<typename T> inline bool operator ==(T * p1, VclPtr<T> const & p2) {
238 return p1 == p2.get();
239}
240
241template<typename T1, typename T2>
242inline bool operator !=(VclPtr<T1> const & p1, VclPtr<T2> const & p2) {
243 return !(p1 == p2);
244}
245
246template<typename T> inline bool operator !=(VclPtr<T> const & p1, T const * p2)
247{
248 return !(p1 == p2);
249}
250
251template<typename T> inline bool operator !=(VclPtr<T> const & p1, T * p2) {
252 return !(p1 == p2);
253}
254
255template<typename T> inline bool operator !=(T const * p1, VclPtr<T> const & p2)
256{
257 return !(p1 == p2);
258}
259
260template<typename T> inline bool operator !=(T * p1, VclPtr<T> const & p2) {
261 return !(p1 == p2);
262}
263
264/**
265 * A construction helper for a temporary VclPtr. Since VclPtr types
266 * are created with a reference-count of one - to help fit into
267 * the existing code-flow; this helps us to construct them easily.
268 * see also VclPtr::Create and ScopedVclPtr
269 *
270 * For more details on the design please see vcl/README.lifecycle
271 *
272 * @param reference_type must be a subclass of vcl::Window
273 */
274template <class reference_type>
275class SAL_WARN_UNUSED__attribute__((warn_unused)) VclPtrInstance final : public VclPtr<reference_type>
276{
277public:
278 template<typename... Arg> VclPtrInstance(Arg &&... arg)
279 : VclPtr<reference_type>( new reference_type(std::forward<Arg>(arg)...), SAL_NO_ACQUIRE )
280 {
281 }
282
283 /**
284 * Override and disallow this, to prevent people accidentally calling it and actually
285 * getting VclPtr::Create and getting a naked VclPtr<> instance
286 */
287 template<typename... Arg> static VclPtrInstance< reference_type > Create(Arg &&... ) = delete;
288};
289
290template <class reference_type>
291class ScopedVclPtr : public VclPtr<reference_type>
292{
293public:
294 /** Constructor...
295 */
296 ScopedVclPtr()
297 : VclPtr<reference_type>()
298 {}
299
300 /** Constructor
301 */
302 ScopedVclPtr (reference_type * pBody)
303 : VclPtr<reference_type>(pBody)
304 {}
305
306 /** Copy constructor...
307 */
308 ScopedVclPtr (const VclPtr<reference_type> & handle)
309 : VclPtr<reference_type>(handle)
310 {}
311
312 /**
313 Assignment that releases the last reference.
314 */
315 void disposeAndReset(reference_type *pBody)
316 {
317 if (pBody != this->get()) {
318 VclPtr<reference_type>::disposeAndClear();
319 VclPtr<reference_type>::set(pBody);
320 }
321 }
322
323 /**
324 Assignment that releases the last reference.
325 */
326 ScopedVclPtr<reference_type>& operator = (reference_type * pBody)
327 {
328 disposeAndReset(pBody);
329 return *this;
330 }
331
332 /** Up-casting conversion constructor: Copies interface reference.
333
334 Does not work for up-casts to ambiguous bases. For the special case of
335 up-casting to Reference< XInterface >, see the corresponding conversion
336 operator.
337
338 @param rRef another reference
339 */
340 template< class derived_type >
341 ScopedVclPtr(
342 const VclPtr< derived_type > & rRef,
343 typename std::enable_if<
344 std::is_base_of<reference_type, derived_type>::value, int>::type
345 = 0 )
346 : VclPtr<reference_type>( rRef )
347 {
348 }
349
350 /** Up-casting assignment operator.
351
352 Does not work for up-casts to ambiguous bases.
353
354 @param rRef another VclPtr
355 */
356 template<typename derived_type>
357 typename std::enable_if<
358 std::is_base_of<reference_type, derived_type>::value,
359 ScopedVclPtr &>::type
360 operator =(VclPtr<derived_type> const & rRef)
361 {
362 disposeAndReset(rRef.get());
363 return *this;
364 }
365
366 /**
367 * Override and disallow this, to prevent people accidentally calling it and actually
368 * getting VclPtr::Create and getting a naked VclPtr<> instance
369 */
370 template<typename... Arg> static ScopedVclPtr< reference_type > Create(Arg &&... ) = delete;
371
372 ~ScopedVclPtr()
373 {
374 VclPtr<reference_type>::disposeAndClear();
375 assert(VclPtr<reference_type>::get() == nullptr)(static_cast <bool> (VclPtr<reference_type>::get(
) == nullptr) ? void (0) : __assert_fail ("VclPtr<reference_type>::get() == nullptr"
, "/home/maarten/src/libreoffice/core/include/vcl/vclptr.hxx"
, 375, __extension__ __PRETTY_FUNCTION__))
; // make sure there are no lingering references
376 }
377
378private:
379 // Most likely we don't want this default copy-constructor.
380 ScopedVclPtr (const ScopedVclPtr<reference_type> &) = delete;
381 // And certainly we don't want a default assignment operator.
382 ScopedVclPtr<reference_type>& operator = (const ScopedVclPtr<reference_type> &) = delete;
383 // And disallow reset as that doesn't call disposeAndClear on the original reference
384 void reset() = delete;
385 void reset(reference_type *pBody) = delete;
386
387protected:
388 ScopedVclPtr (reference_type * pBody, __sal_NoAcquire)
389 : VclPtr<reference_type>(pBody, SAL_NO_ACQUIRE)
390 {}
391};
392
393/**
394 * A construction helper for ScopedVclPtr. Since VclPtr types are created
395 * with a reference-count of one - to help fit into the existing
396 * code-flow; this helps us to construct them easily.
397 *
398 * For more details on the design please see vcl/README.lifecycle
399 *
400 * @param reference_type must be a subclass of vcl::Window
401 */
402#if defined _MSC_VER
403#pragma warning(push)
404#pragma warning(disable: 4521) // " multiple copy constructors specified"
405#endif
406template <class reference_type>
407class SAL_WARN_UNUSED__attribute__((warn_unused)) ScopedVclPtrInstance final : public ScopedVclPtr<reference_type>
408{
409public:
410 template<typename... Arg> ScopedVclPtrInstance(Arg &&... arg)
411 : ScopedVclPtr<reference_type>( new reference_type(std::forward<Arg>(arg)...), SAL_NO_ACQUIRE )
412 {
413 }
414
415 /**
416 * Override and disallow this, to prevent people accidentally calling it and actually
417 * getting VclPtr::Create and getting a naked VclPtr<> instance
418 */
419 template<typename... Arg> static ScopedVclPtrInstance< reference_type > Create(Arg &&...) = delete;
420
421private:
422 // Prevent the above perfect forwarding ctor from hijacking (accidental)
423 // attempts at ScopedVclPtrInstance copy construction (where the hijacking
424 // would typically lead to somewhat obscure error messages); both non-const
425 // and const variants are needed here, as the ScopedVclPtr base class has a
426 // const--variant copy ctor, so the implicitly declared copy ctor for
427 // ScopedVclPtrInstance would also be the const variant, so non-const copy
428 // construction attempts would be hijacked by the perfect forwarding ctor;
429 // but if we only declared a non-const variant here, the const variant would
430 // no longer be implicitly declared (as there would already be an explicitly
431 // declared copy ctor), so const copy construction attempts would then be
432 // hijacked by the perfect forwarding ctor:
433 ScopedVclPtrInstance(ScopedVclPtrInstance &) = delete;
434 ScopedVclPtrInstance(ScopedVclPtrInstance const &) = delete;
435};
436#if defined _MSC_VER
437#pragma warning(pop)
438#endif
439
440#endif // INCLUDED_VCL_PTR_HXX
441
442/* vim:set shiftwidth=4 softtabstop=4 expandtab: */

/home/maarten/src/libreoffice/core/include/rtl/ref.hxx

1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 */
19
20#ifndef INCLUDED_RTL_REF_HXX
21#define INCLUDED_RTL_REF_HXX
22
23#include "sal/config.h"
24
25#include <cassert>
26#include <cstddef>
27#include <functional>
28#ifdef LIBO_INTERNAL_ONLY1
29#include <type_traits>
30#endif
31
32#include "sal/types.h"
33
34namespace rtl
35{
36
37/** Template reference class for reference type.
38*/
39template <class reference_type>
40class Reference
41{
42 /** The <b>reference_type</b> body pointer.
43 */
44 reference_type * m_pBody;
45
46
47public:
48 /** Constructor...
49 */
50 Reference()
51 : m_pBody (NULL__null)
52 {}
53
54
55 /** Constructor...
56 */
57 Reference (reference_type * pBody, __sal_NoAcquire)
58 : m_pBody (pBody)
59 {
60 }
61
62 /** Constructor...
63 */
64 Reference (reference_type * pBody)
65 : m_pBody (pBody)
66 {
67 if (m_pBody)
68 m_pBody->acquire();
69 }
70
71 /** Copy constructor...
72 */
73 Reference (const Reference<reference_type> & handle)
74 : m_pBody (handle.m_pBody)
75 {
76 if (m_pBody)
38
Assuming field 'm_pBody' is non-null
39
Taking true branch
77 m_pBody->acquire();
78 }
79
80#ifdef LIBO_INTERNAL_ONLY1
81 /** Move constructor...
82 */
83 Reference (Reference<reference_type> && handle) noexcept
84 : m_pBody (handle.m_pBody)
85 {
86 handle.m_pBody = nullptr;
87 }
88#endif
89
90#if defined LIBO_INTERNAL_ONLY1
91 /** Up-casting conversion constructor: Copies interface reference.
92
93 Does not work for up-casts to ambiguous bases.
94
95 @param rRef another reference
96 */
97 template< class derived_type >
98 inline Reference(
99 const Reference< derived_type > & rRef,
100 std::enable_if_t<std::is_base_of_v<reference_type, derived_type>, int> = 0 )
101 : m_pBody (rRef.get())
102 {
103 if (m_pBody)
104 m_pBody->acquire();
105 }
106#endif
107
108 /** Destructor...
109 */
110 ~Reference() COVERITY_NOEXCEPT_FALSE
111 {
112 if (m_pBody)
113 m_pBody->release();
114 }
115
116 /** Set...
117 Similar to assignment.
118 */
119 Reference<reference_type> &
120 SAL_CALL set (reference_type * pBody)
121 {
122 if (pBody)
123 pBody->acquire();
124 reference_type * const pOld = m_pBody;
125 m_pBody = pBody;
126 if (pOld)
127 pOld->release();
128 return *this;
129 }
130
131 /** Assignment.
132 Unbinds this instance from its body (if bound) and
133 bind it to the body represented by the handle.
134 */
135 Reference<reference_type> &
136 SAL_CALL operator= (const Reference<reference_type> & handle)
137 {
138 return set( handle.m_pBody );
139 }
140
141#ifdef LIBO_INTERNAL_ONLY1
142 /** Assignment.
143 * Unbinds this instance from its body (if bound),
144 * bind it to the body represented by the handle, and
145 * set the body represented by the handle to nullptr.
146 */
147 Reference<reference_type> &
148 operator= (Reference<reference_type> && handle)
149 {
150 // self-movement guts ourself
151 if (m_pBody)
152 m_pBody->release();
153 m_pBody = handle.m_pBody;
154 handle.m_pBody = nullptr;
155 return *this;
156 }
157#endif
158
159 /** Assignment...
160 */
161 Reference<reference_type> &
162 SAL_CALL operator= (reference_type * pBody)
163 {
164 return set( pBody );
165 }
166
167 /** Unbind the body from this handle.
168 Note that for a handle representing a large body,
169 "handle.clear().set(new body());" _might_
170 perform a little bit better than "handle.set(new body());",
171 since in the second case two large objects exist in memory
172 (the old body and the new body).
173 */
174 Reference<reference_type> & SAL_CALL clear()
175 {
176 if (m_pBody
41.1
Field 'm_pBody' is non-null
41.1
Field 'm_pBody' is non-null
41.1
Field 'm_pBody' is non-null
41.1
Field 'm_pBody' is non-null
)
42
Taking true branch
177 {
178 reference_type * const pOld = m_pBody;
179 m_pBody = NULL__null;
180 pOld->release();
43
Calling 'VclReferenceBase::release'
47
Returning; memory was released
181 }
182 return *this;
183 }
184
185
186 /** Get the body. Can be used instead of operator->().
187 I.e. handle->someBodyOp() and handle.get()->someBodyOp()
188 are the same.
189 */
190 reference_type * SAL_CALL get() const
191 {
192 return m_pBody;
50
Use of memory after it is freed
193 }
194
195
196 /** Probably most common used: handle->someBodyOp().
197 */
198 reference_type * SAL_CALL operator->() const
199 {
200 assert(m_pBody != NULL)(static_cast <bool> (m_pBody != __null) ? void (0) : __assert_fail
("m_pBody != NULL", "/home/maarten/src/libreoffice/core/include/rtl/ref.hxx"
, 200, __extension__ __PRETTY_FUNCTION__))
;
201 return m_pBody;
202 }
203
204
205 /** Allows (*handle).someBodyOp().
206 */
207 reference_type & SAL_CALL operator*() const
208 {
209 assert(m_pBody != NULL)(static_cast <bool> (m_pBody != __null) ? void (0) : __assert_fail
("m_pBody != NULL", "/home/maarten/src/libreoffice/core/include/rtl/ref.hxx"
, 209, __extension__ __PRETTY_FUNCTION__))
;
210 return *m_pBody;
211 }
212
213
214 /** Returns True if the handle does point to a valid body.
215 */
216 bool SAL_CALL is() const
217 {
218 return (m_pBody != NULL__null);
219 }
220
221#if defined LIBO_INTERNAL_ONLY1
222 /** Returns True if the handle does point to a valid body.
223 */
224 explicit operator bool() const
225 {
226 return is();
227 }
228#endif
229
230 /** Returns True if this points to pBody.
231 */
232 bool SAL_CALL operator== (const reference_type * pBody) const
233 {
234 return (m_pBody == pBody);
235 }
236
237
238 /** Returns True if handle points to the same body.
239 */
240 bool
241 SAL_CALL operator== (const Reference<reference_type> & handle) const
242 {
243 return (m_pBody == handle.m_pBody);
244 }
245
246
247 /** Needed to place References into STL collection.
248 */
249 bool
250 SAL_CALL operator!= (const Reference<reference_type> & handle) const
251 {
252 return (m_pBody != handle.m_pBody);
253 }
254
255
256 /** Needed to place References into STL collection.
257 */
258 bool
259 SAL_CALL operator< (const Reference<reference_type> & handle) const
260 {
261 return (m_pBody < handle.m_pBody);
262 }
263
264
265 /** Needed to place References into STL collection.
266 */
267 bool
268 SAL_CALL operator> (const Reference<reference_type> & handle) const
269 {
270 return (m_pBody > handle.m_pBody);
271 }
272};
273
274} // namespace rtl
275
276#if defined LIBO_INTERNAL_ONLY1
277namespace std
278{
279
280/// @cond INTERNAL
281/**
282 Make rtl::Reference hashable by default for use in STL containers.
283
284 @since LibreOffice 6.3
285*/
286template<typename T>
287struct hash<::rtl::Reference<T>>
288{
289 std::size_t operator()(::rtl::Reference<T> const & s) const
290 { return std::size_t(s.get()); }
291};
292/// @endcond
293
294}
295
296#endif
297
298#endif /* ! INCLUDED_RTL_REF_HXX */
299
300/* vim:set shiftwidth=4 softtabstop=4 expandtab: */

/home/maarten/src/libreoffice/core/include/vcl/vclreferencebase.hxx

1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 */
19#ifndef INCLUDED_VCL_Reference_HXX
20#define INCLUDED_VCL_Reference_HXX
21
22#include <vcl/dllapi.h>
23#include <osl/interlck.h>
24
25class VCL_DLLPUBLIC__attribute__ ((visibility("default"))) VclReferenceBase
26{
27 mutable oslInterlockedCount mnRefCnt;
28
29 template<typename T> friend class VclPtr;
30
31public:
32 void acquire() const
33 {
34 osl_atomic_increment(&mnRefCnt)__sync_add_and_fetch((&mnRefCnt), 1);
35 }
36
37 void release() const
38 {
39 if (osl_atomic_decrement(&mnRefCnt)__sync_sub_and_fetch((&mnRefCnt), 1) == 0)
44
Assuming the condition is true
45
Taking true branch
40 delete this;
46
Memory is released
41 }
42#ifdef DBG_UTIL
43#ifndef _WIN32
44 sal_Int32 getRefCount() const { return mnRefCnt; }
45#endif
46#endif
47
48
49private:
50 VclReferenceBase(const VclReferenceBase&) = delete;
51 VclReferenceBase& operator=(const VclReferenceBase&) = delete;
52
53 bool mbDisposed : 1;
54
55protected:
56 VclReferenceBase();
57protected:
58 virtual ~VclReferenceBase();
59
60protected:
61 virtual void dispose();
62
63public:
64 void disposeOnce();
65 bool isDisposed() const { return mbDisposed; }
66
67};
68#endif