Added initial implementations of NSSegmentedCell and NSSegmentedControl.

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@25884 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Gregory John Casamento 2008-01-07 14:33:58 +00:00
parent 30c6bccd90
commit 83a6e40893
7 changed files with 622 additions and 0 deletions

View file

@ -1,3 +1,13 @@
2008-01-07 09:33-EST Gregory John Casamento <greg_casamento@yahoo.com>
* Headers/AppKit/AppKit.h
* Headers/AppKit/NSSegmentedCell.h
* Headers/AppKit/NSSegmentedControl.h
* Source/GNUmakefile
* Source/NSSegmentedCell.m
* Source/NSSegmentedControl.m: Added initial implementation of
NSSegmentedCell/NSSegmentedControl.
2008-01-07 Fred Kiefer <FredKiefer@gmx.de>
* Headers/AppKit/NSTextView.h,

View file

@ -103,6 +103,8 @@
#include <AppKit/NSScreen.h>
#include <AppKit/NSScroller.h>
#include <AppKit/NSScrollView.h>
#include <AppKit/NSSegmentedCell.h>
#include <AppKit/NSSegmentedControl.h>
#include <AppKit/NSSelection.h>
#include <AppKit/NSSlider.h>
#include <AppKit/NSSliderCell.h>

View file

@ -0,0 +1,99 @@
/* NSSegmentedCell.h
*
* Copyright (C) 2007 Free Software Foundation, Inc.
*
* Author: Gregory John Casamento <greg_casamento@yahoo.com>
* Date: 2007
*
* This file is part of GNUstep.
*
* 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 3 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., 51 Franklin Street, Fifth Floor, Boston, MA 02111
* USA.
*/
#ifndef _GNUstep_H_NSSegmentedCell
#define _GNUstep_H_NSSegmentedCell
#include <AppKit/NSActionCell.h>
// tracking types...
typedef enum {
NSSegmentSwitchTrackingSelectOne = 0,
NSSegmentSwitchTrackingSelectAny = 1,
NSSegmentSwitchTrackingMomentary = 2
} NSSegmentSwitchTracking;
// forward declarations
@class NSMutableArray;
@class NSImage;
@class NSString;
@class NSMenu;
@class NSView;
@interface NSSegmentedCell : NSActionCell
{
@private
int _selected_segment;
int _key_selection;
NSMutableArray *_items;
struct {
unsigned int _tracking_mode:3;
unsigned int _trimmed_labels:1;
unsigned int _drawing:1;
unsigned int _style:1;
unsigned int _recalcToolTips:1;
unsigned int unused:24;
} _segmentCellFlags;
}
// Specifying number of segments...
- (void) setSegmentCount: (int) count;
- (int) segmentCount;
// Specifying selected segment...
- (void) setSelectedSegment: (int) segment;
- (void) setSelected: (BOOL)flag forSegment: (int)segment;
- (int) selectedSegment;
- (void) selectSegmentWithTag: (int) tag;
- (void) makeNextSegmentKey;
- (void) makePreviousSegmentKey;
// Specify tracking mode...
- (void) setTrackingMode: (NSSegmentSwitchTracking)mode;
- (NSSegmentSwitchTracking) trackingMode;
// Working with individual segments...
- (void) setWidth: (float)width forSegment: (int)segment;
- (float) widthForSegment: (int)segment;
- (void) setImage: (NSImage *)image forSegment: (int)segment;
- (NSImage *) imageForSegment: (int)segment;
- (void) setLabel: (NSString *)label forSegment: (int)segment;
- (NSString *) labelForSegment: (int)segment;
- (BOOL) isSelectedForSegment: (int)segment;
- (void) setEnabled: (BOOL)flag forSegment: (int)segment;
- (BOOL) isEnabledForSegment: (int)segment;
- (void) setMenu: (NSMenu *)menu forSegment: (int)segment;
- (NSMenu *) menuForSegment: (int)segment;
- (void) setToolTip: (NSString *) toolTip forSegment: (int)segment;
- (NSString *) toolTipForSegment: (int)segment;
- (void) setTag: (int)tag forSegment: (int)segment;
- (int) tagForSegment: (int)segment;
// Drawing custom content
- (void) drawSegment: (int)segment
inFrame: (NSRect)frame
withView: (NSView *)view;
@end
#endif

View file

@ -0,0 +1,57 @@
/* NSSegmentedControl.h
*
* Copyright (C) 2007 Free Software Foundation, Inc.
*
* Author: Gregory John Casamento <greg_casamento@yahoo.com>
* Date: 2007
*
* This file is part of GNUstep.
*
* 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 3 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., 51 Franklin Street, Fifth Floor, Boston, MA 02111
* USA.
*/
#ifndef _GNUstep_H_NSSegmentedControl
#define _GNUstep_H_NSSegmentedControl
#include <AppKit/NSControl.h>
#include <AppKit/NSSegmentedCell.h>
@interface NSSegmentedControl : NSControl
// Specifying number of segments...
- (void) setSegmentCount: (int) count;
- (int) segmentCount;
// Specifying selected segment...
- (void) setSelectedSegment: (int) segment;
- (int) selectedSegment;
- (void) selectSegmentWithTag: (int) tag;
// Working with individual segments...
- (void) setWidth: (float)width forSegment: (int)segment;
- (float) widthForSegment: (int)segment;
- (void) setImage: (NSImage *)image forSegment: (int)segment;
- (NSImage *) imageForSegment: (int)segment;
- (void) setLabel: (NSString *)label forSegment: (int)segment;
- (NSString *) labelForSegment: (int)segment;
- (void) setMenu: (NSMenu *)menu forSegment: (int)segment;
- (NSMenu *) menuForSegment: (int)segment;
- (void) setSelected: (BOOL)flag forSegment: (int)segment;
- (BOOL) isSelectedForSegment: (int)segment;
- (void) setEnabled: (BOOL)flag forSegment: (int)segment;
- (BOOL) isEnabledForSegment: (int)segment;
@end
#endif

View file

@ -141,6 +141,8 @@ NSRulerView.m \
NSSavePanel.m \
NSSearchField.m \
NSSearchFieldCell.m \
NSSegmentedCell.m \
NSSegmentedControl.m \
NSScreen.m \
NSScroller.m \
NSScrollView.m \
@ -332,6 +334,8 @@ NSScroller.h \
NSSearchField.h \
NSSearchFieldCell.h \
NSSecureTextField.h \
NSSegmentedCell.h \
NSSegmentedControl.h \
NSSelection.h \
NSSlider.h \
NSSliderCell.h \

332
Source/NSSegmentedCell.m Normal file
View file

@ -0,0 +1,332 @@
/* NSSegmentedCell.m
*
* Copyright (C) 2007 Free Software Foundation, Inc.
*
* Author: Gregory John Casamento <greg_casamento@yahoo.com>
* Date: 2007
*
* This file is part of GNUstep.
*
* 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 3 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., 51 Franklin Street, Fifth Floor, Boston, MA 02111
* USA.
*/
#include <AppKit/NSSegmentedCell.h>
#include <AppKit/NSMenu.h>
#include <AppKit/NSImage.h>
#include <Foundation/NSArray.h>
#include <Foundation/NSEnumerator.h>
@interface NSSegmentItem : NSObject
{
BOOL _selected;
BOOL _enabled;
BOOL _is_key;
int _tag;
float _width;
NSMenu *_menu;
NSString *_label;
NSString *_tool_tip;
NSImage *_image;
}
- (BOOL) isSelected;
- (void) setSelected: (BOOL)flag;
- (BOOL) isSelected;
- (void) setSelected: (BOOL)flag;
- (BOOL) isKey;
- (void) setKey: (BOOL)flag;
- (NSMenu *) menu;
- (void) setMenu: (NSMenu *)menu;
- (NSString *) label;
- (void) setLabel: (NSString *)label;
- (NSString *) toolTip;
- (void) setToolTip: (NSString *)toolTip;
- (NSImage *) image;
- (void) setImage: (NSImage *)image;
- (int) tag;
- (void) setTag: (int)tag;
- (float) width;
- (void) setWidth: (float)width;
@end
@implementation NSSegmentItem
- (BOOL) isSelected
{
return _selected;
}
- (void) setSelected: (BOOL)flag
{
_selected = flag;
}
- (BOOL) isEnabled
{
return _enabled;
}
- (void) setEnabled: (BOOL)flag
{
_enabled = flag;
}
- (BOOL) isKey
{
return _is_key;
}
- (void) setKey: (BOOL)flag
{
_is_key = flag;
}
- (NSMenu *) menu
{
return _menu;
}
- (void) setMenu: (NSMenu *)menu
{
_menu = menu;
}
- (NSString *) label
{
return _label;
}
- (void) setLabel: (NSString *)label
{
ASSIGN(_label, label);
}
- (NSString *) toolTip
{
return _tool_tip;
}
- (void) setToolTip: (NSString *)toolTip
{
ASSIGN(_tool_tip, toolTip);
}
- (NSImage *) image
{
return _image;
}
- (void) setImage: (NSImage *)image
{
ASSIGN(_image, image);
}
- (int) tag
{
return _tag;
}
- (void) setTag: (int)tag
{
_tag = tag;
}
- (float) width
{
return _width;
}
- (void) setWidth: (float)width
{
_width = width;
}
@end
@implementation NSSegmentedCell
// Specifying number of segments...
- (void) setSegmentCount: (int) count
{
}
- (int) segmentCount
{
return [_items count];
}
// Specifying selected segment...
- (void) setSelectedSegment: (int) segment
{
_selected_segment = segment;
}
- (void) setSelected: (BOOL)flag forSegment: (int)seg
{
NSSegmentItem *segment = [_items objectAtIndex: seg];
[segment setSelected: flag];
}
- (int) selectedSegment
{
return _selected_segment;
}
- (void) selectSegmentWithTag: (int) tag
{
NSEnumerator *en = [_items objectEnumerator];
id o = nil;
int segment = 0;
while((o = [en nextObject]) != nil)
{
if([o tag] == tag)
{
break;
}
segment++;
}
[o setSelected: YES];
_selected_segment = segment;
}
- (void) makeNextSegmentKey
{
if(_selected_segment < [_items count])
{
_selected_segment++;
}
}
- (void) makePreviousSegmentKey
{
if(_selected_segment > 0)
{
_selected_segment--;
}
}
// Specify tracking mode...
- (void) setTrackingMode: (NSSegmentSwitchTracking)mode
{
_segmentCellFlags._tracking_mode = mode;
}
- (NSSegmentSwitchTracking) trackingMode
{
return _segmentCellFlags._tracking_mode;
}
// Working with individual segments...
- (void) setWidth: (float)width forSegment: (int)seg
{
id segment = [_items objectAtIndex: seg];
[segment setWidth: width];
}
- (float) widthForSegment: (int)seg
{
id segment = [_items objectAtIndex: seg];
return [segment width];
}
- (void) setImage: (NSImage *)image forSegment: (int)seg
{
id segment = [_items objectAtIndex: seg];
[segment setImage: image];
}
- (NSImage *) imageForSegment: (int)seg
{
id segment = [_items objectAtIndex: seg];
return [segment image];
}
- (void) setLabel: (NSString *)label forSegment: (int)seg
{
id segment = [_items objectAtIndex: seg];
[segment setLabel: label];
}
- (NSString *) labelForSegment: (int)seg
{
id segment = [_items objectAtIndex: seg];
return [segment label];
}
- (BOOL) isSelectedForSegment: (int)seg
{
id segment = [_items objectAtIndex: seg];
return [segment isSelected];
}
- (void) setEnabled: (BOOL)flag forSegment: (int)seg
{
id segment = [_items objectAtIndex: seg];
return [segment setEnabled: flag];
}
- (BOOL) isEnabledForSegment: (int)seg
{
id segment = [_items objectAtIndex: seg];
return [segment isEnabled];
}
- (void) setMenu: (NSMenu *)menu forSegment: (int)seg
{
id segment = [_items objectAtIndex: seg];
return [segment setMenu: menu];
}
- (NSMenu *) menuForSegment: (int)seg
{
id segment = [_items objectAtIndex: seg];
return [segment menu];
}
- (void) setToolTip: (NSString *) toolTip forSegment: (int)seg
{
id segment = [_items objectAtIndex: seg];
return [segment setToolTip: toolTip];
}
- (NSString *) toolTipForSegment: (int)seg
{
id segment = [_items objectAtIndex: seg];
return [segment toolTip];
}
- (void) setTag: (int)tag forSegment: (int)seg
{
id segment = [_items objectAtIndex: seg];
return [segment setTag: tag];
}
- (int) tagForSegment: (int)seg
{
id segment = [_items objectAtIndex: seg];
return [segment tag];
}
// Drawing custom content
- (void) drawSegment: (int)seg
inFrame: (NSRect)frame
withView: (NSView *)view
{
}
@end

118
Source/NSSegmentedControl.m Normal file
View file

@ -0,0 +1,118 @@
/* NSSegmentedControl.m
*
* Copyright (C) 2007 Free Software Foundation, Inc.
*
* Author: Gregory John Casamento <greg_casamento@yahoo.com>
* Date: 2007
*
* This file is part of GNUstep.
*
* 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 3 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., 51 Franklin Street, Fifth Floor, Boston, MA 02111
* USA.
*/
#include <AppKit/NSControl.h>
#include <AppKit/NSSegmentedControl.h>
@implementation NSSegmentedControl
// Specifying number of segments...
- (void) setSegmentCount: (int) count
{
[_cell setSegmentCount: count];
}
- (int) segmentCount
{
return [_cell segmentCount];
}
// Specifying selected segment...
- (void) setSelectedSegment: (int) segment
{
[_cell setSelectedSegment: segment];
}
- (int) selectedSegment
{
return [_cell selectedSegment];
}
- (void) selectSegmentWithTag: (int) tag
{
[_cell selectSegmentWithTag: tag];
}
// Working with individual segments...
- (void) setWidth: (float)width forSegment: (int)segment
{
[_cell setWidth: width forSegment: segment];
}
- (float) widthForSegment: (int)segment
{
return [_cell widthForSegment: segment];
}
- (void) setImage: (NSImage *)image forSegment: (int)segment
{
[_cell setImage: image forSegment: segment];
}
- (NSImage *) imageForSegment: (int)segment
{
return [_cell imageForSegment: segment];
}
- (void) setLabel: (NSString *)label forSegment: (int)segment
{
[_cell setLabel: label forSegment: segment];
}
- (NSString *) labelForSegment: (int)segment
{
return [_cell labelForSegment: segment];
}
- (void) setMenu: (NSMenu *)menu forSegment: (int)segment
{
[_cell setMenu: menu forSegment: segment];
}
- (NSMenu *) menuForSegment: (int)segment
{
return [_cell menuForSegment: segment];
}
- (void) setSelected: (BOOL)flag forSegment: (int)segment
{
[_cell setSelected: flag forSegment: segment];
}
- (BOOL) isSelectedForSegment: (int)segment
{
return [_cell isSelectedForSegment: segment];
}
- (void) setEnabled: (BOOL)flag forSegment: (int)segment
{
[_cell setEnabled: flag forSegment: segment];
}
- (BOOL) isEnabledForSegment: (int)segment
{
return [_cell isEnabledForSegment: segment];
}
@end