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