/Tools/nib2cib/NSPopUpButton.j

http://github.com/cacaodev/cappuccino · Unknown · 103 lines · 81 code · 22 blank · 0 comment · 0 complexity · eef6f579c41604c4207cbe39190e7c63 MD5 · raw file

  1. /*
  2. * NSPopUpButton.j
  3. * nib2cib
  4. *
  5. * Created by Thomas Robinson.
  6. * Copyright 2008, 280 North, Inc.
  7. *
  8. * This library is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU Lesser General Public
  10. * License as published by the Free Software Foundation; either
  11. * version 2.1 of the License, or (at your option) any later version.
  12. *
  13. * This library is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16. * Lesser General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU Lesser General Public
  19. * License along with this library; if not, write to the Free Software
  20. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  21. */
  22. @import <AppKit/CPPopUpButton.j>
  23. @import "NSMenu.j"
  24. @import "NSMenuItem.j"
  25. @implementation CPPopUpButton (CPCoding)
  26. - (id)NS_initWithCoder:(CPCoder)aCoder
  27. {
  28. return [super NS_initWithCoder:aCoder];
  29. }
  30. - (void)NS_initWithCell:(NSCell)cell
  31. {
  32. [super NS_initWithCell:cell];
  33. _menu = [cell menu];
  34. [self setPullsDown:[cell pullsDown]];
  35. _preferredEdge = [cell preferredEdge];
  36. }
  37. @end
  38. @implementation NSPopUpButton : CPPopUpButton
  39. {
  40. }
  41. - (id)initWithCoder:(CPCoder)aCoder
  42. {
  43. self = [self NS_initWithCoder:aCoder];
  44. if (self)
  45. {
  46. var cell = [aCoder decodeObjectForKey:@"NSCell"];
  47. [self NS_initWithCell:cell];
  48. [self _adjustNib2CibSize];
  49. }
  50. return self;
  51. }
  52. - (Class)classForKeyedArchiver
  53. {
  54. return [CPPopUpButton class];
  55. }
  56. @end
  57. @implementation NSPopUpButtonCell : NSMenuItemCell
  58. {
  59. BOOL pullsDown @accessors(readonly);
  60. int selectedIndex @accessors(readonly);
  61. int preferredEdge @accessors(readonly);
  62. CPMenu menu @accessors(readonly);
  63. }
  64. - (id)initWithCoder:(CPCoder)aCoder
  65. {
  66. self = [super initWithCoder:aCoder];
  67. if (self)
  68. {
  69. pullsDown = [aCoder decodeBoolForKey:@"NSPullDown"];
  70. selectedIndex = [aCoder decodeIntForKey:@"NSSelectedIndex"];
  71. preferredEdge = [aCoder decodeIntForKey:@"NSPreferredEdge"];
  72. menu = [aCoder decodeObjectForKey:@"NSMenu"];
  73. }
  74. return self;
  75. }
  76. // - [NSPopUpButton objectValue] is overridden to return the selected index.
  77. - (CPUInteger)objectValue
  78. {
  79. return selectedIndex;
  80. }
  81. @end