File: | home/maarten/src/libreoffice/core/include/rtl/ref.hxx |
Warning: | line 192, column 9 Use of memory after it is freed |
Press '?' to see keyboard shortcuts
Keyboard shortcuts:
1 | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ | |||
2 | /* | |||
3 | * This file is part of the LibreOffice project. | |||
4 | * | |||
5 | * This Source Code Form is subject to the terms of the Mozilla Public | |||
6 | * License, v. 2.0. If a copy of the MPL was not distributed with this | |||
7 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. | |||
8 | * | |||
9 | * This file incorporates work covered by the following license notice: | |||
10 | * | |||
11 | * Licensed to the Apache Software Foundation (ASF) under one or more | |||
12 | * contributor license agreements. See the NOTICE file distributed | |||
13 | * with this work for additional information regarding copyright | |||
14 | * ownership. The ASF licenses this file to you under the Apache | |||
15 | * License, Version 2.0 (the "License"); you may not use this file | |||
16 | * except in compliance with the License. You may obtain a copy of | |||
17 | * the License at http://www.apache.org/licenses/LICENSE-2.0 . | |||
18 | */ | |||
19 | ||||
20 | #include <svtools/brwbox.hxx> | |||
21 | #include <svtools/brwhead.hxx> | |||
22 | #include <svtools/recorditemwindow.hxx> | |||
23 | #include <o3tl/numeric.hxx> | |||
24 | #include <o3tl/safeint.hxx> | |||
25 | #include "datwin.hxx" | |||
26 | #include <tools/debug.hxx> | |||
27 | #include <tools/fract.hxx> | |||
28 | #include <sal/log.hxx> | |||
29 | #include <vcl/scrbar.hxx> | |||
30 | #include <vcl/svapp.hxx> | |||
31 | ||||
32 | #include <algorithm> | |||
33 | #include <com/sun/star/accessibility/AccessibleTableModelChange.hpp> | |||
34 | #include <com/sun/star/accessibility/AccessibleTableModelChangeType.hpp> | |||
35 | #include <com/sun/star/accessibility/AccessibleEventId.hpp> | |||
36 | #include <tools/multisel.hxx> | |||
37 | #include "brwimpl.hxx" | |||
38 | ||||
39 | ||||
40 | #define SCROLL_FLAGS(ScrollFlags::Clip | ScrollFlags::NoChildren) (ScrollFlags::Clip | ScrollFlags::NoChildren) | |||
41 | ||||
42 | using namespace com::sun::star::accessibility::AccessibleEventId; | |||
43 | using namespace com::sun::star::accessibility::AccessibleTableModelChangeType; | |||
44 | using com::sun::star::accessibility::AccessibleTableModelChange; | |||
45 | using namespace ::com::sun::star::uno; | |||
46 | using namespace svt; | |||
47 | ||||
48 | namespace | |||
49 | { | |||
50 | void disposeAndClearHeaderCell(::svt::BrowseBoxImpl::THeaderCellMap& _rHeaderCell) | |||
51 | { | |||
52 | ::std::for_each( | |||
53 | _rHeaderCell.begin(), | |||
54 | _rHeaderCell.end(), | |||
55 | ::svt::BrowseBoxImpl::THeaderCellMapFunctorDispose() | |||
56 | ); | |||
57 | _rHeaderCell.clear(); | |||
58 | } | |||
59 | } | |||
60 | ||||
61 | void BrowseBox::ConstructImpl( BrowserMode nMode ) | |||
62 | { | |||
63 | SAL_INFO("svtools", "BrowseBox:ConstructImpl " << this )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:ConstructImpl " << this) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_INFO ), ("svtools"), ("/home/maarten/src/libreoffice/core/svtools/source/brwbox/brwbox1.cxx" ":" "63" ": "), ::sal::detail::unwrapStream( ::sal::detail:: StreamStart() << "BrowseBox:ConstructImpl " << this ), 0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream << "BrowseBox:ConstructImpl " << this; ::sal::detail ::log( (::SAL_DETAIL_LOG_LEVEL_INFO), ("svtools"), ("/home/maarten/src/libreoffice/core/svtools/source/brwbox/brwbox1.cxx" ":" "63" ": "), sal_detail_stream, 0); }; break; case SAL_DETAIL_LOG_ACTION_FATAL : if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart () << "BrowseBox:ConstructImpl " << this) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_INFO), ("svtools") , ("/home/maarten/src/libreoffice/core/svtools/source/brwbox/brwbox1.cxx" ":" "63" ": "), ::sal::detail::unwrapStream( ::sal::detail:: StreamStart() << "BrowseBox:ConstructImpl " << this ), 0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream << "BrowseBox:ConstructImpl " << this; ::sal::detail ::log( (::SAL_DETAIL_LOG_LEVEL_INFO), ("svtools"), ("/home/maarten/src/libreoffice/core/svtools/source/brwbox/brwbox1.cxx" ":" "63" ": "), sal_detail_stream, 0); }; std::abort(); break ; } } } while (false); | |||
64 | bMultiSelection = false; | |||
65 | pColSel = nullptr; | |||
66 | pVScroll = nullptr; | |||
67 | pDataWin = VclPtr<BrowserDataWin>::Create( this ).get(); | |||
68 | m_pImpl.reset( new ::svt::BrowseBoxImpl() ); | |||
69 | ||||
70 | InitSettings_Impl( this ); | |||
71 | InitSettings_Impl( pDataWin ); | |||
72 | ||||
73 | bBootstrapped = false; | |||
74 | nDataRowHeight = 0; | |||
75 | nTitleLines = 1; | |||
76 | nFirstCol = 0; | |||
77 | nTopRow = 0; | |||
78 | nCurRow = BROWSER_ENDOFSELECTION(static_cast<long>((-1))); | |||
79 | nCurColId = 0; | |||
80 | bResizing = false; | |||
81 | bSelect = false; | |||
82 | bSelecting = false; | |||
83 | bScrolling = false; | |||
84 | bSelectionIsVisible = false; | |||
85 | bNotToggleSel = false; | |||
86 | bRowDividerDrag = false; | |||
87 | bHit = false; | |||
88 | mbInteractiveRowHeight = false; | |||
89 | bHideSelect = false; | |||
90 | bHideCursor = TRISTATE_FALSE; | |||
91 | nRowCount = 0; | |||
92 | m_bFocusOnlyCursor = true; | |||
93 | m_aCursorColor = COL_TRANSPARENT; | |||
94 | m_nCurrentMode = BrowserMode::NONE; | |||
95 | nControlAreaWidth = USHRT_MAX(32767 *2 +1); | |||
96 | uRow.nSel = BROWSER_ENDOFSELECTION(static_cast<long>((-1))); | |||
97 | ||||
98 | aHScroll->SetLineSize(1); | |||
99 | aHScroll->SetScrollHdl( LINK( this, BrowseBox, ScrollHdl )::tools::detail::makeLink( ::tools::detail::castTo<BrowseBox *>(this), &BrowseBox::LinkStubScrollHdl) ); | |||
100 | pDataWin->Show(); | |||
101 | ||||
102 | SetMode( nMode ); | |||
103 | bSelectionIsVisible = bKeepHighlight; | |||
104 | bHasFocus = HasChildPathFocus(); | |||
105 | pDataWin->nCursorHidden = | |||
106 | ( bHasFocus ? 0 : 1 ) + ( GetUpdateMode() ? 0 : 1 ); | |||
107 | } | |||
108 | ||||
109 | // we're just measuring the "real" NavigationBar | |||
110 | class MeasureStatusBar final : public InterimItemWindow | |||
111 | { | |||
112 | private: | |||
113 | std::unique_ptr<weld::Label> m_xRecordText; | |||
114 | std::unique_ptr<weld::Entry> m_xAbsolute; | |||
115 | std::unique_ptr<weld::Label> m_xRecordOf; | |||
116 | std::unique_ptr<weld::Label> m_xRecordCount; | |||
117 | public: | |||
118 | MeasureStatusBar(vcl::Window *pParent) | |||
119 | : InterimItemWindow(pParent, "svx/ui/navigationbar.ui", "NavigationBar") | |||
120 | , m_xRecordText(m_xBuilder->weld_label("recordtext")) | |||
121 | , m_xAbsolute(m_xBuilder->weld_entry("entry-noframe")) | |||
122 | , m_xRecordOf(m_xBuilder->weld_label("recordof")) | |||
123 | , m_xRecordCount(m_xBuilder->weld_label("recordcount")) | |||
124 | { | |||
125 | vcl::Font aApplFont(Application::GetSettings().GetStyleSettings().GetToolFont()); | |||
126 | m_xAbsolute->set_font(aApplFont); | |||
127 | m_xRecordText->set_font(aApplFont); | |||
128 | m_xRecordOf->set_font(aApplFont); | |||
129 | m_xRecordCount->set_font(aApplFont); | |||
130 | ||||
131 | SetSizePixel(get_preferred_size()); | |||
132 | } | |||
133 | ||||
134 | virtual void dispose() override | |||
135 | { | |||
136 | m_xRecordCount.reset(); | |||
137 | m_xRecordOf.reset(); | |||
138 | m_xAbsolute.reset(); | |||
139 | m_xRecordText.reset(); | |||
140 | InterimItemWindow::dispose(); | |||
141 | } | |||
142 | }; | |||
143 | ||||
144 | long BrowseBox::GetBarHeight() const | |||
145 | { | |||
146 | // tdf#115941 because some platforms have things like overlay scrollbars, take a max | |||
147 | // of a statusbar height and a scrollbar height as the control area height | |||
148 | ||||
149 | // (we can't ask the scrollbars for their size cause if we're zoomed they still have to be | |||
150 | // resized - which is done in UpdateScrollbars) | |||
151 | ||||
152 | return std::max(aStatusBarHeight->GetSizePixel().Height(), GetSettings().GetStyleSettings().GetScrollBarSize()); | |||
153 | } | |||
154 | ||||
155 | BrowseBox::BrowseBox( vcl::Window* pParent, WinBits nBits, BrowserMode nMode ) | |||
156 | :Control( pParent, nBits | WB_3DLOOK ) | |||
157 | ,DragSourceHelper( this ) | |||
158 | ,DropTargetHelper( this ) | |||
159 | ,aHScroll( VclPtr<ScrollBar>::Create(this, WB_HSCROLL) ) | |||
160 | // see NavigationBar ctor, here we just want to know its height | |||
161 | ,aStatusBarHeight(VclPtr<MeasureStatusBar>::Create(this)) | |||
162 | { | |||
163 | ConstructImpl( nMode ); | |||
164 | } | |||
165 | ||||
166 | BrowseBox::~BrowseBox() | |||
167 | { | |||
168 | disposeOnce(); | |||
169 | } | |||
170 | ||||
171 | void BrowseBox::dispose() | |||
172 | { | |||
173 | SAL_INFO("svtools", "BrowseBox:dispose " << this )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:dispose " << this) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_INFO ), ("svtools"), ("/home/maarten/src/libreoffice/core/svtools/source/brwbox/brwbox1.cxx" ":" "173" ": "), ::sal::detail::unwrapStream( ::sal::detail:: StreamStart() << "BrowseBox:dispose " << this), 0 ); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream << "BrowseBox:dispose " << this; ::sal::detail:: log( (::SAL_DETAIL_LOG_LEVEL_INFO), ("svtools"), ("/home/maarten/src/libreoffice/core/svtools/source/brwbox/brwbox1.cxx" ":" "173" ": "), sal_detail_stream, 0); }; break; case SAL_DETAIL_LOG_ACTION_FATAL : if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart () << "BrowseBox:dispose " << this) == 1) { ::sal_detail_log ( (::SAL_DETAIL_LOG_LEVEL_INFO), ("svtools"), ("/home/maarten/src/libreoffice/core/svtools/source/brwbox/brwbox1.cxx" ":" "173" ": "), ::sal::detail::unwrapStream( ::sal::detail:: StreamStart() << "BrowseBox:dispose " << this), 0 ); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream << "BrowseBox:dispose " << this; ::sal::detail:: log( (::SAL_DETAIL_LOG_LEVEL_INFO), ("svtools"), ("/home/maarten/src/libreoffice/core/svtools/source/brwbox/brwbox1.cxx" ":" "173" ": "), sal_detail_stream, 0); }; std::abort(); break ; } } } while (false); | |||
174 | ||||
175 | if ( m_pImpl->m_pAccessible ) | |||
176 | { | |||
177 | disposeAndClearHeaderCell(m_pImpl->m_aColHeaderCellMap); | |||
178 | disposeAndClearHeaderCell(m_pImpl->m_aRowHeaderCellMap); | |||
179 | m_pImpl->m_pAccessible->dispose(); | |||
180 | } | |||
181 | ||||
182 | Hide(); | |||
183 | pDataWin->pHeaderBar.disposeAndClear(); | |||
184 | pDataWin->pCornerWin.disposeAndClear(); | |||
185 | pDataWin.disposeAndClear(); | |||
186 | pVScroll.disposeAndClear(); | |||
187 | aHScroll.disposeAndClear(); | |||
188 | aStatusBarHeight.disposeAndClear(); | |||
189 | ||||
190 | // free columns-space | |||
191 | mvCols.clear(); | |||
192 | pColSel.reset(); | |||
193 | if ( bMultiSelection ) | |||
194 | delete uRow.pSel; | |||
195 | DragSourceHelper::dispose(); | |||
196 | DropTargetHelper::dispose(); | |||
197 | Control::dispose(); | |||
198 | } | |||
199 | ||||
200 | ||||
201 | short BrowseBox::GetCursorHideCount() const | |||
202 | { | |||
203 | return pDataWin->nCursorHidden; | |||
204 | } | |||
205 | ||||
206 | ||||
207 | void BrowseBox::DoShowCursor( const char * ) | |||
208 | { | |||
209 | if (!pDataWin) | |||
210 | return; | |||
211 | short nHiddenCount = --pDataWin->nCursorHidden; | |||
212 | if (PaintCursorIfHiddenOnce()) | |||
213 | { | |||
214 | if (1 == nHiddenCount) | |||
215 | DrawCursor(); | |||
216 | } | |||
217 | else | |||
218 | { | |||
219 | if (0 == nHiddenCount) | |||
220 | DrawCursor(); | |||
221 | } | |||
222 | } | |||
223 | ||||
224 | ||||
225 | void BrowseBox::DoHideCursor( const char * ) | |||
226 | { | |||
227 | short nHiddenCount = ++pDataWin->nCursorHidden; | |||
228 | if (PaintCursorIfHiddenOnce()) | |||
229 | { | |||
230 | if (2 == nHiddenCount) | |||
231 | DrawCursor(); | |||
232 | } | |||
233 | else | |||
234 | { | |||
235 | if (1 == nHiddenCount) | |||
236 | DrawCursor(); | |||
237 | } | |||
238 | } | |||
239 | ||||
240 | ||||
241 | void BrowseBox::SetRealRowCount( const OUString &rRealRowCount ) | |||
242 | { | |||
243 | pDataWin->aRealRowCount = rRealRowCount; | |||
244 | } | |||
245 | ||||
246 | ||||
247 | void BrowseBox::SetFont( const vcl::Font& rNewFont ) | |||
248 | { | |||
249 | pDataWin->SetFont( rNewFont ); | |||
250 | ImpGetDataRowHeight(); | |||
251 | } | |||
252 | ||||
253 | const vcl::Font& BrowseBox::GetFont() const | |||
254 | { | |||
255 | return pDataWin->GetFont(); | |||
256 | } | |||
257 | ||||
258 | sal_uLong BrowseBox::GetDefaultColumnWidth( const OUString& _rText ) const | |||
259 | { | |||
260 | return pDataWin->GetTextWidth( _rText ) + pDataWin->GetTextWidth(OUString('0')) * 4; | |||
261 | } | |||
262 | ||||
263 | ||||
264 | void BrowseBox::InsertHandleColumn( sal_uLong nWidth ) | |||
265 | { | |||
266 | ||||
267 | #if OSL_DEBUG_LEVEL1 > 0 | |||
268 | OSL_ENSURE( ColCount() == 0 || mvCols[0]->GetId() != HandleColumnId , "BrowseBox::InsertHandleColumn: there is already a handle column" )do { if (true && (!(ColCount() == 0 || mvCols[0]-> GetId() != HandleColumnId))) { sal_detail_logFormat((SAL_DETAIL_LOG_LEVEL_WARN ), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/svtools/source/brwbox/brwbox1.cxx" ":" "268" ": "), "%s", "BrowseBox::InsertHandleColumn: there is already a handle column" ); } } while (false); | |||
269 | { | |||
270 | for (auto const & col : mvCols) | |||
271 | OSL_ENSURE( col->GetId() != HandleColumnId, "BrowseBox::InsertHandleColumn: there is a non-Handle column with handle ID" )do { if (true && (!(col->GetId() != HandleColumnId ))) { sal_detail_logFormat((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl" ), ("/home/maarten/src/libreoffice/core/svtools/source/brwbox/brwbox1.cxx" ":" "271" ": "), "%s", "BrowseBox::InsertHandleColumn: there is a non-Handle column with handle ID" ); } } while (false); | |||
272 | } | |||
273 | #endif | |||
274 | ||||
275 | mvCols.insert( mvCols.begin(), std::unique_ptr<BrowserColumn>(new BrowserColumn( 0, OUString(), nWidth, GetZoom() )) ); | |||
276 | FreezeColumn( 0 ); | |||
277 | ||||
278 | // adjust headerbar | |||
279 | if ( pDataWin->pHeaderBar ) | |||
280 | { | |||
281 | pDataWin->pHeaderBar->SetPosSizePixel( | |||
282 | Point(nWidth, 0), | |||
283 | Size( GetOutputSizePixel().Width() - nWidth, GetTitleHeight() ) | |||
284 | ); | |||
285 | } | |||
286 | ||||
287 | ColumnInserted( 0 ); | |||
288 | } | |||
289 | ||||
290 | ||||
291 | void BrowseBox::InsertDataColumn( sal_uInt16 nItemId, const OUString& rText, | |||
292 | long nWidth, HeaderBarItemBits nBits, sal_uInt16 nPos ) | |||
293 | { | |||
294 | ||||
295 | OSL_ENSURE( nItemId != HandleColumnId, "BrowseBox::InsertDataColumn: nItemId is HandleColumnId" )do { if (true && (!(nItemId != HandleColumnId))) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/svtools/source/brwbox/brwbox1.cxx" ":" "295" ": "), "%s", "BrowseBox::InsertDataColumn: nItemId is HandleColumnId" ); } } while (false); | |||
296 | OSL_ENSURE( nItemId != BROWSER_INVALIDID, "BrowseBox::InsertDataColumn: nItemId is reserved value BROWSER_INVALIDID" )do { if (true && (!(nItemId != ((sal_uInt16) 0xFFFF)) )) { sal_detail_logFormat((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl" ), ("/home/maarten/src/libreoffice/core/svtools/source/brwbox/brwbox1.cxx" ":" "296" ": "), "%s", "BrowseBox::InsertDataColumn: nItemId is reserved value BROWSER_INVALIDID" ); } } while (false); | |||
297 | ||||
298 | #if OSL_DEBUG_LEVEL1 > 0 | |||
299 | { | |||
300 | for (auto const& col : mvCols) | |||
301 | OSL_ENSURE( col->GetId() != nItemId, "BrowseBox::InsertDataColumn: duplicate column Id" )do { if (true && (!(col->GetId() != nItemId))) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/svtools/source/brwbox/brwbox1.cxx" ":" "301" ": "), "%s", "BrowseBox::InsertDataColumn: duplicate column Id" ); } } while (false); | |||
302 | } | |||
303 | #endif | |||
304 | ||||
305 | if ( nPos < mvCols.size() ) | |||
306 | { | |||
307 | mvCols.emplace( mvCols.begin() + nPos, new BrowserColumn( nItemId, rText, nWidth, GetZoom() ) ); | |||
308 | } | |||
309 | else | |||
310 | { | |||
311 | mvCols.emplace_back( new BrowserColumn( nItemId, rText, nWidth, GetZoom() ) ); | |||
312 | } | |||
313 | if ( nCurColId == 0 ) | |||
314 | nCurColId = nItemId; | |||
315 | ||||
316 | if ( pDataWin->pHeaderBar ) | |||
317 | { | |||
318 | // Handle column not in the header bar | |||
319 | sal_uInt16 nHeaderPos = nPos; | |||
320 | if (nHeaderPos != HEADERBAR_APPEND(sal_uInt16(0xFFFF)) && GetColumnId(0) == HandleColumnId ) | |||
321 | nHeaderPos--; | |||
322 | pDataWin->pHeaderBar->InsertItem( | |||
323 | nItemId, rText, nWidth, nBits, nHeaderPos ); | |||
324 | } | |||
325 | ColumnInserted( nPos ); | |||
326 | } | |||
327 | ||||
328 | sal_uInt16 BrowseBox::ToggleSelectedColumn() | |||
329 | { | |||
330 | sal_uInt16 nSelectedColId = BROWSER_INVALIDID((sal_uInt16) 0xFFFF); | |||
331 | if ( pColSel && pColSel->GetSelectCount() ) | |||
332 | { | |||
333 | DoHideCursor( "ToggleSelectedColumn" ); | |||
334 | ToggleSelection(); | |||
335 | long nSelected = pColSel->FirstSelected(); | |||
336 | if (nSelected != static_cast<long>(SFX_ENDOFSELECTION(-1))) | |||
337 | nSelectedColId = mvCols[nSelected]->GetId(); | |||
338 | pColSel->SelectAll(false); | |||
339 | } | |||
340 | return nSelectedColId; | |||
341 | } | |||
342 | ||||
343 | void BrowseBox::SetToggledSelectedColumn(sal_uInt16 _nSelectedColumnId) | |||
344 | { | |||
345 | if ( pColSel && _nSelectedColumnId != BROWSER_INVALIDID((sal_uInt16) 0xFFFF) ) | |||
346 | { | |||
347 | pColSel->Select( GetColumnPos( _nSelectedColumnId ) ); | |||
348 | ToggleSelection(); | |||
349 | SAL_INFO("svtools", "BrowseBox::SetToggledSelectedColumn " << this )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::SetToggledSelectedColumn " << this) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_INFO ), ("svtools"), ("/home/maarten/src/libreoffice/core/svtools/source/brwbox/brwbox1.cxx" ":" "349" ": "), ::sal::detail::unwrapStream( ::sal::detail:: StreamStart() << "BrowseBox::SetToggledSelectedColumn " << this), 0); } else { ::std::ostringstream sal_detail_stream ; sal_detail_stream << "BrowseBox::SetToggledSelectedColumn " << this; ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_INFO ), ("svtools"), ("/home/maarten/src/libreoffice/core/svtools/source/brwbox/brwbox1.cxx" ":" "349" ": "), sal_detail_stream, 0); }; break; case SAL_DETAIL_LOG_ACTION_FATAL : if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart () << "BrowseBox::SetToggledSelectedColumn " << this ) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_INFO), ("svtools" ), ("/home/maarten/src/libreoffice/core/svtools/source/brwbox/brwbox1.cxx" ":" "349" ": "), ::sal::detail::unwrapStream( ::sal::detail:: StreamStart() << "BrowseBox::SetToggledSelectedColumn " << this), 0); } else { ::std::ostringstream sal_detail_stream ; sal_detail_stream << "BrowseBox::SetToggledSelectedColumn " << this; ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_INFO ), ("svtools"), ("/home/maarten/src/libreoffice/core/svtools/source/brwbox/brwbox1.cxx" ":" "349" ": "), sal_detail_stream, 0); }; std::abort(); break ; } } } while (false); | |||
350 | DoShowCursor( "SetToggledSelectedColumn" ); | |||
351 | } | |||
352 | } | |||
353 | ||||
354 | void BrowseBox::FreezeColumn( sal_uInt16 nItemId ) | |||
355 | { | |||
356 | // get the position in the current array | |||
357 | size_t nItemPos = GetColumnPos( nItemId ); | |||
358 | if ( nItemPos >= mvCols.size() ) | |||
359 | // not available! | |||
360 | return; | |||
361 | ||||
362 | // doesn't the state change? | |||
363 | if ( mvCols[ nItemPos ]->IsFrozen() ) | |||
364 | return; | |||
365 | ||||
366 | // remark the column selection | |||
367 | sal_uInt16 nSelectedColId = ToggleSelectedColumn(); | |||
368 | ||||
369 | // to be moved? | |||
370 | if ( nItemPos != 0 && !mvCols[ nItemPos-1 ]->IsFrozen() ) | |||
371 | { | |||
372 | // move to the right of the last frozen column | |||
373 | sal_uInt16 nFirstScrollable = FrozenColCount(); | |||
374 | std::unique_ptr<BrowserColumn> pColumn = std::move(mvCols[ nItemPos ]); | |||
375 | mvCols.erase( mvCols.begin() + nItemPos ); | |||
376 | nItemPos = nFirstScrollable; | |||
377 | mvCols.insert( mvCols.begin() + nItemPos, std::move(pColumn) ); | |||
378 | } | |||
379 | ||||
380 | // adjust the number of the first scrollable and visible column | |||
381 | if ( nFirstCol <= nItemPos ) | |||
382 | nFirstCol = nItemPos + 1; | |||
383 | ||||
384 | // toggle the freeze-state of the column | |||
385 | mvCols[ nItemPos ]->Freeze(); | |||
386 | ||||
387 | // align the scrollbar-range | |||
388 | UpdateScrollbars(); | |||
389 | ||||
390 | // repaint | |||
391 | Control::Invalidate(); | |||
392 | pDataWin->Invalidate(); | |||
393 | ||||
394 | // remember the column selection | |||
395 | SetToggledSelectedColumn(nSelectedColId); | |||
396 | } | |||
397 | ||||
398 | ||||
399 | void BrowseBox::SetColumnPos( sal_uInt16 nColumnId, sal_uInt16 nPos ) | |||
400 | { | |||
401 | // never set pos of the handle column | |||
402 | if ( nColumnId == HandleColumnId ) | |||
403 | return; | |||
404 | ||||
405 | // get the position in the current array | |||
406 | sal_uInt16 nOldPos = GetColumnPos( nColumnId ); | |||
407 | if ( nOldPos >= mvCols.size() ) | |||
408 | // not available! | |||
409 | return; | |||
410 | ||||
411 | // does the state change? | |||
412 | if (nOldPos == nPos) | |||
413 | return; | |||
414 | ||||
415 | // remark the column selection | |||
416 | sal_uInt16 nSelectedColId = ToggleSelectedColumn(); | |||
417 | ||||
418 | // determine old column area | |||
419 | Size aDataWinSize( pDataWin->GetSizePixel() ); | |||
420 | if ( pDataWin->pHeaderBar ) | |||
421 | aDataWinSize.AdjustHeight(pDataWin->pHeaderBar->GetSizePixel().Height() ); | |||
422 | ||||
423 | tools::Rectangle aFromRect( GetFieldRect( nColumnId) ); | |||
424 | aFromRect.AdjustRight(2*MIN_COLUMNWIDTH2 ); | |||
425 | ||||
426 | sal_uInt16 nNextPos = nOldPos + 1; | |||
427 | if ( nOldPos > nPos ) | |||
428 | nNextPos = nOldPos - 1; | |||
429 | ||||
430 | BrowserColumn *pNextCol = mvCols[ nNextPos ].get(); | |||
431 | tools::Rectangle aNextRect(GetFieldRect( pNextCol->GetId() )); | |||
432 | ||||
433 | // move column internally | |||
434 | { | |||
435 | std::unique_ptr<BrowserColumn> pTemp = std::move(mvCols[nOldPos]); | |||
436 | mvCols.erase( mvCols.begin() + nOldPos ); | |||
437 | mvCols.insert( mvCols.begin() + nPos, std::move(pTemp) ); | |||
438 | } | |||
439 | ||||
440 | // determine new column area | |||
441 | tools::Rectangle aToRect( GetFieldRect( nColumnId ) ); | |||
442 | aToRect.AdjustRight(2*MIN_COLUMNWIDTH2 ); | |||
443 | ||||
444 | // do scroll, let redraw | |||
445 | if( pDataWin->GetBackground().IsScrollable() ) | |||
446 | { | |||
447 | long nScroll = -aFromRect.GetWidth(); | |||
448 | tools::Rectangle aScrollArea; | |||
449 | if ( nOldPos > nPos ) | |||
450 | { | |||
451 | long nFrozenWidth = GetFrozenWidth(); | |||
452 | if ( aToRect.Left() < nFrozenWidth ) | |||
453 | aToRect.SetLeft( nFrozenWidth ); | |||
454 | aScrollArea = tools::Rectangle(Point(aToRect.Left(),0), | |||
455 | Point(aNextRect.Right(),aDataWinSize.Height())); | |||
456 | nScroll *= -1; // reverse direction | |||
457 | } | |||
458 | else | |||
459 | aScrollArea = tools::Rectangle(Point(aNextRect.Left(),0), | |||
460 | Point(aToRect.Right(),aDataWinSize.Height())); | |||
461 | ||||
462 | pDataWin->Scroll( nScroll, 0, aScrollArea ); | |||
463 | aToRect.SetTop( 0 ); | |||
464 | aToRect.SetBottom( aScrollArea.Bottom() ); | |||
465 | Invalidate( aToRect ); | |||
466 | } | |||
467 | else | |||
468 | pDataWin->Window::Invalidate( InvalidateFlags::NoChildren ); | |||
469 | ||||
470 | // adjust header bar positions | |||
471 | if ( pDataWin->pHeaderBar ) | |||
472 | { | |||
473 | sal_uInt16 nNewPos = nPos; | |||
474 | if ( GetColumnId(0) == HandleColumnId ) | |||
475 | --nNewPos; | |||
476 | pDataWin->pHeaderBar->MoveItem(nColumnId,nNewPos); | |||
477 | } | |||
478 | // remember the column selection | |||
479 | SetToggledSelectedColumn(nSelectedColId); | |||
480 | ||||
481 | if ( !isAccessibleAlive() ) | |||
482 | return; | |||
483 | ||||
484 | commitTableEvent( | |||
485 | TABLE_MODEL_CHANGED, | |||
486 | makeAny( AccessibleTableModelChange( | |||
487 | DELETE, | |||
488 | 0, | |||
489 | GetRowCount(), | |||
490 | nOldPos, | |||
491 | nOldPos | |||
492 | ) | |||
493 | ), | |||
494 | Any() | |||
495 | ); | |||
496 | ||||
497 | commitTableEvent( | |||
498 | TABLE_MODEL_CHANGED, | |||
499 | makeAny( AccessibleTableModelChange( | |||
500 | INSERT, | |||
501 | 0, | |||
502 | GetRowCount(), | |||
503 | nPos, | |||
504 | nPos | |||
505 | ) | |||
506 | ), | |||
507 | Any() | |||
508 | ); | |||
509 | ||||
510 | } | |||
511 | ||||
512 | ||||
513 | void BrowseBox::SetColumnTitle( sal_uInt16 nItemId, const OUString& rTitle ) | |||
514 | { | |||
515 | ||||
516 | // never set title of the handle-column | |||
517 | if ( nItemId == HandleColumnId ) | |||
518 | return; | |||
519 | ||||
520 | // get the position in the current array | |||
521 | sal_uInt16 nItemPos = GetColumnPos( nItemId ); | |||
522 | if ( nItemPos >= mvCols.size() ) | |||
523 | // not available! | |||
524 | return; | |||
525 | ||||
526 | // does the state change? | |||
527 | BrowserColumn *pCol = mvCols[ nItemPos ].get(); | |||
528 | if ( pCol->Title() == rTitle ) | |||
529 | return; | |||
530 | ||||
531 | OUString sOld(pCol->Title()); | |||
532 | ||||
533 | pCol->Title() = rTitle; | |||
534 | ||||
535 | // adjust headerbar column | |||
536 | if ( pDataWin->pHeaderBar ) | |||
537 | pDataWin->pHeaderBar->SetItemText( nItemId, rTitle ); | |||
538 | else | |||
539 | { | |||
540 | // redraw visible columns | |||
541 | if ( GetUpdateMode() && ( pCol->IsFrozen() || nItemPos > nFirstCol ) ) | |||
542 | Invalidate( tools::Rectangle( Point(0,0), | |||
543 | Size( GetOutputSizePixel().Width(), GetTitleHeight() ) ) ); | |||
544 | } | |||
545 | ||||
546 | if ( isAccessibleAlive() ) | |||
547 | { | |||
548 | commitTableEvent( TABLE_COLUMN_DESCRIPTION_CHANGED, | |||
549 | makeAny( rTitle ), | |||
550 | makeAny( sOld ) | |||
551 | ); | |||
552 | } | |||
553 | } | |||
554 | ||||
555 | ||||
556 | void BrowseBox::SetColumnWidth( sal_uInt16 nItemId, sal_uLong nWidth ) | |||
557 | { | |||
558 | ||||
559 | // get the position in the current array | |||
560 | size_t nItemPos = GetColumnPos( nItemId ); | |||
561 | if ( nItemPos >= mvCols.size() ) | |||
562 | return; | |||
563 | ||||
564 | // does the state change? | |||
565 | if ( nWidth < LONG_MAX9223372036854775807L && mvCols[ nItemPos ]->Width() == nWidth ) | |||
566 | return; | |||
567 | ||||
568 | long nOldWidth = mvCols[ nItemPos ]->Width(); | |||
569 | ||||
570 | // adjust last column, if necessary | |||
571 | if ( IsVisible() && nItemPos == mvCols.size() - 1 ) | |||
572 | { | |||
573 | long nMaxWidth = pDataWin->GetSizePixel().Width(); | |||
574 | nMaxWidth -= pDataWin->bAutoSizeLastCol | |||
575 | ? GetFieldRect(nItemId).Left() | |||
576 | : GetFrozenWidth(); | |||
577 | if ( pDataWin->bAutoSizeLastCol || nWidth > o3tl::make_unsigned(nMaxWidth) ) | |||
578 | { | |||
579 | nWidth = nMaxWidth > 16 ? nMaxWidth : nOldWidth; | |||
580 | } | |||
581 | } | |||
582 | ||||
583 | // OV | |||
584 | // In AutoSizeLastColumn(), we call SetColumnWidth with nWidth==0xffff. | |||
585 | // Thus, check here, if the width has actually changed. | |||
586 | if( static_cast<sal_uLong>(nOldWidth) == nWidth ) | |||
587 | return; | |||
588 | ||||
589 | // do we want to display the change immediately? | |||
590 | bool bUpdate = GetUpdateMode() && | |||
591 | ( mvCols[ nItemPos ]->IsFrozen() || nItemPos >= nFirstCol ); | |||
592 | ||||
593 | if ( bUpdate ) | |||
594 | { | |||
595 | // Selection hidden | |||
596 | DoHideCursor( "SetColumnWidth" ); | |||
597 | ToggleSelection(); | |||
598 | //!pDataWin->Update(); | |||
599 | //!Control::Update(); | |||
600 | } | |||
601 | ||||
602 | // set width | |||
603 | mvCols[ nItemPos ]->SetWidth(nWidth, GetZoom()); | |||
604 | ||||
605 | // scroll and invalidate | |||
606 | if ( bUpdate ) | |||
607 | { | |||
608 | // get X-Pos of the column changed | |||
609 | long nX = 0; | |||
610 | for ( size_t nCol = 0; nCol < nItemPos; ++nCol ) | |||
611 | { | |||
612 | BrowserColumn *pCol = mvCols[ nCol ].get(); | |||
613 | if ( pCol->IsFrozen() || nCol >= nFirstCol ) | |||
614 | nX += pCol->Width(); | |||
615 | } | |||
616 | ||||
617 | // actually scroll+invalidate | |||
618 | pDataWin->SetClipRegion(); | |||
619 | bool bSelVis = bSelectionIsVisible; | |||
620 | bSelectionIsVisible = false; | |||
621 | if( GetBackground().IsScrollable() ) | |||
622 | { | |||
623 | ||||
624 | tools::Rectangle aScrRect( nX + std::min( static_cast<sal_uLong>(nOldWidth), nWidth ), 0, | |||
625 | GetSizePixel().Width() , // the header is longer than the datawin | |||
626 | pDataWin->GetPosPixel().Y() - 1 ); | |||
627 | Control::Scroll( nWidth-nOldWidth, 0, aScrRect, SCROLL_FLAGS(ScrollFlags::Clip | ScrollFlags::NoChildren) ); | |||
628 | aScrRect.SetBottom( pDataWin->GetSizePixel().Height() ); | |||
629 | pDataWin->Scroll( nWidth-nOldWidth, 0, aScrRect, SCROLL_FLAGS(ScrollFlags::Clip | ScrollFlags::NoChildren) ); | |||
630 | tools::Rectangle aInvRect( nX, 0, nX + std::max( nWidth, static_cast<sal_uLong>(nOldWidth) ), USHRT_MAX(32767 *2 +1) ); | |||
631 | Control::Invalidate( aInvRect, InvalidateFlags::NoChildren ); | |||
632 | pDataWin->Invalidate( aInvRect ); | |||
633 | } | |||
634 | else | |||
635 | { | |||
636 | Control::Invalidate( InvalidateFlags::NoChildren ); | |||
637 | pDataWin->Window::Invalidate( InvalidateFlags::NoChildren ); | |||
638 | } | |||
639 | ||||
640 | ||||
641 | //!pDataWin->Update(); | |||
642 | //!Control::Update(); | |||
643 | bSelectionIsVisible = bSelVis; | |||
644 | ToggleSelection(); | |||
645 | DoShowCursor( "SetColumnWidth" ); | |||
646 | } | |||
647 | UpdateScrollbars(); | |||
648 | ||||
649 | // adjust headerbar column | |||
650 | if ( pDataWin->pHeaderBar ) | |||
651 | pDataWin->pHeaderBar->SetItemSize( | |||
652 | nItemId ? nItemId : USHRT_MAX(32767 *2 +1) - 1, nWidth ); | |||
653 | ||||
654 | // adjust last column | |||
655 | if ( nItemPos != mvCols.size() - 1 ) | |||
656 | AutoSizeLastColumn(); | |||
657 | } | |||
658 | ||||
659 | ||||
660 | void BrowseBox::AutoSizeLastColumn() | |||
661 | { | |||
662 | if ( pDataWin->bAutoSizeLastCol && | |||
663 | pDataWin->GetUpdateMode() ) | |||
664 | { | |||
665 | sal_uInt16 nId = GetColumnId( static_cast<sal_uInt16>(mvCols.size()) - 1 ); | |||
666 | SetColumnWidth( nId, LONG_MAX9223372036854775807L ); | |||
667 | ColumnResized( nId ); | |||
668 | } | |||
669 | } | |||
670 | ||||
671 | ||||
672 | void BrowseBox::RemoveColumn( sal_uInt16 nItemId ) | |||
673 | { | |||
674 | ||||
675 | // get column position | |||
676 | sal_uInt16 nPos = GetColumnPos(nItemId); | |||
677 | if ( nPos >= ColCount() ) | |||
678 | // not available | |||
679 | return; | |||
680 | ||||
681 | // correct column selection | |||
682 | if ( pColSel ) | |||
683 | pColSel->Remove( nPos ); | |||
684 | ||||
685 | // correct column cursor | |||
686 | if ( nCurColId == nItemId ) | |||
687 | nCurColId = 0; | |||
688 | ||||
689 | // delete column | |||
690 | mvCols.erase( mvCols.begin() + nPos ); | |||
691 | if ( nFirstCol >= nPos && nFirstCol > FrozenColCount() ) | |||
692 | { | |||
693 | OSL_ENSURE(nFirstCol > 0,"FirstCol must be greater zero!")do { if (true && (!(nFirstCol > 0))) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/svtools/source/brwbox/brwbox1.cxx" ":" "693" ": "), "%s", "FirstCol must be greater zero!"); } } while (false); | |||
694 | --nFirstCol; | |||
695 | } | |||
696 | ||||
697 | // handlecolumn not in headerbar | |||
698 | if (nItemId) | |||
699 | { | |||
700 | if ( pDataWin->pHeaderBar ) | |||
701 | pDataWin->pHeaderBar->RemoveItem( nItemId ); | |||
702 | } | |||
703 | else | |||
704 | { | |||
705 | // adjust headerbar | |||
706 | if ( pDataWin->pHeaderBar ) | |||
707 | { | |||
708 | pDataWin->pHeaderBar->SetPosSizePixel( | |||
709 | Point(0, 0), | |||
710 | Size( GetOutputSizePixel().Width(), GetTitleHeight() ) | |||
711 | ); | |||
712 | } | |||
713 | } | |||
714 | ||||
715 | // correct vertical scrollbar | |||
716 | UpdateScrollbars(); | |||
717 | ||||
718 | // trigger repaint, if necessary | |||
719 | if ( GetUpdateMode() ) | |||
720 | { | |||
721 | pDataWin->Invalidate(); | |||
722 | Control::Invalidate(); | |||
723 | if ( pDataWin->bAutoSizeLastCol && nPos ==ColCount() ) | |||
724 | SetColumnWidth( GetColumnId( nPos - 1 ), LONG_MAX9223372036854775807L ); | |||
725 | } | |||
726 | ||||
727 | if ( !isAccessibleAlive() ) | |||
728 | return; | |||
729 | ||||
730 | commitTableEvent( | |||
731 | TABLE_MODEL_CHANGED, | |||
732 | makeAny( AccessibleTableModelChange( DELETE, | |||
733 | 0, | |||
734 | GetRowCount(), | |||
735 | nPos, | |||
736 | nPos | |||
737 | ) | |||
738 | ), | |||
739 | Any() | |||
740 | ); | |||
741 | ||||
742 | commitHeaderBarEvent( | |||
743 | CHILD, | |||
744 | Any(), | |||
745 | makeAny( CreateAccessibleColumnHeader( nPos ) ), | |||
746 | true | |||
747 | ); | |||
748 | } | |||
749 | ||||
750 | ||||
751 | void BrowseBox::RemoveColumns() | |||
752 | { | |||
753 | size_t nOldCount = mvCols.size(); | |||
754 | ||||
755 | // remove all columns | |||
756 | mvCols.clear(); | |||
757 | ||||
758 | // correct column selection | |||
759 | if ( pColSel ) | |||
760 | { | |||
761 | pColSel->SelectAll(false); | |||
762 | pColSel->SetTotalRange( Range( 0, 0 ) ); | |||
763 | } | |||
764 | ||||
765 | // correct column cursor | |||
766 | nCurColId = 0; | |||
767 | nFirstCol = 0; | |||
768 | ||||
769 | if ( pDataWin->pHeaderBar ) | |||
770 | pDataWin->pHeaderBar->Clear( ); | |||
771 | ||||
772 | // correct vertical scrollbar | |||
773 | UpdateScrollbars(); | |||
774 | ||||
775 | // trigger repaint if necessary | |||
776 | if ( GetUpdateMode() ) | |||
777 | { | |||
778 | pDataWin->Invalidate(); | |||
779 | Control::Invalidate(); | |||
780 | } | |||
781 | ||||
782 | if ( !isAccessibleAlive() ) | |||
783 | return; | |||
784 | ||||
785 | if ( mvCols.size() == nOldCount ) | |||
786 | return; | |||
787 | ||||
788 | // all columns should be removed, so we remove the column header bar and append it again | |||
789 | // to avoid to notify every column remove | |||
790 | commitBrowseBoxEvent( | |||
791 | CHILD, | |||
792 | Any(), | |||
793 | makeAny(m_pImpl->getAccessibleHeaderBar(vcl::BBTYPE_COLUMNHEADERBAR)) | |||
794 | ); | |||
795 | ||||
796 | // and now append it again | |||
797 | commitBrowseBoxEvent( | |||
798 | CHILD, | |||
799 | makeAny(m_pImpl->getAccessibleHeaderBar(vcl::BBTYPE_COLUMNHEADERBAR)), | |||
800 | Any() | |||
801 | ); | |||
802 | ||||
803 | // notify a table model change | |||
804 | commitTableEvent( | |||
805 | TABLE_MODEL_CHANGED, | |||
806 | makeAny ( AccessibleTableModelChange( DELETE, | |||
807 | 0, | |||
808 | GetRowCount(), | |||
809 | 0, | |||
810 | nOldCount | |||
811 | ) | |||
812 | ), | |||
813 | Any() | |||
814 | ); | |||
815 | } | |||
816 | ||||
817 | ||||
818 | OUString BrowseBox::GetColumnTitle( sal_uInt16 nId ) const | |||
819 | { | |||
820 | ||||
821 | sal_uInt16 nItemPos = GetColumnPos( nId ); | |||
822 | if ( nItemPos >= mvCols.size() ) | |||
823 | return OUString(); | |||
824 | return mvCols[ nItemPos ]->Title(); | |||
825 | } | |||
826 | ||||
827 | long BrowseBox::GetRowCount() const | |||
828 | { | |||
829 | return nRowCount; | |||
830 | } | |||
831 | ||||
832 | sal_uInt16 BrowseBox::ColCount() const | |||
833 | { | |||
834 | return static_cast<sal_uInt16>(mvCols.size()); | |||
835 | } | |||
836 | ||||
837 | long BrowseBox::ImpGetDataRowHeight() const | |||
838 | { | |||
839 | BrowseBox *pThis = const_cast<BrowseBox*>(this); | |||
840 | pThis->nDataRowHeight = pThis->CalcReverseZoom(pDataWin->GetTextHeight() + 4); | |||
841 | pThis->Resize(); | |||
842 | pDataWin->Invalidate(); | |||
843 | return nDataRowHeight; | |||
844 | } | |||
845 | ||||
846 | void BrowseBox::SetDataRowHeight( long nPixel ) | |||
847 | { | |||
848 | ||||
849 | nDataRowHeight = CalcReverseZoom(nPixel); | |||
850 | Resize(); | |||
851 | pDataWin->Invalidate(); | |||
852 | } | |||
853 | ||||
854 | void BrowseBox::SetTitleLines( sal_uInt16 nLines ) | |||
855 | { | |||
856 | ||||
857 | nTitleLines = nLines; | |||
858 | } | |||
859 | ||||
860 | long BrowseBox::ScrollColumns( long nCols ) | |||
861 | { | |||
862 | ||||
863 | if ( nFirstCol + nCols < 0 || | |||
864 | nFirstCol + nCols >= static_cast<long>(mvCols.size()) ) | |||
865 | return 0; | |||
866 | ||||
867 | // implicitly hides cursor while scrolling | |||
868 | StartScroll(); | |||
869 | bScrolling = true; | |||
870 | bool bScrollable = pDataWin->GetBackground().IsScrollable(); | |||
871 | bool bInvalidateView = false; | |||
872 | ||||
873 | // scrolling one column to the right? | |||
874 | if ( nCols == 1 ) | |||
875 | { | |||
876 | // update internal value and scrollbar | |||
877 | ++nFirstCol; | |||
878 | aHScroll->SetThumbPos( nFirstCol - FrozenColCount() ); | |||
879 | ||||
880 | if ( !bScrollable ) | |||
881 | { | |||
882 | bInvalidateView = true; | |||
883 | } | |||
884 | else | |||
885 | { | |||
886 | long nDelta = mvCols[ nFirstCol-1 ]->Width(); | |||
887 | long nFrozenWidth = GetFrozenWidth(); | |||
888 | ||||
889 | tools::Rectangle aScrollRect( Point( nFrozenWidth + nDelta, 0 ), | |||
890 | Size ( GetOutputSizePixel().Width() - nFrozenWidth - nDelta, | |||
891 | GetTitleHeight() - 1 | |||
892 | ) ); | |||
893 | ||||
894 | // scroll the header bar area (if there is no dedicated HeaderBar control) | |||
895 | if ( !pDataWin->pHeaderBar && nTitleLines ) | |||
896 | { | |||
897 | // actually scroll | |||
898 | Scroll( -nDelta, 0, aScrollRect, SCROLL_FLAGS(ScrollFlags::Clip | ScrollFlags::NoChildren) ); | |||
899 | ||||
900 | // invalidate the area of the column which was scrolled out to the left hand side | |||
901 | tools::Rectangle aInvalidateRect( aScrollRect ); | |||
902 | aInvalidateRect.SetLeft( nFrozenWidth ); | |||
903 | aInvalidateRect.SetRight( nFrozenWidth + nDelta - 1 ); | |||
904 | Invalidate( aInvalidateRect ); | |||
905 | } | |||
906 | ||||
907 | // scroll the data-area | |||
908 | aScrollRect.SetBottom( pDataWin->GetOutputSizePixel().Height() ); | |||
909 | ||||
910 | // actually scroll | |||
911 | pDataWin->Scroll( -nDelta, 0, aScrollRect, SCROLL_FLAGS(ScrollFlags::Clip | ScrollFlags::NoChildren) ); | |||
912 | ||||
913 | // invalidate the area of the column which was scrolled out to the left hand side | |||
914 | aScrollRect.SetLeft( nFrozenWidth ); | |||
915 | aScrollRect.SetRight( nFrozenWidth + nDelta - 1 ); | |||
916 | pDataWin->Invalidate( aScrollRect ); | |||
917 | } | |||
918 | } | |||
919 | ||||
920 | // scrolling one column to the left? | |||
921 | else if ( nCols == -1 ) | |||
922 | { | |||
923 | --nFirstCol; | |||
924 | aHScroll->SetThumbPos( nFirstCol - FrozenColCount() ); | |||
925 | ||||
926 | if ( !bScrollable ) | |||
927 | { | |||
928 | bInvalidateView = true; | |||
929 | } | |||
930 | else | |||
931 | { | |||
932 | long nDelta = mvCols[ nFirstCol ]->Width(); | |||
933 | long nFrozenWidth = GetFrozenWidth(); | |||
934 | ||||
935 | tools::Rectangle aScrollRect( Point( nFrozenWidth, 0 ), | |||
936 | Size ( GetOutputSizePixel().Width() - nFrozenWidth, | |||
937 | GetTitleHeight() - 1 | |||
938 | ) ); | |||
939 | ||||
940 | // scroll the header bar area (if there is no dedicated HeaderBar control) | |||
941 | if ( !pDataWin->pHeaderBar && nTitleLines ) | |||
942 | { | |||
943 | Scroll( nDelta, 0, aScrollRect, SCROLL_FLAGS(ScrollFlags::Clip | ScrollFlags::NoChildren) ); | |||
944 | } | |||
945 | ||||
946 | // scroll the data-area | |||
947 | aScrollRect.SetBottom( pDataWin->GetOutputSizePixel().Height() ); | |||
948 | pDataWin->Scroll( nDelta, 0, aScrollRect, SCROLL_FLAGS(ScrollFlags::Clip | ScrollFlags::NoChildren) ); | |||
949 | } | |||
950 | } | |||
951 | else | |||
952 | { | |||
953 | if ( GetUpdateMode() ) | |||
954 | { | |||
955 | Invalidate( tools::Rectangle( | |||
956 | Point( GetFrozenWidth(), 0 ), | |||
957 | Size( GetOutputSizePixel().Width(), GetTitleHeight() ) ) ); | |||
958 | pDataWin->Invalidate( tools::Rectangle( | |||
959 | Point( GetFrozenWidth(), 0 ), | |||
960 | pDataWin->GetSizePixel() ) ); | |||
961 | } | |||
962 | ||||
963 | nFirstCol = nFirstCol + static_cast<sal_uInt16>(nCols); | |||
964 | aHScroll->SetThumbPos( nFirstCol - FrozenColCount() ); | |||
965 | } | |||
966 | ||||
967 | // adjust external headerbar, if necessary | |||
968 | if ( pDataWin->pHeaderBar ) | |||
969 | { | |||
970 | long nWidth = 0; | |||
971 | for ( size_t nCol = 0; | |||
972 | nCol < mvCols.size() && nCol < nFirstCol; | |||
973 | ++nCol ) | |||
974 | { | |||
975 | // not the handle column | |||
976 | if ( mvCols[ nCol ]->GetId() ) | |||
977 | nWidth += mvCols[ nCol ]->Width(); | |||
978 | } | |||
979 | ||||
980 | pDataWin->pHeaderBar->SetOffset( nWidth ); | |||
981 | } | |||
982 | ||||
983 | if( bInvalidateView ) | |||
984 | { | |||
985 | Control::Invalidate( InvalidateFlags::NoChildren ); | |||
986 | pDataWin->Window::Invalidate( InvalidateFlags::NoChildren ); | |||
987 | } | |||
988 | ||||
989 | // implicitly show cursor after scrolling | |||
990 | if ( nCols ) | |||
991 | { | |||
992 | pDataWin->Update(); | |||
993 | PaintImmediately(); | |||
994 | } | |||
995 | bScrolling = false; | |||
996 | EndScroll(); | |||
997 | ||||
998 | return nCols; | |||
999 | } | |||
1000 | ||||
1001 | ||||
1002 | long BrowseBox::ScrollRows( long nRows ) | |||
1003 | { | |||
1004 | // compute new top row | |||
1005 | long nTmpMin = std::min( static_cast<long>(nTopRow + nRows), static_cast<long>(nRowCount - 1) ); | |||
1006 | ||||
1007 | long nNewTopRow = std::max<long>( nTmpMin, 0 ); | |||
1008 | ||||
1009 | if ( nNewTopRow == nTopRow ) | |||
1010 | return 0; | |||
1011 | ||||
1012 | sal_uInt16 nVisibleRows = | |||
1013 | static_cast<sal_uInt16>(pDataWin->GetOutputSizePixel().Height() / GetDataRowHeight() + 1); | |||
1014 | ||||
1015 | VisibleRowsChanged(nNewTopRow, nVisibleRows); | |||
1016 | ||||
1017 | // compute new top row again (nTopRow might have changed!) | |||
1018 | nTmpMin = std::min( static_cast<long>(nTopRow + nRows), static_cast<long>(nRowCount - 1) ); | |||
1019 | ||||
1020 | nNewTopRow = std::max<long>( nTmpMin, 0 ); | |||
1021 | ||||
1022 | StartScroll(); | |||
1023 | ||||
1024 | // scroll area on screen and/or repaint | |||
1025 | long nDeltaY = GetDataRowHeight() * ( nNewTopRow - nTopRow ); | |||
1026 | long nOldTopRow = nTopRow; | |||
1027 | nTopRow = nNewTopRow; | |||
1028 | ||||
1029 | if ( GetUpdateMode() ) | |||
1030 | { | |||
1031 | pVScroll->SetRange( Range( 0L, nRowCount ) ); | |||
1032 | pVScroll->SetThumbPos( nTopRow ); | |||
1033 | ||||
1034 | if( pDataWin->GetBackground().IsScrollable() && | |||
1035 | std::abs( nDeltaY ) > 0 && | |||
1036 | std::abs( nDeltaY ) < pDataWin->GetSizePixel().Height() ) | |||
1037 | { | |||
1038 | pDataWin->Scroll( 0, static_cast<short>(-nDeltaY), SCROLL_FLAGS(ScrollFlags::Clip | ScrollFlags::NoChildren) ); | |||
1039 | } | |||
1040 | else | |||
1041 | pDataWin->Invalidate(); | |||
1042 | ||||
1043 | if ( nTopRow - nOldTopRow ) | |||
1044 | pDataWin->Update(); | |||
1045 | } | |||
1046 | ||||
1047 | EndScroll(); | |||
1048 | ||||
1049 | return nTopRow - nOldTopRow; | |||
1050 | } | |||
1051 | ||||
1052 | ||||
1053 | void BrowseBox::RowModified( long nRow, sal_uInt16 nColId ) | |||
1054 | { | |||
1055 | ||||
1056 | if ( !GetUpdateMode() ) | |||
1057 | return; | |||
1058 | ||||
1059 | tools::Rectangle aRect; | |||
1060 | if ( nColId == BROWSER_INVALIDID((sal_uInt16) 0xFFFF) ) | |||
1061 | // invalidate the whole row | |||
1062 | aRect = tools::Rectangle( Point( 0, (nRow-nTopRow) * GetDataRowHeight() ), | |||
1063 | Size( pDataWin->GetSizePixel().Width(), GetDataRowHeight() ) ); | |||
1064 | else | |||
1065 | { | |||
1066 | // invalidate the specific field | |||
1067 | aRect = GetFieldRectPixel( nRow, nColId, false ); | |||
1068 | } | |||
1069 | pDataWin->Invalidate( aRect ); | |||
1070 | } | |||
1071 | ||||
1072 | ||||
1073 | void BrowseBox::Clear() | |||
1074 | { | |||
1075 | ||||
1076 | // adjust the total number of rows | |||
1077 | DoHideCursor( "Clear" ); | |||
1078 | long nOldRowCount = nRowCount; | |||
1079 | nRowCount = 0; | |||
1080 | if(bMultiSelection) | |||
1081 | { | |||
1082 | assert(uRow.pSel)(static_cast <bool> (uRow.pSel) ? void (0) : __assert_fail ("uRow.pSel", "/home/maarten/src/libreoffice/core/svtools/source/brwbox/brwbox1.cxx" , 1082, __extension__ __PRETTY_FUNCTION__)); | |||
1083 | uRow.pSel->Reset(); | |||
1084 | } | |||
1085 | else | |||
1086 | uRow.nSel = BROWSER_ENDOFSELECTION(static_cast<long>((-1))); | |||
1087 | nCurRow = BROWSER_ENDOFSELECTION(static_cast<long>((-1))); | |||
1088 | nTopRow = 0; | |||
1089 | nCurColId = 0; | |||
1090 | ||||
1091 | // nFirstCol may not be reset, else the scrolling code will become confused. | |||
1092 | // nFirstCol may only be changed when adding or deleting columns | |||
1093 | // nFirstCol = 0; -> wrong! | |||
1094 | aHScroll->SetThumbPos( 0 ); | |||
1095 | pVScroll->SetThumbPos( 0 ); | |||
1096 | ||||
1097 | Invalidate(); | |||
1098 | UpdateScrollbars(); | |||
1099 | SetNoSelection(); | |||
1100 | DoShowCursor( "Clear" ); | |||
1101 | CursorMoved(); | |||
1102 | ||||
1103 | if ( !isAccessibleAlive() ) | |||
1104 | return; | |||
1105 | ||||
1106 | // all rows should be removed, so we remove the row header bar and append it again | |||
1107 | // to avoid to notify every row remove | |||
1108 | if ( nOldRowCount == nRowCount ) | |||
1109 | return; | |||
1110 | ||||
1111 | commitBrowseBoxEvent( | |||
1112 | CHILD, | |||
1113 | Any(), | |||
1114 | makeAny( m_pImpl->getAccessibleHeaderBar( vcl::BBTYPE_ROWHEADERBAR ) ) | |||
1115 | ); | |||
1116 | ||||
1117 | // and now append it again | |||
1118 | commitBrowseBoxEvent( | |||
1119 | CHILD, | |||
1120 | makeAny( m_pImpl->getAccessibleHeaderBar( vcl::BBTYPE_ROWHEADERBAR ) ), | |||
1121 | Any() | |||
1122 | ); | |||
1123 | ||||
1124 | // notify a table model change | |||
1125 | commitTableEvent( | |||
1126 | TABLE_MODEL_CHANGED, | |||
1127 | makeAny( AccessibleTableModelChange( DELETE, | |||
1128 | 0, | |||
1129 | nOldRowCount, | |||
1130 | 0, | |||
1131 | GetColumnCount()) | |||
1132 | ), | |||
1133 | Any() | |||
1134 | ); | |||
1135 | } | |||
1136 | ||||
1137 | void BrowseBox::RowInserted( long nRow, long nNumRows, bool bDoPaint, bool bKeepSelection ) | |||
1138 | { | |||
1139 | ||||
1140 | if (nRow < 0) | |||
1141 | nRow = 0; | |||
1142 | else if (nRow > nRowCount) // maximal = nRowCount | |||
1143 | nRow = nRowCount; | |||
1144 | ||||
1145 | if ( nNumRows <= 0 ) | |||
1146 | return; | |||
1147 | ||||
1148 | // adjust total row count | |||
1149 | bool bLastRow = nRow >= nRowCount; | |||
1150 | nRowCount += nNumRows; | |||
1151 | ||||
1152 | DoHideCursor( "RowInserted" ); | |||
1153 | ||||
1154 | // must we paint the new rows? | |||
1155 | long nOldCurRow = nCurRow; | |||
1156 | Size aSz = pDataWin->GetOutputSizePixel(); | |||
1157 | if ( bDoPaint && nRow >= nTopRow && | |||
1158 | nRow <= nTopRow + aSz.Height() / GetDataRowHeight() ) | |||
1159 | { | |||
1160 | long nY = (nRow-nTopRow) * GetDataRowHeight(); | |||
1161 | if ( !bLastRow ) | |||
1162 | { | |||
1163 | // scroll down the rows behind the new row | |||
1164 | pDataWin->SetClipRegion(); | |||
1165 | if( pDataWin->GetBackground().IsScrollable() ) | |||
1166 | { | |||
1167 | pDataWin->Scroll( 0, GetDataRowHeight() * nNumRows, | |||
1168 | tools::Rectangle( Point( 0, nY ), | |||
1169 | Size( aSz.Width(), aSz.Height() - nY ) ), | |||
1170 | SCROLL_FLAGS(ScrollFlags::Clip | ScrollFlags::NoChildren) ); | |||
1171 | } | |||
1172 | else | |||
1173 | pDataWin->Window::Invalidate( InvalidateFlags::NoChildren ); | |||
1174 | } | |||
1175 | else | |||
1176 | // scroll would cause a repaint, so we must explicitly invalidate | |||
1177 | pDataWin->Invalidate( tools::Rectangle( Point( 0, nY ), | |||
1178 | Size( aSz.Width(), nNumRows * GetDataRowHeight() ) ) ); | |||
1179 | } | |||
1180 | ||||
1181 | // correct top row if necessary | |||
1182 | if ( nRow < nTopRow ) | |||
1183 | nTopRow += nNumRows; | |||
1184 | ||||
1185 | // adjust the selection | |||
1186 | if ( bMultiSelection ) | |||
1187 | uRow.pSel->Insert( nRow, nNumRows ); | |||
1188 | else if ( uRow.nSel != BROWSER_ENDOFSELECTION(static_cast<long>((-1))) && nRow <= uRow.nSel ) | |||
1189 | uRow.nSel += nNumRows; | |||
1190 | ||||
1191 | // adjust the cursor | |||
1192 | if ( nCurRow == BROWSER_ENDOFSELECTION(static_cast<long>((-1))) ) | |||
1193 | GoToRow( 0, false, bKeepSelection ); | |||
1194 | else if ( nRow <= nCurRow ) | |||
1195 | { | |||
1196 | nCurRow += nNumRows; | |||
1197 | GoToRow( nCurRow, false, bKeepSelection ); | |||
1198 | } | |||
1199 | ||||
1200 | // adjust the vertical scrollbar | |||
1201 | if ( bDoPaint ) | |||
1202 | { | |||
1203 | UpdateScrollbars(); | |||
1204 | AutoSizeLastColumn(); | |||
1205 | } | |||
1206 | ||||
1207 | DoShowCursor( "RowInserted" ); | |||
1208 | // notify accessible that rows were inserted | |||
1209 | if ( isAccessibleAlive() ) | |||
1210 | { | |||
1211 | commitTableEvent( | |||
1212 | TABLE_MODEL_CHANGED, | |||
1213 | makeAny( AccessibleTableModelChange( | |||
1214 | INSERT, | |||
1215 | nRow, | |||
1216 | nRow + nNumRows, | |||
1217 | 0, | |||
1218 | GetColumnCount() | |||
1219 | ) | |||
1220 | ), | |||
1221 | Any() | |||
1222 | ); | |||
1223 | ||||
1224 | for (long i = nRow+1 ; i <= nRowCount ; ++i) | |||
1225 | { | |||
1226 | commitHeaderBarEvent( | |||
1227 | CHILD, | |||
1228 | makeAny( CreateAccessibleRowHeader( i ) ), | |||
1229 | Any(), | |||
1230 | false | |||
1231 | ); | |||
1232 | } | |||
1233 | } | |||
1234 | ||||
1235 | if ( nCurRow != nOldCurRow ) | |||
1236 | CursorMoved(); | |||
1237 | ||||
1238 | DBG_ASSERT(nRowCount > 0,"BrowseBox: nRowCount <= 0")do { if (true && (!(nRowCount > 0))) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.tools"), ("/home/maarten/src/libreoffice/core/svtools/source/brwbox/brwbox1.cxx" ":" "1238" ": "), "%s", "BrowseBox: nRowCount <= 0"); } } while (false); | |||
1239 | DBG_ASSERT(nCurRow >= 0,"BrowseBox: nCurRow < 0")do { if (true && (!(nCurRow >= 0))) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.tools"), ("/home/maarten/src/libreoffice/core/svtools/source/brwbox/brwbox1.cxx" ":" "1239" ": "), "%s", "BrowseBox: nCurRow < 0"); } } while (false); | |||
1240 | DBG_ASSERT(nCurRow < nRowCount,"nCurRow >= nRowCount")do { if (true && (!(nCurRow < nRowCount))) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.tools"), ("/home/maarten/src/libreoffice/core/svtools/source/brwbox/brwbox1.cxx" ":" "1240" ": "), "%s", "nCurRow >= nRowCount"); } } while (false); | |||
1241 | } | |||
1242 | ||||
1243 | ||||
1244 | void BrowseBox::RowRemoved( long nRow, long nNumRows, bool bDoPaint ) | |||
1245 | { | |||
1246 | ||||
1247 | if ( nRow < 0 ) | |||
1248 | nRow = 0; | |||
1249 | else if ( nRow >= nRowCount ) | |||
1250 | nRow = nRowCount - 1; | |||
1251 | ||||
1252 | if ( nNumRows <= 0 ) | |||
1253 | return; | |||
1254 | ||||
1255 | if ( nRowCount <= 0 ) | |||
1256 | return; | |||
1257 | ||||
1258 | if ( bDoPaint ) | |||
1259 | { | |||
1260 | // hide cursor and selection | |||
1261 | SAL_INFO("svtools", "BrowseBox::HideCursor " << this )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::HideCursor " << this) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_INFO ), ("svtools"), ("/home/maarten/src/libreoffice/core/svtools/source/brwbox/brwbox1.cxx" ":" "1261" ": "), ::sal::detail::unwrapStream( ::sal::detail ::StreamStart() << "BrowseBox::HideCursor " << this ), 0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream << "BrowseBox::HideCursor " << this; ::sal::detail ::log( (::SAL_DETAIL_LOG_LEVEL_INFO), ("svtools"), ("/home/maarten/src/libreoffice/core/svtools/source/brwbox/brwbox1.cxx" ":" "1261" ": "), sal_detail_stream, 0); }; break; case SAL_DETAIL_LOG_ACTION_FATAL : if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart () << "BrowseBox::HideCursor " << this) == 1) { :: sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_INFO), ("svtools"), ( "/home/maarten/src/libreoffice/core/svtools/source/brwbox/brwbox1.cxx" ":" "1261" ": "), ::sal::detail::unwrapStream( ::sal::detail ::StreamStart() << "BrowseBox::HideCursor " << this ), 0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream << "BrowseBox::HideCursor " << this; ::sal::detail ::log( (::SAL_DETAIL_LOG_LEVEL_INFO), ("svtools"), ("/home/maarten/src/libreoffice/core/svtools/source/brwbox/brwbox1.cxx" ":" "1261" ": "), sal_detail_stream, 0); }; std::abort(); break ; } } } while (false); | |||
1262 | ToggleSelection(); | |||
1263 | DoHideCursor( "RowRemoved" ); | |||
1264 | } | |||
1265 | ||||
1266 | // adjust total row count | |||
1267 | nRowCount -= nNumRows; | |||
1268 | if (nRowCount < 0) nRowCount = 0; | |||
1269 | long nOldCurRow = nCurRow; | |||
1270 | ||||
1271 | // adjust the selection | |||
1272 | if ( bMultiSelection ) | |||
1273 | // uRow.pSel->Remove( nRow, nNumRows ); | |||
1274 | for ( long i = 0; i < nNumRows; i++ ) | |||
1275 | uRow.pSel->Remove( nRow ); | |||
1276 | else if ( nRow < uRow.nSel && uRow.nSel >= nNumRows ) | |||
1277 | uRow.nSel -= nNumRows; | |||
1278 | else if ( nRow <= uRow.nSel ) | |||
1279 | uRow.nSel = BROWSER_ENDOFSELECTION(static_cast<long>((-1))); | |||
1280 | ||||
1281 | // adjust the cursor | |||
1282 | if ( nRowCount == 0 ) // don't compare nRowCount with nNumRows as nNumRows already was subtracted from nRowCount | |||
1283 | nCurRow = BROWSER_ENDOFSELECTION(static_cast<long>((-1))); | |||
1284 | else if ( nRow < nCurRow ) | |||
1285 | { | |||
1286 | nCurRow -= std::min( nCurRow - nRow, nNumRows ); | |||
1287 | // with the above nCurRow points a) to the first row after the removed block or b) to the same line | |||
1288 | // as before, but moved up nNumRows | |||
1289 | // case a) needs an additional correction if the last n lines were deleted, as 'the first row after the | |||
1290 | // removed block' is an invalid position then | |||
1291 | // FS - 09/28/99 - 68429 | |||
1292 | if (nCurRow == nRowCount) | |||
1293 | --nCurRow; | |||
1294 | } | |||
1295 | else if( nRow == nCurRow && nCurRow == nRowCount ) | |||
1296 | nCurRow = nRowCount-1; | |||
1297 | ||||
1298 | // is the deleted row visible? | |||
1299 | Size aSz = pDataWin->GetOutputSizePixel(); | |||
1300 | if ( nRow >= nTopRow && | |||
1301 | nRow <= nTopRow + aSz.Height() / GetDataRowHeight() ) | |||
1302 | { | |||
1303 | if ( bDoPaint ) | |||
1304 | { | |||
1305 | // scroll up the rows behind the deleted row | |||
1306 | // if there are Rows behind | |||
1307 | if (nRow < nRowCount) | |||
1308 | { | |||
1309 | long nY = (nRow-nTopRow) * GetDataRowHeight(); | |||
1310 | pDataWin->SetClipRegion(); | |||
1311 | if( pDataWin->GetBackground().IsScrollable() ) | |||
1312 | { | |||
1313 | pDataWin->Scroll( 0, - static_cast<short>(GetDataRowHeight()) * nNumRows, | |||
1314 | tools::Rectangle( Point( 0, nY ), Size( aSz.Width(), | |||
1315 | aSz.Height() - nY + nNumRows*GetDataRowHeight() ) ), | |||
1316 | SCROLL_FLAGS(ScrollFlags::Clip | ScrollFlags::NoChildren) ); | |||
1317 | } | |||
1318 | else | |||
1319 | pDataWin->Window::Invalidate( InvalidateFlags::NoChildren ); | |||
1320 | } | |||
1321 | else | |||
1322 | { | |||
1323 | // Repaint the Rect of the deleted row | |||
1324 | tools::Rectangle aRect( | |||
1325 | Point( 0, (nRow-nTopRow)*GetDataRowHeight() ), | |||
1326 | Size( pDataWin->GetSizePixel().Width(), | |||
1327 | nNumRows * GetDataRowHeight() ) ); | |||
1328 | pDataWin->Invalidate( aRect ); | |||
1329 | } | |||
1330 | } | |||
1331 | } | |||
1332 | // is the deleted row above of the visible area? | |||
1333 | else if ( nRow < nTopRow ) | |||
1334 | nTopRow = nTopRow >= nNumRows ? nTopRow-nNumRows : 0; | |||
1335 | ||||
1336 | if ( bDoPaint ) | |||
1337 | { | |||
1338 | // reshow cursor and selection | |||
1339 | ToggleSelection(); | |||
1340 | SAL_INFO("svtools", "BrowseBox::ShowCursor " << this )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::ShowCursor " << this) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_INFO ), ("svtools"), ("/home/maarten/src/libreoffice/core/svtools/source/brwbox/brwbox1.cxx" ":" "1340" ": "), ::sal::detail::unwrapStream( ::sal::detail ::StreamStart() << "BrowseBox::ShowCursor " << this ), 0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream << "BrowseBox::ShowCursor " << this; ::sal::detail ::log( (::SAL_DETAIL_LOG_LEVEL_INFO), ("svtools"), ("/home/maarten/src/libreoffice/core/svtools/source/brwbox/brwbox1.cxx" ":" "1340" ": "), sal_detail_stream, 0); }; break; case SAL_DETAIL_LOG_ACTION_FATAL : if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart () << "BrowseBox::ShowCursor " << this) == 1) { :: sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_INFO), ("svtools"), ( "/home/maarten/src/libreoffice/core/svtools/source/brwbox/brwbox1.cxx" ":" "1340" ": "), ::sal::detail::unwrapStream( ::sal::detail ::StreamStart() << "BrowseBox::ShowCursor " << this ), 0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream << "BrowseBox::ShowCursor " << this; ::sal::detail ::log( (::SAL_DETAIL_LOG_LEVEL_INFO), ("svtools"), ("/home/maarten/src/libreoffice/core/svtools/source/brwbox/brwbox1.cxx" ":" "1340" ": "), sal_detail_stream, 0); }; std::abort(); break ; } } } while (false); | |||
1341 | DoShowCursor( "RowRemoved" ); | |||
1342 | ||||
1343 | // adjust the vertical scrollbar | |||
1344 | UpdateScrollbars(); | |||
1345 | AutoSizeLastColumn(); | |||
1346 | } | |||
1347 | ||||
1348 | if ( isAccessibleAlive() ) | |||
1349 | { | |||
1350 | if ( nRowCount == 0 ) | |||
1351 | { | |||
1352 | // all columns should be removed, so we remove the column header bar and append it again | |||
1353 | // to avoid to notify every column remove | |||
1354 | commitBrowseBoxEvent( | |||
1355 | CHILD, | |||
1356 | Any(), | |||
1357 | makeAny( m_pImpl->getAccessibleHeaderBar( vcl::BBTYPE_ROWHEADERBAR ) ) | |||
1358 | ); | |||
1359 | ||||
1360 | // and now append it again | |||
1361 | commitBrowseBoxEvent( | |||
1362 | CHILD, | |||
1363 | makeAny(m_pImpl->getAccessibleHeaderBar(vcl::BBTYPE_ROWHEADERBAR)), | |||
1364 | Any() | |||
1365 | ); | |||
1366 | commitBrowseBoxEvent( | |||
1367 | CHILD, | |||
1368 | Any(), | |||
1369 | makeAny( m_pImpl->getAccessibleTable() ) | |||
1370 | ); | |||
1371 | ||||
1372 | // and now append it again | |||
1373 | commitBrowseBoxEvent( | |||
1374 | CHILD, | |||
1375 | makeAny( m_pImpl->getAccessibleTable() ), | |||
1376 | Any() | |||
1377 | ); | |||
1378 | } | |||
1379 | else | |||
1380 | { | |||
1381 | commitTableEvent( | |||
1382 | TABLE_MODEL_CHANGED, | |||
1383 | makeAny( AccessibleTableModelChange( | |||
1384 | DELETE, | |||
1385 | nRow, | |||
1386 | nRow + nNumRows, | |||
1387 | 0, | |||
1388 | GetColumnCount() | |||
1389 | ) | |||
1390 | ), | |||
1391 | Any() | |||
1392 | ); | |||
1393 | ||||
1394 | for (long i = nRow+1 ; i <= (nRow+nNumRows) ; ++i) | |||
1395 | { | |||
1396 | commitHeaderBarEvent( | |||
1397 | CHILD, | |||
1398 | Any(), | |||
1399 | makeAny( CreateAccessibleRowHeader( i ) ), | |||
1400 | false | |||
1401 | ); | |||
1402 | } | |||
1403 | } | |||
1404 | } | |||
1405 | ||||
1406 | if ( nOldCurRow != nCurRow ) | |||
1407 | CursorMoved(); | |||
1408 | ||||
1409 | DBG_ASSERT(nRowCount >= 0,"BrowseBox: nRowCount < 0")do { if (true && (!(nRowCount >= 0))) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.tools"), ("/home/maarten/src/libreoffice/core/svtools/source/brwbox/brwbox1.cxx" ":" "1409" ": "), "%s", "BrowseBox: nRowCount < 0"); } } while (false); | |||
1410 | DBG_ASSERT(nCurRow >= 0 || nRowCount == 0,"BrowseBox: nCurRow < 0 && nRowCount != 0")do { if (true && (!(nCurRow >= 0 || nRowCount == 0 ))) { sal_detail_logFormat((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.tools" ), ("/home/maarten/src/libreoffice/core/svtools/source/brwbox/brwbox1.cxx" ":" "1410" ": "), "%s", "BrowseBox: nCurRow < 0 && nRowCount != 0" ); } } while (false); | |||
1411 | DBG_ASSERT(nCurRow < nRowCount,"nCurRow >= nRowCount")do { if (true && (!(nCurRow < nRowCount))) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.tools"), ("/home/maarten/src/libreoffice/core/svtools/source/brwbox/brwbox1.cxx" ":" "1411" ": "), "%s", "nCurRow >= nRowCount"); } } while (false); | |||
1412 | } | |||
1413 | ||||
1414 | ||||
1415 | bool BrowseBox::GoToRow( long nRow) | |||
1416 | { | |||
1417 | return GoToRow(nRow, false); | |||
1418 | } | |||
1419 | ||||
1420 | ||||
1421 | bool BrowseBox::GoToRow( long nRow, bool bRowColMove, bool bKeepSelection ) | |||
1422 | { | |||
1423 | ||||
1424 | long nOldCurRow = nCurRow; | |||
1425 | ||||
1426 | // nothing to do? | |||
1427 | if ( nRow == nCurRow && ( bMultiSelection || uRow.nSel == nRow ) ) | |||
1428 | return true; | |||
1429 | ||||
1430 | // out of range? | |||
1431 | if ( nRow < 0 || nRow >= nRowCount ) | |||
1432 | return false; | |||
1433 | ||||
1434 | // not allowed? | |||
1435 | if ( !bRowColMove && !IsCursorMoveAllowed( nRow, nCurColId ) ) | |||
1436 | return false; | |||
1437 | ||||
1438 | // compute the last visible row | |||
1439 | Size aSz( pDataWin->GetSizePixel() ); | |||
1440 | sal_uInt16 nVisibleRows = sal_uInt16( aSz.Height() / GetDataRowHeight() - 1 ); | |||
1441 | long nLastRow = nTopRow + nVisibleRows; | |||
1442 | ||||
1443 | // suspend Updates | |||
1444 | pDataWin->EnterUpdateLock(); | |||
1445 | ||||
1446 | // remove old highlight, if necessary | |||
1447 | if ( !bMultiSelection && !bKeepSelection ) | |||
1448 | ToggleSelection(); | |||
1449 | DoHideCursor( "GoToRow" ); | |||
1450 | ||||
1451 | // must we scroll? | |||
1452 | bool bWasVisible = bSelectionIsVisible; | |||
1453 | if (! bMultiSelection) | |||
1454 | { | |||
1455 | if( !bKeepSelection ) | |||
1456 | bSelectionIsVisible = false; | |||
1457 | } | |||
1458 | if ( nRow < nTopRow ) | |||
1459 | ScrollRows( nRow - nTopRow ); | |||
1460 | else if ( nRow > nLastRow ) | |||
1461 | ScrollRows( nRow - nLastRow ); | |||
1462 | bSelectionIsVisible = bWasVisible; | |||
1463 | ||||
1464 | // adjust cursor (selection) and thumb | |||
1465 | if ( GetUpdateMode() ) | |||
1466 | pVScroll->SetThumbPos( nTopRow ); | |||
1467 | ||||
1468 | // relative positioning (because nCurRow might have changed in the meantime)! | |||
1469 | if (nCurRow != BROWSER_ENDOFSELECTION(static_cast<long>((-1))) ) | |||
1470 | nCurRow = nCurRow + (nRow - nOldCurRow); | |||
1471 | ||||
1472 | // make sure that the current position is valid | |||
1473 | if (nCurRow == BROWSER_ENDOFSELECTION(static_cast<long>((-1))) && nRowCount > 0) | |||
1474 | nCurRow = 0; | |||
1475 | else if ( nCurRow >= nRowCount ) | |||
1476 | nCurRow = nRowCount - 1; | |||
1477 | aSelRange = Range( nCurRow, nCurRow ); | |||
1478 | ||||
1479 | // display new highlight if necessary | |||
1480 | if ( !bMultiSelection && !bKeepSelection ) | |||
1481 | uRow.nSel = nRow; | |||
1482 | ||||
1483 | // resume Updates | |||
1484 | pDataWin->LeaveUpdateLock(); | |||
1485 | ||||
1486 | // Cursor+Highlight | |||
1487 | if ( !bMultiSelection && !bKeepSelection) | |||
1488 | ToggleSelection(); | |||
1489 | DoShowCursor( "GoToRow" ); | |||
1490 | if ( !bRowColMove && nOldCurRow != nCurRow ) | |||
1491 | CursorMoved(); | |||
1492 | ||||
1493 | if ( !bMultiSelection && !bKeepSelection ) | |||
1494 | { | |||
1495 | if ( !bSelecting ) | |||
1496 | Select(); | |||
1497 | else | |||
1498 | bSelect = true; | |||
1499 | } | |||
1500 | return true; | |||
1501 | } | |||
1502 | ||||
1503 | ||||
1504 | bool BrowseBox::GoToColumnId( sal_uInt16 nColId) | |||
1505 | { | |||
1506 | return GoToColumnId(nColId, true); | |||
1507 | } | |||
1508 | ||||
1509 | ||||
1510 | bool BrowseBox::GoToColumnId( sal_uInt16 nColId, bool bMakeVisible, bool bRowColMove) | |||
1511 | { | |||
1512 | if (!bColumnCursor) | |||
1513 | return false; | |||
1514 | ||||
1515 | // allowed? | |||
1516 | if (!bRowColMove && !IsCursorMoveAllowed( nCurRow, nColId ) ) | |||
1517 | return false; | |||
1518 | ||||
1519 | if ( nColId != nCurColId || (bMakeVisible && !IsFieldVisible(nCurRow, nColId, true))) | |||
1520 | { | |||
1521 | sal_uInt16 nNewPos = GetColumnPos(nColId); | |||
1522 | BrowserColumn* pColumn = (nNewPos < mvCols.size()) ? mvCols[ nNewPos ].get() : nullptr; | |||
1523 | DBG_ASSERT( pColumn, "no column object - invalid id?" )do { if (true && (!(pColumn))) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.tools"), ("/home/maarten/src/libreoffice/core/svtools/source/brwbox/brwbox1.cxx" ":" "1523" ": "), "%s", "no column object - invalid id?"); } } while (false); | |||
1524 | if ( !pColumn ) | |||
1525 | return false; | |||
1526 | ||||
1527 | DoHideCursor( "GoToColumnId" ); | |||
1528 | nCurColId = nColId; | |||
1529 | ||||
1530 | bool bScrolled = false; | |||
1531 | ||||
1532 | sal_uInt16 nFirstPos = nFirstCol; | |||
1533 | sal_uInt16 nWidth = static_cast<sal_uInt16>(pColumn->Width()); | |||
1534 | sal_uInt16 nLastPos = GetColumnAtXPosPixel( | |||
1535 | pDataWin->GetSizePixel().Width()-nWidth ); | |||
1536 | sal_uInt16 nFrozen = FrozenColCount(); | |||
1537 | if ( bMakeVisible && nLastPos && | |||
1538 | nNewPos >= nFrozen && ( nNewPos < nFirstPos || nNewPos > nLastPos ) ) | |||
1539 | { | |||
1540 | if ( nNewPos < nFirstPos ) | |||
1541 | ScrollColumns( nNewPos-nFirstPos ); | |||
1542 | else if ( nNewPos > nLastPos ) | |||
1543 | ScrollColumns( nNewPos-nLastPos ); | |||
1544 | bScrolled = true; | |||
1545 | } | |||
1546 | ||||
1547 | DoShowCursor( "GoToColumnId" ); | |||
1548 | if (!bRowColMove) | |||
1549 | { | |||
1550 | //try to move to nCurRow, nColId | |||
1551 | CursorMoveAttempt aAttempt(nCurRow, nColId, bScrolled); | |||
1552 | //Detect if we are already in a call to BrowseBox::GoToColumnId | |||
1553 | //but the attempt is impossible and we are simply recursing | |||
1554 | //into BrowseBox::GoToColumnId with the same impossible to | |||
1555 | //fulfill conditions | |||
1556 | if (m_aGotoStack.empty() || aAttempt != m_aGotoStack.top()) | |||
1557 | { | |||
1558 | m_aGotoStack.push(aAttempt); | |||
1559 | CursorMoved(); | |||
1560 | m_aGotoStack.pop(); | |||
1561 | } | |||
1562 | } | |||
1563 | return true; | |||
1564 | } | |||
1565 | return true; | |||
1566 | } | |||
1567 | ||||
1568 | ||||
1569 | bool BrowseBox::GoToRowColumnId( long nRow, sal_uInt16 nColId ) | |||
1570 | { | |||
1571 | ||||
1572 | // out of range? | |||
1573 | if ( nRow < 0 || nRow >= nRowCount ) | |||
1574 | return false; | |||
1575 | ||||
1576 | if (!bColumnCursor) | |||
1577 | return false; | |||
1578 | ||||
1579 | // nothing to do ? | |||
1580 | if ( nRow == nCurRow && ( bMultiSelection || uRow.nSel == nRow ) && | |||
1581 | nColId == nCurColId && IsFieldVisible(nCurRow, nColId, true)) | |||
1582 | return true; | |||
1583 | ||||
1584 | // allowed? | |||
1585 | if (!IsCursorMoveAllowed(nRow, nColId)) | |||
1586 | return false; | |||
1587 | ||||
1588 | DoHideCursor( "GoToRowColumnId" ); | |||
1589 | bool bMoved = GoToRow(nRow, true) && GoToColumnId(nColId, true, true); | |||
1590 | DoShowCursor( "GoToRowColumnId" ); | |||
1591 | ||||
1592 | if (bMoved) | |||
1593 | CursorMoved(); | |||
1594 | ||||
1595 | return bMoved; | |||
1596 | } | |||
1597 | ||||
1598 | ||||
1599 | void BrowseBox::SetNoSelection() | |||
1600 | { | |||
1601 | ||||
1602 | // is there no selection | |||
1603 | if ( ( !pColSel || !pColSel->GetSelectCount() ) && | |||
1604 | ( ( !bMultiSelection && uRow.nSel == BROWSER_ENDOFSELECTION(static_cast<long>((-1))) ) || | |||
1605 | ( bMultiSelection && !uRow.pSel->GetSelectCount() ) ) ) | |||
1606 | // nothing to do | |||
1607 | return; | |||
1608 | ||||
1609 | SAL_INFO("svtools", "BrowseBox::HideCursor " << this )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::HideCursor " << this) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_INFO ), ("svtools"), ("/home/maarten/src/libreoffice/core/svtools/source/brwbox/brwbox1.cxx" ":" "1609" ": "), ::sal::detail::unwrapStream( ::sal::detail ::StreamStart() << "BrowseBox::HideCursor " << this ), 0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream << "BrowseBox::HideCursor " << this; ::sal::detail ::log( (::SAL_DETAIL_LOG_LEVEL_INFO), ("svtools"), ("/home/maarten/src/libreoffice/core/svtools/source/brwbox/brwbox1.cxx" ":" "1609" ": "), sal_detail_stream, 0); }; break; case SAL_DETAIL_LOG_ACTION_FATAL : if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart () << "BrowseBox::HideCursor " << this) == 1) { :: sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_INFO), ("svtools"), ( "/home/maarten/src/libreoffice/core/svtools/source/brwbox/brwbox1.cxx" ":" "1609" ": "), ::sal::detail::unwrapStream( ::sal::detail ::StreamStart() << "BrowseBox::HideCursor " << this ), 0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream << "BrowseBox::HideCursor " << this; ::sal::detail ::log( (::SAL_DETAIL_LOG_LEVEL_INFO), ("svtools"), ("/home/maarten/src/libreoffice/core/svtools/source/brwbox/brwbox1.cxx" ":" "1609" ": "), sal_detail_stream, 0); }; std::abort(); break ; } } } while (false); | |||
1610 | ToggleSelection(); | |||
1611 | ||||
1612 | // unselect all | |||
1613 | if ( bMultiSelection ) | |||
1614 | uRow.pSel->SelectAll(false); | |||
1615 | else | |||
1616 | uRow.nSel = BROWSER_ENDOFSELECTION(static_cast<long>((-1))); | |||
1617 | if ( pColSel ) | |||
1618 | pColSel->SelectAll(false); | |||
1619 | if ( !bSelecting ) | |||
1620 | Select(); | |||
1621 | else | |||
1622 | bSelect = true; | |||
1623 | ||||
1624 | // restore screen | |||
1625 | SAL_INFO("svtools", "BrowseBox::ShowCursor " << this )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::ShowCursor " << this) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_INFO ), ("svtools"), ("/home/maarten/src/libreoffice/core/svtools/source/brwbox/brwbox1.cxx" ":" "1625" ": "), ::sal::detail::unwrapStream( ::sal::detail ::StreamStart() << "BrowseBox::ShowCursor " << this ), 0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream << "BrowseBox::ShowCursor " << this; ::sal::detail ::log( (::SAL_DETAIL_LOG_LEVEL_INFO), ("svtools"), ("/home/maarten/src/libreoffice/core/svtools/source/brwbox/brwbox1.cxx" ":" "1625" ": "), sal_detail_stream, 0); }; break; case SAL_DETAIL_LOG_ACTION_FATAL : if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart () << "BrowseBox::ShowCursor " << this) == 1) { :: sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_INFO), ("svtools"), ( "/home/maarten/src/libreoffice/core/svtools/source/brwbox/brwbox1.cxx" ":" "1625" ": "), ::sal::detail::unwrapStream( ::sal::detail ::StreamStart() << "BrowseBox::ShowCursor " << this ), 0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream << "BrowseBox::ShowCursor " << this; ::sal::detail ::log( (::SAL_DETAIL_LOG_LEVEL_INFO), ("svtools"), ("/home/maarten/src/libreoffice/core/svtools/source/brwbox/brwbox1.cxx" ":" "1625" ": "), sal_detail_stream, 0); }; std::abort(); break ; } } } while (false); | |||
1626 | ||||
1627 | if ( isAccessibleAlive() ) | |||
1628 | { | |||
1629 | commitTableEvent( | |||
1630 | SELECTION_CHANGED, | |||
1631 | Any(), | |||
1632 | Any() | |||
1633 | ); | |||
1634 | } | |||
1635 | } | |||
1636 | ||||
1637 | ||||
1638 | void BrowseBox::SelectAll() | |||
1639 | { | |||
1640 | ||||
1641 | if ( !bMultiSelection ) | |||
1642 | return; | |||
1643 | ||||
1644 | SAL_INFO("svtools", "BrowseBox::HideCursor " << this )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::HideCursor " << this) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_INFO ), ("svtools"), ("/home/maarten/src/libreoffice/core/svtools/source/brwbox/brwbox1.cxx" ":" "1644" ": "), ::sal::detail::unwrapStream( ::sal::detail ::StreamStart() << "BrowseBox::HideCursor " << this ), 0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream << "BrowseBox::HideCursor " << this; ::sal::detail ::log( (::SAL_DETAIL_LOG_LEVEL_INFO), ("svtools"), ("/home/maarten/src/libreoffice/core/svtools/source/brwbox/brwbox1.cxx" ":" "1644" ": "), sal_detail_stream, 0); }; break; case SAL_DETAIL_LOG_ACTION_FATAL : if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart () << "BrowseBox::HideCursor " << this) == 1) { :: sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_INFO), ("svtools"), ( "/home/maarten/src/libreoffice/core/svtools/source/brwbox/brwbox1.cxx" ":" "1644" ": "), ::sal::detail::unwrapStream( ::sal::detail ::StreamStart() << "BrowseBox::HideCursor " << this ), 0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream << "BrowseBox::HideCursor " << this; ::sal::detail ::log( (::SAL_DETAIL_LOG_LEVEL_INFO), ("svtools"), ("/home/maarten/src/libreoffice/core/svtools/source/brwbox/brwbox1.cxx" ":" "1644" ": "), sal_detail_stream, 0); }; std::abort(); break ; } } } while (false); | |||
1645 | ToggleSelection(); | |||
1646 | ||||
1647 | // select all rows | |||
1648 | if ( pColSel ) | |||
1649 | pColSel->SelectAll(false); | |||
1650 | uRow.pSel->SelectAll(); | |||
1651 | ||||
1652 | // don't highlight handle column | |||
1653 | BrowserColumn *pFirstCol = mvCols[ 0 ].get(); | |||
1654 | long nOfsX = pFirstCol->GetId() ? 0 : pFirstCol->Width(); | |||
1655 | ||||
1656 | // highlight the row selection | |||
1657 | if ( !bHideSelect ) | |||
1658 | { | |||
1659 | tools::Rectangle aHighlightRect; | |||
1660 | sal_uInt16 nVisibleRows = | |||
1661 | static_cast<sal_uInt16>(pDataWin->GetOutputSizePixel().Height() / GetDataRowHeight() + 1); | |||
1662 | for ( long nRow = std::max<long>( nTopRow, uRow.pSel->FirstSelected() ); | |||
1663 | nRow != BROWSER_ENDOFSELECTION(static_cast<long>((-1))) && nRow < nTopRow + nVisibleRows; | |||
1664 | nRow = uRow.pSel->NextSelected() ) | |||
1665 | aHighlightRect.Union( tools::Rectangle( | |||
1666 | Point( nOfsX, (nRow-nTopRow)*GetDataRowHeight() ), | |||
1667 | Size( pDataWin->GetSizePixel().Width(), GetDataRowHeight() ) ) ); | |||
1668 | pDataWin->Invalidate( aHighlightRect ); | |||
1669 | } | |||
1670 | ||||
1671 | if ( !bSelecting ) | |||
1672 | Select(); | |||
1673 | else | |||
1674 | bSelect = true; | |||
1675 | ||||
1676 | // restore screen | |||
1677 | SAL_INFO("svtools", "BrowseBox::ShowCursor " << this )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::ShowCursor " << this) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_INFO ), ("svtools"), ("/home/maarten/src/libreoffice/core/svtools/source/brwbox/brwbox1.cxx" ":" "1677" ": "), ::sal::detail::unwrapStream( ::sal::detail ::StreamStart() << "BrowseBox::ShowCursor " << this ), 0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream << "BrowseBox::ShowCursor " << this; ::sal::detail ::log( (::SAL_DETAIL_LOG_LEVEL_INFO), ("svtools"), ("/home/maarten/src/libreoffice/core/svtools/source/brwbox/brwbox1.cxx" ":" "1677" ": "), sal_detail_stream, 0); }; break; case SAL_DETAIL_LOG_ACTION_FATAL : if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart () << "BrowseBox::ShowCursor " << this) == 1) { :: sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_INFO), ("svtools"), ( "/home/maarten/src/libreoffice/core/svtools/source/brwbox/brwbox1.cxx" ":" "1677" ": "), ::sal::detail::unwrapStream( ::sal::detail ::StreamStart() << "BrowseBox::ShowCursor " << this ), 0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream << "BrowseBox::ShowCursor " << this; ::sal::detail ::log( (::SAL_DETAIL_LOG_LEVEL_INFO), ("svtools"), ("/home/maarten/src/libreoffice/core/svtools/source/brwbox/brwbox1.cxx" ":" "1677" ": "), sal_detail_stream, 0); }; std::abort(); break ; } } } while (false); | |||
1678 | ||||
1679 | if ( !isAccessibleAlive() ) | |||
1680 | return; | |||
1681 | ||||
1682 | commitTableEvent( | |||
1683 | SELECTION_CHANGED, | |||
1684 | Any(), | |||
1685 | Any() | |||
1686 | ); | |||
1687 | commitHeaderBarEvent( | |||
1688 | SELECTION_CHANGED, | |||
1689 | Any(), | |||
1690 | Any(), | |||
1691 | true | |||
1692 | ); // column header event | |||
1693 | ||||
1694 | commitHeaderBarEvent( | |||
1695 | SELECTION_CHANGED, | |||
1696 | Any(), | |||
1697 | Any(), | |||
1698 | false | |||
1699 | ); // row header event | |||
1700 | } | |||
1701 | ||||
1702 | ||||
1703 | void BrowseBox::SelectRow( long nRow, bool _bSelect, bool bExpand ) | |||
1704 | { | |||
1705 | ||||
1706 | if ( !bMultiSelection ) | |||
1707 | { | |||
1708 | // deselecting is impossible, selecting via cursor | |||
1709 | if ( _bSelect ) | |||
1710 | GoToRow(nRow, false); | |||
1711 | return; | |||
1712 | } | |||
1713 | ||||
1714 | SAL_INFO("svtools", "BrowseBox::HideCursor " << this )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::HideCursor " << this) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_INFO ), ("svtools"), ("/home/maarten/src/libreoffice/core/svtools/source/brwbox/brwbox1.cxx" ":" "1714" ": "), ::sal::detail::unwrapStream( ::sal::detail ::StreamStart() << "BrowseBox::HideCursor " << this ), 0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream << "BrowseBox::HideCursor " << this; ::sal::detail ::log( (::SAL_DETAIL_LOG_LEVEL_INFO), ("svtools"), ("/home/maarten/src/libreoffice/core/svtools/source/brwbox/brwbox1.cxx" ":" "1714" ": "), sal_detail_stream, 0); }; break; case SAL_DETAIL_LOG_ACTION_FATAL : if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart () << "BrowseBox::HideCursor " << this) == 1) { :: sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_INFO), ("svtools"), ( "/home/maarten/src/libreoffice/core/svtools/source/brwbox/brwbox1.cxx" ":" "1714" ": "), ::sal::detail::unwrapStream( ::sal::detail ::StreamStart() << "BrowseBox::HideCursor " << this ), 0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream << "BrowseBox::HideCursor " << this; ::sal::detail ::log( (::SAL_DETAIL_LOG_LEVEL_INFO), ("svtools"), ("/home/maarten/src/libreoffice/core/svtools/source/brwbox/brwbox1.cxx" ":" "1714" ": "), sal_detail_stream, 0); }; std::abort(); break ; } } } while (false); | |||
1715 | ||||
1716 | // remove old selection? | |||
1717 | if ( !bExpand || !bMultiSelection ) | |||
1718 | { | |||
1719 | ToggleSelection(); | |||
1720 | if ( bMultiSelection ) | |||
1721 | uRow.pSel->SelectAll(false); | |||
1722 | else | |||
1723 | uRow.nSel = BROWSER_ENDOFSELECTION(static_cast<long>((-1))); | |||
1724 | if ( pColSel ) | |||
1725 | pColSel->SelectAll(false); | |||
1726 | } | |||
1727 | ||||
1728 | // set new selection | |||
1729 | if ( !bHideSelect | |||
1730 | && ( ( bMultiSelection | |||
1731 | && uRow.pSel->GetTotalRange().Max() >= nRow | |||
1732 | && uRow.pSel->Select( nRow, _bSelect ) | |||
1733 | ) | |||
1734 | || ( !bMultiSelection | |||
1735 | && ( uRow.nSel = nRow ) != BROWSER_ENDOFSELECTION(static_cast<long>((-1))) ) | |||
1736 | ) | |||
1737 | ) | |||
1738 | { | |||
1739 | // don't highlight handle column | |||
1740 | BrowserColumn *pFirstCol = mvCols[ 0 ].get(); | |||
1741 | long nOfsX = pFirstCol->GetId() ? 0 : pFirstCol->Width(); | |||
1742 | ||||
1743 | // highlight only newly selected part | |||
1744 | tools::Rectangle aRect( | |||
1745 | Point( nOfsX, (nRow-nTopRow)*GetDataRowHeight() ), | |||
1746 | Size( pDataWin->GetSizePixel().Width(), GetDataRowHeight() ) ); | |||
1747 | pDataWin->Invalidate( aRect ); | |||
1748 | } | |||
1749 | ||||
1750 | if ( !bSelecting ) | |||
1751 | Select(); | |||
1752 | else | |||
1753 | bSelect = true; | |||
1754 | ||||
1755 | // restore screen | |||
1756 | SAL_INFO("svtools", "BrowseBox::ShowCursor " << this )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::ShowCursor " << this) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_INFO ), ("svtools"), ("/home/maarten/src/libreoffice/core/svtools/source/brwbox/brwbox1.cxx" ":" "1756" ": "), ::sal::detail::unwrapStream( ::sal::detail ::StreamStart() << "BrowseBox::ShowCursor " << this ), 0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream << "BrowseBox::ShowCursor " << this; ::sal::detail ::log( (::SAL_DETAIL_LOG_LEVEL_INFO), ("svtools"), ("/home/maarten/src/libreoffice/core/svtools/source/brwbox/brwbox1.cxx" ":" "1756" ": "), sal_detail_stream, 0); }; break; case SAL_DETAIL_LOG_ACTION_FATAL : if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart () << "BrowseBox::ShowCursor " << this) == 1) { :: sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_INFO), ("svtools"), ( "/home/maarten/src/libreoffice/core/svtools/source/brwbox/brwbox1.cxx" ":" "1756" ": "), ::sal::detail::unwrapStream( ::sal::detail ::StreamStart() << "BrowseBox::ShowCursor " << this ), 0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream << "BrowseBox::ShowCursor " << this; ::sal::detail ::log( (::SAL_DETAIL_LOG_LEVEL_INFO), ("svtools"), ("/home/maarten/src/libreoffice/core/svtools/source/brwbox/brwbox1.cxx" ":" "1756" ": "), sal_detail_stream, 0); }; std::abort(); break ; } } } while (false); | |||
1757 | ||||
1758 | if ( !isAccessibleAlive() ) | |||
1759 | return; | |||
1760 | ||||
1761 | commitTableEvent( | |||
1762 | SELECTION_CHANGED, | |||
1763 | Any(), | |||
1764 | Any() | |||
1765 | ); | |||
1766 | commitHeaderBarEvent( | |||
1767 | SELECTION_CHANGED, | |||
1768 | Any(), | |||
1769 | Any(), | |||
1770 | false | |||
1771 | ); // row header event | |||
1772 | } | |||
1773 | ||||
1774 | ||||
1775 | long BrowseBox::GetSelectRowCount() const | |||
1776 | { | |||
1777 | ||||
1778 | return bMultiSelection ? uRow.pSel->GetSelectCount() : | |||
1779 | uRow.nSel == BROWSER_ENDOFSELECTION(static_cast<long>((-1))) ? 0 : 1; | |||
1780 | } | |||
1781 | ||||
1782 | ||||
1783 | void BrowseBox::SelectColumnPos( sal_uInt16 nNewColPos, bool _bSelect, bool bMakeVisible ) | |||
1784 | { | |||
1785 | ||||
1786 | if ( !bColumnCursor || nNewColPos == BROWSER_INVALIDID((sal_uInt16) 0xFFFF) ) | |||
1787 | return; | |||
1788 | ||||
1789 | if ( !bMultiSelection ) | |||
1790 | { | |||
1791 | if ( _bSelect ) | |||
1792 | GoToColumnId( mvCols[ nNewColPos ]->GetId(), bMakeVisible ); | |||
1793 | return; | |||
1794 | } | |||
1795 | else | |||
1796 | { | |||
1797 | if ( !GoToColumnId( mvCols[ nNewColPos ]->GetId(), bMakeVisible ) ) | |||
1798 | return; | |||
1799 | } | |||
1800 | ||||
1801 | SAL_INFO("svtools", "BrowseBox::HideCursor " << this )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::HideCursor " << this) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_INFO ), ("svtools"), ("/home/maarten/src/libreoffice/core/svtools/source/brwbox/brwbox1.cxx" ":" "1801" ": "), ::sal::detail::unwrapStream( ::sal::detail ::StreamStart() << "BrowseBox::HideCursor " << this ), 0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream << "BrowseBox::HideCursor " << this; ::sal::detail ::log( (::SAL_DETAIL_LOG_LEVEL_INFO), ("svtools"), ("/home/maarten/src/libreoffice/core/svtools/source/brwbox/brwbox1.cxx" ":" "1801" ": "), sal_detail_stream, 0); }; break; case SAL_DETAIL_LOG_ACTION_FATAL : if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart () << "BrowseBox::HideCursor " << this) == 1) { :: sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_INFO), ("svtools"), ( "/home/maarten/src/libreoffice/core/svtools/source/brwbox/brwbox1.cxx" ":" "1801" ": "), ::sal::detail::unwrapStream( ::sal::detail ::StreamStart() << "BrowseBox::HideCursor " << this ), 0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream << "BrowseBox::HideCursor " << this; ::sal::detail ::log( (::SAL_DETAIL_LOG_LEVEL_INFO), ("svtools"), ("/home/maarten/src/libreoffice/core/svtools/source/brwbox/brwbox1.cxx" ":" "1801" ": "), sal_detail_stream, 0); }; std::abort(); break ; } } } while (false); | |||
1802 | ToggleSelection(); | |||
1803 | if ( bMultiSelection ) | |||
1804 | uRow.pSel->SelectAll(false); | |||
1805 | else | |||
1806 | uRow.nSel = BROWSER_ENDOFSELECTION(static_cast<long>((-1))); | |||
1807 | pColSel->SelectAll(false); | |||
1808 | ||||
1809 | if ( pColSel->Select( nNewColPos, _bSelect ) ) | |||
1810 | { | |||
1811 | // GoToColumnId( mvCols->GetObject(nNewColPos)->GetId(), bMakeVisible ); | |||
1812 | ||||
1813 | // only highlight painted areas | |||
1814 | pDataWin->Update(); | |||
1815 | tools::Rectangle aFieldRectPix( GetFieldRectPixel( nCurRow, nCurColId, false ) ); | |||
1816 | tools::Rectangle aRect( | |||
1817 | Point( aFieldRectPix.Left() - MIN_COLUMNWIDTH2, 0 ), | |||
1818 | Size( mvCols[ nNewColPos ]->Width(), | |||
1819 | pDataWin->GetOutputSizePixel().Height() ) ); | |||
1820 | pDataWin->Invalidate( aRect ); | |||
1821 | if ( !bSelecting ) | |||
1822 | Select(); | |||
1823 | else | |||
1824 | bSelect = true; | |||
1825 | ||||
1826 | if ( isAccessibleAlive() ) | |||
1827 | { | |||
1828 | commitTableEvent( | |||
1829 | SELECTION_CHANGED, | |||
1830 | Any(), | |||
1831 | Any() | |||
1832 | ); | |||
1833 | commitHeaderBarEvent( | |||
1834 | SELECTION_CHANGED, | |||
1835 | Any(), | |||
1836 | Any(), | |||
1837 | true | |||
1838 | ); // column header event | |||
1839 | } | |||
1840 | } | |||
1841 | ||||
1842 | // restore screen | |||
1843 | SAL_INFO("svtools", "BrowseBox::ShowCursor " << this )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::ShowCursor " << this) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_INFO ), ("svtools"), ("/home/maarten/src/libreoffice/core/svtools/source/brwbox/brwbox1.cxx" ":" "1843" ": "), ::sal::detail::unwrapStream( ::sal::detail ::StreamStart() << "BrowseBox::ShowCursor " << this ), 0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream << "BrowseBox::ShowCursor " << this; ::sal::detail ::log( (::SAL_DETAIL_LOG_LEVEL_INFO), ("svtools"), ("/home/maarten/src/libreoffice/core/svtools/source/brwbox/brwbox1.cxx" ":" "1843" ": "), sal_detail_stream, 0); }; break; case SAL_DETAIL_LOG_ACTION_FATAL : if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart () << "BrowseBox::ShowCursor " << this) == 1) { :: sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_INFO), ("svtools"), ( "/home/maarten/src/libreoffice/core/svtools/source/brwbox/brwbox1.cxx" ":" "1843" ": "), ::sal::detail::unwrapStream( ::sal::detail ::StreamStart() << "BrowseBox::ShowCursor " << this ), 0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream << "BrowseBox::ShowCursor " << this; ::sal::detail ::log( (::SAL_DETAIL_LOG_LEVEL_INFO), ("svtools"), ("/home/maarten/src/libreoffice/core/svtools/source/brwbox/brwbox1.cxx" ":" "1843" ": "), sal_detail_stream, 0); }; std::abort(); break ; } } } while (false); | |||
1844 | } | |||
1845 | ||||
1846 | ||||
1847 | sal_uInt16 BrowseBox::GetSelectColumnCount() const | |||
1848 | { | |||
1849 | ||||
1850 | // while bAutoSelect (==!pColSel), 1 if any rows (yes rows!) else none | |||
1851 | return pColSel ? static_cast<sal_uInt16>(pColSel->GetSelectCount()) : | |||
1852 | nCurRow >= 0 ? 1 : 0; | |||
1853 | } | |||
1854 | ||||
1855 | ||||
1856 | long BrowseBox::FirstSelectedColumn( ) const | |||
1857 | { | |||
1858 | return pColSel ? pColSel->FirstSelected() : BROWSER_ENDOFSELECTION(static_cast<long>((-1))); | |||
1859 | } | |||
1860 | ||||
1861 | ||||
1862 | long BrowseBox::FirstSelectedRow() | |||
1863 | { | |||
1864 | ||||
1865 | return bMultiSelection ? uRow.pSel->FirstSelected() : uRow.nSel; | |||
1866 | } | |||
1867 | ||||
1868 | ||||
1869 | long BrowseBox::NextSelectedRow() | |||
1870 | { | |||
1871 | ||||
1872 | return bMultiSelection ? uRow.pSel->NextSelected() : BROWSER_ENDOFSELECTION(static_cast<long>((-1))); | |||
1873 | } | |||
1874 | ||||
1875 | ||||
1876 | long BrowseBox::LastSelectedRow() | |||
1877 | { | |||
1878 | ||||
1879 | return bMultiSelection ? uRow.pSel->LastSelected() : uRow.nSel; | |||
1880 | } | |||
1881 | ||||
1882 | ||||
1883 | bool BrowseBox::IsRowSelected( long nRow ) const | |||
1884 | { | |||
1885 | ||||
1886 | return bMultiSelection ? uRow.pSel->IsSelected(nRow) : nRow == uRow.nSel; | |||
1887 | } | |||
1888 | ||||
1889 | ||||
1890 | bool BrowseBox::IsColumnSelected( sal_uInt16 nColumnId ) const | |||
1891 | { | |||
1892 | ||||
1893 | return pColSel ? pColSel->IsSelected( GetColumnPos(nColumnId) ) : | |||
1894 | nCurColId == nColumnId; | |||
1895 | } | |||
1896 | ||||
1897 | ||||
1898 | void BrowseBox::MakeFieldVisible | |||
1899 | ( | |||
1900 | long nRow, // line number of the field (starting with 0) | |||
1901 | sal_uInt16 nColId // column ID of the field | |||
1902 | ) | |||
1903 | ||||
1904 | /* [Description] | |||
1905 | ||||
1906 | Makes visible the field described in 'nRow' and 'nColId' by scrolling | |||
1907 | accordingly. | |||
1908 | ||||
1909 | */ | |||
1910 | ||||
1911 | { | |||
1912 | if (!pDataWin) | |||
1913 | return; | |||
1914 | ||||
1915 | Size aTestSize = pDataWin->GetSizePixel(); | |||
1916 | ||||
1917 | if ( !bBootstrapped || aTestSize.IsEmpty() ) | |||
1918 | return; | |||
1919 | ||||
1920 | // is it visible already? | |||
1921 | bool bVisible = IsFieldVisible( nRow, nColId, true/*bComplete*/ ); | |||
1922 | if ( bVisible ) | |||
1923 | return; | |||
1924 | ||||
1925 | // calculate column position, field rectangle and painting area | |||
1926 | sal_uInt16 nColPos = GetColumnPos( nColId ); | |||
1927 | tools::Rectangle aFieldRect = GetFieldRectPixel( nRow, nColId, false ); | |||
1928 | tools::Rectangle aDataRect( Point(0, 0), pDataWin->GetSizePixel() ); | |||
1929 | ||||
1930 | // positioned outside on the left? | |||
1931 | if ( nColPos >= FrozenColCount() && nColPos < nFirstCol ) | |||
1932 | // => scroll to the right | |||
1933 | ScrollColumns( nColPos - nFirstCol ); | |||
1934 | ||||
1935 | // while outside on the right | |||
1936 | while ( aDataRect.Right() < aFieldRect.Right() ) | |||
1937 | { | |||
1938 | // => scroll to the left | |||
1939 | if ( ScrollColumns( 1 ) != 1 ) | |||
1940 | // no more need to scroll | |||
1941 | break; | |||
1942 | aFieldRect = GetFieldRectPixel( nRow, nColId, false ); | |||
1943 | } | |||
1944 | ||||
1945 | // positioned outside above? | |||
1946 | if ( nRow < nTopRow ) | |||
1947 | // scroll further to the bottom | |||
1948 | ScrollRows( nRow - nTopRow ); | |||
1949 | ||||
1950 | // positioned outside below? | |||
1951 | long nBottomRow = nTopRow + GetVisibleRows(); | |||
1952 | // decrement nBottomRow to make it the number of the last visible line | |||
1953 | // (count starts with 0!). | |||
1954 | // Example: BrowseBox contains exactly one entry. nBottomRow := 0 + 1 - 1 | |||
1955 | if( nBottomRow ) | |||
1956 | nBottomRow--; | |||
1957 | ||||
1958 | if ( nRow > nBottomRow ) | |||
1959 | // scroll further to the top | |||
1960 | ScrollRows( nRow - nBottomRow ); | |||
1961 | } | |||
1962 | ||||
1963 | ||||
1964 | bool BrowseBox::IsFieldVisible( long nRow, sal_uInt16 nColumnId, | |||
1965 | bool bCompletely ) const | |||
1966 | { | |||
1967 | ||||
1968 | // hidden by frozen column? | |||
1969 | sal_uInt16 nColPos = GetColumnPos( nColumnId ); | |||
1970 | if ( nColPos >= FrozenColCount() && nColPos < nFirstCol ) | |||
1971 | return false; | |||
1972 | ||||
1973 | tools::Rectangle aRect( ImplFieldRectPixel( nRow, nColumnId ) ); | |||
1974 | if ( aRect.IsEmpty() ) | |||
1975 | return false; | |||
1976 | ||||
1977 | // get the visible area | |||
1978 | tools::Rectangle aOutRect( Point(0, 0), pDataWin->GetOutputSizePixel() ); | |||
1979 | ||||
1980 | if ( bCompletely ) | |||
1981 | // test if the field is completely visible | |||
1982 | return aOutRect.IsInside( aRect ); | |||
1983 | else | |||
1984 | // test if the field is partly of completely visible | |||
1985 | return !aOutRect.Intersection( aRect ).IsEmpty(); | |||
1986 | } | |||
1987 | ||||
1988 | ||||
1989 | tools::Rectangle BrowseBox::GetFieldRectPixel( long nRow, sal_uInt16 nColumnId, | |||
1990 | bool bRelToBrowser) const | |||
1991 | { | |||
1992 | ||||
1993 | // get the rectangle relative to DataWin | |||
1994 | tools::Rectangle aRect( ImplFieldRectPixel( nRow, nColumnId ) ); | |||
1995 | if ( aRect.IsEmpty() ) | |||
1996 | return aRect; | |||
1997 | ||||
1998 | // adjust relative to BrowseBox's output area | |||
1999 | Point aTopLeft( aRect.TopLeft() ); | |||
2000 | if ( bRelToBrowser ) | |||
2001 | { | |||
2002 | aTopLeft = pDataWin->OutputToScreenPixel( aTopLeft ); | |||
2003 | aTopLeft = ScreenToOutputPixel( aTopLeft ); | |||
2004 | } | |||
2005 | ||||
2006 | return tools::Rectangle( aTopLeft, aRect.GetSize() ); | |||
2007 | } | |||
2008 | ||||
2009 | ||||
2010 | tools::Rectangle BrowseBox::GetRowRectPixel( long nRow ) const | |||
2011 | { | |||
2012 | ||||
2013 | // get the rectangle relative to DataWin | |||
2014 | tools::Rectangle aRect; | |||
2015 | if ( nTopRow > nRow ) | |||
2016 | // row is above visible area | |||
2017 | return aRect; | |||
2018 | aRect = tools::Rectangle( | |||
2019 | Point( 0, GetDataRowHeight() * (nRow-nTopRow) ), | |||
2020 | Size( pDataWin->GetOutputSizePixel().Width(), GetDataRowHeight() ) ); | |||
2021 | if ( aRect.TopLeft().Y() > pDataWin->GetOutputSizePixel().Height() ) | |||
2022 | // row is below visible area | |||
2023 | return aRect; | |||
2024 | ||||
2025 | // adjust relative to BrowseBox's output area | |||
2026 | Point aTopLeft( aRect.TopLeft() ); | |||
2027 | aTopLeft = pDataWin->OutputToScreenPixel( aTopLeft ); | |||
2028 | aTopLeft = ScreenToOutputPixel( aTopLeft ); | |||
2029 | ||||
2030 | return tools::Rectangle( aTopLeft, aRect.GetSize() ); | |||
2031 | } | |||
2032 | ||||
2033 | ||||
2034 | tools::Rectangle BrowseBox::ImplFieldRectPixel( long nRow, sal_uInt16 nColumnId ) const | |||
2035 | { | |||
2036 | ||||
2037 | // compute the X-coordinate relative to DataWin by accumulation | |||
2038 | long nColX = 0; | |||
2039 | sal_uInt16 nFrozenCols = FrozenColCount(); | |||
2040 | size_t nCol; | |||
2041 | for ( nCol = 0; | |||
2042 | nCol < mvCols.size() && mvCols[ nCol ]->GetId() != nColumnId; | |||
2043 | ++nCol ) | |||
2044 | if ( mvCols[ nCol ]->IsFrozen() || nCol >= nFirstCol ) | |||
2045 | nColX += mvCols[ nCol ]->Width(); | |||
2046 | ||||
2047 | if ( nCol >= mvCols.size() || ( nCol >= nFrozenCols && nCol < nFirstCol ) ) | |||
2048 | return tools::Rectangle(); | |||
2049 | ||||
2050 | // compute the Y-coordinate relative to DataWin | |||
2051 | long nRowY = GetDataRowHeight(); | |||
2052 | if ( nRow != BROWSER_ENDOFSELECTION(static_cast<long>((-1))) ) // #105497# OJ | |||
2053 | nRowY = ( nRow - nTopRow ) * GetDataRowHeight(); | |||
2054 | ||||
2055 | // assemble the Rectangle relative to DataWin | |||
2056 | return tools::Rectangle( | |||
2057 | Point( nColX + MIN_COLUMNWIDTH2, nRowY ), | |||
2058 | Size( (mvCols[nCol]->Width() == LONG_MAX9223372036854775807L | |||
2059 | ? LONG_MAX9223372036854775807L - (nColX + MIN_COLUMNWIDTH2) : mvCols[ nCol ]->Width() - 2*MIN_COLUMNWIDTH2), | |||
2060 | GetDataRowHeight() - 1 ) ); | |||
2061 | } | |||
2062 | ||||
2063 | ||||
2064 | long BrowseBox::GetRowAtYPosPixel( long nY, bool bRelToBrowser ) const | |||
2065 | { | |||
2066 | ||||
2067 | // compute the Y-coordinate | |||
2068 | if ( bRelToBrowser ) | |||
2069 | { | |||
2070 | Point aDataTopLeft = pDataWin->OutputToScreenPixel( Point(0, 0) ); | |||
2071 | Point aTopLeft = OutputToScreenPixel( Point(0, 0) ); | |||
2072 | nY -= aDataTopLeft.Y() - aTopLeft.Y(); | |||
2073 | } | |||
2074 | ||||
2075 | // no row there (e.g. in the header) | |||
2076 | if ( nY < 0 || nY >= pDataWin->GetOutputSizePixel().Height() ) | |||
2077 | return -1; | |||
2078 | ||||
2079 | return nY / GetDataRowHeight() + nTopRow; | |||
2080 | } | |||
2081 | ||||
2082 | ||||
2083 | tools::Rectangle BrowseBox::GetFieldRect( sal_uInt16 nColumnId ) const | |||
2084 | { | |||
2085 | ||||
2086 | return GetFieldRectPixel( nCurRow, nColumnId ); | |||
2087 | } | |||
2088 | ||||
2089 | ||||
2090 | sal_uInt16 BrowseBox::GetColumnAtXPosPixel( long nX ) const | |||
2091 | { | |||
2092 | ||||
2093 | // accumulate the widths of the visible columns | |||
2094 | long nColX = 0; | |||
2095 | for ( size_t nCol = 0; nCol < mvCols.size(); ++nCol ) | |||
2096 | { | |||
2097 | BrowserColumn *pCol = mvCols[ nCol ].get(); | |||
2098 | if ( pCol->IsFrozen() || nCol >= nFirstCol ) | |||
2099 | nColX += pCol->Width(); | |||
2100 | ||||
2101 | if ( nColX > nX ) | |||
2102 | return nCol; | |||
2103 | } | |||
2104 | ||||
2105 | return BROWSER_INVALIDID((sal_uInt16) 0xFFFF); | |||
2106 | } | |||
2107 | ||||
2108 | bool BrowseBox::ReserveControlArea(sal_uInt16 nWidth) | |||
2109 | { | |||
2110 | if (nWidth != nControlAreaWidth) | |||
2111 | { | |||
2112 | OSL_ENSURE(nWidth,"Control area of 0 is not allowed, Use USHRT_MAX instead!")do { if (true && (!(nWidth))) { sal_detail_logFormat( (SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/svtools/source/brwbox/brwbox1.cxx" ":" "2112" ": "), "%s", "Control area of 0 is not allowed, Use USHRT_MAX instead!" ); } } while (false); | |||
2113 | nControlAreaWidth = nWidth; | |||
2114 | UpdateScrollbars(); | |||
2115 | return true; | |||
2116 | } | |||
2117 | return false; | |||
2118 | } | |||
2119 | ||||
2120 | tools::Rectangle BrowseBox::GetControlArea() const | |||
2121 | { | |||
2122 | auto nHeight = aHScroll->GetSizePixel().Height(); | |||
2123 | auto nEndRight = aHScroll->IsVisible() ? aHScroll->GetPosPixel().X() : GetOutputSizePixel().Width(); | |||
2124 | ||||
2125 | return tools::Rectangle( | |||
2126 | Point( 0, GetOutputSizePixel().Height() - nHeight ), | |||
2127 | Size( nEndRight, nHeight ) ); | |||
2128 | } | |||
2129 | ||||
2130 | void BrowseBox::SetMode( BrowserMode nMode ) | |||
2131 | { | |||
2132 | ||||
2133 | pDataWin->bAutoHScroll = BrowserMode::AUTO_HSCROLL == ( nMode & BrowserMode::AUTO_HSCROLL ); | |||
2134 | pDataWin->bAutoVScroll = BrowserMode::AUTO_VSCROLL == ( nMode & BrowserMode::AUTO_VSCROLL ); | |||
2135 | pDataWin->bNoHScroll = BrowserMode::NO_HSCROLL == ( nMode & BrowserMode::NO_HSCROLL ); | |||
2136 | pDataWin->bNoVScroll = BrowserMode::NO_VSCROLL == ( nMode & BrowserMode::NO_VSCROLL ); | |||
2137 | ||||
2138 | DBG_ASSERT( !( pDataWin->bAutoHScroll && pDataWin->bNoHScroll ),do { if (true && (!(!( pDataWin->bAutoHScroll && pDataWin->bNoHScroll )))) { sal_detail_logFormat((SAL_DETAIL_LOG_LEVEL_WARN ), ("legacy.tools"), ("/home/maarten/src/libreoffice/core/svtools/source/brwbox/brwbox1.cxx" ":" "2139" ": "), "%s", "BrowseBox::SetMode: AutoHScroll *and* NoHScroll?" ); } } while (false) | |||
2139 | "BrowseBox::SetMode: AutoHScroll *and* NoHScroll?" )do { if (true && (!(!( pDataWin->bAutoHScroll && pDataWin->bNoHScroll )))) { sal_detail_logFormat((SAL_DETAIL_LOG_LEVEL_WARN ), ("legacy.tools"), ("/home/maarten/src/libreoffice/core/svtools/source/brwbox/brwbox1.cxx" ":" "2139" ": "), "%s", "BrowseBox::SetMode: AutoHScroll *and* NoHScroll?" ); } } while (false); | |||
2140 | DBG_ASSERT( !( pDataWin->bAutoVScroll && pDataWin->bNoVScroll ),do { if (true && (!(!( pDataWin->bAutoVScroll && pDataWin->bNoVScroll )))) { sal_detail_logFormat((SAL_DETAIL_LOG_LEVEL_WARN ), ("legacy.tools"), ("/home/maarten/src/libreoffice/core/svtools/source/brwbox/brwbox1.cxx" ":" "2141" ": "), "%s", "BrowseBox::SetMode: AutoVScroll *and* NoVScroll?" ); } } while (false) | |||
2141 | "BrowseBox::SetMode: AutoVScroll *and* NoVScroll?" )do { if (true && (!(!( pDataWin->bAutoVScroll && pDataWin->bNoVScroll )))) { sal_detail_logFormat((SAL_DETAIL_LOG_LEVEL_WARN ), ("legacy.tools"), ("/home/maarten/src/libreoffice/core/svtools/source/brwbox/brwbox1.cxx" ":" "2141" ": "), "%s", "BrowseBox::SetMode: AutoVScroll *and* NoVScroll?" ); } } while (false); | |||
2142 | if ( pDataWin->bAutoHScroll ) | |||
2143 | pDataWin->bNoHScroll = false; | |||
2144 | if ( pDataWin->bAutoVScroll ) | |||
2145 | pDataWin->bNoVScroll = false; | |||
2146 | ||||
2147 | if ( pDataWin->bNoHScroll ) | |||
2148 | aHScroll->Hide(); | |||
2149 | ||||
2150 | nControlAreaWidth = USHRT_MAX(32767 *2 +1); | |||
2151 | ||||
2152 | long nOldRowSel = bMultiSelection ? uRow.pSel->FirstSelected() : uRow.nSel; | |||
2153 | MultiSelection *pOldRowSel = bMultiSelection ? uRow.pSel : nullptr; | |||
2154 | ||||
2155 | pVScroll.disposeAndClear(); | |||
2156 | ||||
2157 | bMultiSelection = bool( nMode & BrowserMode::MULTISELECTION ); | |||
2158 | bColumnCursor = bool( nMode & BrowserMode::COLUMNSELECTION ); | |||
2159 | bKeepHighlight = bool( nMode & BrowserMode::KEEPHIGHLIGHT ); | |||
2160 | ||||
2161 | bHideSelect = ((nMode & BrowserMode::HIDESELECT) == BrowserMode::HIDESELECT); | |||
2162 | // default: do not hide the cursor at all (untaken scrolling and such) | |||
2163 | bHideCursor = TRISTATE_FALSE; | |||
2164 | ||||
2165 | if ( BrowserMode::HIDECURSOR == ( nMode & BrowserMode::HIDECURSOR ) ) | |||
2166 | { | |||
2167 | bHideCursor = TRISTATE_TRUE; | |||
2168 | } | |||
2169 | ||||
2170 | m_bFocusOnlyCursor = ((nMode & BrowserMode::CURSOR_WO_FOCUS) == BrowserMode::NONE); | |||
2171 | ||||
2172 | bHLines = ( nMode & BrowserMode::HLINES ) == BrowserMode::HLINES; | |||
2173 | bVLines = ( nMode & BrowserMode::VLINES ) == BrowserMode::VLINES; | |||
2174 | ||||
2175 | constexpr WinBits nVScrollWinBits = WB_VSCROLL; | |||
2176 | pVScroll = ( nMode & BrowserMode::TRACKING_TIPS ) == BrowserMode::TRACKING_TIPS | |||
2177 | ? VclPtr<BrowserScrollBar>::Create( this, nVScrollWinBits, pDataWin.get() ) | |||
2178 | : VclPtr<ScrollBar>::Create( this, nVScrollWinBits ); | |||
2179 | pVScroll->SetLineSize( 1 ); | |||
2180 | pVScroll->SetPageSize(1); | |||
2181 | pVScroll->SetScrollHdl( LINK( this, BrowseBox, ScrollHdl )::tools::detail::makeLink( ::tools::detail::castTo<BrowseBox *>(this), &BrowseBox::LinkStubScrollHdl) ); | |||
2182 | ||||
2183 | pDataWin->bAutoSizeLastCol = | |||
2184 | BrowserMode::AUTOSIZE_LASTCOL == ( nMode & BrowserMode::AUTOSIZE_LASTCOL ); | |||
2185 | ||||
2186 | // create a headerbar. what happens, if a headerbar has to be created and | |||
2187 | // there already are columns? | |||
2188 | if ( BrowserMode::HEADERBAR_NEW == ( nMode & BrowserMode::HEADERBAR_NEW ) ) | |||
2189 | { | |||
2190 | if (!pDataWin->pHeaderBar) | |||
2191 | pDataWin->pHeaderBar = CreateHeaderBar( this ); | |||
2192 | } | |||
2193 | else | |||
2194 | { | |||
2195 | pDataWin->pHeaderBar.disposeAndClear(); | |||
2196 | } | |||
2197 | ||||
2198 | if ( bColumnCursor ) | |||
2199 | { | |||
2200 | if (!pColSel) | |||
2201 | pColSel.reset(new MultiSelection); | |||
2202 | pColSel->SetTotalRange( Range( 0, mvCols.size()-1 ) ); | |||
2203 | } | |||
2204 | else | |||
2205 | { | |||
2206 | pColSel.reset(); | |||
2207 | } | |||
2208 | ||||
2209 | if ( bMultiSelection ) | |||
2210 | { | |||
2211 | if ( pOldRowSel ) | |||
2212 | uRow.pSel = pOldRowSel; | |||
2213 | else | |||
2214 | uRow.pSel = new MultiSelection; | |||
2215 | } | |||
2216 | else | |||
2217 | { | |||
2218 | uRow.nSel = nOldRowSel; | |||
2219 | delete pOldRowSel; | |||
2220 | } | |||
2221 | ||||
2222 | if ( bBootstrapped ) | |||
2223 | { | |||
2224 | StateChanged( StateChangedType::InitShow ); | |||
2225 | if ( bMultiSelection && !pOldRowSel && | |||
2226 | nOldRowSel != BROWSER_ENDOFSELECTION(static_cast<long>((-1))) ) | |||
2227 | uRow.pSel->Select( nOldRowSel ); | |||
2228 | } | |||
2229 | ||||
2230 | if ( pDataWin ) | |||
2231 | pDataWin->Invalidate(); | |||
2232 | ||||
2233 | // no cursor on handle column | |||
2234 | if ( nCurColId == HandleColumnId ) | |||
2235 | nCurColId = GetColumnId( 1 ); | |||
2236 | ||||
2237 | m_nCurrentMode = nMode; | |||
2238 | } | |||
2239 | ||||
2240 | ||||
2241 | void BrowseBox::VisibleRowsChanged( long, sal_uInt16 ) | |||
2242 | { | |||
2243 | ||||
2244 | // old behavior: automatically correct NumRows: | |||
2245 | if ( nRowCount < GetRowCount() ) | |||
2246 | { | |||
2247 | RowInserted(nRowCount,GetRowCount() - nRowCount, false); | |||
2248 | } | |||
2249 | else if ( nRowCount > GetRowCount() ) | |||
2250 | { | |||
2251 | RowRemoved(nRowCount-(nRowCount - GetRowCount()),nRowCount - GetRowCount(), false); | |||
2252 | } | |||
2253 | } | |||
2254 | ||||
2255 | ||||
2256 | bool BrowseBox::IsCursorMoveAllowed( long, sal_uInt16 ) const | |||
2257 | ||||
2258 | /* [Description] | |||
2259 | ||||
2260 | This virtual method is always called before the cursor is moved directly. | |||
2261 | By means of 'return false', we avoid doing this if e.g. a record | |||
2262 | contradicts any rules. | |||
2263 | ||||
2264 | This method is not called, if the cursor movement results from removing or | |||
2265 | deleting a row/column (thus, in cases where only a "cursor correction" happens). | |||
2266 | ||||
2267 | The base implementation currently always returns true. | |||
2268 | */ | |||
2269 | ||||
2270 | { | |||
2271 | return true; | |||
2272 | } | |||
2273 | ||||
2274 | ||||
2275 | long BrowseBox::GetDataRowHeight() const | |||
2276 | { | |||
2277 | return CalcZoom(nDataRowHeight ? nDataRowHeight : ImpGetDataRowHeight()); | |||
2278 | } | |||
2279 | ||||
2280 | ||||
2281 | VclPtr<BrowserHeader> BrowseBox::CreateHeaderBar( BrowseBox* pParent ) | |||
2282 | { | |||
2283 | VclPtr<BrowserHeader> pNewBar = VclPtr<BrowserHeader>::Create( pParent ); | |||
2284 | pNewBar->SetStartDragHdl( LINK( this, BrowseBox, StartDragHdl )::tools::detail::makeLink( ::tools::detail::castTo<BrowseBox *>(this), &BrowseBox::LinkStubStartDragHdl) ); | |||
2285 | return pNewBar; | |||
2286 | } | |||
2287 | ||||
2288 | void BrowseBox::SetHeaderBar( BrowserHeader* pHeaderBar ) | |||
2289 | { | |||
2290 | pDataWin->pHeaderBar.disposeAndClear(); | |||
| ||||
2291 | pDataWin->pHeaderBar = pHeaderBar; | |||
2292 | pDataWin->pHeaderBar->SetStartDragHdl( LINK( this, BrowseBox, StartDragHdl )::tools::detail::makeLink( ::tools::detail::castTo<BrowseBox *>(this), &BrowseBox::LinkStubStartDragHdl) ); | |||
2293 | } | |||
2294 | ||||
2295 | long BrowseBox::GetTitleHeight() const | |||
2296 | { | |||
2297 | long nHeight; | |||
2298 | // ask the header bar for the text height (if possible), as the header bar's font is adjusted with | |||
2299 | // our (and the header's) zoom factor | |||
2300 | HeaderBar* pHeaderBar = pDataWin->pHeaderBar; | |||
2301 | if ( pHeaderBar ) | |||
2302 | nHeight = pHeaderBar->GetTextHeight(); | |||
2303 | else | |||
2304 | nHeight = GetTextHeight(); | |||
2305 | ||||
2306 | return nTitleLines ? nTitleLines * nHeight + 4 : 0; | |||
2307 | } | |||
2308 | ||||
2309 | long BrowseBox::CalcReverseZoom(long nVal) | |||
2310 | { | |||
2311 | if (IsZoom()) | |||
2312 | { | |||
2313 | const Fraction& rZoom = GetZoom(); | |||
2314 | double n = static_cast<double>(nVal); | |||
2315 | n *= static_cast<double>(rZoom.GetDenominator()); | |||
2316 | if (!rZoom.GetNumerator()) | |||
2317 | throw o3tl::divide_by_zero(); | |||
2318 | n /= static_cast<double>(rZoom.GetNumerator()); | |||
2319 | nVal = n>0 ? static_cast<long>(n + 0.5) : -static_cast<long>(-n + 0.5); | |||
2320 | } | |||
2321 | ||||
2322 | return nVal; | |||
2323 | } | |||
2324 | ||||
2325 | void BrowseBox::CursorMoved() | |||
2326 | { | |||
2327 | // before implementing more here, please adjust the EditBrowseBox | |||
2328 | ||||
2329 | if ( isAccessibleAlive() && HasFocus() ) | |||
2330 | commitTableEvent( | |||
2331 | ACTIVE_DESCENDANT_CHANGED, | |||
2332 | makeAny( CreateAccessibleCell( GetCurRow(),GetColumnPos( GetCurColumnId() ) ) ), | |||
2333 | Any() | |||
2334 | ); | |||
2335 | } | |||
2336 | ||||
2337 | void BrowseBox::LoseFocus() | |||
2338 | { | |||
2339 | SAL_INFO("svtools", "BrowseBox::LoseFocus " << this )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::LoseFocus " << this) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_INFO ), ("svtools"), ("/home/maarten/src/libreoffice/core/svtools/source/brwbox/brwbox1.cxx" ":" "2339" ": "), ::sal::detail::unwrapStream( ::sal::detail ::StreamStart() << "BrowseBox::LoseFocus " << this ), 0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream << "BrowseBox::LoseFocus " << this; ::sal::detail ::log( (::SAL_DETAIL_LOG_LEVEL_INFO), ("svtools"), ("/home/maarten/src/libreoffice/core/svtools/source/brwbox/brwbox1.cxx" ":" "2339" ": "), sal_detail_stream, 0); }; break; case SAL_DETAIL_LOG_ACTION_FATAL : if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart () << "BrowseBox::LoseFocus " << this) == 1) { :: sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_INFO), ("svtools"), ( "/home/maarten/src/libreoffice/core/svtools/source/brwbox/brwbox1.cxx" ":" "2339" ": "), ::sal::detail::unwrapStream( ::sal::detail ::StreamStart() << "BrowseBox::LoseFocus " << this ), 0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream << "BrowseBox::LoseFocus " << this; ::sal::detail ::log( (::SAL_DETAIL_LOG_LEVEL_INFO), ("svtools"), ("/home/maarten/src/libreoffice/core/svtools/source/brwbox/brwbox1.cxx" ":" "2339" ": "), sal_detail_stream, 0); }; std::abort(); break ; } } } while (false); | |||
2340 | ||||
2341 | if ( bHasFocus ) | |||
2342 | { | |||
2343 | SAL_INFO("svtools", "BrowseBox::HideCursor " << this )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::HideCursor " << this) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_INFO ), ("svtools"), ("/home/maarten/src/libreoffice/core/svtools/source/brwbox/brwbox1.cxx" ":" "2343" ": "), ::sal::detail::unwrapStream( ::sal::detail ::StreamStart() << "BrowseBox::HideCursor " << this ), 0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream << "BrowseBox::HideCursor " << this; ::sal::detail ::log( (::SAL_DETAIL_LOG_LEVEL_INFO), ("svtools"), ("/home/maarten/src/libreoffice/core/svtools/source/brwbox/brwbox1.cxx" ":" "2343" ": "), sal_detail_stream, 0); }; break; case SAL_DETAIL_LOG_ACTION_FATAL : if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart () << "BrowseBox::HideCursor " << this) == 1) { :: sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_INFO), ("svtools"), ( "/home/maarten/src/libreoffice/core/svtools/source/brwbox/brwbox1.cxx" ":" "2343" ": "), ::sal::detail::unwrapStream( ::sal::detail ::StreamStart() << "BrowseBox::HideCursor " << this ), 0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream << "BrowseBox::HideCursor " << this; ::sal::detail ::log( (::SAL_DETAIL_LOG_LEVEL_INFO), ("svtools"), ("/home/maarten/src/libreoffice/core/svtools/source/brwbox/brwbox1.cxx" ":" "2343" ": "), sal_detail_stream, 0); }; std::abort(); break ; } } } while (false); | |||
2344 | DoHideCursor( "LoseFocus" ); | |||
2345 | ||||
2346 | if ( !bKeepHighlight ) | |||
2347 | { | |||
2348 | ToggleSelection(); | |||
2349 | bSelectionIsVisible = false; | |||
2350 | } | |||
2351 | ||||
2352 | bHasFocus = false; | |||
2353 | } | |||
2354 | Control::LoseFocus(); | |||
2355 | } | |||
2356 | ||||
2357 | ||||
2358 | void BrowseBox::GetFocus() | |||
2359 | { | |||
2360 | SAL_INFO("svtools", "BrowseBox::GetFocus " << this )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::GetFocus " << this) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_INFO ), ("svtools"), ("/home/maarten/src/libreoffice/core/svtools/source/brwbox/brwbox1.cxx" ":" "2360" ": "), ::sal::detail::unwrapStream( ::sal::detail ::StreamStart() << "BrowseBox::GetFocus " << this ), 0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream << "BrowseBox::GetFocus " << this; ::sal::detail ::log( (::SAL_DETAIL_LOG_LEVEL_INFO), ("svtools"), ("/home/maarten/src/libreoffice/core/svtools/source/brwbox/brwbox1.cxx" ":" "2360" ": "), sal_detail_stream, 0); }; break; case SAL_DETAIL_LOG_ACTION_FATAL : if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart () << "BrowseBox::GetFocus " << this) == 1) { ::sal_detail_log ( (::SAL_DETAIL_LOG_LEVEL_INFO), ("svtools"), ("/home/maarten/src/libreoffice/core/svtools/source/brwbox/brwbox1.cxx" ":" "2360" ": "), ::sal::detail::unwrapStream( ::sal::detail ::StreamStart() << "BrowseBox::GetFocus " << this ), 0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream << "BrowseBox::GetFocus " << this; ::sal::detail ::log( (::SAL_DETAIL_LOG_LEVEL_INFO), ("svtools"), ("/home/maarten/src/libreoffice/core/svtools/source/brwbox/brwbox1.cxx" ":" "2360" ": "), sal_detail_stream, 0); }; std::abort(); break ; } } } while (false); | |||
2361 | ||||
2362 | if ( !bHasFocus ) | |||
2363 | { | |||
2364 | if ( !bSelectionIsVisible ) | |||
2365 | { | |||
2366 | bSelectionIsVisible = true; | |||
2367 | if ( bBootstrapped ) | |||
2368 | ToggleSelection(); | |||
2369 | } | |||
2370 | ||||
2371 | bHasFocus = true; | |||
2372 | DoShowCursor( "GetFocus" ); | |||
2373 | } | |||
2374 | Control::GetFocus(); | |||
2375 | } | |||
2376 | ||||
2377 | ||||
2378 | sal_uInt16 BrowseBox::GetVisibleRows() const | |||
2379 | { | |||
2380 | return static_cast<sal_uInt16>((pDataWin->GetOutputSizePixel().Height() - 1 )/ GetDataRowHeight() + 1); | |||
2381 | } | |||
2382 | ||||
2383 | BrowserDataWin& BrowseBox::GetDataWindow() const | |||
2384 | { | |||
2385 | return *pDataWin; | |||
2386 | } | |||
2387 | ||||
2388 | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |
1 | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
2 | /* |
3 | * This file is part of the LibreOffice project. |
4 | * |
5 | * This Source Code Form is subject to the terms of the Mozilla Public |
6 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
7 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. |
8 | * |
9 | * This file incorporates work covered by the following license notice: |
10 | * |
11 | * Licensed to the Apache Software Foundation (ASF) under one or more |
12 | * contributor license agreements. See the NOTICE file distributed |
13 | * with this work for additional information regarding copyright |
14 | * ownership. The ASF licenses this file to you under the Apache |
15 | * License, Version 2.0 (the "License"); you may not use this file |
16 | * except in compliance with the License. You may obtain a copy of |
17 | * the License at http://www.apache.org/licenses/LICENSE-2.0 . |
18 | */ |
19 | |
20 | #ifndef INCLUDED_VCL_PTR_HXX |
21 | #define INCLUDED_VCL_PTR_HXX |
22 | |
23 | #include <sal/config.h> |
24 | |
25 | #include <rtl/ref.hxx> |
26 | |
27 | #include <utility> |
28 | #include <type_traits> |
29 | |
30 | #ifdef DBG_UTIL |
31 | #ifndef _WIN32 |
32 | #include <vcl/vclmain.hxx> |
33 | #endif |
34 | #endif |
35 | |
36 | class VclReferenceBase; |
37 | |
38 | namespace vcl::detail { |
39 | |
40 | template<typename> |
41 | constexpr bool isIncompleteOrDerivedFromVclReferenceBase(...) { return true; } |
42 | |
43 | template<typename T> constexpr bool isIncompleteOrDerivedFromVclReferenceBase( |
44 | int (*)[sizeof(T)]) |
45 | { return std::is_base_of<VclReferenceBase, T>::value; } |
46 | |
47 | } // namespace vcl::detail |
48 | |
49 | /** |
50 | * A thin wrapper around rtl::Reference to implement the acquire and dispose semantics we want for references to vcl::Window subclasses. |
51 | * |
52 | * For more details on the design please see vcl/README.lifecycle |
53 | * |
54 | * @param reference_type must be a subclass of vcl::Window |
55 | */ |
56 | template <class reference_type> |
57 | class VclPtr |
58 | { |
59 | static_assert( |
60 | vcl::detail::isIncompleteOrDerivedFromVclReferenceBase<reference_type>( |
61 | nullptr), |
62 | "template argument type must be derived from VclReferenceBase"); |
63 | |
64 | ::rtl::Reference<reference_type> m_rInnerRef; |
65 | |
66 | public: |
67 | /** Constructor... |
68 | */ |
69 | VclPtr() |
70 | : m_rInnerRef() |
71 | {} |
72 | |
73 | /** Constructor... |
74 | */ |
75 | VclPtr (reference_type * pBody) |
76 | : m_rInnerRef(pBody) |
77 | {} |
78 | |
79 | /** Constructor... that doesn't take a ref. |
80 | */ |
81 | VclPtr (reference_type * pBody, __sal_NoAcquire) |
82 | : m_rInnerRef(pBody, SAL_NO_ACQUIRE) |
83 | {} |
84 | |
85 | /** Up-casting conversion constructor: Copies interface reference. |
86 | |
87 | Does not work for up-casts to ambiguous bases. For the special case of |
88 | up-casting to Reference< XInterface >, see the corresponding conversion |
89 | operator. |
90 | |
91 | @param rRef another reference |
92 | */ |
93 | template< class derived_type > |
94 | VclPtr( |
95 | const VclPtr< derived_type > & rRef, |
96 | typename std::enable_if< |
97 | std::is_base_of<reference_type, derived_type>::value, int>::type |
98 | = 0 ) |
99 | : m_rInnerRef( static_cast<reference_type*>(rRef) ) |
100 | { |
101 | } |
102 | |
103 | #if defined(DBG_UTIL) && !defined(_WIN32) |
104 | virtual ~VclPtr() |
105 | { |
106 | assert(m_rInnerRef.get() == nullptr || vclmain::isAlive())(static_cast <bool> (m_rInnerRef.get() == nullptr || vclmain ::isAlive()) ? void (0) : __assert_fail ("m_rInnerRef.get() == nullptr || vclmain::isAlive()" , "/home/maarten/src/libreoffice/core/include/vcl/vclptr.hxx" , 106, __extension__ __PRETTY_FUNCTION__)); |
107 | // We can be one of the intermediate counts, but if we are the last |
108 | // VclPtr keeping this object alive, then something forgot to call dispose(). |
109 | assert((!m_rInnerRef.get() || m_rInnerRef->isDisposed() || m_rInnerRef->getRefCount() > 1)(static_cast <bool> ((!m_rInnerRef.get() || m_rInnerRef ->isDisposed() || m_rInnerRef->getRefCount() > 1) && "someone forgot to call dispose()") ? void (0) : __assert_fail ("(!m_rInnerRef.get() || m_rInnerRef->isDisposed() || m_rInnerRef->getRefCount() > 1) && \"someone forgot to call dispose()\"" , "/home/maarten/src/libreoffice/core/include/vcl/vclptr.hxx" , 110, __extension__ __PRETTY_FUNCTION__)) |
110 | && "someone forgot to call dispose()")(static_cast <bool> ((!m_rInnerRef.get() || m_rInnerRef ->isDisposed() || m_rInnerRef->getRefCount() > 1) && "someone forgot to call dispose()") ? void (0) : __assert_fail ("(!m_rInnerRef.get() || m_rInnerRef->isDisposed() || m_rInnerRef->getRefCount() > 1) && \"someone forgot to call dispose()\"" , "/home/maarten/src/libreoffice/core/include/vcl/vclptr.hxx" , 110, __extension__ __PRETTY_FUNCTION__)); |
111 | } |
112 | VclPtr(VclPtr const &) = default; |
113 | VclPtr(VclPtr &&) = default; |
114 | VclPtr & operator =(VclPtr const &) = default; |
115 | VclPtr & operator =(VclPtr &&) = default; |
116 | #endif |
117 | |
118 | /** |
119 | * A construction helper for VclPtr. Since VclPtr types are created |
120 | * with a reference-count of one - to help fit into the existing |
121 | * code-flow; this helps us to construct them easily. |
122 | * |
123 | * For more details on the design please see vcl/README.lifecycle |
124 | * |
125 | * @tparam reference_type must be a subclass of vcl::Window |
126 | */ |
127 | template<typename... Arg> [[nodiscard]] static VclPtr< reference_type > Create(Arg &&... arg) |
128 | { |
129 | return VclPtr< reference_type >( new reference_type(std::forward<Arg>(arg)...), SAL_NO_ACQUIRE ); |
130 | } |
131 | |
132 | /** Probably most common used: handle->someBodyOp(). |
133 | */ |
134 | reference_type * operator->() const |
135 | { |
136 | return m_rInnerRef.get(); |
137 | } |
138 | |
139 | /** Get the body. Can be used instead of operator->(). |
140 | I.e. handle->someBodyOp() and handle.get()->someBodyOp() |
141 | are the same. |
142 | */ |
143 | reference_type * get() const |
144 | { |
145 | return m_rInnerRef.get(); |
146 | } |
147 | |
148 | void set(reference_type *pBody) |
149 | { |
150 | m_rInnerRef.set(pBody); |
151 | } |
152 | |
153 | void reset(reference_type *pBody) |
154 | { |
155 | m_rInnerRef.set(pBody); |
156 | } |
157 | |
158 | /** Up-casting copy assignment operator. |
159 | |
160 | Does not work for up-casts to ambiguous bases. |
161 | |
162 | @param rRef another reference |
163 | */ |
164 | template<typename derived_type> |
165 | typename std::enable_if< |
166 | std::is_base_of<reference_type, derived_type>::value, |
167 | VclPtr &>::type |
168 | operator =(VclPtr<derived_type> const & rRef) |
169 | { |
170 | m_rInnerRef.set(rRef.get()); |
171 | return *this; |
172 | } |
173 | |
174 | VclPtr & operator =(reference_type * pBody) |
175 | { |
176 | m_rInnerRef.set(pBody); |
177 | return *this; |
178 | } |
179 | |
180 | operator reference_type * () const |
181 | { |
182 | return m_rInnerRef.get(); |
183 | } |
184 | |
185 | explicit operator bool () const |
186 | { |
187 | return m_rInnerRef.get() != nullptr; |
188 | } |
189 | |
190 | void clear() |
191 | { |
192 | m_rInnerRef.clear(); |
193 | } |
194 | |
195 | void reset() |
196 | { |
197 | m_rInnerRef.clear(); |
198 | } |
199 | |
200 | void disposeAndClear() |
201 | { |
202 | // hold it alive for the lifetime of this method |
203 | ::rtl::Reference<reference_type> aTmp(m_rInnerRef); |
204 | m_rInnerRef.clear(); // we should use some 'swap' method ideally ;-) |
205 | if (aTmp.get()) { |
206 | aTmp->disposeOnce(); |
207 | } |
208 | } |
209 | |
210 | /** Needed to place VclPtr's into STL collection. |
211 | */ |
212 | bool operator< (const VclPtr<reference_type> & handle) const |
213 | { |
214 | return (m_rInnerRef < handle.m_rInnerRef); |
215 | } |
216 | }; // class VclPtr |
217 | |
218 | template<typename T1, typename T2> |
219 | inline bool operator ==(VclPtr<T1> const & p1, VclPtr<T2> const & p2) { |
220 | return p1.get() == p2.get(); |
221 | } |
222 | |
223 | template<typename T> inline bool operator ==(VclPtr<T> const & p1, T const * p2) |
224 | { |
225 | return p1.get() == p2; |
226 | } |
227 | |
228 | template<typename T> inline bool operator ==(VclPtr<T> const & p1, T * p2) { |
229 | return p1.get() == p2; |
230 | } |
231 | |
232 | template<typename T> inline bool operator ==(T const * p1, VclPtr<T> const & p2) |
233 | { |
234 | return p1 == p2.get(); |
235 | } |
236 | |
237 | template<typename T> inline bool operator ==(T * p1, VclPtr<T> const & p2) { |
238 | return p1 == p2.get(); |
239 | } |
240 | |
241 | template<typename T1, typename T2> |
242 | inline bool operator !=(VclPtr<T1> const & p1, VclPtr<T2> const & p2) { |
243 | return !(p1 == p2); |
244 | } |
245 | |
246 | template<typename T> inline bool operator !=(VclPtr<T> const & p1, T const * p2) |
247 | { |
248 | return !(p1 == p2); |
249 | } |
250 | |
251 | template<typename T> inline bool operator !=(VclPtr<T> const & p1, T * p2) { |
252 | return !(p1 == p2); |
253 | } |
254 | |
255 | template<typename T> inline bool operator !=(T const * p1, VclPtr<T> const & p2) |
256 | { |
257 | return !(p1 == p2); |
258 | } |
259 | |
260 | template<typename T> inline bool operator !=(T * p1, VclPtr<T> const & p2) { |
261 | return !(p1 == p2); |
262 | } |
263 | |
264 | /** |
265 | * A construction helper for a temporary VclPtr. Since VclPtr types |
266 | * are created with a reference-count of one - to help fit into |
267 | * the existing code-flow; this helps us to construct them easily. |
268 | * see also VclPtr::Create and ScopedVclPtr |
269 | * |
270 | * For more details on the design please see vcl/README.lifecycle |
271 | * |
272 | * @param reference_type must be a subclass of vcl::Window |
273 | */ |
274 | template <class reference_type> |
275 | class SAL_WARN_UNUSED__attribute__((warn_unused)) VclPtrInstance final : public VclPtr<reference_type> |
276 | { |
277 | public: |
278 | template<typename... Arg> VclPtrInstance(Arg &&... arg) |
279 | : VclPtr<reference_type>( new reference_type(std::forward<Arg>(arg)...), SAL_NO_ACQUIRE ) |
280 | { |
281 | } |
282 | |
283 | /** |
284 | * Override and disallow this, to prevent people accidentally calling it and actually |
285 | * getting VclPtr::Create and getting a naked VclPtr<> instance |
286 | */ |
287 | template<typename... Arg> static VclPtrInstance< reference_type > Create(Arg &&... ) = delete; |
288 | }; |
289 | |
290 | template <class reference_type> |
291 | class ScopedVclPtr : public VclPtr<reference_type> |
292 | { |
293 | public: |
294 | /** Constructor... |
295 | */ |
296 | ScopedVclPtr() |
297 | : VclPtr<reference_type>() |
298 | {} |
299 | |
300 | /** Constructor |
301 | */ |
302 | ScopedVclPtr (reference_type * pBody) |
303 | : VclPtr<reference_type>(pBody) |
304 | {} |
305 | |
306 | /** Copy constructor... |
307 | */ |
308 | ScopedVclPtr (const VclPtr<reference_type> & handle) |
309 | : VclPtr<reference_type>(handle) |
310 | {} |
311 | |
312 | /** |
313 | Assignment that releases the last reference. |
314 | */ |
315 | void disposeAndReset(reference_type *pBody) |
316 | { |
317 | if (pBody != this->get()) { |
318 | VclPtr<reference_type>::disposeAndClear(); |
319 | VclPtr<reference_type>::set(pBody); |
320 | } |
321 | } |
322 | |
323 | /** |
324 | Assignment that releases the last reference. |
325 | */ |
326 | ScopedVclPtr<reference_type>& operator = (reference_type * pBody) |
327 | { |
328 | disposeAndReset(pBody); |
329 | return *this; |
330 | } |
331 | |
332 | /** Up-casting conversion constructor: Copies interface reference. |
333 | |
334 | Does not work for up-casts to ambiguous bases. For the special case of |
335 | up-casting to Reference< XInterface >, see the corresponding conversion |
336 | operator. |
337 | |
338 | @param rRef another reference |
339 | */ |
340 | template< class derived_type > |
341 | ScopedVclPtr( |
342 | const VclPtr< derived_type > & rRef, |
343 | typename std::enable_if< |
344 | std::is_base_of<reference_type, derived_type>::value, int>::type |
345 | = 0 ) |
346 | : VclPtr<reference_type>( rRef ) |
347 | { |
348 | } |
349 | |
350 | /** Up-casting assignment operator. |
351 | |
352 | Does not work for up-casts to ambiguous bases. |
353 | |
354 | @param rRef another VclPtr |
355 | */ |
356 | template<typename derived_type> |
357 | typename std::enable_if< |
358 | std::is_base_of<reference_type, derived_type>::value, |
359 | ScopedVclPtr &>::type |
360 | operator =(VclPtr<derived_type> const & rRef) |
361 | { |
362 | disposeAndReset(rRef.get()); |
363 | return *this; |
364 | } |
365 | |
366 | /** |
367 | * Override and disallow this, to prevent people accidentally calling it and actually |
368 | * getting VclPtr::Create and getting a naked VclPtr<> instance |
369 | */ |
370 | template<typename... Arg> static ScopedVclPtr< reference_type > Create(Arg &&... ) = delete; |
371 | |
372 | ~ScopedVclPtr() |
373 | { |
374 | VclPtr<reference_type>::disposeAndClear(); |
375 | assert(VclPtr<reference_type>::get() == nullptr)(static_cast <bool> (VclPtr<reference_type>::get( ) == nullptr) ? void (0) : __assert_fail ("VclPtr<reference_type>::get() == nullptr" , "/home/maarten/src/libreoffice/core/include/vcl/vclptr.hxx" , 375, __extension__ __PRETTY_FUNCTION__)); // make sure there are no lingering references |
376 | } |
377 | |
378 | private: |
379 | // Most likely we don't want this default copy-constructor. |
380 | ScopedVclPtr (const ScopedVclPtr<reference_type> &) = delete; |
381 | // And certainly we don't want a default assignment operator. |
382 | ScopedVclPtr<reference_type>& operator = (const ScopedVclPtr<reference_type> &) = delete; |
383 | // And disallow reset as that doesn't call disposeAndClear on the original reference |
384 | void reset() = delete; |
385 | void reset(reference_type *pBody) = delete; |
386 | |
387 | protected: |
388 | ScopedVclPtr (reference_type * pBody, __sal_NoAcquire) |
389 | : VclPtr<reference_type>(pBody, SAL_NO_ACQUIRE) |
390 | {} |
391 | }; |
392 | |
393 | /** |
394 | * A construction helper for ScopedVclPtr. Since VclPtr types are created |
395 | * with a reference-count of one - to help fit into the existing |
396 | * code-flow; this helps us to construct them easily. |
397 | * |
398 | * For more details on the design please see vcl/README.lifecycle |
399 | * |
400 | * @param reference_type must be a subclass of vcl::Window |
401 | */ |
402 | #if defined _MSC_VER |
403 | #pragma warning(push) |
404 | #pragma warning(disable: 4521) // " multiple copy constructors specified" |
405 | #endif |
406 | template <class reference_type> |
407 | class SAL_WARN_UNUSED__attribute__((warn_unused)) ScopedVclPtrInstance final : public ScopedVclPtr<reference_type> |
408 | { |
409 | public: |
410 | template<typename... Arg> ScopedVclPtrInstance(Arg &&... arg) |
411 | : ScopedVclPtr<reference_type>( new reference_type(std::forward<Arg>(arg)...), SAL_NO_ACQUIRE ) |
412 | { |
413 | } |
414 | |
415 | /** |
416 | * Override and disallow this, to prevent people accidentally calling it and actually |
417 | * getting VclPtr::Create and getting a naked VclPtr<> instance |
418 | */ |
419 | template<typename... Arg> static ScopedVclPtrInstance< reference_type > Create(Arg &&...) = delete; |
420 | |
421 | private: |
422 | // Prevent the above perfect forwarding ctor from hijacking (accidental) |
423 | // attempts at ScopedVclPtrInstance copy construction (where the hijacking |
424 | // would typically lead to somewhat obscure error messages); both non-const |
425 | // and const variants are needed here, as the ScopedVclPtr base class has a |
426 | // const--variant copy ctor, so the implicitly declared copy ctor for |
427 | // ScopedVclPtrInstance would also be the const variant, so non-const copy |
428 | // construction attempts would be hijacked by the perfect forwarding ctor; |
429 | // but if we only declared a non-const variant here, the const variant would |
430 | // no longer be implicitly declared (as there would already be an explicitly |
431 | // declared copy ctor), so const copy construction attempts would then be |
432 | // hijacked by the perfect forwarding ctor: |
433 | ScopedVclPtrInstance(ScopedVclPtrInstance &) = delete; |
434 | ScopedVclPtrInstance(ScopedVclPtrInstance const &) = delete; |
435 | }; |
436 | #if defined _MSC_VER |
437 | #pragma warning(pop) |
438 | #endif |
439 | |
440 | #endif // INCLUDED_VCL_PTR_HXX |
441 | |
442 | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |
1 | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ | ||||||||
2 | /* | ||||||||
3 | * This file is part of the LibreOffice project. | ||||||||
4 | * | ||||||||
5 | * This Source Code Form is subject to the terms of the Mozilla Public | ||||||||
6 | * License, v. 2.0. If a copy of the MPL was not distributed with this | ||||||||
7 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||||||||
8 | * | ||||||||
9 | * This file incorporates work covered by the following license notice: | ||||||||
10 | * | ||||||||
11 | * Licensed to the Apache Software Foundation (ASF) under one or more | ||||||||
12 | * contributor license agreements. See the NOTICE file distributed | ||||||||
13 | * with this work for additional information regarding copyright | ||||||||
14 | * ownership. The ASF licenses this file to you under the Apache | ||||||||
15 | * License, Version 2.0 (the "License"); you may not use this file | ||||||||
16 | * except in compliance with the License. You may obtain a copy of | ||||||||
17 | * the License at http://www.apache.org/licenses/LICENSE-2.0 . | ||||||||
18 | */ | ||||||||
19 | |||||||||
20 | #ifndef INCLUDED_RTL_REF_HXX | ||||||||
21 | #define INCLUDED_RTL_REF_HXX | ||||||||
22 | |||||||||
23 | #include "sal/config.h" | ||||||||
24 | |||||||||
25 | #include <cassert> | ||||||||
26 | #include <cstddef> | ||||||||
27 | #include <functional> | ||||||||
28 | #ifdef LIBO_INTERNAL_ONLY1 | ||||||||
29 | #include <type_traits> | ||||||||
30 | #endif | ||||||||
31 | |||||||||
32 | #include "sal/types.h" | ||||||||
33 | |||||||||
34 | namespace rtl | ||||||||
35 | { | ||||||||
36 | |||||||||
37 | /** Template reference class for reference type. | ||||||||
38 | */ | ||||||||
39 | template <class reference_type> | ||||||||
40 | class Reference | ||||||||
41 | { | ||||||||
42 | /** The <b>reference_type</b> body pointer. | ||||||||
43 | */ | ||||||||
44 | reference_type * m_pBody; | ||||||||
45 | |||||||||
46 | |||||||||
47 | public: | ||||||||
48 | /** Constructor... | ||||||||
49 | */ | ||||||||
50 | Reference() | ||||||||
51 | : m_pBody (NULL__null) | ||||||||
52 | {} | ||||||||
53 | |||||||||
54 | |||||||||
55 | /** Constructor... | ||||||||
56 | */ | ||||||||
57 | Reference (reference_type * pBody, __sal_NoAcquire) | ||||||||
58 | : m_pBody (pBody) | ||||||||
59 | { | ||||||||
60 | } | ||||||||
61 | |||||||||
62 | /** Constructor... | ||||||||
63 | */ | ||||||||
64 | Reference (reference_type * pBody) | ||||||||
65 | : m_pBody (pBody) | ||||||||
66 | { | ||||||||
67 | if (m_pBody) | ||||||||
68 | m_pBody->acquire(); | ||||||||
69 | } | ||||||||
70 | |||||||||
71 | /** Copy constructor... | ||||||||
72 | */ | ||||||||
73 | Reference (const Reference<reference_type> & handle) | ||||||||
74 | : m_pBody (handle.m_pBody) | ||||||||
75 | { | ||||||||
76 | if (m_pBody) | ||||||||
77 | m_pBody->acquire(); | ||||||||
78 | } | ||||||||
79 | |||||||||
80 | #ifdef LIBO_INTERNAL_ONLY1 | ||||||||
81 | /** Move constructor... | ||||||||
82 | */ | ||||||||
83 | Reference (Reference<reference_type> && handle) noexcept | ||||||||
84 | : m_pBody (handle.m_pBody) | ||||||||
85 | { | ||||||||
86 | handle.m_pBody = nullptr; | ||||||||
87 | } | ||||||||
88 | #endif | ||||||||
89 | |||||||||
90 | #if defined LIBO_INTERNAL_ONLY1 | ||||||||
91 | /** Up-casting conversion constructor: Copies interface reference. | ||||||||
92 | |||||||||
93 | Does not work for up-casts to ambiguous bases. | ||||||||
94 | |||||||||
95 | @param rRef another reference | ||||||||
96 | */ | ||||||||
97 | template< class derived_type > | ||||||||
98 | inline Reference( | ||||||||
99 | const Reference< derived_type > & rRef, | ||||||||
100 | std::enable_if_t<std::is_base_of_v<reference_type, derived_type>, int> = 0 ) | ||||||||
101 | : m_pBody (rRef.get()) | ||||||||
102 | { | ||||||||
103 | if (m_pBody) | ||||||||
104 | m_pBody->acquire(); | ||||||||
105 | } | ||||||||
106 | #endif | ||||||||
107 | |||||||||
108 | /** Destructor... | ||||||||
109 | */ | ||||||||
110 | ~Reference() COVERITY_NOEXCEPT_FALSE | ||||||||
111 | { | ||||||||
112 | if (m_pBody) | ||||||||
113 | m_pBody->release(); | ||||||||
114 | } | ||||||||
115 | |||||||||
116 | /** Set... | ||||||||
117 | Similar to assignment. | ||||||||
118 | */ | ||||||||
119 | Reference<reference_type> & | ||||||||
120 | SAL_CALL set (reference_type * pBody) | ||||||||
121 | { | ||||||||
122 | if (pBody) | ||||||||
123 | pBody->acquire(); | ||||||||
124 | reference_type * const pOld = m_pBody; | ||||||||
125 | m_pBody = pBody; | ||||||||
126 | if (pOld) | ||||||||
127 | pOld->release(); | ||||||||
128 | return *this; | ||||||||
129 | } | ||||||||
130 | |||||||||
131 | /** Assignment. | ||||||||
132 | Unbinds this instance from its body (if bound) and | ||||||||
133 | bind it to the body represented by the handle. | ||||||||
134 | */ | ||||||||
135 | Reference<reference_type> & | ||||||||
136 | SAL_CALL operator= (const Reference<reference_type> & handle) | ||||||||
137 | { | ||||||||
138 | return set( handle.m_pBody ); | ||||||||
139 | } | ||||||||
140 | |||||||||
141 | #ifdef LIBO_INTERNAL_ONLY1 | ||||||||
142 | /** Assignment. | ||||||||
143 | * Unbinds this instance from its body (if bound), | ||||||||
144 | * bind it to the body represented by the handle, and | ||||||||
145 | * set the body represented by the handle to nullptr. | ||||||||
146 | */ | ||||||||
147 | Reference<reference_type> & | ||||||||
148 | operator= (Reference<reference_type> && handle) | ||||||||
149 | { | ||||||||
150 | // self-movement guts ourself | ||||||||
151 | if (m_pBody) | ||||||||
152 | m_pBody->release(); | ||||||||
153 | m_pBody = handle.m_pBody; | ||||||||
154 | handle.m_pBody = nullptr; | ||||||||
155 | return *this; | ||||||||
156 | } | ||||||||
157 | #endif | ||||||||
158 | |||||||||
159 | /** Assignment... | ||||||||
160 | */ | ||||||||
161 | Reference<reference_type> & | ||||||||
162 | SAL_CALL operator= (reference_type * pBody) | ||||||||
163 | { | ||||||||
164 | return set( pBody ); | ||||||||
165 | } | ||||||||
166 | |||||||||
167 | /** Unbind the body from this handle. | ||||||||
168 | Note that for a handle representing a large body, | ||||||||
169 | "handle.clear().set(new body());" _might_ | ||||||||
170 | perform a little bit better than "handle.set(new body());", | ||||||||
171 | since in the second case two large objects exist in memory | ||||||||
172 | (the old body and the new body). | ||||||||
173 | */ | ||||||||
174 | Reference<reference_type> & SAL_CALL clear() | ||||||||
175 | { | ||||||||
176 | if (m_pBody
| ||||||||
177 | { | ||||||||
178 | reference_type * const pOld = m_pBody; | ||||||||
179 | m_pBody = NULL__null; | ||||||||
180 | pOld->release(); | ||||||||
181 | } | ||||||||
182 | return *this; | ||||||||
183 | } | ||||||||
184 | |||||||||
185 | |||||||||
186 | /** Get the body. Can be used instead of operator->(). | ||||||||
187 | I.e. handle->someBodyOp() and handle.get()->someBodyOp() | ||||||||
188 | are the same. | ||||||||
189 | */ | ||||||||
190 | reference_type * SAL_CALL get() const | ||||||||
191 | { | ||||||||
192 | return m_pBody; | ||||||||
| |||||||||
193 | } | ||||||||
194 | |||||||||
195 | |||||||||
196 | /** Probably most common used: handle->someBodyOp(). | ||||||||
197 | */ | ||||||||
198 | reference_type * SAL_CALL operator->() const | ||||||||
199 | { | ||||||||
200 | assert(m_pBody != NULL)(static_cast <bool> (m_pBody != __null) ? void (0) : __assert_fail ("m_pBody != NULL", "/home/maarten/src/libreoffice/core/include/rtl/ref.hxx" , 200, __extension__ __PRETTY_FUNCTION__)); | ||||||||
201 | return m_pBody; | ||||||||
202 | } | ||||||||
203 | |||||||||
204 | |||||||||
205 | /** Allows (*handle).someBodyOp(). | ||||||||
206 | */ | ||||||||
207 | reference_type & SAL_CALL operator*() const | ||||||||
208 | { | ||||||||
209 | assert(m_pBody != NULL)(static_cast <bool> (m_pBody != __null) ? void (0) : __assert_fail ("m_pBody != NULL", "/home/maarten/src/libreoffice/core/include/rtl/ref.hxx" , 209, __extension__ __PRETTY_FUNCTION__)); | ||||||||
210 | return *m_pBody; | ||||||||
211 | } | ||||||||
212 | |||||||||
213 | |||||||||
214 | /** Returns True if the handle does point to a valid body. | ||||||||
215 | */ | ||||||||
216 | bool SAL_CALL is() const | ||||||||
217 | { | ||||||||
218 | return (m_pBody != NULL__null); | ||||||||
219 | } | ||||||||
220 | |||||||||
221 | #if defined LIBO_INTERNAL_ONLY1 | ||||||||
222 | /** Returns True if the handle does point to a valid body. | ||||||||
223 | */ | ||||||||
224 | explicit operator bool() const | ||||||||
225 | { | ||||||||
226 | return is(); | ||||||||
227 | } | ||||||||
228 | #endif | ||||||||
229 | |||||||||
230 | /** Returns True if this points to pBody. | ||||||||
231 | */ | ||||||||
232 | bool SAL_CALL operator== (const reference_type * pBody) const | ||||||||
233 | { | ||||||||
234 | return (m_pBody == pBody); | ||||||||
235 | } | ||||||||
236 | |||||||||
237 | |||||||||
238 | /** Returns True if handle points to the same body. | ||||||||
239 | */ | ||||||||
240 | bool | ||||||||
241 | SAL_CALL operator== (const Reference<reference_type> & handle) const | ||||||||
242 | { | ||||||||
243 | return (m_pBody == handle.m_pBody); | ||||||||
244 | } | ||||||||
245 | |||||||||
246 | |||||||||
247 | /** Needed to place References into STL collection. | ||||||||
248 | */ | ||||||||
249 | bool | ||||||||
250 | SAL_CALL operator!= (const Reference<reference_type> & handle) const | ||||||||
251 | { | ||||||||
252 | return (m_pBody != handle.m_pBody); | ||||||||
253 | } | ||||||||
254 | |||||||||
255 | |||||||||
256 | /** Needed to place References into STL collection. | ||||||||
257 | */ | ||||||||
258 | bool | ||||||||
259 | SAL_CALL operator< (const Reference<reference_type> & handle) const | ||||||||
260 | { | ||||||||
261 | return (m_pBody < handle.m_pBody); | ||||||||
262 | } | ||||||||
263 | |||||||||
264 | |||||||||
265 | /** Needed to place References into STL collection. | ||||||||
266 | */ | ||||||||
267 | bool | ||||||||
268 | SAL_CALL operator> (const Reference<reference_type> & handle) const | ||||||||
269 | { | ||||||||
270 | return (m_pBody > handle.m_pBody); | ||||||||
271 | } | ||||||||
272 | }; | ||||||||
273 | |||||||||
274 | } // namespace rtl | ||||||||
275 | |||||||||
276 | #if defined LIBO_INTERNAL_ONLY1 | ||||||||
277 | namespace std | ||||||||
278 | { | ||||||||
279 | |||||||||
280 | /// @cond INTERNAL | ||||||||
281 | /** | ||||||||
282 | Make rtl::Reference hashable by default for use in STL containers. | ||||||||
283 | |||||||||
284 | @since LibreOffice 6.3 | ||||||||
285 | */ | ||||||||
286 | template<typename T> | ||||||||
287 | struct hash<::rtl::Reference<T>> | ||||||||
288 | { | ||||||||
289 | std::size_t operator()(::rtl::Reference<T> const & s) const | ||||||||
290 | { return std::size_t(s.get()); } | ||||||||
291 | }; | ||||||||
292 | /// @endcond | ||||||||
293 | |||||||||
294 | } | ||||||||
295 | |||||||||
296 | #endif | ||||||||
297 | |||||||||
298 | #endif /* ! INCLUDED_RTL_REF_HXX */ | ||||||||
299 | |||||||||
300 | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |
1 | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
2 | /* |
3 | * This file is part of the LibreOffice project. |
4 | * |
5 | * This Source Code Form is subject to the terms of the Mozilla Public |
6 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
7 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. |
8 | * |
9 | * This file incorporates work covered by the following license notice: |
10 | * |
11 | * Licensed to the Apache Software Foundation (ASF) under one or more |
12 | * contributor license agreements. See the NOTICE file distributed |
13 | * with this work for additional information regarding copyright |
14 | * ownership. The ASF licenses this file to you under the Apache |
15 | * License, Version 2.0 (the "License"); you may not use this file |
16 | * except in compliance with the License. You may obtain a copy of |
17 | * the License at http://www.apache.org/licenses/LICENSE-2.0 . |
18 | */ |
19 | #ifndef INCLUDED_VCL_Reference_HXX |
20 | #define INCLUDED_VCL_Reference_HXX |
21 | |
22 | #include <vcl/dllapi.h> |
23 | #include <osl/interlck.h> |
24 | |
25 | class VCL_DLLPUBLIC__attribute__ ((visibility("default"))) VclReferenceBase |
26 | { |
27 | mutable oslInterlockedCount mnRefCnt; |
28 | |
29 | template<typename T> friend class VclPtr; |
30 | |
31 | public: |
32 | void acquire() const |
33 | { |
34 | osl_atomic_increment(&mnRefCnt)__sync_add_and_fetch((&mnRefCnt), 1); |
35 | } |
36 | |
37 | void release() const |
38 | { |
39 | if (osl_atomic_decrement(&mnRefCnt)__sync_sub_and_fetch((&mnRefCnt), 1) == 0) |
40 | delete this; |
41 | } |
42 | #ifdef DBG_UTIL |
43 | #ifndef _WIN32 |
44 | sal_Int32 getRefCount() const { return mnRefCnt; } |
45 | #endif |
46 | #endif |
47 | |
48 | |
49 | private: |
50 | VclReferenceBase(const VclReferenceBase&) = delete; |
51 | VclReferenceBase& operator=(const VclReferenceBase&) = delete; |
52 | |
53 | bool mbDisposed : 1; |
54 | |
55 | protected: |
56 | VclReferenceBase(); |
57 | protected: |
58 | virtual ~VclReferenceBase(); |
59 | |
60 | protected: |
61 | virtual void dispose(); |
62 | |
63 | public: |
64 | void disposeOnce(); |
65 | bool isDisposed() const { return mbDisposed; } |
66 | |
67 | }; |
68 | #endif |