A
download VBoxLayout.cs
Language: C#
License: GPL
Copyright: (C) 2003 Southern Storm Software, Pty Ltd.
LOC: 238
Project Info
DotGNU Portable.NET(dotgnu-pnet)
Server: Savannah GNU
Type: cvs
...etlib\System.Windows.Forms\
   .cvsignore
   AccessibleEvents.cs
   AccessibleNavigation.cs
   AccessibleObject.cs
   AccessibleRole.cs
   AccessibleSelection.cs
   AccessibleStates.cs
   ActivationGesture.cs
   ActivationState.cs
   AmbientProperties.cs
   AnchorStyles.cs
   Appearance.cs
   Application.cs
   ApplicationContext.cs
   ArrangeDirection.cs
   ArrangeStartingPosition.cs
   BaseCollection.cs
   Binding.cs
   BindingContext.cs
   BindingManagerBase.cs
   BindingMemberInfo.cs
   BindingsCollection.cs
   BootMode.cs
   Border3DSide.cs
   Border3DStyle.cs
   BorderStyle.cs
   BoundsSpecified.cs
   Button.cs
   ButtonBase.cs
   ButtonBorderStyle.cs
   ButtonBoxLayout.cs
   ButtonState.cs
   CancelEventArgs.cs
   CancelEventHandler.cs
   CaptionButton.cs
   CharacterCasing.cs
   CheckBox.cs
   CheckListBox.cs
   CheckState.cs
   Clipboard.cs
   ColorDepth.cs
   ColorDialog.cs
   ColumnClickEventArgs.cs
   ColumnClickEventHandler.cs
   ColumnHeader.cs
   ColumnHeaderStyle.cs
   ComboBox.cs
   ComboBoxStyle.cs
   CommonDialog.cs
   ContainerControl.cs
   ...entsResizedEventArgs.cs
   ...sResizedEventHandler.cs
   ContextMenu.cs
   Control.cs
   ...olBindingsCollection.cs
   ControlEventArgs.cs
   ControlEventHandler.cs
   ControlPaint.cs
   ControlStyles.cs
   ControlToolkitMgr.cs
   ConvertEventArgs.cs
   ConvertEventHandler.cs
   CreateParams.cs
   CurrencyManager.cs
   Cursor.cs
   CursorConverter.cs
   Cursors.cs
   DataFormats.cs
   DataGrid.cs
   DataGridBoolColumn.cs
   DataGridCell.cs
   DataGridColumnStyle.cs
   DataGridLineStyle.cs
   ...ParentRowsLabelStyle.cs
   ...mnWidthTypeConverter.cs
   DataGridTableStyle.cs
   DataGridTextBox.cs
   DataGridTextBoxColumn.cs
   DataObject.cs
   DateBoldEventArgs.cs
   DateBoldEventHandler.cs
   DateRangeEventArgs.cs
   DateRangeEventHandler.cs
   DateTimePickerFormat.cs
   Day.cs
   DialogResult.cs
   DockStyle.cs
   DomainUpDown.cs
   DragAction.cs
   DragDropEffects.cs
   DragEventArgs.cs
   DragEventHandler.cs
   DrawItemEventArgs.cs
   DrawItemEventHandler.cs
   DrawItemState.cs
   DrawMode.cs
   ErrorBlinkStyle.cs
   ErrorIconAlignment.cs
   ErrorProvider.cs
   EventId.cs
   FeatureSupport.cs
   FileDialog.cs
   FlatStyle.cs
   FolderBrowserDialog.cs
   FontDialog.cs
   Form.cs
   FormBorderStyle.cs
   Forms.build
   FormStartPosition.cs
   FormWindowState.cs
   FrameStyle.cs
   GiveFeedbackEventArgs.cs
   ...FeedbackEventHandler.cs
   ...lumnStylesCollection.cs
   GridItem.cs
   GridItemCollection.cs
   GridItemType.cs
   GridLayout.cs
   ...ableStylesCollection.cs
   GroupBox.cs
   HBoxLayout.cs
   Help.cs
   HelpEventArgs.cs
   HelpEventHandler.cs
   HelpNavigator.cs
   HelpProvider.cs
   HorizontalAlignment.cs
   HScrollBar.cs
   IBindableComponent.cs
   IButtonControl.cs
   ICommandExecutor.cs
   ...ponentEditorPageSite.cs
   IContainerControl.cs
   ...gNotificationService.cs
   IDataGridEditingService.cs
   IDataObject.cs
   IDropTarget.cs
   IFeatureSupport.cs
   IFileReaderService.cs
   ImageIndexConverter.cs
   ImageList.cs
   ImageListStreamer.cs
   ImeMode.cs
   IMessageFilter.cs
   InputLanguage.cs
   ...uageChangedEventArgs.cs
   ...eChangedEventHandler.cs
   ...ageChangingEventArgs.cs
   ...ChangingEventHandler.cs
   InvalidateEventArgs.cs
   InvalidateEventHandler.cs
   IRecommendedSize.cs
   ItemActivation.cs
   ItemBoundsPortion.cs
   ItemChangedEventArgs.cs
   ItemChangedEventHandler.cs
   ItemCheckEventArgs.cs
   ItemCheckEventHandler.cs
   ItemDragEventArgs.cs
   ItemDragEventHandler.cs
   IWin32Window.cs
   IWindowTarget.cs
   KeyEventArgs.cs
   KeyEventHandler.cs
   KeyPressEventArgs.cs
   KeyPressEventHandler.cs
   Keys.cs
   Label.cs
   LabelEditEventArgs.cs
   LabelEditEventHandler.cs
   LayoutEventArgs.cs
   LayoutEventHandler.cs
   LeftRightAlignment.cs
   LinkArea.cs
   LinkBehavior.cs
   LinkClickedEventArgs.cs
   LinkClickedEventHandler.cs
   LinkLabel.cs
   ...LinkClickedEventArgs.cs
   ...kClickedEventHandler.cs
   LinkState.cs
   ListBindingConverter.cs
   ListBox.cs
   ListControl.cs
   ListView.cs
   ListViewAlignment.cs
   ListViewItem.cs
   ListViewItemConverter.cs
   ...ViewSubItemConverter.cs
   MainMenu.cs
   Makefile.am
   MdiClient.cs
   MdiLayout.cs
   MeasureItemEventArgs.cs
   MeasureItemEventHandler.cs
   Menu.cs
   MenuGlyph.cs
   MenuItem.cs
   MenuMerge.cs
   Message.cs
   MessageBox.cs
   MessageBoxButtons.cs
   MessageBoxDefaultButton.cs
   MessageBoxIcon.cs
   MessageBoxOptions.cs
   MethodInvoker.cs
   MonthCalendar.cs
   MouseButtons.cs
   MouseEventArgs.cs
   MouseEventHandler.cs
   NativeWindow.cs
   NavigateEventArgs.cs
   NavigateEventHandler.cs
   NodeLabelEditEventArgs.cs
   ...abelEditEventHandler.cs
   NotifyIcon.cs
   NumericUpDown.cs
   OpenFileDialog.cs
   Orientation.cs
   OSFeature.cs
   OwnerDrawPropertyBag.cs
   PaintEventArgs.cs
   PaintEventHandler.cs
   Panel.cs
   PictureBox.cs
   PictureBoxSizeMode.cs
   PopupControl.cs
   PrintDialog.cs
   ProgressBar.cs
   PropertySort.cs
   ...yTabChangedEventArgs.cs
   ...bChangedEventHandler.cs
   ...alueChangedEventArgs.cs
   ...eChangedEventHandler.cs
   ...ccessibilityHelpArgs.cs
   ...lityHelpEventHandler.cs
   ...ontinueDragEventArgs.cs
   ...inueDragEventHandler.cs
   RadioButton.cs
   RichTextBox.cs
   RichTextBoxFinds.cs
   RichTextBoxScrollBars.cs
   ...oxSelectionAttribute.cs
   ...extBoxSelectionTypes.cs
   RichTextBoxStreamType.cs
   ...tBoxWordPunctuations.cs
   RightToLeft.cs
   S.cs
   SaveFileDialog.cs
   Screen.cs
   ScrollableControl.cs
   ScrollBar.cs
   ScrollBars.cs
   ScrollButton.cs
   ScrollEventArgs.cs
   ScrollEventHandler.cs
   ScrollEventType.cs
   SecurityIDType.cs
   ...ItemChangedEventArgs.cs
   ...mChangedEventHandler.cs
   SelectionMode.cs
   Shortcut.cs
   SizeGripStyle.cs
   SortOrder.cs
   Splitter.cs
   SplitterEventArgs.cs
   SplitterEventHandler.cs
   StatusBar.cs
   ...BarDrawItemEventArgs.cs
   ...DrawItemEventHandler.cs
   StatusBarPanel.cs
   StatusBarPanelAutoSize.cs
   ...sBarPanelBorderStyle.cs
   ...rPanelClickEventArgs.cs
   ...nelClickEventHandler.cs
   StatusBarPanelStyle.cs
   StructFormat.cs
   SystemInformation.cs
   TabAlignment.cs
   TabAppearance.cs
   TabControl.cs
   TabDrawMode.cs
   TabPage.cs
   TabSizeMode.cs
   TextBox.cs
   TextBoxBase.cs
   TickStyle.cs
   Timer.cs
   TODOAttribute.cs
   ToolBar.cs
   ToolBarAppearance.cs
   ToolBarButton.cs
   ...ButtonClickEventArgs.cs
   ...tonClickEventHandler.cs
   ToolBarButtonStyle.cs
   ToolBarTextAlign.cs
   ToolTip.cs
   TrackBar.cs
   TreeNode.cs
   TreeNodeCollection.cs
   TreeView.cs
   TreeViewAction.cs
   TreeViewCancelEventArgs.cs
   ...ewCancelEventHandler.cs
   TreeViewEventArgs.cs
   TreeViewEventHandler.cs
   TriangleDirection.cs
   UICues.cs
   UICuesEventArgs.cs
   UICuesEventHandler.cs
   UpDownBase.cs
   UpDownEventArgs.cs
   UpDownEventHandler.cs
   UserControl.cs
   VBoxLayout.cs
   View.cs
   VScrollBar.cs
   Win32Constants.cs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
/*
 * VBoxLayout.cs - Implementation of the
 *			"System.Windows.Forms.VBoxLayout" class.
 *
 * Copyright (C) 2003  Southern Storm Software, Pty Ltd.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

namespace System.Windows.Forms
{

using System.Drawing;

// This is a special-purpose control that lays out its children vertically.
// It is intended for use inside dialog box controls like "MessageBox".

internal class VBoxLayout : Control, IRecommendedSize
{
	// Internal state.
	private bool uniformSize;
	private Control stretchControl;
	private int margin, spacing;

	// Constructor.
	public VBoxLayout()
			{
				uniformSize = false;
				stretchControl = null;
				margin = 4;
				spacing = 4;
				TabStop = false;
			}

	// Get or set whether all controls will have a uniform size.
	public bool UniformSize
			{
				get
				{
					return uniformSize;
				}
				set
				{
					uniformSize = value;
				}
			}

	// Get or set the control to be stretched in non-uniform layouts.
	// If this is not set, then the last control will be stretched.
	public Control StretchControl
			{
				get
				{
					return stretchControl;
				}
				set
				{
					stretchControl = value;
				}
			}

	// Get or set the margin.
	public int Margin
			{
				get
				{
					return margin;
				}
				set
				{
					margin = value;
				}
			}

	// Get or set the spacing between items.
	public int Spacing
			{
				get
				{
					return spacing;
				}
				set
				{
					spacing = value;
				}
			}

	// Get the recommended client size for this control.
	public Size RecommendedSize
			{
				get
				{
					int height = 0;
					int maxWidth = 0;
					int maxHeight = 0;
					int numVisible = 0;
					int xextra, yextra;
					Size childSize;
					foreach(Control child in Controls)
					{
						if(child.visible)
						{
							childSize = HBoxLayout.GetRecommendedSize(child);
							height += childSize.Height;
							if(childSize.Width > maxWidth)
							{
								maxWidth = childSize.Width;
							}
							if(childSize.Height > maxHeight)
							{
								maxHeight = childSize.Height;
							}
							++numVisible;
						}
					}
					xextra = margin * 2;
					yextra = margin * 2;
					if(numVisible >= 2)
					{
						yextra += (numVisible - 1) * spacing;
					}
					if(uniformSize)
					{
						return new Size
							(maxWidth + xextra,
							 maxHeight * numVisible + yextra);
					}
					else
					{
						return new Size
							(maxWidth + xextra, height + yextra);
					}
				}
			}

	// Lay out the children in this control uniformly.
	private void UniformLayout()
			{
				int numVisible = 0;
				int index;
				int width, height;

				// Count the number of visible child controls.
				foreach(Control child1 in Controls)
				{
					if(child1.visible)
					{
						++numVisible;
					}
				}
				if(numVisible == 0)
				{
					return;
				}

				// Determine the optimal width and height.
				width = ClientSize.Width - margin * 2;
				height = ClientSize.Height - margin * 2;
				height -= (numVisible - 1) * spacing;
				height = height / numVisible;

				// Lay out the visible controls.
				index = 0;
				foreach(Control child in Controls)
				{
					if(!(child.visible))
					{
						continue;
					}
					if(index == (numVisible - 1) && margin == 0)
					{
						// Lay out the final control to the full width,
						// to undo the effect of slight rounding errors.
						child.SetBounds
							(0, index * (height + spacing), width,
							 ClientSize.Height - index * (height + spacing));
					}
					else
					{
						// Lay out some control other than the last.
						child.SetBounds
							(margin, margin + index * (height + spacing),
							 width, height);
					}
					++index;
				}
			}

	// Lay out the children in this control non-uniformly.
	private void NonUniformLayout()
			{
				ControlCollection controls = Controls;
				int count, index;
				Control stretch;
				Control child;
				int posn, posn2;
				Size clientSize;
				Size childSize;

				// Find the control to be stretched.
				if(stretchControl != null && stretchControl.visible)
				{
					stretch = stretchControl;
				}
				else
				{
					stretch = null;
					foreach(Control child1 in controls)
					{
						if(child1.visible)
						{
							stretch = child1;
						}
					}
					if(stretch == null)
					{
						// Abort layout - none of the children are visible.
						return;
					}
				}

				// Lay out the children before the stretched control.
				count = controls.Count;
				index = 0;
				posn = margin;
				clientSize = ClientSize;
				while(index < count)
				{
					child = controls[index];
					if(child == stretch)
					{
						break;
					}
					if(child.visible)
					{
						childSize = HBoxLayout.GetRecommendedSize(child);
						child.SetBounds
							(margin, posn, clientSize.Width - 2 * margin,
							 childSize.Height);
						posn += childSize.Height + spacing;
					}
					++index;
				}

				// Lay out the children after the stretched control.
				posn2 = clientSize.Height - margin;
				index = count - 1;
				while(index >= 0)
				{
					child = controls[index];
					if(child == stretch)
					{
						break;
					}
					if(child.visible)
					{
						childSize = HBoxLayout.GetRecommendedSize(child);
						posn2 -= childSize.Height;
						child.SetBounds
							(margin, posn2, clientSize.Width - 2 * margin,
							 childSize.Height);
						posn2 -= spacing;
					}
					--index;
				}

				// Lay out the stretched control.
				if(posn2 < posn)
				{
					posn2 = posn;
				}
				stretch.SetBounds
					(margin, posn, clientSize.Width - 2 * margin,
					 posn2 - posn);
			}

	// Lay out the children in this control.
	protected override void OnLayout(LayoutEventArgs e)
			{
				if(uniformSize)
				{
					UniformLayout();
				}
				else
				{
					NonUniformLayout();
				}
			}

}; // class VBoxLayout

}; // namespace System.Windows.Forms

About Koders | Resources | Downloads | Support | Black Duck | Terms of Service | DMCA | Privacy Policy | Contact Us