Added NSTab* classes.

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@4432 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
michael 1999-06-19 11:44:32 +00:00
parent 8408ebf0b7
commit a9cce23dbb
8 changed files with 512 additions and 1 deletions

View file

@ -1,3 +1,15 @@
1999-06-19 Michael Hanni <mhanni@sprintmail.com>
* Images/common_Nibble.tiff: made inner gray area transparent.
* Source/NSTabView.m: new file. implemented, save for drawing and
event.
* Source/NSTabViewItem.m: new file. implemented, save for drawing
and event.
TabView should be fun to get drawing. :-) I'm going to follow
Alfredo's lead by using a few drawn lines instead of bezier curves to draw
the tabs for now (since xgps doesn't do bezier).
1999-06-18 Michael Hanni <mhanni@sprintmail.com>
* Images/common_Nibble.tiff: new image for NSPopUpButton.

View file

@ -0,0 +1,93 @@
/*
NSTabView.h
Copyright (C) 1996 Free Software Foundation, Inc.
Author: Michael Hanni <mhanni@sprintmail.com>
Date: 1999
This file is part of the GNUstep GUI Library.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library 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
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; see the file COPYING.LIB.
If not, write to the Free Software Foundation,
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#ifndef _GNUstep_H_NSTabView
#define _GNUstep_H_NSTabView
#include <AppKit/NSView.h>
typedef enum {
NSTopTabsBezelBorder,
NSNoTabsBezelBorder,
NSNoTabsLineBorder,
NSNoTabsNoBorder
} NSTabViewType;
@class NSFont;
@class NSTabViewItem;
@interface NSTabView : NSView <NSCoding>
{
NSMutableArray *tab_items;
NSFont *tab_font;
NSTabViewType tab_type;
BOOL tab_draws_background;
BOOL tab_truncated_label;
id tab_delegate;
int tab_selected_item;
}
- (void)addTabViewItem:(NSTabViewItem *)tabViewItem;
- (void)insertTabViewItem:(NSTabViewItem *)tabViewItem
atIndex:(int)index;
- (void)removeTabViewItem:(NSTabViewItem *)tabViewItem;
- (int)indexOfTabViewItem:(NSTabViewItem *)tabViewItem;
- (int)indexOfTabViewItemWithIdentifier:(id)identifier;
- (int)numberOfTabViewItems;
- (NSTabViewItem *)tabViewItemAtIndex:(int)index;
- (NSArray *)tabViewItems;
- (void)selectFirstTabViewItem:(id)sender;
- (void)selectLastTabViewItem:(id)sender;
- (void)selectNextTabViewItem:(id)sender;
- (void)selectPreviousTabViewItem:(id)sender;
- (void)selectTabViewItem:(NSTabViewItem *)tabViewItem;
- (void)selectTabViewItemAtIndex:(int)index;
- (void)takeSelectedTabViewItemFromSender:(id)sender;
- (void)setFont:(NSFont *)font;
- (NSFont *)font;
- (void)setTabViewType:(NSTabViewType)tabViewType;
- (NSTabViewType)tabViewType;
- (void)setDrawsBackground:(BOOL)flag;
- (BOOL)drawsBackground;
- (void)setAllowsTruncatedLabels:(BOOL)allowTruncatedLabels;
- (BOOL)allowsTruncatedLabels;
- (void)setDelegate:(id)anObject;
- (id)delegate;
- (NSSize)minimumSize;
- (NSRect)contentRect;
- (NSTabViewItem *)tabViewItemAtPoint:(NSPoint)point;
@end
#endif // _GNUstep_H_NSTabView

View file

@ -0,0 +1,78 @@
/*
NSTabViewItem.h
Copyright (C) 1996 Free Software Foundation, Inc.
Author: Michael Hanni <mhanni@sprintmail.com>
Date: 1999
This file is part of the GNUstep GUI Library.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library 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
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; see the file COPYING.LIB.
If not, write to the Free Software Foundation,
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#ifndef _GNUstep_H_NSTabViewItem
#define _GNUstep_H_NSTabViewItem
#include <AppKit/NSTabView.h>
typedef enum {
NSSelectedTab,
NSBackgroundTab,
NSPressedTab
} NSTabState;
@class NSColor;
@interface NSTabViewItem : NSObject <NSCoding>
{
id item_ident;
NSString *item_label;
NSView *item_view;
NSColor *item_color;
NSTabState item_state;
NSTabView *item_tabview;
}
- (id) initWithIdentifier:(id)identifier;
- (void)setIdentifier:(id)identifier;
- (id)identifier;
- (void)setLabel:(NSString *)label;
- (NSString *)label;
- (NSSize)sizeOfLabel:(BOOL)shouldTruncateLabel;
- (void)setView:(NSView *)view;
- (NSView *)view;
- (void)setColor:(NSColor *)color;
- (NSColor *)color;
- (NSTabState)tabState;
- (NSTabView *)tabView;
- (void)setInitialFirstResponder:(NSView *)view;
- (id)initialFirstResponder;
- (void)drawLabel:(BOOL)shouldTruncateLabel
inRect:(NSRect)tabRect;
- (void) encodeWithCoder: (NSCoder*)aCoder;
- (id) initWithCoder: (NSCoder*)aDecoder;
@end
#endif // _GNUstep_H_NSTabViewItem

Binary file not shown.

View file

@ -102,6 +102,8 @@ NSSpellChecker.m \
NSSpellServer.m \
NSSplitView.m \
NSStringDrawing.m \
NSTabView.m \
NSTabViewItem.m \
NSText.m \
NSTextContainer.m \
NSTextField.m \
@ -198,6 +200,8 @@ AppKit/NSSpellProtocol.h \
AppKit/NSSpellServer.h \
AppKit/NSSplitView.h \
AppKit/NSStringDrawing.h \
AppKit/NSTabView.h \
AppKit/NSTabViewItem.h \
AppKit/NSText.h \
AppKit/NSTextAttachment.h \
AppKit/NSTextContainer.h \

View file

@ -118,7 +118,7 @@
list_items = [[NSPopUpButtonMatrix alloc] initWithFrame:frameRect];
is_up = NO;
pulls_down = flag;
selected_item = 2;
selected_item = 0;
return self;
}

194
Source/NSTabView.m Normal file
View file

@ -0,0 +1,194 @@
#include <AppKit/NSTabView.h>
@implementation NSTabView
- (id)initWithFrame:(NSRect)rect
{
[super initWithFrame:rect];
// setup variables
tab_items = [NSMutableArray new];
return self;
}
// tab management.
- (void)addTabViewItem:(NSTabViewItem *)tabViewItem
{
[tab_items insertObject:tabViewItem atIndex:[tab_items count]];
}
- (void)insertTabViewItem:(NSTabViewItem *)tabViewItem
atIndex:(int)index
{
[tab_items insertObject:tabViewItem atIndex:index];
}
- (void)removeTabViewItem:(NSTabViewItem *)tabViewItem
{
int i = [tab_items indexOfObject:tabViewItem];
if (i == -1)
return;
[tab_items removeObjectAtIndex:i];
}
- (int)indexOfTabViewItem:(NSTabViewItem *)tabViewItem
{
return [tab_items indexOfObject:tabViewItem];
}
- (int)indexOfTabViewItemWithIdentifier:(id)identifier
{
// the spec is confusing on this method.
return 0;
}
- (int)numberOfTabViewItems
{
return [tab_items count];
}
- (NSTabViewItem *)tabViewItemAtIndex:(int)index
{
return [tab_items objectAtIndex:index];
}
- (NSArray *)tabViewItems
{
return (NSArray *)tab_items;
}
- (void)selectFirstTabViewItem:(id)sender
{
[self selectTabViewItemAtIndex:0];
}
- (void)selectLastTabViewItem:(id)sender
{
[self selectTabViewItem:[tab_items lastObject]];
}
- (void)selectNextTabViewItem:(id)sender
{
[self selectTabViewItemAtIndex:tab_selected_item+1];
}
- (void)selectPreviousTabViewItem:(id)sender
{
[self selectTabViewItemAtIndex:tab_selected_item-1];
}
- (void)selectTabViewItem:(NSTabViewItem *)tabViewItem
{
}
- (void)selectTabViewItemAtIndex:(int)index
{
}
- (void)takeSelectedTabViewItemFromSender:(id)sender
{
}
- (void)setFont:(NSFont *)font
{
ASSIGN(tab_font, font);
}
- (NSFont *)font
{
return tab_font;
}
- (void)setTabViewType:(NSTabViewType)tabViewType
{
tab_type = tabViewType;
}
- (NSTabViewType)tabViewType
{
return tab_type;
}
- (void)setDrawsBackground:(BOOL)flag
{
tab_draws_background = flag;
}
- (BOOL) drawsBackground
{
return tab_draws_background;
}
- (void)setAllowsTruncatedLabels:(BOOL)allowTruncatedLabels
{
tab_truncated_label = allowTruncatedLabels;
}
- (BOOL)allowsTruncatedLabels
{
return tab_truncated_label;
}
- (void)setDelegate:(id)anObject
{
ASSIGN(tab_delegate, anObject);
}
- (id)delegate
{
return tab_delegate;
}
// content and size
- (NSSize)minimumSize
{
return NSZeroSize;
}
- (NSRect)contentRect
{
return NSZeroRect;
}
// Event handling.
- (NSTabViewItem *)tabViewItemAtPoint:(NSPoint)point
{
return nil;
}
// Coding.
- (void) encodeWithCoder: (NSCoder*)aCoder
{
[super encodeWithCoder: aCoder];
[aCoder encodeObject:tab_items];
[aCoder encodeObject:tab_font];
[aCoder encodeValueOfObjCType: @encode(NSTabViewType) at: &tab_type];
[aCoder encodeValueOfObjCType: @encode(BOOL) at: &tab_draws_background];
[aCoder encodeValueOfObjCType: @encode(BOOL) at: &tab_truncated_label];
[aCoder encodeObject:tab_delegate];
[aCoder encodeValueOfObjCType: "i" at: &tab_selected_item];
}
- (id) initWithCoder: (NSCoder*)aDecoder
{
[super initWithCoder: aDecoder];
[aDecoder decodeValueOfObjCType: @encode(id) at: &tab_items];
[aDecoder decodeValueOfObjCType: @encode(id) at: &tab_font];
[aDecoder decodeValueOfObjCType: @encode(NSTabViewType) at:&tab_type];
[aDecoder decodeValueOfObjCType: @encode(BOOL) at: &tab_draws_background];
[aDecoder decodeValueOfObjCType: @encode(BOOL) at: &tab_truncated_label];
[aDecoder decodeValueOfObjCType: @encode(id) at: &tab_delegate];
[aDecoder decodeValueOfObjCType: "i" at: &tab_selected_item];
return self;
}
@end

130
Source/NSTabViewItem.m Normal file
View file

@ -0,0 +1,130 @@
#include <AppKit/NSTabViewItem.h>
@implementation NSTabViewItem
- (id) initWithIdentifier:(id)identifier
{
[super init];
ASSIGN(item_ident, identifier);
return self;
}
// Set identifier.
- (void)setIdentifier:(id)identifier
{
ASSIGN(item_ident, identifier);
}
- (id)identifier
{
return item_ident;
}
// Set label for item.
- (void)setLabel:(NSString *)label
{
ASSIGN(item_label, label);
}
- (NSString *)label
{
return item_label;
}
- (NSSize)sizeOfLabel:(BOOL)shouldTruncateLabel
{
if (shouldTruncateLabel) {
} else {
}
return NSZeroSize;
}
// Set view to display when item is clicked.
- (void)setView:(NSView *)view
{
ASSIGN(item_view, view);
}
- (NSView *)view
{
return item_view;
}
// Set color of tab surface.
- (void)setColor:(NSColor *)color
{
ASSIGN(item_color, color);
}
- (NSColor *)color
{
return item_color;
}
// tab state
- (NSTabState)tabState
{
return item_state;
}
// Tab view, this is the "super" view.
- (NSTabView *)tabView
{
return item_tabview;
}
// First responder.
- (void)setInitialFirstResponder:(NSView *)view
{
}
- (id)initialFirstResponder
{
return nil;
}
// Draw item.
- (void)drawLabel:(BOOL)shouldTruncateLabel
inRect:(NSRect)tabRect
{
// Implement in backend?
}
// NSCoding protocol.
- (void) encodeWithCoder: (NSCoder*)aCoder
{
[super encodeWithCoder: aCoder];
[aCoder encodeObject:item_ident];
[aCoder encodeObject:item_label];
[aCoder encodeObject:item_view];
[aCoder encodeObject:item_color];
[aCoder encodeValueOfObjCType: @encode(NSTabState) at: &item_state];
[aCoder encodeObject:item_tabview];
}
- (id) initWithCoder: (NSCoder*)aDecoder
{
[super initWithCoder: aDecoder];
[aDecoder decodeValueOfObjCType: @encode(id) at: &item_ident];
[aDecoder decodeValueOfObjCType: @encode(id) at: &item_label];
[aDecoder decodeValueOfObjCType: @encode(id) at: &item_view];
[aDecoder decodeValueOfObjCType: @encode(id) at: &item_color];
[aDecoder decodeValueOfObjCType: @encode(NSTabState) at:&item_state];
[aDecoder decodeValueOfObjCType: @encode(id) at: &item_tabview];
return self;
}
@end