Mercurial > osx-quasimode
changeset 16:1e83bbfdd190
Added quasimode.setPosition().
author | Atul Varma <avarma@mozilla.com> |
---|---|
date | Sun, 11 Apr 2010 22:28:00 -0700 |
parents | 547b12bed241 |
children | 8c5678d7b5e9 |
files | JavaScriptQuasimode.m |
diffstat | 1 files changed, 39 insertions(+), 5 deletions(-) [+] |
line wrap: on
line diff
--- a/JavaScriptQuasimode.m Sun Apr 11 22:16:41 2010 -0700 +++ b/JavaScriptQuasimode.m Sun Apr 11 22:28:00 2010 -0700 @@ -38,10 +38,10 @@ ENSURE_ARGCOUNT(2); if (!JSValueIsNumber(ctx, arguments[0])) - RAISE_ERROR("first argument must be a number"); + RAISE_ERROR("first argument (width) must be a number"); if (!JSValueIsNumber(ctx, arguments[1])) - RAISE_ERROR("second argument must be a number"); + RAISE_ERROR("second argument (height) must be a number"); Quasimode *quasimode = (Quasimode *) JSObjectGetPrivate(thisObject); if (!quasimode) @@ -61,6 +61,39 @@ } static JSValueRef +method_setPosition(JSContextRef ctx, + JSObjectRef function, + JSObjectRef thisObject, + size_t argumentCount, + const JSValueRef arguments[], + JSValueRef* exception) +{ + ENSURE_ARGCOUNT(2); + + if (!JSValueIsNumber(ctx, arguments[0])) + RAISE_ERROR("first argument (x) must be a number"); + + if (!JSValueIsNumber(ctx, arguments[1])) + RAISE_ERROR("second argument (y) must be a number"); + + Quasimode *quasimode = (Quasimode *) JSObjectGetPrivate(thisObject); + if (!quasimode) + return raiseError(ctx, exception, + "method must be invoked on a Quasimode instance"); + + int x = (int) JSValueToNumber(ctx, arguments[0], NULL); + int y = (int) JSValueToNumber(ctx, arguments[1], NULL); + + if (x < 0) RAISE_ERROR("x must be non-negative"); + if (y < 0) RAISE_ERROR("y must be non-negative"); + + NSPoint point = {x, y}; + + [[quasimode window] setFrameOrigin: point]; + return JSValueMakeUndefined(ctx); +} + +static JSValueRef method_log(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, @@ -71,7 +104,7 @@ ENSURE_ARGCOUNT(1); if (!JSValueIsString(ctx, arguments[0])) - RAISE_ERROR("first argument must be a string"); + RAISE_ERROR("first argument (message) must be a string"); JSStringRef str = JSValueToStringCopy(ctx, arguments[0], NULL); size_t len = JSStringGetMaximumUTF8CStringSize(str); @@ -83,8 +116,9 @@ } static JSQuasimodeMethod jsQuasimodeMethods[] = { - {"setSize", method_setSize}, - {"log", method_log}, + {"setSize", method_setSize}, + {"setPosition", method_setPosition}, + {"log", method_log}, {NULL, NULL} };