1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <svx/SvxColorValueSet.hxx>
21 #include <svx/xtable.hxx>
22 #include <vcl/svapp.hxx>
23 #include <vcl/settings.hxx>
24 #include <osl/diagnose.h>
26 #include <svx/uiobject.hxx>
28 SvxColorValueSet::SvxColorValueSet(std::unique_ptr
<weld::ScrolledWindow
> pWindow
)
29 : ValueSet(std::move(pWindow
))
31 SetEdgeBlending(true);
34 FactoryFunction
SvxColorValueSet::GetUITestFactory() const
36 return SvxColorValueSetUIObject::create
;
39 sal_uInt32
SvxColorValueSet::getMaxRowCount()
41 return StyleSettings::GetColorValueSetMaximumRowCount();
44 sal_uInt32
SvxColorValueSet::getEntryEdgeLength()
46 const StyleSettings
& rStyleSettings
= Application::GetSettings().GetStyleSettings();
48 return rStyleSettings
.GetListBoxPreviewDefaultPixelSize().Height() + 1;
51 sal_uInt32
SvxColorValueSet::getColumnCount()
53 const StyleSettings
& rStyleSettings
= Application::GetSettings().GetStyleSettings();
55 return rStyleSettings
.GetColorValueSetColumnCount();
58 void SvxColorValueSet::addEntriesForXColorList(const XColorList
& rXColorList
, sal_uInt32 nStartIndex
)
60 const sal_uInt32
nColorCount(rXColorList
.Count());
62 for(sal_uInt32
nIndex(0); nIndex
< nColorCount
; nIndex
++, nStartIndex
++)
64 const XColorEntry
* pEntry
= rXColorList
.GetColor(nIndex
);
68 InsertItem(nStartIndex
, pEntry
->GetColor(), pEntry
->GetName());
72 OSL_ENSURE(false, "OOps, XColorList with empty entries (!)");
77 void SvxColorValueSet::addEntriesForColorSet(const std::set
<Color
>& rColorSet
, const OUString
& rNamePrefix
)
79 sal_uInt32 nStartIndex
= 1;
80 if(rNamePrefix
.getLength() != 0)
82 for(const auto& rColor
: rColorSet
)
84 InsertItem(nStartIndex
, rColor
, rNamePrefix
+ OUString::number(nStartIndex
));
90 for(const auto& rColor
: rColorSet
)
92 InsertItem(nStartIndex
, rColor
, "");
98 Size
SvxColorValueSet::layoutAllVisible(sal_uInt32 nEntryCount
)
105 const sal_uInt32
nRowCount(ceil(double(nEntryCount
)/SvxColorValueSet::getColumnCount()));
106 const Size
aItemSize(SvxColorValueSet::getEntryEdgeLength() - 2, SvxColorValueSet::getEntryEdgeLength() - 2);
107 const WinBits
aWinBits(GetStyle() & ~WB_VSCROLL
);
109 if (nRowCount
> SvxColorValueSet::getMaxRowCount())
111 SetStyle(aWinBits
|WB_VSCROLL
);
118 SetColCount(SvxColorValueSet::getColumnCount());
119 SetLineCount(std::min(nRowCount
, SvxColorValueSet::getMaxRowCount()));
120 SetItemWidth(aItemSize
.Width());
121 SetItemHeight(aItemSize
.Height());
123 return CalcWindowSizePixel(aItemSize
);
126 void SvxColorValueSet::Resize()
128 layoutToGivenHeight(GetOutputSizePixel().Height(), GetItemCount());
132 Size
SvxColorValueSet::layoutToGivenHeight(sal_uInt32 nHeight
, sal_uInt32 nEntryCount
)
139 const Size
aItemSize(SvxColorValueSet::getEntryEdgeLength() - 2, SvxColorValueSet::getEntryEdgeLength() - 2);
140 const WinBits
aWinBits(GetStyle() & ~WB_VSCROLL
);
142 // get size with all fields disabled
143 const WinBits
aWinBitsNoScrollNoFields(GetStyle() & ~(WB_VSCROLL
|WB_NAMEFIELD
|WB_NONEFIELD
));
144 SetStyle(aWinBitsNoScrollNoFields
);
145 const Size
aSizeNoScrollNoFields(CalcWindowSizePixel(aItemSize
, SvxColorValueSet::getColumnCount()));
147 // get size with all needed fields
149 Size
aNewSize(CalcWindowSizePixel(aItemSize
, SvxColorValueSet::getColumnCount()));
151 const Size
aItemSizePixel(CalcItemSizePixel(aItemSize
));
152 // calculate field height and available height for requested height
153 const sal_uInt32
nFieldHeight(aNewSize
.Height() - aSizeNoScrollNoFields
.Height());
154 const sal_uInt32
nAvailableHeight(nHeight
>= nFieldHeight
? nHeight
- nFieldHeight
+ aItemSizePixel
.Height() - 1 : 0);
156 // calculate how many lines can be shown there
157 const sal_uInt32
nLineCount(nAvailableHeight
/ aItemSizePixel
.Height());
158 const sal_uInt32
nLineMax(ceil(double(nEntryCount
)/SvxColorValueSet::getColumnCount()));
160 if(nLineMax
> nLineCount
)
162 SetStyle(aWinBits
|WB_VSCROLL
);
165 // set height to wanted height
166 aNewSize
.setHeight( nHeight
);
168 SetItemWidth(aItemSize
.Width());
169 SetItemHeight(aItemSize
.Height());
170 SetColCount(SvxColorValueSet::getColumnCount());
171 SetLineCount(nLineCount
);
176 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */