LibreOffice Module sd (master) 1
PreviewValueSet.cxx
Go to the documentation of this file.
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 "PreviewValueSet.hxx"
21#include <vcl/commandevent.hxx>
22
23namespace sd::sidebar {
24
25const int gnBorderWidth(3);
26const int gnBorderHeight(3);
27
29 : ValueSet(nullptr)
30 , maPreviewSize(10,10)
31{
32 SetStyle (
33 GetStyle()
34 & ~(WB_ITEMBORDER)// | WB_MENUSTYLEVALUESET)
35 // | WB_FLATVALUESET);
36 );
37}
38
40{
41 ValueSet::SetDrawingArea(pDrawingArea);
42
43 SetColCount(2);
45}
46
48{
49}
50
52{
53 maPreviewSize = rSize;
54}
55
57{
59}
60
62{
63 if (rEvent.GetCommand() != CommandEventId::ContextMenu)
64 return ValueSet::Command(rEvent);
65 maContextMenuHandler.Call(rEvent.IsMouseEvent() ? &rEvent.GetMousePosPixel() : nullptr);
66 return true;
67}
68
70{
72
73 Size aWindowSize (GetOutputSizePixel());
74 if (!aWindowSize.IsEmpty())
75 {
76 Rearrange();
77 }
78}
79
81{
82 sal_uInt16 nNewColumnCount (CalculateColumnCount (
83 GetOutputSizePixel().Width()));
84 sal_uInt16 nNewRowCount (CalculateRowCount (nNewColumnCount));
85
86 SetFormat();
87 SetColCount(nNewColumnCount);
88 SetLineCount(nNewRowCount);
89}
90
91sal_uInt16 PreviewValueSet::CalculateColumnCount (int nWidth) const
92{
93 int nColumnCount = 0;
94 if (nWidth > 0)
95 {
96 nColumnCount = nWidth / (maPreviewSize.Width() + 2*gnBorderWidth);
97 if (nColumnCount < 1)
98 nColumnCount = 1;
99 }
100 return static_cast<sal_uInt16>(nColumnCount);
101}
102
103sal_uInt16 PreviewValueSet::CalculateRowCount (sal_uInt16 nColumnCount) const
104{
105 int nRowCount = 0;
106 int nItemCount = GetItemCount();
107 if (nColumnCount > 0)
108 {
109 nRowCount = (nItemCount+nColumnCount-1) / nColumnCount;
110 if (nRowCount < 1)
111 nRowCount = 1;
112 }
113
114 return static_cast<sal_uInt16>(nRowCount);
115}
116
117sal_Int32 PreviewValueSet::GetPreferredHeight (sal_Int32 nWidth)
118{
119 int nRowCount (CalculateRowCount(CalculateColumnCount(nWidth)));
120 int nItemHeight (maPreviewSize.Height());
121
122 return nRowCount * (nItemHeight + 2*gnBorderHeight);
123}
124
125} // end of namespace sd::sidebar
126
127/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
CommandEventId GetCommand() const
const Point & GetMousePosPixel() const
bool IsMouseEvent() const
bool IsEmpty() const
constexpr tools::Long Height() const
constexpr tools::Long Width() const
void SetFormat()
size_t GetItemCount() const
void SetStyle(WinBits nStyle)
void SetLineCount(sal_uInt16 nNewLines=0)
WinBits GetStyle() const
void SetColCount(sal_uInt16 nNewCols=1)
virtual void Resize() override
virtual void SetDrawingArea(weld::DrawingArea *pDrawingArea) override
void SetExtraSpacing(sal_uInt16 nNewSpacing)
Link< const Point *, void > maContextMenuHandler
void Rearrange()
Set the number of rows and columns according to the current number of items.
virtual void SetDrawingArea(weld::DrawingArea *pDrawingArea) override
sal_uInt16 CalculateRowCount(sal_uInt16 nColumnCount) const
virtual bool Command(const CommandEvent &rEvent) override
sal_uInt16 CalculateColumnCount(int nWidth) const
sal_Int32 GetPreferredHeight(sal_Int32 nWidth)
void SetContextMenuHandler(const Link< const Point *, void > &rLink)
virtual void Resize() override
virtual ~PreviewValueSet() override
void SetPreviewSize(const Size &rSize)
const int gnBorderHeight(3)
const int gnBorderWidth(3)
#define WB_ITEMBORDER