/Polish/POText.j

http://github.com/polymar/polish · Unknown · 99 lines · 85 code · 14 blank · 0 comment · 0 complexity · 76ccf9b686d4cf5dceef8b1e63b0a876 MD5 · raw file

  1. /*
  2. * POText.j
  3. *
  4. * Created by Roberto Gamboni on 02/17/2009.
  5. * Copyright 2008 Roberto Gamboni. All rights reserved.
  6. */
  7. @import <AppKit/CPTextField.j>
  8. @import "CPViewAdditions.j"
  9. @implementation POText : CPTextField {
  10. CPString _name;
  11. var _begin_function;
  12. var _change_function;
  13. var _done_function;
  14. }
  15. /*
  16. * Init an editable text field with hmargin and vmargin = 0;
  17. */
  18. - (id) text {
  19. self = [super init];
  20. if(self) {
  21. [self createJSMethods: ['value:', 'name:']];
  22. [self setFont:[CPFont systemFontOfSize:14]];
  23. [self setBezelStyle:CPTextFieldSquareBezel];
  24. [self setBezeled:YES];
  25. [self setEditable:YES];
  26. [[CPNotificationCenter defaultCenter] addObserver: self selector: @selector(begin_action:) name: "CPControlTextDidBeginEditingNotification" object: nil];
  27. [[CPNotificationCenter defaultCenter] addObserver: self selector: @selector(change_action:) name: "CPControlTextDidChangeNotification" object: nil];
  28. [[CPNotificationCenter defaultCenter] addObserver: self selector: @selector(done_action:) name: "CPControlTextDidEndEditingNotification" object: nil];
  29. }
  30. return self;
  31. }
  32. /*
  33. * Init a label with hmargin and vmargin = 0
  34. */
  35. - (id) label {
  36. self = [super init];
  37. if(self) {
  38. [self createJSMethods: ['para:', 'name:']];
  39. [self setFont:[CPFont systemFontOfSize:14]];
  40. [self setTextColor:[CPColor whiteColor]];
  41. [self sizeToFit];
  42. [self setFrame:CGRectMake(0.0, 0.0, CGRectGetWidth([self bounds]), CGRectGetHeight([self bounds]))];
  43. }
  44. return self;
  45. }
  46. - (void) on_begin:(Function)aFunction {
  47. _begin_function = aFunction;
  48. }
  49. - (void) on_change:(Function)aFunction {
  50. _change_function = aFunction;
  51. }
  52. - (void) on_done:(Function)aFunction {
  53. _done_function = aFunction;
  54. }
  55. - (void) begin_action:(CPNotification) notification {
  56. if(_begin_function != nil)
  57. _begin_function.call();
  58. }
  59. - (void) change_action:(CPNotification) notification {
  60. if(_change_function != nil)
  61. _change_function.call();
  62. }
  63. - (void) done_action:(CPNotification) notification {
  64. if(_done_function != nil)
  65. _done_function.call();
  66. }
  67. - (CPString) name:(CPString) n {
  68. if(n != undefined)
  69. _name = n;
  70. else
  71. return _name;
  72. }
  73. - (void) value:(CPString) v {
  74. if(v != undefined)
  75. [self setStringValue:v];
  76. else
  77. return [self stringValue];
  78. }
  79. - (void) para:(CPString) v {
  80. if(v != undefined)
  81. [self setStringValue:v];
  82. else
  83. return [self stringValue];
  84. }
  85. @end