* NSWindow.h change window style enum to match WindowMaker's definition.

* GNUAlertPanel.m NSGetAlertPanel() replace centering code with call to
	center method, change window style mask, add class initialize.
	* libgnustep-gui.m rename to Functions.m.
	* Functions.m add new file as location for generic NS* and GS* functions,
	move backend NSEventMaskFromType() into it.
	* NSApplication.m discardEventsMatchingMask:.. rewrite (fix bugs),
	runModalSession: dump all events not for modal window (fixes modal panel
	button display bug), arrangeInFront: preliminary implemenation.
	* NSCell.m: Polish.
	* NSWindow.m: center remove display invocation per 4.2 docs.


git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@3426 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
far 1998-12-10 18:07:24 +00:00
parent 520320cf92
commit d1b08f9835
8 changed files with 225 additions and 219 deletions

View file

@ -1,3 +1,17 @@
Thu Dec 10 1998 Felipe A. Rodriguez <far@ix.netcom.com>
* NSWindow.h change window style enum to match WindowMaker's definition.
* GNUAlertPanel.m NSGetAlertPanel() replace centering code with call to
center method, change window style mask, add class initialize.
* libgnustep-gui.m rename to Functions.m.
* Functions.m add new file as location for generic NS* and GS* functions,
move backend NSEventMaskFromType() into it.
* NSApplication.m discardEventsMatchingMask:.. rewrite (fix bugs),
runModalSession: dump all events not for modal window (fixes modal panel
button display bug), arrangeInFront: preliminary implemenation.
* NSCell.m: Polish.
* NSWindow.m: center remove display invocation per 4.2 docs.
Wed Dec 9 1998 Felipe A. Rodriguez <far@ix.netcom.com> Wed Dec 9 1998 Felipe A. Rodriguez <far@ix.netcom.com>
* NSView.m resizeWithOldSuperviewSize: revert to previous code and add bug * NSView.m resizeWithOldSuperviewSize: revert to previous code and add bug

View file

@ -54,19 +54,19 @@
@class NSScreen; @class NSScreen;
enum { enum {
NSNormalWindowLevel = 0, NSNormalWindowLevel = 0,
NSFloatingWindowLevel = 3, NSFloatingWindowLevel = 3,
NSDockWindowLevel = 5, NSDockWindowLevel = 5,
NSSubmenuWindowLevel = 10, NSSubmenuWindowLevel = 10,
NSMainMenuWindowLevel = 20 NSMainMenuWindowLevel = 20
}; };
enum { enum {
NSBorderlessWindowMask = 1, NSBorderlessWindowMask = 0,
NSTitledWindowMask = 2, NSTitledWindowMask = 1,
NSClosableWindowMask = 4, NSClosableWindowMask = 2,
NSMiniaturizableWindowMask = 8, NSMiniaturizableWindowMask = 4,
NSResizableWindowMask = 16 NSResizableWindowMask = 8
}; };
extern NSSize NSIconSize; extern NSSize NSIconSize;

View file

@ -69,6 +69,16 @@ static GNUAlertPanel *reusableAlertPanel = nil;
@end @end
@implementation GNUAlertPanel @implementation GNUAlertPanel
//
// Class methods
//
+ (void)initialize
{
if (self == [GNUAlertPanel class])
[self setVersion:1];
}
- (void) buttonAction: (id)sender - (void) buttonAction: (id)sender
{ {
if (active == NO) if (active == NO)
@ -129,7 +139,7 @@ static GNUAlertPanel *reusableAlertPanel = nil;
if (self) if (self)
{ {
NSView *content; NSView *content;
unsigned bs = 8.0; /* Inter-button space */ unsigned bs = 10.0; /* Inter-button space */
unsigned bh = 24.0; /* Button height. */ unsigned bh = 24.0; /* Button height. */
unsigned bw = 72.0; /* Button width. */ unsigned bw = 72.0; /* Button width. */
NSRect rect; NSRect rect;
@ -373,25 +383,15 @@ NSGetAlertPanel(NSString *title,
return nil; return nil;
} }
#else #else
NSRect frame = [[NSScreen mainScreen] frame];
/*
* Center the panel in the screen.
*/
if (frame.size.width > PANX)
frame.origin.x += (frame.size.width - PANX)/2.0;
frame.size.width = PANX;
if (frame.size.height > PANY)
frame.origin.y += (frame.size.height - PANY)/2.0;
frame.size.height = PANY;
panel = [GNUAlertPanel alloc]; panel = [GNUAlertPanel alloc];
panel = [panel initWithContentRect: frame panel = [panel initWithContentRect:NSMakeRect(0,0,PANX,PANY)
styleMask: 0 styleMask: NSTitledWindowMask
backing: NSBackingStoreRetained backing: NSBackingStoreRetained
defer: YES defer: YES
screen: nil]; screen: nil];
[panel center];
#endif #endif
} }
else else

View file

@ -36,7 +36,7 @@ include ../Version
LIBRARY_NAME=libgnustep-gui LIBRARY_NAME=libgnustep-gui
# The Objective-C source files to be compiled # The Objective-C source files to be compiled
libgnustep-gui_OBJC_FILES = libgnustep-gui.m \ libgnustep-gui_OBJC_FILES = Functions.m \
GSContext.m \ GSContext.m \
NSActionCell.m \ NSActionCell.m \
NSApplication.m \ NSApplication.m \

View file

@ -67,7 +67,7 @@
// //
// Types // Types
// //
struct _NSModalSession { struct _NSModalSession {
int runState; int runState;
NSWindow *window; NSWindow *window;
NSModalSession previous; NSModalSession previous;
@ -96,13 +96,13 @@ static NSString *NSAbortModalException = @"NSAbortModalException";
// Initial version // Initial version
[self setVersion:1]; [self setVersion:1];
// So the application knows // So the application knows
gnustep_gui_app_is_in_dealloc = NO; // its within dealloc and gnustep_gui_app_is_in_dealloc = NO; // it's within dealloc and
} // can prevent -release } // can prevent -release
} // loops. } // loops.
+ (NSApplication *)sharedApplication + (NSApplication *)sharedApplication
{ // If the global application does { // If the global application does
if (!NSApp) // not exist yet then create it if (!NSApp) // not yet exist then create it
{ {
NSApp = [self alloc]; // Don't combine the following two NSApp = [self alloc]; // Don't combine the following two
[NSApp init]; // statements into one to avoid [NSApp init]; // statements into one to avoid
@ -362,12 +362,14 @@ unsigned i;
count = [event_queue count]; // that there is an count = [event_queue count]; // that there is an
for (i = 0; i < count; i++) // event. for (i = 0; i < count; i++) // event.
{ {
event = [event_queue objectAtIndex: i]; event = [event_queue objectAtIndex: 0];
if ([event window] == theSession->window) if ([event window] == theSession->window)
{ {
found = YES; found = YES;
break; break;
} }
else // dump events not for
[event_queue removeObjectAtIndex:0]; // the modal window
} }
if (found == NO) if (found == NO)
@ -515,22 +517,21 @@ unsigned i;
- (void)discardEventsMatchingMask:(unsigned int)mask - (void)discardEventsMatchingMask:(unsigned int)mask
beforeEvent:(NSEvent *)lastEvent beforeEvent:(NSEvent *)lastEvent
{ {
int i = 0, count; int i = 0, count, loop;
NSEvent* event = nil; NSEvent* event = nil;
BOOL match = NO; BOOL match;
// if queue contains
if ((count = [event_queue count])) // events check them
{
for (loop = 0; ((event != lastEvent) && (loop < count)); loop++)
{
event = [event_queue objectAtIndex:i]; // Get next event from
match = NO; // the events queue
count = [event_queue count]; if (mask == NSAnyEventMask) // the any event mask
event = [event_queue objectAtIndex:i]; match = YES; // matches all events
while((event != lastEvent) && (i < count))
{
if (mask == NSAnyEventMask) // any event is a match
match = YES;
else
{
if (event == null_event)
match = YES; // dump all null events
else else
{ {
switch([event type]) switch([event type])
{ {
case NSLeftMouseDown: case NSLeftMouseDown:
@ -604,14 +605,15 @@ BOOL match = NO;
break; break;
default: default:
match = NO;
break; break;
} } } // remove event from } } // remove event from
// the queue if it // the queue if it
if (match) // matched the mask if (match) // matched the mask
[event_queue removeObjectAtIndex:i]; [event_queue removeObjectAtIndex:i];
event = [event_queue objectAtIndex:++i]; // get the next event else // inc queue cntr only
}; // in the queue i++; // if not a match else
} // we will run off the
} // end of the queue
} }
- (NSEvent*)_eventMatchingMask:(unsigned int)mask dequeue:(BOOL)flag - (NSEvent*)_eventMatchingMask:(unsigned int)mask dequeue:(BOOL)flag
@ -848,7 +850,7 @@ BOOL done = NO;
} }
// //
// Hiding all windows // Hiding and arranging windows
// //
- (void)hide:sender - (void)hide:sender
{ {
@ -904,6 +906,14 @@ NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
object: self]; object: self];
} }
- (void)arrangeInFront:sender // preliminary FIX ME
{
int i, count;
// Tell windows to unhide
for (i = 0, count = [window_list count]; i < count; i++)
[[window_list objectAtIndex:i] orderFront:sender];
}
// //
// Managing windows // Managing windows
// //
@ -1077,10 +1087,6 @@ int i;
} }
} }
- (void)arrangeInFront:sender
{
}
- (void)changeWindowsItem:aWindow - (void)changeWindowsItem:aWindow
title:(NSString *)aString title:(NSString *)aString
filename:(BOOL)isFilename filename:(BOOL)isFilename

View file

@ -487,6 +487,7 @@ NSString* _string;
// Target and Action // Target and Action
// //
- (SEL)action { return NULL; } - (SEL)action { return NULL; }
- (void)setAction:(SEL)aSelector {}
- (BOOL)isContinuous { return cell_continuous; } - (BOOL)isContinuous { return cell_continuous; }
- (int)sendActionOn:(int)mask - (int)sendActionOn:(int)mask
@ -498,22 +499,14 @@ unsigned int previousMask = action_mask;
return previousMask; return previousMask;
} }
- (void)setAction:(SEL)aSelector
{}
- (void)setContinuous:(BOOL)flag - (void)setContinuous:(BOOL)flag
{ {
cell_continuous = flag; cell_continuous = flag;
[self sendActionOn:(NSLeftMouseUpMask|NSPeriodicMask)]; [self sendActionOn:(NSLeftMouseUpMask|NSPeriodicMask)];
} }
- (void)setTarget:(id)anObject - (void)setTarget:(id)anObject {}
{} - (id)target { return nil; }
- (id)target
{
return nil;
}
- (void)performClick:(id)sender - (void)performClick:(id)sender
{ {
@ -522,21 +515,13 @@ unsigned int previousMask = action_mask;
// //
// Assigning a Tag // Assigning a Tag
// //
- (void)setTag:(int)anInt - (void)setTag:(int)anInt {}
{} - (int)tag { return -1; }
- (int)tag
{
return -1;
}
// //
// Handling Keyboard Alternatives // Handling Keyboard Alternatives
// //
- (NSString *)keyEquivalent - (NSString *)keyEquivalent { return nil; }
{
return nil;
}
// //
// Tracking the Mouse // Tracking the Mouse
@ -582,7 +567,8 @@ unsigned int previousMask = action_mask;
{ {
NSApplication *theApp = [NSApplication sharedApplication]; NSApplication *theApp = [NSApplication sharedApplication];
unsigned int event_mask = NSLeftMouseDownMask | NSLeftMouseUpMask | unsigned int event_mask = NSLeftMouseDownMask | NSLeftMouseUpMask |
NSMouseMovedMask | NSLeftMouseDraggedMask | NSRightMouseDraggedMask; NSMouseMovedMask | NSLeftMouseDraggedMask |
NSRightMouseDraggedMask;
NSPoint location = [theEvent locationInWindow]; NSPoint location = [theEvent locationInWindow];
NSPoint point = [controlView convertPoint: location fromView: nil]; NSPoint point = [controlView convertPoint: location fromView: nil];
float delay, interval; float delay, interval;
@ -592,169 +578,171 @@ NSPoint last_point;
BOOL done; BOOL done;
BOOL mouseWentUp; BOOL mouseWentUp;
NSDebugLog(@"NSCell start tracking\n"); NSDebugLog(@"NSCell start tracking\n");
NSDebugLog(@"NSCell tracking in rect %f %f %f %f\n", NSDebugLog(@"NSCell tracking in rect %f %f %f %f\n",
cellFrame.origin.x, cellFrame.origin.y, cellFrame.origin.x, cellFrame.origin.y,
cellFrame.size.width, cellFrame.size.height); cellFrame.size.width, cellFrame.size.height);
NSDebugLog(@"NSCell initial point %f %f\n", point.x, point.y); NSDebugLog(@"NSCell initial point %f %f\n", point.x, point.y);
if (![self startTrackingAt: point inView: controlView]) if (![self startTrackingAt: point inView: controlView])
return NO; return NO;
if (![controlView mouse: point inRect: cellFrame]) if (![controlView mouse: point inRect: cellFrame])
return NO; // point is not in cell return NO; // point is not in cell
if ([theEvent type] == NSLeftMouseDown if ([theEvent type] == NSLeftMouseDown &&
&& (action_mask & NSLeftMouseDownMask)) (action_mask & NSLeftMouseDownMask))
[(NSControl*)controlView sendAction:action to:target]; [(NSControl*)controlView sendAction:action to:target];
if (cell_continuous) { if (cell_continuous)
[self getPeriodicDelay:&delay interval:&interval]; {
[NSEvent startPeriodicEventsAfterDelay:delay withPeriod:interval]; [self getPeriodicDelay:&delay interval:&interval];
event_mask |= NSPeriodicMask; [NSEvent startPeriodicEventsAfterDelay:delay withPeriod:interval];
} event_mask |= NSPeriodicMask;
}
// Get next mouse events until a mouse up is obtained NSDebugLog(@"NSCell get mouse events\n");
NSDebugLog(@"NSCell get mouse events\n"); mouseWentUp = NO;
mouseWentUp = NO; done = NO;
done = NO; while (!done) // Get next mouse
while (!done) { { // event until a mouse
NSEventType eventType; NSEventType eventType; // up is obtained
BOOL pointIsInCell; BOOL pointIsInCell;
last_point = point; last_point = point;
theEvent = [theApp nextEventMatchingMask:event_mask untilDate:nil theEvent = [theApp nextEventMatchingMask:event_mask
inMode:NSEventTrackingRunLoopMode dequeue:YES]; untilDate:nil
eventType = [theEvent type]; inMode:NSEventTrackingRunLoopMode
dequeue:YES];
eventType = [theEvent type];
if (eventType != NSPeriodic) { if (eventType != NSPeriodic)
location = [theEvent locationInWindow]; {
point = [controlView convertPoint: location fromView: nil]; location = [theEvent locationInWindow];
NSDebugLog(@"NSCell location %f %f\n", location.x, location.y); point = [controlView convertPoint: location fromView: nil];
NSDebugLog(@"NSCell point %f %f\n", point.x, point.y); NSDebugLog(@"NSCell location %f %f\n", location.x, location.y);
} NSDebugLog(@"NSCell point %f %f\n", point.x, point.y);
else }
NSDebugLog (@"got a periodic event"); else
NSDebugLog (@"got a periodic event");
// Point is not in cell
if (![controlView mouse: point inRect: cellFrame])
{
NSDebugLog(@"NSCell point not in cell frame\n");
// Point is not in cell pointIsInCell = NO; // Do we return now or
if (![controlView mouse: point inRect: cellFrame]) { // keep tracking?
NSDebugLog(@"NSCell point not in cell frame\n"); if (![[self class] prefersTrackingUntilMouseUp] && flag)
{
NSDebugLog(@"NSCell return immediately\n");
done = YES;
}
}
else
pointIsInCell = YES; // Point is in cell
pointIsInCell = NO; if (!done && ![self continueTracking:last_point // should continue
at:point // tracking?
inView:controlView])
{
NSDebugLog(@"NSCell stop tracking\n");
done = YES;
}
// Did the mouse go up?
if (eventType == NSLeftMouseUp)
{
NSDebugLog(@"NSCell mouse went up\n");
mouseWentUp = YES;
done = YES;
if ((action_mask & NSLeftMouseUpMask))
[(NSControl*)controlView sendAction:action to:target];
}
else
{
if (pointIsInCell && ((eventType == NSLeftMouseDragged
&& (action_mask & NSLeftMouseDraggedMask))
|| ((eventType == NSPeriodic)
&& (action_mask & NSPeriodicMask))))
[(NSControl*)controlView sendAction:action to:target];
}
}
// Tell ourselves to
[self stopTracking:last_point // stop tracking
at:point
inView:controlView
mouseIsUp:mouseWentUp];
// Do we return now or keep tracking if (cell_continuous)
if (![[self class] prefersTrackingUntilMouseUp] && flag) { [NSEvent stopPeriodicEvents];
NSDebugLog(@"NSCell return immediately\n"); // Return YES only if the mouse
done = YES; // went up within the cell
} if (mouseWentUp && [controlView mouse: point inRect: cellFrame])
} {
else NSDebugLog(@"NSCell mouse went up in cell\n");
pointIsInCell = YES; // Point is in cell return YES;
}
// should we continue tracking?
if (!done
&& ![self continueTracking:last_point at:point inView:controlView]) {
NSDebugLog(@"NSCell stop tracking\n");
done = YES;
}
// Did the mouse go up?
if (eventType == NSLeftMouseUp) {
NSDebugLog(@"NSCell mouse went up\n");
mouseWentUp = YES;
done = YES;
if ((action_mask & NSLeftMouseUpMask))
[(NSControl*)controlView sendAction:action to:target];
}
else {
if (pointIsInCell
&& ((eventType == NSLeftMouseDragged
&& (action_mask & NSLeftMouseDraggedMask))
|| ((eventType == NSPeriodic)
&& (action_mask & NSPeriodicMask))))
[(NSControl*)controlView sendAction:action to:target];
}
}
// Tell ourselves to stop tracking
[self stopTracking:last_point at:point
inView:controlView mouseIsUp:mouseWentUp];
if (cell_continuous)
[NSEvent stopPeriodicEvents];
// Return YES only if the mouse went up within the cell
if (mouseWentUp && [controlView mouse: point inRect: cellFrame]) {
NSDebugLog(@"NSCell mouse went up in cell\n");
return YES;
}
#if 1 #if 1
[controlView setNeedsDisplayInRect:cellFrame]; [controlView setNeedsDisplayInRect:cellFrame];
#endif #endif
// Otherwise return NO NSDebugLog(@"NSCell mouse did not go up in cell\n");
NSDebugLog(@"NSCell mouse did not go up in cell\n"); return NO; // Otherwise return NO
return NO;
} }
// //
// Managing the Cursor // Managing the Cursor
// //
- (void)resetCursorRect:(NSRect)cellFrame - (void)resetCursorRect:(NSRect)cellFrame inView:(NSView *)controlView
inView:(NSView *)controlView {
{} }
// //
// Comparing to Another NSCell // Comparing to Another NSCell
// //
- (NSComparisonResult)compare:(id)otherCell - (NSComparisonResult)compare:(id)otherCell
{ {
return 0; return 0;
} }
// //
// Using the NSCell to Represent an Object // Using the NSCell to Represent an Object
// //
- (id)representedObject - (id)representedObject { return represented_object; }
{
return represented_object;
}
- (void)setRepresentedObject:(id)anObject - (void)setRepresentedObject:(id)anObject
{ {
ASSIGN(represented_object, anObject); ASSIGN(represented_object, anObject);
} }
- (id)copyWithZone:(NSZone*)zone - (id)copyWithZone:(NSZone*)zone
{ {
NSCell* c = [[isa allocWithZone: zone] init]; NSCell* c = [[isa allocWithZone: zone] init];
c->contents = [[contents copy] retain]; c->contents = [[contents copy] retain];
ASSIGN(c->cell_image, cell_image); ASSIGN(c->cell_image, cell_image);
ASSIGN(c->cell_font, cell_font); ASSIGN(c->cell_font, cell_font);
c->cell_state = cell_state; c->cell_state = cell_state;
c->cell_highlighted = cell_highlighted; c->cell_highlighted = cell_highlighted;
c->cell_enabled = cell_enabled; c->cell_enabled = cell_enabled;
c->cell_editable = cell_editable; c->cell_editable = cell_editable;
c->cell_bordered = cell_bordered; c->cell_bordered = cell_bordered;
c->cell_bezeled = cell_bezeled; c->cell_bezeled = cell_bezeled;
c->cell_scrollable = cell_scrollable; c->cell_scrollable = cell_scrollable;
c->cell_selectable = cell_selectable; c->cell_selectable = cell_selectable;
[c setContinuous:cell_continuous]; [c setContinuous:cell_continuous];
c->cell_float_autorange = cell_float_autorange; c->cell_float_autorange = cell_float_autorange;
c->cell_float_left = cell_float_left; c->cell_float_left = cell_float_left;
c->cell_float_right = cell_float_right; c->cell_float_right = cell_float_right;
c->image_position = image_position; c->image_position = image_position;
c->cell_type = cell_type; c->cell_type = cell_type;
c->text_align = text_align; c->text_align = text_align;
c->entry_type = entry_type; c->entry_type = entry_type;
c->control_view = control_view; c->control_view = control_view;
c->cell_size = cell_size; c->cell_size = cell_size;
[c setRepresentedObject:represented_object]; [c setRepresentedObject:represented_object];
return c; return c;
} }
// //
@ -816,10 +804,9 @@ BOOL mouseWentUp;
// //
@implementation NSCell (GNUstepBackend) @implementation NSCell (GNUstepBackend)
// Returns the size of a border
+ (NSSize)sizeForBorderType:(NSBorderType)aType + (NSSize)sizeForBorderType:(NSBorderType)aType
{ { // Returns the size of a
return NSZeroSize; return NSZeroSize; // border
} }
@end @end

View file

@ -357,15 +357,14 @@ static id MB_NSCONTROL_CELL_CLASS = nil;
return [cell isContinuous]; return [cell isContinuous];
} }
- (BOOL)sendAction:(SEL)theAction - (BOOL)sendAction:(SEL)theAction to:(id)theTarget
to:(id)theTarget
{ {
NSApplication *theApp = [NSApplication sharedApplication]; NSApplication *theApp = [NSApplication sharedApplication];
if (theAction && theTarget) if (theAction && theTarget)
return [theApp sendAction:theAction to:theTarget from:self]; return [theApp sendAction:theAction to:theTarget from:self];
else else
return NO; return NO;
} }
- (int)sendActionOn:(int)mask - (int)sendActionOn:(int)mask

View file

@ -420,11 +420,11 @@ NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
- (void)center - (void)center
{ {
NSSize screenSize = [[NSScreen mainScreen] frame].size; NSSize screenSize = [[NSScreen mainScreen] frame].size;
NSRect n = frame; // center the window NSPoint origin = frame.origin; // center the window
// within it's screen // within it's screen
n.origin.x = (screenSize.width - frame.size.width) / 2; origin.x = (screenSize.width - frame.size.width) / 2;
n.origin.y = (screenSize.height - frame.size.height) / 2; origin.y = (screenSize.height - frame.size.height) / 2;
[self setFrame:n display:YES]; [self setFrameOrigin:origin];
} }
- (NSRect)constrainFrameRect:(NSRect)frameRect toScreen:screen - (NSRect)constrainFrameRect:(NSRect)frameRect toScreen:screen