PageRenderTime 17ms CodeModel.GetById 10ms app.highlight 3ms RepoModel.GetById 1ms app.codeStats 0ms

/Frameworks/Debug/AppKit/browser.platform/CPTableColumn.j

http://github.com/jfahrenkrug/MapKit-HelloWorld
Unknown | 252 lines | 251 code | 1 blank | 0 comment | 0 complexity | ad52de63e0c6391865c46d5ffb68ff5d MD5 | raw file
  1I;23;Foundation/Foundation.jc;10280;
  2CPTableColumnNoResizing = 0;
  3CPTableColumnAutoresizingMask = 1;
  4CPTableColumnUserResizingMask = 2;
  5{var the_class = objj_allocateClassPair(CPObject, "CPTableColumn"),
  6meta_class = the_class.isa;class_addIvars(the_class, [new objj_ivar("_identifier"), new objj_ivar("_headerView"), new objj_ivar("_tableView"), new objj_ivar("_width"), new objj_ivar("_minWidth"), new objj_ivar("_maxWidth"), new objj_ivar("_resizingMask"), new objj_ivar("_dataView"), new objj_ivar("_dataViewData"), new objj_ivar("_dataViewForView"), new objj_ivar("_purgableInfosForDataView")]);
  7objj_registerClassPair(the_class);
  8objj_addClassForBundle(the_class, objj_getBundleWithPath(OBJJ_CURRENT_BUNDLE.path));
  9class_addMethods(the_class, [new objj_method(sel_getUid("initWithIdentifier:"), function $CPTableColumn__initWithIdentifier_(self, _cmd, anIdentifier)
 10{ with(self)
 11{
 12    self = objj_msgSendSuper({ receiver:self, super_class:objj_getClass("CPObject") }, "init");
 13    if (self)
 14    {
 15        objj_msgSend(self, "_init");
 16        _identifier = anIdentifier;
 17        _width = 40.0;
 18        _minWidth = 8.0;
 19        _maxWidth = 1000.0;
 20        var dataView = objj_msgSend(objj_msgSend(CPTextField, "alloc"), "initWithFrame:", CPRectMakeZero());
 21        objj_msgSend(dataView, "setValue:forThemeAttribute:inState:", objj_msgSend(CPColor, "whiteColor"), "text-color", CPThemeStateHighlighted);
 22        objj_msgSend(self, "setDataView:", dataView);
 23        _headerView = objj_msgSend(objj_msgSend(CPTextField, "alloc"), "initWithFrame:", CPRectMakeZero());
 24        objj_msgSend(_headerView, "setBackgroundColor:", objj_msgSend(CPColor, "greenColor"));
 25    }
 26    return self;
 27}
 28}), new objj_method(sel_getUid("_init"), function $CPTableColumn___init(self, _cmd)
 29{ with(self)
 30{
 31    _dataViewData = {};
 32    _dataViewForView = {};
 33    _purgableInfosForDataView = {};
 34}
 35}), new objj_method(sel_getUid("setIdentifier:"), function $CPTableColumn__setIdentifier_(self, _cmd, anIdentifier)
 36{ with(self)
 37{
 38    _identifier = anIdentifier;
 39}
 40}), new objj_method(sel_getUid("identifier"), function $CPTableColumn__identifier(self, _cmd)
 41{ with(self)
 42{
 43    return _identifier;
 44}
 45}), new objj_method(sel_getUid("setTableView:"), function $CPTableColumn__setTableView_(self, _cmd, aTableView)
 46{ with(self)
 47{
 48    _tableView = aTableView;
 49}
 50}), new objj_method(sel_getUid("tableView"), function $CPTableColumn__tableView(self, _cmd)
 51{ with(self)
 52{
 53    return _tableView;
 54}
 55}), new objj_method(sel_getUid("setWidth:"), function $CPTableColumn__setWidth_(self, _cmd, aWidth)
 56{ with(self)
 57{
 58    _width = aWidth;
 59}
 60}), new objj_method(sel_getUid("width"), function $CPTableColumn__width(self, _cmd)
 61{ with(self)
 62{
 63    return _width;
 64}
 65}), new objj_method(sel_getUid("setMinWidth:"), function $CPTableColumn__setMinWidth_(self, _cmd, aWidth)
 66{ with(self)
 67{
 68    if (_width < (_minWidth = aWidth))
 69        objj_msgSend(self, "setWidth:", _minWidth);
 70}
 71}), new objj_method(sel_getUid("minWidth"), function $CPTableColumn__minWidth(self, _cmd)
 72{ with(self)
 73{
 74    return _minWidth;
 75}
 76}), new objj_method(sel_getUid("setMaxWidth:"), function $CPTableColumn__setMaxWidth_(self, _cmd, aWidth)
 77{ with(self)
 78{
 79    if (_width > (_maxmimumWidth = aWidth))
 80        objj_msgSend(self, "setWidth:", _maxWidth);
 81}
 82}), new objj_method(sel_getUid("setResizingMask:"), function $CPTableColumn__setResizingMask_(self, _cmd, aMask)
 83{ with(self)
 84{
 85    _resizingMask = aMask;
 86}
 87}), new objj_method(sel_getUid("resizingMask"), function $CPTableColumn__resizingMask(self, _cmd)
 88{ with(self)
 89{
 90    return _resizingMask;
 91}
 92}), new objj_method(sel_getUid("sizeToFit"), function $CPTableColumn__sizeToFit(self, _cmd)
 93{ with(self)
 94{
 95    var width = CPRectGetWidth(objj_msgSend(_headerView, "frame"));
 96    if (width < _minWidth)
 97        objj_msgSend(self, "setMinWidth:", width);
 98    else if (width > _maxWidth)
 99        objj_msgSend(self, "setMaxWidth:", width)
100    if (_width != width)
101        objj_msgSend(self, "setWidth:", width);
102}
103}), new objj_method(sel_getUid("setEditable:"), function $CPTableColumn__setEditable_(self, _cmd, aFlag)
104{ with(self)
105{
106    _isEditable = aFlag;
107}
108}), new objj_method(sel_getUid("isEditable"), function $CPTableColumn__isEditable(self, _cmd)
109{ with(self)
110{
111    return _isEditable;
112}
113}), new objj_method(sel_getUid("setHeaderView:"), function $CPTableColumn__setHeaderView_(self, _cmd, aView)
114{ with(self)
115{
116    _headerView = aView;
117}
118}), new objj_method(sel_getUid("headerView"), function $CPTableColumn__headerView(self, _cmd)
119{ with(self)
120{
121    return _headerView;
122}
123}), new objj_method(sel_getUid("setDataCell:"), function $CPTableColumn__setDataCell_(self, _cmd, aView)
124{ with(self)
125{
126    objj_msgSend(self, "setDataView:", aView);
127}
128}), new objj_method(sel_getUid("setDataView:"), function $CPTableColumn__setDataView_(self, _cmd, aView)
129{ with(self)
130{
131    if (_dataView)
132        _dataViewData[objj_msgSend(_dataView, "hash")] = nil;
133    _dataView = aView;
134    _dataViewData[objj_msgSend(aView, "hash")] = objj_msgSend(CPKeyedArchiver, "archivedDataWithRootObject:", aView);
135}
136}), new objj_method(sel_getUid("dataCell"), function $CPTableColumn__dataCell(self, _cmd)
137{ with(self)
138{
139    return _dataView;
140}
141}), new objj_method(sel_getUid("dataView"), function $CPTableColumn__dataView(self, _cmd)
142{ with(self)
143{
144    return objj_msgSend(self, "dataCell");
145}
146}), new objj_method(sel_getUid("dataCellForRow:"), function $CPTableColumn__dataCellForRow_(self, _cmd, aRowIndex)
147{ with(self)
148{
149    return objj_msgSend(self, "dataView");
150}
151}), new objj_method(sel_getUid("dataViewForRow:"), function $CPTableColumn__dataViewForRow_(self, _cmd, aRowIndex)
152{ with(self)
153{
154    return objj_msgSend(self, "dataCellForRow:", aRowIndex);
155}
156}), new objj_method(sel_getUid("_markView:inRow:asPurgable:"), function $CPTableColumn___markView_inRow_asPurgable_(self, _cmd, aView, aRow, isPurgable)
157{ with(self)
158{
159    var viewHash = objj_msgSend(aView, "hash"),
160        dataViewHash = objj_msgSend(_dataViewForView[viewHash], "hash");
161    if (!_purgableInfosForDataView[dataViewHash])
162    {
163        if (!isPurgable)
164            return;
165        _purgableInfosForDataView[dataViewHash] = {};
166    }
167    if (!isPurgable) {
168        if (_purgableInfosForDataView[dataViewHash][viewHash])
169            CPLog.warn("removing unpurgable " + _purgableInfosForDataView[dataViewHash][viewHash]);
170        delete _purgableInfosForDataView[dataViewHash][viewHash];
171    }
172    else
173        _purgableInfosForDataView[dataViewHash][viewHash] = { view:(aView), row:(aRow) };
174}
175}), new objj_method(sel_getUid("_newDataViewForRow:avoidingRows:"), function $CPTableColumn___newDataViewForRow_avoidingRows_(self, _cmd, aRowIndex, rows)
176{ with(self)
177{
178    var view = objj_msgSend(self, "dataViewForRow:", aRowIndex),
179        viewHash = objj_msgSend(view, "hash"),
180        purgableInfos = _purgableInfosForDataView[viewHash];
181    if (purgableInfos)
182    {
183        for (var key in purgableInfos)
184        {
185            var info = purgableInfos[key];
186                delete purgableInfos[key];
187                return ((info).view);
188        }
189    }
190    if (!_dataViewData[viewHash])
191        _dataViewData[viewHash] = objj_msgSend(CPKeyedArchiver, "archivedDataWithRootObject:", view);
192    var newView = objj_msgSend(CPKeyedUnarchiver, "unarchiveObjectWithData:", _dataViewData[viewHash]);
193    _dataViewForView[objj_msgSend(newView, "hash")] = view;
194    CPLog.warn("creating cell: %s", newView);
195    return newView;
196}
197}), new objj_method(sel_getUid("_purge"), function $CPTableColumn___purge(self, _cmd)
198{ with(self)
199{
200    for (var viewHash in _purgableInfosForDataView)
201    {
202        var purgableInfos = _purgableInfosForDataView[viewHash];
203        for (var key in purgableInfos)
204        {
205            var view = ((purgableInfos[key]).view);
206            if (!view)
207                CPLog.info("key="+key+" view=" + view + " purgableInfos[key]="+purgableInfos[key])
208            else if (view._superview) {
209                objj_msgSend(view, "setHidden:", YES);
210            }
211        }
212    }
213}
214})]);
215}
216var CPTableColumnIdentifierKey = "CPTableColumnIdentifierKey",
217    CPTableColumnHeaderViewKey = "CPTableColumnHeaderViewKey",
218    CPTableColumnDataViewKey = "CPTableColumnDataViewKey",
219    CPTableColumnWidthKey = "CPTableColumnWidthKey",
220    CPTableColumnMinWidthKey = "CPTableColumnMinWidthKey",
221    CPTableColumnMaxWidthKey = "CPTableColumnMaxWidthKey",
222    CPTableColumnResizingMaskKey = "CPTableColumnResizingMaskKey";
223{
224var the_class = objj_getClass("CPTableColumn")
225if(!the_class) objj_exception_throw(new objj_exception(OBJJClassNotFoundException, "*** Could not find definition for class \"CPTableColumn\""));
226var meta_class = the_class.isa;class_addMethods(the_class, [new objj_method(sel_getUid("initWithCoder:"), function $CPTableColumn__initWithCoder_(self, _cmd, aCoder)
227{ with(self)
228{
229    objj_msgSend(self, "_init");
230    _identifier = objj_msgSend(aCoder, "decodeObjectForKey:", CPTableColumnIdentifierKey);
231    objj_msgSend(self, "setHeaderView:", objj_msgSend(aCoder, "decodeObjectForKey:", CPTableColumnHeaderViewKey));
232    objj_msgSend(self, "setDataView:", objj_msgSend(aCoder, "decodeObjectForKey:", CPTableColumnDataViewKey));
233    _width = objj_msgSend(aCoder, "decodeFloatForKey:", CPTableColumnWidthKey);
234    _minWidth = objj_msgSend(aCoder, "decodeFloatForKey:", CPTableColumnMinWidthKey);
235    _maxWidth = objj_msgSend(aCoder, "decodeFloatForKey:", CPTableColumnMaxWidthKey);
236    _resizingMask = objj_msgSend(aCoder, "decodeBoolForKey:", CPTableColumnResizingMaskKey);
237    return self;
238}
239}), new objj_method(sel_getUid("encodeWithCoder:"), function $CPTableColumn__encodeWithCoder_(self, _cmd, aCoder)
240{ with(self)
241{
242    objj_msgSend(aCoder, "encodeObject:forKey:", _identifier, CPTableColumnIdentifierKey);
243    objj_msgSend(aCoder, "encodeObject:forKey:", _headerView, CPTableColumnHeaderViewKey);
244    objj_msgSend(aCoder, "encodeObject:forKey:", _dataView, CPTableColumnDataViewKey);
245    objj_msgSend(aCoder, "encodeObject:forKey:", _width, CPTableColumnWidthKey);
246    objj_msgSend(aCoder, "encodeObject:forKey:", _minWidth, CPTableColumnMinWidthKey);
247    objj_msgSend(aCoder, "encodeObject:forKey:", _maxWidth, CPTableColumnMaxWidthKey);
248    objj_msgSend(aCoder, "encodeObject:forKey:", _resizingMask, CPTableColumnResizingMaskKey);
249}
250})]);
251}
252