/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. @import <Foundation/CPObject.j>
  9. @import <AppKit/CPScrollView.j>
  10. @implementation AppController : CPObject
  11. {
  12. int scrollViewXCount;
  13. int scrollViewYCount;
  14. }
  15. - (void)applicationDidFinishLaunching:(CPNotification)aNotification
  16. {
  17. var theWindow = [[CPWindow alloc] initWithContentRect:CGRectMakeZero() styleMask:CPBorderlessBridgeWindowMask];
  18. [theWindow orderFront:self];
  19. scrollViewXCount = 0;
  20. scrollViewYCount = 0;
  21. // Vanilla scrollview
  22. var imageView = [[CPImageView alloc] initWithFrame:CGRectMake(0,0,900,675)];
  23. [imageView setImage:[[CPImage alloc] initWithContentsOfFile:[[CPBundle mainBundle] pathForResource:@"photo.jpg"]]];
  24. var scrollView = [self makeScrollview];
  25. [scrollView setDocumentView:imageView];
  26. [scrollView setDelegate:self];
  27. [[theWindow contentView] addSubview:scrollView];
  28. // Scrollview with a CPTextField in it
  29. var textField = [CPTextField textFieldWithStringValue:@"Try to select this" placeholder:@"" width:120];
  30. [textField setFrameOrigin:CGPointMake(20,20)];
  31. [textField setSelectable:YES];
  32. var scrollView = [self makeScrollview];
  33. [[scrollView documentView] addSubview:textField];
  34. [[theWindow contentView] addSubview:scrollView];
  35. // In another window
  36. var aWindow = [[CPWindow alloc] initWithContentRect:CGRectMake(120,400,400,300) styleMask:CPTitledWindowMask];
  37. [aWindow setTitle:@"Scrollview in a ScrollView in a Window."]
  38. [aWindow orderFront:nil];
  39. // Scrollview with another scrollview in it
  40. var imageView = [[CPImageView alloc] initWithFrame:CGRectMake(0,0,900,675)];
  41. [imageView setImage:[[CPImage alloc] initWithContentsOfFile:[[CPBundle mainBundle] pathForResource:@"photo.jpg"]]];
  42. var innerScrollView = [[CPScrollView alloc] initWithFrame:CGRectMake(20, 20, 150, 150)];
  43. [innerScrollView setDocumentView:imageView];
  44. var scrollView = [self makeScrollview];
  45. [scrollView setFrameOrigin:CGPointMake(20,20)]
  46. [[scrollView documentView] setBackgroundColor:[CPColor checkerBoardColor]];
  47. [[scrollView documentView] addSubview:innerScrollView];
  48. [[aWindow contentView] addSubview:scrollView];
  49. var button = [CPButton buttonWithTitle:@"Change Scroller Mode"];
  50. [button setFrameOrigin:CGPointMake(10.0, 10.0)];
  51. [button setTarget:self];
  52. [button setAction:@selector(changeScrollerMode:)];
  53. [[theWindow contentView] addSubview:button];
  54. }
  55. - (void)scrollViewWillScroll:(CPScrollView)aScrollView
  56. {
  57. CPLogConsole(_cmd+aScrollView);
  58. }
  59. - (void)scrollViewDidScroll:(CPScrollView)aScrollView
  60. {
  61. CPLogConsole(_cmd+aScrollView);
  62. }
  63. - (void)makeScrollview
  64. {
  65. var scrollView = [[CPScrollView alloc] initWithFrame:CGRectMake((scrollViewXCount * 320) + 120, (scrollViewYCount * 220) + 100, 300, 200)];
  66. [scrollView setDocumentView:[[CPView alloc] initWithFrame:CGRectMake(0,0,1000,1000)]];
  67. scrollViewXCount += 1;
  68. if (scrollViewXCount === 3)
  69. {
  70. scrollViewXCount = 0;
  71. scrollViewYCount += 1;
  72. }
  73. return scrollView;
  74. }
  75. - (IBAction)changeScrollerMode:(id)aSender
  76. {
  77. if ([CPScrollView globalScrollerStyle] == CPScrollerStyleOverlay)
  78. [CPScrollView setGlobalScrollerStyle:CPScrollerStyleLegacy];
  79. else
  80. [CPScrollView setGlobalScrollerStyle:CPScrollerStyleOverlay];
  81. }
  82. @end