1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: PreviewValueSet.cxx,v $
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
),
51 & ~(WB_ITEMBORDER
)// | WB_MENUSTYLEVALUESET)
52 // | WB_FLATVALUESET);
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
)
89 maRightMouseClickHandler
.Call(reinterpret_cast<void*>(
90 &const_cast<MouseEvent
&>(rEvent
)));
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)
115 Size
aWindowSize (GetOutputSizePixel());
116 if (aWindowSize
.Width()>0 && aWindowSize
.Height()>0)
125 void PreviewValueSet::Command (const CommandEvent
& rEvent
)
127 switch (rEvent
.GetCommand())
129 case COMMAND_CONTEXTMENU
:
131 CommandEvent
aNonConstEventCopy (rEvent
);
132 maContextMenuCallback
.Call(&aNonConstEventCopy
);
137 ValueSet::Command(rEvent
);
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;
179 nColumnCount
= nWidth
/ (maPreviewSize
.Width() + 2*mnBorderWidth
);
180 if (nColumnCount
< 1)
182 else if (mnMaxColumnCount
>0 && nColumnCount
>mnMaxColumnCount
)
183 nColumnCount
= mnMaxColumnCount
;
185 return (USHORT
)nColumnCount
;
191 USHORT
PreviewValueSet::CalculateRowCount (USHORT nColumnCount
) const
194 int nItemCount
= GetItemCount();
195 if (nColumnCount
> 0)
197 nRowCount
= (nItemCount
+nColumnCount
-1) / nColumnCount
;
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
217 int nRowCount
= nHeight
/ nItemHeight
;
220 int nColumnCount
= (GetItemCount()+nRowCount
-1) / nRowCount
;
221 if (nColumnCount
> 0)
222 nPreferredWidth
= (maPreviewSize
.Width() + 2*mnBorderWidth
)
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