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