saikat (owner)

Revisions

gist: 228624 Download_button fork
public
Public Clone URL: git://gist.github.com/228624.git
Embed All Files: show embed
CPTextField Bug Example #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
/*
 * AppController.j
 * CPTextFieldBug
 *
 * Created by You on November 7, 2009.
 * Copyright 2009, Your Company All rights reserved.
 */
 
@import <Foundation/CPObject.j>
 
@implementation TestWindow : CPWindow { }
- (void)keyDown:(CPEvent)anEvent
{
  console.log([anEvent keyCode]);
  [super keyDown:anEvent];
}
@end
 
@implementation AppController : CPObject
{
  CPTextField label;
}
 
- (void)applicationDidFinishLaunching:(CPNotification)aNotification
{
    var theWindow = [[TestWindow alloc] initWithContentRect:CGRectMakeZero() styleMask:CPBorderlessBridgeWindowMask],
        contentView = [theWindow contentView];
 
    label = [[CPTextField alloc] initWithFrame:CGRectMakeZero()];
 
    [label setStringValue:@"Hello World!"];
    [label setFont:[CPFont boldSystemFontOfSize:24.0]];
 
    [label sizeToFit];
    [label setEditable:YES];
    [label setBackgroundColor:[CPColor yellowColor]];
    [label setTarget:self];
    [label setAction:@selector(didPressReturn:)];
 
    [label setAutoresizingMask:CPViewMinXMargin | CPViewMaxXMargin | CPViewMinYMargin | CPViewMaxYMargin];
    [label setCenter:[contentView center]];
 
    [contentView addSubview:label];
 
    [theWindow orderFront:self];
 
    // Uncomment the following line to turn on the standard menu bar.
    //[CPMenu setMenuBarVisible:YES];
}
 
- (void)didPressReturn:(CPTextField)aTextField
{
  console.log("Return hit!");
  [[label window] makeFirstResponder:nil];
  [label sizeToFit];
  [label setBackgroundColor:[CPColor redColor]];
}
 
@end