xref: /trunk/main/svx/source/sidebar/ColorPanel.cxx (revision 2d839242)
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 #include "precompiled_svx.hxx"
23 
24 #include "ColorPanel.hxx"
25 
26 #include <vcl/image.hxx>
27 #include <vcl/svapp.hxx>
28 
29 namespace svx { namespace sidebar {
30 
ColorPanel(::Window * pParent)31 ColorPanel::ColorPanel (::Window* pParent)
32     : ValueSet(pParent),
33       mnPreferredColumnCount(2)
34 {
35     WinBits aStyle =
36         WB_ITEMBORDER
37         | WB_DOUBLEBORDER
38         | WB_NAMEFIELD
39         | WB_FLATVALUESET
40         | WB_TABSTOP
41         | WB_VSCROLL;
42 
43     SetStyle(GetStyle() | aStyle);
44     SetExtraSpacing(2);
45 
46     Fill ();
47     Show();
48 }
49 
50 
51 
52 
~ColorPanel(void)53 ColorPanel::~ColorPanel (void)
54 {
55 }
56 
57 
58 
59 
GetPreferredHeight(sal_Int32 nWidth)60 sal_Int32 ColorPanel::GetPreferredHeight (sal_Int32 nWidth)
61 {
62     sal_Int32 nPreferredHeight = 0;
63     if (GetItemCount()>0)
64     {
65         Image aImage = GetItemImage(GetItemId(0));
66         Size aItemSize = CalcItemSizePixel (aImage.GetSizePixel());
67         if (nWidth>0 && aItemSize.Width()>0)
68         {
69             int nColumnCount = nWidth / aItemSize.Width();
70             if (nColumnCount <= 0)
71                 nColumnCount = 1;
72             else if (nColumnCount > 4)
73                 nColumnCount = 4;
74             int nRowCount = (GetItemCount() + nColumnCount-1)
75                 / nColumnCount;
76             nPreferredHeight = nRowCount * aItemSize.Height();
77         }
78     }
79     return nPreferredHeight;
80 }
81 
82 
83 
84 
Resize(void)85 void ColorPanel::Resize (void)
86 {
87     ::Window::Resize();
88     Size aWindowSize = GetOutputSizePixel();
89     SetPosSizePixel(Point(0,0), aWindowSize);
90     if (IsVisible() && aWindowSize.Width() > 0)
91     {
92         // Calculate the number of rows and columns.
93         if (GetItemCount() > 0)
94         {
95             Image aImage = GetItemImage(GetItemId(0));
96             Size aItemSize = CalcItemSizePixel (
97                 aImage.GetSizePixel());
98             int nColumnCount = aWindowSize.Width() / 30;
99             if (nColumnCount < 1)
100                 nColumnCount = 1;
101             else if (nColumnCount > 4)
102                 nColumnCount = 4;
103 
104             sal_uInt16 nRowCount = (sal_uInt16)CalculateRowCount(aItemSize, nColumnCount);
105 
106             SetColCount((sal_uInt16)nColumnCount);
107             SetLineCount(nRowCount);
108         }
109     }
110 
111 }
112 
113 
114 
115 
CalculateRowCount(const Size &,int nColumnCount)116 int ColorPanel::CalculateRowCount (const Size&, int nColumnCount)
117 {
118     int nRowCount = 0;
119 
120     if (GetItemCount()>0 && nColumnCount>0)
121     {
122         nRowCount = GetOutputSizePixel().Height() / 30;
123         if (nRowCount < 1)
124             nRowCount = 1;
125     }
126 
127     return nRowCount;
128 }
129 
130 
131 
132 
DataChanged(const DataChangedEvent & rEvent)133 void ColorPanel::DataChanged (const DataChangedEvent& rEvent)
134 {
135     Fill();
136 }
137 
138 
139 
140 
Fill(void)141 void ColorPanel::Fill (void)
142 {
143     const StyleSettings& rSettings (
144         Application::GetSettings().GetStyleSettings());
145     Clear();
146     SetItemWidth (30);
147     SetItemHeight (30);
148     sal_uInt16 i = 0;
149     InsertItem (++i, rSettings.GetFaceColor());
150     SetItemText (i, String::CreateFromAscii("FaceColor"));
151     InsertItem (++i, rSettings.GetCheckedColor());
152     SetItemText (i, String::CreateFromAscii("CheckedColor"));
153     InsertItem (++i, rSettings.GetLightColor());
154     SetItemText (i, String::CreateFromAscii("LightColor"));
155     InsertItem (++i, rSettings.GetLightBorderColor());
156     SetItemText (i, String::CreateFromAscii("LightBorderColor"));
157     InsertItem (++i, rSettings.GetShadowColor());
158     SetItemText (i, String::CreateFromAscii("ShadowColor"));
159     InsertItem (++i, rSettings.GetDarkShadowColor());
160     SetItemText (i, String::CreateFromAscii("DarkShadowColor"));
161     InsertItem (++i, rSettings.GetButtonTextColor());
162     SetItemText (i, String::CreateFromAscii("ButtonTextColor"));
163     InsertItem (++i, rSettings.GetRadioCheckTextColor());
164     SetItemText (i, String::CreateFromAscii("RadioCheckTextColor"));
165     InsertItem (++i, rSettings.GetGroupTextColor());
166     SetItemText (i, String::CreateFromAscii("GroupTextColor"));
167     InsertItem (++i, rSettings.GetLabelTextColor());
168     SetItemText (i, String::CreateFromAscii("LabelTextColor"));
169     InsertItem (++i, rSettings.GetInfoTextColor());
170     SetItemText (i, String::CreateFromAscii("InfoTextColor"));
171     InsertItem (++i, rSettings.GetWindowColor());
172     SetItemText (i, String::CreateFromAscii("WindowColor"));
173     InsertItem (++i, rSettings.GetWindowTextColor());
174     SetItemText (i, String::CreateFromAscii("WindowTextColor"));
175     InsertItem (++i, rSettings.GetDialogColor());
176     SetItemText (i, String::CreateFromAscii("DialogColor"));
177     InsertItem (++i, rSettings.GetDialogTextColor());
178     SetItemText (i, String::CreateFromAscii("DialogTextColor"));
179     InsertItem (++i, rSettings.GetWorkspaceColor());
180     SetItemText (i, String::CreateFromAscii("WorkspaceColor"));
181     InsertItem (++i, rSettings.GetFieldColor());
182     SetItemText (i, String::CreateFromAscii("FieldColor"));
183     InsertItem (++i, rSettings.GetFieldTextColor());
184     SetItemText (i, String::CreateFromAscii("FieldTextColor"));
185     InsertItem (++i, rSettings.GetActiveColor());
186     SetItemText (i, String::CreateFromAscii("ActiveColor"));
187     InsertItem (++i, rSettings.GetActiveColor2());
188     SetItemText (i, String::CreateFromAscii("ActiveColor2"));
189     InsertItem (++i, rSettings.GetActiveTextColor());
190     SetItemText (i, String::CreateFromAscii("ActiveTextColor"));
191     InsertItem (++i, rSettings.GetActiveBorderColor());
192     SetItemText (i, String::CreateFromAscii("ActiveBorderColor"));
193     InsertItem (++i, rSettings.GetDeactiveColor());
194     SetItemText (i, String::CreateFromAscii("DeactiveColor"));
195     InsertItem (++i, rSettings.GetDeactiveColor2());
196     SetItemText (i, String::CreateFromAscii("DeactiveColor2"));
197     InsertItem (++i, rSettings.GetDeactiveTextColor());
198     SetItemText (i, String::CreateFromAscii("DeactiveTextColor"));
199     InsertItem (++i, rSettings.GetDeactiveBorderColor());
200     SetItemText (i, String::CreateFromAscii("DeactiveBorderColor"));
201     InsertItem (++i, rSettings.GetHighlightColor());
202     SetItemText (i, String::CreateFromAscii("HighlightColor"));
203     InsertItem (++i, rSettings.GetHighlightTextColor());
204     SetItemText (i, String::CreateFromAscii("HighlightTextColor"));
205     InsertItem (++i, rSettings.GetDisableColor());
206     SetItemText (i, String::CreateFromAscii("DisableColor"));
207     InsertItem (++i, rSettings.GetHelpColor());
208     SetItemText (i, String::CreateFromAscii("HelpColor"));
209     InsertItem (++i, rSettings.GetHelpTextColor());
210     SetItemText (i, String::CreateFromAscii("HelpTextColor"));
211     InsertItem (++i, rSettings.GetMenuColor());
212     SetItemText (i, String::CreateFromAscii("MenuColor"));
213     InsertItem (++i, rSettings.GetMenuBarColor());
214     SetItemText (i, String::CreateFromAscii("MenuBarColor"));
215     InsertItem (++i, rSettings.GetMenuBorderColor());
216     SetItemText (i, String::CreateFromAscii("MenuBorderColor"));
217     InsertItem (++i, rSettings.GetMenuTextColor());
218     SetItemText (i, String::CreateFromAscii("MenuTextColor"));
219     InsertItem (++i, rSettings.GetMenuHighlightColor());
220     SetItemText (i, String::CreateFromAscii("MenuHighlightColor"));
221     InsertItem (++i, rSettings.GetMenuHighlightTextColor());
222     SetItemText (i, String::CreateFromAscii("MenuHighlightTextColor"));
223     InsertItem (++i, rSettings.GetLinkColor());
224     SetItemText (i, String::CreateFromAscii("LinkColor"));
225     InsertItem (++i, rSettings.GetVisitedLinkColor());
226     SetItemText (i, String::CreateFromAscii("VisitedLinkColor"));
227     InsertItem (++i, rSettings.GetHighlightLinkColor());
228     SetItemText (i, String::CreateFromAscii("HighlightLinkColor"));
229     InsertItem (++i, rSettings.GetFontColor());
230     SetItemText (i, String::CreateFromAscii("FontColor"));
231 }
232 
233 } } // end of namespace ::svx::sidebar
234