PageRenderTime 51ms CodeModel.GetById 18ms app.highlight 14ms RepoModel.GetById 2ms app.codeStats 0ms

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

http://github.com/jfahrenkrug/MapKit-HelloWorld
Unknown | 751 lines | 750 code | 1 blank | 0 comment | 0 complexity | 32c2b5910bf2eae2315809f8b76b4ff8 MD5 | raw file
  1I;20;Foundation/CPCoder.jI;21;Foundation/CPObject.jI;21;Foundation/CPString.jI;16;AppKit/CPImage.jI;15;AppKit/CPMenu.jI;15;AppKit/CPView.jc;32228;
  2{var the_class = objj_allocateClassPair(CPObject, "CPMenuItem"),
  3meta_class = the_class.isa;class_addIvars(the_class, [new objj_ivar("_title"), new objj_ivar("_font"), new objj_ivar("_target"), new objj_ivar("_action"), new objj_ivar("_isEnabled"), new objj_ivar("_isHidden"), new objj_ivar("_tag"), new objj_ivar("_state"), new objj_ivar("_image"), new objj_ivar("_alternateImage"), new objj_ivar("_onStateImage"), new objj_ivar("_offStateImage"), new objj_ivar("_mixedStateImage"), new objj_ivar("_submenu"), new objj_ivar("_menu"), new objj_ivar("_keyEquivalent"), new objj_ivar("_keyEquivalentModifierMask"), new objj_ivar("_mnemonicLocation"), new objj_ivar("_isAlternate"), new objj_ivar("_indentationLevel"), new objj_ivar("_toolTip"), new objj_ivar("_representedObject"), new objj_ivar("_view"), new objj_ivar("_menuItemView")]);
  4objj_registerClassPair(the_class);
  5objj_addClassForBundle(the_class, objj_getBundleWithPath(OBJJ_CURRENT_BUNDLE.path));
  6class_addMethods(the_class, [new objj_method(sel_getUid("initWithTitle:action:keyEquivalent:"), function $CPMenuItem__initWithTitle_action_keyEquivalent_(self, _cmd, aTitle, anAction, aKeyEquivalent)
  7{ with(self)
  8{
  9    self = objj_msgSendSuper({ receiver:self, super_class:objj_getClass("CPObject") }, "init");
 10    if (self)
 11    {
 12        _title = aTitle;
 13        _action = anAction;
 14        _isEnabled = YES;
 15        _tag = 0;
 16        _state = CPOffState;
 17        _keyEquivalent = aKeyEquivalent || "";
 18        _keyEquivalentModifierMask = CPPlatformActionKeyMask;
 19        _mnemonicLocation = CPNotFound;
 20    }
 21    return self;
 22}
 23}), new objj_method(sel_getUid("setEnabled:"), function $CPMenuItem__setEnabled_(self, _cmd, isEnabled)
 24{ with(self)
 25{
 26    if (objj_msgSend(_menu, "autoenablesItems"))
 27        return;
 28    _isEnabled = isEnabled;
 29    objj_msgSend(_menuItemView, "setDirty");
 30    objj_msgSend(_menu, "itemChanged:", self);
 31}
 32}), new objj_method(sel_getUid("isEnabled"), function $CPMenuItem__isEnabled(self, _cmd)
 33{ with(self)
 34{
 35    return _isEnabled;
 36}
 37}), new objj_method(sel_getUid("setHidden:"), function $CPMenuItem__setHidden_(self, _cmd, isHidden)
 38{ with(self)
 39{
 40    if (_isHidden == isHidden)
 41        return;
 42    _isHidden = isHidden;
 43    objj_msgSend(_menu, "itemChanged:", self);
 44}
 45}), new objj_method(sel_getUid("isHidden"), function $CPMenuItem__isHidden(self, _cmd)
 46{ with(self)
 47{
 48    return _isHidden;
 49}
 50}), new objj_method(sel_getUid("isHiddenOrHasHiddenAncestor"), function $CPMenuItem__isHiddenOrHasHiddenAncestor(self, _cmd)
 51{ with(self)
 52{
 53    if (_isHidden)
 54        return YES;
 55    var supermenu = objj_msgSend(_menu, "supermenu");
 56    if (objj_msgSend(objj_msgSend(supermenu, "itemAtIndex:", objj_msgSend(supermenu, "indexOfItemWithSubmenu:", _menu)), "isHiddenOrHasHiddenAncestor"))
 57        return YES;
 58    return NO;
 59}
 60}), new objj_method(sel_getUid("setTarget:"), function $CPMenuItem__setTarget_(self, _cmd, aTarget)
 61{ with(self)
 62{
 63    _target = aTarget;
 64}
 65}), new objj_method(sel_getUid("target"), function $CPMenuItem__target(self, _cmd)
 66{ with(self)
 67{
 68    return _target;
 69}
 70}), new objj_method(sel_getUid("setAction:"), function $CPMenuItem__setAction_(self, _cmd, anAction)
 71{ with(self)
 72{
 73    _action = anAction;
 74}
 75}), new objj_method(sel_getUid("action"), function $CPMenuItem__action(self, _cmd)
 76{ with(self)
 77{
 78    return _action;
 79}
 80}), new objj_method(sel_getUid("setTitle:"), function $CPMenuItem__setTitle_(self, _cmd, aTitle)
 81{ with(self)
 82{
 83    _mnemonicLocation = CPNotFound;
 84    if (_title == aTitle)
 85        return;
 86    _title = aTitle;
 87    objj_msgSend(_menuItemView, "setDirty");
 88    objj_msgSend(_menu, "itemChanged:", self);
 89}
 90}), new objj_method(sel_getUid("title"), function $CPMenuItem__title(self, _cmd)
 91{ with(self)
 92{
 93    return _title;
 94}
 95}), new objj_method(sel_getUid("setTextColor:"), function $CPMenuItem__setTextColor_(self, _cmd, aColor)
 96{ with(self)
 97{
 98}
 99}), new objj_method(sel_getUid("setFont:"), function $CPMenuItem__setFont_(self, _cmd, aFont)
100{ with(self)
101{
102    if (_font == aFont)
103        return;
104    _font = aFont;
105    objj_msgSend(_menu, "itemChanged:", self);
106    objj_msgSend(_menuItemView, "setDirty");
107}
108}), new objj_method(sel_getUid("font"), function $CPMenuItem__font(self, _cmd)
109{ with(self)
110{
111    return _font;
112}
113}), new objj_method(sel_getUid("setTag:"), function $CPMenuItem__setTag_(self, _cmd, aTag)
114{ with(self)
115{
116    _tag = aTag;
117}
118}), new objj_method(sel_getUid("tag"), function $CPMenuItem__tag(self, _cmd)
119{ with(self)
120{
121    return _tag;
122}
123}), new objj_method(sel_getUid("setState:"), function $CPMenuItem__setState_(self, _cmd, aState)
124{ with(self)
125{
126    if (_state == aState)
127        return;
128    _state = aState;
129    objj_msgSend(_menu, "itemChanged:", self);
130    objj_msgSend(_menuItemView, "setDirty");
131}
132}), new objj_method(sel_getUid("state"), function $CPMenuItem__state(self, _cmd)
133{ with(self)
134{
135    return _state;
136}
137}), new objj_method(sel_getUid("setImage:"), function $CPMenuItem__setImage_(self, _cmd, anImage)
138{ with(self)
139{
140    if (_image == anImage)
141        return;
142    _image = anImage;
143    objj_msgSend(_menuItemView, "setDirty");
144    objj_msgSend(_menu, "itemChanged:", self);
145}
146}), new objj_method(sel_getUid("image"), function $CPMenuItem__image(self, _cmd)
147{ with(self)
148{
149    return _image;
150}
151}), new objj_method(sel_getUid("setAlternateImage:"), function $CPMenuItem__setAlternateImage_(self, _cmd, anImage)
152{ with(self)
153{
154    _alternateImage = anImage;
155}
156}), new objj_method(sel_getUid("alternateImage"), function $CPMenuItem__alternateImage(self, _cmd)
157{ with(self)
158{
159    return _alternateImage;
160}
161}), new objj_method(sel_getUid("setOnStateImage:"), function $CPMenuItem__setOnStateImage_(self, _cmd, anImage)
162{ with(self)
163{
164    if (_onStateImage == anImage)
165        return;
166    _onStateImage = anImage;
167    objj_msgSend(_menu, "itemChanged:", self);
168}
169}), new objj_method(sel_getUid("onStateImage"), function $CPMenuItem__onStateImage(self, _cmd)
170{ with(self)
171{
172    return _onStateImage;
173}
174}), new objj_method(sel_getUid("setOffStateImage:"), function $CPMenuItem__setOffStateImage_(self, _cmd, anImage)
175{ with(self)
176{
177    if (_offStateImage == anImage)
178        return;
179    _offStateImage = anImage;
180    objj_msgSend(_menu, "itemChanged:", self);
181}
182}), new objj_method(sel_getUid("offStateImage"), function $CPMenuItem__offStateImage(self, _cmd)
183{ with(self)
184{
185    return _offStateImage;
186}
187}), new objj_method(sel_getUid("setMixedStateImage:"), function $CPMenuItem__setMixedStateImage_(self, _cmd, anImage)
188{ with(self)
189{
190    if (_mixedStateImage == anImage)
191        return;
192    _mixedStateImage = anImage;
193    objj_msgSend(_menu, "itemChanged:", self);
194}
195}), new objj_method(sel_getUid("mixedStateImage"), function $CPMenuItem__mixedStateImage(self, _cmd)
196{ with(self)
197{
198    return _mixedStateImage;
199}
200}), new objj_method(sel_getUid("setSubmenu:"), function $CPMenuItem__setSubmenu_(self, _cmd, aMenu)
201{ with(self)
202{
203    var supermenu = objj_msgSend(_submenu, "supermenu");
204    if (supermenu == self)
205        return;
206    if (supermenu)
207        return alert("bad");
208    objj_msgSend(_submenu, "setSupermenu:", _menu);
209    _submenu = aMenu;
210    objj_msgSend(_menuItemView, "setDirty");
211    objj_msgSend(_menu, "itemChanged:", self);
212}
213}), new objj_method(sel_getUid("submenu"), function $CPMenuItem__submenu(self, _cmd)
214{ with(self)
215{
216    return _submenu;
217}
218}), new objj_method(sel_getUid("hasSubmenu"), function $CPMenuItem__hasSubmenu(self, _cmd)
219{ with(self)
220{
221    return _submenu ? YES : NO;
222}
223}), new objj_method(sel_getUid("isSeparatorItem"), function $CPMenuItem__isSeparatorItem(self, _cmd)
224{ with(self)
225{
226    return NO;
227}
228}), new objj_method(sel_getUid("setMenu:"), function $CPMenuItem__setMenu_(self, _cmd, aMenu)
229{ with(self)
230{
231    _menu = aMenu;
232}
233}), new objj_method(sel_getUid("menu"), function $CPMenuItem__menu(self, _cmd)
234{ with(self)
235{
236    return _menu;
237}
238}), new objj_method(sel_getUid("setKeyEquivalent:"), function $CPMenuItem__setKeyEquivalent_(self, _cmd, aString)
239{ with(self)
240{
241    _keyEquivalent = aString || "";
242}
243}), new objj_method(sel_getUid("keyEquivalent"), function $CPMenuItem__keyEquivalent(self, _cmd)
244{ with(self)
245{
246    return _keyEquivalent;
247}
248}), new objj_method(sel_getUid("setKeyEquivalentModifierMask:"), function $CPMenuItem__setKeyEquivalentModifierMask_(self, _cmd, aMask)
249{ with(self)
250{
251    _keyEquivalentModifierMask = aMask;
252}
253}), new objj_method(sel_getUid("keyEquivalentModifierMask"), function $CPMenuItem__keyEquivalentModifierMask(self, _cmd)
254{ with(self)
255{
256    return _keyEquivalentModifierMask;
257}
258}), new objj_method(sel_getUid("setMnemonicLocation:"), function $CPMenuItem__setMnemonicLocation_(self, _cmd, aLocation)
259{ with(self)
260{
261    _mnemonicLocation = aLocation;
262}
263}), new objj_method(sel_getUid("mnemonicLocation"), function $CPMenuItem__mnemonicLocation(self, _cmd)
264{ with(self)
265{
266    return _mnemonicLocation;
267}
268}), new objj_method(sel_getUid("setTitleWithMnemonicLocation:"), function $CPMenuItem__setTitleWithMnemonicLocation_(self, _cmd, aTitle)
269{ with(self)
270{
271    var location = objj_msgSend(aTitle, "rangeOfString:", "&").location;
272    if (location == CPNotFound)
273        objj_msgSend(self, "setTitle:", aTitle);
274    else
275    {
276        objj_msgSend(self, "setTitle:", objj_msgSend(aTitle, "substringToIndex:", location) + objj_msgSend(aTitle, "substringFromIndex:", location + 1));
277        objj_msgSend(self, "setMnemonicLocation:", location);
278    }
279}
280}), new objj_method(sel_getUid("mnemonic"), function $CPMenuItem__mnemonic(self, _cmd)
281{ with(self)
282{
283    return _mnemonicLocation == CPNotFound ? "" : objj_msgSend(_title, "characterAtIndex:", _mnemonicLocation);
284}
285}), new objj_method(sel_getUid("setAlternate:"), function $CPMenuItem__setAlternate_(self, _cmd, isAlternate)
286{ with(self)
287{
288    _isAlternate = isAlternate;
289}
290}), new objj_method(sel_getUid("isAlternate"), function $CPMenuItem__isAlternate(self, _cmd)
291{ with(self)
292{
293    return _isAlternate;
294}
295}), new objj_method(sel_getUid("setIndentationLevel:"), function $CPMenuItem__setIndentationLevel_(self, _cmd, aLevel)
296{ with(self)
297{
298    if (aLevel < 0)
299        objj_msgSend(CPException, "raise:reason:", CPInvalidArgumentException, "setIndentationLevel: argument must be greater than 0.");
300    _indentationLevel = MIN(15, aLevel);
301}
302}), new objj_method(sel_getUid("indentationLevel"), function $CPMenuItem__indentationLevel(self, _cmd)
303{ with(self)
304{
305    return _indentationLevel;
306}
307}), new objj_method(sel_getUid("setToolTip:"), function $CPMenuItem__setToolTip_(self, _cmd, aToolTip)
308{ with(self)
309{
310    _toolTip = aToolTip;
311}
312}), new objj_method(sel_getUid("toolTip"), function $CPMenuItem__toolTip(self, _cmd)
313{ with(self)
314{
315    return _toolTip;
316}
317}), new objj_method(sel_getUid("setRepresentedObject:"), function $CPMenuItem__setRepresentedObject_(self, _cmd, anObject)
318{ with(self)
319{
320    _representedObject = anObject;
321}
322}), new objj_method(sel_getUid("representedObject"), function $CPMenuItem__representedObject(self, _cmd)
323{ with(self)
324{
325    return _representedObject;
326}
327}), new objj_method(sel_getUid("setView:"), function $CPMenuItem__setView_(self, _cmd, aView)
328{ with(self)
329{
330    if (_view === aView)
331        return;
332    _view = aView;
333    objj_msgSend(_menuItemView, "setDirty");
334    objj_msgSend(_menu, "itemChanged:", self);
335}
336}), new objj_method(sel_getUid("view"), function $CPMenuItem__view(self, _cmd)
337{ with(self)
338{
339    return _view;
340}
341}), new objj_method(sel_getUid("isHighlighted"), function $CPMenuItem__isHighlighted(self, _cmd)
342{ with(self)
343{
344    return objj_msgSend(objj_msgSend(self, "menu"), "highlightedItem") == self;
345}
346}), new objj_method(sel_getUid("_menuItemView"), function $CPMenuItem___menuItemView(self, _cmd)
347{ with(self)
348{
349    if (!_menuItemView)
350        _menuItemView = objj_msgSend(objj_msgSend(_CPMenuItemView, "alloc"), "initWithFrame:forMenuItem:", CGRectMakeZero(), self);
351    return _menuItemView;
352}
353})]);
354class_addMethods(meta_class, [new objj_method(sel_getUid("separatorItem"), function $CPMenuItem__separatorItem(self, _cmd)
355{ with(self)
356{
357    return objj_msgSend(objj_msgSend(_CPMenuItemSeparator, "alloc"), "init");
358}
359})]);
360}
361{var the_class = objj_allocateClassPair(CPMenuItem, "_CPMenuItemSeparator"),
362meta_class = the_class.isa;objj_registerClassPair(the_class);
363objj_addClassForBundle(the_class, objj_getBundleWithPath(OBJJ_CURRENT_BUNDLE.path));
364class_addMethods(the_class, [new objj_method(sel_getUid("init"), function $_CPMenuItemSeparator__init(self, _cmd)
365{ with(self)
366{
367    self = objj_msgSendSuper({ receiver:self, super_class:objj_getClass("CPMenuItem") }, "initWithTitle:action:keyEquivalent:", "", nil, nil);
368    if (self)
369        objj_msgSend(self, "setEnabled:", NO);
370    return self;
371}
372}), new objj_method(sel_getUid("isSeparatorItem"), function $_CPMenuItemSeparator__isSeparatorItem(self, _cmd)
373{ with(self)
374{
375    return YES;
376}
377})]);
378}
379var CPMenuItemTitleKey = "CPMenuItemTitleKey",
380    CPMenuItemTargetKey = "CPMenuItemTargetKey",
381    CPMenuItemActionKey = "CPMenuItemActionKey",
382    CPMenuItemIsEnabledKey = "CPMenuItemIsEnabledKey",
383    CPMenuItemIsHiddenKey = "CPMenuItemIsHiddenKey",
384    CPMenuItemTagKey = "CPMenuItemTagKey",
385    CPMenuItemStateKey = "CPMenuItemStateKey",
386    CPMenuItemImageKey = "CPMenuItemImageKey",
387    CPMenuItemAlternateImageKey = "CPMenuItemAlternateImageKey",
388    CPMenuItemSubmenuKey = "CPMenuItemSubmenuKey",
389    CPMenuItemMenuKey = "CPMenuItemMenuKey",
390    CPMenuItemRepresentedObjectKey = "CPMenuItemRepresentedObjectKey",
391    CPMenuItemViewKey = "CPMenuItemViewKey";
392{
393var the_class = objj_getClass("CPMenuItem")
394if(!the_class) objj_exception_throw(new objj_exception(OBJJClassNotFoundException, "*** Could not find definition for class \"CPMenuItem\""));
395var meta_class = the_class.isa;class_addMethods(the_class, [new objj_method(sel_getUid("initWithCoder:"), function $CPMenuItem__initWithCoder_(self, _cmd, aCoder)
396{ with(self)
397{
398    self = objj_msgSendSuper({ receiver:self, super_class:objj_getClass("CPObject") }, "init");
399    if (self)
400    {
401        _title = objj_msgSend(aCoder, "decodeObjectForKey:", CPMenuItemTitleKey);
402        _target = objj_msgSend(aCoder, "decodeObjectForKey:", CPMenuItemTargetKey);
403        _action = objj_msgSend(aCoder, "decodeObjectForKey:", CPMenuItemActionKey);
404        _isEnabled = objj_msgSend(aCoder, "containsValueForKey:", (CPMenuItemIsEnabledKey)) ? objj_msgSend(aCoder, "decodeObjectForKey:", (CPMenuItemIsEnabledKey)) : (YES);
405        _isHidden = objj_msgSend(aCoder, "containsValueForKey:", (CPMenuItemIsHiddenKey)) ? objj_msgSend(aCoder, "decodeObjectForKey:", (CPMenuItemIsHiddenKey)) : (NO);
406        _tag = objj_msgSend(aCoder, "containsValueForKey:", (CPMenuItemTagKey)) ? objj_msgSend(aCoder, "decodeObjectForKey:", (CPMenuItemTagKey)) : (0);
407        _state = objj_msgSend(aCoder, "containsValueForKey:", (CPMenuItemStateKey)) ? objj_msgSend(aCoder, "decodeObjectForKey:", (CPMenuItemStateKey)) : (CPOffState);
408        _image = objj_msgSend(aCoder, "containsValueForKey:", (CPMenuItemImageKey)) ? objj_msgSend(aCoder, "decodeObjectForKey:", (CPMenuItemImageKey)) : (nil);
409        _alternateImage = objj_msgSend(aCoder, "containsValueForKey:", (CPMenuItemAlternateImageKey)) ? objj_msgSend(aCoder, "decodeObjectForKey:", (CPMenuItemAlternateImageKey)) : (nil);
410        _submenu = objj_msgSend(aCoder, "containsValueForKey:", (CPMenuItemSubmenuKey)) ? objj_msgSend(aCoder, "decodeObjectForKey:", (CPMenuItemSubmenuKey)) : (nil);
411        _menu = objj_msgSend(aCoder, "containsValueForKey:", (CPMenuItemMenuKey)) ? objj_msgSend(aCoder, "decodeObjectForKey:", (CPMenuItemMenuKey)) : (nil);
412        _representedObject = objj_msgSend(aCoder, "containsValueForKey:", (CPMenuItemRepresentedObjectKey)) ? objj_msgSend(aCoder, "decodeObjectForKey:", (CPMenuItemRepresentedObjectKey)) : (nil);
413        _view = objj_msgSend(aCoder, "containsValueForKey:", (CPMenuItemViewKey)) ? objj_msgSend(aCoder, "decodeObjectForKey:", (CPMenuItemViewKey)) : (nil);
414    }
415    return self;
416}
417}), new objj_method(sel_getUid("encodeWithCoder:"), function $CPMenuItem__encodeWithCoder_(self, _cmd, aCoder)
418{ with(self)
419{
420    objj_msgSend(aCoder, "encodeObject:forKey:", _title, CPMenuItemTitleKey);
421    objj_msgSend(aCoder, "encodeObject:forKey:", _target, CPMenuItemTargetKey);
422    objj_msgSend(aCoder, "encodeObject:forKey:", _action, CPMenuItemActionKey);
423    if ((_isEnabled) !== (YES)) objj_msgSend(aCoder, "encodeObject:forKey:", (_isEnabled), (CPMenuItemIsEnabledKey));;
424    if ((_isHidden) !== (NO)) objj_msgSend(aCoder, "encodeObject:forKey:", (_isHidden), (CPMenuItemIsHiddenKey));;
425    if ((_tag) !== (0)) objj_msgSend(aCoder, "encodeObject:forKey:", (_tag), (CPMenuItemTagKey));;
426    if ((_state) !== (CPOffState)) objj_msgSend(aCoder, "encodeObject:forKey:", (_state), (CPMenuItemStateKey));;
427    if ((_image) !== (nil)) objj_msgSend(aCoder, "encodeObject:forKey:", (_image), (CPMenuItemImageKey));;
428    if ((_alternateImage) !== (nil)) objj_msgSend(aCoder, "encodeObject:forKey:", (_alternateImage), (CPMenuItemAlternateImageKey));;
429    if ((_submenu) !== (nil)) objj_msgSend(aCoder, "encodeObject:forKey:", (_submenu), (CPMenuItemSubmenuKey));;
430    if ((_menu) !== (nil)) objj_msgSend(aCoder, "encodeObject:forKey:", (_menu), (CPMenuItemMenuKey));;
431    if ((_representedObject) !== (nil)) objj_msgSend(aCoder, "encodeObject:forKey:", (_representedObject), (CPMenuItemRepresentedObjectKey));;
432    if ((_view) !== (nil)) objj_msgSend(aCoder, "encodeObject:forKey:", (_view), (CPMenuItemViewKey));;
433}
434})]);
435}
436var LEFT_MARGIN = 3.0,
437    RIGHT_MARGIN = 16.0,
438    STATE_COLUMN_WIDTH = 14.0,
439    INDENTATION_WIDTH = 17.0,
440    VERTICAL_MARGIN = 4.0;
441var _CPMenuItemSelectionColor = nil,
442    _CPMenuItemTextShadowColor = nil,
443    _CPMenuItemDefaultStateImages = [],
444    _CPMenuItemDefaultStateHighlightedImages = [];
445{var the_class = objj_allocateClassPair(CPView, "_CPMenuItemView"),
446meta_class = the_class.isa;class_addIvars(the_class, [new objj_ivar("_menuItem"), new objj_ivar("_font"), new objj_ivar("_textColor"), new objj_ivar("_textShadowColor"), new objj_ivar("_activateColor"), new objj_ivar("_activateShadowColor"), new objj_ivar("_minSize"), new objj_ivar("_isDirty"), new objj_ivar("_showsStateColumn"), new objj_ivar("_belongsToMenuBar"), new objj_ivar("_stateView"), new objj_ivar("_imageAndTextView"), new objj_ivar("_submenuView")]);
447objj_registerClassPair(the_class);
448objj_addClassForBundle(the_class, objj_getBundleWithPath(OBJJ_CURRENT_BUNDLE.path));
449class_addMethods(the_class, [new objj_method(sel_getUid("initWithFrame:forMenuItem:"), function $_CPMenuItemView__initWithFrame_forMenuItem_(self, _cmd, aFrame, aMenuItem)
450{ with(self)
451{
452    self = objj_msgSendSuper({ receiver:self, super_class:objj_getClass("CPView") }, "initWithFrame:", aFrame);
453    if (self)
454    {
455        _menuItem = aMenuItem;
456        _showsStateColumn = YES;
457        _isDirty = YES;
458        objj_msgSend(self, "setAutoresizingMask:", CPViewWidthSizable);
459        objj_msgSend(self, "synchronizeWithMenuItem");
460    }
461    return self;
462}
463}), new objj_method(sel_getUid("minSize"), function $_CPMenuItemView__minSize(self, _cmd)
464{ with(self)
465{
466    return _minSize;
467}
468}), new objj_method(sel_getUid("setDirty"), function $_CPMenuItemView__setDirty(self, _cmd)
469{ with(self)
470{
471    _isDirty = YES;
472}
473}), new objj_method(sel_getUid("synchronizeWithMenuItem"), function $_CPMenuItemView__synchronizeWithMenuItem(self, _cmd)
474{ with(self)
475{
476    if (!_isDirty)
477        return;
478    _isDirty = NO;
479    var view = objj_msgSend(_menuItem, "view");
480    if (objj_msgSend(_menuItem, "isSeparatorItem"))
481    {
482        var line = objj_msgSend(objj_msgSend(CPView, "alloc"), "initWithFrame:", CGRectMake(0.0, 5.0, 10.0, 1.0));
483        view = objj_msgSend(objj_msgSend(CPView, "alloc"), "initWithFrame:", CGRectMake(0.0, 0.0, 0.0, 10.0));
484        objj_msgSend(view, "setAutoresizingMask:", CPViewWidthSizable);
485        objj_msgSend(line, "setAutoresizingMask:", CPViewWidthSizable);
486        objj_msgSend(line, "setBackgroundColor:", objj_msgSend(CPColor, "lightGrayColor"));
487        objj_msgSend(view, "addSubview:", line);
488    }
489    if (view)
490    {
491        objj_msgSend(_imageAndTextView, "removeFromSuperview");
492        _imageAndTextView = nil;
493        objj_msgSend(_stateView, "removeFromSuperview");
494        _stateView = nil;
495        objj_msgSend(_submenuView, "removeFromSuperview");
496        _submenuView = nil;
497        _minSize = objj_msgSend(view, "frame").size;
498        objj_msgSend(self, "setFrameSize:", _minSize);
499        objj_msgSend(self, "addSubview:", view);
500        return;
501    }
502    var x = _belongsToMenuBar ? 0.0 : (LEFT_MARGIN + objj_msgSend(_menuItem, "indentationLevel") * INDENTATION_WIDTH);
503    if (_showsStateColumn)
504    {
505        if (!_stateView)
506        {
507            _stateView = objj_msgSend(objj_msgSend(CPImageView, "alloc"), "initWithFrame:", CGRectMake(x, (CGRectGetHeight(objj_msgSend(self, "frame")) - STATE_COLUMN_WIDTH) / 2.0, STATE_COLUMN_WIDTH, STATE_COLUMN_WIDTH));
508            objj_msgSend(_stateView, "setAutoresizingMask:", CPViewMinYMargin | CPViewMaxYMargin);
509            objj_msgSend(self, "addSubview:", _stateView);
510        }
511        var state = objj_msgSend(_menuItem, "state");
512        switch (state)
513        {
514            case CPOffState:
515            case CPOnState:
516            case CPMixedState: objj_msgSend(_stateView, "setImage:", _CPMenuItemDefaultStateImages[state]);
517                                break;
518            default: objj_msgSend(_stateView, "setImage:", nil);
519        }
520        x += STATE_COLUMN_WIDTH;
521    }
522    else
523    {
524        objj_msgSend(_stateView, "removeFromSuperview");
525        _stateView = nil;
526    }
527    if (!_imageAndTextView)
528    {
529        _imageAndTextView = objj_msgSend(objj_msgSend(_CPImageAndTextView, "alloc"), "initWithFrame:", CGRectMake(0.0, 0.0, 0.0, 0.0));
530        objj_msgSend(_imageAndTextView, "setImagePosition:", CPImageLeft);
531        objj_msgSend(_imageAndTextView, "setTextShadowOffset:", CGSizeMake(0.0, 1.0));
532        objj_msgSend(self, "addSubview:", _imageAndTextView);
533    }
534    var font = objj_msgSend(_menuItem, "font");
535    if (!font)
536        font = _font;
537    objj_msgSend(_imageAndTextView, "setFont:", font);
538    objj_msgSend(_imageAndTextView, "setVerticalAlignment:", CPCenterVerticalTextAlignment);
539    objj_msgSend(_imageAndTextView, "setImage:", objj_msgSend(_menuItem, "image"));
540    objj_msgSend(_imageAndTextView, "setText:", objj_msgSend(_menuItem, "title"));
541    objj_msgSend(_imageAndTextView, "setTextColor:", objj_msgSend(self, "textColor"));
542    objj_msgSend(_imageAndTextView, "setTextShadowColor:", objj_msgSend(self, "textShadowColor"));
543    objj_msgSend(_imageAndTextView, "setTextShadowOffset:", CGSizeMake(0, 1));
544    objj_msgSend(_imageAndTextView, "setFrameOrigin:", CGPointMake(x, VERTICAL_MARGIN));
545    objj_msgSend(_imageAndTextView, "sizeToFit");
546    var frame = objj_msgSend(_imageAndTextView, "frame");
547    frame.size.height += 2 * VERTICAL_MARGIN;
548    x += CGRectGetWidth(frame);
549    if (objj_msgSend(_menuItem, "hasSubmenu"))
550    {
551        x += 3.0;
552        if (!_submenuView)
553        {
554            _submenuView = objj_msgSend(objj_msgSend(_CPMenuItemArrowView, "alloc"), "initWithFrame:", CGRectMake(0.0, 0.0, 10.0, 10.0));
555            objj_msgSend(self, "addSubview:", _submenuView);
556        }
557        objj_msgSend(_submenuView, "setHidden:", NO);
558        objj_msgSend(_submenuView, "setColor:", _belongsToMenuBar ? objj_msgSend(self, "textColor") : nil);
559        objj_msgSend(_submenuView, "setFrameOrigin:", CGPointMake(x, (CGRectGetHeight(frame) - 10.0) / 2.0));
560        x += 10.0;
561    }
562    else
563        objj_msgSend(_submenuView, "setHidden:", YES);
564    _minSize = CGSizeMake(x + (_belongsToMenuBar ? 0.0 : RIGHT_MARGIN) + 3.0, CGRectGetHeight(frame));
565    objj_msgSend(self, "setFrameSize:", _minSize);
566}
567}), new objj_method(sel_getUid("overlapOffsetWidth"), function $_CPMenuItemView__overlapOffsetWidth(self, _cmd)
568{ with(self)
569{
570    return LEFT_MARGIN + (objj_msgSend(objj_msgSend(_menuItem, "menu"), "showsStateColumn") ? STATE_COLUMN_WIDTH : 0.0);
571}
572}), new objj_method(sel_getUid("setShowsStateColumn:"), function $_CPMenuItemView__setShowsStateColumn_(self, _cmd, shouldShowStateColumn)
573{ with(self)
574{
575    _showsStateColumn = shouldShowStateColumn;
576}
577}), new objj_method(sel_getUid("setBelongsToMenuBar:"), function $_CPMenuItemView__setBelongsToMenuBar_(self, _cmd, shouldBelongToMenuBar)
578{ with(self)
579{
580    _belongsToMenuBar = shouldBelongToMenuBar;
581}
582}), new objj_method(sel_getUid("highlight:"), function $_CPMenuItemView__highlight_(self, _cmd, shouldHighlight)
583{ with(self)
584{
585    if (_belongsToMenuBar)
586        objj_msgSend(_imageAndTextView, "setImage:", shouldHighlight ? objj_msgSend(_menuItem, "alternateImage") : objj_msgSend(_menuItem, "image"));
587    else if (objj_msgSend(_menuItem, "isEnabled"))
588    {
589        if (shouldHighlight)
590        {
591            objj_msgSend(self, "setBackgroundColor:", _CPMenuItemSelectionColor);
592            objj_msgSend(_imageAndTextView, "setTextColor:", objj_msgSend(CPColor, "whiteColor"));
593            objj_msgSend(_imageAndTextView, "setTextShadowColor:", _CPMenuItemTextShadowColor);
594        }
595        else
596        {
597            objj_msgSend(self, "setBackgroundColor:", nil);
598            objj_msgSend(_imageAndTextView, "setTextColor:", objj_msgSend(self, "textColor"));
599            objj_msgSend(_imageAndTextView, "setTextShadowColor:", objj_msgSend(self, "textShadowColor"));
600        }
601        var state = objj_msgSend(_menuItem, "state");
602        switch (state)
603        {
604            case CPOffState:
605            case CPOnState:
606            case CPMixedState: objj_msgSend(_stateView, "setImage:", shouldHighlight ? _CPMenuItemDefaultStateHighlightedImages[state] : _CPMenuItemDefaultStateImages[state]);
607                            break;
608            default: objj_msgSend(_stateView, "setImage:", nil);
609        }
610    }
611}
612}), new objj_method(sel_getUid("activate:"), function $_CPMenuItemView__activate_(self, _cmd, shouldActivate)
613{ with(self)
614{
615    objj_msgSend(_imageAndTextView, "setImage:", objj_msgSend(_menuItem, "image"));
616    if (shouldActivate)
617    {
618        objj_msgSend(_imageAndTextView, "setTextColor:", objj_msgSend(self, "activateColor") || objj_msgSend(CPColor, "whiteColor"));
619        objj_msgSend(_imageAndTextView, "setTextShadowColor:", objj_msgSend(self, "activateShadowColor") || objj_msgSend(CPColor, "blackColor"));
620        objj_msgSend(_submenuView, "setColor:", objj_msgSend(self, "activateColor") || objj_msgSend(CPColor, "whiteColor"));
621    }
622    else
623    {
624        objj_msgSend(_imageAndTextView, "setTextColor:", objj_msgSend(self, "textColor"));
625        objj_msgSend(_imageAndTextView, "setTextShadowColor:", objj_msgSend(self, "textShadowColor"));
626        objj_msgSend(_submenuView, "setColor:", objj_msgSend(self, "textColor"));
627    }
628}
629}), new objj_method(sel_getUid("eventOnSubmenu:"), function $_CPMenuItemView__eventOnSubmenu_(self, _cmd, anEvent)
630{ with(self)
631{
632    if (!objj_msgSend(_menuItem, "hasSubmenu"))
633        return NO;
634    return CGRectContainsPoint(objj_msgSend(_submenuView, "frame"), objj_msgSend(self, "convertPoint:fromView:", objj_msgSend(anEvent, "locationInWindow"), nil));
635}
636}), new objj_method(sel_getUid("isHidden"), function $_CPMenuItemView__isHidden(self, _cmd)
637{ with(self)
638{
639    return objj_msgSend(_menuItem, "isHidden");
640}
641}), new objj_method(sel_getUid("menuItem"), function $_CPMenuItemView__menuItem(self, _cmd)
642{ with(self)
643{
644    return _menuItem;
645}
646}), new objj_method(sel_getUid("setFont:"), function $_CPMenuItemView__setFont_(self, _cmd, aFont)
647{ with(self)
648{
649    if (_font == aFont)
650        return;
651    _font = aFont;
652    objj_msgSend(self, "setDirty");
653}
654}), new objj_method(sel_getUid("setTextColor:"), function $_CPMenuItemView__setTextColor_(self, _cmd, aColor)
655{ with(self)
656{
657    if (_textColor == aColor)
658        return;
659    _textColor = aColor;
660    objj_msgSend(_imageAndTextView, "setTextColor:", objj_msgSend(self, "textColor"));
661    objj_msgSend(_submenuView, "setColor:", objj_msgSend(self, "textColor"));
662}
663}), new objj_method(sel_getUid("textColor"), function $_CPMenuItemView__textColor(self, _cmd)
664{ with(self)
665{
666    return objj_msgSend(_menuItem, "isEnabled") ? (_textColor ? _textColor : objj_msgSend(CPColor, "colorWithCalibratedRed:green:blue:alpha:", 70.0 / 255.0, 69.0 / 255.0, 69.0 / 255.0, 1.0)) : objj_msgSend(CPColor, "darkGrayColor");
667}
668}), new objj_method(sel_getUid("setTextShadowColor:"), function $_CPMenuItemView__setTextShadowColor_(self, _cmd, aColor)
669{ with(self)
670{
671    if (_textShadowColor == aColor)
672        return;
673    _textShadowColor = aColor;
674    objj_msgSend(_imageAndTextView, "setTextShadowColor:", objj_msgSend(self, "textShadowColor"));
675}
676}), new objj_method(sel_getUid("textShadowColor"), function $_CPMenuItemView__textShadowColor(self, _cmd)
677{ with(self)
678{
679    return objj_msgSend(_menuItem, "isEnabled") ? (_textShadowColor ? _textShadowColor : objj_msgSend(CPColor, "colorWithWhite:alpha:", 1.0, 0.8)) : objj_msgSend(CPColor, "colorWithWhite:alpha:", 0.8, 0.8);
680}
681}), new objj_method(sel_getUid("setActivateColor:"), function $_CPMenuItemView__setActivateColor_(self, _cmd, aColor)
682{ with(self)
683{
684    _activateColor = aColor;
685}
686}), new objj_method(sel_getUid("activateColor"), function $_CPMenuItemView__activateColor(self, _cmd)
687{ with(self)
688{
689    return _activateColor;
690}
691}), new objj_method(sel_getUid("setActivateShadowColor:"), function $_CPMenuItemView__setActivateShadowColor_(self, _cmd, aColor)
692{ with(self)
693{
694    _activateShadowColor = aColor;
695}
696}), new objj_method(sel_getUid("activateShadowColor"), function $_CPMenuItemView__activateShadowColor(self, _cmd)
697{ with(self)
698{
699    return _activateShadowColor;
700}
701})]);
702class_addMethods(meta_class, [new objj_method(sel_getUid("initialize"), function $_CPMenuItemView__initialize(self, _cmd)
703{ with(self)
704{
705    if (self != objj_msgSend(_CPMenuItemView, "class"))
706        return;
707    _CPMenuItemSelectionColor = objj_msgSend(CPColor, "colorWithCalibratedRed:green:blue:alpha:", 95.0 / 255.0, 131.0 / 255.0, 185.0 / 255.0, 1.0);
708    _CPMenuItemTextShadowColor = objj_msgSend(CPColor, "colorWithCalibratedRed:green:blue:alpha:", 26.0 / 255.0,  73.0 / 255.0, 109.0 / 255.0, 1.0)
709    var bundle = objj_msgSend(CPBundle, "bundleForClass:", self);
710    _CPMenuItemDefaultStateImages[CPOffState] = nil;
711    _CPMenuItemDefaultStateHighlightedImages[CPOffState] = nil;
712    _CPMenuItemDefaultStateImages[CPOnState] = objj_msgSend(objj_msgSend(CPImage, "alloc"), "initWithContentsOfFile:size:", objj_msgSend(bundle, "pathForResource:", "CPMenuItem/CPMenuItemOnState.png"), CGSizeMake(14.0, 14.0));
713    _CPMenuItemDefaultStateHighlightedImages[CPOnState] = objj_msgSend(objj_msgSend(CPImage, "alloc"), "initWithContentsOfFile:size:", objj_msgSend(bundle, "pathForResource:", "CPMenuItem/CPMenuItemOnStateHighlighted.png"), CGSizeMake(14.0, 14.0));
714    _CPMenuItemDefaultStateImages[CPMixedState] = nil;
715    _CPMenuItemDefaultStateHighlightedImages[CPMixedState] = nil;
716}
717}), new objj_method(sel_getUid("leftMargin"), function $_CPMenuItemView__leftMargin(self, _cmd)
718{ with(self)
719{
720    return LEFT_MARGIN + STATE_COLUMN_WIDTH;
721}
722})]);
723}
724{var the_class = objj_allocateClassPair(CPView, "_CPMenuItemArrowView"),
725meta_class = the_class.isa;class_addIvars(the_class, [new objj_ivar("_color")]);
726objj_registerClassPair(the_class);
727objj_addClassForBundle(the_class, objj_getBundleWithPath(OBJJ_CURRENT_BUNDLE.path));
728class_addMethods(the_class, [new objj_method(sel_getUid("setColor:"), function $_CPMenuItemArrowView__setColor_(self, _cmd, aColor)
729{ with(self)
730{
731    if (_color == aColor)
732        return;
733    _color = aColor;
734    objj_msgSend(self, "setNeedsDisplay:", YES);
735}
736}), new objj_method(sel_getUid("drawRect:"), function $_CPMenuItemArrowView__drawRect_(self, _cmd, aRect)
737{ with(self)
738{
739    var context = objj_msgSend(objj_msgSend(CPGraphicsContext, "currentContext"), "graphicsPort");
740    CGContextBeginPath(context);
741    CGContextMoveToPoint(context, 1.0, 4.0);
742    CGContextAddLineToPoint(context, 9.0, 4.0);
743    CGContextAddLineToPoint(context, 5.0, 8.0);
744    CGContextAddLineToPoint(context, 1.0, 4.0);
745    CGContextClosePath(context);
746    CGContextSetFillColor(context, _color);
747    CGContextFillPath(context);
748}
749})]);
750}
751