Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 : #include <svx/SvxColorValueSet.hxx>
21 : #include <svx/xtable.hxx>
22 : #include <vcl/builder.hxx>
23 : #include <vcl/svapp.hxx>
24 : #include <vcl/settings.hxx>
25 :
26 0 : SvxColorValueSet::SvxColorValueSet(vcl::Window* _pParent, WinBits nWinStyle)
27 0 : : ValueSet(_pParent, nWinStyle)
28 : {
29 0 : SetEdgeBlending(true);
30 0 : }
31 :
32 0 : extern "C" SAL_DLLPUBLIC_EXPORT vcl::Window* SAL_CALL makeSvxColorValueSet(vcl::Window *pParent, VclBuilder::stringmap &rMap)
33 : {
34 0 : WinBits nWinBits = WB_TABSTOP;
35 :
36 0 : OString sBorder = VclBuilder::extractCustomProperty(rMap);
37 0 : if (!sBorder.isEmpty())
38 0 : nWinBits |= WB_BORDER;
39 :
40 0 : return new SvxColorValueSet(pParent, nWinBits);
41 : }
42 :
43 0 : SvxColorValueSet::SvxColorValueSet(vcl::Window* _pParent, const ResId& rResId)
44 0 : : ValueSet(_pParent, rResId)
45 : {
46 0 : SetEdgeBlending(true);
47 0 : }
48 :
49 0 : sal_uInt32 SvxColorValueSet::getMaxRowCount() const
50 : {
51 0 : const StyleSettings& rStyleSettings = Application::GetSettings().GetStyleSettings();
52 :
53 0 : return rStyleSettings.GetColorValueSetMaximumRowCount();
54 : }
55 :
56 0 : sal_uInt32 SvxColorValueSet::getEntryEdgeLength() const
57 : {
58 0 : const StyleSettings& rStyleSettings = Application::GetSettings().GetStyleSettings();
59 :
60 0 : return rStyleSettings.GetListBoxPreviewDefaultPixelSize().Height() + 1;
61 : }
62 :
63 0 : sal_uInt32 SvxColorValueSet::getColumnCount() const
64 : {
65 0 : const StyleSettings& rStyleSettings = Application::GetSettings().GetStyleSettings();
66 :
67 0 : return rStyleSettings.GetColorValueSetColumnCount();
68 : }
69 :
70 0 : void SvxColorValueSet::addEntriesForXColorList(const XColorList& rXColorList, sal_uInt32 nStartIndex)
71 : {
72 0 : const sal_uInt32 nColorCount(rXColorList.Count());
73 :
74 0 : for(sal_uInt32 nIndex(0); nIndex < nColorCount; nIndex++, nStartIndex++)
75 : {
76 0 : const XColorEntry* pEntry = rXColorList.GetColor(nIndex);
77 :
78 0 : if(pEntry)
79 : {
80 0 : InsertItem(nStartIndex, pEntry->GetColor(), pEntry->GetName());
81 : }
82 : else
83 : {
84 : OSL_ENSURE(false, "OOps, XColorList with empty entries (!)");
85 : }
86 : }
87 0 : }
88 :
89 0 : void SvxColorValueSet::addEntriesForColorVector(const std::vector<Color>& rColorVector, const OUString& rNamePrefix, sal_uInt32 nStartIndex)
90 : {
91 0 : if(rNamePrefix.getLength() != 0)
92 : {
93 0 : for(std::vector<Color>::const_iterator it = rColorVector.begin();
94 0 : it != rColorVector.end(); ++it, nStartIndex++)
95 : {
96 0 : InsertItem(nStartIndex, *it, rNamePrefix + OUString::number(nStartIndex));
97 : }
98 : }
99 : else
100 : {
101 0 : for(std::vector<Color>::const_iterator it = rColorVector.begin();
102 0 : it != rColorVector.end(); ++it, nStartIndex++)
103 : {
104 0 : InsertItem(nStartIndex, *it, "");
105 : }
106 : }
107 0 : }
108 :
109 0 : Size SvxColorValueSet::layoutAllVisible(sal_uInt32 nEntryCount)
110 : {
111 0 : if(!nEntryCount)
112 : {
113 0 : nEntryCount++;
114 : }
115 :
116 0 : const sal_uInt32 nRowCount(ceil(double(nEntryCount)/getColumnCount()));
117 0 : const Size aItemSize(getEntryEdgeLength() - 2, getEntryEdgeLength() - 2);
118 0 : const WinBits aWinBits(GetStyle() & ~WB_VSCROLL);
119 :
120 0 : if(nRowCount > getMaxRowCount())
121 : {
122 0 : SetStyle(aWinBits|WB_VSCROLL);
123 : }
124 : else
125 : {
126 0 : SetStyle(aWinBits);
127 : }
128 :
129 0 : SetColCount(getColumnCount());
130 0 : SetLineCount(std::min(nRowCount, getMaxRowCount()));
131 0 : SetItemWidth(aItemSize.Width());
132 0 : SetItemHeight(aItemSize.Height());
133 :
134 0 : return CalcWindowSizePixel(aItemSize);
135 : }
136 :
137 0 : void SvxColorValueSet::Resize()
138 : {
139 0 : vcl::Window *pParent = GetParent();
140 : //don't do this for the drop down color palettes
141 0 : if (pParent && pParent->GetType() != WINDOW_FLOATINGWINDOW)
142 0 : layoutToGivenHeight(GetOutputSizePixel().Height(), GetItemCount());
143 0 : ValueSet::Resize();
144 0 : }
145 :
146 0 : Size SvxColorValueSet::layoutToGivenHeight(sal_uInt32 nHeight, sal_uInt32 nEntryCount)
147 : {
148 0 : if(!nEntryCount)
149 : {
150 0 : nEntryCount++;
151 : }
152 :
153 0 : const Size aItemSize(getEntryEdgeLength(), getEntryEdgeLength());
154 0 : const WinBits aWinBits(GetStyle() & ~WB_VSCROLL);
155 :
156 : // get size with all fields disabled
157 0 : const WinBits aWinBitsNoScrollNoFields(GetStyle() & ~(WB_VSCROLL|WB_NAMEFIELD|WB_NONEFIELD));
158 0 : SetStyle(aWinBitsNoScrollNoFields);
159 0 : const Size aSizeNoScrollNoFields(CalcWindowSizePixel(aItemSize, getColumnCount()));
160 :
161 : // get size with all needed fields
162 0 : SetStyle(aWinBits);
163 0 : Size aNewSize(CalcWindowSizePixel(aItemSize, getColumnCount()));
164 :
165 : // evtl. activate vertical scroll
166 0 : const bool bAdaptHeight(static_cast< sal_uInt32 >(aNewSize.Height()) > nHeight);
167 :
168 0 : if(bAdaptHeight)
169 : {
170 0 : SetStyle(aWinBits|WB_VSCROLL);
171 0 : aNewSize = CalcWindowSizePixel(aItemSize, getColumnCount());
172 : }
173 :
174 : // calculate field height and available height for requested height
175 0 : const sal_uInt32 nFieldHeight(aNewSize.Height() - aSizeNoScrollNoFields.Height());
176 0 : const sal_uInt32 nAvailableHeight(nHeight >= nFieldHeight ? nHeight - nFieldHeight : 0);
177 :
178 : // calculate how many lines can be shown there
179 0 : const Size aItemSizePixel(CalcItemSizePixel(aItemSize));
180 0 : const sal_uInt32 nLineCount((nAvailableHeight + aItemSizePixel.Height() - 1) / aItemSizePixel.Height());
181 :
182 : // set height to wanted height
183 0 : aNewSize.Height() = nHeight;
184 :
185 0 : SetItemWidth(aItemSize.Width());
186 0 : SetItemHeight(aItemSize.Height());
187 0 : SetColCount(getColumnCount());
188 0 : SetLineCount(nLineCount);
189 :
190 0 : return aNewSize;
191 651 : }
192 :
193 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|