diff --git a/AppKit/CPAnimation.j b/AppKit/CPAnimation.j
index 43b7154ed..c2e745a6d 100644
--- a/AppKit/CPAnimation.j
+++ b/AppKit/CPAnimation.j
@@ -117,10 +117,6 @@ ACTUAL_FRAME_RATE = 0;
*/
- (void)setAnimationCurve:(CPAnimationCurve)anAnimationCurve
{
- _animationCurve = anAnimationCurve;
-
- var timingFunctionName = kCAMediaTimingFunctionLinear;
-
switch (_animationCurve)
{
case CPAnimationEaseInOut: timingFunctionName = kCAMediaTimingFunctionEaseInEaseOut;
@@ -131,12 +127,16 @@ ACTUAL_FRAME_RATE = 0;
case CPAnimationEaseOut: timingFunctionName = kCAMediaTimingFunctionEaseOut;
break;
+
+ case CPAnimationLinear: timingFunctionName = kCAMediaTimingFunctionLinear;
+ break;
default: [CPException raise:CPInvalidArgumentException
reason:"Invalid value provided for animation curve"];
break;
}
+ _animationCurve = anAnimationCurve;
_timingFunction = [CAMediaTimingFunction functionWithName:timingFunctionName];
}
diff --git a/AppKit/CPDragServer.j b/AppKit/CPDragServer.j
index da1b4e5bd..0c1cdf798 100644
--- a/AppKit/CPDragServer.j
+++ b/AppKit/CPDragServer.j
@@ -157,6 +157,16 @@ var CPDragServerUpdateDragging = function(anEvent)
return [CPDragServerView image];
}
+- (CGPoint)draggedImageLocation
+{
+ return [self draggedViewLocation];
+}
+
+- (CGPoint)draggedViewLocation
+{
+ return [[CPDragServerDestination window] convertBridgeToBase:[CPDragServerView frame].origin];
+}
+
- (CPView)draggedView
{
return CPDragServerView;
diff --git a/AppKit/CPMenu.j b/AppKit/CPMenu.j
index 1179ef946..1aed32613 100644
--- a/AppKit/CPMenu.j
+++ b/AppKit/CPMenu.j
@@ -905,7 +905,7 @@ var STICKY_TIME_INTERVAL = 500,
if (self)
{
- [self setLevel:CPTornOffMenuWindowLevel];
+ [self setLevel:CPPopUpMenuWindowLevel];
[self setHasShadow:YES];
[self setAcceptsMouseMovedEvents:YES];
diff --git a/AppKit/CPPopUpButton.j b/AppKit/CPPopUpButton.j
index 32eabce09..bd8f19659 100644
--- a/AppKit/CPPopUpButton.j
+++ b/AppKit/CPPopUpButton.j
@@ -631,8 +631,9 @@ var CPPopUpButtonArrowsImage = nil;
[self highlight:YES];
- var theWindow = [self window],
- menuWindow = [_CPMenuWindow menuWindowWithMenu:[self menu] font:[self font]];
+ var menu = [self menu],
+ theWindow = [self window],
+ menuWindow = [_CPMenuWindow menuWindowWithMenu:menu font:[self font]];
[menuWindow setDelegate:self];
[menuWindow setBackgroundStyle:_CPMenuWindowPopUpBackgroundStyle];
@@ -648,14 +649,14 @@ var CPPopUpButtonArrowsImage = nil;
{
var contentRect = [menuWindow rectForItemAtIndex:_selectedIndex];
- menuOrigin.x -= CGRectGetMinX(contentRect) + [_CPMenuItemView leftMargin];
+ menuOrigin.x -= CGRectGetMinX(contentRect) + [[[menu itemAtIndex:_selectedIndex] _menuItemView] calculatedLeftMargin];
menuOrigin.y -= CGRectGetMinY(contentRect);
}
[menuWindow setFrameOrigin:menuOrigin];
var menuMaxX = CGRectGetMaxX([menuWindow frame]),
- buttonMaxX = CGRectGetMaxX([self convertRect:[self bounds] toView:nil]);
+ buttonMaxX = [theWindow convertBaseToBridge:CGPointMake(CGRectGetMaxX([self convertRect:[self bounds] toView:nil]), 0.0)].x;
if (menuMaxX < buttonMaxX)
[menuWindow setMinWidth:CGRectGetWidth([menuWindow frame]) + buttonMaxX - menuMaxX - VISIBLE_MARGIN];
diff --git a/AppKit/CPSplitView.j b/AppKit/CPSplitView.j
index e6c07a987..0358f3f81 100644
--- a/AppKit/CPSplitView.j
+++ b/AppKit/CPSplitView.j
@@ -369,6 +369,7 @@ var CPSplitViewHorizontalImage = nil,
- (void)mouseDown:(CPEvent)anEvent
{
+ // FIXME: This should not trap events if not on a divider!
[self trackDivider:anEvent];
}
diff --git a/AppKit/CPTableColumn.j b/AppKit/CPTableColumn.j
index 2407b4c3a..1421eecb1 100644
--- a/AppKit/CPTableColumn.j
+++ b/AppKit/CPTableColumn.j
@@ -43,6 +43,10 @@ CPTableColumnAutoresizingMask = 1;
*/
CPTableColumnUserResizingMask = 2;
+#define PurgableInfoMake(aView, aRow) { view:(aView), row:(aRow) }
+#define PurgableInfoView(anInfo) ((anInfo).view)
+#define PurgableInfoRow(anInfo) ((anInfo).row)
+
/*! @class CPTableColumn
An CPTableColumn object mainly keeps information about the width of the column, its minimum and maximum width; whether the column can be edited or resized; and the cells used to draw the column header and the data in the column. You can change all these attributes of the column by calling the appropriate methods. Please note that the table column does not hold nor has access to the data to be displayed in the column; this data is maintained in the table view's data source.
@@ -54,6 +58,7 @@ CPTableColumnUserResizingMask = 2;
@implementation CPTableColumn : CPObject
{
CPString _identifier;
+ CPView _headerView;
CPTableView _tableView;
@@ -62,6 +67,12 @@ CPTableColumnUserResizingMask = 2;
float _maxWidth;
unsigned _resizingMask;
+
+ CPView _dataView;
+
+ Object _dataViewData;
+ Object _dataViewForView;
+ Object _purgableInfosForDataView;
}
/*!
@@ -81,8 +92,14 @@ CPTableColumnUserResizingMask = 2;
_minWidth = 8.0;
_maxWidth = 1000.0;
- // FIXME
- _dataCell = [[CPTextField alloc] initWithFrame:CPRectMakeZero()];
+ _dataViewData = {};
+ _dataViewForView = {};
+ _purgableInfosForDataView = {};
+
+ [self setDataView:[[CPTextField alloc] initWithFrame:CPRectMakeZero()]];
+
+ _headerView = [[CPTextField alloc] initWithFrame:CPRectMakeZero()];
+ [_headerView setBackgroundColor:[CPColor greenColor]];
}
return self;
@@ -229,13 +246,16 @@ CPTableColumnUserResizingMask;
return _isEditable;
}
+//Setting the column header view
+
/*!
Sets the view that draws the column's header.
@param aHeaderView the view that will draws the column header
*/
-- (void)setHeaderView:(CPView)aHeaderView
+
+- (void)setHeaderView:(CPView)aView
{
- _headerView = aHeaderView;
+ _headerView = aView;
}
/*!
@@ -249,9 +269,21 @@ CPTableColumnUserResizingMask;
/*!
Sets the data cell that draws rows in this column.
*/
-- (void)setDataCell:(CPCell)aDataCell
+- (void)setDataCell:(CPView )aView
{
- _dataCell = aDataCell;
+ [self setDataView:aView];
+}
+
+/*
+ Sets the data view that draws rows in this column.
+*/
+- (void)setDataView:(CPView )aView
+{
+ if (_dataView)
+ _dataViewData[[_dataView hash]] = nil;
+
+ _dataView = aView;
+ _dataViewData[[aView hash]] = [CPKeyedArchiver archivedDataWithRootObject:aView];
}
/*!
@@ -259,7 +291,15 @@ CPTableColumnUserResizingMask;
*/
- (CPCell)dataCell
{
- return _dataCell;
+ return _dataView;
+}
+
+/*
+ Returns the data view that draws rows in this column
+*/
+- (CPView)dataView
+{
+ return [self dataCell];
}
/*!
@@ -270,7 +310,84 @@ CPTableColumnUserResizingMask;
*/
- (CPCell)dataCellForRow:(int)aRowIndex
{
- return [self dataCell];
+ return [self dataView];
+}
+
+- (CPView)dataViewForRow:(int)aRowIndex
+{
+ return [self dataCellForRow:aRowIndex];
+}
+
+- (void)_markViewAsPurgable:(CPView)aView
+{
+ var viewHash = [aView hash],
+ dataViewHash = [_dataViewForView[viewHash] hash];
+
+ if (!_purgableInfosForDataView[dataViewHash])
+ _purgableInfosForDataView[dataViewHash] = [CPDictionary dictionary];
+
+ [_purgableInfosForDataView[dataViewHash] setObject:aView forKey:viewHash];
+}
+
+- (void)_markView:(CPView)aView inRow:(unsigned)aRow asPurgable:(BOOL)isPurgable
+{
+ var viewHash = [aView hash],
+ dataViewHash = [_dataViewForView[viewHash] hash];
+
+ if (!_purgableInfosForDataView[dataViewHash])
+ {
+ if (!isPurgable)
+ return;
+
+ _purgableInfosForDataView[dataViewHash] = [CPDictionary dictionary];
+ }
+
+ if (!isPurgable)
+ [_purgableInfosForDataView[dataViewHash] removeObjectForKey:viewHash];
+ else
+ [_purgableInfosForDataView[dataViewHash] setObject:PurgableInfoMake(aView, aRow) forKey:viewHash];
+}
+
+- (CPView)_newDataViewForRow:(int)aRowIndex avoidingRows:(CPRange)rows
+{
+ var view = [self dataViewForRow:aRowIndex],
+ viewHash = [view hash],
+ dataViewHash = [_dataViewForView[viewHash] hash],
+ purgableInfos = _purgableInfosForDataView[dataViewHash];
+ //console.warn("ok, a cell is needed");
+ if (purgableInfos && [purgableInfos count])
+ {//console.warn("yes, inside");
+ var keys = [purgableInfos allKeys],
+ count = keys.length;
+
+ while (count--)
+ {
+ var key = keys[count],
+ info = [purgableInfos objectForKey:key];
+
+ [purgableInfos removeObjectForKey:key];
+
+ if (CPLocationInRange(PurgableInfoRow(info), rows))
+ continue;
+ //console.warn("yes, a purged view is usable, its called" + PurgableInfoView(info));
+ return PurgableInfoView(info);
+ }
+ }
+
+ var data = _dataViewData[viewHash];
+
+ if (!data)
+ {
+ _dataViewData[viewHash] = [CPKeyedArchiver archivedDataWithRootObject:view];
+ data = _dataViewData[viewHash];
+ }
+ //console.warn("nope, time for creation");
+ return [CPKeyedUnarchiver unarchiveObjectWithData:data];
}
@end
+
+_PurgableViewInfoMake = function(aView, aRow)
+{
+ return { view:aView, row:aRow};
+}
diff --git a/AppKit/CPTableView.j b/AppKit/CPTableView.j
index cf4bcd744..87362ebd5 100644
--- a/AppKit/CPTableView.j
+++ b/AppKit/CPTableView.j
@@ -20,11 +20,12 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
-import "CPControl.j"
-import "CPTableColumn.j"
+@import "CPControl.j"
+@import "CPTableColumn.j"
+//objj_backtrace_set_enable(true);
-var CPTableViewCellPlaceholder = nil;
+#define ROW_HEIGHT(aRow) (_hasVariableHeightRows ? _rowHeights[aRow] : _rowHeight);
/*
CPTableView is located within the AppKit framework and is used to display tables. It uses a delegate model for getting its data i.e. you give it an object that provides it with the data it should display.
@@ -33,28 +34,40 @@ var CPTableViewCellPlaceholder = nil;
*/
@implementation CPTableView : CPControl
{
- id _dataSource;
+ id _dataSource;
CPScrollView _scrollView;
CPTableHeaderView _headerView;
- CPArray _tableColumns;
+ CPArray _tableColumns;
+ //
unsigned _numberOfRows;
unsigned _numberOfColumns;
+ // Heights
+ float _rowHeight;
+ float _columnHeight; // calculated
+
+ CPArray _rowMinYs;
+ CPArray _rowHeights;
+
+ BOOL _hasVariableHeightRows;
+
CPArray _tableCells;
CPArray _tableColumnViews;
- CGSize _intercellSpacing;
-}
-
-+ (void)initialize
-{
- if (self != [CPTableView class])
- return;
+ CGSize _intercellSpacing;
- CPTableViewCellPlaceholder = [[CPObject alloc] init];
+ // Caching
+ Object _dataViewCache;
+ CPArray _objectValueCache;
+
+ CPRange _visibleRows;
+ CPRange _visibleColumns;
+
+ CPRange _populatedRows;
+ CPRange _populatedColumns;
}
- (id)initWithFrame:(CGRect)aFrame
@@ -62,27 +75,20 @@ var CPTableViewCellPlaceholder = nil;
self = [super initWithFrame:aFrame];
if (self)
- {
- /*_scrollView = [[CPView alloc] initWithFrame:CPRectMakeZero()];
- _headerView = [[CPView alloc] initWithFrame:CPRectMakeZero()];
-
- [_scrollView setBackgroundColor:[CPColor redColor]];
- [_headerView setBackgroundColor:[CPColor blueColor]];
-
- [self addSubview:_scrollView];
- [self addSubview:_headerView];
-
- [self tile];*/
-
- //[self setBackgroundColor:[CPColor redColor]];
-
+ {
_rowHeight = 17.0;
- _tableCells = [[CPArray alloc] init];
- _tableColumns = [[CPArray alloc] init];
- _tableColumnViews = [[CPArray alloc] init];
+ _tableCells = [];
+ _tableColumns = [];
+ _tableColumnViews = [];
+ _dataViewCache = {};
+ _objectValueCache = {};
+
_intercellSpacing = CPSizeMake(3.0, 2.0);
+
+ _visibleRows = CPMakeRange(0, 0);
+ _visibleColumns = CPMakeRange(0, 0);
}
return self;
@@ -91,52 +97,186 @@ var CPTableViewCellPlaceholder = nil;
/*
Returns the table's column height
*/
-- (float)columnHeight
+- (float)_columnHeight
{
- var bounds = [self bounds],
- height = _numberOfRows * (_rowHeight + _intercellSpacing.height);
+ return _numberOfRows * (_rowHeight + _intercellSpacing.height);
+}
+
+- (void)newCellForRow:(unsigned)aRowIndex column:(unsigned)aColumnIndex avoidingRows:(CPRange)rows
+{//console.warn("new cell please.");
+ var dataView = [_tableColumns[aColumnIndex] _newDataViewForRow:aRowIndex avoidingRows:rows];
+
+ [dataView setFrame:CGRectMake(0.0, aRowIndex * (_rowHeight + _intercellSpacing.height), [_tableColumns[aColumnIndex] width], _rowHeight)];
+ [dataView setBackgroundColor:[CPColor greenColor]];
- return CPRectGetHeight(bounds) > height ? CPRectGetHeight(bounds) : height;
+ if (!_objectValueCache[aColumnIndex])
+ _objectValueCache[aColumnIndex] = [];
+
+ // We may be storing 0 after all!
+ if (typeof _objectValueCache[aColumnIndex][aRowIndex] === "undefined")
+ _objectValueCache[aColumnIndex][aRowIndex] = [_dataSource tableView:self objectValueForTableColumn:_tableColumns[aColumnIndex] row:aRowIndex];
+
+ [dataView setObjectValue:_objectValueCache[aColumnIndex][aRowIndex]];
+
+ return dataView;
}
- (void)loadTableCellsInRect:(CGRect)aRect
{
if (!_dataSource)
return;
+
+ // Determine new visible rows and columns.
+
+ // Use a ambitious estimate for our starting row.
+ var rowStart = MAX(FLOOR((CGRectGetMinY(aRect) + _intercellSpacing.height) / (_rowHeight + _intercellSpacing.height)), 0),
- // Use a ambitious estimate for our starting row.
- var rows = CPMakeRange(MAX(Math.floor((CPRectGetMinY(aRect) + _intercellSpacing.height) / (_rowHeight + _intercellSpacing.height)), 0), 1);
+ // Use a conservative estimate for the final row.
+ rowEnd = MIN(_numberOfRows, CEIL(CGRectGetMaxY(aRect) / (_rowHeight + _intercellSpacing.height))),
+
+ visibleRows = CPMakeRange(rowStart, rowEnd - rowStart);
+
+ var columnStart = 0;
+
+ // Iterate through all our columns until we find the first one that intersects the rect.
+ while (columnStart < _numberOfColumns && !CGRectIntersectsRect([_tableColumnViews[columnStart] frame], aRect))
+ ++columnStart;
+
+ // Now use a binary search to find the last visible column
+ // O (lg n) < O (n), but O(n) (above), so O (n + lg n) = O (n) ?
+ var first = columnStart + 1,
+ last = _numberOfColumns - 1;
+ columnEnd = columnStart;
- // Use a conservative estimate for the final row.
- rows.length = MIN(_numberOfRows, Math.ceil(CPRectGetMaxY(aRect) / (_rowHeight + _intercellSpacing.height))) - rows.location;
-
- var columns = CPMakeRange(0, 1);
-
- // Iterate through all our columns until we find one that intersects the rect.
- while (columns.location < _numberOfColumns && !CPRectIntersectsRect([_tableColumnViews[columns.location] frame], aRect))
- ++columns.location;
-
- // Now iterate through our columns until we find one that doesn't intersect our rect.
- while (CPMaxRange(columns) < _numberOfColumns && CPRectIntersectsRect([_tableColumnViews[CPMaxRange(columns)] frame], aRect))
- ++columns.length;
-
- var row = rows.location,
- column = 0;
-
- for (; row < CPMaxRange(rows); ++row)
- for (column = columns.location; column < CPMaxRange(columns); ++column)
- {
- if (!_tableCells[column][row] || _tableCells[column][row] == CPTableViewCellPlaceholder)
- {
- _tableCells[column][row] = [[_tableColumns[column] dataCellForRow:row] copy];
-
- [_tableCells[column][row] setFrame:CPRectMake(0.0, row * (_rowHeight + _intercellSpacing.height), [_tableColumns[column] width], _rowHeight)];
- //[_tableCells[column][row] setBackgroundColor:[CPColor blueColor]];
- [_tableColumnViews[column] addSubview:_tableCells[column][row]];
- }
+ while (first <= last)
+ {
+ // Assume this is the one.
+ var columnEnd = FLOOR((first + last) / 2),
+ columnIsVisible = CGRectIntersectsRect([_tableColumnViews[columnEnd] frame], aRect);
- [_tableCells[column][row] setObjectValue:[_dataSource tableView:self objectValueForTableColumn:_tableColumns[column] row:row]];
+ // If the column isn't visible, look left!
+ if (!columnIsVisible)
+ last = columnEnd - 1;
+
+ // Visible, nothing to the right, found it...
+ if (columnEnd + 1 >= _numberOfColumns)
+ break;
+
+ // Visible, column to the right is NOT visible, found it! (the good way)
+ if (!CGRectIntersectsRect([_tableColumnViews[columnEnd + 1] frame], aRect))
+ break;
+
+ // If not, look right! (2 since we checked the dude to the right already)
+ first = columnEnd + 2;
+ }
+
+ // columnEnd is our "count" in loops.
+ ++columnEnd;
+
+ var visibleColumns = CPMakeRange(columnStart, columnEnd - columnStart);
+
+ if (CPEqualRanges(_visibleRows, visibleRows) && CPEqualRanges(_visibleColumns, visibleColumns))
+ return;
+
+ var unionVisibleRows = CPUnionRange(_visibleRows, visibleRows),
+ unionVisibleColumns = CPUnionRange(_visibleColumns, visibleColumns);
+
+ // Determine whether to use 2 sweeps or one. If we have lots of overlap of cells, use just one.
+ if (unionVisibleRows.length * unionVisibleColumns.length <=
+ (_visibleRows.length + visibleRows.length) * (_visibleColumns.length + visibleColumns.length))
+ {
+ var column = unionVisibleColumns.location,
+ columnEnd = CPMaxRange(unionVisibleColumns),
+
+ rowStart = unionVisibleRows.location,
+ rowEnd = CPMaxRange(unionVisibleRows);
+
+ for (; column < columnEnd; ++column)
+ {
+ var row = rowStart,
+ tableColumn = _tableColumns[column],
+ tableColumnCells = _tableCells[column],
+ columnIsVisible = CPLocationInRange(column, visibleColumns);
+
+ for (; row < rowEnd; ++row)
+ {
+ var cell = tableColumnCells[row];
+
+ if (cell)
+ {
+ if (columnIsVisible && CPLocationInRange(row, visibleRows))
+ [tableColumn _markView:cell inRow:row asPurgable:NO];
+ else {
+ //!!!
+ _tableCells[column][row] = nil;
+ [tableColumn _markView:cell inRow:row asPurgable:YES];
+ }
+ }
+
+ else
+ {
+// ASSERT(CPLocationInRange(row, visibleRows) && CPLocationInRange(column, visibleColumns))
+ tableColumnCells[row] = [self newCellForRow:row column:column avoidingRows:visibleRows];
+
+ [_tableColumnViews[column] addSubview:tableColumnCells[row]];
+ }
+ }
}
+ }
+ else
+ {
+
+ }
+
+ _visibleRows = visibleRows;
+ _visibleColumns = visibleColumns;
+
+ /*
+ var column = columnStart;
+
+ for (; column < _numberOfColumns && CGRectIntersectsRect([_tableColumnViews[column] frame], aRect); ++column)
+ {
+ var row = rowStart,
+ tableColumn = _tableColumns[column];
+
+ for (; row < rowEnd; ++row)
+ {
+ //if (CPLocationInRange(row, _visibleRows))
+ // continue;
+
+ var cell = _tableCells[column][row];
+
+ if (cell)
+ [tableColumn _markView:cell inRow:row asPurgable:NO];
+
+ else
+ _tableCells[column][row] = [self newCellForRow:row column:column avoidingRows:visibleRows];
+ }
+ }
+
+ var visibleRows = visibleRowsCPMakeRange(rowStart, rowEnd - rowStart),
+ visibleColumns = CPMakeRange(columnStart, rememberColumn - columnStart);
+
+ var columnEnd = CPMaxRange(_visibelColumns);
+
+
+ for (column = _visibleColumns.location; column < columnEnd; ++column)
+ {
+ var tableColumn = _tableColumns[tableColumn],
+ tableColumnCells = _tableCells[column];
+
+ for (row = _visibleRows.location, rowEnd = CPMaxRange(_visibleRows); row < rowEnd; ++row)
+ if (!CPLocationInRange(row, visibleRows) || !CPLocationInRange(column, visibleColumns))
+ {
+ var view = tableColumnCells[row];
+
+ if (view)
+ [tableColumn _markView:view inRow:row asPurgable:YES];
+ }
+ }
+
+ _visibleRows = visibleRows;
+ _visibleColumns = visibleColumns;*/
}
// Setting display attributes
@@ -155,7 +295,7 @@ var CPTableViewCellPlaceholder = nil;
for (; i < _numberOfColumns; ++i, total += delta)
{
var origin = [_tableColumnViews[i] frame].origin;
- [_tableColumnViews[i] setFrameOrigin:CPPointMake(origin.x + total, origin.y)];
+ [_tableColumnViews[i] setFrameOrigin:CGPointMake(origin.x + total, origin.y)];
}
}
@@ -165,14 +305,14 @@ var CPTableViewCellPlaceholder = nil;
for (; i < _numberOfColumns; ++i, total += delta)
{
- [_tableColumnViews[i] setFrameSize:CPSizeMake([_tableColumnViews[i] width], _numberOfRows * (_rowHeight + _intercellSpacing.height))];
+ [_tableColumnViews[i] setFrameSize:CGSizeMake([_tableColumnViews[i] width], _numberOfRows * (_rowHeight + _intercellSpacing.height))];
var j = 1,
y = _rowHeight + _intercellSpacing.height;
for (; j < _numberOfRows; ++i, y += _rowHeight + _intercellSpacing.height)
{
- if (_tableCells[i][j] == CPTableViewCellPlaceholder)
+ if (!_tableCells[i][j])
continue;
[_tableCells[i][j] setFrameOrigin:CPPointMake(0.0, y)];
@@ -227,8 +367,8 @@ var CPTableViewCellPlaceholder = nil;
{
var i = 0,
x = _numberOfColumns ? CPRectGetMaxX([self rectOfColumn:_numberOfColumns - 1]) + _intercellSpacing.width : 0.0,
- tableColumnView = [[CPView alloc] initWithFrame:CPRectMake(x, 0.0, [aTableColumn width], [self columnHeight])],
- tableColumnCells = [[CPArray alloc] init];
+ tableColumnView = [[CPView alloc] initWithFrame:CPRectMake(x, 0.0, [aTableColumn width], [self _columnHeight])],
+ tableColumnCells = [];
[_tableColumns addObject:aTableColumn];
[_tableColumnViews addObject:tableColumnView];
@@ -240,8 +380,8 @@ var CPTableViewCellPlaceholder = nil;
[_tableCells addObject:tableColumnCells];
for (; i < _numberOfRows; ++i)
- _tableCells[_numberOfColumns][i] = CPTableViewCellPlaceholder;
-
+ _tableCells[_numberOfColumns][i] = nil;
+
++_numberOfColumns;
}
@@ -315,8 +455,8 @@ var CPTableViewCellPlaceholder = nil;
{
var HEIGHT = 10.0;
- [_headerView setFrame:CPRectMake(0.0, 0.0, CPRectGetWidth([self bounds]), HEIGHT)];
- [_scrollView setFrame:CPRectMake(0.0, HEIGHT, CPRectGetWidth([self bounds]), CPRectGetHeight([self bounds]) - HEIGHT)];
+// [_headerView setFrame:CPRectMake(0.0, 0.0, CPRectGetWidth([self bounds]), HEIGHT)];
+// [_scrollView setFrame:CPRectMake(0.0, HEIGHT, CPRectGetWidth([self bounds]), CPRectGetHeight([self bounds]) - HEIGHT)];
}
/*
@@ -349,25 +489,6 @@ var CPTableViewCellPlaceholder = nil;
return _dataSource;
}
-- (void)setFrameSize:(CGSize)aSize
-{
- var oldColumnHeight = [self columnHeight];
-
- [super setFrameSize:aSize];
-
- var columnHeight = [self columnHeight];
-
- if (columnHeight != oldColumnHeight)
- {
- var i = 0;
-
- for (; i < _numberOfColumns; ++i)
- [_tableColumnViews[i] setFrameSize:CPSizeMake([_tableColumns[i] width], columnHeight)];
- }
-
- [self tile];
-}
-
/*
Tells the table view that the number of rows in the table
has changed.
@@ -379,7 +500,8 @@ var CPTableViewCellPlaceholder = nil;
if (_numberOfRows != numberOfRows)
{
_numberOfRows = numberOfRows;
- [self sizeToFit];
+
+ [self _recalculateColumnHeight];
}
}
@@ -400,7 +522,7 @@ var CPTableViewCellPlaceholder = nil;
*/
- (CGRect)rectOfColumn:(int)aColumnIndex
{
- return CPRectCreateCopy([_tableColumnViews[aColumnIndex] frame]);
+ return [_tableColumnViews[aColumnIndex] frame];
}
/*
@@ -408,7 +530,35 @@ var CPTableViewCellPlaceholder = nil;
*/
- (void)sizeToFit
{
- [self tile];
+// [self tile];
+}
+
+- (void)_recalculateColumnHeight
+{
+ var oldColumnHeight = _columnHeight;
+
+ if (_hasVariableHeightRows)
+ {
+ }
+ else
+ _columnHeight = _numberOfRows * (_rowHeight + _intercellSpacing.height);
+
+ var count = _tableColumnViews.length;
+
+ while (count--)
+ [_tableColumnViews[count] setFrameSize:CGSizeMake([_tableColumns[count] width], _columnHeight)];
+
+ [self setFrameSize:CGSizeMake(CGRectGetWidth([self frame]), _columnHeight)];
+}
+
+- (CGRect)visibleRectInParent
+{
+ var superview = [self superview];
+
+ if (!superview)
+ return [self bounds];
+
+ return [self convertRect:CGRectIntersection([superview bounds], [self frame]) fromView:superview];
}
/*
@@ -417,9 +567,60 @@ var CPTableViewCellPlaceholder = nil;
*/
- (void)reloadData
{
+ var oldNumberOfRows = _numberOfRows;
+
_numberOfRows = [_dataSource numberOfRowsInTableView:self];
- [self loadTableCellsInRect:[self bounds]];
+ if (oldNumberOfRows != _numberOfRows)
+ {
+ [self _recalculateColumnHeight];
+ [self setFrameSize:CGSizeMake(CGRectGetWidth([self frame]), [self _columnHeight])];
+ }
+
+ [self setNeedsDisplay:YES];
+}
+
+- (void)viewWillDraw
+{
+ [self loadTableCellsInRect:[self visibleRectInParent]];
+
+ //alert("oh yes. " + CPStringFromRect([self visibleRect]));
+ //[self reloadData];
+}
+
+- (void)drawRect:(CGRect)aRect
+{
+}
+
+- (void)setFrameSize:(CGSize)aFrameSize
+{
+ [super setFrameSize:aFrameSize];
+
+// [self setNeedsDisplay:YES];
+}
+
+- (void)displaySoon
+{
+// window.setTimeout();
+}
+
+- (void)viewDidMoveToSuperview
+{
+ [[[self enclosingScrollView] contentView] setPostsBoundsChangedNotifications:YES];
+
+ [[CPNotificationCenter defaultCenter]
+ addObserver:self
+ selector:@selector(viewBoundsChanged:)
+ name:CPViewBoundsDidChangeNotification
+ object:[[self enclosingScrollView] contentView]];
+ //console.warn("cheese");
+}
+
+- (void)viewBoundsChanged:(CPNotification)aNotification
+{
+ //console.warn(_cmd + CPStringFromRect([[[self enclosingScrollView] contentView] bounds]));
+ //objj_debug_print_backtrace();
+ [self setNeedsDisplay:YES];
}
@end
diff --git a/AppKit/CPToolbar.j b/AppKit/CPToolbar.j
index 2d72bece0..fe6667585 100644
--- a/AppKit/CPToolbar.j
+++ b/AppKit/CPToolbar.j
@@ -100,6 +100,7 @@ var CPToolbarConfigurationsByIdentifier = nil;
CPArray _itemsSortedByVisibilityPriority;
CPView _toolbarView;
+ CPWindow _window;
}
/* @ignore */
@@ -187,13 +188,22 @@ var CPToolbarConfigurationsByIdentifier = nil;
*/
- (void)setVisible:(BOOL)aFlag
{
- if (_isVisible == aFlag)
+ if (_isVisible === aFlag)
return;
-
+
_isVisible = aFlag;
- [_window _setToolbarVisible:_isVisible];
- [self _reloadToolbarItems];
+ [_window _noteToolbarChanged];
+}
+
+- (CPWindow)_window
+{
+ return _window;
+}
+
+- (void)_setWindow:(CPWindow)aWindow
+{
+ _window = aWindow;
}
/*!
@@ -222,9 +232,10 @@ var CPToolbarConfigurationsByIdentifier = nil;
if (!_toolbarView)
{
_toolbarView = [[_CPToolbarView alloc] initWithFrame:CPRectMake(0.0, 0.0, 1200.0, 59.0)];
- [_toolbarView setAutoresizingMask:CPViewWidthSizable];
-
+
[_toolbarView setToolbar:self];
+ [_toolbarView setAutoresizingMask:CPViewWidthSizable];
+ [_toolbarView reloadToolbarItems];
}
return _toolbarView;
@@ -233,9 +244,9 @@ var CPToolbarConfigurationsByIdentifier = nil;
/* @ignore */
- (void)_reloadToolbarItems
{
- if (![_toolbarView superview] || !_delegate)
+ if (!_delegate)
return;
-
+
var count = [_itemIdentifiers count];
if (!count)
@@ -243,8 +254,6 @@ var CPToolbarConfigurationsByIdentifier = nil;
_itemIdentifiers = [[_delegate toolbarDefaultItemIdentifiers:self] mutableCopy];
count = [_itemIdentifiers count];
}
-
- [[_toolbarView subviews] makeObjectsPerformSelector:@selector(removeFromSuperview)];
_items = [];
@@ -256,8 +265,10 @@ var CPToolbarConfigurationsByIdentifier = nil;
item = [CPToolbarItem _standardItemWithItemIdentifier:identifier];
if (!item)
- item = [[_delegate toolbar:self itemForItemIdentifier:identifier willBeInsertedIntoToolbar:YES] copy];
-
+ item = [_delegate toolbar:self itemForItemIdentifier:identifier willBeInsertedIntoToolbar:YES];
+
+ item = [item copy];
+
if (item == nil)
[CPException raise:CPInvalidArgumentException
reason:sprintf(@"_delegate %s returned nil toolbar item returned for identifier %s", _delegate, identifier)];
@@ -436,6 +447,7 @@ var _CPToolbarItemInfoMake = function(anIndex, aView, aLabel, aMinWidth)
CPArray _invisibleItems;
CPPopUpButton _additionalItemsButton;
+ CPColor _labelColor;
}
+ (void)initialize
@@ -445,8 +457,6 @@ var _CPToolbarItemInfoMake = function(anIndex, aView, aLabel, aMinWidth)
var bundle = [CPBundle bundleForClass:self];
- _CPToolbarViewBackgroundColor = [CPColor colorWithPatternImage:[[CPImage alloc] initWithContentsOfFile:[bundle pathForResource:@"_CPToolbarView/_CPToolbarViewBackground.png"] size:CGSizeMake(1.0, 59.0)]];
-
_CPToolbarViewExtraItemsImage = [[CPImage alloc] initWithContentsOfFile: [bundle pathForResource:"_CPToolbarView/_CPToolbarViewExtraItemsImage.png"] size: CPSizeMake(10.0, 15.0)];
_CPToolbarViewExtraItemsAlternateImage = [[CPImage alloc] initWithContentsOfFile: [bundle pathForResource:"_CPToolbarView/_CPToolbarViewExtraItemsAlternateImage.png"] size:CGSizeMake(10.0, 15.0)];
@@ -460,7 +470,7 @@ var _CPToolbarItemInfoMake = function(anIndex, aView, aLabel, aMinWidth)
{
_minWidth = 0;
- [self setBackgroundColor:_CPToolbarViewBackgroundColor];
+ _labelColor = [CPColor blackColor];
_additionalItemsButton = [[CPPopUpButton alloc] initWithFrame:CGRectMake(0.0, 0.0, 10.0, 15.0) pullsDown:YES];
[_additionalItemsButton setBordered:NO];
@@ -484,6 +494,20 @@ var _CPToolbarItemInfoMake = function(anIndex, aView, aLabel, aMinWidth)
return _toolbar;
}
+- (void)setLabelColor:(CPColor)aColor
+{
+ if (_labelColor === aColor)
+ return;
+
+ _labelColor = aColor;
+
+ var items = [_toolbar items],
+ count = [items count];
+
+ while (count--)
+ [[self labelForItem:items[count]] setTextColor:_labelColor];
+}
+
// This *should* be roughly O(3N) = O(N)
- (void)resizeSubviewsWithOldSize:(CGSize)aSize
{
@@ -527,7 +551,7 @@ var _CPToolbarItemInfoMake = function(anIndex, aView, aLabel, aMinWidth)
[[self labelForItem:item] setHidden:YES];
}
}
-
+
// Determine all the items that have flexible width.
// Also determine the height of the toolbar.
// NOTE: height is height without top margin, and bottom margin/label.
@@ -717,8 +741,8 @@ var _CPToolbarItemInfoMake = function(anIndex, aView, aLabel, aMinWidth)
count = subviews.length;
while (count--)
- [subviews removeObjectAtIndex:count];
-
+ [subviews[count] removeFromSuperview];
+
// Populate with new subviews.
var items = [_toolbar items],
index = 0;
@@ -745,10 +769,12 @@ var _CPToolbarItemInfoMake = function(anIndex, aView, aLabel, aMinWidth)
[view setTarget:[item target]];
[view setAction:[item action]];
+
+ [view setTag:[item tag]];
[view setImagePosition:CPImageOnly];
}
-
+
[self addSubview:view];
// Create a lable for this item.
@@ -756,6 +782,7 @@ var _CPToolbarItemInfoMake = function(anIndex, aView, aLabel, aMinWidth)
[label setStringValue:[item label]];
[label setFont:[CPFont systemFontOfSize:11.0]];
+ [label setTextColor:_labelColor];
[label sizeToFit];
[label setTarget:[item target]];
diff --git a/AppKit/CPToolbarItem.j b/AppKit/CPToolbarItem.j
index c56791a9f..1e5bcda53 100644
--- a/AppKit/CPToolbarItem.j
+++ b/AppKit/CPToolbarItem.j
@@ -56,8 +56,6 @@ CPToolbarShowFontsItemIdentifier = @"CPToolbarShowFontsItemIdentifier";
CPToolbarCustomizeToolbarItemIdentifier = @"CPToolbarCustomizeToolbarItemIdentifier";
CPToolbarPrintItemIdentifier = @"CPToolbarPrintItemIdentifier";
-var _CPToolbarSeparatorItemView = nil;
-
/*! @class CPToolbarItem
A representation of an item in a CPToolbar.
@@ -479,8 +477,33 @@ CPToolbarItemVisibilityPriorityUser
// Standard toolbar identifiers
+var _CPToolbarSeparatorItemView = nil,
+ _CPToolbarSpaceItemView = nil;
+
@implementation CPToolbarItem (Standard)
++ (CPView)_separatorItemView
+{
+ if (!_CPToolbarSeparatorItemView)
+ {
+ _CPToolbarSeparatorItemView = [[CPView alloc] initWithFrame:CGRectMake(0.0, 0.0, 2.0, 32.0)];
+
+ sizes = {};
+ sizes[@"CPToolbarItemSeparator"] = [CGSizeMake(2.0, 26.0), CGSizeMake(2.0, 1.0), CGSizeMake(2.0, 26.0)];
+ [_CPToolbarSeparatorItemView setBackgroundColor:_CPControlThreePartImagePattern(YES, sizes, @"CPToolbarItem", @"Separator")];
+ }
+
+ return _CPToolbarSeparatorItemView;
+}
+
++ (CPView)_spaceItemView
+{
+ if (!_CPToolbarSpaceItemView)
+ _CPToolbarSpaceItemView = [[CPView alloc] initWithFrame:CGRectMakeZero()];
+
+ return _CPToolbarSpaceItemView;
+}
+
/* @ignore */
+ (CPToolbarItem)_standardItemWithItemIdentifier:(CPString)anItemIdentifier
{
@@ -488,29 +511,23 @@ CPToolbarItemVisibilityPriorityUser
switch (anItemIdentifier)
{
- case CPToolbarSeparatorItemIdentifier: [item setMinSize:CGSizeMake(2.0, 0.0)];
+ case CPToolbarSeparatorItemIdentifier: [item setView:[self _separatorItemView]];
+
+ [item setMinSize:CGSizeMake(2.0, 0.0)];
[item setMaxSize:CGSizeMake(2.0, 100000.0)];
- if (!_CPToolbarSeparatorItemView)
- {
- _CPToolbarSeparatorItemView = [[CPView alloc] initWithFrame:CGRectMake(0.0, 0.0, 2.0, 32.0)];
-
- sizes = {};
- sizes[@"CPToolbarItemSeparator"] = [CGSizeMake(2.0, 26.0), CGSizeMake(2.0, 1.0), CGSizeMake(2.0, 26.0)];
- [_CPToolbarSeparatorItemView setBackgroundColor:_CPControlThreePartImagePattern(YES, sizes, @"CPToolbarItem", @"Separator")];
- }
-
- [item setView:_CPToolbarSeparatorItemView];
-
-
return item;
- case CPToolbarSpaceItemIdentifier: [item setMinSize:CGSizeMake(32.0, 32.0)];
+ case CPToolbarSpaceItemIdentifier: [item setView:[self _spaceItemView]];
+
+ [item setMinSize:CGSizeMake(32.0, 32.0)];
[item setMaxSize:CGSizeMake(32.0, 32.0)];
return item;
- case CPToolbarFlexibleSpaceItemIdentifier: [item setMinSize:CGSizeMake(32.0, 32.0)];
+ case CPToolbarFlexibleSpaceItemIdentifier: [item setView:[self _spaceItemView]];
+
+ [item setMinSize:CGSizeMake(32.0, 32.0)];
[item setMaxSize:CGSizeMake(10000.0, 32.0)];
return item;
diff --git a/AppKit/CPView.j b/AppKit/CPView.j
index f330dfd15..93f806436 100644
--- a/AppKit/CPView.j
+++ b/AppKit/CPView.j
@@ -1844,7 +1844,10 @@ var _CPViewFullScreenModeStateMake = function(aView)
var _CPViewGetTransform = function(/*CPView*/ fromView, /*CPView */ toView)
{
- var transform = CGAffineTransformMakeIdentity();
+ var transform = CGAffineTransformMakeIdentity(),
+ sameWindow = YES,
+ fromWindow = nil,
+ toWindow = nil;
if (fromView)
{
@@ -1868,8 +1871,24 @@ var _CPViewGetTransform = function(/*CPView*/ fromView, /*CPView */ toView)
}
// If we hit toView, then we're done.
- if (view == toView)
+ if (view === toView)
return transform;
+
+ else if (fromView && toView)
+ {
+ fromWindow = [fromView window];
+ toWindow = [toView window];
+
+ if (fromWindow && toWindow && fromWindow !== toWindow)
+ {
+ sameWindow = NO;
+
+ var frame = [fromWindow frame];
+
+ transform.tx += _CGRectGetMinX(frame);
+ transform.ty += _CGRectGetMinY(frame);
+ }
+ }
}
// FIXME: For now we can do things this way, but eventually we need to do them the "hard" way.
@@ -1890,6 +1909,13 @@ var _CPViewGetTransform = function(/*CPView*/ fromView, /*CPView */ toView)
view = view._superview;
}
+ if (!sameWindow)
+ {
+ var frame = [toWindow frame];
+
+ transform.tx -= _CGRectGetMinX(frame);
+ transform.ty -= _CGRectGetMinY(frame);
+ }
/* var views = [],
view = toView;
diff --git a/AppKit/CPWindow.j b/AppKit/CPWindow/CPWindow.j
similarity index 91%
rename from AppKit/CPWindow.j
rename to AppKit/CPWindow/CPWindow.j
index aec1dc6da..774be7efc 100644
--- a/AppKit/CPWindow.j
+++ b/AppKit/CPWindow/CPWindow.j
@@ -27,10 +27,10 @@
@import "CPAnimation.j"
@import "CPResponder.j"
-#include "Platform/Platform.h"
-#include "Platform/DOM/CPDOMDisplayServer.h"
+#include "../Platform/Platform.h"
+#include "../Platform/DOM/CPDOMDisplayServer.h"
-#include "CoreGraphics/CGGeometry.h"
+#include "../CoreGraphics/CGGeometry.h"
/*
@@ -88,6 +88,7 @@ CPWindowMinYMargin = 8;
CPWindowHeightSizable = 16;
CPWindowMaxYMargin = 32;
+CPBackgroundWindowLevel = -1;
/*
Default level for windows
@group CPWindowLevel
@@ -292,8 +293,6 @@ var CPWindowSaveImage = nil,
var bundle = [CPBundle bundleForClass:[CPWindow class]];
- CPWindowResizeIndicatorImage = [[CPImage alloc] initWithContentsOfFile:[bundle pathForResource:@"CPWindowResizeIndicator.png"] size:CGSizeMake(12.0, 12.0)];
-
CPWindowSavingImage = [[CPImage alloc] initWithContentsOfFile:[bundle pathForResource:@"CPProgressIndicator/CPProgressIndicatorSpinningStyleRegular.gif"] size:CGSizeMake(16.0, 16.0)]
}
@@ -345,11 +344,7 @@ CPTexturedBackgroundWindowMask
CPApp._windows[_windowNumber] = self;
_styleMask = aStyleMask;
-
- _frame = [self frameRectForContentRect:aContentRect];
-
- _level = CPNormalWindowLevel;
- _hasShadow = NO;
+ _level = aStyleMask === CPBorderlessBridgeWindowMask ? CPBackgroundWindowLevel : CPNormalWindowLevel;
_minSize = CGSizeMake(0.0, 0.0);
_maxSize = CGSizeMake(1000000.0, 1000000.0);
@@ -358,16 +353,19 @@ CPTexturedBackgroundWindowMask
_autoresizingMask = CPWindowWidthSizable | CPWindowHeightSizable;
// Create our border view which is the actual root of our view hierarchy.
- _windowView = [[_CPWindowView alloc] initWithFrame:CGRectMake(0.0, 0.0, CGRectGetWidth(_frame), CGRectGetHeight(_frame)) forStyleMask:_styleMask];
+ var windowViewClass = [[self class] _windowViewClassForStyleMask:aStyleMask];
+ _frame = [windowViewClass frameRectForContentRect:aContentRect];
+ _windowView = [[windowViewClass alloc] initWithFrame:CGRectMake(0.0, 0.0, CGRectGetWidth(_frame), CGRectGetHeight(_frame)) styleMask:aStyleMask owningWindow:self];
+
[_windowView _setWindow:self];
[_windowView setNextResponder:self];
-
+
[self setMovableByWindowBackground:aStyleMask & CPHUDBackgroundWindowMask];
// Create a generic content view.
[self setContentView:[[CPView alloc] initWithFrame:CGRectMakeZero()]];
-
+
_firstResponder = self;
#if PLATFORM(DOM)
@@ -384,13 +382,32 @@ CPTexturedBackgroundWindowMask
#endif
[self setBridge:aBridge];
-
+
[self setNextResponder:CPApp];
+
+ [self setHasShadow:aStyleMask !== CPBorderlessWindowMask && !(aStyleMask & CPBorderlessBridgeWindowMask)];
}
return self;
}
+/*!
+ @ignore
+*/
++ (Class)_windowViewClassForStyleMask:(unsigned)aStyleMask
+{
+ if (aStyleMask & CPHUDBackgroundWindowMask)
+ return _CPHUDWindowView;
+
+ else if (aStyleMask & CPBorderlessBridgeWindowMask)
+ return _CPBorderlessBridgeWindowView;
+
+ else if (aStyleMask === CPBorderlessWindowMask)
+ return _CPBorderlessWindowView;
+
+ return _CPStandardWindowView;
+}
+
/*!
Returns the window's style mask.
*/
@@ -407,9 +424,7 @@ CPTexturedBackgroundWindowMask
*/
+ (CGRect)frameRectForContentRect:(CGRect)aContentRect styleMask:(unsigned)aStyleMask
{
- var frame = CGRectMakeCopy(aContentRect);
-
- return frame;
+ return [[[self class] _windowViewClassForStyleMask:_styleMask] frameRectForContentRect:aContentRect];
}
/*!
@@ -418,31 +433,7 @@ CPTexturedBackgroundWindowMask
*/
- (CGRect)contentRectForFrameRect:(CGRect)aFrame
{
- // FIXME: EXTRA RECT COPY
- var contentRect = CGRectMakeCopy([_windowView bounds]);
-
- if (_styleMask & CPHUDBackgroundWindowMask)
- {
- contentRect.origin.x += 7.0;
- contentRect.origin.y += 30.0;
- contentRect.size.width -= 14.0;
- contentRect.size.height -= 40.0;
- }
-
- else if (_styleMask & CPBorderlessBridgeWindowMask)
- {
- // The full width, like borderless.
- }
-
- if ([_toolbar isVisible])
- {
- var toolbarHeight = CGRectGetHeight([_toolbarView frame]);
-
- contentRect.origin.y += toolbarHeight;
- contentRect.size.height -= toolbarHeight;
- }
-
- return contentRect;
+ return [_windowView contentRectForFrameRect:aFrame];
}
/*!
@@ -452,12 +443,7 @@ CPTexturedBackgroundWindowMask
*/
- (CGRect)frameRectForContentRect:(CGRect)aContentRect
{
- if (_styleMask & CPBorderlessBridgeWindowMask)
- return _bridge ? [_bridge visibleFrame] : CGRectMakeZero();
-
- var frame = [[self class] frameRectForContentRect:aContentRect styleMask:_styleMask];
-
- return frame;
+ return [_windowView frameRectForContentRect:aContentRect];
}
/*!
@@ -539,51 +525,6 @@ CPTexturedBackgroundWindowMask
[_delegate windowDidResize:self];
}
-/*
- @ignore
-*/
-- (void)trackMoveWithEvent:(CPEvent)anEvent
-{
- var type = [anEvent type];
-
- if (type == CPLeftMouseUp)
- return;
-
- else if (type == CPLeftMouseDown)
- _mouseDraggedPoint = [self convertBaseToBridge:[anEvent locationInWindow]];
-
- else if (type == CPLeftMouseDragged)
- {
- var location = [self convertBaseToBridge:[anEvent locationInWindow]];
-
- [self setFrameOrigin:CGPointMake(_CGRectGetMinX(_frame) + (location.x - _mouseDraggedPoint.x), _CGRectGetMinY(_frame) + (location.y - _mouseDraggedPoint.y))];
-
- _mouseDraggedPoint = location;
- }
-
- [CPApp setTarget:self selector:@selector(trackMoveWithEvent:) forNextEventMatchingMask:CPLeftMouseDraggedMask | CPLeftMouseUpMask untilDate:nil inMode:nil dequeue:YES];
-}
-
-/*
- @ignore
-*/
-- (void)trackResizeWithEvent:(CPEvent)anEvent
-{
- var location = [anEvent locationInWindow],
- type = [anEvent type];
-
- if (type == CPLeftMouseUp)
- return;
-
- else if (type == CPLeftMouseDown)
- _resizeFrame = CGRectMake(location.x, location.y, CGRectGetWidth(_frame), CGRectGetHeight(_frame));
-
- else if (type == CPLeftMouseDragged)
- [self setFrameSize:CGSizeMake(CGRectGetWidth(_resizeFrame) + location.x - CGRectGetMinX(_resizeFrame), CGRectGetHeight(_resizeFrame) + location.y - CGRectGetMinY(_resizeFrame))];
-
- [CPApp setTarget:self selector:@selector(trackResizeWithEvent:) forNextEventMatchingMask:CPLeftMouseDraggedMask | CPLeftMouseUpMask untilDate:nil inMode:nil dequeue:YES];
-}
-
/*!
Makes the receiver the front most window in the screen ordering.
@param aSender the object that requested this
@@ -701,11 +642,13 @@ CPTexturedBackgroundWindowMask
if (_contentView)
[_contentView removeFromSuperview];
+ var bounds = CGRectMake(0.0, 0.0, CGRectGetWidth(_frame), CGRectGetHeight(_frame));
+
_contentView = aView;
- [_contentView setFrame:[self contentRectForFrameRect:_frame]];
+ [_contentView setFrame:[self contentRectForFrameRect:bounds]];
[_contentView setAutoresizingMask:CPViewWidthSizable | CPViewHeightSizable];
- [_windowView addSubview:_contentView positioned:CPWindowBelow relativeTo:nil];
+ [_windowView addSubview:_contentView];// positioned:CPWindowBelow relativeTo:nil];
}
/*!
@@ -826,7 +769,7 @@ CPTexturedBackgroundWindowMask
*/
- (void)setHasShadow:(BOOL)shouldHaveShadow
{
- if (_hasShadow == shouldHaveShadow)
+ if (_hasShadow === shouldHaveShadow)
return;
_hasShadow = shouldHaveShadow;
@@ -840,7 +783,7 @@ CPTexturedBackgroundWindowMask
if (!_CPWindowShadowColor)
{
- var bundle = [CPBundle bundleForClass:[self class]];
+ var bundle = [CPBundle bundleForClass:[CPWindow class]];
_CPWindowShadowColor = [CPColor colorWithPatternImage:[[CPNinePartImage alloc] initWithImageSlices:
[
@@ -865,7 +808,7 @@ CPTexturedBackgroundWindowMask
CPDOMDisplayServerInsertBefore(_DOMElement, _shadowView._DOMElement, _windowView._DOMElement);
#endif
}
- else
+ else if (_shadowView)
{
#if PLATFORM(DOM)
CPDOMDisplayServerRemoveChild(_DOMElement, _shadowView._DOMElement);
@@ -1434,49 +1377,34 @@ CPTexturedBackgroundWindowMask
*/
- (void)setToolbar:(CPToolbar)aToolbar
{
- if (_toolbar == aToolbar)
+ if (_toolbar === aToolbar)
return;
- // Cleanup old toolbar
- if (_toolbar)
- {
- [self _setToolbarVisible:NO];
+ // If this has an owner, dump it!
+ [[aToolbar _window] setToolbar:nil];
- _toolbar._window = nil;
- _toolbarView = nil;
- }
+ // This is no longer out toolbar.
+ [_toolbar _setWindow:nil];
- if (_toolbar = aToolbar)
- {
- // Set up new toolbar
- _toolbar = aToolbar;
- _toolbar._window = self;
-
- if ([_toolbar isVisible])
- [self _setToolbarVisible:YES];
-
- [_toolbar _reloadToolbarItems];
- }
+ _toolbar = aToolbar;
+
+ // THIS is our toolbar.
+ [_toolbar _setWindow:self];
+
+ [self _noteToolbarChanged];
}
-/* @ignore */
-- (void)_setToolbarVisible:(BOOL)aFlag
+- (void)toggleToolbarShown:(id)aSender
{
- if (aFlag)
- {
- if (!_toolbarView)
- _toolbarView = [_toolbar _toolbarView];
-
- [_toolbarView setFrame:CGRectMake(0.0, 0.0, CGRectGetWidth([_windowView bounds]), CGRectGetHeight([_toolbarView frame]))];
- [_windowView addSubview:_toolbarView];
- }
- else
- [_toolbarView removeFromSuperview];
+ var toolbar = [self toolbar];
- [_contentView setFrame:[self contentRectForFrameRect:[_windowView bounds]]];
+ [toolbar setVisible:![toolbar isVisible]];
}
-// Managing Sheets
+- (void)_noteToolbarChanged
+{
+ [_windowView noteToolbarChanged];
+}
/* @ignore */
- (void)_setAttachedSheetFrameOrigin
@@ -1757,7 +1685,11 @@ var interpolate = function(fromValue, toValue, progress)
@end
+@import "_CPWindowView.j"
+@import "_CPStandardWindowView.j"
+@import "_CPHUDWindowView.j"
+@import "_CPBorderlessWindowView.j"
+@import "_CPBorderlessBridgeWindowView.j"
@import "CPDragServer.j"
@import "CPDOMWindowBridge.j"
-@import "_CPWindowView.j"
@import "CPView.j"
diff --git a/AppKit/CPWindow/_CPBorderlessBridgeWindowView.j b/AppKit/CPWindow/_CPBorderlessBridgeWindowView.j
new file mode 100644
index 000000000..f6549fa4f
--- /dev/null
+++ b/AppKit/CPWindow/_CPBorderlessBridgeWindowView.j
@@ -0,0 +1,77 @@
+/*
+ * _CPBorderlessWindowView.j
+ * AppKit
+ *
+ * Created by Francisco Tolmasky.
+ * Copyright 2008, 280 North, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+@import "_CPWindowView.j"
+
+
+var _CPToolbarViewBackgroundColor = nil;
+
+@implementation _CPBorderlessBridgeWindowView : _CPWindowView
+{
+ CPView _toolbarBackgroundView;
+}
+
++ (CPColor)toolbarBackgroundColor
+{
+ if (!_CPToolbarViewBackgroundColor)
+ _CPToolbarViewBackgroundColor = [CPColor colorWithPatternImage:[[CPImage alloc] initWithContentsOfFile:[[CPBundle bundleForClass:[_CPBorderlessBridgeWindowView class]] pathForResource:@"_CPToolbarView/_CPToolbarViewBackground.png"] size:CGSizeMake(1.0, 59.0)]];
+
+ return _CPToolbarViewBackgroundColor;
+}
+
+- (void)tile
+{
+ [super tile];
+
+ var owningWindow = [self owningWindow],
+ bounds = [self bounds];
+
+ [[owningWindow contentView] setFrame:CGRectMake(0.0, [self toolbarMaxY], CGRectGetWidth(bounds), CGRectGetHeight(bounds) - [self toolbarMaxY])];
+
+ if (![[owningWindow toolbar] isVisible])
+ {
+ [_toolbarBackgroundView removeFromSuperview];
+
+ _toolbarBackgroundView = nil;
+
+ return;
+ }
+
+ if (!_toolbarBackgroundView)
+ {
+ _toolbarBackgroundView = [[CPView alloc] initWithFrame:CGRectMakeZero()];
+
+ [_toolbarBackgroundView setBackgroundColor:[[self class] toolbarBackgroundColor]];
+ [_toolbarBackgroundView setAutoresizingMask:CPViewWidthSizable];
+
+ [self addSubview:_toolbarBackgroundView positioned:CPWindowBelow relativeTo:nil];
+ }
+
+ var frame = CGRectMakeZero();
+
+ frame.origin = CGPointMakeCopy([self toolbarOffset]);
+ frame.size = [_toolbarView frame].size;
+
+ [_toolbarBackgroundView setFrame:frame];
+}
+
+@end
diff --git a/AppKit/CPWindow/_CPBorderlessWindowView.j b/AppKit/CPWindow/_CPBorderlessWindowView.j
new file mode 100644
index 000000000..386eae2b1
--- /dev/null
+++ b/AppKit/CPWindow/_CPBorderlessWindowView.j
@@ -0,0 +1,29 @@
+/*
+ * _CPBorderlessWindowView.j
+ * AppKit
+ *
+ * Created by Francisco Tolmasky.
+ * Copyright 2008, 280 North, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+@import "_CPWindowView.j"
+
+
+@implementation _CPBorderlessWindowView : _CPWindowView
+{
+}
+@end
\ No newline at end of file
diff --git a/AppKit/CPWindow/_CPHUDWindowView.j b/AppKit/CPWindow/_CPHUDWindowView.j
new file mode 100644
index 000000000..3434663bc
--- /dev/null
+++ b/AppKit/CPWindow/_CPHUDWindowView.j
@@ -0,0 +1,199 @@
+/*
+ * _CPHUDWindowView.j
+ * AppKit
+ *
+ * Created by Francisco Tolmasky.
+ * Copyright 2008, 280 North, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+var _CPHUDWindowViewBackgroundColor = nil,
+
+ CPHUDCloseButtonImage = nil;
+
+var HUD_TITLEBAR_HEIGHT = 26.0;
+
+@implementation _CPHUDWindowView : _CPWindowView
+{
+ CPView _toolbarView;
+
+ CPTextField _titleField;
+ CPButton _closeButton;
+}
+
++ (void)initialize
+{
+ if (self != [_CPHUDWindowView class])
+ return;
+
+ var bundle = [CPBundle bundleForClass:self];
+
+ _CPHUDWindowViewBackgroundColor = [CPColor colorWithPatternImage:[[CPNinePartImage alloc] initWithImageSlices:
+ [
+ [[CPImage alloc] initWithContentsOfFile:[bundle pathForResource:@"CPWindow/HUD/CPWindowHUDBackground0.png"] size:CPSizeMake(6.0, 78.0)],
+ [[CPImage alloc] initWithContentsOfFile:[bundle pathForResource:@"CPWindow/HUD/CPWindowHUDBackground1.png"] size:CPSizeMake(1.0, 78.0)],
+ [[CPImage alloc] initWithContentsOfFile:[bundle pathForResource:@"CPWindow/HUD/CPWindowHUDBackground2.png"] size:CPSizeMake(6.0, 78.0)],
+
+ [[CPImage alloc] initWithContentsOfFile:[bundle pathForResource:@"CPWindow/HUD/CPWindowHUDBackground3.png"] size:CPSizeMake(6.0, 1.0)],
+ [[CPImage alloc] initWithContentsOfFile:[bundle pathForResource:@"CPWindow/HUD/CPWindowHUDBackground4.png"] size:CPSizeMake(1.0, 1.0)],
+ [[CPImage alloc] initWithContentsOfFile:[bundle pathForResource:@"CPWindow/HUD/CPWindowHUDBackground5.png"] size:CPSizeMake(6.0, 1.0)],
+
+ [[CPImage alloc] initWithContentsOfFile:[bundle pathForResource:@"CPWindow/HUD/CPWindowHUDBackground6.png"] size:CPSizeMake(6.0, 6.0)],
+ [[CPImage alloc] initWithContentsOfFile:[bundle pathForResource:@"CPWindow/HUD/CPWindowHUDBackground7.png"] size:CPSizeMake(6.0, 6.0)],
+ [[CPImage alloc] initWithContentsOfFile:[bundle pathForResource:@"CPWindow/HUD/CPWindowHUDBackground8.png"] size:CPSizeMake(6.0, 6.0)]
+ ]]];
+
+ _CPHUDWindowViewCloseImage = [[CPImage alloc] initWithContentsOfFile:[bundle pathForResource:@"HUDTheme/WindowClose.png"] size:CPSizeMake(20.0, 20.0)];
+ _CPHUDWindowViewCloseActiveImage = [[CPImage alloc] initWithContentsOfFile:[bundle pathForResource:@"HUDTheme/WindowCloseActive.png"] size:CPSizeMake(20.0, 20.0)];
+}
+
++ (CGRect)contentRectForFrameRect:(CGRect)aFrameRect
+{
+ var contentRect = CGRectMakeCopy(aFrameRect),
+ titleBarHeight = HUD_TITLEBAR_HEIGHT;
+
+ contentRect.origin.y += titleBarHeight;
+ contentRect.size.height -= titleBarHeight;
+
+ return contentRect;
+}
+
++ (CGRect)frameRectForContentRect:(CGRect)aContentRect
+{
+ var frameRect = CGRectMakeCopy(aContentRect),
+ titleBarHeight = HUD_TITLEBAR_HEIGHT;
+
+ frameRect.origin.y -= titleBarHeight;
+ frameRect.size.height += titleBarHeight;
+
+ return frameRect;
+}
+
+- (CGRect)contentRectForFrameRect:(CGRect)aFrameRect
+{
+ var contentRect = [[self class] contentRectForFrameRect:aFrameRect];
+
+ if ([[[self owningWindow] toolbar] isVisible])
+ {
+ toolbarHeight = CGRectGetHeight([[self toolbarView] frame]);
+
+ contentRect.origin.y += toolbarHeight;
+ contentRect.size.height -= toolbarHeight;
+ }
+
+ return contentRect;
+}
+
+- (CGRect)frameRectForContentRect:(CGRect)aContentRect
+{
+ var frameRect = [[self class] frameRectForContentRect:aContentRect];
+
+ if ([[[self owningWindow] toolbar] isVisible])
+ {
+ toolbarHeight = CGRectGetHeight([[self toolbarView] frame]);
+
+ frameRect.origin.y -= toolbarHeight;
+ frameRect.size.height += toolbarHeight;
+ }
+
+ return frameRect;
+}
+
+- (id)initWithFrame:(CPRect)aFrame styleMask:(unsigned)aStyleMask owningWindow:(CPWindow)aWindow
+{
+ self = [super initWithFrame:aFrame styleMask:aStyleMask owningWindow:aWindow];
+
+ if (self)
+ {
+ var bounds = [self bounds];
+
+ [self setBackgroundColor:_CPHUDWindowViewBackgroundColor];
+
+ _titleField = [[CPTextField alloc] initWithFrame:CGRectMakeZero()];
+
+ [_titleField setHitTests:NO];
+ [_titleField setFont:[CPFont systemFontOfSize:11.0]];
+ [_titleField setTextColor:[CPColor whiteColor]];
+ [_titleField setTextShadow:[CPShadow shadowWithOffset:CPSizeMake(0.0, 1.0) blurRadius:2.0 color:[CPColor blackColor]]];
+ [_titleField setAutoresizingMask:CPViewWidthSizable];
+
+ // FIXME: Make this to CPLineBreakByTruncatingMiddle once it's implemented.
+ [_titleField setLineBreakMode:CPLineBreakByTruncatingTail];
+ [_titleField setAlignment:CPCenterTextAlignment];
+
+ [_titleField setStringValue:@"Untitled"];
+ [_titleField sizeToFit];
+ [_titleField setAutoresizingMask:CPViewWidthSizable];
+ [_titleField setStringValue:@""];
+
+ [_titleField setFrame:CGRectMake(20.0, 3.0, CGRectGetWidth([self bounds]) - 40.0, CGRectGetHeight([_titleField frame]))];
+
+ [self addSubview:_titleField];
+
+ if (_styleMask & CPClosableWindowMask)
+ {
+ var closeSize = [_CPHUDWindowViewCloseImage size];
+
+ _closeButton = [[CPButton alloc] initWithFrame:CGRectMake(4.0, 4.0, closeSize.width, closeSize.height)];
+
+ [_closeButton setBordered:NO];
+
+ [_closeButton setImage:_CPHUDWindowViewCloseImage];
+ [_closeButton setAlternateImage:_CPHUDWindowViewCloseActiveImage];
+
+ [_closeButton setTarget:aWindow];
+ [_closeButton setAction:@selector(performClose:)];
+
+ [self addSubview:_closeButton];
+ }
+
+ [self setResizeIndicatorOffset:CGSizeMake(5.0, 5.0)];
+ }
+
+ return self;
+}
+
+- (void)setTitle:(CPString)aTitle
+{
+ [_titleField setStringValue:aTitle];
+}
+
+- (_CPToolbarView)toolbarView
+{
+ return _toolbarView;
+}
+
+- (CPColor)toolbarLabelColor
+{
+ return [CPColor whiteColor];
+}
+
+- (CGSize)toolbarOffset
+{
+ return CGSizeMake(0.0, HUD_TITLEBAR_HEIGHT);
+}
+
+- (void)tile
+{
+ [super tile];
+
+ var owningWindow = [self owningWindow];
+
+ [[owningWindow contentView] setFrameOrigin:CGPointMake(0.0, [self toolbarMaxY])];//HUD_TITLEBAR_HEIGHT + toolbarHeight)];
+}
+
+@end
+
diff --git a/AppKit/CPWindow/_CPStandardWindowView.j b/AppKit/CPWindow/_CPStandardWindowView.j
new file mode 100644
index 000000000..5c1c4995e
--- /dev/null
+++ b/AppKit/CPWindow/_CPStandardWindowView.j
@@ -0,0 +1,285 @@
+/*
+ * _CPStandardWindowView.j
+ * AppKit
+ *
+ * Created by Francisco Tolmasky.
+ * Copyright 2008, 280 North, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+@import "_CPWindowView.j"
+
+var GRADIENT_HEIGHT = 41.0;
+
+var _CPTexturedWindowHeadGradientColor = nil,
+ _CPTexturedWindowHeadSolidColor = nil;
+
+@implementation _CPTexturedWindowHeadView : CPView
+{
+ CPView _gradientView;
+ CPView _solidView;
+ CPView _dividerView;
+}
+
++ (CPColor)gradientColor
+{
+ if (!_CPTexturedWindowHeadGradientColor)
+ {
+ var bundle = [CPBundle bundleForClass:[_CPWindowView class]];
+
+ _CPTexturedWindowHeadGradientColor = [CPColor colorWithPatternImage:[[CPThreePartImage alloc] initWithImageSlices:
+ [
+ [[CPImage alloc] initWithContentsOfFile:[bundle pathForResource:@"CPWindow/Standard/CPWindowStandardTop0.png"] size:CGSizeMake(6.0, 41.0)],
+ [[CPImage alloc] initWithContentsOfFile:[bundle pathForResource:@"CPWindow/Standard/CPWindowStandardTop1.png"] size:CGSizeMake(1.0, 41.0)],
+ [[CPImage alloc] initWithContentsOfFile:[bundle pathForResource:@"CPWindow/Standard/CPWindowStandardTop2.png"] size:CGSizeMake(6.0, 41.0)]
+ ]
+ isVertical:NO
+ ]];
+ }
+
+ return _CPTexturedWindowHeadGradientColor;
+}
+
++ (CPColor)solidColor
+{
+ if (!_CPTexturedWindowHeadSolidColor)
+ _CPTexturedWindowHeadSolidColor = [CPColor colorWithCalibratedRed:182.0 / 255.0 green:182.0 / 255.0 blue:182.0 / 255.0 alpha:1.0];
+
+ return _CPTexturedWindowHeadSolidColor;
+}
+
+- (id)initWithFrame:(CGRect)aFrame
+{
+ self = [super initWithFrame:aFrame];
+
+ if (self)
+ {
+ var theClass = [self class],
+ bounds = [self bounds];
+
+ _gradientView = [[CPView alloc] initWithFrame:CGRectMake(0.0, 0.0, CGRectGetWidth(bounds), GRADIENT_HEIGHT)];
+ [_gradientView setBackgroundColor:[theClass gradientColor]];
+
+ [self addSubview:_gradientView];
+
+ _solidView = [[CPView alloc] initWithFrame:CGRectMake(0.0, GRADIENT_HEIGHT, CGRectGetWidth(bounds), CGRectGetHeight(bounds) - GRADIENT_HEIGHT)];
+ [_solidView setBackgroundColor:[theClass solidColor]];
+
+ [self addSubview:_solidView];
+ }
+
+ return self;
+}
+
+- (void)resizeSubviewsWithOldSize:(CGSize)aSize
+{
+ var bounds = [self bounds];
+
+ [_gradientView setFrameSize:CGSizeMake(CGRectGetWidth(bounds), GRADIENT_HEIGHT)];
+ [_solidView setFrameSize:CGSizeMake(CGRectGetWidth(bounds), CGRectGetHeight(bounds) - GRADIENT_HEIGHT)];
+}
+
+@end
+
+var _CPStandardWindowViewBodyBackgroundColor = nil,
+ _CPStandardWindowViewDividerBackgroundColor = nil,
+ _CPStandardWindowViewTitleBackgroundColor = nil;
+
+var STANDARD_GRADIENT_HEIGHT = 41.0;
+ STANDARD_TITLEBAR_HEIGHT = 22.0;
+
+@implementation _CPStandardWindowView : _CPWindowView
+{
+ _CPTexturedWindowHeadView _headView;
+ CPView _dividerView;
+ CPView _bodyView;
+ CPView _toolbarView;
+
+ CPTextField _titleField;
+ CPButton _closeButton;
+}
+
++ (CPColor)bodyBackgroundColor
+{
+ if (!_CPStandardWindowViewBodyBackgroundColor)
+ _CPStandardWindowViewBodyBackgroundColor = [CPColor whiteColor];//
+
+ return _CPStandardWindowViewBodyBackgroundColor;
+}
+
++ (CPColor)dividerBackgroundColor
+{
+ if (!_CPStandardWindowViewDividerBackgroundColor)
+ _CPStandardWindowViewDividerBackgroundColor = [CPColor colorWithCalibratedRed:125.0 / 255.0 green:125.0 / 255.0 blue:125.0 / 255.0 alpha:1.0];
+
+ return _CPStandardWindowViewDividerBackgroundColor;
+}
+
++ (CPColor)titleColor
+{
+ if (!_CPStandardWindowViewTitleBackgroundColor)
+ _CPStandardWindowViewTitleBackgroundColor = [CPColor colorWithCalibratedRed:44.0 / 255.0 green:44.0 / 255.0 blue:44.0 / 255.0 alpha:1.0];
+
+ return _CPStandardWindowViewTitleBackgroundColor;
+}
+
++ (CGRect)contentRectForFrameRect:(CGRect)aFrameRect
+{
+ var contentRect = CGRectMakeCopy(aFrameRect),
+ titleBarHeight = STANDARD_TITLEBAR_HEIGHT + 1.0;
+
+ contentRect.origin.y += titleBarHeight;
+ contentRect.size.height -= titleBarHeight;
+
+ return contentRect;
+}
+
++ (CGRect)frameRectForContentRect:(CGRect)aContentRect
+{
+ var frameRect = CGRectMakeCopy(aContentRect),
+ titleBarHeight = STANDARD_TITLEBAR_HEIGHT + 1.0;
+
+ frameRect.origin.y -= titleBarHeight;
+ frameRect.size.height += titleBarHeight;
+
+ return frameRect;
+}
+
+- (CGRect)contentRectForFrameRect:(CGRect)aFrameRect
+{
+ var contentRect = [[self class] contentRectForFrameRect:aFrameRect];
+
+ if ([[[self owningWindow] toolbar] isVisible])
+ {
+ toolbarHeight = CGRectGetHeight([[self toolbarView] frame]);
+
+ contentRect.origin.y += toolbarHeight;
+ contentRect.size.height -= toolbarHeight;
+ }
+
+ return contentRect;
+}
+
+- (CGRect)frameRectForContentRect:(CGRect)aContentRect
+{
+ var frameRect = [[self class] frameRectForContentRect:aContentRect];
+
+ if ([[[self owningWindow] toolbar] isVisible])
+ {
+ toolbarHeight = CGRectGetHeight([[self toolbarView] frame]);
+
+ frameRect.origin.y -= toolbarHeight;
+ frameRect.size.height += toolbarHeight;
+ }
+
+ return frameRect;
+}
+
+- (id)initWithFrame:(CPRect)aFrame styleMask:(unsigned)aStyleMask owningWindow:(CPWindow)aWindow
+{
+ self = [super initWithFrame:aFrame styleMask:aStyleMask owningWindow:aWindow];
+
+ if (self)
+ {
+ var theClass = [self class],
+ bounds = [self bounds];
+
+ _headView = [[_CPTexturedWindowHeadView alloc] initWithFrame:CGRectMake(0.0, 0.0, CGRectGetWidth(bounds), STANDARD_TITLEBAR_HEIGHT)];
+
+ [_headView setAutoresizingMask:CPViewWidthSizable];;
+ [_headView setHitTests:NO];
+
+ [self addSubview:_headView];
+
+ _dividerView = [[CPView alloc] initWithFrame:CGRectMake(0.0, CGRectGetMaxY([_headView frame]), CGRectGetWidth(bounds), 1.0)];
+
+ [_dividerView setAutoresizingMask:CPViewWidthSizable];
+ [_dividerView setBackgroundColor:[theClass dividerBackgroundColor]];
+ [_dividerView setHitTests:NO];
+
+ [self addSubview:_dividerView];
+
+ var y = CGRectGetMaxY([_dividerView frame]);
+
+ _bodyView = [[CPView alloc] initWithFrame:CGRectMake(0.0, y, CGRectGetWidth(bounds), CGRectGetHeight(bounds) - y)];
+
+ [_bodyView setAutoresizingMask:CPViewWidthSizable | CPViewHeightSizable];
+ [_bodyView setBackgroundColor:[theClass bodyBackgroundColor]];
+ [_bodyView setHitTests:NO];
+
+ [self addSubview:_bodyView];
+
+ [self setResizeIndicatorOffset:CGSizeMake(2.0, 2.0)];
+ [self setShowsResizeIndicator:NO];
+ [self setShowsResizeIndicator:YES];
+
+ _titleField = [[CPTextField alloc] initWithFrame:CGRectMakeZero()];
+
+ [_titleField setFont:[CPFont boldSystemFontOfSize:12.0]];
+ [_titleField setAutoresizingMask:CPViewWidthSizable];
+
+ // FIXME: Make this to CPLineBreakByTruncatingMiddle once it's implemented.
+ [_titleField setLineBreakMode:CPLineBreakByTruncatingTail];
+ [_titleField setAlignment:CPCenterTextAlignment];
+
+ [_titleField setStringValue:@"Untitled"];
+ [_titleField sizeToFit];
+ [_titleField setAutoresizingMask:CPViewWidthSizable];
+ [_titleField setStringValue:@""];
+
+ [self addSubview:_titleField];
+
+ [self tile];
+ }
+
+ return self;
+}
+
+- (CGSize)toolbarOffset
+{
+ return CGSizeMake(0.0, STANDARD_TITLEBAR_HEIGHT);
+}
+
+- (void)tile
+{
+ [super tile];
+
+ var owningWindow = [self owningWindow],
+ width = CGRectGetWidth([self bounds]);
+
+ [_headView setFrameSize:CGSizeMake(width, [self toolbarMaxY])];
+ [_dividerView setFrameOrigin:CGPointMake(0.0, CGRectGetMaxY([_headView frame]))];
+ [_bodyView setFrameOrigin:CGPointMake(0.0, CGRectGetMaxY([_dividerView frame]))];
+
+ [_titleField setFrame:CGRectMake(10.0, 0.0, width - 20.0, CGRectGetHeight([_titleField frame]))];
+
+ [[owningWindow contentView] setFrameOrigin:CGPointMake(0.0, CGRectGetMaxY([_dividerView frame]))];
+}
+
+- (void)setTitle:(CPString)aTitle
+{
+ [_titleField setStringValue:aTitle];
+}
+
+- (void)mouseDown:(CPEvent)anEvent
+{
+ if (CGRectContainsPoint([_headView frame], [self convertPoint:[anEvent locationInWindow] fromView:nil]))
+ return [self trackMoveWithEvent:anEvent];
+
+ [super mouseDown:anEvent];
+}
+
+@end
diff --git a/AppKit/CPWindow/_CPWindowView.j b/AppKit/CPWindow/_CPWindowView.j
new file mode 100644
index 000000000..e5ec2da77
--- /dev/null
+++ b/AppKit/CPWindow/_CPWindowView.j
@@ -0,0 +1,311 @@
+/*
+ * _CPWindowView.j
+ * AppKit
+ *
+ * Created by Francisco Tolmasky.
+ * Copyright 2008, 280 North, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+@import "CPView.j"
+@import "CPImageView.j"
+
+#include "../CoreGraphics/CGGeometry.h"
+
+
+var _CPWindowViewResizeIndicatorImage = nil;
+
+@implementation _CPWindowView : CPView
+{
+ unsigned _styleMask;
+
+ CPImageView _resizeIndicator;
+ CGSize _resizeIndicatorOffset;
+
+ CPView _toolbarView;
+
+ CPWindow _owningWindow;
+
+ CGRect _resizeFrame;
+ CGPoint _mouseDraggedPoint;
+}
+
++ (void)initialize
+{
+ if (self != [_CPWindowView class])
+ return;
+
+ _CPWindowViewResizeIndicatorImage = [[CPImage alloc] initWithContentsOfFile:[[CPBundle bundleForClass:[CPWindow class]] pathForResource:@"_CPWindowView/_CPWindowViewResizeIndicator.png"] size:CGSizeMake(12.0, 12.0)];
+}
+
++ (CGRect)contentRectForFrameRect:(CGRect)aFrameRect
+{
+ return CGRectMakeCopy(aFrameRect);
+}
+
++ (CGRect)frameRectForContentRect:(CGRect)aContentRect
+{
+ return CGRectMakeCopy(aContentRect);
+}
+
+- (CGRect)contentRectForFrameRect:(CGRect)aFrameRect
+{
+ return [[self class] contentRectForFrameRect:aFrameRect];
+}
+
+- (CGRect)frameRectForContentRect:(CGRect)aContentRect
+{
+ return [[self class] frameRectForContentRect:aContentRect];
+}
+
+- (id)initWithFrame:(CPRect)aFrame styleMask:(unsigned)aStyleMask owningWindow:(CPWindow)aWindow
+{
+ self = [super initWithFrame:aFrame];
+
+ if (self)
+ {
+ _styleMask = aStyleMask;
+ _owningWindow = aWindow;
+ _resizeIndicatorOffset = CGSizeMake(0.0, 0.0);
+ _toolbarOffset = CGSizeMake(0.0, 0.0);
+
+ [self setShowsResizeIndicator:!(_styleMask & CPBorderlessBridgeWindowMask) && (_styleMask & CPResizableWindowMask)];
+ }
+
+ return self;
+}
+
+- (CPWindow)owningWindow
+{
+ return _owningWindow;
+}
+
+- (void)setTitle:(CPString)aTitle
+{
+}
+
+- (BOOL)acceptsFirstMouse:(CPEvent)anEvent
+{
+ return YES;
+}
+
+- (void)mouseDown:(CPEvent)anEvent
+{
+ var theWindow = [self owningWindow];
+
+ if ((_styleMask & CPResizableWindowMask) && _resizeIndicator)
+ {
+ // FIXME: This should be better
+ var frame = [_resizeIndicator frame];
+
+ if (CGRectContainsPoint(frame, [self convertPoint:[anEvent locationInWindow] fromView:nil]))
+ return [self trackResizeWithEvent:anEvent];
+ }
+
+ if ([theWindow isMovableByWindowBackground])
+ [self trackMoveWithEvent:anEvent];
+
+ else
+ [super mouseDown:anEvent];
+}
+
+- (void)trackResizeWithEvent:(CPEvent)anEvent
+{
+ var location = [anEvent locationInWindow],
+ type = [anEvent type];
+
+ if (type === CPLeftMouseUp)
+ return;
+
+ var theWindow = [self owningWindow];
+
+ if (type === CPLeftMouseDown)
+ {
+ var frame = [theWindow frame];
+
+ _resizeFrame = CGRectMake(location.x, location.y, CGRectGetWidth(frame), CGRectGetHeight(frame));
+ }
+
+ else if (type === CPLeftMouseDragged)
+ [theWindow setFrameSize:CGSizeMake(CGRectGetWidth(_resizeFrame) + location.x - CGRectGetMinX(_resizeFrame), CGRectGetHeight(_resizeFrame) + location.y - CGRectGetMinY(_resizeFrame))];
+
+ [CPApp setTarget:self selector:@selector(trackResizeWithEvent:) forNextEventMatchingMask:CPLeftMouseDraggedMask | CPLeftMouseUpMask untilDate:nil inMode:nil dequeue:YES];
+}
+
+- (void)trackMoveWithEvent:(CPEvent)anEvent
+{
+ var type = [anEvent type];
+
+ if (type === CPLeftMouseUp)
+ return;
+
+ else if (type === CPLeftMouseDown)
+ _mouseDraggedPoint = [[self owningWindow] convertBaseToBridge:[anEvent locationInWindow]];
+
+ else if (type === CPLeftMouseDragged)
+ {
+ var theWindow = [self owningWindow],
+ location = [theWindow convertBaseToBridge:[anEvent locationInWindow]],
+ frame = [theWindow frame];
+
+ [theWindow setFrameOrigin:CGPointMake(_CGRectGetMinX(frame) + (location.x - _mouseDraggedPoint.x), _CGRectGetMinY(frame) + (location.y - _mouseDraggedPoint.y))];
+
+ _mouseDraggedPoint = location;
+ }
+
+ [CPApp setTarget:self selector:@selector(trackMoveWithEvent:) forNextEventMatchingMask:CPLeftMouseDraggedMask | CPLeftMouseUpMask untilDate:nil inMode:nil dequeue:YES];
+}
+
+- (void)setShowsResizeIndicator:(BOOL)shouldShowResizeIndicator
+{
+ if (shouldShowResizeIndicator)
+ {
+ var size = [_CPWindowViewResizeIndicatorImage size],
+ boundsSize = [self frame].size;
+
+ _resizeIndicator = [[CPImageView alloc] initWithFrame:CGRectMake(boundsSize.width - size.width - _resizeIndicatorOffset.width, boundsSize.height - size.height - _resizeIndicatorOffset.height, size.width, size.height)];
+
+ [_resizeIndicator setImage:_CPWindowViewResizeIndicatorImage];
+ [_resizeIndicator setAutoresizingMask:CPViewMinXMargin | CPViewMinYMargin];
+
+ [self addSubview:_resizeIndicator positioned:CPWindowAbove relativeTo:nil];
+ }
+ else
+ {
+ [_resizeIndicator removeFromSuperview];
+
+ _resizeIndicator = nil;
+ }
+}
+
+- (CPImage)showsResizeIndicator
+{
+ return _resizeIndicator != nil;
+}
+
+- (void)setResizeIndicatorOffset:(CGSize)anOffset
+{
+ if (CGSizeEqualToSize(_resizeIndicatorOffset, anOffset))
+ return;
+
+ _resizeIndicatorOffset = anOffset;
+
+ if (!_resizeIndicator)
+ return;
+
+ var size = [_resizeIndicator frame].size,
+ boundsSize = [self frame].size;
+
+ [_resizeIndicator setFrameOrigin:CGPointMake(boundsSize.width - size.width - anOffset.width, boundsSize.height - size.height - anOffset.height)];
+}
+
+- (CGSize)resizeIndicatorOffset
+{
+ return _resizeIndicatorOffset;
+}
+
+- (void)windowDidChangeDocumentEdited
+{
+}
+
+- (void)windowDidChangeDocumentSaving
+{
+}
+
+- (BOOL)showsToolbar
+{
+ return YES;
+ return NO;
+}
+
+- (CGSize)toolbarOffset
+{
+ return CGSizeMakeZero();
+}
+
+- (CPColor)toolbarLabelColor
+{
+ return [CPColor blackColor];
+}
+
+- (float)toolbarMaxY
+{
+ if (!_toolbarView || [_toolbarView isHidden])
+ return [self toolbarOffset].height;
+
+ return CGRectGetMaxY([_toolbarView frame]);
+}
+
+- (_CPToolbarView)toolbarView
+{
+ return _toolbarView;
+}
+
+- (void)tile
+{
+ var owningWindow = [self owningWindow],
+ bounds = [self bounds],
+ width = CGRectGetWidth(bounds);
+
+ if ([[owningWindow toolbar] isVisible])
+ {
+ var toolbarView = [self toolbarView],
+ toolbarOffset = [self toolbarOffset];
+
+ [toolbarView setFrameOrigin:CGPointMake(toolbarOffset.width, toolbarOffset.height)];
+ }
+
+ if ([self showsResizeIndicator])
+ {
+ var size = [_resizeIndicator frame].size,
+ boundsSize = [self bounds].size;
+
+ [_resizeIndicator setFrameOrigin:CGPointMake(boundsSize.width - size.width - _resizeIndicatorOffset.width, boundsSize.height - size.height - _resizeIndicatorOffset.height)];
+ }
+}
+
+- (void)noteToolbarChanged
+{
+ var owningWindow = [self owningWindow],
+ toolbar = [owningWindow toolbar],
+ toolbarView = [toolbar _toolbarView];
+
+ if (_toolbarView !== toolbarView)
+ {
+ [_toolbarView removeFromSuperview];
+
+ if (toolbarView)
+ {
+ [toolbarView removeFromSuperview];
+ [toolbarView setLabelColor:[self toolbarLabelColor]];
+ [toolbarView setFrameSize:CGSizeMake(CGRectGetWidth([self bounds]), CGRectGetHeight([toolbarView frame]))];
+
+ [self addSubview:toolbarView];
+ }
+
+ _toolbarView = toolbarView;
+ }
+
+ [toolbarView setHidden:![self showsToolbar] || ![toolbar isVisible]];
+
+ [self setAutoresizesSubviews:NO];
+ [owningWindow setFrameSize:[self frameRectForContentRect:[[owningWindow contentView] frame]].size];
+ [self setAutoresizesSubviews:YES];
+
+ [self tile];
+}
+
+@end
diff --git a/AppKit/Resources/CPWindow/HUD/CPWindowHUDBackground0.png b/AppKit/Resources/CPWindow/HUD/CPWindowHUDBackground0.png
new file mode 100644
index 000000000..d6f02e4e4
Binary files /dev/null and b/AppKit/Resources/CPWindow/HUD/CPWindowHUDBackground0.png differ
diff --git a/AppKit/Resources/CPWindow/HUD/CPWindowHUDBackground1.png b/AppKit/Resources/CPWindow/HUD/CPWindowHUDBackground1.png
new file mode 100644
index 000000000..8ebf760e8
Binary files /dev/null and b/AppKit/Resources/CPWindow/HUD/CPWindowHUDBackground1.png differ
diff --git a/AppKit/Resources/CPWindow/HUD/CPWindowHUDBackground2.png b/AppKit/Resources/CPWindow/HUD/CPWindowHUDBackground2.png
new file mode 100644
index 000000000..d855c0987
Binary files /dev/null and b/AppKit/Resources/CPWindow/HUD/CPWindowHUDBackground2.png differ
diff --git a/AppKit/Resources/CPWindow/HUD/CPWindowHUDBackground3.png b/AppKit/Resources/CPWindow/HUD/CPWindowHUDBackground3.png
new file mode 100644
index 000000000..f0093ecb7
Binary files /dev/null and b/AppKit/Resources/CPWindow/HUD/CPWindowHUDBackground3.png differ
diff --git a/AppKit/Resources/CPWindow/HUD/CPWindowHUDBackground4.png b/AppKit/Resources/CPWindow/HUD/CPWindowHUDBackground4.png
new file mode 100644
index 000000000..1e23c9402
Binary files /dev/null and b/AppKit/Resources/CPWindow/HUD/CPWindowHUDBackground4.png differ
diff --git a/AppKit/Resources/CPWindow/HUD/CPWindowHUDBackground5.png b/AppKit/Resources/CPWindow/HUD/CPWindowHUDBackground5.png
new file mode 100644
index 000000000..37aed4be3
Binary files /dev/null and b/AppKit/Resources/CPWindow/HUD/CPWindowHUDBackground5.png differ
diff --git a/AppKit/Resources/CPWindow/HUD/CPWindowHUDBackground6.png b/AppKit/Resources/CPWindow/HUD/CPWindowHUDBackground6.png
new file mode 100644
index 000000000..c2e32acb6
Binary files /dev/null and b/AppKit/Resources/CPWindow/HUD/CPWindowHUDBackground6.png differ
diff --git a/AppKit/Resources/CPWindow/HUD/CPWindowHUDBackground7.png b/AppKit/Resources/CPWindow/HUD/CPWindowHUDBackground7.png
new file mode 100644
index 000000000..71d3c5ac9
Binary files /dev/null and b/AppKit/Resources/CPWindow/HUD/CPWindowHUDBackground7.png differ
diff --git a/AppKit/Resources/CPWindow/HUD/CPWindowHUDBackground8.png b/AppKit/Resources/CPWindow/HUD/CPWindowHUDBackground8.png
new file mode 100644
index 000000000..fabaf041c
Binary files /dev/null and b/AppKit/Resources/CPWindow/HUD/CPWindowHUDBackground8.png differ
diff --git a/AppKit/Resources/HUDTheme/WindowCenterRight.png b/AppKit/Resources/CPWindow/Standard/CPWindowStandardTop0.png
similarity index 92%
rename from AppKit/Resources/HUDTheme/WindowCenterRight.png
rename to AppKit/Resources/CPWindow/Standard/CPWindowStandardTop0.png
index 750eb7131..bf64acfec 100644
Binary files a/AppKit/Resources/HUDTheme/WindowCenterRight.png and b/AppKit/Resources/CPWindow/Standard/CPWindowStandardTop0.png differ
diff --git a/AppKit/Resources/HUDTheme/WindowCenter.png b/AppKit/Resources/CPWindow/Standard/CPWindowStandardTop1.png
similarity index 95%
rename from AppKit/Resources/HUDTheme/WindowCenter.png
rename to AppKit/Resources/CPWindow/Standard/CPWindowStandardTop1.png
index 5b9ae35e2..430955e20 100644
Binary files a/AppKit/Resources/HUDTheme/WindowCenter.png and b/AppKit/Resources/CPWindow/Standard/CPWindowStandardTop1.png differ
diff --git a/AppKit/Resources/HUDTheme/WindowBottomCenter.png b/AppKit/Resources/CPWindow/Standard/CPWindowStandardTop2.png
similarity index 93%
rename from AppKit/Resources/HUDTheme/WindowBottomCenter.png
rename to AppKit/Resources/CPWindow/Standard/CPWindowStandardTop2.png
index ca64f73a9..ac1f24209 100644
Binary files a/AppKit/Resources/HUDTheme/WindowBottomCenter.png and b/AppKit/Resources/CPWindow/Standard/CPWindowStandardTop2.png differ
diff --git a/AppKit/Resources/HUDTheme/WindowBottomLeft.png b/AppKit/Resources/HUDTheme/WindowBottomLeft.png
deleted file mode 100644
index 521b7c6f8..000000000
Binary files a/AppKit/Resources/HUDTheme/WindowBottomLeft.png and /dev/null differ
diff --git a/AppKit/Resources/HUDTheme/WindowBottomRight.png b/AppKit/Resources/HUDTheme/WindowBottomRight.png
deleted file mode 100644
index ac800b041..000000000
Binary files a/AppKit/Resources/HUDTheme/WindowBottomRight.png and /dev/null differ
diff --git a/AppKit/Resources/HUDTheme/WindowCenterLeft.png b/AppKit/Resources/HUDTheme/WindowCenterLeft.png
deleted file mode 100644
index 4d6b63fff..000000000
Binary files a/AppKit/Resources/HUDTheme/WindowCenterLeft.png and /dev/null differ
diff --git a/AppKit/Resources/HUDTheme/WindowTopCenter.png b/AppKit/Resources/HUDTheme/WindowTopCenter.png
deleted file mode 100644
index 0b89f1b01..000000000
Binary files a/AppKit/Resources/HUDTheme/WindowTopCenter.png and /dev/null differ
diff --git a/AppKit/Resources/HUDTheme/WindowTopLeft.png b/AppKit/Resources/HUDTheme/WindowTopLeft.png
deleted file mode 100644
index 290db9241..000000000
Binary files a/AppKit/Resources/HUDTheme/WindowTopLeft.png and /dev/null differ
diff --git a/AppKit/Resources/HUDTheme/WindowTopRight.png b/AppKit/Resources/HUDTheme/WindowTopRight.png
deleted file mode 100644
index dbb8e39b9..000000000
Binary files a/AppKit/Resources/HUDTheme/WindowTopRight.png and /dev/null differ
diff --git a/AppKit/_CPWindowView.j b/AppKit/_CPWindowView.j
deleted file mode 100644
index 8954d52f4..000000000
--- a/AppKit/_CPWindowView.j
+++ /dev/null
@@ -1,298 +0,0 @@
-/*
- * _CPWindowView.j
- * AppKit
- *
- * Created by Francisco Tolmasky.
- * Copyright 2008, 280 North, Inc.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- */
-
-@import "CPView.j"
-@import "CPImageView.j"
-
-
-var _CPWindowViewResizeIndicatorImage = nil;
-
-@implementation _CPWindowView : CPView
-{
- unsigned _styleMask;
-
- CPImageView _resizeIndicator;
- CGSize _resizeIndicatorOffset;
-
- CPString _title;
-}
-
-+ (void)initialize
-{
- if (self != [_CPWindowView class])
- return;
-
- _CPWindowViewResizeIndicatorImage = [[CPImage alloc] initWithContentsOfFile:[[CPBundle bundleForClass:self] pathForResource:@"_CPWindowView/_CPWindowViewResizeIndicator.png"] size:CGSizeMake(12.0, 12.0)];
-}
-
-- (id)initWithFrame:(CPRect)aFrame forStyleMask:(unsigned)aStyleMask
-{
- if (aStyleMask & CPHUDBackgroundWindowMask)
- self = [_CPHUDWindowView alloc];
-
- self._styleMask = aStyleMask;
-
- return [self initWithFrame:aFrame];
-}
-
-- (id)initWithFrame:(CGRect)aFrame
-{
- self = [super initWithFrame:aFrame];
-
- if (self)
- {
- _resizeIndicatorOffset = CGSizeMake(0.0, 0.0);
-
- [self setShowsResizeIndicator:!(_styleMask & CPBorderlessBridgeWindowMask) && (_styleMask & CPResizableWindowMask)];
- }
-
- return self;
-}
-
-- (void)setTitle:(CPString)aTitle
-{
-}
-
-- (CPString)title
-{
- return nil;
-}
-
-- (BOOL)acceptsFirstMouse:(CPEvent)anEvent
-{
- return YES;
-}
-
-- (void)mouseDown:(CPEvent)anEvent
-{
- var theWindow = [self window];
-
- if ((_styleMask & CPResizableWindowMask) && _resizeIndicator)
- {
- // FIXME: This should be better
- var frame = [_resizeIndicator frame];
-
- if (CGRectContainsPoint(frame, [self convertPoint:[anEvent locationInWindow] fromView:nil]))
- return [theWindow trackResizeWithEvent:anEvent];
- }
-
- if ([theWindow isMovableByWindowBackground])
- [theWindow trackMoveWithEvent:anEvent];
-
- else
- [super mouseDown:anEvent];
-}
-
-- (void)setShowsResizeIndicator:(BOOL)shouldShowResizeIndicator
-{
- if (shouldShowResizeIndicator)
- {
- var size = [_CPWindowViewResizeIndicatorImage size],
- boundsSize = [self frame].size;
-
- _resizeIndicator = [[CPImageView alloc] initWithFrame:CGRectMake(boundsSize.width - size.width - _resizeIndicatorOffset.width, boundsSize.height - size.height - _resizeIndicatorOffset.height, size.width, size.height)];
-
- [_resizeIndicator setImage:_CPWindowViewResizeIndicatorImage];
- [_resizeIndicator setAutoresizingMask:CPViewMinXMargin | CPViewMinYMargin];
-
- [self addSubview:_resizeIndicator positioned:CPWindowAbove relativeTo:nil];
- }
- else
- {
- [_resizeIndicator removeFromSuperview];
-
- _resizeIndicator = nil;
- }
-}
-
-- (CPImage)showsResizeIndicator
-{
- return _resizeIndicator != nil;
-}
-
-- (void)setResizeIndicatorOffset:(CGSize)anOffset
-{
- if (CGSizeEqualToSize(_resizeIndicatorOffset, anOffset))
- return;
-
- _resizeIndicatorOffset = anOffset;
-
- if (!_resizeIndicator)
- return;
-
- var size = [_resizeIndicator frame].size,
- boundsSize = [self frame].size;
-
- [_resizeIndicator setFrameOrigin:CGPointMake(boundsSize.width - size.width - anOffset.width, boundsSize.height - size.height - anOffset.height)];
-}
-
-- (CGSize)resizeIndicatorOffset
-{
- return _resizeIndicatorOffset;
-}
-
-- (void)setTitle:(CPString)title
-{
- _title = title;
-}
-
-- (CPString)title
-{
- return _title;
-}
-
-- (void)windowDidChangeDocumentEdited
-{
-}
-
-- (void)windowDidChangeDocumentSaving
-{
-}
-
-@end
-
-var _CPHUDWindowViewTopImage = nil,
- _CPHUDWindowViewTopLeftImage = nil,
- _CPHUDWindowViewTopRightImage = nil,
-
- _CPHUDWindowViewLeftImage = nil,
- _CPHUDWindowViewRightImage = nil,
- _CPHUDWindowViewCenterImage = nil,
-
- _CPHUDWindowViewBottomImage = nil,
- _CPHUDWindowViewBottomLeftImage = nil,
- _CPHUDWindowViewBottomRightImage = nil,
-
- _CPHUDWindowViewBackgroundColor = nil,
-
- CPHUDCloseButtonImage = nil;
-
-@implementation _CPHUDWindowView : _CPWindowView
-{
- CPTextField _titleField;
- CPButton _closeButton;
-}
-
-+ (void)initialize
-{
- if (self != [_CPHUDWindowView class])
- return;
-
- var bundle = [CPBundle bundleForClass:self];
-
- _CPHUDWindowViewBackgroundColor = [CPColor colorWithPatternImage:[[CPNinePartImage alloc] initWithImageSlices:
- [
- [[CPImage alloc] initWithContentsOfFile:[bundle pathForResource:@"HUDTheme/WindowTopLeft.png"] size:CPSizeMake(15.0, 86.0)],
- [[CPImage alloc] initWithContentsOfFile:[bundle pathForResource:@"HUDTheme/WindowTopCenter.png"] size:CPSizeMake(1.0, 86.0)],
- [[CPImage alloc] initWithContentsOfFile:[bundle pathForResource:@"HUDTheme/WindowTopRight.png"] size:CPSizeMake(15.0, 86.0)],
-
- [[CPImage alloc] initWithContentsOfFile:[bundle pathForResource:@"HUDTheme/WindowCenterLeft.png"] size:CPSizeMake(15.0, 1.0)],
- [[CPImage alloc] initWithContentsOfFile:[bundle pathForResource:@"HUDTheme/WindowCenter.png"] size:CPSizeMake(1.0, 1.0)],
- [[CPImage alloc] initWithContentsOfFile:[bundle pathForResource:@"HUDTheme/WindowCenterRight.png"] size:CPSizeMake(15.0, 1.0)],
-
- [[CPImage alloc] initWithContentsOfFile:[bundle pathForResource:@"HUDTheme/WindowBottomLeft.png"] size:CPSizeMake(15.0, 39.0)],
- [[CPImage alloc] initWithContentsOfFile:[bundle pathForResource:@"HUDTheme/WindowBottomCenter.png"] size:CPSizeMake(1.0, 39.0)],
- [[CPImage alloc] initWithContentsOfFile:[bundle pathForResource:@"HUDTheme/WindowBottomRight.png"] size:CPSizeMake(15.0, 39.0)]
- ]]];
-
- _CPHUDWindowViewCloseImage = [[CPImage alloc] initWithContentsOfFile:[bundle pathForResource:@"HUDTheme/WindowClose.png"] size:CPSizeMake(20.0, 20.0)];
- _CPHUDWindowViewCloseActiveImage = [[CPImage alloc] initWithContentsOfFile:[bundle pathForResource:@"HUDTheme/WindowCloseActive.png"] size:CPSizeMake(20.0, 20.0)];
-}
-
-- (CPView)hitTest:(CPPoint)aPoint
-{
- var view = [super hitTest:aPoint];
-
- if (view == _titleField)
- return self;
-
- return view;
-}
-
-- (id)initWithFrame:(CPRect)aFrame
-{
- self = [super initWithFrame:aFrame];
-
- if (self)
- {
- var bounds = [self bounds];
-
- [self setBackgroundColor:_CPHUDWindowViewBackgroundColor];
-
- _titleField = [[CPTextField alloc] initWithFrame:CPRectMakeZero()];
-
- [_titleField setFont:[CPFont systemFontOfSize:11.0]];
- [_titleField setTextColor:[CPColor whiteColor]];
- [_titleField setTextShadow:[CPShadow shadowWithOffset:CPSizeMake(0.0, 1.0) blurRadius:2.0 color:[CPColor blackColor]]];
- [_titleField setAutoresizingMask:CPViewMinXMargin | CPViewMaxXMargin];
-
- [self addSubview:_titleField];
-
- if (_styleMask & CPClosableWindowMask)
- {
- var closeSize = [_CPHUDWindowViewCloseImage size];
-
- _closeButton = [[CPButton alloc] initWithFrame:CPRectMake(10.0, 7.0, closeSize.width, closeSize.height)];
-
- [_closeButton setBordered:NO];
-
- [_closeButton setImage:_CPHUDWindowViewCloseImage];
- [_closeButton setAlternateImage:_CPHUDWindowViewCloseActiveImage];
-
- [_closeButton setTarget:self];
- [_closeButton setAction:@selector(close:)];
-
- [self addSubview:_closeButton];
- }
-
- [self setResizeIndicatorOffset:CGSizeMake(8.0, 12.0)];
- }
-
- return self;
-}
-
-- (void)close:(id)aSender
-{
- [[self window] performClose:self];
-}
-
-- (void)setTitle:(CPString)aTitle
-{
- [_titleField setStringValue:aTitle];
- [_titleField sizeToFit];
-
- var size = [_titleField frame].size;
-
- [_titleField setFrameOrigin:CPPointMake((CPRectGetWidth([self frame]) - size.width) / 2.0, (26.0 - size.height) / 2.0)];
-}
-
-- (CPString)title
-{
- return [_titleField stringValue];
-}
-
-- (void)setFrameSize:(CPSize)aSize
-{
- [super setFrameSize:aSize];
-}
-
-@end
diff --git a/Foundation/CPDictionary.j b/Foundation/CPDictionary.j
index 62f12dfb9..593558502 100755
--- a/Foundation/CPDictionary.j
+++ b/Foundation/CPDictionary.j
@@ -305,9 +305,9 @@
*/
- (id)objectForKey:(CPString)aKey
{
- // We should really do this with inlining or something of that nature.
- return _buckets[aKey];
- //return dictionary_getValue(self, aKey);
+ var object = _buckets[aKey];
+
+ return (object === undefined) ? nil : object;
}
/*
Instance.objectsForKeys(keys, aNotFoundMarker)
diff --git a/Foundation/CPRange.j b/Foundation/CPRange.j
index ebdee50c9..2d6519784 100755
--- a/Foundation/CPRange.j
+++ b/Foundation/CPRange.j
@@ -62,7 +62,7 @@ function CPMakeRangeCopy(aRange)
*/
function CPEmptyRange(aRange)
{
- return aRange.length == 0;
+ return aRange.length === 0;
}
/*!
@@ -84,7 +84,7 @@ function CPMaxRange(aRange)
*/
function CPEqualRanges(lhsRange, rhsRange)
{
- return ((lhsRange.location == rhsRange.location) && (lhsRange.length == rhsRange.length));
+ return ((lhsRange.location === rhsRange.location) && (lhsRange.length === rhsRange.length));
}
/*!
@@ -109,8 +109,8 @@ function CPLocationInRange(aLocation, aRange)
*/
function CPUnionRange(lhsRange, rhsRange)
{
- var location = Math.min(lhsRange.location, rhsRange.location);
- return CPMakeRange(location, Math.max(CPMaxRange(lhsRange), CPMaxRange(rhsRange)) - location);
+ var location = MIN(lhsRange.location, rhsRange.location);
+ return CPMakeRange(location, MAX(CPMaxRange(lhsRange), CPMaxRange(rhsRange)) - location);
}
/*!
@@ -125,8 +125,8 @@ function CPIntersectionRange(lhsRange, rhsRange)
if(CPMaxRange(lhsRange) < rhsRange.location || CPMaxRange(rhsRange) < lhsRange.location)
return CPMakeRange(0, 0);
- var location = Math.max(lhsRange.location, rhsRange.location);
- return CPMakeRange(location, Math.min(CPMaxRange(lhsRange), CPMaxRange(rhsRange)) - location);
+ var location = MAX(lhsRange.location, rhsRange.location);
+ return CPMakeRange(location, MIN(CPMaxRange(lhsRange), CPMaxRange(rhsRange)) - location);
}
/*!
diff --git a/Foundation/CPSet.j b/Foundation/CPSet.j
index 2ba0b995d..9e739c743 100644
--- a/Foundation/CPSet.j
+++ b/Foundation/CPSet.j
@@ -6,13 +6,13 @@
* Extended by Ross Boucher
* Extended by Nabil Elisa
*
- * TODO: Needs to implement CPCoding, CPCopying, CPEnumerator.
+ * TODO: Needs to implement CPCoding, CPCopying.
*/
@import "CPObject.j"
@import "CPArray.j"
@import "CPNumber.j"
-//import "CPEnumerator.j"
+@import "CPEnumerator.j"
@implementation CPSet : CPObject
@@ -163,6 +163,7 @@
- (CPArray)allObjects
{
var array = [];
+
for (var property in _contents)
{
if (_contents.hasOwnProperty(property))
@@ -289,7 +290,10 @@
return nil;
}
-//- (CPEnumerator)objectEnumerator;
+- (CPEnumerator)objectEnumerator
+{
+ return [[self allObjects] objectEnumerator];
+}
// Mutable Set Methods
diff --git a/Tools/nib2cib/NSAppKit.j b/Tools/nib2cib/NSAppKit.j
index e10183182..c0d4dd8cf 100644
--- a/Tools/nib2cib/NSAppKit.j
+++ b/Tools/nib2cib/NSAppKit.j
@@ -55,6 +55,7 @@ function CP_NSMapClassName(aClassName)
{
case @"NSApplication": return @"CPApplication";
case @"NSObject": return @"CPObject";
+ case @"NSPanel": return @"CPPanel";
case @"NSView": return @"CPView";
case @"NSWindow": return @"CPWindow";
diff --git a/Tools/nib2cib/NSWindowTemplate.j b/Tools/nib2cib/NSWindowTemplate.j
index 3f96196e0..b2a27ad62 100644
--- a/Tools/nib2cib/NSWindowTemplate.j
+++ b/Tools/nib2cib/NSWindowTemplate.j
@@ -23,6 +23,15 @@
@import
+var NSBorderlessWindowMask = 0x00,
+ NSTitledWindowMask = 0x01,
+ NSClosableWindowMask = 0x02,
+ NSMiniaturizableWindowMask = 0x04,
+ NSResizableWindowMask = 0x08,
+ NSUtilityWindowMask = 0x10,
+ NSTexturedBackgroundWindowMask = 0x100,
+ NSHUDBackgroundWindowMask = 0x2000;
+
@implementation _CPCibWindowTemplate (NSCoding)
- (id)NS_initWithCoder:(CPCoder)aCoder
@@ -52,18 +61,15 @@
// Flip Y coordinate
_windowRect.origin.y = _screenRect.size.height - _windowRect.origin.y - _windowRect.size.height;
- // Only window style so far is CPHUDBackgroundWindowMask
- _windowStyleMask |= CPHUDBackgroundWindowMask;
-
- // Adjust size for HUD window - FIXME: in CPWindow.j
- if (_windowStyleMask & CPHUDBackgroundWindowMask)
- {
- CPLog.warn("Adjusting window rect.");
- _windowRect.origin.x -= 7.0;
- _windowRect.origin.y -= 30.0;
- _windowRect.size.width += 14.0;
- _windowRect.size.height += 40.0;
- }
+ if (_windowStyleMask === NSBorderlessWindowMask)
+ _windowStyleMask = CPBorderlessWindowMask;
+
+ else
+ _windowStyleMask = (_windowStyleMask & NSTitledWindowMask ? CPTitledWindowMask : 0) |
+ (_windowStyleMask & NSMiniaturizableWindowMask ? CPMiniaturizableWindowMask : 0) |
+ (_windowStyleMask & NSResizableWindowMask ? CPResizableWindowMask : 0) |
+ (_windowStyleMask & NSTexturedBackgroundWindowMask ? NSTexturedBackgroundWindowMask : 0) |
+ (_windowStyleMask & NSHUDBackgroundWindowMask ? CPHUDBackgroundWindowMask : 0);
/*if (![_windowClass isEqualToString:@"NSPanel"])
_windowRect.origin.y -= [NSMainMenuView menuHeight]; // compensation for the additional menu bar