bump product version to 4.1.6.2
[LibreOffice.git] / svx / source / sidebar / ColorPanel.cxx
blob92874c03f1392e19265621df5b6daaadf4fe2913
1 /*
2 * This file is part of the LibreOffice project.
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/.
8 * This file incorporates work covered by the following license notice:
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 .
18 #include "precompiled_svx.hxx"
20 #include "ColorPanel.hxx"
22 #include <vcl/image.hxx>
23 #include <vcl/svapp.hxx>
25 namespace svx { namespace sidebar {
27 ColorPanel::ColorPanel (::Window* pParent)
28 : ValueSet(pParent),
29 mnPreferredColumnCount(2)
31 WinBits aStyle =
32 WB_ITEMBORDER
33 | WB_DOUBLEBORDER
34 | WB_NAMEFIELD
35 | WB_FLATVALUESET
36 | WB_TABSTOP
37 | WB_VSCROLL;
39 SetStyle(GetStyle() | aStyle);
40 SetExtraSpacing(2);
42 Fill ();
43 Show();
49 ColorPanel::~ColorPanel (void)
56 sal_Int32 ColorPanel::GetPreferredHeight (sal_Int32 nWidth)
58 sal_Int32 nPreferredHeight = 0;
59 if (GetItemCount()>0)
61 Image aImage = GetItemImage(GetItemId(0));
62 Size aItemSize = CalcItemSizePixel (aImage.GetSizePixel());
63 if (nWidth>0 && aItemSize.Width()>0)
65 int nColumnCount = nWidth / aItemSize.Width();
66 if (nColumnCount <= 0)
67 nColumnCount = 1;
68 else if (nColumnCount > 4)
69 nColumnCount = 4;
70 int nRowCount = (GetItemCount() + nColumnCount-1)
71 / nColumnCount;
72 nPreferredHeight = nRowCount * aItemSize.Height();
75 return nPreferredHeight;
81 void ColorPanel::Resize (void)
83 ::Window::Resize();
84 Size aWindowSize = GetOutputSizePixel();
85 SetPosSizePixel(Point(0,0), aWindowSize);
86 if (IsVisible() && aWindowSize.Width() > 0)
88 // Calculate the number of rows and columns.
89 if (GetItemCount() > 0)
91 Image aImage = GetItemImage(GetItemId(0));
92 Size aItemSize = CalcItemSizePixel (
93 aImage.GetSizePixel());
94 int nColumnCount = aWindowSize.Width() / 30;
95 if (nColumnCount < 1)
96 nColumnCount = 1;
97 else if (nColumnCount > 4)
98 nColumnCount = 4;
100 sal_uInt16 nRowCount = (sal_uInt16)CalculateRowCount(aItemSize, nColumnCount);
102 SetColCount((sal_uInt16)nColumnCount);
103 SetLineCount(nRowCount);
112 int ColorPanel::CalculateRowCount (const Size&, int nColumnCount)
114 int nRowCount = 0;
116 if (GetItemCount()>0 && nColumnCount>0)
118 nRowCount = GetOutputSizePixel().Height() / 30;
119 if (nRowCount < 1)
120 nRowCount = 1;
123 return nRowCount;
129 void ColorPanel::DataChanged (const DataChangedEvent& rEvent)
131 Fill();
137 void ColorPanel::Fill (void)
139 const StyleSettings& rSettings (
140 Application::GetSettings().GetStyleSettings());
141 Clear();
142 SetItemWidth (30);
143 SetItemHeight (30);
144 sal_uInt16 i = 0;
145 InsertItem (++i, rSettings.GetFaceColor());
146 SetItemText (i, String::CreateFromAscii("FaceColor"));
147 InsertItem (++i, rSettings.GetCheckedColor());
148 SetItemText (i, String::CreateFromAscii("CheckedColor"));
149 InsertItem (++i, rSettings.GetLightColor());
150 SetItemText (i, String::CreateFromAscii("LightColor"));
151 InsertItem (++i, rSettings.GetLightBorderColor());
152 SetItemText (i, String::CreateFromAscii("LightBorderColor"));
153 InsertItem (++i, rSettings.GetShadowColor());
154 SetItemText (i, String::CreateFromAscii("ShadowColor"));
155 InsertItem (++i, rSettings.GetDarkShadowColor());
156 SetItemText (i, String::CreateFromAscii("DarkShadowColor"));
157 InsertItem (++i, rSettings.GetButtonTextColor());
158 SetItemText (i, String::CreateFromAscii("ButtonTextColor"));
159 InsertItem (++i, rSettings.GetRadioCheckTextColor());
160 SetItemText (i, String::CreateFromAscii("RadioCheckTextColor"));
161 InsertItem (++i, rSettings.GetGroupTextColor());
162 SetItemText (i, String::CreateFromAscii("GroupTextColor"));
163 InsertItem (++i, rSettings.GetLabelTextColor());
164 SetItemText (i, String::CreateFromAscii("LabelTextColor"));
165 InsertItem (++i, rSettings.GetInfoTextColor());
166 SetItemText (i, String::CreateFromAscii("InfoTextColor"));
167 InsertItem (++i, rSettings.GetWindowColor());
168 SetItemText (i, String::CreateFromAscii("WindowColor"));
169 InsertItem (++i, rSettings.GetWindowTextColor());
170 SetItemText (i, String::CreateFromAscii("WindowTextColor"));
171 InsertItem (++i, rSettings.GetDialogColor());
172 SetItemText (i, String::CreateFromAscii("DialogColor"));
173 InsertItem (++i, rSettings.GetDialogTextColor());
174 SetItemText (i, String::CreateFromAscii("DialogTextColor"));
175 InsertItem (++i, rSettings.GetWorkspaceColor());
176 SetItemText (i, String::CreateFromAscii("WorkspaceColor"));
177 InsertItem (++i, rSettings.GetFieldColor());
178 SetItemText (i, String::CreateFromAscii("FieldColor"));
179 InsertItem (++i, rSettings.GetFieldTextColor());
180 SetItemText (i, String::CreateFromAscii("FieldTextColor"));
181 InsertItem (++i, rSettings.GetActiveColor());
182 SetItemText (i, String::CreateFromAscii("ActiveColor"));
183 InsertItem (++i, rSettings.GetActiveColor2());
184 SetItemText (i, String::CreateFromAscii("ActiveColor2"));
185 InsertItem (++i, rSettings.GetActiveTextColor());
186 SetItemText (i, String::CreateFromAscii("ActiveTextColor"));
187 InsertItem (++i, rSettings.GetActiveBorderColor());
188 SetItemText (i, String::CreateFromAscii("ActiveBorderColor"));
189 InsertItem (++i, rSettings.GetDeactiveColor());
190 SetItemText (i, String::CreateFromAscii("DeactiveColor"));
191 InsertItem (++i, rSettings.GetDeactiveColor2());
192 SetItemText (i, String::CreateFromAscii("DeactiveColor2"));
193 InsertItem (++i, rSettings.GetDeactiveTextColor());
194 SetItemText (i, String::CreateFromAscii("DeactiveTextColor"));
195 InsertItem (++i, rSettings.GetDeactiveBorderColor());
196 SetItemText (i, String::CreateFromAscii("DeactiveBorderColor"));
197 InsertItem (++i, rSettings.GetHighlightColor());
198 SetItemText (i, String::CreateFromAscii("HighlightColor"));
199 InsertItem (++i, rSettings.GetHighlightTextColor());
200 SetItemText (i, String::CreateFromAscii("HighlightTextColor"));
201 InsertItem (++i, rSettings.GetDisableColor());
202 SetItemText (i, String::CreateFromAscii("DisableColor"));
203 InsertItem (++i, rSettings.GetHelpColor());
204 SetItemText (i, String::CreateFromAscii("HelpColor"));
205 InsertItem (++i, rSettings.GetHelpTextColor());
206 SetItemText (i, String::CreateFromAscii("HelpTextColor"));
207 InsertItem (++i, rSettings.GetMenuColor());
208 SetItemText (i, String::CreateFromAscii("MenuColor"));
209 InsertItem (++i, rSettings.GetMenuBarColor());
210 SetItemText (i, String::CreateFromAscii("MenuBarColor"));
211 InsertItem (++i, rSettings.GetMenuBorderColor());
212 SetItemText (i, String::CreateFromAscii("MenuBorderColor"));
213 InsertItem (++i, rSettings.GetMenuTextColor());
214 SetItemText (i, String::CreateFromAscii("MenuTextColor"));
215 InsertItem (++i, rSettings.GetMenuHighlightColor());
216 SetItemText (i, String::CreateFromAscii("MenuHighlightColor"));
217 InsertItem (++i, rSettings.GetMenuHighlightTextColor());
218 SetItemText (i, String::CreateFromAscii("MenuHighlightTextColor"));
219 InsertItem (++i, rSettings.GetLinkColor());
220 SetItemText (i, String::CreateFromAscii("LinkColor"));
221 InsertItem (++i, rSettings.GetVisitedLinkColor());
222 SetItemText (i, String::CreateFromAscii("VisitedLinkColor"));
223 InsertItem (++i, rSettings.GetHighlightLinkColor());
224 SetItemText (i, String::CreateFromAscii("HighlightLinkColor"));
225 InsertItem (++i, rSettings.GetFontColor());
226 SetItemText (i, String::CreateFromAscii("FontColor"));
229 } } // end of namespace ::svx::sidebar