2 * This file is part of the LibreOffice project.
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 * This file incorporates work covered by the following license notice:
10 * Licensed to the Apache Software Foundation (ASF) under one or more
11 * contributor license agreements. See the NOTICE file distributed
12 * with this work for additional information regarding copyright
13 * ownership. The ASF licenses this file to you under the Apache
14 * License, Version 2.0 (the "License"); you may not use this file
15 * except in compliance with the License. You may obtain a copy of
16 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
19 #include <svx/SvxColorValueSet.hxx>
20 #include <svx/xtable.hxx>
21 #include <vcl/builder.hxx>
22 #include <vcl/svapp.hxx>
24 //////////////////////////////////////////////////////////////////////////////
26 SvxColorValueSet::SvxColorValueSet(Window
* _pParent
, WinBits nWinStyle
)
27 : ValueSet(_pParent
, nWinStyle
)
29 SetEdgeBlending(true);
32 extern "C" SAL_DLLPUBLIC_EXPORT Window
* SAL_CALL
makeSvxColorValueSet(Window
*pParent
, VclBuilder::stringmap
&rMap
)
34 WinBits nWinBits
= WB_TABSTOP
;
36 VclBuilder::stringmap::iterator aFind
= rMap
.find(OString("border"));
37 if (aFind
!= rMap
.end())
39 if (toBool(aFind
->second
))
40 nWinBits
|= WB_BORDER
;
44 return new SvxColorValueSet(pParent
, nWinBits
);
47 SvxColorValueSet::SvxColorValueSet(Window
* _pParent
, const ResId
& rResId
)
48 : ValueSet(_pParent
, rResId
)
50 SetEdgeBlending(true);
53 sal_uInt32
SvxColorValueSet::getMaxRowCount() const
55 const StyleSettings
& rStyleSettings
= Application::GetSettings().GetStyleSettings();
57 return rStyleSettings
.GetColorValueSetMaximumRowCount();
60 sal_uInt32
SvxColorValueSet::getEntryEdgeLength() const
62 const StyleSettings
& rStyleSettings
= Application::GetSettings().GetStyleSettings();
64 return rStyleSettings
.GetListBoxPreviewDefaultPixelSize().Height() + 1;
67 sal_uInt32
SvxColorValueSet::getColumnCount() const
69 const StyleSettings
& rStyleSettings
= Application::GetSettings().GetStyleSettings();
71 return rStyleSettings
.GetColorValueSetColumnCount();
74 void SvxColorValueSet::addEntriesForXColorList(const XColorList
& rXColorList
, sal_uInt32 nStartIndex
)
76 const sal_uInt32
nColorCount(rXColorList
.Count());
78 for(sal_uInt32
nIndex(0); nIndex
< nColorCount
; nIndex
++, nStartIndex
++)
80 const XColorEntry
* pEntry
= rXColorList
.GetColor(nIndex
);
84 InsertItem(nStartIndex
, pEntry
->GetColor(), pEntry
->GetName());
88 OSL_ENSURE(false, "OOps, XColorList with empty entries (!)");
93 Size
SvxColorValueSet::layoutAllVisible(sal_uInt32 nEntryCount
)
100 const sal_uInt32
nRowCount(ceil(double(nEntryCount
)/getColumnCount()));
101 const Size
aItemSize(getEntryEdgeLength() - 2, getEntryEdgeLength() - 2);
102 const WinBits
aWinBits(GetStyle() & ~WB_VSCROLL
);
104 if(nRowCount
> getMaxRowCount())
106 SetStyle(aWinBits
|WB_VSCROLL
);
113 SetColCount(getColumnCount());
114 SetLineCount(std::min(nRowCount
, getMaxRowCount()));
115 SetItemWidth(aItemSize
.Width());
116 SetItemHeight(aItemSize
.Height());
118 return CalcWindowSizePixel(aItemSize
);
121 void SvxColorValueSet::Resize()
123 Window
*pParent
= GetParent();
124 //don't do this for the drop down color palettes
125 if (pParent
&& pParent
->GetType() != WINDOW_FLOATINGWINDOW
)
126 layoutToGivenHeight(GetOutputSizePixel().Height(), GetItemCount());
130 Size
SvxColorValueSet::layoutToGivenHeight(sal_uInt32 nHeight
, sal_uInt32 nEntryCount
)
137 const Size
aItemSize(getEntryEdgeLength(), getEntryEdgeLength());
138 const WinBits
aWinBits(GetStyle() & ~WB_VSCROLL
);
140 // get size whith all fields disabled
141 const WinBits
aWinBitsNoScrollNoFields(GetStyle() & ~(WB_VSCROLL
|WB_NAMEFIELD
|WB_NONEFIELD
));
142 SetStyle(aWinBitsNoScrollNoFields
);
143 const Size
aSizeNoScrollNoFields(CalcWindowSizePixel(aItemSize
, getColumnCount()));
145 // get size with all needed fields
147 Size
aNewSize(CalcWindowSizePixel(aItemSize
, getColumnCount()));
149 // evtl. activate vertical scroll
150 const bool bAdaptHeight(static_cast< sal_uInt32
>(aNewSize
.Height()) > nHeight
);
154 SetStyle(aWinBits
|WB_VSCROLL
);
155 aNewSize
= CalcWindowSizePixel(aItemSize
, getColumnCount());
158 // calculate field height and available height for requested height
159 const sal_uInt32
nFieldHeight(aNewSize
.Height() - aSizeNoScrollNoFields
.Height());
160 const sal_uInt32
nAvailableHeight(nHeight
>= nFieldHeight
? nHeight
- nFieldHeight
: 0);
162 // calculate how many lines can be shown there
163 const Size
aItemSizePixel(CalcItemSizePixel(aItemSize
));
164 const sal_uInt32
nLineCount((nAvailableHeight
+ aItemSizePixel
.Height() - 1) / aItemSizePixel
.Height());
166 // set height to wanted height
167 aNewSize
.Height() = nHeight
;
169 SetItemWidth(aItemSize
.Width());
170 SetItemHeight(aItemSize
.Height());
171 SetColCount(getColumnCount());
172 SetLineCount(nLineCount
);