bump product version to 6.3.0.0.beta1
[LibreOffice.git] / sd / source / ui / sidebar / PreviewValueSet.cxx
blob9cde13dac181a47bdd157cc2ce205e6257c471fe
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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),
31 maPreviewSize(10,10)
33 SetStyle (
34 GetStyle()
35 & ~(WB_ITEMBORDER)// | WB_MENUSTYLEVALUESET)
36 // | WB_FLATVALUESET);
38 SetColCount(2);
39 SetExtraSpacing (2);
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)
58 if (rEvent.IsRight())
59 maRightMouseClickHandler.Call(rEvent);
60 else
61 ValueSet::MouseButtonDown(rEvent);
65 void PreviewValueSet::Resize()
67 ValueSet::Resize ();
69 Size aWindowSize (GetOutputSizePixel());
70 if (aWindowSize.Width()>0 && aWindowSize.Height()>0)
72 Rearrange();
76 void PreviewValueSet::Rearrange()
78 sal_uInt16 nNewColumnCount (CalculateColumnCount (
79 GetOutputSizePixel().Width()));
80 sal_uInt16 nNewRowCount (CalculateRowCount (nNewColumnCount));
82 SetFormat();
83 SetColCount(nNewColumnCount);
84 SetLineCount(nNewRowCount);
87 sal_uInt16 PreviewValueSet::CalculateColumnCount (int nWidth) const
89 int nColumnCount = 0;
90 if (nWidth > 0)
92 nColumnCount = nWidth / (maPreviewSize.Width() + 2*gnBorderWidth);
93 if (nColumnCount < 1)
94 nColumnCount = 1;
96 return static_cast<sal_uInt16>(nColumnCount);
99 sal_uInt16 PreviewValueSet::CalculateRowCount (sal_uInt16 nColumnCount) const
101 int nRowCount = 0;
102 int nItemCount = GetItemCount();
103 if (nColumnCount > 0)
105 nRowCount = (nItemCount+nColumnCount-1) / nColumnCount;
106 if (nRowCount < 1)
107 nRowCount = 1;
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: */