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 <svtools/accessibilityoptions.hxx> 28 29 ////////////////////////////////////////////////////////////////////////////// 30 31 SvxColorValueSet::SvxColorValueSet(Window* _pParent, WinBits nWinStyle) 32 : ValueSet(_pParent, nWinStyle) 33 { 34 } 35 36 SvxColorValueSet::SvxColorValueSet(Window* _pParent, const ResId& rResId) 37 : ValueSet(_pParent, rResId) 38 { 39 } 40 41 sal_uInt32 SvxColorValueSet::getMaxRowCount() const 42 { 43 const SvtAccessibilityOptions aOptions; 44 45 return aOptions.GetColorValueSetMaximumRowCount(); 46 } 47 48 sal_uInt32 SvxColorValueSet::getEntryEdgeLength() const 49 { 50 const SvtAccessibilityOptions aOptions; 51 52 return aOptions.GetColorValueSetEntryEdgeLength(); 53 } 54 55 sal_uInt32 SvxColorValueSet::getColumnCount() const 56 { 57 const SvtAccessibilityOptions aOptions; 58 59 return aOptions.GetColorValueSetColumnCount(); 60 } 61 62 void SvxColorValueSet::addEntriesForXColorList(const XColorList& rXColorList, sal_uInt32 nStartIndex) 63 { 64 const sal_uInt32 nColorCount(rXColorList.Count()); 65 66 for(sal_uInt32 nIndex(0); nIndex < nColorCount; nIndex++, nStartIndex++) 67 { 68 const XColorEntry* pEntry = rXColorList.GetColor(nIndex); 69 70 if(pEntry) 71 { 72 InsertItem(nStartIndex, pEntry->GetColor(), pEntry->GetName()); 73 } 74 else 75 { 76 OSL_ENSURE(false, "OOps, XColorList with empty entries (!)"); 77 } 78 } 79 } 80 81 Size SvxColorValueSet::layoutAllVisible(sal_uInt32 nEntryCount) 82 { 83 if(!nEntryCount) 84 { 85 nEntryCount++; 86 } 87 88 const sal_uInt32 nRowCount(ceil(double(nEntryCount)/getColumnCount())); 89 const Size aItemSize(getEntryEdgeLength() - 2, getEntryEdgeLength() - 2); 90 const WinBits aWinBits(GetStyle() & ~WB_VSCROLL); 91 92 if(nRowCount > getMaxRowCount()) 93 { 94 SetStyle(aWinBits|WB_VSCROLL); 95 } 96 else 97 { 98 SetStyle(aWinBits); 99 } 100 101 SetColCount(getColumnCount()); 102 SetLineCount(std::min(nRowCount, getMaxRowCount())); 103 SetItemWidth(aItemSize.Width()); 104 SetItemHeight(aItemSize.Height()); 105 106 return CalcWindowSizePixel(aItemSize); 107 } 108 109 Size SvxColorValueSet::layoutToGivenHeight(sal_uInt32 nHeight, sal_uInt32 nEntryCount) 110 { 111 if(!nEntryCount) 112 { 113 nEntryCount++; 114 } 115 116 const sal_uInt32 nRowCount(ceil(double(nEntryCount)/getColumnCount())); 117 const Size aItemSize(getEntryEdgeLength(), getEntryEdgeLength()); 118 const WinBits aWinBits(GetStyle() & ~WB_VSCROLL); 119 120 // get size whith all fields disabled 121 const WinBits aWinBitsNoScrollNoFields(GetStyle() & ~(WB_VSCROLL|WB_NAMEFIELD|WB_NONEFIELD)); 122 SetStyle(aWinBitsNoScrollNoFields); 123 const Size aSizeNoScrollNoFields(CalcWindowSizePixel(aItemSize, getColumnCount())); 124 125 // get size with all needed fields 126 SetStyle(aWinBits); 127 Size aNewSize(CalcWindowSizePixel(aItemSize, getColumnCount())); 128 129 // evtl. activate vertical scroll 130 const bool bAdaptHeight(aNewSize.Height() > nHeight); 131 132 if(bAdaptHeight) 133 { 134 SetStyle(aWinBits|WB_VSCROLL); 135 aNewSize = CalcWindowSizePixel(aItemSize, getColumnCount()); 136 } 137 138 // calculate field height and available height for requested height 139 const sal_uInt32 nFieldHeight(aNewSize.Height() - aSizeNoScrollNoFields.Height()); 140 const sal_uInt32 nAvailableHeight(nHeight >= nFieldHeight ? nHeight - nFieldHeight : 0); 141 142 // calculate how many lines can be shown there 143 const Size aItemSizePixel(CalcItemSizePixel(aItemSize)); 144 const sal_uInt32 nLineCount((nAvailableHeight + aItemSizePixel.Height() - 1) / aItemSizePixel.Height()); 145 146 // set height to wanted height 147 aNewSize.Height() = nHeight; 148 149 SetItemWidth(aItemSize.Width()); 150 SetItemHeight(aItemSize.Height()); 151 SetColCount(getColumnCount()); 152 SetLineCount(nLineCount); 153 154 return aNewSize; 155 } 156 157 ////////////////////////////////////////////////////////////////////////////// 158 // eof 159