Updated documentation in .m and .h files.

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@22716 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Gregory John Casamento 2006-03-26 17:58:19 +00:00
parent 96cdd5eff5
commit 0474a23212
4 changed files with 373 additions and 91 deletions

View file

@ -1,3 +1,10 @@
2006-03-26 12:52 Gregory John Casamento <greg_casamento@yahoo.com>
* Headers/AppKit/NSPopUpButtonCell.h: Refactored header,
added documentation
* Source/NSNib.m: Added documentation.
* Source/NSPopUpButtonCell.m: Improved documentation.
2006-03-26 Fred Kiefer <FredKiefer@gmx.de>
* Headers/AppKit/NSSearchFieldCell.h:

View file

@ -29,15 +29,17 @@
#ifndef _GNUstep_H_NSPopUpButtonCell
#define _GNUstep_H_NSPopUpButtonCell
#include <AppKit/NSMenuItemCell.h>
#include <AppKit/NSMenuItem.h>
#include <AppKit/NSMenuItemCell.h>
APPKIT_EXPORT NSString*NSPopUpButtonCellWillPopUpNotification;
@class NSMenu;
typedef enum {
NSPopUpNoArrow = 0,
NSPopUpArrowAtCenter = 1,
NSPopUpArrowAtBottom = 2,
NSPopUpNoArrow = 0,
NSPopUpArrowAtCenter = 1,
NSPopUpArrowAtBottom = 2
} NSPopUpArrowPosition;
@interface NSPopUpButtonCell : NSMenuItemCell
@ -52,80 +54,243 @@ typedef enum {
} _pbcFlags;
}
- (id) initTextCell: (NSString*)stringValue pullsDown: (BOOL)pullDown;
// Initialization
/**
* Initialize with stringValue and pullDown. If pullDown is YES, the
* reciever will be a pulldown button.
*/
- (id) initTextCell: (NSString*)stringValue pullsDown: (BOOL)flag;
// Overrides behavior of NSCell. This is the menu for the popup, not a
// context menu. PopUpButtonCells do not have context menus.
// Selection processing
/**
* The currently selected item in the reciever.
*/
- (id <NSMenuItem>) selectedItem;
/**
* Index of the currently selected item in the reciever.
*/
- (int) indexOfSelectedItem;
/**
* Synchronizes the title and the selected item. This sets
* the selected item to the title of the reciever.
*/
- (void) synchronizeTitleAndSelectedItem;
/**
* Select item in the reciever.
*/
- (void) selectItem: (id <NSMenuItem>)item;
/**
* Select item at the given index.
*/
- (void) selectItemAtIndex: (int)index;
/**
* Select the item with the given title.
*/
- (void) selectItemWithTitle: (NSString*)title;
/**
* Set title to aString.
*/
- (void) setTitle: (NSString*)aString;
// Getters and setters.
/**
* Set the menu for the popup.
*/
- (void) setMenu: (NSMenu*)menu;
/**
* Return the menu for the popup.
*/
- (NSMenu*) menu;
// Behavior settings
/**
* Set to YES to make the popup button a pull-down style control.
*/
- (void) setPullsDown: (BOOL)flag;
/**
* Returns YES, if this is a pull-down
*/
- (BOOL) pullsDown;
/**
* Set to YES, if the items are to be autoenabled.
*/
- (void) setAutoenablesItems: (BOOL)flag;
/**
* Returns YES, if the items are autoenabled.
*/
- (BOOL) autoenablesItems;
- (void) setPreferredEdge: (NSRectEdge)edge;
/**
* Set the preferred edge as described by edge. This is used
* to determine the edge which will open the popup when the screen
* is small.
*/
- (void) setPreferredEdge: (NSRectEdge)preferredEdge;
/**
* Return the preferred edge.
*/
- (NSRectEdge) preferredEdge;
/**
* Set to YES, if the reciever should use a menu item for its title. YES
* is the default.
*/
- (void) setUsesItemFromMenu: (BOOL)flag;
/**
* Returns YES, if the reciever uses a menu item for its title.
*/
- (BOOL) usesItemFromMenu;
/**
* Set to YES, if the state of the menu item selected in the reciever
* should be changed when it's selected.
*/
- (void) setAltersStateOfSelectedItem: (BOOL)flag;
/**
* Return YES, if the reciever changes the state of the item chosen by
* the user.
*/
- (BOOL) altersStateOfSelectedItem;
// Adding and removing items
- (void) addItemWithTitle: (NSString*)title;
- (void) addItemsWithTitles: (NSArray*)itemTitles;
- (void) insertItemWithTitle: (NSString*)title atIndex: (int)index;
- (void) removeItemWithTitle: (NSString*)title;
- (void) removeItemAtIndex: (int)index;
- (void) removeAllItems;
/**
* Returns the current arrow position of the reciever.
*/
- (NSPopUpArrowPosition) arrowPosition;
// Accessing the items
/**
* Sets the current arrow position of the reciever.
*/
- (void) setArrowPosition: (NSPopUpArrowPosition)pos;
// Item management
/**
* Add an item to the popup with title.
*/
- (void) addItemWithTitle: (NSString*)title;
/**
* Add a number of items to the reciever using the provided itemTitles array.
*/
- (void) addItemsWithTitles: (NSArray*)titles;
/**
* Adds an item with the given title at index. If an item already exists at
* index, it, and all items after it are advanced one position. Index needs
* to be within the valid range for the array of items in the popup button.
*/
- (void) insertItemWithTitle: (NSString*)title atIndex: (int)index;
/**
* Remove a given item based on its title.
*/
- (void) removeItemWithTitle: (NSString*)title;
/**
* Remove a given item based on its index, must be a valid index within the
* range for the item array of this popup.
*/
- (void) removeItemAtIndex: (int)index;
/**
* Purges all items from the popup.
*/
- (void) removeAllItems;
// Referencing items...
/**
* Item array of the reciever.
*/
- (NSArray*) itemArray;
/**
* Number of items in the reciever.
*/
- (int) numberOfItems;
- (int) indexOfItem: (id <NSMenuItem>)item;
/**
* Return the index of item in the item array of the reciever.
*/
- (int) indexOfItem: (id<NSMenuItem>)item;
/**
* Return index of the item with the given title.
*/
- (int) indexOfItemWithTitle: (NSString*)title;
- (int) indexOfItemWithTag: (int)aTag;
/**
* Return index of the item with a tag equal to aTag.
*/
- (int) indexOfItemWithTag: (int)tag;
/**
* Index of the item whose menu item's representedObject is equal to obj.
*/
- (int) indexOfItemWithRepresentedObject: (id)obj;
/**
* Index of the item in the reciever whose target and action
* are equal to aTarget and actionSelector.
*/
- (int) indexOfItemWithTarget: (id)aTarget andAction: (SEL)actionSelector;
/**
* Return the item at index.
*/
- (id <NSMenuItem>) itemAtIndex: (int)index;
/**
* Return the item with title.
*/
- (id <NSMenuItem>) itemWithTitle: (NSString*)title;
/**
* Return the item listed last in the reciever.
*/
- (id <NSMenuItem>) lastItem;
// Dealing with selection
- (void) selectItem: (id <NSMenuItem>)item;
- (void) selectItemAtIndex: (int)index;
- (void) selectItemWithTitle: (NSString*)title;
- (void) setTitle: (NSString*)aString;
- (id <NSMenuItem>) selectedItem;
- (int) indexOfSelectedItem;
- (void) synchronizeTitleAndSelectedItem;
// Title conveniences
// Title management
/**
* Set item title at the given index in the reciever.
*/
- (NSString*) itemTitleAtIndex: (int)index;
/**
* Returns an array containing all of the current item titles.
*/
- (NSArray*) itemTitles;
/**
* Returns the title of the currently selected item in the reciever.
*/
- (NSString*) titleOfSelectedItem;
/**
* Attach popup
*/
- (void) attachPopUpWithFrame: (NSRect)cellFrame inView: (NSView*)controlView;
- (void) dismissPopUp;
- (void) performClickWithFrame: (NSRect)frame inView: (NSView*)controlView;
// Arrow position for bezel style and borderless popups.
- (NSPopUpArrowPosition) arrowPosition;
- (void) setArrowPosition: (NSPopUpArrowPosition)position;
/**
* Dismiss the reciever.
*/
- (void) dismissPopUp;
/**
* Perform the click operation with the given frame and controlView.
*/
- (void) performClickWithFrame: (NSRect)frame inView: (NSView*)controlView;
@end
/* Notifications */
APPKIT_EXPORT NSString*NSPopUpButtonCellWillPopUpNotification;
#endif // _GNUstep_H_NSPopUpButtonCell

View file

@ -161,8 +161,8 @@
/**
* Load the nib indicated by <code>nibNamed</code>. If the <code>bundle</code>
* argument is <code>nil</code>, then the main bundle is used to resolve the path,
* otherwise the bundle which is supplied will be used.
* argument is <code>nil</code>, then the main bundle is used to resolve
* the path, otherwise the bundle which is supplied will be used.
*/
- (id)initWithNibNamed: (NSString *)nibNamed bundle: (NSBundle *)bundle
{
@ -185,8 +185,9 @@
}
/**
* This is a GNUstep specific method. This method is used when the caller wants the
* objects instantiated in the nib to be stored in the given <code>zone</code>.
* This is a GNUstep specific method. This method is used when the caller
* wants the objects instantiated in the nib to be stored in the given
* <code>zone</code>.
*/
- (BOOL)instantiateNibWithExternalNameTable: (NSDictionary *)externalNameTable
withZone: (NSZone *)zone

View file

@ -51,18 +51,29 @@ static NSImage *_pbc_image[2];
}
}
// Initialization
/**
* Initialize a blank cell.
*/
- (id) init
{
return [self initTextCell: @"" pullsDown: NO];
}
/**
* Initialize with stringValue.
*/
- (id) initTextCell: (NSString *)stringValue
{
return [self initTextCell: stringValue pullsDown: NO];
}
/**
* Initialize with stringValue and pullDown. If pullDown is YES, the
* reciever will be a pulldown button.
*/
- (id) initTextCell: (NSString *)stringValue
pullsDown: (BOOL)pullDown
pullsDown: (BOOL)flag
{
NSMenu *menu;
@ -72,7 +83,7 @@ static NSImage *_pbc_image[2];
[self setMenu: menu];
RELEASE(menu);
[self setPullsDown: pullDown];
[self setPullsDown: flag];
_pbcFlags.usesItemFromMenu = YES;
if ([stringValue length] > 0)
@ -106,6 +117,10 @@ static NSImage *_pbc_image[2];
[super dealloc];
}
// Getters and setters.
/**
* Set the menu for the popup.
*/
- (void) setMenu: (NSMenu *)menu
{
if (_menu == menu)
@ -132,12 +147,17 @@ static NSImage *_pbc_image[2];
}
}
/**
* Return the menu for the popup.
*/
- (NSMenu *) menu
{
return _menu;
}
// Behaviour settings
/**
* Returns YES, if this is a pull-down
*/
- (void) setPullsDown: (BOOL)flag
{
NSMenuItem *item = _menuItem;
@ -162,51 +182,69 @@ static NSImage *_pbc_image[2];
[self setMenuItem: item];
}
/**
* Returns YES, if this is a pull-down
*/
- (BOOL) pullsDown
{
return _pbcFlags.pullsDown;
}
/**
* Set to YES, if the items are to be autoenabled.
*/
- (void) setAutoenablesItems: (BOOL)flag
{
[_menu setAutoenablesItems: flag];
}
/**
* Returns YES, if the items are autoenabled.
*/
- (BOOL) autoenablesItems
{
return [_menu autoenablesItems];
}
// The preferred edge is used for pull down menus and for popups under
// severe screen position restrictions. It indicates what edge of the
// cell the menu should pop out from.
- (void) setPreferredEdge: (NSRectEdge)edge
/**
* Set the preferred edge as described by edge. This is used
* to determine the edge which will open the popup when the screen
* is small.
*/
- (void) setPreferredEdge: (NSRectEdge)preferredEdge
{
_pbcFlags.preferredEdge = edge;
_pbcFlags.preferredEdge = preferredEdge;
}
/**
* Return the preferred edge.
*/
- (NSRectEdge) preferredEdge
{
return _pbcFlags.preferredEdge;
}
// If YES (the default) the popup button will display an item from the
// menu. This will be the selected item for a popup or the first item for
// a pull-down. If this is NO, then the menu item set with -setMenuItem:
// is always displayed. This can be useful for a popup button that is an
// icon button that pops up a menu full of textual items, for example.
/**
* Set to YES, if the reciever should use a menu item for its title. YES
* is the default.
*/
- (void) setUsesItemFromMenu: (BOOL)flag
{
_pbcFlags.usesItemFromMenu = flag;
}
/**
* Returns YES, if the reciever uses a menu item for its title.
*/
- (BOOL) usesItemFromMenu
{
return _pbcFlags.usesItemFromMenu;
}
// If YES (the default for popups) then the selected item gets its state
// set to NSOnState. If NO the items in the menu are left alone.
/**
* Return YES, if the reciever changes the state of the item chosen by
* the user.
*/
- (void) setAltersStateOfSelectedItem: (BOOL)flag
{
id <NSMenuItem> selectedItem = [self selectedItem];
@ -223,29 +261,61 @@ static NSImage *_pbc_image[2];
_pbcFlags.altersStateOfSelectedItem = flag;
}
/**
* Return YES, if the reciever changes the state of the item chosen by
* the user.
*/
- (BOOL) altersStateOfSelectedItem
{
return _pbcFlags.altersStateOfSelectedItem;
}
// Adding and removing items
/**
* Returns the current arrow position of the reciever.
*/
- (NSPopUpArrowPosition) arrowPosition
{
return _pbcFlags.arrowPosition;
}
/**
* Sets the current arrow position of the reciever.
*/
- (void) setArrowPosition: (NSPopUpArrowPosition)pos
{
_pbcFlags.arrowPosition = pos;
}
// Item management
/**
* Add an item to the popup with title.
*/
- (void) addItemWithTitle: (NSString *)title
{
[self insertItemWithTitle: title
atIndex: [_menu numberOfItems]];
}
- (void) addItemsWithTitles: (NSArray *)itemTitles
/**
* Add a number of items to the reciever using the provided itemTitles array.
*/
- (void) addItemsWithTitles: (NSArray *)titles
{
unsigned c = [itemTitles count];
unsigned c = [titles count];
unsigned i;
for (i = 0; i < c; i++)
{
[self addItemWithTitle: [itemTitles objectAtIndex: i]];
[self addItemWithTitle: [titles objectAtIndex: i]];
}
}
/**
* Adds an item with the given title at index. If an item already exists at
* index, it, and all items after it are advanced one position. Index needs
* to be within the valid range for the array of items in the popup button.
*/
- (void) insertItemWithTitle: (NSString *)title atIndex: (int)index
{
id <NSMenuItem> anItem;
@ -280,11 +350,18 @@ static NSImage *_pbc_image[2];
//[anItem setTarget: [self target]];
}
/**
* Remove a given item based on its title.
*/
- (void) removeItemWithTitle: (NSString *)title
{
[self removeItemAtIndex: [self indexOfItemWithTitle: title]];
}
/**
* Remove a given item based on its index, must be a valid index within the
* range for the item array of this popup.
*/
- (void) removeItemAtIndex: (int)index
{
if (index == [self indexOfSelectedItem])
@ -295,6 +372,9 @@ static NSImage *_pbc_image[2];
[_menu removeItemAtIndex: index];
}
/**
* Purges all items from the popup.
*/
- (void) removeAllItems
{
[self selectItem: nil];
@ -305,42 +385,67 @@ static NSImage *_pbc_image[2];
}
}
// Accessing the items
// Referencing items...
/**
* Item array of the reciever.
*/
- (NSArray *) itemArray
{
return [_menu itemArray];
}
/**
* Number of items in the reciever.
*/
- (int) numberOfItems
{
return [_menu numberOfItems];
}
/**
* Return the index of item in the item array of the reciever.
*/
- (int) indexOfItem: (id <NSMenuItem>)item
{
return [_menu indexOfItem: item];
}
/**
* Return index of the item with the given title.
*/
- (int) indexOfItemWithTitle: (NSString *)title
{
return [_menu indexOfItemWithTitle: title];
}
- (int) indexOfItemWithTag: (int)aTag
/**
* Return index of the item with a tag equal to aTag.
*/
- (int) indexOfItemWithTag: (int)tag
{
return [_menu indexOfItemWithTag: aTag];
return [_menu indexOfItemWithTag: tag];
}
/**
* Index of the item whose menu item's representedObject is equal to obj.
*/
- (int) indexOfItemWithRepresentedObject: (id)obj
{
return [_menu indexOfItemWithRepresentedObject: obj];
}
/**
* Index of the item in the reciever whose target and action
* are equal to aTarget and actionSelector.
*/
- (int) indexOfItemWithTarget: (id)aTarget andAction: (SEL)actionSelector
{
return [_menu indexOfItemWithTarget: aTarget andAction: actionSelector];
}
/**
* Return the item at index.
*/
- (id <NSMenuItem>) itemAtIndex: (int)index
{
if ((index >= 0) && (index < [_menu numberOfItems]))
@ -353,11 +458,17 @@ static NSImage *_pbc_image[2];
}
}
/**
* Return the item with title.
*/
- (id <NSMenuItem>) itemWithTitle: (NSString *)title
{
return [_menu itemWithTitle: title];
}
/**
* Return the item listed last in the reciever.
*/
- (id <NSMenuItem>) lastItem
{
int end = [_menu numberOfItems] - 1;
@ -368,9 +479,11 @@ static NSImage *_pbc_image[2];
}
/*
The Cocoa specification has this method as
The Cocoa specification has this method as:
- (id <NSCopying>) objectValue
but this gives a conflict with the NSCell declaration of this method, which is
But this gives a conflict with the NSCell declaration of this method,
which is:
- (id) objectValue
*/
- (id <NSCopying>) objectValue
@ -428,7 +541,6 @@ static NSImage *_pbc_image[2];
}
}
// Dealing with selection
- (void) selectItem: (id <NSMenuItem>)item
{
if (_selectedItem == item)
@ -567,12 +679,19 @@ static NSImage *_pbc_image[2];
[(NSControl *)_control_view updateCell: self];
}
// Title conveniences
// Title management
/**
* Set item title at the given index in the reciever.
*/
- (NSString *) itemTitleAtIndex: (int)index
{
return [[self itemAtIndex: index] title];
}
/**
* Returns an array containing all of the current item titles.
*/
- (NSArray *) itemTitles
{
unsigned count = [_menu numberOfItems];
@ -588,6 +707,9 @@ static NSImage *_pbc_image[2];
return [NSArray arrayWithObjects: items count: count];
}
/**
* Returns the title of the currently selected item in the reciever.
*/
- (NSString *) titleOfSelectedItem
{
id <NSMenuItem> item = [self selectedItem];
@ -598,6 +720,9 @@ static NSImage *_pbc_image[2];
return @"";
}
/**
* Attach popup
*/
- (void) attachPopUpWithFrame: (NSRect)cellFrame
inView: (NSView *)controlView
{
@ -641,6 +766,9 @@ static NSImage *_pbc_image[2];
object: _menu];
}
/**
* Dismiss the reciever.
*/
- (void) dismissPopUp
{
NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
@ -715,16 +843,8 @@ static NSImage *_pbc_image[2];
return NO;
}
// This method is called to simulate programmatically a click by overriding
// -[NSCell performClickWithFrame:inView:]
// This method is not executed upon mouse down; rather, it should simulate what
// would happen upon mouse down. It should not start any real mouse tracking.
/**
* Simulates a single click in the pop up button cell (the display of the cell
* with this event occurs in the area delimited by <var>frame</var> in the view
* <var>controlView</var>) and displays the popup button cell menu attached to
* the view <var>controlView</var>, the menu width depends on the
* <var>frame</var> width value.
* Perform the click operation with the given frame and controlView.
*/
- (void) performClickWithFrame: (NSRect)frame inView: (NSView *)controlView
{
@ -733,17 +853,6 @@ static NSImage *_pbc_image[2];
[self attachPopUpWithFrame: frame inView: controlView];
}
// Arrow position for bezel style and borderless popups.
- (NSPopUpArrowPosition) arrowPosition
{
return _pbcFlags.arrowPosition;
}
- (void) setArrowPosition: (NSPopUpArrowPosition)position
{
_pbcFlags.arrowPosition = position;
}
/*
* This drawing uses the same code that is used to draw cells in the menu.
*/