1 /**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 *
20 *************************************************************/
21
22 // MARKER(update_precomp.py): autogen include statement, do not remove
23 #include "precompiled_svx.hxx"
24
25 #include <svx/SvxColorValueSet.hxx>
26 #include <svx/xtable.hxx>
27 #include <vcl/svapp.hxx>
28
29 //////////////////////////////////////////////////////////////////////////////
30
SvxColorValueSet(Window * _pParent,WinBits nWinStyle)31 SvxColorValueSet::SvxColorValueSet(Window* _pParent, WinBits nWinStyle)
32 : ValueSet(_pParent, nWinStyle)
33 {
34 SetEdgeBlending(true);
35 }
36
SvxColorValueSet(Window * _pParent,const ResId & rResId)37 SvxColorValueSet::SvxColorValueSet(Window* _pParent, const ResId& rResId)
38 : ValueSet(_pParent, rResId)
39 {
40 SetEdgeBlending(true);
41 }
42
getMaxRowCount() const43 sal_uInt32 SvxColorValueSet::getMaxRowCount() const
44 {
45 const StyleSettings& rStyleSettings = Application::GetSettings().GetStyleSettings();
46
47 return rStyleSettings.GetColorValueSetMaximumRowCount();
48 }
49
getEntryEdgeLength() const50 sal_uInt32 SvxColorValueSet::getEntryEdgeLength() const
51 {
52 const StyleSettings& rStyleSettings = Application::GetSettings().GetStyleSettings();
53
54 return rStyleSettings.GetListBoxPreviewDefaultPixelSize().Height() + 1;
55 }
56
getColumnCount() const57 sal_uInt32 SvxColorValueSet::getColumnCount() const
58 {
59 const StyleSettings& rStyleSettings = Application::GetSettings().GetStyleSettings();
60
61 return rStyleSettings.GetColorValueSetColumnCount();
62 }
63
addEntriesForXColorList(const XColorListSharedPtr aXColorList,sal_uInt32 nStartIndex)64 void SvxColorValueSet::addEntriesForXColorList(const XColorListSharedPtr aXColorList, sal_uInt32 nStartIndex)
65 {
66 const sal_uInt32 nColorCount(aXColorList ? aXColorList->Count() : 0);
67
68 for(sal_uInt32 nIndex(0); nIndex < nColorCount; nIndex++, nStartIndex++)
69 {
70 const XColorEntry* pEntry = aXColorList->GetColor(nIndex);
71
72 if(pEntry)
73 {
74 InsertItem(nStartIndex, pEntry->GetColor(), pEntry->GetName());
75 }
76 else
77 {
78 OSL_ENSURE(false, "OOps, XColorList with empty entries (!)");
79 }
80 }
81 }
82
layoutAllVisible(sal_uInt32 nEntryCount)83 Size SvxColorValueSet::layoutAllVisible(sal_uInt32 nEntryCount)
84 {
85 if(!nEntryCount)
86 {
87 nEntryCount++;
88 }
89
90 const sal_uInt32 nRowCount(ceil(double(nEntryCount)/getColumnCount()));
91 const Size aItemSize(getEntryEdgeLength() - 2, getEntryEdgeLength() - 2);
92 const WinBits aWinBits(GetStyle() & ~WB_VSCROLL);
93
94 if(nRowCount > getMaxRowCount())
95 {
96 SetStyle(aWinBits|WB_VSCROLL);
97 }
98 else
99 {
100 SetStyle(aWinBits);
101 }
102
103 SetColCount(getColumnCount());
104 SetLineCount(std::min(nRowCount, getMaxRowCount()));
105 SetItemWidth(aItemSize.Width());
106 SetItemHeight(aItemSize.Height());
107
108 return CalcWindowSizePixel(aItemSize);
109 }
110
layoutToGivenHeight(sal_uInt32 nHeight,sal_uInt32 nEntryCount)111 Size SvxColorValueSet::layoutToGivenHeight(sal_uInt32 nHeight, sal_uInt32 nEntryCount)
112 {
113 if(!nEntryCount)
114 {
115 nEntryCount++;
116 }
117
118 const Size aItemSize(getEntryEdgeLength(), getEntryEdgeLength());
119 const WinBits aWinBits(GetStyle() & ~WB_VSCROLL);
120
121 // get size whith all fields disabled
122 const WinBits aWinBitsNoScrollNoFields(GetStyle() & ~(WB_VSCROLL|WB_NAMEFIELD|WB_NONEFIELD));
123 SetStyle(aWinBitsNoScrollNoFields);
124 const Size aSizeNoScrollNoFields(CalcWindowSizePixel(aItemSize, getColumnCount()));
125
126 // get size with all needed fields
127 SetStyle(aWinBits);
128 Size aNewSize(CalcWindowSizePixel(aItemSize, getColumnCount()));
129
130 // evtl. activate vertical scroll
131 const bool bAdaptHeight(static_cast< sal_uInt32 >(aNewSize.Height()) > nHeight);
132
133 if(bAdaptHeight)
134 {
135 SetStyle(aWinBits|WB_VSCROLL);
136 aNewSize = CalcWindowSizePixel(aItemSize, getColumnCount());
137 }
138
139 // calculate field height and available height for requested height
140 const sal_uInt32 nFieldHeight(aNewSize.Height() - aSizeNoScrollNoFields.Height());
141 const sal_uInt32 nAvailableHeight(nHeight >= nFieldHeight ? nHeight - nFieldHeight : 0);
142
143 // calculate how many lines can be shown there
144 const Size aItemSizePixel(CalcItemSizePixel(aItemSize));
145 const sal_uInt32 nLineCount((nAvailableHeight + aItemSizePixel.Height() - 1) / aItemSizePixel.Height());
146
147 // set height to wanted height
148 aNewSize.Height() = nHeight;
149
150 SetItemWidth(aItemSize.Width());
151 SetItemHeight(aItemSize.Height());
152 SetColCount(getColumnCount());
153 SetLineCount(nLineCount);
154
155 return aNewSize;
156 }
157
158 //////////////////////////////////////////////////////////////////////////////
159 // eof
160