Update ooo320-m1
[ooovba.git] / sd / source / ui / toolpanel / TestMenu.cxx
blobb05824c5433307da6544a4f6c6b77ce8e71cfe14
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: TestMenu.cxx,v $
10 * $Revision: 1.7 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sd.hxx"
34 #include "TestMenu.hxx"
36 #include "taskpane/TaskPaneControlFactory.hxx"
38 #include <vcl/image.hxx>
39 #include <vcl/svapp.hxx>
41 namespace sd { namespace toolpanel {
43 /** This factory class is used to create instances of ColorMenu. It can be
44 extended so that its constructor stores arguments that later are passed
45 to new ColorMenu objects.
47 class ColorMenuFactory
48 : public ControlFactory
50 protected:
51 virtual TreeNode* InternalCreateControl (TreeNode* pTreeNode)
53 return new ColorMenu (pTreeNode);
58 ColorMenu::ColorMenu (TreeNode* pParent)
59 : Window (pParent->GetWindow()),
60 TreeNode(pParent),
61 maSet (this),
62 mnPreferredColumnCount(2)
64 WinBits aStyle =
65 WB_ITEMBORDER
66 | WB_DOUBLEBORDER
67 | WB_NAMEFIELD
68 | WB_FLATVALUESET
69 | WB_TABSTOP
70 | WB_VSCROLL;
72 maSet.SetStyle (maSet.GetStyle() | aStyle);
73 maSet.SetExtraSpacing(2);
75 Fill ();
76 maSet.Show();
77 pParent->RequestResize();
83 ColorMenu::~ColorMenu (void)
90 ::std::auto_ptr<ControlFactory> ColorMenu::CreateControlFactory (void)
92 return ::std::auto_ptr<ControlFactory>(new ColorMenuFactory());
98 /** The preferred size depends on the preferred number of columns, the
99 number of items, and the size of the items.
101 Size ColorMenu::GetPreferredSize (void)
103 Size aItemSize = maSet.CalcItemSizePixel (Size());
104 Size aPreferredWindowSize = maSet.CalcWindowSizePixel (
105 aItemSize,
106 (USHORT)mnPreferredColumnCount,
107 (USHORT)CalculateRowCount (aItemSize, (USHORT)mnPreferredColumnCount));
108 return aPreferredWindowSize;
114 sal_Int32 ColorMenu::GetPreferredWidth (sal_Int32 nHeight)
116 sal_Int32 nPreferredWidth = 0;
117 if (maSet.GetItemCount() > 0)
119 Image aImage = maSet.GetItemImage(maSet.GetItemId(0));
120 Size aItemSize = maSet.CalcItemSizePixel (aImage.GetSizePixel());
121 if (nHeight>0 && aItemSize.Height()>0)
123 int nRowCount = nHeight / aItemSize.Height();
124 if (nRowCount <= 0)
125 nRowCount = 1;
126 int nColumnCount = (maSet.GetItemCount() + nRowCount-1)
127 / nRowCount;
128 nPreferredWidth = nColumnCount * aItemSize.Width();
132 return nPreferredWidth;
138 sal_Int32 ColorMenu::GetPreferredHeight (sal_Int32 nWidth)
140 sal_Int32 nPreferredHeight = 0;
141 if (maSet.GetItemCount()>0)
143 Image aImage = maSet.GetItemImage(maSet.GetItemId(0));
144 Size aItemSize = maSet.CalcItemSizePixel (aImage.GetSizePixel());
145 if (nWidth>0 && aItemSize.Width()>0)
147 int nColumnCount = nWidth / aItemSize.Width();
148 if (nColumnCount <= 0)
149 nColumnCount = 1;
150 else if (nColumnCount > 4)
151 nColumnCount = 4;
152 int nRowCount = (maSet.GetItemCount() + nColumnCount-1)
153 / nColumnCount;
154 nPreferredHeight = nRowCount * aItemSize.Height();
157 return nPreferredHeight;
163 bool ColorMenu::IsResizable (void)
165 return true;
171 ::Window* ColorMenu::GetWindow (void)
173 return this;
179 void ColorMenu::Resize (void)
181 ::Window::Resize();
182 Size aWindowSize = GetOutputSizePixel();
183 maSet.SetPosSizePixel (Point(0,0), aWindowSize);
184 if (IsVisible() && aWindowSize.Width() > 0)
186 // maSet.SetPosSizePixel (
187 // Point (0,0),
188 // aWindowSize);
190 // Calculate the number of rows and columns.
191 if (maSet.GetItemCount() > 0)
193 Image aImage = maSet.GetItemImage(maSet.GetItemId(0));
194 Size aItemSize = maSet.CalcItemSizePixel (
195 aImage.GetSizePixel());
196 int nColumnCount = aWindowSize.Width() / 30;
197 if (nColumnCount < 1)
198 nColumnCount = 1;
199 else if (nColumnCount > 4)
200 nColumnCount = 4;
202 USHORT nRowCount = (USHORT)CalculateRowCount (aItemSize, nColumnCount);
204 maSet.SetColCount ((USHORT)nColumnCount);
205 maSet.SetLineCount (nRowCount);
214 int ColorMenu::CalculateRowCount (const Size&, int nColumnCount)
216 int nRowCount = 0;
218 if (maSet.GetItemCount()>0 && nColumnCount>0)
220 nRowCount = GetOutputSizePixel().Height() / 30;
221 if (nRowCount < 1)
222 nRowCount = 1;
225 return nRowCount;
231 void ColorMenu::Fill (void)
233 const StyleSettings& rSettings (
234 Application::GetSettings().GetStyleSettings());
235 maSet.Clear();
236 maSet.SetItemWidth (30);
237 maSet.SetItemHeight (30);
238 USHORT i = 0;
239 maSet.InsertItem (++i, rSettings.GetFaceColor());
240 maSet.SetItemText (i, String::CreateFromAscii("FaceColor"));
241 maSet.InsertItem (++i, rSettings.GetCheckedColor());
242 maSet.SetItemText (i, String::CreateFromAscii("CheckedColor"));
243 maSet.InsertItem (++i, rSettings.GetLightColor());
244 maSet.SetItemText (i, String::CreateFromAscii("LightColor"));
245 maSet.InsertItem (++i, rSettings.GetLightBorderColor());
246 maSet.SetItemText (i, String::CreateFromAscii("LightBorderColor"));
247 maSet.InsertItem (++i, rSettings.GetShadowColor());
248 maSet.SetItemText (i, String::CreateFromAscii("ShadowColor"));
249 maSet.InsertItem (++i, rSettings.GetDarkShadowColor());
250 maSet.SetItemText (i, String::CreateFromAscii("DarkShadowColor"));
251 maSet.InsertItem (++i, rSettings.GetButtonTextColor());
252 maSet.SetItemText (i, String::CreateFromAscii("ButtonTextColor"));
253 maSet.InsertItem (++i, rSettings.GetRadioCheckTextColor());
254 maSet.SetItemText (i, String::CreateFromAscii("RadioCheckTextColor"));
255 maSet.InsertItem (++i, rSettings.GetGroupTextColor());
256 maSet.SetItemText (i, String::CreateFromAscii("GroupTextColor"));
257 maSet.InsertItem (++i, rSettings.GetLabelTextColor());
258 maSet.SetItemText (i, String::CreateFromAscii("LabelTextColor"));
259 maSet.InsertItem (++i, rSettings.GetInfoTextColor());
260 maSet.SetItemText (i, String::CreateFromAscii("InfoTextColor"));
261 maSet.InsertItem (++i, rSettings.GetWindowColor());
262 maSet.SetItemText (i, String::CreateFromAscii("WindowColor"));
263 maSet.InsertItem (++i, rSettings.GetWindowTextColor());
264 maSet.SetItemText (i, String::CreateFromAscii("WindowTextColor"));
265 maSet.InsertItem (++i, rSettings.GetDialogColor());
266 maSet.SetItemText (i, String::CreateFromAscii("DialogColor"));
267 maSet.InsertItem (++i, rSettings.GetDialogTextColor());
268 maSet.SetItemText (i, String::CreateFromAscii("DialogTextColor"));
269 maSet.InsertItem (++i, rSettings.GetWorkspaceColor());
270 maSet.SetItemText (i, String::CreateFromAscii("WorkspaceColor"));
271 maSet.InsertItem (++i, rSettings.GetFieldColor());
272 maSet.SetItemText (i, String::CreateFromAscii("FieldColor"));
273 maSet.InsertItem (++i, rSettings.GetFieldTextColor());
274 maSet.SetItemText (i, String::CreateFromAscii("FieldTextColor"));
275 maSet.InsertItem (++i, rSettings.GetActiveColor());
276 maSet.SetItemText (i, String::CreateFromAscii("ActiveColor"));
277 maSet.InsertItem (++i, rSettings.GetActiveColor2());
278 maSet.SetItemText (i, String::CreateFromAscii("ActiveColor2"));
279 maSet.InsertItem (++i, rSettings.GetActiveTextColor());
280 maSet.SetItemText (i, String::CreateFromAscii("ActiveTextColor"));
281 maSet.InsertItem (++i, rSettings.GetActiveBorderColor());
282 maSet.SetItemText (i, String::CreateFromAscii("ActiveBorderColor"));
283 maSet.InsertItem (++i, rSettings.GetDeactiveColor());
284 maSet.SetItemText (i, String::CreateFromAscii("DeactiveColor"));
285 maSet.InsertItem (++i, rSettings.GetDeactiveColor2());
286 maSet.SetItemText (i, String::CreateFromAscii("DeactiveColor2"));
287 maSet.InsertItem (++i, rSettings.GetDeactiveTextColor());
288 maSet.SetItemText (i, String::CreateFromAscii("DeactiveTextColor"));
289 maSet.InsertItem (++i, rSettings.GetDeactiveBorderColor());
290 maSet.SetItemText (i, String::CreateFromAscii("DeactiveBorderColor"));
291 maSet.InsertItem (++i, rSettings.GetHighlightColor());
292 maSet.SetItemText (i, String::CreateFromAscii("HighlightColor"));
293 maSet.InsertItem (++i, rSettings.GetHighlightTextColor());
294 maSet.SetItemText (i, String::CreateFromAscii("HighlightTextColor"));
295 maSet.InsertItem (++i, rSettings.GetDisableColor());
296 maSet.SetItemText (i, String::CreateFromAscii("DisableColor"));
297 maSet.InsertItem (++i, rSettings.GetHelpColor());
298 maSet.SetItemText (i, String::CreateFromAscii("HelpColor"));
299 maSet.InsertItem (++i, rSettings.GetHelpTextColor());
300 maSet.SetItemText (i, String::CreateFromAscii("HelpTextColor"));
301 maSet.InsertItem (++i, rSettings.GetMenuColor());
302 maSet.SetItemText (i, String::CreateFromAscii("MenuColor"));
303 maSet.InsertItem (++i, rSettings.GetMenuBarColor());
304 maSet.SetItemText (i, String::CreateFromAscii("MenuBarColor"));
305 maSet.InsertItem (++i, rSettings.GetMenuBorderColor());
306 maSet.SetItemText (i, String::CreateFromAscii("MenuBorderColor"));
307 maSet.InsertItem (++i, rSettings.GetMenuTextColor());
308 maSet.SetItemText (i, String::CreateFromAscii("MenuTextColor"));
309 maSet.InsertItem (++i, rSettings.GetMenuHighlightColor());
310 maSet.SetItemText (i, String::CreateFromAscii("MenuHighlightColor"));
311 maSet.InsertItem (++i, rSettings.GetMenuHighlightTextColor());
312 maSet.SetItemText (i, String::CreateFromAscii("MenuHighlightTextColor"));
313 maSet.InsertItem (++i, rSettings.GetLinkColor());
314 maSet.SetItemText (i, String::CreateFromAscii("LinkColor"));
315 maSet.InsertItem (++i, rSettings.GetVisitedLinkColor());
316 maSet.SetItemText (i, String::CreateFromAscii("VisitedLinkColor"));
317 maSet.InsertItem (++i, rSettings.GetHighlightLinkColor());
318 maSet.SetItemText (i, String::CreateFromAscii("HighlightLinkColor"));
319 maSet.InsertItem (++i, rSettings.GetFontColor());
320 maSet.SetItemText (i, String::CreateFromAscii("FontColor"));
323 } } // end of namespace ::sd::toolpanel