PageRenderTime 19ms CodeModel.GetById 11ms app.highlight 3ms RepoModel.GetById 1ms app.codeStats 0ms

/Tests/Manual/CPScrollView/AppController.j

http://github.com/cacaodev/cappuccino
Unknown | 108 lines | 82 code | 26 blank | 0 comment | 0 complexity | f669bef698e4c56c72bc92def3464ff6 MD5 | raw file
  1/*
  2 * AppController.j
  3 * Scrolling
  4 *
  5 * Created by You on August 27, 2010.
  6 * Copyright 2010, Your Company All rights reserved.
  7 */
  8
  9@import <Foundation/CPObject.j>
 10@import <AppKit/CPScrollView.j>
 11
 12
 13@implementation AppController : CPObject
 14{
 15    int scrollViewXCount;
 16    int scrollViewYCount;
 17}
 18
 19- (void)applicationDidFinishLaunching:(CPNotification)aNotification
 20{
 21    var theWindow = [[CPWindow alloc] initWithContentRect:CGRectMakeZero() styleMask:CPBorderlessBridgeWindowMask];
 22    [theWindow orderFront:self];
 23
 24    scrollViewXCount = 0;
 25    scrollViewYCount = 0;
 26
 27    // Vanilla scrollview
 28    var imageView = [[CPImageView alloc] initWithFrame:CGRectMake(0,0,900,675)];
 29    [imageView setImage:[[CPImage alloc] initWithContentsOfFile:[[CPBundle mainBundle] pathForResource:@"photo.jpg"]]];
 30
 31    var scrollView = [self makeScrollview];
 32    [scrollView setDocumentView:imageView];
 33    [scrollView setDelegate:self];
 34    [[theWindow contentView] addSubview:scrollView];
 35
 36    // Scrollview with a CPTextField in it
 37    var textField = [CPTextField textFieldWithStringValue:@"Try to select this" placeholder:@"" width:120];
 38
 39    [textField setFrameOrigin:CGPointMake(20,20)];
 40    [textField setSelectable:YES];
 41
 42    var scrollView = [self makeScrollview];
 43
 44    [[scrollView documentView] addSubview:textField];
 45    [[theWindow contentView] addSubview:scrollView];
 46
 47    // In another window
 48    var aWindow = [[CPWindow alloc] initWithContentRect:CGRectMake(120,400,400,300) styleMask:CPTitledWindowMask];
 49    [aWindow setTitle:@"Scrollview in a ScrollView in a Window."]
 50    [aWindow orderFront:nil];
 51
 52    // Scrollview with another scrollview in it
 53    var imageView = [[CPImageView alloc] initWithFrame:CGRectMake(0,0,900,675)];
 54    [imageView setImage:[[CPImage alloc] initWithContentsOfFile:[[CPBundle mainBundle] pathForResource:@"photo.jpg"]]];
 55
 56    var innerScrollView = [[CPScrollView alloc] initWithFrame:CGRectMake(20, 20, 150, 150)];
 57    [innerScrollView setDocumentView:imageView];
 58
 59    var scrollView = [self makeScrollview];
 60    [scrollView setFrameOrigin:CGPointMake(20,20)]
 61
 62    [[scrollView documentView] setBackgroundColor:[CPColor checkerBoardColor]];
 63    [[scrollView documentView] addSubview:innerScrollView];
 64    [[aWindow contentView] addSubview:scrollView];
 65
 66    var button = [CPButton buttonWithTitle:@"Change Scroller Mode"];
 67    [button setFrameOrigin:CGPointMake(10.0, 10.0)];
 68    [button setTarget:self];
 69    [button setAction:@selector(changeScrollerMode:)];
 70
 71    [[theWindow contentView] addSubview:button];
 72}
 73
 74- (void)scrollViewWillScroll:(CPScrollView)aScrollView
 75{
 76    CPLogConsole(_cmd+aScrollView);
 77}
 78
 79- (void)scrollViewDidScroll:(CPScrollView)aScrollView
 80{
 81    CPLogConsole(_cmd+aScrollView);
 82}
 83
 84- (void)makeScrollview
 85{
 86    var scrollView = [[CPScrollView alloc] initWithFrame:CGRectMake((scrollViewXCount * 320) + 120, (scrollViewYCount * 220) + 100, 300, 200)];
 87    [scrollView setDocumentView:[[CPView alloc] initWithFrame:CGRectMake(0,0,1000,1000)]];
 88
 89    scrollViewXCount += 1;
 90
 91    if (scrollViewXCount === 3)
 92    {
 93        scrollViewXCount = 0;
 94        scrollViewYCount += 1;
 95    }
 96
 97    return scrollView;
 98}
 99
100- (IBAction)changeScrollerMode:(id)aSender
101{
102    if ([CPScrollView globalScrollerStyle] == CPScrollerStyleOverlay)
103        [CPScrollView setGlobalScrollerStyle:CPScrollerStyleLegacy];
104    else
105        [CPScrollView setGlobalScrollerStyle:CPScrollerStyleOverlay];
106}
107
108@end