CWS-TOOLING: integrate CWS os150
[LibreOffice.git] / sd / source / ui / toolpanel / TestMenu.cxx
blobc3eba17900933ce2652ca4319caf2f85e5f108e5
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_sd.hxx"
31 #include "TestMenu.hxx"
33 #include "taskpane/TaskPaneControlFactory.hxx"
35 #include <vcl/image.hxx>
36 #include <vcl/svapp.hxx>
38 namespace sd { namespace toolpanel {
40 #ifdef SHOW_COLOR_MENU
41 /** This factory class is used to create instances of ColorMenu. It can be
42 extended so that its constructor stores arguments that later are passed
43 to new ColorMenu objects.
45 class ColorMenuFactory
46 : public ControlFactory
48 protected:
49 virtual TreeNode* InternalCreateControl( ::Window& i_rParent )
51 return new ColorMenu (&i_rParent);
56 ColorMenu::ColorMenu (::Window* i_pParent)
57 : Window (i_pParent),
58 TreeNode(NULL),
59 maSet (this),
60 mnPreferredColumnCount(2)
62 WinBits aStyle =
63 WB_ITEMBORDER
64 | WB_DOUBLEBORDER
65 | WB_NAMEFIELD
66 | WB_FLATVALUESET
67 | WB_TABSTOP
68 | WB_VSCROLL;
70 maSet.SetStyle (maSet.GetStyle() | aStyle);
71 maSet.SetExtraSpacing(2);
73 Fill ();
74 maSet.Show();
75 i_pParent->Resize();
81 ColorMenu::~ColorMenu (void)
86 ::std::auto_ptr<ControlFactory> ColorMenu::CreateControlFactory (void)
88 return ::std::auto_ptr<ControlFactory>(new ColorMenuFactory());
92 /** The preferred size depends on the preferred number of columns, the
93 number of items, and the size of the items.
95 Size ColorMenu::GetPreferredSize (void)
97 Size aItemSize = maSet.CalcItemSizePixel (Size());
98 Size aPreferredWindowSize = maSet.CalcWindowSizePixel (
99 aItemSize,
100 (sal_uInt16)mnPreferredColumnCount,
101 (sal_uInt16)CalculateRowCount (aItemSize, (sal_uInt16)mnPreferredColumnCount));
102 return aPreferredWindowSize;
108 sal_Int32 ColorMenu::GetPreferredWidth (sal_Int32 nHeight)
110 sal_Int32 nPreferredWidth = 0;
111 if (maSet.GetItemCount() > 0)
113 Image aImage = maSet.GetItemImage(maSet.GetItemId(0));
114 Size aItemSize = maSet.CalcItemSizePixel (aImage.GetSizePixel());
115 if (nHeight>0 && aItemSize.Height()>0)
117 int nRowCount = nHeight / aItemSize.Height();
118 if (nRowCount <= 0)
119 nRowCount = 1;
120 int nColumnCount = (maSet.GetItemCount() + nRowCount-1)
121 / nRowCount;
122 nPreferredWidth = nColumnCount * aItemSize.Width();
126 return nPreferredWidth;
132 sal_Int32 ColorMenu::GetPreferredHeight (sal_Int32 nWidth)
134 sal_Int32 nPreferredHeight = 0;
135 if (maSet.GetItemCount()>0)
137 Image aImage = maSet.GetItemImage(maSet.GetItemId(0));
138 Size aItemSize = maSet.CalcItemSizePixel (aImage.GetSizePixel());
139 if (nWidth>0 && aItemSize.Width()>0)
141 int nColumnCount = nWidth / aItemSize.Width();
142 if (nColumnCount <= 0)
143 nColumnCount = 1;
144 else if (nColumnCount > 4)
145 nColumnCount = 4;
146 int nRowCount = (maSet.GetItemCount() + nColumnCount-1)
147 / nColumnCount;
148 nPreferredHeight = nRowCount * aItemSize.Height();
151 return nPreferredHeight;
157 bool ColorMenu::IsResizable (void)
159 return true;
165 ::Window* ColorMenu::GetWindow (void)
167 return this;
173 void ColorMenu::Resize (void)
175 ::Window::Resize();
176 Size aWindowSize = GetOutputSizePixel();
177 maSet.SetPosSizePixel (Point(0,0), aWindowSize);
178 if (IsVisible() && aWindowSize.Width() > 0)
180 // maSet.SetPosSizePixel (
181 // Point (0,0),
182 // aWindowSize);
184 // Calculate the number of rows and columns.
185 if (maSet.GetItemCount() > 0)
187 Image aImage = maSet.GetItemImage(maSet.GetItemId(0));
188 Size aItemSize = maSet.CalcItemSizePixel (
189 aImage.GetSizePixel());
190 int nColumnCount = aWindowSize.Width() / 30;
191 if (nColumnCount < 1)
192 nColumnCount = 1;
193 else if (nColumnCount > 4)
194 nColumnCount = 4;
196 sal_uInt16 nRowCount = (sal_uInt16)CalculateRowCount (aItemSize, nColumnCount);
198 maSet.SetColCount ((sal_uInt16)nColumnCount);
199 maSet.SetLineCount (nRowCount);
208 int ColorMenu::CalculateRowCount (const Size&, int nColumnCount)
210 int nRowCount = 0;
212 if (maSet.GetItemCount()>0 && nColumnCount>0)
214 nRowCount = GetOutputSizePixel().Height() / 30;
215 if (nRowCount < 1)
216 nRowCount = 1;
219 return nRowCount;
225 void ColorMenu::Fill (void)
227 const StyleSettings& rSettings (
228 Application::GetSettings().GetStyleSettings());
229 maSet.Clear();
230 maSet.SetItemWidth (30);
231 maSet.SetItemHeight (30);
232 sal_uInt16 i = 0;
233 maSet.InsertItem (++i, rSettings.GetFaceColor());
234 maSet.SetItemText (i, String::CreateFromAscii("FaceColor"));
235 maSet.InsertItem (++i, rSettings.GetCheckedColor());
236 maSet.SetItemText (i, String::CreateFromAscii("CheckedColor"));
237 maSet.InsertItem (++i, rSettings.GetLightColor());
238 maSet.SetItemText (i, String::CreateFromAscii("LightColor"));
239 maSet.InsertItem (++i, rSettings.GetLightBorderColor());
240 maSet.SetItemText (i, String::CreateFromAscii("LightBorderColor"));
241 maSet.InsertItem (++i, rSettings.GetShadowColor());
242 maSet.SetItemText (i, String::CreateFromAscii("ShadowColor"));
243 maSet.InsertItem (++i, rSettings.GetDarkShadowColor());
244 maSet.SetItemText (i, String::CreateFromAscii("DarkShadowColor"));
245 maSet.InsertItem (++i, rSettings.GetButtonTextColor());
246 maSet.SetItemText (i, String::CreateFromAscii("ButtonTextColor"));
247 maSet.InsertItem (++i, rSettings.GetRadioCheckTextColor());
248 maSet.SetItemText (i, String::CreateFromAscii("RadioCheckTextColor"));
249 maSet.InsertItem (++i, rSettings.GetGroupTextColor());
250 maSet.SetItemText (i, String::CreateFromAscii("GroupTextColor"));
251 maSet.InsertItem (++i, rSettings.GetLabelTextColor());
252 maSet.SetItemText (i, String::CreateFromAscii("LabelTextColor"));
253 maSet.InsertItem (++i, rSettings.GetInfoTextColor());
254 maSet.SetItemText (i, String::CreateFromAscii("InfoTextColor"));
255 maSet.InsertItem (++i, rSettings.GetWindowColor());
256 maSet.SetItemText (i, String::CreateFromAscii("WindowColor"));
257 maSet.InsertItem (++i, rSettings.GetWindowTextColor());
258 maSet.SetItemText (i, String::CreateFromAscii("WindowTextColor"));
259 maSet.InsertItem (++i, rSettings.GetDialogColor());
260 maSet.SetItemText (i, String::CreateFromAscii("DialogColor"));
261 maSet.InsertItem (++i, rSettings.GetDialogTextColor());
262 maSet.SetItemText (i, String::CreateFromAscii("DialogTextColor"));
263 maSet.InsertItem (++i, rSettings.GetWorkspaceColor());
264 maSet.SetItemText (i, String::CreateFromAscii("WorkspaceColor"));
265 maSet.InsertItem (++i, rSettings.GetFieldColor());
266 maSet.SetItemText (i, String::CreateFromAscii("FieldColor"));
267 maSet.InsertItem (++i, rSettings.GetFieldTextColor());
268 maSet.SetItemText (i, String::CreateFromAscii("FieldTextColor"));
269 maSet.InsertItem (++i, rSettings.GetActiveColor());
270 maSet.SetItemText (i, String::CreateFromAscii("ActiveColor"));
271 maSet.InsertItem (++i, rSettings.GetActiveColor2());
272 maSet.SetItemText (i, String::CreateFromAscii("ActiveColor2"));
273 maSet.InsertItem (++i, rSettings.GetActiveTextColor());
274 maSet.SetItemText (i, String::CreateFromAscii("ActiveTextColor"));
275 maSet.InsertItem (++i, rSettings.GetActiveBorderColor());
276 maSet.SetItemText (i, String::CreateFromAscii("ActiveBorderColor"));
277 maSet.InsertItem (++i, rSettings.GetDeactiveColor());
278 maSet.SetItemText (i, String::CreateFromAscii("DeactiveColor"));
279 maSet.InsertItem (++i, rSettings.GetDeactiveColor2());
280 maSet.SetItemText (i, String::CreateFromAscii("DeactiveColor2"));
281 maSet.InsertItem (++i, rSettings.GetDeactiveTextColor());
282 maSet.SetItemText (i, String::CreateFromAscii("DeactiveTextColor"));
283 maSet.InsertItem (++i, rSettings.GetDeactiveBorderColor());
284 maSet.SetItemText (i, String::CreateFromAscii("DeactiveBorderColor"));
285 maSet.InsertItem (++i, rSettings.GetHighlightColor());
286 maSet.SetItemText (i, String::CreateFromAscii("HighlightColor"));
287 maSet.InsertItem (++i, rSettings.GetHighlightTextColor());
288 maSet.SetItemText (i, String::CreateFromAscii("HighlightTextColor"));
289 maSet.InsertItem (++i, rSettings.GetDisableColor());
290 maSet.SetItemText (i, String::CreateFromAscii("DisableColor"));
291 maSet.InsertItem (++i, rSettings.GetHelpColor());
292 maSet.SetItemText (i, String::CreateFromAscii("HelpColor"));
293 maSet.InsertItem (++i, rSettings.GetHelpTextColor());
294 maSet.SetItemText (i, String::CreateFromAscii("HelpTextColor"));
295 maSet.InsertItem (++i, rSettings.GetMenuColor());
296 maSet.SetItemText (i, String::CreateFromAscii("MenuColor"));
297 maSet.InsertItem (++i, rSettings.GetMenuBarColor());
298 maSet.SetItemText (i, String::CreateFromAscii("MenuBarColor"));
299 maSet.InsertItem (++i, rSettings.GetMenuBorderColor());
300 maSet.SetItemText (i, String::CreateFromAscii("MenuBorderColor"));
301 maSet.InsertItem (++i, rSettings.GetMenuTextColor());
302 maSet.SetItemText (i, String::CreateFromAscii("MenuTextColor"));
303 maSet.InsertItem (++i, rSettings.GetMenuHighlightColor());
304 maSet.SetItemText (i, String::CreateFromAscii("MenuHighlightColor"));
305 maSet.InsertItem (++i, rSettings.GetMenuHighlightTextColor());
306 maSet.SetItemText (i, String::CreateFromAscii("MenuHighlightTextColor"));
307 maSet.InsertItem (++i, rSettings.GetLinkColor());
308 maSet.SetItemText (i, String::CreateFromAscii("LinkColor"));
309 maSet.InsertItem (++i, rSettings.GetVisitedLinkColor());
310 maSet.SetItemText (i, String::CreateFromAscii("VisitedLinkColor"));
311 maSet.InsertItem (++i, rSettings.GetHighlightLinkColor());
312 maSet.SetItemText (i, String::CreateFromAscii("HighlightLinkColor"));
313 maSet.InsertItem (++i, rSettings.GetFontColor());
314 maSet.SetItemText (i, String::CreateFromAscii("FontColor"));
316 #endif
318 } } // end of namespace ::sd::toolpanel