File: | home/maarten/src/libreoffice/core/sfx2/source/sidebar/DeckLayouter.cxx |
Warning: | line 349, column 39 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 <sidebar/DeckLayouter.hxx> | ||||||
21 | #include <sfx2/sidebar/Theme.hxx> | ||||||
22 | #include <sfx2/sidebar/Panel.hxx> | ||||||
23 | #include <sidebar/PanelTitleBar.hxx> | ||||||
24 | #include <sfx2/sidebar/Deck.hxx> | ||||||
25 | #include <sfx2/sidebar/SidebarController.hxx> | ||||||
26 | #include <comphelper/lok.hxx> | ||||||
27 | |||||||
28 | #include <comphelper/processfactory.hxx> | ||||||
29 | #include <vcl/window.hxx> | ||||||
30 | #include <vcl/scrbar.hxx> | ||||||
31 | |||||||
32 | #include <com/sun/star/uno/Reference.hxx> | ||||||
33 | #include <com/sun/star/frame/Desktop.hpp> | ||||||
34 | #include <com/sun/star/frame/XDesktop2.hpp> | ||||||
35 | #include <com/sun/star/frame/XFrame.hpp> | ||||||
36 | #include <com/sun/star/ui/XSidebarPanel.hpp> | ||||||
37 | |||||||
38 | using namespace css; | ||||||
39 | using namespace css::uno; | ||||||
40 | |||||||
41 | namespace sfx2::sidebar { | ||||||
42 | |||||||
43 | namespace { | ||||||
44 | const sal_Int32 MinimalPanelHeight (25); | ||||||
45 | |||||||
46 | enum LayoutMode | ||||||
47 | { | ||||||
48 | MinimumOrLarger, | ||||||
49 | PreferredOrLarger, | ||||||
50 | Preferred | ||||||
51 | }; | ||||||
52 | class LayoutItem | ||||||
53 | { | ||||||
54 | public: | ||||||
55 | VclPtr<Panel> mpPanel; | ||||||
56 | css::ui::LayoutSize maLayoutSize; | ||||||
57 | sal_Int32 mnDistributedHeight; | ||||||
58 | sal_Int32 mnWeight; | ||||||
59 | bool mbShowTitleBar; | ||||||
60 | |||||||
61 | LayoutItem(const VclPtr<Panel>& rPanel) | ||||||
62 | : mpPanel(rPanel) | ||||||
63 | , maLayoutSize(0, 0, 0) | ||||||
64 | , mnDistributedHeight(0) | ||||||
65 | , mnWeight(0) | ||||||
66 | , mbShowTitleBar(true) | ||||||
67 | { | ||||||
68 | } | ||||||
69 | }; | ||||||
70 | tools::Rectangle LayoutPanels ( | ||||||
71 | const tools::Rectangle& rContentArea, | ||||||
72 | sal_Int32& rMinimalWidth, | ||||||
73 | sal_Int32& rMinimalHeight, | ||||||
74 | ::std::vector<LayoutItem>& rLayoutItems, | ||||||
75 | vcl::Window& rScrollClipWindow, | ||||||
76 | vcl::Window& rScrollContainer, | ||||||
77 | ScrollBar& pVerticalScrollBar, | ||||||
78 | const bool bShowVerticalScrollBar); | ||||||
79 | void GetRequestedSizes ( | ||||||
80 | ::std::vector<LayoutItem>& rLayoutItem, | ||||||
81 | sal_Int32& rAvailableHeight, | ||||||
82 | sal_Int32& rMinimalWidth, | ||||||
83 | const tools::Rectangle& rContentBox); | ||||||
84 | void DistributeHeights ( | ||||||
85 | ::std::vector<LayoutItem>& rLayoutItems, | ||||||
86 | const sal_Int32 nHeightToDistribute, | ||||||
87 | const sal_Int32 nContainerHeight, | ||||||
88 | const bool bMinimumHeightIsBase); | ||||||
89 | bool MoveResizePixel(const VclPtr<vcl::Window> &pWindow, | ||||||
90 | const Point &rNewPos, const Size &rNewSize); | ||||||
91 | sal_Int32 PlacePanels ( | ||||||
92 | ::std::vector<LayoutItem>& rLayoutItems, | ||||||
93 | const sal_Int32 nWidth, | ||||||
94 | const LayoutMode eMode, | ||||||
95 | vcl::Window& rScrollContainer); | ||||||
96 | tools::Rectangle PlaceDeckTitle ( | ||||||
97 | vcl::Window& rTitleBar, | ||||||
98 | const tools::Rectangle& rAvailableSpace); | ||||||
99 | tools::Rectangle PlaceVerticalScrollBar ( | ||||||
100 | ScrollBar& rVerticalScrollBar, | ||||||
101 | const tools::Rectangle& rAvailableSpace, | ||||||
102 | const bool bShowVerticalScrollBar); | ||||||
103 | void SetupVerticalScrollBar( | ||||||
104 | ScrollBar& rVerticalScrollBar, | ||||||
105 | const sal_Int32 nContentHeight, | ||||||
106 | const sal_Int32 nVisibleHeight); | ||||||
107 | void UpdateFiller ( | ||||||
108 | vcl::Window& rFiller, | ||||||
109 | const tools::Rectangle& rBox); | ||||||
110 | } | ||||||
111 | |||||||
112 | void DeckLayouter::LayoutDeck ( | ||||||
113 | const tools::Rectangle& rContentArea, | ||||||
114 | sal_Int32& rMinimalWidth, | ||||||
115 | sal_Int32& rMinimalHeight, | ||||||
116 | SharedPanelContainer& rPanels, | ||||||
117 | vcl::Window& rDeckTitleBar, | ||||||
118 | vcl::Window& rScrollClipWindow, | ||||||
119 | vcl::Window& rScrollContainer, | ||||||
120 | vcl::Window& rFiller, | ||||||
121 | ScrollBar& rVerticalScrollBar) | ||||||
122 | { | ||||||
123 | if (rContentArea.GetWidth()<=0 || rContentArea.GetHeight()<=0) | ||||||
| |||||||
124 | return; | ||||||
125 | tools::Rectangle aBox (PlaceDeckTitle(rDeckTitleBar, rContentArea)); | ||||||
126 | |||||||
127 | if ( ! rPanels.empty()) | ||||||
128 | { | ||||||
129 | // Prepare the layout item container. | ||||||
130 | ::std::vector<LayoutItem> aLayoutItems; | ||||||
131 | aLayoutItems.reserve(rPanels.size()); | ||||||
132 | for (const auto& rPanel : rPanels) | ||||||
133 | aLayoutItems.emplace_back(rPanel); | ||||||
134 | |||||||
135 | aBox = LayoutPanels( | ||||||
136 | aBox, | ||||||
137 | rMinimalWidth, | ||||||
138 | rMinimalHeight, | ||||||
139 | aLayoutItems, | ||||||
140 | rScrollClipWindow, | ||||||
141 | rScrollContainer, | ||||||
142 | rVerticalScrollBar, | ||||||
143 | false); | ||||||
144 | } | ||||||
145 | UpdateFiller(rFiller, aBox); | ||||||
146 | } | ||||||
147 | |||||||
148 | namespace { | ||||||
149 | |||||||
150 | tools::Rectangle LayoutPanels ( | ||||||
151 | const tools::Rectangle& rContentArea, | ||||||
152 | sal_Int32& rMinimalWidth, | ||||||
153 | sal_Int32& rMinimalHeight, | ||||||
154 | ::std::vector<LayoutItem>& rLayoutItems, | ||||||
155 | vcl::Window& rScrollClipWindow, | ||||||
156 | vcl::Window& rScrollContainer, | ||||||
157 | ScrollBar& rVerticalScrollBar, | ||||||
158 | const bool bShowVerticalScrollBar) | ||||||
159 | { | ||||||
160 | tools::Rectangle aBox (PlaceVerticalScrollBar(rVerticalScrollBar, rContentArea, bShowVerticalScrollBar)); | ||||||
161 | |||||||
162 | const sal_Int32 nWidth (aBox.GetWidth()); | ||||||
163 | |||||||
164 | // Get the requested heights of the panels and the available | ||||||
165 | // height that is left when all panel titles and separators are | ||||||
166 | // taken into account. | ||||||
167 | sal_Int32 nAvailableHeight (aBox.GetHeight()); | ||||||
168 | GetRequestedSizes(rLayoutItems, nAvailableHeight, rMinimalWidth, aBox); | ||||||
169 | const sal_Int32 nTotalDecorationHeight (aBox.GetHeight() - nAvailableHeight); | ||||||
170 | |||||||
171 | // Analyze the requested heights. | ||||||
172 | // Determine the height that is available for panel content | ||||||
173 | // and count the different layouts. | ||||||
174 | sal_Int32 nTotalPreferredHeight (0); | ||||||
175 | sal_Int32 nTotalMinimumHeight (0); | ||||||
176 | |||||||
177 | for (const auto& rItem : rLayoutItems) | ||||||
178 | { | ||||||
179 | nTotalMinimumHeight += rItem.maLayoutSize.Minimum; | ||||||
180 | nTotalPreferredHeight += rItem.maLayoutSize.Preferred; | ||||||
181 | } | ||||||
182 | |||||||
183 | if (nTotalMinimumHeight > nAvailableHeight && !bShowVerticalScrollBar | ||||||
184 | && !comphelper::LibreOfficeKit::isActive()) | ||||||
185 | { | ||||||
186 | // Not enough space, even when all panels are shrunk to their | ||||||
187 | // minimum height. | ||||||
188 | // Show a vertical scrollbar. | ||||||
189 | return LayoutPanels( | ||||||
190 | rContentArea, | ||||||
191 | rMinimalWidth, | ||||||
192 | rMinimalHeight, | ||||||
193 | rLayoutItems, | ||||||
194 | rScrollClipWindow, | ||||||
195 | rScrollContainer, | ||||||
196 | rVerticalScrollBar, | ||||||
197 | true); | ||||||
198 | } | ||||||
199 | |||||||
200 | // We are now in one of three modes. | ||||||
201 | // - The preferred height fits into the available size: | ||||||
202 | // Use the preferred size, distribute the remaining height by | ||||||
203 | // enlarging panels. | ||||||
204 | // - The total minimum height fits into the available size: | ||||||
205 | // Use the minimum size, distribute the remaining height by | ||||||
206 | // enlarging panels. | ||||||
207 | // - The total minimum height does not fit into the available | ||||||
208 | // size: | ||||||
209 | // Use the unmodified preferred height for all panels. | ||||||
210 | |||||||
211 | LayoutMode eMode (MinimumOrLarger); | ||||||
212 | if (bShowVerticalScrollBar
| ||||||
213 | eMode = Preferred; | ||||||
214 | else if (nTotalPreferredHeight
| ||||||
215 | eMode = PreferredOrLarger; | ||||||
216 | else | ||||||
217 | eMode = MinimumOrLarger; | ||||||
218 | |||||||
219 | if (eMode
| ||||||
220 | { | ||||||
221 | const sal_Int32 nTotalHeight (eMode
| ||||||
222 | |||||||
223 | DistributeHeights( | ||||||
224 | rLayoutItems, | ||||||
225 | nAvailableHeight-nTotalHeight, | ||||||
226 | aBox.GetHeight(), | ||||||
227 | eMode==MinimumOrLarger); | ||||||
228 | } | ||||||
229 | |||||||
230 | // Set position and size of the mpScrollClipWindow to the available | ||||||
231 | // size. Its child, the mpScrollContainer, may have a bigger | ||||||
232 | // height. | ||||||
233 | rScrollClipWindow.setPosSizePixel(aBox.Left(), aBox.Top(), aBox.GetWidth(), aBox.GetHeight()); | ||||||
234 | |||||||
235 | const sal_Int32 nContentHeight ( | ||||||
236 | eMode
| ||||||
237 | ? nTotalPreferredHeight + nTotalDecorationHeight | ||||||
238 | : aBox.GetHeight()); | ||||||
239 | sal_Int32 nY = rVerticalScrollBar.GetThumbPos(); | ||||||
240 | if (nContentHeight-nY < aBox.GetHeight()) | ||||||
241 | nY = nContentHeight-aBox.GetHeight(); | ||||||
242 | if (nY < 0) | ||||||
243 | nY = 0; | ||||||
244 | rScrollContainer.setPosSizePixel( | ||||||
245 | 0, | ||||||
246 | -nY, | ||||||
247 | nWidth, | ||||||
248 | nContentHeight); | ||||||
249 | |||||||
250 | if (bShowVerticalScrollBar
| ||||||
251 | SetupVerticalScrollBar(rVerticalScrollBar, nContentHeight, aBox.GetHeight()); | ||||||
252 | |||||||
253 | const sal_Int32 nUsedHeight (PlacePanels(rLayoutItems, nWidth, eMode, rScrollContainer)); | ||||||
254 | aBox.AdjustTop(nUsedHeight ); | ||||||
255 | rMinimalHeight = nUsedHeight; | ||||||
256 | return aBox; | ||||||
257 | } | ||||||
258 | |||||||
259 | bool MoveResizePixel(const VclPtr<vcl::Window> &pWindow, | ||||||
260 | const Point &rNewPos, const Size &rNewSize) | ||||||
261 | { | ||||||
262 | Point aCurPos = pWindow->GetPosPixel(); | ||||||
263 | Size aCurSize = pWindow->GetSizePixel(); | ||||||
264 | if (rNewPos == aCurPos && aCurSize == rNewSize) | ||||||
265 | return false; | ||||||
266 | pWindow->setPosSizePixel(rNewPos.X(), rNewPos.Y(), rNewSize.Width(), rNewSize.Height()); | ||||||
267 | return true; | ||||||
268 | } | ||||||
269 | |||||||
270 | sal_Int32 PlacePanels ( | ||||||
271 | ::std::vector<LayoutItem>& rLayoutItems, | ||||||
272 | const sal_Int32 nWidth, | ||||||
273 | const LayoutMode eMode, | ||||||
274 | vcl::Window& rScrollContainer) | ||||||
275 | { | ||||||
276 | ::std::vector<sal_Int32> aSeparators; | ||||||
277 | const sal_Int32 nDeckSeparatorHeight (Theme::GetInteger(Theme::Int_DeckSeparatorHeight)); | ||||||
278 | sal_Int32 nY (0); | ||||||
279 | |||||||
280 | vcl::Region aInvalidRegions; | ||||||
281 | |||||||
282 | // Assign heights and places. | ||||||
283 | for(::std::vector<LayoutItem>::const_iterator iItem(rLayoutItems.begin()), | ||||||
284 | iEnd(rLayoutItems.end()); | ||||||
285 | iItem!=iEnd; | ||||||
286 | ++iItem) | ||||||
287 | { | ||||||
288 | if (!iItem->mpPanel) | ||||||
289 | continue; | ||||||
290 | |||||||
291 | Panel& rPanel (*iItem->mpPanel); | ||||||
292 | |||||||
293 | // Separator above the panel title bar. | ||||||
294 | if (!rPanel.IsLurking()) | ||||||
295 | { | ||||||
296 | aSeparators.push_back(nY); | ||||||
297 | nY += nDeckSeparatorHeight; | ||||||
298 | } | ||||||
299 | |||||||
300 | // Place the title bar. | ||||||
301 | VclPtr<PanelTitleBar> pTitleBar = rPanel.GetTitleBar(); | ||||||
302 | if (pTitleBar) | ||||||
303 | { | ||||||
304 | const sal_Int32 nPanelTitleBarHeight (Theme::GetInteger(Theme::Int_PanelTitleBarHeight) * rPanel.GetDPIScaleFactor()); | ||||||
305 | |||||||
306 | if (iItem->mbShowTitleBar) | ||||||
307 | { | ||||||
308 | pTitleBar->setPosSizePixel(0, nY, nWidth, nPanelTitleBarHeight); | ||||||
309 | pTitleBar->Show(); | ||||||
310 | nY += nPanelTitleBarHeight; | ||||||
311 | } | ||||||
312 | else | ||||||
313 | { | ||||||
314 | pTitleBar->Hide(); | ||||||
315 | } | ||||||
316 | } | ||||||
317 | |||||||
318 | if (rPanel.IsExpanded() && !rPanel.IsLurking()) | ||||||
319 | { | ||||||
320 | rPanel.Show(); | ||||||
321 | |||||||
322 | // Determine the height of the panel depending on layout | ||||||
323 | // mode and distributed heights. | ||||||
324 | sal_Int32 nPanelHeight (0); | ||||||
325 | switch(eMode) | ||||||
326 | { | ||||||
327 | case MinimumOrLarger: | ||||||
328 | nPanelHeight = iItem->maLayoutSize.Minimum + iItem->mnDistributedHeight; | ||||||
329 | break; | ||||||
330 | case PreferredOrLarger: | ||||||
331 | nPanelHeight = iItem->maLayoutSize.Preferred + iItem->mnDistributedHeight; | ||||||
332 | break; | ||||||
333 | case Preferred: | ||||||
334 | nPanelHeight = iItem->maLayoutSize.Preferred; | ||||||
335 | break; | ||||||
336 | default: | ||||||
337 | OSL_ASSERT(false)do { if (true && (!(false))) { sal_detail_logFormat(( SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/sfx2/source/sidebar/DeckLayouter.cxx" ":" "337" ": "), "OSL_ASSERT: %s", "false"); } } while (false ); | ||||||
338 | break; | ||||||
339 | } | ||||||
340 | |||||||
341 | // Place the panel. | ||||||
342 | Point aNewPos(0, nY); | ||||||
343 | Size aNewSize(nWidth, nPanelHeight); | ||||||
344 | |||||||
345 | // Only invalidate if we moved | ||||||
346 | if (MoveResizePixel(&rPanel, aNewPos, aNewSize)) | ||||||
347 | { | ||||||
348 | tools::Rectangle aRect(aNewPos, aNewSize); | ||||||
349 | aInvalidRegions.Union(rPanel.PixelToLogic(aRect)); | ||||||
| |||||||
350 | } | ||||||
351 | |||||||
352 | nY += nPanelHeight; | ||||||
353 | } | ||||||
354 | else | ||||||
355 | { | ||||||
356 | rPanel.Hide(); | ||||||
357 | |||||||
358 | // Add a separator below the collapsed panel, if it is the | ||||||
359 | // last panel in the deck. | ||||||
360 | if (iItem == rLayoutItems.end()-1) | ||||||
361 | { | ||||||
362 | // Separator below the panel title bar. | ||||||
363 | aSeparators.push_back(nY); | ||||||
364 | nY += nDeckSeparatorHeight; | ||||||
365 | } | ||||||
366 | } | ||||||
367 | } | ||||||
368 | |||||||
369 | Deck::ScrollContainerWindow* pScrollContainerWindow | ||||||
370 | = dynamic_cast<Deck::ScrollContainerWindow*>(&rScrollContainer); | ||||||
371 | if (pScrollContainerWindow != nullptr) | ||||||
372 | pScrollContainerWindow->SetSeparators(aSeparators); | ||||||
373 | |||||||
374 | rScrollContainer.Invalidate(aInvalidRegions); | ||||||
375 | |||||||
376 | return nY; | ||||||
377 | } | ||||||
378 | |||||||
379 | void GetRequestedSizes ( | ||||||
380 | ::std::vector<LayoutItem>& rLayoutItems, | ||||||
381 | sal_Int32& rAvailableHeight, | ||||||
382 | sal_Int32& rMinimalWidth, | ||||||
383 | const tools::Rectangle& rContentBox) | ||||||
384 | { | ||||||
385 | rAvailableHeight = rContentBox.GetHeight(); | ||||||
386 | |||||||
387 | const sal_Int32 nDeckSeparatorHeight (Theme::GetInteger(Theme::Int_DeckSeparatorHeight)); | ||||||
388 | |||||||
389 | for (auto& rItem : rLayoutItems) | ||||||
390 | { | ||||||
391 | rItem.maLayoutSize = ui::LayoutSize(0,0,0); | ||||||
392 | |||||||
393 | if (rItem.mpPanel == nullptr) | ||||||
394 | continue; | ||||||
395 | |||||||
396 | if (rItem.mpPanel->IsLurking()) | ||||||
397 | { | ||||||
398 | rItem.mbShowTitleBar = false; | ||||||
399 | continue; | ||||||
400 | } | ||||||
401 | |||||||
402 | if (rLayoutItems.size() == 1 | ||||||
403 | && rItem.mpPanel->IsTitleBarOptional()) | ||||||
404 | { | ||||||
405 | // There is only one panel and its title bar is | ||||||
406 | // optional => hide it. | ||||||
407 | rAvailableHeight -= nDeckSeparatorHeight; | ||||||
408 | rItem.mbShowTitleBar = false; | ||||||
409 | } | ||||||
410 | else | ||||||
411 | { | ||||||
412 | // Show the title bar and a separator above and below | ||||||
413 | // the title bar. | ||||||
414 | const sal_Int32 nPanelTitleBarHeight (Theme::GetInteger(Theme::Int_PanelTitleBarHeight) * rItem.mpPanel->GetDPIScaleFactor()); | ||||||
415 | |||||||
416 | rAvailableHeight -= nPanelTitleBarHeight; | ||||||
417 | rAvailableHeight -= nDeckSeparatorHeight; | ||||||
418 | } | ||||||
419 | |||||||
420 | if (rItem.mpPanel->IsExpanded() && rItem.mpPanel->GetPanelComponent().is()) | ||||||
421 | { | ||||||
422 | Reference<ui::XSidebarPanel> xPanel (rItem.mpPanel->GetPanelComponent()); | ||||||
423 | |||||||
424 | rItem.maLayoutSize = xPanel->getHeightForWidth(rContentBox.GetWidth()); | ||||||
425 | if (!(0 <= rItem.maLayoutSize.Minimum && rItem.maLayoutSize.Minimum <= rItem.maLayoutSize.Preferred | ||||||
426 | && rItem.maLayoutSize.Preferred <= rItem.maLayoutSize.Maximum)) | ||||||
427 | { | ||||||
428 | SAL_WARN("sfx.sidebar", "Please follow LayoutSize constraints: 0 ≤ "do { if (true) { switch (sal_detail_log_report(::SAL_DETAIL_LOG_LEVEL_WARN , "sfx.sidebar")) { case SAL_DETAIL_LOG_ACTION_IGNORE: break; case SAL_DETAIL_LOG_ACTION_LOG: if (sizeof ::sal::detail::getResult ( ::sal::detail::StreamStart() << "Please follow LayoutSize constraints: 0 ≤ " "Minimum ≤ Preferred ≤ Maximum." " Currently: Minimum: " << rItem.maLayoutSize.Minimum << " Preferred: " << rItem.maLayoutSize.Preferred << " Maximum: " << rItem .maLayoutSize.Maximum) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_WARN ), ("sfx.sidebar"), ("/home/maarten/src/libreoffice/core/sfx2/source/sidebar/DeckLayouter.cxx" ":" "433" ": "), ::sal::detail::unwrapStream( ::sal::detail:: StreamStart() << "Please follow LayoutSize constraints: 0 ≤ " "Minimum ≤ Preferred ≤ Maximum." " Currently: Minimum: " << rItem.maLayoutSize.Minimum << " Preferred: " << rItem.maLayoutSize.Preferred << " Maximum: " << rItem .maLayoutSize.Maximum), 0); } else { ::std::ostringstream sal_detail_stream ; sal_detail_stream << "Please follow LayoutSize constraints: 0 ≤ " "Minimum ≤ Preferred ≤ Maximum." " Currently: Minimum: " << rItem.maLayoutSize.Minimum << " Preferred: " << rItem.maLayoutSize.Preferred << " Maximum: " << rItem .maLayoutSize.Maximum; ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_WARN ), ("sfx.sidebar"), ("/home/maarten/src/libreoffice/core/sfx2/source/sidebar/DeckLayouter.cxx" ":" "433" ": "), sal_detail_stream, 0); }; break; case SAL_DETAIL_LOG_ACTION_FATAL : if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart () << "Please follow LayoutSize constraints: 0 ≤ " "Minimum ≤ Preferred ≤ Maximum." " Currently: Minimum: " << rItem.maLayoutSize.Minimum << " Preferred: " << rItem.maLayoutSize.Preferred << " Maximum: " << rItem.maLayoutSize.Maximum) == 1) { :: sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("sfx.sidebar" ), ("/home/maarten/src/libreoffice/core/sfx2/source/sidebar/DeckLayouter.cxx" ":" "433" ": "), ::sal::detail::unwrapStream( ::sal::detail:: StreamStart() << "Please follow LayoutSize constraints: 0 ≤ " "Minimum ≤ Preferred ≤ Maximum." " Currently: Minimum: " << rItem.maLayoutSize.Minimum << " Preferred: " << rItem.maLayoutSize.Preferred << " Maximum: " << rItem .maLayoutSize.Maximum), 0); } else { ::std::ostringstream sal_detail_stream ; sal_detail_stream << "Please follow LayoutSize constraints: 0 ≤ " "Minimum ≤ Preferred ≤ Maximum." " Currently: Minimum: " << rItem.maLayoutSize.Minimum << " Preferred: " << rItem.maLayoutSize.Preferred << " Maximum: " << rItem .maLayoutSize.Maximum; ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_WARN ), ("sfx.sidebar"), ("/home/maarten/src/libreoffice/core/sfx2/source/sidebar/DeckLayouter.cxx" ":" "433" ": "), sal_detail_stream, 0); }; std::abort(); break ; } } } while (false) | ||||||
429 | "Minimum ≤ Preferred ≤ Maximum."do { if (true) { switch (sal_detail_log_report(::SAL_DETAIL_LOG_LEVEL_WARN , "sfx.sidebar")) { case SAL_DETAIL_LOG_ACTION_IGNORE: break; case SAL_DETAIL_LOG_ACTION_LOG: if (sizeof ::sal::detail::getResult ( ::sal::detail::StreamStart() << "Please follow LayoutSize constraints: 0 ≤ " "Minimum ≤ Preferred ≤ Maximum." " Currently: Minimum: " << rItem.maLayoutSize.Minimum << " Preferred: " << rItem.maLayoutSize.Preferred << " Maximum: " << rItem .maLayoutSize.Maximum) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_WARN ), ("sfx.sidebar"), ("/home/maarten/src/libreoffice/core/sfx2/source/sidebar/DeckLayouter.cxx" ":" "433" ": "), ::sal::detail::unwrapStream( ::sal::detail:: StreamStart() << "Please follow LayoutSize constraints: 0 ≤ " "Minimum ≤ Preferred ≤ Maximum." " Currently: Minimum: " << rItem.maLayoutSize.Minimum << " Preferred: " << rItem.maLayoutSize.Preferred << " Maximum: " << rItem .maLayoutSize.Maximum), 0); } else { ::std::ostringstream sal_detail_stream ; sal_detail_stream << "Please follow LayoutSize constraints: 0 ≤ " "Minimum ≤ Preferred ≤ Maximum." " Currently: Minimum: " << rItem.maLayoutSize.Minimum << " Preferred: " << rItem.maLayoutSize.Preferred << " Maximum: " << rItem .maLayoutSize.Maximum; ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_WARN ), ("sfx.sidebar"), ("/home/maarten/src/libreoffice/core/sfx2/source/sidebar/DeckLayouter.cxx" ":" "433" ": "), sal_detail_stream, 0); }; break; case SAL_DETAIL_LOG_ACTION_FATAL : if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart () << "Please follow LayoutSize constraints: 0 ≤ " "Minimum ≤ Preferred ≤ Maximum." " Currently: Minimum: " << rItem.maLayoutSize.Minimum << " Preferred: " << rItem.maLayoutSize.Preferred << " Maximum: " << rItem.maLayoutSize.Maximum) == 1) { :: sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("sfx.sidebar" ), ("/home/maarten/src/libreoffice/core/sfx2/source/sidebar/DeckLayouter.cxx" ":" "433" ": "), ::sal::detail::unwrapStream( ::sal::detail:: StreamStart() << "Please follow LayoutSize constraints: 0 ≤ " "Minimum ≤ Preferred ≤ Maximum." " Currently: Minimum: " << rItem.maLayoutSize.Minimum << " Preferred: " << rItem.maLayoutSize.Preferred << " Maximum: " << rItem .maLayoutSize.Maximum), 0); } else { ::std::ostringstream sal_detail_stream ; sal_detail_stream << "Please follow LayoutSize constraints: 0 ≤ " "Minimum ≤ Preferred ≤ Maximum." " Currently: Minimum: " << rItem.maLayoutSize.Minimum << " Preferred: " << rItem.maLayoutSize.Preferred << " Maximum: " << rItem .maLayoutSize.Maximum; ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_WARN ), ("sfx.sidebar"), ("/home/maarten/src/libreoffice/core/sfx2/source/sidebar/DeckLayouter.cxx" ":" "433" ": "), sal_detail_stream, 0); }; std::abort(); break ; } } } while (false) | ||||||
430 | " Currently: Minimum: "do { if (true) { switch (sal_detail_log_report(::SAL_DETAIL_LOG_LEVEL_WARN , "sfx.sidebar")) { case SAL_DETAIL_LOG_ACTION_IGNORE: break; case SAL_DETAIL_LOG_ACTION_LOG: if (sizeof ::sal::detail::getResult ( ::sal::detail::StreamStart() << "Please follow LayoutSize constraints: 0 ≤ " "Minimum ≤ Preferred ≤ Maximum." " Currently: Minimum: " << rItem.maLayoutSize.Minimum << " Preferred: " << rItem.maLayoutSize.Preferred << " Maximum: " << rItem .maLayoutSize.Maximum) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_WARN ), ("sfx.sidebar"), ("/home/maarten/src/libreoffice/core/sfx2/source/sidebar/DeckLayouter.cxx" ":" "433" ": "), ::sal::detail::unwrapStream( ::sal::detail:: StreamStart() << "Please follow LayoutSize constraints: 0 ≤ " "Minimum ≤ Preferred ≤ Maximum." " Currently: Minimum: " << rItem.maLayoutSize.Minimum << " Preferred: " << rItem.maLayoutSize.Preferred << " Maximum: " << rItem .maLayoutSize.Maximum), 0); } else { ::std::ostringstream sal_detail_stream ; sal_detail_stream << "Please follow LayoutSize constraints: 0 ≤ " "Minimum ≤ Preferred ≤ Maximum." " Currently: Minimum: " << rItem.maLayoutSize.Minimum << " Preferred: " << rItem.maLayoutSize.Preferred << " Maximum: " << rItem .maLayoutSize.Maximum; ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_WARN ), ("sfx.sidebar"), ("/home/maarten/src/libreoffice/core/sfx2/source/sidebar/DeckLayouter.cxx" ":" "433" ": "), sal_detail_stream, 0); }; break; case SAL_DETAIL_LOG_ACTION_FATAL : if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart () << "Please follow LayoutSize constraints: 0 ≤ " "Minimum ≤ Preferred ≤ Maximum." " Currently: Minimum: " << rItem.maLayoutSize.Minimum << " Preferred: " << rItem.maLayoutSize.Preferred << " Maximum: " << rItem.maLayoutSize.Maximum) == 1) { :: sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("sfx.sidebar" ), ("/home/maarten/src/libreoffice/core/sfx2/source/sidebar/DeckLayouter.cxx" ":" "433" ": "), ::sal::detail::unwrapStream( ::sal::detail:: StreamStart() << "Please follow LayoutSize constraints: 0 ≤ " "Minimum ≤ Preferred ≤ Maximum." " Currently: Minimum: " << rItem.maLayoutSize.Minimum << " Preferred: " << rItem.maLayoutSize.Preferred << " Maximum: " << rItem .maLayoutSize.Maximum), 0); } else { ::std::ostringstream sal_detail_stream ; sal_detail_stream << "Please follow LayoutSize constraints: 0 ≤ " "Minimum ≤ Preferred ≤ Maximum." " Currently: Minimum: " << rItem.maLayoutSize.Minimum << " Preferred: " << rItem.maLayoutSize.Preferred << " Maximum: " << rItem .maLayoutSize.Maximum; ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_WARN ), ("sfx.sidebar"), ("/home/maarten/src/libreoffice/core/sfx2/source/sidebar/DeckLayouter.cxx" ":" "433" ": "), sal_detail_stream, 0); }; std::abort(); break ; } } } while (false) | ||||||
431 | << rItem.maLayoutSize.Minimumdo { if (true) { switch (sal_detail_log_report(::SAL_DETAIL_LOG_LEVEL_WARN , "sfx.sidebar")) { case SAL_DETAIL_LOG_ACTION_IGNORE: break; case SAL_DETAIL_LOG_ACTION_LOG: if (sizeof ::sal::detail::getResult ( ::sal::detail::StreamStart() << "Please follow LayoutSize constraints: 0 ≤ " "Minimum ≤ Preferred ≤ Maximum." " Currently: Minimum: " << rItem.maLayoutSize.Minimum << " Preferred: " << rItem.maLayoutSize.Preferred << " Maximum: " << rItem .maLayoutSize.Maximum) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_WARN ), ("sfx.sidebar"), ("/home/maarten/src/libreoffice/core/sfx2/source/sidebar/DeckLayouter.cxx" ":" "433" ": "), ::sal::detail::unwrapStream( ::sal::detail:: StreamStart() << "Please follow LayoutSize constraints: 0 ≤ " "Minimum ≤ Preferred ≤ Maximum." " Currently: Minimum: " << rItem.maLayoutSize.Minimum << " Preferred: " << rItem.maLayoutSize.Preferred << " Maximum: " << rItem .maLayoutSize.Maximum), 0); } else { ::std::ostringstream sal_detail_stream ; sal_detail_stream << "Please follow LayoutSize constraints: 0 ≤ " "Minimum ≤ Preferred ≤ Maximum." " Currently: Minimum: " << rItem.maLayoutSize.Minimum << " Preferred: " << rItem.maLayoutSize.Preferred << " Maximum: " << rItem .maLayoutSize.Maximum; ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_WARN ), ("sfx.sidebar"), ("/home/maarten/src/libreoffice/core/sfx2/source/sidebar/DeckLayouter.cxx" ":" "433" ": "), sal_detail_stream, 0); }; break; case SAL_DETAIL_LOG_ACTION_FATAL : if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart () << "Please follow LayoutSize constraints: 0 ≤ " "Minimum ≤ Preferred ≤ Maximum." " Currently: Minimum: " << rItem.maLayoutSize.Minimum << " Preferred: " << rItem.maLayoutSize.Preferred << " Maximum: " << rItem.maLayoutSize.Maximum) == 1) { :: sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("sfx.sidebar" ), ("/home/maarten/src/libreoffice/core/sfx2/source/sidebar/DeckLayouter.cxx" ":" "433" ": "), ::sal::detail::unwrapStream( ::sal::detail:: StreamStart() << "Please follow LayoutSize constraints: 0 ≤ " "Minimum ≤ Preferred ≤ Maximum." " Currently: Minimum: " << rItem.maLayoutSize.Minimum << " Preferred: " << rItem.maLayoutSize.Preferred << " Maximum: " << rItem .maLayoutSize.Maximum), 0); } else { ::std::ostringstream sal_detail_stream ; sal_detail_stream << "Please follow LayoutSize constraints: 0 ≤ " "Minimum ≤ Preferred ≤ Maximum." " Currently: Minimum: " << rItem.maLayoutSize.Minimum << " Preferred: " << rItem.maLayoutSize.Preferred << " Maximum: " << rItem .maLayoutSize.Maximum; ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_WARN ), ("sfx.sidebar"), ("/home/maarten/src/libreoffice/core/sfx2/source/sidebar/DeckLayouter.cxx" ":" "433" ": "), sal_detail_stream, 0); }; std::abort(); break ; } } } while (false) | ||||||
432 | << " Preferred: " << rItem.maLayoutSize.Preferreddo { if (true) { switch (sal_detail_log_report(::SAL_DETAIL_LOG_LEVEL_WARN , "sfx.sidebar")) { case SAL_DETAIL_LOG_ACTION_IGNORE: break; case SAL_DETAIL_LOG_ACTION_LOG: if (sizeof ::sal::detail::getResult ( ::sal::detail::StreamStart() << "Please follow LayoutSize constraints: 0 ≤ " "Minimum ≤ Preferred ≤ Maximum." " Currently: Minimum: " << rItem.maLayoutSize.Minimum << " Preferred: " << rItem.maLayoutSize.Preferred << " Maximum: " << rItem .maLayoutSize.Maximum) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_WARN ), ("sfx.sidebar"), ("/home/maarten/src/libreoffice/core/sfx2/source/sidebar/DeckLayouter.cxx" ":" "433" ": "), ::sal::detail::unwrapStream( ::sal::detail:: StreamStart() << "Please follow LayoutSize constraints: 0 ≤ " "Minimum ≤ Preferred ≤ Maximum." " Currently: Minimum: " << rItem.maLayoutSize.Minimum << " Preferred: " << rItem.maLayoutSize.Preferred << " Maximum: " << rItem .maLayoutSize.Maximum), 0); } else { ::std::ostringstream sal_detail_stream ; sal_detail_stream << "Please follow LayoutSize constraints: 0 ≤ " "Minimum ≤ Preferred ≤ Maximum." " Currently: Minimum: " << rItem.maLayoutSize.Minimum << " Preferred: " << rItem.maLayoutSize.Preferred << " Maximum: " << rItem .maLayoutSize.Maximum; ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_WARN ), ("sfx.sidebar"), ("/home/maarten/src/libreoffice/core/sfx2/source/sidebar/DeckLayouter.cxx" ":" "433" ": "), sal_detail_stream, 0); }; break; case SAL_DETAIL_LOG_ACTION_FATAL : if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart () << "Please follow LayoutSize constraints: 0 ≤ " "Minimum ≤ Preferred ≤ Maximum." " Currently: Minimum: " << rItem.maLayoutSize.Minimum << " Preferred: " << rItem.maLayoutSize.Preferred << " Maximum: " << rItem.maLayoutSize.Maximum) == 1) { :: sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("sfx.sidebar" ), ("/home/maarten/src/libreoffice/core/sfx2/source/sidebar/DeckLayouter.cxx" ":" "433" ": "), ::sal::detail::unwrapStream( ::sal::detail:: StreamStart() << "Please follow LayoutSize constraints: 0 ≤ " "Minimum ≤ Preferred ≤ Maximum." " Currently: Minimum: " << rItem.maLayoutSize.Minimum << " Preferred: " << rItem.maLayoutSize.Preferred << " Maximum: " << rItem .maLayoutSize.Maximum), 0); } else { ::std::ostringstream sal_detail_stream ; sal_detail_stream << "Please follow LayoutSize constraints: 0 ≤ " "Minimum ≤ Preferred ≤ Maximum." " Currently: Minimum: " << rItem.maLayoutSize.Minimum << " Preferred: " << rItem.maLayoutSize.Preferred << " Maximum: " << rItem .maLayoutSize.Maximum; ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_WARN ), ("sfx.sidebar"), ("/home/maarten/src/libreoffice/core/sfx2/source/sidebar/DeckLayouter.cxx" ":" "433" ": "), sal_detail_stream, 0); }; std::abort(); break ; } } } while (false) | ||||||
433 | << " Maximum: " << rItem.maLayoutSize.Maximum)do { if (true) { switch (sal_detail_log_report(::SAL_DETAIL_LOG_LEVEL_WARN , "sfx.sidebar")) { case SAL_DETAIL_LOG_ACTION_IGNORE: break; case SAL_DETAIL_LOG_ACTION_LOG: if (sizeof ::sal::detail::getResult ( ::sal::detail::StreamStart() << "Please follow LayoutSize constraints: 0 ≤ " "Minimum ≤ Preferred ≤ Maximum." " Currently: Minimum: " << rItem.maLayoutSize.Minimum << " Preferred: " << rItem.maLayoutSize.Preferred << " Maximum: " << rItem .maLayoutSize.Maximum) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_WARN ), ("sfx.sidebar"), ("/home/maarten/src/libreoffice/core/sfx2/source/sidebar/DeckLayouter.cxx" ":" "433" ": "), ::sal::detail::unwrapStream( ::sal::detail:: StreamStart() << "Please follow LayoutSize constraints: 0 ≤ " "Minimum ≤ Preferred ≤ Maximum." " Currently: Minimum: " << rItem.maLayoutSize.Minimum << " Preferred: " << rItem.maLayoutSize.Preferred << " Maximum: " << rItem .maLayoutSize.Maximum), 0); } else { ::std::ostringstream sal_detail_stream ; sal_detail_stream << "Please follow LayoutSize constraints: 0 ≤ " "Minimum ≤ Preferred ≤ Maximum." " Currently: Minimum: " << rItem.maLayoutSize.Minimum << " Preferred: " << rItem.maLayoutSize.Preferred << " Maximum: " << rItem .maLayoutSize.Maximum; ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_WARN ), ("sfx.sidebar"), ("/home/maarten/src/libreoffice/core/sfx2/source/sidebar/DeckLayouter.cxx" ":" "433" ": "), sal_detail_stream, 0); }; break; case SAL_DETAIL_LOG_ACTION_FATAL : if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart () << "Please follow LayoutSize constraints: 0 ≤ " "Minimum ≤ Preferred ≤ Maximum." " Currently: Minimum: " << rItem.maLayoutSize.Minimum << " Preferred: " << rItem.maLayoutSize.Preferred << " Maximum: " << rItem.maLayoutSize.Maximum) == 1) { :: sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("sfx.sidebar" ), ("/home/maarten/src/libreoffice/core/sfx2/source/sidebar/DeckLayouter.cxx" ":" "433" ": "), ::sal::detail::unwrapStream( ::sal::detail:: StreamStart() << "Please follow LayoutSize constraints: 0 ≤ " "Minimum ≤ Preferred ≤ Maximum." " Currently: Minimum: " << rItem.maLayoutSize.Minimum << " Preferred: " << rItem.maLayoutSize.Preferred << " Maximum: " << rItem .maLayoutSize.Maximum), 0); } else { ::std::ostringstream sal_detail_stream ; sal_detail_stream << "Please follow LayoutSize constraints: 0 ≤ " "Minimum ≤ Preferred ≤ Maximum." " Currently: Minimum: " << rItem.maLayoutSize.Minimum << " Preferred: " << rItem.maLayoutSize.Preferred << " Maximum: " << rItem .maLayoutSize.Maximum; ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_WARN ), ("sfx.sidebar"), ("/home/maarten/src/libreoffice/core/sfx2/source/sidebar/DeckLayouter.cxx" ":" "433" ": "), sal_detail_stream, 0); }; std::abort(); break ; } } } while (false); | ||||||
434 | } | ||||||
435 | |||||||
436 | sal_Int32 nWidth = xPanel->getMinimalWidth(); | ||||||
437 | |||||||
438 | uno::Reference<frame::XDesktop2> xDesktop | ||||||
439 | = frame::Desktop::create(comphelper::getProcessComponentContext()); | ||||||
440 | uno::Reference<frame::XFrame> xFrame = xDesktop->getActiveFrame(); | ||||||
441 | if (xFrame.is()) | ||||||
442 | { | ||||||
443 | SidebarController* pController | ||||||
444 | = SidebarController::GetSidebarControllerForFrame(xFrame); | ||||||
445 | if (pController && pController->getMaximumWidth() < nWidth) | ||||||
446 | { | ||||||
447 | // Add 100 extra pixels to still have the sidebar resizable | ||||||
448 | // (See also documentation of XSidebarPanel::getMinimalWidth) | ||||||
449 | pController->setMaximumWidth(nWidth + 100); | ||||||
450 | } | ||||||
451 | } | ||||||
452 | |||||||
453 | if (nWidth > rMinimalWidth) | ||||||
454 | rMinimalWidth = nWidth; | ||||||
455 | } | ||||||
456 | else | ||||||
457 | rItem.maLayoutSize = ui::LayoutSize(MinimalPanelHeight, -1, 0); | ||||||
458 | } | ||||||
459 | } | ||||||
460 | |||||||
461 | void DistributeHeights ( | ||||||
462 | ::std::vector<LayoutItem>& rLayoutItems, | ||||||
463 | const sal_Int32 nHeightToDistribute, | ||||||
464 | const sal_Int32 nContainerHeight, | ||||||
465 | const bool bMinimumHeightIsBase) | ||||||
466 | { | ||||||
467 | if (nHeightToDistribute <= 0) | ||||||
468 | return; | ||||||
469 | |||||||
470 | sal_Int32 nRemainingHeightToDistribute (nHeightToDistribute); | ||||||
471 | |||||||
472 | // Compute the weights as difference between panel base height | ||||||
473 | // (either its minimum or preferred height) and the container height. | ||||||
474 | sal_Int32 nTotalWeight (0); | ||||||
475 | sal_Int32 nNoMaximumCount (0); | ||||||
476 | |||||||
477 | for (auto& rItem : rLayoutItems) | ||||||
478 | { | ||||||
479 | if (rItem.maLayoutSize.Maximum == 0) | ||||||
480 | continue; | ||||||
481 | if (rItem.maLayoutSize.Maximum < 0) | ||||||
482 | ++nNoMaximumCount; | ||||||
483 | |||||||
484 | const sal_Int32 nBaseHeight ( | ||||||
485 | bMinimumHeightIsBase | ||||||
486 | ? rItem.maLayoutSize.Minimum | ||||||
487 | : rItem.maLayoutSize.Preferred); | ||||||
488 | if (nBaseHeight < nContainerHeight) | ||||||
489 | { | ||||||
490 | rItem.mnWeight = nContainerHeight - nBaseHeight; | ||||||
491 | nTotalWeight += rItem.mnWeight; | ||||||
492 | } | ||||||
493 | } | ||||||
494 | |||||||
495 | if (nTotalWeight == 0) | ||||||
496 | return; | ||||||
497 | |||||||
498 | // First pass of height distribution. | ||||||
499 | for (auto& rItem : rLayoutItems) | ||||||
500 | { | ||||||
501 | const sal_Int32 nBaseHeight ( | ||||||
502 | bMinimumHeightIsBase | ||||||
503 | ? rItem.maLayoutSize.Minimum | ||||||
504 | : rItem.maLayoutSize.Preferred); | ||||||
505 | sal_Int32 nDistributedHeight (rItem.mnWeight * nHeightToDistribute / nTotalWeight); | ||||||
506 | if (nBaseHeight+nDistributedHeight > rItem.maLayoutSize.Maximum | ||||||
507 | && rItem.maLayoutSize.Maximum >= 0) | ||||||
508 | { | ||||||
509 | nDistributedHeight = ::std::max<sal_Int32>(0, rItem.maLayoutSize.Maximum - nBaseHeight); | ||||||
510 | } | ||||||
511 | rItem.mnDistributedHeight = nDistributedHeight; | ||||||
512 | nRemainingHeightToDistribute -= nDistributedHeight; | ||||||
513 | } | ||||||
514 | |||||||
515 | if (nRemainingHeightToDistribute == 0) | ||||||
516 | return; | ||||||
517 | OSL_ASSERT(nRemainingHeightToDistribute > 0)do { if (true && (!(nRemainingHeightToDistribute > 0))) { sal_detail_logFormat((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl" ), ("/home/maarten/src/libreoffice/core/sfx2/source/sidebar/DeckLayouter.cxx" ":" "517" ": "), "OSL_ASSERT: %s", "nRemainingHeightToDistribute > 0" ); } } while (false); | ||||||
518 | |||||||
519 | // It is possible that not all of the height could be distributed | ||||||
520 | // because of Maximum heights being smaller than expected. | ||||||
521 | // Distribute the remaining height between the panels that have no | ||||||
522 | // Maximum (ie Maximum==-1). | ||||||
523 | if (nNoMaximumCount == 0) | ||||||
524 | { | ||||||
525 | // There are no panels with unrestricted height. | ||||||
526 | return; | ||||||
527 | } | ||||||
528 | |||||||
529 | const sal_Int32 nAdditionalHeightPerPanel(nRemainingHeightToDistribute / nNoMaximumCount); | ||||||
530 | // Handle rounding error. | ||||||
531 | sal_Int32 nAdditionalHeightForFirstPanel (nRemainingHeightToDistribute | ||||||
532 | - nNoMaximumCount*nAdditionalHeightPerPanel); | ||||||
533 | |||||||
534 | for (auto& rItem : rLayoutItems) | ||||||
535 | { | ||||||
536 | if (rItem.maLayoutSize.Maximum < 0) | ||||||
537 | { | ||||||
538 | rItem.mnDistributedHeight += nAdditionalHeightPerPanel + nAdditionalHeightForFirstPanel; | ||||||
539 | nRemainingHeightToDistribute -= nAdditionalHeightPerPanel + nAdditionalHeightForFirstPanel; | ||||||
540 | } | ||||||
541 | } | ||||||
542 | |||||||
543 | OSL_ASSERT(nRemainingHeightToDistribute==0)do { if (true && (!(nRemainingHeightToDistribute==0)) ) { sal_detail_logFormat((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl" ), ("/home/maarten/src/libreoffice/core/sfx2/source/sidebar/DeckLayouter.cxx" ":" "543" ": "), "OSL_ASSERT: %s", "nRemainingHeightToDistribute==0" ); } } while (false); | ||||||
544 | } | ||||||
545 | |||||||
546 | tools::Rectangle PlaceDeckTitle ( | ||||||
547 | vcl::Window& rDeckTitleBar, | ||||||
548 | const tools::Rectangle& rAvailableSpace) | ||||||
549 | { | ||||||
550 | if (static_cast<DockingWindow*>(rDeckTitleBar.GetParent()->GetParent())->IsFloatingMode()) | ||||||
551 | { | ||||||
552 | // When the side bar is undocked then the outer system window displays the deck title. | ||||||
553 | rDeckTitleBar.Hide(); | ||||||
554 | return rAvailableSpace; | ||||||
555 | } | ||||||
556 | else | ||||||
557 | { | ||||||
558 | const sal_Int32 nDeckTitleBarHeight (Theme::GetInteger(Theme::Int_DeckTitleBarHeight) * rDeckTitleBar.GetDPIScaleFactor()); | ||||||
559 | rDeckTitleBar.setPosSizePixel( | ||||||
560 | rAvailableSpace.Left(), | ||||||
561 | rAvailableSpace.Top(), | ||||||
562 | rAvailableSpace.GetWidth(), | ||||||
563 | nDeckTitleBarHeight); | ||||||
564 | rDeckTitleBar.Show(); | ||||||
565 | return tools::Rectangle( | ||||||
566 | rAvailableSpace.Left(), | ||||||
567 | rAvailableSpace.Top() + nDeckTitleBarHeight, | ||||||
568 | rAvailableSpace.Right(), | ||||||
569 | rAvailableSpace.Bottom()); | ||||||
570 | } | ||||||
571 | } | ||||||
572 | |||||||
573 | tools::Rectangle PlaceVerticalScrollBar ( | ||||||
574 | ScrollBar& rVerticalScrollBar, | ||||||
575 | const tools::Rectangle& rAvailableSpace, | ||||||
576 | const bool bShowVerticalScrollBar) | ||||||
577 | { | ||||||
578 | if (bShowVerticalScrollBar) | ||||||
579 | { | ||||||
580 | const sal_Int32 nScrollBarWidth (rVerticalScrollBar.GetSizePixel().Width()); | ||||||
581 | rVerticalScrollBar.setPosSizePixel( | ||||||
582 | rAvailableSpace.Right() - nScrollBarWidth + 1, | ||||||
583 | rAvailableSpace.Top(), | ||||||
584 | nScrollBarWidth, | ||||||
585 | rAvailableSpace.GetHeight()); | ||||||
586 | rVerticalScrollBar.Show(); | ||||||
587 | return tools::Rectangle( | ||||||
588 | rAvailableSpace.Left(), | ||||||
589 | rAvailableSpace.Top(), | ||||||
590 | rAvailableSpace.Right() - nScrollBarWidth, | ||||||
591 | rAvailableSpace.Bottom()); | ||||||
592 | } | ||||||
593 | else | ||||||
594 | { | ||||||
595 | rVerticalScrollBar.Hide(); | ||||||
596 | return rAvailableSpace; | ||||||
597 | } | ||||||
598 | } | ||||||
599 | |||||||
600 | void SetupVerticalScrollBar( | ||||||
601 | ScrollBar& rVerticalScrollBar, | ||||||
602 | const sal_Int32 nContentHeight, | ||||||
603 | const sal_Int32 nVisibleHeight) | ||||||
604 | { | ||||||
605 | OSL_ASSERT(nContentHeight > nVisibleHeight)do { if (true && (!(nContentHeight > nVisibleHeight ))) { sal_detail_logFormat((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl" ), ("/home/maarten/src/libreoffice/core/sfx2/source/sidebar/DeckLayouter.cxx" ":" "605" ": "), "OSL_ASSERT: %s", "nContentHeight > nVisibleHeight" ); } } while (false); | ||||||
606 | |||||||
607 | rVerticalScrollBar.SetRangeMin(0); | ||||||
608 | rVerticalScrollBar.SetRangeMax(nContentHeight-1); | ||||||
609 | rVerticalScrollBar.SetVisibleSize(nVisibleHeight); | ||||||
610 | } | ||||||
611 | |||||||
612 | void UpdateFiller ( | ||||||
613 | vcl::Window& rFiller, | ||||||
614 | const tools::Rectangle& rBox) | ||||||
615 | { | ||||||
616 | if (rBox.GetHeight() > 0) | ||||||
617 | { | ||||||
618 | // Show the filler. | ||||||
619 | rFiller.SetBackground(Theme::GetPaint(Theme::Paint_PanelBackground).GetWallpaper()); | ||||||
620 | rFiller.SetPosSizePixel(rBox.TopLeft(), rBox.GetSize()); | ||||||
621 | rFiller.Show(); | ||||||
622 | } | ||||||
623 | else | ||||||
624 | { | ||||||
625 | // Hide the filler. | ||||||
626 | rFiller.Hide(); | ||||||
627 | } | ||||||
628 | } | ||||||
629 | |||||||
630 | } | ||||||
631 | |||||||
632 | } // end of namespace sfx2::sidebar | ||||||
633 | |||||||
634 | /* 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 |