PageRenderTime 509ms CodeModel.GetById 494ms app.highlight 8ms RepoModel.GetById 1ms app.codeStats 0ms

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

http://github.com/jfahrenkrug/MapKit-HelloWorld
Unknown | 627 lines | 626 code | 1 blank | 0 comment | 0 complexity | 3c2071f064bf2f7e4c3ea0e3079937db MD5 | raw file
  1i;11;CPControl.ji;17;CPStringDrawing.ji;17;CPCompatibility.jc;31053;
  2CPLineBreakByWordWrapping = 0;
  3CPLineBreakByCharWrapping = 1;
  4CPLineBreakByClipping = 2;
  5CPLineBreakByTruncatingHead = 3;
  6CPLineBreakByTruncatingTail = 4;
  7CPLineBreakByTruncatingMiddle = 5;
  8CPTextFieldSquareBezel = 0;
  9CPTextFieldRoundedBezel = 1;
 10var CPTextFieldDOMInputElement = nil,
 11    CPTextFieldDOMPasswordInputElement = nil,
 12    CPTextFieldDOMStandardInputElement = nil,
 13    CPTextFieldInputOwner = nil,
 14    CPTextFieldTextDidChangeValue = nil,
 15    CPTextFieldInputResigning = NO,
 16    CPTextFieldInputDidBlur = NO,
 17    CPTextFieldInputIsActive = NO,
 18    CPTextFieldCachedSelectStartFunction = nil,
 19    CPTextFieldCachedDragFunction = nil,
 20    CPTextFieldBlurFunction = nil,
 21    CPTextFieldKeyUpFunction = nil,
 22    CPTextFieldKeyPressFunction = nil,
 23    CPTextFieldKeyDownFunction = nil;
 24var CPSecureTextFieldCharacter = "\u2022";
 25{
 26var the_class = objj_getClass("CPString")
 27if(!the_class) objj_exception_throw(new objj_exception(OBJJClassNotFoundException, "*** Could not find definition for class \"CPString\""));
 28var meta_class = the_class.isa;class_addMethods(the_class, [new objj_method(sel_getUid("string"), function $CPString__string(self, _cmd)
 29{ with(self)
 30{
 31    return self;
 32}
 33})]);
 34}
 35CPTextFieldStateRounded = CPThemeState("rounded");
 36CPTextFieldStatePlaceholder = CPThemeState("placeholder");
 37{var the_class = objj_allocateClassPair(CPControl, "CPTextField"),
 38meta_class = the_class.isa;class_addIvars(the_class, [new objj_ivar("_isEditable"), new objj_ivar("_isSelectable"), new objj_ivar("_isSecure"), new objj_ivar("_drawsBackground"), new objj_ivar("_textFieldBackgroundColor"), new objj_ivar("_placeholderString"), new objj_ivar("_delegate"), new objj_ivar("_textDidChangeValue"), new objj_ivar("_bezelStyle"), new objj_ivar("_isBordered"), new objj_ivar("_controlSize")]);
 39objj_registerClassPair(the_class);
 40objj_addClassForBundle(the_class, objj_getBundleWithPath(OBJJ_CURRENT_BUNDLE.path));
 41class_addMethods(the_class, [new objj_method(sel_getUid("_inputElement"), function $CPTextField___inputElement(self, _cmd)
 42{ with(self)
 43{
 44    if (!CPTextFieldDOMInputElement)
 45    {
 46        CPTextFieldDOMInputElement = document.createElement("input");
 47        CPTextFieldDOMInputElement.style.position = "absolute";
 48        CPTextFieldDOMInputElement.style.border = "0px";
 49        CPTextFieldDOMInputElement.style.padding = "0px";
 50        CPTextFieldDOMInputElement.style.margin = "0px";
 51        CPTextFieldDOMInputElement.style.whiteSpace = "pre";
 52        CPTextFieldDOMInputElement.style.background = "transparent";
 53        CPTextFieldDOMInputElement.style.outline = "none";
 54        CPTextFieldBlurFunction = function(anEvent)
 55        {
 56            if (CPTextFieldInputOwner && CPTextFieldInputOwner._DOMElement != CPTextFieldDOMInputElement.parentNode)
 57                return;
 58            if (!CPTextFieldInputResigning)
 59            {
 60                objj_msgSend(objj_msgSend(CPTextFieldInputOwner, "window"), "makeFirstResponder:", nil);
 61                return;
 62            }
 63            CPTextFieldHandleBlur(anEvent, CPTextFieldDOMInputElement);
 64            CPTextFieldInputDidBlur = YES;
 65            return true;
 66        }
 67        CPTextFieldKeyDownFunction = function(anEvent)
 68        {
 69            CPTextFieldTextDidChangeValue = objj_msgSend(CPTextFieldInputOwner, "stringValue");
 70            CPTextFieldKeyPressFunction(anEvent);
 71            return true;
 72        }
 73        CPTextFieldKeyPressFunction = function(aDOMEvent)
 74        {
 75            aDOMEvent = aDOMEvent || window.event;
 76            if (aDOMEvent.keyCode == CPReturnKeyCode || aDOMEvent.keyCode == CPTabKeyCode)
 77            {
 78                if (aDOMEvent.preventDefault)
 79                    aDOMEvent.preventDefault();
 80                if (aDOMEvent.stopPropagation)
 81                    aDOMEvent.stopPropagation();
 82                aDOMEvent.cancelBubble = true;
 83                var owner = CPTextFieldInputOwner;
 84                if (aDOMEvent && aDOMEvent.keyCode == CPReturnKeyCode)
 85                {
 86                    objj_msgSend(owner, "sendAction:to:", objj_msgSend(owner, "action"), objj_msgSend(owner, "target"));
 87                    objj_msgSend(objj_msgSend(owner, "window"), "makeFirstResponder:", nil);
 88                }
 89                else if (aDOMEvent && aDOMEvent.keyCode == CPTabKeyCode)
 90                {
 91                    if (!aDOMEvent.shiftKey)
 92                        objj_msgSend(objj_msgSend(owner, "window"), "selectNextKeyView:", owner);
 93                    else
 94                        objj_msgSend(objj_msgSend(owner, "window"), "selectPreviousKeyView:", owner);
 95                }
 96            }
 97            objj_msgSend(objj_msgSend(CPRunLoop, "currentRunLoop"), "limitDateForMode:", CPDefaultRunLoopMode);
 98        }
 99        CPTextFieldKeyUpFunction = function()
100        {
101            objj_msgSend(CPTextFieldInputOwner, "setStringValue:", CPTextFieldDOMInputElement.value);
102            if (objj_msgSend(CPTextFieldInputOwner, "stringValue") !== CPTextFieldTextDidChangeValue)
103            {
104                CPTextFieldTextDidChangeValue = objj_msgSend(CPTextFieldInputOwner, "stringValue");
105                objj_msgSend(CPTextFieldInputOwner, "textDidChange:", objj_msgSend(CPNotification, "notificationWithName:object:userInfo:", CPControlTextDidChangeNotification, CPTextFieldInputOwner, nil));
106            }
107            objj_msgSend(objj_msgSend(CPRunLoop, "currentRunLoop"), "limitDateForMode:", CPDefaultRunLoopMode);
108        }
109        CPTextFieldHandleBlur = function(anEvent)
110        {
111            var owner = CPTextFieldInputOwner;
112            CPTextFieldInputOwner = nil;
113            objj_msgSend(objj_msgSend(CPRunLoop, "currentRunLoop"), "limitDateForMode:", CPDefaultRunLoopMode);
114        }
115        if (document.attachEvent)
116        {
117            CPTextFieldDOMInputElement.attachEvent("on" + CPDOMEventKeyUp, CPTextFieldKeyUpFunction);
118            CPTextFieldDOMInputElement.attachEvent("on" + CPDOMEventKeyDown, CPTextFieldKeyDownFunction);
119            CPTextFieldDOMInputElement.attachEvent("on" + CPDOMEventKeyPress, CPTextFieldKeyPressFunction);
120        }
121        else
122        {
123            CPTextFieldDOMInputElement.addEventListener(CPDOMEventKeyUp, CPTextFieldKeyUpFunction, NO);
124            CPTextFieldDOMInputElement.addEventListener(CPDOMEventKeyDown, CPTextFieldKeyDownFunction, NO);
125            CPTextFieldDOMInputElement.addEventListener(CPDOMEventKeyPress, CPTextFieldKeyPressFunction, NO);
126        }
127        CPTextFieldDOMInputElement.onblur = CPTextFieldBlurFunction;
128        CPTextFieldDOMStandardInputElement = CPTextFieldDOMInputElement;
129    }
130    if (CPFeatureIsCompatible(CPInputTypeCanBeChangedFeature))
131    {
132        if (objj_msgSend(self, "isSecure"))
133            CPTextFieldDOMInputElement.type = "password";
134        else
135            CPTextFieldDOMInputElement.type = "text";
136        return CPTextFieldDOMInputElement;
137    }
138    if (objj_msgSend(self, "isSecure"))
139    {
140        if (!CPTextFieldDOMPasswordInputElement)
141        {
142            CPTextFieldDOMPasswordInputElement = document.createElement("input");
143            CPTextFieldDOMPasswordInputElement.style.position = "absolute";
144            CPTextFieldDOMPasswordInputElement.style.border = "0px";
145            CPTextFieldDOMPasswordInputElement.style.padding = "0px";
146            CPTextFieldDOMPasswordInputElement.style.margin = "0px";
147            CPTextFieldDOMPasswordInputElement.style.whiteSpace = "pre";
148            CPTextFieldDOMPasswordInputElement.style.background = "transparent";
149            CPTextFieldDOMPasswordInputElement.style.outline = "none";
150            CPTextFieldDOMPasswordInputElement.type = "password";
151            CPTextFieldDOMPasswordInputElement.attachEvent("on" + CPDOMEventKeyUp, CPTextFieldKeyUpFunction);
152            CPTextFieldDOMPasswordInputElement.attachEvent("on" + CPDOMEventKeyDown, CPTextFieldKeyDownFunction);
153            CPTextFieldDOMPasswordInputElement.attachEvent("on" + CPDOMEventKeyPress, CPTextFieldKeyPressFunction);
154            CPTextFieldDOMPasswordInputElement.onblur = CPTextFieldBlurFunction;
155        }
156        CPTextFieldDOMInputElement = CPTextFieldDOMPasswordInputElement;
157    }
158    else
159    {
160        CPTextFieldDOMInputElement = CPTextFieldDOMStandardInputElement;
161    }
162    return CPTextFieldDOMInputElement;
163}
164}), new objj_method(sel_getUid("initWithFrame:"), function $CPTextField__initWithFrame_(self, _cmd, aFrame)
165{ with(self)
166{
167    self = objj_msgSendSuper({ receiver:self, super_class:objj_getClass("CPControl") }, "initWithFrame:", aFrame);
168    if (self)
169    {
170        objj_msgSend(self, "setStringValue:", "");
171        objj_msgSend(self, "setPlaceholderString:", "");
172        _sendActionOn = CPKeyUpMask | CPKeyDownMask;
173        objj_msgSend(self, "setValue:forThemeAttribute:", CPLeftTextAlignment, "alignment");
174    }
175    return self;
176}
177}), new objj_method(sel_getUid("setEditable:"), function $CPTextField__setEditable_(self, _cmd, shouldBeEditable)
178{ with(self)
179{
180    _isEditable = shouldBeEditable;
181}
182}), new objj_method(sel_getUid("isEditable"), function $CPTextField__isEditable(self, _cmd)
183{ with(self)
184{
185    return _isEditable;
186}
187}), new objj_method(sel_getUid("setSelectable:"), function $CPTextField__setSelectable_(self, _cmd, aFlag)
188{ with(self)
189{
190    _isSelectable = aFlag;
191}
192}), new objj_method(sel_getUid("isSelectable"), function $CPTextField__isSelectable(self, _cmd)
193{ with(self)
194{
195    return _isSelectable;
196}
197}), new objj_method(sel_getUid("setSecure:"), function $CPTextField__setSecure_(self, _cmd, aFlag)
198{ with(self)
199{
200    _isSecure = aFlag;
201}
202}), new objj_method(sel_getUid("isSecure"), function $CPTextField__isSecure(self, _cmd)
203{ with(self)
204{
205    return _isSecure;
206}
207}), new objj_method(sel_getUid("setBezeled:"), function $CPTextField__setBezeled_(self, _cmd, shouldBeBezeled)
208{ with(self)
209{
210    if (shouldBeBezeled)
211        objj_msgSend(self, "setThemeState:", CPThemeStateBezeled);
212    else
213        objj_msgSend(self, "unsetThemeState:", CPThemeStateBezeled);
214}
215}), new objj_method(sel_getUid("isBezeled"), function $CPTextField__isBezeled(self, _cmd)
216{ with(self)
217{
218    return objj_msgSend(self, "hasThemeState:", CPThemeStateBezeled);
219}
220}), new objj_method(sel_getUid("setBezelStyle:"), function $CPTextField__setBezelStyle_(self, _cmd, aBezelStyle)
221{ with(self)
222{
223    var shouldBeRounded = aBezelStyle === CPTextFieldRoundedBezel;
224    if (shouldBeRounded)
225        objj_msgSend(self, "setThemeState:", CPTextFieldStateRounded);
226    else
227        objj_msgSend(self, "unsetThemeState:", CPTextFieldStateRounded);
228}
229}), new objj_method(sel_getUid("bezelStyle"), function $CPTextField__bezelStyle(self, _cmd)
230{ with(self)
231{
232    if (objj_msgSend(self, "hasThemeState:", CPTextFieldStateRounded))
233        return CPTextFieldRoundedBezel;
234    return CPTextFieldSquareBezel;
235}
236}), new objj_method(sel_getUid("setBordered:"), function $CPTextField__setBordered_(self, _cmd, shouldBeBordered)
237{ with(self)
238{
239    if (shouldBeBordered)
240        objj_msgSend(self, "setThemeState:", CPThemeStateBordered);
241    else
242        objj_msgSend(self, "unsetThemeState:", CPThemeStateBordered);
243}
244}), new objj_method(sel_getUid("isBordered"), function $CPTextField__isBordered(self, _cmd)
245{ with(self)
246{
247    return objj_msgSend(self, "hasThemeState:", CPThemeStateBordered);
248}
249}), new objj_method(sel_getUid("setDrawsBackground:"), function $CPTextField__setDrawsBackground_(self, _cmd, shouldDrawBackground)
250{ with(self)
251{
252    if (_drawsBackground == shouldDrawBackground)
253        return;
254    _drawsBackground = shouldDrawBackground;
255    objj_msgSend(self, "setNeedsLayout");
256    objj_msgSend(self, "setNeedsDisplay:", YES);
257}
258}), new objj_method(sel_getUid("drawsBackground"), function $CPTextField__drawsBackground(self, _cmd)
259{ with(self)
260{
261    return _drawsBackground;
262}
263}), new objj_method(sel_getUid("setTextFieldBackgroundColor:"), function $CPTextField__setTextFieldBackgroundColor_(self, _cmd, aColor)
264{ with(self)
265{
266    if (_textFieldBackgroundColor == aColor)
267        return;
268    _textFieldBackgroundColor = aColor;
269    objj_msgSend(self, "setNeedsLayout");
270    objj_msgSend(self, "setNeedsDisplay:", YES);
271}
272}), new objj_method(sel_getUid("textFieldBackgroundColor"), function $CPTextField__textFieldBackgroundColor(self, _cmd)
273{ with(self)
274{
275    return _textFieldBackgroundColor;
276}
277}), new objj_method(sel_getUid("acceptsFirstResponder"), function $CPTextField__acceptsFirstResponder(self, _cmd)
278{ with(self)
279{
280    return objj_msgSend(self, "isEditable") && objj_msgSend(self, "isEnabled");
281}
282}), new objj_method(sel_getUid("becomeFirstResponder"), function $CPTextField__becomeFirstResponder(self, _cmd)
283{ with(self)
284{
285    if (CPTextFieldInputOwner && objj_msgSend(CPTextFieldInputOwner, "window") !== objj_msgSend(self, "window"))
286        objj_msgSend(objj_msgSend(CPTextFieldInputOwner, "window"), "makeFirstResponder:", nil);
287    objj_msgSend(self, "setThemeState:", CPThemeStateEditing);
288    objj_msgSend(self, "_updatePlaceholderState");
289    objj_msgSend(self, "setNeedsLayout");
290    var string = objj_msgSend(self, "stringValue"),
291        element = objj_msgSend(self, "_inputElement");
292    element.value = string;
293    element.style.color = objj_msgSend(objj_msgSend(self, "currentValueForThemeAttribute:", "text-color"), "cssString");
294    element.style.font = objj_msgSend(objj_msgSend(self, "currentValueForThemeAttribute:", "font"), "cssString");
295    element.style.zIndex = 1000;
296    var contentRect = objj_msgSend(self, "contentRectForBounds:", objj_msgSend(self, "bounds"));
297    element.style.top = (contentRect.origin.y) + "px";
298    element.style.left = ((contentRect.origin.x) - 1) + "px";
299    element.style.width = (contentRect.size.width) + "px";
300    element.style.height = (contentRect.size.height) + "px";
301    _DOMElement.appendChild(element);
302    window.setTimeout(function()
303    {
304        element.focus();
305        CPTextFieldInputOwner = self;
306    }, 0.0);
307    objj_msgSend(self, "textDidBeginEditing:", objj_msgSend(CPNotification, "notificationWithName:object:userInfo:", CPControlTextDidBeginEditingNotification, self, nil));
308    objj_msgSend(objj_msgSend(CPDOMWindowBridge, "sharedDOMWindowBridge"), "_propagateCurrentDOMEvent:", YES);
309    CPTextFieldInputIsActive = YES;
310    if (document.attachEvent)
311    {
312        CPTextFieldCachedSelectStartFunction = document.body.onselectstart;
313        CPTextFieldCachedDragFunction = document.body.ondrag;
314        document.body.ondrag = function () {};
315        document.body.onselectstart = function () {};
316    }
317    return YES;
318}
319}), new objj_method(sel_getUid("resignFirstResponder"), function $CPTextField__resignFirstResponder(self, _cmd)
320{ with(self)
321{
322    objj_msgSend(self, "unsetThemeState:", CPThemeStateEditing);
323    objj_msgSend(self, "_updatePlaceholderState");
324    objj_msgSend(self, "setNeedsLayout");
325    var element = objj_msgSend(self, "_inputElement");
326    objj_msgSend(self, "setObjectValue:", element.value);
327    CPTextFieldInputResigning = YES;
328    element.blur();
329    if (!CPTextFieldInputDidBlur)
330        CPTextFieldBlurFunction();
331    CPTextFieldInputDidBlur = NO;
332    CPTextFieldInputResigning = NO;
333    if (element.parentNode == _DOMElement)
334        element.parentNode.removeChild(element);
335    CPTextFieldInputIsActive = NO;
336    if (document.attachEvent)
337    {
338        CPTextFieldCachedSelectStartFunction = nil;
339        CPTextFieldCachedDragFunction = nil;
340        document.body.ondrag = CPTextFieldCachedDragFunction
341        document.body.onselectstart = CPTextFieldCachedSelectStartFunction
342    }
343    objj_msgSend(self, "textDidEndEditing:", objj_msgSend(CPNotification, "notificationWithName:object:userInfo:", CPControlTextDidBeginEditingNotification, self, nil));
344    return YES;
345}
346}), new objj_method(sel_getUid("mouseDown:"), function $CPTextField__mouseDown_(self, _cmd, anEvent)
347{ with(self)
348{
349    if (objj_msgSend(self, "isEditable") && objj_msgSend(self, "isEnabled"))
350        return objj_msgSend(objj_msgSend(self, "window"), "makeFirstResponder:", self);
351    else
352        return objj_msgSend(objj_msgSend(self, "nextResponder"), "mouseDown:", anEvent);
353}
354}), new objj_method(sel_getUid("objectValue"), function $CPTextField__objectValue(self, _cmd)
355{ with(self)
356{
357    return objj_msgSendSuper({ receiver:self, super_class:objj_getClass("CPControl") }, "objectValue");
358}
359}), new objj_method(sel_getUid("setObjectValue:"), function $CPTextField__setObjectValue_(self, _cmd, aValue)
360{ with(self)
361{
362    objj_msgSendSuper({ receiver:self, super_class:objj_getClass("CPControl") }, "setObjectValue:", aValue);
363    objj_msgSend(self, "_updatePlaceholderState");
364}
365}), new objj_method(sel_getUid("_updatePlaceholderState"), function $CPTextField___updatePlaceholderState(self, _cmd)
366{ with(self)
367{
368    var string = objj_msgSend(self, "stringValue");
369    if ((!string || objj_msgSend(string, "length") === 0) && !objj_msgSend(self, "hasThemeState:", CPThemeStateEditing))
370        objj_msgSend(self, "setThemeState:", CPTextFieldStatePlaceholder);
371    else
372        objj_msgSend(self, "unsetThemeState:", CPTextFieldStatePlaceholder);
373}
374}), new objj_method(sel_getUid("setPlaceholderString:"), function $CPTextField__setPlaceholderString_(self, _cmd, aStringValue)
375{ with(self)
376{
377    if (_placeholderString === aStringValue)
378        return;
379    _placeholderString = aStringValue;
380    if (objj_msgSend(self, "hasThemeState:", CPTextFieldStatePlaceholder))
381    {
382        objj_msgSend(self, "setNeedsLayout");
383        objj_msgSend(self, "setNeedsDisplay:", YES);
384    }
385}
386}), new objj_method(sel_getUid("placeholderString"), function $CPTextField__placeholderString(self, _cmd)
387{ with(self)
388{
389    return _placeholderString;
390}
391}), new objj_method(sel_getUid("sizeToFit"), function $CPTextField__sizeToFit(self, _cmd)
392{ with(self)
393{
394    var size = objj_msgSend((objj_msgSend(self, "stringValue") || " "), "sizeWithFont:", objj_msgSend(self, "currentValueForThemeAttribute:", "font")),
395        contentInset = objj_msgSend(self, "currentValueForThemeAttribute:", "content-inset"),
396        minSize = objj_msgSend(self, "currentValueForThemeAttribute:", "min-size"),
397        maxSize = objj_msgSend(self, "currentValueForThemeAttribute:", "max-size");
398    size.width = MAX(size.width + contentInset.left + contentInset.right, minSize.width);
399    size.height = MAX(size.height + contentInset.top + contentInset.bottom, minSize.height);
400    if (maxSize.width >= 0.0)
401        size.width = MIN(size.width, maxSize.width);
402    if (maxSize.height >= 0.0)
403        size.height = MIN(size.height, maxSize.height);
404    if (objj_msgSend(self, "isEditable"))
405        size.width = CGRectGetWidth(objj_msgSend(self, "frame"));
406    objj_msgSend(self, "setFrameSize:", size);
407}
408}), new objj_method(sel_getUid("selectText:"), function $CPTextField__selectText_(self, _cmd, sender)
409{ with(self)
410{
411    var element = objj_msgSend(self, "_inputElement");
412    if (element.parentNode == _DOMElement && (objj_msgSend(self, "isEditable") || objj_msgSend(self, "isSelectable")))
413        element.select();
414}
415}), new objj_method(sel_getUid("setDelegate:"), function $CPTextField__setDelegate_(self, _cmd, aDelegate)
416{ with(self)
417{
418    var defaultCenter = objj_msgSend(CPNotificationCenter, "defaultCenter");
419    if (_delegate)
420    {
421        objj_msgSend(defaultCenter, "removeObserver:name:object:", _delegate, CPControlTextDidBeginEditingNotification, self);
422        objj_msgSend(defaultCenter, "removeObserver:name:object:", _delegate, CPControlTextDidChangeNotification, self);
423        objj_msgSend(defaultCenter, "removeObserver:name:object:", _delegate, CPControlTextDidEndEditingNotification, self);
424    }
425    _delegate = aDelegate;
426    if (objj_msgSend(_delegate, "respondsToSelector:", sel_getUid("controlTextDidBeginEditing:")))
427        objj_msgSend(defaultCenter, "addObserver:selector:name:object:", _delegate, sel_getUid("controlTextDidBeginEditing:"), CPControlTextDidBeginEditingNotification, self);
428    if (objj_msgSend(_delegate, "respondsToSelector:", sel_getUid("controlTextDidChange:")))
429        objj_msgSend(defaultCenter, "addObserver:selector:name:object:", _delegate, sel_getUid("controlTextDidChange:"), CPControlTextDidChangeNotification, self);
430    if (objj_msgSend(_delegate, "respondsToSelector:", sel_getUid("controlTextDidEndEditing:")))
431        objj_msgSend(defaultCenter, "addObserver:selector:name:object:", _delegate, sel_getUid("controlTextDidEndEditing:"), CPControlTextDidEndEditingNotification, self);
432}
433}), new objj_method(sel_getUid("delegate"), function $CPTextField__delegate(self, _cmd)
434{ with(self)
435{
436    return _delegate;
437}
438}), new objj_method(sel_getUid("contentRectForBounds:"), function $CPTextField__contentRectForBounds_(self, _cmd, bounds)
439{ with(self)
440{
441    var contentInset = objj_msgSend(self, "currentValueForThemeAttribute:", "content-inset");
442    if (!contentInset)
443        return bounds;
444    bounds.origin.x += contentInset.left;
445    bounds.origin.y += contentInset.top;
446    bounds.size.width -= contentInset.left + contentInset.right;
447    bounds.size.height -= contentInset.top + contentInset.bottom;
448    return bounds;
449}
450}), new objj_method(sel_getUid("bezelRectForBounds:"), function $CPTextField__bezelRectForBounds_(self, _cmd, bounds)
451{ with(self)
452{
453    var bezelInset = objj_msgSend(self, "currentValueForThemeAttribute:", "bezel-inset");
454    if (((bezelInset).top === 0 && (bezelInset).right === 0 && (bezelInset).bottom === 0 && (bezelInset).left === 0))
455        return bounds;
456    bounds.origin.x += bezelInset.left;
457    bounds.origin.y += bezelInset.top;
458    bounds.size.width -= bezelInset.left + bezelInset.right;
459    bounds.size.height -= bezelInset.top + bezelInset.bottom;
460    return bounds;
461}
462}), new objj_method(sel_getUid("rectForEphemeralSubviewNamed:"), function $CPTextField__rectForEphemeralSubviewNamed_(self, _cmd, aName)
463{ with(self)
464{
465    if (aName === "bezel-view")
466        return objj_msgSend(self, "bezelRectForBounds:", objj_msgSend(self, "bounds"));
467    else if (aName === "content-view")
468        return objj_msgSend(self, "contentRectForBounds:", objj_msgSend(self, "bounds"));
469    return objj_msgSendSuper({ receiver:self, super_class:objj_getClass("CPControl") }, "rectForEphemeralSubviewNamed:", aName);
470}
471}), new objj_method(sel_getUid("createEphemeralSubviewNamed:"), function $CPTextField__createEphemeralSubviewNamed_(self, _cmd, aName)
472{ with(self)
473{
474    if (aName === "bezel-view")
475    {
476        var view = objj_msgSend(objj_msgSend(CPView, "alloc"), "initWithFrame:", { origin: { x:0.0, y:0.0 }, size: { width:0.0, height:0.0 } });
477        objj_msgSend(view, "setHitTests:", NO);
478        return view;
479    }
480    else
481    {
482        var view = objj_msgSend(objj_msgSend(_CPImageAndTextView, "alloc"), "initWithFrame:", { origin: { x:0.0, y:0.0 }, size: { width:0.0, height:0.0 } });
483        return view;
484    }
485    return objj_msgSendSuper({ receiver:self, super_class:objj_getClass("CPControl") }, "createEphemeralSubviewNamed:", aName);
486}
487}), new objj_method(sel_getUid("layoutSubviews"), function $CPTextField__layoutSubviews(self, _cmd)
488{ with(self)
489{
490    var bezelView = objj_msgSend(self, "layoutEphemeralSubviewNamed:positioned:relativeToEphemeralSubviewNamed:", "bezel-view", CPWindowBelow, "content-view");
491    if (bezelView)
492        objj_msgSend(bezelView, "setBackgroundColor:", objj_msgSend(self, "currentValueForThemeAttribute:", "bezel-color"));
493    var contentView = objj_msgSend(self, "layoutEphemeralSubviewNamed:positioned:relativeToEphemeralSubviewNamed:", "content-view", CPWindowAbove, "bezel-view");
494    if (contentView)
495    {
496        objj_msgSend(contentView, "setHidden:", objj_msgSend(self, "hasThemeState:", CPThemeStateEditing));
497        var string = "";
498        if (objj_msgSend(self, "hasThemeState:", CPTextFieldStatePlaceholder))
499            string = objj_msgSend(self, "placeholderString");
500        else
501        {
502            string = objj_msgSend(self, "stringValue");
503            if (objj_msgSend(self, "isSecure"))
504                string = secureStringForString(string);
505        }
506        objj_msgSend(contentView, "setText:", string);
507        objj_msgSend(contentView, "setTextColor:", objj_msgSend(self, "currentValueForThemeAttribute:", "text-color"));
508        objj_msgSend(contentView, "setFont:", objj_msgSend(self, "currentValueForThemeAttribute:", "font"));
509        objj_msgSend(contentView, "setAlignment:", objj_msgSend(self, "currentValueForThemeAttribute:", "alignment"));
510        objj_msgSend(contentView, "setVerticalAlignment:", objj_msgSend(self, "currentValueForThemeAttribute:", "vertical-alignment"));
511        objj_msgSend(contentView, "setLineBreakMode:", objj_msgSend(self, "currentValueForThemeAttribute:", "line-break-mode"));
512        objj_msgSend(contentView, "setTextShadowColor:", objj_msgSend(self, "currentValueForThemeAttribute:", "text-shadow-color"));
513        objj_msgSend(contentView, "setTextShadowOffset:", objj_msgSend(self, "currentValueForThemeAttribute:", "text-shadow-offset"));
514    }
515}
516})]);
517class_addMethods(meta_class, [new objj_method(sel_getUid("textFieldWithStringValue:placeholder:width:"), function $CPTextField__textFieldWithStringValue_placeholder_width_(self, _cmd, aStringValue, aPlaceholder, aWidth)
518{ with(self)
519{
520    return objj_msgSend(self, "textFieldWithStringValue:placeholder:width:theme:", aStringValue, aPlaceholder, aWidth, objj_msgSend(CPTheme, "defaultTheme"));
521}
522}), new objj_method(sel_getUid("textFieldWithStringValue:placeholder:width:theme:"), function $CPTextField__textFieldWithStringValue_placeholder_width_theme_(self, _cmd, aStringValue, aPlaceholder, aWidth, aTheme)
523{ with(self)
524{
525    var textField = objj_msgSend(objj_msgSend(self, "alloc"), "initWithFrame:", CGRectMake(0.0, 0.0, aWidth, 29.0));
526    objj_msgSend(textField, "setTheme:", aTheme);
527    objj_msgSend(textField, "setStringValue:", aStringValue);
528    objj_msgSend(textField, "setPlaceholderString:", aPlaceholder);
529    objj_msgSend(textField, "setBordered:", YES);
530    objj_msgSend(textField, "setBezeled:", YES);
531    objj_msgSend(textField, "setEditable:", YES);
532    objj_msgSend(textField, "sizeToFit");
533    return textField;
534}
535}), new objj_method(sel_getUid("roundedTextFieldWithStringValue:placeholder:width:"), function $CPTextField__roundedTextFieldWithStringValue_placeholder_width_(self, _cmd, aStringValue, aPlaceholder, aWidth)
536{ with(self)
537{
538    return objj_msgSend(self, "roundedTextFieldWithStringValue:placeholder:width:theme:", aStringValue, aPlaceholder, aWidth, objj_msgSend(CPTheme, "defaultTheme"));
539}
540}), new objj_method(sel_getUid("roundedTextFieldWithStringValue:placeholder:width:theme:"), function $CPTextField__roundedTextFieldWithStringValue_placeholder_width_theme_(self, _cmd, aStringValue, aPlaceholder, aWidth, aTheme)
541{ with(self)
542{
543    var textField = objj_msgSend(objj_msgSend(CPTextField, "alloc"), "initWithFrame:", CGRectMake(0.0, 0.0, aWidth, 29.0));
544    objj_msgSend(textField, "setTheme:", aTheme);
545    objj_msgSend(textField, "setStringValue:", aStringValue);
546    objj_msgSend(textField, "setPlaceholderString:", aPlaceholder);
547    objj_msgSend(textField, "setBezelStyle:", CPTextFieldRoundedBezel);
548    objj_msgSend(textField, "setBordered:", YES);
549    objj_msgSend(textField, "setBezeled:", YES);
550    objj_msgSend(textField, "setEditable:", YES);
551    objj_msgSend(textField, "sizeToFit");
552    return textField;
553}
554}), new objj_method(sel_getUid("labelWithTitle:"), function $CPTextField__labelWithTitle_(self, _cmd, aTitle)
555{ with(self)
556{
557    return objj_msgSend(self, "labelWithTitle:theme:", aTitle, objj_msgSend(CPTheme, "defaultTheme"));
558}
559}), new objj_method(sel_getUid("labelWithTitle:theme:"), function $CPTextField__labelWithTitle_theme_(self, _cmd, aTitle, aTheme)
560{ with(self)
561{
562    var textField = objj_msgSend(objj_msgSend(self, "alloc"), "init");
563    objj_msgSend(textField, "setStringValue:", aTitle);
564    objj_msgSend(textField, "sizeToFit");
565    return textField;
566}
567}), new objj_method(sel_getUid("themeClass"), function $CPTextField__themeClass(self, _cmd)
568{ with(self)
569{
570    return "textfield";
571}
572}), new objj_method(sel_getUid("themeAttributes"), function $CPTextField__themeAttributes(self, _cmd)
573{ with(self)
574{
575    return objj_msgSend(CPDictionary, "dictionaryWithObjects:forKeys:", [{ top:(0), right:(0), bottom:(0), left:(0) }, { top:(2.0), right:(2.0), bottom:(2.0), left:(2.0) }, nil], ["bezel-inset", "content-inset", "bezel-color"]);
576}
577})]);
578}
579var secureStringForString = function(aString)
580{
581    if (!aString)
582        return "";
583    var secureString = "",
584        length = aString.length;
585    while (length--)
586        secureString += CPSecureTextFieldCharacter;
587    return secureString;
588}
589var CPTextFieldIsEditableKey = "CPTextFieldIsEditableKey",
590    CPTextFieldIsSelectableKey = "CPTextFieldIsSelectableKey",
591    CPTextFieldIsBorderedKey = "CPTextFieldIsBorderedKey",
592    CPTextFieldIsBezeledKey = "CPTextFieldIsBezeledKey",
593    CPTextFieldBezelStyleKey = "CPTextFieldBezelStyleKey",
594    CPTextFieldDrawsBackgroundKey = "CPTextFieldDrawsBackgroundKey",
595    CPTextFieldLineBreakModeKey = "CPTextFieldLineBreakModeKey",
596    CPTextFieldBackgroundColorKey = "CPTextFieldBackgroundColorKey",
597    CPTextFieldPlaceholderStringKey = "CPTextFieldPlaceholderStringKey";
598{
599var the_class = objj_getClass("CPTextField")
600if(!the_class) objj_exception_throw(new objj_exception(OBJJClassNotFoundException, "*** Could not find definition for class \"CPTextField\""));
601var meta_class = the_class.isa;class_addMethods(the_class, [new objj_method(sel_getUid("initWithCoder:"), function $CPTextField__initWithCoder_(self, _cmd, aCoder)
602{ with(self)
603{
604    self = objj_msgSendSuper({ receiver:self, super_class:objj_getClass("CPControl") }, "initWithCoder:", aCoder);
605    if (self)
606    {
607        objj_msgSend(self, "setEditable:", objj_msgSend(aCoder, "decodeBoolForKey:", CPTextFieldIsEditableKey));
608        objj_msgSend(self, "setSelectable:", objj_msgSend(aCoder, "decodeBoolForKey:", CPTextFieldIsSelectableKey));
609        objj_msgSend(self, "setDrawsBackground:", objj_msgSend(aCoder, "decodeBoolForKey:", CPTextFieldDrawsBackgroundKey));
610        objj_msgSend(self, "setTextFieldBackgroundColor:", objj_msgSend(aCoder, "decodeObjectForKey:", CPTextFieldBackgroundColorKey));
611        objj_msgSend(self, "setPlaceholderString:", objj_msgSend(aCoder, "decodeObjectForKey:", CPTextFieldPlaceholderStringKey));
612    }
613    return self;
614}
615}), new objj_method(sel_getUid("encodeWithCoder:"), function $CPTextField__encodeWithCoder_(self, _cmd, aCoder)
616{ with(self)
617{
618    objj_msgSendSuper({ receiver:self, super_class:objj_getClass("CPControl") }, "encodeWithCoder:", aCoder);
619    objj_msgSend(aCoder, "encodeBool:forKey:", _isEditable, CPTextFieldIsEditableKey);
620    objj_msgSend(aCoder, "encodeBool:forKey:", _isSelectable, CPTextFieldIsSelectableKey);
621    objj_msgSend(aCoder, "encodeBool:forKey:", _drawsBackground, CPTextFieldDrawsBackgroundKey);
622    objj_msgSend(aCoder, "encodeObject:forKey:", _textFieldBackgroundColor, CPTextFieldBackgroundColorKey);
623    objj_msgSend(aCoder, "encodeObject:forKey:", _placeholderString, CPTextFieldPlaceholderStringKey);
624}
625})]);
626}
627