1*6a606da0SAndre Fischer /**************************************************************
2*6a606da0SAndre Fischer  *
3*6a606da0SAndre Fischer  * Licensed to the Apache Software Foundation (ASF) under one
4*6a606da0SAndre Fischer  * or more contributor license agreements.  See the NOTICE file
5*6a606da0SAndre Fischer  * distributed with this work for additional information
6*6a606da0SAndre Fischer  * regarding copyright ownership.  The ASF licenses this file
7*6a606da0SAndre Fischer  * to you under the Apache License, Version 2.0 (the
8*6a606da0SAndre Fischer  * "License"); you may not use this file except in compliance
9*6a606da0SAndre Fischer  * with the License.  You may obtain a copy of the License at
10*6a606da0SAndre Fischer  *
11*6a606da0SAndre Fischer  *   http://www.apache.org/licenses/LICENSE-2.0
12*6a606da0SAndre Fischer  *
13*6a606da0SAndre Fischer  * Unless required by applicable law or agreed to in writing,
14*6a606da0SAndre Fischer  * software distributed under the License is distributed on an
15*6a606da0SAndre Fischer  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*6a606da0SAndre Fischer  * KIND, either express or implied.  See the License for the
17*6a606da0SAndre Fischer  * specific language governing permissions and limitations
18*6a606da0SAndre Fischer  * under the License.
19*6a606da0SAndre Fischer  *
20*6a606da0SAndre Fischer  *************************************************************/
21*6a606da0SAndre Fischer 
22*6a606da0SAndre Fischer #ifndef SFX_SIDEBAR_GRID_LAYOUTER_HXX
23*6a606da0SAndre Fischer #define SFX_SIDEBAR_GRID_LAYOUTER_HXX
24*6a606da0SAndre Fischer 
25*6a606da0SAndre Fischer #include "sfx2/dllapi.h"
26*6a606da0SAndre Fischer #include <boost/scoped_ptr.hpp>
27*6a606da0SAndre Fischer 
28*6a606da0SAndre Fischer class Rectangle;
29*6a606da0SAndre Fischer class Window;
30*6a606da0SAndre Fischer 
31*6a606da0SAndre Fischer namespace sfx2 { namespace sidebar {
32*6a606da0SAndre Fischer 
33*6a606da0SAndre Fischer class CellDescriptor;
34*6a606da0SAndre Fischer class ColumnDescriptor;
35*6a606da0SAndre Fischer 
36*6a606da0SAndre Fischer /** A simple layouter that organizes controls in a grid.
37*6a606da0SAndre Fischer     At the moment only horizontal positions and sizes are processed.
38*6a606da0SAndre Fischer     It can handle all or only a subset of the controls in one panel.
39*6a606da0SAndre Fischer */
40*6a606da0SAndre Fischer class SFX2_DLLPUBLIC GridLayouter
41*6a606da0SAndre Fischer {
42*6a606da0SAndre Fischer public:
43*6a606da0SAndre Fischer     GridLayouter (Window& rParent);
44*6a606da0SAndre Fischer     ~GridLayouter (void);
45*6a606da0SAndre Fischer 
46*6a606da0SAndre Fischer     /** Return the cell descriptor for the specified cell.
47*6a606da0SAndre Fischer         This creates empty column data structures as needed.
48*6a606da0SAndre Fischer 
49*6a606da0SAndre Fischer         By default a cell has only one cell descriptor.  Different
50*6a606da0SAndre Fischer         variants allow different cell descriptors for different
51*6a606da0SAndre Fischer         controls.  This is useful if different controls are displayed
52*6a606da0SAndre Fischer         for different contexts, and, say, one has a fixed width and
53*6a606da0SAndre Fischer         another is to fill the column.
54*6a606da0SAndre Fischer 
55*6a606da0SAndre Fischer         During layouting only cell descriptors are processed that have
56*6a606da0SAndre Fischer         visible controls.
57*6a606da0SAndre Fischer     */
58*6a606da0SAndre Fischer     CellDescriptor& GetCell (
59*6a606da0SAndre Fischer         const sal_Int32 nRow,
60*6a606da0SAndre Fischer         const sal_Int32 nColumn,
61*6a606da0SAndre Fischer         const sal_Int32 nVariant = 0);
62*6a606da0SAndre Fischer 
63*6a606da0SAndre Fischer     ColumnDescriptor& GetColumn (
64*6a606da0SAndre Fischer         const sal_Int32 nColumn);
65*6a606da0SAndre Fischer 
66*6a606da0SAndre Fischer     /** Calculate positions and sizes for all visible controls under
67*6a606da0SAndre Fischer         the control of the grid layouter according to the current size
68*6a606da0SAndre Fischer         of the parent window.
69*6a606da0SAndre Fischer     */
70*6a606da0SAndre Fischer     void Layout (void);
71*6a606da0SAndre Fischer 
72*6a606da0SAndre Fischer     /** Paint some debug information.
73*6a606da0SAndre Fischer     */
74*6a606da0SAndre Fischer     void Paint (const Rectangle& rBox);
75*6a606da0SAndre Fischer 
76*6a606da0SAndre Fischer private:
77*6a606da0SAndre Fischer     class Implementation;
78*6a606da0SAndre Fischer     ::boost::scoped_ptr<Implementation> mpImplementation;
79*6a606da0SAndre Fischer };
80*6a606da0SAndre Fischer 
81*6a606da0SAndre Fischer 
82*6a606da0SAndre Fischer 
83*6a606da0SAndre Fischer /** A collection of attributes for a single cell in a grid layout.
84*6a606da0SAndre Fischer     Represents one control.
85*6a606da0SAndre Fischer */
86*6a606da0SAndre Fischer class SFX2_DLLPUBLIC CellDescriptor
87*6a606da0SAndre Fischer {
88*6a606da0SAndre Fischer public:
89*6a606da0SAndre Fischer     CellDescriptor (void);
90*6a606da0SAndre Fischer     ~CellDescriptor (void);
91*6a606da0SAndre Fischer 
92*6a606da0SAndre Fischer     /** Set the number of columns covered by the cell.  The default
93*6a606da0SAndre Fischer         value is 1.
94*6a606da0SAndre Fischer     */
95*6a606da0SAndre Fischer     CellDescriptor& SetGridWidth (const sal_Int32 nColumnCount);
96*6a606da0SAndre Fischer 
97*6a606da0SAndre Fischer     /** Set the control represented by the cell and whose position and
98*6a606da0SAndre Fischer         size will be modified in subsequent calls to
99*6a606da0SAndre Fischer         GridLayouter::Layout().
100*6a606da0SAndre Fischer         The cell is only taken into account in Layout() when the
101*6a606da0SAndre Fischer         control is visible.
102*6a606da0SAndre Fischer     */
103*6a606da0SAndre Fischer     CellDescriptor& SetControl (Window& rWindow);
104*6a606da0SAndre Fischer 
105*6a606da0SAndre Fischer     /** Set the minimum and maximum width of the cell to the given
106*6a606da0SAndre Fischer         value.
107*6a606da0SAndre Fischer     */
108*6a606da0SAndre Fischer     CellDescriptor& SetFixedWidth (const sal_Int32 nWidth);
109*6a606da0SAndre Fischer 
110*6a606da0SAndre Fischer     /** Set the minimum and maximum width of the cell to the current
111*6a606da0SAndre Fischer         width of the control.
112*6a606da0SAndre Fischer     */
113*6a606da0SAndre Fischer     CellDescriptor& SetFixedWidth (void);
114*6a606da0SAndre Fischer     CellDescriptor& SetMinimumWidth (const sal_Int32 nWidth);
115*6a606da0SAndre Fischer 
116*6a606da0SAndre Fischer     /** Set the horizontal offset of the control with respect to the
117*6a606da0SAndre Fischer         containing column.  The offset is only used when the position
118*6a606da0SAndre Fischer         of the control is calculated not when the sizes of columns are
119*6a606da0SAndre Fischer         calculated.
120*6a606da0SAndre Fischer     */
121*6a606da0SAndre Fischer     CellDescriptor& SetOffset (const sal_Int32 nOffset);
122*6a606da0SAndre Fischer 
123*6a606da0SAndre Fischer     sal_Int32 GetGridWidth (void) const;
124*6a606da0SAndre Fischer     Window* GetControl (void) const;
125*6a606da0SAndre Fischer     sal_Int32 GetMinimumWidth (void) const;
126*6a606da0SAndre Fischer     sal_Int32 GetMaximumWidth (void) const;
127*6a606da0SAndre Fischer     sal_Int32 GetOffset (void) const;
128*6a606da0SAndre Fischer 
129*6a606da0SAndre Fischer private:
130*6a606da0SAndre Fischer     Window* mpControl;
131*6a606da0SAndre Fischer     sal_Int32 mnGridWidth;
132*6a606da0SAndre Fischer     sal_Int32 mnMinimumWidth;
133*6a606da0SAndre Fischer     sal_Int32 mnMaximumWidth;
134*6a606da0SAndre Fischer     sal_Int32 mnOffset;
135*6a606da0SAndre Fischer };
136*6a606da0SAndre Fischer 
137*6a606da0SAndre Fischer 
138*6a606da0SAndre Fischer 
139*6a606da0SAndre Fischer /** A collection of attributes for a single column in a grid layout.
140*6a606da0SAndre Fischer */
141*6a606da0SAndre Fischer class SFX2_DLLPUBLIC ColumnDescriptor
142*6a606da0SAndre Fischer {
143*6a606da0SAndre Fischer public:
144*6a606da0SAndre Fischer     ColumnDescriptor (void);
145*6a606da0SAndre Fischer     ~ColumnDescriptor (void);
146*6a606da0SAndre Fischer 
147*6a606da0SAndre Fischer     ColumnDescriptor& SetWeight (
148*6a606da0SAndre Fischer         const sal_Int32 nWeight);
149*6a606da0SAndre Fischer     ColumnDescriptor& SetMinimumWidth (
150*6a606da0SAndre Fischer         const sal_Int32 nWidth);
151*6a606da0SAndre Fischer     /** Set both minimum and maximum width to the given value.
152*6a606da0SAndre Fischer     */
153*6a606da0SAndre Fischer     ColumnDescriptor& SetFixedWidth (
154*6a606da0SAndre Fischer         const sal_Int32 nWidth);
155*6a606da0SAndre Fischer 
156*6a606da0SAndre Fischer     /** Set external padding on the left side of the column.
157*6a606da0SAndre Fischer     */
158*6a606da0SAndre Fischer     ColumnDescriptor& SetLeftPadding (
159*6a606da0SAndre Fischer         const sal_Int32 nPadding);
160*6a606da0SAndre Fischer 
161*6a606da0SAndre Fischer     /** Set external padding on the right side of the column.
162*6a606da0SAndre Fischer     */
163*6a606da0SAndre Fischer     ColumnDescriptor& SetRightPadding (
164*6a606da0SAndre Fischer         const sal_Int32 nPadding);
165*6a606da0SAndre Fischer 
166*6a606da0SAndre Fischer     sal_Int32 GetWeight (void) const;
167*6a606da0SAndre Fischer 
168*6a606da0SAndre Fischer     /** Return the minimum width of the column without external
169*6a606da0SAndre Fischer         padding.  This is the value last set with SetMinimumWidth() or SetFixedWidth().
170*6a606da0SAndre Fischer     */
171*6a606da0SAndre Fischer     sal_Int32 GetMinimumWidth (void) const;
172*6a606da0SAndre Fischer 
173*6a606da0SAndre Fischer     /** Return the maximum width of the column without external
174*6a606da0SAndre Fischer         padding.  This is the value last set with SetFixedWidth().
175*6a606da0SAndre Fischer     */
176*6a606da0SAndre Fischer     sal_Int32 GetMaximumWidth (void) const;
177*6a606da0SAndre Fischer 
178*6a606da0SAndre Fischer     /** Return the maximum width of the column including external
179*6a606da0SAndre Fischer         padding.
180*6a606da0SAndre Fischer     */
181*6a606da0SAndre Fischer     sal_Int32 GetTotalMaximumWidth (void) const;
182*6a606da0SAndre Fischer 
183*6a606da0SAndre Fischer     sal_Int32 GetLeftPadding (void) const;
184*6a606da0SAndre Fischer     sal_Int32 GetRightPadding (void) const;
185*6a606da0SAndre Fischer 
186*6a606da0SAndre Fischer     /** The width of the column is a temporary and internal value that
187*6a606da0SAndre Fischer         is calculated in GridLayouter::Layout().
188*6a606da0SAndre Fischer         Calling this method outside of Layout() does not have any effect.
189*6a606da0SAndre Fischer     */
190*6a606da0SAndre Fischer     void SetWidth (const sal_Int32 nWidth);
191*6a606da0SAndre Fischer     sal_Int32 GetWidth (void) const;
192*6a606da0SAndre Fischer 
193*6a606da0SAndre Fischer private:
194*6a606da0SAndre Fischer     sal_Int32 mnWeight;
195*6a606da0SAndre Fischer     sal_Int32 mnMinimumWidth;
196*6a606da0SAndre Fischer     sal_Int32 mnMaximumWidth;
197*6a606da0SAndre Fischer     sal_Int32 mnLeftPadding;
198*6a606da0SAndre Fischer     sal_Int32 mnRightPadding;
199*6a606da0SAndre Fischer 
200*6a606da0SAndre Fischer     // Temporary values set calculated in the Layout() method.
201*6a606da0SAndre Fischer     sal_Int32 mnWidth;
202*6a606da0SAndre Fischer };
203*6a606da0SAndre Fischer 
204*6a606da0SAndre Fischer 
205*6a606da0SAndre Fischer } } // end of namespace sfx2::sidebar
206*6a606da0SAndre Fischer 
207*6a606da0SAndre Fischer #endif
208