Files
cappuccino/Tests/Manual/CPComboBoxTest/AppController.j
T
Aparajita Fishman 2be149c486 Finished theming CPComboBox and reworked related themes...
- Using more logical scheme for widget layout. bezel-inset is inset from frame to the bezel image. border-inset is the inset from the frame to the visible border (if any), which usually is the width of a focus ring. content-inset is the inset from the border rect to the content frame, including the width of the border. This scheme makes it much easier to visualize what is happening, and also makes it possible to ensure a consistent margin between the content and the surrounding bezel border. It also allowed me to remove the funky +1 pixel hack in [CPTextField becomeFirstResponder].

- CPTextField (square and rounded) and CPTokenField had their theme insets reworked to fit the new scheme.

- Added missing disabled bezel for rounded textfield.

- All textfield focus rings look much nicer now (more like Cocoa). Previously the actual border of a textfield would shrink when focused, now it stays the same.

- In CPTokenField, wrapped all references to _inputElement in #if PLATFORM(DOM).

- Placeholder state was not being set correctly because a recent change to [CPTextField _updatePlaceholderState] uses the cached _stringValue instead of [self stringValue]. CPTokenField has its own override now that checks the token count.
2011-08-21 01:40:10 -04:00

230 lines
9.4 KiB
Plaintext

/*
* AppController.j
* CPComboBoxTest
*
* Created by Aparajita Fishman.
* Copyright (c) 2011, Intalio, 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 <AppKit/CPComboBox.j>
@implementation Companies : CPObject
{
CPMutableArray items @accessors;
}
- (id)init
{
self = [super init];
if (self)
{
items = [CPMutableArray array];
var employees = "Tom,Dick,Harry,Ted,Sam,Fred,Ralph,Ed,Tim,John,Bill,Irving,Stan,Rodney".split(",");
employees = [CPArray arrayWithObjects:employees count:employees.length];
[items addObject:[CPDictionary dictionaryWithObjectsAndKeys:@"Spacely Sprockets", @"name", employees, @"employees"]];
employees = "Jane,Sally,Joan,Sara,Melissa,Beverly,Gillian,Sandra,Samantha,Mary,Kate".split(",");
employees = [CPArray arrayWithObjects:employees count:employees.length];
[items addObject:[CPDictionary dictionaryWithObjectsAndKeys:@"Cogswell Cogs", @"name", employees, @"employees"]];
}
return self;
}
@end
@implementation AppController : CPObject
{
@outlet CPWindow theWindow;
CPString employee @accessors;
Companies companies @accessors;
CPArrayController companiesController;
CPArrayController employeesController;
CPComboBox combo;
@outlet CPComboBox cibCombo;
CPString fontName;
int nextCheckboxY;
}
- (id)init
{
if (self = [super init])
{
fontName = [CPFont systemFontFace];
companies = [Companies new];
}
return self;
}
- (void)awakeFromCib
{
}
- (void)applicationDidFinishLaunching:(CPNotification)aNotification
{
theWindow = [[CPWindow alloc] initWithContentRect:CGRectMake(30, 50, 500, 400) styleMask:CPTitledWindowMask | CPResizableWindowMask];
var contentView = [theWindow contentView],
companiesScrollView = [[CPScrollView alloc] initWithFrame:CGRectMake(30, 30, 200, 100)],
companiesTable = [[CPTableView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)],
employeesScrollView = [[CPScrollView alloc] initWithFrame:CGRectMake(250, 30, 200, 200)],
employeesTable = [[CPTableView alloc] initWithFrame:CGRectMake(0, 0, 200, 200)];
[theWindow setTitle:@"CPComboBox (from code)"];
var column = [[CPTableColumn alloc] initWithIdentifier:@"name"];
[column setResizingMask:CPTableColumnAutoresizingMask];
[companiesTable addTableColumn:column];
[companiesTable setAllowsMultipleSelection:YES];
[companiesTable setColumnAutoresizingStyle:CPTableViewLastColumnOnlyAutoresizingStyle];
[companiesScrollView setHasHorizontalScroller:NO];
[companiesScrollView setHasVerticalScroller:YES];
[companiesScrollView setDocumentView:companiesTable];
[companiesScrollView setBorderType:CPBezelBorder];
[companiesTable setHeaderView:nil];
[companiesTable setAllowsEmptySelection:NO];
[contentView addSubview:companiesScrollView];
column = [[CPTableColumn alloc] initWithIdentifier:@"name"];
[column setResizingMask:CPTableColumnAutoresizingMask];
[employeesTable addTableColumn:column];
[employeesTable setAllowsMultipleSelection:YES];
[employeesTable setColumnAutoresizingStyle:CPTableViewLastColumnOnlyAutoresizingStyle];
[employeesScrollView setHasHorizontalScroller:NO];
[employeesScrollView setHasVerticalScroller:YES];
[employeesScrollView setDocumentView:employeesTable];
[employeesScrollView setBorderType:CPBezelBorder];
[employeesTable setHeaderView:nil];
[employeesTable setAllowsEmptySelection:YES];
[contentView addSubview:employeesScrollView];
combo = [[CPComboBox alloc] initWithFrame:CGRectMake(250, 240, 200, 29)];
[combo setCompletes:YES];
[contentView addSubview:combo];
var textfield = [CPTextField textFieldWithStringValue:@"" placeholder:@"" width:200];
[textfield setFrameOrigin:CGPointMake(250, 290)];
[contentView addSubview:textfield];
var center = [CPNotificationCenter defaultCenter];
[center addObserver:self selector:@selector(comboNote:) name:CPComboBoxSelectionDidChangeNotification object:combo];
[center addObserver:self selector:@selector(comboNote:) name:CPComboBoxSelectionIsChangingNotification object:combo];
[center addObserver:self selector:@selector(comboNote:) name:CPComboBoxWillDismissNotification object:combo];
[center addObserver:self selector:@selector(comboNote:) name:CPComboBoxWillPopUpNotification object:combo];
nextCheckboxY = 166;
[self makeCheckBoxWithTitle:@"Enabled" defaultState:CPOnState];
[self makeCheckBoxWithTitle:@"Button bordered" defaultState:CPOnState];
[self makeCheckBoxWithTitle:@"Bold" defaultState:CPOffState];
[self makeCheckBoxWithTitle:@"Completes" defaultState:CPOnState];
[self makeCheckBoxWithTitle:@"Force selection" defaultState:CPOffState];
[self makeCheckBoxWithTitle:@"Vertical scroller" defaultState:CPOnState];
[self makeCheckBoxWithTitle:@"Big item height" defaultState:CPOffState];
[self makeCheckBoxWithTitle:@"More visible items" defaultState:CPOffState];
companiesController = [CPArrayController new];
[companiesController bind:@"contentArray" toObject:companies withKeyPath:@"items" options:nil];
employeesController = [CPArrayController new];
[employeesController bind:@"contentArray" toObject:companiesController withKeyPath:@"selection.employees" options:nil];
var employeeController = [CPObjectController new];
[employeeController bind:@"content" toObject:employeesController withKeyPath:@"selection.self" options:nil];
[[companiesTable tableColumnWithIdentifier:@"name"] bind:@"value" toObject:companiesController withKeyPath:@"arrangedObjects.name" options:nil];
[[employeesTable tableColumnWithIdentifier:@"name"] bind:@"value" toObject:employeesController withKeyPath:@"arrangedObjects" options:nil];
[combo bind:@"contentValues" toObject:employeesController withKeyPath:@"arrangedObjects" options:nil];
[combo bind:@"value" toObject:employeeController withKeyPath:@"content" options:nil];
[companiesController addObserver:self forKeyPath:@"selection" options:0 context:@"companies.selection"];
[companiesController addObserver:self forKeyPath:@"selectionIndexes" options:0 context:@"companies.selectionIndexes"];
[companiesController addObserver:self forKeyPath:@"arrangedObjects" options:0 context:@"companies.arrangedObjects"];
[employeesController addObserver:self forKeyPath:@"selectionIndexes" options:0 context:@"employees.selectionIndexes"];
[employeesController addObserver:self forKeyPath:@"selection" options:0 context:@"employees.selection"];
[employeesController addObserver:self forKeyPath:@"arrangedObjects" options:0 context:@"employees.arrangedObjects"];
[combo addObserver:self forKeyPath:@"value" options:0 context:@"combo.value"];
[theWindow setInitialFirstResponder:companiesTable];
[theWindow orderFront:self];
}
- (void)makeCheckBoxWithTitle:(CPString)aTitle defaultState:(BOOL)aState
{
var checkbox = [CPCheckBox checkBoxWithTitle:aTitle];
[checkbox setFrameOrigin:CGPointMake(55, nextCheckboxY)];
[checkbox setState:aState];
[checkbox setTarget:self];
[checkbox setAction:@selector(setComboState:)];
[[theWindow contentView] addSubview:checkbox];
nextCheckboxY += 25;
}
- (void)observeValueForKeyPath:(CPString)keyPath ofObject:(id)object change:(CPDictionary)change context:(id)context
{
console.log("\nkeyPath: %s\ncontext: %s\nnew: %s\nold: %s", keyPath, context, [[change valueForKey:CPKeyValueChangeNewKey] description], [[change valueForKey:CPKeyValueChangeOldKey] description]);
}
- (void)setComboState:(id)sender
{
var title = [sender title],
state = [sender state] === CPOnState;
if (title === @"Enabled")
[combo setEnabled:state];
else if (title === @"Button bordered")
[combo setButtonBordered:state];
else if (title === @"Bold")
{
var font = [sender state] === CPOnState ? [CPFont boldFontWithName:fontName size:12] : [CPFont fontWithName:fontName size:12];
[combo setFont:font];
}
else if (title === @"Completes")
[combo setCompletes:state];
else if (title === @"Force selection")
[combo setForceSelection:state];
else if (title === @"Vertical scroller")
[combo setHasVerticalScroller:state];
else if (title === @"Big item height")
[combo setItemHeight:state ? 47 : 23];
else if (title === @"More visible items")
[combo setNumberOfVisibleItems:state ? 10 : 5];
}
- (void)comboNote:(CPNotification)aNote
{
console.log([aNote name]);
var object = [aNote object];
if ([aNote name] === CPComboBoxWillDismissNotification)
console.log("Selected: %d - %s", [object indexOfSelectedItem], [object objectValueOfSelectedItem]);
}
@end