[Scopeapp-cvs]scopeapp/src/gnustep-compat GSHbox.h,NONE,1.1 GSHbox.m,NONE,1.1 GSTable.h,NONE,1.1 GST
Status: Alpha
Brought to you by:
narge
From: <sco...@li...> - 2002-08-31 03:39:20
|
Update of /cvsroot/scopeapp/scopeapp/src/gnustep-compat In directory usw-pr-cvs1:/tmp/cvs-serv19189 Added Files: GSHbox.h GSHbox.m GSTable.h GSTable.m GSVbox.h GSVbox.m Log Message: Added GSHbox, GSVbox and GSTable to sources for use on Mac OS X (makes window layout code much less ugly) --- NEW FILE: GSHbox.h --- /* GSHbox.h The GSHbox class (a GNU extension) Copyright (C) 1999 Free Software Foundation, Inc. Author: Nicola Pero <n....@mi...> Date: 1999 This file is part of the GNUstep GUI Library. This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library 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 Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #ifndef _GNUstep_H_GSHbox #define _GNUstep_H_GSHbox #include "GSTable.h" // // GSHbox inherits from GSTable the autosizing/autoresizing engine. // The only real difference between a GSHbox and a GSTable with 1 row // is that the GSHbox has a much simpler, easier and friendlier API. // // You shouldn't use GSTable methods with GSHbox (exception: methods // explicitly quoted in comments to this file as 'inherited from GSTable'). // If you need to do that, you should be using GSTable instead. // @interface GSHbox: GSTable { BOOL _haveViews; float _defaultMinXMargin; } // // Initizialing. // Always use init for GSHbox: other methods don't make sense. // Don't used GSTable methods. You do not need to specify // the number of views you plan to put in the box // when you initialize it. // So, the correct way to start a new GSHbox is simply: // // hbox = [GSHbox new]; // -(id) init; // // Setting Border. // // Use these if you want some spacing around the table. // Changing the border will update immediately the box. // The default border is zero. // // Inherited from GSTable Class: // To have the same border on the four sides use: //-(void) setBorder: (float)aBorder; // // To set borders in the horizontal or vertical direction, use: //-(void) setXBorder: (float)aBorder; //-(void) setYBorder: (float)aBorder; // // To specificy different borders, use: //-(void) setMinXBorder: (float)aBorder; //-(void) setMaxXBorder: (float)aBorder; //-(void) setMinYBorder: (float)aBorder; //-(void) setMaxYBorder: (float)aBorder; // // // Adding a View. // Use these methods to pack views in the GSHbox. // Don't use the corresponding methods of GSTable, which are far more general // and far more complicate. If you need to do that, use GSTable instead. // -(void) addView: (NSView *)aView; -(void) addView: (NSView *)aView enablingXResizing: (BOOL)aFlag; -(void) addView: (NSView *)aView withMinXMargin: (float)aMargin; -(void) addView: (NSView *)aView // enablingXResizing is YES if the {view and its margins} should be // resized when the GSHbox is resized in the horizontal direction. // FALSE does not resize it. Default is YES. enablingXResizing: (BOOL)aFlag // With a GSHbox, only one margin is set when you add views to the GSHbox: // the margin between each view and the preceding one. // Exception: the first view is special, and has no margin set (it has no // preceding view to be separated from). // Space above or below the view may result if the view is shorter, // in the vertical direction, than the other views in the GSHbox; // in that case the view is resized to fit vertically, // according to its autoresizingMask. // By changing the autoresizingMask you may decide whether the space // should go to the view or to its vertical margins; this for example // lets you center vertically or flush up/down your view. withMinXMargin: (float)aMargin; // // Adding a Separator. // -(void) addSeparator; -(void) addSeparatorWithMinXMargin: (float)aMargin; // // Setting Margins. // // Use only the following method to set a default margin. // The default margin set with the following method will be used // for all the views added after. // (Exception: the first view put in the box has no margins at all) // It will not affect already added views. // In a GSHbox, only one margin is used, the one between each view // and the preceding one. If what you want is space around the GSHbox, // you don't want a margin but a border; use setBorder: // (see above, "Setting Border"). // If you need more complicated margins/borders, use GSTable. -(void) setDefaultMinXMargin: (float)aMargin; // // Minimum Size. // // This returns the minimum size the GSHbox should be resized to. // Trying to resize the GSHbox below this size will only result in clipping // (ie, making it disappear) part of the GSHbox. // Inherited from GSTable Class: // -(NSSize) minimumSize; // // Resizing. // // If for any reason you need the GSHbox to revert to its minimum size, // invoke the following. // Inherited from GSTable Class: // -(void) sizeToFit; // // Getting Number of Views // // Return the number of views in the GSHbox (separators included). -(int) numberOfViews; @end #endif /* _GNUstep_H_GSHbox */ --- NEW FILE: GSHbox.m --- /** <title>GSHbox</title> <abstract>The GSHbox class (a GNU extension)</abstract> Copyright (C) 1999 Free Software Foundation, Inc. Author: Nicola Pero <n....@mi...> Date: 1999 This file is part of the GNUstep GUI Library. This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library 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 Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #import "GSHbox.h" // For the separator #import <AppKit/AppKit.h> @implementation GSHbox: GSTable // // Class methods // +(void) initialize { if (self == [GSHbox class]) [self setVersion: 1]; } // // Instance Methods // -(id) init { [super initWithNumberOfRows: 1 numberOfColumns: 1]; _haveViews = NO; _defaultMinXMargin = 0; return self; } -(void) dealloc { [super dealloc]; } // // Adding Views // -(void) addView: (NSView *)aView { [self addView: aView enablingXResizing: YES withMinXMargin: _defaultMinXMargin]; } -(void) addView: (NSView *)aView enablingXResizing: (BOOL)aFlag { [self addView: aView enablingXResizing: aFlag withMinXMargin: _defaultMinXMargin]; } -(void) addView: (NSView *)aView withMinXMargin: (float) aMargin { [self addView: aView enablingXResizing: YES withMinXMargin: aMargin]; } -(void) addView: (NSView *)aView enablingXResizing: (BOOL)aFlag withMinXMargin: (float)aMargin { if (_haveViews) { int entries = _numberOfColumns; [super addColumn]; [super setXResizingEnabled: aFlag forColumn: entries]; [super putView: aView atRow: 0 column: entries withMinXMargin: aMargin maxXMargin: 0 minYMargin: 0 maxYMargin: 0]; } else // !_haveViews { [super setXResizingEnabled: aFlag forColumn: 0]; [super putView: aView atRow: 0 column: 0 withMinXMargin: 0 maxXMargin: 0 minYMargin: 0 maxYMargin: 0]; _haveViews = YES; } } // // Adding a Separator // -(void) addSeparator { [self addSeparatorWithMinXMargin: _defaultMinXMargin]; } -(void) addSeparatorWithMinXMargin: (float)aMargin { NSBox *separator; separator = [[NSBox alloc] initWithFrame: NSMakeRect (0, 0, 2, 2)]; [separator setAutoresizingMask: (NSViewMinXMargin | NSViewMaxXMargin | NSViewHeightSizable)]; [separator setTitlePosition: NSNoTitle]; [separator setBorderType: NSGrooveBorder]; [self addView: separator enablingXResizing: NO withMinXMargin: aMargin]; [separator release]; } // // Setting Margins // -(void) setDefaultMinXMargin: (float)aMargin { _defaultMinXMargin = aMargin; } // // Getting the number of Entries // -(int) numberOfViews { if (_haveViews) return _numberOfColumns; else return 0; } // // NSCoding protocol // -(void) encodeWithCoder: (NSCoder*)aCoder { [super encodeWithCoder: aCoder]; [aCoder encodeValueOfObjCType: @encode(BOOL) at: &_haveViews]; [aCoder encodeValueOfObjCType: @encode(float) at: &_defaultMinXMargin]; } -(id) initWithCoder: (NSCoder*)aDecoder { [super initWithCoder: aDecoder]; [aDecoder decodeValueOfObjCType: @encode(BOOL) at: &_haveViews]; [aDecoder decodeValueOfObjCType: @encode(float) at: &_defaultMinXMargin]; return self; } @end --- NEW FILE: GSTable.h --- /* GSTable.h The GSTable class (a GNU extension) Copyright (C) 1999 Free Software Foundation, Inc. Author: Nicola Pero <n....@mi...> Date: 1999 This file is part of the GNUstep GUI Library. This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library 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 Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #ifndef _GNUstep_H_GSTable #define _GNUstep_H_GSTable #include <AppKit/AppKit.h> @interface GSTable: NSView { int _numberOfRows; int _numberOfColumns; // Border around the table. float _minXBorder; float _maxXBorder; float _minYBorder; float _maxYBorder; // We control the NSView inserted in the GSTable (which we call // the prisoners) by enclosing them in jails. // Each prisoner is enclosed in a jail (which is a subview under // our control). // Each prisoner is allowed to resize only inside its jail. NSView **_jails; // YES if the column/row should be expanded/reduced when the size // of the GSTable is expanded/reduced (this BOOL is otherwhere // called X/Y Resizing Enabled). BOOL *_expandColumn; BOOL *_expandRow; // Cache the total number of rows/columns which have expand set to YES int _expandingColumnNumber; int _expandingRowNumber; // Dimension of each column/row float *_columnDimension; float *_rowDimension; // Origin of each column/row float *_columnXOrigin; float *_rowYOrigin; // Minimum dimension each row/column is allowed to have // (which is the size the jail had when first created). float *_minColumnDimension; float *_minRowDimension; // Cache the minimum size the GSTable should be resized to. NSSize _minimumSize; // YES if there is a prisoner in that GSTable position. // (to avoid creating a jail if there is no prisoner to control). BOOL *_havePrisoner; } // // Initizialing. // -(id) initWithNumberOfRows: (int)rows numberOfColumns: (int)columns; // Initialize with a default of 2 columns and 2 rows. -(id) init; // // Setting Border Dimension. // Border is space around the table. // -(void) setBorder: (float)aBorder; -(void) setXBorder: (float)aBorder; -(void) setYBorder: (float)aBorder; -(void) setMinXBorder: (float)aBorder; -(void) setMaxXBorder: (float)aBorder; -(void) setMinYBorder: (float)aBorder; -(void) setMaxYBorder: (float)aBorder; // // Adding a View. // Use these methods to put views in the GSTable. // -(void) putView: (NSView *)aView atRow: (int)row column: (int)column; -(void) putView: (NSView *)aView atRow: (int)row column: (int)column withMargins: (float)margins; -(void) putView: (NSView *)aView atRow: (int)row column: (int)column withXMargins: (float)xMargins yMargins: (float)yMargins; -(void) putView: (NSView *)aView atRow: (int)row column: (int)column // Each view which is added to the GSTable can have some margins // set. The GSTable treats the view and its margins as a whole. // They are given (as a whole) some space, which is reduced or // increased (but only if X or Y Resizing is Enabled for the column // or the row in which the view resides) when the GSTable is // resized. When this happens, the space is added (or subtracted) // to the view or to the margins according to the autoResizeMask of // the view. withMinXMargin: (float)minXMargin // Left Margin maxXMargin: (float)maxXMargin // Right Margin minYMargin: (float)minYMargin // Lower Margin (Upper if flipped) maxYMargin: (float)maxYMargin; // Upper Margin (Lower if flipped) // // Minimum Size. // This returns the minimum size the GSTable should be resized to. // Trying to resize the GSTable below this size will only result in clipping // (ie, making it disappear) part of the GSTable. // -(NSSize) minimumSize; // // Resizing. // If for any reason you need the GSTable to be redrawn (with minimum size), // invoke the following. -(void) sizeToFit; // // Setting Row and Column Expand Flag // When the GSTable is resized, the extra space is equally divided // between the Rows and Columns which have X/Y Resizing Enabled. // -(void) setXResizingEnabled: (BOOL)aFlag forColumn: (int)aColumn; -(BOOL) isXResizingEnabledForColumn: (int)aColumn; -(void) setYResizingEnabled: (BOOL)aFlag forRow: (int)aRow; -(BOOL) isYResizingEnabledForRow: (int)aRow; // // Adding Rows and Columns // These should be used to add more rows and columns to the GSTable. // Of course it is faster to create a GSTable with the right number of rows // and columns from the beginning. // -(void) addRow; // TODO: -(void) insertRow: (int)row; // TODO: -(void) removeRow: (int)row; -(void) addColumn; // TODO: -(void) insertColumn: (int)column; // TODO: -(void) removeColumn: (int)column; // // Getting Row and Column Number // -(int) numberOfRows; -(int) numberOfColumns; @end #endif /* _GNUstep_H_GSTable */ --- NEW FILE: GSTable.m --- /** <titlt>GSTable.m</title> <abstract>The GSTable class (a GNU extension)</abstract> Copyright (C) 1999 Free Software Foundation, Inc. Author: Nicola Pero <n....@mi...> Date: 1999 This file is part of the GNUstep GUI Library. This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library 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 [...986 lines suppressed...] int i,j; for (j = 0; j < _numberOfColumns; j++) for (i = 0; i < _numberOfRows; i++) { if (_havePrisoner[(i * _numberOfColumns) + j]) { [_jails[(i * _numberOfColumns) + j] setFrameOrigin: NSMakePoint (_columnXOrigin[j], _rowYOrigin[i])]; [_jails[(i * _numberOfColumns) + j] setFrameSize: NSMakeSize (_columnDimension[j], _rowDimension[i])]; } } } @end --- NEW FILE: GSVbox.h --- /* GSVbox.h The GSVbox class (a GNU extension) Copyright (C) 1999 Free Software Foundation, Inc. Author: Nicola Pero <n....@mi...> Date: 1999 This file is part of the GNUstep GUI Library. This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library 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 Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ // // See GSHbox.h for comments. // This file is generated from GSHbox.h by removing comments // and substituting all occurrences of "hbox" with "vbox", // "XResizing" with "YResizing", "MinXMargin" with "MinYMargin". // #ifndef _GNUstep_H_GSVbox #define _GNUstep_H_GSVbox #include "GSTable.h" @interface GSVbox: GSTable { BOOL _haveViews; float _defaultMinYMargin; } // // Initizialing. // -(id) init; // // Setting Border. // // Inherited from GSTable Class: //-(void) setBorder: (float)aBorder; //-(void) setXBorder: (float)aBorder; //-(void) setYBorder: (float)aBorder; //-(void) setMinXBorder: (float)aBorder; //-(void) setMaxXBorder: (float)aBorder; //-(void) setMinYBorder: (float)aBorder; //-(void) setMaxYBorder: (float)aBorder; // // Adding a View. // -(void) addView: (NSView *)aView; -(void) addView: (NSView *)aView enablingYResizing: (BOOL)aFlag; -(void) addView: (NSView *)aView withMinYMargin: (float)aMargin; -(void) addView: (NSView *)aView enablingYResizing: (BOOL)aFlag withMinYMargin: (float)aMargin; // // Adding a Separator. // -(void) addSeparator; -(void) addSeparatorWithMinYMargin: (float)aMargin; // // Setting Margins. // -(void) setDefaultMinYMargin: (float)aMargin; // // Minimum Size. // // Inherited from GSTable Class: // -(NSSize) minimumSize; // // Resizing. // // Inherited from GSTable Class: // -(void) sizeToFit; // // Getting Number of Views // -(int) numberOfViews; @end #endif /* _GNUstep_H_GSVbox */ --- NEW FILE: GSVbox.m --- /** <title>GSVbox</title> <abstract>The GSVbox class (a GNU extension)</abstract> Copyright (C) 1999 Free Software Foundation, Inc. Author: Nicola Pero <n....@mi...> Date: 1999 This file is part of the GNUstep GUI Library. This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library 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 Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ // See GSHbox.m for comments // This file is derived from GSVbox.m #import "GSVbox.h" #import <AppKit/AppKit.h> @implementation GSVbox: GSTable // // Class methods // +(void) initialize { if (self == [GSVbox class]) [self setVersion: 1]; } // // Instance Methods // -(id) init { [super initWithNumberOfRows: 1 numberOfColumns: 1]; _haveViews = NO; _defaultMinYMargin = 0; return self; } -(void) dealloc { [super dealloc]; } // // Adding Views // -(void) addView: (NSView *)aView { [self addView: aView enablingYResizing: YES withMinYMargin: _defaultMinYMargin]; } -(void) addView: (NSView *)aView enablingYResizing: (BOOL)aFlag { [self addView: aView enablingYResizing: aFlag withMinYMargin: _defaultMinYMargin]; } -(void) addView: (NSView *)aView withMinYMargin: (float) aMargin { [self addView: aView enablingYResizing: YES withMinYMargin: aMargin]; } -(void) addView: (NSView *)aView enablingYResizing: (BOOL)aFlag withMinYMargin: (float)aMargin { if (_haveViews) { int entries = _numberOfRows; [super addRow]; [super setYResizingEnabled: aFlag forRow: entries]; [super putView: aView atRow: entries column: 0 withMinXMargin: 0 maxXMargin: 0 minYMargin: aMargin maxYMargin: 0]; } else // !_haveViews { [super setYResizingEnabled: aFlag forRow: 0]; [super putView: aView atRow: 0 column: 0 withMinXMargin: 0 maxXMargin: 0 minYMargin: 0 maxYMargin: 0]; _haveViews = YES; } } // // Adding a Separator // -(void) addSeparator { [self addSeparatorWithMinYMargin: _defaultMinYMargin]; } -(void) addSeparatorWithMinYMargin: (float)aMargin { NSBox *separator; separator = [[NSBox alloc] initWithFrame: NSMakeRect (0, 0, 2, 2)]; [separator setAutoresizingMask: (NSViewWidthSizable | NSViewMinYMargin | NSViewMaxYMargin)]; [separator setTitlePosition: NSNoTitle]; [separator setBorderType: NSGrooveBorder]; [self addView: separator enablingYResizing: NO withMinYMargin: aMargin]; [separator release]; } // // Setting Margins // -(void) setDefaultMinYMargin: (float)aMargin { _defaultMinYMargin = aMargin; } // // Getting the number of Entries // -(int) numberOfViews { if (_haveViews) return _numberOfRows; else return 0; } // // NSCoding protocol // -(void) encodeWithCoder: (NSCoder*)aCoder { [super encodeWithCoder: aCoder]; [aCoder encodeValueOfObjCType: @encode(BOOL) at: &_haveViews]; [aCoder encodeValueOfObjCType: @encode(float) at: &_defaultMinYMargin]; } -(id) initWithCoder: (NSCoder*)aDecoder { [super initWithCoder: aDecoder]; [aDecoder decodeValueOfObjCType: @encode(BOOL) at: &_haveViews]; [aDecoder decodeValueOfObjCType: @encode(float) at: &_defaultMinYMargin]; return self; } @end |