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/builderfactory.hxx>
23 #include <vcl/svapp.hxx>
24 #include <vcl/settings.hxx>
26 SvxColorValueSet::SvxColorValueSet(vcl::Window
* _pParent
, WinBits nWinStyle
)
27 : ValueSet(_pParent
, nWinStyle
)
29 SetEdgeBlending(true);
32 VCL_BUILDER_DECL_FACTORY(SvxColorValueSet
)
34 WinBits nWinBits
= WB_TABSTOP
;
36 OString sBorder
= VclBuilder::extractCustomProperty(rMap
);
37 if (!sBorder
.isEmpty())
38 nWinBits
|= WB_BORDER
;
40 rRet
= VclPtr
<SvxColorValueSet
>::Create(pParent
, nWinBits
);
43 sal_uInt32
SvxColorValueSet::getMaxRowCount()
45 const StyleSettings
& rStyleSettings
= Application::GetSettings().GetStyleSettings();
47 return rStyleSettings
.GetColorValueSetMaximumRowCount();
50 sal_uInt32
SvxColorValueSet::getEntryEdgeLength()
52 const StyleSettings
& rStyleSettings
= Application::GetSettings().GetStyleSettings();
54 return rStyleSettings
.GetListBoxPreviewDefaultPixelSize().Height() + 1;
57 sal_uInt32
SvxColorValueSet::getColumnCount()
59 const StyleSettings
& rStyleSettings
= Application::GetSettings().GetStyleSettings();
61 return rStyleSettings
.GetColorValueSetColumnCount();
64 void SvxColorValueSet::addEntriesForXColorList(const XColorList
& rXColorList
, sal_uInt32 nStartIndex
)
66 const sal_uInt32
nColorCount(rXColorList
.Count());
68 for(sal_uInt32
nIndex(0); nIndex
< nColorCount
; nIndex
++, nStartIndex
++)
70 const XColorEntry
* pEntry
= rXColorList
.GetColor(nIndex
);
74 InsertItem(nStartIndex
, pEntry
->GetColor(), pEntry
->GetName());
78 OSL_ENSURE(false, "OOps, XColorList with empty entries (!)");
83 void SvxColorValueSet::addEntriesForColorSet(const std::set
<Color
>& rColorSet
, const OUString
& rNamePrefix
, sal_uInt32 nStartIndex
)
85 if(rNamePrefix
.getLength() != 0)
87 for(std::set
<Color
>::const_iterator it
= rColorSet
.begin();
88 it
!= rColorSet
.end(); ++it
, nStartIndex
++)
90 InsertItem(nStartIndex
, *it
, rNamePrefix
+ OUString::number(nStartIndex
));
95 for(std::set
<Color
>::const_iterator it
= rColorSet
.begin();
96 it
!= rColorSet
.end(); ++it
, nStartIndex
++)
98 InsertItem(nStartIndex
, *it
, "");
103 Size
SvxColorValueSet::layoutAllVisible(sal_uInt32 nEntryCount
)
110 const sal_uInt32
nRowCount(ceil(double(nEntryCount
)/getColumnCount()));
111 const Size
aItemSize(getEntryEdgeLength() - 2, getEntryEdgeLength() - 2);
112 const WinBits
aWinBits(GetStyle() & ~WB_VSCROLL
);
114 if(nRowCount
> getMaxRowCount())
116 SetStyle(aWinBits
|WB_VSCROLL
);
123 SetColCount(getColumnCount());
124 SetLineCount(std::min(nRowCount
, getMaxRowCount()));
125 SetItemWidth(aItemSize
.Width());
126 SetItemHeight(aItemSize
.Height());
128 return CalcWindowSizePixel(aItemSize
);
131 void SvxColorValueSet::Resize()
133 vcl::Window
*pParent
= GetParent();
134 //don't do this for the drop down color palettes
135 if (pParent
&& pParent
->GetType() != WINDOW_FLOATINGWINDOW
)
136 layoutToGivenHeight(GetOutputSizePixel().Height(), GetItemCount());
140 Size
SvxColorValueSet::layoutToGivenHeight(sal_uInt32 nHeight
, sal_uInt32 nEntryCount
)
147 const Size
aItemSize(getEntryEdgeLength(), getEntryEdgeLength());
148 const WinBits
aWinBits(GetStyle() & ~WB_VSCROLL
);
150 // get size with all fields disabled
151 const WinBits
aWinBitsNoScrollNoFields(GetStyle() & ~(WB_VSCROLL
|WB_NAMEFIELD
|WB_NONEFIELD
));
152 SetStyle(aWinBitsNoScrollNoFields
);
153 const Size
aSizeNoScrollNoFields(CalcWindowSizePixel(aItemSize
, getColumnCount()));
155 // get size with all needed fields
157 Size
aNewSize(CalcWindowSizePixel(aItemSize
, getColumnCount()));
159 const Size
aItemSizePixel(CalcItemSizePixel(aItemSize
));
160 // calculate field height and available height for requested height
161 const sal_uInt32
nFieldHeight(aNewSize
.Height() - aSizeNoScrollNoFields
.Height());
162 const sal_uInt32
nAvailableHeight(nHeight
>= nFieldHeight
? nHeight
- nFieldHeight
+ aItemSizePixel
.Height() - 1 : 0);
164 // calculate how many lines can be shown there
165 const sal_uInt32
nLineCount(nAvailableHeight
/ aItemSizePixel
.Height());
166 const sal_uInt32
nLineMax(ceil(double(nEntryCount
)/getColumnCount()));
168 if(nLineMax
> nLineCount
)
170 SetStyle(aWinBits
|WB_VSCROLL
);
173 // set height to wanted height
174 aNewSize
.Height() = nHeight
;
176 SetItemWidth(aItemSize
.Width());
177 SetItemHeight(aItemSize
.Height());
178 SetColCount(getColumnCount());
179 SetLineCount(nLineCount
);
184 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */