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