LibreOffice Module svx (master) 1
SvxColorValueSet.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
21#include <svx/xtable.hxx>
22#include <vcl/svapp.hxx>
23#include <vcl/settings.hxx>
24#include <osl/diagnose.h>
25
26#include <svx/uiobject.hxx>
27
28SvxColorValueSet::SvxColorValueSet(std::unique_ptr<weld::ScrolledWindow> pWindow)
29 : ValueSet(std::move(pWindow))
30{
31 SetEdgeBlending(true);
32}
33
35{
37}
38
40{
42
43 return rStyleSettings.GetListBoxPreviewDefaultPixelSize().Height() + 1;
44}
45
47{
49
50 return rStyleSettings.GetColorValueSetColumnCount();
51}
52
53void SvxColorValueSet::addEntriesForXColorList(const XColorList& rXColorList, sal_uInt32 nStartIndex)
54{
55 const sal_uInt32 nColorCount(rXColorList.Count());
56
57 for(sal_uInt32 nIndex(0); nIndex < nColorCount; nIndex++, nStartIndex++)
58 {
59 const XColorEntry* pEntry = rXColorList.GetColor(nIndex);
60
61 if(pEntry)
62 {
63 InsertItem(nStartIndex, pEntry->GetColor(), pEntry->GetName());
64 }
65 else
66 {
67 OSL_ENSURE(false, "OOps, XColorList with empty entries (!)");
68 }
69 }
70}
71
72void SvxColorValueSet::addEntriesForColorSet(const std::set<Color>& rColorSet, std::u16string_view rNamePrefix)
73{
74 sal_uInt32 nStartIndex = 1;
75 if(rNamePrefix.size() != 0)
76 {
77 for(const auto& rColor : rColorSet)
78 {
79 InsertItem(nStartIndex, rColor, rNamePrefix + OUString::number(nStartIndex));
80 nStartIndex++;
81 }
82 }
83 else
84 {
85 for(const auto& rColor : rColorSet)
86 {
87 InsertItem(nStartIndex, rColor, "");
88 nStartIndex++;
89 }
90 }
91}
92
94{
95 if(!nEntryCount)
96 {
97 nEntryCount++;
98 }
99
100 const sal_uInt32 nRowCount(ceil(double(nEntryCount)/SvxColorValueSet::getColumnCount()));
102 const WinBits aWinBits(GetStyle() & ~WB_VSCROLL);
103
104 if (nRowCount > SvxColorValueSet::getMaxRowCount())
105 {
106 SetStyle(aWinBits|WB_VSCROLL);
107 }
108 else
109 {
110 SetStyle(aWinBits);
111 }
112
114 SetLineCount(std::min(nRowCount, SvxColorValueSet::getMaxRowCount()));
115 SetItemWidth(aItemSize.Width());
116 SetItemHeight(aItemSize.Height());
117
118 return CalcWindowSizePixel(aItemSize);
119}
120
122{
123 layoutToGivenHeight(GetOutputSizePixel().Height(), GetItemCount());
125}
126
127void SvxColorValueSet::layoutToGivenHeight(sal_uInt32 nHeight, sal_uInt32 nEntryCount)
128{
129 if(!nEntryCount)
130 {
131 nEntryCount++;
132 }
133
135 const WinBits aWinBits(GetStyle() & ~WB_VSCROLL);
136
137 // get size with all fields disabled
138 const WinBits aWinBitsNoScrollNoFields(GetStyle() & ~(WB_VSCROLL|WB_NAMEFIELD|WB_NONEFIELD));
139 SetStyle(aWinBitsNoScrollNoFields);
140 const Size aSizeNoScrollNoFields(CalcWindowSizePixel(aItemSize, SvxColorValueSet::getColumnCount()));
141
142 // get size with all needed fields
143 SetStyle(aWinBits);
145
146 const Size aItemSizePixel(CalcItemSizePixel(aItemSize));
147 // calculate field height and available height for requested height
148 const sal_uInt32 nFieldHeight(aNewSize.Height() - aSizeNoScrollNoFields.Height());
149 const sal_uInt32 nAvailableHeight(nHeight >= nFieldHeight ? nHeight - nFieldHeight + aItemSizePixel.Height() - 1 : 0);
150
151 // calculate how many lines can be shown there
152 const sal_uInt32 nLineCount(nAvailableHeight / aItemSizePixel.Height());
153 const sal_uInt32 nLineMax(ceil(double(nEntryCount)/SvxColorValueSet::getColumnCount()));
154
155 if(nLineMax > nLineCount)
156 {
157 SetStyle(aWinBits|WB_VSCROLL);
158 }
159
160 SetItemWidth(aItemSize.Width());
161 SetItemHeight(aItemSize.Height());
163 SetLineCount(nLineCount);
164}
165
166/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
const StyleSettings & GetStyleSettings() const
static const AllSettings & GetSettings()
constexpr tools::Long Height() const
constexpr tools::Long Width() const
const Size & GetListBoxPreviewDefaultPixelSize() const
sal_uInt16 GetColorValueSetColumnCount() const
static std::unique_ptr< UIObject > create(vcl::Window *pWindow)
Definition: sdrobject.cxx:181
virtual FactoryFunction GetUITestFactory() const override
SvxColorValueSet(std::unique_ptr< weld::ScrolledWindow > pWindow)
virtual void Resize() override
Size layoutAllVisible(sal_uInt32 nEntryCount)
static sal_uInt32 getColumnCount()
static sal_uInt32 getEntryEdgeLength()
void addEntriesForColorSet(const std::set< Color > &rColorSet, std::u16string_view rNamePrefix)
void addEntriesForXColorList(const XColorList &rXColorList, sal_uInt32 nStartIndex=1)
void layoutToGivenHeight(sal_uInt32 nHeight, sal_uInt32 nEntryCount)
static constexpr sal_uInt32 getMaxRowCount()
void InsertItem(sal_uInt16 nItemId, const Image &rImage)
size_t GetItemCount() const
void SetEdgeBlending(bool bNew)
void SetStyle(WinBits nStyle)
Size CalcWindowSizePixel(const Size &rItemSize, sal_uInt16 nCalcCols=0, sal_uInt16 nCalcLines=0) const
Size CalcItemSizePixel(const Size &rSize) const
void SetLineCount(sal_uInt16 nNewLines=0)
WinBits GetStyle() const
void SetColCount(sal_uInt16 nNewCols=1)
virtual void Resize() override
void SetItemHeight(tools::Long nLineHeight)
void SetItemWidth(tools::Long nItemWidth)
const Color & GetColor() const
Definition: xtable.hxx:50
XColorEntry * GetColor(tools::Long nIndex) const
Definition: xtabcolr.cxx:50
const OUString & GetName() const
tools::Long Count() const
Definition: xtable.cxx:122
std::function< std::unique_ptr< UIObject >(vcl::Window *)> FactoryFunction
sal_Int32 nIndex
#define WB_NONEFIELD
#define WB_NAMEFIELD
sal_Int64 WinBits
WinBits const WB_VSCROLL