From c0aa78eb762f7a993f8e3a5bda7c501f4536cedd Mon Sep 17 00:00:00 2001 From: Tom Robinson Date: Thu, 4 Dec 2008 21:58:01 -0800 Subject: [PATCH 1/5] Make CPColorWell resize correctly, and display immediately upon unarchiving. --- AppKit/CPColorWell.j | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/AppKit/CPColorWell.j b/AppKit/CPColorWell.j index d2a16d1d9..cc605e841 100644 --- a/AppKit/CPColorWell.j +++ b/AppKit/CPColorWell.j @@ -199,6 +199,7 @@ var _CPColorWellDidBecomeExclusiveNotification = @"_CPColorWellDidBecomeExclusiv if (!_wellView) { _wellView = [[CPView alloc] initWithFrame:aRect]; + [_wellView setAutoresizingMask:CPViewWidthSizable | CPViewHeightSizable]; [self addSubview:_wellView]; } @@ -272,7 +273,10 @@ var CPColorWellColorKey = "CPColorWellColorKey", _active = NO; _bordered = [aCoder decodeObjectForKey:CPColorWellBorderedKey]; _color = [aCoder decodeObjectForKey:CPColorWellColorKey]; - + + [self drawBezelWithHighlight:NO]; + [self drawWellInside:CGRectInset([self bounds], 3.0, 3.0)]; + [self _registerForNotifications]; } From e0967272e762f1f5b7b3729b9996c24097fb82dd Mon Sep 17 00:00:00 2001 From: Tom Robinson Date: Thu, 4 Dec 2008 22:04:41 -0800 Subject: [PATCH 2/5] Explicitly set radix to 10 for Ross. --- AppKit/CPGeometry.j | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/AppKit/CPGeometry.j b/AppKit/CPGeometry.j index 885db67ce..ca1c3118a 100644 --- a/AppKit/CPGeometry.j +++ b/AppKit/CPGeometry.j @@ -430,7 +430,7 @@ function CPPointFromString(aString) { var comma = aString.indexOf(','); - return { x:parseFloat(aString.substr(1, comma - 1)), y:parseFloat(aString.substring(comma + 1, aString.length)) }; + return { x:parseFloat(aString.substr(1, comma - 1), 10), y:parseFloat(aString.substring(comma + 1, aString.length), 10) }; } /*! @@ -443,7 +443,7 @@ function CPSizeFromString(aString) { var comma = aString.indexOf(','); - return { width:parseFloat(aString.substr(1, comma - 1)), height:parseFloat(aString.substring(comma + 1, aString.length)) }; + return { width:parseFloat(aString.substr(1, comma - 1), 10), height:parseFloat(aString.substring(comma + 1, aString.length), 10) }; } /*! From 10db0dab7ece9f2ab207f7094d647f2102452325 Mon Sep 17 00:00:00 2001 From: Tom Robinson Date: Thu, 4 Dec 2008 22:11:25 -0800 Subject: [PATCH 3/5] Add %b specifier to sprintf for printing in binary. --- Foundation/CPString.j | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/Foundation/CPString.j b/Foundation/CPString.j index c7468c685..310a9aecc 100644 --- a/Foundation/CPString.j +++ b/Foundation/CPString.j @@ -645,8 +645,8 @@ String.prototype.isa = CPString; // sprintf: -var sprintfFormatRegex = new RegExp("([^%]+|%[\\+\\-\\ \\#0]*[0-9\\*]*(.[0-9\\*]+)?[hlL]?[cdieEfgGosuxXpn%@])", "g"); -var sprintfTagRegex = new RegExp("(%)([\\+\\-\\ \\#0]*)([0-9\\*]*)((.[0-9\\*]+)?)([hlL]?)([cdieEfgGosuxXpn%@])"); +var sprintfFormatRegex = new RegExp("([^%]+|%[\\+\\-\\ \\#0]*[0-9\\*]*(.[0-9\\*]+)?[hlL]?[cbBdieEfgGosuxXpn%@])", "g"); +var sprintfTagRegex = new RegExp("(%)([\\+\\-\\ \\#0]*)([0-9\\*]*)((.[0-9\\*]+)?)([hlL]?)([cbBdieEfgGosuxXpn%@])"); /*! Creates a new string using C printf-style formatting. First argument should be a constant format string, like ' "float val = %f" ', remaining arguments should be the variables to print the values of, comma-separated. @@ -706,7 +706,7 @@ function sprintf(format) var subresult = ""; - if (RegExp("[diufeExXo]").test(specifier)) + if (RegExp("[bBdiufeExXo]").test(specifier)) { var num = Number(arguments[arg++]); @@ -754,6 +754,14 @@ function sprintf(format) subresult = sprintf_justify(sign, prefix, number, "", width, leftJustify, padZeros); } + if (specifier == "b" || specifier == "B") + { + var number = String(Math.abs(num).toString(2)); + var prefix = (flags.indexOf("#") >= 0 && num != 0) ? "0b" : ""; + + subresult = sprintf_justify(sign, prefix, number, "", width, leftJustify, padZeros); + } + if (specifier == "o") { var number = String(Math.abs(num).toString(8)); From 3516e026d06eb38710495c902972f3166be78aa2 Mon Sep 17 00:00:00 2001 From: Tom Robinson Date: Thu, 4 Dec 2008 22:13:41 -0800 Subject: [PATCH 4/5] Improved nib2cib support for windows (min/max size, correct autoresize mask, flipped Y coordinate) --- AppKit/Cib/_CPCibWindowTemplate.j | 25 +++++++++++++++---------- Tools/nib2cib/NSWindowTemplate.j | 16 ++++++++++------ 2 files changed, 25 insertions(+), 16 deletions(-) diff --git a/AppKit/Cib/_CPCibWindowTemplate.j b/AppKit/Cib/_CPCibWindowTemplate.j index a9a168d4e..31d9ce3a1 100644 --- a/AppKit/Cib/_CPCibWindowTemplate.j +++ b/AppKit/Cib/_CPCibWindowTemplate.j @@ -35,8 +35,10 @@ var _CPCibWindowTemplateMinSizeKey = @"_CPCibWindowTemplateMinSizeKey", if (self) { - _minSize = [aCoder decodeSizeForKey:_CPCibWindowTemplateMinSizeKey]; - _maxSize = [aCoder decodeSizeForKey:_CPCibWindowTemplateMaxSizeKey]; + if ([aCoder containsValueForKey:_CPCibWindowTemplateMinSizeKey]) + _minSize = [aCoder decodeSizeForKey:_CPCibWindowTemplateMinSizeKey]; + if ([aCoder containsValueForKey:_CPCibWindowTemplateMaxSizeKey]) + _maxSize = [aCoder decodeSizeForKey:_CPCibWindowTemplateMaxSizeKey]; _viewClass = [aCoder decodeObjectForKey:_CPCibWindowTemplateViewClassKey]; @@ -53,8 +55,10 @@ var _CPCibWindowTemplateMinSizeKey = @"_CPCibWindowTemplateMinSizeKey", - (void)encodeWithCoder:(CPCoder)aCoder { - [aCoder encodeSize:_minSize forKey:_CPCibWindowTemplateMinSizeKey]; - [aCoder encodeSize:_maxSize forKey:_CPCibWindowTemplateMaxSizeKey]; + if (_minSize) + [aCoder encodeSize:_minSize forKey:_CPCibWindowTemplateMinSizeKey]; + if (_maxSize) + [aCoder encodeSize:_maxSize forKey:_CPCibWindowTemplateMaxSizeKey]; [aCoder encodeObject:_viewClass forKey:_CPCibWindowTemplateViewClassKey]; @@ -74,12 +78,13 @@ var _CPCibWindowTemplateMinSizeKey = @"_CPCibWindowTemplateMinSizeKey", [NSException raise:NSInvalidArgumentException format:@"Unable to locate NSWindow class %@, using NSWindow",_windowClass]; class=[NSWindow class];*/ - var theWindow = [[windowClass alloc] initWithContentRect:_windowRect styleMask:CPHUDBackgroundWindowMask | CPClosableWindowMask];//styleMask:_windowStyleMask]; -// alert(CPStringFromRect(_windowRect)); -// alert(CPStringFromSize(_minSize)); -// alert(CPStringFromSize(_maxSize)); - //[theWindow setMinSize:_minSize]; - //[theWindow setMaxSize:_maxSize]; + _windowStyleMask = (CPHUDBackgroundWindowMask | CPClosableWindowMask | CPResizableWindowMask); + var theWindow = [[windowClass alloc] initWithContentRect:_windowRect styleMask:_windowStyleMask]; + + if (_minSize) + [theWindow setMinSize:_minSize]; + if (_maxSize) + [theWindow setMaxSize:_maxSize]; [theWindow setLevel:CPFloatingWindowLevel]; //[result setHidesOnDeactivate:(_wtFlags&0x80000000)?YES:NO]; diff --git a/Tools/nib2cib/NSWindowTemplate.j b/Tools/nib2cib/NSWindowTemplate.j index 42537c657..9063c18a9 100644 --- a/Tools/nib2cib/NSWindowTemplate.j +++ b/Tools/nib2cib/NSWindowTemplate.j @@ -30,9 +30,12 @@ self = [super init]; if (self) - { - _minSize = [aCoder decodeSizeForKey:@"NSMinSize"]; - _maxSize = [aCoder decodeSizeForKey:@"NSMaxSize"]; + { + if ([aCoder containsValueForKey:@"NSMinSize"]) + _minSize = [aCoder decodeSizeForKey:@"NSMinSize"]; + if ([aCoder containsValueForKey:@"NSMaxSize"]) + _maxSize = [aCoder decodeSizeForKey:@"NSMaxSize"]; + _screenRect = [aCoder decodeRectForKey:@"NSScreenRect"]; // screen created on _viewClass = [aCoder decodeObjectForKey:@"NSViewClass"]; _wtFlags = [aCoder decodeIntForKey:@"NSWTFlags"]; @@ -46,9 +49,10 @@ _windowTitle = [aCoder decodeObjectForKey:@"NSWindowTitle"]; _windowView = [aCoder decodeObjectForKey:@"NSWindowView"]; - /* - _windowRect.origin.y -= _screenRect.size.height - [[NSScreen mainScreen] frame].size.height; - if (![_windowClass isEqualToString:@"NSPanel"]) + // Flip Y coordinate + _windowRect.origin.y = _screenRect.size.height - _windowRect.origin.y - _windowRect.size.height; + + /*if (![_windowClass isEqualToString:@"NSPanel"]) _windowRect.origin.y -= [NSMainMenuView menuHeight]; // compensation for the additional menu bar */ } From abe2e14af4c67a3f006be29721f91f2cc536a310 Mon Sep 17 00:00:00 2001 From: Tom Robinson Date: Thu, 4 Dec 2008 22:16:24 -0800 Subject: [PATCH 5/5] CPLog integration with sprintf. --- Foundation/CPLog.j | 43 ++++++++++++++++++++++--------------------- 1 file changed, 22 insertions(+), 21 deletions(-) diff --git a/Foundation/CPLog.j b/Foundation/CPLog.j index 77000967f..d2f814bd4 100644 --- a/Foundation/CPLog.j +++ b/Foundation/CPLog.j @@ -27,9 +27,9 @@ var CPLogDefaultTitle = "Cappuccino"; var CPLogLevels = ["fatal", "error", "warn", "info", "debug", "trace"]; var CPLogDefaultLevel = CPLogLevels[0]; -var CPLogLevelsInverted = {}; +var _CPLogLevelsInverted = {}; for (var i = 0; i < CPLogLevels.length; i++) - CPLogLevelsInverted[CPLogLevels[i]] = i; + _CPLogLevelsInverted[CPLogLevels[i]] = i; var _CPLogRegistrations = {}; @@ -37,20 +37,15 @@ var _CPLogRegistrations = {}; var _CPFormatLogMessage = function(aString, aLevel, aTitle) { - var now = new Date(), - zero = function(number, zeros) - { - var digits = number.toString(); - return zeros.substring(0, zeros.length - digits.length) + digits; - } + var now = new Date(); - var level = aLevel ? " ["+aLevel+"]" : ""; - var message = - now.getFullYear() + "-" + zero(now.getMonth()+1, "00") + "-" + zero(now.getDate(), "00") + " " + - zero(now.getHours(), "00") + ":" + zero(now.getMinutes(), "00") + ":" + zero(now.getSeconds(), "00") + "." + - zero(now.getMilliseconds(), "000")+" " + aTitle + level + ": " + aString; - - return message; + if (typeof sprintf == "function") + return sprintf("%4d-%02d-%02d %02d:%02d:%02d.%03d %s [%s]: %s", + now.getFullYear(), now.getMonth(), now.getDate(), + now.getHours(), now.getMinutes(), now.getSeconds(), now.getMilliseconds(), + aTitle, aLevel, aString); + else + return now + " " + aTitle + " [" + aLevel + "]: " + aString; } // Register Functions: @@ -63,8 +58,8 @@ function CPLogRegister(aProvider, aMaxLevel) // Register a logger for a range of levels function CPLogRegisterRange(aProvider, aMinLevel, aMaxLevel) { - var min = CPLogLevelsInverted[aMinLevel]; - var max = CPLogLevelsInverted[aMaxLevel]; + var min = _CPLogLevelsInverted[aMinLevel]; + var max = _CPLogLevelsInverted[aMaxLevel]; if (min != undefined && max != undefined) for (var i = 0; i <= max; i++) @@ -80,21 +75,27 @@ function CPLogRegisterSingle(aProvider, aLevel) } // Main CPLog, which dispatches to individual loggers -function CPLog(aString, aLevel, aTitle) +function _CPLogDispatch(parameters, aLevel, aTitle) { if (aTitle == undefined) aTitle = CPLogDefaultTitle; if (aLevel == undefined) aLevel = CPLogDefaultLevel; + // to format message: use sprintf if available; otherwise do a simple join + var message = (typeof sprintf == "function") ? sprintf.apply(null, parameters) : Array.prototype.join.call(parameters, ", "); + if (_CPLogRegistrations[aLevel]) for (var i = 0; i < _CPLogRegistrations[aLevel].length; i++) - _CPLogRegistrations[aLevel][i](aString, aLevel, aTitle); + _CPLogRegistrations[aLevel][i](message, aLevel, aTitle); } -// Shortcuts for common log levels (CPLog.fatal(), CPLog.error(), etc) +// Setup CPLog() and CPLog.xxx() aliases + +function CPLog() { _CPLogDispatch(arguments); } + for (var i = 0; i < CPLogLevels.length; i++) - CPLog[CPLogLevels[i]] = (function(level) { return function(message, title) { CPLog(message, level, title); }; })(CPLogLevels[i]); + CPLog[CPLogLevels[i]] = (function(level) { return function() { _CPLogDispatch(arguments, level); }; })(CPLogLevels[i]); // Loggers: