1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include "PreviewValueSet.hxx"
21 #include <vcl/image.hxx>
24 namespace sd
{ namespace sidebar
{
27 PreviewValueSet::PreviewValueSet (::Window
* pParent
)
28 : ValueSet (pParent
, WB_TABSTOP
),
36 & ~(WB_ITEMBORDER
)// | WB_MENUSTYLEVALUESET)
37 // | WB_FLATVALUESET);
46 PreviewValueSet::~PreviewValueSet (void)
53 void PreviewValueSet::SetPreviewSize (const Size
& rSize
)
55 maPreviewSize
= rSize
;
61 void PreviewValueSet::SetRightMouseClickHandler (const Link
& rLink
)
63 maRightMouseClickHandler
= rLink
;
69 void PreviewValueSet::MouseButtonDown (const MouseEvent
& rEvent
)
72 maRightMouseClickHandler
.Call(reinterpret_cast<void*>(
73 &const_cast<MouseEvent
&>(rEvent
)));
75 ValueSet::MouseButtonDown (rEvent
);
82 void PreviewValueSet::Resize (void)
86 Size
aWindowSize (GetOutputSizePixel());
87 if (aWindowSize
.Width()>0 && aWindowSize
.Height()>0)
96 void PreviewValueSet::Rearrange (bool /*bForceRequestResize*/)
98 sal_uInt16
nNewColumnCount (CalculateColumnCount (
99 GetOutputSizePixel().Width()));
100 sal_uInt16
nNewRowCount (CalculateRowCount (nNewColumnCount
));
102 SetColCount(nNewColumnCount
);
103 SetLineCount(nNewRowCount
);
109 sal_uInt16
PreviewValueSet::CalculateColumnCount (int nWidth
) const
111 int nColumnCount
= 0;
114 nColumnCount
= nWidth
/ (maPreviewSize
.Width() + 2*mnBorderWidth
);
115 if (nColumnCount
< 1)
117 else if (mnMaxColumnCount
>0 && nColumnCount
>mnMaxColumnCount
)
118 nColumnCount
= mnMaxColumnCount
;
120 return (sal_uInt16
)nColumnCount
;
126 sal_uInt16
PreviewValueSet::CalculateRowCount (sal_uInt16 nColumnCount
) const
129 int nItemCount
= GetItemCount();
130 if (nColumnCount
> 0)
132 nRowCount
= (nItemCount
+nColumnCount
-1) / nColumnCount
;
137 return (sal_uInt16
)nRowCount
;
143 sal_Int32
PreviewValueSet::GetPreferredWidth (sal_Int32 nHeight
)
145 int nPreferredWidth (maPreviewSize
.Width() + 2*mnBorderWidth
);
147 // Get height of each row.
148 int nItemHeight (maPreviewSize
.Height() + 2*mnBorderHeight
);
150 // Calculate the row- and column count and from the later the preferred
152 int nRowCount
= nHeight
/ nItemHeight
;
155 int nColumnCount
= (GetItemCount()+nRowCount
-1) / nRowCount
;
156 if (nColumnCount
> 0)
157 nPreferredWidth
= (maPreviewSize
.Width() + 2*mnBorderWidth
)
161 return nPreferredWidth
;
167 sal_Int32
PreviewValueSet::GetPreferredHeight (sal_Int32 nWidth
)
169 int nRowCount (CalculateRowCount(CalculateColumnCount(nWidth
)));
170 int nItemHeight (maPreviewSize
.Height());
172 return nRowCount
* (nItemHeight
+ 2*mnBorderHeight
);
178 } } // end of namespace sd::sidebar
180 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */