From ae0a552cc038dbb65eb433aba282e193e075643c Mon Sep 17 00:00:00 2001 From: fredkiefer Date: Fri, 17 Aug 2012 13:16:12 +0000 Subject: [PATCH] Merged changes from gnustep_testplant_branch branch and cleaned them up a bit. git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@35417 72102866-910b-0410-8b05-ffd578937521 --- ChangeLog | 56 ++++++++++++++++ ColorPickers/GSNamedColorPicker.m | 2 +- ColorPickers/GSStandardColorPicker.h | 4 +- Headers/AppKit/NSControl.h | 19 ++++-- Headers/AppKit/NSFontPanel.h | 3 +- Headers/AppKit/NSSavePanel.h | 25 +++++++ Headers/AppKit/NSTextField.h | 7 +- Source/NSImage.m | 17 ++--- Source/NSSavePanel.m | 7 +- Source/NSScreen.m | 8 +++ Source/NSTextField.m | 4 +- Source/NSWindow.m | 97 +++++++++++++++++++++++----- 12 files changed, 209 insertions(+), 40 deletions(-) diff --git a/ChangeLog b/ChangeLog index bb4f90a3a..7419f8482 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,59 @@ +2012-08-17 Fred Kiefer + + Merged changes from gnustep_testplant_branch branch. + + * Source/NSImage.m (-initWithCoder:): Adopt to coding standard. + * Source/NSScreen.m (-description): Simplify code. + * Source/NSWindow.m (-screen): Only recompute the screen if the + frame isn't fully covered by the current screen. + * Headers/AppKit/NSFontPanel.h: Import NSTextField to have the + NSTextFieldDelegate protocol defined. + * Headers/AppKit/NSControl.h: remove the three now duplicated + methods from NSControlTextEditingDelegate. + +2012-08-14 Marcian Lytwyn + + * Source/NSImage.m (-initWithCoder:): Fix bug in last commit. + * Source/NSWindow.m (- +2012-06-28 Marcian Lytwyn + + * ColorPickers/GSNamedColorPicker.m + GSNamedColorPicker needs to conform to NSTtextFieldDelegate + * ColorPickers/GSStandardColorPicker.h + GSStandardCSColorPicker needs to conform to NSTextFieldDelegate + +2012-06-27 Marcian Lytwyn + + * Source/NSWindow.m - Fix [NSWindow screen] method according + to documented behavior (return screen that window show up + the most or nil). Fix [NSWindow setFrameFromString] to account for + possible nil screen on input frame and throw window on main screen + in this case. This is to fix an issue with windows not properly + showing up when moved to another monitor during multi-monitor + usage and then the extra monitor(s) are removed. + * Source/NSScreen.m - Added -description method for more information. + +2012-06-27 Marcian Lytwyn + + *** NSOpenSavePanelDelegate *** + * Headers/AppKit/NSSavePanel.h - Added NSOpenSavePanelDelegate + protocol definition + * Source/NSSavePanel.m - Qualify delegate method(s) with + id + + *** NSControlTextEditingDelegate *** + * Headers/AppKit/NSControl.h - Added NSControlTextEditingDelegate + protocol definition + * Headers/AppKit/NSTextField.h - Added NSTextFieldDelegate + protocol definition + * Source/NSTextField.m - Qualify delegate method(s) with + id + * Headers/AppKit/NSFontPanel.h - NSFontPanel assigns itself as a + delegate to a NSTextField object and must declare that it + conforms to NSTextFieldDelegate protocol. Added a forward + declaration for NSTextFieldDelegate and added NSTextFieldDelegate + on class interface definition. + 2012-08-10 Richard Frith-Macdonald * Source/NSColorList.m: diff --git a/ColorPickers/GSNamedColorPicker.m b/ColorPickers/GSNamedColorPicker.m index 41b475fb0..b652409a1 100644 --- a/ColorPickers/GSNamedColorPicker.m +++ b/ColorPickers/GSNamedColorPicker.m @@ -27,7 +27,7 @@ #import #import -@interface GSNamedColorPicker: NSColorPicker +@interface GSNamedColorPicker: NSColorPicker { NSView *baseView; NSComboBox *cb; diff --git a/ColorPickers/GSStandardColorPicker.h b/ColorPickers/GSStandardColorPicker.h index 196949469..5ff1a51e7 100644 --- a/ColorPickers/GSStandardColorPicker.h +++ b/ColorPickers/GSStandardColorPicker.h @@ -35,6 +35,8 @@ @class GSTable, NSSlider, NSTextField; @class NSBox, NSButtonCell, NSMatrix; +@protocol NSTextFieldDelegate; + @interface GSStandardColorPicker: NSColorPicker { GSTable *baseView; @@ -50,7 +52,7 @@ @end -@interface GSStandardCSColorPicker: NSColorPicker +@interface GSStandardCSColorPicker: NSColorPicker { GSTable *baseView;; diff --git a/Headers/AppKit/NSControl.h b/Headers/AppKit/NSControl.h index f50b35d57..aff702393 100644 --- a/Headers/AppKit/NSControl.h +++ b/Headers/AppKit/NSControl.h @@ -200,7 +200,13 @@ APPKIT_EXPORT NSString *NSControlTextDidChangeNotification; // // Methods Implemented by the Delegate // -@interface NSObject (NSControlDelegate) +@protocol NSControlTextEditingDelegate +#ifdef __OBJC2__ +@optional +#else +@end +@interface NSObject (NSControlTextEditingDelegate) +#endif - (BOOL) control: (NSControl *)control isValidObject:(id)object; - (BOOL) control: (NSControl *)control @@ -209,12 +215,6 @@ APPKIT_EXPORT NSString *NSControlTextDidChangeNotification; - (BOOL) control: (NSControl *)control textShouldEndEditing: (NSText *)fieldEditor; -- (void) controlTextDidBeginEditing: (NSNotification *)aNotification; - -- (void) controlTextDidEndEditing: (NSNotification *)aNotification; - -- (void) controlTextDidChange: (NSNotification *)aNotification; - - (BOOL) control: (NSControl *)control didFailToFormatString: (NSString *)string errorDescription: (NSString *)error; @@ -237,5 +237,10 @@ APPKIT_EXPORT NSString *NSControlTextDidChangeNotification; @end +@interface NSObject (NSControlDelegate) +- (void) controlTextDidBeginEditing: (NSNotification *)aNotification; +- (void) controlTextDidEndEditing: (NSNotification *)aNotification; +- (void) controlTextDidChange: (NSNotification *)aNotification; +@end #endif // _GNUstep_H_NSControl diff --git a/Headers/AppKit/NSFontPanel.h b/Headers/AppKit/NSFontPanel.h index 9c7d4cbd7..30627fa09 100644 --- a/Headers/AppKit/NSFontPanel.h +++ b/Headers/AppKit/NSFontPanel.h @@ -33,6 +33,7 @@ #import #import +#import // needed for NSTextFieldDelegate @class NSFont; @class NSView; @@ -55,7 +56,7 @@ enum { NSFPSizeBrowser }; -@interface NSFontPanel : NSPanel +@interface NSFontPanel : NSPanel { // Attributes NSFont *_panelFont; diff --git a/Headers/AppKit/NSSavePanel.h b/Headers/AppKit/NSSavePanel.h index 277d71d3f..05ad0897f 100644 --- a/Headers/AppKit/NSSavePanel.h +++ b/Headers/AppKit/NSSavePanel.h @@ -56,6 +56,31 @@ enum { NSFileHandlingPanelDiskButton, NSFileHandlingPanelDiskEjectButton }; + +@protocol NSOpenSavePanelDelegate +#ifdef __OBJC2__ +@optional +#else +@end +@interface NSObject (NSOpenSavePanelDelegate) +#endif +- (BOOL)panel:(id)sender shouldEnableURL:(NSURL*)url; +- (BOOL)panel:(id)sender validateURL:(NSURL*)url error:(NSError **)error; +- (void)panel:(id)sender didChangeToDirectoryURL:(NSURL*)url; +- (NSString *)panel:(id)sender userEnteredFilename:(NSString*)filename confirmed:(BOOL)flag; +- (void)panel:(id)sender willExpand:(BOOL)expand; +- (void)panelSelectionDidChange:(id)sender; + +// Deprecated in 10.6... +- (BOOL)panel:(id)sender isValidFilename:(NSString*)filename; +- (void)panel:(id)sender directoryDidChange:(NSString*)path; + - (NSComparisonResult)panel:(id)sender + compareFilename:(NSString*)name1 + with:(NSString*)name2 + caseSensitive:(BOOL)caseSensitive; +- (BOOL)panel:(id)sender shouldShowFilename:(NSString*)filename; +@end + @interface NSSavePanel : NSPanel { diff --git a/Headers/AppKit/NSTextField.h b/Headers/AppKit/NSTextField.h index 7eb0121c6..62ed04be0 100644 --- a/Headers/AppKit/NSTextField.h +++ b/Headers/AppKit/NSTextField.h @@ -40,6 +40,9 @@ @class NSText; @class NSCursor; +@protocol NSTextFieldDelegate +@end + @interface NSTextField : NSControl { // Attributes @@ -72,8 +75,8 @@ // // Assigning a Delegate // -- (void)setDelegate:(id)anObject; -- (id)delegate; +- (void)setDelegate:(id)anObject; +- (id)delegate; // // Modifying Graphic Attributes diff --git a/Source/NSImage.m b/Source/NSImage.m index 4468a5a76..1b5e5b3bb 100644 --- a/Source/NSImage.m +++ b/Source/NSImage.m @@ -1653,27 +1653,28 @@ static NSSize GSResolutionOfImageRep(NSImageRep *rep) reps = [coder decodeObjectForKey: @"NSReps"]; reps = [reps objectAtIndex: 0]; id rep = [reps objectAtIndex: 1]; - if([rep isKindOfClass:[NSImageRep class]]) + if ([rep isKindOfClass: [NSImageRep class]]) { [self addRepresentation: rep]; } else { - if([rep isKindOfClass:[NSURL class]]) + if ([rep isKindOfClass: [NSURL class]]) { - rep = [NSImageRep imageRepWithContentsOfURL:rep]; + NSURL *tmp = (NSURL*)rep; + rep = [NSImageRep imageRepWithContentsOfURL: rep]; // If we are unable to resolved the URL, try to get it from the // resources folder. - if(rep == nil) + if (rep == nil) { - NSString *fileName = [[rep absoluteString] lastPathComponent]; - NSString *path = [[NSBundle mainBundle] pathForImageResource:fileName]; - rep = [NSImageRep imageRepWithContentsOfFile:path]; + NSString *fileName = [[tmp absoluteString] lastPathComponent]; + NSString *path = [[NSBundle mainBundle] pathForImageResource: fileName]; + rep = [NSImageRep imageRepWithContentsOfFile: path]; } // If the representation was found, add it... - if(rep != nil) + if (rep != nil) { [self addRepresentation: rep]; } diff --git a/Source/NSSavePanel.m b/Source/NSSavePanel.m index f2670852e..53f616486 100644 --- a/Source/NSSavePanel.m +++ b/Source/NSSavePanel.m @@ -1407,7 +1407,12 @@ selectCellWithString: (NSString*)title } } -- (void) setDelegate: (id)aDelegate +- (id) delegate +{ + return [super delegate]; +} + +- (void) setDelegate: (id)aDelegate { if ([aDelegate respondsToSelector: @selector(panel:compareFilename:with:caseSensitive:)]) diff --git a/Source/NSScreen.m b/Source/NSScreen.m index 075f5e560..d00908791 100644 --- a/Source/NSScreen.m +++ b/Source/NSScreen.m @@ -258,6 +258,14 @@ static NSMutableArray *screenArray = nil; return _frame; } +- (NSString*) description +{ + return [NSString stringWithFormat: @"%@ number: %ld frame: %@", + [super description], (long)_screenNumber, + NSStringFromRect(_frame)]; +} + + /** *

* This method generates a dictionary containing information diff --git a/Source/NSTextField.m b/Source/NSTextField.m index 22281d324..4993f9b31 100644 --- a/Source/NSTextField.m +++ b/Source/NSTextField.m @@ -246,7 +246,7 @@ static Class textFieldCellClass; /**

Sets the delegate to anObject.

See Also: -delegate

*/ -- (void) setDelegate: (id)anObject +- (void) setDelegate: (id)anObject { if (_delegate) [nc removeObserver: _delegate name: nil object: self]; @@ -266,7 +266,7 @@ static Class textFieldCellClass; /**

Returns the delegate object.

See Also: -setDelegate:

*/ -- (id) delegate +- (id) delegate { return _delegate; } diff --git a/Source/NSWindow.m b/Source/NSWindow.m index 2881799af..793ffab5e 100644 --- a/Source/NSWindow.m +++ b/Source/NSWindow.m @@ -164,6 +164,7 @@ static GSWindowAnimationDelegate *animationDelegate; - (void) _lossOfKeyOrMainWindow; - (NSView *) _windowView; +- (NSScreen *) _screenForFrame: (NSRect)frame; @end @implementation NSWindow (GNUstepPrivate) @@ -378,12 +379,41 @@ has blocked and waited for events. { return _wv; } - + +/* Support method to properly implement the 'screen' method for NSWindow. + According to documentation the 'screen' method should return the screen + that the window "show up the most or nil". This method supports the 'screen' + method and internal requests for the correct 'screen' based on the + supplied frame request. +*/ +- (NSScreen *) _screenForFrame: (NSRect)frame +{ + NSInteger largest = 0; + NSArray *screens = [NSScreen screens]; + NSInteger index = 0; + NSScreen *theScreen = nil; + + for (index = 0; index < [screens count]; ++index) + { + NSScreen *screen = [screens objectAtIndex: index]; + NSRect sframe = [screen frame]; + NSRect iframe = NSIntersectionRect(frame, sframe); + NSInteger isize = NSWidth(iframe) * NSHeight(iframe); + if (isize > largest) + { + largest = isize; + theScreen = screen; + } + } + NSDebugLLog(@"NSWindow", @"%s: frame: %@ screen: %@ size: %ld\n", __PRETTY_FUNCTION__, + NSStringFromRect(frame), theScreen, (long)largest); + + return theScreen; +} + @end - - @interface NSMiniWindow : NSWindow @end @@ -1073,9 +1103,9 @@ many times. if (style == NSWindows95InterfaceStyle) { if([self canBecomeMainWindow]) - { - [self setMenu: [NSApp mainMenu]]; - } + { + [self setMenu: [NSApp mainMenu]]; + } } NSDebugLLog(@"NSWindow", @"NSWindow end of init\n"); @@ -2553,6 +2583,18 @@ many times. /** Returns the screen the window is on. */ - (NSScreen *) screen { + // Only recompute the screen if the current screen + // doesn't contain the whole window. + // FIXME: Containing half the window would be enough + if (_screen != nil) + { + NSRect sframe = [_screen frame]; + if (NSContainsRect(sframe, _frame)) + { + return _screen; + } + } + ASSIGN(_screen, [self _screenForFrame: _frame]); return _screen; } @@ -4603,6 +4645,7 @@ current key view.
NSRect sRect; NSRect fRect; int value; + NSScreen *screen; /* * Scan in the window frame (flipped coordinate system). @@ -4638,11 +4681,13 @@ current key view.
/* * Check that the window will come up on screen */ +#if 0 // Not valid since screen frame x/y values can be negative... if (fRect.origin.x + fRect.size.width < 0) { NSLog(@"Bad screen frame - window is off screen"); - return; + return; } +#endif // if toolbar is showing, adjust saved frame to add the toolbar back in if ([_toolbar isVisible]) @@ -4694,8 +4739,19 @@ current key view.
* The screen rectangle gives the area of the screen in which * the window could be placed (ie a rectangle excluding the dock). */ - nRect = [[self screen] visibleFrame]; - + screen = [self _screenForFrame: fRect]; + + // Check whether a portion is showing somewhere... + if (screen == nil) + { + // If the window doesn't show up on any screen then we need + // to move it so it can be seen and assign it to the main + // screen... + screen = [NSScreen mainScreen]; + NSDebugLLog(@"NSWindow", @"%s: re-assigning to main screen\n", __PRETTY_FUNCTION__); + } + nRect = [screen visibleFrame]; + /* * If the new screen drawable area has moved relative to the one in * which the window was saved, adjust the window position accordingly. @@ -4725,9 +4781,9 @@ current key view.
* If height of the window goes above the screen height, then adjust the window down. */ if ((fRect.size.height + fRect.origin.y) > nRect.size.height) - { - fRect.origin.y = nRect.size.height - fRect.size.height; - } + { + fRect.origin.y = nRect.size.height - fRect.size.height; + } } // FIXME: Is this check needed? @@ -4745,6 +4801,9 @@ current key view.
} } + // Make sure we are using the new screen we are applying to... + ASSIGN(_screen, screen); + /* * Set frame. */ @@ -4781,6 +4840,7 @@ current key view.
{ NSRect fRect; NSRect sRect; + NSString *autosaveString; fRect = _frame; @@ -4804,12 +4864,15 @@ current key view.
* the window could be placed (ie a rectangle excluding the dock). */ sRect = [[self screen] visibleFrame]; + autosaveString = [NSString stringWithFormat: @"%d %d %d %d %d %d % d %d ", + (int)fRect.origin.x, (int)fRect.origin.y, + (int)fRect.size.width, (int)fRect.size.height, + (int)sRect.origin.x, (int)sRect.origin.y, + (int)sRect.size.width, (int)sRect.size.height]; + NSDebugLLog(@"NSWindow", @"%s:autosaveName: %@ frame string: %@", __PRETTY_FUNCTION__, + _autosaveName, autosaveString); - return [NSString stringWithFormat: @"%d %d %d %d %d %d % d %d ", - (int)fRect.origin.x, (int)fRect.origin.y, - (int)fRect.size.width, (int)fRect.size.height, - (int)sRect.origin.x, (int)sRect.origin.y, - (int)sRect.size.width, (int)sRect.size.height]; + return autosaveString; } /*