From d79ed12b5cc601215d8b4b6825cdb1c846f906b9 Mon Sep 17 00:00:00 2001 From: cacaodev Date: Fri, 18 Sep 2009 13:28:30 +0200 Subject: [PATCH 01/10] Attached sheet implementation --- AppKit/CPApplication.j | 31 +++++ AppKit/CPPanel.j | 7 + AppKit/CPWindow/CPWindow.j | 168 +++++++++++++++++++----- AppKit/CPWindow/_CPDocModalWindowView.j | 50 +++++++ AppKit/CPWindow/_CPWindowView.j | 9 +- 5 files changed, 229 insertions(+), 36 deletions(-) create mode 100644 AppKit/CPWindow/_CPDocModalWindowView.j diff --git a/AppKit/CPApplication.j b/AppKit/CPApplication.j index 26aa821e6..626d36718 100644 --- a/AppKit/CPApplication.j +++ b/AppKit/CPApplication.j @@ -719,9 +719,40 @@ CPRunContinuesResponse = -1002; */ - (void)beginSheet:(CPWindow)aSheet modalForWindow:(CPWindow)aWindow modalDelegate:(id)aModalDelegate didEndSelector:(SEL)aDidEndSelector contextInfo:(id)aContextInfo { + var styleMask = [aSheet styleMask]; + if (!(styleMask & CPDocModalWindowMask)) + { + [CPException raise:CPInternalInconsistencyException reason:@"Currently only CPDocModalWindowMask style mask is supported for attached sheets"]; + return; + } + [aWindow _attachSheet:aSheet modalDelegate:aModalDelegate didEndSelector:aDidEndSelector contextInfo:aContextInfo]; } +- (void)endSheet:(CPWindow)sheet returnCode:(int)returnCode +{ + var count = [_windows count]; + + while (--count >= 0) + { + var aWindow = [_windows objectAtIndex:count]; + var context = aWindow._sheetContext; + + if (context != nil && context["sheet"] === sheet) + { + context["returnCode"] = returnCode; + [aWindow _detachSheetWindow]; + return; + } + } +} + +- (void)endSheet:(CPWindow)sheet +{ + [self endSheet:sheet returnCode:0]; +} + + - (CPArray)arguments { if(_fullArgsString != window.location.hash) diff --git a/AppKit/CPPanel.j b/AppKit/CPPanel.j index 65dc9b177..61480d50a 100644 --- a/AppKit/CPPanel.j +++ b/AppKit/CPPanel.j @@ -46,6 +46,13 @@ CPCancelButton = 0;
  • A panel can be made to work even when there's an attention panel on-screen. This permits actions within the panel to affect the attention panel.
  • */ + +/* + @global + @class CPWindow +*/ +CPDocModalWindowMask = 1 << 6; + @implementation CPPanel : CPWindow { BOOL _becomesKeyOnlyIfNeeded; diff --git a/AppKit/CPWindow/CPWindow.j b/AppKit/CPWindow/CPWindow.j index 7dc79c3ca..a341b0852 100644 --- a/AppKit/CPWindow/CPWindow.j +++ b/AppKit/CPWindow/CPWindow.j @@ -309,6 +309,8 @@ var CPWindowSaveImage = nil, BOOL _isFullPlatformWindow; _CPWindowFullPlatformWindowSession _fullPlatformWindowSession; + + CPDictionary _sheetContext; } /* @@ -439,7 +441,10 @@ CPTexturedBackgroundWindowMask else if (aStyleMask === CPBorderlessWindowMask) return _CPBorderlessWindowView; - + + else if (aStyleMask & CPDocModalWindowMask) + return _CPDocModalWindowView; + return _CPStandardWindowView; } @@ -1722,57 +1727,146 @@ CPTexturedBackgroundWindowMask */ } +- (void)_setFrame:(CGRect)aFrame delegate:(id)delegate duration:(int)duration curve:(CPAnimationCurve)curve +{ + var animation = [[_CPWindowFrameAnimation alloc] initWithWindow:self targetFrame:aFrame]; + [animation setDelegate:delegate]; + [animation setAnimationCurve:curve]; + [animation setDuration:duration]; + [animation startAnimation]; +} + /* @ignore */ - (void)_setAttachedSheetFrameOrigin { // Position the sheet above the contentRect. + var attachedSheet = [self attachedSheet]; var contentRect = [[self contentView] frame], - sheetFrame = CGRectMakeCopy([_attachedSheet frame]); + sheetFrame = CGRectMakeCopy([attachedSheet frame]); sheetFrame.origin.y = CGRectGetMinY(_frame) + CGRectGetMinY(contentRect); sheetFrame.origin.x = CGRectGetMinX(_frame) + FLOOR((CGRectGetWidth(_frame) - CGRectGetWidth(sheetFrame)) / 2.0); - [_attachedSheet setFrameOrigin:sheetFrame.origin]; -} - -/* @ignore */ -- (void)_animateAttachedSheet -{ -/* NSWindow *sheet = [sheetContext sheet]; - NSRect sheetFrame; - - [_sheetContext autorelease]; - _sheetContext=[sheetContext retain]; - - [self _setSheetOrigin]; - sheetFrame = [sheet frame]; - - [(NSWindowBackgroundView *)[sheet _backgroundView] setBorderType:NSButtonBorder]; - [[sheet contentView] setAutoresizesSubviews:NO]; - [[sheet contentView] setAutoresizingMask:NSViewNotSizable]; - -// [(NSWindowBackgroundView *)[sheet _backgroundView] cacheImageForAnimation]; - - [_attachedSheet setFrame:CPRectMake(CGRectGetMinX(sheetFrame), CGRectGetMinY(sheetFrame), CGRectGetWidth(sheetFrame), 0.0) display:YES]; - [sheet setFrame:NSMakeRect(sheetFrame.origin.x, NSMaxY([self frame]), sheetFrame.size.width, 0) display:YES]; - [self _setSheetOriginAndFront]; - - [sheet setFrame:sheetFrame display:YES animate:YES];*/ + [attachedSheet setFrameOrigin:sheetFrame.origin]; } /* @ignore */ - (void)_attachSheet:(CPWindow)aSheet modalDelegate:(id)aModalDelegate didEndSelector:(SEL)aDidEndSelector contextInfo:(id)aContextInfo { - // Set this as our attached sheet. - _attachedSheet = aSheet; + var sheetFrame = [aSheet frame]; + +// setup contexts + _sheetContext = {"sheet":aSheet, "modalDelegate":aModalDelegate, "endSelector":aDidEndSelector, "contextInfo":aContextInfo, "frame":CGRectMakeCopy(sheetFrame), "returnCode":-1, "opened": NO}; + + [self _attachSheetWindow:aSheet]; +} + +/* @ignore */ +- (void)_attachSheetWindow:(CPWindow)aSheet +{ + var sheetFrame = [aSheet frame], + frame = [self frame], + sheetContent = [aSheet contentView]; - // If a window is ever run as a sheet, then it's sheet bit is set to YES. +// Configure sheet. +// if ([aSheet styleMask] & CPHUDBackgroundWindowMask) +// [aSheet setMovableByWindowBackground:NO]; + + _sheetContext["autoresizingMask"] = [sheetContent autoresizingMask]; + [sheetContent setAutoresizingMask:CPViewMinYMargin]; + [sheetContent setAutoresizesSubviews:NO]; aSheet._isSheet = YES; + aSheet._parentView = self; - [self _setAttachedSheetFrameOrigin]; +// calculate start/end frames + var originx = frame.origin.x + FLOOR((frame.size.width - sheetFrame.size.width)/2); + var originy = frame.origin.y + [[self contentView] frame].origin.y; + var startFrame = CGRectMake(originx, originy , sheetFrame.size.width, 0); + var endFrame = CGRectMake(originx, originy ,sheetFrame.size.width,sheetFrame.size.height); + +// Notify the world we will open the sheet + [[CPNotificationCenter defaultCenter] postNotificationName:@"CPWindowWillBeginSheetNotification" object:self]; +// Start modal + [CPApp runModalForWindow:aSheet]; + +// Order front and animate the sheet +// aSheet._isAnimating = YES; + [aSheet orderFront:self]; + [aSheet setFrame:startFrame]; + _sheetContext["opened"] = YES; + + [aSheet _setFrame:endFrame delegate:self duration:0.3 curve:CPAnimationEaseOut]; + + // Should run the main loop here until _isAnimating = FALSE + [aSheet becomeKeyWindow]; +} + +/* @ignore */ +- (void)_detachSheetWindow +{ + var sheet = [self attachedSheet]; - // Place this window above ourselves. - [_platformWindow order:CPWindowAbove window:aSheet relativeTo:self]; +// End frame for animation + var startFrame = [sheet frame]; + var endFrame = CGRectMakeCopy(startFrame); + endFrame.size.height = 0; + +// Set the new frame in case the sheet have been resized + _sheetContext["frame"] = startFrame; + +// Autoresizing + var sheetContent = [sheet contentView]; + [sheetContent setAutoresizingMask:CPViewMinYMargin]; + [sheetContent setAutoresizesSubviews:NO]; + +// Start animation with delegate + _sheetContext["opened"] = NO; + + [sheet _setFrame:endFrame delegate:self duration:0.2 curve:CPAnimationLinear]; +} + +/* @ignore */ +- (void)animationDidEnd:(id)anim +{ + var sheet = _sheetContext["sheet"]; + if (anim._window != sheet) + return; + +// Retore autoresizing + var sheetContent = [sheet contentView]; + [sheetContent setAutoresizingMask:_sheetContext["autoresizingMask"]]; + [sheetContent setAutoresizesSubviews:YES]; + +// If we are opened return now + if (_sheetContext["opened"] == YES) + return; + +// Stop modal + [CPApp stopModal]; + +// Notify the world we closed the sheet + [[CPNotificationCenter defaultCenter] postNotificationName:@"CPWindowDidEndSheetNotification" object:self]; + +// check first if front ? + [sheet orderOut:self]; + +// Set the sheet frame to its last open state. + var lastFrame = _sheetContext["frame"]; + [sheet setFrame:lastFrame]; + +// Send didEndSelector + var delegate = _sheetContext["modalDelegate"]; + var endSelector = _sheetContext["endSelector"]; + if(delegate != nil && endSelector != nil) + objj_msgSend(_sheetContext["modalDelegate"], + _sheetContext["endSelector"], + sheet, + _sheetContext["returnCode"], + _sheetContext["contextInfo"]); + +// reset contexts + _sheetContext = nil; + sheet._parentView = nil; } /*! @@ -1780,7 +1874,10 @@ CPTexturedBackgroundWindowMask */ - (CPWindow)attachedSheet { - return _attachedSheet; + if (_sheetContext == nil) + return nil; + + return _sheetContext["sheet"]; } /*! @@ -2225,6 +2322,7 @@ function _CPWindowFullPlatformWindowSessionMake(aWindowView, aContentRect, hasSh @import "_CPWindowView.j" @import "_CPStandardWindowView.j" +@import "_CPDocModalWindowView.j" @import "_CPHUDWindowView.j" @import "_CPBorderlessWindowView.j" @import "_CPBorderlessBridgeWindowView.j" diff --git a/AppKit/CPWindow/_CPDocModalWindowView.j b/AppKit/CPWindow/_CPDocModalWindowView.j new file mode 100644 index 000000000..af233e84d --- /dev/null +++ b/AppKit/CPWindow/_CPDocModalWindowView.j @@ -0,0 +1,50 @@ + +@import "_CPWindowView.j" + +var _CPStandardWindowViewBodyBackgroundColor = nil; + +@implementation _CPDocModalWindowView : _CPWindowView +{ + CPView _bodyView; +} + ++ (CPColor)bodyBackgroundColor +{ + if (!_CPStandardWindowViewBodyBackgroundColor) + _CPStandardWindowViewBodyBackgroundColor = [CPColor colorWithWhite:0.96 alpha:1.0]; + + return _CPStandardWindowViewBodyBackgroundColor; +} + +- (id)initWithFrame:(CPRect)aFrame styleMask:(unsigned)aStyleMask +{ + self = [super initWithFrame:aFrame styleMask:aStyleMask]; + + if (self) + { + var theClass = [self class], + bounds = [self bounds]; + + _bodyView = [[CPView alloc] initWithFrame:CGRectMake(0.0, 0.0, CGRectGetWidth(bounds), CGRectGetHeight(bounds))]; + + [_bodyView setAutoresizingMask:CPViewWidthSizable | CPViewHeightSizable]; + [_bodyView setBackgroundColor:[theClass bodyBackgroundColor]]; + [_bodyView setHitTests:NO]; + + [self addSubview:_bodyView]; + } + + return self; +} + +- (CGRect)contentRectForFrameRect:(CGRect)aFrameRect +{ + return aFrameRect; +} + +- (CGRect)frameRectForContentRect:(CGRect)aContentRect +{ + return aContentRect; +} + +@end \ No newline at end of file diff --git a/AppKit/CPWindow/_CPWindowView.j b/AppKit/CPWindow/_CPWindowView.j index 890044daa..5231016f6 100644 --- a/AppKit/CPWindow/_CPWindowView.j +++ b/AppKit/CPWindow/_CPWindowView.j @@ -135,7 +135,14 @@ var _CPWindowViewResizeIndicatorImage = nil; } else if (type === CPLeftMouseDragged) - [theWindow setFrameSize:CGSizeMake(CGRectGetWidth(_resizeFrame) + location.x - CGRectGetMinX(_resizeFrame), CGRectGetHeight(_resizeFrame) + location.y - CGRectGetMinY(_resizeFrame))]; + { + var newSize = CGSizeMake(CGRectGetWidth(_resizeFrame) + location.x - CGRectGetMinX(_resizeFrame), CGRectGetHeight(_resizeFrame) + location.y - CGRectGetMinY(_resizeFrame)); + + if (theWindow._isSheet && theWindow._parentView && (theWindow._frame.size.width !== newSize.width)) + [theWindow._parentView _setAttachedSheetFrameOrigin]; + + [theWindow setFrameSize:newSize]; + } [CPApp setTarget:self selector:@selector(trackResizeWithEvent:) forNextEventMatchingMask:CPLeftMouseDraggedMask | CPLeftMouseUpMask untilDate:nil inMode:nil dequeue:YES]; } From 570a2a56ffa25db172f2b2ab04b3ac74778eb7b7 Mon Sep 17 00:00:00 2001 From: cacaodev Date: Mon, 21 Sep 2009 22:05:42 +0200 Subject: [PATCH 02/10] Added sample app. Corrected style (tabs) --- AppKit/CPApplication.j | 42 +++--- AppKit/CPWindow/CPWindow.j | 129 +++++++++--------- AppKit/CPWindow/_CPDocModalWindowView.j | 8 +- Tests/AppKit/AttachedSheet/AppController.j | 84 ++++++++++++ Tests/AppKit/AttachedSheet/Info.plist | 12 ++ Tests/AppKit/AttachedSheet/Rakefile | 25 ++++ .../AttachedSheet/Resources/spinner.gif | Bin 0 -> 1849 bytes Tests/AppKit/AttachedSheet/index-debug.html | 83 +++++++++++ Tests/AppKit/AttachedSheet/index.html | 69 ++++++++++ Tests/AppKit/AttachedSheet/main.j | 18 +++ 10 files changed, 380 insertions(+), 90 deletions(-) create mode 100644 Tests/AppKit/AttachedSheet/AppController.j create mode 100644 Tests/AppKit/AttachedSheet/Info.plist create mode 100644 Tests/AppKit/AttachedSheet/Rakefile create mode 100644 Tests/AppKit/AttachedSheet/Resources/spinner.gif create mode 100644 Tests/AppKit/AttachedSheet/index-debug.html create mode 100644 Tests/AppKit/AttachedSheet/index.html create mode 100755 Tests/AppKit/AttachedSheet/main.j diff --git a/AppKit/CPApplication.j b/AppKit/CPApplication.j index 626d36718..72f88a420 100644 --- a/AppKit/CPApplication.j +++ b/AppKit/CPApplication.j @@ -719,32 +719,32 @@ CPRunContinuesResponse = -1002; */ - (void)beginSheet:(CPWindow)aSheet modalForWindow:(CPWindow)aWindow modalDelegate:(id)aModalDelegate didEndSelector:(SEL)aDidEndSelector contextInfo:(id)aContextInfo { - var styleMask = [aSheet styleMask]; - if (!(styleMask & CPDocModalWindowMask)) - { - [CPException raise:CPInternalInconsistencyException reason:@"Currently only CPDocModalWindowMask style mask is supported for attached sheets"]; - return; - } - + var styleMask = [aSheet styleMask]; + if (!(styleMask & CPDocModalWindowMask)) + { + [CPException raise:CPInternalInconsistencyException reason:@"Currently only CPDocModalWindowMask style mask is supported for attached sheets"]; + return; + } + [aWindow _attachSheet:aSheet modalDelegate:aModalDelegate didEndSelector:aDidEndSelector contextInfo:aContextInfo]; } - (void)endSheet:(CPWindow)sheet returnCode:(int)returnCode { - var count = [_windows count]; - - while (--count >= 0) - { - var aWindow = [_windows objectAtIndex:count]; - var context = aWindow._sheetContext; - - if (context != nil && context["sheet"] === sheet) - { - context["returnCode"] = returnCode; - [aWindow _detachSheetWindow]; - return; - } - } + var count = [_windows count]; + + while (--count >= 0) + { + var aWindow = [_windows objectAtIndex:count]; + var context = aWindow._sheetContext; + + if (context != nil && context["sheet"] === sheet) + { + context["returnCode"] = returnCode; + [aWindow _detachSheetWindow]; + return; + } + } } - (void)endSheet:(CPWindow)sheet diff --git a/AppKit/CPWindow/CPWindow.j b/AppKit/CPWindow/CPWindow.j index a341b0852..6019bd4f6 100644 --- a/AppKit/CPWindow/CPWindow.j +++ b/AppKit/CPWindow/CPWindow.j @@ -310,7 +310,7 @@ var CPWindowSaveImage = nil, BOOL _isFullPlatformWindow; _CPWindowFullPlatformWindowSession _fullPlatformWindowSession; - CPDictionary _sheetContext; + CPDictionary _sheetContext; } /* @@ -443,7 +443,7 @@ CPTexturedBackgroundWindowMask return _CPBorderlessWindowView; else if (aStyleMask & CPDocModalWindowMask) - return _CPDocModalWindowView; + return _CPDocModalWindowView; return _CPStandardWindowView; } @@ -1729,11 +1729,11 @@ CPTexturedBackgroundWindowMask - (void)_setFrame:(CGRect)aFrame delegate:(id)delegate duration:(int)duration curve:(CPAnimationCurve)curve { - var animation = [[_CPWindowFrameAnimation alloc] initWithWindow:self targetFrame:aFrame]; - [animation setDelegate:delegate]; - [animation setAnimationCurve:curve]; - [animation setDuration:duration]; - [animation startAnimation]; + var animation = [[_CPWindowFrameAnimation alloc] initWithWindow:self targetFrame:aFrame]; + [animation setDelegate:delegate]; + [animation setAnimationCurve:curve]; + [animation setDuration:duration]; + [animation startAnimation]; } /* @ignore */ @@ -1744,60 +1744,60 @@ CPTexturedBackgroundWindowMask var contentRect = [[self contentView] frame], sheetFrame = CGRectMakeCopy([attachedSheet frame]); - sheetFrame.origin.y = CGRectGetMinY(_frame) + CGRectGetMinY(contentRect); - sheetFrame.origin.x = CGRectGetMinX(_frame) + FLOOR((CGRectGetWidth(_frame) - CGRectGetWidth(sheetFrame)) / 2.0); + sheetFrame.origin.y = CGRectGetMinY(_frame) + CGRectGetMinY(contentRect); + sheetFrame.origin.x = CGRectGetMinX(_frame) + FLOOR((CGRectGetWidth(_frame) - CGRectGetWidth(sheetFrame)) / 2.0); - [attachedSheet setFrameOrigin:sheetFrame.origin]; + [attachedSheet setFrameOrigin:sheetFrame.origin]; } /* @ignore */ - (void)_attachSheet:(CPWindow)aSheet modalDelegate:(id)aModalDelegate didEndSelector:(SEL)aDidEndSelector contextInfo:(id)aContextInfo { - var sheetFrame = [aSheet frame]; + var sheetFrame = [aSheet frame]; // setup contexts - _sheetContext = {"sheet":aSheet, "modalDelegate":aModalDelegate, "endSelector":aDidEndSelector, "contextInfo":aContextInfo, "frame":CGRectMakeCopy(sheetFrame), "returnCode":-1, "opened": NO}; - - [self _attachSheetWindow:aSheet]; + _sheetContext = {"sheet":aSheet, "modalDelegate":aModalDelegate, "endSelector":aDidEndSelector, "contextInfo":aContextInfo, "frame":CGRectMakeCopy(sheetFrame), "returnCode":-1, "opened": NO}; + + [self _attachSheetWindow:aSheet]; } /* @ignore */ - (void)_attachSheetWindow:(CPWindow)aSheet { var sheetFrame = [aSheet frame], - frame = [self frame], - sheetContent = [aSheet contentView]; + frame = [self frame], + sheetContent = [aSheet contentView]; // Configure sheet. // if ([aSheet styleMask] & CPHUDBackgroundWindowMask) -// [aSheet setMovableByWindowBackground:NO]; +// [aSheet setMovableByWindowBackground:NO]; - _sheetContext["autoresizingMask"] = [sheetContent autoresizingMask]; + _sheetContext["autoresizingMask"] = [sheetContent autoresizingMask]; [sheetContent setAutoresizingMask:CPViewMinYMargin]; [sheetContent setAutoresizesSubviews:NO]; aSheet._isSheet = YES; aSheet._parentView = self; // calculate start/end frames - var originx = frame.origin.x + FLOOR((frame.size.width - sheetFrame.size.width)/2); - var originy = frame.origin.y + [[self contentView] frame].origin.y; - var startFrame = CGRectMake(originx, originy , sheetFrame.size.width, 0); - var endFrame = CGRectMake(originx, originy ,sheetFrame.size.width,sheetFrame.size.height); + var originx = frame.origin.x + FLOOR((frame.size.width - sheetFrame.size.width)/2); + var originy = frame.origin.y + [[self contentView] frame].origin.y; + var startFrame = CGRectMake(originx, originy, sheetFrame.size.width, 0); + var endFrame = CGRectMake(originx, originy, sheetFrame.size.width, sheetFrame.size.height); // Notify the world we will open the sheet [[CPNotificationCenter defaultCenter] postNotificationName:@"CPWindowWillBeginSheetNotification" object:self]; // Start modal - [CPApp runModalForWindow:aSheet]; - + [CPApp runModalForWindow:aSheet]; + // Order front and animate the sheet -// aSheet._isAnimating = YES; +// aSheet._isAnimating = YES; [aSheet orderFront:self]; [aSheet setFrame:startFrame]; _sheetContext["opened"] = YES; [aSheet _setFrame:endFrame delegate:self duration:0.3 curve:CPAnimationEaseOut]; - // Should run the main loop here until _isAnimating = FALSE + // Should run the main loop here until _isAnimating = FALSE [aSheet becomeKeyWindow]; } @@ -1812,61 +1812,60 @@ CPTexturedBackgroundWindowMask endFrame.size.height = 0; // Set the new frame in case the sheet have been resized - _sheetContext["frame"] = startFrame; - + _sheetContext["frame"] = startFrame; + // Autoresizing - var sheetContent = [sheet contentView]; + var sheetContent = [sheet contentView]; [sheetContent setAutoresizingMask:CPViewMinYMargin]; [sheetContent setAutoresizesSubviews:NO]; - + + _sheetContext["opened"] = NO; // Start animation with delegate - _sheetContext["opened"] = NO; - - [sheet _setFrame:endFrame delegate:self duration:0.2 curve:CPAnimationLinear]; + [sheet _setFrame:endFrame delegate:self duration:0.2 curve:CPAnimationLinear]; } /* @ignore */ - (void)animationDidEnd:(id)anim { - var sheet = _sheetContext["sheet"]; - if (anim._window != sheet) - return; + var sheet = _sheetContext["sheet"]; + if (anim._window != sheet) + return; // Retore autoresizing - var sheetContent = [sheet contentView]; - [sheetContent setAutoresizingMask:_sheetContext["autoresizingMask"]]; - [sheetContent setAutoresizesSubviews:YES]; + var sheetContent = [sheet contentView]; + [sheetContent setAutoresizingMask:_sheetContext["autoresizingMask"]]; + [sheetContent setAutoresizesSubviews:YES]; -// If we are opened return now - if (_sheetContext["opened"] == YES) - return; - +// If we are opened return now + if (_sheetContext["opened"] === YES) + return; + // Stop modal - [CPApp stopModal]; - + [CPApp stopModal]; + // Notify the world we closed the sheet - [[CPNotificationCenter defaultCenter] postNotificationName:@"CPWindowDidEndSheetNotification" object:self]; + [[CPNotificationCenter defaultCenter] postNotificationName:@"CPWindowDidEndSheetNotification" object:self]; // check first if front ? - [sheet orderOut:self]; + [sheet orderOut:self]; // Set the sheet frame to its last open state. - var lastFrame = _sheetContext["frame"]; - [sheet setFrame:lastFrame]; - -// Send didEndSelector - var delegate = _sheetContext["modalDelegate"]; - var endSelector = _sheetContext["endSelector"]; - if(delegate != nil && endSelector != nil) - objj_msgSend(_sheetContext["modalDelegate"], - _sheetContext["endSelector"], - sheet, - _sheetContext["returnCode"], - _sheetContext["contextInfo"]); - + var lastFrame = _sheetContext["frame"]; + [sheet setFrame:lastFrame]; + +// Send didEndSelector + var delegate = _sheetContext["modalDelegate"]; + var endSelector = _sheetContext["endSelector"]; + if (delegate != nil && endSelector != nil) + objj_msgSend(_sheetContext["modalDelegate"], + _sheetContext["endSelector"], + sheet, + _sheetContext["returnCode"], + _sheetContext["contextInfo"]); + // reset contexts - _sheetContext = nil; - sheet._parentView = nil; + _sheetContext = nil; + sheet._parentView = nil; } /*! @@ -1874,9 +1873,9 @@ CPTexturedBackgroundWindowMask */ - (CPWindow)attachedSheet { - if (_sheetContext == nil) - return nil; - + if (_sheetContext === nil) + return nil; + return _sheetContext["sheet"]; } diff --git a/AppKit/CPWindow/_CPDocModalWindowView.j b/AppKit/CPWindow/_CPDocModalWindowView.j index af233e84d..9db0ee9c7 100644 --- a/AppKit/CPWindow/_CPDocModalWindowView.j +++ b/AppKit/CPWindow/_CPDocModalWindowView.j @@ -5,7 +5,7 @@ var _CPStandardWindowViewBodyBackgroundColor = nil; @implementation _CPDocModalWindowView : _CPWindowView { - CPView _bodyView; + CPView _bodyView; } + (CPColor)bodyBackgroundColor @@ -22,9 +22,9 @@ var _CPStandardWindowViewBodyBackgroundColor = nil; if (self) { - var theClass = [self class], + var theClass = [self class], bounds = [self bounds]; - + _bodyView = [[CPView alloc] initWithFrame:CGRectMake(0.0, 0.0, CGRectGetWidth(bounds), CGRectGetHeight(bounds))]; [_bodyView setAutoresizingMask:CPViewWidthSizable | CPViewHeightSizable]; @@ -34,7 +34,7 @@ var _CPStandardWindowViewBodyBackgroundColor = nil; [self addSubview:_bodyView]; } - return self; + return self; } - (CGRect)contentRectForFrameRect:(CGRect)aFrameRect diff --git a/Tests/AppKit/AttachedSheet/AppController.j b/Tests/AppKit/AttachedSheet/AppController.j new file mode 100644 index 000000000..e40c804b6 --- /dev/null +++ b/Tests/AppKit/AttachedSheet/AppController.j @@ -0,0 +1,84 @@ +/* + * AppController.j + * AttachedSheet + * + * Created by Cacaodev on August 1, 2009. + * Copyright 2009, Your Company All rights reserved. + */ + +@import + +@implementation AppController : CPObject +{ + CPWindow window; + CPWindow sheet; + CPTextField textField; +} + +- (void)applicationDidFinishLaunching:(CPNotification)aNotification +{ + window = [[CPWindow alloc] initWithContentRect:CGRectMake(100,100,500,300) styleMask:CPResizableWindowMask], + contentView = [window contentView]; + + sheet = [[CPWindow alloc] initWithContentRect:CGRectMake(0,0,300,100) styleMask:CPDocModalWindowMask|CPResizableWindowMask]; + // [sheet setMinSize:CGSizeMake(300,100)]; + + var sheetContent = [sheet contentView]; + + textField = [[CPTextField alloc] initWithFrame:CGRectMake(10,30,280,30)]; + [textField setEditable:YES]; + [textField setBezeled:YES]; + [textField setAutoresizingMask:CPViewMinYMargin|CPViewWidthSizable]; + + var okButton = [[CPButton alloc] initWithFrame:CGRectMake(230,70,50,24)]; + [okButton setTitle:"OK"]; + [okButton setTarget:self]; + [okButton setTag:1]; + [okButton setAction:@selector(closeSheet:)]; + [okButton setAutoresizingMask:CPViewMinXMargin|CPViewMinYMargin]; + + var cancelButton = [[CPButton alloc] initWithFrame:CGRectMake(120,70,100,24)]; + [cancelButton setTitle:"Cancel"]; + [cancelButton setTarget:self]; + [cancelButton setTag:0]; + [cancelButton setAction:@selector(closeSheet:)]; + [cancelButton setAutoresizingMask:CPViewMinXMargin|CPViewMinYMargin]; + + [sheetContent addSubview:textField]; + [sheetContent addSubview:okButton]; + [sheetContent addSubview:cancelButton]; + + var displayButton = [[CPButton alloc] initWithFrame:CGRectMake(200,150,100,24)]; + [displayButton setTitle:"Display Sheet"]; + [displayButton setTarget:self]; + [displayButton setAction:@selector(displaySheet:)]; + + [contentView addSubview:displayButton]; + [window orderFront:self] +} + +- (void)displaySheet:(id)sender +{ + [textField setStringValue:""]; + [sheet makeFirstResponder:textField]; + + [CPApp beginSheet:sheet modalForWindow:window modalDelegate:self didEndSelector:@selector(didEndSheet:returnCode:contextInfo:) contextInfo:nil]; +} + +- (void)closeSheet:(id)sender +{ + [CPApp endSheet:sheet returnCode:[sender tag]]; +} + +- (void)didEndSheet:(CPWindow)sheet returnCode:(int)returnCode contextInfo:(id)contextInfo +{ + var str = [textField stringValue]; + + [sheet orderOut:self]; + if (returnCode == CPOKButton && [str length] > 0) + { + [window setTitle:str]; + } +} + +@end \ No newline at end of file diff --git a/Tests/AppKit/AttachedSheet/Info.plist b/Tests/AppKit/AttachedSheet/Info.plist new file mode 100644 index 000000000..143e86dbd --- /dev/null +++ b/Tests/AppKit/AttachedSheet/Info.plist @@ -0,0 +1,12 @@ + + + + + CPApplicationDelegateClass + AppController + CPBundleName + FullOfSheet + CPPrincipalClass + CPApplication + + diff --git a/Tests/AppKit/AttachedSheet/Rakefile b/Tests/AppKit/AttachedSheet/Rakefile new file mode 100644 index 000000000..3fc1dbfa1 --- /dev/null +++ b/Tests/AppKit/AttachedSheet/Rakefile @@ -0,0 +1,25 @@ + +require 'objective-j' +require 'objective-j/bundletask' + +if !ENV['CONFIG'] + ENV['CONFIG'] = 'Debug' +end + +ObjectiveJ::BundleTask.new(:SplitView) do |t| + t.name = 'SplitView' + t.identifier = 'com.yourcompany.SplitView' + t.version = '1.0' + t.author = 'Your Company' + t.email = 'feedback @nospam@ yourcompany.com' + t.summary = 'SplitView' + t.sources = FileList['*.j'] + t.resources = FileList['Resources/*'] + t.index_file = 'index.html' + t.info_plist = 'Info.plist' + t.build_path = File.join('Build', ENV['CONFIG'], 'SplitView') + t.flag = '-DDEBUG' if ENV['CONFIG'] == 'Debug' + t.flag = '-O' if ENV['CONFIG'] == 'Release' +end + +task :default => [:SplitView] diff --git a/Tests/AppKit/AttachedSheet/Resources/spinner.gif b/Tests/AppKit/AttachedSheet/Resources/spinner.gif new file mode 100644 index 0000000000000000000000000000000000000000..06dbc2bc21dddcf0e09b566d5b211aee89570f52 GIT binary patch literal 1849 zcma*odr(tX9tZHtz31lM+(&Y`A`Ou`NeG&R#DrIfV%?hng21vs6v>ooRQQFbk7E_K!V( z{?5!fpZWgIZ%*d6t%i*j24bL}AZUJm9)h6R*;%L4IWse3G#VWaN1#$zSSXcBhlYlH zJ|D}n{r&w2f+Qp)SS*&n?*G4}{}!h?td_mjU6Kad-rW*QwWYCUk7d^e+sjpZAn6kT z5rM;`{~_}-wm+L@%+E;JphLm}C3WzQAQD0wBoY|rOTQX{(@pp-WAA8Iw0HKl|15j) zhGh(SFWu#5zUCw^T!}C~eC}~?{xG-r7ugQC>taC+|L^xr&a%{#cgUOZXIM&v?)k^2 z1i5%0!U00wq)r4vlAwXBA_m5J5WNeuBm-XJQ5pG4GD%vc|K){+TJ{AkHqN@SJKczX zU}QRd9n*_bf^h94)6Ctv{CUfz_;qs#RDuQ$DR%y1&5G-a6rhf*4Y zl+UOD1*GE{GQ7vv;c-tTIMkz0ovO>9j%b5hpa@a*CBJ#W!0@ndSwF|%hMkdFtXiU) z`BEp+yhkt8ZY>tg&uyH@%^%K4jDrbA;et&vnnzZ3z22@e6<27z2Vk13kb7OtISyxv z(XoO-LNQCZe3lfzc%*pNqU<9T+p~teThOEB+~e&U0mC|zS{Q)dJZ)!^1f7L(zg*L> z*vSW%?dR~@@0(}x6-V^A`~ImD;)NaBUnP8;RH=bS2@pk`wp>>8r&jGjmGPy%1BW}v zoPo}ca$~bze@efc3kapuEVW1!%teOZT3j2Tw5=hjiAf02d}7dL0oFC%@=RXp5Ow#% z@a>+AM|YWt$n&e`>sB-32gBcuTi>R>*|8@lp`y6thc7ydyqDsuUn~YzZf|{-R@-3y zL#wx{Ii}xxL_csiW*LBn0-A$>zp4WOmkf6=ilrjlW?-l9+bCd7|i?*b5NTmy<<6NZ0T8$SN@mwdC2f z6jqK=N@bS@!=YSj%>h0}*4p+%0HbTIrE$w7UMT6+AZZ&DAo*qZAAi(OtNbIfl#Dw^ zJWeiCp~zi#&t6x}m9)O^eR4HiLV3QA<<0>HZ8%$^lrSE94Wb}=+MM^!b>n#5&-JQR zkr-CEu9C;_F*7DqDisulV6Pmg$nFL0TPn%~*m^-`Z3^BgU(sNpnx%nW(!eV9A&FvI zHL3X3lw8Wji^6=8KbQDE-e%b?svdFxxdh$8r97@7$ojeI`6AL8Ob6QC$qh&>ZWVDX1F{0vJnT%%mE;GveKWR%C} zM&4d;Jf3s9|HAA)yVUPo`Aq;0do#)uHSXi5*QF*)x@MVVHr+cN)uMZ__F|&Ta#p8d z53TOKtce!PJUuie8UWol-S(`c2nH?UGqJP{!4RR4u$LCfn)q-hj0^f=h(VYy)T6eN zhRO!ja-aDBTcgeyP(8Ua4IdiOog^*CQa?R(cP#9AgL9`j>EX-6Yf1lzX(!~``M1XC zNmM<4<6d~wWZ$Xrk0K}UteTrq@LBBk#MsjkK;pbuVhe)NI7(7Pf(l?lxC7=1Z7Pzl zMbS;nV4NI5_N{1$P)&XC)huOGQ+h^zpYUZfb*1n6>!`#*b3y52LGmi+<4sY5jyD#- zw&$d}DTguLAfnRtjrM*JfqtHqUu6rQoU=g%1E9xk%;)TDm^2<8n-0IhTsQFaek)MY}>PK4;nBk=ow4pF>vzkO& gna%Org-kgQCf=+BeMi^RbuY;YE~rTjend;_cdi8t>i_@% literal 0 HcmV?d00001 diff --git a/Tests/AppKit/AttachedSheet/index-debug.html b/Tests/AppKit/AttachedSheet/index-debug.html new file mode 100644 index 000000000..12093852b --- /dev/null +++ b/Tests/AppKit/AttachedSheet/index-debug.html @@ -0,0 +1,83 @@ + + + + + + + + Untitled + + + + + + + + + + + + + +
    + + + +
    + + + diff --git a/Tests/AppKit/AttachedSheet/index.html b/Tests/AppKit/AttachedSheet/index.html new file mode 100644 index 000000000..d44a75d39 --- /dev/null +++ b/Tests/AppKit/AttachedSheet/index.html @@ -0,0 +1,69 @@ + + + + + + + + Attached Sheet + + + + + + + + + + + + +
    + + + +
    + + + + diff --git a/Tests/AppKit/AttachedSheet/main.j b/Tests/AppKit/AttachedSheet/main.j new file mode 100755 index 000000000..b67c4550b --- /dev/null +++ b/Tests/AppKit/AttachedSheet/main.j @@ -0,0 +1,18 @@ +/* + * AppController.j + * SplitView + * + * Created by You on August 1, 2009. + * Copyright 2009, Your Company All rights reserved. + */ + +@import +@import + +@import "AppController.j" + + +function main(args, namedArgs) +{ + CPApplicationMain(args, namedArgs); +} From 5b531b200543f96f5112506181716ccfa669f24f Mon Sep 17 00:00:00 2001 From: cacaodev Date: Wed, 7 Oct 2009 17:16:50 +0200 Subject: [PATCH 03/10] Improved autoresizing mechanism for attached sheets --- AppKit/CPControl.j | 16 +++--- AppKit/CPWindow/CPWindow.j | 108 ++++++++++++++++++++----------------- 2 files changed, 66 insertions(+), 58 deletions(-) diff --git a/AppKit/CPControl.j b/AppKit/CPControl.j index 87d11f5f7..d00f3aa6f 100644 --- a/AppKit/CPControl.j +++ b/AppKit/CPControl.j @@ -293,14 +293,6 @@ var CPControlBlackColor = [CPColor blackColor]; _previousTrackingLocation = currentLocation; } -- (void)performClick:(id)sender -{ - [self highlight:YES]; - [self setState:[self nextState]]; - [self sendAction:[self action] to:[self target]]; - [self highlight:NO]; -} - - (void)setState:(int)state { } @@ -310,6 +302,14 @@ var CPControlBlackColor = [CPColor blackColor]; return 0; } +- (void)performClick:(id)sender +{ + [self highlight:YES]; + [self setState:[self nextState]]; + [self sendAction:[self action] to:[self target]]; + [self highlight:NO]; +} + - (unsigned)mouseDownFlags { return _trackingMouseDownFlags; diff --git a/AppKit/CPWindow/CPWindow.j b/AppKit/CPWindow/CPWindow.j index 6019bd4f6..688fd01d8 100644 --- a/AppKit/CPWindow/CPWindow.j +++ b/AppKit/CPWindow/CPWindow.j @@ -1755,7 +1755,6 @@ CPTexturedBackgroundWindowMask { var sheetFrame = [aSheet frame]; -// setup contexts _sheetContext = {"sheet":aSheet, "modalDelegate":aModalDelegate, "endSelector":aDidEndSelector, "contextInfo":aContextInfo, "frame":CGRectMakeCopy(sheetFrame), "returnCode":-1, "opened": NO}; [self _attachSheetWindow:aSheet]; @@ -1768,29 +1767,22 @@ CPTexturedBackgroundWindowMask frame = [self frame], sheetContent = [aSheet contentView]; -// Configure sheet. -// if ([aSheet styleMask] & CPHUDBackgroundWindowMask) -// [aSheet setMovableByWindowBackground:NO]; - - _sheetContext["autoresizingMask"] = [sheetContent autoresizingMask]; - [sheetContent setAutoresizingMask:CPViewMinYMargin]; - [sheetContent setAutoresizesSubviews:NO]; + // Autoresizing + [self _setUpMasksForView:sheetContent]; + aSheet._isSheet = YES; aSheet._parentView = self; -// calculate start/end frames - var originx = frame.origin.x + FLOOR((frame.size.width - sheetFrame.size.width)/2); - var originy = frame.origin.y + [[self contentView] frame].origin.y; - var startFrame = CGRectMake(originx, originy, sheetFrame.size.width, 0); - var endFrame = CGRectMake(originx, originy, sheetFrame.size.width, sheetFrame.size.height); + // calculate start/end frames + var originx = frame.origin.x + FLOOR((frame.size.width - sheetFrame.size.width)/2), + originy = frame.origin.y + [[self contentView] frame].origin.y, + startFrame = CGRectMake(originx, originy, sheetFrame.size.width, 0), + endFrame = CGRectMake(originx, originy, sheetFrame.size.width, sheetFrame.size.height); -// Notify the world we will open the sheet [[CPNotificationCenter defaultCenter] postNotificationName:@"CPWindowWillBeginSheetNotification" object:self]; -// Start modal [CPApp runModalForWindow:aSheet]; -// Order front and animate the sheet -// aSheet._isAnimating = YES; + // Order front and animate the sheet [aSheet orderFront:self]; [aSheet setFrame:startFrame]; _sheetContext["opened"] = YES; @@ -1804,23 +1796,18 @@ CPTexturedBackgroundWindowMask /* @ignore */ - (void)_detachSheetWindow { - var sheet = [self attachedSheet]; - -// End frame for animation - var startFrame = [sheet frame]; - var endFrame = CGRectMakeCopy(startFrame); + var sheet = [self attachedSheet], + startFrame = [sheet frame], + endFrame = CGRectMakeCopy(startFrame); + endFrame.size.height = 0; - -// Set the new frame in case the sheet have been resized _sheetContext["frame"] = startFrame; -// Autoresizing var sheetContent = [sheet contentView]; - [sheetContent setAutoresizingMask:CPViewMinYMargin]; - [sheetContent setAutoresizesSubviews:NO]; - + + [self _setUpMasksForView:sheetContent]; + _sheetContext["opened"] = NO; -// Start animation with delegate [sheet _setFrame:endFrame delegate:self duration:0.2 curve:CPAnimationLinear]; } @@ -1831,43 +1818,64 @@ CPTexturedBackgroundWindowMask if (anim._window != sheet) return; -// Retore autoresizing var sheetContent = [sheet contentView]; - [sheetContent setAutoresizingMask:_sheetContext["autoresizingMask"]]; - [sheetContent setAutoresizesSubviews:YES]; - -// If we are opened return now + if (_sheetContext["opened"] === YES) + { + [self _restoreMasksForView:sheetContent]; return; - -// Stop modal + } + [CPApp stopModal]; - -// Notify the world we closed the sheet [[CPNotificationCenter defaultCenter] postNotificationName:@"CPWindowDidEndSheetNotification" object:self]; -// check first if front ? [sheet orderOut:self]; -// Set the sheet frame to its last open state. var lastFrame = _sheetContext["frame"]; [sheet setFrame:lastFrame]; - -// Send didEndSelector - var delegate = _sheetContext["modalDelegate"]; - var endSelector = _sheetContext["endSelector"]; + + [self _restoreMasksForView:sheetContent]; + + var delegate = _sheetContext["modalDelegate"], + endSelector = _sheetContext["endSelector"]; + if (delegate != nil && endSelector != nil) - objj_msgSend(_sheetContext["modalDelegate"], - _sheetContext["endSelector"], - sheet, - _sheetContext["returnCode"], - _sheetContext["contextInfo"]); + objj_msgSend(_sheetContext["modalDelegate"], _sheetContext["endSelector"], sheet, _sheetContext["returnCode"], _sheetContext["contextInfo"]); -// reset contexts _sheetContext = nil; sheet._parentView = nil; } +- (void)_setUpMasksForView:(CPView)aView +{ + var views = [CPArray arrayWithArray:[aView subviews]]; + [views addObject:aView]; + + for (var i = 0, count = [views count]; i < count; i++) + { + var view = [views objectAtIndex:i], + mask = [view autoresizingMask], + maskToAdd = (mask & CPViewMinYMargin) ? 128 : CPViewMinYMargin; + + [view setAutoresizingMask:(mask | maskToAdd)]; + } +} + +- (void)_restoreMasksForView:(CPView)aView +{ + var views = [CPArray arrayWithArray:[aView subviews]]; + [views addObject:aView]; + + for (var i = 0, count = [views count]; i < count; i++) + { + var view = [views objectAtIndex:i], + mask = [view autoresizingMask], + maskToRemove = (mask & 128) ? 128 : CPViewMinYMargin; + + [view setAutoresizingMask:(mask & (~ maskToRemove))]; + } +} + /*! Returns the window's attached sheet. */ From c6b934a035ce1a34f954ad706cb2faea91eb8045 Mon Sep 17 00:00:00 2001 From: cacaodev Date: Fri, 18 Sep 2009 13:28:30 +0200 Subject: [PATCH 04/10] Attached sheet implementation --- AppKit/CPApplication.j | 31 +++++ AppKit/CPPanel.j | 7 + AppKit/CPWindow/CPWindow.j | 168 +++++++++++++++++++----- AppKit/CPWindow/_CPDocModalWindowView.j | 50 +++++++ AppKit/CPWindow/_CPWindowView.j | 9 +- 5 files changed, 229 insertions(+), 36 deletions(-) create mode 100644 AppKit/CPWindow/_CPDocModalWindowView.j diff --git a/AppKit/CPApplication.j b/AppKit/CPApplication.j index 26aa821e6..626d36718 100644 --- a/AppKit/CPApplication.j +++ b/AppKit/CPApplication.j @@ -719,9 +719,40 @@ CPRunContinuesResponse = -1002; */ - (void)beginSheet:(CPWindow)aSheet modalForWindow:(CPWindow)aWindow modalDelegate:(id)aModalDelegate didEndSelector:(SEL)aDidEndSelector contextInfo:(id)aContextInfo { + var styleMask = [aSheet styleMask]; + if (!(styleMask & CPDocModalWindowMask)) + { + [CPException raise:CPInternalInconsistencyException reason:@"Currently only CPDocModalWindowMask style mask is supported for attached sheets"]; + return; + } + [aWindow _attachSheet:aSheet modalDelegate:aModalDelegate didEndSelector:aDidEndSelector contextInfo:aContextInfo]; } +- (void)endSheet:(CPWindow)sheet returnCode:(int)returnCode +{ + var count = [_windows count]; + + while (--count >= 0) + { + var aWindow = [_windows objectAtIndex:count]; + var context = aWindow._sheetContext; + + if (context != nil && context["sheet"] === sheet) + { + context["returnCode"] = returnCode; + [aWindow _detachSheetWindow]; + return; + } + } +} + +- (void)endSheet:(CPWindow)sheet +{ + [self endSheet:sheet returnCode:0]; +} + + - (CPArray)arguments { if(_fullArgsString != window.location.hash) diff --git a/AppKit/CPPanel.j b/AppKit/CPPanel.j index 65dc9b177..61480d50a 100644 --- a/AppKit/CPPanel.j +++ b/AppKit/CPPanel.j @@ -46,6 +46,13 @@ CPCancelButton = 0;
  • A panel can be made to work even when there's an attention panel on-screen. This permits actions within the panel to affect the attention panel.
  • */ + +/* + @global + @class CPWindow +*/ +CPDocModalWindowMask = 1 << 6; + @implementation CPPanel : CPWindow { BOOL _becomesKeyOnlyIfNeeded; diff --git a/AppKit/CPWindow/CPWindow.j b/AppKit/CPWindow/CPWindow.j index 7dc79c3ca..a341b0852 100644 --- a/AppKit/CPWindow/CPWindow.j +++ b/AppKit/CPWindow/CPWindow.j @@ -309,6 +309,8 @@ var CPWindowSaveImage = nil, BOOL _isFullPlatformWindow; _CPWindowFullPlatformWindowSession _fullPlatformWindowSession; + + CPDictionary _sheetContext; } /* @@ -439,7 +441,10 @@ CPTexturedBackgroundWindowMask else if (aStyleMask === CPBorderlessWindowMask) return _CPBorderlessWindowView; - + + else if (aStyleMask & CPDocModalWindowMask) + return _CPDocModalWindowView; + return _CPStandardWindowView; } @@ -1722,57 +1727,146 @@ CPTexturedBackgroundWindowMask */ } +- (void)_setFrame:(CGRect)aFrame delegate:(id)delegate duration:(int)duration curve:(CPAnimationCurve)curve +{ + var animation = [[_CPWindowFrameAnimation alloc] initWithWindow:self targetFrame:aFrame]; + [animation setDelegate:delegate]; + [animation setAnimationCurve:curve]; + [animation setDuration:duration]; + [animation startAnimation]; +} + /* @ignore */ - (void)_setAttachedSheetFrameOrigin { // Position the sheet above the contentRect. + var attachedSheet = [self attachedSheet]; var contentRect = [[self contentView] frame], - sheetFrame = CGRectMakeCopy([_attachedSheet frame]); + sheetFrame = CGRectMakeCopy([attachedSheet frame]); sheetFrame.origin.y = CGRectGetMinY(_frame) + CGRectGetMinY(contentRect); sheetFrame.origin.x = CGRectGetMinX(_frame) + FLOOR((CGRectGetWidth(_frame) - CGRectGetWidth(sheetFrame)) / 2.0); - [_attachedSheet setFrameOrigin:sheetFrame.origin]; -} - -/* @ignore */ -- (void)_animateAttachedSheet -{ -/* NSWindow *sheet = [sheetContext sheet]; - NSRect sheetFrame; - - [_sheetContext autorelease]; - _sheetContext=[sheetContext retain]; - - [self _setSheetOrigin]; - sheetFrame = [sheet frame]; - - [(NSWindowBackgroundView *)[sheet _backgroundView] setBorderType:NSButtonBorder]; - [[sheet contentView] setAutoresizesSubviews:NO]; - [[sheet contentView] setAutoresizingMask:NSViewNotSizable]; - -// [(NSWindowBackgroundView *)[sheet _backgroundView] cacheImageForAnimation]; - - [_attachedSheet setFrame:CPRectMake(CGRectGetMinX(sheetFrame), CGRectGetMinY(sheetFrame), CGRectGetWidth(sheetFrame), 0.0) display:YES]; - [sheet setFrame:NSMakeRect(sheetFrame.origin.x, NSMaxY([self frame]), sheetFrame.size.width, 0) display:YES]; - [self _setSheetOriginAndFront]; - - [sheet setFrame:sheetFrame display:YES animate:YES];*/ + [attachedSheet setFrameOrigin:sheetFrame.origin]; } /* @ignore */ - (void)_attachSheet:(CPWindow)aSheet modalDelegate:(id)aModalDelegate didEndSelector:(SEL)aDidEndSelector contextInfo:(id)aContextInfo { - // Set this as our attached sheet. - _attachedSheet = aSheet; + var sheetFrame = [aSheet frame]; + +// setup contexts + _sheetContext = {"sheet":aSheet, "modalDelegate":aModalDelegate, "endSelector":aDidEndSelector, "contextInfo":aContextInfo, "frame":CGRectMakeCopy(sheetFrame), "returnCode":-1, "opened": NO}; + + [self _attachSheetWindow:aSheet]; +} + +/* @ignore */ +- (void)_attachSheetWindow:(CPWindow)aSheet +{ + var sheetFrame = [aSheet frame], + frame = [self frame], + sheetContent = [aSheet contentView]; - // If a window is ever run as a sheet, then it's sheet bit is set to YES. +// Configure sheet. +// if ([aSheet styleMask] & CPHUDBackgroundWindowMask) +// [aSheet setMovableByWindowBackground:NO]; + + _sheetContext["autoresizingMask"] = [sheetContent autoresizingMask]; + [sheetContent setAutoresizingMask:CPViewMinYMargin]; + [sheetContent setAutoresizesSubviews:NO]; aSheet._isSheet = YES; + aSheet._parentView = self; - [self _setAttachedSheetFrameOrigin]; +// calculate start/end frames + var originx = frame.origin.x + FLOOR((frame.size.width - sheetFrame.size.width)/2); + var originy = frame.origin.y + [[self contentView] frame].origin.y; + var startFrame = CGRectMake(originx, originy , sheetFrame.size.width, 0); + var endFrame = CGRectMake(originx, originy ,sheetFrame.size.width,sheetFrame.size.height); + +// Notify the world we will open the sheet + [[CPNotificationCenter defaultCenter] postNotificationName:@"CPWindowWillBeginSheetNotification" object:self]; +// Start modal + [CPApp runModalForWindow:aSheet]; + +// Order front and animate the sheet +// aSheet._isAnimating = YES; + [aSheet orderFront:self]; + [aSheet setFrame:startFrame]; + _sheetContext["opened"] = YES; + + [aSheet _setFrame:endFrame delegate:self duration:0.3 curve:CPAnimationEaseOut]; + + // Should run the main loop here until _isAnimating = FALSE + [aSheet becomeKeyWindow]; +} + +/* @ignore */ +- (void)_detachSheetWindow +{ + var sheet = [self attachedSheet]; - // Place this window above ourselves. - [_platformWindow order:CPWindowAbove window:aSheet relativeTo:self]; +// End frame for animation + var startFrame = [sheet frame]; + var endFrame = CGRectMakeCopy(startFrame); + endFrame.size.height = 0; + +// Set the new frame in case the sheet have been resized + _sheetContext["frame"] = startFrame; + +// Autoresizing + var sheetContent = [sheet contentView]; + [sheetContent setAutoresizingMask:CPViewMinYMargin]; + [sheetContent setAutoresizesSubviews:NO]; + +// Start animation with delegate + _sheetContext["opened"] = NO; + + [sheet _setFrame:endFrame delegate:self duration:0.2 curve:CPAnimationLinear]; +} + +/* @ignore */ +- (void)animationDidEnd:(id)anim +{ + var sheet = _sheetContext["sheet"]; + if (anim._window != sheet) + return; + +// Retore autoresizing + var sheetContent = [sheet contentView]; + [sheetContent setAutoresizingMask:_sheetContext["autoresizingMask"]]; + [sheetContent setAutoresizesSubviews:YES]; + +// If we are opened return now + if (_sheetContext["opened"] == YES) + return; + +// Stop modal + [CPApp stopModal]; + +// Notify the world we closed the sheet + [[CPNotificationCenter defaultCenter] postNotificationName:@"CPWindowDidEndSheetNotification" object:self]; + +// check first if front ? + [sheet orderOut:self]; + +// Set the sheet frame to its last open state. + var lastFrame = _sheetContext["frame"]; + [sheet setFrame:lastFrame]; + +// Send didEndSelector + var delegate = _sheetContext["modalDelegate"]; + var endSelector = _sheetContext["endSelector"]; + if(delegate != nil && endSelector != nil) + objj_msgSend(_sheetContext["modalDelegate"], + _sheetContext["endSelector"], + sheet, + _sheetContext["returnCode"], + _sheetContext["contextInfo"]); + +// reset contexts + _sheetContext = nil; + sheet._parentView = nil; } /*! @@ -1780,7 +1874,10 @@ CPTexturedBackgroundWindowMask */ - (CPWindow)attachedSheet { - return _attachedSheet; + if (_sheetContext == nil) + return nil; + + return _sheetContext["sheet"]; } /*! @@ -2225,6 +2322,7 @@ function _CPWindowFullPlatformWindowSessionMake(aWindowView, aContentRect, hasSh @import "_CPWindowView.j" @import "_CPStandardWindowView.j" +@import "_CPDocModalWindowView.j" @import "_CPHUDWindowView.j" @import "_CPBorderlessWindowView.j" @import "_CPBorderlessBridgeWindowView.j" diff --git a/AppKit/CPWindow/_CPDocModalWindowView.j b/AppKit/CPWindow/_CPDocModalWindowView.j new file mode 100644 index 000000000..af233e84d --- /dev/null +++ b/AppKit/CPWindow/_CPDocModalWindowView.j @@ -0,0 +1,50 @@ + +@import "_CPWindowView.j" + +var _CPStandardWindowViewBodyBackgroundColor = nil; + +@implementation _CPDocModalWindowView : _CPWindowView +{ + CPView _bodyView; +} + ++ (CPColor)bodyBackgroundColor +{ + if (!_CPStandardWindowViewBodyBackgroundColor) + _CPStandardWindowViewBodyBackgroundColor = [CPColor colorWithWhite:0.96 alpha:1.0]; + + return _CPStandardWindowViewBodyBackgroundColor; +} + +- (id)initWithFrame:(CPRect)aFrame styleMask:(unsigned)aStyleMask +{ + self = [super initWithFrame:aFrame styleMask:aStyleMask]; + + if (self) + { + var theClass = [self class], + bounds = [self bounds]; + + _bodyView = [[CPView alloc] initWithFrame:CGRectMake(0.0, 0.0, CGRectGetWidth(bounds), CGRectGetHeight(bounds))]; + + [_bodyView setAutoresizingMask:CPViewWidthSizable | CPViewHeightSizable]; + [_bodyView setBackgroundColor:[theClass bodyBackgroundColor]]; + [_bodyView setHitTests:NO]; + + [self addSubview:_bodyView]; + } + + return self; +} + +- (CGRect)contentRectForFrameRect:(CGRect)aFrameRect +{ + return aFrameRect; +} + +- (CGRect)frameRectForContentRect:(CGRect)aContentRect +{ + return aContentRect; +} + +@end \ No newline at end of file diff --git a/AppKit/CPWindow/_CPWindowView.j b/AppKit/CPWindow/_CPWindowView.j index 890044daa..5231016f6 100644 --- a/AppKit/CPWindow/_CPWindowView.j +++ b/AppKit/CPWindow/_CPWindowView.j @@ -135,7 +135,14 @@ var _CPWindowViewResizeIndicatorImage = nil; } else if (type === CPLeftMouseDragged) - [theWindow setFrameSize:CGSizeMake(CGRectGetWidth(_resizeFrame) + location.x - CGRectGetMinX(_resizeFrame), CGRectGetHeight(_resizeFrame) + location.y - CGRectGetMinY(_resizeFrame))]; + { + var newSize = CGSizeMake(CGRectGetWidth(_resizeFrame) + location.x - CGRectGetMinX(_resizeFrame), CGRectGetHeight(_resizeFrame) + location.y - CGRectGetMinY(_resizeFrame)); + + if (theWindow._isSheet && theWindow._parentView && (theWindow._frame.size.width !== newSize.width)) + [theWindow._parentView _setAttachedSheetFrameOrigin]; + + [theWindow setFrameSize:newSize]; + } [CPApp setTarget:self selector:@selector(trackResizeWithEvent:) forNextEventMatchingMask:CPLeftMouseDraggedMask | CPLeftMouseUpMask untilDate:nil inMode:nil dequeue:YES]; } From 0e55a5d7c448a733ae1ad6373c356bb79fb1f759 Mon Sep 17 00:00:00 2001 From: cacaodev Date: Mon, 21 Sep 2009 22:05:42 +0200 Subject: [PATCH 05/10] Added sample app. Corrected style (tabs) --- AppKit/CPApplication.j | 42 +++--- AppKit/CPWindow/CPWindow.j | 129 +++++++++--------- AppKit/CPWindow/_CPDocModalWindowView.j | 8 +- Tests/AppKit/AttachedSheet/AppController.j | 84 ++++++++++++ Tests/AppKit/AttachedSheet/Info.plist | 12 ++ Tests/AppKit/AttachedSheet/Rakefile | 25 ++++ .../AttachedSheet/Resources/spinner.gif | Bin 0 -> 1849 bytes Tests/AppKit/AttachedSheet/index-debug.html | 83 +++++++++++ Tests/AppKit/AttachedSheet/index.html | 69 ++++++++++ Tests/AppKit/AttachedSheet/main.j | 18 +++ 10 files changed, 380 insertions(+), 90 deletions(-) create mode 100644 Tests/AppKit/AttachedSheet/AppController.j create mode 100644 Tests/AppKit/AttachedSheet/Info.plist create mode 100644 Tests/AppKit/AttachedSheet/Rakefile create mode 100644 Tests/AppKit/AttachedSheet/Resources/spinner.gif create mode 100644 Tests/AppKit/AttachedSheet/index-debug.html create mode 100644 Tests/AppKit/AttachedSheet/index.html create mode 100755 Tests/AppKit/AttachedSheet/main.j diff --git a/AppKit/CPApplication.j b/AppKit/CPApplication.j index 626d36718..72f88a420 100644 --- a/AppKit/CPApplication.j +++ b/AppKit/CPApplication.j @@ -719,32 +719,32 @@ CPRunContinuesResponse = -1002; */ - (void)beginSheet:(CPWindow)aSheet modalForWindow:(CPWindow)aWindow modalDelegate:(id)aModalDelegate didEndSelector:(SEL)aDidEndSelector contextInfo:(id)aContextInfo { - var styleMask = [aSheet styleMask]; - if (!(styleMask & CPDocModalWindowMask)) - { - [CPException raise:CPInternalInconsistencyException reason:@"Currently only CPDocModalWindowMask style mask is supported for attached sheets"]; - return; - } - + var styleMask = [aSheet styleMask]; + if (!(styleMask & CPDocModalWindowMask)) + { + [CPException raise:CPInternalInconsistencyException reason:@"Currently only CPDocModalWindowMask style mask is supported for attached sheets"]; + return; + } + [aWindow _attachSheet:aSheet modalDelegate:aModalDelegate didEndSelector:aDidEndSelector contextInfo:aContextInfo]; } - (void)endSheet:(CPWindow)sheet returnCode:(int)returnCode { - var count = [_windows count]; - - while (--count >= 0) - { - var aWindow = [_windows objectAtIndex:count]; - var context = aWindow._sheetContext; - - if (context != nil && context["sheet"] === sheet) - { - context["returnCode"] = returnCode; - [aWindow _detachSheetWindow]; - return; - } - } + var count = [_windows count]; + + while (--count >= 0) + { + var aWindow = [_windows objectAtIndex:count]; + var context = aWindow._sheetContext; + + if (context != nil && context["sheet"] === sheet) + { + context["returnCode"] = returnCode; + [aWindow _detachSheetWindow]; + return; + } + } } - (void)endSheet:(CPWindow)sheet diff --git a/AppKit/CPWindow/CPWindow.j b/AppKit/CPWindow/CPWindow.j index a341b0852..6019bd4f6 100644 --- a/AppKit/CPWindow/CPWindow.j +++ b/AppKit/CPWindow/CPWindow.j @@ -310,7 +310,7 @@ var CPWindowSaveImage = nil, BOOL _isFullPlatformWindow; _CPWindowFullPlatformWindowSession _fullPlatformWindowSession; - CPDictionary _sheetContext; + CPDictionary _sheetContext; } /* @@ -443,7 +443,7 @@ CPTexturedBackgroundWindowMask return _CPBorderlessWindowView; else if (aStyleMask & CPDocModalWindowMask) - return _CPDocModalWindowView; + return _CPDocModalWindowView; return _CPStandardWindowView; } @@ -1729,11 +1729,11 @@ CPTexturedBackgroundWindowMask - (void)_setFrame:(CGRect)aFrame delegate:(id)delegate duration:(int)duration curve:(CPAnimationCurve)curve { - var animation = [[_CPWindowFrameAnimation alloc] initWithWindow:self targetFrame:aFrame]; - [animation setDelegate:delegate]; - [animation setAnimationCurve:curve]; - [animation setDuration:duration]; - [animation startAnimation]; + var animation = [[_CPWindowFrameAnimation alloc] initWithWindow:self targetFrame:aFrame]; + [animation setDelegate:delegate]; + [animation setAnimationCurve:curve]; + [animation setDuration:duration]; + [animation startAnimation]; } /* @ignore */ @@ -1744,60 +1744,60 @@ CPTexturedBackgroundWindowMask var contentRect = [[self contentView] frame], sheetFrame = CGRectMakeCopy([attachedSheet frame]); - sheetFrame.origin.y = CGRectGetMinY(_frame) + CGRectGetMinY(contentRect); - sheetFrame.origin.x = CGRectGetMinX(_frame) + FLOOR((CGRectGetWidth(_frame) - CGRectGetWidth(sheetFrame)) / 2.0); + sheetFrame.origin.y = CGRectGetMinY(_frame) + CGRectGetMinY(contentRect); + sheetFrame.origin.x = CGRectGetMinX(_frame) + FLOOR((CGRectGetWidth(_frame) - CGRectGetWidth(sheetFrame)) / 2.0); - [attachedSheet setFrameOrigin:sheetFrame.origin]; + [attachedSheet setFrameOrigin:sheetFrame.origin]; } /* @ignore */ - (void)_attachSheet:(CPWindow)aSheet modalDelegate:(id)aModalDelegate didEndSelector:(SEL)aDidEndSelector contextInfo:(id)aContextInfo { - var sheetFrame = [aSheet frame]; + var sheetFrame = [aSheet frame]; // setup contexts - _sheetContext = {"sheet":aSheet, "modalDelegate":aModalDelegate, "endSelector":aDidEndSelector, "contextInfo":aContextInfo, "frame":CGRectMakeCopy(sheetFrame), "returnCode":-1, "opened": NO}; - - [self _attachSheetWindow:aSheet]; + _sheetContext = {"sheet":aSheet, "modalDelegate":aModalDelegate, "endSelector":aDidEndSelector, "contextInfo":aContextInfo, "frame":CGRectMakeCopy(sheetFrame), "returnCode":-1, "opened": NO}; + + [self _attachSheetWindow:aSheet]; } /* @ignore */ - (void)_attachSheetWindow:(CPWindow)aSheet { var sheetFrame = [aSheet frame], - frame = [self frame], - sheetContent = [aSheet contentView]; + frame = [self frame], + sheetContent = [aSheet contentView]; // Configure sheet. // if ([aSheet styleMask] & CPHUDBackgroundWindowMask) -// [aSheet setMovableByWindowBackground:NO]; +// [aSheet setMovableByWindowBackground:NO]; - _sheetContext["autoresizingMask"] = [sheetContent autoresizingMask]; + _sheetContext["autoresizingMask"] = [sheetContent autoresizingMask]; [sheetContent setAutoresizingMask:CPViewMinYMargin]; [sheetContent setAutoresizesSubviews:NO]; aSheet._isSheet = YES; aSheet._parentView = self; // calculate start/end frames - var originx = frame.origin.x + FLOOR((frame.size.width - sheetFrame.size.width)/2); - var originy = frame.origin.y + [[self contentView] frame].origin.y; - var startFrame = CGRectMake(originx, originy , sheetFrame.size.width, 0); - var endFrame = CGRectMake(originx, originy ,sheetFrame.size.width,sheetFrame.size.height); + var originx = frame.origin.x + FLOOR((frame.size.width - sheetFrame.size.width)/2); + var originy = frame.origin.y + [[self contentView] frame].origin.y; + var startFrame = CGRectMake(originx, originy, sheetFrame.size.width, 0); + var endFrame = CGRectMake(originx, originy, sheetFrame.size.width, sheetFrame.size.height); // Notify the world we will open the sheet [[CPNotificationCenter defaultCenter] postNotificationName:@"CPWindowWillBeginSheetNotification" object:self]; // Start modal - [CPApp runModalForWindow:aSheet]; - + [CPApp runModalForWindow:aSheet]; + // Order front and animate the sheet -// aSheet._isAnimating = YES; +// aSheet._isAnimating = YES; [aSheet orderFront:self]; [aSheet setFrame:startFrame]; _sheetContext["opened"] = YES; [aSheet _setFrame:endFrame delegate:self duration:0.3 curve:CPAnimationEaseOut]; - // Should run the main loop here until _isAnimating = FALSE + // Should run the main loop here until _isAnimating = FALSE [aSheet becomeKeyWindow]; } @@ -1812,61 +1812,60 @@ CPTexturedBackgroundWindowMask endFrame.size.height = 0; // Set the new frame in case the sheet have been resized - _sheetContext["frame"] = startFrame; - + _sheetContext["frame"] = startFrame; + // Autoresizing - var sheetContent = [sheet contentView]; + var sheetContent = [sheet contentView]; [sheetContent setAutoresizingMask:CPViewMinYMargin]; [sheetContent setAutoresizesSubviews:NO]; - + + _sheetContext["opened"] = NO; // Start animation with delegate - _sheetContext["opened"] = NO; - - [sheet _setFrame:endFrame delegate:self duration:0.2 curve:CPAnimationLinear]; + [sheet _setFrame:endFrame delegate:self duration:0.2 curve:CPAnimationLinear]; } /* @ignore */ - (void)animationDidEnd:(id)anim { - var sheet = _sheetContext["sheet"]; - if (anim._window != sheet) - return; + var sheet = _sheetContext["sheet"]; + if (anim._window != sheet) + return; // Retore autoresizing - var sheetContent = [sheet contentView]; - [sheetContent setAutoresizingMask:_sheetContext["autoresizingMask"]]; - [sheetContent setAutoresizesSubviews:YES]; + var sheetContent = [sheet contentView]; + [sheetContent setAutoresizingMask:_sheetContext["autoresizingMask"]]; + [sheetContent setAutoresizesSubviews:YES]; -// If we are opened return now - if (_sheetContext["opened"] == YES) - return; - +// If we are opened return now + if (_sheetContext["opened"] === YES) + return; + // Stop modal - [CPApp stopModal]; - + [CPApp stopModal]; + // Notify the world we closed the sheet - [[CPNotificationCenter defaultCenter] postNotificationName:@"CPWindowDidEndSheetNotification" object:self]; + [[CPNotificationCenter defaultCenter] postNotificationName:@"CPWindowDidEndSheetNotification" object:self]; // check first if front ? - [sheet orderOut:self]; + [sheet orderOut:self]; // Set the sheet frame to its last open state. - var lastFrame = _sheetContext["frame"]; - [sheet setFrame:lastFrame]; - -// Send didEndSelector - var delegate = _sheetContext["modalDelegate"]; - var endSelector = _sheetContext["endSelector"]; - if(delegate != nil && endSelector != nil) - objj_msgSend(_sheetContext["modalDelegate"], - _sheetContext["endSelector"], - sheet, - _sheetContext["returnCode"], - _sheetContext["contextInfo"]); - + var lastFrame = _sheetContext["frame"]; + [sheet setFrame:lastFrame]; + +// Send didEndSelector + var delegate = _sheetContext["modalDelegate"]; + var endSelector = _sheetContext["endSelector"]; + if (delegate != nil && endSelector != nil) + objj_msgSend(_sheetContext["modalDelegate"], + _sheetContext["endSelector"], + sheet, + _sheetContext["returnCode"], + _sheetContext["contextInfo"]); + // reset contexts - _sheetContext = nil; - sheet._parentView = nil; + _sheetContext = nil; + sheet._parentView = nil; } /*! @@ -1874,9 +1873,9 @@ CPTexturedBackgroundWindowMask */ - (CPWindow)attachedSheet { - if (_sheetContext == nil) - return nil; - + if (_sheetContext === nil) + return nil; + return _sheetContext["sheet"]; } diff --git a/AppKit/CPWindow/_CPDocModalWindowView.j b/AppKit/CPWindow/_CPDocModalWindowView.j index af233e84d..9db0ee9c7 100644 --- a/AppKit/CPWindow/_CPDocModalWindowView.j +++ b/AppKit/CPWindow/_CPDocModalWindowView.j @@ -5,7 +5,7 @@ var _CPStandardWindowViewBodyBackgroundColor = nil; @implementation _CPDocModalWindowView : _CPWindowView { - CPView _bodyView; + CPView _bodyView; } + (CPColor)bodyBackgroundColor @@ -22,9 +22,9 @@ var _CPStandardWindowViewBodyBackgroundColor = nil; if (self) { - var theClass = [self class], + var theClass = [self class], bounds = [self bounds]; - + _bodyView = [[CPView alloc] initWithFrame:CGRectMake(0.0, 0.0, CGRectGetWidth(bounds), CGRectGetHeight(bounds))]; [_bodyView setAutoresizingMask:CPViewWidthSizable | CPViewHeightSizable]; @@ -34,7 +34,7 @@ var _CPStandardWindowViewBodyBackgroundColor = nil; [self addSubview:_bodyView]; } - return self; + return self; } - (CGRect)contentRectForFrameRect:(CGRect)aFrameRect diff --git a/Tests/AppKit/AttachedSheet/AppController.j b/Tests/AppKit/AttachedSheet/AppController.j new file mode 100644 index 000000000..e40c804b6 --- /dev/null +++ b/Tests/AppKit/AttachedSheet/AppController.j @@ -0,0 +1,84 @@ +/* + * AppController.j + * AttachedSheet + * + * Created by Cacaodev on August 1, 2009. + * Copyright 2009, Your Company All rights reserved. + */ + +@import + +@implementation AppController : CPObject +{ + CPWindow window; + CPWindow sheet; + CPTextField textField; +} + +- (void)applicationDidFinishLaunching:(CPNotification)aNotification +{ + window = [[CPWindow alloc] initWithContentRect:CGRectMake(100,100,500,300) styleMask:CPResizableWindowMask], + contentView = [window contentView]; + + sheet = [[CPWindow alloc] initWithContentRect:CGRectMake(0,0,300,100) styleMask:CPDocModalWindowMask|CPResizableWindowMask]; + // [sheet setMinSize:CGSizeMake(300,100)]; + + var sheetContent = [sheet contentView]; + + textField = [[CPTextField alloc] initWithFrame:CGRectMake(10,30,280,30)]; + [textField setEditable:YES]; + [textField setBezeled:YES]; + [textField setAutoresizingMask:CPViewMinYMargin|CPViewWidthSizable]; + + var okButton = [[CPButton alloc] initWithFrame:CGRectMake(230,70,50,24)]; + [okButton setTitle:"OK"]; + [okButton setTarget:self]; + [okButton setTag:1]; + [okButton setAction:@selector(closeSheet:)]; + [okButton setAutoresizingMask:CPViewMinXMargin|CPViewMinYMargin]; + + var cancelButton = [[CPButton alloc] initWithFrame:CGRectMake(120,70,100,24)]; + [cancelButton setTitle:"Cancel"]; + [cancelButton setTarget:self]; + [cancelButton setTag:0]; + [cancelButton setAction:@selector(closeSheet:)]; + [cancelButton setAutoresizingMask:CPViewMinXMargin|CPViewMinYMargin]; + + [sheetContent addSubview:textField]; + [sheetContent addSubview:okButton]; + [sheetContent addSubview:cancelButton]; + + var displayButton = [[CPButton alloc] initWithFrame:CGRectMake(200,150,100,24)]; + [displayButton setTitle:"Display Sheet"]; + [displayButton setTarget:self]; + [displayButton setAction:@selector(displaySheet:)]; + + [contentView addSubview:displayButton]; + [window orderFront:self] +} + +- (void)displaySheet:(id)sender +{ + [textField setStringValue:""]; + [sheet makeFirstResponder:textField]; + + [CPApp beginSheet:sheet modalForWindow:window modalDelegate:self didEndSelector:@selector(didEndSheet:returnCode:contextInfo:) contextInfo:nil]; +} + +- (void)closeSheet:(id)sender +{ + [CPApp endSheet:sheet returnCode:[sender tag]]; +} + +- (void)didEndSheet:(CPWindow)sheet returnCode:(int)returnCode contextInfo:(id)contextInfo +{ + var str = [textField stringValue]; + + [sheet orderOut:self]; + if (returnCode == CPOKButton && [str length] > 0) + { + [window setTitle:str]; + } +} + +@end \ No newline at end of file diff --git a/Tests/AppKit/AttachedSheet/Info.plist b/Tests/AppKit/AttachedSheet/Info.plist new file mode 100644 index 000000000..143e86dbd --- /dev/null +++ b/Tests/AppKit/AttachedSheet/Info.plist @@ -0,0 +1,12 @@ + + + + + CPApplicationDelegateClass + AppController + CPBundleName + FullOfSheet + CPPrincipalClass + CPApplication + + diff --git a/Tests/AppKit/AttachedSheet/Rakefile b/Tests/AppKit/AttachedSheet/Rakefile new file mode 100644 index 000000000..3fc1dbfa1 --- /dev/null +++ b/Tests/AppKit/AttachedSheet/Rakefile @@ -0,0 +1,25 @@ + +require 'objective-j' +require 'objective-j/bundletask' + +if !ENV['CONFIG'] + ENV['CONFIG'] = 'Debug' +end + +ObjectiveJ::BundleTask.new(:SplitView) do |t| + t.name = 'SplitView' + t.identifier = 'com.yourcompany.SplitView' + t.version = '1.0' + t.author = 'Your Company' + t.email = 'feedback @nospam@ yourcompany.com' + t.summary = 'SplitView' + t.sources = FileList['*.j'] + t.resources = FileList['Resources/*'] + t.index_file = 'index.html' + t.info_plist = 'Info.plist' + t.build_path = File.join('Build', ENV['CONFIG'], 'SplitView') + t.flag = '-DDEBUG' if ENV['CONFIG'] == 'Debug' + t.flag = '-O' if ENV['CONFIG'] == 'Release' +end + +task :default => [:SplitView] diff --git a/Tests/AppKit/AttachedSheet/Resources/spinner.gif b/Tests/AppKit/AttachedSheet/Resources/spinner.gif new file mode 100644 index 0000000000000000000000000000000000000000..06dbc2bc21dddcf0e09b566d5b211aee89570f52 GIT binary patch literal 1849 zcma*odr(tX9tZHtz31lM+(&Y`A`Ou`NeG&R#DrIfV%?hng21vs6v>ooRQQFbk7E_K!V( z{?5!fpZWgIZ%*d6t%i*j24bL}AZUJm9)h6R*;%L4IWse3G#VWaN1#$zSSXcBhlYlH zJ|D}n{r&w2f+Qp)SS*&n?*G4}{}!h?td_mjU6Kad-rW*QwWYCUk7d^e+sjpZAn6kT z5rM;`{~_}-wm+L@%+E;JphLm}C3WzQAQD0wBoY|rOTQX{(@pp-WAA8Iw0HKl|15j) zhGh(SFWu#5zUCw^T!}C~eC}~?{xG-r7ugQC>taC+|L^xr&a%{#cgUOZXIM&v?)k^2 z1i5%0!U00wq)r4vlAwXBA_m5J5WNeuBm-XJQ5pG4GD%vc|K){+TJ{AkHqN@SJKczX zU}QRd9n*_bf^h94)6Ctv{CUfz_;qs#RDuQ$DR%y1&5G-a6rhf*4Y zl+UOD1*GE{GQ7vv;c-tTIMkz0ovO>9j%b5hpa@a*CBJ#W!0@ndSwF|%hMkdFtXiU) z`BEp+yhkt8ZY>tg&uyH@%^%K4jDrbA;et&vnnzZ3z22@e6<27z2Vk13kb7OtISyxv z(XoO-LNQCZe3lfzc%*pNqU<9T+p~teThOEB+~e&U0mC|zS{Q)dJZ)!^1f7L(zg*L> z*vSW%?dR~@@0(}x6-V^A`~ImD;)NaBUnP8;RH=bS2@pk`wp>>8r&jGjmGPy%1BW}v zoPo}ca$~bze@efc3kapuEVW1!%teOZT3j2Tw5=hjiAf02d}7dL0oFC%@=RXp5Ow#% z@a>+AM|YWt$n&e`>sB-32gBcuTi>R>*|8@lp`y6thc7ydyqDsuUn~YzZf|{-R@-3y zL#wx{Ii}xxL_csiW*LBn0-A$>zp4WOmkf6=ilrjlW?-l9+bCd7|i?*b5NTmy<<6NZ0T8$SN@mwdC2f z6jqK=N@bS@!=YSj%>h0}*4p+%0HbTIrE$w7UMT6+AZZ&DAo*qZAAi(OtNbIfl#Dw^ zJWeiCp~zi#&t6x}m9)O^eR4HiLV3QA<<0>HZ8%$^lrSE94Wb}=+MM^!b>n#5&-JQR zkr-CEu9C;_F*7DqDisulV6Pmg$nFL0TPn%~*m^-`Z3^BgU(sNpnx%nW(!eV9A&FvI zHL3X3lw8Wji^6=8KbQDE-e%b?svdFxxdh$8r97@7$ojeI`6AL8Ob6QC$qh&>ZWVDX1F{0vJnT%%mE;GveKWR%C} zM&4d;Jf3s9|HAA)yVUPo`Aq;0do#)uHSXi5*QF*)x@MVVHr+cN)uMZ__F|&Ta#p8d z53TOKtce!PJUuie8UWol-S(`c2nH?UGqJP{!4RR4u$LCfn)q-hj0^f=h(VYy)T6eN zhRO!ja-aDBTcgeyP(8Ua4IdiOog^*CQa?R(cP#9AgL9`j>EX-6Yf1lzX(!~``M1XC zNmM<4<6d~wWZ$Xrk0K}UteTrq@LBBk#MsjkK;pbuVhe)NI7(7Pf(l?lxC7=1Z7Pzl zMbS;nV4NI5_N{1$P)&XC)huOGQ+h^zpYUZfb*1n6>!`#*b3y52LGmi+<4sY5jyD#- zw&$d}DTguLAfnRtjrM*JfqtHqUu6rQoU=g%1E9xk%;)TDm^2<8n-0IhTsQFaek)MY}>PK4;nBk=ow4pF>vzkO& gna%Org-kgQCf=+BeMi^RbuY;YE~rTjend;_cdi8t>i_@% literal 0 HcmV?d00001 diff --git a/Tests/AppKit/AttachedSheet/index-debug.html b/Tests/AppKit/AttachedSheet/index-debug.html new file mode 100644 index 000000000..12093852b --- /dev/null +++ b/Tests/AppKit/AttachedSheet/index-debug.html @@ -0,0 +1,83 @@ + + + + + + + + Untitled + + + + + + + + + + + + + +
    + + + +
    + + + diff --git a/Tests/AppKit/AttachedSheet/index.html b/Tests/AppKit/AttachedSheet/index.html new file mode 100644 index 000000000..d44a75d39 --- /dev/null +++ b/Tests/AppKit/AttachedSheet/index.html @@ -0,0 +1,69 @@ + + + + + + + + Attached Sheet + + + + + + + + + + + + +
    + + + +
    + + + + diff --git a/Tests/AppKit/AttachedSheet/main.j b/Tests/AppKit/AttachedSheet/main.j new file mode 100755 index 000000000..b67c4550b --- /dev/null +++ b/Tests/AppKit/AttachedSheet/main.j @@ -0,0 +1,18 @@ +/* + * AppController.j + * SplitView + * + * Created by You on August 1, 2009. + * Copyright 2009, Your Company All rights reserved. + */ + +@import +@import + +@import "AppController.j" + + +function main(args, namedArgs) +{ + CPApplicationMain(args, namedArgs); +} From 1d8cebd5be0f4659620a501d746f59c132a92bc5 Mon Sep 17 00:00:00 2001 From: cacaodev Date: Wed, 7 Oct 2009 12:44:26 +0200 Subject: [PATCH 06/10] CPWindow : Added missing declarations for _isSheet and _parentView sheet's subviews autoresizingMask is now correctly restored when the sheet is open or ended. Added CPWindow(WillBegin/DidEnd)SheetNotification globals To do : support for maxSize and minSize --- AppKit/CPWindow/CPWindow.j | 56 ++++++++++++++++----- Tests/AppKit/AttachedSheet/AppController.j | 21 +++++--- Tests/AppKit/AttachedSheet/index-debug.html | 4 +- 3 files changed, 58 insertions(+), 23 deletions(-) diff --git a/AppKit/CPWindow/CPWindow.j b/AppKit/CPWindow/CPWindow.j index 6019bd4f6..35f023f3f 100644 --- a/AppKit/CPWindow/CPWindow.j +++ b/AppKit/CPWindow/CPWindow.j @@ -176,7 +176,8 @@ CPWindowWillCloseNotification = @"CPWindowWillCloseNotification"; CPWindowDidBecomeMainNotification = @"CPWindowDidBecomeMainNotification"; CPWindowDidResignMainNotification = @"CPWindowDidResignMainNotification"; CPWindowDidMoveNotification = @"CPWindowDidMoveNotification"; - +CPWindowWillBeginSheetNotification = @"CPWindowWillBeginSheetNotification"; +CPWindowDidEndSheetNotification = @"CPWindowDidEndSheetNotification"; CPWindowShadowStyleStandard = 0; CPWindowShadowStyleMenu = 1; @@ -311,6 +312,8 @@ var CPWindowSaveImage = nil, _CPWindowFullPlatformWindowSession _fullPlatformWindowSession; CPDictionary _sheetContext; + CPWindow _parentView; + BOOL _isSheet; } /* @@ -365,6 +368,7 @@ CPTexturedBackgroundWindowMask _isFullPlatformWindow = NO; _registeredDraggedTypes = [CPSet set]; _registeredDraggedTypesArray = []; + _isSheet = NO; // Set up our window number. _windowNumber = [CPApp._windows count]; @@ -1769,12 +1773,10 @@ CPTexturedBackgroundWindowMask sheetContent = [aSheet contentView]; // Configure sheet. -// if ([aSheet styleMask] & CPHUDBackgroundWindowMask) -// [aSheet setMovableByWindowBackground:NO]; - _sheetContext["autoresizingMask"] = [sheetContent autoresizingMask]; [sheetContent setAutoresizingMask:CPViewMinYMargin]; - [sheetContent setAutoresizesSubviews:NO]; + [self _hookSubviews:sheetContent]; + aSheet._isSheet = YES; aSheet._parentView = self; @@ -1785,7 +1787,7 @@ CPTexturedBackgroundWindowMask var endFrame = CGRectMake(originx, originy, sheetFrame.size.width, sheetFrame.size.height); // Notify the world we will open the sheet - [[CPNotificationCenter defaultCenter] postNotificationName:@"CPWindowWillBeginSheetNotification" object:self]; + [[CPNotificationCenter defaultCenter] postNotificationName:CPWindowWillBeginSheetNotification object:self]; // Start modal [CPApp runModalForWindow:aSheet]; @@ -1817,8 +1819,8 @@ CPTexturedBackgroundWindowMask // Autoresizing var sheetContent = [sheet contentView]; [sheetContent setAutoresizingMask:CPViewMinYMargin]; - [sheetContent setAutoresizesSubviews:NO]; - + [self _hookSubviews:sheetContent]; + _sheetContext["opened"] = NO; // Start animation with delegate [sheet _setFrame:endFrame delegate:self duration:0.2 curve:CPAnimationLinear]; @@ -1834,17 +1836,19 @@ CPTexturedBackgroundWindowMask // Retore autoresizing var sheetContent = [sheet contentView]; [sheetContent setAutoresizingMask:_sheetContext["autoresizingMask"]]; - [sheetContent setAutoresizesSubviews:YES]; // If we are opened return now if (_sheetContext["opened"] === YES) + { + [self _unHookSubviews:sheetContent]; return; + } // Stop modal [CPApp stopModal]; // Notify the world we closed the sheet - [[CPNotificationCenter defaultCenter] postNotificationName:@"CPWindowDidEndSheetNotification" object:self]; + [[CPNotificationCenter defaultCenter] postNotificationName:CPWindowDidEndSheetNotification object:self]; // check first if front ? [sheet orderOut:self]; @@ -1852,13 +1856,15 @@ CPTexturedBackgroundWindowMask // Set the sheet frame to its last open state. var lastFrame = _sheetContext["frame"]; [sheet setFrame:lastFrame]; - + + [self _unHookSubviews:sheetContent]; + // Send didEndSelector var delegate = _sheetContext["modalDelegate"]; var endSelector = _sheetContext["endSelector"]; if (delegate != nil && endSelector != nil) - objj_msgSend(_sheetContext["modalDelegate"], - _sheetContext["endSelector"], + objj_msgSend(delegate, + endSelector, sheet, _sheetContext["returnCode"], _sheetContext["contextInfo"]); @@ -1868,6 +1874,30 @@ CPTexturedBackgroundWindowMask sheet._parentView = nil; } +- (void)_hookSubviews:(CPView)view +{ + var subviews = [view subviews]; + for (var i = 0; i < [subviews count]; i++) + { + var subview = [subviews objectAtIndex:i]; + var mask = [subview autoresizingMask]; + var addMask = (mask & CPViewMinYMargin) ? 128 : CPViewMinYMargin; + [subview setAutoresizingMask:(mask | addMask)]; + } +} + +- (void)_unHookSubviews:(CPView)view +{ + var subviews = [view subviews]; + for (var i = 0; i < [subviews count]; i++) + { + var subview = [subviews objectAtIndex:i]; + var mask = [subview autoresizingMask]; + var subMask = (mask & 128) ? 128 : CPViewMinYMargin; + [subview setAutoresizingMask:(mask & (~ subMask))]; + } +} + /*! Returns the window's attached sheet. */ diff --git a/Tests/AppKit/AttachedSheet/AppController.j b/Tests/AppKit/AttachedSheet/AppController.j index e40c804b6..d5ef53467 100644 --- a/Tests/AppKit/AttachedSheet/AppController.j +++ b/Tests/AppKit/AttachedSheet/AppController.j @@ -10,16 +10,16 @@ @implementation AppController : CPObject { - CPWindow window; - CPWindow sheet; - CPTextField textField; + CPWindow window; + CPWindow sheet; + CPTextField textField; } - (void)applicationDidFinishLaunching:(CPNotification)aNotification { window = [[CPWindow alloc] initWithContentRect:CGRectMake(100,100,500,300) styleMask:CPResizableWindowMask], contentView = [window contentView]; - + sheet = [[CPWindow alloc] initWithContentRect:CGRectMake(0,0,300,100) styleMask:CPDocModalWindowMask|CPResizableWindowMask]; // [sheet setMinSize:CGSizeMake(300,100)]; @@ -28,7 +28,7 @@ textField = [[CPTextField alloc] initWithFrame:CGRectMake(10,30,280,30)]; [textField setEditable:YES]; [textField setBezeled:YES]; - [textField setAutoresizingMask:CPViewMinYMargin|CPViewWidthSizable]; + [textField setAutoresizingMask:CPViewWidthSizable]; var okButton = [[CPButton alloc] initWithFrame:CGRectMake(230,70,50,24)]; [okButton setTitle:"OK"]; @@ -47,13 +47,13 @@ [sheetContent addSubview:textField]; [sheetContent addSubview:okButton]; [sheetContent addSubview:cancelButton]; - + var displayButton = [[CPButton alloc] initWithFrame:CGRectMake(200,150,100,24)]; [displayButton setTitle:"Display Sheet"]; [displayButton setTarget:self]; [displayButton setAction:@selector(displaySheet:)]; - [contentView addSubview:displayButton]; + [window orderFront:self] } @@ -62,7 +62,12 @@ [textField setStringValue:""]; [sheet makeFirstResponder:textField]; - [CPApp beginSheet:sheet modalForWindow:window modalDelegate:self didEndSelector:@selector(didEndSheet:returnCode:contextInfo:) contextInfo:nil]; + [CPApp beginSheet:sheet modalForWindow:window modalDelegate:self didEndSelector:@selector(didEndSheet:returnCode:contextInfo:) contextInfo:nil]; +} + +- (void)alertDidEnd:(CPWindow)sheet returnCode:(int)returnCode contextInfo:(id)contextInfo +{ + CPLogConsole(_cmd+" returnCode " + returnCode); } - (void)closeSheet:(id)sender diff --git a/Tests/AppKit/AttachedSheet/index-debug.html b/Tests/AppKit/AttachedSheet/index-debug.html index 12093852b..4daefda17 100644 --- a/Tests/AppKit/AttachedSheet/index-debug.html +++ b/Tests/AppKit/AttachedSheet/index-debug.html @@ -13,7 +13,7 @@ - Untitled + Attached Sheet