From c58c1924d81e6b890ef41ccb9d6c4c2d0465fa5f Mon Sep 17 00:00:00 2001 From: FredKiefer Date: Mon, 31 May 2004 19:24:10 +0000 Subject: [PATCH] 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 --- ChangeLog | 16 ++++ .../Additions/GNUstepGUI/GSDrawFunctions.h | 15 ++-- Images/nsmapping.strings | 3 +- Source/GSDrawFunctions.m | 70 ++++++++++----- Source/NSComboBoxCell.m | 87 ++++++++++--------- 5 files changed, 122 insertions(+), 69 deletions(-) diff --git a/ChangeLog b/ChangeLog index 5f786c07a..e6c4aa5d0 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,19 @@ +2004-05-31 Fred Kiefer + + * 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 . + * 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 * Source/NSComboBoxCell.m: Fixed problems related to decoding an encoded diff --git a/Headers/Additions/GNUstepGUI/GSDrawFunctions.h b/Headers/Additions/GNUstepGUI/GSDrawFunctions.h index 348d565be..f23257a4d 100644 --- a/Headers/Additions/GNUstepGUI/GSDrawFunctions.h +++ b/Headers/Additions/GNUstepGUI/GSDrawFunctions.h @@ -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 diff --git a/Images/nsmapping.strings b/Images/nsmapping.strings index 4423248b1..77adf9bac 100644 --- a/Images/nsmapping.strings +++ b/Images/nsmapping.strings @@ -9,4 +9,5 @@ NSHighlightedRadioButton = common_RadioOn; AppleMenuImage = GNUstepMenuImage; NSMenuCheckmark = common_2DCheckMark; NSMenuArrow = common_3DArrowRight; -NSMenuMixedState = common_2DDash; \ No newline at end of file +NSMenuMixedState = common_2DDash; +NSComboArrow = common_ComboBoxEllipsis; diff --git a/Source/GSDrawFunctions.m b/Source/GSDrawFunctions.m index cd31fe1e0..dac071ca7 100644 --- a/Source/GSDrawFunctions.m +++ b/Source/GSDrawFunctions.m @@ -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); } } diff --git a/Source/NSComboBoxCell.m b/Source/NSComboBoxCell.m index 2907b7b94..e78cb7e72 100644 --- a/Source/NSComboBoxCell.m +++ b/Source/NSComboBoxCell.m @@ -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