1 /**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 *
20 *************************************************************/
21
22 #include "precompiled_sd.hxx"
23
24 #include "PreviewValueSet.hxx"
25 #include <vcl/image.hxx>
26
27
28 namespace sd { namespace sidebar {
29
30
PreviewValueSet(::Window * pParent)31 PreviewValueSet::PreviewValueSet (::Window* pParent)
32 : ValueSet (pParent, WB_TABSTOP),
33 maPreviewSize(10,10),
34 mnBorderWidth(3),
35 mnBorderHeight(3),
36 mnMaxColumnCount(-1)
37 {
38 SetStyle (
39 GetStyle()
40 & ~(WB_ITEMBORDER)// | WB_MENUSTYLEVALUESET)
41 // | WB_FLATVALUESET);
42 );
43 SetColCount(2);
44 SetExtraSpacing (2);
45 }
46
47
48
49
~PreviewValueSet(void)50 PreviewValueSet::~PreviewValueSet (void)
51 {
52 }
53
54
55
56
SetPreviewSize(const Size & rSize)57 void PreviewValueSet::SetPreviewSize (const Size& rSize)
58 {
59 maPreviewSize = rSize;
60 }
61
62
63
64
SetRightMouseClickHandler(const Link & rLink)65 void PreviewValueSet::SetRightMouseClickHandler (const Link& rLink)
66 {
67 maRightMouseClickHandler = rLink;
68 }
69
70
71
72
MouseButtonDown(const MouseEvent & rEvent)73 void PreviewValueSet::MouseButtonDown (const MouseEvent& rEvent)
74 {
75 if (rEvent.IsRight())
76 maRightMouseClickHandler.Call(reinterpret_cast<void*>(
77 &const_cast<MouseEvent&>(rEvent)));
78 else
79 ValueSet::MouseButtonDown (rEvent);
80
81 }
82
83
84
85
Resize(void)86 void PreviewValueSet::Resize (void)
87 {
88 ValueSet::Resize ();
89
90 Size aWindowSize (GetOutputSizePixel());
91 if (aWindowSize.Width()>0 && aWindowSize.Height()>0)
92 {
93 Rearrange();
94 }
95 }
96
97
98
99
Rearrange(bool bForceRequestResize)100 void PreviewValueSet::Rearrange (bool bForceRequestResize)
101 {
102 sal_uInt16 nNewColumnCount (CalculateColumnCount (
103 GetOutputSizePixel().Width()));
104 sal_uInt16 nNewRowCount (CalculateRowCount (nNewColumnCount));
105
106 SetColCount(nNewColumnCount);
107 SetLineCount(nNewRowCount);
108 }
109
110
111
112
CalculateColumnCount(int nWidth) const113 sal_uInt16 PreviewValueSet::CalculateColumnCount (int nWidth) const
114 {
115 int nColumnCount = 0;
116 if (nWidth > 0)
117 {
118 nColumnCount = nWidth / (maPreviewSize.Width() + 2*mnBorderWidth);
119 if (nColumnCount < 1)
120 nColumnCount = 1;
121 else if (mnMaxColumnCount>0 && nColumnCount>mnMaxColumnCount)
122 nColumnCount = mnMaxColumnCount;
123 }
124 return (sal_uInt16)nColumnCount;
125 }
126
127
128
129
CalculateRowCount(sal_uInt16 nColumnCount) const130 sal_uInt16 PreviewValueSet::CalculateRowCount (sal_uInt16 nColumnCount) const
131 {
132 int nRowCount = 0;
133 int nItemCount = GetItemCount();
134 if (nColumnCount > 0)
135 {
136 nRowCount = (nItemCount+nColumnCount-1) / nColumnCount;
137 if (nRowCount < 1)
138 nRowCount = 1;
139 }
140
141 return (sal_uInt16)nRowCount;
142 }
143
144
145
146
GetPreferredWidth(sal_Int32 nHeight)147 sal_Int32 PreviewValueSet::GetPreferredWidth (sal_Int32 nHeight)
148 {
149 int nPreferredWidth (maPreviewSize.Width() + 2*mnBorderWidth);
150
151 // Get height of each row.
152 int nItemHeight (maPreviewSize.Height() + 2*mnBorderHeight);
153
154 // Calculate the row- and column count and from the later the preferred
155 // width.
156 int nRowCount = nHeight / nItemHeight;
157 if (nRowCount > 0)
158 {
159 int nColumnCount = (GetItemCount()+nRowCount-1) / nRowCount;
160 if (nColumnCount > 0)
161 nPreferredWidth = (maPreviewSize.Width() + 2*mnBorderWidth)
162 * nColumnCount;
163 }
164
165 return nPreferredWidth;
166 }
167
168
169
170
GetPreferredHeight(sal_Int32 nWidth)171 sal_Int32 PreviewValueSet::GetPreferredHeight (sal_Int32 nWidth)
172 {
173 int nRowCount (CalculateRowCount(CalculateColumnCount(nWidth)));
174 int nItemHeight (maPreviewSize.Height());
175
176 return nRowCount * (nItemHeight + 2*mnBorderHeight);
177 }
178
179
180
181
182 } } // end of namespace sd::sidebar
183