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/event.hxx>
22 #include <vcl/image.hxx>
24 namespace sd
{ namespace sidebar
{
26 static const int gnBorderWidth(3);
27 static const int gnBorderHeight(3);
29 PreviewValueSet::PreviewValueSet (vcl::Window
* pParent
)
30 : ValueSet (pParent
, WB_TABSTOP
),
35 & ~(WB_ITEMBORDER
)// | WB_MENUSTYLEVALUESET)
36 // | WB_FLATVALUESET);
42 PreviewValueSet::~PreviewValueSet()
46 void PreviewValueSet::SetPreviewSize (const Size
& rSize
)
48 maPreviewSize
= rSize
;
51 void PreviewValueSet::SetRightMouseClickHandler (const Link
<const MouseEvent
&,void>& rLink
)
53 maRightMouseClickHandler
= rLink
;
56 void PreviewValueSet::MouseButtonDown (const MouseEvent
& rEvent
)
59 maRightMouseClickHandler
.Call(rEvent
);
61 ValueSet::MouseButtonDown(rEvent
);
65 void PreviewValueSet::Resize()
69 Size
aWindowSize (GetOutputSizePixel());
70 if (aWindowSize
.Width()>0 && aWindowSize
.Height()>0)
76 void PreviewValueSet::Rearrange()
78 sal_uInt16
nNewColumnCount (CalculateColumnCount (
79 GetOutputSizePixel().Width()));
80 sal_uInt16
nNewRowCount (CalculateRowCount (nNewColumnCount
));
83 SetColCount(nNewColumnCount
);
84 SetLineCount(nNewRowCount
);
87 sal_uInt16
PreviewValueSet::CalculateColumnCount (int nWidth
) const
92 nColumnCount
= nWidth
/ (maPreviewSize
.Width() + 2*gnBorderWidth
);
96 return static_cast<sal_uInt16
>(nColumnCount
);
99 sal_uInt16
PreviewValueSet::CalculateRowCount (sal_uInt16 nColumnCount
) const
102 int nItemCount
= GetItemCount();
103 if (nColumnCount
> 0)
105 nRowCount
= (nItemCount
+nColumnCount
-1) / nColumnCount
;
110 return static_cast<sal_uInt16
>(nRowCount
);
113 sal_Int32
PreviewValueSet::GetPreferredHeight (sal_Int32 nWidth
)
115 int nRowCount (CalculateRowCount(CalculateColumnCount(nWidth
)));
116 int nItemHeight (maPreviewSize
.Height());
118 return nRowCount
* (nItemHeight
+ 2*gnBorderHeight
);
121 } } // end of namespace sd::sidebar
123 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */