102c50d82SAndre Fischer /**************************************************************
202c50d82SAndre Fischer *
302c50d82SAndre Fischer * Licensed to the Apache Software Foundation (ASF) under one
402c50d82SAndre Fischer * or more contributor license agreements. See the NOTICE file
502c50d82SAndre Fischer * distributed with this work for additional information
602c50d82SAndre Fischer * regarding copyright ownership. The ASF licenses this file
702c50d82SAndre Fischer * to you under the Apache License, Version 2.0 (the
802c50d82SAndre Fischer * "License"); you may not use this file except in compliance
902c50d82SAndre Fischer * with the License. You may obtain a copy of the License at
1002c50d82SAndre Fischer *
1102c50d82SAndre Fischer * http://www.apache.org/licenses/LICENSE-2.0
1202c50d82SAndre Fischer *
1302c50d82SAndre Fischer * Unless required by applicable law or agreed to in writing,
1402c50d82SAndre Fischer * software distributed under the License is distributed on an
1502c50d82SAndre Fischer * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
1602c50d82SAndre Fischer * KIND, either express or implied. See the License for the
1702c50d82SAndre Fischer * specific language governing permissions and limitations
1802c50d82SAndre Fischer * under the License.
1902c50d82SAndre Fischer *
2002c50d82SAndre Fischer *************************************************************/
2102c50d82SAndre Fischer
2202c50d82SAndre Fischer #include "precompiled_sd.hxx"
2302c50d82SAndre Fischer
2402c50d82SAndre Fischer #include "PreviewValueSet.hxx"
2502c50d82SAndre Fischer #include <vcl/image.hxx>
2602c50d82SAndre Fischer
27*37fee4fdSAndre Fischer
2802c50d82SAndre Fischer namespace sd { namespace sidebar {
2902c50d82SAndre Fischer
3002c50d82SAndre Fischer
PreviewValueSet(::Window * pParent)3102c50d82SAndre Fischer PreviewValueSet::PreviewValueSet (::Window* pParent)
3202c50d82SAndre Fischer : ValueSet (pParent, WB_TABSTOP),
3302c50d82SAndre Fischer maPreviewSize(10,10),
3402c50d82SAndre Fischer mnBorderWidth(3),
3502c50d82SAndre Fischer mnBorderHeight(3),
3602c50d82SAndre Fischer mnMaxColumnCount(-1)
3702c50d82SAndre Fischer {
3802c50d82SAndre Fischer SetStyle (
3902c50d82SAndre Fischer GetStyle()
4002c50d82SAndre Fischer & ~(WB_ITEMBORDER)// | WB_MENUSTYLEVALUESET)
4102c50d82SAndre Fischer // | WB_FLATVALUESET);
4202c50d82SAndre Fischer );
4302c50d82SAndre Fischer SetColCount(2);
4402c50d82SAndre Fischer SetExtraSpacing (2);
4502c50d82SAndre Fischer }
4602c50d82SAndre Fischer
4702c50d82SAndre Fischer
4802c50d82SAndre Fischer
4902c50d82SAndre Fischer
~PreviewValueSet(void)5002c50d82SAndre Fischer PreviewValueSet::~PreviewValueSet (void)
5102c50d82SAndre Fischer {
5202c50d82SAndre Fischer }
5302c50d82SAndre Fischer
5402c50d82SAndre Fischer
5502c50d82SAndre Fischer
5602c50d82SAndre Fischer
SetPreviewSize(const Size & rSize)5702c50d82SAndre Fischer void PreviewValueSet::SetPreviewSize (const Size& rSize)
5802c50d82SAndre Fischer {
5902c50d82SAndre Fischer maPreviewSize = rSize;
6002c50d82SAndre Fischer }
6102c50d82SAndre Fischer
6202c50d82SAndre Fischer
6302c50d82SAndre Fischer
6402c50d82SAndre Fischer
SetRightMouseClickHandler(const Link & rLink)6502c50d82SAndre Fischer void PreviewValueSet::SetRightMouseClickHandler (const Link& rLink)
6602c50d82SAndre Fischer {
6702c50d82SAndre Fischer maRightMouseClickHandler = rLink;
6802c50d82SAndre Fischer }
6902c50d82SAndre Fischer
7002c50d82SAndre Fischer
7102c50d82SAndre Fischer
7202c50d82SAndre Fischer
MouseButtonDown(const MouseEvent & rEvent)7302c50d82SAndre Fischer void PreviewValueSet::MouseButtonDown (const MouseEvent& rEvent)
7402c50d82SAndre Fischer {
7502c50d82SAndre Fischer if (rEvent.IsRight())
7602c50d82SAndre Fischer maRightMouseClickHandler.Call(reinterpret_cast<void*>(
7702c50d82SAndre Fischer &const_cast<MouseEvent&>(rEvent)));
7802c50d82SAndre Fischer else
7902c50d82SAndre Fischer ValueSet::MouseButtonDown (rEvent);
8002c50d82SAndre Fischer
8102c50d82SAndre Fischer }
8202c50d82SAndre Fischer
8302c50d82SAndre Fischer
8402c50d82SAndre Fischer
8502c50d82SAndre Fischer
Resize(void)8602c50d82SAndre Fischer void PreviewValueSet::Resize (void)
8702c50d82SAndre Fischer {
8802c50d82SAndre Fischer ValueSet::Resize ();
8902c50d82SAndre Fischer
9002c50d82SAndre Fischer Size aWindowSize (GetOutputSizePixel());
9102c50d82SAndre Fischer if (aWindowSize.Width()>0 && aWindowSize.Height()>0)
9202c50d82SAndre Fischer {
9302c50d82SAndre Fischer Rearrange();
9402c50d82SAndre Fischer }
9502c50d82SAndre Fischer }
9602c50d82SAndre Fischer
9702c50d82SAndre Fischer
9802c50d82SAndre Fischer
9902c50d82SAndre Fischer
Rearrange(bool bForceRequestResize)10002c50d82SAndre Fischer void PreviewValueSet::Rearrange (bool bForceRequestResize)
10102c50d82SAndre Fischer {
10202c50d82SAndre Fischer sal_uInt16 nNewColumnCount (CalculateColumnCount (
10302c50d82SAndre Fischer GetOutputSizePixel().Width()));
10402c50d82SAndre Fischer sal_uInt16 nNewRowCount (CalculateRowCount (nNewColumnCount));
10502c50d82SAndre Fischer
10602c50d82SAndre Fischer SetColCount(nNewColumnCount);
10702c50d82SAndre Fischer SetLineCount(nNewRowCount);
10802c50d82SAndre Fischer }
10902c50d82SAndre Fischer
11002c50d82SAndre Fischer
11102c50d82SAndre Fischer
11202c50d82SAndre Fischer
CalculateColumnCount(int nWidth) const11302c50d82SAndre Fischer sal_uInt16 PreviewValueSet::CalculateColumnCount (int nWidth) const
11402c50d82SAndre Fischer {
11502c50d82SAndre Fischer int nColumnCount = 0;
11602c50d82SAndre Fischer if (nWidth > 0)
11702c50d82SAndre Fischer {
11802c50d82SAndre Fischer nColumnCount = nWidth / (maPreviewSize.Width() + 2*mnBorderWidth);
11902c50d82SAndre Fischer if (nColumnCount < 1)
12002c50d82SAndre Fischer nColumnCount = 1;
12102c50d82SAndre Fischer else if (mnMaxColumnCount>0 && nColumnCount>mnMaxColumnCount)
12202c50d82SAndre Fischer nColumnCount = mnMaxColumnCount;
12302c50d82SAndre Fischer }
12402c50d82SAndre Fischer return (sal_uInt16)nColumnCount;
12502c50d82SAndre Fischer }
12602c50d82SAndre Fischer
12702c50d82SAndre Fischer
12802c50d82SAndre Fischer
12902c50d82SAndre Fischer
CalculateRowCount(sal_uInt16 nColumnCount) const13002c50d82SAndre Fischer sal_uInt16 PreviewValueSet::CalculateRowCount (sal_uInt16 nColumnCount) const
13102c50d82SAndre Fischer {
13202c50d82SAndre Fischer int nRowCount = 0;
13302c50d82SAndre Fischer int nItemCount = GetItemCount();
13402c50d82SAndre Fischer if (nColumnCount > 0)
13502c50d82SAndre Fischer {
13602c50d82SAndre Fischer nRowCount = (nItemCount+nColumnCount-1) / nColumnCount;
13702c50d82SAndre Fischer if (nRowCount < 1)
13802c50d82SAndre Fischer nRowCount = 1;
13902c50d82SAndre Fischer }
14002c50d82SAndre Fischer
14102c50d82SAndre Fischer return (sal_uInt16)nRowCount;
14202c50d82SAndre Fischer }
14302c50d82SAndre Fischer
14402c50d82SAndre Fischer
14502c50d82SAndre Fischer
14602c50d82SAndre Fischer
GetPreferredWidth(sal_Int32 nHeight)14702c50d82SAndre Fischer sal_Int32 PreviewValueSet::GetPreferredWidth (sal_Int32 nHeight)
14802c50d82SAndre Fischer {
14902c50d82SAndre Fischer int nPreferredWidth (maPreviewSize.Width() + 2*mnBorderWidth);
15002c50d82SAndre Fischer
15102c50d82SAndre Fischer // Get height of each row.
15202c50d82SAndre Fischer int nItemHeight (maPreviewSize.Height() + 2*mnBorderHeight);
15302c50d82SAndre Fischer
15402c50d82SAndre Fischer // Calculate the row- and column count and from the later the preferred
15502c50d82SAndre Fischer // width.
15602c50d82SAndre Fischer int nRowCount = nHeight / nItemHeight;
15702c50d82SAndre Fischer if (nRowCount > 0)
15802c50d82SAndre Fischer {
15902c50d82SAndre Fischer int nColumnCount = (GetItemCount()+nRowCount-1) / nRowCount;
16002c50d82SAndre Fischer if (nColumnCount > 0)
16102c50d82SAndre Fischer nPreferredWidth = (maPreviewSize.Width() + 2*mnBorderWidth)
16202c50d82SAndre Fischer * nColumnCount;
16302c50d82SAndre Fischer }
16402c50d82SAndre Fischer
16502c50d82SAndre Fischer return nPreferredWidth;
16602c50d82SAndre Fischer }
16702c50d82SAndre Fischer
16802c50d82SAndre Fischer
16902c50d82SAndre Fischer
17002c50d82SAndre Fischer
GetPreferredHeight(sal_Int32 nWidth)17102c50d82SAndre Fischer sal_Int32 PreviewValueSet::GetPreferredHeight (sal_Int32 nWidth)
17202c50d82SAndre Fischer {
17302c50d82SAndre Fischer int nRowCount (CalculateRowCount(CalculateColumnCount(nWidth)));
17402c50d82SAndre Fischer int nItemHeight (maPreviewSize.Height());
17502c50d82SAndre Fischer
17602c50d82SAndre Fischer return nRowCount * (nItemHeight + 2*mnBorderHeight);
17702c50d82SAndre Fischer }
17802c50d82SAndre Fischer
17902c50d82SAndre Fischer
18002c50d82SAndre Fischer
18102c50d82SAndre Fischer
18202c50d82SAndre Fischer } } // end of namespace sd::sidebar
183