OWLNext    7.0
Borland's Object Windows Library for the modern age
Loading...
Searching...
No Matches
toolbox.cpp
Go to the documentation of this file.
1//----------------------------------------------------------------------------
2// ObjectWindows
3// Copyright (c) 1992, 1996 by Borland International, All Rights Reserved
4//
5/// \file
6/// Implementation of class TToolBox, a 2-d arrangement of TButtonGadgets.
7//----------------------------------------------------------------------------
8#include <owl/pch.h>
9#include <owl/toolbox.h>
10#include <owl/buttonga.h>
11#include <owl/uimetric.h>
12
13namespace owl {
14
16
17//
18/// Constructs a TToolBox object with the specified number of columns and rows and
19/// tiling direction. Overlaps the borders of the toolbox with those of the gadget
20/// and sets ShrinkWrapWidth to true.
21//
23 int numColumns,
24 int numRows,
26 TModule* module)
27:
29{
30 NumRows = numRows;
31 NumColumns = numColumns;
32
33 // Make the gadget borders (if any) overlap the tool box's borders
34 //
35 Margins.Units = TMargins::BorderUnits;
36 Margins.Left = Margins.Right = 0;
37 Margins.Top = Margins.Bottom = 0;
38
39 ShrinkWrapWidth = true;
40}
41
42//
43/// Overrides TGadget's Insert function and tells the button not to notch its corners.
44///
45/// Only TButtonGadgets or derived gadgets are supported.
46//
47void
49{
51
52 // Notch the corners if it's a buttonGadget
53 //
55 if (bg)
56 bg->SetNotchCorners(false);
57}
58
59//
60/// Sets the direction of the tiling--either horizontal or vertical.
61///
62/// Swap the rows & columns count, and let our base class do the rest
63//
64void
66{
67 TTileDirection dir = Direction;
68 if (dir != direction) {
69 int t = NumRows;
70 NumRows = NumColumns;
71 NumColumns = t;
72 }
73
75}
76
77//
78// Compute the numer of rows & columns, filling in rows OR columns if left
79// unspecified using AS_MANY_AS_NEEDED (but not both).
80//
81void
82TToolBox::ComputeNumRowsColumns(int& numRows, int& numColumns)
83{
84 CHECK(NumRows != AS_MANY_AS_NEEDED || NumColumns != AS_MANY_AS_NEEDED);
85 numRows = NumRows == AS_MANY_AS_NEEDED ?
86 (NumGadgets + NumColumns - 1) / NumColumns :
87 NumRows;
88 numColumns = NumColumns == AS_MANY_AS_NEEDED ?
89 (NumGadgets + NumRows - 1) / NumRows :
90 NumColumns;
91}
92
93//
94// Compute the cell size which is determined by the widest and the highest
95// gadget
96//
97void
98TToolBox::ComputeCellSize(TSize& cellSize)
99{
100 cellSize.cx = cellSize.cy = 0;
101
102 for (TGadget* g = Gadgets; g; g = g->NextGadget()) {
103 TSize desiredSize(0, 0);
104
105 g->GetDesiredSize(desiredSize);
106
107 if (desiredSize.cx > cellSize.cx)
108 cellSize.cx = desiredSize.cx;
109
110 if (desiredSize.cy > cellSize.cy)
111 cellSize.cy = desiredSize.cy;
112 }
113}
114
115//
116/// Overrides TGadget's GetDesiredSize function and computes the size of the cell by
117/// calling GetMargins to get the margins.
118//
119void
121{
122 // Get border sizes
123 //
124 int cxBorder = 0;
125 int cyBorder = 0;
126
127 int left, right, top, bottom;
128 GetMargins(Margins, left, right, top, bottom);
129 size.cx = left + right;
130 size.cy = top + bottom;
131
132 // Add in this window's border size if used
133 //
134 if (Attr.Style & WS_BORDER) {
135 size.cx += 2 * TUIMetric::CxBorder;
136 size.cy += 2 * TUIMetric::CyBorder;
137 }
138
140 ComputeCellSize(cellSize);
141
142 int numRows, numColumns;
143 ComputeNumRowsColumns(numRows, numColumns);
144
145 size.cx += numColumns * cellSize.cx;
146 size.cy += numRows * cellSize.cy;
147
148 // Compensate for the gadgets overlapping if UI style does that
149 //
150 size.cx -= (numColumns - 1) * cxBorder;
151 size.cy -= (numRows - 1) * cyBorder;
152}
153
154//
155/// Tiles the gadgets in the direction requested (horizontal or vertical). Derived
156/// classes can adjust the spacing between gadgets.
157///
158/// Horizontal direction results in a row-major layout,
159/// and vertical direction results in column-major layout
160//
161TRect
163{
165 ComputeCellSize(cellSize);
166
167 int numRows, numColumns;
168 ComputeNumRowsColumns(numRows, numColumns);
169
172
174 invalidRect.SetEmpty();
175
176 if (Direction == Horizontal) {
177 // Row Major
178 //
179 int y = innerRect.top;
180 TGadget* g = Gadgets;
181
182 for (int r = 0; r < numRows; r++) {
183 int x = innerRect.left;
184
185 for (int c = 0; c < numColumns && g; c++) {
186 TRect bounds(TPoint(x, y), cellSize);
187 TRect originalBounds(g->GetBounds());
188
189 if (bounds != g->GetBounds()) {
190 g->SetBounds(bounds);
191
192 if (invalidRect.IsNull())
194 else
196
197 if (originalBounds.TopLeft() != TPoint(0, 0))
199 }
200
201 x += cellSize.cx;
202 g = g->NextGadget();
203 }
204
205 y += cellSize.cy;
206 }
207 }
208 else {
209 // Column Major
210 //
211 int x = innerRect.left;
212 TGadget* g = Gadgets;
213
214 for (int c = 0; c < numColumns; c++) {
215 int y = innerRect.top;
216
217 for (int r = 0; r < numRows && g; r++) {
218 TRect bounds(TPoint(x, y), cellSize);
219 TRect originalBounds(g->GetBounds());
220
221 if (bounds != originalBounds) {
222 g->SetBounds(bounds);
223
224 if (invalidRect.IsNull())
226 else
228
229 if (originalBounds.TopLeft() != TPoint(0, 0))
231 }
232
233 y += cellSize.cy;
234 g = g->NextGadget();
235 }
236
237 x += cellSize.cx;
238 }
239 }
240 return invalidRect;
241}
242
243//
244/// Called when a change occurs in the size of the margins of the tool box or size
245/// of the gadgets, LayoutSession gets the desired size and moves the window to
246/// adjust to the desired change in size.
247///
248/// Assumes it is used as a client in a frame.
249//
250void
260
261} // OWL namespace
262/* ========================================================================== */
263
264
Definition of class TButtonGadget.
#define CHECK(condition)
Definition checks.h:239
Derived from TGadget, TButtonGadget represent buttons that you can click on or off.
Definition buttonga.h:65
TGadget is the base class for the following derived gadget classes:
Definition gadget.h:120
TPlacement
Enumerates the placement of a gadget.
Definition gadgetwi.h:47
Derived from TFont, TGadgetWindowFont is the default font used by TGadgetWindow.
Definition gadgetwi.h:92
Derived from TWindow, TGadgetWindow maintains a list of tiled gadgets for a window and lets you dynam...
Definition gadgetwi.h:122
void Insert(TGadget &, TPlacement=After, TGadget *sibling=nullptr) override
Inserts a gadget before or after a sibling gadget (TPlacement).
friend class TGadget
Definition gadgetwi.h:361
TMargins & GetMargins()
Definition gadgetwi.h:481
virtual void GetInnerRect(TRect &rect)
GetInnerRect computes the rectangle inside of the borders and margins of the gadget.
Definition gadgetwi.cpp:564
virtual void SetDirection(TTileDirection direction)
Sets the horizontal or vertical orientation of the gadgets.
Definition gadgetwi.cpp:449
virtual void LayoutSession()
LayoutSession is typically called when a change occurs in the size of the margins or gadgets,...
Definition gadgetwi.cpp:357
TTileDirection
Enumeration describing how gadgets should be laid out within the gadget window.
Definition gadgetwi.h:130
@ Horizontal
Arrange gadgets in a row.
Definition gadgetwi.h:131
ObjectWindows dynamic-link libraries (DLLs) construct an instance of TModule, which acts as an object...
Definition module.h:75
TPoint is a support class, derived from tagPOINT.
Definition geometry.h:87
TRect is a mathematical class derived from tagRect.
Definition geometry.h:308
The tagSIZE struct is defined as.
Definition geometry.h:234
TRect TileGadgets()
Tiles the gadgets in the direction requested (horizontal or vertical).
Definition toolbox.cpp:162
virtual void SetDirection(TTileDirection direction)
Sets the direction of the tiling–either horizontal or vertical.
Definition toolbox.cpp:65
TToolBox(TWindow *parent, int numColumns=2, int numRows=AS_MANY_AS_NEEDED, TTileDirection direction=Horizontal, TModule *module=0)
Constructs a TToolBox object with the specified number of columns and rows and tiling direction.
Definition toolbox.cpp:22
void GetDesiredSize(TSize &size)
Overrides TGadget's GetDesiredSize function and computes the size of the cell by calling GetMargins t...
Definition toolbox.cpp:120
void Insert(TGadget &gadget, TPlacement=After, TGadget *sibling=0)
Override Insert member function and tell the button to not notch its corners.
Definition toolbox.cpp:48
void LayoutSession()
Called when a change occurs in the size of the margins of the tool box or size of the gadgets,...
Definition toolbox.cpp:251
static const TUIMetric CyBorder
Definition uimetric.h:40
static const TUIMetric CxBorder
Definition uimetric.h:39
TWindow, derived from TEventHandler and TStreamableBase, provides window-specific behavior and encaps...
Definition window.h:414
bool SetWindowPos(HWND hWndInsertAfter, const TRect &rect, uint flags)
Changes the size of the window pointed to by rect.
Definition window.h:2809
const int AS_MANY_AS_NEEDED
Arranges its gadgets in a matrix.
Definition toolbox.h:40
Object Windows Library (OWLNext Core)
Definition animctrl.h:22
OWL_DIAGINFO
Definition animctrl.cpp:14
#define TYPESAFE_DOWNCAST(object, toClass)
Definition defs.h:269
Definition of class TToolBox.
Definition of TUIMetric, a UI metrics provider class.