Added new MacOSX classes.

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@19693 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Fred Kiefer 2004-07-07 22:43:04 +00:00
parent 5db71a9678
commit 605f60b151
7 changed files with 717 additions and 0 deletions

View file

@ -46,6 +46,7 @@ libgnustep-gui_C_FILES =
libgnustep-gui_OBJC_FILES = Functions.m \
NSActionCell.m \
NSAffineTransform.m \
NSAlert.m \
NSApplication.m \
NSAttributedString.m \
NSBezierPath.m \
@ -103,6 +104,8 @@ NSMenu.m \
NSMenuView.m \
NSMenuItem.m \
NSMenuItemCell.m \
NSMovie.m \
NSMovieView.m \
NSNib.m \
NSOpenGLContext.m \
NSOpenGLPixelFormat.m \
@ -208,6 +211,7 @@ AppKitDefines.h \
AppKitExceptions.h \
NSActionCell.h \
NSAffineTransform.h \
NSAlert.h \
NSApplication.h \
NSBezierPath.h \
NSBox.h \
@ -259,6 +263,8 @@ NSMenu.h \
NSMenuItem.h \
NSMenuItemCell.h \
NSMenuView.h \
NSMovie.h \
NSMovieView.h \
NSOpenPanel.h \
NSOpenGL.h \
NSOpenGLView.h \

238
Source/NSAlert.m Normal file
View file

@ -0,0 +1,238 @@
/** <title>NSAlert</title>
<abstract>Encapsulate an alert panel</abstract>
Copyright <copy>(C) 2004 Free Software Foundation, Inc.</copy>
Author: Fred Kiefer <FredKiefer@gmx.de>
Date: July 2004
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.
*/
#include "config.h"
#include <Foundation/NSString.h>
#include "AppKit/NSAlert.h"
#include "AppKit/NSPanel.h"
#include "AppKit/NSButton.h"
#include "AppKit/NSImage.h"
@implementation NSAlert
/*
* Class methods
*/
+ (void)initialize
{
if (self == [NSAlert class])
{
[self setVersion: 1];
}
}
+ (NSAlert *)alertWithMessageText:(NSString *)messageTitle
defaultButton:(NSString *)defaultButtonTitle
alternateButton:(NSString *)alternateButtonTitle
otherButton:(NSString *)otherButtonTitle
informativeTextWithFormat:(NSString *)format, ...
{
va_list ap;
NSAlert *alert = [[self alloc] init];
NSString *text;
va_start(ap, format);
if (format != nil)
{
text = [[NSString alloc] initWithFormat: format arguments: ap];
[alert setInformativeText: text];
RELEASE(text);
}
va_end(ap);
[alert setMessageText: messageTitle];
if (defaultButtonTitle != nil)
{
[alert addButtonWithTitle: defaultButtonTitle];
}
else
{
[alert addButtonWithTitle: _(@"OK")];
}
if (alternateButtonTitle != nil)
{
[alert addButtonWithTitle: alternateButtonTitle];
}
if (otherButtonTitle != nil)
{
[alert addButtonWithTitle: otherButtonTitle];
}
return AUTORELEASE(alert);
}
- (id) init
{
_buttons = [[NSMutableArray alloc] init];
_style = NSWarningAlertStyle;
return self;
}
- (void) dealloc
{
RELEASE(_informative_text);
RELEASE(_message_text);
RELEASE(_icon);
RELEASE(_buttons);
RELEASE(_help_anchor);
RELEASE(_window);
[super dealloc];
}
- (void)setInformativeText:(NSString *)informativeText
{
ASSIGN(_informative_text, informativeText);
}
- (NSString *)informativeText
{
return _informative_text;
}
- (void)setMessageText:(NSString *)messageText
{
ASSIGN(_message_text, messageText);
}
- (NSString *)messageText
{
return _message_text;
}
- (void)setIcon:(NSImage *)icon
{
ASSIGN(_icon, icon);
}
- (NSImage *)icon
{
return _icon;
}
- (NSButton *)addButtonWithTitle:(NSString *)aTitle
{
NSButton *button = [[NSButton alloc] init];
int count = [_buttons count];
[button setTitle: aTitle];
[button setAutoresizingMask: NSViewMinXMargin | NSViewMaxYMargin];
[button setButtonType: NSMomentaryPushButton];
[button setTarget: self];
[button setAction: @selector(buttonAction: )];
[button setFont: [NSFont systemFontOfSize: 0]];
if (count == 0)
{
[button setTag: NSAlertFirstButtonReturn];
[button setKeyEquivalent: @"\r"];
}
else
{
[button setTag: NSAlertFirstButtonReturn + count];
if ([aTitle isEqualToString: @"Cancel"])
{
[button setKeyEquivalent: @"\e"];
}
else if ([aTitle isEqualToString: @"Don't Save"])
{
[button setKeyEquivalent: @"D"];
[button setKeyEquivalentModifierMask: NSCommandKeyMask];
}
}
[_buttons addObject: button];
RELEASE(button);
return button;
}
- (NSArray *)buttons
{
return _buttons;
}
- (void)setShowsHelp:(BOOL)showsHelp
{
_shows_help = showsHelp;
}
- (BOOL)showsHelp
{
return _shows_help;
}
- (void)setHelpAnchor:(NSString *)anchor
{
ASSIGN(_help_anchor, anchor);
}
- (NSString *)helpAnchor
{
return _help_anchor;
}
- (void)setAlertStyle:(NSAlertStyle)style
{
_style = style;
}
- (NSAlertStyle)alertStyle
{
return _style;
}
- (void)setDelegate:(id)delegate
{
_delegate = delegate;
}
- (id)delegate
{
return _delegate;
}
- (int)runModal
{
// FIXME
return NSAlertFirstButtonReturn;
}
- (void)beginSheetModalForWindow:(NSWindow *)window
modalDelegate:(id)delegate
didEndSelector:(SEL)didEndSelector
contextInfo:(void *)contextInfo
{
// FIXME
}
- (id)window
{
return _window;
}
@end

163
Source/NSMovie.m Normal file
View file

@ -0,0 +1,163 @@
/** <title>NSMovie</title>
<abstract>Encapsulate a Quicktime movie</abstract>
Copyright <copy>(C) 2003 Free Software Foundation, Inc.</copy>
Author: Fred Kiefer <FredKiefer@gmx.de>
Date: March 2003
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.
*/
#include <Foundation/NSArray.h>
#include <Foundation/NSCoder.h>
#include <Foundation/NSData.h>
#include <Foundation/NSURL.h>
#include <AppKit/NSMovie.h>
#include <AppKit/NSPasteboard.h>
@implementation NSMovie
+ (NSArray*) movieUnfilteredFileTypes
{
return [NSArray arrayWithObject: @"mov"];
}
+ (NSArray*) movieUnfilteredPasteboardTypes
{
// FIXME
return [NSArray arrayWithObject: @"QuickTimeMovie"];
}
+ (BOOL) canInitWithPasteboard: (NSPasteboard*)pasteboard
{
NSArray *pbTypes = [pasteboard types];
NSArray *myTypes = [self movieUnfilteredPasteboardTypes];
return ([pbTypes firstObjectCommonWithArray: myTypes] != nil);
}
- (id) initWithData: (NSData *)movie
{
if (movie == nil)
{
RELEASE(self);
return nil;
}
[super init];
ASSIGN(_movie, movie);
return self;
}
- (id) initWithMovie: (void*)movie
{
//FIXME
return self;
}
- (id) initWithURL: (NSURL*)url byReference: (BOOL)byRef
{
NSData* data = [url resourceDataUsingCache: YES];
self = [self initWithData: data];
if (byRef)
{
ASSIGN(_url, url);
}
return self;
}
- (id) initWithPasteboard: (NSPasteboard*)pasteboard
{
NSString *type;
NSData* data;
type = [pasteboard availableTypeFromArray:
[isa movieUnfilteredPasteboardTypes]];
if (type == nil)
{
//NSArray *array = [pasteboard propertyListForType: NSFilenamesPboardType];
// FIXME
data = nil;
}
else
{
data = [pasteboard dataForType: type];
}
if (data == nil)
{
RELEASE(self);
return nil;
}
self = [self initWithData: data];
return self;
}
- (void) dealloc
{
TEST_RELEASE(_url);
TEST_RELEASE(_movie);
[super dealloc];
}
- (void*) QTMovie
{
return (void*)[_movie bytes];
}
- (NSURL*) URL
{
return _url;
}
// NSCopying protocoll
- (id) copyWithZone: (NSZone *)zone
{
NSMovie *new = (NSMovie*)NSCopyObject (self, 0, zone);
new->_movie = [_movie copyWithZone: zone];
new->_url = [_url copyWithZone: zone];
return new;
}
// NSCoding protocoll
- (void) encodeWithCoder: (NSCoder*)aCoder
{
[aCoder encodeObject: _movie];
[aCoder encodeObject: _url];
}
- (id) initWithCoder: (NSCoder*)aDecoder
{
ASSIGN (_movie, [aDecoder decodeObject]);
ASSIGN (_url, [aDecoder decodeObject]);
return self;
}
@end