Extension of drawing functions and corrections for combo box.

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@19430 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Fred Kiefer 2004-05-31 19:24:10 +00:00
parent ce40c0e08b
commit a86cde69a9
5 changed files with 122 additions and 69 deletions

View file

@ -1,3 +1,19 @@
2004-05-31 Fred Kiefer <FredKiefer@gmx.de>
* Headers/Additions/GNUstepGUI/GSDrawFunctions.h:
* Source/GSDrawFunctions.m: (-drawDarkButton::) New
method. Changed all methods to return the interior rectangle.
based on patch by Nicolas Roard <nicolas@roard.com>.
* Source/NSComboBoxCell.m: (-_selectCompleted) new method to
handle completion of selection in data source case correctly.
(-popUpForComboBoxCell:) use this method and also clear
selection at the end, so a new popup starts without selection.
(-selectItemAtIndex:) simplified and return when invalid
index is given. (-_loadButtonCell) always use image name
"NSComboArrow" and removed force arrow variable.
* Images/nsmapping.strings: mapping "NSComboArrow" to
"common_ComboBoxEllipsis".
2004-05-29 Quentin Mathe <qmathe@lub-internet.fr>
* Source/NSComboBoxCell.m: Fixed problems related to decoding an encoded

View file

@ -35,13 +35,14 @@
@interface GSDrawFunctions : NSObject
+ (void) drawButton: (NSRect)border : (NSRect)clip;
+ (void) drawDarkBezel: (NSRect)border : (NSRect)clip;
+ (void) drawLightBezel: (NSRect) border : (NSRect)clip;
+ (void) drawGrayBezel: (NSRect)border : (NSRect)clip;
+ (void) drawWhiteBezel: (NSRect) border : (NSRect)clip;
+ (void) drawGroove: (NSRect)border : (NSRect)clip;
+ (void) drawFramePhoto: (NSRect)border : (NSRect)clip;
+ (NSRect) drawButton: (NSRect)border : (NSRect)clip;
+ (NSRect) drawDarkButton: (NSRect)border : (NSRect)clip;
+ (NSRect) drawDarkBezel: (NSRect)border : (NSRect)clip;
+ (NSRect) drawLightBezel: (NSRect)border : (NSRect)clip;
+ (NSRect) drawGrayBezel: (NSRect)border : (NSRect)clip;
+ (NSRect) drawWhiteBezel: (NSRect)border : (NSRect)clip;
+ (NSRect) drawGroove: (NSRect)border : (NSRect)clip;
+ (NSRect) drawFramePhoto: (NSRect)border : (NSRect)clip;
+ (NSRect) drawGradientBorder: (NSGradientType)gradientType
inRect: (NSRect)border

View file

@ -9,4 +9,5 @@ NSHighlightedRadioButton = common_RadioOn;
AppleMenuImage = GNUstepMenuImage;
NSMenuCheckmark = common_2DCheckMark;
NSMenuArrow = common_3DArrowRight;
NSMenuMixedState = common_2DDash;
NSMenuMixedState = common_2DDash;
NSComboArrow = common_ComboBoxEllipsis;

View file

@ -51,7 +51,7 @@
@implementation GSDrawFunctions
/** Draw a button border */
+ (void) drawButton: (NSRect)border : (NSRect)clip
+ (NSRect) drawButton: (NSRect)border : (NSRect)clip
{
NSRectEdge up_sides[] = {NSMaxXEdge, NSMinYEdge,
NSMinXEdge, NSMaxYEdge,
@ -68,16 +68,38 @@
if ([[NSView focusView] isFlipped] == YES)
{
NSDrawColorTiledRects(border, clip, dn_sides, colors, 6);
return NSDrawColorTiledRects(border, clip, dn_sides, colors, 6);
}
else
{
NSDrawColorTiledRects(border, clip, up_sides, colors, 6);
return NSDrawColorTiledRects(border, clip, up_sides, colors, 6);
}
}
/** Draw a "dark" button border (used in tableviews) */
+ (NSRect) drawDarkButton: (NSRect)border : (NSRect)clip
{
NSRectEdge up_sides[] = {NSMaxXEdge, NSMinYEdge,
NSMinXEdge, NSMaxYEdge};
NSRectEdge dn_sides[] = {NSMaxXEdge, NSMaxYEdge,
NSMinXEdge, NSMinYEdge};
// These names are role names not the actual colours
NSColor *black = [NSColor controlDarkShadowColor];
NSColor *white = [NSColor controlHighlightColor];
NSColor *colors[] = {black, black, white, white};
if ([[NSView focusView] isFlipped] == YES)
{
return NSDrawColorTiledRects(border, clip, dn_sides, colors, 4);
}
else
{
return NSDrawColorTiledRects(border, clip, up_sides, colors, 4);
}
}
/** Draw a dark bezel border */
+ (void) drawDarkBezel: (NSRect)border : (NSRect)clip
+ (NSRect) drawDarkBezel: (NSRect)border : (NSRect)clip
{
NSRectEdge up_sides[] = {NSMaxXEdge, NSMinYEdge, NSMinXEdge, NSMaxYEdge,
NSMinXEdge, NSMaxYEdge, NSMaxXEdge, NSMinYEdge};
@ -90,10 +112,11 @@
NSColor *white = [NSColor controlLightHighlightColor];
NSColor *colors[] = {white, white, dark, dark,
black, black, light, light};
NSRect rect;
if ([[NSView focusView] isFlipped] == YES)
{
NSDrawColorTiledRects(border, clip, dn_sides, colors, 8);
rect = NSDrawColorTiledRects(border, clip, dn_sides, colors, 8);
[dark set];
PSrectfill(NSMinX(border) + 1., NSMinY(border) - 2., 1., 1.);
@ -101,16 +124,17 @@
}
else
{
NSDrawColorTiledRects(border, clip, up_sides, colors, 8);
rect = NSDrawColorTiledRects(border, clip, up_sides, colors, 8);
[dark set];
PSrectfill(NSMinX(border) + 1., NSMinY(border) + 1., 1., 1.);
PSrectfill(NSMaxX(border) - 2., NSMaxY(border) - 2., 1., 1.);
}
return rect;
}
/** Draw a light bezel border */
+ (void) drawLightBezel: (NSRect) border : (NSRect)clip
+ (NSRect) drawLightBezel: (NSRect)border : (NSRect)clip
{
NSRectEdge up_sides[] = {NSMaxXEdge, NSMinYEdge, NSMinXEdge, NSMaxYEdge,
NSMaxXEdge, NSMinYEdge, NSMinXEdge, NSMaxYEdge};
@ -125,16 +149,16 @@
if ([[NSView focusView] isFlipped] == YES)
{
NSDrawColorTiledRects(border, clip, dn_sides, colors, 8);
return NSDrawColorTiledRects(border, clip, dn_sides, colors, 8);
}
else
{
NSDrawColorTiledRects(border, clip, up_sides, colors, 8);
return NSDrawColorTiledRects(border, clip, up_sides, colors, 8);
}
}
/** Draw a white bezel border */
+ (void) drawWhiteBezel: (NSRect) border : (NSRect)clip
+ (NSRect) drawWhiteBezel: (NSRect)border : (NSRect)clip
{
NSRectEdge up_sides[] = {NSMaxYEdge, NSMaxXEdge, NSMinYEdge, NSMinXEdge,
NSMaxYEdge, NSMaxXEdge, NSMinYEdge, NSMinXEdge};
@ -149,16 +173,16 @@
if ([[NSView focusView] isFlipped] == YES)
{
NSDrawColorTiledRects(border, clip, dn_sides, colors, 8);
return NSDrawColorTiledRects(border, clip, dn_sides, colors, 8);
}
else
{
NSDrawColorTiledRects(border, clip, up_sides, colors, 8);
return NSDrawColorTiledRects(border, clip, up_sides, colors, 8);
}
}
/** Draw a grey bezel border */
+ (void) drawGrayBezel: (NSRect) border : (NSRect)clip
+ (NSRect) drawGrayBezel: (NSRect)border : (NSRect)clip
{
NSRectEdge up_sides[] = {NSMaxXEdge, NSMinYEdge, NSMinXEdge, NSMaxYEdge,
NSMaxXEdge, NSMinYEdge, NSMinXEdge, NSMaxYEdge};
@ -171,25 +195,27 @@
NSColor *white = [NSColor controlLightHighlightColor];
NSColor *colors[] = {white, white, dark, dark,
light, light, black, black};
NSRect rect;
if ([[NSView focusView] isFlipped] == YES)
{
NSDrawColorTiledRects(border, clip, dn_sides, colors, 8);
rect = NSDrawColorTiledRects(border, clip, dn_sides, colors, 8);
[dark set];
PSrectfill(NSMinX(border) + 1., NSMaxY(border) - 2., 1., 1.);
PSrectfill(NSMaxX(border) - 2., NSMinY(border) + 1., 1., 1.);
}
else
{
NSDrawColorTiledRects(border, clip, up_sides, colors, 8);
rect = NSDrawColorTiledRects(border, clip, up_sides, colors, 8);
[dark set];
PSrectfill(NSMinX(border) + 1., NSMinY(border) + 1., 1., 1.);
PSrectfill(NSMaxX(border) - 2., NSMaxY(border) - 2., 1., 1.);
}
return rect;
}
/** Draw a groove border */
+ (void) drawGroove: (NSRect)border : (NSRect)clip
+ (NSRect) drawGroove: (NSRect)border : (NSRect)clip
{
// go clockwise from the top twice -- makes the groove come out right
NSRectEdge up_sides[] = {NSMaxYEdge, NSMaxXEdge, NSMinYEdge, NSMinXEdge,
@ -204,16 +230,16 @@
if ([[NSView focusView] isFlipped] == YES)
{
NSDrawColorTiledRects(border, clip, dn_sides, colors, 8);
return NSDrawColorTiledRects(border, clip, dn_sides, colors, 8);
}
else
{
NSDrawColorTiledRects(border, clip, up_sides, colors, 8);
return NSDrawColorTiledRects(border, clip, up_sides, colors, 8);
}
}
/** Draw a frame photo border. Used in NSImageView. */
+ (void) drawFramePhoto: (NSRect) border : (NSRect)clip
+ (NSRect) drawFramePhoto: (NSRect)border : (NSRect)clip
{
NSRectEdge up_sides[] = {NSMaxXEdge, NSMinYEdge,
NSMinXEdge, NSMaxYEdge,
@ -229,11 +255,11 @@
if ([[NSView focusView] isFlipped] == YES)
{
NSDrawColorTiledRects(border, clip, dn_sides, colors, 6);
return NSDrawColorTiledRects(border, clip, dn_sides, colors, 6);
}
else
{
NSDrawColorTiledRects(border, clip, up_sides, colors, 6);
return NSDrawColorTiledRects(border, clip, up_sides, colors, 6);
}
}

View file

@ -52,8 +52,6 @@
static NSNotificationCenter *nc;
static const BOOL ForceBrowser = NO;
static const BOOL ForceArrowIcon = NO;
@interface GSFirstMouseTableView : NSTableView
{
@ -107,6 +105,7 @@ static const BOOL ForceArrowIcon = NO;
- (NSRect) _textCellFrame;
- (void) _setSelectedItem: (int)index;
- (void) _loadButtonCell;
- (void) _selectCompleted;
@end
// ---
@ -369,24 +368,16 @@ static GSComboWindow *gsWindow = nil;
- (void) popUpForComboBoxCell: (NSComboBoxCell *)comboBoxCell
{
NSString *more;
unsigned int index = NSNotFound;
_cell = comboBoxCell;
_cell = comboBoxCell;
[self positionWithComboBoxCell: _cell];
more = [_cell completedString: [_cell stringValue]];
index = [[_cell objectValues] indexOfObject: more];
if (index != NSNotFound)
{
[_cell _setSelectedItem: index];
}
[_cell _selectCompleted];
[self reloadData];
[self enableKeyEquivalentForDefaultButtonCell];
[self runModalPopUpWithComboBoxCell: _cell];
_cell = nil;
[self deselectItemAtIndex: 0];
}
- (void) runModalPopUpWithComboBoxCell: (NSComboBoxCell *)comboBoxCell
@ -811,25 +802,15 @@ numberOfRowsInColumn: (int)column
{
// Method called by GSComboWindow when a selection is done in the table view or
// the browser
NSText *textObject = [[[self controlView] window] fieldEditor: YES
forObject: self];
if ([self usesDataSource])
{
if ([self numberOfItems] <= index)
; // raise exception
}
else
{
if ([_popUpList count] <= index)
; // raise exception
}
if (index < 0)
; // rais exception
return; // raise exception?
if ([self numberOfItems] <= index)
return; // raise exception?
if (_selectedItem != index)
{
NSText *textObject = [[[self controlView] window] fieldEditor: YES
forObject: self];
_selectedItem = index;
[_popup selectItemAtIndex: index];
@ -1504,17 +1485,8 @@ static inline NSRect buttonCellFrameFromRect(NSRect cellRect)
- (void) _loadButtonCell
{
if (!ForceArrowIcon)
{
_buttonCell = [[NSButtonCell alloc] initImageCell:
[NSImage imageNamed: @"common_ComboBoxEllipsis"]];
}
else
{
_buttonCell = [[NSButtonCell alloc] initImageCell:
[NSImage imageNamed: @"NSComboArrow"]];
}
_buttonCell = [[NSButtonCell alloc] initImageCell:
[NSImage imageNamed: @"NSComboArrow"]];
[_buttonCell setImagePosition: NSImageOnly];
[_buttonCell setButtonType: NSMomentaryPushButton];
[_buttonCell setHighlightsBy: NSPushInCellMask];
@ -1523,4 +1495,41 @@ static inline NSRect buttonCellFrameFromRect(NSRect cellRect)
[_buttonCell setAction: @selector(_didClickWithinButton:)];
}
- (void) _selectCompleted
{
NSString *more;
unsigned int index = NSNotFound;
more = [self completedString: [self stringValue]];
if (_usesDataSource)
{
if (!_dataSource)
{
NSLog(@"%@: A DataSource should be specified", self);
}
else
{
if ([_dataSource respondsToSelector:
@selector(comboBoxCell:indexOfItemWithStringValue:)])
{
index = [_dataSource comboBoxCell: self
indexOfItemWithStringValue: more];
}
}
}
else
{
index = [[self objectValues] indexOfObject: more];
}
if (index != NSNotFound)
{
[self _setSelectedItem: index];
}
else
{
[self _setSelectedItem: -1];
}
}
@end