* Headers/AppKit/NSSegmentedCell.h: Added rect ivar to cache frame.

* Source/NSBundleAdditions.m: Minor formatting changes.
	* Source/NSController.m: Added ivars to encodeWithCoder:.
	* Source/NSNibBindingConnector.m: Added ivars to encodeWithCoder:.
	* Source/NSSegmentedCell.m: Changes to fully implement rendering
	of the cell.
	* Source/NSSegmentedControl.m: Changes to fully implement
	control.


git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@25900 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
gcasa 2008-01-09 03:37:59 +00:00
parent f84948848a
commit efdf40b451
7 changed files with 120 additions and 16 deletions

View file

@ -1,3 +1,14 @@
2008-01-08 22:35-EST Gregory John Casamento <greg_casamento@yahoo.com>
* Headers/AppKit/NSSegmentedCell.h: Added rect ivar to cache frame.
* Source/NSBundleAdditions.m: Minor formatting changes.
* Source/NSController.m: Added ivars to encodeWithCoder:.
* Source/NSNibBindingConnector.m: Added ivars to encodeWithCoder:.
* Source/NSSegmentedCell.m: Changes to fully implement rendering
of the cell.
* Source/NSSegmentedControl.m: Changes to fully implement
control.
2008-01-08 09:42-EST Gregory John Casamento <greg_casamento@yahoo.com> 2008-01-08 09:42-EST Gregory John Casamento <greg_casamento@yahoo.com>
* Source/NSSegmentedCell.m: Code to draw and render text in * Source/NSSegmentedCell.m: Code to draw and render text in

View file

@ -56,6 +56,7 @@ typedef enum {
unsigned int _recalcToolTips:1; unsigned int _recalcToolTips:1;
unsigned int unused:24; unsigned int unused:24;
} _segmentCellFlags; } _segmentCellFlags;
int _previous_selection;
} }
// Specifying number of segments... // Specifying number of segments...

View file

@ -186,7 +186,7 @@
@implementation NSNibControlConnector @implementation NSNibControlConnector
- (void) establishConnection - (void) establishConnection
{ {
SEL sel = NSSelectorFromString(_tag); SEL sel = NSSelectorFromString(_tag);
[_src setTarget: _dst]; [_src setTarget: _dst];
[_src setAction: sel]; [_src setAction: sel];
@ -198,8 +198,8 @@
{ {
if (_src != nil) if (_src != nil)
{ {
NSString *selName; NSString *selName;
SEL sel; SEL sel;
selName = [NSString stringWithFormat: @"set%@%@:", selName = [NSString stringWithFormat: @"set%@%@:",
[[_tag substringToIndex: 1] uppercaseString], [[_tag substringToIndex: 1] uppercaseString],
@ -212,10 +212,10 @@
} }
else else
{ {
const char *nam = [_tag cString]; const char *nam = [_tag cString];
const char *type; const char *type;
unsigned int size; unsigned int size;
int offset; int offset;
/* /*
* Use the GNUstep additional function to set the instance * Use the GNUstep additional function to set the instance

View file

@ -53,7 +53,14 @@
- (void) encodeWithCoder: (NSCoder *)aCoder - (void) encodeWithCoder: (NSCoder *)aCoder
{ {
// TODO if([aCoder allowsKeyedCoding])
{
[aCoder encodeObject: _declared_keys forKey: @"NSDeclaredKeys"];
}
else
{
[aCoder encodeObject: _declared_keys];
}
} }
- (id) initWithCoder: (NSCoder *)aDecoder - (id) initWithCoder: (NSCoder *)aDecoder

View file

@ -36,6 +36,17 @@
@implementation NSNibBindingConnector @implementation NSNibBindingConnector
- (id) init
{
if((self = [super init]) != nil)
{
_binding = RETAIN([NSString stringWithString: @""]);
_keyPath = RETAIN([NSString stringWithString: @""]);
_options = RETAIN([NSMutableDictionary dictionary]);
}
return self;
}
- (void) dealloc - (void) dealloc
{ {
RELEASE(_binding); RELEASE(_binding);
@ -154,9 +165,9 @@
} }
else else
{ {
[aDecoder decodeValueOfObjCType: @encode(id) at: &_binding]; ASSIGN(_binding,[aDecoder decodeObject]);
[aDecoder decodeValueOfObjCType: @encode(id) at: &_keyPath]; ASSIGN(_keyPath,[aDecoder decodeObject]);
[aDecoder decodeValueOfObjCType: @encode(id) at: &_options]; ASSIGN(_options,[aDecoder decodeObject]);
} }
return self; return self;

View file

@ -33,6 +33,7 @@
#include <AppKit/NSGraphics.h> #include <AppKit/NSGraphics.h>
#include <AppKit/NSFont.h> #include <AppKit/NSFont.h>
#include <AppKit/NSStringDrawing.h> #include <AppKit/NSStringDrawing.h>
#include <AppKit/NSEvent.h>
@interface NSSegmentItem : NSObject @interface NSSegmentItem : NSObject
{ {
@ -44,6 +45,7 @@
NSString *_label; NSString *_label;
NSString *_tool_tip; NSString *_tool_tip;
NSImage *_image; NSImage *_image;
NSRect _frame;
} }
- (BOOL) isSelected; - (BOOL) isSelected;
@ -62,6 +64,8 @@
- (void) setTag: (int)tag; - (void) setTag: (int)tag;
- (float) width; - (float) width;
- (void) setWidth: (float)width; - (void) setWidth: (float)width;
- (NSRect) frame;
- (void) setFrame: (NSRect)frame;
@end @end
@implementation NSSegmentItem @implementation NSSegmentItem
@ -163,6 +167,16 @@
_width = width; _width = width;
} }
- (NSRect) frame
{
return _frame;
}
- (void) setFrame: (NSRect)frame
{
_frame = frame;
}
- (void) encodeWithCoder:(NSCoder *) aCoder - (void) encodeWithCoder:(NSCoder *) aCoder
{ {
if ([aCoder allowsKeyedCoding]) if ([aCoder allowsKeyedCoding])
@ -245,6 +259,7 @@
_items = [[NSMutableArray alloc] initWithCapacity: 2]; _items = [[NSMutableArray alloc] initWithCapacity: 2];
_selected_segment = -1; _selected_segment = -1;
_previous_selection = -1;
[self setAlignment: NSCenterTextAlignment]; [self setAlignment: NSCenterTextAlignment];
return self; return self;
@ -258,6 +273,7 @@
_items = [[NSMutableArray alloc] initWithCapacity: 2]; _items = [[NSMutableArray alloc] initWithCapacity: 2];
_selected_segment = -1; _selected_segment = -1;
_previous_selection = -1;
[self setAlignment: NSCenterTextAlignment]; [self setAlignment: NSCenterTextAlignment];
return self; return self;
@ -319,12 +335,27 @@
- (void) setSelected: (BOOL)flag forSegment: (int)seg - (void) setSelected: (BOOL)flag forSegment: (int)seg
{ {
NSSegmentItem *segment = [_items objectAtIndex: seg]; NSSegmentItem *segment = [_items objectAtIndex: seg];
NSSegmentItem *previous = nil;
[segment setSelected: flag]; if(_selected_segment != -1)
if (flag) {
_selected_segment = seg; _previous_selection = _selected_segment;
else if (seg == _selected_segment) previous = [_items objectAtIndex: _previous_selection];
_selected_segment = -1; [previous setSelected: NO];
}
if([segment isEnabled])
{
[segment setSelected: flag];
if (flag)
{
_selected_segment = seg;
}
else if (seg == _selected_segment)
{
_selected_segment = -1;
}
}
} }
- (int) selectedSegment - (int) selectedSegment
@ -501,6 +532,7 @@
textFrame.origin.x += x_offset; textFrame.origin.x += x_offset;
textFrame.size.width -= x_offset; textFrame.size.width -= x_offset;
[segment setFrame: frame];
if([segment isSelected]) if([segment isSelected])
{ {
@ -567,6 +599,7 @@
ASSIGN(_items, [aDecoder decodeObjectForKey: @"NSSegmentImages"]); ASSIGN(_items, [aDecoder decodeObjectForKey: @"NSSegmentImages"]);
if ([aDecoder containsValueForKey: @"NSSelectedSegment"]) if ([aDecoder containsValueForKey: @"NSSelectedSegment"])
_selected_segment = [aDecoder decodeIntForKey: @"NSSelectedSegment"]; _selected_segment = [aDecoder decodeIntForKey: @"NSSelectedSegment"];
_previous_selection = -1;
} }
else else
{ {
@ -576,4 +609,32 @@
return self; return self;
} }
- (void) _detectHit: (NSPoint)point
{
int count = [self segmentCount];
int i = 0;
for(i = 0; i < count; i++)
{
id segment = [_items objectAtIndex: i];
NSRect frame = [segment frame];
if(NSPointInRect(point,frame))
{
[self setSelectedSegment: i];
break;
}
}
}
- (void) stopTracking: (NSPoint)lastPoint
at: (NSPoint)stopPoint
inView: (NSView*)controlView
mouseIsUp: (BOOL)flag
{
[super stopTracking: lastPoint
at: stopPoint
inView: controlView
mouseIsUp: (BOOL)flag];
[self _detectHit: lastPoint];
}
@end @end

View file

@ -25,6 +25,7 @@
#include <AppKit/NSControl.h> #include <AppKit/NSControl.h>
#include <AppKit/NSSegmentedControl.h> #include <AppKit/NSSegmentedControl.h>
#include <AppKit/NSEvent.h>
@implementation NSSegmentedControl @implementation NSSegmentedControl
@ -115,4 +116,16 @@
{ {
return [_cell isEnabledForSegment: segment]; return [_cell isEnabledForSegment: segment];
} }
/*
- (void) mouseDown: (NSEvent *)event
{
NSPoint location = [self convertPoint: [event locationInWindow]
fromView: nil];
[super mouseDown: event];
[_cell _detectHit: location];
NSLog(@"%@",NSStringFromPoint(location));
}
*/
@end @end