dotgnu-pnet-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Dotgnu-pnet-commits] pnetlib/System.Windows.Forms GridLayout.cs, NONE,


From: Rhys Weatherley <address@hidden>
Subject: [Dotgnu-pnet-commits] pnetlib/System.Windows.Forms GridLayout.cs, NONE, 1.1 IRecommendedSize.cs, NONE, 1.1 FileDialog.cs, 1.3, 1.4 HBoxLayout.cs, 1.2, 1.3 VBoxLayout.cs, 1.1, 1.2
Date: Fri, 14 Nov 2003 07:30:20 +0000

Update of /cvsroot/dotgnu-pnet/pnetlib/System.Windows.Forms
In directory subversions:/tmp/cvs-serv18412/System.Windows.Forms

Modified Files:
        FileDialog.cs HBoxLayout.cs VBoxLayout.cs 
Added Files:
        GridLayout.cs IRecommendedSize.cs 
Log Message:


Add a "GridLayout" control to better lay out the bottom part of the file dialog.


--- NEW FILE: GridLayout.cs ---
/*
 * GridLayout.cs - Implementation of the
 *                      "System.Windows.Forms.GridLayout" 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 in a grid.
// It is intended for use inside dialog box controls like "FileDialog".

internal class GridLayout : Control, IRecommendedSize
{
        // Internal state.
        private int columns;
        private int rows;
        private int stretchColumn;
        private int stretchRow;
        private int margin;
        private int colSpacing;
        private int rowSpacing;
        private Control[] children;

        // Constructor.
        public GridLayout(int columns, int rows)
                        {
                                this.columns = columns;
                                this.rows = rows;
                                this.stretchColumn = columns - 1;
                                this.stretchRow = rows - 1;
                                this.margin = 4;
                                this.colSpacing = 4;
                                this.rowSpacing = 4;
                                this.children = new Control [columns * rows];
                        }

        // Get or set the column to be stretched.
        public int StretchColumn
                        {
                                get
                                {
                                        return stretchColumn;
                                }
                                set
                                {
                                        stretchColumn = value;
                                }
                        }

        // Get or set the row to be stretched.
        public int StretchRow
                        {
                                get
                                {
                                        return stretchRow;
                                }
                                set
                                {
                                        stretchRow = value;
                                }
                        }

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

        // Get or set the spacing between columns.
        public int ColumnSpacing
                        {
                                get
                                {
                                        return colSpacing;
                                }
                                set
                                {
                                        colSpacing = value;
                                }
                        }

        // Get or set the spacing between rows.
        public int RowSpacing
                        {
                                get
                                {
                                        return rowSpacing;
                                }
                                set
                                {
                                        rowSpacing = value;
                                }
                        }

        // Get the child control at a particular location.
        public Control GetControl(int column, int row)
                        {
                                return children[column * rows + row];
                        }

        // Set the child control at a particular location.  Locations can be 
blank.
        public void SetControl(int column, int row, Control child)
                        {
                                if(child.Parent != this)
                                {
                                        Controls.Add(child);
                                }
                                children[column * rows + row] = child;
                        }

        // Get the recommended client size for this control.
        public Size RecommendedSize
                        {
                                get
                                {
                                        int width = 0;
                                        int height = 0;
                                        int maxWidth;
                                        int maxHeight;
                                        int xextra, yextra;
                                        Size childSize;
                                        int x, y;
                                        Control child;

                                        // Scan the columns, looking for 
maximums.
                                        for(x = 0; x < columns; ++x)
                                        {
                                                maxWidth = 0;
                                                for(y = 0; y < rows; ++y)
                                                {
                                                        child = GetControl(x, 
y);
                                                        if(child != null && 
child.visible)
                                                        {
                                                                childSize =
                                                                        
HBoxLayout.GetRecommendedSize(child);
                                                                
if(childSize.Width > maxWidth)
                                                                {
                                                                        
maxWidth = childSize.Width;
                                                                }
                                                        }
                                                }
                                                width += maxWidth;
                                        }

                                        // Scan the rows, looking for maximums.
                                        for(y = 0; y < rows; ++y)
                                        {
                                                maxHeight = 0;
                                                for(x = 0; x < columns; ++x)
                                                {
                                                        child = GetControl(x, 
y);
                                                        if(child != null && 
child.visible)
                                                        {
                                                                childSize =
                                                                        
HBoxLayout.GetRecommendedSize(child);
                                                                
if(childSize.Height > maxHeight)
                                                                {
                                                                        
maxHeight = childSize.Height;
                                                                }
                                                        }
                                                }
                                                height += maxHeight;
                                        }

                                        // Add the margins and return the final 
size.
                                        xextra = margin * 2;
                                        if(columns >= 2)
                                        {
                                                xextra += (columns - 1) * 
colSpacing;
                                        }
                                        yextra = margin * 2;
                                        if(rows >= 2)
                                        {
                                                yextra += (rows - 1) * 
rowSpacing;
                                        }
                                        return new Size(width + xextra, height 
+ yextra);
                                }
                        }

        // Lay out the children in this control.
        protected override void OnLayout(LayoutEventArgs e)
                        {
                                int[] columnOffsets = new int [columns];
                                int[] columnWidths = new int [columns];
                                int[] rowOffsets = new int [rows];
                                int[] rowHeights = new int [rows];
                                int x, y;
                                Control child;
                                int posnLower, posnUpper;
                                Size childSize;

                                // Compute the offset and width of all columns.
                                posnLower = margin;
                                posnUpper = ClientSize.Width - margin;
                                for(x = 0; x < stretchColumn; ++x)
                                {
                                        columnOffsets[x] = posnLower;
                                        columnWidths[x] = 0;
                                        for(y = 0; y < rows; ++y)
                                        {
                                                child = GetControl(x, y);
                                                if(child != null && 
child.visible)
                                                {
                                                        childSize = 
HBoxLayout.GetRecommendedSize(child);
                                                        if(childSize.Width > 
columnWidths[x])
                                                        {
                                                                columnWidths[x] 
= childSize.Width;
                                                        }
                                                }
                                        }
                                        posnLower += columnWidths[x] + 
colSpacing;
                                }
                                for(x = columns - 1; x > stretchColumn; --x)
                                {
                                        columnWidths[x] = 0;
                                        for(y = 0; y < rows; ++y)
                                        {
                                                child = GetControl(x, y);
                                                if(child != null && 
child.visible)
                                                {
                                                        childSize = 
HBoxLayout.GetRecommendedSize(child);
                                                        if(childSize.Width > 
columnWidths[x])
                                                        {
                                                                columnWidths[x] 
= childSize.Width;
                                                        }
                                                }
                                        }
                                        posnUpper -= columnWidths[x];
                                        columnOffsets[x] = posnUpper;
                                        posnUpper -= colSpacing;
                                }
                                columnOffsets[stretchColumn] = posnLower;
                                columnWidths[stretchColumn] = posnUpper - 
posnLower;

                                // Compute the offset and height of all rows.
                                posnLower = margin;
                                posnUpper = ClientSize.Height - margin;
                                for(y = 0; y < stretchRow; ++y)
                                {
                                        rowOffsets[y] = posnLower;
                                        rowHeights[y] = 0;
                                        for(x = 0; x < columns; ++x)
                                        {
                                                child = GetControl(x, y);
                                                if(child != null && 
child.visible)
                                                {
                                                        childSize = 
HBoxLayout.GetRecommendedSize(child);
                                                        if(childSize.Height > 
rowHeights[y])
                                                        {
                                                                rowHeights[y] = 
childSize.Height;
                                                        }
                                                }
                                        }
                                        posnLower += rowHeights[y] + rowSpacing;
                                }
                                for(y = rows - 1; y > stretchRow; --y)
                                {
                                        rowHeights[y] = 0;
                                        for(x = 0; x < columns; ++x)
                                        {
                                                child = GetControl(x, y);
                                                if(child != null && 
child.visible)
                                                {
                                                        childSize = 
HBoxLayout.GetRecommendedSize(child);
                                                        if(childSize.Height > 
rowHeights[y])
                                                        {
                                                                rowHeights[y] = 
childSize.Height;
                                                        }
                                                }
                                        }
                                        posnUpper -= rowHeights[y];
                                        rowOffsets[y] = posnUpper;
                                        posnUpper -= rowSpacing;
                                }
                                rowOffsets[stretchRow] = posnLower;
                                rowHeights[stretchRow] = posnUpper - posnLower;

                                // Place the controls in their final locations.
                                for(y = 0; y < rows; ++y)
                                {
                                        for(x = 0; x < columns; ++x)
                                        {
                                                child = GetControl(x, y);
                                                if(child != null && 
child.visible)
                                                {
                                                        child.SetBounds
                                                                
(columnOffsets[x], rowOffsets[y],
                                                                 
columnWidths[x], rowHeights[y]);
                                                }
                                        }
                                }
                        }

}; // class GridLayout

}; // namespace System.Windows.Forms

Index: FileDialog.cs
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnetlib/System.Windows.Forms/FileDialog.cs,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** FileDialog.cs       14 Nov 2003 04:51:32 -0000      1.3
--- FileDialog.cs       14 Nov 2003 07:30:18 -0000      1.4
***************
*** 361,367 ****
                private FileDialog fileDialogParent;
                private VBoxLayout vbox;
!               private HBoxLayout hbox1;
!               private HBoxLayout hbox2;
!               private HBoxLayout hbox3;
                private ListBox listBox;
                private ComboBox directory;
--- 361,366 ----
                private FileDialog fileDialogParent;
                private VBoxLayout vbox;
!               private HBoxLayout hbox;
!               private GridLayout grid;
                private ListBox listBox;
                private ComboBox directory;
***************
*** 386,397 ****
                                        vbox = new VBoxLayout();
                                        vbox.Dock = DockStyle.Fill;
!                                       hbox1 = new HBoxLayout();
                                        listBox = new ListBox();
!                                       hbox2 = new HBoxLayout();
!                                       hbox3 = new HBoxLayout();
!                                       vbox.Controls.Add(hbox1);
                                        vbox.Controls.Add(listBox);
!                                       vbox.Controls.Add(hbox2);
!                                       vbox.Controls.Add(hbox3);
                                        vbox.StretchControl = listBox;
  
--- 385,395 ----
                                        vbox = new VBoxLayout();
                                        vbox.Dock = DockStyle.Fill;
!                                       hbox = new HBoxLayout();
                                        listBox = new ListBox();
!                                       grid = new GridLayout(3, 2);
!                                       grid.StretchColumn = 1;
!                                       vbox.Controls.Add(hbox);
                                        vbox.Controls.Add(listBox);
!                                       vbox.Controls.Add(grid);
                                        vbox.StretchControl = listBox;
  
***************
*** 401,411 ****
                                        upButton.FlatStyle = FlatStyle.Popup;
                                        upButton.Text = "Up";   // TODO: change 
to an image.
!                                       hbox1.StretchControl = directory;
!                                       hbox1.Controls.Add(directory);
!                                       hbox1.Controls.Add(upButton);
  
                                        // The second line is "listBox", 
already created above.
  
!                                       // Add the third line (file name 
fields).
                                        nameLabel = new Label();
                                        nameLabel.Text = "File name:";  // 
TODO: translate.
--- 399,409 ----
                                        upButton.FlatStyle = FlatStyle.Popup;
                                        upButton.Text = "Up";   // TODO: change 
to an image.
!                                       hbox.StretchControl = directory;
!                                       hbox.Controls.Add(directory);
!                                       hbox.Controls.Add(upButton);
  
                                        // The second line is "listBox", 
already created above.
  
!                                       // Add the third line (file name entry 
fields).
                                        nameLabel = new Label();
                                        nameLabel.Text = "File name:";  // 
TODO: translate.
***************
*** 413,422 ****
                                        okButton = new Button();
                                        okButton.Text = 
fileDialogParent.OkButtonName;
!                                       hbox2.StretchControl = name;
!                                       hbox2.Controls.Add(nameLabel);
!                                       hbox2.Controls.Add(name);
!                                       hbox2.Controls.Add(okButton);
  
!                                       // Add the fourth line (file type 
fields).
                                        typeLabel = new Label();
                                        typeLabel.Text = "Files of type:";      
// TODO: translate.
--- 411,419 ----
                                        okButton = new Button();
                                        okButton.Text = 
fileDialogParent.OkButtonName;
!                                       grid.SetControl(0, 0, nameLabel);
!                                       grid.SetControl(1, 0, name);
!                                       grid.SetControl(2, 0, okButton);
  
!                                       // Add the fourth line (file type entry 
fields).
                                        typeLabel = new Label();
                                        typeLabel.Text = "Files of type:";      
// TODO: translate.
***************
*** 424,431 ****
                                        cancelButton = new Button();
                                        cancelButton.Text = 
S._("SWF_MessageBox_Cancel", "Cancel");
!                                       hbox3.StretchControl = type;
!                                       hbox3.Controls.Add(typeLabel);
!                                       hbox3.Controls.Add(type);
!                                       hbox3.Controls.Add(cancelButton);
  
                                        // Add the top-level vbox to the dialog 
and set the size.
--- 421,427 ----
                                        cancelButton = new Button();
                                        cancelButton.Text = 
S._("SWF_MessageBox_Cancel", "Cancel");
!                                       grid.SetControl(0, 1, typeLabel);
!                                       grid.SetControl(1, 1, type);
!                                       grid.SetControl(2, 1, cancelButton);
  
                                        // Add the top-level vbox to the dialog 
and set the size.

Index: HBoxLayout.cs
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnetlib/System.Windows.Forms/HBoxLayout.cs,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** HBoxLayout.cs       14 Nov 2003 05:54:15 -0000      1.2
--- HBoxLayout.cs       14 Nov 2003 07:30:18 -0000      1.3
***************
*** 28,32 ****
  // It is intended for use inside dialog box controls like "MessageBox".
  
! internal class HBoxLayout : Control
  {
        // Internal state.
--- 28,32 ----
  // It is intended for use inside dialog box controls like "MessageBox".
  
! internal class HBoxLayout : Control, IRecommendedSize
  {
        // Internal state.
***************
*** 100,110 ****
        internal static Size GetRecommendedSize(Control control)
                        {
!                               if(control is HBoxLayout)
!                               {
!                                       return 
((HBoxLayout)control).RecommendedSize;
!                               }
!                               else if(control is VBoxLayout)
                                {
!                                       return 
((VBoxLayout)control).RecommendedSize;
                                }
                                else if(control is Label)
--- 100,106 ----
        internal static Size GetRecommendedSize(Control control)
                        {
!                               if(control is IRecommendedSize)
                                {
!                                       return 
((IRecommendedSize)control).RecommendedSize;
                                }
                                else if(control is Label)

Index: VBoxLayout.cs
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnetlib/System.Windows.Forms/VBoxLayout.cs,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** VBoxLayout.cs       14 Nov 2003 02:36:32 -0000      1.1
--- VBoxLayout.cs       14 Nov 2003 07:30:18 -0000      1.2
***************
*** 28,32 ****
  // It is intended for use inside dialog box controls like "MessageBox".
  
! internal class VBoxLayout : Control
  {
        // Internal state.
--- 28,32 ----
  // It is intended for use inside dialog box controls like "MessageBox".
  
! internal class VBoxLayout : Control, IRecommendedSize
  {
        // Internal state.

--- NEW FILE: IRecommendedSize.cs ---
/*
 * IRecommendedSize.cs - Implementation of the
 *                      "System.Windows.Forms.IRecommendedSize" 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;

internal interface IRecommendedSize
{
        // Get the recommended size of this control.
        Size RecommendedSize { get; }

}; // interface IRecommendedSize

}; // namespace System.Windows.Forms





reply via email to

[Prev in Thread] Current Thread [Next in Thread]