/Tools/nib2cib/NSBox.j

http://github.com/cacaodev/cappuccino · Unknown · 98 lines · 78 code · 20 blank · 0 comment · 0 complexity · ed92d1b7905d672be5a0e4bdc7ca9252 MD5 · raw file

  1. /*
  2. * NSBox.j
  3. * nib2cib
  4. *
  5. * Created by Aparajita Fishman.
  6. *
  7. * This library is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU Lesser General Public
  9. * License as published by the Free Software Foundation; either
  10. * version 2.1 of the License, or (at your option) any later version.
  11. *
  12. * This library is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * Lesser General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Lesser General Public
  18. * License along with this library; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  20. */
  21. @import <AppKit/CPBox.j>
  22. @implementation CPBox (NSCoding)
  23. - (id)NS_initWithCoder:(CPCoder)aCoder
  24. {
  25. self = [super NS_initWithCoder:aCoder];
  26. if (self)
  27. {
  28. _boxType = [aCoder decodeIntForKey:@"NSBoxType"];
  29. _borderType = [aCoder decodeIntForKey:@"NSBorderType"];
  30. var borderColor = [aCoder decodeObjectForKey:@"NSBorderColor2"],
  31. fillColor = [aCoder decodeObjectForKey:@"NSFillColor2"],
  32. cornerRadius = [aCoder decodeFloatForKey:@"NSCornerRadius2"],
  33. borderWidth = [aCoder decodeFloatForKey:@"NSBorderWidth2"],
  34. contentMargin = [aCoder decodeSizeForKey:@"NSOffsets"];
  35. // small hack to position the box pixel perfect
  36. var frame = [self frame];
  37. // The primary and secondary boxes have a well-like look both in Cocoa and Cappuccino, but there
  38. // are some sizing differences. Regular custom boxes have no size differences.
  39. if (_boxType !== CPBoxSeparator && (_boxType === CPBoxPrimary || _boxType === CPBoxSecondary))
  40. {
  41. frame.origin.y += 4;
  42. frame.origin.x += 4;
  43. frame.size.width -= 8;
  44. frame.size.height -= 6;
  45. }
  46. [self setFrame:frame];
  47. if (_boxType !== CPBoxPrimary && _boxType !== CPBoxSecondary)
  48. {
  49. // Primary and secondary boxes have a fixed look that can't be customised, but for a CPBoxCustom
  50. // all of these parameters can be changed.
  51. if (borderColor)
  52. [self setBorderColor:borderColor];
  53. if (fillColor)
  54. [self setFillColor:fillColor];
  55. [self setCornerRadius:cornerRadius];
  56. [self setBorderWidth:borderWidth];
  57. [self setContentViewMargins:contentMargin];
  58. }
  59. _title = [[aCoder decodeObjectForKey:@"NSTitleCell"] objectValue] || @"";
  60. _titlePosition = [aCoder decodeObjectForKey:@"NSTitlePosition"];
  61. if (_titlePosition === undefined)
  62. _titlePosition = CPAtTop;
  63. }
  64. return self;
  65. }
  66. @end
  67. @implementation NSBox : CPBox
  68. {
  69. }
  70. - (id)initWithCoder:(CPCoder)aCoder
  71. {
  72. return [self NS_initWithCoder:aCoder];
  73. }
  74. - (Class)classForKeyedArchiver
  75. {
  76. return [CPBox class];
  77. }
  78. @end