PageRenderTime 37ms CodeModel.GetById 15ms app.highlight 10ms RepoModel.GetById 2ms app.codeStats 0ms

/Frameworks/Debug/AppKit/rhino.platform/CPSegmentedControl.j

http://github.com/jfahrenkrug/MapKit-HelloWorld
Unknown | 587 lines | 586 code | 1 blank | 0 comment | 0 complexity | 435d5b5ca8c5d65ea86b17b0b6d61098 MD5 | raw file
  1I;20;Foundation/CPArray.ji;11;CPControl.jc;28921;
  2CPSegmentSwitchTrackingSelectOne = 0;
  3CPSegmentSwitchTrackingSelectAny = 1;
  4CPSegmentSwitchTrackingMomentary = 2;
  5{var the_class = objj_allocateClassPair(CPControl, "CPSegmentedControl"),
  6meta_class = the_class.isa;class_addIvars(the_class, [new objj_ivar("_segments"), new objj_ivar("_themeStates"), new objj_ivar("_selectedSegment"), new objj_ivar("_segmentStyle"), new objj_ivar("_trackingMode"), new objj_ivar("_trackingSegment"), new objj_ivar("_trackingHighlighted")]);
  7objj_registerClassPair(the_class);
  8objj_addClassForBundle(the_class, objj_getBundleWithPath(OBJJ_CURRENT_BUNDLE.path));
  9class_addMethods(the_class, [new objj_method(sel_getUid("initWithFrame:"), function $CPSegmentedControl__initWithFrame_(self, _cmd, aRect)
 10{ with(self)
 11{
 12    _segments = [];
 13    _themeStates = [];
 14    self = objj_msgSendSuper({ receiver:self, super_class:objj_getClass("CPControl") }, "initWithFrame:", aRect);
 15    if (self)
 16    {
 17        _selectedSegment = -1;
 18        _trackingMode = CPSegmentSwitchTrackingSelectOne;
 19    }
 20    return self;
 21}
 22}), new objj_method(sel_getUid("selectedTag"), function $CPSegmentedControl__selectedTag(self, _cmd)
 23{ with(self)
 24{
 25    return _segments[_selectedSegment].tag;
 26}
 27}), new objj_method(sel_getUid("setSegmentCount:"), function $CPSegmentedControl__setSegmentCount_(self, _cmd, aCount)
 28{ with(self)
 29{
 30    if (_segments.length == aCount)
 31        return;
 32    var height = CGRectGetHeight(objj_msgSend(self, "bounds"));
 33    if (_segments.length < aCount)
 34    {
 35        for (var index = _segments.length; index < aCount; ++index)
 36        {
 37            _segments[index] = objj_msgSend(objj_msgSend(_CPSegmentItem, "alloc"), "init");
 38            _themeStates[index] = CPThemeStateNormal;
 39        }
 40    }
 41    else if (aCount < _segments.length)
 42    {
 43        for (var index = aCount; index < _segments.length; ++index)
 44            _segments[index] = nil;
 45    }
 46    if (_selectedSegment < _segments.length)
 47        _selectedSegment = -1;
 48    objj_msgSend(self, "tileWithChangedSegment:", 0);
 49}
 50}), new objj_method(sel_getUid("segmentCount"), function $CPSegmentedControl__segmentCount(self, _cmd)
 51{ with(self)
 52{
 53    return _segments.length;
 54}
 55}), new objj_method(sel_getUid("setSelectedSegment:"), function $CPSegmentedControl__setSelectedSegment_(self, _cmd, aSegment)
 56{ with(self)
 57{
 58    objj_msgSend(self, "setSelected:forSegment:", YES, aSegment);
 59}
 60}), new objj_method(sel_getUid("selectedSegment"), function $CPSegmentedControl__selectedSegment(self, _cmd)
 61{ with(self)
 62{
 63    return _selectedSegment;
 64}
 65}), new objj_method(sel_getUid("selectSegmentWithTag:"), function $CPSegmentedControl__selectSegmentWithTag_(self, _cmd, aTag)
 66{ with(self)
 67{
 68    var index = 0;
 69    for (; index < _segments.length; ++index)
 70        if (_segments[index].tag == aTag)
 71        {
 72            objj_msgSend(self, "setSelectedSegment:", index);
 73            return YES;
 74        }
 75    return NO;
 76}
 77}), new objj_method(sel_getUid("isTracking"), function $CPSegmentedControl__isTracking(self, _cmd)
 78{ with(self)
 79{
 80}
 81}), new objj_method(sel_getUid("setTrackingMode:"), function $CPSegmentedControl__setTrackingMode_(self, _cmd, aTrackingMode)
 82{ with(self)
 83{
 84    if (_trackingMode == aTrackingMode)
 85        return;
 86    _trackingMode = aTrackingMode;
 87    if (_trackingMode == CPSegmentSwitchTrackingSelectOne)
 88    {
 89        var index = 0,
 90            selected = NO;
 91        for (; index < _segments.length; ++index)
 92            if (_segments[index].selected)
 93                if (selected)
 94                    objj_msgSend(self, "setSelected:forSegment:", NO, index);
 95                else
 96                    selected = YES;
 97    }
 98    else if (_trackingMode == CPSegmentSwitchTrackingMomentary)
 99    {
100        var index = 0;
101        for (; index < _segments.length; ++index)
102            if (_segments[index].selected)
103                objj_msgSend(self, "setSelected:forSegment:", NO, index);
104    }
105}
106}), new objj_method(sel_getUid("trackingMode"), function $CPSegmentedControl__trackingMode(self, _cmd)
107{ with(self)
108{
109    return _trackingMode;
110}
111}), new objj_method(sel_getUid("setWidth:forSegment:"), function $CPSegmentedControl__setWidth_forSegment_(self, _cmd, aWidth, aSegment)
112{ with(self)
113{
114    _segments[aSegment].width = aWidth;
115    objj_msgSend(self, "tileWithChangedSegment:", aSegment);
116}
117}), new objj_method(sel_getUid("widthForSegment:"), function $CPSegmentedControl__widthForSegment_(self, _cmd, aSegment)
118{ with(self)
119{
120    return _segments[aSegment].width;
121}
122}), new objj_method(sel_getUid("setImage:forSegment:"), function $CPSegmentedControl__setImage_forSegment_(self, _cmd, anImage, aSegment)
123{ with(self)
124{
125    var segment = _segments[aSegment];
126    segment.image = anImage;
127    objj_msgSend(self, "tileWithChangedSegment:", aSegment);
128}
129}), new objj_method(sel_getUid("imageForSegment:"), function $CPSegmentedControl__imageForSegment_(self, _cmd, aSegment)
130{ with(self)
131{
132    return _segments[aSegment].image;
133}
134}), new objj_method(sel_getUid("setLabel:forSegment:"), function $CPSegmentedControl__setLabel_forSegment_(self, _cmd, aLabel, aSegment)
135{ with(self)
136{
137    var segment = _segments[aSegment];
138    _segments[aSegment].label = aLabel;
139    objj_msgSend(self, "tileWithChangedSegment:", aSegment);
140}
141}), new objj_method(sel_getUid("labelForSegment:"), function $CPSegmentedControl__labelForSegment_(self, _cmd, aSegment)
142{ with(self)
143{
144    return _segments[aSegment].label;
145}
146}), new objj_method(sel_getUid("setMenu:forSegment:"), function $CPSegmentedControl__setMenu_forSegment_(self, _cmd, aMenu, aSegment)
147{ with(self)
148{
149    _segments[aSegment].menu = aMenu;
150}
151}), new objj_method(sel_getUid("menuForSegment:"), function $CPSegmentedControl__menuForSegment_(self, _cmd, aSegment)
152{ with(self)
153{
154    return _segments[aSegment].menu;
155}
156}), new objj_method(sel_getUid("setSelected:forSegment:"), function $CPSegmentedControl__setSelected_forSegment_(self, _cmd, isSelected, aSegment)
157{ with(self)
158{
159    var segment = _segments[aSegment];
160    if (segment.selected == isSelected)
161        return;
162    segment.selected = isSelected;
163    _themeStates[aSegment] = isSelected ? CPThemeStateSelected : CPThemeStateNormal;
164    if (isSelected)
165    {
166        var oldSelectedSegment = _selectedSegment;
167        _selectedSegment = aSegment;
168        if (_trackingMode == CPSegmentSwitchTrackingSelectOne && oldSelectedSegment != aSegment && oldSelectedSegment != -1)
169        {
170            _segments[oldSelectedSegment].selected = NO;
171            _themeStates[oldSelectedSegment] = CPThemeStateNormal;
172            objj_msgSend(self, "drawSegmentBezel:highlight:", oldSelectedSegment, NO);
173        }
174    }
175    if (_trackingMode != CPSegmentSwitchTrackingMomentary)
176        objj_msgSend(self, "drawSegmentBezel:highlight:", aSegment, NO);
177    objj_msgSend(self, "setNeedsLayout");
178    objj_msgSend(self, "setNeedsDisplay:", YES);
179}
180}), new objj_method(sel_getUid("isSelectedForSegment:"), function $CPSegmentedControl__isSelectedForSegment_(self, _cmd, aSegment)
181{ with(self)
182{
183    return _segments[aSegment].selected;
184}
185}), new objj_method(sel_getUid("setEnabled:forSegment:"), function $CPSegmentedControl__setEnabled_forSegment_(self, _cmd, isEnabled, aSegment)
186{ with(self)
187{
188    _segments[aSegment].enabled = isEnabled;
189    objj_msgSend(self, "setNeedsLayout");
190    objj_msgSend(self, "setNeedsDisplay:", YES);
191}
192}), new objj_method(sel_getUid("isEnabledForSegment:"), function $CPSegmentedControl__isEnabledForSegment_(self, _cmd, aSegment)
193{ with(self)
194{
195    return _segments[aSegment].enabled;
196}
197}), new objj_method(sel_getUid("setTag:forSegment:"), function $CPSegmentedControl__setTag_forSegment_(self, _cmd, aTag, aSegment)
198{ with(self)
199{
200    _segments[aSegment].tag = aTag;
201}
202}), new objj_method(sel_getUid("tagForSegment:"), function $CPSegmentedControl__tagForSegment_(self, _cmd, aSegment)
203{ with(self)
204{
205    return _segments[aSegment].tag;
206}
207}), new objj_method(sel_getUid("drawSegmentBezel:highlight:"), function $CPSegmentedControl__drawSegmentBezel_highlight_(self, _cmd, aSegment, shouldHighlight)
208{ with(self)
209{
210    if (shouldHighlight)
211        _themeStates[aSegment] |= CPThemeStateHighlighted;
212    else
213        _themeStates[aSegment] &= ~CPThemeStateHighlighted;
214    objj_msgSend(self, "setNeedsLayout");
215    objj_msgSend(self, "setNeedsDisplay:", YES);
216}
217}), new objj_method(sel_getUid("_leftOffsetForSegment:"), function $CPSegmentedControl___leftOffsetForSegment_(self, _cmd, segment)
218{ with(self)
219{
220    var bezelInset = objj_msgSend(self, "currentValueForThemeAttribute:", "bezel-inset");
221    if (segment == 0)
222        return bezelInset.left;
223    var thickness = objj_msgSend(self, "currentValueForThemeAttribute:", "divider-thickness");
224    return objj_msgSend(self, "_leftOffsetForSegment:", segment - 1) + objj_msgSend(self, "widthForSegment:", segment - 1) + thickness;
225}
226}), new objj_method(sel_getUid("rectForEphemeralSubviewNamed:"), function $CPSegmentedControl__rectForEphemeralSubviewNamed_(self, _cmd, aName)
227{ with(self)
228{
229    var height = objj_msgSend(self, "currentValueForThemeAttribute:", "default-height"),
230        contentInset = objj_msgSend(self, "currentValueForThemeAttribute:", "content-inset"),
231        bezelInset = objj_msgSend(self, "currentValueForThemeAttribute:", "bezel-inset"),
232        bounds = objj_msgSend(self, "bounds");
233    if (aName === "left-segment-bezel")
234    {
235        return CGRectMake(bezelInset.left, bezelInset.top, contentInset.left, height);
236    }
237    else if (aName === "right-segment-bezel")
238    {
239        return CGRectMake(CGRectGetMaxX(bounds) - contentInset.right - bezelInset.right, bezelInset.top, contentInset.right, height);
240    }
241    else if (aName.substring(0, "segment-bezel".length) == "segment-bezel")
242    {
243        var segment = parseInt(aName.substring("segment-bezel-".length), 10),
244            frame = CGRectCreateCopy(_segments[segment].frame);
245        if (segment == 0)
246        {
247            frame.origin.x += contentInset.left;
248            frame.size.width -= contentInset.left;
249        }
250        if (segment == _segments.length - 1)
251            frame.size.width -= contentInset.right;
252        return frame;
253    }
254    else if (aName.substring(0, "divider-bezel".length) == "divider-bezel")
255    {
256        var segment = parseInt(aName.substring("divider-bezel-".length), 10),
257            width = objj_msgSend(self, "widthForSegment:", segment),
258            left = objj_msgSend(self, "_leftOffsetForSegment:", segment),
259            thickness = objj_msgSend(self, "currentValueForThemeAttribute:", "divider-thickness");
260        return CGRectMake(left + width, bezelInset.top, thickness, height);
261    }
262    else if (aName.substring(0, "segment-content".length) == "segment-content")
263    {
264        var segment = parseInt(aName.substring("segment-content-".length), 10);
265        return objj_msgSend(self, "contentFrameForSegment:", segment);
266    }
267    return objj_msgSendSuper({ receiver:self, super_class:objj_getClass("CPControl") }, "rectForEphemeralSubviewNamed:", aName);
268}
269}), new objj_method(sel_getUid("createEphemeralSubviewNamed:"), function $CPSegmentedControl__createEphemeralSubviewNamed_(self, _cmd, aName)
270{ with(self)
271{
272    if (aName.substring(0, "segment-content".length) == "segment-content")
273        return objj_msgSend(objj_msgSend(_CPImageAndTextView, "alloc"), "initWithFrame:", { origin: { x:0.0, y:0.0 }, size: { width:0.0, height:0.0 } });
274    return objj_msgSend(objj_msgSend(CPView, "alloc"), "initWithFrame:", { origin: { x:0.0, y:0.0 }, size: { width:0.0, height:0.0 } });
275}
276}), new objj_method(sel_getUid("layoutSubviews"), function $CPSegmentedControl__layoutSubviews(self, _cmd)
277{ with(self)
278{
279    var leftCapColor = objj_msgSend(self, "valueForThemeAttribute:inState:", "left-segment-bezel-color", _themeStates[0]);
280    var leftBezelView = objj_msgSend(self, "layoutEphemeralSubviewNamed:positioned:relativeToEphemeralSubviewNamed:", "left-segment-bezel", CPWindowBelow, nil);
281    objj_msgSend(leftBezelView, "setBackgroundColor:", leftCapColor);
282    var rightCapColor = objj_msgSend(self, "valueForThemeAttribute:inState:", "right-segment-bezel-color", _themeStates[_themeStates.length - 1]);
283    var rightBezelView = objj_msgSend(self, "layoutEphemeralSubviewNamed:positioned:relativeToEphemeralSubviewNamed:", "right-segment-bezel", CPWindowBelow, nil);
284    objj_msgSend(rightBezelView, "setBackgroundColor:", rightCapColor);
285    for (var i=0, count = _themeStates.length; i<count; i++)
286    {
287        var themeState = _themeStates[i];
288        themeState |= _themeState & CPThemeStateDisabled;
289        var bezelColor = objj_msgSend(self, "valueForThemeAttribute:inState:", "center-segment-bezel-color", themeState);
290        var bezelView = objj_msgSend(self, "layoutEphemeralSubviewNamed:positioned:relativeToEphemeralSubviewNamed:", "segment-bezel-"+i, CPWindowBelow, nil);
291        objj_msgSend(bezelView, "setBackgroundColor:", bezelColor);
292        var segment = _segments[i];
293        var contentView = objj_msgSend(self, "layoutEphemeralSubviewNamed:positioned:relativeToEphemeralSubviewNamed:", "segment-content-"+i, CPWindowAbove, "segment-bezel-"+i);
294        objj_msgSend(contentView, "setText:", segment.label);
295        objj_msgSend(contentView, "setImage:", segment.image);
296        objj_msgSend(contentView, "setFont:", objj_msgSend(self, "valueForThemeAttribute:inState:", "font", themeState));
297        objj_msgSend(contentView, "setTextColor:", objj_msgSend(self, "valueForThemeAttribute:inState:", "text-color", themeState));
298        objj_msgSend(contentView, "setAlignment:", objj_msgSend(self, "valueForThemeAttribute:inState:", "alignment", themeState));
299        objj_msgSend(contentView, "setVerticalAlignment:", objj_msgSend(self, "valueForThemeAttribute:inState:", "vertical-alignment", themeState));
300        objj_msgSend(contentView, "setLineBreakMode:", objj_msgSend(self, "valueForThemeAttribute:inState:", "line-break-mode", themeState));
301        objj_msgSend(contentView, "setTextShadowColor:", objj_msgSend(self, "valueForThemeAttribute:inState:", "text-shadow-color", themeState));
302        objj_msgSend(contentView, "setTextShadowOffset:", objj_msgSend(self, "valueForThemeAttribute:inState:", "text-shadow-offset", themeState));
303        objj_msgSend(contentView, "setImageScaling:", objj_msgSend(self, "valueForThemeAttribute:inState:", "image-scaling", themeState));
304        if (segment.image && segment.label)
305            objj_msgSend(contentView, "setImagePosition:", objj_msgSend(self, "valueForThemeAttribute:inState:", "image-position", themeState));
306        else if (segment.image)
307            objj_msgSend(contentView, "setImagePosition:", CPImageOnly);
308        if (i == count - 1)
309            continue;
310        var borderState = _themeStates[i] | _themeStates[i+1];
311        borderState = (borderState & CPThemeStateSelected & ~CPThemeStateHighlighted) ? CPThemeStateSelected : CPThemeStateNormal;
312        borderState |= _themeState & CPThemeStateDisabled;
313        var borderColor = objj_msgSend(self, "valueForThemeAttribute:inState:", "divider-bezel-color", borderState);
314        var borderView = objj_msgSend(self, "layoutEphemeralSubviewNamed:positioned:relativeToEphemeralSubviewNamed:", "divider-bezel-"+i, CPWindowBelow, nil);
315        objj_msgSend(borderView, "setBackgroundColor:", borderColor);
316    }
317}
318}), new objj_method(sel_getUid("drawSegment:highlight:"), function $CPSegmentedControl__drawSegment_highlight_(self, _cmd, aSegment, shouldHighlight)
319{ with(self)
320{
321}
322}), new objj_method(sel_getUid("tileWithChangedSegment:"), function $CPSegmentedControl__tileWithChangedSegment_(self, _cmd, aSegment)
323{ with(self)
324{
325    if (aSegment >= _segments.length)
326        return;
327    var segment = _segments[aSegment],
328        segmentWidth = segment.width,
329        themeState = _themeStates[aSegment] | (_themeState & CPThemeStateDisabled),
330        contentInset = objj_msgSend(self, "valueForThemeAttribute:inState:", "content-inset", themeState),
331        font = objj_msgSend(self, "valueForThemeAttribute:inState:", "font", themeState);
332    if (!segmentWidth)
333    {
334        if (segment.image && segment.label)
335            segmentWidth = objj_msgSend(segment.label, "sizeWithFont:", font).width + objj_msgSend(segment.image, "size").width + contentInset.left + contentInset.right;
336        else if (segment.image)
337            segmentWidth = objj_msgSend(segment.image, "size").width + contentInset.left + contentInset.right;
338        else if (segment.label)
339            segmentWidth = objj_msgSend(segment.label, "sizeWithFont:", font).width + contentInset.left + contentInset.right;
340        else
341            segmentWidth = 0.0;
342    }
343    var delta = segmentWidth - CGRectGetWidth(segment.frame);
344    if (!delta)
345        return;
346    var frame = objj_msgSend(self, "frame");
347    objj_msgSend(self, "setFrameSize:", CGSizeMake(CGRectGetWidth(frame) + delta, CGRectGetHeight(frame)));
348    segment.width = segmentWidth;
349    segment.frame = objj_msgSend(self, "frameForSegment:", aSegment);;
350    var index = aSegment + 1;
351    for (; index < _segments.length; ++index)
352    {
353        _segments[index].frame.origin.x += delta;
354        objj_msgSend(self, "drawSegmentBezel:highlight:", index, NO);
355        objj_msgSend(self, "drawSegment:highlight:", index, NO);
356    }
357    objj_msgSend(self, "drawSegmentBezel:highlight:", aSegment, NO);
358    objj_msgSend(self, "drawSegment:highlight:", aSegment, NO);
359    objj_msgSend(self, "setNeedsLayout");
360    objj_msgSend(self, "setNeedsDisplay:", YES);
361}
362}), new objj_method(sel_getUid("frameForSegment:"), function $CPSegmentedControl__frameForSegment_(self, _cmd, aSegment)
363{ with(self)
364{
365    return objj_msgSend(self, "bezelFrameForSegment:", aSegment);
366}
367}), new objj_method(sel_getUid("bezelFrameForSegment:"), function $CPSegmentedControl__bezelFrameForSegment_(self, _cmd, aSegment)
368{ with(self)
369{
370    var height = objj_msgSend(self, "currentValueForThemeAttribute:", "default-height"),
371        bezelInset = objj_msgSend(self, "currentValueForThemeAttribute:", "bezel-inset"),
372        width = objj_msgSend(self, "widthForSegment:", aSegment),
373        left = objj_msgSend(self, "_leftOffsetForSegment:", aSegment);
374    return CGRectMake(left, bezelInset.top, width, height);
375}
376}), new objj_method(sel_getUid("contentFrameForSegment:"), function $CPSegmentedControl__contentFrameForSegment_(self, _cmd, aSegment)
377{ with(self)
378{
379    var height = objj_msgSend(self, "currentValueForThemeAttribute:", "default-height"),
380        contentInset = objj_msgSend(self, "currentValueForThemeAttribute:", "content-inset"),
381        width = objj_msgSend(self, "widthForSegment:", aSegment),
382        left = objj_msgSend(self, "_leftOffsetForSegment:", aSegment);
383    return CGRectMake(left + contentInset.left, contentInset.top, width - contentInset.left - contentInset.right, height - contentInset.top - contentInset.bottom);
384}
385}), new objj_method(sel_getUid("testSegment:"), function $CPSegmentedControl__testSegment_(self, _cmd, aPoint)
386{ with(self)
387{
388    var location = objj_msgSend(self, "convertPoint:fromView:", aPoint, nil),
389        count = _segments.length;
390    while (count--)
391        if (CGRectContainsPoint(_segments[count].frame, aPoint))
392            return count;
393    return -1;
394}
395}), new objj_method(sel_getUid("mouseDown:"), function $CPSegmentedControl__mouseDown_(self, _cmd, anEvent)
396{ with(self)
397{
398    if (!objj_msgSend(self, "isEnabled"))
399        return;
400    objj_msgSend(self, "trackSegment:", anEvent);
401}
402}), new objj_method(sel_getUid("mouseUp:"), function $CPSegmentedControl__mouseUp_(self, _cmd, anEvent)
403{ with(self)
404{
405}
406}), new objj_method(sel_getUid("trackSegment:"), function $CPSegmentedControl__trackSegment_(self, _cmd, anEvent)
407{ with(self)
408{
409    var type = objj_msgSend(anEvent, "type"),
410        location = objj_msgSend(self, "convertPoint:fromView:", objj_msgSend(anEvent, "locationInWindow"), nil);
411    if (type == CPLeftMouseUp)
412    {
413        if (_trackingSegment == -1)
414            return;
415        if (CGRectContainsPoint(_segments[_trackingSegment].frame, location))
416        {
417            if (_trackingMode == CPSegmentSwitchTrackingSelectAny)
418            {
419                objj_msgSend(self, "setSelected:forSegment:", !objj_msgSend(self, "isSelectedForSegment:", _trackingSegment), _trackingSegment);
420                _selectedSegment = _trackingSegment;
421            }
422            else
423                objj_msgSend(self, "setSelected:forSegment:", YES, _trackingSegment);
424            objj_msgSend(self, "sendAction:to:", objj_msgSend(self, "action"), objj_msgSend(self, "target"));
425            if (_trackingMode == CPSegmentSwitchTrackingMomentary)
426            {
427                objj_msgSend(self, "setSelected:forSegment:", NO, _trackingSegment);
428                _selectedSegment = -1;
429            }
430        }
431        objj_msgSend(self, "drawSegmentBezel:highlight:", _trackingSegment, NO);
432        _trackingSegment = -1;
433        return;
434    }
435    if (type == CPLeftMouseDown)
436    {
437        _trackingHighlighted = YES;
438        _trackingSegment = objj_msgSend(self, "testSegment:", location);
439        objj_msgSend(self, "drawSegmentBezel:highlight:", _trackingSegment, YES);
440    }
441    else if (type == CPLeftMouseDragged)
442    {
443        if (_trackingSegment == -1)
444            return;
445        var highlighted = CGRectContainsPoint(_segments[_trackingSegment].frame, location);
446        if (highlighted != _trackingHighlighted)
447        {
448            _trackingHighlighted = highlighted;
449            objj_msgSend(self, "drawSegmentBezel:highlight:", _trackingSegment, _trackingHighlighted);
450        }
451    }
452    objj_msgSend(CPApp, "setTarget:selector:forNextEventMatchingMask:untilDate:inMode:dequeue:", self, sel_getUid("trackSegment:"), CPLeftMouseDraggedMask | CPLeftMouseUpMask, nil, nil, YES);
453}
454}), new objj_method(sel_getUid("setFont:"), function $CPSegmentedControl__setFont_(self, _cmd, aFont)
455{ with(self)
456{
457    objj_msgSendSuper({ receiver:self, super_class:objj_getClass("CPControl") }, "setFont:", aFont);
458    objj_msgSend(self, "tileWithChangedSegment:", 0);
459}
460})]);
461class_addMethods(meta_class, [new objj_method(sel_getUid("themeClass"), function $CPSegmentedControl__themeClass(self, _cmd)
462{ with(self)
463{
464    return "segmented-control";
465}
466}), new objj_method(sel_getUid("themeAttributes"), function $CPSegmentedControl__themeAttributes(self, _cmd)
467{ with(self)
468{
469    return objj_msgSend(CPDictionary, "dictionaryWithObjects:forKeys:", [CPCenterTextAlignment, CPCenterVerticalTextAlignment, CPImageLeft, CPScaleNone, { top:(0), right:(0), bottom:(0), left:(0) }, { top:(0), right:(0), bottom:(0), left:(0) }, nil, nil, nil, nil, 1.0, 24.0], ["alignment", "vertical-alignment", "image-position", "image-scaling", "bezel-inset", "content-inset", "left-segment-bezel-color", "right-segment-bezel-color", "center-segment-bezel-color", "divider-bezel-color", "divider-thickness", "default-height"]);
470}
471})]);
472}
473var CPSegmentedControlSegmentsKey = "CPSegmentedControlSegmentsKey",
474    CPSegmentedControlSelectedKey = "CPSegmentedControlSelectedKey",
475    CPSegmentedControlSegmentStyleKey = "CPSegmentedControlSegmentStyleKey",
476    CPSegmentedControlTrackingModeKey = "CPSegmentedControlTrackingModeKey";
477{
478var the_class = objj_getClass("CPSegmentedControl")
479if(!the_class) objj_exception_throw(new objj_exception(OBJJClassNotFoundException, "*** Could not find definition for class \"CPSegmentedControl\""));
480var meta_class = the_class.isa;class_addMethods(the_class, [new objj_method(sel_getUid("initWithCoder:"), function $CPSegmentedControl__initWithCoder_(self, _cmd, aCoder)
481{ with(self)
482{
483    self = objj_msgSendSuper({ receiver:self, super_class:objj_getClass("CPControl") }, "initWithCoder:", aCoder);
484    if (self)
485    {
486        var frame = objj_msgSend(self, "frame"),
487            originalWidth = frame.size.width;
488        frame.size.width = 0;
489        objj_msgSend(self, "setFrame:", frame);
490        _segments = objj_msgSend(aCoder, "decodeObjectForKey:", CPSegmentedControlSegmentsKey);
491        _segmentStyle = objj_msgSend(aCoder, "decodeIntForKey:", CPSegmentedControlSegmentStyleKey);
492        _themeStates = [];
493        if (objj_msgSend(aCoder, "containsValueForKey:", CPSegmentedControlSelectedKey))
494            _selectedSegment = objj_msgSend(aCoder, "decodeIntForKey:", CPSegmentedControlSelectedKey);
495        else
496            _selectedSegment = -1;
497        if (objj_msgSend(aCoder, "containsValueForKey:", CPSegmentedControlTrackingModeKey))
498            _trackingMode = objj_msgSend(aCoder, "decodeIntForKey:", CPSegmentedControlTrackingModeKey);
499        else
500            _trackingMode = CPSegmentSwitchTrackingSelectOne;
501        for (var i = 0; i < _segments.length; i++)
502        {
503            _themeStates[i] = _segments[i].selected ? CPThemeStateSelected : CPThemeStateNormal;
504            objj_msgSend(self, "tileWithChangedSegment:", i);
505        }
506        var difference = MAX(originalWidth - objj_msgSend(self, "frame").size.width, 0.0),
507            remainingWidth = FLOOR(difference / _segments.length);
508        for (var i=0; i < _segments.length; i++)
509            objj_msgSend(self, "setWidth:forSegment:", _segments[i].width + remainingWidth, i);
510        objj_msgSend(self, "tileWithChangedSegment:", 0);
511    }
512    return self;
513}
514}), new objj_method(sel_getUid("encodeWithCoder:"), function $CPSegmentedControl__encodeWithCoder_(self, _cmd, aCoder)
515{ with(self)
516{
517    objj_msgSendSuper({ receiver:self, super_class:objj_getClass("CPControl") }, "encodeWithCoder:", aCoder);
518    objj_msgSend(aCoder, "encodeObject:forKey:", _segments, CPSegmentedControlSegmentsKey);
519    objj_msgSend(aCoder, "encodeInt:forKey:", _selectedSegment, CPSegmentedControlSelectedKey);
520    objj_msgSend(aCoder, "encodeInt:forKey:", _segmentStyle, CPSegmentedControlSegmentStyleKey);
521    objj_msgSend(aCoder, "encodeInt:forKey:", _trackingMode, CPSegmentedControlTrackingModeKey);
522}
523})]);
524}
525{var the_class = objj_allocateClassPair(CPObject, "_CPSegmentItem"),
526meta_class = the_class.isa;class_addIvars(the_class, [new objj_ivar("image"), new objj_ivar("label"), new objj_ivar("menu"), new objj_ivar("selected"), new objj_ivar("enabled"), new objj_ivar("tag"), new objj_ivar("width"), new objj_ivar("frame")]);
527objj_registerClassPair(the_class);
528objj_addClassForBundle(the_class, objj_getBundleWithPath(OBJJ_CURRENT_BUNDLE.path));
529class_addMethods(the_class, [new objj_method(sel_getUid("init"), function $_CPSegmentItem__init(self, _cmd)
530{ with(self)
531{
532    if (self = objj_msgSendSuper({ receiver:self, super_class:objj_getClass("CPObject") }, "init"))
533    {
534        image = nil;
535        label = "";
536        menu = nil;
537        selected = NO;
538        enabled = NO;
539        tag = 0;
540        width = 0;
541        frame = CGRectMakeZero();
542    }
543    return self;
544}
545})]);
546}
547var CPSegmentItemImageKey = "CPSegmentItemImageKey",
548    CPSegmentItemLabelKey = "CPSegmentItemLabelKey",
549    CPSegmentItemMenuKey = "CPSegmentItemMenuKey",
550    CPSegmentItemSelectedKey = "CPSegmentItemSelectedKey",
551    CPSegmentItemEnabledKey = "CPSegmentItemEnabledKey",
552    CPSegmentItemTagKey = "CPSegmentItemTagKey",
553    CPSegmentItemWidthKey = "CPSegmentItemWidthKey";
554{
555var the_class = objj_getClass("_CPSegmentItem")
556if(!the_class) objj_exception_throw(new objj_exception(OBJJClassNotFoundException, "*** Could not find definition for class \"_CPSegmentItem\""));
557var meta_class = the_class.isa;class_addMethods(the_class, [new objj_method(sel_getUid("initWithCoder:"), function $_CPSegmentItem__initWithCoder_(self, _cmd, aCoder)
558{ with(self)
559{
560    self = objj_msgSendSuper({ receiver:self, super_class:objj_getClass("CPObject") }, "init");
561    if (self)
562    {
563        image = objj_msgSend(aCoder, "decodeObjectForKey:", CPSegmentItemImageKey);
564        label = objj_msgSend(aCoder, "decodeObjectForKey:", CPSegmentItemLabelKey);
565        menu = objj_msgSend(aCoder, "decodeObjectForKey:", CPSegmentItemMenuKey);
566        selected = objj_msgSend(aCoder, "decodeBoolForKey:", CPSegmentItemSelectedKey);
567        enabled = objj_msgSend(aCoder, "decodeBoolForKey:", CPSegmentItemEnabledKey);
568        tag = objj_msgSend(aCoder, "decodeIntForKey:", CPSegmentItemTagKey);
569        width = objj_msgSend(aCoder, "decodeFloatForKey:", CPSegmentItemWidthKey);
570        frame = CGRectMakeZero();
571    }
572    return self;
573}
574}), new objj_method(sel_getUid("encodeWithCoder:"), function $_CPSegmentItem__encodeWithCoder_(self, _cmd, aCoder)
575{ with(self)
576{
577    objj_msgSend(aCoder, "encodeObject:forKey:", image, CPSegmentItemImageKey);
578    objj_msgSend(aCoder, "encodeObject:forKey:", label, CPSegmentItemLabelKey);
579    objj_msgSend(aCoder, "encodeObject:forKey:", menu, CPSegmentItemMenuKey);
580    objj_msgSend(aCoder, "encodeBool:forKey:", selected, CPSegmentItemSelectedKey);
581    objj_msgSend(aCoder, "encodeBool:forKey:", enabled, CPSegmentItemEnabledKey);
582    objj_msgSend(aCoder, "encodeInt:forKey:", tag, CPSegmentItemTagKey);
583    objj_msgSend(aCoder, "encodeFloat:forKey:", width, CPSegmentItemWidthKey);
584}
585})]);
586}
587