update dev300-m58
[ooovba.git] / sd / source / ui / toolpanel / controls / PreviewValueSet.cxx
blobdf09d725bd86c435a3b626cd85cec88858290c68
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: PreviewValueSet.cxx,v $
10 * $Revision: 1.9 $
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 "PreviewValueSet.hxx"
35 #include <vcl/image.hxx>
36 #include "taskpane/TaskPaneTreeNode.hxx"
38 namespace sd { namespace toolpanel { namespace controls {
41 PreviewValueSet::PreviewValueSet (TreeNode* pParent)
42 : ValueSet (pParent->GetWindow(), WB_TABSTOP),
43 mpParent(pParent),
44 maPreviewSize(10,10),
45 mnBorderWidth(3),
46 mnBorderHeight(3),
47 mnMaxColumnCount(-1)
49 SetStyle (
50 GetStyle()
51 & ~(WB_ITEMBORDER)// | WB_MENUSTYLEVALUESET)
52 // | WB_FLATVALUESET);
55 SetColCount(2);
56 // SetLineCount(1);
57 SetExtraSpacing (2);
63 PreviewValueSet::~PreviewValueSet (void)
70 void PreviewValueSet::SetPreviewSize (const Size& rSize)
72 maPreviewSize = rSize;
78 void PreviewValueSet::SetRightMouseClickHandler (const Link& rLink)
80 maRightMouseClickHandler = rLink;
86 void PreviewValueSet::MouseButtonDown (const MouseEvent& rEvent)
88 if (rEvent.IsRight())
89 maRightMouseClickHandler.Call(reinterpret_cast<void*>(
90 &const_cast<MouseEvent&>(rEvent)));
91 else
92 ValueSet::MouseButtonDown (rEvent);
99 void PreviewValueSet::Paint (const Rectangle& rRect)
101 SetBackground (GetSettings().GetStyleSettings().GetWindowColor());
103 ValueSet::Paint (rRect);
105 SetBackground (Wallpaper());
111 void PreviewValueSet::Resize (void)
113 ValueSet::Resize ();
115 Size aWindowSize (GetOutputSizePixel());
116 if (aWindowSize.Width()>0 && aWindowSize.Height()>0)
118 Rearrange();
125 void PreviewValueSet::Command (const CommandEvent& rEvent)
127 switch (rEvent.GetCommand())
129 case COMMAND_CONTEXTMENU:
131 CommandEvent aNonConstEventCopy (rEvent);
132 maContextMenuCallback.Call(&aNonConstEventCopy);
134 break;
136 default:
137 ValueSet::Command(rEvent);
138 break;
145 void PreviewValueSet::Rearrange (bool bForceRequestResize)
147 USHORT nOldColumnCount (GetColCount());
148 USHORT nOldRowCount (GetLineCount());
150 USHORT nNewColumnCount (CalculateColumnCount (
151 GetOutputSizePixel().Width()));
152 USHORT nNewRowCount (CalculateRowCount (nNewColumnCount));
154 SetColCount(nNewColumnCount);
155 SetLineCount(nNewRowCount);
157 if (bForceRequestResize
158 || nOldColumnCount != nNewColumnCount
159 || nOldRowCount != nNewRowCount)
160 mpParent->RequestResize();
166 void PreviewValueSet::SetContextMenuCallback (const Link& rLink)
168 maContextMenuCallback = rLink;
174 USHORT PreviewValueSet::CalculateColumnCount (int nWidth) const
176 int nColumnCount = 0;
177 if (nWidth > 0)
179 nColumnCount = nWidth / (maPreviewSize.Width() + 2*mnBorderWidth);
180 if (nColumnCount < 1)
181 nColumnCount = 1;
182 else if (mnMaxColumnCount>0 && nColumnCount>mnMaxColumnCount)
183 nColumnCount = mnMaxColumnCount;
185 return (USHORT)nColumnCount;
191 USHORT PreviewValueSet::CalculateRowCount (USHORT nColumnCount) const
193 int nRowCount = 0;
194 int nItemCount = GetItemCount();
195 if (nColumnCount > 0)
197 nRowCount = (nItemCount+nColumnCount-1) / nColumnCount;
198 if (nRowCount < 1)
199 nRowCount = 1;
202 return (USHORT)nRowCount;
208 sal_Int32 PreviewValueSet::GetPreferredWidth (sal_Int32 nHeight)
210 int nPreferredWidth (maPreviewSize.Width() + 2*mnBorderWidth);
212 // Get height of each row.
213 int nItemHeight (maPreviewSize.Height() + 2*mnBorderHeight);
215 // Calculate the row- and column count and from the later the preferred
216 // width.
217 int nRowCount = nHeight / nItemHeight;
218 if (nRowCount > 0)
220 int nColumnCount = (GetItemCount()+nRowCount-1) / nRowCount;
221 if (nColumnCount > 0)
222 nPreferredWidth = (maPreviewSize.Width() + 2*mnBorderWidth)
223 * nColumnCount;
226 return nPreferredWidth;
232 sal_Int32 PreviewValueSet::GetPreferredHeight (sal_Int32 nWidth)
234 int nRowCount (CalculateRowCount(CalculateColumnCount(nWidth)));
235 int nItemHeight (maPreviewSize.Height());
237 return nRowCount * (nItemHeight + 2*mnBorderHeight);
243 } } } // end of namespace ::sd::toolpanel::controls