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