PageRenderTime 5ms CodeModel.GetById 2ms app.highlight 1ms RepoModel.GetById 1ms app.codeStats 0ms

/Tests/Manual/CPTextField/AppController.j

http://github.com/cacaodev/cappuccino
Unknown | 167 lines | 123 code | 44 blank | 0 comment | 0 complexity | c71bcaadfdc5445ad63f340e2c43361f MD5 | raw file
  1/*
  2 * AppController.j
  3 * CPTextField
  4 *
  5 * Created by Alexander Ljungberg on August 2, 2010.
  6 * Copyright 2010, WireLoad, LLC All rights reserved.
  7 */
  8
  9@import <Foundation/CPObject.j>
 10
 11
 12@implementation AppController : CPObject
 13{
 14    CPWindow    aWindow;
 15    CPTextField bezelToggleField;
 16}
 17
 18- (void)applicationDidFinishLaunching:(CPNotification)aNotification
 19{
 20    var theWindow = [[CPWindow alloc] initWithContentRect:CGRectMakeZero() styleMask:CPBorderlessBridgeWindowMask],
 21        contentView = [theWindow contentView];
 22
 23    var textField = [CPTextField textFieldWithStringValue:"" placeholder:"Edit me!" width:200],
 24        label = [[CPTextField alloc] initWithFrame:CGRectMake(15, 15, 400, 24)];
 25
 26    [label setStringValue:"Edit and hit enter: editing should end."];
 27    [contentView addSubview:label];
 28
 29    [textField setFrameOrigin:CGPointMake(15, 35)];
 30
 31    [textField setEditable:YES];
 32    [textField setPlaceholderString:"Edit me!"];
 33
 34    [textField setTarget:self];
 35    [textField setAction:@selector(textAction:)];
 36
 37    [contentView addSubview:textField];
 38
 39    var shadowLabel = [CPTextField labelWithTitle:@"This text should have a shadow."],
 40        championOfLightLabel = [CPTextField labelWithTitle:@"This text should have no shadow."];
 41
 42    [shadowLabel setTextColor:[CPColor blackColor]];
 43    [shadowLabel setTextShadowOffset:CGSizeMake(0, 1)];
 44    [shadowLabel setTextShadowColor:[CPColor colorWithCSSString:@"rgba(0, 0, 0, 0.5)"]];
 45
 46    [championOfLightLabel setTextColor:[CPColor blackColor]];
 47    [championOfLightLabel setTextShadowOffset:CGSizeMake(0, 1)];
 48    [championOfLightLabel setTextShadowColor:[CPColor clearColor]];
 49
 50    [shadowLabel setFrame:CGRectMake(15, CGRectGetMaxY([textField frame]) + 10, 300, 18)];
 51    [championOfLightLabel setFrame:CGRectMake(15, CGRectGetMaxY([shadowLabel frame]) + 2, 300, 18)];
 52
 53    var selectableLabel = [CPTextField labelWithTitle:@"This text should be selectable and you should see the selectable cursor."];
 54    [selectableLabel setSelectable:YES];
 55    [selectableLabel setFrame:CGRectMake(15, CGRectGetMaxY([championOfLightLabel frame]) + 8, 600, 18)];
 56
 57    [contentView addSubview:shadowLabel];
 58    [contentView addSubview:championOfLightLabel];
 59    [contentView addSubview:selectableLabel];
 60
 61    var jumpLabel = [CPTextField labelWithTitle:@"The text of these text fields should not move ('jump') when a field becomes the first responder. Labels on the right should replicate the input."];
 62
 63    [jumpLabel sizeToFit];
 64    [jumpLabel setFrameOrigin:CGPointMake(15, 150)];
 65    [contentView addSubview:jumpLabel];
 66
 67    var y = CGRectGetMaxY([jumpLabel frame]) + 10;
 68
 69    for (var i = 0; i < 5; i++)
 70    {
 71        var size = 10 + 3 * i,
 72            textField = [CPTextField textFieldWithStringValue:@"Size " + size placeholder:@"Size " + size width:200],
 73            echoField = [CPTextField labelWithTitle:""];
 74
 75        [textField setFont:[CPFont systemFontOfSize:size]];
 76        [textField sizeToFit];
 77        [textField setFrameOrigin:CGPointMake(15, y)];
 78        textField.echoField = echoField;
 79        [contentView addSubview:textField];
 80
 81        [echoField setFont:[CPFont systemFontOfSize:size]];
 82        [echoField setStringValue:[textField stringValue]];
 83        [echoField sizeToFit];
 84        [echoField setFrameOrigin:CGPointMake(CGRectGetMaxX([textField frame]) + 15, CGRectGetMidY([textField frame]) - CGRectGetHeight([echoField frame]) / 2.0)];
 85        [contentView addSubview:echoField];
 86
 87        [[CPNotificationCenter defaultCenter] addObserver:self selector:@selector(textDidChange:) name:CPControlTextDidChangeNotification object:textField];
 88
 89        y = CGRectGetMaxY([textField frame]) + 6;
 90    }
 91
 92    label = [[CPTextField alloc] initWithFrame:CGRectMake(15, 420, 600, 60)];
 93    [label setLineBreakMode:CPLineBreakByWordWrapping];
 94    [label setStringValue:"This text field has been configured to show its text at a fixed location both with and without bezel.\nThis text should also display the word \"Placeholder\" when its value is empty."];
 95    [contentView addSubview:label];
 96
 97    bezelToggleField = [CPTextField textFieldWithStringValue:"" placeholder:"Placeholder" width:200],
 98
 99    [bezelToggleField setEditable:YES];
100    [bezelToggleField setFrameOrigin:CGPointMake(15, 475)];
101    console.log("" + bezelToggleField._themeAttributes['content-inset']._themeDefaultAttribute._values);
102    console.log("" + bezelToggleField._themeAttributes['content-inset']._values);
103    [bezelToggleField setValue:[bezelToggleField valueForThemeAttribute:@"content-inset" inState:CPThemeStateBezeled] forThemeAttribute:@"content-inset" inState:CPThemeStateNormal];
104    console.log("" + bezelToggleField._themeAttributes['content-inset']._themeDefaultAttribute._values);
105    console.log("" + bezelToggleField._themeAttributes['content-inset']._values);
106
107    [contentView addSubview:bezelToggleField];
108
109    var bezelToggleButton = [CPButton buttonWithTitle:"Show Bezel"];
110
111    [bezelToggleButton setButtonType:CPPushOnPushOffButton];
112    [bezelToggleButton setAction:@selector(toggleBezel:)];
113    [bezelToggleButton setTarget:self];
114    [bezelToggleButton setState:CPOnState];
115    [bezelToggleButton sizeToFit];
116    [bezelToggleButton setFrameOrigin:CGPointMake(CGRectGetMaxX([bezelToggleField frame]) + 15, 478)];
117    [contentView addSubview:bezelToggleButton];
118
119    [theWindow orderFront:self];
120
121    aWindow = [[CPWindow alloc] initWithContentRect:CGRectMake(150, 300, 400, 150) styleMask:CPTitledWindowMask | CPClosableWindowMask | CPDocModalWindowMask];
122    [aWindow setTitle:@"Text Field in a Window"]
123
124    contentView = [aWindow contentView];
125
126    textField = [CPTextField textFieldWithStringValue:"Select me!" placeholder:"" width:0];
127    label = [[CPTextField alloc] initWithFrame:CGRectMake(15, 15, 360, 30)];
128    [label setLineBreakMode:CPLineBreakByWordWrapping];
129
130    [label setStringValue:"Select the field and double click it to select text. The text should become selected. Then hit enter to continue."];
131    [contentView addSubview:label];
132
133    [textField setFrame:CGRectMake(15, CGRectGetMaxY([label frame]) + 10, 300, 30)];
134    [textField setEditable:YES];
135    [textField setTarget:self];
136    [textField setAction:@selector(modalAction:)];
137
138    [contentView addSubview:textField];
139
140    [CPApp beginSheet:aWindow modalForWindow:theWindow modalDelegate:self didEndSelector:nil contextInfo:nil];
141}
142
143- (@action)toggleBezel:(id)sender
144{
145    [bezelToggleField setBezeled:([sender state] == CPOnState)];
146}
147
148- (void)modalAction:(id)sender
149{
150    [CPApp endSheet:aWindow returnCode:0];
151    [aWindow orderOut:sender];
152}
153
154- (void)textAction:(id)sender
155{
156    [sender setEditable:NO];
157}
158
159- (void)textDidChange:(CPNotification)aNotification
160{
161    var changedField = [aNotification object];
162
163    [changedField.echoField setStringValue:[changedField stringValue]];
164    [changedField.echoField sizeToFit];
165}
166
167@end