/Tools/nib2cib/NSTableColumn.j

http://github.com/cacaodev/cappuccino · Unknown · 164 lines · 125 code · 39 blank · 0 comment · 0 complexity · 01dee0e796aa948a0a4f24e7cdef7535 MD5 · raw file

  1. /*
  2. * NSTableColumn.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/CPLevelIndicator.j>
  23. @import <AppKit/CPTableColumn.j>
  24. @import <AppKit/CPTableHeaderView.j>
  25. @import <AppKit/CPButton.j>
  26. @import "NSButton.j"
  27. @import "NSImageView.j"
  28. @import "NSLevelIndicator.j"
  29. @import "NSTextField.j"
  30. @class Converter
  31. @class Nib2Cib
  32. var IBDefaultFontSizeTableHeader = 11.0;
  33. @implementation CPTableColumn (NSCoding)
  34. - (id)NS_initWithCoder:(CPCoder)aCoder
  35. {
  36. self = [self init];
  37. if (self)
  38. {
  39. _identifier = [aCoder decodeObjectForKey:@"NSIdentifier"];
  40. var dataViewCell = [aCoder decodeObjectForKey:@"NSDataCell"],
  41. viewClass = nil;
  42. if ([dataViewCell isKindOfClass:[NSImageCell class]])
  43. viewClass = CPImageView;
  44. else if ([dataViewCell isKindOfClass:[NSTextFieldCell class]])
  45. viewClass = CPTextField;
  46. else if ([dataViewCell isKindOfClass:[NSButtonCell class]])
  47. viewClass = CPButton;
  48. else if ([dataViewCell isKindOfClass:[NSLevelIndicatorCell class]])
  49. viewClass = CPLevelIndicator;
  50. if (viewClass)
  51. _dataView = [self makeDataViewOfClass:viewClass withCell:dataViewCell];
  52. [_dataView setValue:[dataViewCell alignment] forThemeAttribute:@"alignment"];
  53. var headerCell = [aCoder decodeObjectForKey:@"NSHeaderCell"],
  54. headerView = [[_CPTableColumnHeaderView alloc] initWithFrame:CGRectMakeZero()],
  55. theme = [Nib2Cib defaultTheme];
  56. [headerView setStringValue:[headerCell objectValue]];
  57. [headerView setFont:[headerCell font]];
  58. [headerView setAlignment:[headerCell alignment]];
  59. if ([[headerCell font] familyName] === IBDefaultFontFace && [[headerCell font] size] == IBDefaultFontSizeTableHeader)
  60. {
  61. [headerView setTextColor:[theme valueForAttributeWithName:@"text-color" forClass:_CPTableColumnHeaderView]];
  62. [headerView setFont:[theme valueForAttributeWithName:@"font" forClass:_CPTableColumnHeaderView]];
  63. }
  64. [self setHeaderView:headerView];
  65. _width = [aCoder decodeFloatForKey:@"NSWidth"];
  66. _minWidth = [aCoder decodeFloatForKey:@"NSMinWidth"];
  67. _maxWidth = [aCoder decodeFloatForKey:@"NSMaxWidth"];
  68. _resizingMask = [aCoder decodeIntForKey:@"NSResizingMask"];
  69. _isHidden = [aCoder decodeBoolForKey:@"NSHidden"];
  70. _isEditable = [aCoder decodeBoolForKey:@"NSIsEditable"];
  71. _sortDescriptorPrototype = [aCoder decodeObjectForKey:@"NSSortDescriptorPrototype"];
  72. }
  73. return self;
  74. }
  75. - (id)makeDataViewOfClass:(Class)aClass withCell:(NSCell)aCell
  76. {
  77. var dataView = [[aClass alloc] initWithFrame:CGRectMakeZero()];
  78. // Set the theme state to make sure the data view's theme attributes are correct
  79. [dataView setThemeState:CPThemeStateTableDataView];
  80. [dataView NS_initWithCell:aCell];
  81. if (aClass === CPTextField)
  82. {
  83. // Text cells have to have their font replaced
  84. [[Converter sharedConverter] replaceFontForObject:dataView];
  85. // If a text cell has a custom color, we have to set the selected color,
  86. // otherwise it defaults to the custom color.
  87. var textColor = [aCell textColor],
  88. defaultColor = [self valueForDataViewThemeAttribute:@"text-color" inState:CPThemeStateNormal];
  89. if (![textColor isEqual:defaultColor])
  90. {
  91. var selectedColor = [self valueForDataViewThemeAttribute:@"text-color" inState:CPThemeState(CPThemeStateTableDataView, CPThemeStateSelectedDataView)];
  92. [dataView setValue:selectedColor forThemeAttribute:@"text-color" inState:CPThemeState(CPThemeStateTableDataView, CPThemeStateSelectedDataView)];
  93. [dataView setValue:textColor forThemeAttribute:@"text-color" inState:CPThemeState(CPThemeStateTableDataView, CPThemeStateSelectedDataView, CPThemeStateEditing)];
  94. }
  95. }
  96. return dataView;
  97. }
  98. - (id)valueForDataViewThemeAttribute:(CPString)attribute inState:(int)state
  99. {
  100. var themes = [[Nib2Cib sharedNib2Cib] themes];
  101. for (var i = 0; i < themes.length; ++i)
  102. {
  103. var value = [themes[i] valueForAttributeWithName:attribute inState:state forClass:CPTextField];
  104. if (value)
  105. return value;
  106. }
  107. return nil;
  108. }
  109. @end
  110. @implementation NSTableColumn : CPTableColumn
  111. {
  112. }
  113. - (id)initWithCoder:(CPCoder)aCoder
  114. {
  115. return [self NS_initWithCoder:aCoder];
  116. }
  117. - (Class)classForKeyedArchiver
  118. {
  119. return [CPTableColumn class];
  120. }
  121. @end
  122. @implementation NSTableHeaderCell : NSActionCell
  123. {
  124. }
  125. @end