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
This commit is contained in:
cacaodev authored and Ross Boucher committed 2009-10-08 12:58:37 -07:00
1 parent 0e55a5d7c4
commit 1d8cebd5be
3 files changed
+58 -23

No files matched your search

+43 -13
View File
@@ -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.
*/
+13 -8
View File
@@ -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
+2 -2
View File
@@ -13,7 +13,7 @@
<head>
<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" />
<title>Untitled</title>
<title>Attached Sheet</title>
<script type = "text/javascript">
OBJJ_MAIN_FILE = "main.j";
@@ -58,7 +58,7 @@
<script type = "text/javascript">
document.write("<div id='container'><p id='content'>" +
"<img id='loadgraphic' width='16' height='16' src='Resources/spinner.gif' /> " +
"Loading Untitled...</p></div>");
"Loading Attached Sheet...</p></div>");
</script>
<noscript>