Created
October 9, 2009 02:47
-
-
Save boucher/205661 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| * AppController.j | |
| * scrollview | |
| * | |
| * Created by You on August 17, 2009. | |
| * Copyright 2009, Your Company All rights reserved. | |
| */ | |
| @import <Foundation/CPObject.j> | |
| @import "CustomTextField.j" | |
| @implementation AppController : CPObject | |
| { | |
| CPWindow theWindow; | |
| CPView contentView; | |
| CPNumber itemIndex; | |
| CPCollectionView collectionView; | |
| } | |
| - (void)applicationDidFinishLaunching:(CPNotification)aNotification | |
| { | |
| theWindow = [[CPWindow alloc] initWithContentRect:CGRectMakeZero() styleMask:CPBorderlessBridgeWindowMask]; | |
| contentView = [theWindow contentView]; | |
| [theWindow orderFront:self]; | |
| itemIndex = 2; | |
| [self initScrollView]; | |
| // Uncomment the following line to turn on the standard menu bar. | |
| //[CPMenu setMenuBarVisible:YES]; | |
| } | |
| - (void) initScrollView | |
| { | |
| // Add Fixed Collection View. | |
| var view = [[CPScrollView alloc] initWithFrame:CGRectMake(0, 0, 200, CGRectGetHeight([contentView bounds]))]; | |
| [view setBackgroundColor: [CPColor darkGrayColor]]; | |
| [view setAutoresizingMask: CPViewHeightSizable]; | |
| [view setAutohidesScrollers: YES]; | |
| [view setHasHorizontalScroller: NO]; | |
| var button = [[CPButton alloc] initWithFrame:CGRectMake(40, 10, 120, 24)]; | |
| [button setTitle: "Add Item"]; | |
| [view addSubview: button]; | |
| [button setTarget: self]; | |
| [button setAction: @selector(addItem:)]; | |
| // Create the CollectionViewItem. | |
| var collectionViewItem = [[CPCollectionViewItem alloc] init]; | |
| [collectionViewItem setView:[[CollectionViewItem alloc] initWithFrame:CGRectMakeZero()]]; | |
| // Create the CollectionView | |
| collectionView = [[CPCollectionView alloc] initWithFrame:CGRectMake(5, 44, 190, CGRectGetHeight([view bounds]))]; | |
| [collectionView setItemPrototype: collectionViewItem]; | |
| [collectionView setBackgroundColor: [CPColor darkGrayColor]]; | |
| [collectionView setAutoresizingMask: CPViewHeightSizable]; | |
| [collectionView setMinItemSize:CGSizeMake(190, 60.0)]; | |
| [collectionView setMaxItemSize:CGSizeMake(190, 60.0)]; | |
| [collectionView setVerticalMargin: 2]; | |
| [view addSubview: collectionView]; | |
| [view setDocumentView: collectionView]; | |
| [contentView addSubview: view]; | |
| // | |
| [collectionView setContent: [{'name': "Untitled"}, {'name': "Untitled " + (itemIndex++)}, {'name': "Untitled " + (itemIndex++)}]]; | |
| } | |
| - (void) addItem: (id)sender | |
| { | |
| [collectionView setContent: [[collectionView content] arrayByAddingObject: {'name': "Untitled " + (itemIndex++)}]]; | |
| } | |
| @end | |
| @implementation CollectionViewItem: CPView | |
| { | |
| // CPTextField textField; | |
| CustomTextField textField; | |
| CPObject representedObject; | |
| } | |
| - (void) mouseDown: (CPEvent) anEvent | |
| { | |
| if([anEvent clickCount] > 1){ | |
| [textField startEditing]; | |
| } | |
| } | |
| - (void) setRepresentedObject: (JSObject)anObject | |
| { | |
| if(representedObject == anObject){ | |
| return; | |
| } | |
| representedObject = anObject; | |
| textField = [[CustomTextField alloc] initWithFrame:CGRectMakeZero()]; | |
| [textField setFont:[CPFont systemFontOfSize: 12.0]]; | |
| [textField setTextColor:[CPColor whiteColor]]; | |
| [textField setFrameSize:CGSizeMake(160.0, 30.0)]; | |
| [textField setFrameOrigin: CGPointMake(10, 15)]; | |
| [textField setStringValue: representedObject.name]; | |
| [textField setDrawsBackground: YES]; | |
| [textField setBackgroundColor: [CPColor colorWithHexString: @"333333"]]; | |
| [textField setBezeled: NO]; | |
| [textField setEditable: NO]; | |
| [self setBackgroundColor: [CPColor whiteColor]]; | |
| [self addSubview: textField]; | |
| } | |
| - (void) setSelected: (BOOL) setSelected | |
| { | |
| // [textField setEditable: YES]; | |
| } | |
| @end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @implementation CustomTextField : CPTextField | |
| { | |
| } | |
| - (void)startEditing | |
| { | |
| [self setEditable:YES]; | |
| [[self window] makeFirstResponder:self]; | |
| } | |
| - (BOOL)becomeFirstResponder | |
| { | |
| [self setTextColor:[CPColor blackColor]]; | |
| [self setBackgroundColor:[CPColor whiteColor]]; | |
| [self setBezeled:YES]; | |
| if (![super becomeFirstResponder]) | |
| return NO; | |
| return YES; | |
| } | |
| - (BOOL)resignFirstResponder | |
| { | |
| [self setBackgroundColor:[CPColor blackColor]]; | |
| [self setTextColor:[CPColor whiteColor]]; | |
| [self setBezeled:NO]; | |
| if (![super resignFirstResponder]) | |
| return NO; | |
| [self setEditable:NO]; | |
| return YES; | |
| } | |
| @end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment