Index: ps/trunk/source/ps/Util.cpp =================================================================== --- ps/trunk/source/ps/Util.cpp (revision 5153) +++ ps/trunk/source/ps/Util.cpp (revision 5154) @@ -1,314 +1,321 @@ #include "precompiled.h" #include "lib/posix/posix_utsname.h" #include "lib/posix/posix_sock.h" #include "lib/res/file/path.h" #include "lib/res/file/vfs.h" #include "lib/ogl.h" #include "lib/timer.h" #include "lib/sysdep/gfx.h" #include "lib/sysdep/snd.h" #include "lib/sysdep/cpu.h" #include "lib/res/res.h" #include "lib/res/graphics/tex.h" #include "ps/GameSetup/Config.h" #include "ps/GameSetup/GameSetup.h" #include "ps/Game.h" #include "renderer/Renderer.h" #include "maths/MathUtil.h" #include "graphics/GameView.h" static std::string SplitExts(const char *exts) { std::string str = exts; std::string ret = ""; size_t idx = str.find_first_of(" "); while(idx != std::string::npos) { if(idx >= str.length() - 1) { ret += str; break; } ret += str.substr(0, idx); ret += "\n"; str = str.substr(idx + 1); idx = str.find_first_of(" "); } return ret; } void WriteSystemInfo() { TIMER("write_sys_info"); // get_cpu_info and gfx_detect already called during init - see call site snd_detect(); struct utsname un; uname(&un); char N_path[PATH_MAX]; (void)file_make_full_native_path("../logs/system_info.txt", N_path); FILE* f = fopen(N_path, "w"); if(!f) return; // current timestamp (redundant WRT OS timestamp, but that is not // visible when people are posting this file's contents online) { char timestamp_buf[100] = {'\0'}; time_t seconds; time(&seconds); struct tm* t = gmtime(&seconds); const size_t chars_written = strftime(timestamp_buf, ARRAY_SIZE(timestamp_buf), "(generated %Y-%m-%d %H:%M:%S UTC)", t); debug_assert(chars_written != 0); fprintf(f, "%s\n\n", timestamp_buf); } // OS fprintf(f, "OS : %s %s (%s)\n", un.sysname, un.release, un.version); // CPU +#if OS_LINUX + // TODO: implement the cpu_ functions on Linux, then add them back here. (But it's not worthwhile + // doing that while we're not using those functions for anything that's actually useful, so currently + // we just don't use them here.) + fprintf(f, "CPU : %s, %s", un.machine, cpu_IdentifierString()); +#else fprintf(f, "CPU : %s, %s (%dx%dx%d)", un.machine, cpu_IdentifierString(), cpu_NumPackages(), cpu_CoresPerPackage(), cpu_LogicalPerCore()); +#endif const double cpu_freq = cpu_ClockFrequency(); if(cpu_freq != 0.0f) { if(cpu_freq < 1e9) fprintf(f, ", %.2f MHz\n", cpu_freq*1e-6); else fprintf(f, ", %.2f GHz\n", cpu_freq*1e-9); } else fprintf(f, "\n"); // memory fprintf(f, "Memory : %lu MiB; %lu MiB free\n", cpu_MemoryTotalMiB(), cpu_MemorySize(CPU_MEM_AVAILABLE)/MiB); // graphics fprintf(f, "Graphics Card : %s\n", gfx_card); fprintf(f, "OpenGL Drivers : %s; %s\n", glGetString(GL_VERSION), gfx_drv_ver); fprintf(f, "Video Mode : %dx%d:%d@%d\n", g_xres, g_yres, g_bpp, g_freq); // sound fprintf(f, "Sound Card : %s\n", snd_card); fprintf(f, "Sound Drivers : %s\n", snd_drv_ver); // // network name / ips // // note: can't use un.nodename because it is for an // "implementation-defined communications network". char hostname[128] = "(unknown)"; (void)gethostname(hostname, sizeof(hostname)-1); // -1 makes sure it's 0-terminated. if the function fails, // we display "(unknown)" and will skip IP output below. fprintf(f, "Network Name : %s", hostname); { hostent* host = gethostbyname(hostname); if(!host) goto no_ip; struct in_addr** ips = (struct in_addr**)host->h_addr_list; if(!ips) goto no_ip; // output all IPs (> 1 if using VMware or dual ethernet) fprintf(f, " ("); for(uint i = 0; i < 256 && ips[i]; i++) // safety { // separate entries but avoid trailing comma if(i != 0) fprintf(f, ", "); fprintf(f, "%s", inet_ntoa(*ips[i])); } fprintf(f, ")"); } no_ip: fprintf(f, "\n"); // OpenGL extensions (write them last, since it's a lot of text) const char* exts = ogl_ExtensionString(); if (!exts) exts = "{unknown}"; fprintf(f, "\nOpenGL Extensions: \n%s\n", SplitExts(exts).c_str()); fclose(f); f = 0; } // not thread-safe! static const wchar_t* HardcodedErrorString(int err) { char description[200]; error_description_r((LibError)err, description, ARRAY_SIZE(description)); static wchar_t output_buf[200]; mbstowcs(output_buf, description, ARRAY_SIZE(output_buf)); return output_buf; } // not thread-safe! const wchar_t* ErrorString(int err) { // language file not available (yet) return HardcodedErrorString(err); // TODO: load from language file } static NextNumberedFilenameInfo screenshot_nfi; // identifies the file format that is to be written // (case-insensitive). examples: "bmp", "png", "jpg". // BMP is good for quick output at the expense of large files. void WriteScreenshot(const char* extension) { // get next available numbered filename // .. bake extension into format string. // note: %04d -> always 4 digits, so sorting by filename works correctly. char file_format_string[PATH_MAX]; snprintf(file_format_string, PATH_MAX, "screenshots/screenshot%%04d.%s", extension); file_format_string[PATH_MAX-1] = '\0'; char fn[PATH_MAX]; next_numbered_filename(file_format_string, &screenshot_nfi, fn); const char* atom_fn = file_make_unique_fn_copy(fn); const int w = g_xres, h = g_yres; const int bpp = 24; GLenum fmt = GL_RGB; int flags = TEX_BOTTOM_UP; // we want writing BMP to be as fast as possible, // so read data from OpenGL in BMP format to obviate conversion. if(!strcasecmp(extension, "bmp")) { fmt = GL_BGR; flags |= TEX_BGR; } const size_t img_size = w * h * bpp/8; const size_t hdr_size = tex_hdr_size(fn); FileIOBuf buf = file_buf_alloc(hdr_size+img_size, atom_fn, FB_FROM_HEAP); GLvoid* img = (u8*)buf + hdr_size; Tex t; if(tex_wrap(w, h, bpp, flags, img, &t) < 0) return; glReadPixels(0, 0, w, h, fmt, GL_UNSIGNED_BYTE, img); (void)tex_write(&t, fn); (void)tex_free(&t); (void)file_buf_free(buf, FB_FROM_HEAP); } // Similar to WriteScreenshot, but generates an image of size 640*tiles x 480*tiles. void WriteBigScreenshot(const char* extension, int tiles) { // get next available numbered filename // .. bake extension into format string. // note: %04d -> always 4 digits, so sorting by filename works correctly. char file_format_string[PATH_MAX]; snprintf(file_format_string, PATH_MAX, "screenshots/screenshot%%04d.%s", extension); file_format_string[PATH_MAX-1] = '\0'; char fn[PATH_MAX]; next_numbered_filename(file_format_string, &screenshot_nfi, fn); const char* atom_fn = file_make_unique_fn_copy(fn); // Slightly ugly and inflexible: Always draw 640*480 tiles onto the screen, and // hope the screen is actually large enough for that. const int tile_w = 640, tile_h = 480; debug_assert(g_xres >= tile_w && g_yres >= tile_h); const int img_w = tile_w*tiles, img_h = tile_h*tiles; const int bpp = 24; GLenum fmt = GL_RGB; int flags = TEX_BOTTOM_UP; // we want writing BMP to be as fast as possible, // so read data from OpenGL in BMP format to obviate conversion. if(!strcasecmp(extension, "bmp")) { fmt = GL_BGR; flags |= TEX_BGR; } const size_t img_size = img_w * img_h * bpp/8; const size_t tile_size = tile_w * tile_h * bpp/8; const size_t hdr_size = tex_hdr_size(fn); void* tile_data = malloc(tile_size); if(!tile_data) WARN_ERR_RETURN(ERR::NO_MEM); FileIOBuf img_buf = file_buf_alloc(hdr_size+img_size, atom_fn, FB_FROM_HEAP); Tex t; GLvoid* img = (u8*)img_buf + hdr_size; if(tex_wrap(img_w, img_h, bpp, flags, img, &t) < 0) return; ogl_WarnIfError(); // Resize various things so that the sizes and aspect ratios are correct { g_Renderer.Resize(tile_w, tile_h); SViewPort vp = { 0, 0, tile_w, tile_h }; g_Game->GetView()->GetCamera()->SetViewPort(&vp); g_Game->GetView()->GetCamera()->SetProjection(CGameView::defaultNear, CGameView::defaultFar, CGameView::defaultFOV); } // Temporarily move everything onto the front buffer, so the user can // see the exciting progress as it renders (and can tell when it's finished). // (It doesn't just use SwapBuffers, because it doesn't know whether to // call the SDL version or the Atlas version.) GLint oldReadBuffer, oldDrawBuffer; glGetIntegerv(GL_READ_BUFFER, &oldReadBuffer); glGetIntegerv(GL_DRAW_BUFFER, &oldDrawBuffer); glDrawBuffer(GL_FRONT); glReadBuffer(GL_FRONT); // Render each tile for (int tile_y = 0; tile_y < tiles; ++tile_y) { for (int tile_x = 0; tile_x < tiles; ++tile_x) { // Adjust the camera to render the appropriate region g_Game->GetView()->GetCamera()->SetProjectionTile(tiles, tile_x, tile_y); Render(); // Copy the tile pixels into the main image glReadPixels(0, 0, tile_w, tile_h, fmt, GL_UNSIGNED_BYTE, tile_data); for (int y = 0; y < tile_h; ++y) { void* dest = (char*)img + ((tile_y*tile_h + y) * img_w + (tile_x*tile_w)) * bpp/8; void* src = (char*)tile_data + y * tile_w * bpp/8; cpu_memcpy(dest, src, tile_w * bpp/8); } } } // Restore the buffer settings glDrawBuffer(oldDrawBuffer); glReadBuffer(oldReadBuffer); // Restore the viewport settings { g_Renderer.Resize(g_xres, g_yres); SViewPort vp = { 0, 0, g_xres, g_yres }; g_Game->GetView()->GetCamera()->SetViewPort(&vp); g_Game->GetView()->GetCamera()->SetProjection(CGameView::defaultNear, CGameView::defaultFar, CGameView::defaultFOV); g_Game->GetView()->GetCamera()->SetProjectionTile(1, 0, 0); } (void)tex_write(&t, fn); (void)tex_free(&t); free(tile_data); (void)file_buf_free(img_buf, FB_FROM_HEAP); } Index: ps/trunk/source/gui/scripting/JSInterface_IGUIObject.cpp =================================================================== --- ps/trunk/source/gui/scripting/JSInterface_IGUIObject.cpp (revision 5153) +++ ps/trunk/source/gui/scripting/JSInterface_IGUIObject.cpp (revision 5154) @@ -1,579 +1,577 @@ #include "precompiled.h" #include "JSInterface_IGUIObject.h" #include "JSInterface_GUITypes.h" #include "gui/IGUIObject.h" #include "gui/CGUI.h" #include "gui/CList.h" #include "ps/CLogger.h" #include "ps/StringConvert.h" JSClass JSI_IGUIObject::JSI_class = { "GUIObject", JSCLASS_HAS_PRIVATE, JS_PropertyStub, JS_PropertyStub, JSI_IGUIObject::getProperty, JSI_IGUIObject::setProperty, JS_EnumerateStub, JS_ResolveStub, JS_ConvertStub, JS_FinalizeStub, NULL, NULL, NULL, JSI_IGUIObject::construct }; JSPropertySpec JSI_IGUIObject::JSI_props[] = { { 0 } }; JSFunctionSpec JSI_IGUIObject::JSI_methods[] = { { "toString", JSI_IGUIObject::toString, 0, 0, 0 }, { "getByName", JSI_IGUIObject::getByName, 1, 0, 0 }, { 0 } }; JSBool JSI_IGUIObject::getProperty(JSContext* cx, JSObject* obj, jsval id, jsval* vp) { CStr propName = JS_GetStringBytes(JS_ValueToString(cx, id)); // Skip some things which are known to be functions rather than properties. // ("constructor" *must* be here, else it'll try to GetSettingType before // the private IGUIObject* has been set (and thus crash). The others are // partly for efficiency, and also to allow correct reporting of attempts to // access nonexistent properties.) if (propName == "constructor" || propName == "prototype" || propName == "toString" || propName == "getByName" ) return JS_TRUE; IGUIObject* e = (IGUIObject*)JS_GetPrivate(cx, obj); // Use onWhatever to access event handlers if (propName.Left(2) == "on") { CStr eventName (CStr(propName.substr(2)).LowerCase()); std::map::iterator it = e->m_ScriptHandlers.find(eventName); if (it == e->m_ScriptHandlers.end()) *vp = JSVAL_NULL; else *vp = OBJECT_TO_JSVAL(*(it->second)); return JS_TRUE; } // Handle the "parent" property specially if (propName == "parent") { IGUIObject* parent = e->GetParent(); if (parent) { // If the object isn't parentless, return a new object JSObject* entity = JS_NewObject(cx, &JSI_IGUIObject::JSI_class, NULL, NULL); JS_SetPrivate(cx, entity, parent); *vp = OBJECT_TO_JSVAL(entity); } else { // Return null if there's no parent *vp = JSVAL_NULL; } return JS_TRUE; } // Also handle "name" specially else if (propName == "name") { *vp = STRING_TO_JSVAL(JS_NewStringCopyZ(cx, e->GetName())); return JS_TRUE; } // Handle all other properties else { // Retrieve the setting's type (and make sure it actually exists) EGUISettingType Type; if (e->GetSettingType(propName, Type) != PS_OK) { JS_ReportError(cx, "Invalid GUIObject property '%s'", propName.c_str()); return JS_FALSE; } // (All the cases are in {...} to avoid scoping problems) switch (Type) { case GUIST_bool: { bool value; GUI::GetSetting(e, propName, value); *vp = value ? JSVAL_TRUE : JSVAL_FALSE; break; } case GUIST_int: { int value; GUI::GetSetting(e, propName, value); *vp = INT_TO_JSVAL(value); break; } case GUIST_float: { float value; GUI::GetSetting(e, propName, value); // Create a garbage-collectable double *vp = DOUBLE_TO_JSVAL(JS_NewDouble(cx, value) ); break; } case GUIST_CColor: { CColor colour; GUI::GetSetting(e, propName, colour); JSObject* obj = JS_NewObject(cx, &JSI_GUIColor::JSI_class, NULL, NULL); + *vp = OBJECT_TO_JSVAL(obj); // root it // Attempt to minimise ugliness through macrosity #define P(x) jsval x = DOUBLE_TO_JSVAL(JS_NewDouble(cx, colour.x)); JS_SetProperty(cx, obj, #x, &x) P(r); P(g); P(b); P(a); #undef P - *vp = OBJECT_TO_JSVAL(obj); break; } case GUIST_CClientArea: { CClientArea area; GUI::GetSetting(e, propName, area); JSObject* obj = JS_NewObject(cx, &JSI_GUISize::JSI_class, NULL, NULL); - JS_AddRoot(cx, &obj); + *vp = OBJECT_TO_JSVAL(obj); // root it try { #define P(x, y, z) g_ScriptingHost.SetObjectProperty_Double(obj, #z, area.x.y) P(pixel, left, left); P(pixel, top, top); P(pixel, right, right); P(pixel, bottom, bottom); P(percent, left, rleft); P(percent, top, rtop); P(percent, right, rright); P(percent, bottom, rbottom); #undef P } catch (PSERROR_Scripting_ConversionFailed) { debug_warn("Error creating size object!"); - JS_RemoveRoot(cx, &obj); break; } - *vp = OBJECT_TO_JSVAL(obj); - JS_RemoveRoot(cx, &obj); break; } case GUIST_CGUIString: { CGUIString value; GUI::GetSetting(e, propName, value); JSString* s = StringConvert::wchars_to_jsstring(cx, value.GetRawString().c_str()); *vp = STRING_TO_JSVAL(s); break; } case GUIST_CStr: { CStr value; GUI::GetSetting(e, propName, value); *vp = STRING_TO_JSVAL(JS_NewStringCopyZ(cx, value)); break; } case GUIST_CStrW: { CStrW value; GUI::GetSetting(e, propName, value); *vp = STRING_TO_JSVAL(JS_NewUCStringCopyZ(cx, value.utf16().c_str())); break; } case GUIST_CGUISpriteInstance: { CGUISpriteInstance *value; GUI::GetSettingPointer(e, propName, value); *vp = STRING_TO_JSVAL(JS_NewStringCopyZ(cx, value->GetName())); break; } case GUIST_EAlign: { EAlign value; GUI::GetSetting(e, propName, value); CStr word; switch (value) { case EAlign_Left: word = "left"; break; case EAlign_Right: word = "right"; break; case EAlign_Center: word = "center"; break; default: debug_warn("Invalid EAlign!"); word = "error"; break; } *vp = STRING_TO_JSVAL(JS_NewStringCopyZ(cx, word)); break; } case GUIST_EVAlign: { EVAlign value; GUI::GetSetting(e, propName, value); CStr word; switch (value) { case EVAlign_Top: word = "top"; break; case EVAlign_Bottom: word = "bottom"; break; case EVAlign_Center: word = "center"; break; default: debug_warn("Invalid EVAlign!"); word = "error"; break; } *vp = STRING_TO_JSVAL(JS_NewStringCopyZ(cx, word)); break; } case GUIST_CGUIList: { CGUIList value; GUI::GetSetting(e, propName, value); - jsval *vector = new jsval[value.m_Items.size()]; - for (size_t i=0; iSetName(propValue); return JS_TRUE; } // Use onWhatever to set event handlers if (propName.Left(2) == "on") { if (!JSVAL_IS_OBJECT(*vp) || !JS_ValueToFunction(cx, *vp)) { JS_ReportError(cx, "on- event-handlers must be functions"); return JS_FALSE; } CStr eventName (CStr(propName.substr(2)).LowerCase()); e->SetScriptHandler(eventName, JSVAL_TO_OBJECT(*vp)); return JS_TRUE; } // Retrieve the setting's type (and make sure it actually exists) EGUISettingType Type; if (e->GetSettingType(propName, Type) != PS_OK) { JS_ReportError(cx, "Invalid setting '%s'", propName.c_str()); return JS_TRUE; } switch (Type) { case GUIST_CStr: { CStr value (JS_GetStringBytes(JS_ValueToString(cx, *vp))); GUI::SetSetting(e, propName, value); break; } case GUIST_CStrW: { utf16string value (JS_GetStringChars(JS_ValueToString(cx, *vp))); GUI::SetSetting(e, propName, value); break; } case GUIST_CGUISpriteInstance: { CStr value (JS_GetStringBytes(JS_ValueToString(cx, *vp))); GUI::SetSetting(e, propName, value); break; } case GUIST_CGUIString: { std::wstring value; StringConvert::jsstring_to_wstring(JS_ValueToString(cx, *vp), value); CGUIString str; str.SetValue(value); GUI::SetSetting(e, propName, str); break; } case GUIST_EAlign: { CStr value (JS_GetStringBytes(JS_ValueToString(cx, *vp))); EAlign a; if (value == "left") a = EAlign_Left; else if (value == "right") a = EAlign_Right; else if (value == "center" || value == "centre") a = EAlign_Center; else { JS_ReportError(cx, "Invalid alignment (should be 'left', 'right' or 'center')"); return JS_FALSE; } GUI::SetSetting(e, propName, a); break; } case GUIST_EVAlign: { CStr value (JS_GetStringBytes(JS_ValueToString(cx, *vp))); EVAlign a; if (value == "top") a = EVAlign_Top; else if (value == "bottom") a = EVAlign_Bottom; else if (value == "center" || value == "centre") a = EVAlign_Center; else { JS_ReportError(cx, "Invalid alignment (should be 'top', 'bottom' or 'center')"); return JS_FALSE; } GUI::SetSetting(e, propName, a); break; } case GUIST_int: { int32 value; if (JS_ValueToInt32(cx, *vp, &value) == JS_TRUE) GUI::SetSetting(e, propName, value); else { JS_ReportError(cx, "Cannot convert value to int"); return JS_FALSE; } break; } case GUIST_float: { jsdouble value; if (JS_ValueToNumber(cx, *vp, &value) == JS_TRUE) GUI::SetSetting(e, propName, (float)value); else { JS_ReportError(cx, "Cannot convert value to float"); return JS_FALSE; } break; } case GUIST_bool: { JSBool value; if (JS_ValueToBoolean(cx, *vp, &value) == JS_TRUE) GUI::SetSetting(e, propName, value||0); // ||0 to avoid int-to-bool compiler warnings else { JS_ReportError(cx, "Cannot convert value to bool"); return JS_FALSE; } break; } case GUIST_CClientArea: { if (JSVAL_IS_STRING(*vp)) { if (e->SetSetting(propName, JS_GetStringBytes(JS_ValueToString(cx, *vp))) != PS_OK) { JS_ReportError(cx, "Invalid value for setting '%s'", propName.c_str()); return JS_FALSE; } } - else if (JSVAL_IS_OBJECT(*vp) && JS_GetClass(JSVAL_TO_OBJECT(*vp)) == &JSI_GUISize::JSI_class) + else if (JSVAL_IS_OBJECT(*vp) && JS_GetClass(cx, JSVAL_TO_OBJECT(*vp)) == &JSI_GUISize::JSI_class) { CClientArea area; GUI::GetSetting(e, propName, area); JSObject* obj = JSVAL_TO_OBJECT(*vp); #define P(x, y, z) area.x.y = (float)g_ScriptingHost.GetObjectProperty_Double(obj, #z) P(pixel, left, left); P(pixel, top, top); P(pixel, right, right); P(pixel, bottom, bottom); P(percent, left, rleft); P(percent, top, rtop); P(percent, right, rright); P(percent, bottom, rbottom); #undef P GUI::SetSetting(e, propName, area); } else { JS_ReportError(cx, "Size only accepts strings or GUISize objects"); return JS_FALSE; } break; } case GUIST_CColor: { if (JSVAL_IS_STRING(*vp)) { if (e->SetSetting(propName, JS_GetStringBytes(JS_ValueToString(cx, *vp))) != PS_OK) { JS_ReportError(cx, "Invalid value for setting '%s'", propName.c_str()); return JS_FALSE; } } - else if (JSVAL_IS_OBJECT(*vp) && JS_GetClass(JSVAL_TO_OBJECT(*vp)) == &JSI_GUIColor::JSI_class) + else if (JSVAL_IS_OBJECT(*vp) && JS_GetClass(cx, JSVAL_TO_OBJECT(*vp)) == &JSI_GUIColor::JSI_class) { CColor colour; JSObject* obj = JSVAL_TO_OBJECT(*vp); jsval t; double s; #define PROP(x) JS_GetProperty(cx, obj, #x, &t); \ JS_ValueToNumber(cx, t, &s); \ colour.x = (float)s PROP(r); PROP(g); PROP(b); PROP(a); #undef PROP GUI::SetSetting(e, propName, colour); } else { JS_ReportError(cx, "Color only accepts strings or GUIColor objects"); return JS_FALSE; } break; } case GUIST_CGUIList: { JSObject* obj = JSVAL_TO_OBJECT(*vp); jsuint length; if (JSVAL_IS_OBJECT(*vp) && JS_GetArrayLength(cx, obj, &length) == JS_TRUE) { CGUIList list; for (int i=0; i<(int)length; ++i) { jsval element; - JS_GetElement(cx, obj, i, &element); + if (! JS_GetElement(cx, obj, i, &element)) + { + JS_ReportError(cx, "Failed to get list element"); + return JS_FALSE; + } std::wstring value; - StringConvert::jsstring_to_wstring(JS_ValueToString(cx, element), value); + JSString* string = JS_ValueToString(cx, element); + StringConvert::jsstring_to_wstring(string, value); CGUIString str; str.SetValue(value); list.m_Items.push_back(str); } GUI::SetSetting(e, propName, list); } else { JS_ReportError(cx, "List only accepts a GUIList object"); return JS_FALSE; } break; } // TODO Gee: (2004-09-01) EAlign and EVAlign too. default: JS_ReportError(cx, "Setting '%s' uses an unimplemented type", propName.c_str()); break; } return JS_TRUE; } JSBool JSI_IGUIObject::construct(JSContext* cx, JSObject* obj, uint argc, jsval* argv, jsval* UNUSED(rval)) { if (argc == 0) { JS_ReportError(cx, "GUIObject has no default constructor"); return JS_FALSE; } debug_assert(argc == 1); // Store the IGUIObject in the JS object's 'private' area IGUIObject* guiObject = (IGUIObject*)JSVAL_TO_PRIVATE(argv[0]); JS_SetPrivate(cx, obj, guiObject); return JS_TRUE; } JSBool JSI_IGUIObject::getByName(JSContext* cx, JSObject* UNUSED(obj), uint argc, jsval* argv, jsval* rval) { debug_assert(argc == 1); CStr objectName = JS_GetStringBytes(JS_ValueToString(cx, argv[0])); IGUIObject* guiObject = g_GUI.FindObjectByName(objectName); if (!guiObject) { // Not found - return null *rval = JSVAL_NULL; return JS_TRUE; } - JSObject* entity = JS_NewObject(cx, &JSI_IGUIObject::JSI_class, NULL, NULL); - JS_SetPrivate(cx, entity, guiObject); - *rval = OBJECT_TO_JSVAL(entity); + *rval = OBJECT_TO_JSVAL(guiObject->GetJSObject()); return JS_TRUE; } void JSI_IGUIObject::init() { g_ScriptingHost.DefineCustomObjectType(&JSI_class, construct, 1, JSI_props, JSI_methods, NULL, NULL); } JSBool JSI_IGUIObject::toString(JSContext* cx, JSObject* obj, uintN UNUSED(argc), jsval* UNUSED(argv), jsval* rval) { IGUIObject* e = (IGUIObject*)JS_GetPrivate( cx, obj ); char buffer[256]; snprintf(buffer, 256, "[GUIObject: %s]", e->GetName().c_str()); buffer[255] = 0; *rval = STRING_TO_JSVAL(JS_NewStringCopyZ(cx, buffer)); return JS_TRUE; } Index: ps/trunk/source/gui/IGUIObject.h =================================================================== --- ps/trunk/source/gui/IGUIObject.h (revision 5153) +++ ps/trunk/source/gui/IGUIObject.h (revision 5154) @@ -1,543 +1,551 @@ /* The base class of an object --Overview-- All objects are derived from this class, it's an ADT so it can't be used per se Also contains a Dummy object which is used for completely blank objects. --Usage-- Write about how to use it here --Examples-- Provide examples of how to use this code, if necessary --More info-- Check GUI.h */ #ifndef INCLUDED_IGUIOBJECT #define INCLUDED_IGUIOBJECT //-------------------------------------------------------- // Includes / Compiler directives //-------------------------------------------------------- #include "GUIbase.h" #include "GUItext.h" #include #include #include "lib/input.h" // just for IN_PASS #include "ps/XML/Xeromyces.h" #include "gui/scripting/JSInterface_IGUIObject.h" struct SGUISetting; struct SGUIStyle; class CGUI; //-------------------------------------------------------- // Macros //-------------------------------------------------------- //-------------------------------------------------------- // Types //-------------------------------------------------------- // Map with pointers typedef std::map map_Settings; struct JSObject; //-------------------------------------------------------- // Error declarations //-------------------------------------------------------- //-------------------------------------------------------- // Declarations //-------------------------------------------------------- /** * Setting Type * @see SGUISetting * * For use of later macros, all names should be GUIST_ followed * by the code name (case sensitive!). */ #define TYPE(T) GUIST_##T, enum EGUISettingType { #include "GUItypes.h" }; #undef TYPE /** * A GUI Setting is anything that can be inputted from XML as * -attributes (with exceptions). For instance: * * * "style" will be a SGUISetting. */ struct SGUISetting { SGUISetting() : m_pSetting(NULL) {} void *m_pSetting; EGUISettingType m_Type; }; /** * Base settings, all objects possess these settings * in their m_BaseSettings * Instructions can be found in the documentations. */ /*struct SGUIBaseSettings { //int banan; bool m_Absolute; CStr m_Caption; // Is usually set within an XML element and not in the attributes bool m_Enabled; bool m_Ghost; bool m_Hidden; CClientArea m_Size; CStr m_Style; float m_Z; };*/ ////////////////////////////////////////////////////////// /** * GUI object such as a button or an input-box. * Abstract data type ! */ class IGUIObject { friend class CGUI; friend class CInternalCGUIAccessorBase; friend class IGUIScrollBar; friend class GUITooltip; // Allow getProperty to access things like GetParent() friend JSBool JSI_IGUIObject::getProperty(JSContext* cx, JSObject* obj, jsval id, jsval* vp); friend JSBool JSI_IGUIObject::setProperty(JSContext* cx, JSObject* obj, jsval id, jsval* vp); public: IGUIObject(); virtual ~IGUIObject(); /** * Checks if mouse is hovering this object. * The mouse position is cached in CGUI. * * This function checks if the mouse is hovering the * rectangle that the base setting "size" makes. * Although it is virtual, so one could derive * an object from CButton, which changes only this * to checking the circle that "size" makes. * * @return true if mouse is hovering */ virtual bool MouseOver(); //-------------------------------------------------------- /** @name Leaf Functions */ //-------------------------------------------------------- //@{ /// Get object name, name is unique const CStr& GetName() const { return m_Name; } /// Get object name void SetName(const CStr& Name) { m_Name = Name; } // Get Presentable name. // Will change all internally set names to something like "" CStr GetPresentableName() const; /** * Adds object and its children to the map, it's name being the * first part, and the second being itself. * * @param ObjectMap Adds this to the map_pObjects. * * @throws PS_NEEDS_NAME Name is missing * @throws PS_NAME_AMBIGUITY Name is already taken */ void AddToPointersMap(map_pObjects &ObjectMap); /** * Notice nothing will be returned or thrown if the child hasn't * been inputted into the GUI yet. This is because that's were * all is checked. Now we're just linking two objects, but * it's when we're inputting them into the GUI we'll check * validity! Notice also when adding it to the GUI this function * will inevitably have been called by CGUI::AddObject which * will catch the throw and return the error code. * i.e. The user will never put in the situation wherein a throw * must be caught, the GUI's internal error handling will be * completely transparent to the interfacially sequential model. * * @param pChild Child to add * * @throws PS_RESULT from CGUI::UpdateObjects(). */ void AddChild(IGUIObject *pChild); //@} //-------------------------------------------------------- /** @name Iterate */ //-------------------------------------------------------- //@{ vector_pObjects::iterator ChildrenItBegin() { return m_Children.begin(); } vector_pObjects::iterator ChildrenItEnd() { return m_Children.end(); } //@} //-------------------------------------------------------- /** @name Settings Management */ //-------------------------------------------------------- //@{ /** * Checks if settings exists, only available for derived * classes that has this set up, that's why the base * class just returns false * * @param Setting setting name * @return True if settings exist. */ bool SettingExists(const CStr& Setting) const; /** * All sizes are relative to resolution, and the calculation * is not wanted in real time, therefore it is cached, update * the cached size with this function. */ void UpdateCachedSize(); /** * Should be called every time the settings has been updated * will also send a message GUIM_SETTINGS_UPDATED, so that * if a derived object wants to add things to be updated, * they add it in that message part, this is a better solution * than making this virtual, since the updates that the base * class does, are the most essential. * This is not private since there should be no harm in * checking validity. * * @throws TODO not quite settled yet. */ void CheckSettingsValidity(); /** * Sets up a map_size_t to include the variables in m_BaseSettings * * @param SettingsInfo Pointers that should be filled with base variables */ //void SetupBaseSettingsInfo(map_Settings &SettingsInfo); /** * Set a setting by string, regardless of what type it is. * * example a CRect(10,10,20,20) would be "10 10 20 20" * * @param Setting Setting by name * @param Value Value to set to * * @return PS_RESULT (PS_OK if successful) */ PS_RESULT SetSetting(const CStr& Setting, const CStr& Value, const bool& SkipMessage=false); /** * Retrieves the type of a named setting. * * @param Setting Setting by name * @param Type Stores an EGUISettingType * @return PS_RESULT (PS_OK if successful) */ PS_RESULT GetSettingType(const CStr& Setting, EGUISettingType &Type) const; /** * Set the script handler for a particular object-specific action * * @param Action Name of action * @param Code Javascript code to execute when the action occurs * @param pGUI GUI instance to associate the script with */ void RegisterScriptHandler(const CStr& Action, const CStr& Code, CGUI* pGUI); + + /** + * Retrieves the JSObject representing this GUI object. + */ + JSObject* GetJSObject(); //@} protected: //-------------------------------------------------------- /** @name Called by CGUI and friends * * Methods that the CGUI will call using * its friendship, these should not * be called by user. * These functions' security are a lot * what constitutes the GUI's */ //-------------------------------------------------------- //@{ /** * Add a setting to m_Settings * * @param Type Setting type * @param Name Setting reference name */ void AddSetting(const EGUISettingType &Type, const CStr& Name); /** * Calls Destroy on all children, and deallocates all memory. * MEGA TODO Should it destroy it's children? */ virtual void Destroy(); /** * This function is called with different messages * for instance when the mouse enters the object. * * @param Message GUI Message */ virtual void HandleMessage(const SGUIMessage& UNUSED(Message)) {} /** * Draws the object. * * @throws PS_RESULT if any. But this will mostlikely be * very rare since if an object is drawn unsuccessfully * it'll probably only output in the Error log, and not * disrupt the whole GUI drawing. */ virtual void Draw()=0; /** * Some objects need to handle the SDL_Event_ manually. * For instance the input box. * * Only the object with focus will have this function called. * * Returns either IN_PASS or IN_HANDLED. If IN_HANDLED, then * the key won't be passed on and processed by other handlers. * This is used for keys that the GUI uses. */ virtual InReaction ManuallyHandleEvent(const SDL_Event_* UNUSED(ev)) { return IN_PASS; } /** * Loads a style. * * @param GUIinstance Reference to the GUI * @param StyleName Style by name */ void LoadStyle(CGUI &GUIinstance, const CStr& StyleName); /** * Loads a style. * * @param Style The style object. */ void LoadStyle(const SGUIStyle &Style); /** * Returns not the Z value, but the actual buffered Z value, i.e. if it's * defined relative, then it will check its parent's Z value and add * the relativity. * * @return Actual Z value on the screen. */ virtual float GetBufferedZ() const; // This is done internally CGUI *GetGUI() { return m_pGUI; } const CGUI *GetGUI() const { return m_pGUI; } void SetGUI(CGUI * const &pGUI) { m_pGUI = pGUI; } // Set parent void SetParent(IGUIObject *pParent) { m_pParent = pParent; } virtual void ResetStates() { m_MouseHovering = false; } /** * Take focus! */ void SetFocus(); /** * Check if object is focused. */ bool IsFocused() const; /** * NOTE! This will not just return m_pParent, when that is * need use it! There is one exception to it, when the parent is * the top-node (the object that isn't a real object), this * will return NULL, so that the top-node's children are * seemingly parentless. * * @return Pointer to parent */ IGUIObject *GetParent() const; /** * Same as reference, but returns a const */ // IGUIObject const *GetParent() const; /** * You input the setting struct you want, and it will return a pointer to * the struct. * * @param SettingsStruct tells us which pointer ot return */ //virtual void *GetStructPointer(const EGUISettingsStruct &SettingsStruct) const; /** * Get Mouse from CGUI. */ CPos GetMousePos() const; /** * Handle additional children to the -tag. In IGUIObject, this function does * nothing. In CList and CDropDown, it handles the , used to build the data. * * Returning false means the object doesn't recognize the child. Should be reported. * Notice 'false' is default, because an object not using this function, should not * have any additional children (and this function should never be called). */ virtual bool HandleAdditionalChildren(const XMBElement& UNUSED(child), CXeromyces* UNUSED(pFile)) { return false; } /** * Cached size, real size m_Size is actually dependent on resolution * and can have different *real* outcomes, this is the real outcome * cached to avoid slow calculations in real time. */ CRect m_CachedActualSize; /** * Execute the script for a particular action. * Does nothing if no script has been registered for that action. * * @param Action Name of action */ void ScriptEvent(const CStr& Action); void SetScriptHandler(const CStr& Action, JSObject* Function); //@} private: //-------------------------------------------------------- /** @name Internal functions */ //-------------------------------------------------------- //@{ /** * Inputs a reference pointer, checks if the new inputted object * if hovered, if so, then check if this's Z value is greater * than the inputted object... If so then the object is closer * and we'll replace the pointer with this. * Also Notice input can be NULL, which means the Z value demand * is out. NOTICE you can't input NULL as const so you'll have * to set an object to NULL. * * @param pObject Object pointer, can be either the old one, or * the new one. */ void ChooseMouseOverAndClosest(IGUIObject* &pObject); /** * Inputes the object that is currently hovered, this function * updates this object accordingly (i.e. if it's the object * being inputted one thing happens, and not, another). * * @param pMouseOver Object that is currently hovered, * can OF COURSE be NULL too! */ void UpdateMouseOver(IGUIObject * const &pMouseOver); // Is the object a Root object, in philosophy, this means it // has got no parent, and technically, it's got the m_BaseObject // as parent. bool IsRootObject() const; // Variables protected: // Name of object CStr m_Name; // Constructed on the heap, will be destroyed along with the the object // TODO Gee: really the above? vector_pObjects m_Children; // Pointer to parent IGUIObject *m_pParent; //This represents the last click time for each mouse button double m_LastClickTime[6]; /** * This is an array of true or false, each element is associated with * a string representing a setting. Number of elements is equal to * number of settings. * * A true means the setting has been manually set in the file when * read. This is important to know because I don't want to force * the user to include its -XML-files first, so somehow * the GUI needs to know which settings were set, and which is meant * to */ // More variables // Is mouse hovering the object? used with the function MouseOver() bool m_MouseHovering; /** * Settings pool, all an object's settings are located here * If a derived object has got more settings that the base * settings, it's because they have a new version of the * function SetupSettings(). * * @see SetupSettings() */ public: std::map m_Settings; private: // An object can't function stand alone CGUI *m_pGUI; // Internal storage for registered script handlers. std::map m_ScriptHandlers; + + // Cached JSObject representing this GUI object + JSObject *m_JSObject; }; /** * Dummy object used primarily for the root object * or objects of type 'empty' */ class CGUIDummyObject : public IGUIObject { GUI_OBJECT(CGUIDummyObject) public: virtual void HandleMessage(const SGUIMessage& UNUSED(Message)) {} virtual void Draw() {} // Empty can never be hovered. It is only a category. virtual bool MouseOver() { return false; } }; #endif Index: ps/trunk/source/gui/IGUIObject.cpp =================================================================== --- ps/trunk/source/gui/IGUIObject.cpp (revision 5153) +++ ps/trunk/source/gui/IGUIObject.cpp (revision 5154) @@ -1,524 +1,542 @@ /* IGUIObject */ #include "precompiled.h" #include "GUI.h" ///// janwas: again, including etiquette? #include "ps/Parser.h" ///// #include "gui/scripting/JSInterface_IGUIObject.h" #include "gui/scripting/JSInterface_GUITypes.h" extern int g_xres, g_yres; using namespace std; //------------------------------------------------------------------- // Implementation Macros //------------------------------------------------------------------- //------------------------------------------------------------------- // Constructor / Destructor //------------------------------------------------------------------- IGUIObject::IGUIObject() : m_pGUI(NULL), m_pParent(NULL), - m_MouseHovering(false) + m_MouseHovering(false), + m_JSObject(NULL) { AddSetting(GUIST_bool, "enabled"); AddSetting(GUIST_bool, "hidden"); AddSetting(GUIST_CClientArea, "size"); AddSetting(GUIST_CStr, "style"); AddSetting(GUIST_CStr, "hotkey" ); AddSetting(GUIST_float, "z"); AddSetting(GUIST_bool, "absolute"); AddSetting(GUIST_bool, "ghost"); // Setup important defaults GUI::SetSetting(this, "hidden", false); GUI::SetSetting(this, "ghost", false); GUI::SetSetting(this, "enabled", true); GUI::SetSetting(this, "absolute", true); for (int i=0; i<6; i++) m_LastClickTime[i]=0; bool hidden=true; GUI::GetSetting(this, "hidden", hidden); } IGUIObject::~IGUIObject() { { map::iterator it; for (it = m_Settings.begin(); it != m_Settings.end(); ++it) { switch (it->second.m_Type) { // delete() needs to know the type of the variable - never delete a void* #define TYPE(t) case GUIST_##t: delete (t*)it->second.m_pSetting; break; #include "GUItypes.h" #undef TYPE default: debug_warn("Invalid setting type"); } } } { std::map::iterator it; for (it = m_ScriptHandlers.begin(); it != m_ScriptHandlers.end(); ++it) { JS_RemoveRoot(g_ScriptingHost.getContext(), it->second); delete it->second; } } + + if (m_JSObject) + JS_RemoveRoot(g_ScriptingHost.getContext(), &m_JSObject); } //------------------------------------------------------------------- // Functions //------------------------------------------------------------------- void IGUIObject::AddChild(IGUIObject *pChild) { // // debug_assert(pChild); pChild->SetParent(this); m_Children.push_back(pChild); // If this (not the child) object is already attached // to a CGUI, it pGUI pointer will be non-null. // This will mean we'll have to check if we're using // names already used. if (pChild->GetGUI()) { try { // Atomic function, if it fails it won't // have changed anything //UpdateObjects(); pChild->GetGUI()->UpdateObjects(); } catch (PS_RESULT e) { // If anything went wrong, reverse what we did and throw // an exception telling it never added a child m_Children.erase( m_Children.end()-1 ); // We'll throw the same exception for easier // error handling throw e; } } // else do nothing } void IGUIObject::AddToPointersMap(map_pObjects &ObjectMap) { // Just don't do anything about the top node if (m_pParent == NULL) return; // Now actually add this one // notice we won't add it if it's doesn't have any parent // (i.e. being the base object) if (m_Name.empty()) { throw PS_NEEDS_NAME; } if (ObjectMap.count(m_Name) > 0) { throw PS_NAME_AMBIGUITY; } else { ObjectMap[m_Name] = this; } } void IGUIObject::Destroy() { // Is there anything besides the children to destroy? } // Notice if using this, the naming convention of GUIST_ should be strict. #define TYPE(type) \ case GUIST_##type: \ m_Settings[Name].m_pSetting = new type(); \ break; void IGUIObject::AddSetting(const EGUISettingType &Type, const CStr& Name) { // Is name already taken? if (m_Settings.count(Name) >= 1) return; // Construct, and set type m_Settings[Name].m_Type = Type; switch (Type) { // Construct the setting. #include "GUItypes.h" default: debug_warn("IGUIObject::AddSetting failed, type not recognized!"); break; } } #undef TYPE bool IGUIObject::MouseOver() { if(!GetGUI()) throw PS_NEEDS_PGUI; return m_CachedActualSize.PointInside(GetMousePos()); } CPos IGUIObject::GetMousePos() const { return ((GetGUI())?(GetGUI()->m_MousePos):CPos()); } void IGUIObject::UpdateMouseOver(IGUIObject * const &pMouseOver) { // Check if this is the object being hovered. if (pMouseOver == this) { if (!m_MouseHovering) { // It wasn't hovering, so that must mean it just entered HandleMessage(GUIM_MOUSE_ENTER); ScriptEvent("mouseenter"); } // Either way, set to true m_MouseHovering = true; // call mouse over HandleMessage(GUIM_MOUSE_OVER); ScriptEvent("mousemove"); } else // Some other object (or none) is hovered { if (m_MouseHovering) { m_MouseHovering = false; HandleMessage(GUIM_MOUSE_LEAVE); ScriptEvent("mouseleave"); } } } bool IGUIObject::SettingExists(const CStr& Setting) const { // Because GetOffsets will direct dynamically defined // classes with polymorphism to respective ms_SettingsInfo // we need to make no further updates on this function // in derived classes. //return (GetSettingsInfo().count(Setting) >= 1); return (m_Settings.count(Setting) >= 1); } #define TYPE(type) \ else \ if (set.m_Type == GUIST_##type) \ { \ type _Value; \ if (!GUI::ParseString(Value, _Value)) \ return PS_FAIL; \ \ GUI::SetSetting(this, Setting, _Value, SkipMessage); \ } PS_RESULT IGUIObject::SetSetting(const CStr& Setting, const CStr& Value, const bool& SkipMessage) { if (!SettingExists(Setting)) { return PS_FAIL; } // Get setting SGUISetting set = m_Settings[Setting]; if (0); // else... #include "GUItypes.h" else { return PS_FAIL; } return PS_OK; } #undef TYPE PS_RESULT IGUIObject::GetSettingType(const CStr& Setting, EGUISettingType &Type) const { if (!SettingExists(Setting)) return PS_SETTING_FAIL; if (m_Settings.find(Setting) == m_Settings.end()) return PS_FAIL; Type = m_Settings.find(Setting)->second.m_Type; return PS_OK; } void IGUIObject::ChooseMouseOverAndClosest(IGUIObject* &pObject) { if (MouseOver()) { // Check if we've got competition at all if (pObject == NULL) { pObject = this; return; } // Or if it's closer if (GetBufferedZ() >= pObject->GetBufferedZ()) { pObject = this; return; } } } IGUIObject *IGUIObject::GetParent() const { // Important, we're not using GetParent() for these // checks, that could screw it up if (m_pParent) { if (m_pParent->m_pParent == NULL) return NULL; } return m_pParent; } void IGUIObject::UpdateCachedSize() { bool absolute; GUI::GetSetting(this, "absolute", absolute); CClientArea ca; GUI::GetSetting(this, "size", ca); // If absolute="false" and the object has got a parent, // use its cached size instead of the screen. Notice // it must have just been cached for it to work. if (absolute == false && m_pParent && !IsRootObject()) m_CachedActualSize = ca.GetClientArea(m_pParent->m_CachedActualSize); else m_CachedActualSize = ca.GetClientArea(CRect(0.f, 0.f, (float)g_xres, (float)g_yres)); } void IGUIObject::LoadStyle(CGUI &GUIinstance, const CStr& StyleName) { // Fetch style if (GUIinstance.m_Styles.count(StyleName)==1) { LoadStyle(GUIinstance.m_Styles[StyleName]); } else { debug_warn("IGUIObject::LoadStyle failed"); } } void IGUIObject::LoadStyle(const SGUIStyle &Style) { // Iterate settings, it won't be able to set them all probably, but that doesn't matter std::map::const_iterator cit; for (cit = Style.m_SettingsDefaults.begin(); cit != Style.m_SettingsDefaults.end(); ++cit) { // Try set setting in object SetSetting(cit->first, cit->second); // It doesn't matter if it fail, it's not suppose to be able to set every setting. // since it's generic. // The beauty with styles is that it can contain more settings // than exists for the objects using it. So if the SetSetting // fails, don't care. } } float IGUIObject::GetBufferedZ() const { bool absolute; GUI::GetSetting(this, "absolute", absolute); float Z; GUI::GetSetting(this, "z", Z); if (absolute) return Z; else { if (GetParent()) return GetParent()->GetBufferedZ() + Z; else { // In philosophy, a parentless object shouldn't be able to have a relative sizing, // but we'll accept it so that absolute can be used as default without a complaint. // Also, you could consider those objects children to the screen resolution. return Z; } } } // TODO Gee: keep this function and all??? void IGUIObject::CheckSettingsValidity() { bool hidden; GUI::GetSetting(this, "hidden", hidden); // If we hide an object, reset many of its parts if (hidden) { // Simulate that no object is hovered for this object and all its children // why? because it's try { GUI::RecurseObject(0, this, &IGUIObject::UpdateMouseOver, NULL); } catch (PS_RESULT) { } } try { // Send message to itself HandleMessage(GUIM_SETTINGS_UPDATED); ScriptEvent("update"); } catch (PS_RESULT) { } } void IGUIObject::RegisterScriptHandler(const CStr& Action, const CStr& Code, CGUI* pGUI) { const int paramCount = 1; const char* paramNames[paramCount] = { "mouse" }; // Location to report errors from CStr CodeName = GetName()+" "+Action; // Generate a unique name static int x=0; char buf[64]; sprintf(buf, "__eventhandler%d", x++); JSFunction* func = JS_CompileFunction(g_ScriptingHost.getContext(), pGUI->m_ScriptObject, buf, paramCount, paramNames, (const char*)Code, Code.length(), CodeName, 0); debug_assert(func); // TODO: Handle errors if (func) SetScriptHandler(Action, JS_GetFunctionObject(func)); } void IGUIObject::SetScriptHandler(const CStr& Action, JSObject* Function) { JSObject** obj = new JSObject*; *obj = Function; JS_AddRoot(g_ScriptingHost.getContext(), obj); if (m_ScriptHandlers[Action]) { JS_RemoveRoot(g_ScriptingHost.getContext(), m_ScriptHandlers[Action]); delete m_ScriptHandlers[Action]; } m_ScriptHandlers[Action] = obj; } void IGUIObject::ScriptEvent(const CStr& Action) { map::iterator it = m_ScriptHandlers.find(Action); if (it == m_ScriptHandlers.end()) return; // PRIVATE_TO_JSVAL assumes two-byte alignment, // so make sure that's always true debug_assert(! ((jsval)this & JSVAL_INT)); // The IGUIObject needs to be stored inside the script's object jsval guiObject = PRIVATE_TO_JSVAL(this); // Make a 'this', allowing access to the IGUIObject JSObject* jsGuiObject = JS_ConstructObjectWithArguments(g_ScriptingHost.getContext(), &JSI_IGUIObject::JSI_class, NULL, m_pGUI->m_ScriptObject, 1, &guiObject); debug_assert(jsGuiObject); // TODO: Handle errors // Prevent it from being garbage-collected before it's passed into the function JS_AddRoot(g_ScriptingHost.getContext(), &jsGuiObject); // Set up the 'mouse' parameter jsval mouseParams[3]; mouseParams[0] = INT_TO_JSVAL(m_pGUI->m_MousePos.x); mouseParams[1] = INT_TO_JSVAL(m_pGUI->m_MousePos.y); mouseParams[2] = INT_TO_JSVAL(m_pGUI->m_MouseButtons); JSObject* mouseObj = JS_ConstructObjectWithArguments(g_ScriptingHost.getContext(), &JSI_GUIMouse::JSI_class, NULL, m_pGUI->m_ScriptObject, 3, mouseParams); debug_assert(mouseObj); // TODO: Handle errors // Don't garbage collect the mouse JS_AddRoot(g_ScriptingHost.getContext(), &mouseObj); const int paramCount = 1; jsval paramData[paramCount]; paramData[0] = OBJECT_TO_JSVAL(mouseObj); jsval result; JSBool ok = JS_CallFunctionValue(g_ScriptingHost.getContext(), jsGuiObject, OBJECT_TO_JSVAL(*it->second), 1, paramData, &result); if (!ok) { JS_ReportError(g_ScriptingHost.getContext(), "Errors executing script action \"%s\"", Action.c_str()); } // Allow the temporary parameters to be garbage-collected JS_RemoveRoot(g_ScriptingHost.getContext(), &mouseObj); JS_RemoveRoot(g_ScriptingHost.getContext(), &jsGuiObject); } +JSObject* IGUIObject::GetJSObject() +{ + // Cache the object when somebody first asks for it, because otherwise + // we end up doing far too much object allocation. TODO: Would be nice to + // not have these objects hang around forever using up memory, though. + if (! m_JSObject) + { + m_JSObject = JS_NewObject(g_ScriptingHost.getContext(), &JSI_IGUIObject::JSI_class, NULL, NULL); + JS_AddRoot(g_ScriptingHost.getContext(), &m_JSObject); + JS_SetPrivate(g_ScriptingHost.getContext(), m_JSObject, this); + } + return m_JSObject; +} + CStr IGUIObject::GetPresentableName() const { // __internal(), must be at least 13 letters to be able to be // an internal name if (m_Name.length() <= 12) return m_Name; if (m_Name.substr(0, 10) == "__internal") return CStr("[unnamed object]"); else return m_Name; } void IGUIObject::SetFocus() { GetGUI()->m_FocusedObject = this; } bool IGUIObject::IsFocused() const { return GetGUI()->m_FocusedObject == this; } bool IGUIObject::IsRootObject() const { return (GetGUI() != 0 && m_pParent == GetGUI()->m_BaseObject); } Index: ps/trunk/source/tools/atlas/wxJS/gui/control/gauge.h =================================================================== --- ps/trunk/source/tools/atlas/wxJS/gui/control/gauge.h (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/gui/control/gauge.h (revision 5154) @@ -0,0 +1,78 @@ +/* + * wxJavaScript - gauge.h + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: gauge.h 682 2007-04-24 20:38:18Z fbraem $ + */ +#ifndef _WXJSGauge_H +#define _WXJSGauge_H + +namespace wxjs +{ + namespace gui + { + class Gauge: public ApiWrapper + { + public: + + static bool GetProperty(wxGauge *p, + JSContext *cx, + JSObject *obj, + int id, + jsval *vp); + static bool SetProperty(wxGauge *p, + JSContext *cx, + JSObject *obj, + int id, + jsval *vp); + static bool AddProperty(wxGauge *p, + JSContext *cx, + JSObject *obj, + const wxString &prop, + jsval *vp); + + static bool DeleteProperty(wxGauge *p, + JSContext* cx, + JSObject* obj, + const wxString &prop); + static wxGauge* Construct(JSContext *cx, + JSObject *obj, + uintN argc, + jsval *argv, + bool constructing); + + WXJS_DECLARE_CONSTANT_MAP() + + WXJS_DECLARE_PROPERTY_MAP() + enum + { + P_BEZEL_FACE + , P_RANGE + , P_SHADOW_WIDTH + , P_VALUE + }; + + WXJS_DECLARE_METHOD_MAP() + WXJS_DECLARE_METHOD(create) + }; + }; // namespace gui +}; // namespace wxjs +#endif //_WXJSGauge_H Property changes on: ps/trunk/source/tools/atlas/wxJS/gui/control/gauge.h ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/AtlasUI/ScenarioEditor/ScenarioEditor.h =================================================================== --- ps/trunk/source/tools/atlas/AtlasUI/ScenarioEditor/ScenarioEditor.h (revision 5153) +++ ps/trunk/source/tools/atlas/AtlasUI/ScenarioEditor/ScenarioEditor.h (revision 5154) @@ -1,55 +1,56 @@ #ifndef INCLUDED_SCENARIOEDITOR #define INCLUDED_SCENARIOEDITOR #include "General/AtlasWindowCommandProc.h" #include "CustomControls/FileHistory/FileHistory.h" #include "SectionLayout.h" class ScriptInterface; class ScenarioEditor : public wxFrame { public: - ScenarioEditor(wxWindow* parent); + ScenarioEditor(wxWindow* parent, ScriptInterface& scriptInterface); void OnClose(wxCloseEvent& event); void OnTimer(wxTimerEvent& event); void OnIdle(wxIdleEvent& event); // void OnNew(wxCommandEvent& event); void OnOpen(wxCommandEvent& event); void OnSave(wxCommandEvent& event); void OnSaveAs(wxCommandEvent& event); void OnMRUFile(wxCommandEvent& event); void OnQuit(wxCommandEvent& event); void OnUndo(wxCommandEvent& event); void OnRedo(wxCommandEvent& event); void OnWireframe(wxCommandEvent& event); void OnMessageTrace(wxCommandEvent& event); void OnScreenshot(wxCommandEvent& event); void OnMediaPlayer(wxCommandEvent& event); void OnJavaScript(wxCommandEvent& event); void OpenFile(const wxString& name); static AtlasWindowCommandProc& GetCommandProc(); static float GetSpeedModifier(); - ScriptInterface& GetScriptInterface() const { return *m_ScriptInterface; } + ScriptInterface& GetScriptInterface() const { return m_ScriptInterface; } private: + ScriptInterface& m_ScriptInterface; + wxTimer m_Timer; SectionLayout m_SectionLayout; - std::auto_ptr m_ScriptInterface; void SetOpenFilename(const wxString& filename); wxString m_OpenFilename; FileHistory m_FileHistory; DECLARE_EVENT_TABLE(); }; #endif // INCLUDED_SCENARIOEDITOR Index: ps/trunk/source/tools/atlas/AtlasUI/ScenarioEditor/ScenarioEditor.cpp =================================================================== --- ps/trunk/source/tools/atlas/AtlasUI/ScenarioEditor/ScenarioEditor.cpp (revision 5153) +++ ps/trunk/source/tools/atlas/AtlasUI/ScenarioEditor/ScenarioEditor.cpp (revision 5154) @@ -1,720 +1,720 @@ #include "precompiled.h" #include "ScenarioEditor.h" #include "wx/busyinfo.h" #include "wx/config.h" #include "wx/evtloop.h" #include "wx/ffile.h" #include "wx/filename.h" #include "wx/image.h" #include "wx/tooltip.h" #include "General/AtlasEventLoop.h" #include "General/Datafile.h" #include "HighResTimer/HighResTimer.h" #include "Buttons/ToolButton.h" #include "CustomControls/Canvas/Canvas.h" #include "GameInterface/MessagePasser.h" #include "GameInterface/Messages.h" #include "AtlasScript/ScriptInterface.h" #include "Tools/Common/Tools.h" static HighResTimer g_Timer; using namespace AtlasMessage; ////////////////////////////////////////////////////////////////////////// // GL functions exported from DLL, and called by game (in a separate // thread to the standard wx one) ATLASDLLIMPEXP void Atlas_GLSetCurrent(void* canvas) { static_cast(canvas)->SetCurrent(); } ATLASDLLIMPEXP void Atlas_GLSwapBuffers(void* canvas) { static_cast(canvas)->SwapBuffers(); } ////////////////////////////////////////////////////////////////////////// class GameCanvas : public Canvas { public: GameCanvas(wxWindow* parent, int* attribList) : Canvas(parent, attribList, wxWANTS_CHARS), m_MouseState(NONE), m_LastMouseState(NONE) { } private: bool KeyScroll(wxKeyEvent& evt, bool enable) { int dir; switch (evt.GetKeyCode()) { case WXK_LEFT: dir = eScrollConstantDir::LEFT; break; case WXK_RIGHT: dir = eScrollConstantDir::RIGHT; break; case WXK_UP: dir = eScrollConstantDir::FORWARDS; break; case WXK_DOWN: dir = eScrollConstantDir::BACKWARDS; break; case WXK_SHIFT: case WXK_CONTROL: dir = -1; break; default: return false; } float speed = 120.f * ScenarioEditor::GetSpeedModifier(); if (dir == -1) // changed modifier keys - update all currently-scrolling directions { if (wxGetKeyState(WXK_LEFT)) POST_MESSAGE(ScrollConstant, (eRenderView::GAME, eScrollConstantDir::LEFT, speed)); if (wxGetKeyState(WXK_RIGHT)) POST_MESSAGE(ScrollConstant, (eRenderView::GAME, eScrollConstantDir::RIGHT, speed)); if (wxGetKeyState(WXK_UP)) POST_MESSAGE(ScrollConstant, (eRenderView::GAME, eScrollConstantDir::FORWARDS, speed)); if (wxGetKeyState(WXK_DOWN)) POST_MESSAGE(ScrollConstant, (eRenderView::GAME, eScrollConstantDir::BACKWARDS, speed)); } else { POST_MESSAGE(ScrollConstant, (eRenderView::GAME, dir, enable ? speed : 0.0f)); } return true; } void OnKeyDown(wxKeyEvent& evt) { if (GetCurrentTool().OnKey(evt, ITool::KEY_DOWN)) { // Key event has been handled by the tool, so don't try // to use it for camera motion too return; } if (KeyScroll(evt, true)) return; evt.Skip(); } void OnKeyUp(wxKeyEvent& evt) { if (GetCurrentTool().OnKey(evt, ITool::KEY_UP)) return; if (KeyScroll(evt, false)) return; evt.Skip(); } void OnChar(wxKeyEvent& evt) { if (GetCurrentTool().OnKey(evt, ITool::KEY_CHAR)) return; int dir = 0; if (evt.GetKeyCode() == '-' || evt.GetKeyCode() == '_') dir = -1; else if (evt.GetKeyCode() == '+' || evt.GetKeyCode() == '=') dir = +1; // TODO: internationalisation (-/_ and +/= don't always share a key) if (dir) { float speed = 16.f; if (wxGetKeyState(WXK_SHIFT)) speed *= 4.f; POST_MESSAGE(SmoothZoom, (eRenderView::GAME, speed*dir)); } else evt.Skip(); } virtual void HandleMouseEvent(wxMouseEvent& evt) { // TODO or at least to think about: When using other controls in the // editor, it's annoying that keyboard/scrollwheel no longer navigate // around the world until you click on it. // Setting focus back whenever the mouse moves over the GL window // feels like a fairly natural solution to me, since I can use // e.g. brush-editing controls normally, and then move the mouse to // see the brush outline and magically get given back full control // of the camera. if (evt.Moving()) SetFocus(); if (GetCurrentTool().OnMouse(evt)) { // Mouse event has been handled by the tool, so don't try // to use it for camera motion too return; } // Global mouse event handlers (for camera motion) if (evt.GetWheelRotation()) { float speed = 16.f * ScenarioEditor::GetSpeedModifier(); POST_MESSAGE(SmoothZoom, (eRenderView::GAME, evt.GetWheelRotation() * speed / evt.GetWheelDelta())); } else { if (evt.MiddleIsDown()) { if (wxGetKeyState(WXK_CONTROL) || evt.RightIsDown()) m_MouseState = ROTATEAROUND; else m_MouseState = SCROLL; } else m_MouseState = NONE; if (m_MouseState != m_LastMouseState) { switch (m_MouseState) { case NONE: break; case SCROLL: POST_MESSAGE(Scroll, (eRenderView::GAME, eScrollType::FROM, evt.GetPosition())); break; case ROTATEAROUND: POST_MESSAGE(RotateAround, (eRenderView::GAME, eRotateAroundType::FROM, evt.GetPosition())); break; default: wxFAIL; } m_LastMouseState = m_MouseState; } else if (evt.Dragging()) { switch (m_MouseState) { case NONE: break; case SCROLL: POST_MESSAGE(Scroll, (eRenderView::GAME, eScrollType::TO, evt.GetPosition())); break; case ROTATEAROUND: POST_MESSAGE(RotateAround, (eRenderView::GAME, eRotateAroundType::TO, evt.GetPosition())); break; default: wxFAIL; } } } } enum { NONE, SCROLL, ROTATEAROUND }; int m_MouseState, m_LastMouseState; DECLARE_EVENT_TABLE(); }; BEGIN_EVENT_TABLE(GameCanvas, Canvas) EVT_KEY_DOWN(GameCanvas::OnKeyDown) EVT_KEY_UP(GameCanvas::OnKeyUp) EVT_CHAR(GameCanvas::OnChar) END_EVENT_TABLE() ////////////////////////////////////////////////////////////////////////// volatile bool g_FrameHasEnded; // Called from game thread ATLASDLLIMPEXP void Atlas_NotifyEndOfFrame() { g_FrameHasEnded = true; } enum { ID_Quit = 1, // ID_New, ID_Open, ID_Save, ID_SaveAs, ID_Wireframe, ID_MessageTrace, ID_Screenshot, ID_JavaScript, ID_Toolbar // must be last in the list }; BEGIN_EVENT_TABLE(ScenarioEditor, wxFrame) EVT_CLOSE(ScenarioEditor::OnClose) EVT_TIMER(wxID_ANY, ScenarioEditor::OnTimer) // EVT_MENU(ID_New, ScenarioEditor::OnNew) EVT_MENU(ID_Open, ScenarioEditor::OnOpen) EVT_MENU(ID_Save, ScenarioEditor::OnSave) EVT_MENU(ID_SaveAs, ScenarioEditor::OnSaveAs) EVT_MENU_RANGE(wxID_FILE1, wxID_FILE9, ScenarioEditor::OnMRUFile) EVT_MENU(ID_Quit, ScenarioEditor::OnQuit) EVT_MENU(wxID_UNDO, ScenarioEditor::OnUndo) EVT_MENU(wxID_REDO, ScenarioEditor::OnRedo) EVT_MENU(ID_Wireframe, ScenarioEditor::OnWireframe) EVT_MENU(ID_MessageTrace, ScenarioEditor::OnMessageTrace) EVT_MENU(ID_Screenshot, ScenarioEditor::OnScreenshot) EVT_MENU(ID_JavaScript, ScenarioEditor::OnJavaScript) EVT_IDLE(ScenarioEditor::OnIdle) END_EVENT_TABLE() static AtlasWindowCommandProc g_CommandProc; AtlasWindowCommandProc& ScenarioEditor::GetCommandProc() { return g_CommandProc; } -ScenarioEditor::ScenarioEditor(wxWindow* parent) +ScenarioEditor::ScenarioEditor(wxWindow* parent, ScriptInterface& scriptInterface) : wxFrame(parent, wxID_ANY, _T(""), wxDefaultPosition, wxSize(1024, 768)) -, m_FileHistory(_T("Scenario Editor")), m_ScriptInterface(new ScriptInterface()) +, m_FileHistory(_T("Scenario Editor")), m_ScriptInterface(scriptInterface) { // Global application initialisation: // wxLog::SetTraceMask(wxTraceMessages); SetOpenFilename(_T("")); SetIcon(wxIcon(_T("ICON_ScenarioEditor"))); wxToolTip::Enable(true); wxImage::AddHandler(new wxPNGHandler); ////////////////////////////////////////////////////////////////////////// // Script interface functions - m_ScriptInterface->RegisterFunction("GetDataDirectory"); + GetScriptInterface().RegisterFunction("GetDataDirectory"); { const wxString relativePath (_T("tools/atlas/scripts/main.js")); wxFileName filename (relativePath, wxPATH_UNIX); filename.MakeAbsolute(Datafile::GetDataDirectory()); wxFFile file (filename.GetFullPath()); wxString script; if (! file.ReadAll(&script)) wxLogError(_("Failed to read script")); GetScriptInterface().LoadScript(filename.GetFullName(), script); } ////////////////////////////////////////////////////////////////////////// // Menu wxMenuBar* menuBar = new wxMenuBar; SetMenuBar(menuBar); wxMenu *menuFile = new wxMenu; menuBar->Append(menuFile, _("&File")); { // menuFile->Append(ID_New, _("&New")); menuFile->Append(ID_Open, _("&Open...")); menuFile->Append(ID_Save, _("&Save")); menuFile->Append(ID_SaveAs, _("Save &As...")); menuFile->AppendSeparator();//----------- menuFile->Append(ID_Quit, _("E&xit")); m_FileHistory.UseMenu(menuFile);//------- m_FileHistory.AddFilesToMenu(); } // m_menuItem_Save = menuFile->FindItem(ID_Save); // remember this item, to let it be greyed out // wxASSERT(m_menuItem_Save); wxMenu *menuEdit = new wxMenu; menuBar->Append(menuEdit, _("&Edit")); { menuEdit->Append(wxID_UNDO, _("&Undo")); menuEdit->Append(wxID_REDO, _("&Redo")); } GetCommandProc().SetEditMenu(menuEdit); GetCommandProc().Initialize(); wxMenu *menuMisc = new wxMenu; menuBar->Append(menuMisc, _("&Misc hacks")); { menuMisc->AppendCheckItem(ID_Wireframe, _("&Wireframe")); menuMisc->AppendCheckItem(ID_MessageTrace, _("Message debug trace")); menuMisc->Append(ID_Screenshot, _("&Screenshot")); menuMisc->Append(ID_JavaScript, _("&JS console")); } m_FileHistory.Load(*wxConfigBase::Get()); m_SectionLayout.SetWindow(this); // Toolbar: ToolButtonBar* toolbar = new ToolButtonBar(this, &m_SectionLayout, ID_Toolbar); // TODO: configurable small vs large icon images // (button label; tooltip text; image; internal tool name; section to switch to) toolbar->AddToolButton(_("Default"), _("Default"), _T("default.png"), _T(""), _T("")); toolbar->AddToolButton(_("Move"), _("Move/rotate object"), _T("moveobject.png"), _T("TransformObject"), _T("")/*_T("ObjectSidebar")*/); toolbar->AddToolButton(_("Elevation"), _("Alter terrain elevation"), _T("alterelevation.png"), _T("AlterElevation"), _T("")/*_T("TerrainSidebar")*/); toolbar->AddToolButton(_("Flatten"), _("Flatten terrain elevation"), _T("flattenelevation.png"), _T("FlattenElevation"), _T("")/*_T("TerrainSidebar")*/); toolbar->AddToolButton(_("Paint Terrain"), _("Paint terrain texture"), _T("paintterrain.png"), _T("PaintTerrain"), _T("")/*_T("TerrainSidebar")*/); toolbar->Realize(); SetToolBar(toolbar); // Set the default tool to be selected SetCurrentTool(_T("")); // Set up GL canvas: int glAttribList[] = { WX_GL_RGBA, WX_GL_DOUBLEBUFFER, WX_GL_DEPTH_SIZE, 24, // TODO: wx documentation doesn't say 24 is valid WX_GL_BUFFER_SIZE, 24, // colour bits WX_GL_MIN_ALPHA, 8, // alpha bits 0 }; Canvas* canvas = new GameCanvas(m_SectionLayout.GetCanvasParent(), glAttribList); m_SectionLayout.SetCanvas(canvas); // Set up sidebars: m_SectionLayout.Build(*this); #if defined(__WXMSW__) // The canvas' context gets made current on creation; but it can only be // current for one thread at a time, and it needs to be current for the // thread that is doing the draw calls, so disable it for this one. wglMakeCurrent(NULL, NULL); #elif defined(__WXGTK__) // Need to make sure the canvas is realized by GTK, so that its context is valid Show(true); wxSafeYield(); #endif // Send setup messages to game engine: POST_MESSAGE(SetCanvas, (static_cast(canvas))); POST_MESSAGE(Init, (true)); canvas->InitSize(); // Start with a blank map (so that the editor can assume there's always // a valid map loaded) POST_MESSAGE(GenerateMap, (9)); POST_MESSAGE(RenderEnable, (eRenderView::GAME)); // Set up a timer to make sure tool-updates happen frequently (in addition // to the idle handler (which makes them happen more frequently if there's nothing // else to do)) m_Timer.SetOwner(this); m_Timer.Start(20); #ifdef __WXGTK__ // HACK: because of how we fiddle with stuff earlier to make sure the canvas // is displayed, the layout gets messed up, and it only seems to be fixable // by changing the window's size SetSize(GetSize() + wxSize(1, 0)); #endif } float ScenarioEditor::GetSpeedModifier() { if (wxGetKeyState(WXK_SHIFT) && wxGetKeyState(WXK_CONTROL)) return 1.f/64.f; else if (wxGetKeyState(WXK_CONTROL)) return 1.f/4.f; else if (wxGetKeyState(WXK_SHIFT)) return 4.f; else return 1.f; } void ScenarioEditor::OnClose(wxCloseEvent&) { SetCurrentTool(_T("")); m_FileHistory.Save(*wxConfigBase::Get()); POST_MESSAGE(Shutdown, ()); qExit().Post(); // blocks until engine has noticed the message, so we won't be // destroying the GLCanvas while it's still rendering Destroy(); } static void UpdateTool() { // Don't keep posting events if the game can't keep up if (g_FrameHasEnded) { g_FrameHasEnded = false; // (thread safety doesn't matter here) // TODO: Smoother timing stuff? static double last = g_Timer.GetTime(); double time = g_Timer.GetTime(); GetCurrentTool().OnTick(time-last); last = time; } } void ScenarioEditor::OnTimer(wxTimerEvent&) { UpdateTool(); } void ScenarioEditor::OnIdle(wxIdleEvent&) { UpdateTool(); } void ScenarioEditor::OnQuit(wxCommandEvent&) { Close(); } void ScenarioEditor::OnUndo(wxCommandEvent&) { GetCommandProc().Undo(); } void ScenarioEditor::OnRedo(wxCommandEvent&) { GetCommandProc().Redo(); } ////////////////////////////////////////////////////////////////////////// void ScenarioEditor::OpenFile(const wxString& name) { wxBusyInfo busy(_("Loading map")); wxBusyCursor busyc; // TODO: Work when the map is not in .../maps/scenarios/ std::wstring map = name.c_str(); // Deactivate tools, so they don't carry forwards into the new CWorld // and crash. SetCurrentTool(_T("")); // TODO: clear the undo buffer, etc POST_MESSAGE(LoadMap, (map)); SetOpenFilename(name); // Wait for it to load, while the wxBusyInfo is telling the user that we're doing that qPing qry; qry.Post(); // TODO: Make this a non-undoable command } // TODO (eventually): replace all this file-handling stuff with the Workspace Editor void ScenarioEditor::OnOpen(wxCommandEvent& WXUNUSED(event)) { wxFileDialog dlg (NULL, wxFileSelectorPromptStr, Datafile::GetDataDirectory() + _T("/mods/official/maps/scenarios"), m_OpenFilename, _T("PMP files (*.pmp)|*.pmp|All files (*.*)|*.*"), wxOPEN); wxString cwd = wxFileName::GetCwd(); if (dlg.ShowModal() == wxID_OK) OpenFile(dlg.GetFilename()); wxCHECK_RET(cwd == wxFileName::GetCwd(), _T("cwd changed")); // paranoia - MSDN says OFN_NOCHANGEDIR (used when we don't give wxCHANGE_DIR) // "is ineffective for GetOpenFileName", but it seems to work anyway // TODO: Make this a non-undoable command } void ScenarioEditor::OnMRUFile(wxCommandEvent& event) { wxString file (m_FileHistory.GetHistoryFile(event.GetId() - wxID_FILE1)); if (file.Len()) OpenFile(file); } void ScenarioEditor::OnSave(wxCommandEvent& event) { if (m_OpenFilename.IsEmpty()) OnSaveAs(event); else { wxBusyInfo busy(_("Saving map")); // Deactivate tools, so things like unit previews don't get saved. // (TODO: Would be nicer to leave the tools active, and just not save // the preview units.) SetCurrentTool(_T("")); std::wstring map = m_OpenFilename.c_str(); POST_MESSAGE(SaveMap, (map)); // Wait for it to finish saving qPing qry; qry.Post(); } } void ScenarioEditor::OnSaveAs(wxCommandEvent& WXUNUSED(event)) { wxFileDialog dlg (NULL, wxFileSelectorPromptStr, Datafile::GetDataDirectory() + _T("/mods/official/maps/scenarios"), m_OpenFilename, _T("PMP files (*.pmp)|*.pmp|All files (*.*)|*.*"), wxSAVE | wxOVERWRITE_PROMPT); if (dlg.ShowModal() == wxID_OK) { wxBusyInfo busy(_("Saving map")); SetCurrentTool(_T("")); // TODO: Work when the map is not in .../maps/scenarios/ std::wstring map = dlg.GetFilename().c_str(); POST_MESSAGE(SaveMap, (map)); SetOpenFilename(dlg.GetFilename()); // Wait for it to finish saving qPing qry; qry.Post(); } } void ScenarioEditor::SetOpenFilename(const wxString& filename) { SetTitle(wxString::Format(_("Atlas - Scenario Editor - %s"), (filename.IsEmpty() ? wxString(_("(untitled)")) : filename).c_str())); m_OpenFilename = filename; if (! filename.IsEmpty()) m_FileHistory.AddFileToHistory(filename); } ////////////////////////////////////////////////////////////////////////// void ScenarioEditor::OnWireframe(wxCommandEvent& event) { POST_MESSAGE(RenderStyle, (event.IsChecked())); } void ScenarioEditor::OnMessageTrace(wxCommandEvent& event) { POST_MESSAGE(MessageTrace, (event.IsChecked())); } void ScenarioEditor::OnScreenshot(wxCommandEvent& WXUNUSED(event)) { POST_MESSAGE(Screenshot, (10)); } void ScenarioEditor::OnJavaScript(wxCommandEvent& WXUNUSED(event)) { wxString cmd = ::wxGetTextFromUser(_T(""), _("JS command"), _T(""), this); if (cmd.IsEmpty()) return; POST_MESSAGE(JavaScript, (cmd.c_str())); } ////////////////////////////////////////////////////////////////////////// Position::Position(const wxPoint& pt) : type(1) { type1.x = pt.x; type1.y = pt.y; } ////////////////////////////////////////////////////////////////////////// /* Disabled (and should be removed if it turns out to be unnecessary) - see MessagePasserImpl.cpp for information static void QueryCallback() { // If this thread completely blocked on the semaphore inside Query, it would // never respond to window messages, and the system deadlocks if the // game tries to display an assertion failure dialog. (See // WaitForSingleObject on MSDN.) // So, this callback is called occasionally, and gives wx a change to // handle messages. // This is kind of like wxYield, but without the ProcessPendingEvents - // it's enough to make Windows happy and stop deadlocking, without actually // calling the event handlers (which could lead to nasty recursion) // while (wxEventLoop::GetActive()->Pending()) // wxEventLoop::GetActive()->Dispatch(); // Oh dear, we can't use that either - it (at least in wx 2.6.3) still // processes messages, which causes reentry into various things that we // don't want to be reentrant. So do it all manually, accepting Windows // messages and sticking them on a list for later processing (in a custom // event loop class): // (TODO: Rethink this entire process on Linux) // (Alt TODO: Could we make the game never pop up windows (or use the Win32 // GUI in any other way) when it's running under Atlas, so we wouldn't need // to do any message processing here at all?) #ifdef _WIN32 AtlasEventLoop* evtLoop = (AtlasEventLoop*)wxEventLoop::GetActive(); // evtLoop might be NULL, particularly if we're still initialising windows // and haven't got into the normal event loop yet. But we'd have to process // messages anyway, to avoid the deadlocks that this is for. So, don't bother // with that and just crash instead. // (Maybe it could be solved better by constructing/finding an event loop // object here and setting it as the global one, assuming it's not overwritten // later by wx.) while (evtLoop->Pending()) { // Based on src/msw/evtloop.cpp's wxEventLoop::Dispatch() MSG msg; BOOL rc = ::GetMessage(&msg, (HWND) NULL, 0, 0); if (rc == 0) { // got WM_QUIT return; } if (rc == -1) { wxLogLastError(wxT("GetMessage")); return; } // Our special bits: if (msg.message == WM_PAINT) { // "GetMessage does not remove WM_PAINT messages from the queue. // The messages remain in the queue until processed." // So let's process them, to avoid infinite loops... PAINTSTRUCT paint; ::BeginPaint(msg.hwnd, &paint); ::EndPaint(msg.hwnd, &paint); // Remember that some painting was needed - we'll just repaint // the whole screen when this is finished. evtLoop->NeedsPaint(); } else { // Add this message to a queue for later processing. (That's // probably kind of valid, at least in most cases.) MSG* pMsg = new MSG(msg); evtLoop->AddMessage(pMsg); } } #endif } */ void QueryMessage::Post() { // g_MessagePasser->Query(this, &QueryCallback); g_MessagePasser->Query(this, NULL); } Index: ps/trunk/source/tools/atlas/AtlasUI/Misc/DLLInterface.cpp =================================================================== --- ps/trunk/source/tools/atlas/AtlasUI/Misc/DLLInterface.cpp (revision 5153) +++ ps/trunk/source/tools/atlas/AtlasUI/Misc/DLLInterface.cpp (revision 5154) @@ -1,270 +1,287 @@ #include "precompiled.h" #include "DLLInterface.h" #include "General/AtlasEventLoop.h" #include "General/Datafile.h" #include "ActorEditor/ActorEditor.h" #include "ActorViewer/ActorViewer.h" #include "ArchiveViewer/ArchiveViewer.h" #include "ColourTester/ColourTester.h" #include "FileConverter/FileConverter.h" #include "ScenarioEditor/ScenarioEditor.h" #include "ErrorReporter/ErrorReporter.h" #include "GameInterface/MessagePasser.h" +#include "AtlasScript/ScriptInterface.h" + #include "wx/config.h" #include "wx/debugrpt.h" #include "wx/file.h" #ifdef __WXGTK__ #include #endif // Shared memory allocation functions ATLASDLLIMPEXP void* ShareableMalloc(size_t n) { // TODO: make sure this is thread-safe everywhere. (It is in MSVC with the // multithreaded CRT.) return malloc(n); } ATLASDLLIMPEXP void ShareableFree(void* p) { free(p); } // Define the function pointers that we'll use when calling those functions. // (The game loads the addresses of the above functions, then does the same.) namespace AtlasMessage { void* (*ShareableMallocFptr) (size_t) = &ShareableMalloc; void (*ShareableFreeFptr) (void*) = &ShareableFree; } // Global variables, to remember state between DllMain and StartWindow and OnInit wxString g_InitialWindowType; bool g_IsLoaded = false; #ifdef __WXMSW__ HINSTANCE g_Module; BOOL APIENTRY DllMain(HINSTANCE hModule, DWORD fdwReason, LPVOID WXUNUSED(lpReserved)) { switch (fdwReason) { case DLL_PROCESS_ATTACH: g_Module = hModule; return TRUE; case DLL_PROCESS_DETACH: if (g_IsLoaded) { wxEntryCleanup(); g_IsLoaded = false; } break; } return TRUE; } #endif // __WXMSW__ using namespace AtlasMessage; MessagePasser* AtlasMessage::g_MessagePasser = NULL; ATLASDLLIMPEXP void Atlas_SetMessagePasser(MessagePasser* passer) { g_MessagePasser = passer; } ATLASDLLIMPEXP void Atlas_StartWindow(const wchar_t* type) { g_InitialWindowType = type; #ifdef __WXMSW__ wxEntry(g_Module); #else # ifdef __WXGTK__ // Because we do GL calls from a secondary thread, Xlib needs to // be told to support multiple threads safely int status = XInitThreads(); if (status == 0) { fprintf(stderr, "Error enabling thread-safety via XInitThreads\n"); } # endif int argc = 1; char *argv[] = {"atlas", NULL}; wxEntry(argc, argv); #endif } ATLASDLLIMPEXP void Atlas_DisplayError(const wchar_t* text, unsigned int WXUNUSED(flags)) { // This is called from the game thread. // wxLog appears to be thread-safe, so that's okay. wxLogError(L"%s", text); // TODO: wait for user response (if possible) before returning, // and return their status (break/continue/debug/etc), but only in // cases where we're certain it won't deadlock (i.e. the UI event loop // is still running and won't block before showing the dialog to the user) // and where it matters (i.e. errors, not warnings (unless they're going to // turn into errors after continuing)) // TODO: 'text' (or at least some copy of it) appears to get leaked when // this function is called } ATLASDLLIMPEXP void Atlas_ReportError() { ///ReportError(); // janwas: disabled until ErrorReporter.cpp compiles } class AtlasDLLApp : public wxApp { public: + AtlasDLLApp() + : m_ScriptInterface(NULL) + { + } + + ~AtlasDLLApp() + { + delete m_ScriptInterface; + } virtual bool OnInit() { // _CrtSetBreakAlloc(5632); if (! wxIsDebuggerRunning()) wxHandleFatalExceptions(); // Initialise the global config file wxConfigBase::Set(new wxConfig(_T("Atlas Editor"), _T("Wildfire Games"))); // Assume that the .exe is located in .../binaries/system. (We can't // just use the cwd, since that isn't correct when being executed by // dragging-and-dropping onto the program in Explorer.) Datafile::SetSystemDirectory(argv[0]); // Display the appropriate window wxFrame* frame; #define MAYBE(t) if (g_InitialWindowType == _T(#t)) frame = new t(NULL); else MAYBE(ActorEditor) MAYBE(ActorViewer) MAYBE(ArchiveViewer) MAYBE(ColourTester) MAYBE(FileConverter) - MAYBE(ScenarioEditor) #undef MAYBE // else + if (g_InitialWindowType == _T("ScenarioEditor")) + { + m_ScriptInterface = new ScriptInterface(); + frame = new ScenarioEditor(NULL, *m_ScriptInterface); + } + else { wxFAIL_MSG(_("Internal error: invalid window type")); return false; } frame->Show(); SetTopWindow(frame); AtlasWindow* win = wxDynamicCast(frame, AtlasWindow); if (win) { // One argument => argv[1] is probably a filename to open if (argc > 1) { wxChar* filename = argv[1]; if (filename[0] != _T('-')) // ignore -options { if (wxFile::Exists(filename)) { win->OpenFile(filename); } else wxLogError(_("Cannot find file '%s'"), filename); } } } return true; } virtual void OnFatalException() { wxDebugReport report; wxDebugReportPreviewStd preview; report.AddAll(); if (preview.Show(report)) { wxString dir = report.GetDirectory(); // save the string, since it gets cleared by Process report.Process(); OpenDirectory(dir); } } /* Disabled (and should be removed if it turns out to be unnecessary) - see MessagePasserImpl.cpp for information virtual int MainLoop() { // Override the default MainLoop so that we can provide our own event loop wxEventLoop* old = m_mainLoop; m_mainLoop = new AtlasEventLoop; int ret = m_mainLoop->Run(); delete m_mainLoop; m_mainLoop = old; return ret; } */ private: + ScriptInterface* m_ScriptInterface; bool OpenDirectory(const wxString& dir) { // Open a directory on the filesystem - used so people can find the // debug report files generated in OnFatalException easily #ifdef __WXMSW__ // Code largely copied from wxLaunchDefaultBrowser: typedef HINSTANCE (WINAPI *LPShellExecute)(HWND hwnd, const wxChar* lpOperation, const wxChar* lpFile, const wxChar* lpParameters, const wxChar* lpDirectory, INT nShowCmd); HINSTANCE hShellDll = ::LoadLibrary(_T("shell32.dll")); if (hShellDll == NULL) return false; LPShellExecute lpShellExecute = (LPShellExecute) ::GetProcAddress(hShellDll, wxString(_T("ShellExecute") # ifdef _UNICODE _T("W") # else _T("A") # endif ).mb_str(wxConvLocal)); if (lpShellExecute == NULL) return false; /*HINSTANCE nResult =*/ (*lpShellExecute)(NULL, _T("explore"), dir.c_str(), NULL, NULL, SW_SHOWNORMAL); // ignore return value, since we're not going to do anything if this fails ::FreeLibrary(hShellDll); return true; #else // Figure out what goes for "default browser" on unix/linux/whatever // open an xterm perhaps? :) return false; #endif } }; IMPLEMENT_APP_NO_MAIN(AtlasDLLApp) Index: ps/trunk/source/tools/atlas/AtlasScript/ScriptInterface.cpp =================================================================== --- ps/trunk/source/tools/atlas/AtlasScript/ScriptInterface.cpp (revision 5153) +++ ps/trunk/source/tools/atlas/AtlasScript/ScriptInterface.cpp (revision 5154) @@ -1,309 +1,331 @@ #include "ScriptInterface.h" #include #include "js/jsapi.h" #include "wx/wx.h" #include "wxJS/common/main.h" #include "wxJS/ext/jsmembuf.h" #include "wxJS/io/init.h" #include "wxJS/gui/init.h" -#include "wxJS/gui/control/window.h" +#include "wxJS/gui/control/panel.h" #include "GameInterface/Shareable.h" #include "GameInterface/Messages.h" // We want to include Messages.h again below, with some different definitions, // so cheat and undefine its include-guard #undef INCLUDED_MESSAGES #include #include const int RUNTIME_SIZE = 1024*1024; // TODO: how much memory is needed? const int STACK_CHUNK_SIZE = 8192; //////////////////////////////////////////////////////////////// template bool ScriptInterface::FromJSVal(JSContext* cx, jsval WXUNUSED(v), T& WXUNUSED(out)) { JS_ReportError(cx, "Unrecognised argument type"); // TODO: SetPendingException turns the error into a JS-catchable exception, // but the error report doesn't say anything useful like the line number, // so I'm just using ReportError instead for now (and failures are uncatchable // and will terminate the whole script) //JS_SetPendingException(cx, STRING_TO_JSVAL(JS_NewStringCopyZ(cx, "Unrecognised argument type"))); return false; } template<> bool ScriptInterface::FromJSVal(JSContext* cx, jsval v, bool& out) { JSBool ret; if (! JS_ValueToBoolean(cx, v, &ret)) return false; out = ret; return true; } template<> bool ScriptInterface::FromJSVal(JSContext* cx, jsval v, float& out) { jsdouble ret; if (! JS_ValueToNumber(cx, v, &ret)) return false; out = ret; return true; } template<> bool ScriptInterface::FromJSVal(JSContext* cx, jsval v, int& out) { int32 ret; if (! JS_ValueToInt32(cx, v, &ret)) return false; out = ret; return true; } template<> bool ScriptInterface::FromJSVal(JSContext* cx, jsval v, std::wstring& out) { JSString* ret = JS_ValueToString(cx, v); // never returns NULL jschar* ch = JS_GetStringChars(ret); out = std::wstring(ch, ch+JS_GetStringLength(ret)); return true; } +template<> bool ScriptInterface::FromJSVal(JSContext* cx, jsval v, std::string& out) +{ + JSString* ret = JS_ValueToString(cx, v); // never returns NULL + char* ch = JS_GetStringBytes(ret); + out = std::string(ch); + return true; +} + template<> jsval ScriptInterface::ToJSVal(JSContext* cx, const float& val) { jsval rval = JSVAL_VOID; JS_NewDoubleValue(cx, val, &rval); // ignore return value return rval; } template<> jsval ScriptInterface::ToJSVal(JSContext* WXUNUSED(cx), const int& val) { return INT_TO_JSVAL(val); } template<> jsval ScriptInterface::ToJSVal(JSContext* cx, const wxString& val) { wxMBConvUTF16 conv; size_t length; wxCharBuffer utf16 = conv.cWC2MB(val.c_str(), val.length()+1, &length); JSString* str = JS_NewUCStringCopyN(cx, reinterpret_cast(utf16.data()), length/2); if (str) return STRING_TO_JSVAL(str); else return JSVAL_VOID; } //////////////////////////////////////////////////////////////// struct ScriptInterface_impl { ScriptInterface_impl(); ~ScriptInterface_impl(); void LoadScript(const wxString& filename, const wxString& code); void RegisterMessages(JSObject* parent); void Register(const char* name, JSNative fptr, uintN nargs); JSRuntime* m_rt; JSContext* m_cx; JSObject* m_glob; // global scope object JSObject* m_atlas; // Atlas scope object }; namespace { JSClass global_class = { "global", 0, JS_PropertyStub, JS_PropertyStub, JS_PropertyStub, JS_PropertyStub, JS_EnumerateStub, JS_ResolveStub, JS_ConvertStub, JS_FinalizeStub }; void ErrorReporter(JSContext* WXUNUSED(cx), const char* message, JSErrorReport* report) { bool isWarning = JSREPORT_IS_WARNING(report->flags); wxString logMessage(isWarning ? _T("JavaScript warning: ") : _T("JavaScript error: ")); if (report->filename) { logMessage << wxString::FromAscii(report->filename); logMessage << _T(" line ") << report->lineno << _T("\n"); } logMessage << wxString::FromAscii(message); if (isWarning) - wxLogWarning(logMessage); + wxLogWarning(_T("%s"), logMessage.c_str()); else - wxLogError(logMessage); + wxLogError(_T("%s"), logMessage.c_str()); + wxPrintf(_T("wxJS %s: %s\n--------\n"), isWarning ? _T("warning") : _T("error"), logMessage.c_str()); } JSBool LoadScript(JSContext* cx, JSObject* obj, uintN argc, jsval* argv, jsval* rval) { if (! ( JSVAL_IS_STRING(argv[0]) && JSVAL_IS_STRING(argv[1]) )) return JS_FALSE; JSString* name = JSVAL_TO_STRING(argv[0]); JSString* code = JSVAL_TO_STRING(argv[1]); JSObject* scriptObj = JS_NewObject(cx, NULL, NULL, NULL); if (! scriptObj) return JS_FALSE; *rval = OBJECT_TO_JSVAL(scriptObj); // root it to keep GC happy jsval scriptRval; JSBool ok = JS_EvaluateUCScript( cx, scriptObj, JS_GetStringChars(code), JS_GetStringLength(code), JS_GetStringBytes(name), 1, &scriptRval); if (! ok) return JS_FALSE; return JS_TRUE; } + + JSBool ForceGC(JSContext* cx, JSObject* WXUNUSED(obj), uintN WXUNUSED(argc), jsval* WXUNUSED(argv), jsval* WXUNUSED(rval)) + { + JS_GC(cx); + return JS_TRUE; + } + + JSBool print(JSContext* cx, JSObject* WXUNUSED(obj), uintN argc, jsval* argv, jsval* WXUNUSED(rval)) + { + for (uintN i = 0; i < argc; ++i) + { + std::string str; + if (! ScriptInterface::FromJSVal(cx, argv[i], str)) + return JS_FALSE; + printf("%s", str.c_str()); + } + return JS_TRUE; + } } ScriptInterface_impl::ScriptInterface_impl() { JSBool ok; m_rt = JS_NewRuntime(RUNTIME_SIZE); assert(m_rt); // TODO: error handling m_cx = JS_NewContext(m_rt, STACK_CHUNK_SIZE); assert(m_cx); JS_BeginRequest(m_cx); // if you get linker errors, see the comment in the .h about JS_THREADSAFE JS_SetErrorReporter(m_cx, ErrorReporter); JS_SetOptions(m_cx, JSOPTION_STRICT // "warn on dubious practice" | JSOPTION_XML // "ECMAScript for XML support: parse as a token" ); m_glob = JS_NewObject(m_cx, &global_class, NULL, NULL); ok = JS_InitStandardClasses(m_cx, m_glob); wxjs::gui::InitClass(m_cx, m_glob); wxjs::io::InitClass(m_cx, m_glob); wxjs::ext::MemoryBuffer::JSInit(m_cx, m_glob); + JS_DefineFunction(m_cx, m_glob, "print", ::print, 0, JSPROP_ENUMERATE|JSPROP_READONLY|JSPROP_PERMANENT); + m_atlas = JS_DefineObject(m_cx, m_glob, "Atlas", NULL, NULL, JSPROP_READONLY|JSPROP_PERMANENT); JS_DefineFunction(m_cx, m_atlas, "LoadScript", ::LoadScript, 2, JSPROP_ENUMERATE|JSPROP_READONLY|JSPROP_PERMANENT); - + JS_DefineFunction(m_cx, m_atlas, "ForceGC", ::ForceGC, 0, JSPROP_ENUMERATE|JSPROP_READONLY|JSPROP_PERMANENT); + RegisterMessages(m_atlas); } ScriptInterface_impl::~ScriptInterface_impl() { JS_EndRequest(m_cx); JS_DestroyContext(m_cx); JS_DestroyRuntime(m_rt); } void ScriptInterface_impl::LoadScript(const wxString& filename, const wxString& code) { size_t codeLength; wxMBConvUTF16 conv; wxCharBuffer codeUTF16 = conv.cWC2MB(code.c_str(), code.length()+1, &codeLength); jsval rval; JS_EvaluateUCScript(m_cx, m_glob, reinterpret_cast(codeUTF16.data()), codeLength/2, filename.ToAscii(), 1, &rval); } void ScriptInterface_impl::Register(const char* name, JSNative fptr, uintN nargs) { JS_DefineFunction(m_cx, m_atlas, name, fptr, nargs, JSPROP_ENUMERATE|JSPROP_READONLY|JSPROP_PERMANENT); } ScriptInterface::ScriptInterface() : m(new ScriptInterface_impl) { } ScriptInterface::~ScriptInterface() { } void ScriptInterface::Register(const char* name, JSNative fptr, size_t nargs) { m->Register(name, fptr, nargs); } -// wxJS requires an object that's a wxWindow* and also a wxjs::Object*, -// so define one based on wxPanel -struct WindowWrapper : public wxPanel, wxjs::Object -{ - WindowWrapper(wxWindow* parent) - : wxPanel(parent, -1) - { - } -}; - void ScriptInterface::LoadScript(const wxString& filename, const wxString& code) { m->LoadScript(filename, code); } wxPanel* ScriptInterface::LoadScriptAsPanel(const wxString& name, wxWindow* parent) { - wxPanel* panel = new WindowWrapper(parent); - jsval jsWindow = wxjs::gui::Window::CreateObject(m->m_cx, panel); + wxPanel* panel = new wxPanel(parent, -1); + JSObject* jsWindow = JSVAL_TO_OBJECT(wxjs::gui::Panel::CreateObject(m->m_cx, panel)); + panel->SetClientObject(new wxjs::JavaScriptClientData(m->m_cx, jsWindow, true, false)); + jsval jsName = ToJSVal(m->m_cx, name); - + const uintN argc = 2; - jsval argv[argc] = { jsName, jsWindow }; - + jsval argv[argc] = { jsName, OBJECT_TO_JSVAL(jsWindow) }; + jsval rval; JS_CallFunctionName(m->m_cx, m->m_glob, "loadScript", argc, argv, &rval); // TODO: error checking return panel; } //////////////////////////////////////////////////////////////// struct MessageWrapper { #define NUMBERED_LIST(z, i, data) , data##i #define NUMBERED_LIST2(z, i, data) BOOST_PP_COMMA_IF(i) data##i #define CONVERT_ARGS(z, i, data) T##i a##i; if (! ScriptInterface::FromJSVal(cx, argv[i], a##i)) return JS_FALSE; #define OVERLOADS(z, i, data) \ template \ static JSNative call(Message* (*WXUNUSED(fptr)) ( BOOST_PP_REPEAT_##z(i, NUMBERED_LIST2, T) )) { \ return &_call; \ } \ template \ static uintN nargs(Message* (*WXUNUSED(fptr)) ( BOOST_PP_REPEAT_##z(i, NUMBERED_LIST2, T) )) { \ return i; \ } \ template \ static JSBool _call(JSContext* cx, JSObject* obj, uintN argc, jsval* argv, jsval* WXUNUSED(rval)) \ { \ (void)cx; (void)obj; (void)argc; (void)argv; /* avoid 'unused parameter' warnings */ \ BOOST_PP_REPEAT_##z (i, CONVERT_ARGS, ~) \ AtlasMessage::g_MessagePasser->Add(SHAREABLE_NEW(Message, ( BOOST_PP_REPEAT_##z(i, NUMBERED_LIST2, a) ))); \ return JS_TRUE; \ } BOOST_PP_REPEAT(7, OVERLOADS, ~) }; void ScriptInterface_impl::RegisterMessages(JSObject* parent) { using namespace AtlasMessage; JSFunction* ret; JSObject* obj = JS_DefineObject(m_cx, parent, "Message", NULL, NULL, JSPROP_ENUMERATE|JSPROP_READONLY|JSPROP_PERMANENT); #define MESSAGE(name, vals) \ ret = JS_DefineFunction(m_cx, obj, #name, MessageWrapper::call(&m##name::CtorType), MessageWrapper::nargs(&m##name::CtorType), JSPROP_ENUMERATE|JSPROP_READONLY|JSPROP_PERMANENT); #define QUERY(name, in_vals, out_vals) /* TODO \ extern void f##name##_wrapper(AtlasMessage::IMessage*); \ AtlasMessage::GetMsgHandlers().insert(std::pair(#name, &f##name##_wrapper));*/ #define COMMAND(name, merge, vals) /* TODO \ extern cmdHandler c##name##_create(); \ GetCmdHandlers().insert(std::pair("c"#name, c##name##_create()));*/ #undef SHAREABLE_STRUCT #define SHAREABLE_STRUCT(name) #define MESSAGES_SKIP_SETUP #include "GameInterface/Messages.h" } Index: ps/trunk/source/tools/atlas/wxJS/gui/control/menubar.h =================================================================== --- ps/trunk/source/tools/atlas/wxJS/gui/control/menubar.h (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/gui/control/menubar.h (revision 5154) @@ -0,0 +1,80 @@ +/* + * wxJavaScript - menubar.h + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: menubar.h 675 2007-04-17 21:37:49Z fbraem $ + */ +#ifndef _WXJSMENUBAR_H +#define _WXJSMENUBAR_H + +namespace wxjs +{ + namespace gui + { + class MenuBar : public ApiWrapper + { + public: + + static bool GetProperty(wxMenuBar *p, + JSContext *cx, + JSObject *obj, + int id, + jsval *vp); + static wxMenuBar* Construct(JSContext *cx, + JSObject *obj, + uintN argc, + jsval *argv, + bool constructing); + + WXJS_DECLARE_METHOD_MAP() + WXJS_DECLARE_METHOD(append) + WXJS_DECLARE_METHOD(get_menu) + WXJS_DECLARE_METHOD(check) + WXJS_DECLARE_METHOD(insert) + WXJS_DECLARE_METHOD(enable) + WXJS_DECLARE_METHOD(enableTop) + WXJS_DECLARE_METHOD(findMenu) + WXJS_DECLARE_METHOD(findMenuItem) + WXJS_DECLARE_METHOD(getHelpString) + WXJS_DECLARE_METHOD(getLabel) + WXJS_DECLARE_METHOD(getLabelTop) + WXJS_DECLARE_METHOD(isChecked) + WXJS_DECLARE_METHOD(isEnabled) + WXJS_DECLARE_METHOD(refresh) + WXJS_DECLARE_METHOD(remove) + WXJS_DECLARE_METHOD(replace) + WXJS_DECLARE_METHOD(setHelpString) + WXJS_DECLARE_METHOD(setLabel) + WXJS_DECLARE_METHOD(setLabelTop) + + WXJS_DECLARE_CONSTANT_MAP() + + WXJS_DECLARE_PROPERTY_MAP() + enum + { + P_MENUCOUNT + , P_MENUS + }; + }; + }; // namespace gui +}; // namespace wxjs + +#endif // _WXJSMENUBAR_H Property changes on: ps/trunk/source/tools/atlas/wxJS/gui/control/menubar.h ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/gui/control/treeitem.h =================================================================== --- ps/trunk/source/tools/atlas/wxJS/gui/control/treeitem.h (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/gui/control/treeitem.h (revision 5154) @@ -0,0 +1,76 @@ +/* + * wxJavaScript - treeitem.h + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: treeitem.h 696 2007-05-07 21:16:23Z fbraem $ + */ +#ifndef _WXJSTreeItem_H +#define _WXJSTreeItem_H + +namespace wxjs +{ + namespace gui + { + class TreeItem : public ApiWrapper + { + public: + static bool GetProperty(wxTreeItemId *p, + JSContext *cx, + JSObject *obj, + int id, + jsval *vp); + static bool SetProperty(wxTreeItemId *p, + JSContext *cx, + JSObject *obj, + int id, + jsval *vp); + + WXJS_DECLARE_PROPERTY_MAP() + enum + { + P_TEXT + , P_DATA + , P_TEXT_COLOUR + , P_BACKGROUND_COLOUR + , P_FONT + , P_HAS_CHILDREN + , P_BOLD + , P_VISIBLE + , P_EXPANDED + , P_SELECTED + , P_CHILDREN_COUNT + , P_ALL_CHILDREN_COUNT + , P_PARENT + , P_LAST_CHILD + , P_NEXT_SIBLING + , P_PREV_SIBLING + }; + + WXJS_DECLARE_METHOD_MAP() + WXJS_DECLARE_METHOD(getImage) + WXJS_DECLARE_METHOD(setImage) + WXJS_DECLARE_METHOD(getFirstChild) + WXJS_DECLARE_METHOD(getNextChild) + }; + }; // namespace gui +}; // namespace wxjs + +#endif //_WXJSTreeItem_H Property changes on: ps/trunk/source/tools/atlas/wxJS/gui/control/treeitem.h ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/gui/control/sttext.h =================================================================== --- ps/trunk/source/tools/atlas/wxJS/gui/control/sttext.h (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/gui/control/sttext.h (revision 5154) @@ -0,0 +1,76 @@ +/* + * wxJavaScript - sttext.h + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: sttext.h 695 2007-05-04 20:51:28Z fbraem $ + */ +#ifndef _WXJSStaticText_H +#define _WXJSStaticText_H + +namespace wxjs +{ + namespace gui + { + class StaticText : public ApiWrapper + { + public: + + static bool AddProperty(wxStaticText *p, + JSContext *cx, + JSObject *obj, + const wxString &prop, + jsval *vp); + static bool DeleteProperty(wxStaticText *p, + JSContext* cx, + JSObject* obj, + const wxString &prop); + static bool GetProperty(wxStaticText *p, + JSContext *cx, + JSObject *obj, + int id, + jsval *vp); + static bool SetProperty(wxStaticText *p, + JSContext *cx, + JSObject *obj, + int id, + jsval *vp); + + static wxStaticText* Construct(JSContext *cx, + JSObject *obj, + uintN argc, + jsval *argv, + bool constructing); + + WXJS_DECLARE_CONSTANT_MAP() + + WXJS_DECLARE_PROPERTY_MAP() + enum + { + P_LABEL + }; + + WXJS_DECLARE_METHOD_MAP() + WXJS_DECLARE_METHOD(create) + }; + }; // namespace gui +}; // namespace wxjs + +#endif //_WXJSStaticText_H Property changes on: ps/trunk/source/tools/atlas/wxJS/gui/control/sttext.h ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/gui/control/dirdlg.cpp =================================================================== --- ps/trunk/source/tools/atlas/wxJS/gui/control/dirdlg.cpp (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/gui/control/dirdlg.cpp (revision 5154) @@ -0,0 +1,195 @@ +#include "precompiled.h" + +/* + * wxJavaScript - dirdlg.cpp + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: dirdlg.cpp 708 2007-05-14 15:30:45Z fbraem $ + */ + +#ifndef WX_PRECOMP + #include +#endif + +#include "../../common/main.h" + +#include "dirdlg.h" +#include "window.h" +#include "../misc/point.h" + +#include "../errors.h" + +using namespace wxjs; +using namespace wxjs::gui; + +/*** + * control/dirdlg + * gui + * + * This class represents the directory chooser dialog. + * + */ +WXJS_INIT_CLASS(DirDialog, "wxDirDialog", 1) + +/*** + * + * + * Get/Set the message of the dialog + * + * + * Get/Set the full path of the selected file + * + * + */ +WXJS_BEGIN_PROPERTY_MAP(DirDialog) + WXJS_PROPERTY(P_MESSAGE, "message") + WXJS_PROPERTY(P_PATH, "path") +WXJS_END_PROPERTY_MAP() + +bool DirDialog::GetProperty(wxDirDialog *p, + JSContext *cx, + JSObject* WXUNUSED(obj), + int id, + jsval *vp) +{ + switch (id) + { + case P_MESSAGE: + *vp = ToJS(cx, p->GetMessage()); + break; + case P_PATH: + *vp = ToJS(cx, p->GetPath()); + break; + } + return true; +} + +bool DirDialog::SetProperty(wxDirDialog *p, + JSContext *cx, + JSObject* WXUNUSED(obj), + int id, + jsval *vp) +{ + switch (id) + { + case P_MESSAGE: + { + wxString msg; + FromJS(cx, *vp, msg); + p->SetMessage(msg); + break; + } + case P_PATH: + { + wxString path; + FromJS(cx, *vp, path); + p->SetPath(path); + break; + } + } + return true; +} + +/*** + * + * + * + * The parent of wxDirDialog + * + * + * The title of the dialog + * + * + * The default directory + * + * + * Unused + * + * + * The position of the dialog. + * + * + * + * Constructs a new wxDirDialog object + * + * + */ +wxDirDialog* DirDialog::Construct(JSContext *cx, + JSObject *obj, + uintN argc, + jsval *argv, + bool WXUNUSED(constructing)) +{ + if ( argc > 5 ) + argc = 5; + + const wxPoint *pt = &wxDefaultPosition; + int style = 0; + wxString defaultPath = wxEmptyString; + wxString message = wxDirSelectorPromptStr; + + switch(argc) + { + case 5: + pt = Point::GetPrivate(cx, argv[4]); + if ( pt == NULL ) + { + JS_ReportError(cx, WXJS_INVALID_ARG_TYPE, 5, "wxPoint"); + return JS_FALSE; + } + // Fall through + case 4: + if ( ! FromJS(cx, argv[3], style) ) + { + JS_ReportError(cx, WXJS_INVALID_ARG_TYPE, 4, "Integer"); + return JS_FALSE; + } + // Fall through + case 3: + FromJS(cx, argv[2], defaultPath); + // Fall through + case 2: + FromJS(cx, argv[1], message); + // Fall through + default: + wxWindow *parent = Window::GetPrivate(cx, argv[0]); + if ( parent != NULL ) + { + JavaScriptClientData *clntParent = + dynamic_cast(parent->GetClientObject()); + if ( clntParent == NULL ) + { + JS_ReportError(cx, WXJS_NO_PARENT_ERROR, GetClass()->name); + return JS_FALSE; + } + JS_SetParent(cx, obj, clntParent->GetObject()); + } + + return new wxDirDialog(parent, message, defaultPath, style, *pt); + } + + return NULL; +} + +void DirDialog::Destruct(JSContext* WXUNUSED(cx), wxDirDialog *p) +{ + p->Destroy(); +} Property changes on: ps/trunk/source/tools/atlas/wxJS/gui/control/dirdlg.cpp ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/gui/control/dialog.cpp =================================================================== --- ps/trunk/source/tools/atlas/wxJS/gui/control/dialog.cpp (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/gui/control/dialog.cpp (revision 5154) @@ -0,0 +1,456 @@ +#include "precompiled.h" + +/* + * wxJavaScript - dialog.cpp + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: dialog.cpp 708 2007-05-14 15:30:45Z fbraem $ + */ + +#ifndef WX_PRECOMP + #include +#endif + +#include "../../common/main.h" + +#include "../event/jsevent.h" +#include "../event/jsevent.h" +#include "../event/close.h" + +#include "dialog.h" +#include "window.h" + +#include "../misc/point.h" +#include "../misc/size.h" + +#include "../errors.h" + +using namespace wxjs; +using namespace wxjs::gui; + +/*** + * control/dialog + * gui + * + * A dialog box is a window with a title bar and sometimes a system menu, + * which can be moved around the screen. It can contain controls and other windows. + *

+ * The following sample shows a simple dialog: + *
// Initialize the application
+ *  wxTheApp.onInit = function()
+ *  {
+ *    dlg = new wxDialog(null, -1, "test");
+ *  
+ *    dlg.button = new wxButton(dlg, 1, "Ok");
+ *  
+ *    dlg.button.onClicked = function()
+ *    {
+ *       endModal(1);
+ *    }
+ *    
+ *    dlg.showModal();
+ *    
+ *    // Return false, will end the main loop
+ *    return false;
+ *  }
+ *  
+ *  wxTheApp.mainLoop();
+ *
+ */ +WXJS_INIT_CLASS(Dialog, "wxDialog", 3) + +void Dialog::InitClass(JSContext* WXUNUSED(cx), + JSObject* WXUNUSED(obj), + JSObject* WXUNUSED(proto)) +{ + DialogEventHandler::InitConnectEventMap(); +} + +/*** + * + * + * The returncode of the modal dialog + * + * + * Returns true when the dialog is a modal dialog + * + * + */ +WXJS_BEGIN_PROPERTY_MAP(Dialog) + WXJS_READONLY_PROPERTY(P_RETURN_CODE, "returnCode") + WXJS_READONLY_PROPERTY(P_MODAL, "modal") +WXJS_END_PROPERTY_MAP() + +bool Dialog::GetProperty(wxDialog *p, + JSContext *cx, + JSObject* WXUNUSED(obj), + int id, + jsval *vp) +{ + switch (id) + { + case P_RETURN_CODE: + *vp = ToJS(cx, p->GetReturnCode()); + break; + case P_MODAL: + *vp = ToJS(cx, p->IsModal()); + break; + } + return true; +} + +bool Dialog::AddProperty(wxDialog *p, + JSContext* WXUNUSED(cx), + JSObject* WXUNUSED(obj), + const wxString &prop, + jsval* WXUNUSED(vp)) +{ + if ( WindowEventHandler::ConnectEvent(p, prop, true) ) + return true; + + DialogEventHandler::ConnectEvent(p, prop, true); + return true; +} + +bool Dialog::DeleteProperty(wxDialog *p, + JSContext* WXUNUSED(cx), + JSObject* WXUNUSED(obj), + const wxString &prop) +{ + if ( WindowEventHandler::ConnectEvent(p, prop, false) ) + return true; + + DialogEventHandler::ConnectEvent(p, prop, false); + return true; +} + +/*** + * + * + * + * + * + * + * + * + * + * + * + * + * + */ +WXJS_BEGIN_CONSTANT_MAP(Dialog) + // Style constants + WXJS_CONSTANT(wx, DIALOG_MODAL) + WXJS_CONSTANT(wx, CAPTION) + WXJS_CONSTANT(wx, DEFAULT_DIALOG_STYLE) + WXJS_CONSTANT(wx, RESIZE_BORDER) + WXJS_CONSTANT(wx, SYSTEM_MENU) + WXJS_CONSTANT(wx, THICK_FRAME) + WXJS_CONSTANT(wx, STAY_ON_TOP) + WXJS_CONSTANT(wx, NO_3D) + WXJS_CONSTANT(wx, DIALOG_EX_CONTEXTHELP) +WXJS_END_CONSTANT_MAP() + +/*** + * + * + * + * + * The parent of the dialog. null is Allowed. + * + * + * The window identifier + * + * + * The title of the dialog + * + * + * The position of the dialog. + * + * + * The size of the dialog + * + * + * The window style + * + * + * + * Creates a dialog + * + * + */ +wxDialog* Dialog::Construct(JSContext *cx, + JSObject *obj, + uintN argc, + jsval *argv, + bool WXUNUSED(constructing)) +{ + wxDialog *p = new wxDialog(); + SetPrivate(cx, obj, p); + + if ( argc > 0 ) + { + jsval rval; + create(cx, obj, argc, argv, &rval); + } + return p; +} + +WXJS_BEGIN_METHOD_MAP(Dialog) + WXJS_METHOD("create", create, 3) + WXJS_METHOD("endModal", end_modal, 1) + WXJS_METHOD("showModal", show_modal, 0) +WXJS_END_METHOD_MAP() + +/*** + * + * + * + * The parent of the dialog. null is Allowed. + * + * + * The window identifier + * + * + * The title of the dialog + * + * + * The position of the dialog. + * + * + * The size of the dialog + * + * + * The window style + * + * + * + * Creates a dialog. + * + * + */ +JSBool Dialog::create(JSContext *cx, + JSObject *obj, + uintN argc, + jsval *argv, + jsval *rval) +{ + wxDialog *p = GetPrivate(cx, obj); + *rval = JSVAL_FALSE; + + if ( argc > 6 ) + argc = 6; + + int style = wxDEFAULT_DIALOG_STYLE; + const wxPoint *pt = &wxDefaultPosition; + const wxSize *size = &wxDefaultSize; + + switch(argc) + { + case 6: + if ( ! FromJS(cx, argv[5], style) ) + { + JS_ReportError(cx, WXJS_INVALID_ARG_TYPE, 6, "Integer"); + return JS_FALSE; + } + // Fall through + case 5: + size = Size::GetPrivate(cx, argv[4]); + if ( size == NULL ) + { + JS_ReportError(cx, WXJS_INVALID_ARG_TYPE, 5, "wxSize"); + return JS_FALSE; + } + // Fall through + case 4: + pt = Point::GetPrivate(cx, argv[3]); + if ( pt == NULL ) + { + JS_ReportError(cx, WXJS_INVALID_ARG_TYPE, 4, "wxPoint"); + return JS_FALSE; + } + // Fall through + default: + wxString title; + FromJS(cx, argv[2], title); + + int id; + if ( ! FromJS(cx, argv[1], id) ) + { + JS_ReportError(cx, WXJS_INVALID_ARG_TYPE, 2, "Integer"); + return JS_FALSE; + } + + wxWindow *parent = Window::GetPrivate(cx, argv[0]); + if ( parent == NULL ) + { + style |= wxDIALOG_NO_PARENT; + } + else + { + JavaScriptClientData *clntParent + = dynamic_cast(parent->GetClientObject()); + if ( clntParent == NULL ) + { + JS_ReportError(cx, WXJS_NO_PARENT_ERROR, GetClass()->name); + return JS_FALSE; + } + JS_SetParent(cx, obj, clntParent->GetObject()); + } + + if ( p->Create(parent, id, title, *pt, *size, style) ) + { + *rval = JSVAL_TRUE; + p->SetClientObject(new JavaScriptClientData(cx, obj, true, false)); + } + } + return JS_TRUE; +} +/*** + * + * + * + * The value to be returned from @wxDialog#showModal + * + * + * + * Ends a modal dialog. + * + * + */ +JSBool Dialog::end_modal(JSContext *cx, + JSObject *obj, + uintN WXUNUSED(argc), + jsval* argv, + jsval* WXUNUSED(rval)) +{ + wxDialog *p = Dialog::GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + int code; + if ( FromJS(cx, argv[0], code) ) + { + p->EndModal(code); + return JS_TRUE; + } + + return JS_FALSE; +} + +/*** + * + * + * + * Shows a modal dialog. + * The value returned is the return code set by @wxDialog#endModal. + * + * + */ +JSBool Dialog::show_modal(JSContext *cx, + JSObject *obj, + uintN WXUNUSED(argc), + jsval* WXUNUSED(argv), + jsval *rval) +{ + wxDialog *p = Dialog::GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + *rval = ToJS(cx, p->ShowModal()); + + return JS_TRUE; +} + +/*** + * + * + * Called when the dialog is closed. The type of the argument that your + * handler receives is @wxCloseEvent. + * + * + * This event is sent as a dialog or panel is being initialised. + * Handlers for this event can transfer data to the window. + * The function gets a @wxInitDialogEvent as argument + * + * + */ +WXJS_INIT_EVENT_MAP(wxDialog) +const wxString WXJS_CLOSE_EVENT = wxT("onClose"); +const wxString WXJS_INIT_DIALOG_EVENT = wxT("onInitDialog"); + +void DialogEventHandler::OnInitDialog(wxInitDialogEvent &event) +{ + PrivInitDialogEvent::Fire(event, WXJS_INIT_DIALOG_EVENT); +} + +void DialogEventHandler::OnClose(wxCloseEvent &event) +{ + PrivCloseEvent::Fire(event, WXJS_CLOSE_EVENT); +/* + bool destroy = true; + + wxDialog *p = dynamic_cast(event.GetEventObject()); + + if ( PrivCloseEvent::Fire(this, event, "onClose") ) + { + destroy = ! event.GetVeto(); + } + + // When the close event is not handled by JavaScript, + // wxJS destroys the dialog. + if ( destroy ) + { + p->Destroy(); + } +*/ +} + +void DialogEventHandler::ConnectClose(wxDialog *p, bool connect) +{ + if ( connect ) + { + p->Connect(wxEVT_CLOSE_WINDOW, wxCloseEventHandler(OnClose)); + } + else + { + p->Disconnect(wxEVT_CLOSE_WINDOW, wxCloseEventHandler(OnClose)); + } +} + +void DialogEventHandler::ConnectInitDialog(wxDialog *p, bool connect) +{ + if ( connect ) + { + p->Connect(wxEVT_INIT_DIALOG, wxInitDialogEventHandler(OnInitDialog)); + } + else + { + p->Disconnect(wxEVT_INIT_DIALOG, wxInitDialogEventHandler(OnInitDialog)); + } +} + +void DialogEventHandler::InitConnectEventMap() +{ + AddConnector(WXJS_CLOSE_EVENT, ConnectClose); + AddConnector(WXJS_INIT_DIALOG_EVENT, ConnectInitDialog); +} Property changes on: ps/trunk/source/tools/atlas/wxJS/gui/control/dialog.cpp ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/gui/control/treehit.cpp =================================================================== --- ps/trunk/source/tools/atlas/wxJS/gui/control/treehit.cpp (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/gui/control/treehit.cpp (revision 5154) @@ -0,0 +1,112 @@ +#include "precompiled.h" + +/* + * wxJavaScript - treehit.cpp + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: treehit.cpp 598 2007-03-07 20:13:28Z fbraem $ + */ +#ifndef WX_PRECOMP + #include +#endif + +#include "../../common/main.h" +#include "treectrl.h" +#include "treeid.h" +#include "treeitem.h" +#include "treehit.h" + +using namespace wxjs; +using namespace wxjs::gui; + +/*** + * control/treehit + * gui + * + * Helper class for returning information from wxTreeCtrl @wxTreeCtrl#hitTest. + * This class is specific for wxJavaScript. It doesn't exist in wxWindows. + * + */ +WXJS_INIT_CLASS(TreeHitTest, "wxTreeHitTest", 0) + +/*** + * + * + * Get the item. + * + * + * Get the flags. These flags give details about the position and the tree control item. + * + * + */ +WXJS_BEGIN_PROPERTY_MAP(TreeHitTest) + WXJS_READONLY_PROPERTY(P_ITEM, "item") + WXJS_READONLY_PROPERTY(P_FLAGS, "flags") +WXJS_END_PROPERTY_MAP() + +bool TreeHitTest::GetProperty(wxTreeHitTest *p, JSContext *cx, JSObject *obj, int id, jsval *vp) +{ + switch (id) + { + case P_ITEM: + *vp = TreeItemId::CreateObject(cx, new wxTreeItemId(p->GetItem())); + break; + case P_FLAGS: + *vp = ToJS(cx, p->GetFlags()); + break; + } + return true; +} + +/*** + * + * + * Above the client area. + * Below the client area. + * In the client area but below the last item. + * On the button associated with an item. + * On the bitmap associated with an item. + * In the indentation associated with an item. + * On the label (string) associated with an item. + * In the area to the right of an item. + * On the state icon for a tree view item that is in a user-defined state. + * To the left of the client area. + * To the right of the client area. + * (ONITEMICON | ONITEMLABEL) + * + * + */ +WXJS_BEGIN_CONSTANT_MAP(TreeHitTest) + WXJS_CONSTANT(wxTREE_HITTEST_, ABOVE) + WXJS_CONSTANT(wxTREE_HITTEST_, BELOW) + WXJS_CONSTANT(wxTREE_HITTEST_, NOWHERE) + WXJS_CONSTANT(wxTREE_HITTEST_, ONITEMBUTTON) + WXJS_CONSTANT(wxTREE_HITTEST_, ONITEMICON) + WXJS_CONSTANT(wxTREE_HITTEST_, ONITEMINDENT) + WXJS_CONSTANT(wxTREE_HITTEST_, ONITEMLABEL) + WXJS_CONSTANT(wxTREE_HITTEST_, ONITEMRIGHT) + WXJS_CONSTANT(wxTREE_HITTEST_, ONITEMSTATEICON) + WXJS_CONSTANT(wxTREE_HITTEST_, TOLEFT) + WXJS_CONSTANT(wxTREE_HITTEST_, TORIGHT) + WXJS_CONSTANT(wxTREE_HITTEST_, ONITEMUPPERPART) + WXJS_CONSTANT(wxTREE_HITTEST_, ONITEMLOWERPART) + WXJS_CONSTANT(wxTREE_HITTEST_, ONITEM) +WXJS_END_CONSTANT_MAP() Property changes on: ps/trunk/source/tools/atlas/wxJS/gui/control/treehit.cpp ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/gui/control/tbartool.cpp =================================================================== --- ps/trunk/source/tools/atlas/wxJS/gui/control/tbartool.cpp (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/gui/control/tbartool.cpp (revision 5154) @@ -0,0 +1,117 @@ +#include "precompiled.h" + +/* + * wxJavaScript - toolbar.cpp + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: toolbar.cpp 696 2007-05-07 21:16:23Z fbraem $ + */ + +#include +#ifndef WX_PRECOMP + #include +#endif + +#include + +#include "../../common/main.h" + +#include "tbartool.h" +#include "../errors.h" + +using namespace wxjs; +using namespace wxjs::gui; + +/*** + * control/tbartool + * gui + * + * A tool on a toolbar. See @wxToolBar. + * + */ +WXJS_INIT_CLASS(ToolBarToolBase, "wxToolBarTool", 0) + +/*** + * + * + * The function to execute when the tool is clicked + * + * + */ + +WXJS_BEGIN_METHOD_MAP(ToolBarToolBase) + WXJS_METHOD("enable", enable, 1) + WXJS_METHOD("toggle", toggle, 1) +WXJS_END_METHOD_MAP() + +/*** + * + * + * + * + * + * Enable/disable the tool + * + * + */ +JSBool ToolBarToolBase::enable(JSContext *cx, + JSObject *obj, + uintN argc, + jsval *argv, + jsval *rval) +{ + wxToolBarToolBase *p = GetPrivate(cx, obj); + + bool enable; + if ( FromJS(cx, argv[0], enable) ) + { + *rval = ToJS(cx, p->Enable(enable)); + } + + return JS_TRUE; +} + +/*** + * + * + * + * + * + * Toggle the tool + * + * + */ +JSBool ToolBarToolBase::toggle(JSContext *cx, + JSObject *obj, + uintN argc, + jsval *argv, + jsval *rval) +{ + wxToolBarToolBase *p = GetPrivate(cx, obj); + + bool sw; + if ( FromJS(cx, argv[0], sw) ) + { + *rval = ToJS(cx, p->Toggle(sw)); + } + + return JS_TRUE; +} Property changes on: ps/trunk/source/tools/atlas/wxJS/gui/control/tbartool.cpp ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/gui/control/menuitem.h =================================================================== --- ps/trunk/source/tools/atlas/wxJS/gui/control/menuitem.h (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/gui/control/menuitem.h (revision 5154) @@ -0,0 +1,82 @@ +/* + * wxJavaScript - menuitem.h + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: menuitem.h 688 2007-04-27 20:45:09Z fbraem $ + */ +#ifndef _WXJSMENUITEM_H +#define _WXJSMENUITEM_H + +namespace wxjs +{ + namespace gui + { + class MenuItem : public ApiWrapper + { + public: + static bool GetProperty(wxMenuItem *p, + JSContext *cx, + JSObject *obj, + int id, + jsval *vp); + static bool SetProperty(wxMenuItem *p, + JSContext *cx, + JSObject *obj, + int id, + jsval *vp); + + static wxMenuItem* Construct(JSContext *cx, + JSObject *obj, + uintN argc, + jsval *argv, + bool constructing); + static void Destruct(JSContext *cx, wxMenuItem *p); + + WXJS_DECLARE_METHOD_MAP() + WXJS_DECLARE_METHOD(is_checkable) + WXJS_DECLARE_METHOD(is_separator) + WXJS_DECLARE_METHOD(setBitmaps) + + WXJS_DECLARE_PROPERTY_MAP() + enum + { + P_LABEL = WXJS_START_PROPERTY_ID + , P_TEXT + , P_CHECK + , P_CHECKABLE + , P_ENABLE + , P_HELP + , P_ID + , P_MARGIN_WIDTH + , P_SUB_MENU + , P_ACCEL + , P_BG_COLOUR + , P_MENU + , P_FONT + , P_BITMAP + , P_TEXT_COLOUR + , P_SEPARATOR + }; + }; + }; // namespace gui +}; // namespace wxjs + +#endif //_WXJSMENUITEM_H Property changes on: ps/trunk/source/tools/atlas/wxJS/gui/control/menuitem.h ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/gui/control/finddata.cpp =================================================================== --- ps/trunk/source/tools/atlas/wxJS/gui/control/finddata.cpp (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/gui/control/finddata.cpp (revision 5154) @@ -0,0 +1,167 @@ +#include "precompiled.h" + +/* + * wxJavaScript - finddata.cpp + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: finddata.cpp 672 2007-04-12 20:29:39Z fbraem $ + */ + +#ifndef WX_PRECOMP + #include +#endif + +#include "../../common/main.h" + +#include "finddata.h" + +using namespace wxjs; +using namespace wxjs::gui; + +/*** + * control/finddata + * gui + * + * wxFindReplaceData holds the data for @wxFindReplaceDialog. + * It is used to initialize the dialog with the default values and + * will keep the last values from the dialog when it is closed. + * It is also updated each time a @wxFindDialogEvent is generated so + * instead of using the @wxFindDialogEvent methods + * you can also directly query this object. + * + */ +WXJS_INIT_CLASS(FindReplaceData, "wxFindReplaceData", 0) + +/*** + * + * + * Get/Set the string to find + * + * + * Get/Set the flags. + * + * + * Get/Set the replacement string + * + * + */ +WXJS_BEGIN_PROPERTY_MAP(FindReplaceData) + WXJS_PROPERTY(P_FINDSTRING, "findString") + WXJS_PROPERTY(P_REPLACESTRING, "replaceString") + WXJS_PROPERTY(P_FLAGS, "flags") +WXJS_END_PROPERTY_MAP() + +bool FindReplaceData::GetProperty(wxFindReplaceData *p, + JSContext *cx, + JSObject* WXUNUSED(obj), + int id, + jsval *vp) +{ + switch(id) + { + case P_FLAGS: + *vp = ToJS(cx, p->GetFlags()); + break; + case P_FINDSTRING: + *vp = ToJS(cx, p->GetFindString()); + break; + case P_REPLACESTRING: + *vp = ToJS(cx, p->GetReplaceString()); + break; + } + return true; +} + +bool FindReplaceData::SetProperty(wxFindReplaceData *p, + JSContext *cx, + JSObject* WXUNUSED(obj), + int id, + jsval *vp) +{ + switch(id) + { + case P_FLAGS: + { + int flag; + if ( FromJS(cx, *vp, flag) ) + p->SetFlags(flag); + break; + } + case P_FINDSTRING: + { + wxString str; + FromJS(cx, *vp, str); + p->SetFindString(str); + break; + } + case P_REPLACESTRING: + { + wxString str; + FromJS(cx, *vp, str); + p->SetReplaceString(str); + break; + } + } + return true; +} + +/*** + * + * + * + * + * + * + * + */ +WXJS_BEGIN_CONSTANT_MAP(FindReplaceData) + WXJS_CONSTANT(wx, FR_DOWN) + WXJS_CONSTANT(wx, FR_WHOLEWORD) + WXJS_CONSTANT(wx, FR_MATCHCASE) +WXJS_END_CONSTANT_MAP() + +/*** + * + * + * + * + * + * Constructs a new wxFindReplaceData object. + * + * + */ +wxFindReplaceData* FindReplaceData::Construct(JSContext *cx, + JSObject* WXUNUSED(obj), + uintN argc, + jsval *argv, + bool WXUNUSED(constructing)) +{ + if ( argc == 0 ) + return new wxFindReplaceData(); + else + { + int flags = 0; + if ( FromJS(cx, argv[0], flags) ) + return new wxFindReplaceData(flags); + } + + return NULL; +} Property changes on: ps/trunk/source/tools/atlas/wxJS/gui/control/finddata.cpp ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/ext/wxjs_ext.h =================================================================== --- ps/trunk/source/tools/atlas/wxJS/ext/wxjs_ext.h (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/ext/wxjs_ext.h (revision 5154) @@ -0,0 +1,52 @@ +/* + * wxJavaScript - wxjs_ext.h + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: wxjs_ext.h 598 2007-03-07 20:13:28Z fbraem $ + */ +#ifndef _wxjs_ext_h +#define _wxjs_ext_h + +#include + +#include + +#ifdef WXJSDLL_BUILD + #define WXJSAPI WXEXPORT +#else + #define WXJSAPI WXIMPORT +#endif + +WXJSAPI bool wxJS_EXTInit(JSContext *cx, JSObject *global); +WXJSAPI bool wxJS_EXTInitClass(JSContext *cx, JSObject *obj); +WXJSAPI void wxJS_EXTDestroy(); + +namespace wxjs +{ + namespace ext + { + WXJSAPI wxMemoryBuffer* NewMemoryBuffer(void *buffer, int size); + WXJSAPI JSObject *CreateMemoryBuffer(JSContext *cx, void *buffer, int size); + WXJSAPI wxMemoryBuffer* GetMemoryBuffer(JSContext *cx, JSObject *obj); + }; +}; + +#endif // _wxjs_ext_h Property changes on: ps/trunk/source/tools/atlas/wxJS/ext/wxjs_ext.h ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/ext/ext_main.cpp =================================================================== --- ps/trunk/source/tools/atlas/wxJS/ext/ext_main.cpp (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/ext/ext_main.cpp (revision 5154) @@ -0,0 +1,90 @@ +#include "precompiled.h" + +/* + * wxJavaScript - main.cpp + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: main.cpp 598 2007-03-07 20:13:28Z fbraem $ + */ +#ifdef __WXMSW__ + #include +#endif +#include "../common/main.h" + +#include "jsmembuf.h" +#include "wxjs_ext.h" + +using namespace wxjs; +using namespace wxjs::ext; + +#ifdef __WXMSW__ + BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) + { + BOOL result = TRUE; + + switch(fdwReason) + { + case DLL_PROCESS_ATTACH: + DisableThreadLibraryCalls(hinstDLL); + break; + case DLL_PROCESS_DETACH: + break; + } + + return result; + } +#endif + +WXJSAPI bool wxJS_EXTInit(JSContext *cx, JSObject *global) +{ + MemoryBuffer::JSInit(cx, global); + return true; +} + +WXJSAPI bool wxJS_EXTInitClass(JSContext *cx, JSObject *obj) +{ + return true; +} + +WXJSAPI void wxJS_EXTDestroy() +{ +} + +WXJSAPI JSObject *wxjs::ext::CreateMemoryBuffer(JSContext *cx, void *buffer, int size) +{ + wxMemoryBuffer *membuf = new wxMemoryBuffer(size); + membuf->AppendData(buffer, size); + JSObject *obj = JS_NewObject(cx, MemoryBuffer::GetClass(), NULL, NULL); + JS_SetPrivate(cx, obj, membuf); + return obj; +} + +WXJSAPI wxMemoryBuffer* wxjs::ext::GetMemoryBuffer(JSContext *cx, JSObject *obj) +{ + return MemoryBuffer::GetPrivate(cx, obj); +} + +WXJSAPI wxMemoryBuffer* wxjs::ext::NewMemoryBuffer(void *buffer, int size) +{ + wxMemoryBuffer *membuf = new wxMemoryBuffer(size); + membuf->AppendData(buffer, size); + return membuf; +} Property changes on: ps/trunk/source/tools/atlas/wxJS/ext/ext_main.cpp ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/ext/jsmembuf.cpp =================================================================== --- ps/trunk/source/tools/atlas/wxJS/ext/jsmembuf.cpp (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/ext/jsmembuf.cpp (revision 5154) @@ -0,0 +1,322 @@ +#include "precompiled.h" + +/* + * wxJavaScript - jsmembuf.cpp + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: jsmembuf.cpp 737 2007-06-08 18:12:16Z fbraem $ + */ +// jsmembuf.cpp +#include "../common/main.h" +#include "jsmembuf.h" +#include + +using namespace wxjs; +using namespace ext; + +/*** + * memorybuffer + * ext + * + * A wxMemoryBuffer is a useful data structure for storing arbitrary sized blocks of memory. + *
+ *
+ * You can access the data of the buffer as a JavaScript array. + * For example:
+ *

+ *   var buffer = new wxMemoryBuffer(10);
+ *   buffer[0] = 10;
+ *   buffer[1] = 'a';
+ *  
+ *
+ */ +WXJS_INIT_CLASS(MemoryBuffer, "wxMemoryBuffer", 0) + +/*** + * + * + * Is the buffer null? (dataLen and bufSize are 0). + * + * + * Get/Set the length of the data in the buffer. The length of the data + * can be less then the length of the buffer. + * + * + * Get/Set the size of the buffer. + * + * + */ +WXJS_BEGIN_PROPERTY_MAP(MemoryBuffer) + WXJS_PROPERTY(P_DATA_LENGTH, "dataLen") + WXJS_PROPERTY(P_LENGTH, "bufSize") + WXJS_READONLY_PROPERTY(P_IS_NULL, "isNull") +WXJS_END_PROPERTY_MAP() + +bool MemoryBuffer::GetProperty(wxMemoryBuffer *p, JSContext *cx, JSObject *obj, int id, jsval *vp) +{ + if ( id > -1 ) + { + if ( (unsigned int) id < p->GetDataLen() ) + { + unsigned int *data = (unsigned int*) p->GetData(); + *vp = ToJS(cx, (int) data[id]); + } + } + else + { + switch(id) + { + case P_DATA_LENGTH: + *vp = ToJS(cx, p->GetDataLen()); + break; + case P_LENGTH: + *vp = ToJS(cx, p->GetBufSize()); + break; + case P_IS_NULL: + *vp = ToJS(cx, p->GetDataLen() == 0 && p->GetBufSize() == 0); + break; + } + } + return true; +} + +bool MemoryBuffer::SetProperty(wxMemoryBuffer *p, JSContext *cx, JSObject *obj, int id, jsval *vp) +{ + if ( id > -1 ) + { + if ( (unsigned int) id < p->GetDataLen() ) + { + if ( JSVAL_IS_STRING(*vp) ) + { + wxString str; + FromJS(cx, *vp, str); + if ( str.Length() > 0 ) + { + char *bufdata = (char *) p->GetData(); + bufdata[id] = str[0]; + } + } + else + { + int data; + if ( FromJS(cx, *vp, data) ) + { + char *bufdata = (char *) p->GetData(); + bufdata[id] = data; + } + } + } + } + else + { + switch(id) + { + case P_DATA_LENGTH: + { + int length = 0; + if ( FromJS(cx, *vp, length) ) + p->SetDataLen(length); + break; + } + case P_LENGTH: + { + int dlength = 0; + if ( FromJS(cx, *vp, dlength) ) + p->SetBufSize(dlength); + break; + } + } + } + return true; +} + +/*** + * + * + * The size of the buffer + * + * + * A string to fill the buffer + * The encoding to use to put this string in the buffer + * + * + * Creates a new wxMemoryBuffer object with the given size or with + * string as content. + * + * + */ +wxMemoryBuffer *MemoryBuffer::Construct(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, bool constructing) +{ + if ( argc == 0 ) + return new wxMemoryBuffer(); + + if ( argc == 1 + && JSVAL_IS_INT(argv[0]) ) + { + int size = 0; + if ( FromJS(cx, argv[0], size) + && size > 0 ) + { + return new wxMemoryBuffer(size); + } + } + + wxString encoding(wxJS_INTERNAL_ENCODING); + if ( argc > 1 ) + { + FromJS(cx, argv[1], encoding); + } + wxString data; + FromJS(cx, argv[0], data); + + wxCharBuffer content; + if ( encoding.CmpNoCase(wxJS_INTERNAL_ENCODING) == 0 ) + { + content = data.mb_str(); + } + else + { + wxCSConv conv(encoding); + content = data.mb_str(conv); + } + + wxMemoryBuffer *buffer = new wxMemoryBuffer(); + buffer->AppendData(content, strlen(content)); + + return buffer; +} + +WXJS_BEGIN_METHOD_MAP(MemoryBuffer) + WXJS_METHOD("append", append, 1) + WXJS_METHOD("toString", toString, 0) +WXJS_END_METHOD_MAP() + +/*** + * + * + * The byte to add + * + * + * The buffer to add + * The size of the buffer to add. When not set, the full buffer is added. + * + * + * Concatenate a byte or buffer to this buffer. + * + * + */ +JSBool MemoryBuffer::append(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxMemoryBuffer *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + if ( JSVAL_IS_INT(argv[0]) ) + { + int byte; + FromJS(cx, argv[0], byte); + p->AppendByte((char) byte); + return JS_TRUE; + } + + if ( JSVAL_IS_OBJECT(argv[0]) ) + { + wxMemoryBuffer *buffer = GetPrivate(cx, argv[0], false); + if ( buffer != NULL ) + { + if ( argc > 1 ) + { + int size; + if ( FromJS(cx, argv[1], size) ) + { + if ( size > (int) buffer->GetDataLen() ) + size = buffer->GetDataLen(); + p->AppendData(buffer->GetData(), size); + } + else + { + return JS_FALSE; + } + } + else + { + p->AppendData(buffer->GetData(), buffer->GetDataLen()); + return JS_TRUE; + } + } + } + + wxString encoding(wxJS_INTERNAL_ENCODING); + if ( argc > 1 ) + { + FromJS(cx, argv[1], encoding); + } + + wxString data; + FromJS(cx, argv[0], data); + + wxCharBuffer content; + if ( encoding.CmpNoCase(wxJS_INTERNAL_ENCODING) == 0 ) + { + content = data.mb_str(); + } + else + { + wxCSConv conv(encoding); + content = data.mb_str(conv); + } + + p->AppendData(content, strlen(content)); + + return JS_TRUE; +} + +/*** + * + * + * + * The encoding of the string in this buffer. + * + * + * + * Converts the content in the buffer to a String. + * The default encoding is UTF-16 because in JavaScript all strings + * are stored in UTF-16. A conversion is done to UTF-16, + * when another encoding is specified. + * + * + */ +JSBool MemoryBuffer::toString(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxMemoryBuffer *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + wxString encoding(wxJS_INTERNAL_ENCODING); + if ( argc > 0 ) + FromJS(cx, argv[0], encoding); + + wxCSConv conv(encoding); + wxString content((const char*) p->GetData(), conv, p->GetDataLen()); + *rval = ToJS(cx, content); + + return JS_TRUE; +} Property changes on: ps/trunk/source/tools/atlas/wxJS/ext/jsmembuf.cpp ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/ext/jsmembuf.h =================================================================== --- ps/trunk/source/tools/atlas/wxJS/ext/jsmembuf.h (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/ext/jsmembuf.h (revision 5154) @@ -0,0 +1,68 @@ +/* + * wxJavaScript - jsmembuf.h + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: jsmembuf.h 598 2007-03-07 20:13:28Z fbraem $ + */ +#ifndef _WXJS_MEMBUF_H +#define _WXJS_MEMBUF_H + +///////////////////////////////////////////////////////////////////////////// +// Name: jsmembuf.h +// Purpose: Ports wxMemoryBuffer to JavaScript +// Author: Franky Braem +// Modified by: +// Created: 02.12.2005 +// Copyright: (c) 2001-2005 Franky Braem +// Licence: LGPL +///////////////////////////////////////////////////////////////////////////// + +#include + +namespace wxjs +{ + namespace ext + { + class MemoryBuffer : public ApiWrapper + { + public: + + static bool GetProperty(wxMemoryBuffer *p, JSContext *cx, JSObject *obj, int id, jsval *vp); + static bool SetProperty(wxMemoryBuffer *p, JSContext *cx, JSObject *obj, int id, jsval *vp); + + enum + { + P_DATA_LENGTH = WXJS_START_PROPERTY_ID, + P_LENGTH, + P_IS_NULL + }; + + WXJS_DECLARE_PROPERTY_MAP() + WXJS_DECLARE_METHOD_MAP() + + static wxMemoryBuffer *Construct(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, bool constructing); + + static JSBool append(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval); + static JSBool toString(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval); + }; + }; // namespace ext +}; // namespace wxjs +#endif Property changes on: ps/trunk/source/tools/atlas/wxJS/ext/jsmembuf.h ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/gui/control/panel.cpp =================================================================== --- ps/trunk/source/tools/atlas/wxJS/gui/control/panel.cpp (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/gui/control/panel.cpp (revision 5154) @@ -0,0 +1,336 @@ +#include "precompiled.h" + +/* + * wxJavaScript - panel.cpp + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: panel.cpp 708 2007-05-14 15:30:45Z fbraem $ + */ +// panel.cpp + +#ifndef WX_PRECOMP + #include "wx/wx.h" +#endif + +#include "../../common/main.h" + +#include "../event/jsevent.h" + + +#include "../misc/size.h" +#include "../misc/point.h" + +#include "button.h" +#include "panel.h" +#include "window.h" +#include "../errors.h" + +using namespace wxjs; +using namespace wxjs::gui; + +/*** + * control/panel + * gui + * + * A panel is a window on which controls are placed. It is usually placed within a frame. + * Its main purpose is to be similar in appearance and functionality to a dialog, + * but with the flexibility of having any window as a parent. + * See @wxDialog and @wxFrame + * + */ +WXJS_INIT_CLASS(Panel, "wxPanel", 2) + +void Panel::InitClass(JSContext* WXUNUSED(cx), + JSObject* WXUNUSED(obj), + JSObject* WXUNUSED(proto)) +{ + PanelEventHandler::InitConnectEventMap(); +} + +/*** + * + * + * Get/Set the default button. + * + * + */ +WXJS_BEGIN_PROPERTY_MAP(Panel) + WXJS_PROPERTY(P_DEFAULT_ITEM, "defaultItem") +WXJS_END_PROPERTY_MAP() + +bool Panel::GetProperty(wxPanel *p, + JSContext* WXUNUSED(cx), + JSObject* WXUNUSED(obj), + int id, + jsval *vp) +{ + if ( id == P_DEFAULT_ITEM ) + { + wxWindow *win = NULL; + + #if wxCHECK_VERSION(2,7,0) + wxTopLevelWindow *tlw = wxDynamicCast(wxGetTopLevelParent(p), + wxTopLevelWindow); + if ( tlw ) + win = tlw->GetDefaultItem(); + #else + win = p->GetDefaultItem(); + #endif + + if ( win ) + { + JavaScriptClientData *data + = dynamic_cast(win->GetClientObject()); + *vp = data->GetObject() == NULL ? JSVAL_VOID + : OBJECT_TO_JSVAL(data->GetObject()); + } + } + return true; +} + +bool Panel::SetProperty(wxPanel *p, + JSContext *cx, + JSObject* WXUNUSED(obj), + int id, + jsval *vp) +{ + if ( id == P_DEFAULT_ITEM ) + { + wxWindow *win = Window::GetPrivate(cx, *vp); + if ( win != NULL ) + { + #if wxCHECK_VERSION(2,7,0) + wxTopLevelWindow *tlw = wxDynamicCast(wxGetTopLevelParent(p), + wxTopLevelWindow); + if ( tlw ) + tlw->SetDefaultItem(win); + #else + p->SetDefaultItem(win); + #endif + } + } + return true; +} + +bool Panel::AddProperty(wxPanel *p, + JSContext* WXUNUSED(cx), + JSObject* WXUNUSED(obj), + const wxString &prop, + jsval* WXUNUSED(vp)) +{ + if ( WindowEventHandler::ConnectEvent(p, prop, true) ) + return true; + + PanelEventHandler::ConnectEvent(p, prop, true); + + return true; +} + + +bool Panel::DeleteProperty(wxPanel *p, + JSContext* WXUNUSED(cx), + JSObject* WXUNUSED(obj), + const wxString &prop) +{ + if ( WindowEventHandler::ConnectEvent(p, prop, false) ) + return true; + + PanelEventHandler::ConnectEvent(p, prop, false); + return true; +} + +/*** + * + * + * + * + * The parent of wxPanel. + * + * + * A window identifier. Use -1 when you don't need it. + * + * + * The position of the Panel control on the given parent. + * + * + * The size of the Panel control. + * + * + * The wxPanel style. + * + * + * + * Constructs a new wxPanel object. + * + * + */ +wxPanel* Panel::Construct(JSContext *cx, + JSObject *obj, + uintN argc, + jsval *argv, + bool WXUNUSED(constructing)) +{ + wxPanel *p = new wxPanel(); + if ( argc > 0 ) + { + jsval rval; + create(cx, obj, argc, argv, &rval); + } + + return p; +} + +WXJS_BEGIN_METHOD_MAP(Panel) + WXJS_METHOD("create", create, 2) +WXJS_END_METHOD_MAP() + +/*** + * + * + * + * The parent of wxPanel. + * + * + * A window identifier. Use -1 when you don't need it. + * + * + * The position of the Panel control on the given parent. + * + * + * The size of the Panel control. + * + * + * The wxPanel style. + * + * + * + * Constructs a new wxPanel object. + * + * + */ +JSBool Panel::create(JSContext *cx, + JSObject *obj, + uintN argc, + jsval *argv, + jsval *rval) +{ + wxPanel *p = GetPrivate(cx, obj); + *rval = JSVAL_FALSE; + + if ( argc > 5 ) + argc = 5; + + int style = 0; + const wxPoint *pt = &wxDefaultPosition; + const wxSize *size = &wxDefaultSize; + + switch(argc) + { + case 5: + if ( ! FromJS(cx, argv[4], style) ) + { + JS_ReportError(cx, WXJS_INVALID_ARG_TYPE, 5, "Integer"); + return JS_FALSE; + } + // Fall through + case 4: + size = Size::GetPrivate(cx, argv[3]); + if ( size == NULL ) + { + JS_ReportError(cx, WXJS_INVALID_ARG_TYPE, 4, "wxSize"); + return JS_FALSE; + } + // Fall through + case 3: + pt = Point::GetPrivate(cx, argv[2]); + if ( pt == NULL ) + { + JS_ReportError(cx, WXJS_INVALID_ARG_TYPE, 3, "wxPoint"); + return JS_FALSE; + } + // Fall through + default: + int id; + if ( ! FromJS(cx, argv[1], id) ) + { + JS_ReportError(cx, WXJS_INVALID_ARG_TYPE, 2, "Integer"); + return JS_FALSE; + } + + wxWindow *parent = Window::GetPrivate(cx, argv[0]); + if ( parent == NULL ) + { + JS_ReportError(cx, WXJS_NO_PARENT_ERROR, GetClass()->name); + return JS_FALSE; + } + JavaScriptClientData *clntParent = + dynamic_cast(parent->GetClientObject()); + if ( clntParent == NULL ) + { + JS_ReportError(cx, WXJS_NO_PARENT_ERROR, GetClass()->name); + return JS_FALSE; + } + JS_SetParent(cx, obj, clntParent->GetObject()); + + if ( p->Create(parent, id, *pt, *size, style) ) + { + *rval = JSVAL_TRUE; + p->SetClientObject(new JavaScriptClientData(cx, obj, true, false)); + } + } + + return JS_TRUE; +} + +/*** + * + * + * To process a system colour changed event, use this property to set + * an event handler function. The function takes a @wxSysColourChangedEvent argument. + * + * + */ +WXJS_INIT_EVENT_MAP(wxPanel) +const wxString WXJS_SYS_COLOUR_CHANGED_EVENT = wxT("onSysColourChanged"); + +void PanelEventHandler::OnSysColourChanged(wxSysColourChangedEvent &event) +{ + PrivSysColourChangedEvent::Fire(event, WXJS_SYS_COLOUR_CHANGED_EVENT); +} + +void PanelEventHandler::ConnectSysColourChanged(wxPanel *p, bool connect) +{ + if ( connect ) + { + p->Connect(wxEVT_SYS_COLOUR_CHANGED, + wxSysColourChangedEventHandler(OnSysColourChanged)); + } + else + { + p->Disconnect(wxEVT_SYS_COLOUR_CHANGED, + wxSysColourChangedEventHandler(OnSysColourChanged)); + } +} + +void PanelEventHandler::InitConnectEventMap() +{ + AddConnector(WXJS_SYS_COLOUR_CHANGED_EVENT, ConnectSysColourChanged); +} Property changes on: ps/trunk/source/tools/atlas/wxJS/gui/control/panel.cpp ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/gui/control/dialog.h =================================================================== --- ps/trunk/source/tools/atlas/wxJS/gui/control/dialog.h (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/gui/control/dialog.h (revision 5154) @@ -0,0 +1,105 @@ +/* + * wxJavaScript - dialog.h + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: dialog.h 682 2007-04-24 20:38:18Z fbraem $ + */ +#ifndef _WXJSDialog_H +#define _WXJSDialog_H + +#include "../../common/evtconn.h" + +namespace wxjs +{ + namespace gui + { + class Dialog : public ApiWrapper + { + public: + + static void InitClass(JSContext* cx, + JSObject* obj, + JSObject* proto); + + static bool AddProperty(wxDialog *p, + JSContext *cx, + JSObject *obj, + const wxString &prop, + jsval *vp); + static bool DeleteProperty(wxDialog *p, + JSContext* cx, + JSObject* obj, + const wxString &prop); + static bool GetProperty(wxDialog *p, + JSContext *cx, + JSObject *obj, + int id, + jsval *vp); + + static wxDialog* Construct(JSContext *cx, + JSObject *obj, + uintN argc, + jsval *argv, + bool constructing); + + WXJS_DECLARE_PROPERTY_MAP() + enum + { + P_RETURN_CODE + , P_TITLE + , P_MODAL + }; + + WXJS_DECLARE_CONSTANT_MAP() + + WXJS_DECLARE_METHOD_MAP() + static JSBool end_modal(JSContext *cx, + JSObject *obj, + uintN argc, + jsval *argv, + jsval *rval); + static JSBool show_modal(JSContext *cx, + JSObject *obj, + uintN argc, + jsval *argv, + jsval *rval); + static JSBool create(JSContext *cx, + JSObject *obj, + uintN argc, + jsval *argv, + jsval *rval); + }; + + class DialogEventHandler : public EventConnector + , public wxEvtHandler + { + public: + void OnClose(wxCloseEvent &event); + void OnInitDialog(wxInitDialogEvent &event); + static void InitConnectEventMap(); + private: + static void ConnectClose(wxDialog *p, bool connect); + static void ConnectInitDialog(wxDialog *p, bool connect); + }; + }; // namespace gui +}; // namespace wxjs + +#endif //_WXJSDialog_H Property changes on: ps/trunk/source/tools/atlas/wxJS/gui/control/dialog.h ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/gui/control/menu.cpp =================================================================== --- ps/trunk/source/tools/atlas/wxJS/gui/control/menu.cpp (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/gui/control/menu.cpp (revision 5154) @@ -0,0 +1,835 @@ +#include "precompiled.h" + +/* + * wxJavaScript - menu.cpp + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: menu.cpp 696 2007-05-07 21:16:23Z fbraem $ + */ +// menu.cpp +#ifndef WX_PRECOMP + #include +#endif + +#include "../../common/main.h" +#include "../../common/type.h" + +#include "menu.h" +#include "menuitem.h" + +#include "../misc/app.h" + +#include "../event/jsevent.h" + +#include "../event/command.h" + +using namespace wxjs; +using namespace wxjs::gui; +/* +Menu::~Menu() +{ + // When the menu is attached, it's destroyed by wxWindows + // Setting the private data to NULL, will prevent an access-violation. + if ( IsAttached() ) + { + JS_SetPrivate(GetContext(), GetObject(), NULL); + } +} +*/ +/*** + * control/menu + * gui + * + * A menu is a popup (or pull down) list of items, + * one of which may be selected before the menu goes away + * (clicking elsewhere dismisses the menu). Menus may + * be used to construct either menu bars or popup menus. + * See @wxMenuBar and @wxFrame#menuBar property. + * + */ +WXJS_INIT_CLASS(Menu, "wxMenu", 0) + +/*** + * + * + * An array containing the function callbacks. A function will be called when a menu item is selected. + * Use @wxMenuItem#id id as index of the array. It is possible to change the function + * after the menu item is appended to the menu. + * + * + * Returns the number of menu items. + * + * + * Returns all the menu items. + * + * + * Get/Set the title of the menu + * + * + */ +WXJS_BEGIN_PROPERTY_MAP(Menu) + WXJS_READONLY_PROPERTY(P_MENU_ITEM_COUNT, "menuItemCount") + WXJS_READONLY_PROPERTY(P_MENU_ITEMS, "menuItems") + WXJS_PROPERTY(P_TITLE, "title") +WXJS_END_PROPERTY_MAP() + +bool Menu::GetProperty(wxMenu *p, + JSContext *cx, + JSObject* WXUNUSED(obj), + int id, + jsval *vp) +{ + switch (id) + { + case P_MENU_ITEM_COUNT: + { + *vp = ToJS(cx, p->GetMenuItemCount()); + break; + } + case P_MENU_ITEMS: + { + wxMenuItemList &list = p->GetMenuItems(); + jsint count = list.GetCount(); + + JSObject *objItems = JS_NewArrayObject(cx, count, NULL); + *vp = OBJECT_TO_JSVAL(objItems); + + jsint i = 0; + for (wxMenuItemList::Node *node = list.GetFirst(); + node; + node = node->GetNext() ) + { + jsval element = MenuItem::CreateObject(cx, node->GetData()); + JS_SetElement(cx, objItems, i++, &element); + } + + break; + } + case P_TITLE: + *vp = ToJS(cx, p->GetTitle()); + break; + } + return true; +} + +bool Menu::SetProperty(wxMenu *p, + JSContext *cx, + JSObject* WXUNUSED(obj), + int id, + jsval *vp) +{ + if ( id == P_TITLE ) + { + wxString title; + FromJS(cx, *vp, title); + p->SetTitle(title); + } + + return true; +} + +/*** + * + * + * (wxGTK only) + * + * + */ +WXJS_BEGIN_CONSTANT_MAP(Menu) + // Style constants + WXJS_CONSTANT(wxMENU_, TEAROFF) +WXJS_END_CONSTANT_MAP() + +/*** + * + * + * + * A title for the popup menu + * + * + * A menu style + * + * + * + * + * A menu style + * + * + * + * Creates a new wxMenu object + * + * + */ +wxMenu* Menu::Construct(JSContext *cx, + JSObject *obj, + uintN argc, + jsval *argv, + bool WXUNUSED(constructing)) +{ + if ( argc > 2 ) + argc = 2; + + wxMenu *p = NULL; + + switch(argc) + { + case 2: + { + wxString title; + int style; + + FromJS(cx, argv[0], title); + if ( FromJS(cx, argv[1], style) ) + p = new wxMenu(title, style); + break; + } + case 1: + if ( JSVAL_IS_INT(argv[0]) ) + { + int style = 0; + if ( FromJS(cx, argv[0], style) ) + p = new wxMenu(style); + } + else + { + wxString title; + FromJS(cx, argv[0], title); + p = new wxMenu(title); + } + break; + default: + p = new wxMenu(); + } + + if ( p != NULL ) + { + p->SetClientObject(new JavaScriptClientData(cx, obj, true, false)); + JSObject *objActionArray = JS_NewArrayObject(cx, 0, NULL); + JS_DefineProperty(cx, obj, "actions", OBJECT_TO_JSVAL(objActionArray), + NULL, NULL, JSPROP_ENUMERATE |JSPROP_PERMANENT); + } + + return p; +} + +/* +void Menu::Destruct(JSContext *cx, wxMenu *p) +{ + if ( p != NULL ) + { + delete p; + p = NULL; + } +} +*/ + +WXJS_BEGIN_METHOD_MAP(Menu) + WXJS_METHOD("append", append, 3) + WXJS_METHOD("appendSeparator", append_separator, 0) + WXJS_METHOD("deleteItem", delete_item, 1) + WXJS_METHOD("destroy", destroy, 0) + WXJS_METHOD("findItem", find_item, 1) + WXJS_METHOD("getHelpString", getHelpString, 1) + WXJS_METHOD("getLabel", getLabel, 1) + WXJS_METHOD("newColumn", new_column, 0) + WXJS_METHOD("check", check, 2) + WXJS_METHOD("enable", enable, 2) + WXJS_METHOD("getItem", getItem, 1) + WXJS_METHOD("insert", insert, 2) + WXJS_METHOD("isChecked", isChecked, 1) + WXJS_METHOD("isEnabled", isEnabled, 1) + WXJS_METHOD("remove", remove, 1) + WXJS_METHOD("setHelpString", setHelpString, 2) + WXJS_METHOD("setLabel", setLabel, 2) +WXJS_END_METHOD_MAP() + +/*** + * + * + * + * The id of the menu item. + * + * + * The name of the menu item. + * + * + * The function that is called when the menu item is selected. The argument to the + * function will be @wxCommandEvent. + * + * + * Message which is shown in the statusbar. + * + * + * Indicates if the menu item can be checked or not. + * + * + * + * Appends a new menu item to the menu. + * + * + */ +JSBool Menu::append(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxMenu *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + wxString help = wxEmptyString; + bool checkable = false; + + switch(argc) + { + case 5: + if ( ! FromJS(cx, argv[4], checkable) ) + break; + // Fall through + case 4: + FromJS(cx, argv[3], help); + // Fall through + default: + wxString name; + FromJS(cx, argv[1], name); + + int id = 0; + + if ( ! FromJS(cx, argv[0], id) ) + break; + + p->Append(id, name, help, checkable); + + jsval actions; + if ( JS_GetProperty(cx, obj, "actions", &actions) == JS_TRUE ) + { + JS_SetElement(cx, JSVAL_TO_OBJECT(actions), id, &argv[2]); + } + return JS_TRUE; + } + + return JS_FALSE; +} + +/*** + * + * + * + * The id of the menu item. + * + * + * Check (true) or uncheck (false) the item + * + * + * + * Checks or unchecks the menu item. + * + * + */ +JSBool Menu::check(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxMenu *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + int id = 0; + bool check = false; + + if ( FromJS(cx, argv[0], id) + && FromJS(cx, argv[1], check) ) + { + p->Check(id, check); + return JS_TRUE; + } + + return JS_FALSE; +} + +/*** + * + * + * + * The id of the menu item. + * + * + * Enables (true) or disables (false) the item + * + * + * + * Enables or disables the menu item. + * + * + */ +JSBool Menu::enable(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxMenu *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + int id = 0; + bool flag = false; + + if ( FromJS(cx, argv[0], id) + && FromJS(cx, argv[1], flag) ) + { + p->Enable(id, flag); + return JS_TRUE; + } + + return JS_FALSE; +} + +/*** + * + * + * + * The id of the menu item. + * + * + * + * + * A menu item. + * + * + * + * Deletes the menu item from the menu. If the item is a submenu, + * it will not be deleted. Use @wxMenu#destroy if you want to delete a submenu. + * + * + */ +JSBool Menu::delete_item(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxMenu *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + int id; + if ( FromJS(cx, argv[0], id) ) + { + p->Delete(id); + return JS_TRUE; + } + else + { + wxMenuItem *item = MenuItem::GetPrivate(cx, argv[0]); + if ( item != NULL ) + { + p->Delete(item); + return JS_TRUE; + } + } + + return JS_FALSE; +} + +/*** + * + * + * + * The search string + * + * + * + * Searches the menu item with the given search string and + * returns its identifier. -1 is returned when the item is not found. + * Any special menu codes are stripped out of source and target strings before matching. + * + * + */ +JSBool Menu::find_item(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxMenu *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + wxString search; + FromJS(cx, argv[0], search); + *rval = ToJS(cx, p->FindItem(search)); + + return JS_TRUE; +} + +/*** + * + * + * + * Adds a new column + * + * + */ +JSBool Menu::new_column(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxMenu *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + p->Break(); + + return JS_TRUE; +} + +/*** + * + * + * + * Adds a separator + * + * + */ +JSBool Menu::append_separator(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxMenu *p = Menu::GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + p->AppendSeparator(); + + return JS_TRUE; +} + +/*** + * + * + * + * The id of the menu item + * + * + * + * Returns the helpstring of the menu item with the given id. + * See @wxMenu#setHelpString and @wxMenuItem#help property + * + * + */ +JSBool Menu::getHelpString(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxMenu *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + int id; + if ( FromJS(cx, argv[0], id) ) + { + *rval = ToJS(cx, p->GetHelpString(id)); + return JS_TRUE; + } + + return JS_FALSE; +} + +/*** + * + * + * + * The id of the menu item + * + * + * + * Returns the label of the menu item with the given id. + * See @wxMenu#setLabel and @wxMenuItem#label property. + * + * + */ +JSBool Menu::getLabel(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxMenu *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + int id; + if ( FromJS(cx, argv[0], id) ) + { + *rval = ToJS(cx, p->GetLabel(id)); + return JS_TRUE; + } + + return JS_FALSE; +} + +/*** + * + * + * + * The id of the menu item + * + * + * + * Returns the @wxMenuItem object of the menu item with the given id. + * + * + */ +JSBool Menu::getItem(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxMenu *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + int id; + if ( FromJS(cx, argv[0], id) ) + { + wxMenuItem *item = p->FindItem(id); + *rval = ( item == NULL ) ? JSVAL_NULL : MenuItem::CreateObject(cx, item); + return JS_TRUE; + } + + return JS_FALSE; +} + +/*** + * + * + * + * The id of the menu item + * + * + * + * + * + * + * Deletes the menu item from the menu. If the item is a submenu, it will be deleted. + * Use @wxMenu#remove if you want to keep the submenu (for example, to reuse it later). + * + * + */ +JSBool Menu::destroy(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxMenu *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + int id; + if ( FromJS(cx, argv[0], id) ) + { + p->Destroy(id); + return JS_TRUE; + } + else if ( JSVAL_IS_OBJECT(argv[0]) ) + { + wxMenuItem *item = MenuItem::GetPrivate(cx, argv[0]); + if ( item != NULL ) + { + p->Destroy(item); + return JS_TRUE; + } + } + + return JS_FALSE; +} + +/*** + * + * + * + * + * + * + * Inserts the given item before the position pos. + * Inserting the item at the position @wxMenu#menuItemCount + * is the same as appending it. + * + * + */ +JSBool Menu::insert(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxMenu *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + int pos; + if ( FromJS(cx, argv[0], pos) + && JSVAL_IS_OBJECT(argv[1]) ) + { + wxMenuItem *item = MenuItem::GetPrivate(cx, argv[1]); + if ( item != NULL ) + { + return JS_TRUE; + } + } + + return JS_FALSE; +} + +/*** + * + * + * + * A menu item identifier. + * + * + * + * Returns true when the menu item is checked. + * + * + */ +JSBool Menu::isChecked(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxMenu *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + int idx; + if ( FromJS(cx, argv[0], idx) ) + { + *rval = ToJS(cx, p->IsChecked(idx)); + return JS_TRUE; + } + + return JS_FALSE; +} + +/*** + * + * + * + * A menu item identifier. + * + * + * + * Returns true when the menu item is enabled. + * + * + */ +JSBool Menu::isEnabled(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxMenu *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + int idx; + if ( FromJS(cx, argv[0], idx) ) + { + *rval = ToJS(cx, p->IsEnabled(idx)); + return JS_TRUE; + } + + return JS_FALSE; +} + +/*** + * + * + * + * An identifier of a menu item. + * + * + * + * + * + * + * Removes the menu item from the menu but doesn't delete the object. + * This allows to reuse the same item later by adding it back to the menu + * (especially useful with submenus). + * + * + */ +JSBool Menu::remove(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxMenu *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + wxMenuItem *item = NULL; + int id; + + if ( FromJS(cx, argv[0], id) ) + { + item = p->Remove(id); + } + else if ( JSVAL_IS_OBJECT(argv[0]) ) + { + wxMenuItem *removeItem = MenuItem::GetPrivate(cx, argv[1]); + if ( removeItem != NULL ) + item = p->Remove(removeItem); + } + else + { + return JS_FALSE; + } + + *rval = ( item == NULL ) ? JSVAL_VOID : MenuItem::CreateObject(cx, item); + return JS_TRUE; + +} + +/*** + * + * + * + * A menu item identifier. + * + * + * The help text + * + * + * + * Sets the help associated with a menu item. + * See @wxMenuItem#help property and @wxMenuBar#setHelpString method. + * + * + */ +JSBool Menu::setHelpString(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxMenu *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + int id; + wxString help; + + if ( FromJS(cx, argv[0], id) ) + { + FromJS(cx, argv[1], help); + p->SetHelpString(id, help); + } + + return JS_FALSE; +} + +/*** + * + * + * + * A menu item identifier. + * + * + * A new label + * + * + * + * Sets the label of a menu item. + * See @wxMenuItem#label property and @wxMenuBar#setLabel method + * + * + */ +JSBool Menu::setLabel(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxMenu *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + int id; + wxString label; + + if ( FromJS(cx, argv[0], id) ) + { + FromJS(cx, argv[1], label); + p->SetLabel(id, label); + return JS_TRUE; + } + + return JS_FALSE; +} Property changes on: ps/trunk/source/tools/atlas/wxJS/gui/control/menu.cpp ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/gui/control/listctrl.h =================================================================== --- ps/trunk/source/tools/atlas/wxJS/gui/control/listctrl.h (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/gui/control/listctrl.h (revision 5154) @@ -0,0 +1,244 @@ +/* + * wxJavaScript - listctrl.h + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: listctrl.h 734 2007-06-06 20:09:13Z fbraem $ + */ +#ifndef _WXJSListCtrl_H +#define _WXJSListCtrl_H + +#include + +#include "../../common/evtconn.h" + +namespace wxjs +{ + namespace gui + { + class ListCtrl : public wxListCtrl + , public ApiWrapper + { + public: + ListCtrl(); + ~ListCtrl(); + + // Callback used for sorting. + static int wxCALLBACK SortFn(long item1, long item2, long data); + // Fn's for virtual list controls. + wxString OnGetItemText(long item, long column) const; + int OnGetItemImage(long item) const; + wxListItemAttr *OnGetItemAttr(long item) const; + + static bool GetProperty(wxListCtrl *p, + JSContext *cx, + JSObject *obj, + int id, + jsval *vp); + static bool SetProperty(wxListCtrl *p, + JSContext *cx, + JSObject *obj, + int id, + jsval *vp); + static bool AddProperty(wxListCtrl *p, + JSContext *cx, + JSObject *obj, + const wxString &prop, + jsval *vp); + static bool DeleteProperty(wxListCtrl *p, + JSContext* cx, + JSObject* obj, + const wxString &prop); + + /** + * Callback for when a wxListCtrl object is created + */ + static wxListCtrl* Construct(JSContext *cx, + JSObject *obj, + uintN argc, + jsval *argv, + bool constructing); + static void InitClass(JSContext *cx, + JSObject *obj, + JSObject *proto); + + WXJS_DECLARE_PROPERTY_MAP() + enum + { + P_COUNT_PER_PAGE + , P_EDIT_CONTROL + , P_COLUMN_COUNT + , P_ITEM_COUNT + , P_SELECTED_ITEM_COUNT + , P_TEXT_COLOUR + , P_TOP_ITEM + , P_WINDOW_STYLE + , P_IS_VIRTUAL + }; + + WXJS_DECLARE_METHOD_MAP() + WXJS_DECLARE_METHOD(create) + WXJS_DECLARE_METHOD(getColumn) + WXJS_DECLARE_METHOD(setColumn) + WXJS_DECLARE_METHOD(getColumnWidth) + WXJS_DECLARE_METHOD(setColumnWidth) + WXJS_DECLARE_METHOD(getItem) + WXJS_DECLARE_METHOD(setItem) + WXJS_DECLARE_METHOD(getItemState) + WXJS_DECLARE_METHOD(setItemState) + WXJS_DECLARE_METHOD(setItemImage) + WXJS_DECLARE_METHOD(getItemText) + WXJS_DECLARE_METHOD(setItemText) + WXJS_DECLARE_METHOD(getItemData) + WXJS_DECLARE_METHOD(setItemData) + WXJS_DECLARE_METHOD(getItemRect) + WXJS_DECLARE_METHOD(getItemPosition) + WXJS_DECLARE_METHOD(setItemPosition) + WXJS_DECLARE_METHOD(getItemSpacing) + WXJS_DECLARE_METHOD(setSingleStyle) + WXJS_DECLARE_METHOD(getNextItem) + WXJS_DECLARE_METHOD(getImageList) + WXJS_DECLARE_METHOD(setImageList) + WXJS_DECLARE_METHOD(refreshItem) + WXJS_DECLARE_METHOD(refreshItems) + WXJS_DECLARE_METHOD(arrange) + WXJS_DECLARE_METHOD(deleteItem) + WXJS_DECLARE_METHOD(deleteAllItems) + WXJS_DECLARE_METHOD(deleteColumn) + WXJS_DECLARE_METHOD(deleteAllColumns) + WXJS_DECLARE_METHOD(clearAll) + WXJS_DECLARE_METHOD(insertColumn) + WXJS_DECLARE_METHOD(insertItem) + WXJS_DECLARE_METHOD(editLabel) + WXJS_DECLARE_METHOD(endEditLabel) + WXJS_DECLARE_METHOD(ensureVisible) + WXJS_DECLARE_METHOD(findItem) + WXJS_DECLARE_METHOD(hitTest) + WXJS_DECLARE_METHOD(scrollList) + WXJS_DECLARE_METHOD(sortItems) + + WXJS_DECLARE_CONSTANT_MAP() + }; + + class ListCtrlEventHandler : public EventConnector + , public wxEvtHandler + { + public: + // Events + void OnBeginDrag(wxListEvent &event); + void OnBeginRDrag(wxListEvent &event); + void OnBeginLabelEdit(wxListEvent &event); + void OnEndLabelEdit(wxListEvent &event); + void OnDeleteItem(wxListEvent &event); + void OnDeleteAllItems(wxListEvent &event); + void OnItemSelected(wxListEvent &event); + void OnItemDeselected(wxListEvent &event); + void OnItemActivated(wxListEvent &event); + void OnItemFocused(wxListEvent &event); + void OnItemRightClick(wxListEvent &event); + void OnListKeyDown(wxListEvent &event); + void OnInsertItem(wxListEvent &event); + void OnColClick(wxListEvent &event); + void OnColRightClick(wxListEvent &event); + void OnColBeginDrag(wxListEvent &event); + void OnColDragging(wxListEvent &event); + void OnColEndDrag(wxListEvent &event); + void OnCacheHint(wxListEvent &event); + static void InitConnectEventMap(); + private: + static void ConnectBeginDrag(wxListCtrl *p, bool connect); + static void ConnectBeginRDrag(wxListCtrl *p, bool connect); + static void ConnectBeginLabelEdit(wxListCtrl *p, bool connect); + static void ConnectEndLabelEdit(wxListCtrl *p, bool connect); + static void ConnectDeleteItem(wxListCtrl *p, bool connect); + static void ConnectDeleteAllItems(wxListCtrl *p, bool connect); + static void ConnectItemSelected(wxListCtrl *p, bool connect); + static void ConnectItemDeselected(wxListCtrl *p, bool connect); + static void ConnectItemActivated(wxListCtrl *p, bool connect); + static void ConnectItemFocused(wxListCtrl *p, bool connect); + static void ConnectItemRightClick(wxListCtrl *p, bool connect); + static void ConnectListKeyDown(wxListCtrl *p, bool connect); + static void ConnectInsertItem(wxListCtrl *p, bool connect); + static void ConnectColClick(wxListCtrl *p, bool connect); + static void ConnectColRightClick(wxListCtrl *p, bool connect); + static void ConnectColBeginDrag(wxListCtrl *p, bool connect); + static void ConnectColDragging(wxListCtrl *p, bool connect); + static void ConnectColEndDrag(wxListCtrl *p, bool connect); + static void ConnectCacheHint(wxListCtrl *p, bool connect); + }; + + /** + * Helper class used for sorting items in wxListCtrl + */ + class ListSort + { + public: + ListSort(JSContext *cx, JSFunction *fun, long data) : m_cx(cx), m_fun(fun), m_data(data) + { + } + + JSFunction *GetFn() const + { + return m_fun; + } + + long GetData() const + { + return m_data; + } + + JSContext *GetContext() const + { + return m_cx; + } + + private: + JSContext *m_cx; + JSFunction *m_fun; + long m_data; + }; + + class ListObjectData + { + public: + ListObjectData(JSContext *cx, jsval v) : m_cx(cx), m_val(v) + { + if ( JSVAL_IS_GCTHING(m_val) ) {} + JS_AddRoot(m_cx, &m_val); + } + + virtual ~ListObjectData() + { + if ( JSVAL_IS_GCTHING(m_val) ) {} + JS_RemoveRoot(m_cx, &m_val); + } + + jsval GetJSVal() + { + return m_val; + } + private: + JSContext *m_cx; + jsval m_val; + }; + }; // namespace gui +}; // namespace wxjs + +#endif //_WXJSListCtrl_H Property changes on: ps/trunk/source/tools/atlas/wxJS/gui/control/listctrl.h ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/gui/control/txtdlg.cpp =================================================================== --- ps/trunk/source/tools/atlas/wxJS/gui/control/txtdlg.cpp (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/gui/control/txtdlg.cpp (revision 5154) @@ -0,0 +1,191 @@ +#include "precompiled.h" + +/* + * wxJavaScript - txtdlg.cpp + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: txtdlg.cpp 708 2007-05-14 15:30:45Z fbraem $ + */ +// txtdlg.cpp + +#ifndef WX_PRECOMP + #include +#endif +#include + +#include "../../common/main.h" + +#include "../misc/point.h" +#include "../event/jsevent.h" + +#include "../errors.h" + +#include "txtdlg.h" +#include "window.h" +#include "dialog.h" + +using namespace wxjs; +using namespace wxjs::gui; + +/*** + * control/txtdlg + * gui + * + * This class represents a dialog that requests a one-line text string from the user. + * See also @wxPasswordEntryDialog. + * + */ +WXJS_INIT_CLASS(TextEntryDialog, "wxTextEntryDialog", 2) + +/*** + * + * The value entered in the dialog + * + */ +WXJS_BEGIN_PROPERTY_MAP(TextEntryDialog) + WXJS_PROPERTY(P_VALUE, "value") +WXJS_END_PROPERTY_MAP() + +bool TextEntryDialog::GetProperty(wxTextEntryDialog *p, JSContext *cx, JSObject *obj, int id, jsval *vp) +{ + switch (id) + { + case P_VALUE: + *vp = ToJS(cx, p->GetValue()); + break; + } + return true; +} + +bool TextEntryDialog::SetProperty(wxTextEntryDialog *p, JSContext *cx, JSObject *obj, int id, jsval *vp) +{ + switch (id) + { + case P_VALUE: + { + wxString value; + if ( FromJS(cx, *vp, value) ) + p->SetValue(value); + break; + } + } + return true; +} + +bool TextEntryDialog::AddProperty(wxTextEntryDialog *p, + JSContext* WXUNUSED(cx), + JSObject* WXUNUSED(obj), + const wxString &prop, + jsval* WXUNUSED(vp)) +{ + if ( WindowEventHandler::ConnectEvent(p, prop, true) ) + return true; + + DialogEventHandler::ConnectEvent(p, prop, true); + + return true; +} + +bool TextEntryDialog::DeleteProperty(wxTextEntryDialog *p, + JSContext* WXUNUSED(cx), + JSObject* WXUNUSED(obj), + const wxString &prop) +{ + if ( WindowEventHandler::ConnectEvent(p, prop, false) ) + return true; + + DialogEventHandler::ConnectEvent(p, prop, false); + return true; +} + +/*** + * + * + * The parent of the dialog. null is Allowed. + * Message to show on the dialog. + * The title of the dialog. + * The default value of the text control. + * The position of the dialog. + * A dialog style, the buttons (wxId.OK and wxId.CANCEL) and wxCENTRE can be used. + * + * + * Constructs a new wxTextEntryDialog object. + * + * + */ +wxTextEntryDialog* TextEntryDialog::Construct(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, bool constructing) +{ + if ( argc > 6 ) + argc = 6; + + int style = wxOK | wxCANCEL | wxCENTRE; + const wxPoint *pt = &wxDefaultPosition; + wxString defaultValue = wxEmptyString; + wxString caption = wxEmptyString; + + switch(argc) + { + case 6: + pt = Point::GetPrivate(cx, argv[5]); + if ( pt == NULL ) + { + JS_ReportError(cx, WXJS_INVALID_ARG_TYPE, 6, "wxPoint"); + return NULL; + } + // Fall through + case 5: + if ( ! FromJS(cx, argv[4], style) ) + { + JS_ReportError(cx, WXJS_INVALID_ARG_TYPE, 5, "Integer"); + return NULL; + } + // Fall through + case 4: + FromJS(cx, argv[3], defaultValue); + // Fall through + case 3: + FromJS(cx, argv[2], caption); + // Fall through + default: + wxString message; + FromJS(cx, argv[1], message); + + wxWindow *parent = Window::GetPrivate(cx, argv[0]); + if ( parent != NULL ) + { + JavaScriptClientData *clntParent = + dynamic_cast(parent->GetClientObject()); + if ( clntParent == NULL ) + { + JS_ReportError(cx, WXJS_NO_PARENT_ERROR, GetClass()->name); + return JS_FALSE; + } + JS_SetParent(cx, obj, clntParent->GetObject()); + } + + wxTextEntryDialog *p = new wxTextEntryDialog(parent, message, caption, + defaultValue, style, *pt); + p->SetClientObject(new JavaScriptClientData(cx, obj, true, false)); + return p; + } + + return NULL; +} Property changes on: ps/trunk/source/tools/atlas/wxJS/gui/control/txtdlg.cpp ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/gui/control/radiobtn.h =================================================================== --- ps/trunk/source/tools/atlas/wxJS/gui/control/radiobtn.h (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/gui/control/radiobtn.h (revision 5154) @@ -0,0 +1,92 @@ +/* + * wxJavaScript - radiobtn.h + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: radiobtn.h 696 2007-05-07 21:16:23Z fbraem $ + */ +#ifndef _WXJSRadioButton_H +#define _WXJSRadioButton_H + +#include "../../common/evtconn.h" + +namespace wxjs +{ + namespace gui + { + class RadioButton : public ApiWrapper + { + public: + + static void InitClass(JSContext* cx, + JSObject* obj, + JSObject* proto); + static bool AddProperty(wxRadioButton *p, + JSContext *cx, + JSObject *obj, + const wxString &prop, + jsval *vp); + static bool DeleteProperty(wxRadioButton *p, + JSContext* cx, + JSObject* obj, + const wxString &prop); + static bool GetProperty(wxRadioButton *p, + JSContext *cx, + JSObject *obj, + int id, + jsval *vp); + static bool SetProperty(wxRadioButton *p, + JSContext *cx, + JSObject *obj, + int id, + jsval *vp); + + static wxRadioButton* Construct(JSContext *cx, + JSObject *obj, + uintN argc, + jsval *argv, + bool constructing); + + WXJS_DECLARE_CONSTANT_MAP() + + WXJS_DECLARE_PROPERTY_MAP() + enum + { + P_VALUE + }; + + WXJS_DECLARE_METHOD_MAP() + WXJS_DECLARE_METHOD(create) + }; + + class RadioButtonEventHandler : public EventConnector + , public wxEvtHandler + { + public: + // Events + void OnRadioButton(wxCommandEvent &event); + static void InitConnectEventMap(); + private: + static void ConnectRadioButton(wxRadioButton *p, bool connect); + }; + }; // namespace gui +}; // namespace wxjs + +#endif //_WXJSRadioButton_H Property changes on: ps/trunk/source/tools/atlas/wxJS/gui/control/radiobtn.h ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/gui/control/toolbar.h =================================================================== --- ps/trunk/source/tools/atlas/wxJS/gui/control/toolbar.h (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/gui/control/toolbar.h (revision 5154) @@ -0,0 +1,114 @@ +/* + * wxJavaScript - toolbar.h + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: toolbar.h 698 2007-05-10 20:57:32Z fbraem $ + */ +#ifndef _WXJSToolBar_H +#define _WXJSToolBar_H + +namespace wxjs +{ + namespace gui + { + class ToolBar : public ApiWrapper + , public wxToolBar + { + public: + + ToolBar() : wxToolBar() + { + } + + virtual ~ToolBar() + { + ClearTools(); + } + + // Derived because the tool is rooted, and the tool must be unrooted + // before it is destroyed + virtual bool DoDeleteTool(size_t pos, wxToolBarToolBase *tool); + + static bool GetProperty(wxToolBar *p, + JSContext *cx, + JSObject *obj, + int id, + jsval *vp); + static bool SetProperty(wxToolBar *p, + JSContext *cx, + JSObject *obj, + int id, + jsval *vp); + + static wxToolBar* Construct(JSContext *cx, + JSObject *obj, + uintN argc, + jsval *argv, + bool constructing); + + WXJS_DECLARE_PROPERTY_MAP() + enum + { + P_TOOL_SIZE + , P_TOOL_BITMAP_SIZE + , P_MARGINS + , P_TOOL_PACKING + , P_TOOL_SEPARATION + }; + + WXJS_DECLARE_CONSTANT_MAP() + + WXJS_DECLARE_METHOD_MAP() + WXJS_DECLARE_METHOD(create) + WXJS_DECLARE_METHOD(addControl) + WXJS_DECLARE_METHOD(addSeparator) + WXJS_DECLARE_METHOD(addTool) + WXJS_DECLARE_METHOD(addCheckTool) + WXJS_DECLARE_METHOD(addRadioTool) + WXJS_DECLARE_METHOD(deleteTool) + WXJS_DECLARE_METHOD(deleteToolByPos) + WXJS_DECLARE_METHOD(enableTool) + WXJS_DECLARE_METHOD(findControl) + WXJS_DECLARE_METHOD(getToolEnabled) + WXJS_DECLARE_METHOD(getToolLongHelp) + WXJS_DECLARE_METHOD(getToolShortHelp) + WXJS_DECLARE_METHOD(getToolState) + WXJS_DECLARE_METHOD(insertControl) + WXJS_DECLARE_METHOD(insertSeparator) + WXJS_DECLARE_METHOD(insertTool) + WXJS_DECLARE_METHOD(realize) + WXJS_DECLARE_METHOD(setToolLongHelp) + WXJS_DECLARE_METHOD(setToolShortHelp) + WXJS_DECLARE_METHOD(toggleTool) + + }; + + class ToolEventHandler : public EventConnector + , public wxEvtHandler + { + public: + // Events + void OnTool(wxCommandEvent &event); + }; + }; // namespace gui +}; // namespace wxjs + +#endif //_WXJSToolBar_H Property changes on: ps/trunk/source/tools/atlas/wxJS/gui/control/toolbar.h ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/gui/control/window.cpp =================================================================== --- ps/trunk/source/tools/atlas/wxJS/gui/control/window.cpp (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/gui/control/window.cpp (revision 5154) @@ -0,0 +1,2446 @@ +#include "precompiled.h" + +/* + * wxJavaScript - window.cpp + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: window.cpp 733 2007-06-05 21:17:25Z fbraem $ + */ +// window.cpp + +#ifndef WX_PRECOMP + #include +#endif + +#include "../../common/main.h" + +#include "window.h" +#include "../misc/point.h" +#include "../misc/size.h" +#include "../misc/rect.h" +#include "../misc/colour.h" +#include "../misc/font.h" +#include "../misc/sizer.h" +#include "../misc/validate.h" +#include "../misc/acctable.h" + +using namespace wxjs; +using namespace wxjs::gui; + +/*** + * control/window + * gui + * + * wxWindow is the prototype of all objects based on wxWindow. + * This means that you can use all properties and methods in all those objects. + * + */ +WXJS_INIT_CLASS(Window, "wxWindow", 0) + +void Window::InitClass(JSContext* WXUNUSED(cx), JSObject* WXUNUSED(obj), JSObject* WXUNUSED(proto)) +{ + WindowEventHandler::InitConnectEventMap(); +} + +/*** + * + * + * + * Can this window have focus? + * + * + * can this window be given focus by keyboard navigation? if not, the + * only way to give it focus (provided it accepts it at all) is to + * click it + * + * + * Indicates whether the layout method must be called automatically or not when a window is resized. + * See @wxSizer + * + * + * Get/Set the background colour of the window + * + * + * Gets the size best suited for the window + * + * + * Gets a list of children + * + * + * Get the origin of the client area of the window relative to the + * window top left corner (the client area may be shifted because of + * the borders, scrollbars, other decorations...) + * + * + * Get/Set the client height. + * + * + * Gets the rectangle of the client area + * + * + * Get/Set the clientsize of the window. You can also use + * @wxRect (only when setting) + * + * + * Get/Set the client width. + * + * + * Enables/Disables the window + * + * + * Get/Set the extra window styles. + * See @wxWindow#extraStyles + * + * + * Get/Set the font. + * + * + * Get/Set the foreground colour of the window + * + * + * Returns true when this window has the capture. + * Set to true to capture this window, or false to release the capture. + * (not possible in wxWindows) + * + * + * Get/Set the height. + * + * + * Gets the unique id of the window, or -1 when it is not set. + * + * + * Get/Set the parent + * + * + * Get/Set the position. + * + * + * Gets the window rectangle + * + * + * Returns true when the window is visible + * See @wxWindow#visible property, @wxWindow#show method + * + * + * Get/Set the size of the window. You can also use + * @wxRect (only when setting) + * + * + * Get/Set the sizer of the window. Set @wxWindow#autoLayout to true when you + * want that the sizer is automatically used when the size of the window is changed. + * + * + * Returns true when the window is a top level window. + * Currently all frames and dialogs are considered to be + * top-level windows (even if they have a parent window). + * + * + * Get/Set the validator of the window + * + * + * Show/Hide the window. + * + * + * Get/Set the window flag styles. + * Please note that some styles cannot be changed after the window + * creation and that @wxWindow#refresh might be called after changing + * the others for the change to take place immediately. + * See @wxWindow#styles + * + * + */ +WXJS_BEGIN_PROPERTY_MAP(Window) + WXJS_PROPERTY(P_AUTO_LAYOUT, "autoLayout") + WXJS_PROPERTY(P_CLIENT_HEIGHT, "clientHeight") + WXJS_PROPERTY(P_CLIENT_WIDTH, "clientWidth") + WXJS_READONLY_PROPERTY(P_CLIENT_ORIGIN, "clientAreaOrigin") + WXJS_READONLY_PROPERTY(P_ACCEPTS_FOCUS, "acceptsFocus") + WXJS_READONLY_PROPERTY(P_ACCEPTS_FOCUS_KEYBOARD, "acceptsFocusFromKeyboard") + WXJS_PROPERTY(P_ENABLE, "enable") + WXJS_PROPERTY(P_HEIGHT, "height") + WXJS_PROPERTY(P_VISIBLE, "visible") + WXJS_PROPERTY(P_WIDTH, "width") + WXJS_PROPERTY(P_SIZE, "size") + WXJS_PROPERTY(P_SIZER, "sizer") + WXJS_PROPERTY(P_CLIENT_SIZE, "clientSize") + WXJS_PROPERTY(P_POSITION, "position") + WXJS_READONLY_PROPERTY(P_ID, "id") + WXJS_READONLY_PROPERTY(P_RECT, "rect") + WXJS_READONLY_PROPERTY(P_CLIENT_RECT, "clientRect") + WXJS_READONLY_PROPERTY(P_BEST_SIZE, "bestSize") + WXJS_PROPERTY(P_WINDOW_STYLE, "windowStyle") + WXJS_PROPERTY(P_EXTRA_STYLE, "extraStyle") + WXJS_READONLY_PROPERTY(P_SHOWN, "shown") + WXJS_READONLY_PROPERTY(P_TOP_LEVEL, "topLevel") + WXJS_READONLY_PROPERTY(P_CHILDREN, "children") + WXJS_PROPERTY(P_PARENT, "parent") + WXJS_PROPERTY(P_VALIDATOR, "validator") + WXJS_PROPERTY(P_ACCELERATOR_TABLE, "acceleratorTable") + WXJS_PROPERTY(P_HAS_CAPTURE, "hasCapture") + WXJS_PROPERTY(P_BACKGROUND_COLOUR, "backgroundColour") + WXJS_PROPERTY(P_FOREGROUND_COLOUR, "foregroundColour") + WXJS_PROPERTY(P_FONT, "font") +WXJS_END_PROPERTY_MAP() + +bool Window::GetProperty(wxWindow *p, JSContext *cx, JSObject *obj, int id, jsval *vp) +{ + switch (id) + { + case P_VISIBLE: + case P_SHOWN: + *vp = ToJS(cx, p->IsShown()); + break; + case P_ENABLE: + *vp = ToJS(cx, p->IsEnabled()); + break; + case P_SIZE: + *vp = Size::CreateObject(cx, new wxSize(p->GetSize())); + break; + case P_CLIENT_SIZE: + *vp = Size::CreateObject(cx, new wxSize(p->GetClientSize())); + break; + case P_WIDTH: + *vp = ToJS(cx, p->GetSize().GetWidth()); + break; + case P_HEIGHT: + *vp = ToJS(cx, p->GetSize().GetHeight()); + break; + case P_CLIENT_HEIGHT: + *vp = ToJS(cx, p->GetClientSize().GetHeight()); + break; + case P_CLIENT_WIDTH: + *vp = ToJS(cx, p->GetClientSize().GetHeight()); + break; + case P_POSITION: + *vp = Point::CreateObject(cx, new wxPoint(p->GetPosition())); + break; + case P_CLIENT_ORIGIN: + { + const wxPoint &pt = p->GetClientAreaOrigin(); + *vp = Point::CreateObject(cx, new wxPoint(pt)); + break; + } + case P_SIZER: + { + wxSizer *sizer = p->GetSizer(); + if ( sizer != NULL ) + { + JavaScriptClientData *data + = dynamic_cast(sizer->GetClientObject()); + if ( data != NULL ) + { + *vp = OBJECT_TO_JSVAL(data->GetObject()); + } + } + break; + } + case P_AUTO_LAYOUT: + *vp = ToJS(cx, p->GetAutoLayout()); + break; + case P_ID: + *vp = ToJS(cx, p->GetId()); + break; + case P_RECT: + *vp = Rect::CreateObject(cx, new wxRect(p->GetRect())); + break; + case P_CLIENT_RECT: + *vp = Rect::CreateObject(cx, new wxRect(p->GetClientRect())); + break; + case P_BEST_SIZE: + *vp = Size::CreateObject(cx, new wxSize(p->GetBestSize())); + break; + case P_WINDOW_STYLE: + *vp = ToJS(cx, p->GetWindowStyle()); + break; + case P_EXTRA_STYLE: + *vp = ToJS(cx, p->GetExtraStyle()); + break; + case P_TOP_LEVEL: + *vp = ToJS(cx, p->IsTopLevel()); + break; + case P_ACCEPTS_FOCUS: + *vp = ToJS(cx, p->AcceptsFocus()); + break; + case P_ACCEPTS_FOCUS_KEYBOARD: + *vp = ToJS(cx, p->AcceptsFocusFromKeyboard()); + break; + case P_CHILDREN: + { + wxWindowList &winList = p->GetChildren(); + jsint count = winList.GetCount(); + + JSObject *objSelections = JS_NewArrayObject(cx, count, NULL); + *vp = OBJECT_TO_JSVAL(objSelections); + + jsint i = 0; + for (wxWindowList::Node *node = winList.GetFirst(); node; node = node->GetNext() ) + { + wxWindow *win = dynamic_cast(node->GetData()); + if ( win ) + { + JavaScriptClientData *data + = dynamic_cast(win->GetClientObject()); + if ( data != NULL ) + { + jsval element = OBJECT_TO_JSVAL(data->GetObject()); + JS_SetElement(cx, objSelections, i++, &element); + } + } + } + break; + } + case P_PARENT: + { + wxWindow *win = p->GetParent(); + if ( win ) + { + JavaScriptClientData *data + = dynamic_cast(win->GetClientObject()); + if ( data != NULL ) + { + *vp = OBJECT_TO_JSVAL(data->GetObject()); + } + } + break; + } + case P_VALIDATOR: + { + wxValidator *val = p->GetValidator(); + if ( val ) + { + JavaScriptClientData *data + = dynamic_cast(val->GetClientObject()); + if ( data != NULL ) + { + *vp = OBJECT_TO_JSVAL(data->GetObject()); + } + } + break; + } + case P_HAS_CAPTURE: + *vp = ToJS(cx, p->HasCapture()); + break; + case P_BACKGROUND_COLOUR: + *vp = Colour::CreateObject(cx, new wxColour(p->GetBackgroundColour())); + break; + case P_FOREGROUND_COLOUR: + *vp = Colour::CreateObject(cx, new wxColour(p->GetForegroundColour())); + break; + case P_FONT: + *vp = Font::CreateObject(cx, new wxFont(p->GetFont()), obj); + break; + } + return true; +} + +bool Window::SetProperty(wxWindow *p, JSContext *cx, JSObject *obj, int id, jsval *vp) +{ + switch(id) + { + case P_ACCELERATOR_TABLE: + { + wxAcceleratorTable *table = AcceleratorTable::GetPrivate(cx, *vp); + if ( table != NULL ) + p->SetAcceleratorTable(*table); + break; + } + case P_VISIBLE: + { + bool visible; + if ( FromJS(cx, *vp, visible) ) + p->Show(visible); + break; + } + case P_ENABLE: + { + bool enable; + if ( FromJS(cx, *vp, enable) ) + p->Enable(enable); + break; + } + case P_WIDTH: + { + int size; + if ( FromJS(cx, *vp, size) ) + p->SetSize(size, -1); + break; + } + case P_HEIGHT: + { + int height; + if ( FromJS(cx, *vp, height) ) + p->SetSize(-1, height); + break; + } + case P_SIZE: + { + wxSize *size = Size::GetPrivate(cx, *vp); + if ( size != NULL ) + { + p->SetSize(*size); + } + else + { + // Try wxRect + wxRect *rect = Rect::GetPrivate(cx, *vp); + if ( rect != NULL ) + p->SetSize(*rect); + } + break; + } + case P_SIZER: + { + wxSizer *sizer = Sizer::GetPrivate(cx, *vp); + if ( sizer != NULL ) + { + p->SetSizer(sizer); + JavaScriptClientData *data + = dynamic_cast(sizer->GetClientObject()); + if ( data != NULL ) + { + data->Protect(true); + data->SetOwner(false); + } + } + break; + } + case P_CLIENT_HEIGHT: + { + int size; + if ( FromJS(cx, *vp, size) ) + p->SetClientSize(-1, size); + break; + } + case P_CLIENT_WIDTH: + { + int size; + if ( FromJS(cx, *vp, size) ) + p->SetClientSize(size, -1); + break; + } + case P_CLIENT_SIZE: + { + wxSize *size = Size::GetPrivate(cx, *vp); + if ( size != NULL ) + { + p->SetClientSize(*size); + } + else + { + // Try wxRect + wxRect *rect = Rect::GetPrivate(cx, *vp); + if ( rect != NULL ) + p->SetClientSize(*rect); + } + break; + } + case P_POSITION: + { + wxPoint *pt = Point::GetPrivate(cx, *vp); + if ( pt != NULL ) + p->Move(*pt); + } + break; + case P_AUTO_LAYOUT: + { + bool autoLayout; + if ( FromJS(cx, *vp, autoLayout) ) + p->SetAutoLayout(autoLayout); + break; + } + case P_WINDOW_STYLE: + { + int style; + if ( FromJS(cx, *vp, style) ) + p->SetWindowStyle(style); + break; + } + case P_EXTRA_STYLE: + { + int style; + if ( FromJS(cx, *vp, style) ) + p->SetExtraStyle(style); + break; + } + case P_PARENT: + { + wxWindow *win = Window::GetPrivate(cx, *vp); + if ( win != NULL ) + { + p->Reparent(win); + } + } + case P_VALIDATOR: + { + wxValidator *val = Validator::GetPrivate(cx, *vp); + if ( val != NULL ) + { + val->SetClientObject(new JavaScriptClientData(cx, JSVAL_TO_OBJECT(*vp), true, true)); + p->SetValidator(*val); + val->SetWindow(p); // We do this, because otherwise we loose the knowledge + // of WindowObject + } + break; + } + case P_HAS_CAPTURE: + { + bool capture; + if ( FromJS(cx, *vp, capture) ) + capture ? p->CaptureMouse() : p->ReleaseMouse(); + break; + } + case P_BACKGROUND_COLOUR: + { + wxColour *colour = Colour::GetPrivate(cx, *vp); + if ( colour != NULL ) + p->SetBackgroundColour(*colour); + break; + } + case P_FOREGROUND_COLOUR: + { + wxColour *colour = Colour::GetPrivate(cx, *vp); + if ( colour != NULL ) + p->SetForegroundColour(*colour); + break; + } + case P_FONT: + { + wxFont *font = Font::GetPrivate(cx, *vp); + if ( font != NULL ) + p->SetFont(*font); + break; + } + } + return true; +} + +/*** + * + * + * Gets the window that has the capture. + * See @wxWindow#hasCapture, @wxWindow#releaseMouse and @wxWindow#captureMouse + * + * + */ +WXJS_BEGIN_STATIC_PROPERTY_MAP(Window) + WXJS_READONLY_STATIC_PROPERTY(P_CAPTURE, "capture") +WXJS_END_PROPERTY_MAP() + +bool Window::GetStaticProperty(JSContext *cx, int id, jsval *vp) +{ + if ( id == P_CAPTURE ) + { + wxWindow *win = wxWindow::GetCapture(); + if ( win != NULL ) + { + JavaScriptClientData *data + = dynamic_cast(win->GetClientObject()); + if ( data != NULL ) + { + *vp = OBJECT_TO_JSVAL(data->GetObject()); + } + } + } + return true; +} + +/*** + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * TransferDataTo/FromWindow() and Validate() methods will recursively descend + * into all children of the window if it has this style flag set. + * + * + * Normally, the command events are propagared upwards to the window parent recursively + * until a handler for them is found. Using this style allows to prevent them from being + * propagated beyond this window. Notice that wxDialog has this style on by default for + * the reasons explained in the event processing overview. + * + * + * This can be used to prevent a window from being used as an implicit parent for the + * dialogs which were created without a parent. It is useful for the windows which can + * disappear at any moment as creating childs of such windows results in fatal problems. + * + * + * + * + * Use internally-calculated width if -1 + * + * + * Use internally-calculated height if -1 + * + * + * Use internally-calculated width and height if each is -1 + * + * + * Ignore missing (-1) dimensions (use existing). + * + * + * Allow -1 as a valid position + * + * + * Don't do parent client adjustments (for implementation only) + * + * + * + */ + +WXJS_BEGIN_CONSTANT_MAP(Window) + WXJS_CONSTANT(wx, DOUBLE_BORDER) + WXJS_CONSTANT(wx, SUNKEN_BORDER) + WXJS_CONSTANT(wx, RAISED_BORDER) + WXJS_CONSTANT(wx, BORDER) + WXJS_CONSTANT(wx, SIMPLE_BORDER) + WXJS_CONSTANT(wx, STATIC_BORDER) + WXJS_CONSTANT(wx, NO_BORDER) + WXJS_CONSTANT(wx, NO_3D) + WXJS_CONSTANT(wx, CLIP_CHILDREN) + WXJS_CONSTANT(wx, TAB_TRAVERSAL) + WXJS_CONSTANT(wx, WANTS_CHARS) + WXJS_CONSTANT(wx, NO_FULL_REPAINT_ON_RESIZE) + WXJS_CONSTANT(wx, VSCROLL) + WXJS_CONSTANT(wx, HSCROLL) + WXJS_CONSTANT(wx, SIZE_AUTO_WIDTH) + WXJS_CONSTANT(wx, SIZE_AUTO_HEIGHT) + WXJS_CONSTANT(wx, SIZE_AUTO) + WXJS_CONSTANT(wx, SIZE_USE_EXISTING) + WXJS_CONSTANT(wx, SIZE_ALLOW_MINUS_ONE) + WXJS_CONSTANT(wx, SIZE_NO_ADJUSTMENTS) + WXJS_CONSTANT(wx, WS_EX_VALIDATE_RECURSIVELY) + WXJS_CONSTANT(wx, WS_EX_BLOCK_EVENTS) + WXJS_CONSTANT(wx, WS_EX_TRANSIENT) +WXJS_END_CONSTANT_MAP() + +WXJS_BEGIN_METHOD_MAP(Window) + WXJS_METHOD("captureMouse", captureMouse, 0) + WXJS_METHOD("centre", centre, 1) + WXJS_METHOD("center", centre, 1) + WXJS_METHOD("clearBackground", clearBackground, 0) + WXJS_METHOD("clientToScreen", clientToScreen, 1) + WXJS_METHOD("close", close, 1) + WXJS_METHOD("convertDialogToPixels", convertDialogToPixels, 1) + WXJS_METHOD("convertPixelsToDialog", convertPixelsToDialog, 1) + WXJS_METHOD("destroy", destroy, 0) + WXJS_METHOD("releaseMouse", releaseMouse, 0) + WXJS_METHOD("layout", layout, 0) + WXJS_METHOD("move", move, 2) + WXJS_METHOD("lower", lower, 0) + WXJS_METHOD("raise", raise, 0) + WXJS_METHOD("centreOnParent", centreOnParent, 1) + WXJS_METHOD("centerOnParent", centreOnParent, 1) + WXJS_METHOD("show", show, 1) + WXJS_METHOD("fit", fit, 0) + WXJS_METHOD("setSizeHints", setSizeHints, 6) + WXJS_METHOD("refresh", refresh, 2) + WXJS_METHOD("setFocus", setFocus, 0) + WXJS_METHOD("findWindow", findWindow, 1) + WXJS_METHOD("initDialog", initDialog, 0) + WXJS_METHOD("transferDataToWindow", transferDataToWindow, 0) + WXJS_METHOD("transferDataFromWindow", transferDataFromWindow, 0) + WXJS_METHOD("validate", validate, 0) + WXJS_METHOD("makeModal", makeModal, 1) + WXJS_METHOD("warpPointer", warpPointer, 1) + WXJS_METHOD("update", update, 0) + WXJS_METHOD("freeze", freeze, 0) + WXJS_METHOD("thaw", thaw, 0) +WXJS_END_METHOD_MAP() + +/*** + * + * + * + * Directs all mouse input to this window. Call @wxWindow#releaseMouse to release the capture. + * See @wxWindow#hasCapture + * + * + */ +JSBool Window::captureMouse(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxWindow *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + p->CaptureMouse(); + + return JS_TRUE; +} + +/*** + * + * + * + * You can use the constants from @wxOrientation + * + * + * + */ +JSBool Window::centre(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxWindow *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + if ( argc == 0 ) + { + p->Centre(); + } + else if (argc == 1) + { + int direction; + if ( FromJS(cx, argv[0], direction) ) + { + p->Centre(direction); + } + else + { + return JS_FALSE; + } + } + else + { + return JS_FALSE; + } + + return JS_TRUE; +} + +/*** + * + * + * + * Clears the window by filling it with the current background color. + * + * + */ +JSBool Window::clearBackground(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxWindow *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + p->ClearBackground(); + + return JS_TRUE; +} + +/*** + * + * + * + * The client position + * + * + * + * Returns the screen coordinates from coordinates relative to this window. + * + * + */ +JSBool Window::clientToScreen(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxWindow *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + wxPoint *pt = Point::GetPrivate(cx, argv[0]); + if ( pt != NULL ) + *rval = Point::CreateObject(cx, new wxPoint(p->ClientToScreen(*pt))); + else + return JS_FALSE; + + return JS_TRUE; +} + +/*** + * + * + * + * When true the application can't veto the close. By default Force is false. + * + * + * + * Closes the window. This applies only for @wxFrame and @wxDialog objects. + * + * + */ +JSBool Window::close(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxWindow *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + if ( argc == 1 ) + { + bool force = false; + if ( FromJS(cx, argv[0], force) ) + { + p->Close(force); + return JS_TRUE; + } + else + { + return JS_FALSE; + } + } + else if ( argc == 0 ) + { + p->Close(); + return JS_TRUE; + } + + return JS_FALSE; +} + +/*** + * + * + * Converts a point + * + * + * + * Converts a size + * + * + * + * Converts a point or a size to from dialog units to pixels. + * + * + */ +JSBool Window::convertDialogToPixels(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxWindow *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + JSBool result = JS_FALSE; + + wxSize *size = Size::GetPrivate(cx, argv[0]); + if ( size != NULL ) + { + *rval = Size::CreateObject(cx, new wxSize(p->ConvertDialogToPixels(*size))); + return JS_TRUE; + } + else + { + wxPoint *pt = Point::GetPrivate(cx, argv[0]); + if ( pt != NULL ) + { + *rval = Point::CreateObject(cx, new wxPoint(p->ConvertDialogToPixels(*pt))); + result = JS_TRUE; + } + } + + return result; +} + +/*** + * + * + * Converts a point + * + * + * + * Converts a size + * + * + * + * Converts a point or a size from pixels to dialog units. + * + * + */ +JSBool Window::convertPixelsToDialog(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxWindow *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + JSBool result = JS_FALSE; + + wxSize *size = Size::GetPrivate(cx, argv[0]); + if ( size != NULL ) + { + *rval = Size::CreateObject(cx, new wxSize(p->ConvertPixelsToDialog(*size))); + result = JS_TRUE; + } + else + { + wxPoint *pt = Point::GetPrivate(cx, argv[0]); + if ( pt != NULL ) + { + *rval = Point::CreateObject(cx, new wxPoint(p->ConvertPixelsToDialog(*pt))); + result = JS_TRUE; + } + } + + return result; +} + +/*** + * + * + * + * Destroys the window. Returns true when the window is destroyed. + * + * + */ +JSBool Window::destroy(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxWindow *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + *rval = ToJS(cx, p->Destroy()); + + return JS_TRUE; +} + +/*** + * + * + * + * Releases mouse input captured by @wxWindow#captureMouse. + * See @wxWindow#hasCapture and @wxWindow#captureMouse + * + * + */ +JSBool Window::releaseMouse(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxWindow *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + p->ReleaseMouse(); + + return JS_TRUE; +} + +/*** + * + * + * + * + * + * + * + * + * + * Moves the mouse to the given position + * + * + */ +JSBool Window::warpPointer(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxWindow *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + if ( argc == 1 ) + { + wxPoint *pt = Point::GetPrivate(cx, argv[0]); + if ( pt != NULL ) + { + p->WarpPointer(pt->x, pt->y); + return JS_TRUE; + } + } + else if ( argc == 2 ) + { + int x = 0; + int y = 0; + if ( FromJS(cx, argv[0], x) + || FromJS(cx, argv[1], y) ) + { + p->WarpPointer(x, y); + return JS_TRUE; + } + } + + return JS_FALSE; +} + +/*** + * + * + * + * Layout the window using the sizer. + * + * + */ +JSBool Window::layout(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxWindow *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + p->Layout(); + + return JS_TRUE; +} + +/*** + * + * + * + * + * + * + * + * + * + * Moves the window. + * + * + */ +JSBool Window::move(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxWindow *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + if ( argc > 2 ) + argc = 2; + + JSBool result = JS_FALSE; + + switch(argc) + { + case 2: + { + int x; + int y; + if ( FromJS(cx, argv[0], x) + && FromJS(cx, argv[1], y) ) + { + p->Move(x, y); + result = JS_TRUE; + } + break; + } + case 1: + { + wxPoint *pt = Point::GetPrivate(cx, argv[0]); + if ( pt == NULL ) + { + p->Move(*pt); + result = JS_TRUE; + } + break; + } + } + + return result; +} + +/*** + * + * + * + * X position in pixels, or -1 to indicate that the existing value should be used. + * + * + * Y position in pixels, or -1 to indicate that the existing value should be used. + * + * + * Width in pixels, or -1 to indicate that the existing value should be used. + * + * + * Height in pixels, or -1 to indicate that the existing value should be used. + * + * + * Indicates the interpretation of the parameters. + * + * + * + * + * Width in pixels, or -1 to indicate that the existing value should be used. + * + * + * Height in pixels, or -1 to indicate that the existing value should be used. + * + * + * + * Sets a new window size. + * See @wxWindow#size property, @wxWindow#sizeFlags + * + * + */ +JSBool Window::setSize(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxWindow *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + JSBool result = JS_FALSE; + + int x; + int y; + int width; + int height; + int flag = wxSIZE_AUTO; + + if ( argc == 2 ) + { + if ( FromJS(cx, argv[0], width) + && FromJS(cx, argv[1], height) ) + { + p->SetSize(width, height); + result = JS_TRUE; + } + } + else if ( argc > 3 ) + { + if ( FromJS(cx, argv[0], x) + && FromJS(cx, argv[1], y) + && FromJS(cx, argv[2], width) + && FromJS(cx, argv[3], height) ) + { + if ( argc > 4 + && ! FromJS(cx, argv[4], flag) ) + { + return JS_FALSE; + } + p->SetSize(x, y, width, height, flag); + result = JS_TRUE; + } + } + + return result; +} + +/*** + * + * + * + * Raises the window to the top of the window hierarchy if it is a managed window (dialog or frame). + * + * + */ +JSBool Window::raise(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxWindow *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + p->Raise(); + + return JS_TRUE; +} + +/*** + * + * + * + * Lowers the window to the bottom of the window hierarchy if it is a managed window (dialog or frame). + * + * + */ +JSBool Window::lower(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxWindow *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + p->Lower(); + + return JS_TRUE; +} + +/*** + * + * + * + * + * + * Centres the window based on the parent. centreOnParent is an alias for this method. + * + * + */ +JSBool Window::centreOnParent(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxWindow *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + if ( argc == 0 ) + { + p->CentreOnParent(); + } + else + { + int direction; + if ( FromJS(cx, argv[0], direction) ) + { + p->CentreOnParent(direction); + } + else + { + return JS_FALSE; + } + } + return JS_TRUE; +} + +/*** + * + * + * + * Set window size to wrap around its children + * + * + */ +JSBool Window::fit(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxWindow *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + p->Fit(); + + return JS_TRUE; +} + +/*** + * + * + * + * The minimum width of the window. + * + * + * The minimum height of the window. + * + * + * The maximum width of the window. + * + * + * The maximum height of the window. + * + * + * The increment for resizing the width (Motif/Xt only). + * + * + * The increment for resizing the height (Motif/Xt only). + * + * + * + * Allows specification of minimum and maximum window sizes, and window size increments. + * If a pair of values is not set (or set to -1), the default values will be used. + * If this function is called, the user will not be able to size the window + * outside the given bounds. + *

+ * The resizing increments are only significant under Motif or Xt. + *
+ *
+ */ +JSBool Window::setSizeHints(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxWindow *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + int minWidth = -1; + int minHeight = -1; + int maxWidth = -1; + int maxHeight = -1; + int incWidth = -1; + int incHeight = -1; + + if ( JS_ConvertArguments(cx, argc, argv, "/iiiiii", + &minWidth, &minHeight, &maxWidth, + &maxHeight, &incWidth, &incHeight) == JS_TRUE ) + { + p->SetSizeHints(minWidth, minHeight, maxWidth, maxHeight, incWidth, incHeight); + } + else + return JS_FALSE; + + return JS_TRUE; +} + +/*** + * + * + * + * + * + * Shows (true) or hides (false) the window. + * See @wxWindow#visible property, @wxWindow#shown property + * + * + */ +JSBool Window::show(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxWindow *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + if ( argc == 0 ) + p->Show(); + else + { + bool visible; + if ( FromJS(cx, argv[0], visible) ) + p->Show(visible); + else + return JS_FALSE; + } + + return JS_TRUE; +} + +/*** + * + * + * + * When true the background is erased. + * + * + * When set, the given rectangle will be treated as damaged. + * + * + * + * Generates an event for repainting the window + * + * + */ +JSBool Window::refresh(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxWindow *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + bool erase = true; + wxRect *rect = NULL; + + if ( argc > 2 ) + argc = 2; + + switch(argc) + { + case 2: + rect = Rect::GetPrivate(cx, argv[1]); + if ( rect == NULL ) + break; + // Fall Through + case 1: + if ( ! FromJS(cx, argv[0], erase) ) + break; + // Fall Through + default: + p->Refresh(erase, rect); + return JS_TRUE; + } + + return JS_FALSE; +} + +/*** + * + * + * + * This sets the window to receive keyboard input. + * + * + */ +JSBool Window::setFocus(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxWindow *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + p->SetFocus(); + + return JS_TRUE; +} + +/*** + * + * + * The id of a window + * + * + * The name of a window + * + * + * Find a child of this window, by identifier or by name + * + * + */ +JSBool Window::findWindow(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxWindow *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + wxWindow *win; + int id; + if ( FromJS(cx, argv[0], id) ) + { + win = p->FindWindow(id); + } + else + { + wxString name; + FromJS(cx, argv[0], name); + win = p->FindWindow(name); + } + if ( win == (wxWindow*) NULL ) + { + *rval = JSVAL_VOID; + } + else + { + JavaScriptClientData *data + = dynamic_cast(win->GetClientObject()); + if ( data == NULL ) + { + *rval = JSVAL_VOID; + } + else + { + *rval = OBJECT_TO_JSVAL(data->GetObject()); + } + } + + return JS_TRUE; + +} + +/*** + * + * + * + * Sends an onInitDialog event, which in turn transfers data to the dialog via validators + * + * + */ +JSBool Window::initDialog(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxWindow *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + p->InitDialog(); + + return JS_TRUE; +} + +/*** + * + * + * + * Transfers values to child controls from data areas specified by their validators + * Returns FALSE if a transfer failed. + * + * + */ +JSBool Window::transferDataToWindow(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxWindow *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + *rval = ToJS(cx, p->TransferDataToWindow()); + + return JS_TRUE; +} + +/*** + * + * + * + * Transfers values from child controls to data areas specified by their validators. + * Returns false if a transfer failed. + * + * + */ +JSBool Window::transferDataFromWindow(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxWindow *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + *rval = ToJS(cx, p->TransferDataToWindow()); + + return JS_TRUE; +} + +/*** + * + * + * + * Validates the current values of the child controls using their validators. + * + * + */ +JSBool Window::validate(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxWindow *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + *rval = ToJS(cx, p->Validate()); + + return JS_TRUE; +} + +/*** + * + * + * + * + * + * Make modal or not. + * When flag is true, all other windows are disabled. + * + * + */ +JSBool Window::makeModal(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxWindow *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + if ( argc == 1 ) + { + bool flag; + if ( FromJS(cx, argv[0], flag) ) + { + p->MakeModal(flag); + } + else + { + return JS_FALSE; + } + } + else + p->MakeModal(); + + return JS_TRUE; +} + +/*** + * + * + * + * Repaint all invalid areas of the window immediately + * + * + */ +JSBool Window::update(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxWindow *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + p->Update(); + + return JS_TRUE; +} + +/*** + * + * + * + * Freeze the window: don't redraw it until it is thawed + * See @wxWindow#thaw + * + * + */ +JSBool Window::freeze(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxWindow *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + p->Freeze(); + + return JS_TRUE; +} + +/*** + * + * + * + * Thaw the window: redraw it after it had been frozen. + * See @wxWindow#freeze + * + * + */ +JSBool Window::thaw(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxWindow *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + p->Thaw(); + + return JS_TRUE; +} + +WXJS_BEGIN_STATIC_METHOD_MAP(Window) + WXJS_METHOD("findFocus", findFocus, 0) + WXJS_METHOD("findWindowById", findWindowById, 1) + WXJS_METHOD("findWindowByLabel", findWindowByLabel, 1) +WXJS_END_METHOD_MAP() + +/*** + * + * + * + * Finds the window or control which currently has the keyboard focus + * + * + */ +JSBool Window::findFocus(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxWindow *win = wxWindow::FindFocus(); + if ( win == NULL ) + { + *rval = JSVAL_VOID; + } + else + { + JavaScriptClientData *data + = dynamic_cast(win->GetClientObject()); + if ( data == NULL ) + { + *rval = JSVAL_VOID; + } + else + { + *rval = OBJECT_TO_JSVAL(data->GetObject()); + } + } + return JS_TRUE; +} + +/*** + * + * + * The id of a window + * + * + * Find a window by identifier + * + * + */ +JSBool Window::findWindowById(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + int id; + if ( FromJS(cx, argv[0], id) ) + { + wxWindow *win = wxWindow::FindWindowById(id); + if ( win == (wxWindow*) NULL ) + { + *rval = JSVAL_VOID; + } + else + { + JavaScriptClientData *data + = dynamic_cast(win->GetClientObject()); + if ( data == NULL ) + { + *rval = JSVAL_VOID; + } + else + { + *rval = OBJECT_TO_JSVAL(data->GetObject()); + } + } + } + return JS_TRUE; +} + +/*** + * + * + * The label of a window + * + * + * Find a window by label + * + * + */ +JSBool Window::findWindowByLabel(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxString label; + if ( FromJS(cx, argv[0], label) ) + { + wxWindow *win = wxWindow::FindWindowByLabel(label); + if ( win == (wxWindow*) NULL ) + { + *rval = JSVAL_VOID; + } + else + { + JavaScriptClientData *data + = dynamic_cast(win->GetClientObject()); + if ( data == NULL ) + { + *rval = JSVAL_VOID; + } + else + { + *rval = OBJECT_TO_JSVAL(data->GetObject()); + } + } + } + + return JS_TRUE; +} + +/*** + * + * + * Called when the window is activated/disactivated. The function + * gets a @wxActivateEvent as argument. + * + * + * Called when the user enters a character. The function + * gets a @wxKeyEvent object as argument. + * + * + * This event is triggered to allow the window to intercept keyboard events before they are + * processed by child windows. The function gets a @wxKeyEvent as argument. + * + * + * Called when the user has pressed a key, before it is translated into an + * ASCII value using other modifier keys that might be pressed at the same time. + * The function gets a @wxKeyEvent object as argument. + * + * + * Called when the user has released the key. + * The function gets a @wxKeyEvent object as argument. + * + * + * Called when the window gets the focus. + * The function gets a @wxFocusEvent object as argument. + * + * + * Called when the window looses the focus. + * The function gets a @wxFocusEvent object as argument. + * + * + * Used for handling all the mouse events. The function + * gets a @wxMouseEvent as argument. + * + * + * Event triggered when the mouse enters the window. The function + * gets a @wxMouseEvent as argument. + * Under Windows mouse enter and leave events are not natively supported by the + * system but are generated by wxWindows itself. This has several drawbacks: + * the @wxWindow#onLeaveWindow event might be received some time after the mouse left + * the window and the state variables for it may have changed during this time. + * See @wxWindow#onLeaveWindow + * + * + * Event triggered when the mouse leaves the window. The function + * gets a @wxMouseEvent as argument. + * Under Windows mouse enter and leave events are not natively supported by the + * system but are generated by wxWindows itself. This has several drawbacks: + * the onLeaveWindow event might be received some time after the mouse left + * the window and the state variables for it may have changed during this time. + * See @wxWindow#onEnterWindow + * + * + * Event triggered when the left button is pressed. The function + * gets a @wxMouseEvent as argument. + * + * + * Event triggered when the left button is released. The function + * gets a @wxMouseEvent as argument. + * + * + * Event triggered when the left button is double clicked. The function + * gets a @wxMouseEvent as argument. + * + * + * Event triggered when the middle button is pressed. The function + * gets a @wxMouseEvent as argument. + * + * + * Event triggered when the middle button is released. The function + * gets a @wxMouseEvent as argument. + * + * + * Event triggered when the middle button is double clicked. The function + * gets a @wxMouseEvent as argument. + * + * + * Event triggered when the right button is pressed. The function + * gets a @wxMouseEvent as argument. + * + * + * Event triggered when the right button is released. The function + * gets a @wxMouseEvent as argument. + * + * + * Event triggered when the right button is double clicked. The function + * gets a @wxMouseEvent as argument. + * + * + * Event triggered when the mouse is moved. The function + * gets a @wxMouseEvent as argument. + * + * + * Event triggered when the mousewheel is used. The function + * gets a @wxMouseEvent as argument. + * + * + * Called when the window is moved. The function gets a @wxMoveEvent as argument. + * + * + * Called when the window is resized. The function gets a @wxSizeEvent as argument. + * + * + * Catch all scroll commands. The argument of the function is a @wxScrollWinEvent. + * + * + * Catch a command to put the scroll thumb at the maximum position. + * The argument of the function is a @wxScrollWinEvent. + * + * + * Catch a command to put the scroll thumb at the maximum position. + * The argument of the function is a @wxScrollWinEvent. + * + * + * Catch a line up command. + * The argument of the function is a @wxScrollWinEvent. + * + * + * Catch a line down command. + * The argument of the function is a @wxScrollWinEvent. + * + * + * Catch a page up command. + * The argument of the function is a @wxScrollWinEvent. + * + * + * Catch a page down command. + * The argument of the function is a @wxScrollWinEvent. + * + * + * Catch a thumbtrack command (continuous movement of the scroll thumb). + * The argument of the function is a @wxScrollWinEvent. + * + * + * Catch a thumbtrack release command. + * The argument of the function is a @wxScrollWinEvent. + * + * + * Triggered when the user pressed F1 (on Windows) or + * when the user requested context-sensitive help. + * The argument of the function is a @wxHelpEvent. + * See @wxContextHelp, @wxHelpEvent and @wxContextHelpButton + * + * +*/ + +#include "../event/jsevent.h" +#include "../event/key.h" +#include "../event/activate.h" +#include "../event/mouse.h" +#include "../event/move.h" +#include "../event/sizeevt.h" +#include "../event/help.h" +#include "../event/scrollwin.h" + +WXJS_INIT_EVENT_MAP(wxWindow) +const wxString WXJS_SETFOCUS_EVENT(wxT("onSetFocus")); +const wxString WXJS_CHAR_EVENT(wxT("onChar")); +const wxString WXJS_CHAR_HOOK_EVENT(wxT("onCharHook")); +const wxString WXJS_KEY_DOWN_EVENT(wxT("onKeyDown")); +const wxString WXJS_KEY_UP_EVENT(wxT("onKeyUp")); +const wxString WXJS_ACTIVATE_EVENT(wxT("onActivate")); +const wxString WXJS_SET_FOCUS_EVENT(wxT("onSetFocus")); +const wxString WXJS_KILL_FOCUS_EVENT(wxT("onKillFocus")); +const wxString WXJS_LEFT_DOWN_EVENT(wxT("onLeftDown")); +const wxString WXJS_LEFT_UP_EVENT(wxT("onLeftUp")); +const wxString WXJS_LEFT_DCLICK_EVENT(wxT("onLeftDClick")); +const wxString WXJS_MIDDLE_DOWN_EVENT(wxT("onMiddleDown")); +const wxString WXJS_MIDDLE_UP_EVENT(wxT("onMiddleUp")); +const wxString WXJS_MIDDLE_DCLICK_EVENT(wxT("onMiddleDClick")); +const wxString WXJS_RIGHT_DOWN_EVENT(wxT("onRightDown")); +const wxString WXJS_RIGHT_UP_EVENT(wxT("onRightUp")); +const wxString WXJS_RIGHT_DCLICK_EVENT(wxT("onRightDClick")); +const wxString WXJS_MOTION_EVENT(wxT("onMotion")); +const wxString WXJS_ENTER_WINDOW_EVENT(wxT("onEnterWindow")); +const wxString WXJS_LEAVE_WINDOW_EVENT(wxT("onLeaveWindow")); +const wxString WXJS_MOUSE_WHEEL_EVENT(wxT("onMouseWheel")); +const wxString WXJS_MOVE_EVENT(wxT("onMove")); +const wxString WXJS_SIZE_EVENT(wxT("onSize")); +const wxString WXJS_SCROLL_EVENT(wxT("onScroll")); +const wxString WXJS_SCROLL_TOP_EVENT(wxT("onScrollTop")); +const wxString WXJS_SCROLL_BOTTOM_EVENT(wxT("onScrollBottom")); +const wxString WXJS_SCROLL_LINEUP_EVENT(wxT("onScrollLineUp")); +const wxString WXJS_SCROLL_LINEDOWN_EVENT(wxT("onScrollLineDown")); +const wxString WXJS_SCROLL_PAGEUP_EVENT(wxT("onScrollPageUp")); +const wxString WXJS_SCROLL_PAGEDOWN_EVENT(wxT("onScrollPageDown")); +const wxString WXJS_SCROLL_THUMBTRACK_EVENT(wxT("onScrollThumbtrack")); +const wxString WXJS_SCROLL_THUMBRELEASE(wxT("onScrollThumbRelease")); +const wxString WXJS_HELP_EVENT(wxT("onHelp")); + +void WindowEventHandler::OnChar(wxKeyEvent &event) +{ + PrivKeyEvent::Fire(event, WXJS_CHAR_EVENT); +} +void WindowEventHandler::OnCharHook(wxKeyEvent &event) +{ + PrivKeyEvent::Fire(event, WXJS_CHAR_HOOK_EVENT); +} +void WindowEventHandler::OnKeyDown(wxKeyEvent &event) +{ + PrivKeyEvent::Fire(event, WXJS_KEY_DOWN_EVENT); +} +void WindowEventHandler::OnKeyUp(wxKeyEvent &event) +{ + PrivKeyEvent::Fire(event, WXJS_KEY_UP_EVENT); +} +void WindowEventHandler::OnActivate(wxActivateEvent &event) +{ + PrivActivateEvent::Fire(event, WXJS_ACTIVATE_EVENT); +} + +void WindowEventHandler::OnSetFocus(wxFocusEvent &event) +{ + PrivFocusEvent::Fire(event, WXJS_SET_FOCUS_EVENT); +} + +void WindowEventHandler::OnKillFocus(wxFocusEvent &event) +{ + PrivFocusEvent::Fire(event, WXJS_KILL_FOCUS_EVENT); +} + +void WindowEventHandler::OnLeftDown(wxMouseEvent &event) +{ + PrivMouseEvent::Fire(event, WXJS_LEFT_DOWN_EVENT); +} + +void WindowEventHandler::OnLeftUp(wxMouseEvent &event) +{ + PrivMouseEvent::Fire(event, WXJS_LEFT_UP_EVENT); +} + +void WindowEventHandler::OnLeftDClick(wxMouseEvent &event) +{ + PrivMouseEvent::Fire(event, WXJS_LEFT_DCLICK_EVENT); +} + +void WindowEventHandler::OnMiddleDown(wxMouseEvent &event) +{ + PrivMouseEvent::Fire(event, WXJS_MIDDLE_DOWN_EVENT); +} + +void WindowEventHandler::OnMiddleUp(wxMouseEvent &event) +{ + PrivMouseEvent::Fire(event, WXJS_MIDDLE_UP_EVENT); +} + +void WindowEventHandler::OnMiddleDClick(wxMouseEvent &event) +{ + PrivMouseEvent::Fire(event, WXJS_MIDDLE_DCLICK_EVENT); +} + +void WindowEventHandler::OnRightDown(wxMouseEvent &event) +{ + PrivMouseEvent::Fire(event, WXJS_RIGHT_DOWN_EVENT); +} + +void WindowEventHandler::OnRightUp(wxMouseEvent &event) +{ + PrivMouseEvent::Fire(event, WXJS_RIGHT_UP_EVENT); +} + +void WindowEventHandler::OnRightDClick(wxMouseEvent &event) +{ + PrivMouseEvent::Fire(event, WXJS_RIGHT_DCLICK_EVENT); +} + +void WindowEventHandler::OnMotion(wxMouseEvent &event) +{ + PrivMouseEvent::Fire(event, WXJS_MOTION_EVENT); +} + +void WindowEventHandler::OnEnterWindow(wxMouseEvent &event) +{ + PrivMouseEvent::Fire(event, WXJS_ENTER_WINDOW_EVENT); +} + +void WindowEventHandler::OnLeaveWindow(wxMouseEvent &event) +{ + PrivMouseEvent::Fire(event, WXJS_LEAVE_WINDOW_EVENT); +} + +void WindowEventHandler::OnMouseWheel(wxMouseEvent &event) +{ + PrivMouseEvent::Fire(event, WXJS_MOUSE_WHEEL_EVENT); +} + +void WindowEventHandler::OnMove(wxMoveEvent &event) +{ + PrivMoveEvent::Fire(event, WXJS_MOVE_EVENT); +} +void WindowEventHandler::OnSize(wxSizeEvent &event) +{ + PrivSizeEvent::Fire(event, WXJS_SIZE_EVENT); +} +void WindowEventHandler::OnScrollTop(wxScrollWinEvent& event) +{ + PrivScrollWinEvent::Fire(event, WXJS_SCROLL_TOP_EVENT); +} +void WindowEventHandler::OnScrollBottom(wxScrollWinEvent& event) +{ + PrivScrollWinEvent::Fire(event, WXJS_SCROLL_BOTTOM_EVENT); +} +void WindowEventHandler::OnScrollLineUp(wxScrollWinEvent& event) +{ + PrivScrollWinEvent::Fire(event, WXJS_SCROLL_LINEUP_EVENT); +} +void WindowEventHandler::OnScrollLineDown(wxScrollWinEvent& event) +{ + PrivScrollWinEvent::Fire(event, WXJS_SCROLL_LINEDOWN_EVENT); +} +void WindowEventHandler::OnScrollPageUp(wxScrollWinEvent& event) +{ + PrivScrollWinEvent::Fire(event, WXJS_SCROLL_PAGEUP_EVENT); +} +void WindowEventHandler::OnScrollPageDown(wxScrollWinEvent& event) +{ + PrivScrollWinEvent::Fire(event, WXJS_SCROLL_PAGEDOWN_EVENT); +} +void WindowEventHandler::OnScrollThumbTrack(wxScrollWinEvent& event) +{ + PrivScrollWinEvent::Fire(event, WXJS_SCROLL_THUMBTRACK_EVENT); +} +void WindowEventHandler::OnScrollThumbRelease(wxScrollWinEvent& event) +{ + PrivScrollWinEvent::Fire(event, WXJS_SCROLL_THUMBRELEASE); +} +void WindowEventHandler::OnHelp(wxHelpEvent &event) +{ + PrivHelpEvent::Fire(event, WXJS_HELP_EVENT); +} + +void WindowEventHandler::InitConnectEventMap(void) +{ + AddConnector(WXJS_CHAR_EVENT, ConnectChar); + AddConnector(WXJS_KEY_DOWN_EVENT, ConnectKeyDown); + AddConnector(WXJS_KEY_UP_EVENT, ConnectKeyUp); + AddConnector(WXJS_CHAR_HOOK_EVENT, ConnectCharHook); + AddConnector(WXJS_ACTIVATE_EVENT, ConnectActivate); + AddConnector(WXJS_SET_FOCUS_EVENT, ConnectSetFocus); + AddConnector(WXJS_KILL_FOCUS_EVENT, ConnectKillFocus); + AddConnector(WXJS_MOVE_EVENT, ConnectMove); + AddConnector(WXJS_SIZE_EVENT, ConnectSize); + AddConnector(WXJS_SCROLL_TOP_EVENT, ConnectScrollTop); + AddConnector(WXJS_SCROLL_BOTTOM_EVENT, ConnectScrollBottom); + AddConnector(WXJS_SCROLL_LINEUP_EVENT, ConnectScrollLineUp); + AddConnector(WXJS_SCROLL_LINEDOWN_EVENT, ConnectScrollLineDown); + AddConnector(WXJS_SCROLL_PAGEUP_EVENT, ConnectScrollPageUp); + AddConnector(WXJS_SCROLL_PAGEDOWN_EVENT, ConnectScrollPageDown); + AddConnector(WXJS_SCROLL_THUMBTRACK_EVENT, ConnectScrollThumbTrack); + AddConnector(WXJS_SCROLL_THUMBRELEASE, ConnectScrollThumbRelease); + AddConnector(WXJS_HELP_EVENT, ConnectHelp); + AddConnector(WXJS_LEFT_DOWN_EVENT, ConnectLeftDown); + AddConnector(WXJS_LEFT_UP_EVENT, ConnectLeftUp); + AddConnector(WXJS_LEFT_DCLICK_EVENT, ConnectLeftDClick); + AddConnector(WXJS_MIDDLE_DOWN_EVENT, ConnectMiddleDown); + AddConnector(WXJS_MIDDLE_UP_EVENT, ConnectMiddleUp); + AddConnector(WXJS_MIDDLE_DCLICK_EVENT, ConnectMiddleDClick); + AddConnector(WXJS_RIGHT_DOWN_EVENT, ConnectRightDown); + AddConnector(WXJS_RIGHT_UP_EVENT, ConnectRightUp); + AddConnector(WXJS_RIGHT_DCLICK_EVENT, ConnectRightDClick); + AddConnector(WXJS_MOTION_EVENT, ConnectMotion); + AddConnector(WXJS_ENTER_WINDOW_EVENT, ConnectEnterWindow); + AddConnector(WXJS_LEAVE_WINDOW_EVENT, ConnectLeaveWindow); + AddConnector(WXJS_MOUSE_WHEEL_EVENT, ConnectMouseWheel); +} + +void WindowEventHandler::ConnectChar(wxWindow *p, bool connect) +{ + if ( connect ) + { + p->Connect(wxEVT_CHAR, wxCharEventHandler(OnChar)); + } + else + { + p->Disconnect(wxEVT_CHAR, wxCharEventHandler(OnChar)); + } +} +void WindowEventHandler::ConnectKeyDown(wxWindow *p, bool connect) +{ + if ( connect ) + { + p->Connect(wxEVT_KEY_DOWN, wxKeyEventHandler(OnKeyDown)); + } + else + { + p->Disconnect(wxEVT_KEY_DOWN, wxKeyEventHandler(OnKeyDown)); + } +} +void WindowEventHandler::ConnectKeyUp(wxWindow *p, bool connect) +{ + if ( connect ) + { + p->Connect(wxEVT_KEY_UP, wxKeyEventHandler(OnKeyUp)); + } + else + { + p->Disconnect(wxEVT_KEY_UP, wxKeyEventHandler(OnKeyUp)); + } +} +void WindowEventHandler::ConnectCharHook(wxWindow *p, bool connect) +{ + if ( connect ) + { + p->Connect(wxEVT_CHAR_HOOK, wxCharEventHandler(OnCharHook)); + } + else + { + p->Disconnect(wxEVT_CHAR_HOOK, wxCharEventHandler(OnCharHook)); + } +} +void WindowEventHandler::ConnectActivate(wxWindow *p, bool connect) +{ + if ( connect ) + { + p->Connect(wxEVT_ACTIVATE, wxActivateEventHandler(OnActivate)); + } + else + { + p->Disconnect(wxEVT_ACTIVATE, wxActivateEventHandler(OnActivate)); + } +} + +void WindowEventHandler::ConnectSetFocus(wxWindow *p, bool connect) +{ + if ( connect ) + { + p->Connect(wxEVT_SET_FOCUS, wxFocusEventHandler(OnSetFocus)); + } + else + { + p->Disconnect(wxEVT_SET_FOCUS, wxFocusEventHandler(OnSetFocus)); + } +} + +void WindowEventHandler::ConnectKillFocus(wxWindow *p, bool connect) +{ + if ( connect ) + { + p->Connect(wxEVT_KILL_FOCUS, wxFocusEventHandler(OnKillFocus)); + } + else + { + p->Disconnect(wxEVT_KILL_FOCUS, wxFocusEventHandler(OnKillFocus)); + } +} +void WindowEventHandler::ConnectMove(wxWindow *p, bool connect) +{ + if ( connect ) + { + p->Connect(wxEVT_MOVE, wxMoveEventHandler(OnMove)); + } + else + { + p->Disconnect(wxEVT_MOVE, wxMoveEventHandler(OnMove)); + } +} +void WindowEventHandler::ConnectSize(wxWindow *p, bool connect) +{ + if ( connect ) + { + p->Connect(wxEVT_SIZE, wxSizeEventHandler(OnSize)); + } + else + { + p->Disconnect(wxEVT_SIZE, wxSizeEventHandler(OnSize)); + } +} +void WindowEventHandler::ConnectScrollTop(wxWindow *p, bool connect) +{ + if ( connect ) + { + p->Connect(wxEVT_SCROLL_TOP, wxScrollWinEventHandler(OnScrollTop)); + } + else + { + p->Disconnect(wxEVT_SCROLL_TOP, wxScrollWinEventHandler(OnScrollTop)); + } +} +void WindowEventHandler::ConnectScrollBottom(wxWindow *p, bool connect) +{ + if ( connect ) + { + p->Connect(wxEVT_SCROLL_BOTTOM, wxScrollWinEventHandler(OnScrollBottom)); + } + else + { + p->Disconnect(wxEVT_SCROLL_BOTTOM, wxScrollWinEventHandler(OnScrollBottom)); + } +} +void WindowEventHandler::ConnectScrollLineUp(wxWindow *p, bool connect) +{ + if ( connect ) + { + p->Connect(wxEVT_SCROLL_LINEUP, wxScrollWinEventHandler(OnScrollLineUp)); + } + else + { + p->Disconnect(wxEVT_SCROLL_LINEUP, wxScrollWinEventHandler(OnScrollLineUp)); + } +} +void WindowEventHandler::ConnectScrollLineDown(wxWindow *p, bool connect) +{ + if ( connect ) + { + p->Connect(wxEVT_SCROLL_LINEDOWN, wxScrollWinEventHandler(OnScrollLineDown)); + } + else + { + p->Disconnect(wxEVT_SCROLL_LINEDOWN, wxScrollWinEventHandler(OnScrollLineDown)); + } +} +void WindowEventHandler::ConnectScrollPageUp(wxWindow *p, bool connect) +{ + if ( connect ) + { + p->Connect(wxEVT_SCROLL_PAGEUP, wxScrollWinEventHandler(OnScrollPageUp)); + } + else + { + p->Disconnect(wxEVT_SCROLL_PAGEUP, wxScrollWinEventHandler(OnScrollPageUp)); + } +} +void WindowEventHandler::ConnectScrollPageDown(wxWindow *p, bool connect) +{ + if ( connect ) + { + p->Connect(wxEVT_SCROLL_PAGEDOWN, wxScrollWinEventHandler(OnScrollPageDown)); + } + else + { + p->Disconnect(wxEVT_SCROLL_PAGEDOWN, wxScrollWinEventHandler(OnScrollPageDown)); + } +} +void WindowEventHandler::ConnectScrollThumbTrack(wxWindow *p, bool connect) +{ + if ( connect ) + { + p->Connect(wxEVT_SCROLL_THUMBTRACK, wxScrollWinEventHandler(OnScrollThumbTrack)); + } + else + { + p->Disconnect(wxEVT_SCROLL_THUMBTRACK, wxScrollWinEventHandler(OnScrollThumbTrack)); + } +} +void WindowEventHandler::ConnectScrollThumbRelease(wxWindow *p, bool connect) +{ + if ( connect ) + { + p->Connect(wxEVT_SCROLL_THUMBRELEASE, wxScrollWinEventHandler(OnScrollThumbRelease)); + } + else + { + p->Disconnect(wxEVT_SCROLL_THUMBRELEASE, wxScrollWinEventHandler(OnScrollThumbRelease)); + } +} +void WindowEventHandler::ConnectHelp(wxWindow *p, bool connect) +{ + if ( connect ) + { + p->Connect(wxEVT_HELP, wxHelpEventHandler(OnHelp)); + } + else + { + p->Disconnect(wxEVT_HELP, wxHelpEventHandler(OnHelp)); + } +} + +void WindowEventHandler::ConnectLeftDown(wxWindow *p, bool connect) +{ + if ( connect ) + { + p->Connect(wxEVT_LEFT_DOWN, wxMouseEventHandler(OnLeftDown)); + } + else + { + p->Disconnect(wxEVT_LEFT_DOWN, wxMouseEventHandler(OnLeftDown)); + } +} +void WindowEventHandler::ConnectLeftUp(wxWindow *p, bool connect) +{ + if ( connect ) + { + p->Connect(wxEVT_LEFT_UP, wxMouseEventHandler(OnLeftUp)); + } + else + { + p->Disconnect(wxEVT_LEFT_UP, wxMouseEventHandler(OnLeftUp)); + } +} +void WindowEventHandler::ConnectLeftDClick(wxWindow *p, bool connect) +{ + if ( connect ) + { + p->Connect(wxEVT_LEFT_DCLICK, wxMouseEventHandler(OnLeftDClick)); + } + else + { + p->Disconnect(wxEVT_LEFT_DCLICK, wxMouseEventHandler(OnLeftDClick)); + } +} + +void WindowEventHandler::ConnectMiddleDown(wxWindow *p, bool connect) +{ + if ( connect ) + { + p->Connect(wxEVT_MIDDLE_DOWN, wxMouseEventHandler(OnMiddleDown)); + } + else + { + p->Disconnect(wxEVT_MIDDLE_DOWN, wxMouseEventHandler(OnMiddleDown)); + } +} + +void WindowEventHandler::ConnectMiddleUp(wxWindow *p, bool connect) +{ + if ( connect ) + { + p->Connect(wxEVT_MIDDLE_UP, wxMouseEventHandler(OnMiddleUp)); + } + else + { + p->Disconnect(wxEVT_MIDDLE_UP, wxMouseEventHandler(OnMiddleUp)); + } +} + +void WindowEventHandler::ConnectMiddleDClick(wxWindow *p, bool connect) +{ + if ( connect ) + { + p->Connect(wxEVT_MIDDLE_DCLICK, wxMouseEventHandler(OnMiddleDClick)); + } + else + { + p->Disconnect(wxEVT_MIDDLE_DCLICK, wxMouseEventHandler(OnMiddleDClick)); + } +} + +void WindowEventHandler::ConnectRightDown(wxWindow *p, bool connect) +{ + if ( connect ) + { + p->Connect(wxEVT_RIGHT_DOWN, wxMouseEventHandler(OnRightDown)); + } + else + { + p->Disconnect(wxEVT_RIGHT_DOWN, wxMouseEventHandler(OnRightDown)); + } +} + +void WindowEventHandler::ConnectRightUp(wxWindow *p, bool connect) +{ + if ( connect ) + { + p->Connect(wxEVT_RIGHT_UP, wxMouseEventHandler(OnRightUp)); + } + else + { + p->Disconnect(wxEVT_RIGHT_UP, wxMouseEventHandler(OnRightUp)); + } +} + +void WindowEventHandler::ConnectRightDClick(wxWindow *p, bool connect) +{ + if ( connect ) + { + p->Connect(wxEVT_RIGHT_DCLICK, wxMouseEventHandler(OnRightDClick)); + } + else + { + p->Disconnect(wxEVT_RIGHT_DCLICK, wxMouseEventHandler(OnRightDClick)); + } +} + +void WindowEventHandler::ConnectMotion(wxWindow *p, bool connect) +{ + if ( connect ) + { + p->Connect(wxEVT_MOTION, wxMouseEventHandler(OnMotion)); + } + else + { + p->Disconnect(wxEVT_MOTION, wxMouseEventHandler(OnMotion)); + } +} + +void WindowEventHandler::ConnectEnterWindow(wxWindow *p, bool connect) +{ + if ( connect ) + { + p->Connect(wxEVT_ENTER_WINDOW, wxMouseEventHandler(OnEnterWindow)); + } + else + { + p->Disconnect(wxEVT_ENTER_WINDOW, wxMouseEventHandler(OnEnterWindow)); + } +} + +void WindowEventHandler::ConnectLeaveWindow(wxWindow *p, bool connect) +{ + if ( connect ) + { + p->Connect(wxEVT_LEAVE_WINDOW, wxMouseEventHandler(OnLeaveWindow)); + } + else + { + p->Disconnect(wxEVT_LEAVE_WINDOW, wxMouseEventHandler(OnLeaveWindow)); + } +} + +void WindowEventHandler::ConnectMouseWheel(wxWindow *p, bool connect) +{ + if ( connect ) + { + p->Connect(wxEVT_MOUSEWHEEL, wxMouseEventHandler(OnMouseWheel)); + } + else + { + p->Disconnect(wxEVT_MOUSEWHEEL, wxMouseEventHandler(OnMouseWheel)); + } +} Property changes on: ps/trunk/source/tools/atlas/wxJS/gui/control/window.cpp ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/gui/control/textctrl.cpp =================================================================== --- ps/trunk/source/tools/atlas/wxJS/gui/control/textctrl.cpp (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/gui/control/textctrl.cpp (revision 5154) @@ -0,0 +1,856 @@ +#include "precompiled.h" + +/* + * wxJavaScript - textctrl.cpp + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: textctrl.cpp 708 2007-05-14 15:30:45Z fbraem $ + */ + +#ifndef WX_PRECOMP + #include +#endif +#include + +#include "../../common/main.h" + + +#include "../event/jsevent.h" +#include "../event/command.h" + +#include "textctrl.h" +#include "window.h" + +#include "../misc/point.h" +#include "../misc/size.h" +#include "../misc/validate.h" +#include "../errors.h" + +using namespace wxjs; +using namespace wxjs::gui; + +/*** + * control/textctrl + * gui + * + * A text control allows text to be displayed and edited. It may be single line or multi-line. + * @section wxTextCtrl_proto Prototype + * + */ +WXJS_INIT_CLASS(TextCtrl, "wxTextCtrl", 2) +void TextCtrl::InitClass(JSContext* WXUNUSED(cx), + JSObject* WXUNUSED(obj), + JSObject* WXUNUSED(proto)) +{ + TextCtrlEventHandler::InitConnectEventMap(); +} + +/*** + * + * + * Returns true if the selection can be copied to the clipboard. + * + * + * Returns true when the selection can be cut to the clipboard. + * + * + * Returns true when the contents of clipboard can be pasted + * into the text control. + * + * + * Returns true if there is a redo facility available and + * the last operation can be redone. + * + * + * Returns true if there is an undo facility available and + * the last operation can be undone. + * + * + * Get/Sets the insertion point + * + * + * Get the number of lines + * + * + * Get the start position of the selection + * + * + * Get the end position of the selection + * + * + * Get/Set the text + * + * + * Returns true when the text is changed + * + * + * Get the position of the last character in the text control + * + * + * Enables/Disables the text control + * + * + */ +WXJS_BEGIN_PROPERTY_MAP(TextCtrl) + WXJS_READONLY_PROPERTY(P_CAN_COPY, "canCopy") + WXJS_READONLY_PROPERTY(P_CAN_CUT, "canCut") + WXJS_READONLY_PROPERTY(P_CAN_PASTE, "canPaste") + WXJS_READONLY_PROPERTY(P_CAN_REDO, "canRedo") + WXJS_READONLY_PROPERTY(P_CAN_UNDO, "canUndo") + WXJS_PROPERTY(P_INSERTION_POINT, "insertionPoint") + WXJS_READONLY_PROPERTY(P_NUMBER_OF_LINES, "numberOfLines") + WXJS_READONLY_PROPERTY(P_SELECTION_FROM, "selectionFrom") + WXJS_READONLY_PROPERTY(P_SELECTION_TO, "selectionTo") + WXJS_PROPERTY(P_VALUE, "value") + WXJS_READONLY_PROPERTY(P_MODIFIED, "modified") + WXJS_READONLY_PROPERTY(P_LAST_POSITION, "lastPosition") + WXJS_PROPERTY(P_EDITABLE, "editable") +WXJS_END_PROPERTY_MAP() + +/*** + * + * + * + * + * + * + * + * + * + * + */ +WXJS_BEGIN_CONSTANT_MAP(TextCtrl) + WXJS_CONSTANT(wxTE_, PROCESS_ENTER) + WXJS_CONSTANT(wxTE_, PROCESS_TAB) + WXJS_CONSTANT(wxTE_, MULTILINE) + WXJS_CONSTANT(wxTE_, PASSWORD) + WXJS_CONSTANT(wxTE_, READONLY) + WXJS_CONSTANT(wxTE_, RICH) +WXJS_END_CONSTANT_MAP() + +bool TextCtrl::GetProperty(wxTextCtrl *p, JSContext *cx, JSObject *obj, int id, jsval *vp) +{ + switch (id) + { + case P_CAN_COPY: + *vp = ToJS(cx, p->CanCopy()); + break; + case P_CAN_PASTE: + *vp = ToJS(cx, p->CanPaste()); + break; + case P_CAN_CUT: + *vp = ToJS(cx, p->CanCut()); + break; + case P_CAN_REDO: + *vp = ToJS(cx, p->CanRedo()); + break; + case P_CAN_UNDO: + *vp = ToJS(cx, p->CanUndo()); + break; + case P_INSERTION_POINT: + *vp = ToJS(cx, p->GetInsertionPoint()); + break; + case P_NUMBER_OF_LINES: + *vp = ToJS(cx, p->GetNumberOfLines()); + break; + case P_SELECTION_FROM: + { + long from = 0L; + long to = 0L; + p->GetSelection(&from, &to); + *vp = ToJS(cx, from); + break; + } + case P_SELECTION_TO: + { + long from = 0L; + long to = 0L; + p->GetSelection(&from, &to); + *vp = ToJS(cx, to); + break; + } + case P_VALUE: + *vp = ToJS(cx, p->GetValue()); + break; + case P_MODIFIED: + *vp = ToJS(cx, p->IsModified()); + break; + case P_LAST_POSITION: + *vp = ToJS(cx, p->GetLastPosition()); + break; + case P_EDITABLE: + { + // Need some testing !!!!!! + long style = p->GetWindowStyleFlag(); + *vp = ToJS(cx, (style & wxTE_READONLY) != wxTE_READONLY); + break; + } + } + return true; +} + +bool TextCtrl::SetProperty(wxTextCtrl *p, JSContext *cx, JSObject *obj, int id, jsval *vp) +{ + switch (id) + { + case P_INSERTION_POINT: + { + int pos; + if ( FromJS(cx, *vp, pos) ) + p->SetInsertionPoint(pos); + break; + } + case P_VALUE: + { + wxString value; + FromJS(cx, *vp, value); + p->SetValue(value); + break; + } + case P_EDITABLE: + { + bool editable; + if ( FromJS(cx, *vp, editable) ) + { + p->SetEditable(editable); + } + break; + } + } + return true; +} + +bool TextCtrl::AddProperty(wxTextCtrl *p, + JSContext* WXUNUSED(cx), + JSObject* WXUNUSED(obj), + const wxString &prop, + jsval* WXUNUSED(vp)) +{ + if ( WindowEventHandler::ConnectEvent(p, prop, true) ) + return true; + + TextCtrlEventHandler::ConnectEvent(p, prop, true); + + return true; +} + +bool TextCtrl::DeleteProperty(wxTextCtrl *p, + JSContext* WXUNUSED(cx), + JSObject* WXUNUSED(obj), + const wxString &prop) +{ + if ( WindowEventHandler::ConnectEvent(p, prop, false) ) + return true; + + TextCtrlEventHandler::ConnectEvent(p, prop, false); + return true; +} + +/*** + * + * + * + * + * The parent of the text control. + * + * + * The unique id + * + * + * The default text + * + * + * The position of the control. + * + * + * The size of the control. + * + * + * + * + * Constructs a new wxTextCtrl object + * + * + */ +wxTextCtrl* TextCtrl::Construct(JSContext *cx, + JSObject *obj, + uintN argc, + jsval *argv, + bool WXUNUSED(constructing)) +{ + wxTextCtrl *p = new wxTextCtrl(); + SetPrivate(cx, obj, p); + + if ( argc > 0 ) + { + jsval rval; + create(cx, obj, argc, argv, &rval); + } + return p; +} + +WXJS_BEGIN_METHOD_MAP(TextCtrl) + WXJS_METHOD("appendText", appendText, 1) + WXJS_METHOD("clear", clear, 0) + WXJS_METHOD("cut", cut, 0) + WXJS_METHOD("discardEdits", discardEdits, 0) + WXJS_METHOD("getLineLength", getLineLength, 1) + WXJS_METHOD("getLineText", getLineText, 1) + WXJS_METHOD("loadFile", loadFile, 1) + WXJS_METHOD("paste", paste, 0) + WXJS_METHOD("setSelection", setSelection, 2) + WXJS_METHOD("redo", redo, 0) + WXJS_METHOD("replace", replace, 3) + WXJS_METHOD("remove", remove, 2) + WXJS_METHOD("saveFile", saveFile, 2) +WXJS_END_METHOD_MAP() + +JSBool TextCtrl::create(JSContext *cx, + JSObject *obj, + uintN argc, + jsval *argv, + jsval *rval) +{ + wxTextCtrl *p = GetPrivate(cx, obj); + *rval = JSVAL_FALSE; + + if ( argc > 7 ) + argc = 7; + + const wxPoint *pt = &wxDefaultPosition; + const wxSize *size = &wxDefaultSize; + int style = 0; + wxString text = wxEmptyString; + const wxValidator *val = &wxDefaultValidator; + + switch(argc) + { + case 7: + val = Validator::GetPrivate(cx, argv[6]); + if ( val == NULL ) + { + JS_ReportError(cx, WXJS_INVALID_ARG_TYPE, 7, "wxValidator"); + return JS_FALSE; + } + case 6: + if ( ! FromJS(cx, argv[5], style) ) + { + JS_ReportError(cx, WXJS_INVALID_ARG_TYPE, 6, "Integer"); + return JS_FALSE; + } + // Fall through + case 5: + size = Size::GetPrivate(cx, argv[4]); + if ( size == NULL ) + { + JS_ReportError(cx, WXJS_INVALID_ARG_TYPE, 5, "wxSize"); + return JS_FALSE; + } + // Fall through + case 4: + pt = Point::GetPrivate(cx, argv[3]); + if ( pt == NULL ) + { + JS_ReportError(cx, WXJS_INVALID_ARG_TYPE, 4, "wxPoint"); + return JS_FALSE; + } + // Fall through + case 3: + FromJS(cx, argv[2], text); + // Fall through + default: + + int id; + if ( ! FromJS(cx, argv[1], id) ) + { + JS_ReportError(cx, WXJS_INVALID_ARG_TYPE, 2, "Integer"); + return JS_FALSE; + } + + wxWindow *parent = Window::GetPrivate(cx, argv[0]); + if ( parent == NULL ) + { + JS_ReportError(cx, WXJS_NO_PARENT_ERROR, GetClass()->name); + return JS_FALSE; + } + JavaScriptClientData *clntParent = + dynamic_cast(parent->GetClientObject()); + if ( clntParent == NULL ) + { + JS_ReportError(cx, WXJS_NO_PARENT_ERROR, GetClass()->name); + return JS_FALSE; + } + JS_SetParent(cx, obj, clntParent->GetObject()); + + if ( p->Create(parent, id, text, *pt, *size, style, *val) ) + { + *rval = JSVAL_TRUE; + p->SetClientObject(new JavaScriptClientData(cx, obj, true, false)); + } + } + + return JS_TRUE; +} + +/*** + * + * + * + * Text to append + * + * + * + * Appends the text to the text of the control. + * + * + */ +JSBool TextCtrl::appendText(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxTextCtrl *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + wxString text; + FromJS(cx, argv[0], text); + p->AppendText(text); + + return JS_TRUE; +} + +/*** + * + * + * + * Removes the text. + * + * + */ +JSBool TextCtrl::clear(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxTextCtrl *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + p->Clear(); + + return JS_TRUE; +} + +/*** + * + * + * + * Removes the selected text and copies it to the clipboard. + * + * + */ +JSBool TextCtrl::cut(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxTextCtrl *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + p->Cut(); + + return JS_TRUE; +} + +/*** + * + * + * + * Resets the modified flag + * + * + */ +JSBool TextCtrl::discardEdits(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxTextCtrl *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + p->DiscardEdits(); + + return JS_TRUE; +} + +/*** + * + * + * + * The line number + * + * + * + * Returns the length of the given line + * + * + */ +JSBool TextCtrl::getLineLength(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxTextCtrl *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + int line; + if ( FromJS(cx, argv[0], line) ) + { + *rval = ToJS(cx, p->GetLineLength(line)); + } + else + { + return JS_FALSE; + } + + return JS_TRUE; +} + +/*** + * + * + * + * The line number + * + * + * + * Returns the text of the given line + * + * + */ +JSBool TextCtrl::getLineText(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxTextCtrl *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + int line; + if ( FromJS(cx, argv[0], line) ) + { + *rval = ToJS(cx, p->GetLineText(line)); + } + else + { + return JS_FALSE; + } + + return JS_TRUE; +} + +/*** + * + * + * + * When not specified, 0 is used. + * + * + * When not specified, the end position is used. + * + * + * + * Selects the text between From and To. + * + * + */ +JSBool TextCtrl::setSelection(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxTextCtrl *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + long from = 0L; + long to = p->GetLastPosition(); + + if (argc > 0) + { + FromJS(cx, argv[0], from); + if ( argc > 1 ) + { + FromJS(cx, argv[1], to); + } + } + p->SetSelection(from, to); + + return JS_TRUE; +} + +/*** + * + * + * + * The name of a file + * + * + * + * Loads a file into the text control + * + * + */ +JSBool TextCtrl::loadFile(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxTextCtrl *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + wxString filename; + FromJS(cx, argv[0], filename); + if ( wxFile::Exists(filename) ) + { + p->LoadFile(filename); + } + else + { + return JS_FALSE; + } + return JS_TRUE; +} + +/*** + * + * + * + * Pastes the content of the clipboard in the selection of the text control. + * + * + */ +JSBool TextCtrl::paste(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxTextCtrl *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + p->Paste(); + + return JS_TRUE; +} + +/*** + * + * + * + * Tries to redo the last operation + * + * + */ +JSBool TextCtrl::redo(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxTextCtrl *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + p->Redo(); + + return JS_TRUE; +} + +/*** + * + * + * + * + * + * + * + * Replaces the text between From and To with the new text + * + * + */ +JSBool TextCtrl::replace(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxTextCtrl *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + long from = 0L; + long to = 0L; + wxString text; + + if ( FromJS(cx, argv[0], from) + && FromJS(cx, argv[1], to) ) + { + FromJS(cx, argv[2], text); + p->Replace(from, to, text); + return JS_TRUE; + } + return JS_FALSE; +} + +/*** + * + * + * + * + * + * + * Removes the text between From and To. + * + * + */ +JSBool TextCtrl::remove(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxTextCtrl *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + long from = 0L; + long to = 0L; + if ( FromJS(cx, argv[0], from) + && FromJS(cx, argv[1], to) ) + { + p->Remove(from, to); + } + else + { + return JS_FALSE; + } + return JS_TRUE; +} + +/*** + * + * + * + * + * + * Saves the content of the text control to the given file + * + * + */ +JSBool TextCtrl::saveFile(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxTextCtrl *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + wxString filename; + FromJS(cx, argv[0], filename); + *rval = ToJS(cx, p->SaveFile(filename)); + + return JS_TRUE; +} + +/*** + * + * + * Triggered when the text is changed. The argument of the function is @wxCommandEvent + * + * + * Triggered when the enter key is pressed in a single-line text control. + * The argument of the function is @wxCommandEvent + * + * + * A mouse event occurred over an URL in the text control + * (wxMSW and wxGTK2 only) + * + * + * User tried to enter more text into the control than the limit set by + * @wxTextCtrl#setMaxLength + * + * + */ +WXJS_INIT_EVENT_MAP(wxTextCtrl) +const wxString WXJS_TEXT_EVENT = wxT("onText"); +const wxString WXJS_TEXT_ENTER_EVENT = wxT("onTextEnter"); +const wxString WXJS_TEXT_URL_EVENT = wxT("onTextURL"); +const wxString WXJS_TEXT_MAX_LEN_EVENT = wxT("onTextMaxLen"); + +void TextCtrlEventHandler::OnText(wxCommandEvent &event) +{ + PrivCommandEvent::Fire(event, WXJS_TEXT_EVENT); +} + +void TextCtrlEventHandler::OnTextEnter(wxCommandEvent &event) +{ + PrivCommandEvent::Fire(event, WXJS_TEXT_ENTER_EVENT); +} + +void TextCtrlEventHandler::OnTextURL(wxCommandEvent &event) +{ + PrivCommandEvent::Fire(event, WXJS_TEXT_URL_EVENT); +} + +void TextCtrlEventHandler::OnTextMaxLen(wxCommandEvent &event) +{ + PrivCommandEvent::Fire(event, WXJS_TEXT_MAX_LEN_EVENT); +} + +void TextCtrlEventHandler::ConnectText(wxTextCtrl *p, bool connect) +{ + if ( connect ) + { + p->Connect(wxEVT_COMMAND_TEXT_UPDATED, + wxCommandEventHandler(OnText)); + } + else + { + p->Disconnect(wxEVT_COMMAND_TEXT_UPDATED, + wxCommandEventHandler(OnText)); + } +} + +void TextCtrlEventHandler::ConnectTextEnter(wxTextCtrl *p, bool connect) +{ + if ( connect ) + { + p->Connect(wxEVT_COMMAND_TEXT_ENTER, + wxCommandEventHandler(OnTextEnter)); + } + else + { + p->Disconnect(wxEVT_COMMAND_TEXT_ENTER, + wxCommandEventHandler(OnTextEnter)); + } +} + +void TextCtrlEventHandler::ConnectTextURL(wxTextCtrl *p, bool connect) +{ + if ( connect ) + { + p->Connect(wxEVT_COMMAND_TEXT_URL, + wxCommandEventHandler(OnTextURL)); + } + else + { + p->Disconnect(wxEVT_COMMAND_TEXT_URL, + wxCommandEventHandler(OnTextURL)); + } +} + +void TextCtrlEventHandler::ConnectTextMaxLen(wxTextCtrl *p, bool connect) +{ + if ( connect ) + { + p->Connect(wxEVT_COMMAND_TEXT_MAXLEN, + wxCommandEventHandler(OnTextMaxLen)); + } + else + { + p->Disconnect(wxEVT_COMMAND_TEXT_MAXLEN, + wxCommandEventHandler(OnTextMaxLen)); + } +} + +void TextCtrlEventHandler::InitConnectEventMap() +{ + AddConnector(WXJS_TEXT_EVENT, ConnectText); + AddConnector(WXJS_TEXT_ENTER_EVENT, ConnectTextEnter); + AddConnector(WXJS_TEXT_URL_EVENT, ConnectTextURL); + AddConnector(WXJS_TEXT_MAX_LEN_EVENT, ConnectTextMaxLen); +} Property changes on: ps/trunk/source/tools/atlas/wxJS/gui/control/textctrl.cpp ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/gui/control/dirdlg.h =================================================================== --- ps/trunk/source/tools/atlas/wxJS/gui/control/dirdlg.h (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/gui/control/dirdlg.h (revision 5154) @@ -0,0 +1,68 @@ +/* + * wxJavaScript - dirdlg.h + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: dirdlg.h 672 2007-04-12 20:29:39Z fbraem $ + */ +#ifndef _WXJSDirDialog_H +#define _WXJSDirDialog_H + +#include + +namespace wxjs +{ + namespace gui + { + class DirDialog : public ApiWrapper + { + public: + + static bool GetProperty(wxDirDialog *p, + JSContext *cx, + JSObject *obj, + int id, + jsval *vp); + static bool SetProperty(wxDirDialog *p, + JSContext *cx, + JSObject *obj, + int id, + jsval *vp); + + static wxDirDialog* Construct(JSContext *cx, + JSObject *obj, + uintN argc, + jsval *argv, + bool constructing); + static void Destruct(JSContext *cx, wxDirDialog *p); + + WXJS_DECLARE_PROPERTY_MAP() + + enum + { + P_MESSAGE + , P_PATH + , P_STYLE + }; + }; + }; // namespace gui +}; // namespace wxjs + +#endif //_WXJSDirDialog_H Property changes on: ps/trunk/source/tools/atlas/wxJS/gui/control/dirdlg.h ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/gui/control/coldata.h =================================================================== --- ps/trunk/source/tools/atlas/wxJS/gui/control/coldata.h (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/gui/control/coldata.h (revision 5154) @@ -0,0 +1,83 @@ +/* + * wxJavaScript - coldata.h + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: coldata.h 672 2007-04-12 20:29:39Z fbraem $ + */ +#ifndef _WXJSColourData_H +#define _WXJSColourData_H + +namespace wxjs +{ + namespace gui + { + class ColourData : public ApiWrapper + { + public: + + static bool GetProperty(wxColourData *p, + JSContext *cx, + JSObject *obj, + int id, + jsval *vp); + static bool SetProperty(wxColourData *p, + JSContext *cx, + JSObject *obj, + int id, + jsval *vp); + + static wxColourData* Construct(JSContext *cx, + JSObject *obj, + uintN argc, + jsval *argv, + bool constructing); + + WXJS_DECLARE_PROPERTY_MAP() + + /** + * Property Ids. + */ + enum + { + P_CHOOSE_FULL + , P_COLOUR + , P_CUSTOM_COLOUR + }; + }; + + class CustomColour : public ApiWrapper + { + public: + + static bool GetProperty(Index *p, + JSContext *cx, + JSObject *obj, + int id, + jsval *vp); + static bool SetProperty(Index *p, + JSContext *cx, + JSObject *obj, + int id, + jsval *vp); + }; + }; // namespace gui +}; // namespace wxjs +#endif //_WXJSColourData_H Property changes on: ps/trunk/source/tools/atlas/wxJS/gui/control/coldata.h ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/gui/control/button.h =================================================================== --- ps/trunk/source/tools/atlas/wxJS/gui/control/button.h (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/gui/control/button.h (revision 5154) @@ -0,0 +1,102 @@ +/* + * wxJavaScript - button.h + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: button.h 678 2007-04-19 20:12:31Z fbraem $ + */ +#ifndef _WXJSButton_H +#define _WXJSButton_H + +#include "../../common/evtconn.h" + +namespace wxjs +{ + namespace gui + { + + class Button : public ApiWrapper + { + public: + + static void InitClass(JSContext* cx, + JSObject* obj, + JSObject* proto); + + static bool AddProperty(wxButton *p, + JSContext *cx, + JSObject *obj, + const wxString &prop, + jsval *vp); + static bool DeleteProperty(wxButton *p, + JSContext* cx, + JSObject* obj, + const wxString &prop); + + static bool GetProperty(wxButton *p, + JSContext *cx, + JSObject *obj, + int id, + jsval *vp); + + static bool SetProperty(wxButton *p, + JSContext *cx, + JSObject *obj, + int id, + jsval *vp); + + static bool GetStaticProperty(JSContext *cx, + int id, + jsval *vp); + + static wxButton *Construct(JSContext *cx, + JSObject *obj, + uintN argc, + jsval *argv, + bool constructing); + + WXJS_DECLARE_PROPERTY_MAP() + WXJS_DECLARE_STATIC_PROPERTY_MAP() + enum + { + P_LABEL + , P_DEFAULT_SIZE + }; + + WXJS_DECLARE_CONSTANT_MAP() + + WXJS_DECLARE_METHOD_MAP() + WXJS_DECLARE_METHOD(setDefault) + WXJS_DECLARE_METHOD(create) + }; + + class ButtonEventHandler : public EventConnector + , public wxEvtHandler + { + public: + // Events + void OnClicked(wxCommandEvent &event); + static void InitConnectEventMap(); + private: + static void ConnectClicked(wxButton *p, bool connect); + }; + }; // namespace gui +}; // namespace wxjs +#endif //_WXJSButton_H Property changes on: ps/trunk/source/tools/atlas/wxJS/gui/control/button.h ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/gui/control/pwdlg.h =================================================================== --- ps/trunk/source/tools/atlas/wxJS/gui/control/pwdlg.h (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/gui/control/pwdlg.h (revision 5154) @@ -0,0 +1,56 @@ +/* + * wxJavaScript - pwdlg.h + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: pwdlg.h 690 2007-04-30 13:09:52Z fbraem $ + */ +#ifndef _WXJSPasswordEntryDialog_H +#define _WXJSPasswordEntryDialog_H + +namespace wxjs +{ + namespace gui + { + class PasswordEntryDialog : public ApiWrapper + { + public: + + static bool AddProperty(wxPasswordEntryDialog *p, + JSContext *cx, + JSObject *obj, + const wxString &prop, + jsval *vp); + static bool DeleteProperty(wxPasswordEntryDialog *p, + JSContext* cx, + JSObject* obj, + const wxString &prop); + + static wxPasswordEntryDialog* Construct(JSContext *cx, + JSObject *obj, + uintN argc, + jsval *argv, + bool constructing); + }; + }; // namespace gui +}; // namespace wxjs + +#endif //_WXJSPasswordEntryDialog_H Property changes on: ps/trunk/source/tools/atlas/wxJS/gui/control/pwdlg.h ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/gui/control/control.h =================================================================== --- ps/trunk/source/tools/atlas/wxJS/gui/control/control.h (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/gui/control/control.h (revision 5154) @@ -0,0 +1,65 @@ +/* + * wxJavaScript - control.h + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: control.h 672 2007-04-12 20:29:39Z fbraem $ + */ +#ifndef _WXJSControl_H +#define _WXJSControl_H + +namespace wxjs +{ + namespace gui + { + class Control : public ApiWrapper + { + public: + /** + * Callback for retrieving properties of wxControl + */ + static bool GetProperty(wxControl *p, + JSContext *cx, + JSObject *obj, + int id, + jsval *vp); + + /** + * Callback for setting properties + */ + static bool SetProperty(wxControl *p, + JSContext *cx, + JSObject *obj, + int id, + jsval *vp); + + WXJS_DECLARE_PROPERTY_MAP() + enum + { + P_LABEL + }; + + WXJS_DECLARE_METHOD_MAP() + WXJS_DECLARE_METHOD(command) + }; + }; // namespace gui +}; // namespace wxjs + +#endif //_WXJSControl_H Property changes on: ps/trunk/source/tools/atlas/wxJS/gui/control/control.h ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/gui/control/ctrlitem.h =================================================================== --- ps/trunk/source/tools/atlas/wxJS/gui/control/ctrlitem.h (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/gui/control/ctrlitem.h (revision 5154) @@ -0,0 +1,72 @@ +/* + * wxJavaScript - ctrlitem.h + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: ctrlitem.h 672 2007-04-12 20:29:39Z fbraem $ + */ +#ifndef _WXJSControlWithItems_H +#define _WXJSControlWithItems_H + +namespace wxjs +{ + namespace gui + { + class ControlWithItems : public ApiWrapper + { + public: + + static bool GetProperty(wxControlWithItems *p, + JSContext *cx, + JSObject *obj, + int id, + jsval *vp); + static bool SetProperty(wxControlWithItems *p, + JSContext *cx, + JSObject *obj, + int id, + jsval *vp); + + WXJS_DECLARE_PROPERTY_MAP() + + /** + * Property Ids. + */ + enum + { + P_COUNT = WXJS_START_PROPERTY_ID + , P_SELECTION + , P_ITEM + , P_STRING_SELECTION + , P_EMPTY + }; + + WXJS_DECLARE_METHOD_MAP() + WXJS_DECLARE_METHOD(append) + WXJS_DECLARE_METHOD(clear) + WXJS_DECLARE_METHOD(delete_item) + WXJS_DECLARE_METHOD(findString) + WXJS_DECLARE_METHOD(insert) + }; + }; // namespace gui +}; // namespace wxjs + +#endif //_WXJSControlWithItems_H Property changes on: ps/trunk/source/tools/atlas/wxJS/gui/control/ctrlitem.h ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/gui/control/listbox.h =================================================================== --- ps/trunk/source/tools/atlas/wxJS/gui/control/listbox.h (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/gui/control/listbox.h (revision 5154) @@ -0,0 +1,93 @@ +/* + * wxJavaScript - listbox.h + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: listbox.h 685 2007-04-25 21:14:49Z fbraem $ + */ +#ifndef _WXJSListBox_H +#define _WXJSListBox_H + +#include "../../common/evtconn.h" + +namespace wxjs +{ + namespace gui + { + class ListBox : public ApiWrapper + { + public: + + static void InitClass(JSContext* cx, + JSObject* obj, + JSObject* proto); + + static bool AddProperty(wxListBox *p, + JSContext *cx, + JSObject *obj, + const wxString &prop, + jsval *vp); + static bool DeleteProperty(wxListBox *p, + JSContext* cx, + JSObject* obj, + const wxString &prop); + + static bool GetProperty(wxListBox *p, + JSContext *cx, + JSObject *obj, + int id, + jsval *vp); + static wxListBox* Construct(JSContext *cx, + JSObject *obj, + uintN argc, + jsval *argv, + bool constructing); + + WXJS_DECLARE_PROPERTY_MAP() + + WXJS_DECLARE_METHOD_MAP() + WXJS_DECLARE_METHOD(create) + WXJS_DECLARE_METHOD(insert_items) + WXJS_DECLARE_METHOD(set_first_item) + + WXJS_DECLARE_CONSTANT_MAP() + + enum + { + P_SELECTIONS + }; + }; + + class ListBoxEventHandler : public EventConnector + , public wxEvtHandler + { + public: + // Events + void OnListBox(wxCommandEvent &event); + void OnDoubleClick(wxCommandEvent &event); + static void InitConnectEventMap(); + private: + static void ConnectListBox(wxListBox *p, bool connect); + static void ConnectDoubleClick(wxListBox *p, bool connect); + }; + }; // namespace gui +}; // namespace wxjs + +#endif //_WXJSListBox_H Property changes on: ps/trunk/source/tools/atlas/wxJS/gui/control/listbox.h ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/gui/control/toplevel.cpp =================================================================== --- ps/trunk/source/tools/atlas/wxJS/gui/control/toplevel.cpp (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/gui/control/toplevel.cpp (revision 5154) @@ -0,0 +1,295 @@ +#include "precompiled.h" + +/* + * wxJavaScript - toplevel.cpp + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: toplevel.cpp 714 2007-05-16 20:24:49Z fbraem $ + */ +// toplevel.cpp + +#ifndef WX_PRECOMP + #include +#endif + +#include "../../common/main.h" + +#include "../misc/icon.h" +#include "toplevel.h" +#include "window.h" + +using namespace wxjs; +using namespace wxjs::gui; + +/*** + * control/toplevel + * gui + * + * wxTopLevelWindow is the prototype class for @wxDialog and @wxFrame. + * + */ +WXJS_INIT_CLASS(TopLevelWindow, "wxTopLevelWindow", 0) + +/*** + * + * + * + * + * + * + * + * + * + * wxFullScreen is ported to wxJS as a separate class + * + * + * + */ +void TopLevelWindow::InitClass(JSContext *cx, JSObject *obj, JSObject *proto) +{ + JSConstDoubleSpec wxFullScreenMap[] = + { + WXJS_CONSTANT(wxFULLSCREEN_, NOMENUBAR) + WXJS_CONSTANT(wxFULLSCREEN_, NOTOOLBAR) + WXJS_CONSTANT(wxFULLSCREEN_, NOSTATUSBAR) + WXJS_CONSTANT(wxFULLSCREEN_, NOBORDER) + WXJS_CONSTANT(wxFULLSCREEN_, NOCAPTION) + WXJS_CONSTANT(wxFULLSCREEN_, ALL) + { 0 } + }; + JSObject *constObj = JS_DefineObject(cx, obj, "wxFullScreen", + NULL, NULL, + JSPROP_READONLY | JSPROP_PERMANENT); + JS_DefineConstDoubles(cx, constObj, wxFullScreenMap); +} + +/*** + * + * + * Get/Set fullscreen mode + * + * + * Get/Set icon + * + * + * Not yet implemented + * + * + * Is the window active? + * + * + * + * Get/Set iconized mode + * + * + * Get/Set maximized mode + * + * + * Get/Set the title + * + * + */ +WXJS_BEGIN_PROPERTY_MAP(TopLevelWindow) + WXJS_PROPERTY(P_DEFAULT_ITEM, "defaultItem") + WXJS_PROPERTY(P_FULL_SCREEN, "fullScreen") + WXJS_PROPERTY(P_ICON, "icon") + WXJS_PROPERTY(P_ICONS, "icons") + WXJS_READONLY_PROPERTY(P_ACTIVE, "active") + WXJS_PROPERTY(P_ICONIZED, "iconized") + WXJS_PROPERTY(P_MAXIMIZED, "maximized") + WXJS_PROPERTY(P_TITLE, "title") +WXJS_END_PROPERTY_MAP() + +bool TopLevelWindow::GetProperty(wxTopLevelWindow *p, + JSContext *cx, + JSObject* WXUNUSED(obj), + int id, + jsval *vp) +{ + switch(id) + { + case P_ICON: + *vp = Icon::CreateObject(cx, new wxIcon(p->GetIcon())); + break; + case P_FULL_SCREEN: + *vp = ToJS(cx, p->IsFullScreen()); + break; + case P_ICONS: + //TODO + break; + case P_ICONIZED: + *vp = ToJS(cx, p->IsIconized()); + break; + case P_MAXIMIZED: + *vp = ToJS(cx, p->IsMaximized()); + break; + case P_TITLE: + *vp = ToJS(cx, p->GetTitle()); + break; + case P_DEFAULT_ITEM: + { + wxWindow *win = p->GetDefaultItem(); + if ( win != NULL ) + { + JavaScriptClientData *data + = dynamic_cast(win->GetClientObject()); + if ( data != NULL ) + { + *vp = OBJECT_TO_JSVAL(data->GetObject()); + } + } + break; + } + } + + return true; +} + +bool TopLevelWindow::SetProperty(wxTopLevelWindow *p, + JSContext *cx, + JSObject* WXUNUSED(obj), + int id, + jsval *vp) +{ + switch(id) + { + case P_ICONS: + //TODO + break; + case P_ICON: + { + wxIcon *ico = Icon::GetPrivate(cx, *vp); + if ( ico ) + p->SetIcon(*ico); + break; + } + case P_ICONIZED: + { + bool iconize; + if ( FromJS(cx, *vp, iconize) ) + p->Iconize(iconize); + break; + } + case P_FULL_SCREEN: + { + bool full; + if ( FromJS(cx, *vp, full) ) + p->ShowFullScreen(full, wxFULLSCREEN_ALL); + break; + } + case P_MAXIMIZED: + { + bool maximize; + if ( FromJS(cx, *vp, maximize) ) + p->Maximize(maximize); + break; + } + case P_TITLE: + { + wxString title; + FromJS(cx, *vp, title); + p->SetTitle(title); + break; + } + case P_DEFAULT_ITEM: + wxWindow *win = Window::GetPrivate(cx, *vp); + if ( win != NULL ) + { + p->SetDefaultItem(win); + } + break; + } + return true; +} + +WXJS_BEGIN_METHOD_MAP(TopLevelWindow) + WXJS_METHOD("requestUserAttention", requestUserAttention, 0) + WXJS_METHOD("setLeftMenu", setLeftMenu, 0) + WXJS_METHOD("setRightMenu", setRightMenu, 0) +WXJS_END_METHOD_MAP() + +JSBool TopLevelWindow::requestUserAttention(JSContext *cx, + JSObject *obj, + uintN argc, + jsval *argv, + jsval *rval) +{ + //TODO + return JS_TRUE; +} + +JSBool TopLevelWindow::setLeftMenu(JSContext *cx, + JSObject *obj, + uintN argc, + jsval *argv, + jsval *rval) +{ + //TODO + return JS_TRUE; +} + +JSBool TopLevelWindow::setRightMenu(JSContext *cx, + JSObject *obj, + uintN argc, + jsval *argv, + jsval *rval) +{ + //TODO + return JS_TRUE; +} +/*** + * + * + * + * Show the frame in full screen when true, restore when false. + * + * + * Use one of @wxTopLevelWindow#wxFullScreen. + * + * + * + * Shows the frame in full screen or restores the frame. + * + * + */ +JSBool TopLevelWindow::showFullScreen(JSContext *cx, + JSObject *obj, + uintN argc, + jsval *argv, + jsval *rval) +{ + wxTopLevelWindow *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + bool show; + if ( ! FromJS(cx, argv[0], show) ) + return JS_FALSE; + + int style = wxFULLSCREEN_ALL; + if ( argc > 1 + && ! FromJS(cx, argv[1], style) ) + return JS_FALSE; + + *rval = ToJS(cx, p->ShowFullScreen(show, style)); + + return JS_TRUE; +} Property changes on: ps/trunk/source/tools/atlas/wxJS/gui/control/toplevel.cpp ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/gui/control/item.cpp =================================================================== --- ps/trunk/source/tools/atlas/wxJS/gui/control/item.cpp (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/gui/control/item.cpp (revision 5154) @@ -0,0 +1,176 @@ +#include "precompiled.h" + +/* + * wxJavaScript - item.cpp + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: item.cpp 598 2007-03-07 20:13:28Z fbraem $ + */ +#ifndef WX_PRECOMP + #include +#endif + +#include "../../common/main.h" +#include "../../common/index.h" + +#include "item.h" +#include "ctrlitem.h" + +using namespace wxjs; +using namespace wxjs::gui; + +/*** + * control/item + * gui + * + * wxControlItem represents an item in a @wxControlWithItems control. + *

Remark: This class is a helper class to make + * it possible to use the items of a @wxControlWithItems as an array. + * It has no corresponding class in wxWidgets. + *
+ */ +WXJS_INIT_CLASS(ControlItem, "wxControlItem", 0) + +/*** + * + * + * Get/Set the value of the item. + * + * + */ +WXJS_BEGIN_PROPERTY_MAP(ControlItem) + WXJS_PROPERTY(P_VALUE, "value") +WXJS_END_PROPERTY_MAP() + +WXJS_BEGIN_METHOD_MAP(ControlItem) + WXJS_METHOD("remove", remove, 0) + WXJS_METHOD("select", select, 0) +WXJS_END_METHOD_MAP() + +bool ControlItem::GetProperty(Index *p, JSContext *cx, JSObject *obj, int id, jsval *vp) +{ + JSObject *parent = JS_GetParent(cx, obj); + wxASSERT_MSG(parent != NULL, wxT("No parent found for ControlItem")); + + wxControlWithItems *ctrl = ControlWithItems::GetPrivate(cx, parent); + wxASSERT_MSG(ctrl != NULL, wxT("No private data associated with ControlWithItems")); + + // When propId is greater then 0, then we have an array index. + if ( id >= 0 ) + { + SetPrivate(cx, obj, new Index(id)); + *vp = OBJECT_TO_JSVAL(obj); + } + else + { + if ( p->GetIndex() < ctrl->GetCount() ) // To be sure + { + switch(id) + { + case P_VALUE: + *vp = ToJS(cx, ctrl->GetString(p->GetIndex())); + break; + } + } + } + return true; +} + +bool ControlItem::SetProperty(Index *p, JSContext *cx, JSObject *obj, int id, jsval *vp) +{ + if ( p == NULL ) + return true; + + JSObject *parent = JS_GetParent(cx, obj); + wxASSERT_MSG(parent != NULL, wxT("No parent found for ControlItem")); + + wxControlWithItems *ctrl = ControlWithItems::GetPrivate(cx, parent); + wxASSERT_MSG(ctrl != NULL, wxT("No private data associated with ControlWithItems")); + + if ( p->GetIndex() < ctrl->GetCount() ) // To be sure + { + switch (id) + { + case P_VALUE: + { + wxString value; + FromJS(cx, *vp, value); + ctrl->SetString(p->GetIndex(), value); + break; + } + } + } + return true; +} + +/*** + * + * + * + * removes the item from the control. + * + * + */ +JSBool ControlItem::remove(JSContext *cx, JSObject *obj, uintN argc, + jsval *argv, jsval *rval) +{ + JSObject *parent = JS_GetParent(cx, obj); + wxASSERT_MSG(parent != NULL, wxT("No parent found for ControlItem")); + + wxControlWithItems *ctrl = ControlWithItems::GetPrivate(cx, parent); + if ( ctrl == NULL ) + return JS_FALSE; + + Index *item = ControlItem::GetPrivate(cx, obj); + wxASSERT_MSG(item != NULL, wxT("No private data associated with ChoiceItem")); + + if ( item->GetIndex() < ctrl->GetCount() ) // To be sure. + ctrl->Delete(item->GetIndex()); + + return JS_TRUE; +} + +/*** + * + * + * + * Selects/unselects the item. + * + * + */ +JSBool ControlItem::select(JSContext *cx, JSObject *obj, uintN argc, + jsval *argv, jsval *rval) +{ + JSObject *parent = JS_GetParent(cx, obj); + wxASSERT_MSG(parent != NULL, wxT("No parent found for ControlItem")); + + wxControlWithItems *ctrl = ControlWithItems::GetPrivate(cx, parent); + if ( ctrl == NULL ) + return JS_FALSE; + + Index *item = ControlItem::GetPrivate(cx, obj); + wxASSERT_MSG(item != NULL, wxT("No private data associated with ChoiceItem")); + + if ( item->GetIndex() < ctrl->GetCount() ) // To be sure. + ctrl->Select(item->GetIndex()); + + return JS_TRUE; +} Property changes on: ps/trunk/source/tools/atlas/wxJS/gui/control/item.cpp ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/gui/control/listitem.h =================================================================== --- ps/trunk/source/tools/atlas/wxJS/gui/control/listitem.h (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/gui/control/listitem.h (revision 5154) @@ -0,0 +1,79 @@ +/* + * wxJavaScript - listitem.h + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: listitem.h 688 2007-04-27 20:45:09Z fbraem $ + */ +#ifndef _WXJSListItem_H +#define _WXJSListItem_H + +namespace wxjs +{ + namespace gui + { + + class ListObjectData; + + class ListItem : public ApiWrapper + { + public: + + static bool GetProperty(wxListItem *p, + JSContext *cx, + JSObject *obj, + int id, + jsval *vp); + static bool SetProperty(wxListItem *p, + JSContext *cx, + JSObject *obj, + int id, + jsval *vp); + + static wxListItem *Construct(JSContext *cx, + JSObject *obj, + uintN argc, + jsval *argv, + bool constructing); + + WXJS_DECLARE_PROPERTY_MAP() + + enum + { + P_MASK = WXJS_START_PROPERTY_ID + , P_ID + , P_COLUMN + , P_STATE + , P_STATE_MASK + , P_TEXT + , P_IMAGE + , P_DATA + , P_WIDTH + , P_ALIGN + , P_TEXT_COLOUR + , P_BG_COLOUR + , P_FONT + , P_HAS_ATTR + }; + }; + }; // namespace gui +}; // namespace wxjs + +#endif //_WXJSListItem_H Property changes on: ps/trunk/source/tools/atlas/wxJS/gui/control/listitem.h ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/gui/control/helpbtn.h =================================================================== --- ps/trunk/source/tools/atlas/wxJS/gui/control/helpbtn.h (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/gui/control/helpbtn.h (revision 5154) @@ -0,0 +1,57 @@ +/* + * wxJavaScript - helpbtn.h + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: helpbtn.h 684 2007-04-25 19:25:02Z fbraem $ + */ +#ifndef _WXJSContextHelpButton_H +#define _WXJSContextHelpButton_H + +#include + +namespace wxjs +{ + namespace gui + { + class ContextHelpButton : public ApiWrapper + { + public: + + static wxContextHelpButton* Construct(JSContext *cx, + JSObject *obj, + uintN argc, + jsval *argv, + bool constructing); + static bool AddProperty(wxContextHelpButton *p, + JSContext *cx, + JSObject *obj, + const wxString &prop, + jsval *vp); + + static bool DeleteProperty(wxContextHelpButton *p, + JSContext* cx, + JSObject* obj, + const wxString &prop); + }; + }; // namespace gui +}; // namespace wxjs +#endif //_WXJSContextHelpButton_H Property changes on: ps/trunk/source/tools/atlas/wxJS/gui/control/helpbtn.h ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/gui/control/coldata.cpp =================================================================== --- ps/trunk/source/tools/atlas/wxJS/gui/control/coldata.cpp (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/gui/control/coldata.cpp (revision 5154) @@ -0,0 +1,185 @@ +#include "precompiled.h" + +/* + * wxJavaScript - coldata.cpp + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: coldata.cpp 672 2007-04-12 20:29:39Z fbraem $ + */ + +#ifndef WX_PRECOMP + #include +#endif + +#include "../../common/main.h" +#include "../../common/index.h" + +#include "../misc/colour.h" + +#include "coldata.h" + +using namespace wxjs; +using namespace wxjs::gui; + +/*** + * control/colourdata + * gui + * + * This class holds a variety of information related to colour dialogs. + * See @wxColourDialog. + * + */ +WXJS_INIT_CLASS(ColourData, "wxColourData", 0) + +/*** + * + * + * Under Windows, determines whether the Windows colour dialog will + * display the full dialog with custom colour selection controls. + * Has no meaning under other platforms. + * + * + * Get/Set the current colour associated with the colour dialog. + * + * + * Get/Set the ith custom colour associated with the colour dialog. + * The index must be between 0 and 15. The element is a @wxColour. + * + * + */ +WXJS_BEGIN_PROPERTY_MAP(ColourData) + WXJS_PROPERTY(P_CUSTOM_COLOUR, "customColour") + WXJS_PROPERTY(P_CHOOSE_FULL, "chooseFull") + WXJS_PROPERTY(P_COLOUR, "colour") +WXJS_END_PROPERTY_MAP() + +bool ColourData::GetProperty(wxColourData *p, + JSContext *cx, + JSObject *obj, + int id, + jsval *vp) +{ + switch(id) + { + case P_CHOOSE_FULL: + *vp = ToJS(cx, p->GetChooseFull()); + break; + case P_COLOUR: + *vp = Colour::CreateObject(cx, new wxColour(p->GetColour())); + break; + case P_CUSTOM_COLOUR: + *vp = CustomColour::CreateObject(cx, new Index(0), obj); + break; + } + return true; +} + +bool ColourData::SetProperty(wxColourData* p, + JSContext *cx, + JSObject* WXUNUSED(obj), + int id, + jsval *vp) +{ + switch (id) + { + case P_CHOOSE_FULL: + { + bool full; + if ( FromJS(cx, *vp, full) ) + p->SetChooseFull(full); + break; + } + case P_COLOUR: + { + wxColour *colour = Colour::GetPrivate(cx, *vp); + if ( colour != NULL ) + p->SetColour(*colour); + break; + } + } + return true; +} + +/*** + * + * + * + * Constructs a new wxColourData object. + * The selected colour is black. And @wxColourData#chooseFull is true. + * + * + */ +wxColourData* ColourData::Construct(JSContext* WXUNUSED(cx), + JSObject* WXUNUSED(obj), + uintN WXUNUSED(argc), + jsval* WXUNUSED(argv), + bool WXUNUSED(constructing)) +{ + return new wxColourData(); +} + +WXJS_INIT_CLASS(CustomColour, "wxCustomColour", 0) + +bool CustomColour::GetProperty(Index *p, + JSContext *cx, + JSObject *obj, + int id, + jsval *vp) +{ + if ( id >= 0 ) + { + p->SetIndex(id); + + JSObject *objColourData = JS_GetParent(cx, obj); + wxASSERT_MSG(objColourData != NULL, wxT("wxCustomColour has no parent !")); + + wxColourData *colourData = ColourData::GetPrivate(cx, objColourData); + if ( colourData == NULL ) + return false; + + *vp = Colour::CreateObject(cx, + new wxColour(colourData->GetCustomColour(id))); + } + return true; +} + +bool CustomColour::SetProperty(Index* WXUNUSED(p), + JSContext *cx, + JSObject *obj, + int id, + jsval *vp) +{ + if ( id >= 0 ) + { + JSObject *objColourData = JS_GetParent(cx, obj); + wxASSERT_MSG(objColourData != NULL, + wxT("wxCustomColour has no parent !")); + + wxColourData *colourData = ColourData::GetPrivate(cx, objColourData); + if ( colourData == NULL ) + return false; + + wxColour *colour = Colour::GetPrivate(cx, *vp); + if ( colour != NULL ) + colourData->SetCustomColour(id, *colour); + } + return true; +} Property changes on: ps/trunk/source/tools/atlas/wxJS/gui/control/coldata.cpp ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/gui/control/txtdlg.h =================================================================== --- ps/trunk/source/tools/atlas/wxJS/gui/control/txtdlg.h (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/gui/control/txtdlg.h (revision 5154) @@ -0,0 +1,70 @@ +/* + * wxJavaScript - txtdlg.h + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: txtdlg.h 696 2007-05-07 21:16:23Z fbraem $ + */ +#ifndef _WXJSTextEntryDialog_H +#define _WXJSTextEntryDialog_H + +namespace wxjs +{ + namespace gui + { + class TextEntryDialog : public ApiWrapper + { + public: + static bool AddProperty(wxTextEntryDialog *p, + JSContext *cx, + JSObject *obj, + const wxString &prop, + jsval *vp); + static bool DeleteProperty(wxTextEntryDialog *p, + JSContext* cx, + JSObject* obj, + const wxString &prop); + + static bool GetProperty(wxTextEntryDialog *p, + JSContext *cx, + JSObject *obj, + int id, + jsval *vp); + static bool SetProperty(wxTextEntryDialog *p, + JSContext *cx, + JSObject *obj, + int id, + jsval *vp); + + static wxTextEntryDialog* Construct(JSContext *cx, + JSObject *obj, + uintN argc, + jsval *argv, + bool constructing); + WXJS_DECLARE_PROPERTY_MAP() + enum + { + P_VALUE + }; + }; + }; // namespace gui +}; // namespace wxjs +#endif //_WXJSTextEntryDialog_H Property changes on: ps/trunk/source/tools/atlas/wxJS/gui/control/txtdlg.h ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/gui/control/pwdlg.cpp =================================================================== --- ps/trunk/source/tools/atlas/wxJS/gui/control/pwdlg.cpp (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/gui/control/pwdlg.cpp (revision 5154) @@ -0,0 +1,179 @@ +#include "precompiled.h" + +/* + * wxJavaScript - pwdlg.cpp + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: pwdlg.cpp 708 2007-05-14 15:30:45Z fbraem $ + */ +#ifndef WX_PRECOMP + #include +#endif +#include + +#include "../../common/main.h" + +#include "../misc/point.h" + +#include "../event/jsevent.h" + + +#include "../errors.h" +#include "pwdlg.h" +#include "dialog.h" +#include "window.h" + +using namespace wxjs; +using namespace wxjs::gui; + +/*** + * control/pwdlg + * gui + * + * This class represents a dialog that requests a password from the user. + * + */ +WXJS_INIT_CLASS(PasswordEntryDialog, "wxPasswordEntryDialog", 2) + +bool PasswordEntryDialog::AddProperty(wxPasswordEntryDialog *p, + JSContext* WXUNUSED(cx), + JSObject* WXUNUSED(obj), + const wxString &prop, + jsval* WXUNUSED(vp)) +{ + if ( WindowEventHandler::ConnectEvent(p, prop, true) ) + return true; + + DialogEventHandler::ConnectEvent(p, prop, true); + + return true; +} + + +bool PasswordEntryDialog::DeleteProperty(wxPasswordEntryDialog *p, + JSContext* WXUNUSED(cx), + JSObject* WXUNUSED(obj), + const wxString &prop) +{ + if ( WindowEventHandler::ConnectEvent(p, prop, false) ) + return true; + + DialogEventHandler::ConnectEvent(p, prop, false); + return true; +} + +/*** + * + * + * + * + * The parent of the dialog. null is Allowed. + * + * Message to show on the dialog. + * The title of the dialog. + * + * The default value of the text control. + * + * + * The position of the dialog. + * + * + * A dialog style, the buttons wxId.OK and wxId.CANCEL can be used. + * + * + * + * Constructs a new wxPasswordEntryDialog object. + * + * + */ +wxPasswordEntryDialog* PasswordEntryDialog::Construct(JSContext *cx, + JSObject *obj, + uintN argc, + jsval *argv, + bool WXUNUSED(constructing)) +{ + if ( argc > 6 ) + argc = 6; + + int style = wxOK | wxCANCEL | wxCENTRE; + const wxPoint *pt = &wxDefaultPosition; + wxString defaultValue = wxEmptyString; + wxString caption = wxEmptyString; + + switch(argc) + { + case 6: + pt = Point::GetPrivate(cx, argv[5]); + if ( pt == NULL ) + { + JS_ReportError(cx, WXJS_INVALID_ARG_TYPE, 6, "wxPoint"); + return NULL; + } + // Fall through + case 5: + if ( ! FromJS(cx, argv[4], style) ) + { + JS_ReportError(cx, WXJS_INVALID_ARG_TYPE, 5, "Integer"); + return NULL; + } + // Fall through + case 4: + if ( ! FromJS(cx, argv[3], defaultValue) ) + { + JS_ReportError(cx, WXJS_INVALID_ARG_TYPE, 4, "String"); + return JS_FALSE; + } + // Fall through + case 3: + if ( ! FromJS(cx, argv[2], caption) ) + { + JS_ReportError(cx, WXJS_INVALID_ARG_TYPE, 2, "String"); + return NULL; + } + // Fall through + default: + wxString message; + if ( ! FromJS(cx, argv[1], message) ) + { + JS_ReportError(cx, WXJS_INVALID_ARG_TYPE, 2, "String"); + return NULL; + } + + wxWindow *parent = Window::GetPrivate(cx, argv[0]); + if ( parent != NULL ) + { + JavaScriptClientData *clntParent = + dynamic_cast(parent->GetClientObject()); + if ( clntParent == NULL ) + { + JS_ReportError(cx, WXJS_NO_PARENT_ERROR, GetClass()->name); + return JS_FALSE; + } + JS_SetParent(cx, obj, clntParent->GetObject()); + } + + wxPasswordEntryDialog *p = new wxPasswordEntryDialog(parent, message, + caption, defaultValue, + style, *pt); + p->SetClientObject(new JavaScriptClientData(cx, obj, true, false)); + return p; + } +} Property changes on: ps/trunk/source/tools/atlas/wxJS/gui/control/pwdlg.cpp ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/gui/control/ctrlitem.cpp =================================================================== --- ps/trunk/source/tools/atlas/wxJS/gui/control/ctrlitem.cpp (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/gui/control/ctrlitem.cpp (revision 5154) @@ -0,0 +1,299 @@ +#include "precompiled.h" + +/* + * wxJavaScript - ctrlitem.cpp + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: ctrlitem.cpp 672 2007-04-12 20:29:39Z fbraem $ + */ +#ifndef WX_PRECOMP + #include +#endif + +#include "../../common/main.h" +#include "../../common/index.h" +#include "ctrlitem.h" +#include "item.h" + +using namespace wxjs; +using namespace wxjs::gui; + +/*** + * control/ctrlitem + * gui + * + * This class is a prototype for some wxWidgets controls which contain + * several items, such as @wxListBox, @wxCheckListBox, @wxChoice and + * @wxComboBox. + *

+ * It defines the methods for accessing the controls items. + *
+ */ +WXJS_INIT_CLASS(ControlWithItems, "wxControlWithItems", 0) + +/*** + * + * + * The number of items + * + * + * Returns true when the control has no items + * + * + * This is an 'array' property. This means that you have to specify an index + * to retrieve the actual item. An example: + * + * choice.item[0].value = "BMW"; + * + * + * + * Get/Set the selected item + * + * + * Get the label of the selected item or an empty string when no item is + * selected. Or select the item with the given string. + * + * + */ +WXJS_BEGIN_PROPERTY_MAP(ControlWithItems) + WXJS_PROPERTY(P_COUNT, "count") + WXJS_PROPERTY(P_SELECTION, "selection") + WXJS_READONLY_PROPERTY(P_ITEM, "item") + WXJS_PROPERTY(P_STRING_SELECTION, "stringSelection") + WXJS_READONLY_PROPERTY(P_EMPTY, "empty") +WXJS_END_PROPERTY_MAP() + +bool ControlWithItems::GetProperty(wxControlWithItems *p, + JSContext *cx, + JSObject *obj, + int id, + jsval *vp) +{ + switch(id) + { + case P_COUNT: + *vp = ToJS(cx, p->GetCount()); + break; + case P_SELECTION: + *vp = ToJS(cx, p->GetSelection()); + break; + case P_ITEM: + *vp = ControlItem::CreateObject(cx, NULL, obj); + break; + case P_STRING_SELECTION: + *vp = ToJS(cx, p->GetStringSelection()); + break; + case P_EMPTY: + *vp = ToJS(cx, p->IsEmpty()); + break; + } + return true; +} + +bool ControlWithItems::SetProperty(wxControlWithItems *p, + JSContext *cx, + JSObject* WXUNUSED(obj), + int id, + jsval *vp) +{ + switch (id) + { + case P_SELECTION: + { + int selection; + if ( FromJS(cx, *vp, selection) ) + p->SetSelection(selection); + } + break; + case P_STRING_SELECTION: + { + wxString selection; + FromJS(cx, *vp, selection); + p->SetStringSelection(selection); + } + } + return true; +} + +WXJS_BEGIN_METHOD_MAP(ControlWithItems) + WXJS_METHOD("append", append, 1) + WXJS_METHOD("clear", clear, 0) + WXJS_METHOD("deleteItem", delete_item, 1) + WXJS_METHOD("findString", findString, 1) + WXJS_METHOD("insert", insert, 2) +WXJS_END_METHOD_MAP() + +/*** + * + * + * + * + * + * + * + * + * Adds the item or all elements of the array to the end of the control. + * When only one item is appended, the return value is the index + * of the newly added item. + * + * + */ + JSBool ControlWithItems::append(JSContext *cx, + JSObject *obj, + uintN WXUNUSED(argc), + jsval *argv, + jsval *rval) +{ + wxControlWithItems *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + if ( JSVAL_IS_OBJECT(argv[0]) + && JS_IsArrayObject(cx, JSVAL_TO_OBJECT(argv[0])) ) + { + wxArrayString strings; + if ( FromJS(cx, argv[0], strings) ) + { + p->Append(strings); + } + } + else + { + wxString item; + FromJS(cx, argv[0], item); + *rval = ToJS(cx, p->Append(item)); + } + + return JS_TRUE; +} + +/*** + * + * + * + * Removes all items from the control. + * + * + */ +JSBool ControlWithItems::clear(JSContext *cx, + JSObject *obj, + uintN WXUNUSED(argc), + jsval* WXUNUSED(argv), + jsval* WXUNUSED(rval)) +{ + wxControlWithItems *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + p->Clear(); + return JS_TRUE; + } + +/*** + * + * + * + * + * + * Removes the item with the given index (zero-based). + * + * + */ +JSBool ControlWithItems::delete_item(JSContext *cx, + JSObject *obj, + uintN WXUNUSED(argc), + jsval *argv, + jsval* WXUNUSED(rval)) +{ + wxControlWithItems *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + int idx; + if ( FromJS(cx, argv[0], idx) ) + { + p->Delete(idx); + return JS_TRUE; + } + + return JS_FALSE; +} + +/*** + * + * + * + * + * + * Returns the zero-based index of the item with the given search text. + * -1 is returned when the string was not found. + * + * + */ +JSBool ControlWithItems::findString(JSContext *cx, + JSObject *obj, + uintN WXUNUSED(argc), + jsval *argv, + jsval *rval) +{ + wxControlWithItems *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + wxString search; + FromJS(cx, argv[0], search); + *rval = ToJS(cx, p->FindString(search)); + return JS_TRUE; +} + +/*** + * + * + * + * + * + * + * Inserts the item into the list before pos. Not valid + * for wxListBox.SORT or wxComboBox.SORT styles, use Append instead. + * The returned value is the index of the new inserted item. + * + * + */ +JSBool ControlWithItems::insert(JSContext *cx, + JSObject *obj, + uintN WXUNUSED(argc), + jsval *argv, + jsval *rval) +{ + wxControlWithItems *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + int pos; + if ( ! FromJS(cx, argv[1], pos) ) + return JS_FALSE; + + wxString item; + FromJS(cx, argv[0], item); + *rval = ToJS(cx, p->Insert(item, pos)); + + return JS_TRUE; +} Property changes on: ps/trunk/source/tools/atlas/wxJS/gui/control/ctrlitem.cpp ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/gui/control/scrollwnd.h =================================================================== --- ps/trunk/source/tools/atlas/wxJS/gui/control/scrollwnd.h (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/gui/control/scrollwnd.h (revision 5154) @@ -0,0 +1,80 @@ +/* + * wxJavaScript - scrollwnd.h + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: scrollwnd.h 692 2007-05-02 21:30:16Z fbraem $ + */ +#ifndef _WXJSScrolledWindow_H +#define _WXJSScrolledWindow_H + +#include + +namespace wxjs +{ + namespace gui + { + class ScrolledWindow : public ApiWrapper + { + public: + + static bool AddProperty(wxScrolledWindow *p, + JSContext *cx, + JSObject *obj, + const wxString &prop, + jsval *vp); + static bool DeleteProperty(wxScrolledWindow *p, + JSContext* cx, + JSObject* obj, + const wxString &prop); + static bool GetProperty(wxScrolledWindow *p, + JSContext *cx, + JSObject *obj, + int id, + jsval *vp); + + static wxScrolledWindow* Construct(JSContext *cx, + JSObject *obj, + uintN argc, + jsval *argv, + bool constructing); + WXJS_DECLARE_PROPERTY_MAP() + enum + { + P_SCROLL_PIXELS_PER_UNIT = WXJS_START_PROPERTY_ID + , P_VIEW_START + , P_VIRTUAL_SIZE + , P_RETAINED + }; + + WXJS_DECLARE_METHOD_MAP() + WXJS_DECLARE_METHOD(create) + WXJS_DECLARE_METHOD(calcScrolledPosition) + WXJS_DECLARE_METHOD(calcUnscrolledPosition) + WXJS_DECLARE_METHOD(enableScrolling) + WXJS_DECLARE_METHOD(getScrollPixelsPerUnit) + WXJS_DECLARE_METHOD(scroll) + WXJS_DECLARE_METHOD(setScrollbars) + WXJS_DECLARE_METHOD(setScrollRate) + WXJS_DECLARE_METHOD(setTargetWindow) + }; + }; // namespace gui +}; //namespace wxjs +#endif //_WXJSScrolledWindow_H Property changes on: ps/trunk/source/tools/atlas/wxJS/gui/control/scrollwnd.h ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/gui/control/chklstbx.cpp =================================================================== --- ps/trunk/source/tools/atlas/wxJS/gui/control/chklstbx.cpp (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/gui/control/chklstbx.cpp (revision 5154) @@ -0,0 +1,328 @@ +#include "precompiled.h" + +/* + * wxJavaScript - chklstbx.cpp + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: chklstbx.cpp 711 2007-05-14 20:59:29Z fbraem $ + */ + +#ifndef WX_PRECOMP + #include +#endif + +#include "../../common/main.h" +#include "../../common/strsptr.h" +#include "../../common/index.h" + +#include "../event/jsevent.h" +#include "../event/command.h" + +#include "chklstbx.h" +#include "chklstbxchk.h" +#include "window.h" +#include "listbox.h" + +#include "../misc/point.h" +#include "../misc/size.h" +#include "../misc/validate.h" +#include "../errors.h" + +using namespace wxjs; +using namespace wxjs::gui; + +/*** + * control/chklstbx + * gui + * + * A checklistbox is like a listbox, but allows items to be checked + * or unchecked. + * + */ +WXJS_INIT_CLASS(CheckListBox, "wxCheckListBox", 2) + +void CheckListBox::InitClass(JSContext* WXUNUSED(cx), + JSObject* WXUNUSED(obj), + JSObject* WXUNUSED(proto)) +{ + CheckListBoxEventHandler::InitConnectEventMap(); +} + +/*** + * + * + * Array with @wxCheckListBoxItem elements. + * Use it to check/uncheck a specific item. + * + * + */ +WXJS_BEGIN_PROPERTY_MAP(CheckListBox) + WXJS_PROPERTY(P_CHECKED, "checked") +WXJS_END_PROPERTY_MAP() + +bool CheckListBox::GetProperty(wxCheckListBox* WXUNUSED(p), + JSContext *cx, + JSObject *obj, + int id, + jsval *vp) +{ + if ( id == P_CHECKED ) + { + *vp = CheckListBoxItem::CreateObject(cx, new Index(0), obj); + } + return true; +} + +bool CheckListBox::AddProperty(wxCheckListBox *p, + JSContext* WXUNUSED(cx), + JSObject* WXUNUSED(obj), + const wxString &prop, + jsval* WXUNUSED(vp)) +{ + if ( WindowEventHandler::ConnectEvent(p, prop, true) ) + return true; + + if ( ListBoxEventHandler::ConnectEvent(p, prop, true) ) + return true; + + CheckListBoxEventHandler::ConnectEvent(p, prop, true); + return true; +} + + +bool CheckListBox::DeleteProperty(wxCheckListBox *p, + JSContext* WXUNUSED(cx), + JSObject* WXUNUSED(obj), + const wxString &prop) +{ + if ( WindowEventHandler::ConnectEvent(p, prop, false) ) + return true; + + if ( ListBoxEventHandler::ConnectEvent(p, prop, false) ) + return true; + + CheckListBoxEventHandler::ConnectEvent(p, prop, false); + return true; +} + +/*** + * + * + * + * The parent of this control + * + * A window identifier. Use -1 when you don't need it. + * + * + * The position of the CheckListBox control on the given parent. + * + * + * The size of the CheckListBox control. + * + * + * An array of Strings to initialize the control + * + * + * The wxCheckListBox style. + * + * A validator + * + * + * Constructs a new wxCheckListBox object. + * + * + */ +wxCheckListBox* CheckListBox::Construct(JSContext *cx, + JSObject *obj, + uintN argc, + jsval *argv, + bool WXUNUSED(constructing)) +{ + wxCheckListBox *p = new wxCheckListBox(); + SetPrivate(cx, obj, p); + + if ( argc > 0 ) + { + jsval rval; + create(cx, obj, argc, argv, &rval); + } + return p; +} + +WXJS_BEGIN_METHOD_MAP(CheckListBox) + WXJS_METHOD("create", create, 2) +WXJS_END_METHOD_MAP() + +/*** + * + * + * The parent of this control + * + * A window identifier. Use -1 when you don't need it. + * + * + * The position of the CheckListBox control on the given parent. + * + * + * The size of the CheckListBox control. + * + * + * An array of Strings to initialize the control + * + * + * The wxCheckListBox style. + * + * A validator + * + * + * Creates wxCheckListBox. + * + * + */ +JSBool CheckListBox::create(JSContext *cx, + JSObject *obj, + uintN argc, + jsval *argv, + jsval *rval) +{ + wxCheckListBox *p = GetPrivate(cx, obj); + *rval = JSVAL_FALSE; + + const wxPoint *pt = &wxDefaultPosition; + const wxSize *size = &wxDefaultSize; + int style = 0; + StringsPtr items; + const wxValidator *val = &wxDefaultValidator; + + if ( argc > 7 ) + argc = 7; + + switch(argc) + { + case 7: + val = Validator::GetPrivate(cx, argv[6]); + if ( val == NULL ) + { + JS_ReportError(cx, WXJS_INVALID_ARG_TYPE, 7, "wxValidator"); + return JS_FALSE; + } + case 6: + if ( ! FromJS(cx, argv[5], style) ) + { + JS_ReportError(cx, WXJS_INVALID_ARG_TYPE, 6, "Integer"); + return JS_FALSE; + } + case 5: + if ( ! FromJS(cx, argv[4], items) ) + { + JS_ReportError(cx, WXJS_INVALID_ARG_TYPE, 5, "Array"); + return JS_FALSE; + } + // Fall through + case 4: + size = Size::GetPrivate(cx, argv[3]); + if ( size == NULL ) + { + JS_ReportError(cx, WXJS_INVALID_ARG_TYPE, 4, "wxSize"); + return JS_FALSE; + } + // Fall through + case 3: + pt = Point::GetPrivate(cx, argv[2]); + if ( pt == NULL ) + { + JS_ReportError(cx, WXJS_INVALID_ARG_TYPE, 3, "wxPoint"); + return JS_FALSE; + } + // Fall through + default: + int id; + if ( ! FromJS(cx, argv[1], id) ) + { + JS_ReportError(cx, WXJS_INVALID_ARG_TYPE, 2, "Integer"); + return JS_FALSE; + } + + wxWindow *parent = Window::GetPrivate(cx, argv[0]); + if ( parent == NULL ) + { + JS_ReportError(cx, WXJS_NO_PARENT_ERROR, GetClass()->name); + return JS_FALSE; + } + JavaScriptClientData *clntParent = + dynamic_cast(parent->GetClientObject()); + if ( clntParent == NULL ) + { + JS_ReportError(cx, WXJS_NO_PARENT_ERROR, GetClass()->name); + return JS_FALSE; + } + JS_SetParent(cx, obj, clntParent->GetObject()); + + // Don't forget the wxLB_OWNERDRAW, + // because Create is called on wxListBox + if ( p->Create(parent, id, *pt, *size, + items.GetCount(), items.GetStrings(), + style | wxLB_OWNERDRAW, *val) ) + { + *rval = JSVAL_TRUE; + p->SetClientObject(new JavaScriptClientData(cx, obj, true, false)); + } + } + + return JS_TRUE; +} + +/*** + * + * + * Called when an item is checked or unchecked. + * The function that is called gets a @wxCommandEvent + * object. + * + */ + +WXJS_INIT_EVENT_MAP(wxCheckListBox) +const wxString WXJS_CHECKLISTBOX_EVENT = wxT("onCheckListBox"); + +void CheckListBoxEventHandler::OnCheckListBox(wxCommandEvent &event) +{ + PrivCommandEvent::Fire(event, WXJS_CHECKLISTBOX_EVENT); +} + +void CheckListBoxEventHandler::ConnectCheckListBox(wxCheckListBox *p, + bool connect) +{ + if ( connect ) + { + p->Connect(wxEVT_COMMAND_CHECKLISTBOX_TOGGLED, + wxCommandEventHandler(OnCheckListBox)); + } + else + { + p->Disconnect(wxEVT_COMMAND_CHECKLISTBOX_TOGGLED, + wxCommandEventHandler(OnCheckListBox)); + } +} + +void CheckListBoxEventHandler::InitConnectEventMap() +{ + AddConnector(WXJS_CHECKLISTBOX_EVENT, ConnectCheckListBox); +} Property changes on: ps/trunk/source/tools/atlas/wxJS/gui/control/chklstbx.cpp ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/gui/control/findrdlg.cpp =================================================================== --- ps/trunk/source/tools/atlas/wxJS/gui/control/findrdlg.cpp (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/gui/control/findrdlg.cpp (revision 5154) @@ -0,0 +1,386 @@ +#include "precompiled.h" + +/* + * wxJavaScript - findrdlg.cpp + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: findrdlg.cpp 682 2007-04-24 20:38:18Z fbraem $ + */ +// findrdlg.cpp + +#ifndef WX_PRECOMP + #include +#endif + +#include "../../common/main.h" + +#include "../event/jsevent.h" +#include "../event/findr.h" + +#include "findrdlg.h" +#include "finddata.h" +#include "window.h" + +#include "../errors.h" + +using namespace wxjs; +using namespace wxjs::gui; + +/*** + * control/findrdlg + * gui + * + * wxFindReplaceDialog is a standard modeless dialog which is used to allow + * the user to search for some text (and possible replace it with something + * else). The actual searching is supposed to be done in the owner window + * which is the parent of this dialog. Note that it means that + * unlike for the other standard dialogs this one must have a parent window. + * Also note that there is no way to use this dialog in a modal way, it is + * always, by design and implementation, modeless. + * + */ +//TODO: add a sample! +WXJS_INIT_CLASS(FindReplaceDialog, "wxFindReplaceDialog", 0) +void FindReplaceDialog::InitClass(JSContext* WXUNUSED(cx), + JSObject* WXUNUSED(obj), + JSObject* WXUNUSED(proto)) +{ + FindReplaceEventHandler::InitConnectEventMap(); +} + +/*** + * + * + * Get/Set the data + * + * + */ +WXJS_BEGIN_PROPERTY_MAP(FindReplaceDialog) + WXJS_PROPERTY(P_DATA, "data") +WXJS_END_PROPERTY_MAP() + +bool FindReplaceDialog::GetProperty(wxFindReplaceDialog* p, + JSContext* cx, + JSObject* WXUNUSED(obj), + int id, + jsval *vp) +{ + if (id == P_DATA ) + { + FindReplaceClientData *data + = dynamic_cast(p->GetClientObject()); + *vp = FindReplaceData::CreateObject(cx, + new wxFindReplaceData(data->m_data)); + } + return true; +} + +bool FindReplaceDialog::AddProperty(wxFindReplaceDialog *p, + JSContext* WXUNUSED(cx), + JSObject* WXUNUSED(obj), + const wxString &prop, + jsval* WXUNUSED(vp)) +{ + if ( WindowEventHandler::ConnectEvent(p, prop, true) ) + return true; + + FindReplaceEventHandler::ConnectEvent(p, prop, true); + + return true; +} + +bool FindReplaceDialog::DeleteProperty(wxFindReplaceDialog *p, + JSContext* WXUNUSED(cx), + JSObject* WXUNUSED(obj), + const wxString &prop) +{ + if ( WindowEventHandler::ConnectEvent(p, prop, false) ) + return true; + + FindReplaceEventHandler::ConnectEvent(p, prop, false); + return true; +} + +/*** + * + * + * + * + * + * + * + * + */ +WXJS_BEGIN_CONSTANT_MAP(FindReplaceDialog) + WXJS_CONSTANT(wxFR_, REPLACEDIALOG) + WXJS_CONSTANT(wxFR_, NOUPDOWN) + WXJS_CONSTANT(wxFR_, NOMATCHCASE) + WXJS_CONSTANT(wxFR_, NOWHOLEWORD) +WXJS_END_CONSTANT_MAP() + +/*** + * + * + * + * The parent of wxFindReplaceDialog. Can't be null. + * + * + * + * The title of the dialog + * + * + * + * + * + * Constructs a new wxFindReplaceDialog object + * + * + */ +wxFindReplaceDialog *FindReplaceDialog::Construct(JSContext *cx, + JSObject *obj, + uintN argc, + jsval *argv, + bool WXUNUSED(constructing)) +{ + wxFindReplaceDialog *p = new wxFindReplaceDialog(); + SetPrivate(cx, obj, p); + + if ( argc > 0 ) + { + jsval rval; + create(cx, obj, argc, argv, &rval); + } + + return p; +} + +WXJS_BEGIN_METHOD_MAP(FindReplaceDialog) + WXJS_METHOD("create", create, 4) +WXJS_END_METHOD_MAP() + +/*** + * + * + * + * The parent of wxFindReplaceDialog. Can't be null. + * + * + * + * The title of the dialog + * + * + * + * + * Creates a wxFindReplaceDialog. + * + * + */ +JSBool FindReplaceDialog::create(JSContext *cx, + JSObject *obj, + uintN argc, + jsval *argv, + jsval *rval) +{ + wxFindReplaceDialog *p = FindReplaceDialog::GetPrivate(cx, obj); + *rval = JSVAL_FALSE; + + if ( argc > 4 ) + argc = 4; + + int style = 0; + if ( argc == 4 ) + { + if ( ! FromJS(cx, argv[3], style) ) + { + JS_ReportError(cx, WXJS_INVALID_ARG_TYPE, 4, "Integer"); + return JS_FALSE; + } + } + + wxString title; + FromJS(cx, argv[2], title); + + wxFindReplaceData *data = FindReplaceData::GetPrivate(cx, argv[1]); + if ( data == NULL ) + { + JS_ReportError(cx, WXJS_INVALID_ARG_TYPE, 2, "wxFindReplaceData"); + return JS_FALSE; + } + + wxWindow *parent = Window::GetPrivate(cx, argv[0]); + if ( parent == NULL ) + { + JS_ReportError(cx, WXJS_NO_PARENT_ERROR, GetClass()->name); + return JS_FALSE; + } + + if ( p->Create(parent, data, title, style) ) + { + FindReplaceClientData *clntData = new FindReplaceClientData(cx, obj, + true, false); + p->SetClientObject(clntData); + // Copy the data + clntData->m_data.SetFlags(data->GetFlags()); + clntData->m_data.SetFindString(data->GetFindString()); + clntData->m_data.SetReplaceString(data->GetReplaceString()); + *rval = JSVAL_TRUE; + p->SetClientObject(new JavaScriptClientData(cx, obj, true, false)); + } + + return JS_TRUE; +} + +/*** + * + * + * The find button was pressed. + * The argument passed to the function is a @wxFindDialogEvent + * + * + * The find next button was pressed. + * The argument passed to the function is a @wxFindDialogEvent + * + * + * The replace button was pressed. + * The argument passed to the function is a @wxFindDialogEvent + * + * + * The replace all button was pressed. + * The argument passed to the function is a @wxFindDialogEvent + * + * + * The dialog is being destroyed. + * The argument passed to the function is a @wxFindDialogEvent + * + * + */ + +WXJS_INIT_EVENT_MAP(wxFindReplaceDialog) +const wxString WXJS_FIND_EVENT = wxT("onFind"); +const wxString WXJS_FIND_NEXT_EVENT = wxT("onFindNext"); +const wxString WXJS_FIND_REPLACE_EVENT = wxT("onFindReplace"); +const wxString WXJS_FIND_REPLACE_ALL_EVENT = wxT("onFindReplaceAll"); +const wxString WXJS_FIND_CLOSE_EVENT = wxT("onFindClose"); + +void FindReplaceEventHandler::OnFind(wxFindDialogEvent& event) +{ + PrivFindDialogEvent::Fire(event, WXJS_FIND_EVENT); +} + +void FindReplaceEventHandler::OnFindNext(wxFindDialogEvent& event) +{ + PrivFindDialogEvent::Fire(event, WXJS_FIND_NEXT_EVENT); +} + +void FindReplaceEventHandler::OnReplace(wxFindDialogEvent& event) +{ + PrivFindDialogEvent::Fire(event, WXJS_FIND_REPLACE_EVENT); +} + +void FindReplaceEventHandler::OnReplaceAll(wxFindDialogEvent& event) +{ + PrivFindDialogEvent::Fire(event, + WXJS_FIND_REPLACE_ALL_EVENT); +} + +void FindReplaceEventHandler::OnFindClose(wxFindDialogEvent& event) +{ + PrivFindDialogEvent::Fire(event, WXJS_FIND_CLOSE_EVENT); + //Destroy(); +} + +void FindReplaceEventHandler::ConnectFind(wxFindReplaceDialog *p, bool connect) +{ + if ( connect ) + { + p->Connect(wxEVT_COMMAND_FIND, wxFindDialogEventHandler(OnFind)); + } + else + { + p->Disconnect(wxEVT_COMMAND_FIND, wxFindDialogEventHandler(OnFind)); + } +} + +void FindReplaceEventHandler::ConnectFindNext(wxFindReplaceDialog *p, + bool connect) +{ + if ( connect ) + { + p->Connect(wxEVT_COMMAND_FIND_NEXT, wxFindDialogEventHandler(OnFindNext)); + } + else + { + p->Disconnect(wxEVT_COMMAND_FIND_NEXT, + wxFindDialogEventHandler(OnFindNext)); + } +} + +void FindReplaceEventHandler::ConnectReplace(wxFindReplaceDialog *p, + bool connect) +{ + if ( connect ) + { + p->Connect(wxEVT_COMMAND_FIND_REPLACE, wxFindDialogEventHandler(OnReplace)); + } + else + { + p->Disconnect(wxEVT_COMMAND_FIND_REPLACE, + wxFindDialogEventHandler(OnReplace)); + } +} + +void FindReplaceEventHandler::ConnectReplaceAll(wxFindReplaceDialog *p, + bool connect) +{ + if ( connect ) + { + p->Connect(wxEVT_COMMAND_FIND_REPLACE_ALL, + wxFindDialogEventHandler(OnReplaceAll)); + } + else + { + p->Disconnect(wxEVT_COMMAND_FIND_REPLACE_ALL, + wxFindDialogEventHandler(OnReplaceAll)); + } +} + +void FindReplaceEventHandler::ConnectFindClose(wxFindReplaceDialog *p, + bool connect) +{ + if ( connect ) + { + p->Connect(wxEVT_COMMAND_FIND_CLOSE, wxFindDialogEventHandler(OnFindClose)); + } + else + { + p->Disconnect(wxEVT_COMMAND_FIND_CLOSE, + wxFindDialogEventHandler(OnFindClose)); + } +} + +void FindReplaceEventHandler::InitConnectEventMap() +{ + AddConnector(WXJS_FIND_EVENT, ConnectFind); + AddConnector(WXJS_FIND_NEXT_EVENT, ConnectFindNext); + AddConnector(WXJS_FIND_REPLACE_EVENT, ConnectReplace); + AddConnector(WXJS_FIND_REPLACE_ALL_EVENT, ConnectReplaceAll); + AddConnector(WXJS_FIND_CLOSE_EVENT, ConnectFindClose); +} Property changes on: ps/trunk/source/tools/atlas/wxJS/gui/control/findrdlg.cpp ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/gui/control/frame.cpp =================================================================== --- ps/trunk/source/tools/atlas/wxJS/gui/control/frame.cpp (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/gui/control/frame.cpp (revision 5154) @@ -0,0 +1,907 @@ +#include "precompiled.h" + +/* + * wxJavaScript - frame.cpp + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: frame.cpp 708 2007-05-14 15:30:45Z fbraem $ + */ +#ifndef WX_PRECOMP + #include +#endif + +#include "../../common/main.h" + +#include "../event/jsevent.h" +#include "../event/command.h" +#include "../event/close.h" +#include "../event/iconize.h" + +#include "../misc/point.h" +#include "../misc/size.h" +#include "../misc/icon.h" +#include "../misc/app.h" +#include "../misc/constant.h" +#include "../errors.h" + +#include "menubar.h" +#include "menu.h" +#include "frame.h" +#include "window.h" +#include "statbar.h" +#include "toolbar.h" + +using namespace wxjs; +using namespace wxjs::gui; + +wxToolBar* Frame::OnCreateToolBar(long style, + wxWindowID id, + const wxString& name) +{ + ToolBar *tbar = new ToolBar(); + tbar->Create(this, id, wxDefaultPosition, wxDefaultSize, style, name); + return tbar; +} + +/*** + * control/frame + * gui + * + * A frame is a window whose size and position can (usually) be changed by + * the user. It usually has thick borders and a title bar, and can optionally + * contain a menu bar, toolbar and status bar. A frame can contain any window + * that is not a frame or dialog. + * + */ +WXJS_INIT_CLASS(Frame, "wxFrame", 3) +void Frame::InitClass(JSContext* WXUNUSED(cx), + JSObject* WXUNUSED(obj), + JSObject* WXUNUSED(proto)) +{ + FrameEventHandler::InitConnectEventMap(); +} + +/*** + * + * + * Set/Get the menubar + * + * + * Set/Get the statusbar + * + * + * Set/Get the number of statusbar fields. A statusbar + * is created when there isn't a statusbar created yet. + * + * + * Set/Get the pane used to display menu and toolbar help. -1 + * disables help display. + * + * + * Set/Get the toolbar + * + * + */ +WXJS_BEGIN_PROPERTY_MAP(Frame) + WXJS_PROPERTY(P_STATUSBAR, "statusBar") + WXJS_PROPERTY(P_TOOLBAR, "toolBar") + WXJS_PROPERTY(P_MENUBAR, "menuBar") + WXJS_PROPERTY(P_STATUSBAR_FIELDS, "statusBarFields") + WXJS_PROPERTY(P_STATUSBAR_PANE, "statusBarPane") +WXJS_END_PROPERTY_MAP() + +bool Frame::GetProperty(wxFrame* p, + JSContext* cx, + JSObject* WXUNUSED(obj), + int id, + jsval* vp) +{ + switch(id) + { + case P_MENUBAR: + { + wxMenuBar *bar = p->GetMenuBar(); + if ( bar != NULL ) + { + JavaScriptClientData *data + = dynamic_cast(bar->GetClientObject()); + *vp = OBJECT_TO_JSVAL(data->GetObject()); + } + else + { + *vp = JSVAL_VOID; + } + break; + } + case P_STATUSBAR: + { + wxStatusBar *bar = p->GetStatusBar(); + if ( bar != NULL ) + { + JavaScriptClientData *data + = dynamic_cast(bar->GetClientObject()); + *vp = OBJECT_TO_JSVAL(data->GetObject()); + } + else + { + *vp = JSVAL_VOID; + } + break; + } + case P_TOOLBAR: + { + wxToolBar *bar = p->GetToolBar(); + if ( bar != NULL ) + { + JavaScriptClientData *data + = dynamic_cast(bar->GetClientObject()); + *vp = OBJECT_TO_JSVAL(data->GetObject()); + } + else + { + *vp = JSVAL_VOID; + } + break; + } + case P_STATUSBAR_FIELDS: + { + wxStatusBar *statusBar = p->GetStatusBar(); + if ( statusBar == NULL ) + { + *vp = ToJS(cx, 0); + } + else + { + *vp = ToJS(cx, statusBar->GetFieldsCount()); + } + break; + } + case P_STATUSBAR_PANE: + *vp = ToJS(cx, p->GetStatusBarPane()); + break; + } + return true; +} + +bool Frame::SetProperty(wxFrame* p, + JSContext* cx, + JSObject* WXUNUSED(obj), + int id, + jsval* vp) +{ + switch(id) + { + case P_MENUBAR: + { + if ( JSVAL_IS_OBJECT(*vp) ) + { + JSObject *jsMenuBar = JSVAL_TO_OBJECT(*vp); + wxMenuBar *menuBar = MenuBar::GetPrivate(cx, jsMenuBar); + if ( menuBar != NULL ) + { + p->SetMenuBar(menuBar); + menuBar->SetClientObject(new JavaScriptClientData(cx, jsMenuBar, true, false)); + break; + } + } + } + case P_STATUSBAR: + { + wxStatusBar *bar = StatusBar::GetPrivate(cx, *vp); + if ( bar != NULL ) + p->SetStatusBar(bar); + break; + } + case P_TOOLBAR: + { + wxToolBar *bar = ToolBar::GetPrivate(cx, *vp); + if ( bar != NULL ) + p->SetToolBar(bar); + break; + } + case P_STATUSBAR_FIELDS: + { + wxStatusBar *statusBar = p->GetStatusBar(); + int fields; + if ( FromJS(cx, *vp, fields) + && fields > 0 ) + { + if ( statusBar == (wxStatusBar*) NULL ) + { + p->CreateStatusBar(fields); + } + else + { + statusBar->SetFieldsCount(fields); + } + } + break; + } + case P_STATUSBAR_PANE: + { + int pane; + if ( FromJS(cx, *vp, pane) ) + p->SetStatusBarPane(pane); + break; + } + } + return true; +} + +bool Frame::AddProperty(wxFrame *p, + JSContext* WXUNUSED(cx), + JSObject* WXUNUSED(obj), + const wxString &prop, + jsval* WXUNUSED(vp)) +{ + if ( WindowEventHandler::ConnectEvent(p, prop, true) ) + return true; + + FrameEventHandler::ConnectEvent(p, prop, true); + + return true; +} + + +bool Frame::DeleteProperty(wxFrame *p, + JSContext* WXUNUSED(cx), + JSObject* WXUNUSED(obj), + const wxString &prop) +{ + if ( WindowEventHandler::ConnectEvent(p, prop, false) ) + return true; + + FrameEventHandler::ConnectEvent(p, prop, false); + + return true; +} + +/*** + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + */ +WXJS_BEGIN_CONSTANT_MAP(Frame) + // Style constants + WXJS_CONSTANT(wx, DEFAULT_FRAME_STYLE) + WXJS_CONSTANT(wx, ICONIZE) + WXJS_CONSTANT(wx, CAPTION) + WXJS_CONSTANT(wx, MINIMIZE) + WXJS_CONSTANT(wx, MINIMIZE_BOX) + WXJS_CONSTANT(wx, MAXIMIZE) + WXJS_CONSTANT(wx, MAXIMIZE_BOX) + WXJS_CONSTANT(wx, STAY_ON_TOP) + WXJS_CONSTANT(wx, SYSTEM_MENU) + WXJS_CONSTANT(wx, SIMPLE_BORDER) + WXJS_CONSTANT(wx, RESIZE_BORDER) + WXJS_CONSTANT(wx, FRAME_FLOAT_ON_PARENT) + WXJS_CONSTANT(wx, FRAME_TOOL_WINDOW) +WXJS_END_CONSTANT_MAP() + +/*** + * + * + * + * + * The parent of the wxFrame. Pass null, when you don't have a parent. + * + * + * The windows identifier. -1 can be used when you don't need a unique id. + * + * + * The caption of the frame. + * + * + * The position of the frame. + * + * + * The size of the frame. + * + * + * The style of the frame. + * + * + * + * Creates a new wxFrame object + * + * + */ +wxFrame* Frame::Construct(JSContext* cx, + JSObject* obj, + uintN argc, + jsval* argv, + bool WXUNUSED(constructing)) +{ + Frame *p = new Frame(); + SetPrivate(cx, obj, p); + + if ( argc > 0 ) + { + jsval rval; + create(cx, obj, argc, argv, &rval); + } + return p; +} + +WXJS_BEGIN_METHOD_MAP(Frame) + WXJS_METHOD("create", create, 3) + WXJS_METHOD("processCommand", processCommand, 1) + WXJS_METHOD("createStatusBar", createStatusBar, 0) + WXJS_METHOD("setStatusText", setStatusText, 1) + WXJS_METHOD("setStatusWidths", setStatusWidths, 1) + WXJS_METHOD("createToolBar", createToolBar, 0) +WXJS_END_METHOD_MAP() + +/*** + * + * + * + * The parent of the wxFrame. Pass null, when you don't have a parent. + * + * + * The windows identifier. -1 can be used when you don't need a unique id. + * + * + * The caption of the frame. + * + * + * The position of the frame. + * + * + * The size of the frame. + * + * + * The style of the frame. + * + * + * + * Creates a new wxFrame object + * + * + */ +JSBool Frame::create(JSContext *cx, + JSObject *obj, + uintN argc, + jsval *argv, + jsval *rval) +{ + wxFrame *p = GetPrivate(cx, obj); + *rval = JSVAL_FALSE; + if ( argc > 6 ) + argc = 6; + + int style = wxDEFAULT_FRAME_STYLE; + const wxPoint *pt = &wxDefaultPosition; + const wxSize *size = &wxDefaultSize; + + switch(argc) + { + case 6: + if ( ! FromJS(cx, argv[5], style) ) + { + JS_ReportError(cx, WXJS_INVALID_ARG_TYPE, 6, "Integer"); + return JS_FALSE; + } + // Fall through + case 5: + size = Size::GetPrivate(cx, argv[4]); + if ( size == NULL ) + { + JS_ReportError(cx, WXJS_INVALID_ARG_TYPE, 5, "wxSize"); + return JS_FALSE; + } + // Fall through + case 4: + pt = Point::GetPrivate(cx, argv[3]); + if ( pt == NULL ) + { + JS_ReportError(cx, WXJS_INVALID_ARG_TYPE, 4, "wxPoint"); + return JS_FALSE; + } + // Fall through + default: + wxString title; + FromJS(cx, argv[2], title); + + int id; + if ( ! FromJS(cx, argv[1], id) ) + { + JS_ReportError(cx, WXJS_INVALID_ARG_TYPE, 2, "Integer"); + return JS_FALSE; + } + + wxWindow *parent = Window::GetPrivate(cx, argv[0]); + if ( parent != NULL ) + { + JavaScriptClientData *clntParent = + dynamic_cast(parent->GetClientObject()); + if ( clntParent == NULL ) + { + JS_ReportError(cx, WXJS_NO_PARENT_ERROR, GetClass()->name); + return JS_FALSE; + } + JS_SetParent(cx, obj, clntParent->GetObject()); + } + + if ( p->Create(parent, id, title, *pt, *size, style) ) + { + *rval = JSVAL_TRUE; + p->SetClientObject(new JavaScriptClientData(cx, obj, true, false)); + p->Connect(wxID_ANY, wxID_ANY, wxEVT_COMMAND_MENU_SELECTED, + wxCommandEventHandler(FrameEventHandler::OnMenu)); + } + } + + return JS_TRUE; +} + +/*** + * + * + * + * Identifier of a menu. + * + * + * + * Simulates a menu command. + * + * + */ +JSBool Frame::processCommand(JSContext *cx, + JSObject *obj, + uintN WXUNUSED(argc), + jsval *argv, + jsval* WXUNUSED(rval)) +{ + wxFrame *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + +#ifdef __WXMSW__ + if ( p->GetHWND() == NULL ) + { + JS_ReportError(cx, "%s is not yet created", GetClass()->name); + return JS_FALSE; + } +#endif + + int id; + if ( ! FromJS(cx, argv[0], id) ) + return JS_FALSE; + + p->ProcessCommand(id); + + return JS_TRUE; +} + +/*** + * + * + * + * The number of fields. Default is 1. + * + * + * The style of the statusbar. + * + * + * A unique id for the statusbar. + * + * + * + * Creates a status bar at the bottom of the frame. + *
Remark: + * The width of the status bar is the whole width of the frame + * (adjusted automatically when resizing), and the height and text size + * are chosen by the host windowing system + *
+ *
+ */ +JSBool Frame::createStatusBar(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxFrame *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + +#ifdef __WXMSW__ + if ( p->GetHWND() == NULL ) + { + JS_ReportError(cx, "%s is not yet created", GetClass()->name); + return JS_FALSE; + } +#endif + + int fields = 1; + long style = 0; + int id = -1; + + switch(argc) + { + case 3: + if ( ! FromJS(cx, argv[2], id) ) + return JS_FALSE; + // Fall through + case 2: + if ( ! FromJS(cx, argv[1], style) ) + return JS_FALSE; + // Fall through + case 1: + if ( ! FromJS(cx, argv[0], fields) ) + return JS_FALSE; + // Fall through + } + + wxStatusBar *bar = p->CreateStatusBar(fields, style, id); + if ( bar ) + { + *rval = StatusBar::CreateObject(cx, bar, obj); + JSObject *obj = JSVAL_TO_OBJECT(*rval); + bar->SetClientObject(new JavaScriptClientData(cx, obj, true, false)); + } + else + { + *rval = JSVAL_VOID; + } + + return JS_TRUE; +} + +/*** + * + * + * + * The toolbar style + * + * + * A unique id for the toolbar + * + * + * + * Creates a toolbar at the top or left of the frame. + * + * + */ +JSBool Frame::createToolBar(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxFrame *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + +#ifdef __WXMSW__ + if ( p->GetHWND() == NULL ) + { + JS_ReportError(cx, "%s is not yet created", GetClass()->name); + return JS_FALSE; + } +#endif + + long style = wxNO_BORDER | wxTB_HORIZONTAL; + int id = -1; + + switch(argc) + { + case 2: + if ( ! FromJS(cx, argv[1], id) ) + return JS_FALSE; + // Fall through + case 1: + if ( ! FromJS(cx, argv[0], style) ) + return JS_FALSE; + // Fall through + } + + wxToolBar *bar = p->CreateToolBar(style, id); + if ( bar == NULL ) + { + *rval = JSVAL_VOID; + } + else + { + *rval = ToolBar::CreateObject(cx, bar, obj); + JSObject *obj = JSVAL_TO_OBJECT(*rval); + bar->SetClientObject(new JavaScriptClientData(cx, obj, true, false)); + bar->Connect(wxID_ANY, wxID_ANY, wxEVT_COMMAND_TOOL_CLICKED, + wxCommandEventHandler(ToolEventHandler::OnTool)); + } + return JS_TRUE; +} + +/*** + * + * + * + * The text to set in the status field + * + * + * The number of the field (zero indexed) + * + * + * + * Sets the text of the given status field. When no field is specified, + * the first one is used. + * + * + */ +JSBool Frame::setStatusText(JSContext *cx, + JSObject *obj, + uintN argc, + jsval *argv, + jsval* WXUNUSED(rval)) +{ + wxFrame *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + +#ifdef __WXMSW__ + if ( p->GetHWND() == NULL ) + { + JS_ReportError(cx, "%s is not yet created", GetClass()->name); + return JS_FALSE; + } +#endif + + wxStatusBar *statusBar = p->GetStatusBar(); + if ( statusBar != (wxStatusBar*) NULL ) + { + wxString text; + FromJS(cx, argv[0], text); + + int field = 0; + if ( argc == 2 + && ! FromJS(cx, argv[1], field) ) + return JS_FALSE; + + if ( field >= 0 + && field < statusBar->GetFieldsCount() ) + { + p->SetStatusText(text, field); + } + } + + return JS_TRUE; +} + +/*** + * + * + * + * Contains an array of status field width in pixels. + * A value of -1 indicates that the field is variable width. + * At least one field must be -1. + * + * + * + * Sets the widths of the fields in the status bar. + * When the array contains more elements then fields, + * those elements are discarded. See also @wxStatusBar#statusWidths. + * + * + */ +JSBool Frame::setStatusWidths(JSContext *cx, + JSObject *obj, + uintN WXUNUSED(argc), + jsval *argv, + jsval* WXUNUSED(rval)) +{ + wxFrame *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + +#ifdef __WXMSW__ + if ( p->GetHWND() == NULL ) + { + JS_ReportError(cx, "%s is not yet created", GetClass()->name); + return JS_FALSE; + } +#endif + + wxStatusBar *statusBar = p->GetStatusBar(); + if ( statusBar == (wxStatusBar*) NULL ) + return JS_TRUE; + + if ( JSVAL_IS_OBJECT(argv[0]) ) + { + JSObject *obj = JSVAL_TO_OBJECT(argv[0]); + if ( JS_IsArrayObject(cx, obj) == JS_TRUE ) + { + jsuint length = 0; + JS_GetArrayLength(cx, obj, &length); + uint fields = statusBar->GetFieldsCount(); + if ( length > fields ) + length = fields; + int *widths = new int[length]; + for(jsuint i =0; i < length; i++) + { + jsval element; + JS_GetElement(cx, obj, i, &element); + if ( ! FromJS(cx, element, widths[i]) ) + { + delete[] widths; + return JS_FALSE; + } + } + p->SetStatusWidths(length, widths); + delete[] widths; + } + } + return JS_TRUE; +} + +/*** + * + * + * Called when the frame is closed. The type of the argument that your + * handler receives is @wxCloseEvent. + * + * + * An event being sent when the frame is iconized (minimized). + * Currently only wxMSW and wxGTK generate such events. + * The type of the argument that your handler receives + * is @wxIconizeEvent. When you handle this event, + * don't forget to set @wxEvent#skip to true. + * Otherwise the frame will not be iconized. + * + * + * An event being sent when the frame is maximized. + * The type of the argument that your handler receives + * is @wxMaximizeEvent. When you handle this event, + * don't forget to set @wxEvent#skip to true. + * Otherwise the frame will not be maximized. + * + * + */ + +WXJS_INIT_EVENT_MAP(wxFrame) +const wxString WXJS_CLOSE_EVENT = wxT("onClose"); +const wxString WXJS_ICONIZE_EVENT = wxT("onIconize"); +const wxString WXJS_MAXIMIZE_EVENT = wxT("onMaximize"); + +void FrameEventHandler::OnMenu(wxCommandEvent &event) +{ + wxWindow *eventObject = dynamic_cast(event.GetEventObject()); + wxFrame *frame = dynamic_cast(eventObject); + if ( frame == NULL ) + { + // It can be a toolbar + frame = dynamic_cast(eventObject->GetParent()); + if ( frame == NULL ) + return; + } + + JavaScriptClientData *clientData + = dynamic_cast(GetClientObject()); + + wxMenuBar *menuBar = frame->GetMenuBar(); + if ( menuBar == NULL ) + return; + + wxMenuItem *item = menuBar->FindItem(event.GetId()); + if ( item == NULL ) + return; + + wxMenu *menu = item->GetMenu(); + if ( menu == NULL ) + return; + + JavaScriptClientData *menuData + = dynamic_cast(menu->GetClientObject()); + + JSContext *cx = clientData->GetContext(); + + jsval actions; + if ( JS_GetProperty(cx, menuData->GetObject(), "actions", &actions) == JS_TRUE + && JSVAL_IS_OBJECT(actions) + && JS_IsArrayObject(cx, JSVAL_TO_OBJECT(actions)) == JS_TRUE ) + { + jsval element; + if ( JS_GetElement(cx, JSVAL_TO_OBJECT(actions), event.GetId(), &element) == JS_TRUE ) + { + JSFunction *action = JS_ValueToFunction(cx, element); + if ( action != NULL ) + { + PrivCommandEvent *wxjsEvent = new PrivCommandEvent(event); + jsval argv[] = { CommandEvent::CreateObject(cx, wxjsEvent) }; + + jsval rval; + JSBool result = JS_CallFunction(cx, clientData->GetObject(), action, 1, argv, &rval); + if ( result == JS_FALSE ) + { + JS_ReportPendingException(cx); + } + } + } + else + { + event.Skip(); + } + } +} + +void FrameEventHandler::OnClose(wxCloseEvent &event) +{ + PrivCloseEvent::Fire(event, WXJS_CLOSE_EVENT); +} + +void FrameEventHandler::OnIconize(wxIconizeEvent &event) +{ + PrivIconizeEvent::Fire(event, WXJS_ICONIZE_EVENT); +} + +void FrameEventHandler::OnMaximize(wxMaximizeEvent &event) +{ + PrivMaximizeEvent::Fire(event, WXJS_MAXIMIZE_EVENT); +} + +void FrameEventHandler::ConnectClose(wxFrame *p, bool connect) +{ + if ( connect ) + { + p->Connect(wxEVT_CLOSE_WINDOW, wxCloseEventHandler(OnClose)); + } + else + { + p->Disconnect(wxEVT_CLOSE_WINDOW, wxCloseEventHandler(OnClose)); + } +} + +void FrameEventHandler::ConnectIconize(wxFrame *p, bool connect) +{ + if ( connect ) + { + p->Connect(wxEVT_ICONIZE, wxIconizeEventHandler(OnIconize)); + } + else + { + p->Disconnect(wxEVT_ICONIZE, wxIconizeEventHandler(OnIconize)); + } +} + +void FrameEventHandler::ConnectMaximize(wxFrame *p, bool connect) +{ + if ( connect ) + { + p->Connect(wxEVT_MAXIMIZE, wxMaximizeEventHandler(OnMaximize)); + } + else + { + p->Disconnect(wxEVT_MAXIMIZE, wxMaximizeEventHandler(OnMaximize)); + } +} + +void FrameEventHandler::InitConnectEventMap() +{ + AddConnector(WXJS_CLOSE_EVENT, ConnectClose); + AddConnector(WXJS_ICONIZE_EVENT, ConnectIconize); + AddConnector(WXJS_MAXIMIZE_EVENT, ConnectMaximize); +} Property changes on: ps/trunk/source/tools/atlas/wxJS/gui/control/frame.cpp ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/gui/control/checkbox.h =================================================================== --- ps/trunk/source/tools/atlas/wxJS/gui/control/checkbox.h (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/gui/control/checkbox.h (revision 5154) @@ -0,0 +1,91 @@ +/* + * wxJavaScript - checkbox.h + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: checkbox.h 678 2007-04-19 20:12:31Z fbraem $ + */ +#ifndef _WXJSCheckBox_H +#define _WXJSCheckBox_H + +#include "../../common/evtconn.h" + +namespace wxjs +{ + namespace gui + { + class CheckBox : public ApiWrapper + { + public: + + static void InitClass(JSContext* cx, + JSObject* obj, + JSObject* proto); + static bool AddProperty(wxCheckBox *p, + JSContext *cx, + JSObject *obj, + const wxString &prop, + jsval *vp); + static bool DeleteProperty(wxCheckBox *p, + JSContext* cx, + JSObject* obj, + const wxString &prop); + static bool GetProperty(wxCheckBox *p, + JSContext *cx, + JSObject *obj, + int id, + jsval *vp); + static bool SetProperty(wxCheckBox *p, + JSContext *cx, + JSObject *obj, + int id, + jsval *vp); + + static wxCheckBox* Construct(JSContext *cx, + JSObject *obj, + uintN argc, + jsval *argv, + bool constructing); + + WXJS_DECLARE_PROPERTY_MAP() + enum + { + P_VALUE + }; + + WXJS_DECLARE_METHOD_MAP() + WXJS_DECLARE_METHOD(create) + }; + + class CheckBoxEventHandler : public EventConnector + , public wxEvtHandler + { + public: + // Events + void OnCheckBox(wxCommandEvent &event); + static void InitConnectEventMap(); + private: + static void ConnectCheckBox(wxCheckBox *p, bool connect); + }; + + }; // namespace gui +}; // namespace wxjs + +#endif //_WXJSCheckBox_H Property changes on: ps/trunk/source/tools/atlas/wxJS/gui/control/checkbox.h ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/gui/control/findrdlg.h =================================================================== --- ps/trunk/source/tools/atlas/wxJS/gui/control/findrdlg.h (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/gui/control/findrdlg.h (revision 5154) @@ -0,0 +1,117 @@ +/* + * wxJavaScript - findrdlg.h + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: findrdlg.h 682 2007-04-24 20:38:18Z fbraem $ + */ +#ifndef _WXJSFindReplaceDialog_H +#define _WXJSFindReplaceDialog_H + +#include +#include "../../common/evtconn.h" + +namespace wxjs +{ + namespace gui + { + class FindReplaceClientData : public JavaScriptClientData + { + public: + FindReplaceClientData(JSContext *cx, + JSObject *obj, + bool protect, + bool owner = true) + : JavaScriptClientData(cx, obj, protect, owner) + { + } + virtual ~FindReplaceClientData() {} + + // Keep our own data. This is because the wxFindReplaceData object + // can be gc'd by the engine, which results in memory problems. + wxFindReplaceData m_data; + }; + + class FindReplaceDialog : public ApiWrapper + { + public: + static void InitClass(JSContext* cx, + JSObject* obj, + JSObject* proto); + + static bool AddProperty(wxFindReplaceDialog *p, + JSContext *cx, + JSObject *obj, + const wxString &prop, + jsval *vp); + static bool DeleteProperty(wxFindReplaceDialog *p, + JSContext* cx, + JSObject* obj, + const wxString &prop); + static bool GetProperty(wxFindReplaceDialog *p, + JSContext *cx, + JSObject *obj, + int id, + jsval *vp); + + static wxFindReplaceDialog* Construct(JSContext *cx, + JSObject *obj, + uintN argc, + jsval *argv, + bool constructing); + + + WXJS_DECLARE_METHOD_MAP() + WXJS_DECLARE_METHOD(create) + + WXJS_DECLARE_CONSTANT_MAP() + + WXJS_DECLARE_PROPERTY_MAP() + enum + { + P_DATA + }; + + }; + + class FindReplaceEventHandler + : public EventConnector + , public wxEvtHandler + { + public: + // Events + void OnFind(wxFindDialogEvent& event); + void OnFindNext(wxFindDialogEvent& event); + void OnReplace(wxFindDialogEvent& event); + void OnReplaceAll(wxFindDialogEvent& event); + void OnFindClose(wxFindDialogEvent& event); + static void InitConnectEventMap(); + private: + static void ConnectFind(wxFindReplaceDialog *p, bool connect); + static void ConnectFindNext(wxFindReplaceDialog *p, bool connect); + static void ConnectReplace(wxFindReplaceDialog *p, bool connect); + static void ConnectReplaceAll(wxFindReplaceDialog *p, bool connect); + static void ConnectFindClose(wxFindReplaceDialog *p, bool connect); + }; + }; // namespace gui +}; // namespace wxjs + +#endif //_WXJSFindReplaceDialog_H Property changes on: ps/trunk/source/tools/atlas/wxJS/gui/control/findrdlg.h ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/gui/control/choice.h =================================================================== --- ps/trunk/source/tools/atlas/wxJS/gui/control/choice.h (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/gui/control/choice.h (revision 5154) @@ -0,0 +1,91 @@ +/* + * wxJavaScript - choice.h + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: choice.h 678 2007-04-19 20:12:31Z fbraem $ + */ +#ifndef _WXJSChoice_H +#define _WXJSChoice_H + +#include "../../common/evtconn.h" + +namespace wxjs +{ + namespace gui + { + class Choice : public ApiWrapper + { + public: + + static void InitClass(JSContext* cx, + JSObject* obj, + JSObject* proto); + static bool AddProperty(wxChoice *p, + JSContext *cx, + JSObject *obj, + const wxString &prop, + jsval *vp); + static bool DeleteProperty(wxChoice *p, + JSContext* cx, + JSObject* obj, + const wxString &prop); + + static bool GetProperty(wxChoice *p, + JSContext *cx, + JSObject *obj, + int id, + jsval *vp); + static bool SetProperty(wxChoice *p, + JSContext *cx, + JSObject *obj, + int id, + jsval *vp); + + static wxChoice* Construct(JSContext *cx, + JSObject *obj, + uintN argc, + jsval *argv, + bool constructing); + + WXJS_DECLARE_PROPERTY_MAP() + + enum + { + P_COLUMNS + }; + + WXJS_DECLARE_METHOD_MAP() + WXJS_DECLARE_METHOD(create) + }; + + class ChoiceEventHandler : public EventConnector + , public wxEvtHandler + { + public: + // Events + void OnChoice(wxCommandEvent &event); + static void InitConnectEventMap(); + private: + static void ConnectChoice(wxChoice *p, bool connect); + }; + }; // namespace gui +}; // namespace wxjs +#endif //_WXJSChoice_H Property changes on: ps/trunk/source/tools/atlas/wxJS/gui/control/choice.h ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/gui/control/fontdlg.h =================================================================== --- ps/trunk/source/tools/atlas/wxJS/gui/control/fontdlg.h (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/gui/control/fontdlg.h (revision 5154) @@ -0,0 +1,62 @@ +/* + * wxJavaScript - fontdlg.h + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: fontdlg.h 673 2007-04-14 20:25:05Z fbraem $ + */ +#ifndef _WXJSFontDialog_H +#define _WXJSFontDialog_H + + +#include + +namespace wxjs +{ + namespace gui + { + class FontDialog : public ApiWrapper + { + public: + + static bool GetProperty(wxFontDialog *p, + JSContext *cx, + JSObject *obj, + int id, + jsval *vp); + + static wxFontDialog* Construct(JSContext *cx, + JSObject *obj, + uintN argc, + jsval *argv, + bool constructing); + static void Destruct(JSContext *cx, wxFontDialog *p); + + WXJS_DECLARE_PROPERTY_MAP() + + enum + { + P_FONT_DATA + }; + }; + }; // namespace gui +}; // namespace wxjs + +#endif //_WXJSFontDialog_H Property changes on: ps/trunk/source/tools/atlas/wxJS/gui/control/fontdlg.h ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/gui/control/menu.h =================================================================== --- ps/trunk/source/tools/atlas/wxJS/gui/control/menu.h (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/gui/control/menu.h (revision 5154) @@ -0,0 +1,92 @@ +/* + * wxJavaScript - menu.h + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: menu.h 688 2007-04-27 20:45:09Z fbraem $ + */ +#ifndef _WXJSMENU_H +#define _WXJSMENU_H + +namespace wxjs +{ + namespace gui + { + class Menu : public ApiWrapper + { + public: + + static bool GetProperty(wxMenu *p, + JSContext *cx, + JSObject *obj, + int id, + jsval *vp); + static bool SetProperty(wxMenu *p, + JSContext *cx, + JSObject *obj, + int id, + jsval *vp); + + static wxMenu* Construct(JSContext *cx, + JSObject *obj, + uintN argc, + jsval *argv, + bool constructing); + +// static void Destruct(JSContext *cx, wxMenu *p); + + //////////////////////// + // JavaScript methods + //////////////////////// + + WXJS_DECLARE_METHOD_MAP() + WXJS_DECLARE_METHOD(append) + WXJS_DECLARE_METHOD(append_separator) + WXJS_DECLARE_METHOD(new_column) + WXJS_DECLARE_METHOD(check) + WXJS_DECLARE_METHOD(delete_item) + WXJS_DECLARE_METHOD(enable) + WXJS_DECLARE_METHOD(find_item) + WXJS_DECLARE_METHOD(getHelpString) + WXJS_DECLARE_METHOD(getItem) + WXJS_DECLARE_METHOD(getLabel) + WXJS_DECLARE_METHOD(destroy) + WXJS_DECLARE_METHOD(insert) + WXJS_DECLARE_METHOD(remove) + WXJS_DECLARE_METHOD(isChecked) + WXJS_DECLARE_METHOD(isEnabled) + WXJS_DECLARE_METHOD(setHelpString) + WXJS_DECLARE_METHOD(setLabel) + + WXJS_DECLARE_CONSTANT_MAP() + + WXJS_DECLARE_PROPERTY_MAP() + enum + { + P_MENU_ITEM_COUNT + , P_MENU_ITEMS + , P_TITLE + }; + }; + }; // namespace gui +}; // namespace wxjs + +#endif //_WXJSMENU_H + Property changes on: ps/trunk/source/tools/atlas/wxJS/gui/control/menu.h ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/gui/control/radiobox.h =================================================================== --- ps/trunk/source/tools/atlas/wxJS/gui/control/radiobox.h (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/gui/control/radiobox.h (revision 5154) @@ -0,0 +1,99 @@ +/* + * wxJavaScript - radiobox.h + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: radiobox.h 691 2007-05-01 20:00:49Z fbraem $ + */ +#ifndef _WXJSRadioBox_H +#define _WXJSRadioBox_H + +#include "../../common/evtconn.h" + +namespace wxjs +{ + namespace gui + { + class RadioBox : public ApiWrapper + { + public: + + static void InitClass(JSContext* cx, + JSObject* obj, + JSObject* proto); + static bool AddProperty(wxRadioBox *p, + JSContext *cx, + JSObject *obj, + const wxString &prop, + jsval *vp); + static bool DeleteProperty(wxRadioBox *p, + JSContext* cx, + JSObject* obj, + const wxString &prop); + static bool GetProperty(wxRadioBox *p, + JSContext *cx, + JSObject *obj, + int id, + jsval *vp); + static bool SetProperty(wxRadioBox *p, + JSContext *cx, + JSObject *obj, + int id, + jsval *vp); + + static wxRadioBox* Construct(JSContext *cx, + JSObject *obj, + uintN argc, + jsval *argv, + bool constructing); + + WXJS_DECLARE_METHOD_MAP() + WXJS_DECLARE_METHOD(create) + WXJS_DECLARE_METHOD(setString) + WXJS_DECLARE_METHOD(findString) + WXJS_DECLARE_METHOD(enable) + WXJS_DECLARE_METHOD(show) + + WXJS_DECLARE_CONSTANT_MAP() + + WXJS_DECLARE_PROPERTY_MAP() + enum + { + P_SELECTION + , P_STRING_SELECTION + , P_ITEM + , P_COUNT + }; + }; + + class RadioBoxEventHandler : public EventConnector + , public wxEvtHandler + { + public: + // Events + void OnRadioBox(wxCommandEvent &event); + static void InitConnectEventMap(); + private: + static void ConnectRadioBox(wxRadioBox *p, bool connect); + }; + }; // namespace gui +}; // namespace wxjs + +#endif //_WXJSRadioBox_H Property changes on: ps/trunk/source/tools/atlas/wxJS/gui/control/radiobox.h ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/gui/control/listhit.cpp =================================================================== --- ps/trunk/source/tools/atlas/wxJS/gui/control/listhit.cpp (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/gui/control/listhit.cpp (revision 5154) @@ -0,0 +1,111 @@ +#include "precompiled.h" + +/* + * wxJavaScript - listhit.cpp + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: listhit.cpp 688 2007-04-27 20:45:09Z fbraem $ + */ +#include +#ifndef WX_PRECOMP + #include +#endif + +#include "../../common/main.h" + +#include "listhit.h" +#include "../misc/constant.h" + +using namespace wxjs; +using namespace wxjs::gui; + +/*** + * control/listhit + * gui + * + * Helper class for returning information from @wxListCtrl#hitTest. + * This class is specific for wxJavaScript. It doesn't exist in wxWidgets. + * + */ +WXJS_INIT_CLASS(ListHitTest, "wxListHitTest", 0) + +/*** + * + * + * Get the item. + * + * + * Get the flags. These flags give details about the position and the list + * control item. + * + * + */ +WXJS_BEGIN_PROPERTY_MAP(ListHitTest) + WXJS_READONLY_PROPERTY(P_ITEM, "item") + WXJS_READONLY_PROPERTY(P_FLAGS, "flags") +WXJS_END_PROPERTY_MAP() + +bool ListHitTest::GetProperty(wxListHitTest *p, + JSContext *cx, + JSObject* WXUNUSED(obj), + int id, + jsval *vp) +{ + switch (id) + { + case P_ITEM: + *vp = ToJS(cx, p->GetItem()); + break; + case P_FLAGS: + *vp = ToJS(cx, p->GetFlags()); + break; + } + return true; +} + +/*** + * + * + * Above the client area. + * Below the client area. + * In the client area but below the last item. + * On the bitmap associated with an item. + * On the label (string) associated with an item. + * In the area to the right of an item. + * On the state icon for a tree view item that is in a user-defined state. + * To the left of the client area. + * To the right of the client area. + * (ONITEMICON | ONITEMLABEL | ONITEMSTATEICON) + * + * + */ +WXJS_BEGIN_CONSTANT_MAP(ListHitTest) + WXJS_CONSTANT(wxLIST_HITTEST_, ABOVE) + WXJS_CONSTANT(wxLIST_HITTEST_, BELOW) + WXJS_CONSTANT(wxLIST_HITTEST_, NOWHERE) + WXJS_CONSTANT(wxLIST_HITTEST_, ONITEMICON) + WXJS_CONSTANT(wxLIST_HITTEST_, ONITEMLABEL) + WXJS_CONSTANT(wxLIST_HITTEST_, ONITEMRIGHT) + WXJS_CONSTANT(wxLIST_HITTEST_, ONITEMSTATEICON) + WXJS_CONSTANT(wxLIST_HITTEST_, TOLEFT) + WXJS_CONSTANT(wxLIST_HITTEST_, TORIGHT) + WXJS_CONSTANT(wxLIST_HITTEST_, ONITEM) +WXJS_END_CONSTANT_MAP() Property changes on: ps/trunk/source/tools/atlas/wxJS/gui/control/listhit.cpp ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/gui/control/menuitem.cpp =================================================================== --- ps/trunk/source/tools/atlas/wxJS/gui/control/menuitem.cpp (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/gui/control/menuitem.cpp (revision 5154) @@ -0,0 +1,434 @@ +#include "precompiled.h" + +/* + * wxJavaScript - menuitem.cpp + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: menuitem.cpp 688 2007-04-27 20:45:09Z fbraem $ + */ +// menuitem.cpp + +#ifndef WX_PRECOMP + #include +#endif + +#include "../../common/main.h" + +#include "menu.h" +#include "menuitem.h" + +#include "../misc/accentry.h" +#include "../misc/font.h" +#include "../misc/bitmap.h" +#include "../misc/colour.h" + +using namespace wxjs; +using namespace wxjs::gui; + +/*** + * control/menuitem + * gui + * + * A menu item represents an item in a popup menu. + * Note that the majority of this class is only implemented under Windows so + * far, but everything except fonts, colours and bitmaps can be achieved via + * @wxMenu on all platforms. + * + */ +WXJS_INIT_CLASS(MenuItem, "wxMenuItem", 1) + +/*** + * + * + * Get/Set the accelerator. + * + * + * Get/Set the background colour of the item (Windows only) + * + * + * Get/Set the checked bitmap. (Windows only) + * + * + * Check or uncheck the menu item. + * + * + * Returns true if the item is checkable. + * + * + * Enables or disables the menu item. + * + * + * Get/Set the font. (Windows only) + * + * + * Get/Set the helpstring shown in the statusbar. + * + * + * Get/Set the id of the menu item + * + * + * Gets the text associated with the menu item without any accelerator + * characters it might contain. + * + * + * Get/Set the width of the menu item checkmark bitmap (Windows only). + * + * + * Gets the menu that owns this item. + * + * + * Returns true if the item is a separator. + * + * + * Gets the submenu associated with the menu item + * + * + * Get/Set the text associated with the menu item with any accelerator + * characters it may contain. + * + * + * Get/Set the text colour. (Windows Only) + * + * + */ +WXJS_BEGIN_PROPERTY_MAP(MenuItem) + WXJS_READONLY_PROPERTY(P_LABEL, "label") + WXJS_PROPERTY(P_ACCEL, "accel") + WXJS_PROPERTY(P_TEXT, "text") + WXJS_PROPERTY(P_CHECK, "check") + WXJS_READONLY_PROPERTY(P_CHECKABLE, "checkable") + WXJS_PROPERTY(P_ENABLE, "enable") + WXJS_PROPERTY(P_HELP, "help") + WXJS_PROPERTY(P_ID, "id") + WXJS_PROPERTY(P_FONT, "font") + WXJS_PROPERTY(P_TEXT_COLOUR, "textColour") + WXJS_PROPERTY(P_BITMAP, "bitmap") + WXJS_PROPERTY(P_MARGIN_WIDTH, "marginWidth") + WXJS_READONLY_PROPERTY(P_SUB_MENU, "subMenu") + WXJS_PROPERTY(P_BG_COLOUR, "backgroundColour") + WXJS_READONLY_PROPERTY(P_MENU, "menu") + WXJS_READONLY_PROPERTY(P_SEPARATOR, "separator") +WXJS_END_PROPERTY_MAP() + +bool MenuItem::GetProperty(wxMenuItem *p, + JSContext *cx, + JSObject* WXUNUSED(obj), + int id, + jsval *vp) +{ + switch (id) + { + case P_ACCEL: + *vp = AcceleratorEntry::CreateObject(cx, p->GetAccel()); + break; + case P_BG_COLOUR: + #ifdef __WXMSW__ + *vp = Colour::CreateObject(cx, new wxColour(p->GetBackgroundColour())); + #endif + break; + case P_LABEL: + *vp = ToJS(cx, p->GetLabel()); + break; + case P_TEXT: + *vp = ToJS(cx, p->GetText()); + break; + case P_CHECK: + *vp = ToJS(cx, p->IsChecked()); + break; + case P_CHECKABLE: + *vp = ToJS(cx, p->IsCheckable()); + break; + case P_ENABLE: + *vp = ToJS(cx, p->IsEnabled()); + break; + case P_HELP: + *vp = ToJS(cx, p->GetHelp()); + break; + case P_ID: + *vp = ToJS(cx, p->GetId()); + break; + case P_MARGIN_WIDTH: + #ifdef __WXMSW__ + *vp = ToJS(cx, p->GetMarginWidth()); + #endif + break; + case P_SUB_MENU: + { + wxMenu *subMenu = p->GetSubMenu(); + JavaScriptClientData *data + = dynamic_cast(subMenu->GetClientObject()); + *vp = (data->GetObject() == NULL) ? JSVAL_NULL + : OBJECT_TO_JSVAL(data->GetObject()); + break; + } + case P_MENU: + { + wxMenu *menu = p->GetMenu(); + JavaScriptClientData *data + = dynamic_cast(menu->GetClientObject()); + *vp = (data->GetObject() == NULL) ? JSVAL_NULL + : OBJECT_TO_JSVAL(data->GetObject()); + break; + } + case P_FONT: + #ifdef __WXMSW__ + *vp = Font::CreateObject(cx, new wxFont(p->GetFont())); + #endif + break; + case P_BITMAP: + *vp = Bitmap::CreateObject(cx, new wxBitmap(p->GetBitmap())); + break; + case P_TEXT_COLOUR: + #ifdef __WXMSW__ + *vp = Colour::CreateObject(cx, new wxColour(p->GetTextColour())); + #endif + break; + case P_SEPARATOR: + *vp = ToJS(cx, p->IsSeparator()); + break; + } + return true; +} + +bool MenuItem::SetProperty(wxMenuItem *p, + JSContext *cx, + JSObject* WXUNUSED(obj), + int id, + jsval *vp) +{ + switch(id) + { + case P_ACCEL: + { + wxAcceleratorEntry *entry = AcceleratorEntry::GetPrivate(cx, *vp); + if ( entry != NULL ) + p->SetAccel(entry); + break; + } + case P_BG_COLOUR: + { + #ifdef __WXMSW__ + wxColour *colour = Colour::GetPrivate(cx, *vp); + if ( colour != NULL ) + p->SetBackgroundColour(*colour); + #endif + break; + } + case P_TEXT: + { + wxString str; + FromJS(cx, *vp, str); + p->SetText(str); + break; + } + case P_CHECK: + { + bool value; + if ( FromJS(cx, *vp, value) ) + p->Check(value); + break; + } + case P_ENABLE: + { + bool value; + if ( FromJS(cx, *vp, value) ) + p->Enable(value); + break; + } + case P_HELP: + { + wxString str; + FromJS(cx, *vp, str); + p->SetHelp(str); + break; + } + case P_MARGIN_WIDTH: + { + #ifdef __WXMSW__ + int value; + if ( FromJS(cx, *vp, value) ) + p->SetMarginWidth(value); + #endif + break; + } + case P_FONT: + { + #ifdef __WXMSW__ + wxFont *font = Font::GetPrivate(cx, *vp); + if ( font ) + p->SetFont(*font); + #endif + break; + } + case P_BITMAP: + { + #ifdef __WXMSW__ + wxBitmap *bmp = Bitmap::GetPrivate(cx, *vp); + if ( bmp ) + p->SetBitmaps(*bmp, wxNullBitmap); + #endif + break; + } + case P_TEXT_COLOUR: + { + #ifdef __WXMSW__ + wxColour *colour = Colour::GetPrivate(cx, *vp); + if ( colour != NULL ) + p->SetTextColour(*colour); + #endif + break; + } + } + return true; +} + +WXJS_BEGIN_METHOD_MAP(MenuItem) + WXJS_METHOD("setBitmaps", setBitmaps, 2) +WXJS_END_METHOD_MAP() + +/*** + * + * + * Menu that owns the item + * Identifier for this item + * The text for the menu item + * The help message shown in +* the statusbar + * + * Indicates if the menu item can be checked or not. + * + * + * Indicates that the menu item is a submenu + * + * + * Constructs a new wxMenuItem object + * + * + */ +wxMenuItem* MenuItem::Construct(JSContext *cx, + JSObject* WXUNUSED(obj), + uintN argc, + jsval *argv, + bool WXUNUSED(constructing)) +{ + if ( argc > 6 ) + argc = 6; + + int id = 0; + wxString text = wxEmptyString; + wxString help = wxEmptyString; + bool checkable = false; + wxMenu *subMenu = NULL; + + switch(argc) + { + case 6: + if ( (subMenu = Menu::GetPrivate(cx, argv[5])) == NULL ) + break; + // Fall through + case 5: + if ( ! FromJS(cx, argv[4], checkable) ) + break; + // Fall through + case 4: + FromJS(cx, argv[3], help); + // Fall through + case 3: + FromJS(cx, argv[2], text); + // Fall through + case 2: + if ( ! FromJS(cx, argv[1], id) ) + break; + // Fall through + default: + wxMenu *menu = Menu::GetPrivate(cx, argv[0]); + if ( menu != NULL ) + { + wxItemKind itemkind = wxITEM_NORMAL; + if ( checkable ) + itemkind = wxITEM_CHECK; + #if wxCHECK_VERSION(2,7,0) + return new wxMenuItem(menu, id, text, help, itemkind, subMenu); + #else + return new wxMenuItem(menu, id, text, help, checkable, subMenu); + #endif + } + } + + return NULL; +} + +void MenuItem::Destruct(JSContext* WXUNUSED(cx), wxMenuItem* WXUNUSED(p)) +{ +/* if ( p->GetMenu() == NULL ) + { + delete p; + p = NULL; + } +*/ +} + +/*** + * + * + * + * + * + * + * Sets the checked/unchecked bitmaps for the menu item (Windows only). + * The first bitmap is also used as the single bitmap for uncheckable menu items. + * + * + */ +JSBool MenuItem::setBitmaps(JSContext *cx, + JSObject *obj, + uintN argc, + jsval *argv, + jsval* WXUNUSED(rval)) +{ + wxMenuItem *p = MenuItem::GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + #ifdef __WXMSW__ + + wxBitmap *bmp1 = Bitmap::GetPrivate(cx, argv[0]); + if ( bmp1 != NULL ) + { + const wxBitmap *bmp2 = &wxNullBitmap; + if ( argc > 1 ) + { + bmp2 = Bitmap::GetPrivate(cx, argv[1]); + if ( bmp2 == NULL ) + { + return JS_FALSE; + } + } + + p->SetBitmaps(*bmp1, *bmp2); + return JS_TRUE; + } + #else + return JS_TRUE; + #endif + + return JS_FALSE; +} Property changes on: ps/trunk/source/tools/atlas/wxJS/gui/control/menuitem.cpp ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/gui/control/button.cpp =================================================================== --- ps/trunk/source/tools/atlas/wxJS/gui/control/button.cpp (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/gui/control/button.cpp (revision 5154) @@ -0,0 +1,409 @@ +#include "precompiled.h" + +/* + * wxJavaScript - button.cpp + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: button.cpp 708 2007-05-14 15:30:45Z fbraem $ + */ + +/*** + * control/button + * gui + * + * A button is a control that contains a text string, + * and is one of the commonest elements of a GUI. It may + * be placed on a dialog box or panel, or indeed almost any other window. + * An example: + *
// dlg is a wxDialog
+ *  var button = new wxButton(dlg, -1, "Click me");
+ *  button.onClicked = function(event)
+ *  {
+ *    wxMessageBox("You've clicked me");
+ *  }

+ *
+ */ + +#ifndef WX_PRECOMP + #include +#endif + +#include "../../common/main.h" + +#include "../event/jsevent.h" +#include "../event/command.h" + +#include "../misc/point.h" +#include "../misc/size.h" +#include "../misc/validate.h" + +#include "button.h" +#include "window.h" +#include "../errors.h" + +using namespace wxjs; +using namespace wxjs::gui; + +WXJS_INIT_CLASS(Button, "wxButton", 3) + +void Button::InitClass(JSContext* WXUNUSED(cx), + JSObject* WXUNUSED(obj), + JSObject* WXUNUSED(proto)) +{ + ButtonEventHandler::InitConnectEventMap(); +} + +/*** + * + * + * Get/Set the label of the button. + * + * + */ +WXJS_BEGIN_PROPERTY_MAP(Button) + WXJS_PROPERTY(P_LABEL, "label") +WXJS_END_PROPERTY_MAP() + +bool Button::GetProperty(wxButton *p, + JSContext *cx, + JSObject* WXUNUSED(obj), + int id, + jsval *vp) +{ + if ( id == P_LABEL ) + *vp = ToJS(cx, p->GetLabel()); + + return true; +} + +bool Button::SetProperty(wxButton *p, + JSContext *cx, + JSObject* WXUNUSED(obj), + int id, + jsval *vp) +{ + if ( id == P_LABEL ) + { + wxString label; + FromJS(cx, *vp, label); + p->SetLabel(label); + } + return true; +} + +bool Button::AddProperty(wxButton *p, + JSContext* WXUNUSED(cx), + JSObject* WXUNUSED(obj), + const wxString &prop, + jsval* WXUNUSED(vp)) +{ + if ( WindowEventHandler::ConnectEvent(p, prop, true) ) + return true; + + ButtonEventHandler::ConnectEvent(p, prop, true); + return true; +} + +bool Button::DeleteProperty(wxButton *p, + JSContext* WXUNUSED(cx), + JSObject* WXUNUSED(obj), + const wxString &prop) +{ + if ( WindowEventHandler::ConnectEvent(p, prop, false) ) + return true; + + ButtonEventHandler::ConnectEvent(p, prop, false); + return true; +} + +/*** + * + * + * Gets the default size of a button. + * + * + */ +WXJS_BEGIN_STATIC_PROPERTY_MAP(Button) + WXJS_READONLY_STATIC_PROPERTY(P_DEFAULT_SIZE, "defaultSize") +WXJS_END_PROPERTY_MAP() + +bool Button::GetStaticProperty(JSContext *cx, int id, jsval *vp) +{ + if ( id == P_DEFAULT_SIZE ) + { + *vp = Size::CreateObject(cx, new wxSize(wxButton::GetDefaultSize())); + } + return true; +} + +/*** + * + * + * + * Left-justifies the label. Windows and GTK+ only. + * + * + * Right-justifies the bitmap label. Windows and GTK+ only. + * + * + * Aligns the label to the top of the button. Windows and GTK+ only. + * + * + * Aligns the label to the bottom of the button. Windows and GTK+ only. + * + * + * Creates the button as small as possible instead of making it of the + * standard size (which is the default behaviour ). + * + * + * Creates a flat button. Windows and GTK+ only. + * + * + * If this is specified, the button will be drawn automatically using + * the label bitmap only, providing a 3D-look border. If this style is not + * specified, + * the button will be drawn without borders and using all provided bitmaps. + * WIN32 only. + * + * + * + */ +WXJS_BEGIN_CONSTANT_MAP(Button) + WXJS_CONSTANT(wxBU_, LEFT) + WXJS_CONSTANT(wxBU_, RIGHT) + WXJS_CONSTANT(wxBU_, TOP) + WXJS_CONSTANT(wxBU_, BOTTOM) + WXJS_CONSTANT(wxBU_, EXACTFIT) + WXJS_CONSTANT(wxBU_, AUTODRAW) + WXJS_CONSTANT(wx, NO_BORDER) +WXJS_END_CONSTANT_MAP() + +/*** + * + * + * + * The parent of the button. + * + * An window identifier. Use -1 when you don't need it. + * + * The label of the button + * + * The position of the button on the given parent. + * + * + * The size of the button. + * + * + * The button style + * + * + * + * + * Constructs a new wxButton object. + * + * + */ +wxButton *Button::Construct(JSContext *cx, + JSObject *obj, + uintN argc, + jsval *argv, + bool WXUNUSED(constructing)) +{ + wxButton *p = new wxButton(); + SetPrivate(cx, obj, p); + + if ( argc > 0 ) + { + jsval rval; + create(cx, obj, argc, argv, &rval); + } + return p; +} + +WXJS_BEGIN_METHOD_MAP(Button) + WXJS_METHOD("create", create, 3) + WXJS_METHOD("setDefault", setDefault, 0) +WXJS_END_METHOD_MAP() + +/*** + * + * + * The parent of the button. + * + * An window identifier. Use -1 when you don't need it. + * + * The label of the button + * + * The position of the button on the given parent. + * + * + * The size of the button. + * + * + * The button style + * + * + * + * + * Creates a button. + * + * + */ +JSBool Button::create(JSContext *cx, + JSObject *obj, + uintN argc, + jsval *argv, + jsval *rval) +{ + wxButton *p = GetPrivate(cx, obj); + *rval = JSVAL_FALSE; + + if ( argc > 7 ) + argc = 7; + + const wxPoint *pt = &wxDefaultPosition; + const wxSize *size = &wxDefaultSize; + int style = 0; + const wxValidator *val = &wxDefaultValidator; + + switch(argc) + { + case 7: + val = Validator::GetPrivate(cx, argv[6]); + if ( val == NULL ) + { + JS_ReportError(cx, WXJS_INVALID_ARG_TYPE, 7, "wxValidator"); + return JS_FALSE; + } + case 6: + if ( ! FromJS(cx, argv[5], style) ) + { + JS_ReportError(cx, WXJS_INVALID_ARG_TYPE, 6, "Integer"); + return JS_FALSE; + } + case 5: + size = Size::GetPrivate(cx, argv[4]); + if ( size == NULL ) + { + JS_ReportError(cx, WXJS_INVALID_ARG_TYPE, 5, "wxSize"); + return JS_FALSE; + } + case 4: + pt = Point::GetPrivate(cx, argv[3]); + if ( pt == NULL ) + { + JS_ReportError(cx, WXJS_INVALID_ARG_TYPE, 4, "wxPoint"); + return JS_FALSE; + } + default: + wxString text; + FromJS(cx, argv[2], text); + + int id; + if ( ! FromJS(cx, argv[1], id) ) + { + JS_ReportError(cx, WXJS_INVALID_ARG_TYPE, 2, "Integer"); + return JS_FALSE; + } + + wxWindow *parent = Window::GetPrivate(cx, argv[0]); + if ( parent == NULL ) + { + JS_ReportError(cx, WXJS_NO_PARENT_ERROR, GetClass()->name); + return JS_FALSE; + } + + JavaScriptClientData *clntParent + = dynamic_cast(parent->GetClientObject()); + if ( clntParent == NULL ) + { + JS_ReportError(cx, WXJS_NO_PARENT_ERROR, GetClass()->name); + return JS_FALSE; + } + JS_SetParent(cx, obj, clntParent->GetObject()); + + if ( p->Create(parent, id, text, *pt, *size, style, *val) ) + { + *rval = JSVAL_TRUE; + p->SetClientObject(new JavaScriptClientData(cx, obj, true, false)); + } + } + + return JS_TRUE; +} + +/*** + * + * + * + * This sets the button to be the default item for the panel or dialog box. + * see @wxPanel#defaultItem. + * + * + */ +JSBool Button::setDefault(JSContext *cx, + JSObject *obj, + uintN WXUNUSED(argc), + jsval* WXUNUSED(argv), + jsval* WXUNUSED(rval)) +{ + wxButton *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + p->SetDefault(); + + return JS_TRUE; +} + +/*** + * + * + * Called when the button is clicked. The type of the argument that your +* handler receives is @wxCommandEvent. + * + * + */ +WXJS_INIT_EVENT_MAP(wxButton) +const wxString WXJS_BUTTON_CLICKED_EVENT = wxT("onClicked"); + +void ButtonEventHandler::OnClicked(wxCommandEvent &event) +{ + PrivCommandEvent::Fire(event, WXJS_BUTTON_CLICKED_EVENT); +} + +void ButtonEventHandler::ConnectClicked(wxButton *p, bool connect) +{ + if ( connect ) + { + p->Connect(wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler(OnClicked)); + } + else + { + p->Disconnect(wxEVT_COMMAND_BUTTON_CLICKED, + wxCommandEventHandler(OnClicked)); + } +} + +void ButtonEventHandler::InitConnectEventMap() +{ + AddConnector(WXJS_BUTTON_CLICKED_EVENT, ConnectClicked); +} Property changes on: ps/trunk/source/tools/atlas/wxJS/gui/control/button.cpp ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/gui/control/treeid.cpp =================================================================== --- ps/trunk/source/tools/atlas/wxJS/gui/control/treeid.cpp (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/gui/control/treeid.cpp (revision 5154) @@ -0,0 +1,78 @@ +#include "precompiled.h" + +/* + * wxJavaScript - treeid.cpp + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: treeid.cpp 696 2007-05-07 21:16:23Z fbraem $ + */ +#ifndef WX_PRECOMP + #include +#endif + +#include +/** + * @if JS + * @page wxTreeItemId wxTreeItemId + * @since version 0.6 + * @endif + */ + +#include "../../common/main.h" + +#include "treeid.h" + +using namespace wxjs; +using namespace wxjs::gui; + +/*** + * control/treeid + * gui + * + * wxTreeItemId identifies an element of the tree. + * See @wxTreeCtrl and @wxTreeEvent + * + */ +WXJS_INIT_CLASS(TreeItemId, "wxTreeItemId", 0) + +/*** + * + * + * Returns true when the item is valid. + * + * + */ +WXJS_BEGIN_PROPERTY_MAP(TreeItemId) + WXJS_READONLY_PROPERTY(P_OK, "ok") +WXJS_END_PROPERTY_MAP() + +bool TreeItemId::GetProperty(wxTreeItemId *p, + JSContext *cx, + JSObject* WXUNUSED(obj), + int id, + jsval *vp) +{ + if ( id == P_OK ) + { + *vp = ToJS(cx, p->IsOk()); + } + return true; +} Property changes on: ps/trunk/source/tools/atlas/wxJS/gui/control/treeid.cpp ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/gui/control/bmpbtn.cpp =================================================================== --- ps/trunk/source/tools/atlas/wxJS/gui/control/bmpbtn.cpp (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/gui/control/bmpbtn.cpp (revision 5154) @@ -0,0 +1,295 @@ +#include "precompiled.h" + +/* + * wxJavaScript - bmpbtn.cpp + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: bmpbtn.cpp 708 2007-05-14 15:30:45Z fbraem $ + */ +// bmpbtn.cpp + +#ifndef WX_PRECOMP + #include +#endif + +/*** + * control/bmpbtn + * gui + * + * A button that contains a bitmap. + * + */ + +#include "../../common/main.h" + +#include "../misc/size.h" +#include "../misc/point.h" +#include "bmpbtn.h" +#include "../misc/bitmap.h" +#include "button.h" +#include "window.h" +#include "../errors.h" + +using namespace wxjs; +using namespace wxjs::gui; + +WXJS_INIT_CLASS(BitmapButton, "wxBitmapButton", 3) + +/*** + * + * Bitmap to show when the button is disabled. + * Bitmap to show when the button has the focus. + * The default bitmap. + * Bitmap to show when the button is selected. + * + */ +WXJS_BEGIN_PROPERTY_MAP(BitmapButton) + WXJS_PROPERTY(P_BITMAP_DISABLED, "bitmapDisabled") + WXJS_PROPERTY(P_BITMAP_FOCUS, "bitmapFocus") + WXJS_PROPERTY(P_BITMAP_LABEL, "bitmapLabel") + WXJS_PROPERTY(P_BITMAP_SELECTED, "bitmapSelected") +WXJS_END_PROPERTY_MAP() + +bool BitmapButton::GetProperty(wxBitmapButton* p, + JSContext* cx, + JSObject* WXUNUSED(obj), + int id, + jsval* vp) +{ + switch (id) + { + case P_BITMAP_DISABLED: + *vp = Bitmap::CreateObject(cx, new wxBitmap(p->GetBitmapDisabled())); + break; + case P_BITMAP_FOCUS: + *vp = Bitmap::CreateObject(cx, new wxBitmap(p->GetBitmapFocus())); + break; + case P_BITMAP_LABEL: + *vp = Bitmap::CreateObject(cx, new wxBitmap(p->GetBitmapLabel())); + break; + case P_BITMAP_SELECTED: + *vp = Bitmap::CreateObject(cx, new wxBitmap(p->GetBitmapSelected())); + break; + } + return true; +} + +bool BitmapButton::SetProperty(wxBitmapButton *p, + JSContext *cx, + JSObject* WXUNUSED(obj), + int id, + jsval *vp) +{ + switch (id) + { + case P_BITMAP_DISABLED: + { + wxBitmap *bitmap = Bitmap::GetPrivate(cx, *vp); + if ( bitmap != NULL ) + p->SetBitmapDisabled(*bitmap); + break; + } + case P_BITMAP_FOCUS: + { + wxBitmap *bitmap = Bitmap::GetPrivate(cx, *vp); + if ( bitmap != NULL ) + p->SetBitmapFocus(*bitmap); + break; + } + case P_BITMAP_LABEL: + { + wxBitmap *bitmap = Bitmap::GetPrivate(cx, *vp); + if ( bitmap != NULL ) + p->SetBitmapLabel(*bitmap); + break; + } + case P_BITMAP_SELECTED: + { + wxBitmap *bitmap = Bitmap::GetPrivate(cx, *vp); + if ( bitmap != NULL ) + p->SetBitmapSelected(*bitmap); + break; + } + } + return true; +} + +bool BitmapButton::AddProperty(wxBitmapButton *p, + JSContext* WXUNUSED(cx), + JSObject* WXUNUSED(obj), + const wxString &prop, + jsval* WXUNUSED(vp)) +{ + if ( WindowEventHandler::ConnectEvent(p, prop, true) ) + return true; + + ButtonEventHandler::ConnectEvent(p, prop, true); + return true; +} + +bool BitmapButton::DeleteProperty(wxBitmapButton *p, + JSContext* WXUNUSED(cx), + JSObject* WXUNUSED(obj), + const wxString &prop) +{ + if ( WindowEventHandler::ConnectEvent(p, prop, false) ) + return true; + + ButtonEventHandler::ConnectEvent(p, prop, false); + return true; +} + +/*** + * + * + * + * The parent window + * A windows identifier. Use -1 when you don't need it. + * The bitmap to display + * The position of the control on the given parent + * The size of the control + * The style of the control + * + * + * Constructs a new wxBitmapButton object. + * + * + */ +wxBitmapButton* BitmapButton::Construct(JSContext *cx, + JSObject *obj, + uintN argc, + jsval *argv, + bool WXUNUSED(constructing)) +{ + wxBitmapButton *p = new wxBitmapButton(); + SetPrivate(cx, obj, p); + + if ( argc > 0 ) + { + jsval rval; + create(cx, obj, argc, argv, &rval); + } + return p; +} + +WXJS_BEGIN_METHOD_MAP(BitmapButton) + WXJS_METHOD("create", create, 3) +WXJS_END_METHOD_MAP() + +/*** + * + * + * The parent window + * A windows identifier. + * Use -1 when you don't need it. + * The bitmap to display + * + * The position of the control on the given parent + * + * The size of the control + * + * The style of the control + * + * + * Creates a bitmap button. + * + * + */ +JSBool BitmapButton::create(JSContext *cx, + JSObject *obj, + uintN argc, + jsval *argv, + jsval *rval) +{ + wxBitmapButton *p = GetPrivate(cx, obj); + *rval = JSVAL_FALSE; + + const wxPoint *pt = &wxDefaultPosition; + const wxSize *size = &wxDefaultSize; + int style = wxBU_AUTODRAW; + + if ( argc > 6 ) + argc = 6; + + switch(argc) + { + case 6: + if ( ! FromJS(cx, argv[5], style) ) + { + JS_ReportError(cx, WXJS_INVALID_ARG_TYPE, 6, "Integer"); + return JS_FALSE; + } + // Walk through + case 5: + size = Size::GetPrivate(cx, argv[4]); + if ( size == NULL ) + { + JS_ReportError(cx, WXJS_INVALID_ARG_TYPE, 5, "wxSize"); + return JS_FALSE; + } + // Walk through + case 4: + pt = Point::GetPrivate(cx, argv[3]); + if ( pt == NULL ) + { + JS_ReportError(cx, WXJS_INVALID_ARG_TYPE, 4, "wxPoint"); + return JS_FALSE; + } + // Walk through + default: + wxBitmap *bmp = Bitmap::GetPrivate(cx, argv[2]); + if ( bmp == NULL ) + { + JS_ReportError(cx, WXJS_INVALID_ARG_TYPE, 3, "wxBitmap"); + return JS_FALSE; + } + + int id; + if ( ! FromJS(cx, argv[1], id) ) + { + JS_ReportError(cx, WXJS_INVALID_ARG_TYPE, 2, "Integer"); + return JS_FALSE; + } + + wxWindow *parent = Window::GetPrivate(cx, argv[0]); + if ( parent == NULL ) + { + JS_ReportError(cx, WXJS_NO_PARENT_ERROR, GetClass()->name); + return JS_FALSE; + } + + JavaScriptClientData *clntParent = + dynamic_cast(parent->GetClientObject()); + if ( clntParent == NULL ) + { + JS_ReportError(cx, WXJS_NO_PARENT_ERROR, GetClass()->name); + return JS_FALSE; + } + JS_SetParent(cx, obj, clntParent->GetObject()); + + if ( p->Create(parent, id, *bmp, *pt, *size, style) ) + { + *rval = JSVAL_TRUE; + p->SetClientObject(new JavaScriptClientData(cx, obj, true, false)); + } + } + return JS_TRUE; +} Property changes on: ps/trunk/source/tools/atlas/wxJS/gui/control/bmpbtn.cpp ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/gui/control/fontdlg.cpp =================================================================== --- ps/trunk/source/tools/atlas/wxJS/gui/control/fontdlg.cpp (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/gui/control/fontdlg.cpp (revision 5154) @@ -0,0 +1,139 @@ +#include "precompiled.h" + +/* + * wxJavaScript - fontdlg.cpp + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: fontdlg.cpp 708 2007-05-14 15:30:45Z fbraem $ + */ + +#ifndef WX_PRECOMP + #include +#endif + +#include "../../common/main.h" + +#include "fontdlg.h" +#include "fontdata.h" +#include "window.h" + +#include "../misc/point.h" + +#include "../errors.h" + +using namespace wxjs; +using namespace wxjs::gui; + +/*** + * control/fontdlg + * gui + * + * The wxFontDialog presents a Font selector to the user. + * + */ +WXJS_INIT_CLASS(FontDialog, "wxFontDialog", 1) + +/*** + * + * + * Gets the Font data. + * + * + */ +WXJS_BEGIN_PROPERTY_MAP(FontDialog) + WXJS_READONLY_PROPERTY(P_FONT_DATA, "FontData") +WXJS_END_PROPERTY_MAP() + +bool FontDialog::GetProperty(wxFontDialog* p, + JSContext* cx, + JSObject* WXUNUSED(obj), + int id, + jsval* vp) +{ + if ( id == P_FONT_DATA ) + *vp = FontData::CreateObject(cx, new wxFontData(p->GetFontData())); + return true; +} + +/*** + * + * + * + * The parent of wxFontDialog. + * + * + * The Font data. + * + * + * + * Constructs a new wxFontDialog object + * + * + */ +wxFontDialog* FontDialog::Construct(JSContext *cx, + JSObject *obj, + uintN argc, + jsval *argv, + bool WXUNUSED(constructing)) +{ + if ( argc > 2 ) + argc = 2; + + wxFontData *data = NULL; + if ( argc == 2 ) + { + if ( (data = FontData::GetPrivate(cx, argv[1])) == NULL ) + { + JS_ReportError(cx, WXJS_INVALID_ARG_TYPE, 2, "wxFontData"); + return NULL; + } + } + + wxWindow *parent = Window::GetPrivate(cx, argv[0]); + if ( parent != NULL ) + { + JavaScriptClientData *clntParent = + dynamic_cast(parent->GetClientObject()); + if ( clntParent == NULL ) + { + JS_ReportError(cx, WXJS_NO_PARENT_ERROR, GetClass()->name); + return JS_FALSE; + } + JS_SetParent(cx, obj, clntParent->GetObject()); + } +#if wxCHECK_VERSION(2,7,0) + wxFontDialog *p = new wxFontDialog(parent, *data); +#else + wxFontDialog *p = new wxFontDialog(parent, data); +#endif + + if ( p != NULL ) + { + p->SetClientObject(new JavaScriptClientData(cx, obj, true, false)); + } + + return p; +} + +void FontDialog::Destruct(JSContext* WXUNUSED(cx), wxFontDialog *p) +{ + p->Destroy(); +} Property changes on: ps/trunk/source/tools/atlas/wxJS/gui/control/fontdlg.cpp ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/gui/control/statbar.cpp =================================================================== --- ps/trunk/source/tools/atlas/wxJS/gui/control/statbar.cpp (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/gui/control/statbar.cpp (revision 5154) @@ -0,0 +1,495 @@ +#include "precompiled.h" + +/* + * wxJavaScript - statbar.cpp + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: statbar.cpp 708 2007-05-14 15:30:45Z fbraem $ + */ +// wxJSStatusBar.cpp + +#ifndef WX_PRECOMP + #include +#endif + +#include "../../common/main.h" + +#include "statbar.h" +#include "window.h" + + + +#include "../misc/rect.h" +#include "../errors.h" + +using namespace wxjs; +using namespace wxjs::gui; + +/*** + * control/statbar + * gui + * + * A status bar is a narrow window that can be placed along the bottom of a frame + * to give small amounts of status information. It can contain one or more fields, + * one or more of which can be variable length according to the size of the window + *

The example shows a frame with a statusbar that contains a wxBitmapButton. + * When you click the button the bitmap is changed. + *

+ *   wxTheApp.onInit = init;
+ *   wxTheApp.mainLoop();
+ *   
+ *   function init()
+ *   {
+ *     wxImage.addHandler(new wxGIFHandler());
+ *   
+ *     var frame = new wxFrame(null, -1, "A Statusbar Example");
+ *   
+ *     var statusbar = frame.createStatusBar(2);
+ *     statusbar.bitmapOn = new wxBitmap("green.gif", wxBitmapType.GIF);
+ *     statusbar.bitmapOff = new wxBitmap("red.gif", wxBitmapType.GIF);
+ *     statusbar.sw = true;
+ *   
+ *     statusbar.button = new wxBitmapButton(statusbar, 1, statusbar.bitmapOn);
+ *     statusbar.button.onClicked = switched;
+ *   
+ *     frame.visible = true;
+ *     topWindow = frame;
+ *   
+ *     return true;
+ *   }
+ *   
+ *   function switched()
+ *   {
+ *     sw = ! sw;
+ *     if ( sw )
+ *        bitmapLabel = bitmapOn;
+ *     else
+ *        bitmapLabel = bitmapOff;
+ *   
+ *     refresh();
+ *   }
+ *  
+ *
+ */ +WXJS_INIT_CLASS(StatusBar, "wxStatusBar", 2) + +/*** + * + * + * Get/Set the number of fields in the statusbar. + * See also @wxStatusBar#setFieldsCount + * + * + * Get/Set the width for each field. At least one element must be -1 (meaning variable width). + * See also @wxFrame#setStatusWidths + * + * + */ +WXJS_BEGIN_PROPERTY_MAP(StatusBar) + WXJS_PROPERTY(P_FIELDS_COUNT, "fieldsCount") + WXJS_PROPERTY(P_STATUS_WIDTHS, "statusWidths") +WXJS_END_PROPERTY_MAP() + +bool StatusBar::GetProperty(wxStatusBar *p, + JSContext *cx, + JSObject* WXUNUSED(obj), + int id, + jsval *vp) +{ + switch (id) + { + case P_FIELDS_COUNT: + *vp = ToJS(cx, p->GetFieldsCount()); + break; + case P_STATUS_WIDTHS: + { + int count = p->GetFieldsCount(); + if ( count == 0 ) + *vp = JSVAL_VOID; + else + { + JSObject *objArr = JS_NewArrayObject(cx, count, NULL); + *vp = OBJECT_TO_JSVAL(objArr); + for(jsint i = 0; i < count; i++) + { + wxRect rect; + p->GetFieldRect(i, rect); + jsval element = INT_TO_JSVAL(rect.GetWidth()); + JS_SetElement(cx, objArr, i, &element); + } + } + break; + } + } + return true; +} + +bool StatusBar::SetProperty(wxStatusBar *p, + JSContext *cx, + JSObject* WXUNUSED(obj), + int id, + jsval *vp) +{ + switch (id) + { + case P_FIELDS_COUNT: + { + int count; + if ( FromJS(cx, *vp, count) ) + p->SetFieldsCount(count); + break; + } + case P_STATUS_WIDTHS: + { + if ( JSVAL_IS_OBJECT(*vp) ) + { + JSObject *arrObj = JSVAL_TO_OBJECT(*vp); + if ( JS_IsArrayObject(cx, arrObj) == JS_TRUE ) + { + jsuint length = 0; + JS_GetArrayLength(cx, arrObj, &length); + uint fields = p->GetFieldsCount(); + if ( length > fields ) + length = fields; + int *widths = new int[length]; + for(jsuint i = 0; i < length; i++) + { + jsval element; + JS_GetElement(cx, arrObj, i, &element); + if ( ! FromJS(cx, element, widths[i]) ) + { + delete[] widths; + return JS_FALSE; + } + } + p->SetStatusWidths(length, widths); + delete[] widths; + } + break; + } + } + } + return true; +} + +/*** + * + * + * + * + * + */ +WXJS_BEGIN_CONSTANT_MAP(StatusBar) + WXJS_CONSTANT(wxST_, SIZEGRIP) +WXJS_END_CONSTANT_MAP() + +/*** + * + * + * + * + * The parent of wxStatusBar. + * + * + * An window identifier. Use -1 when you don't need it. + * + * + * The wxStatusBar style. + * + * + * + * Constructs a new wxStatusBar object. + * + * + */ +wxStatusBar* StatusBar::Construct(JSContext *cx, + JSObject *obj, + uintN argc, + jsval *argv, + bool constructing) +{ + wxStatusBar *p = new wxStatusBar(); + SetPrivate(cx, obj, p); + + if ( argc > 0 ) + { + jsval rval; + create(cx, obj, argc, argv, &rval); + } + return p; +} + +/*** + * + * + * + * The parent of wxStatusBar. + * + * + * An window identifier. Use -1 when you don't need it. + * + * + * The wxStatusBar style. + * + * + * + * Constructs a new wxStatusBar object. + * + * + */ +WXJS_BEGIN_METHOD_MAP(StatusBar) + WXJS_METHOD("create", create, 2) + WXJS_METHOD("getFieldRect", getFieldRect, 2) + WXJS_METHOD("getStatusText", getStatusText, 0) + WXJS_METHOD("setStatusText", setStatusText, 1) + WXJS_METHOD("setFieldsCount", setFieldsCount, 1) +WXJS_END_METHOD_MAP() + +JSBool StatusBar::create(JSContext *cx, + JSObject *obj, + uintN argc, + jsval *argv, + jsval *rval) +{ + wxStatusBar *p = GetPrivate(cx, obj); + *rval = JSVAL_TRUE; + + if ( argc > 3 ) + argc = 3; + + int style = wxST_SIZEGRIP; + switch(argc) + { + case 3: + if ( ! FromJS(cx, argv[2], style) ) + { + JS_ReportError(cx, WXJS_INVALID_ARG_TYPE, 3, "Integer"); + return JS_FALSE; + } + // Fall through + default: + int id; + if ( ! FromJS(cx, argv[1], id) ) + { + JS_ReportError(cx, WXJS_INVALID_ARG_TYPE, 2, "Integer"); + return JS_FALSE; + } + + wxWindow *parent = Window::GetPrivate(cx, argv[0]); + if ( parent == NULL ) + { + JS_ReportError(cx, WXJS_NO_PARENT_ERROR, GetClass()->name); + return JS_FALSE; + } + + JavaScriptClientData *clntParent = + dynamic_cast(parent->GetClientObject()); + if ( clntParent == NULL ) + { + JS_ReportError(cx, WXJS_NO_PARENT_ERROR, GetClass()->name); + return JS_FALSE; + } + JS_SetParent(cx, obj, clntParent->GetObject()); + + if ( p->Create(parent, id, style) ) + { + *rval = JSVAL_TRUE; + p->SetClientObject(new JavaScriptClientData(cx, obj, true, false)); + } + + return JS_TRUE; + } +} + +/*** + * + * + * + * The field of the statusbar. + * + * + * The object that will get the rectangle information. + * + * + * + * Puts the size and position of a fields internal + * bounding rectangle into the Rect object. Returns false on failure, + * true on success. + * Rect is only changed on success. + * + * + */ +JSBool StatusBar::getFieldRect(JSContext *cx, + JSObject *obj, + uintN argc, + jsval *argv, + jsval *rval) +{ + wxStatusBar *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + int field; + if ( ! FromJS(cx, argv[0], field) ) + return JS_FALSE; + + wxRect *rect = Rect::GetPrivate(cx, argv[1]); + if ( rect == NULL ) + return JS_FALSE; + + wxRect result; + if ( p->GetFieldRect(field, result) ) + { + *rect = result; + *rval = JSVAL_TRUE; + } + else + *rval = JSVAL_FALSE; + + return JS_TRUE; +} + +/*** + * + * + * + * The field of the statusbar. + * + * + * + * Gets the status text of the given field + * + * + */ +JSBool StatusBar::getStatusText(JSContext *cx, + JSObject *obj, + uintN argc, + jsval *argv, + jsval *rval) +{ + wxStatusBar *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + int field = 0; + if ( ! FromJS(cx, argv[0], field) ) + return JS_FALSE; + + *rval = ToJS(cx, p->GetStatusText(field)); + return JS_TRUE; +} + +/*** + * + * + * + * The number of fields. + * + * + * + * + * Sets the number of fields, and optionally the field widths. + * + * + */ +JSBool StatusBar::setFieldsCount(JSContext *cx, + JSObject *obj, + uintN argc, + jsval *argv, + jsval *rval) +{ + wxStatusBar *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + int count; + if ( ! FromJS(cx, argv[0], count) ) + return JS_FALSE; + + int *widths = NULL; + if ( JSVAL_IS_OBJECT(argv[0]) ) + { + JSObject *obj = JSVAL_TO_OBJECT(argv[0]); + if ( JS_IsArrayObject(cx, obj) == JS_TRUE ) + { + jsuint length = 0; + JS_GetArrayLength(cx, obj, &length); + uint fields = p->GetFieldsCount(); + if ( length > fields ) + length = fields; + + widths = new int[length]; + for(jsuint i =0; i < length; i++) + { + jsval element; + JS_GetElement(cx, obj, i, &element); + if ( ! FromJS(cx, element, widths[i]) ) + { + delete[] widths; + return JS_FALSE; + } + } + } + } + + p->SetFieldsCount(count, widths); + delete[] widths; + + return JS_TRUE; +} + + +/*** + * + * + * + * The new text for the field. + * + * + * The field to change. Default is 0. + * + * + * + * Sets the text of the field. + * + * + */ +JSBool StatusBar::setStatusText(JSContext *cx, + JSObject *obj, + uintN argc, + jsval *argv, + jsval *rval) +{ + wxStatusBar *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + int field = 0; + if ( argc > 1 + && ! FromJS(cx, argv[0], field) ) + return JS_FALSE; + + wxString text; + FromJS(cx, argv[0], text); + p->SetStatusText(text, field); + + return JS_TRUE; +} Property changes on: ps/trunk/source/tools/atlas/wxJS/gui/control/statbar.cpp ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/gui/control/radioboxit.cpp =================================================================== --- ps/trunk/source/tools/atlas/wxJS/gui/control/radioboxit.cpp (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/gui/control/radioboxit.cpp (revision 5154) @@ -0,0 +1,145 @@ +#include "precompiled.h" + +// radioboxit.cpp + +#ifndef WX_PRECOMP + #include +#endif + +#include "../../common/main.h" +#include "../../common/index.h" + +#include "radiobox.h" +#include "radioboxit.h" + +using namespace wxjs; +using namespace wxjs::gui; + +/*** + * control/radioboxit + * gui + * + * wxRadioBoxItem is a helper class for working with items of @wxRadioBox. + * There's no corresponding class in wxWidgets. + * See wxRadioBox @wxRadioBox#item property. + * + */ +WXJS_INIT_CLASS(RadioBoxItem, "wxRadioBoxItem", 0) + +/*** + * + * + * Enables/Disables the button. + * + * + * Returns true when the item is selected or sets the selection + * + * + * Hides or shows the item. + * + * + * Get/Set the label of the button. + * + * + */ +WXJS_BEGIN_PROPERTY_MAP(RadioBoxItem) + WXJS_PROPERTY(P_ENABLE, "enable") + WXJS_PROPERTY(P_STRING, "string") + WXJS_PROPERTY(P_SELECTED, "selected") + WXJS_PROPERTY(P_SHOW, "show") +WXJS_END_PROPERTY_MAP() + +bool RadioBoxItem::GetProperty(Index *p, + JSContext *cx, + JSObject *obj, + int id, + jsval *vp) +{ + JSObject *parent = JS_GetParent(cx, obj); + wxASSERT_MSG(parent != NULL, wxT("No parent found for RadioBoxItem")); + + wxRadioBox *radiobox = RadioBox::GetPrivate(cx, parent); + if ( radiobox == NULL ) + return false; + + // When id is greater then 0, then we have an array index. + if ( id >= 0 ) + { + if ( id < radiobox->GetCount() ) + { + // Set the item index and don't forget to return ourselves. + p->SetIndex(id); + *vp = OBJECT_TO_JSVAL(obj); + } + } + else + { + // A negative index means a defined property. + int idx = p->GetIndex(); + if ( idx < radiobox->GetCount() ) // To be sure + { + switch (id) + { + case P_STRING: + *vp = ToJS(cx, radiobox->wxControl::GetLabel()); + break; + case P_SELECTED: + *vp = ToJS(cx, radiobox->GetSelection() == idx); + break; + } + } + } + return true; +} + +bool RadioBoxItem::SetProperty(Index *p, + JSContext *cx, + JSObject *obj, + int id, + jsval *vp) +{ + JSObject *parent = JS_GetParent(cx, obj); + wxASSERT_MSG(parent != NULL, wxT("No parent found for RadioBoxItem")); + + wxRadioBox *radiobox = RadioBox::GetPrivate(cx, parent); + if ( radiobox == NULL ) + return false; + + int idx = p->GetIndex(); + if ( idx < radiobox->GetCount() ) // To be sure + { + switch (id) + { + case P_STRING: + { + wxString str; + FromJS(cx, *vp, str); + radiobox->SetString(idx, str); + break; + } + case P_SELECTED: + { + bool value; + if ( FromJS(cx, *vp, value) + && value ) + radiobox->SetSelection(idx); + break; + } + case P_ENABLE: + { + bool value; + if ( FromJS(cx, *vp, value) ) + radiobox->Enable(idx, value); + break; + } + case P_SHOW: + { + bool value; + if ( FromJS(cx, *vp, value) ) + radiobox->Show(idx, value); + break; + } + } + } + return true; +} Property changes on: ps/trunk/source/tools/atlas/wxJS/gui/control/radioboxit.cpp ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/gui/control/listitattr.h =================================================================== --- ps/trunk/source/tools/atlas/wxJS/gui/control/listitattr.h (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/gui/control/listitattr.h (revision 5154) @@ -0,0 +1,55 @@ +/* + * wxJavaScript - listitattr.h + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: listitattr.h 598 2007-03-07 20:13:28Z fbraem $ + */ +#ifndef _wxjs_gui_listitattr_h +#define _wxjs_gui_listitattr_h + +namespace wxjs +{ + namespace gui + { + class ListItemAttr : public ApiWrapper + { + public: + + static bool GetProperty(wxListItemAttr *p, JSContext *cx, JSObject *obj, int id, jsval *vp); + static bool SetProperty(wxListItemAttr *p, JSContext *cx, JSObject *obj, int id, jsval *vp); + static wxListItemAttr *Construct(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, bool constructing); + + WXJS_DECLARE_PROPERTY_MAP() + + enum + { + P_TEXT_COLOUR = WXJS_START_PROPERTY_ID + , P_BG_COLOUR + , P_FONT + , P_HAS_TEXT_COLOUR + , P_HAS_BG_COLOUR + , P_HAS_FONT + }; + }; + }; // namespace gui +}; // namespace wxjs + +#endif //_wxjs_gui_listitattr_h Property changes on: ps/trunk/source/tools/atlas/wxJS/gui/control/listitattr.h ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/gui/control/mdi.h =================================================================== --- ps/trunk/source/tools/atlas/wxJS/gui/control/mdi.h (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/gui/control/mdi.h (revision 5154) @@ -0,0 +1,59 @@ +#ifndef _wxjs_gui_mdi_h +#define _wxjs_gui_mdi_h + +namespace wxjs +{ + namespace gui + { + class MDIParentFrame : public ApiWrapper + , public wxMDIParentFrame + { + public: + + MDIParentFrame() : wxMDIParentFrame() + { + } + + virtual ~MDIParentFrame() {} + + virtual wxToolBar* OnCreateToolBar(long style, + wxWindowID id, + const wxString& name); + static bool AddProperty(wxMDIParentFrame *p, + JSContext *cx, + JSObject *obj, + const wxString &prop, + jsval *vp); + static bool DeleteProperty(wxMDIParentFrame *p, + JSContext* cx, + JSObject* obj, + const wxString &prop); + static wxMDIParentFrame* Construct(JSContext* cx, + JSObject* obj, + uintN argc, + jsval* argv, + bool constructing); + + static bool GetProperty(wxMDIParentFrame* p, + JSContext* cx, JSObject* obj, int id, jsval* vp); + + WXJS_DECLARE_PROPERTY_MAP() + enum + { + P_ACTIVE_CHILD + }; + + WXJS_DECLARE_METHOD_MAP() + WXJS_DECLARE_METHOD(create) + WXJS_DECLARE_METHOD(activateNext) + WXJS_DECLARE_METHOD(activatePrevious) + WXJS_DECLARE_METHOD(arrangeIcons) + WXJS_DECLARE_METHOD(cascade) + WXJS_DECLARE_METHOD(tile) + + private: + }; + } +}; + +#endif // _wxjs_gui_mdi_h Property changes on: ps/trunk/source/tools/atlas/wxJS/gui/control/mdi.h ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/gui/control/treeid.h =================================================================== --- ps/trunk/source/tools/atlas/wxJS/gui/control/treeid.h (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/gui/control/treeid.h (revision 5154) @@ -0,0 +1,56 @@ +/* + * wxJavaScript - treeid.h + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: treeid.h 696 2007-05-07 21:16:23Z fbraem $ + */ +#ifndef _WXJSTreeItemId_H +#define _WXJSTreeItemId_H + +namespace wxjs +{ + namespace gui + { + class TreeItemId : public ApiWrapper + { + public: + /** + * Callback for retrieving properties of wxTreeItemId + */ + static bool GetProperty(wxTreeItemId *p, + JSContext *cx, + JSObject *obj, + int id, + jsval *vp); + + WXJS_DECLARE_PROPERTY_MAP() + /** + * Property Ids. + */ + enum + { + P_OK + }; + }; + }; // namespace gui +}; // namespace wxjs + +#endif //_WXJSTreeItemId_H Property changes on: ps/trunk/source/tools/atlas/wxJS/gui/control/treeid.h ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/gui/control/tbartool.h =================================================================== --- ps/trunk/source/tools/atlas/wxJS/gui/control/tbartool.h (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/gui/control/tbartool.h (revision 5154) @@ -0,0 +1,81 @@ +/* + * wxJavaScript - toolbart.h + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id$ + */ +#ifndef _wxjs_toolbart_h +#define _wxjs_toolbart_h + +namespace wxjs +{ + namespace gui + { + class ToolBarToolBase : public ApiWrapper + { + public: + //static bool GetProperty(wxToolBarToolBase *p, + // JSContext *cx, + // JSObject *obj, + // int id, + // jsval *vp); + //static bool SetProperty(wxToolBarToolBase *p, + // JSContext *cx, + // JSObject *obj, + // int id, + // jsval *vp); + + WXJS_DECLARE_METHOD_MAP() + WXJS_DECLARE_METHOD(enable) + WXJS_DECLARE_METHOD(toggle) + }; + + class ToolBarToolData : public wxObject + { + public: + ToolBarToolData(JSContext *cx, JSObject *obj) : wxObject() + { + data = new JavaScriptClientData(cx, obj, true, false); + } + + virtual ~ToolBarToolData() + { + delete data; + } + + JSContext* GetContext() + { + return data->GetContext(); + } + + JSObject* GetObject() + { + return data->GetObject(); + } + + private: + JavaScriptClientData *data; + }; + }; +}; + +#endif // _wxjs_toolbart_h \ No newline at end of file Property changes on: ps/trunk/source/tools/atlas/wxJS/gui/control/tbartool.h ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/gui/control/fontdata.cpp =================================================================== --- ps/trunk/source/tools/atlas/wxJS/gui/control/fontdata.cpp (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/gui/control/fontdata.cpp (revision 5154) @@ -0,0 +1,171 @@ +#include "precompiled.h" + +/* + * wxJavaScript - fontdata.cpp + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: fontdata.cpp 598 2007-03-07 20:13:28Z fbraem $ + */ +// fontdata.cpp + +#ifndef WX_PRECOMP + #include +#endif + +#include "../../common/main.h" + +#include "fontdata.h" + +#include "../misc/font.h" +#include "../misc/colour.h" + +using namespace wxjs; +using namespace wxjs::gui; + +/*** + * control/fontdata + * gui + * + * This class holds a variety of information related to font dialogs. + * See @wxFontDialog + * + */ +WXJS_INIT_CLASS(FontData, "wxFontData", 0) + +/*** + * + * + * Under MS Windows, get/set a flag determining whether symbol fonts can be selected. + * Has no effect on other platforms + * + * + * Get/Set whether 'effects' are enabled under Windows. This refers to the controls for + * manipulating colour, strikeout and underline properties. + * + * + * Get the selected font + * + * + * + * Get/Set the font that will be initially used by the font dialog + * + * + * Show the help button? Windows only. + * + * + */ +WXJS_BEGIN_PROPERTY_MAP(FontData) + WXJS_PROPERTY(P_ALLOW_SYMBOLS, "allowSymbols") + WXJS_PROPERTY(P_ENABLE_EFFECTS, "enableEffects") + WXJS_PROPERTY(P_CHOSEN_FONT, "chosenFont") + WXJS_PROPERTY(P_COLOUR, "colour") + WXJS_PROPERTY(P_INITIAL_FONT, "initialFont") + WXJS_PROPERTY(P_SHOW_HELP, "showHelp") +WXJS_END_PROPERTY_MAP() + +bool FontData::GetProperty(wxFontData *p, JSContext *cx, JSObject *obj, int id, jsval *vp) +{ + switch (id) + { + case P_ALLOW_SYMBOLS: + *vp = ToJS(cx, p->GetAllowSymbols()); + break; + case P_ENABLE_EFFECTS: + *vp = ToJS(cx, p->GetEnableEffects()); + break; + case P_CHOSEN_FONT: + *vp = Font::CreateObject(cx, new wxFont(p->GetChosenFont()), obj); + break; + case P_COLOUR: + *vp = Colour::CreateObject(cx, new wxColour(p->GetColour())); + break; + case P_INITIAL_FONT: + *vp = Font::CreateObject(cx, new wxFont(p->GetInitialFont()), obj); + break; + case P_SHOW_HELP: + *vp = ToJS(cx, p->GetShowHelp()); + break; + } + return true; +} + +bool FontData::SetProperty(wxFontData *p, JSContext *cx, JSObject *obj, int id, jsval *vp) +{ + switch (id) + { + case P_ALLOW_SYMBOLS: + { + bool value; + if ( FromJS(cx, *vp, value) ) + p->SetAllowSymbols(value); + break; + } + case P_ENABLE_EFFECTS: + { + bool value; + if ( FromJS(cx, *vp, value) ) + p->EnableEffects(value); + break; + } + case P_CHOSEN_FONT: + { + wxFont *value = Font::GetPrivate(cx, *vp); + if ( value != NULL ) + p->SetChosenFont(*value); + break; + } + case P_COLOUR: + { + wxColour *colour = Colour::GetPrivate(cx, *vp); + if ( colour != NULL ) + p->SetColour(*colour); + break; + } + case P_INITIAL_FONT: + { + wxFont *value = Font::GetPrivate(cx, *vp); + if ( value != NULL ) + p->SetInitialFont(*value); + break; + } + case P_SHOW_HELP: + { + bool value; + if ( FromJS(cx, *vp, value) ) + p->SetShowHelp(value); + break; + } + } + return true; +} + +/*** + * + * + * + * Constructs a new wxFontData object. + * + * + */ +wxFontData* FontData::Construct(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, bool constructing) +{ + return new wxFontData(); +} Property changes on: ps/trunk/source/tools/atlas/wxJS/gui/control/fontdata.cpp ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/gui/control/coldlg.cpp =================================================================== --- ps/trunk/source/tools/atlas/wxJS/gui/control/coldlg.cpp (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/gui/control/coldlg.cpp (revision 5154) @@ -0,0 +1,153 @@ +#include "precompiled.h" + +/* + * wxJavaScript - coldlg.cpp + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: coldlg.cpp 708 2007-05-14 15:30:45Z fbraem $ + */ + +#ifndef WX_PRECOMP + #include +#endif + +#include "../../common/main.h" +#include "../../common/index.h" +#include "coldlg.h" +#include "coldata.h" +#include "window.h" + +#include "../misc/point.h" + +#include "../errors.h" + +using namespace wxjs; +using namespace wxjs::gui; + +/*** + * control/coldlg + * gui + * + * The wxColourDialog presents a colour selector to the user. + * See also @wxColourData. The following sample shows this + * dialog: + *

+ *    wxTheApp.onInit = function()
+ *    {
+ *      clrData = new wxColourData();
+ *      // Set the selected colour
+ *      clrData.colour = new wxColour(0, 0, 0);
+ *
+ *      // Set a custom colour
+ *      clrData.customColour[0]  = wxRED;
+ *    
+ *      dlg = new wxColourDialog(null, clrData);
+ *      dlg.title = "Select a colour";
+ *      dlg.showModal();
+ *
+ *      // Return false to exit the mainloop
+ *      return false;
+ *    }
+ *    wxTheApp.mainLoop();
+ *  
+ *
+ */ +WXJS_INIT_CLASS(ColourDialog, "wxColourDialog", 1) + +/*** + * + * + * Gets the colour data. + * + * + */ +WXJS_BEGIN_PROPERTY_MAP(ColourDialog) + WXJS_READONLY_PROPERTY(P_COLOUR_DATA, "colourData") +WXJS_END_PROPERTY_MAP() + +bool ColourDialog::GetProperty(wxColourDialog *p, + JSContext *cx, + JSObject* WXUNUSED(obj), + int id, + jsval *vp) +{ + if ( id == P_COLOUR_DATA ) + { + *vp = ColourData::CreateObject(cx, new wxColourData(p->GetColourData())); + } + return true; +} + +/*** + * + * + * + * The parent of wxColourDialog. + * + * + * The colour data. + * + * + * + * Constructs a new wxColourDialog object + * + * + */ +wxColourDialog* ColourDialog::Construct(JSContext *cx, + JSObject *obj, + uintN argc, + jsval *argv, + bool WXUNUSED(constructing)) +{ + if ( argc > 2 ) + argc = 2; + + wxColourData *data = NULL; + if ( argc == 2 ) + { + data = ColourData::GetPrivate(cx, argv[1]); + if ( data == NULL ) + { + JS_ReportError(cx, WXJS_INVALID_ARG_TYPE, 2, "wxColourData"); + return NULL; + } + } + + wxWindow *parent = Window::GetPrivate(cx, argv[0]); + if ( parent != NULL ) + { + JavaScriptClientData *clntParent = + dynamic_cast(parent->GetClientObject()); + if ( clntParent == NULL ) + { + JS_ReportError(cx, WXJS_NO_PARENT_ERROR, GetClass()->name); + return JS_FALSE; + } + JS_SetParent(cx, obj, clntParent->GetObject()); + } + + return new wxColourDialog(parent, data); +} + +void ColourDialog::Destruct(JSContext* WXUNUSED(cx), wxColourDialog *p) +{ + p->Destroy(); +} Property changes on: ps/trunk/source/tools/atlas/wxJS/gui/control/coldlg.cpp ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/gui/control/scrollwnd.cpp =================================================================== --- ps/trunk/source/tools/atlas/wxJS/gui/control/scrollwnd.cpp (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/gui/control/scrollwnd.cpp (revision 5154) @@ -0,0 +1,668 @@ +#include "precompiled.h" + +/* + * wxJavaScript - scrollwnd.cpp + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: scrollwnd.cpp 708 2007-05-14 15:30:45Z fbraem $ + */ +#ifndef WX_PRECOMP + #include +#endif + +/*** + * control/scrolwin + * gui + * + * The wxScrolledWindow class manages scrolling for its client area, transforming + * the coordinates according to the scrollbar positions, and setting the scroll positions, + * thumb sizes and ranges according to the area in view. + * + */ + +#include "../../common/main.h" + +#include "../misc/size.h" +#include "../misc/point.h" +#include "scrollwnd.h" +#include "panel.h" +#include "window.h" +#include "../errors.h" + +using namespace wxjs; +using namespace wxjs::gui; + +WXJS_INIT_CLASS(ScrolledWindow, "wxScrolledWindow", 1) + +/*** + * + * + * Motif only: true if the window has a backing bitmap + * + * + * Get the number of pixels per scroll unit (line), in each direction, as set + * by @wxScrolledWindow#setScrollbars. A value of zero indicates no scrolling + * in that direction. + * + * + * Get the position at which the visible portion of the window starts. + * + * + * Gets the size in device units of the scrollable window area + * (as opposed to the client size, which is the area of the window currently + * visible) + * + * + */ +WXJS_BEGIN_PROPERTY_MAP(ScrolledWindow) + WXJS_READONLY_PROPERTY(P_RETAINED, "retained") + WXJS_READONLY_PROPERTY(P_SCROLL_PIXELS_PER_UNIT, "scrollPixelsPerUnit") + WXJS_READONLY_PROPERTY(P_VIEW_START, "viewStart") + WXJS_READONLY_PROPERTY(P_VIRTUAL_SIZE, "virtualSize") +WXJS_END_PROPERTY_MAP() + +bool ScrolledWindow::GetProperty(wxScrolledWindow *p, + JSContext *cx, + JSObject* WXUNUSED(obj), + int id, + jsval *vp) +{ + switch (id) + { + case P_RETAINED: + *vp = ToJS(cx, p->IsRetained()); + break; + case P_SCROLL_PIXELS_PER_UNIT: + { + int x = 0; + int y = 0; + + p->GetScrollPixelsPerUnit(&x, &y); + + JSObject *objArr = JS_NewArrayObject(cx, 2, NULL); + *vp = OBJECT_TO_JSVAL(objArr); + jsval element = ToJS(cx, x); + JS_SetElement(cx, objArr, 0, &element); + element = ToJS(cx, y); + JS_SetElement(cx, objArr, 1, &element); + } + case P_VIEW_START: + { + int x = 0; + int y = 0; + + p->GetViewStart(&x, &y); + + JSObject *objArr = JS_NewArrayObject(cx, 2, NULL); + *vp = OBJECT_TO_JSVAL(objArr); + jsval element = ToJS(cx, x); + JS_SetElement(cx, objArr, 0, &element); + element = ToJS(cx, y); + JS_SetElement(cx, objArr, 1, &element); + } + case P_VIRTUAL_SIZE: + { + int x = 0; + int y = 0; + + p->GetVirtualSize(&x, &y); + + JSObject *objArr = JS_NewArrayObject(cx, 2, NULL); + *vp = OBJECT_TO_JSVAL(objArr); + jsval element = ToJS(cx, x); + JS_SetElement(cx, objArr, 0, &element); + element = ToJS(cx, y); + JS_SetElement(cx, objArr, 1, &element); + } + } + return true; +} + +bool ScrolledWindow::AddProperty(wxScrolledWindow *p, + JSContext* WXUNUSED(cx), + JSObject* WXUNUSED(obj), + const wxString &prop, + jsval* WXUNUSED(vp)) +{ + if ( WindowEventHandler::ConnectEvent(p, prop, true) ) + return true; + + PanelEventHandler::ConnectEvent(p, prop, true); + + return true; +} + + +bool ScrolledWindow::DeleteProperty(wxScrolledWindow *p, + JSContext* WXUNUSED(cx), + JSObject* WXUNUSED(obj), + const wxString &prop) +{ + if ( WindowEventHandler::ConnectEvent(p, prop, false) ) + return true; + + PanelEventHandler::ConnectEvent(p, prop, false); + return true; +} + +/*** + * + * + * + * The parent window + * A windows identifier. + * Use -1 when you don't need it. + * + * The position of the control on the given parent + * + * The size of the control + * + * The style of the control + * + * + * + * Constructs a new wxScrolledWindow object. + * + * + */ +wxScrolledWindow* ScrolledWindow::Construct(JSContext *cx, + JSObject *obj, + uintN argc, + jsval *argv, + bool WXUNUSED(constructing)) +{ + wxScrolledWindow *p = new wxScrolledWindow(); + SetPrivate(cx, obj, p); + + if ( argc > 0 ) + { + jsval rval; + create(cx, obj, argc, argv, &rval); + } + return p; +} + +WXJS_BEGIN_METHOD_MAP(ScrolledWindow) + WXJS_METHOD("calcScrolledPosition", calcScrolledPosition, 2) + WXJS_METHOD("calcUnscrolledPosition", calcUnscrolledPosition, 2) + WXJS_METHOD("enableScrolling", enableScrolling, 2) + WXJS_METHOD("scroll", scroll, 2) + WXJS_METHOD("setScrollbars", setScrollbars, 4) + WXJS_METHOD("setScrollRate", setScrollRate, 2) + WXJS_METHOD("setTargetWindow", setTargetWindow, 1) +WXJS_END_METHOD_MAP() + +/*** + * + * + * The parent window + * A windows identifier. + * Use -1 when you don't need it. + * + * The position of the control on the given parent + * + * The size of the control + * + * The style of the control + * + * + * + * Constructs a new wxScrolledWindow object. + * + * + */ +JSBool ScrolledWindow::create(JSContext *cx, + JSObject *obj, + uintN argc, + jsval *argv, + jsval *rval) +{ + wxScrolledWindow *p = GetPrivate(cx, obj); + *rval = JSVAL_FALSE; + + const wxPoint *pt = &wxDefaultPosition; + const wxSize *size = &wxDefaultSize; + int style = wxHSCROLL + wxVSCROLL; + int id = -1; + + if ( argc > 5 ) + argc = 5; + + switch(argc) + { + case 5: + if ( ! FromJS(cx, argv[4], style) ) + { + JS_ReportError(cx, WXJS_INVALID_ARG_TYPE, 5, "Integer"); + return JS_FALSE; + } + // Walk through + case 4: + size = Size::GetPrivate(cx, argv[3]); + if ( size == NULL ) + { + JS_ReportError(cx, WXJS_INVALID_ARG_TYPE, 4, "wxSize"); + return JS_FALSE; + } + // Walk through + case 3: + pt = Point::GetPrivate(cx, argv[2]); + if ( pt == NULL ) + { + JS_ReportError(cx, WXJS_INVALID_ARG_TYPE, 3, "wxPoint"); + return JS_FALSE; + } + // Walk through + case 2: + if ( ! FromJS(cx, argv[1], id) ) + { + JS_ReportError(cx, WXJS_INVALID_ARG_TYPE, 2, "Integer"); + return JS_FALSE; + } + // Walk through + default: + + wxWindow *parent = Window::GetPrivate(cx, argv[0]); + if ( parent == NULL ) + { + JS_ReportError(cx, WXJS_NO_PARENT_ERROR, GetClass()->name); + return JS_FALSE; + } + JavaScriptClientData *clntParent = + dynamic_cast(parent->GetClientObject()); + if ( clntParent == NULL ) + { + JS_ReportError(cx, WXJS_NO_PARENT_ERROR, GetClass()->name); + return JS_FALSE; + } + JS_SetParent(cx, obj, clntParent->GetObject()); + + if ( p->Create(parent, id, *pt, *size, style) ) + { + *rval = JSVAL_TRUE; + p->SetClientObject(new JavaScriptClientData(cx, obj, true, false)); + } + } + return JS_TRUE; +} + +/*** + * + * + * + * + * + * + * Translates the logical coordinates to the device ones. + * + * + */ +JSBool ScrolledWindow::calcScrolledPosition(JSContext* cx, + JSObject* obj, + uintN WXUNUSED(argc), + jsval* argv, + jsval* rval) +{ + wxScrolledWindow *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + int x = 0; + int y = 0; + int xx = 0; + int yy = 0; + + if ( FromJS(cx, argv[0], x) + && FromJS(cx, argv[1], y) ) + { + p->CalcScrolledPosition(x, y, &xx, &yy); + } + + JSObject *objArr = JS_NewArrayObject(cx, 2, NULL); + *rval = OBJECT_TO_JSVAL(objArr); + jsval element = ToJS(cx, xx); + JS_SetElement(cx, objArr, 0, &element); + element = ToJS(cx, yy); + JS_SetElement(cx, objArr, 1, &element); + + return JS_TRUE; +} + +/*** + * + * + * + * + * + * + * Translates the device coordinates to the logical ones. + * + * + */ +JSBool ScrolledWindow::calcUnscrolledPosition(JSContext *cx, + JSObject *obj, + uintN WXUNUSED(argc), + jsval *argv, + jsval *rval) +{ + wxScrolledWindow *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + int x = 0; + int y = 0; + int xx = 0; + int yy = 0; + + if ( FromJS(cx, argv[0], x) + && FromJS(cx, argv[1], y) ) + { + p->CalcUnscrolledPosition(x, y, &xx, &yy); + } + + JSObject *objArr = JS_NewArrayObject(cx, 2, NULL); + *rval = OBJECT_TO_JSVAL(objArr); + jsval element = ToJS(cx, xx); + JS_SetElement(cx, objArr, 0, &element); + element = ToJS(cx, yy); + JS_SetElement(cx, objArr, 1, &element); + + return JS_TRUE; +} + +/*** + * + * + * + * + * + * + * Enable or disable physical scrolling in the given direction. + * Physical scrolling is the physical transfer of bits up or down the + * screen when a scroll event occurs. If the application scrolls by a + * variable amount (e.g. if there are different font sizes) + * then physical scrolling will not work, and you should switch it off. + * Note that you will have to reposition child windows yourself, if physical + * scrolling is disabled. + *
+ * Physical scrolling may not be available on all platforms. Where it is + * available, it is enabled by default. + *
+ *
+ *
+ */ +JSBool ScrolledWindow::enableScrolling(JSContext *cx, + JSObject *obj, + uintN WXUNUSED(argc), + jsval *argv, + jsval* WXUNUSED(rval)) +{ + wxScrolledWindow *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + bool xScrolling = true; + bool yScrolling = true; + + if ( FromJS(cx, argv[0], xScrolling) + && FromJS(cx, argv[1], yScrolling) ) + { + p->EnableScrolling(xScrolling, yScrolling); + } + + return JS_TRUE; +} + +/*** + * + * + * + * Get the number of pixels per scroll unit (line), in each direction, as set + * by @wxScrolledWindow#setScrollbars. A value of zero indicates no scrolling + * in that direction. + * + * + */ +JSBool ScrolledWindow::getScrollPixelsPerUnit(JSContext *cx, + JSObject *obj, + uintN WXUNUSED(argc), + jsval* WXUNUSED(argv), + jsval *rval) +{ + wxScrolledWindow *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + int x = 0; + int y = 0; + + p->GetScrollPixelsPerUnit(&x, &y); + + JSObject *objArr = JS_NewArrayObject(cx, 2, NULL); + *rval = OBJECT_TO_JSVAL(objArr); + jsval element = ToJS(cx, x); + JS_SetElement(cx, objArr, 0, &element); + element = ToJS(cx, y); + JS_SetElement(cx, objArr, 1, &element); + + return JS_TRUE; +} + +/*** + * + * + * The x position to scroll to + * The y position to scroll to + * + * + * Scrolls a window so the view start is at the given point. + *
+ * The positions are in scroll units, not pixels, so to convert to pixels + * you will have to multiply by the number of pixels per scroll increment. + * If either parameter is -1, + * that position will be ignored (no change in that direction). + *
+ *
+ *
+ */ +JSBool ScrolledWindow::scroll(JSContext *cx, + JSObject *obj, + uintN WXUNUSED(argc), + jsval *argv, + jsval* WXUNUSED(rval)) +{ + wxScrolledWindow *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + int x = 0; + int y = 0; + + if ( FromJS(cx, argv[0], x) + && FromJS(cx, argv[1], y) ) + { + p->Scroll(x, y); + } + + return JS_TRUE; +} + +/*** + * + * + * + * Pixels per scroll unit in the horizontal direction. + * + * + * Pixels per scroll unit in the vertical direction. + * + * + * Number of units in the horizontal direction. + * + * + * Number of units in the vertical direction. + * + * + * Position to initialize the scrollbars in the horizontal direction, + * in scroll units. + * + * + * Position to initialize the scrollbars in the vertical direction, + * in scroll units. + * + * + * Will not refresh window if true. + * + * + * + * Sets up vertical and/or horizontal scrollbars. + *
+ * The first pair of parameters give the number of pixels per 'scroll step', + * i.e. amount moved when the up or down scroll arrows are pressed. + * The second pair gives the length of scrollbar in scroll steps, which sets + * the size of the virtual window. + * xPos and yPos optionally specify a position to scroll to immediately. + * For example, the following gives a window horizontal and vertical + * scrollbars with 20 pixels per scroll step, and a size of 50 steps + * (1000 pixels) in each direction. + * + * window.setScrollbars(20, 20, 50, 50); + * + * wxScrolledWindow manages the page size itself, using the current client + * window size as the page size. + *
+ *
+ *
+ */ +JSBool ScrolledWindow::setScrollbars(JSContext *cx, + JSObject *obj, + uintN argc, + jsval *argv, + jsval* WXUNUSED(rval)) +{ + wxScrolledWindow *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + int pixelsPerUnitX; + int pixelsPerUnitY; + int noUnitsX; + int noUnitsY; + int xPos = 0; + int yPos = 0; + bool noRefresh = false; + + if ( argc > 7 ) + argc = 7; + switch(argc) + { + case 7: + if ( ! FromJS(cx, argv[6], noRefresh) ) + break; + // fall trough + case 6: + if ( ! FromJS(cx, argv[5], yPos) ) + break; + // fall through + case 5: + if ( ! FromJS(cx, argv[4], xPos) ) + break; + // fall through + default: + { + if ( FromJS(cx, argv[0], pixelsPerUnitX) + && FromJS(cx, argv[1], pixelsPerUnitY) + && FromJS(cx, argv[2], noUnitsX) + && FromJS(cx, argv[3], noUnitsY) ) + { + p->SetScrollbars(pixelsPerUnitX, pixelsPerUnitY, + noUnitsX, noUnitsY, xPos, yPos, noRefresh); + } + } + } + return JS_TRUE; +} + +/*** + * + * + * + * + * + * + * Set the horizontal and vertical scrolling increment only. + * See the pixelsPerUnit parameter in @wxScrolledWindow#setScrollbars. + * + * + */ +JSBool ScrolledWindow::setScrollRate(JSContext *cx, + JSObject *obj, + uintN WXUNUSED(argc), + jsval *argv, + jsval* WXUNUSED(rval)) +{ + wxScrolledWindow *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + int x = 0; + int y = 0; + + if ( FromJS(cx, argv[0], x) + && FromJS(cx, argv[1], y) ) + { + p->SetScrollRate(x, y); + } + + return JS_TRUE; +} + +/*** + * + * + * + * + * + * Call this function to tell wxScrolledWindow to perform the actual scrolling + * on a different window (and not on itself). + * + * + */ +JSBool ScrolledWindow::setTargetWindow(JSContext *cx, + JSObject *obj, + uintN WXUNUSED(argc), + jsval *argv, + jsval* WXUNUSED(rval)) +{ + wxScrolledWindow *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + wxWindow *win = Window::GetPrivate(cx, argv[0]); + if ( win ) + { + p->SetTargetWindow(win); + } + + return JS_TRUE; +} Property changes on: ps/trunk/source/tools/atlas/wxJS/gui/control/scrollwnd.cpp ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/gui/control/treehit.h =================================================================== --- ps/trunk/source/tools/atlas/wxJS/gui/control/treehit.h (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/gui/control/treehit.h (revision 5154) @@ -0,0 +1,77 @@ +/* + * wxJavaScript - treehit.h + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: treehit.h 598 2007-03-07 20:13:28Z fbraem $ + */ +#ifndef _wxjs_treehit_h +#define _wxjs_treehit_h + +namespace wxjs +{ + namespace gui + { + /** + * Helper class for returning information for hittest + */ + class wxTreeHitTest + { + public: + wxTreeItemId GetItem() const + { + return m_item; + } + long GetFlags() const + { + return m_flags; + } + friend class TreeCtrl; + private: + + wxTreeHitTest(const wxTreeItemId& item, int flags) : m_item(item), m_flags(flags) + { + } + + wxTreeItemId m_item; + int m_flags; + }; + + class TreeHitTest : public ApiWrapper + { + public: + static bool GetProperty(wxTreeHitTest *p, JSContext *cx, JSObject *obj, int id, jsval *vp); + + WXJS_DECLARE_PROPERTY_MAP() + /** + * Property Ids. + */ + enum + { + P_ITEM + , P_FLAGS + }; + + WXJS_DECLARE_CONSTANT_MAP() + }; + }; // namespace gui +}; // namespace wxjs + +#endif // _wxjs_treehit_h Property changes on: ps/trunk/source/tools/atlas/wxJS/gui/control/treehit.h ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/gui/control/finddata.h =================================================================== --- ps/trunk/source/tools/atlas/wxJS/gui/control/finddata.h (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/gui/control/finddata.h (revision 5154) @@ -0,0 +1,68 @@ +/* + * wxJavaScript - finddata.h + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: finddata.h 672 2007-04-12 20:29:39Z fbraem $ + */ +#ifndef _WXJSFindReplaceData_H +#define _WXJSFindReplaceData_H + +#include + +namespace wxjs +{ + namespace gui + { + class FindReplaceData : public ApiWrapper + { + public: + static bool GetProperty(wxFindReplaceData *p, + JSContext *cx, + JSObject *obj, + int id, + jsval *vp); + static bool SetProperty(wxFindReplaceData *p, + JSContext *cx, + JSObject *obj, + int id, + jsval *vp); + + static wxFindReplaceData* Construct(JSContext *cx, + JSObject *obj, + uintN argc, + jsval *argv, + bool constructing); + + WXJS_DECLARE_CONSTANT_MAP() + + WXJS_DECLARE_PROPERTY_MAP() + enum + { + P_FINDSTRING + , P_REPLACESTRING + , P_FLAGS + }; + }; + }; // namespace gui +}; // namespace wxjs + +#endif //_WXJSFindReplaceData_H Property changes on: ps/trunk/source/tools/atlas/wxJS/gui/control/finddata.h ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/gui/control/slider.cpp =================================================================== --- ps/trunk/source/tools/atlas/wxJS/gui/control/slider.cpp (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/gui/control/slider.cpp (revision 5154) @@ -0,0 +1,888 @@ +#include "precompiled.h" + +/* + * wxJavaScript - slider.cpp + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: slider.cpp 708 2007-05-14 15:30:45Z fbraem $ + */ +// slider.cpp + +#ifndef WX_PRECOMP + #include +#endif + +#include "../../common/main.h" + + +#include "../event/jsevent.h" +#include "../event/command.h" +#include "../event/scroll.h" + +#include "../misc/size.h" +#include "../misc/point.h" +#include "../misc/validate.h" + +#include "slider.h" +#include "window.h" +#include "../errors.h" + +using namespace wxjs; +using namespace wxjs::gui; + +/*** + * control/slider + * gui + * + * A slider is a control with a handle which can be pulled back and forth + * to change the value. + * In Windows versions below Windows 95, a scrollbar is used to simulate the + * slider. In Windows 95, the track bar control is used. + * See also @wxScrollEvent. + * + */ +WXJS_INIT_CLASS(Slider, "wxSlider", 5) + +void Slider::InitClass(JSContext* WXUNUSED(cx), + JSObject* WXUNUSED(obj), + JSObject* WXUNUSED(proto)) +{ + SliderEventHandler::InitConnectEventMap(); +} + +/*** + * + * + * Get/Set the line size + * + * + * Get/Set the maximum value + * + * + * Get/Set the minimum value + * + * + * Get/Set the pagesize + * + * + * Get/Set the end selection point + * + * + * Get/Set the start selection point + * + * + * Get/Set the current value + * + * + */ +WXJS_BEGIN_PROPERTY_MAP(Slider) + WXJS_PROPERTY(P_LINESIZE, "lineSize") + WXJS_PROPERTY(P_MAX, "max") + WXJS_PROPERTY(P_MIN, "min") + WXJS_PROPERTY(P_PAGESIZE, "pageSize") + WXJS_PROPERTY(P_SEL_END, "selEnd") + WXJS_PROPERTY(P_SEL_START, "selStart") + WXJS_PROPERTY(P_THUMB_LENGTH, "thumbLength") + WXJS_PROPERTY(P_VALUE, "value") +WXJS_END_PROPERTY_MAP() + +/*** + * + * + * + * Displays the slider horizontally. + * + * + * Displays the slider vertically. + * + * + * Displays tick marks. + * + * + * Displays minimum, maximum and value labels. + * (NB: only displays the current value label under wxGTK) + * + * + * Displays ticks on the left, if a vertical slider. + * + * + * Displays ticks on the right, if a vertical slider. + * + * + * Displays ticks on the top, if a horizontal slider. + * + * + * Allows the user to select a range on the slider. Windows 95 only. + * + * + * + */ +WXJS_BEGIN_CONSTANT_MAP(Slider) + WXJS_CONSTANT(wxSL_, HORIZONTAL) + WXJS_CONSTANT(wxSL_, VERTICAL) + WXJS_CONSTANT(wxSL_, TICKS) + WXJS_CONSTANT(wxSL_, AUTOTICKS) + WXJS_CONSTANT(wxSL_, LABELS) + WXJS_CONSTANT(wxSL_, LEFT) + WXJS_CONSTANT(wxSL_, TOP) + WXJS_CONSTANT(wxSL_, RIGHT) + WXJS_CONSTANT(wxSL_, BOTTOM) + WXJS_CONSTANT(wxSL_, BOTH) + WXJS_CONSTANT(wxSL_, SELRANGE) +WXJS_END_CONSTANT_MAP() + +bool Slider::GetProperty(wxSlider *p, + JSContext *cx, + JSObject* WXUNUSED(obj), + int id, + jsval *vp) +{ + switch (id) + { + case P_LINESIZE: + *vp = ToJS(cx, p->GetLineSize()); + break; + case P_MAX: + *vp = ToJS(cx, p->GetMax()); + break; + case P_MIN: + *vp = ToJS(cx, p->GetMin()); + break; + case P_PAGESIZE: + *vp = ToJS(cx, p->GetPageSize()); + break; + case P_SEL_END: + *vp = ToJS(cx, p->GetSelEnd()); + break; + case P_SEL_START: + *vp = ToJS(cx, p->GetSelStart()); + break; + case P_THUMB_LENGTH: + *vp = ToJS(cx ,p->GetThumbLength()); + break; + case P_VALUE: + *vp = ToJS(cx, p->GetValue()); + break; + } + return true; +} + +bool Slider::SetProperty(wxSlider *p, + JSContext *cx, + JSObject* WXUNUSED(obj), + int id, + jsval *vp) +{ + switch (id) + { + case P_LINESIZE: + { + int value; + if ( FromJS(cx, *vp, value) ) + p->SetLineSize(value); + break; + } + case P_MAX: + { + int value; + if ( FromJS(cx, *vp, value) ) + p->SetRange(p->GetMin(), value); + break; + } + case P_MIN: + { + int value; + if ( FromJS(cx, *vp, value) ) + p->SetRange(value, p->GetMax()); + break; + } + case P_PAGESIZE: + { + int value; + if ( FromJS(cx, *vp, value) ) + p->SetPageSize(value); + break; + } + case P_SEL_END: + { + int value; + if ( FromJS(cx, *vp, value) ) + p->SetSelection(p->GetSelStart(), value); + break; + } + case P_SEL_START: + { + int value; + if ( FromJS(cx, *vp, value) ) + p->SetSelection(value, p->GetSelEnd()); + break; + } + case P_THUMB_LENGTH: + { + int value; + if ( FromJS(cx, *vp, value) ) + p->SetThumbLength(value); + break; + } + case P_TICK: + { + int value; + if ( FromJS(cx, *vp, value) ) + p->SetTick(value); + break; + } + case P_VALUE: + { + int value; + if ( FromJS(cx, *vp, value) ) + p->SetValue(value); + break; + } + } + return true; +} + +bool Slider::AddProperty(wxSlider *p, + JSContext* WXUNUSED(cx), + JSObject* WXUNUSED(obj), + const wxString &prop, + jsval* WXUNUSED(vp)) +{ + if ( WindowEventHandler::ConnectEvent(p, prop, true) ) + return true; + + SliderEventHandler::ConnectEvent(p, prop, true); + + return true; +} + + +bool Slider::DeleteProperty(wxSlider *p, + JSContext* WXUNUSED(cx), + JSObject* WXUNUSED(obj), + const wxString &prop) +{ + if ( WindowEventHandler::ConnectEvent(p, prop, false) ) + return true; + + SliderEventHandler::ConnectEvent(p, prop, false); + return true; +} + +/*** + * + * + * + * + * The parent of wxSlider. + * + * + * An window identifier. Use -1 when you don't need it. + * + * + * Initial position of the slider + * + * + * Minimum slider position. + * + * + * Maximum slider position. + * + * + * The position of the Slider control on the given parent. + * + * + * The size of the Slider control. + * + * + * The wxSlider style. + * + * + * + * + * Constructs a new wxSlider object. + * + * + */ +wxSlider* Slider::Construct(JSContext *cx, + JSObject *obj, + uintN argc, + jsval *argv, + bool WXUNUSED(constructing)) +{ + wxSlider *p = new wxSlider(); + SetPrivate(cx, obj, p); + + if ( argc > 0 ) + { + jsval rval; + create(cx, obj, argc, argv, &rval); + } + return p; +} + +WXJS_BEGIN_METHOD_MAP(Slider) + WXJS_METHOD("create", create, 5) + WXJS_METHOD("clearSel", clearSel, 0) + WXJS_METHOD("setRange", setRange, 2) + WXJS_METHOD("setSelection", setSelection, 2) + WXJS_METHOD("setTickFreq", setTickFreq, 2) +WXJS_END_METHOD_MAP() + +/*** + * + * + * + * The parent of wxSlider. + * + * + * An window identifier. Use -1 when you don't need it. + * + * + * Initial position of the slider + * + * + * Minimum slider position. + * + * + * Maximum slider position. + * + * + * The position of the Slider control on the given parent. + * + * + * The size of the Slider control. + * + * + * The wxSlider style. + * + * + * + * + * Constructs a new wxSlider object. + * + * + */ +JSBool Slider::create(JSContext *cx, + JSObject *obj, + uintN argc, + jsval *argv, + jsval *rval) +{ + wxSlider* p = GetPrivate(cx, obj); + *rval = JSVAL_FALSE; + + if ( argc > 9 ) + argc = 9; + + const wxPoint *pt = &wxDefaultPosition; + const wxSize *size = &wxDefaultSize; + int style = 0; + const wxValidator *val = &wxDefaultValidator; + + switch(argc) + { + case 9: + val = Validator::GetPrivate(cx, argv[8]); + if ( val == NULL ) + { + JS_ReportError(cx, WXJS_INVALID_ARG_TYPE, 9, "wxValidator"); + return JS_FALSE; + } + case 8: + if ( ! FromJS(cx, argv[7], style) ) + { + JS_ReportError(cx, WXJS_INVALID_ARG_TYPE, 8, "Integer"); + return JS_FALSE; + } + // Fall through + case 7: + size = Size::GetPrivate(cx, argv[6]); + if ( size == NULL ) + { + JS_ReportError(cx, WXJS_INVALID_ARG_TYPE, 7, "wxSize"); + return JS_FALSE; + } + // Fall through + case 6: + pt = Point::GetPrivate(cx, argv[5]); + if ( pt == NULL ) + { + JS_ReportError(cx, WXJS_INVALID_ARG_TYPE, 6, "wxPoint"); + return JS_FALSE; + } + // Fall through + default: + int max; + if ( ! FromJS(cx, argv[4], max) ) + { + JS_ReportError(cx, WXJS_INVALID_ARG_TYPE, 5, "Integer"); + return JS_FALSE; + } + + int min; + if ( ! FromJS(cx, argv[3], min) ) + { + JS_ReportError(cx, WXJS_INVALID_ARG_TYPE, 4, "Integer"); + return JS_FALSE; + } + + int value; + if ( ! FromJS(cx, argv[2], value) ) + { + JS_ReportError(cx, WXJS_INVALID_ARG_TYPE, 3, "Integer"); + return JS_FALSE; + } + + int id; + if ( ! FromJS(cx, argv[1], id) ) + { + JS_ReportError(cx, WXJS_INVALID_ARG_TYPE, 2, "Integer"); + return JS_FALSE; + } + + wxWindow *parent = Window::GetPrivate(cx, argv[0]); + if ( parent == NULL ) + { + JS_ReportError(cx, WXJS_NO_PARENT_ERROR, GetClass()->name); + return JS_FALSE; + } + JavaScriptClientData *clntParent = + dynamic_cast(parent->GetClientObject()); + if ( clntParent == NULL ) + { + JS_ReportError(cx, WXJS_NO_PARENT_ERROR, GetClass()->name); + return JS_FALSE; + } + JS_SetParent(cx, obj, clntParent->GetObject()); + + if ( p->Create(parent, id, value, min, max, *pt, *size, style, *val) ) + { + *rval = JSVAL_TRUE; + p->SetClientObject(new JavaScriptClientData(cx, obj, true, false)); + } + } + return JS_TRUE; +} + +/*** + * + * + * + * Clears the selection, for a slider with the SELRANGE style. + * + * + */ +JSBool Slider::clearSel(JSContext *cx, + JSObject *obj, + uintN WXUNUSED(argc), + jsval* WXUNUSED(argv), + jsval* WXUNUSED(rval)) +{ + wxSlider *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + p->ClearSel(); + + return JS_TRUE; +} + +/*** + * + * + * + * Clears the ticks. + * + * + */ +JSBool Slider::clearTicks(JSContext *cx, + JSObject *obj, + uintN WXUNUSED(argc), + jsval* WXUNUSED(argv), + jsval* WXUNUSED(rval)) +{ + wxSlider *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + p->ClearTicks(); + + return JS_TRUE; +} + +/*** + * + * + * + * The minimum value + * + * + * The maximum value + * + * + * + * Sets the minimum and maximum slider values. + * + * + */ +JSBool Slider::setRange(JSContext *cx, + JSObject *obj, + uintN WXUNUSED(argc), + jsval* argv, + jsval* WXUNUSED(rval)) +{ + wxSlider *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + int mini; + int maxi; + + if ( FromJS(cx, argv[0], mini) + && FromJS(cx, argv[1], maxi) ) + { + p->SetRange(mini, maxi); + } + else + { + return JS_FALSE; + } + + return JS_TRUE; +} + +/*** + * + * + * + * The selection start position + * + * + * The selection end position + * + * + * + * Sets the selection + * + * + */ +JSBool Slider::setSelection(JSContext *cx, + JSObject *obj, + uintN WXUNUSED(argc), + jsval *argv, + jsval* WXUNUSED(rval)) +{ + wxSlider *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + int start; + int end; + + if ( FromJS(cx, argv[0], start) + && FromJS(cx, argv[1], end) ) + { + p->SetSelection(start, end); + } + else + { + return JS_FALSE; + } + + return JS_TRUE; +} + +/*** + * + * + * + * Frequency + * + * + * Position + * + * + * + * Sets the tick mark frequency and position. + * + * + */ +JSBool Slider::setTickFreq(JSContext *cx, + JSObject *obj, + uintN WXUNUSED(argc), + jsval *argv, + jsval* WXUNUSED(rval)) +{ + wxSlider *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + int n; + int pos; + + if ( FromJS(cx, argv[0], n) + && FromJS(cx, argv[1], pos) ) + { + p->SetTickFreq(n, pos); + } + else + { + return JS_FALSE; + } + + return JS_TRUE; +} + +/*** + * + * + * Event is triggered when scrolling/ moving has finished independently of the + * way it had started. The argument of the function is a @wxScrollEvent. + * + * + * Catch a command to put the scroll thumb at the maximum position. + * The argument of the function is a @wxScrollEvent. + * + * + * Catch a command to put the scroll thumb at the maximum position. + * The argument of the function is a @wxScrollEvent. + * + * + * Catch a line up command. + * The argument of the function is a @wxScrollEvent. + * + * + * Catch a line down command. + * The argument of the function is a @wxScrollEvent. + * + * + * Catch a page up command. + * The argument of the function is a @wxScrollEvent. + * + * + * Catch a page down command. + * The argument of the function is a @wxScrollEvent. + * + * + * Catch a thumbtrack command (continuous movement of the scroll thumb). + * The argument of the function is a @wxScrollEvent. + * + * + * Catch a thumbtrack release command. + * The argument of the function is a @wxScrollEvent. + * + * + */ +WXJS_INIT_EVENT_MAP(wxSlider) +const wxString WXJS_SCROLL_CHANGED_EVENT = wxT("onScrollChanged"); +const wxString WXJS_SCROLL_TOP_EVENT = wxT("onScrollTop"); +const wxString WXJS_SCROLL_BOTTOM_EVENT = wxT("onScrollBottom"); +const wxString WXJS_SCROLL_LINEUP_EVENT = wxT("onScrollLineUp"); +const wxString WXJS_SCROLL_LINEDOWN_EVENT = wxT("onScrollLineDown"); +const wxString WXJS_SCROLL_PAGEUP_EVENT = wxT("onScrollPageUp"); +const wxString WXJS_SCROLL_PAGEDOWN_EVENT = wxT("onScrollPageDown"); +const wxString WXJS_SCROLL_THUMBTRACK_EVENT = wxT("onScrollThumbTrack"); +const wxString WXJS_SCROLL_THUMBRELEASE_EVENT = wxT("onScrollThumbRelease"); + +void SliderEventHandler::OnScrollChanged(wxScrollEvent& event) +{ + PrivScrollEvent::Fire(event, WXJS_SCROLL_CHANGED_EVENT); +} + +void SliderEventHandler::OnScrollTop(wxScrollEvent& event) +{ + PrivScrollEvent::Fire(event, WXJS_SCROLL_TOP_EVENT); +} + +void SliderEventHandler::OnScrollBottom(wxScrollEvent& event) +{ + PrivScrollEvent::Fire(event, WXJS_SCROLL_BOTTOM_EVENT); +} + +void SliderEventHandler::OnScrollLineUp(wxScrollEvent& event) +{ + PrivScrollEvent::Fire(event, WXJS_SCROLL_LINEUP_EVENT); +} + +void SliderEventHandler::OnScrollLineDown(wxScrollEvent& event) +{ + PrivScrollEvent::Fire(event, WXJS_SCROLL_LINEDOWN_EVENT); +} + +void SliderEventHandler::OnScrollPageUp(wxScrollEvent& event) +{ + PrivScrollEvent::Fire(event, WXJS_SCROLL_PAGEUP_EVENT); +} + +void SliderEventHandler::OnScrollPageDown(wxScrollEvent& event) +{ + PrivScrollEvent::Fire(event, WXJS_SCROLL_PAGEDOWN_EVENT); +} + +void SliderEventHandler::OnScrollThumbTrack(wxScrollEvent& event) +{ + PrivScrollEvent::Fire(event, WXJS_SCROLL_THUMBTRACK_EVENT); +} + +void SliderEventHandler::OnScrollThumbRelease(wxScrollEvent& event) +{ + PrivScrollEvent::Fire(event, WXJS_SCROLL_THUMBRELEASE_EVENT); +} + +void SliderEventHandler::ConnectScrollChanged(wxSlider *p, bool connect) +{ + if ( connect ) + { + p->Connect(wxEVT_SCROLL_CHANGED, + wxScrollEventHandler(OnScrollChanged)); + } + else + { + p->Disconnect(wxEVT_SCROLL_CHANGED, + wxScrollEventHandler(OnScrollChanged)); + } +} + +void SliderEventHandler::ConnectScrollTop(wxSlider *p, bool connect) +{ + if ( connect ) + { + p->Connect(wxEVT_SCROLL_TOP, + wxScrollEventHandler(OnScrollTop)); + } + else + { + p->Disconnect(wxEVT_SCROLL_TOP, + wxScrollEventHandler(OnScrollTop)); + } +} + +void SliderEventHandler::ConnectScrollBottom(wxSlider *p, bool connect) +{ + if ( connect ) + { + p->Connect(wxEVT_SCROLL_BOTTOM, + wxScrollEventHandler(OnScrollBottom)); + } + else + { + p->Disconnect(wxEVT_SCROLL_BOTTOM, + wxScrollEventHandler(OnScrollBottom)); + } +} + +void SliderEventHandler::ConnectScrollLineUp(wxSlider *p, bool connect) +{ + if ( connect ) + { + p->Connect(wxEVT_SCROLL_LINEUP, + wxScrollEventHandler(OnScrollTop)); + } + else + { + p->Disconnect(wxEVT_SCROLL_LINEUP, + wxScrollEventHandler(OnScrollTop)); + } +} + +void SliderEventHandler::ConnectScrollLineDown(wxSlider *p, bool connect) +{ + if ( connect ) + { + p->Connect(wxEVT_SCROLL_LINEDOWN, + wxScrollEventHandler(OnScrollLineDown)); + } + else + { + p->Disconnect(wxEVT_SCROLL_LINEDOWN, + wxScrollEventHandler(OnScrollLineDown)); + } +} + +void SliderEventHandler::ConnectScrollPageUp(wxSlider *p, bool connect) +{ + if ( connect ) + { + p->Connect(wxEVT_SCROLL_PAGEUP, + wxScrollEventHandler(OnScrollPageUp)); + } + else + { + p->Disconnect(wxEVT_SCROLL_PAGEUP, + wxScrollEventHandler(OnScrollPageUp)); + } +} + +void SliderEventHandler::ConnectScrollPageDown(wxSlider *p, bool connect) +{ + if ( connect ) + { + p->Connect(wxEVT_SCROLL_PAGEDOWN, + wxScrollEventHandler(OnScrollPageDown)); + } + else + { + p->Disconnect(wxEVT_SCROLL_PAGEDOWN, + wxScrollEventHandler(OnScrollPageDown)); + } +} + +void SliderEventHandler::ConnectScrollThumbTrack(wxSlider *p, bool connect) +{ + if ( connect ) + { + p->Connect(wxEVT_SCROLL_THUMBTRACK, + wxScrollEventHandler(OnScrollThumbTrack)); + } + else + { + p->Disconnect(wxEVT_SCROLL_THUMBTRACK, + wxScrollEventHandler(OnScrollThumbTrack)); + } +} + +void SliderEventHandler::ConnectScrollThumbRelease(wxSlider *p, bool connect) +{ + if ( connect ) + { + p->Connect(wxEVT_SCROLL_THUMBRELEASE, + wxScrollEventHandler(OnScrollThumbRelease)); + } + else + { + p->Disconnect(wxEVT_SCROLL_THUMBRELEASE, + wxScrollEventHandler(OnScrollThumbRelease)); + } +} + +void SliderEventHandler::InitConnectEventMap() +{ + AddConnector(WXJS_SCROLL_CHANGED_EVENT, ConnectScrollChanged); + AddConnector(WXJS_SCROLL_TOP_EVENT, ConnectScrollTop); + AddConnector(WXJS_SCROLL_BOTTOM_EVENT, ConnectScrollBottom); + AddConnector(WXJS_SCROLL_LINEUP_EVENT, ConnectScrollLineUp); + AddConnector(WXJS_SCROLL_LINEDOWN_EVENT, ConnectScrollLineDown); + AddConnector(WXJS_SCROLL_PAGEUP_EVENT, ConnectScrollPageUp); + AddConnector(WXJS_SCROLL_PAGEDOWN_EVENT, ConnectScrollPageDown); + AddConnector(WXJS_SCROLL_THUMBTRACK_EVENT, ConnectScrollThumbTrack); + AddConnector(WXJS_SCROLL_THUMBRELEASE_EVENT, ConnectScrollThumbRelease); +} Property changes on: ps/trunk/source/tools/atlas/wxJS/gui/control/slider.cpp ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/gui/control/sttext.cpp =================================================================== --- ps/trunk/source/tools/atlas/wxJS/gui/control/sttext.cpp (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/gui/control/sttext.cpp (revision 5154) @@ -0,0 +1,278 @@ +#include "precompiled.h" + +/* + * wxJavaScript - sttext.cpp + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: sttext.cpp 708 2007-05-14 15:30:45Z fbraem $ + */ + +#ifndef WX_PRECOMP + #include +#endif + +#include "../../common/main.h" + + + +#include "sttext.h" +#include "window.h" + +#include "../misc/point.h" +#include "../misc/size.h" +#include "../errors.h" + +using namespace wxjs; +using namespace wxjs::gui; + +/*** + * control/sttext + * gui + * + * A static text control displays one or more lines of read-only text. + * + */ +WXJS_INIT_CLASS(StaticText, "wxStaticText", 3) + +/*** + * + * + * Get/Sets the text. + * + * + */ +WXJS_BEGIN_PROPERTY_MAP(StaticText) + WXJS_PROPERTY(P_LABEL, "label") +WXJS_END_PROPERTY_MAP() + +/*** + * + * + * + * + * + * + * + * + */ +WXJS_BEGIN_CONSTANT_MAP(StaticText) + WXJS_CONSTANT(wx, ALIGN_LEFT) + WXJS_CONSTANT(wx, ALIGN_RIGHT) + WXJS_CONSTANT(wx, ALIGN_CENTER) + WXJS_CONSTANT(wxST_, NO_AUTORESIZE) +WXJS_END_CONSTANT_MAP() + +bool StaticText::GetProperty(wxStaticText *p, + JSContext *cx, + JSObject* WXUNUSED(obj), + int id, + jsval *vp) +{ + if (id == P_LABEL ) + { + *vp = ToJS(cx, p->GetLabel()); + } + return true; +} + +bool StaticText::SetProperty(wxStaticText *p, + JSContext *cx, + JSObject* WXUNUSED(obj), + int id, + jsval *vp) +{ + if ( id == P_LABEL ) + { + wxString label; + FromJS(cx, *vp, label); + p->SetLabel(label); + } + return true; +} + +bool StaticText::AddProperty(wxStaticText *p, + JSContext* WXUNUSED(cx), + JSObject* WXUNUSED(obj), + const wxString &prop, + jsval* WXUNUSED(vp)) +{ + WindowEventHandler::ConnectEvent(p, prop, true); + return true; +} + +bool StaticText::DeleteProperty(wxStaticText *p, + JSContext* WXUNUSED(cx), + JSObject* WXUNUSED(obj), + const wxString &prop) +{ + WindowEventHandler::ConnectEvent(p, prop, false); + return true; +} + +/*** + * + * + * + * + * The parent of the static text. This can't be null. + * + * + * The unique identifier. + * + * + * The text of the static text + * + * + * The position of the static text. + * + * + * The size of the static text. + * + * + * The style of the static text. See @wxStaticText#styles + * + * + * + * Constructs a new wxStaticText object + * + * + */ +wxStaticText* StaticText::Construct(JSContext *cx, + JSObject *obj, + uintN argc, + jsval *argv, + bool WXUNUSED(constructing)) +{ + wxStaticText *p = new wxStaticText(); + SetPrivate(cx, obj, p); + + if ( argc > 0 ) + { + jsval rval; + create(cx, obj, argc, argv, &rval); + } + return p; +} + +WXJS_BEGIN_METHOD_MAP(StaticText) + WXJS_METHOD("create", create, 2) +WXJS_END_METHOD_MAP() + +/*** + * + * + * + * The parent of the static text. This can't be null. + * + * + * The unique identifier. + * + * + * The text of the static text + * + * + * The position of the static text. + * + * + * The size of the static text. + * + * + * The style of the static text. See @wxStaticText#styles + * + * + * + * Constructs a new wxStaticText object + * + * + */ +JSBool StaticText::create(JSContext *cx, + JSObject *obj, + uintN argc, + jsval *argv, + jsval *rval) +{ + wxStaticText *p = GetPrivate(cx, obj); + *rval = JSVAL_FALSE; + + if ( argc > 6 ) + argc = 6; + + const wxPoint *pt = &wxDefaultPosition; + const wxSize *size = &wxDefaultSize; + int style = 0; + + switch(argc) + { + case 6: + if ( ! FromJS(cx, argv[5], style) ) + { + JS_ReportError(cx, WXJS_INVALID_ARG_TYPE, 6, "Integer"); + return JS_FALSE; + } // Fall through + case 5: + size = Size::GetPrivate(cx, argv[4]); + if ( size == NULL ) + { + JS_ReportError(cx, WXJS_INVALID_ARG_TYPE, 5, "wxSize"); + return JS_FALSE; + } // Fall through + case 4: + pt = Point::GetPrivate(cx, argv[3]); + if ( pt == NULL ) + { + JS_ReportError(cx, WXJS_INVALID_ARG_TYPE, 4, "wxPoint"); + return JS_FALSE; + } // Fall through + default: + wxString text; + FromJS(cx, argv[2], text); + + int id; + if ( ! FromJS(cx, argv[1], id) ) + { + JS_ReportError(cx, WXJS_INVALID_ARG_TYPE, 2, "Integer"); + return JS_FALSE; + } + + wxWindow *parent = Window::GetPrivate(cx, argv[0]); + if ( parent == NULL ) + { + JS_ReportError(cx, WXJS_NO_PARENT_ERROR, GetClass()->name); + return JS_FALSE; + } + JavaScriptClientData *clntParent = + dynamic_cast(parent->GetClientObject()); + if ( clntParent == NULL ) + { + JS_ReportError(cx, WXJS_NO_PARENT_ERROR, GetClass()->name); + return JS_FALSE; + } + JS_SetParent(cx, obj, clntParent->GetObject()); + + if ( p->Create(parent, id, text, *pt, *size, style) ) + { + *rval = JSVAL_TRUE; + p->SetClientObject(new JavaScriptClientData(cx, obj, true, false)); + } + } + + return JS_TRUE; +} Property changes on: ps/trunk/source/tools/atlas/wxJS/gui/control/sttext.cpp ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/gui/control/toplevel.h =================================================================== --- ps/trunk/source/tools/atlas/wxJS/gui/control/toplevel.h (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/gui/control/toplevel.h (revision 5154) @@ -0,0 +1,73 @@ +/* + * wxJavaScript - toplevel.h + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: toplevel.h 695 2007-05-04 20:51:28Z fbraem $ + */ +#ifndef _WXJSTopLevel_H +#define _WXJSTopLevel_H + +namespace wxjs +{ + namespace gui + { + class TopLevelWindow : public ApiWrapper + { + public: + static bool GetProperty(wxTopLevelWindow *p, + JSContext *cx, + JSObject *obj, + int id, + jsval *vp); + static bool SetProperty(wxTopLevelWindow *p, + JSContext *cx, + JSObject *obj, + int id, + jsval *vp); + static void InitClass(JSContext *cx, + JSObject *obj, + JSObject *proto); + + WXJS_DECLARE_METHOD(requestUserAttention) + WXJS_DECLARE_METHOD(setLeftMenu) + WXJS_DECLARE_METHOD(setRightMenu) + WXJS_DECLARE_METHOD(showFullScreen) + + enum + { + P_DEFAULT_ITEM + , P_FULL_SCREEN + , P_ICON + , P_ICONS + , P_ACTIVE + , P_ICONIZED + , P_MAXIMIZED + , P_TITLE + }; + + WXJS_DECLARE_PROPERTY_MAP() + WXJS_DECLARE_METHOD_MAP() + }; + }; // namespace gui +}; // namespace wxjs + +#endif //_WXJSTopLevel_H Property changes on: ps/trunk/source/tools/atlas/wxJS/gui/control/toplevel.h ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/gui/control/item.h =================================================================== --- ps/trunk/source/tools/atlas/wxJS/gui/control/item.h (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/gui/control/item.h (revision 5154) @@ -0,0 +1,52 @@ +/* + * wxJavaScript - item.h + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: item.h 598 2007-03-07 20:13:28Z fbraem $ + */ +#ifndef _WXJSControlItem_H +#define _WXJSControlItem_H + +namespace wxjs +{ + namespace gui + { + class ControlItem : public ApiWrapper + { + public: + + static bool GetProperty(Index *p, JSContext *cx, JSObject *obj, int id, jsval *vp); + static bool SetProperty(Index *p, JSContext *cx, JSObject *obj, int id, jsval *vp); + + static JSBool remove(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval); + static JSBool select(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval); + + WXJS_DECLARE_PROPERTY_MAP() + WXJS_DECLARE_METHOD_MAP() + + enum + { + P_VALUE = WXJS_START_PROPERTY_ID + }; + }; + }; // namespace gui +}; // namespace wxjs +#endif //_WXJSControlItem_H Property changes on: ps/trunk/source/tools/atlas/wxJS/gui/control/item.h ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/gui/control/radiobox.cpp =================================================================== --- ps/trunk/source/tools/atlas/wxJS/gui/control/radiobox.cpp (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/gui/control/radiobox.cpp (revision 5154) @@ -0,0 +1,567 @@ +#include "precompiled.h" + +/* + * wxJavaScript - radiobox.cpp + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: radiobox.cpp 708 2007-05-14 15:30:45Z fbraem $ + */ +// radiobox.cpp + +#ifndef WX_PRECOMP + #include +#endif + +#include "../../common/main.h" +#include "../../common/index.h" + + +#include "../event/jsevent.h" +#include "../event/command.h" + +#include "../misc/size.h" +#include "../misc/point.h" +#include "../misc/validate.h" + +#include "radiobox.h" +#include "radioboxit.h" +#include "window.h" +#include "../errors.h" + +using namespace wxjs; +using namespace wxjs::gui; + +/*** + * control/radiobox + * gui + * + * A radio box item is used to select one of number of mutually exclusive choices. + * It is displayed as a vertical column or horizontal row of labelled buttons. + * + */ +WXJS_INIT_CLASS(RadioBox, "wxRadioBox", 3) + +void RadioBox::InitClass(JSContext* WXUNUSED(cx), + JSObject* WXUNUSED(obj), + JSObject* WXUNUSED(proto)) +{ + RadioBoxEventHandler::InitConnectEventMap(); +} + +/*** + * + * + * Get the number of items + * + * + * Get an array of with @wxRadioBoxItem items. + * + * + * Get/Set the selected button. (zero-indexed) + * + * + * Get/Set the selected string. + * + * + */ +WXJS_BEGIN_PROPERTY_MAP(RadioBox) + WXJS_PROPERTY(P_SELECTION, "selection") + WXJS_PROPERTY(P_STRING_SELECTION, "stringSelection") + WXJS_READONLY_PROPERTY(P_COUNT, "count") + WXJS_READONLY_PROPERTY(P_ITEM, "item") +WXJS_END_PROPERTY_MAP() + +bool RadioBox::GetProperty(wxRadioBox* p, + JSContext* cx, + JSObject* WXUNUSED(obj), + int id, + jsval* vp) +{ + switch (id) + { + case P_COUNT: + *vp = ToJS(cx, p->GetCount()); + break; + case P_SELECTION: + *vp = ToJS(cx, p->GetSelection()); + break; + case P_STRING_SELECTION: + *vp = ToJS(cx, p->GetStringSelection()); + break; + case P_ITEM: + *vp = RadioBoxItem::CreateObject(cx, new Index(0)); + break; + } + return true; +} + +bool RadioBox::SetProperty(wxRadioBox* p, + JSContext* cx, + JSObject* WXUNUSED(obj), + int id, + jsval* vp) +{ + switch (id) + { + case P_SELECTION: + { + int value; + if ( FromJS(cx, *vp, value) ) + p->SetSelection(value); + break; + } + case P_STRING_SELECTION: + { + wxString value; + FromJS(cx, *vp, value); + p->SetStringSelection(value); + break; + } + } + return true; +} + +bool RadioBox::AddProperty(wxRadioBox *p, + JSContext* WXUNUSED(cx), + JSObject* WXUNUSED(obj), + const wxString &prop, + jsval* WXUNUSED(vp)) +{ + if ( WindowEventHandler::ConnectEvent(p, prop, true) ) + return true; + + RadioBoxEventHandler::ConnectEvent(p, prop, true); + + return true; +} + +bool RadioBox::DeleteProperty(wxRadioBox *p, + JSContext* WXUNUSED(cx), + JSObject* WXUNUSED(obj), + const wxString &prop) +{ + if ( WindowEventHandler::ConnectEvent(p, prop, false) ) + return true; + + RadioBoxEventHandler::ConnectEvent(p, prop, false); + return true; +} + +/*** + * + * + * The major dimension parameter refers to the maximum number of rows. + * The major dimension parameter refers to the maximum number of columns. + * + * + */ +WXJS_BEGIN_CONSTANT_MAP(RadioBox) + WXJS_CONSTANT(wxRA_, SPECIFY_ROWS) + WXJS_CONSTANT(wxRA_, SPECIFY_COLS) +WXJS_END_CONSTANT_MAP() + +/*** + * + * + * + * The parent of wxRadioBox. + * A window identifier. Use -1 when you don't need it. + * The title of the radiobox. + * + * The position of the RadioBox control on the given parent. + * + * + * The size of the RadioBox control. + * + * + * An array of Strings to initialize the control. + * + * + * Specifies the maximum number of rows (if style contains SPECIFY_ROWS) or columns + * (if style contains SPECIFY_COLS) for a two-dimensional radiobox. + * + * + * The wxRadioBox style. + * + * + * + * + * Constructs a new wxRadioBox object. + * + * + */ +wxRadioBox* RadioBox::Construct(JSContext* cx, + JSObject* obj, + uintN argc, + jsval* argv, + bool WXUNUSED(constructing)) +{ + wxRadioBox *p = new wxRadioBox(); + SetPrivate(cx, obj, p); + + if ( argc > 0 ) + { + jsval rval; + create(cx, obj, argc, argv, &rval); + } + return p; +} + +WXJS_BEGIN_METHOD_MAP(RadioBox) + WXJS_METHOD("create", create, 3) + WXJS_METHOD("setString", setString, 2) + WXJS_METHOD("findString", setString, 2) + WXJS_METHOD("enable", enable, 2) + WXJS_METHOD("show", show, 2) +WXJS_END_METHOD_MAP() + +/*** + * + * + * The parent of wxRadioBox. + * A window identifier. Use -1 when you don't need it. + * The title of the radiobox. + * + * The position of the RadioBox control on the given parent. + * + * + * The size of the RadioBox control. + * + * + * An array of Strings to initialize the control. + * + * + * Specifies the maximum number of rows (if style contains SPECIFY_ROWS) or columns + * (if style contains SPECIFY_COLS) for a two-dimensional radiobox. + * + * + * The wxRadioBox style. + * + * + * + * + * Constructs a new wxRadioBox object. + * + * + */ +JSBool RadioBox::create(JSContext *cx, + JSObject *obj, + uintN argc, + jsval *argv, + jsval *rval) +{ + wxRadioBox *p = GetPrivate(cx, obj); + *rval = JSVAL_FALSE; + + if ( argc > 9 ) + argc = 9; + + int style = 0; + int max = 0; + StringsPtr items; + const wxSize *size = &wxDefaultSize; + const wxPoint *pt = &wxDefaultPosition; + const wxValidator *val = &wxDefaultValidator; + + switch(argc) + { + case 9: + val = Validator::GetPrivate(cx, argv[8]); + if ( val == NULL ) + { + JS_ReportError(cx, WXJS_INVALID_ARG_TYPE, 9, "wxValidator"); + return JS_FALSE; + } + case 8: + if ( ! FromJS(cx, argv[7], style) ) + { + JS_ReportError(cx, WXJS_INVALID_ARG_TYPE, 8, "Integer"); + return JS_FALSE; + } + // Fall through + case 7: + if ( ! FromJS(cx, argv[6], max) ) + { + JS_ReportError(cx, WXJS_INVALID_ARG_TYPE, 7, "Integer"); + return JS_FALSE; + } + // Fall through + case 6: + if ( ! FromJS(cx, argv[5], items) ) + { + JS_ReportError(cx, WXJS_INVALID_ARG_TYPE, 6, "String Array"); + return JS_FALSE; + } + // Fall through + case 5: + size = Size::GetPrivate(cx, argv[4]); + if ( size == NULL ) + { + JS_ReportError(cx, WXJS_INVALID_ARG_TYPE, 5, "wxSize"); + return JS_FALSE; + } + // Fall through + case 4: + pt = Point::GetPrivate(cx, argv[3]); + if ( pt == NULL ) + { + JS_ReportError(cx, WXJS_INVALID_ARG_TYPE, 4, "wxPoint"); + return JS_FALSE; + } + // Fall through + default: + wxString title; + FromJS(cx, argv[2], title); + + int id; + if ( ! FromJS(cx, argv[1], id) ) + { + JS_ReportError(cx, WXJS_INVALID_ARG_TYPE, 2, "Integer"); + return JS_FALSE; + } + + wxWindow *parent = Window::GetPrivate(cx, argv[0]); + if ( parent == NULL ) + { + JS_ReportError(cx, WXJS_NO_PARENT_ERROR, GetClass()->name); + return JS_FALSE; + } + JavaScriptClientData *clntParent = + dynamic_cast(parent->GetClientObject()); + if ( clntParent == NULL ) + { + JS_ReportError(cx, WXJS_NO_PARENT_ERROR, GetClass()->name); + return JS_FALSE; + } + JS_SetParent(cx, obj, clntParent->GetObject()); + if ( p->Create(parent, id, title, *pt, *size, + items.GetCount(), items.GetStrings(), max, style, *val) ) + { + *rval = JSVAL_TRUE; + p->SetClientObject(new JavaScriptClientData(cx, obj, true, false)); + } + } + + return JS_TRUE; +} + +/*** + * + * + * + * The zero-based index of a button + * + * + * Sets the label of the button. + * + * + * + * + */ +JSBool RadioBox::setString(JSContext* cx, + JSObject* obj, + uintN WXUNUSED(argc), + jsval* argv, + jsval* WXUNUSED(rval)) +{ + wxRadioBox *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + int idx; + wxString label; + + if ( FromJS(cx, argv[0], idx) ) + { + FromJS(cx, argv[1], label); + p->SetString(idx, label); + } + else + { + return JS_FALSE; + } + return JS_TRUE; +} + +/*** + * + * + * + * + * + * Finds a button matching the given string, returning the position if found, + * or -1 if not found. + * + * + */ +JSBool RadioBox::findString(JSContext *cx, + JSObject *obj, + uintN WXUNUSED(argc), + jsval *argv, + jsval *rval) +{ + wxRadioBox *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + wxString label; + FromJS(cx, argv[0], label); + *rval = ToJS(cx, p->FindString(label)); + + return JS_TRUE; +} + +/*** + * + * + * + * + * + * + * The zero-based index of a button + * + * + * + * + * Enables/Disables the button at the given index. + * See @wxRadioBoxItem @wxRadioBoxItem#enable. + * + * + */ +JSBool RadioBox::enable(JSContext* cx, + JSObject* obj, + uintN argc, + jsval* argv, + jsval* WXUNUSED(rval)) +{ + wxRadioBox *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + if ( argc == 1 ) // The prototype method enable + { + bool sw; + if ( FromJS(cx, argv[0], sw) ) + { + p->Enable(sw); + return JS_TRUE; + } + } + else if ( argc == 2 ) + { + int idx; + bool sw; + if ( FromJS(cx, argv[0], idx) + && FromJS(cx, argv[1], sw) ) + { + p->Enable(idx, sw); + return JS_TRUE; + } + } + + return JS_FALSE; +} + +/*** + * + * + * + * + * + * + * The zero-based index of a button + * + * + * + * + * Shows/Hides the button at the given index. + * See @wxRadioBoxItem @wxRadioBoxItem#enable. + * + * + */ +JSBool RadioBox::show(JSContext* cx, + JSObject* obj, + uintN argc, + jsval* argv, + jsval* WXUNUSED(rval)) +{ + wxRadioBox *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + if ( argc == 1 ) // The prototype method enable + { + bool sw; + if ( FromJS(cx, argv[0], sw) ) + { + p->Show(sw); + return JS_TRUE; + } + } + else if ( argc == 2 ) + { + int idx; + bool sw; + if ( FromJS(cx, argv[0], idx) + && FromJS(cx, argv[1], sw) ) + { + p->Show(idx, sw); + return JS_TRUE; + } + } + + return JS_FALSE; +} + +/*** + * + * + * Called when a radio button is clicked. The type of the argument that your + * handler receives is @wxCommandEvent. + * + * + */ +WXJS_INIT_EVENT_MAP(wxRadioBox) +const wxString WXJS_RADIOBOX_EVENT = wxT("onRadioBox"); + +void RadioBoxEventHandler::OnRadioBox(wxCommandEvent &event) +{ + PrivCommandEvent::Fire(event, WXJS_RADIOBOX_EVENT); +} + +void RadioBoxEventHandler::ConnectRadioBox(wxRadioBox *p, bool connect) +{ + if ( connect ) + { + p->Connect(wxEVT_COMMAND_RADIOBOX_SELECTED, + wxCommandEventHandler(OnRadioBox)); + } + else + { + p->Disconnect(wxEVT_COMMAND_RADIOBOX_SELECTED, + wxCommandEventHandler(OnRadioBox)); + } +} + +void RadioBoxEventHandler::InitConnectEventMap() +{ + AddConnector(WXJS_RADIOBOX_EVENT, ConnectRadioBox); +} Property changes on: ps/trunk/source/tools/atlas/wxJS/gui/control/radiobox.cpp ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/gui/control/combobox.cpp =================================================================== --- ps/trunk/source/tools/atlas/wxJS/gui/control/combobox.cpp (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/gui/control/combobox.cpp (revision 5154) @@ -0,0 +1,667 @@ +#include "precompiled.h" + +/* + * wxJavaScript - combobox.cpp + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: combobox.cpp 708 2007-05-14 15:30:45Z fbraem $ + */ + +#ifndef WX_PRECOMP + #include +#endif + +#include "../../common/main.h" +#include "../../common/index.h" + +#include "../event/jsevent.h" +#include "../event/command.h" + +#include "combobox.h" +#include "window.h" + +#include "../misc/point.h" +#include "../misc/size.h" +#include "../misc/validate.h" +#include "../errors.h" + +using namespace wxjs; +using namespace wxjs::gui; + +/*** + * control/combobox + * gui + * + * A combobox is like a combination of an edit control and a listbox. + * It can be displayed as static list with editable or read-only text field; + * or a drop-down list with text field; or a drop-down list without a text + * field. + * + */ +WXJS_INIT_CLASS(ComboBox, "wxComboBox", 2) + +void ComboBox::InitClass(JSContext* WXUNUSED(cx), + JSObject* WXUNUSED(obj), + JSObject* WXUNUSED(proto)) +{ + ComboBoxEventHandler::InitConnectEventMap(); +} + +/*** + * + * + * Returns true if the combobox is editable and there is a text + * selection to copy to the clipboard. Only available on Windows. + * + * + * Returns true if the combobox is editable and there is a text selection + * to cut to the clipboard. Only available on Windows. + * + * + * Returns true if the combobox is editable and there is text to paste + * from the clipboard. Only available on Windows. + * + * + * Returns true if the combobox is editable and the last undo can be redone. + * Only available on Windows. + * + * + * Returns true if the combobox is editable and the last edit can be undone. + * Only available on Windows. + * + * + * Gets/Sets the text field + * + * + * Gets/Sets the insertion point of the text field + * + * + * Gets the last position of the text field + * + * + */ +WXJS_BEGIN_PROPERTY_MAP(ComboBox) + WXJS_PROPERTY(P_VALUE, "value") + WXJS_PROPERTY(P_INSERTION_POINT, "insertionPoint") + WXJS_READONLY_PROPERTY(P_LAST_POSITION, "lastPosition") + WXJS_READONLY_PROPERTY(P_CAN_COPY, "canCopy") + WXJS_READONLY_PROPERTY(P_CAN_CUT, "canCut") + WXJS_READONLY_PROPERTY(P_CAN_PASTE, "canPaste") + WXJS_READONLY_PROPERTY(P_CAN_REDO, "canRedo") + WXJS_READONLY_PROPERTY(P_CAN_UNDO, "canUndo") +WXJS_END_PROPERTY_MAP() + +bool ComboBox::GetProperty(wxComboBox *p, + JSContext *cx, + JSObject* WXUNUSED(obj), + int id, + jsval *vp) +{ + switch (id) + { + case P_CAN_COPY: + *vp = ToJS(cx, p->CanCopy()); + break; + case P_CAN_CUT: + *vp = ToJS(cx, p->CanCut()); + break; + case P_CAN_PASTE: + *vp = ToJS(cx, p->CanPaste()); + break; + case P_CAN_REDO: + *vp = ToJS(cx, p->CanRedo()); + break; + case P_CAN_UNDO: + *vp = ToJS(cx, p->CanUndo()); + break; + case P_VALUE: + *vp = ToJS(cx, p->GetValue()); + break; + case P_INSERTION_POINT: + *vp = ToJS(cx, p->GetInsertionPoint()); + break; + case P_LAST_POSITION: + *vp = ToJS(cx, p->GetLastPosition()); + break; + } + return true; +} + +bool ComboBox::SetProperty(wxComboBox *p, + JSContext *cx, + JSObject* WXUNUSED(obj), + int id, + jsval *vp) +{ + switch (id) + { + case P_VALUE: + { + wxString value; + FromJS(cx, *vp, value); + p->SetValue(value); + break; + } + case P_INSERTION_POINT: + { + int point; + if ( FromJS(cx, *vp, point) ) + p->SetInsertionPoint(point); + break; + } + } + return true; +} + +bool ComboBox::AddProperty(wxComboBox *p, + JSContext* WXUNUSED(cx), + JSObject* WXUNUSED(obj), + const wxString &prop, + jsval* WXUNUSED(vp)) +{ + if ( WindowEventHandler::ConnectEvent(p, prop, true) ) + return true; + + ComboBoxEventHandler::ConnectEvent(p, prop, true); + + return true; +} + +bool ComboBox::DeleteProperty(wxComboBox *p, + JSContext* WXUNUSED(cx), + JSObject* WXUNUSED(obj), + const wxString &prop) +{ + if ( WindowEventHandler::ConnectEvent(p, prop, false) ) + return true; + + ComboBoxEventHandler::ConnectEvent(p, prop, false); + return true; +} + +/*** + * + * + * SIMPLE + * DROPDOWN + * READONLY + * SORT + * + * + */ +WXJS_BEGIN_CONSTANT_MAP(ComboBox) + WXJS_CONSTANT(wxCB_, SIMPLE) + WXJS_CONSTANT(wxCB_, DROPDOWN) + WXJS_CONSTANT(wxCB_, READONLY) + WXJS_CONSTANT(wxCB_, SORT) +WXJS_END_CONSTANT_MAP() + +/*** + * + * + * + * + * The parent of the wxComboBox + * + * + * A window identifier. Use -1 when you don't need it + * + * + * The default text of the text field + * + * + * The position of the control on the given parent. + * + * + * The size of the control. + * + * + * An array of Strings to initialize the control. + * + * + * The window style. + * + * + * A validator + * + * + * + * Constructs a new wxComboBox object + * + * + */ +wxComboBox *ComboBox::Construct(JSContext *cx, + JSObject *obj, + uintN argc, + jsval *argv, + bool WXUNUSED(constructing)) +{ + wxComboBox *p = new wxComboBox(); + SetPrivate(cx, obj, p); + + if ( argc > 0 ) + { + jsval rval; + create(cx, obj, argc, argv, &rval); + } + return p; +} + +WXJS_BEGIN_METHOD_MAP(ComboBox) + WXJS_METHOD("create", create, 2) + WXJS_METHOD("copy", copy, 0) + WXJS_METHOD("cut", cut, 0) + WXJS_METHOD("paste", paste, 0) + WXJS_METHOD("replace", replace, 3) + WXJS_METHOD("remove", remove, 2) + WXJS_METHOD("redo", redo, 0) + WXJS_METHOD("undo", undo, 0) +WXJS_END_METHOD_MAP() + +/*** + * + * + * + * The parent of the wxComboBox + * + * + * A window identifier. Use -1 when you don't need it + * + * + * The default text of the text field + * + * + * The position of the control on the given parent. + * + * + * The size of the control. + * + * + * An array of Strings to initialize the control. + * + * + * The window style. + * + * + * A validator + * + * + * + * Creates a wxComboBox + * + * + */ +JSBool ComboBox::create(JSContext *cx, + JSObject *obj, + uintN argc, + jsval *argv, + jsval *rval) +{ + wxComboBox *p = GetPrivate(cx, obj); + *rval = JSVAL_FALSE; + if ( argc > 8 ) + argc = 8; + + int style = 0; + StringsPtr items; + wxString text; + const wxPoint *pt = &wxDefaultPosition; + const wxSize *size = &wxDefaultSize; + const wxValidator *val = &wxDefaultValidator; + + switch(argc) + { + case 8: + val = Validator::GetPrivate(cx, argv[7]); + if ( val == NULL ) + { + JS_ReportError(cx, WXJS_INVALID_ARG_TYPE, 8, "wxValidator"); + return JS_FALSE; + } + case 7: + if ( ! FromJS(cx, argv[6], style) ) + { + JS_ReportError(cx, WXJS_INVALID_ARG_TYPE, 7, "Integer"); + return JS_FALSE; + } + case 6: + if ( ! FromJS(cx, argv[5], items) ) + { + JS_ReportError(cx, WXJS_INVALID_ARG_TYPE, 6, "Array"); + return JS_FALSE; + } + case 5: + size = Size::GetPrivate(cx, argv[4]); + if ( size == NULL ) + { + JS_ReportError(cx, WXJS_INVALID_ARG_TYPE, 5, "wxSize"); + return JS_FALSE; + } + case 4: + pt = Point::GetPrivate(cx, argv[3]); + if ( pt == NULL ) + { + JS_ReportError(cx, WXJS_INVALID_ARG_TYPE, 4, "wxPoint"); + return JS_FALSE; + } + // Fall through + default: + + wxString text; + FromJS(cx, argv[2], text); + + int id; + if ( ! FromJS(cx, argv[1], id) ) + { + JS_ReportError(cx, WXJS_INVALID_ARG_TYPE, 2, "wxValidator"); + return JS_FALSE; + } + + wxWindow *parent = Window::GetPrivate(cx, argv[0]); + if ( parent == NULL ) + { + JS_ReportError(cx, WXJS_NO_PARENT_ERROR, GetClass()->name); + return JS_FALSE; + } + JavaScriptClientData *clntParent = + dynamic_cast(parent->GetClientObject()); + if ( clntParent == NULL ) + { + JS_ReportError(cx, WXJS_NO_PARENT_ERROR, GetClass()->name); + return JS_FALSE; + } + JS_SetParent(cx, obj, clntParent->GetObject()); + + if ( p->Create(parent, id, text, *pt, *size, + items.GetCount(), items.GetStrings(), style, *val) ) + { + *rval = JSVAL_TRUE; + p->SetClientObject(new JavaScriptClientData(cx, obj, true, false)); + } + } + + return JS_TRUE; +} + +/*** + * + * + * + * Copies the selected text to the clipboard + * + * + */ +JSBool ComboBox::copy(JSContext *cx, + JSObject *obj, + uintN WXUNUSED(argc), + jsval* WXUNUSED(argv), + jsval* WXUNUSED(rval)) +{ + wxComboBox *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + p->Copy(); + + return JS_TRUE; +} + +/*** + * + * + * + * Copies the selected text to the clipboard and removes the selected text + * + * + */ +JSBool ComboBox::cut(JSContext *cx, + JSObject *obj, + uintN WXUNUSED(argc), + jsval* WXUNUSED(argv), + jsval* WXUNUSED(rval)) +{ + wxComboBox *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + p->Cut(); + + return JS_TRUE; +} + +/*** + * + * + * + * Pastes the content of the clipboard in the text field. + * + * + */ +JSBool ComboBox::paste(JSContext *cx, + JSObject *obj, + uintN WXUNUSED(argc), + jsval* WXUNUSED(argv), + jsval* WXUNUSED(rval)) +{ + wxComboBox *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + p->Paste(); + + return JS_TRUE; +} + +/*** + * + * + * + * Redoes the last undo in the text field. Windows only. + * + * + */ +JSBool ComboBox::redo(JSContext *cx, + JSObject *obj, + uintN WXUNUSED(argc), + jsval* WXUNUSED(argv), + jsval* WXUNUSED(rval)) +{ + wxComboBox *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + p->Redo(); + + return JS_TRUE; +} + +/*** + * + * + * + * + * + * + * Removes the text between From and To + * + * + */ +JSBool ComboBox::remove(JSContext *cx, + JSObject *obj, + uintN WXUNUSED(argc), + jsval* argv, + jsval* WXUNUSED(rval)) +{ + wxComboBox *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + long from = 0L; + long to = 0L; + if ( FromJS(cx, argv[0], from) + && FromJS(cx, argv[1], to) ) + { + p->Remove(from, to); + return JS_TRUE; + } + + return JS_FALSE; +} + +/*** + * + * + * + * + * + * + * + * Replaces the text between From and To with the given text + * + * + */ +JSBool ComboBox::replace(JSContext *cx, + JSObject *obj, + uintN WXUNUSED(argc), + jsval* argv, + jsval* WXUNUSED(rval)) +{ + wxComboBox *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + int from; + int to; + wxString text; + + if ( FromJS(cx, argv[0], from) + && FromJS(cx, argv[1], to) + && FromJS(cx, argv[2], text) ) + { + p->Replace(from, to, text); + return JS_TRUE; + } + return JS_FALSE; +} + +/*** + * + * + * + * Undoes the last edit in the text field. Windows only. + * + * + */ +JSBool ComboBox::undo(JSContext *cx, + JSObject *obj, + uintN WXUNUSED(argc), + jsval* WXUNUSED(argv), + jsval* WXUNUSED(rval)) +{ + wxComboBox *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + p->Undo(); + + return JS_TRUE; +} + +/*** + * + * + * Called when the text of the textfield is changed. + * The type of the argument that your handler receives is @wxCommandEvent. + * + * + * Called when an item is selected. The type of the argument + * that your handler receives is @wxCommandEvent. + * + * + */ +WXJS_INIT_EVENT_MAP(wxComboBox) +const wxString WXJS_COMBOBOX_EVENT = wxT("onComboBox"); +const wxString WXJS_TEXT_EVENT = wxT("onText"); +const wxString WXJS_TEXT_ENTER_EVENT = wxT("onTextEnter"); + +void ComboBoxEventHandler::OnText(wxCommandEvent &event) +{ + PrivCommandEvent::Fire(event, WXJS_TEXT_EVENT); +} + +void ComboBoxEventHandler::OnTextEnter(wxCommandEvent &event) +{ + PrivCommandEvent::Fire(event, WXJS_TEXT_ENTER_EVENT); +} + +void ComboBoxEventHandler::OnComboBox(wxCommandEvent &event) +{ + PrivCommandEvent::Fire(event, WXJS_COMBOBOX_EVENT); +} + +void ComboBoxEventHandler::ConnectText(wxComboBox *p, bool connect) +{ + if ( connect ) + { + p->Connect(wxEVT_COMMAND_TEXT_UPDATED, + wxCommandEventHandler(OnText)); + } + else + { + p->Disconnect(wxEVT_COMMAND_TEXT_UPDATED, + wxCommandEventHandler(OnText)); + } +} + +void ComboBoxEventHandler::ConnectTextEnter(wxComboBox *p, bool connect) +{ + if ( connect ) + { + p->Connect(wxEVT_COMMAND_TEXT_ENTER, + wxCommandEventHandler(OnTextEnter)); + } + else + { + p->Disconnect(wxEVT_COMMAND_TEXT_ENTER, + wxCommandEventHandler(OnTextEnter)); + } +} + +void ComboBoxEventHandler::ConnectComboBox(wxComboBox *p, bool connect) +{ + if ( connect ) + { + p->Connect(wxEVT_COMMAND_COMBOBOX_SELECTED, + wxCommandEventHandler(OnComboBox)); + } + else + { + p->Disconnect(wxEVT_COMMAND_COMBOBOX_SELECTED, + wxCommandEventHandler(OnComboBox)); + } +} + +void ComboBoxEventHandler::InitConnectEventMap() +{ + AddConnector(WXJS_COMBOBOX_EVENT, ConnectComboBox); + AddConnector(WXJS_TEXT_EVENT, ConnectText); + AddConnector(WXJS_TEXT_ENTER_EVENT, ConnectTextEnter); +} Property changes on: ps/trunk/source/tools/atlas/wxJS/gui/control/combobox.cpp ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/gui/control/splitwin.h =================================================================== --- ps/trunk/source/tools/atlas/wxJS/gui/control/splitwin.h (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/gui/control/splitwin.h (revision 5154) @@ -0,0 +1,116 @@ +/* + * wxJavaScript - splitwin.h + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: splitwin.h 694 2007-05-03 21:14:13Z fbraem $ + */ +#ifndef _WXJSSplitterWindow_H +#define _WXJSSplitterWindow_H + +#include +#include "../../common/evtconn.h" + +namespace wxjs +{ + namespace gui + { + class SplitterWindow : public ApiWrapper + { + public: + + static bool AddProperty(wxSplitterWindow *p, + JSContext *cx, + JSObject *obj, + const wxString &prop, + jsval *vp); + static bool DeleteProperty(wxSplitterWindow *p, + JSContext* cx, + JSObject* obj, + const wxString &prop); + + static bool GetProperty(wxSplitterWindow *p, + JSContext *cx, + JSObject *obj, + int id, + jsval *vp); + + static bool SetProperty(wxSplitterWindow *p, + JSContext *cx, + JSObject *obj, + int id, + jsval *vp); + + static wxSplitterWindow* Construct(JSContext *cx, + JSObject *obj, + uintN argc, + jsval *argv, + bool constructing); + + static void InitClass(JSContext *cx, + JSObject *obj, + JSObject *proto); + + WXJS_DECLARE_CONSTANT_MAP() + + WXJS_DECLARE_METHOD_MAP() + WXJS_DECLARE_METHOD(create) + WXJS_DECLARE_METHOD(setSashPosition) + WXJS_DECLARE_METHOD(initialize) + WXJS_DECLARE_METHOD(replaceWindow) + WXJS_DECLARE_METHOD(splitHorizontally) + WXJS_DECLARE_METHOD(splitVertically) + WXJS_DECLARE_METHOD(unsplit) + + WXJS_DECLARE_PROPERTY_MAP() + enum + { + P_MIN_PANE_SIZE + , P_SASH_POS + , P_WINDOW1 + , P_WINDOW2 + , P_SPLIT_MODE + , P_IS_SPLIT + }; + }; + + class SplitterEventHandler : public EventConnector + , public wxEvtHandler + { + public: + // Events + void OnSashPosChanging(wxSplitterEvent &event); + void OnSashPosChanged(wxSplitterEvent &event); + void OnUnsplit(wxSplitterEvent &event); + void OnDClick(wxSplitterEvent &event); + static void InitConnectEventMap(); + private: + static void ConnectSashPosChanging(wxSplitterWindow *p, + bool connect); + static void ConnectSashPosChanged(wxSplitterWindow *p, + bool connect); + static void ConnectUnsplit(wxSplitterWindow *p, bool connect); + static void ConnectDClick(wxSplitterWindow *p, bool connect); + }; + }; // namespace gui +}; // namespace wxjs + +#endif //_WXJSSplitterWindow_H Property changes on: ps/trunk/source/tools/atlas/wxJS/gui/control/splitwin.h ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/gui/control/htmlwin.cpp =================================================================== --- ps/trunk/source/tools/atlas/wxJS/gui/control/htmlwin.cpp (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/gui/control/htmlwin.cpp (revision 5154) @@ -0,0 +1,825 @@ +#include "precompiled.h" + +/* + * wxJavaScript - htmlwin.cpp + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: htmlwin.cpp 714 2007-05-16 20:24:49Z fbraem $ + */ +#ifndef WX_PRECOMP + #include +#endif +#include + +/*** + * control/htmlwin + * gui + * + * The purpose of this class is to display HTML pages (either local file or downloaded via HTTP protocol) + * in a window. The width of the window is constant - given in the constructor - and virtual height is changed + * dynamically depending on page size. + * + */ + +#include "../../common/main.h" + + +#include "../event/jsevent.h" +#include "../event/htmllink.h" + +#include "../misc/size.h" +#include "../misc/point.h" +#include "htmlwin.h" +#include "frame.h" +#include "window.h" +#include "../errors.h" + +using namespace wxjs; +using namespace wxjs::gui; + +WXJS_INIT_CLASS(HtmlWindow, "wxHtmlWindow", 0) + +void HtmlWindow::InitClass(JSContext* WXUNUSED(cx), + JSObject* WXUNUSED(obj), + JSObject* WXUNUSED(proto)) +{ + HtmlLinkEventHandler::InitConnectEventMap(); +} + +/*** + * + * + * + * Never display scrollbars, not even when the page is larger + * than the window. + * + * Display scrollbars only if page's size exceeds window's size. + * + * + * Don't allow the user to select text. + * + * + * + * + */ + +WXJS_BEGIN_CONSTANT_MAP(HtmlWindow) + WXJS_CONSTANT(wxHW_, SCROLLBAR_NEVER) + WXJS_CONSTANT(wxHW_, SCROLLBAR_AUTO) + WXJS_CONSTANT(wxHW_, NO_SELECTION) + WXJS_CONSTANT(wxHW_, DEFAULT_STYLE) +WXJS_END_CONSTANT_MAP() + +/*** + * + * + * Returns true if it is possible to go back in the history + * (i.e. @wxHtmlWindow#historyBack won't fail). + * + * + * Returns true if it is possible to go forward in the history + * (i.e. @wxHtmlWindow#historyForward won't fail). + * + * + * Returns anchor within currently opened page (see @wxHtmlWindow#openedPage). + * If no page is opened or if the displayed page wasn't produced by call to + * @wxHtmlWindow#loadPage, empty string is returned. + * + * + * Returns full location of the opened page. If no page is opened or if the + * displayed page wasn't produced by call to @wxHtmlWindow#loadPage, empty + * string is returned. + * + * + * Returns title of the opened page or wxEmptyString if current page does +* not contain <title> tag. + * + * + * Gets/Sets the frame in which page title will be displayed. + * + * + * Returns content of currently displayed page as plain text. + * + * + */ +WXJS_BEGIN_PROPERTY_MAP(HtmlWindow) + WXJS_READONLY_PROPERTY(P_HISTORY_CAN_BACK, "historyCanBack") + WXJS_READONLY_PROPERTY(P_HISTORY_CAN_FORWARD, "historyCanForward") + WXJS_READONLY_PROPERTY(P_OPENED_ANCHOR, "openedAnchor") + WXJS_READONLY_PROPERTY(P_OPENED_PAGE, "openedPage") + WXJS_READONLY_PROPERTY(P_OPENED_PAGE_TITLE, "openedPageTitle") + WXJS_PROPERTY(P_RELATED_FRAME, "relatedFrame") + WXJS_READONLY_PROPERTY(P_TEXT, "text") + WXJS_READONLY_PROPERTY(P_SELECTION_TEXT, "selectionText") +WXJS_END_PROPERTY_MAP() + +bool HtmlWindow::GetProperty(wxHtmlWindow *p, + JSContext *cx, + JSObject* WXUNUSED(obj), + int id, + jsval *vp) +{ + switch (id) + { + case P_HISTORY_CAN_BACK: + *vp = ToJS(cx, p->HistoryCanBack()); + break; + case P_HISTORY_CAN_FORWARD: + *vp = ToJS(cx, p->HistoryCanForward()); + break; + case P_OPENED_ANCHOR: + *vp = ToJS(cx, p->GetOpenedAnchor()); + break; + case P_OPENED_PAGE: + *vp = ToJS(cx, p->GetOpenedPage()); + break; + case P_OPENED_PAGE_TITLE: + *vp = ToJS(cx, p->GetOpenedPageTitle()); + break; + case P_RELATED_FRAME: + *vp = Frame::CreateObject(cx, p->GetRelatedFrame(), NULL); + break; + case P_TEXT: + *vp = ToJS(cx, p->ToText()); + break; + case P_SELECTION_TEXT: + *vp = ToJS(cx, p->SelectionToText()); + break; + } + return true; +} + +bool HtmlWindow::SetProperty(wxHtmlWindow *p, + JSContext *cx, + JSObject* WXUNUSED(obj), + int id, + jsval *vp) +{ + switch (id) + { + case P_RELATED_FRAME: + { + wxFrame *frame = Frame::GetPrivate(cx, *vp); + if ( frame != NULL ) + p->SetRelatedFrame(frame, wxT("%s")); + break; + } + } + return true; +} + +bool HtmlWindow::AddProperty(wxHtmlWindow *p, + JSContext* WXUNUSED(cx), + JSObject* WXUNUSED(obj), + const wxString &prop, + jsval* WXUNUSED(vp)) +{ + if ( ! WindowEventHandler::ConnectEvent(p, prop, true) ) + { + HtmlLinkEventHandler::ConnectEvent(p, prop, true); + } + return true; +} + +bool HtmlWindow::DeleteProperty(wxHtmlWindow* p, + JSContext* WXUNUSED(cx), + JSObject* WXUNUSED(obj), + const wxString &prop) +{ + if ( ! WindowEventHandler::ConnectEvent(p, prop, false) ) + { + HtmlLinkEventHandler::ConnectEvent(p, prop, false); + } + return true; +} + +/*** + * + * + * + * The parent window + * A windows identifier. Use -1 when you don't need it. + * The position of the control on the given parent + * The size of the control + * The style of the control + * + * + * Constructs a new wxHtmlWindow object. See also @wxHtmlWindow#create. + * + * + */ +wxHtmlWindow* HtmlWindow::Construct(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, bool WXUNUSED(constructing)) +{ + wxHtmlWindow *p = new wxHtmlWindow(); + SetPrivate(cx, obj, p); + + if ( argc > 0 ) + { + jsval rval; + create(cx, obj, argc, argv, &rval); + } + return p; +} + +WXJS_BEGIN_METHOD_MAP(HtmlWindow) + WXJS_METHOD("create", create, 1) + WXJS_METHOD("appendToPage", appendToPage, 1) + WXJS_METHOD("historyBack", historyBack, 0) + WXJS_METHOD("historyClear", historyClear, 0) + WXJS_METHOD("historyBack", historyBack, 0) + WXJS_METHOD("historyBack", historyBack, 0) + WXJS_METHOD("loadFile", loadFile, 1) + WXJS_METHOD("loadPage", loadPage, 1) + WXJS_METHOD("setPage", setPage, 1) + WXJS_METHOD("setRelatedFrame", setRelatedFrame, 2) + WXJS_METHOD("setRelatedStatusBar", setRelatedStatusBar, 0) + WXJS_METHOD("selectAll", selectAll, 0) + WXJS_METHOD("selectLine", selectWord, 1) + WXJS_METHOD("selectWord", selectWord, 1) + WXJS_METHOD("setBorders", setBorders, 1) + WXJS_METHOD("setFonts", setFonts, 2) +WXJS_END_METHOD_MAP() + +//TODO: AddFilter + +/*** + * + * + * The parent window + * A windows identifier. Use -1 when you don't need it. + * The position of the control on the given parent + * The size of the control + * The style of the control + * + * + * Creates an HTML window. + * + * + */ +JSBool HtmlWindow::create(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxHtmlWindow *p = GetPrivate(cx, obj); + *rval = JSVAL_FALSE; + + const wxPoint *pt = &wxDefaultPosition; + const wxSize *size = &wxDefaultSize; + int style = wxHW_DEFAULT_STYLE; + int id = -1; + + if ( argc > 5 ) + argc = 5; + + switch(argc) + { + case 5: + if ( ! FromJS(cx, argv[4], style) ) + { + JS_ReportError(cx, WXJS_INVALID_ARG_TYPE, 5, "Integer"); + return JS_FALSE; + } + // Walk through + case 4: + size = Size::GetPrivate(cx, argv[3]); + if ( size == NULL ) + { + JS_ReportError(cx, WXJS_INVALID_ARG_TYPE, 4, "wxSize"); + return JS_FALSE; + } + // Walk through + case 3: + pt = Point::GetPrivate(cx, argv[2]); + if ( pt == NULL ) + { + JS_ReportError(cx, WXJS_INVALID_ARG_TYPE, 3, "wxPoint"); + return JS_FALSE; + } + // Walk through + case 2: + if ( ! FromJS(cx, argv[1], id) ) + { + JS_ReportError(cx, WXJS_INVALID_ARG_TYPE, 2, "Integer"); + return JS_FALSE; + } + // Walk through + default: + + wxWindow *parent = Window::GetPrivate(cx, argv[0]); + if ( parent == NULL ) + { + JS_ReportError(cx, WXJS_NO_PARENT_ERROR, GetClass()->name); + return JS_FALSE; + } + + JavaScriptClientData *clntParent = + dynamic_cast(parent->GetClientObject()); + if ( clntParent == NULL ) + { + JS_ReportError(cx, WXJS_NO_PARENT_ERROR, GetClass()->name); + return JS_FALSE; + } + JS_SetParent(cx, obj, clntParent->GetObject()); + + if ( p->Create(parent, id, *pt, *size, style) ) + { + *rval = JSVAL_TRUE; + p->SetClientObject(new JavaScriptClientData(cx, obj, true, false)); + } + } + + return JS_TRUE; +} + +/*** + * + * + * HTML fragment + * + * + * Appends HTML fragment to currently displayed text and refreshes the window. + * False is returned on failure. + * + * + */ +JSBool HtmlWindow::appendToPage(JSContext *cx, + JSObject *obj, + uintN WXUNUSED(argc), + jsval *argv, + jsval *rval) +{ + wxHtmlWindow *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + wxString html; + FromJS(cx, argv[0], html); + *rval = ToJS(cx, p->AppendToPage(html)); + return JS_TRUE; +} + +/*** + * + * + * + * Moves back to the previous page. (each page displayed using + * @wxHtmlWindow#loadPage is stored in history list.) + * + * + */ +JSBool HtmlWindow::historyBack(JSContext *cx, + JSObject *obj, + uintN WXUNUSED(argc), + jsval* WXUNUSED(argv), + jsval *rval) +{ + wxHtmlWindow *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + *rval = ToJS(cx, p->HistoryBack()); + return JS_TRUE; +} + +/*** + * + * + * + * Clears the history. + * + * + */ +JSBool HtmlWindow::historyClear(JSContext *cx, + JSObject *obj, + uintN WXUNUSED(argc), + jsval* WXUNUSED(argv), + jsval* WXUNUSED(rval)) +{ + wxHtmlWindow *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + p->HistoryClear(); + return JS_TRUE; +} + +/*** + * + * + * + * Moves forward to the next page. (each page displayed using + * @wxHtmlWindow#loadPage is stored in history list.) + * + * + */ +JSBool HtmlWindow::historyForward(JSContext *cx, + JSObject *obj, + uintN WXUNUSED(argc), + jsval* WXUNUSED(argv), + jsval* rval) +{ + wxHtmlWindow *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + *rval = ToJS(cx, p->HistoryForward()); + return JS_TRUE; +} + +/*** + * + * + * The file to load + * + * + * The file to load + * + * + * Loads HTML page from file and displays it. Returns false on failure. + * + * + */ +JSBool HtmlWindow::loadFile(JSContext *cx, + JSObject *obj, + uintN WXUNUSED(argc), + jsval* argv, + jsval* rval) +{ + wxHtmlWindow *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + if ( JSVAL_IS_OBJECT(argv[0]) ) + { + JSClass *clazz = wxjs::GetClass(cx, "wxFileName"); + if ( clazz != NULL ) + { + wxFileName *filename = (wxFileName *) JS_GetInstancePrivate(cx, JSVAL_TO_OBJECT(argv[0]), clazz, NULL); + if ( filename != NULL ) + { + *rval = ToJS(cx, p->LoadFile(*filename)); + return JS_TRUE; + } + } + } + + wxString filename; + FromJS(cx, argv[0], filename); + *rval = ToJS(cx, p->LoadFile(filename)); + + return JS_TRUE; +} + +/*** + * + * + * The address of document + * + * + * Unlike @wxHtmlWindow#setPage this function first loads HTML page + * from location and then displays it. + * + * + */ +JSBool HtmlWindow::loadPage(JSContext *cx, + JSObject *obj, + uintN WXUNUSED(argc), + jsval* argv, + jsval* rval) +{ + wxHtmlWindow *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + wxString location; + FromJS(cx, argv[0], location); + *rval = ToJS(cx, p->LoadPage(location)); + + return JS_TRUE; +} + +//TODO: readCustomization + +/*** + * + * + * + * Selects all text in the window. + * + * + */ +JSBool HtmlWindow::selectAll(JSContext *cx, + JSObject *obj, + uintN WXUNUSED(argc), + jsval* WXUNUSED(argv), + jsval* WXUNUSED(rval)) +{ + wxHtmlWindow *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + p->SelectAll(); + + return JS_TRUE; +} + +/*** + * + * + * + * + * + * Selects the line of text that pos points at. Note that pos is relative to + * the top of displayed page, + * not to window's origin, use @wxScrolledWindow#calcUnscrolledPosition to + * convert physical coordinate. + * + * + */ +JSBool HtmlWindow::selectLine(JSContext *cx, + JSObject *obj, + uintN WXUNUSED(argc), + jsval* argv, + jsval* WXUNUSED(rval)) +{ + wxHtmlWindow *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + wxPoint *pos = Point::GetPrivate(cx, argv[0]); + if ( pos != NULL ) + { + p->SelectLine(*pos); + } + return JS_TRUE; +} + +/*** + * + * + * + * + * + * Selects the word at position pos. Note that pos is relative to the + * top of displayed page, + * not to window's origin, use @wxScrolledWindow#calcUnscrolledPosition + * to convert physical coordinate. + * + * + */ +JSBool HtmlWindow::selectWord(JSContext *cx, + JSObject *obj, + uintN WXUNUSED(argc), + jsval* argv, + jsval* WXUNUSED(rval)) +{ + wxHtmlWindow *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + wxPoint *pos = Point::GetPrivate(cx, argv[0]); + if ( pos != NULL ) + { + p->SelectWord(*pos); + } + return JS_TRUE; +} + +/*** + * + * + * + * + * + * This function sets the space between border of window and HTML contents. + * + * + */ +JSBool HtmlWindow::setBorders(JSContext *cx, + JSObject *obj, + uintN WXUNUSED(argc), + jsval* argv, + jsval* WXUNUSED(rval)) +{ + wxHtmlWindow *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + int border; + if ( FromJS(cx, argv[0], border) ) + { + p->SetBorders(border); + } + return JS_TRUE; +} + +/*** + * + * + * + * This is face name for normal (i.e. non-fixed) font. It can be either + * empty string (then the default face is chosen) or platform-specific face + * name. Examples are "helvetica" under Unix or "Times New Roman" under + * Windows. + * + * + * The same thing for fixed face + * + * + * This is an array of 7 items of Integer type. The values represent size + * of font with HTML size from -2 to +4 ( <FONT SIZE=-2> to + * <FONT SIZE=+4> ). Default sizes are used if sizes is null. + * + * + * + * This function sets font sizes and faces + * + * + */ +JSBool HtmlWindow::setFonts(JSContext *cx, + JSObject *obj, + uintN argc, + jsval* argv, + jsval* WXUNUSED(rval)) +{ + wxHtmlWindow *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + wxString normalFace; + wxString fixedFace; + int *sizes = NULL; + if ( argc > 2 + && JSVAL_IS_OBJECT(argv[2]) ) + { + JSObject *objArr = JSVAL_TO_OBJECT(argv[2]); + if ( JS_IsArrayObject(cx, objArr) ) + { + jsuint length = 0; + JS_GetArrayLength(cx, objArr, &length); + sizes = new int[length]; + for(jsuint i =0; i < length; i++) + { + jsval element; + JS_GetElement(cx, objArr, i, &element); + FromJS(cx, element, sizes[i]); + } + } + } + + p->SetFonts(normalFace, fixedFace, sizes); + delete[] sizes; + + return JS_TRUE; +} + +/*** + * + * + * The HTML source + * + * + * Sets HTML page and display it. This won't load the page!! + * It will display the source + * + * + */ +JSBool HtmlWindow::setPage(JSContext *cx, + JSObject *obj, + uintN WXUNUSED(argc), + jsval* argv, + jsval* rval) +{ + wxHtmlWindow *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + wxString source; + FromJS(cx, argv[0], source); + *rval = ToJS(cx, p->SetPage(source)); + + return JS_TRUE; +} + +/*** + * + * + * + * + * + * + * Sets the frame in which page title will be displayed. + * format is format of frame title, e.g. "HtmlHelp : %s". + * It must contain exactly one %s. This %s is substituted with HTML page title. + * + * + */ +JSBool HtmlWindow::setRelatedFrame(JSContext *cx, + JSObject *obj, + uintN WXUNUSED(argc), + jsval* argv, + jsval* WXUNUSED(rval)) +{ + wxHtmlWindow *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + wxFrame *frame = Frame::GetPrivate(cx, argv[0]); + if ( frame == NULL ) + { + JS_ReportError(cx, WXJS_INVALID_ARG_TYPE, 1, "wxFrame"); + return JS_FALSE; + } + + wxString format; + FromJS(cx, argv[1], format); + p->SetRelatedFrame(frame, format); + + return JS_TRUE; +} + +/*** + * + * + * + * + * + * After calling @wxHtmlWindow#setRelatedFrame, this sets statusbar slot + * where messages will be displayed. (Default is -1 = no messages.) + * + * + */ +JSBool HtmlWindow::setRelatedStatusBar(JSContext *cx, + JSObject *obj, + uintN argc, + jsval* argv, + jsval* WXUNUSED(rval)) +{ + wxHtmlWindow *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + int bar = -1; + if ( argc > 0 ) + FromJS(cx, argv[0], bar); + p->SetRelatedStatusBar(bar); + + return JS_TRUE; +} + +//TODO: WriteCustomization + +WXJS_INIT_EVENT_MAP(wxHtmlWindow) +const wxString WXJS_HTMLLINK_EVENT = wxT("onLinkClicked"); + +/*** + * + * + * This event is triggered when a hyperlinck is clicked. The function receives + * a @wxHtmlLinkEvent as argument. + * + * + */ +void HtmlLinkEventHandler::OnLinkClicked(wxHtmlLinkEvent &event) +{ + // The event object must be set here, because wxHtmlLinkEvent + // is created when a wxCommandEvent is handled, and it doesn't copy + // this data yet (this will be solved in 2.8.4) + event.SetEventObject(this); + PrivHtmlLinkEvent::Fire(event, WXJS_HTMLLINK_EVENT); +} + +void HtmlLinkEventHandler::ConnectLinkClicked(wxHtmlWindow *p, bool connect) +{ + if ( connect ) + { + p->Connect(wxEVT_COMMAND_HTML_LINK_CLICKED, + wxHtmlLinkEventHandler(OnLinkClicked)); + } + else + { + p->Disconnect(wxEVT_COMMAND_HTML_LINK_CLICKED, + wxHtmlLinkEventHandler(OnLinkClicked)); + } +} + +void HtmlLinkEventHandler::InitConnectEventMap() +{ + AddConnector(WXJS_HTMLLINK_EVENT, ConnectLinkClicked); +} Property changes on: ps/trunk/source/tools/atlas/wxJS/gui/control/htmlwin.cpp ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/gui/control/chklstbx.h =================================================================== --- ps/trunk/source/tools/atlas/wxJS/gui/control/chklstbx.h (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/gui/control/chklstbx.h (revision 5154) @@ -0,0 +1,91 @@ +/* + * wxJavaScript - chklstbx.h + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: chklstbx.h 678 2007-04-19 20:12:31Z fbraem $ + */ +#ifndef _WXJSCheckListBox_H +#define _WXJSCheckListBox_H + +#include "../../common/evtconn.h" + +namespace wxjs +{ + namespace gui + { + class CheckListBox : public ApiWrapper + { + public: + + static void InitClass(JSContext* cx, + JSObject* obj, + JSObject* proto); + + static bool AddProperty(wxCheckListBox *p, + JSContext *cx, + JSObject *obj, + const wxString &prop, + jsval *vp); + static bool DeleteProperty(wxCheckListBox *p, + JSContext* cx, + JSObject* obj, + const wxString &prop); + + static bool GetProperty(wxCheckListBox *p, + JSContext *cx, + JSObject *obj, + int id, + jsval *vp); + + static wxCheckListBox* Construct(JSContext *cx, + JSObject *obj, + uintN argc, + jsval *argv, + bool constructing); + + WXJS_DECLARE_PROPERTY_MAP() + + /** + * Property Ids. + */ + enum + { + P_CHECKED = WXJS_START_PROPERTY_ID + }; + + WXJS_DECLARE_METHOD_MAP() + WXJS_DECLARE_METHOD(create) + }; + + class CheckListBoxEventHandler : public EventConnector + , public wxEvtHandler + { + public: + // Events + void OnCheckListBox(wxCommandEvent &event); + static void InitConnectEventMap(); + private: + static void ConnectCheckListBox(wxCheckListBox *p, bool connect); + }; + + }; // namespace gui +}; // namespace wxjs +#endif //_WXJSCheckListBox_H Property changes on: ps/trunk/source/tools/atlas/wxJS/gui/control/chklstbx.h ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/gui/control/radiobtn.cpp =================================================================== --- ps/trunk/source/tools/atlas/wxJS/gui/control/radiobtn.cpp (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/gui/control/radiobtn.cpp (revision 5154) @@ -0,0 +1,313 @@ +#include "precompiled.h" + +/* + * wxJavaScript - radiobtn.cpp + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: radiobtn.cpp 708 2007-05-14 15:30:45Z fbraem $ + */ + +#ifndef WX_PRECOMP + #include +#endif + +#include "../../common/main.h" + + +#include "../event/jsevent.h" +#include "../event/command.h" + +#include "../misc/size.h" +#include "../misc/point.h" +#include "../misc/validate.h" + +#include "radiobtn.h" +#include "window.h" +#include "../errors.h" + +using namespace wxjs; +using namespace wxjs::gui; + +/*** + * control/radiobtn + * gui + * + * A radio button item is a button which usually denotes one of several mutually exclusive + * options. It has a text label next to a (usually) round button. + *

You can create a group of mutually-exclusive radio buttons by specifying + * wxRadioButton.GROUP for the first in the group. The group ends when another radio button + * group is created, or there are no more radio buttons. + * See also @wxRadioBox. + *
+ */ +WXJS_INIT_CLASS(RadioButton, "wxRadioButton", 3) +void RadioButton::InitClass(JSContext* WXUNUSED(cx), + JSObject* WXUNUSED(obj), + JSObject* WXUNUSED(proto)) +{ + RadioButtonEventHandler::InitConnectEventMap(); +} + +/*** + * + * + * Select/Deselect the button + * + * + */ +WXJS_BEGIN_PROPERTY_MAP(RadioButton) + WXJS_PROPERTY(P_VALUE, "value") +WXJS_END_PROPERTY_MAP() + +bool RadioButton::GetProperty(wxRadioButton *p, + JSContext *cx, + JSObject* WXUNUSED(obj), + int id, + jsval *vp) +{ + if (id == P_VALUE ) + { + *vp = ToJS(cx, p->GetValue()); + } + return true; +} + +bool RadioButton::SetProperty(wxRadioButton *p, + JSContext *cx, + JSObject* WXUNUSED(obj), + int id, + jsval *vp) +{ + if ( id == P_VALUE ) + { + bool value; + if ( FromJS(cx, *vp, value) ) + p->SetValue(value); + } + return true; +} + +bool RadioButton::AddProperty(wxRadioButton *p, + JSContext* WXUNUSED(cx), + JSObject* WXUNUSED(obj), + const wxString &prop, + jsval* WXUNUSED(vp)) +{ + if ( WindowEventHandler::ConnectEvent(p, prop, true) ) + return true; + + RadioButtonEventHandler::ConnectEvent(p, prop, true); + + return true; +} + +bool RadioButton::DeleteProperty(wxRadioButton *p, + JSContext* WXUNUSED(cx), + JSObject* WXUNUSED(obj), + const wxString &prop) +{ + if ( WindowEventHandler::ConnectEvent(p, prop, false) ) + return true; + + RadioButtonEventHandler::ConnectEvent(p, prop, false); + return true; +} + +/*** + * + * + * Marks the beginning of a new group of radio buttons. + * + * + */ +WXJS_BEGIN_CONSTANT_MAP(RadioButton) + WXJS_CONSTANT(wxRB_, GROUP) +WXJS_END_CONSTANT_MAP() + +/*** + * + * + * + * + * The parent of wxRadioButton. + * + * + * An window identifier. Use -1 when you don't need it. + * + * + * The title of the RadioButton. + * + * + * The position of the RadioButton control on the given parent. + * + * + * The size of the RadioButton control. + * + * + * The wxRadioButton style. + * + * + * + * + * Constructs a new wxRadioButton object. + * + * + */ +wxRadioButton* RadioButton::Construct(JSContext *cx, + JSObject *obj, + uintN argc, + jsval *argv, + bool WXUNUSED(constructing)) +{ + wxRadioButton *p = new wxRadioButton(); + SetPrivate(cx, obj, p); + + if ( argc > 0 ) + { + jsval rval; + create(cx, obj, argc, argv, &rval); + } + return p; +} + +WXJS_BEGIN_METHOD_MAP(RadioButton) + WXJS_METHOD("create", create, 3) +WXJS_END_METHOD_MAP() + +JSBool RadioButton::create(JSContext *cx, + JSObject *obj, + uintN argc, + jsval *argv, + jsval *rval) +{ + wxRadioButton *p = GetPrivate(cx, obj); + *rval = JSVAL_FALSE; + + if ( argc > 7 ) + argc = 7; + + const wxPoint *pt = &wxDefaultPosition; + const wxSize *size = &wxDefaultSize; + int style = 0; + const wxValidator *val = &wxDefaultValidator; + + switch(argc) + { + case 7: + val = Validator::GetPrivate(cx, argv[6]); + if ( val == NULL ) + { + JS_ReportError(cx, WXJS_INVALID_ARG_TYPE, 7, "wxValidator"); + return JS_FALSE; + } + case 6: + if ( ! FromJS(cx, argv[5], style) ) + { + JS_ReportError(cx, WXJS_INVALID_ARG_TYPE, 6, "Integer"); + return JS_FALSE; + } + // Fall through + case 5: + size = Size::GetPrivate(cx, argv[4]); + if ( size == NULL ) + { + JS_ReportError(cx, WXJS_INVALID_ARG_TYPE, 5, "wxSize"); + return JS_FALSE; + } + // Fall through + case 4: + pt = Point::GetPrivate(cx, argv[3]); + if ( pt == NULL ) + { + JS_ReportError(cx, WXJS_INVALID_ARG_TYPE, 4, "wxPoint"); + return JS_FALSE; + } + // Fall through + default: + wxString text; + FromJS(cx, argv[2], text); + + int id; + if ( ! FromJS(cx, argv[1], id) ) + { + JS_ReportError(cx, WXJS_INVALID_ARG_TYPE, 2, "Integer"); + return JS_FALSE; + } + + wxWindow *parent = Window::GetPrivate(cx, argv[0]); + if ( parent == NULL ) + { + JS_ReportError(cx, WXJS_NO_PARENT_ERROR, GetClass()->name); + return JS_FALSE; + } + JavaScriptClientData *clntParent = + dynamic_cast(parent->GetClientObject()); + if ( clntParent == NULL ) + { + JS_ReportError(cx, WXJS_NO_PARENT_ERROR, GetClass()->name); + return JS_FALSE; + } + JS_SetParent(cx, obj, clntParent->GetObject()); + + if ( p->Create(parent, id, text, *pt, *size, style, *val) ) + { + *rval = JSVAL_TRUE; + p->SetClientObject(new JavaScriptClientData(cx, obj, true, false)); + } + } + + return JS_TRUE; +} + +/*** + * + * + * Called when a radio button is clicked. The type of the argument that + * your handler receives is @wxCommandEvent. + * + * + */ +WXJS_INIT_EVENT_MAP(wxRadioButton) +const wxString WXJS_RADIOBUTTON_EVENT = wxT("onRadioButton"); + +void RadioButtonEventHandler::OnRadioButton(wxCommandEvent &event) +{ + PrivCommandEvent::Fire(event, WXJS_RADIOBUTTON_EVENT); +} + +void RadioButtonEventHandler::ConnectRadioButton(wxRadioButton *p, bool connect) +{ + if ( connect ) + { + p->Connect(wxEVT_COMMAND_RADIOBUTTON_SELECTED, + wxCommandEventHandler(OnRadioButton)); + } + else + { + p->Disconnect(wxEVT_COMMAND_RADIOBUTTON_SELECTED, + wxCommandEventHandler(OnRadioButton)); + } +} + +void RadioButtonEventHandler::InitConnectEventMap() +{ + AddConnector(WXJS_RADIOBUTTON_EVENT, ConnectRadioButton); +} Property changes on: ps/trunk/source/tools/atlas/wxJS/gui/control/radiobtn.cpp ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/gui/control/fontdata.h =================================================================== --- ps/trunk/source/tools/atlas/wxJS/gui/control/fontdata.h (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/gui/control/fontdata.h (revision 5154) @@ -0,0 +1,68 @@ +/* + * wxJavaScript - fontdata.h + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: fontdata.h 598 2007-03-07 20:13:28Z fbraem $ + */ +#ifndef _WXJSFontData_H +#define _WXJSFontData_H + +///////////////////////////////////////////////////////////////////////////// +// Name: fontdata.h +// Purpose: FontData ports wxFontData to JavaScript. +// Author: Franky Braem +// Modified by: +// Created: 05.08.02 +// Copyright: (c) 2001-2002 Franky Braem +// Licence: LGPL +///////////////////////////////////////////////////////////////////////////// + +namespace wxjs +{ + namespace gui + { + class FontData : public ApiWrapper + { + public: + static bool GetProperty(wxFontData *p, JSContext *cx, JSObject *obj, int id, jsval *vp); + static bool SetProperty(wxFontData *p, JSContext *cx, JSObject *obj, int id, jsval *vp); + + static wxFontData* Construct(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, bool constructing); + + WXJS_DECLARE_PROPERTY_MAP() + + /** + * Property Ids. + */ + enum + { + P_ALLOW_SYMBOLS + , P_ENABLE_EFFECTS + , P_CHOSEN_FONT + , P_COLOUR + , P_INITIAL_FONT + , P_SHOW_HELP + }; + }; + }; // namespace gui +}; // namespace wxjs + +#endif //_WXJSFontData_H Property changes on: ps/trunk/source/tools/atlas/wxJS/gui/control/fontdata.h ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/gui/control/menubar.cpp =================================================================== --- ps/trunk/source/tools/atlas/wxJS/gui/control/menubar.cpp (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/gui/control/menubar.cpp (revision 5154) @@ -0,0 +1,799 @@ +#include "precompiled.h" + +/* + * wxJavaScript - menubar.cpp + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: menubar.cpp 715 2007-05-18 20:38:04Z fbraem $ + */ +// menubar.cpp +#ifndef WX_PRECOMP + #include +#endif + +#include "../../common/main.h" + +#include "menubar.h" +#include "menu.h" + +#include "../misc/app.h" + +using namespace wxjs; +using namespace wxjs::gui; + +/*** + * control/menubar + * gui + * + * A menu bar is a series of menus accessible from the top of a frame. + * See @wxFrame#menuBar property, @wxMenu and @wxMenuItem. + * + */ +WXJS_INIT_CLASS(MenuBar, "wxMenuBar", 0) + +/*** + * + * + * The number of menus + * + * + * Returns all the menus belonging to the menubar. + * + * + */ +WXJS_BEGIN_PROPERTY_MAP(MenuBar) + WXJS_READONLY_PROPERTY(P_MENUCOUNT, "menuCount") + WXJS_READONLY_PROPERTY(P_MENUS, "menus") +WXJS_END_PROPERTY_MAP() + +bool MenuBar::GetProperty(wxMenuBar *p, + JSContext *cx, + JSObject* WXUNUSED(obj), + int id, + jsval *vp) +{ + switch(id) + { + case P_MENUCOUNT: + { + *vp = ToJS(cx, p->GetMenuCount()); + break; + } + case P_MENUS: + { + jsint count = p->GetMenuCount(); + + JSObject *objMenus = JS_NewArrayObject(cx, count, NULL); + *vp = OBJECT_TO_JSVAL(objMenus); + + for (jsint i = 0; i < count; i++ ) + { + JavaScriptClientData *data + = dynamic_cast(p->GetMenu(i)); + if ( data != NULL ) + { + jsval element = OBJECT_TO_JSVAL(data->GetObject()); + JS_SetElement(cx, objMenus, i++, &element); + } + } + break; + } + } + return true; +} + +/*** + * + * + * (wxGTK only) + * + * + */ +WXJS_BEGIN_CONSTANT_MAP(MenuBar) + // Style constants + WXJS_CONSTANT(wxMB_, DOCKABLE) +WXJS_END_CONSTANT_MAP() + +/*** + * + * + * + * + * + * Constructs a new wxMenuBar object. + * + * + */ +wxMenuBar* MenuBar::Construct(JSContext *cx, + JSObject* obj, + uintN argc, + jsval *argv, + bool WXUNUSED(constructing)) +{ + int style = 0; + if ( argc == 1 + && ! FromJS(cx, argv[0], style) ) + return NULL; + + wxMenuBar *p = new wxMenuBar(style); + SetPrivate(cx, obj, p); + return p; +} + +WXJS_BEGIN_METHOD_MAP(MenuBar) + WXJS_METHOD("append", append, 2) + WXJS_METHOD("check", check, 2) + WXJS_METHOD("enable", enable, 2) + WXJS_METHOD("enableTop", enableTop, 2) + WXJS_METHOD("getMenu", get_menu, 1) + WXJS_METHOD("insert", insert, 3) + WXJS_METHOD("findMenu", findMenu, 1) + WXJS_METHOD("findMenuItem", findMenuItem, 2) + WXJS_METHOD("getHelpString", getHelpString, 1) + WXJS_METHOD("getLabel", getLabel, 1) + WXJS_METHOD("getLabelTop", getLabelTop, 1) + WXJS_METHOD("refresh", refresh, 0) + WXJS_METHOD("remove", remove, 1) + WXJS_METHOD("replace", replace, 3) + WXJS_METHOD("setHelpString", setHelpString, 2) + WXJS_METHOD("setLabel", setLabel, 2) + WXJS_METHOD("setLabelTop", setLabelTop, 2) +WXJS_END_METHOD_MAP() + +/*** + * + * + * + * + * + * + * Adds the menu to the menubar + * + * + */ +JSBool MenuBar::append(JSContext *cx, + JSObject *obj, + uintN argc, + jsval *argv, + jsval *rval) +{ + wxMenuBar *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + wxMenu *menu = Menu::GetPrivate(cx, argv[0]); + if ( menu == NULL ) + return JS_FALSE; + + wxString name; + FromJS(cx, argv[1], name); + + *rval = ToJS(cx, p->Append(menu, name)); + return JS_TRUE; +} + +/*** + * + * + * + * The menu item identifier + * + * + * If true, checks the menu item, otherwise the item is unchecked + * + * + * + * Checks/Unchecks the menu with the given id. Only use this when the + * menu bar has been associated with a @wxFrame; otherwise, + * use the @wxMenu equivalent call. + * + * + */ +JSBool MenuBar::check(JSContext *cx, + JSObject *obj, + uintN argc, + jsval *argv, + jsval *rval) +{ + wxMenuBar *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + int id; + bool checked; + + if ( FromJS(cx, argv[0], id) + && FromJS(cx, argv[1], checked) ) + { + p->Check(id, checked); + return JS_TRUE; + } + + return JS_FALSE; +} + +/*** + * + * + * + * The menu item identifier + * + * + * If true, enables the menu item, otherwise the item is disabled + * + * + * + * Enables/Disables the menu with the given id. + * Only use this when the menu bar has been associated with a + * @wxFrame; otherwise, use the @wxMenu equivalent call. + * + * + */ +JSBool MenuBar::enable(JSContext *cx, + JSObject *obj, + uintN argc, + jsval *argv, + jsval *rval) +{ + wxMenuBar *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + int id; + bool sw; + + if ( FromJS(cx, argv[0], id) + && FromJS(cx, argv[1], sw) ) + { + p->Enable(id, sw); + return JS_TRUE; + } + + return JS_FALSE; +} + +/*** + * + * + * + * The position of the menu, starting from zero + * + * + * If true, enables the menu, otherwise the menu is disabled + * + * + * + * Enables or disables a whole menu. + * Only use this when the menu bar has been associated with a @wxFrame. + * + * + */ +JSBool MenuBar::enableTop(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxMenuBar *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + int id; + bool sw; + + if ( FromJS(cx, argv[0], id) + && FromJS(cx, argv[1], sw) ) + { + p->EnableTop(id, sw); + return JS_TRUE; + } + + return JS_FALSE; +} + +/*** + * + * + * + * The name of the menu + * + * + * + * Returns the index of the menu with the given name. -1 + * is returned when the menu is not found. + * + * + */ +JSBool MenuBar::findMenu(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxMenuBar *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + wxString name; + FromJS(cx, argv[0], name); + *rval = ToJS(cx, p->FindMenu(name)); + return JS_TRUE; +} + +/*** + * + * + * + * The name of the menu + * + * + * The name of the menuitem. + * + * + * + * Finds the menu item id for a menu name/menu item string pair. + * -1 is returned when nothing is found. + * + * + */ +JSBool MenuBar::findMenuItem(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxMenuBar *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + wxString menuName; + wxString itemName; + + FromJS(cx, argv[0], menuName); + FromJS(cx, argv[1], itemName); + *rval = ToJS(cx, p->FindMenuItem(menuName, itemName)); + return JS_TRUE; +} + +/*** + * + * + * + * A menu item identifier. + * + * + * + * Returns the helpstring associated with the menu item or an empty + * String when the menu item is not found. See @wxMenuItem#help property + * and @wxMenu#getHelpString method. + * + * + */ +JSBool MenuBar::getHelpString(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxMenuBar *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + int id; + if ( FromJS(cx, argv[0], id) ) + { + *rval = ToJS(cx, p->GetHelpString(id)); + return JS_TRUE; + } + + return JS_FALSE; +} + +/*** + * + * + * + * A menu item identifier. + * + * + * + * Returns the label associated with the menu item or an empty + * String when the menu item is not found. + * Use only after the menubar has been associated with a @wxFrame. + * + * + */ +JSBool MenuBar::getLabel(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxMenuBar *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + int id; + if ( FromJS(cx, argv[0], id) ) + { + *rval = ToJS(cx, p->GetLabel(id)); + return JS_TRUE; + } + + return JS_FALSE; +} + +/*** + * + * + * + * Position of the menu on the menu bar, starting from zero. + * + * + * + * Returns the menu label, or the empty string if the menu was not found. + * Use only after the menubar has been associated with a @wxFrame. + * See also @wxMenu#title and @wxMenuBar#setLabelTop + * + * + */ +JSBool MenuBar::getLabelTop(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxMenuBar *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + int idx; + if ( FromJS(cx, argv[0], idx) ) + { + *rval = ToJS(cx, p->GetLabelTop(idx)); + return JS_TRUE; + } + + return JS_FALSE; +} + +/*** + * + * + * + * + * + * Returns the @wxMenu at the given index (zero-indexed). + * + * + */ +JSBool MenuBar::get_menu(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxMenuBar *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + int idx; + if ( FromJS(cx, argv[0], idx) ) + { + wxMenu *menu = (wxMenu*) p->GetMenu(idx); + if ( menu != NULL ) + { + JavaScriptClientData *data + = dynamic_cast(menu->GetClientObject()); + if ( data != NULL ) + { + *rval = OBJECT_TO_JSVAL(data->GetObject()); + } + return JS_TRUE; + } + } + + return JS_FALSE; +} + +/*** + * + * + * + * The position of the new menu in the menu bar + * + * + * The menu to add. + * + * + * The title of the menu. + * + * + * + * Inserts the menu at the given position into the menu bar. + * Inserting menu at position 0 will insert it in the very beginning of it, + * inserting at position @wxMenuBar#menuCount is the same as calling + * @wxMenuBar#append. + * + * + */ +JSBool MenuBar::insert(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxMenuBar *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + int pos; + + if ( ! FromJS(cx, argv[0], pos) ) + return JS_FALSE; + + wxMenu *menu = Menu::GetPrivate(cx, argv[1]); + if ( menu == NULL ) + return JS_FALSE; + + wxString title; + FromJS(cx, argv[2], title); + + p->Insert(pos, menu, title); + return JS_TRUE; +} + +/*** + * + * + * + * A menu item identifier. + * + * + * + * Returns true when the menu item is checked. + * See @wxMenu#check method, @wxMenu#isChecked and @wxMenuItem#check property. + * + * + */ +JSBool MenuBar::isChecked(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxMenuBar *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + int idx; + if ( FromJS(cx, argv[0], idx) ) + { + *rval = ToJS(cx, p->IsChecked(idx)); + return JS_TRUE; + } + + return JS_FALSE; +} + +/*** + * + * + * + * A menu item identifier. + * + * + * + * Returns true when the menu item is enabled. + * @wxMenu#enable method, @wxMenuItem#enable property and @wxMenuBar#enable + * + * + */ +JSBool MenuBar::isEnabled(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxMenuBar *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + int idx; + if ( FromJS(cx, argv[0], idx) ) + { + *rval = ToJS(cx, p->IsEnabled(idx)); + return JS_TRUE; + } + + return JS_FALSE; +} + +/*** + * + * + * + * Redraw the menu bar. + * + * + */ +JSBool MenuBar::refresh(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxMenuBar *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + p->Refresh(); + + return JS_TRUE; +} + +/*** + * + * + * + * The index of the menu to remove (zero-indexed). + * + * + * + * Removes the menu from the menu bar and returns the @wxMenu object. + * This function may be used together with @wxMenuBar#insert to change + * the menubar dynamically. + * + * + */ +JSBool MenuBar::remove(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxMenuBar *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + int idx; + if ( FromJS(cx, argv[0], idx) ) + { + wxMenu *menu = p->Remove(idx); + if ( menu != NULL ) + { + JavaScriptClientData *data + = dynamic_cast(menu->GetClientObject()); + if ( data != NULL ) + *rval = OBJECT_TO_JSVAL(data->GetObject()); + } + return JS_TRUE; + } + + return JS_FALSE; +} + +/*** + * + * + * + * The index of the menu to replace (zero-indexed). + * + * + * The new menu + * + * + * The title of the menu + * + * + * + * Replaces the menu at the given position with the new one. + * + * + */ +JSBool MenuBar::replace(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxMenuBar *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + int pos; + if ( ! FromJS(cx, argv[0], pos) ) + return JS_FALSE; + + wxMenu *menu = Menu::GetPrivate(cx, argv[1]); + if ( menu == NULL ) + return JS_FALSE; + + wxString title; + FromJS(cx, argv[2], title); + + wxMenu *oldMenu = p->Replace(pos, menu, title); + if ( oldMenu == NULL ) + { + *rval = JSVAL_VOID; + } + else + { + JavaScriptClientData *data + = dynamic_cast(oldMenu->GetClientObject()); + *rval = ( data == NULL ) ? JSVAL_VOID + : OBJECT_TO_JSVAL(data->GetObject()); + } + return JS_TRUE; +} + +/*** + * + * + * + * A menu item identifier. + * + * + * The help text + * + * + * + * Sets the help associated with a menu item. + * See @wxMenuItem#help property, @wxMenu#setHelpString method + * + * + */ +JSBool MenuBar::setHelpString(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxMenuBar *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + int id; + + if ( ! FromJS(cx, argv[0], id) ) + return JS_FALSE; + + wxString str; + FromJS(cx, argv[1], str); + p->SetHelpString(id, str); + return JS_TRUE; +} + +/*** + * + * + * + * A menu item identifier. + * + * + * A new label + * + * + * + * Sets the label of a menu item. + * Only use this when the menubar is associated with a @wxFrame + * @wxMenuItem#label property, @wxMenu#setLabel method + * + * + */ +JSBool MenuBar::setLabel(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxMenuBar *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + int id; + + if ( ! FromJS(cx, argv[0], id) ) + return JS_FALSE; + + wxString str; + FromJS(cx, argv[1], str); + + p->SetLabel(id, str); + + return JS_TRUE; +} + +/*** + * + * + * + * A menu index (zero-indexed) + * + * + * A label for a menu + * + * + * + * Sets the label of a menu. + * Only use this when the menubar is associated with a @wxFrame + * See @wxMenu#title property + * + * + */ +JSBool MenuBar::setLabelTop(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxMenuBar *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + int idx; + wxString str; + + if ( FromJS(cx, argv[0], idx) ) + { + FromJS(cx, argv[1], str); + p->SetLabelTop(idx, str); + return JS_TRUE; + } + + return JS_FALSE; +} Property changes on: ps/trunk/source/tools/atlas/wxJS/gui/control/menubar.cpp ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/gui/control/frame.h =================================================================== --- ps/trunk/source/tools/atlas/wxJS/gui/control/frame.h (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/gui/control/frame.h (revision 5154) @@ -0,0 +1,125 @@ +/* + * wxJavaScript - frame.h + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: frame.h 704 2007-05-11 19:46:45Z fbraem $ + */ +#ifndef _WXJSFRAME_H +#define _WXJSFRAME_H + +#include "../../common/evtconn.h" + +namespace wxjs +{ + namespace gui + { + class Frame : public ApiWrapper + , public wxFrame + { + public: + + Frame() : wxFrame() + { + } + + virtual ~Frame() + { + } + + virtual wxToolBar* OnCreateToolBar(long style, + wxWindowID id, + const wxString& name); + + static void InitClass(JSContext* cx, + JSObject* obj, + JSObject* proto); + + static bool AddProperty(wxFrame *p, + JSContext *cx, + JSObject *obj, + const wxString &prop, + jsval *vp); + static bool DeleteProperty(wxFrame *p, + JSContext* cx, + JSObject* obj, + const wxString &prop); + + static bool GetProperty(wxFrame *p, + JSContext *cx, + JSObject *obj, + int id, + jsval *vp); + static bool SetProperty(wxFrame *p, + JSContext *cx, + JSObject *obj, + int id, + jsval *vp); + + static wxFrame* Construct(JSContext *cx, + JSObject *obj, + uintN argc, + jsval *argv, + bool constructing); + + WXJS_DECLARE_METHOD_MAP() + WXJS_DECLARE_METHOD(create) + WXJS_DECLARE_METHOD(setStatusText) + WXJS_DECLARE_METHOD(setStatusWidths) + WXJS_DECLARE_METHOD(createStatusBar) + WXJS_DECLARE_METHOD(processCommand) + WXJS_DECLARE_METHOD(createToolBar) + + WXJS_DECLARE_CONSTANT_MAP() + + WXJS_DECLARE_PROPERTY_MAP() + + enum + { + P_MENUBAR + , P_STATUSBAR_FIELDS + , P_STATUS_WIDTHS + , P_TOOLBAR + , P_STATUSBAR + , P_STATUSBAR_PANE + }; + }; + + class FrameEventHandler : public EventConnector + , public wxEvtHandler + { + public: + // Events + void OnClose(wxCloseEvent &event); + void OnMenu(wxCommandEvent &event); + void OnIconize(wxIconizeEvent &event); + void OnMaximize(wxMaximizeEvent &event); + static void InitConnectEventMap(); + private: + static void ConnectClose(wxFrame *p, bool connect); + static void ConnectMenu(wxFrame *p, bool connect); + static void ConnectIconize(wxFrame *p, bool connect); + static void ConnectMaximize(wxFrame *p, bool connect); + }; + + }; // namespace gui +}; // namespace wxjs + +#endif // _WXJSFRAME_H Property changes on: ps/trunk/source/tools/atlas/wxJS/gui/control/frame.h ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/gui/control/caldate.h =================================================================== --- ps/trunk/source/tools/atlas/wxJS/gui/control/caldate.h (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/gui/control/caldate.h (revision 5154) @@ -0,0 +1,76 @@ +/* + * wxJavaScript - caldate.h + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: caldate.h 667 2007-04-06 20:34:24Z fbraem $ + */ +#ifndef _WXJSCalendarDateAttr_H +#define _WXJSCalendarDateAttr_H + +namespace wxjs +{ + namespace gui + { + class CalendarDateAttr : public ApiWrapper + { + public: + + static bool GetProperty(wxCalendarDateAttr *p, + JSContext *cx, + JSObject *obj, + int id, + jsval *vp); + static bool SetProperty(wxCalendarDateAttr *p, + JSContext *cx, + JSObject *obj, + int id, + jsval *vp); + + static wxCalendarDateAttr* Construct(JSContext *cx, + JSObject *obj, + uintN argc, + jsval *argv, + bool constructing); + + static wxCalendarDateAttr *Clone(wxCalendarDateAttr *attr) + { + return new wxCalendarDateAttr(attr->GetTextColour() + , attr->GetBackgroundColour() + , attr->GetBorderColour() + , attr->GetFont() + , attr->GetBorder()); + } + + WXJS_DECLARE_PROPERTY_MAP() + enum + { + P_TEXT_COLOUR = WXJS_START_PROPERTY_ID + , P_BG_COLOUR + , P_BORDER_COLOUR + , P_FONT + , P_BORDER + , P_HOLIDAY + }; + }; + }; // namespace gui +}; // namespace wxjs +#endif //_WXJSCalendarDateAttr_H Property changes on: ps/trunk/source/tools/atlas/wxJS/gui/control/caldate.h ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/gui/control/filedlg.cpp =================================================================== --- ps/trunk/source/tools/atlas/wxJS/gui/control/filedlg.cpp (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/gui/control/filedlg.cpp (revision 5154) @@ -0,0 +1,310 @@ +#include "precompiled.h" + +/* + * wxJavaScript - filedlg.cpp + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: filedlg.cpp 708 2007-05-14 15:30:45Z fbraem $ + */ + +#ifndef WX_PRECOMP + #include +#endif + +#include "../../common/main.h" + +#include "filedlg.h" +#include "window.h" + +#include "../misc/point.h" + +#include "../errors.h" + +using namespace wxjs; +using namespace wxjs::gui; + +/*** + * control/filedlg + * gui + * + * A dialog for saving or opening a file. The following shows a save dialog: + *

+ *   var dlg = new wxFileDialog(frame, "Save a file");
+ *   dlg.style = wxFileDialog.SAVE;
+ *   dlg.showModal();
+ *  
+ *
+ */ +WXJS_INIT_CLASS(FileDialog, "wxFileDialog", 1) + +/*** + * + * + * Get/Set the default directory + * + * + * Get/Set the default filename + * + * + * Get an array of the selected file names + * + * + * Get/Set the filter index (wildcards) + * + * + * Get/Set the message of the dialog + * + * + * Get/Set the full path of the selected file + * + * + * Gets the full path of all selected files + * + * + * Gets/Sets the wildcard such as "*.*" or + * "BMP files (*.bmp)|*.bmp|GIF files (*.gif)|*.gif". + * + * + */ +WXJS_BEGIN_PROPERTY_MAP(FileDialog) + WXJS_PROPERTY(P_DIRECTORY, "directory") + WXJS_PROPERTY(P_FILENAME, "filename") + WXJS_READONLY_PROPERTY(P_FILENAMES, "filenames") + WXJS_PROPERTY(P_FILTER_INDEX, "filterIndex") + WXJS_PROPERTY(P_MESSAGE, "message") + WXJS_PROPERTY(P_PATH, "path") + WXJS_READONLY_PROPERTY(P_PATHS, "paths") + WXJS_PROPERTY(P_WILDCARD, "wildcard") +WXJS_END_PROPERTY_MAP() + +bool FileDialog::GetProperty(wxFileDialog *p, + JSContext *cx, + JSObject* WXUNUSED(obj), + int id, + jsval *vp) +{ + switch(id) + { + case P_DIRECTORY: + *vp = ToJS(cx, p->GetDirectory()); + break; + case P_FILENAME: + *vp = ToJS(cx, p->GetFilename()); + break; + case P_FILENAMES: + { + wxArrayString filenames; + p->GetFilenames(filenames); + *vp = ToJS(cx, filenames); + break; + } + case P_FILTER_INDEX: + *vp = ToJS(cx, p->GetFilterIndex()); + break; + case P_MESSAGE: + *vp = ToJS(cx, p->GetMessage()); + break; + case P_PATH: + *vp = ToJS(cx, p->GetPath()); + break; + case P_PATHS: + { + wxArrayString paths; + p->GetPaths(paths); + *vp = ToJS(cx, paths); + break; + } + case P_WILDCARD: + *vp = ToJS(cx, p->GetWildcard()); + break; + } + return true; +} + +bool FileDialog::SetProperty(wxFileDialog *p, + JSContext *cx, + JSObject* WXUNUSED(obj), + int id, + jsval *vp) +{ + switch (id) + { + case P_DIRECTORY: + { + wxString dir; + FromJS(cx, *vp, dir); + p->SetDirectory(dir); + break; + } + case P_FILENAME: + { + wxString f; + FromJS(cx, *vp, f); + p->SetFilename(f); + break; + } + case P_FILTER_INDEX: + { + int idx; + if ( FromJS(cx, *vp, idx) ) + p->SetFilterIndex(idx); + break; + } + case P_MESSAGE: + { + wxString msg; + FromJS(cx, *vp, msg); + p->SetMessage(msg); + break; + } + case P_PATH: + { + wxString path; + FromJS(cx, *vp, path); + p->SetPath(path); + break; + } + case P_WILDCARD: + { + wxString wildcard; + FromJS(cx, *vp, wildcard); + p->SetWildcard(wildcard); + break; + } + } + return true; +} + +/*** + * + * + * + * + * + * + * + * + */ +WXJS_BEGIN_CONSTANT_MAP(FileDialog) + WXJS_CONSTANT(wx, OPEN) + WXJS_CONSTANT(wx, SAVE) + WXJS_CONSTANT(wx, OVERWRITE_PROMPT) + WXJS_CONSTANT(wx, MULTIPLE) +WXJS_END_CONSTANT_MAP() + +/*** + * + * + * + * The parent of wxFileDialog. + * + * + * The title of the dialog + * + * + * The default directory + * + * + * The default file + * + * + * A wildcard, such as "*.*" + * or "BMP files (*.bmp)|*.bmp|GIF files (*.gif)|*.gif". + * + * + * The style + * + * + * The position of the dialog. + * + * + * + * Constructs a new wxFileDialog object + * + * + */ +wxFileDialog* FileDialog::Construct(JSContext *cx, + JSObject *obj, + uintN argc, + jsval *argv, + bool WXUNUSED(constructing)) +{ + if ( argc > 7 ) + argc = 7; + + const wxPoint *pt = &wxDefaultPosition; + int style = 0; + wxString message = wxFileSelectorPromptStr; + wxString wildcard = wxFileSelectorDefaultWildcardStr; + wxString defaultFile = wxEmptyString; + wxString defaultDir = wxEmptyString; + + switch(argc) + { + case 7: + pt = Point::GetPrivate(cx, argv[6]); + if ( pt == NULL ) + { + JS_ReportError(cx, WXJS_INVALID_ARG_TYPE, 7, "wxPoint"); + return JS_FALSE; + } + // Fall through + case 6: + if ( ! FromJS(cx, argv[5], style) ) + { + JS_ReportError(cx, WXJS_INVALID_ARG_TYPE, 6, "Integer"); + return JS_FALSE; + } + case 5: + FromJS(cx, argv[4], wildcard); + // Fall through + case 4: + FromJS(cx, argv[3], defaultFile); + // Fall through + case 3: + FromJS(cx, argv[2], defaultDir); + // Fall through + case 2: + FromJS(cx, argv[1], message); + // Fall through + default: + wxWindow *parent = Window::GetPrivate(cx, argv[0]); + if ( parent != NULL ) + { + JavaScriptClientData *clntParent = + dynamic_cast(parent->GetClientObject()); + if ( clntParent == NULL ) + { + JS_ReportError(cx, WXJS_NO_PARENT_ERROR, GetClass()->name); + return JS_FALSE; + } + JS_SetParent(cx, obj, clntParent->GetObject()); + } + return new wxFileDialog(parent, message, defaultDir, defaultFile, + wildcard, style, *pt); + } + return NULL; +} + +void FileDialog::Destruct(JSContext* WXUNUSED(cx), wxFileDialog *p) +{ + p->Destroy(); +} Property changes on: ps/trunk/source/tools/atlas/wxJS/gui/control/filedlg.cpp ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/gui/control/chklstbxchk.cpp =================================================================== --- ps/trunk/source/tools/atlas/wxJS/gui/control/chklstbxchk.cpp (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/gui/control/chklstbxchk.cpp (revision 5154) @@ -0,0 +1,100 @@ +#include "precompiled.h" + +/* + * wxJavaScript - chklstbxchk.cpp + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: chklstbxchk.cpp 711 2007-05-14 20:59:29Z fbraem $ + */ +// chklstbx.cpp + +#ifndef WX_PRECOMP + #include +#endif + +#include "../../common/main.h" +#include "../../common/index.h" + +#include "chklstbxchk.h" +#include "chklstbx.h" + +using namespace wxjs; +using namespace wxjs::gui; + +/*** + * control/chklstbxchk + * gui + * + * wxCheckListBoxItem is a helper class used by wxJS to + * provide the use of an array to check or uncheck an item + * of a @wxCheckListBox. The following sample shows a @wxCheckListBox with the first item checked. + *

+ *   dlg = new wxDialog(null, -1, "Test", new wxPoint(0, 0), new wxSize(200, 200));
+ *   items = new Array();
+ *   items[0] = "item 1";
+ *   items[1] = "item 2";
+ *   items[2] = "item 3";
+ *   choice = new wxCheckListBox(dlg, -1, wxDefaultPosition, new wxSize(150, 150), items);
+ *   choice.checked[0] = true;
+ *   dlg.showModal();
+ *  
+ *
+ */ +WXJS_INIT_CLASS(CheckListBoxItem, "wxCheckListBoxItem", 0) + +bool CheckListBoxItem::GetProperty(Index *p, JSContext *cx, JSObject *obj, int id, jsval *vp) +{ + JSObject *parent = JS_GetParent(cx, obj); + wxASSERT_MSG(parent != NULL, wxT("No parent found for wxCheckListBoxItem")); + + if ( id >= 0 ) + { + p->SetIndex(id); + wxCheckListBox *box = CheckListBox::GetPrivate(cx, parent); + if ( box == NULL ) + return false; + + *vp = ToJS(cx, box->IsChecked(id)); + } + return true; +} + +bool CheckListBoxItem::SetProperty(Index* WXUNUSED(p), + JSContext *cx, + JSObject *obj, + int id, + jsval *vp) +{ + JSObject *parent = JS_GetParent(cx, obj); + wxASSERT_MSG(parent != NULL, wxT("No parent found for CheckListBoxItem")); + + if ( id >= 0 ) + { + wxCheckListBox *box = CheckListBox::GetPrivate(cx, parent); + if ( box == NULL ) + return false; + + bool check; + if ( FromJS(cx, *vp, check) ) + box->Check(id, check); + } + return true; +} Property changes on: ps/trunk/source/tools/atlas/wxJS/gui/control/chklstbxchk.cpp ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/gui/control/calendar.h =================================================================== --- ps/trunk/source/tools/atlas/wxJS/gui/control/calendar.h (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/gui/control/calendar.h (revision 5154) @@ -0,0 +1,123 @@ +/* + * wxJavaScript - calendar.h + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: calendar.h 678 2007-04-19 20:12:31Z fbraem $ + */ +#ifndef _WXJSCalendarCtrl_H +#define _WXJSCalendarCtrl_H + +#include "../../common/evtconn.h" + +namespace wxjs +{ + namespace gui + { + class CalendarCtrl : public ApiWrapper + { + public: + + static void InitClass(JSContext* cx, + JSObject* obj, + JSObject* proto); + + static bool AddProperty(wxCalendarCtrl *p, + JSContext *cx, + JSObject *obj, + const wxString &prop, + jsval *vp); + static bool DeleteProperty(wxCalendarCtrl *p, + JSContext* cx, + JSObject* obj, + const wxString &prop); + + static bool GetProperty(wxCalendarCtrl *p, + JSContext *cx, + JSObject *obj, + int id, + jsval *vp); + static bool SetProperty(wxCalendarCtrl *p, + JSContext *cx, + JSObject *obj, + int id, + jsval *vp); + + static wxCalendarCtrl* Construct(JSContext *cx, + JSObject *obj, + uintN argc, + jsval *argv, + bool constructing); + WXJS_DECLARE_PROPERTY_MAP() + enum + { + P_DATE = WXJS_START_PROPERTY_ID + , P_LOWER_DATE_LIMIT + , P_UPPER_DATE_LIMIT + , P_ENABLE_HOLIDAY_DISPLAY + , P_ENABLE_YEAR_CHANGE + , P_ENABLE_MONTH_CHANGE + , P_HEADER_COLOUR_BG + , P_HEADER_COLOUR_FG + , P_HIGHLIGHT_COLOUR_BG + , P_HIGHLIGHT_COLOUR_FG + , P_HOLIDAY_COLOUR_BG + , P_HOLIDAY_COLOUR_FG + , P_ATTR + }; + + WXJS_DECLARE_CONSTANT_MAP() + WXJS_DECLARE_METHOD_MAP() + + WXJS_DECLARE_METHOD(create) + WXJS_DECLARE_METHOD(setDateRange) + WXJS_DECLARE_METHOD(setHeaderColours) + WXJS_DECLARE_METHOD(setHighlightColours) + WXJS_DECLARE_METHOD(setHolidayColours) + }; + + class CalendarEventHandler : public EventConnector + , public wxEvtHandler + { + public: + // Events + void OnCalendar(wxCalendarEvent &event); + void OnCalendarSelChanged(wxCalendarEvent &event); + void OnCalendarDay(wxCalendarEvent &event); + void OnCalendarMonth(wxCalendarEvent &event); + void OnCalendarYear(wxCalendarEvent &event); + void OnCalendarWeekDayClicked(wxCalendarEvent &event); + static void InitConnectEventMap(); + private: + static void ConnectCalendar(wxCalendarCtrl *p, + bool connect); + static void ConnectCalendarSelChanged(wxCalendarCtrl *p, + bool connect); + static void ConnectCalendarDay(wxCalendarCtrl *p, + bool connect); + static void ConnectCalendarMonth(wxCalendarCtrl *p, bool connect); + static void ConnectCalendarYear(wxCalendarCtrl *p, bool connect); + static void ConnectCalendarWeekDayClicked(wxCalendarCtrl *p, + bool connect); + }; + }; // namespace gui +}; // namespace wxjs + +#endif //_WXJSCalendarCtrl_H Property changes on: ps/trunk/source/tools/atlas/wxJS/gui/control/calendar.h ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/gui/control/mdichild.h =================================================================== --- ps/trunk/source/tools/atlas/wxJS/gui/control/mdichild.h (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/gui/control/mdichild.h (revision 5154) @@ -0,0 +1,50 @@ +#ifndef _wxjs_gui_mdi_child_h +#define _wxjs_gui_mdi_child_h + +namespace wxjs +{ + namespace gui + { + class MDIChildFrame : public ApiWrapper + , public wxMDIChildFrame + { + public: + + MDIChildFrame() : wxMDIChildFrame() + { + } + + virtual ~MDIChildFrame() {} + + virtual wxToolBar* OnCreateToolBar(long style, + wxWindowID id, + const wxString& name); + + static bool AddProperty(wxMDIChildFrame *p, + JSContext *cx, + JSObject *obj, + const wxString &prop, + jsval *vp); + static bool DeleteProperty(wxMDIChildFrame *p, + JSContext* cx, + JSObject* obj, + const wxString &prop); + + static wxMDIChildFrame* Construct(JSContext* cx, + JSObject* obj, + uintN argc, + jsval* argv, + bool constructing); + + WXJS_DECLARE_METHOD_MAP() + WXJS_DECLARE_METHOD(create) + WXJS_DECLARE_METHOD(activate) + WXJS_DECLARE_METHOD(maximize) + WXJS_DECLARE_METHOD(restore) + + private: + }; + } +}; + +#endif // _wxjs_gui_mdi_child_h Property changes on: ps/trunk/source/tools/atlas/wxJS/gui/control/mdichild.h ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/gui/control/listhit.h =================================================================== --- ps/trunk/source/tools/atlas/wxJS/gui/control/listhit.h (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/gui/control/listhit.h (revision 5154) @@ -0,0 +1,83 @@ +/* + * wxJavaScript - listhit.h + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: listhit.h 688 2007-04-27 20:45:09Z fbraem $ + */ +#ifndef _wxjs_gui_listhit_h +#define _wxjs_gui_listhit_h + +#include + +namespace wxjs +{ + namespace gui + { + /** + * Helper class for returning information for hittest + */ + class wxListHitTest + { + public: + long GetItem() const + { + return m_item; + } + long GetFlags() const + { + return m_flags; + } + friend class ListCtrl; + private: + + wxListHitTest(long item, int flags) : m_item(item), m_flags(flags) + { + } + + long m_item; + int m_flags; + }; + + class ListHitTest : public ApiWrapper + { + public: + static bool GetProperty(wxListHitTest *p, + JSContext *cx, + JSObject *obj, + int id, + jsval *vp); + + WXJS_DECLARE_PROPERTY_MAP() + /** + * Property Ids. + */ + enum + { + P_ITEM + , P_FLAGS + }; + + WXJS_DECLARE_CONSTANT_MAP() + }; + }; // namespace gui +}; // namespace wxjs + +#endif //_wxjs_gui_listhit_h Property changes on: ps/trunk/source/tools/atlas/wxJS/gui/control/listhit.h ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/gui/control/caldate.cpp =================================================================== --- ps/trunk/source/tools/atlas/wxJS/gui/control/caldate.cpp (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/gui/control/caldate.cpp (revision 5154) @@ -0,0 +1,306 @@ +#include "precompiled.h" + +/* + * wxJavaScript - caldate.cpp + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: caldate.cpp 667 2007-04-06 20:34:24Z fbraem $ + */ +// caldate.cpp + +#ifndef WX_PRECOMP + #include +#endif + +#include + +/*** + * control/caldate + * gui + * + * wxCalendarDateAttr contains all attributes for a calendar date. + * See @wxCalendarCtrl. + * + */ + +#include "../../common/main.h" +#include "../../common/index.h" + +#include "../misc/colour.h" +#include "../misc/font.h" + +#include "calendar.h" +#include "caldate.h" + +using namespace wxjs; +using namespace wxjs::gui; + +WXJS_INIT_CLASS(CalendarDateAttr, "wxCalendarDateAttr", 0) + +/*** + * + * + * The background colour + * + * Type of the border. + * See @wxCalendarDateBorder. + * + * + * The colour of the border + * + * The font of the text + * Is the day a holiday? + * + * The colour of the text + * + * + */ +WXJS_BEGIN_PROPERTY_MAP(CalendarDateAttr) + WXJS_PROPERTY(P_TEXT_COLOUR, "textColour") + WXJS_PROPERTY(P_BG_COLOUR, "backgroundColour") + WXJS_PROPERTY(P_BORDER_COLOUR, "borderColour") + WXJS_PROPERTY(P_FONT, "font") + WXJS_PROPERTY(P_BORDER, "border") + WXJS_PROPERTY(P_HOLIDAY, "holiday") +WXJS_END_PROPERTY_MAP() + +bool CalendarDateAttr::GetProperty(wxCalendarDateAttr *p, + JSContext *cx, + JSObject *obj, + int id, + jsval *vp) +{ + if ( id > 0 && id < 32 ) // Check the day property + { + JSObject *parent = JS_GetParent(cx, obj); + wxASSERT_MSG(parent != NULL, wxT("No parent found for CalendarDateAttr")); + + wxCalendarCtrl *calendar = CalendarCtrl::GetPrivate(cx, parent); + if ( calendar == NULL ) + return false; + + wxCalendarDateAttr *attr = calendar->GetAttr(id); + SetPrivate(cx, obj, (attr == NULL) ? new wxCalendarDateAttr() + : CalendarDateAttr::Clone(attr)); + } + else + { + switch (id) + { + case P_TEXT_COLOUR: + if ( p->HasTextColour() ) + { + *vp = Colour::CreateObject(cx, new wxColour(p->GetTextColour())); + } + break; + case P_BG_COLOUR: + if ( p->HasBackgroundColour() ) + { + *vp = Colour::CreateObject(cx, new wxColour(p->GetBackgroundColour())); + } + break; + case P_BORDER_COLOUR: + if ( p->HasBorderColour() ) + { + *vp = Colour::CreateObject(cx, new wxColour(p->GetBorderColour())); + } + break; + case P_FONT: + if ( p->HasFont() ) + { + *vp = Font::CreateObject(cx, new wxFont(p->GetFont()), obj); + } + break; + case P_BORDER: + if ( p->HasBorder() ) + { + *vp = ToJS(cx, static_cast(p->GetBorder())); + } + break; + case P_HOLIDAY: + *vp = ToJS(cx, p->IsHoliday()); + break; + } + } + return true; +} + +bool CalendarDateAttr::SetProperty(wxCalendarDateAttr *p, + JSContext *cx, + JSObject *obj, + int id, + jsval *vp) +{ + if ( id > 0 && id < 32 ) + { + JSObject *parent = JS_GetParent(cx, obj); + wxASSERT_MSG(parent != NULL, wxT("No parent found for CalendarAttrItem")); + + wxCalendarCtrl *calendar = CalendarCtrl::GetPrivate(cx, parent); + if ( calendar == NULL ) + return false; + + wxCalendarDateAttr *attr = GetPrivate(cx, *vp); + // Clone the attribute because it is owned and destroyed by wxWindows + // which can give problems. For example: when the calendar object is + // garbage collected and the attr object is not, the attr object + // would have an invalid pointer. + calendar->SetAttr(id, CalendarDateAttr::Clone(attr)); + } + else + { + switch (id) + { + case P_TEXT_COLOUR: + { + wxColour *colour = Colour::GetPrivate(cx, *vp); + if ( colour != NULL ) + p->SetTextColour(*colour); + } + break; + case P_BG_COLOUR: + { + wxColour *colour = Colour::GetPrivate(cx, *vp); + if ( colour != NULL ) + p->SetBackgroundColour(*colour); + } + break; + case P_BORDER_COLOUR: + { + wxColour *colour = Colour::GetPrivate(cx, *vp); + if ( colour != NULL ) + p->SetBorderColour(*colour); + } + break; + case P_FONT: + { + wxFont *font = Font::GetPrivate(cx, *vp); + if ( font != NULL ) + p->SetFont(*font); + } + break; + case P_BORDER: + { + int border; + if ( FromJS(cx, *vp, border) ) + p->SetBorder((wxCalendarDateBorder)border); + break; + } + case P_HOLIDAY: + { + bool holiday; + if ( FromJS(cx, *vp, holiday) ) + p->SetHoliday(holiday); + break; + } + } + } + return true; +} + +/*** + * + * + * + * Colour of the text + * + * Backgroundcolour + * + * BorderColour + * The font + * The border type + * + * + * The border type + * BorderColour + * + * + * Constructs a new wxCalendarDateAttr object. + * + * + */ +wxCalendarDateAttr* CalendarDateAttr::Construct(JSContext *cx, + JSObject* WXUNUSED(obj), + uintN argc, + jsval *argv, + bool WXUNUSED(constructing)) +{ + if ( argc == 0 ) + return new wxCalendarDateAttr(); + + if ( Colour::HasPrototype(cx, argv[0]) ) + { + if ( argc > 5 ) + return NULL; + + int border = wxCAL_BORDER_NONE; + const wxColour *textColour = &wxNullColour; + const wxColour *bgColour = &wxNullColour; + const wxColour *borderColour = &wxNullColour; + const wxFont *font = &wxNullFont; + + switch(argc) + { + case 5: + if ( ! FromJS(cx, argv[4], border) ) + break; + // Fall through + case 4: + font = Font::GetPrivate(cx, argv[3]); + if ( font == NULL ) + break; + // Fall through + case 3: + borderColour = Colour::GetPrivate(cx, argv[2]); + if ( borderColour == NULL ) + break; + // Fall through + case 2: + bgColour = Colour::GetPrivate(cx, argv[1]); + if ( bgColour == NULL ) + break; + // Fall through + default: + textColour = Colour::GetPrivate(cx, argv[0]); + if ( textColour == NULL ) + break; + + return new wxCalendarDateAttr(*textColour, *bgColour, + *borderColour, *font, + (wxCalendarDateBorder) border); + } + + return NULL; + } + else + { + int border; + if ( ! FromJS(cx, argv[0], border) ) + return NULL; + + const wxColour *colour = &wxNullColour; + if ( argc > 1 + && (colour = Colour::GetPrivate(cx, argv[1])) == NULL ) + return NULL; + + return new wxCalendarDateAttr((wxCalendarDateBorder) border, *colour); + } +} Property changes on: ps/trunk/source/tools/atlas/wxJS/gui/control/caldate.cpp ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/gui/control/listitattr.cpp =================================================================== --- ps/trunk/source/tools/atlas/wxJS/gui/control/listitattr.cpp (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/gui/control/listitattr.cpp (revision 5154) @@ -0,0 +1,165 @@ +#include "precompiled.h" + +/* + * wxJavaScript - listitattr.cpp + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: listitattr.cpp 598 2007-03-07 20:13:28Z fbraem $ + */ +// listitem.cpp +#include +#ifndef WX_PRECOMP + #include +#endif +#include + +#include "../../common/main.h" + +#include "../misc/app.h" +#include "../misc/font.h" +#include "../misc/colour.h" + +#include "listitattr.h" +#include "listctrl.h" + +using namespace wxjs; +using namespace wxjs::gui; + +/*** + * control/listitattr + * gui + * + * wxListItemAttr is used in virtual list controls. + * See @wxListCtrl#onGetItemAttr property + * + */ +WXJS_INIT_CLASS(ListItemAttr, "wxListItemAttr", 0) + +/*** + * + * + * The colour used for displaying text. + * + * + * The colour used as background. + * + * + * The font used for displaying text. + * + * + * Indicates that this attribute defines the text colour. + * + * + * Indicates that this attribute defines the background colour. + * + * + * Indicates that this attributes defines a font. + * + * + */ +WXJS_BEGIN_PROPERTY_MAP(ListItemAttr) + WXJS_PROPERTY(P_TEXT_COLOUR, "textColour") + WXJS_PROPERTY(P_BG_COLOUR, "backgroundColour") + WXJS_PROPERTY(P_FONT, "font") + WXJS_READONLY_PROPERTY(P_HAS_TEXT_COLOUR, "hasTextColour") + WXJS_READONLY_PROPERTY(P_HAS_BG_COLOUR, "hasBackgroundColour") + WXJS_READONLY_PROPERTY(P_HAS_FONT, "hasFont") +WXJS_END_PROPERTY_MAP() + +bool ListItemAttr::GetProperty(wxListItemAttr *p, JSContext *cx, JSObject *obj, int id, jsval *vp) +{ + switch (id) + { + case P_TEXT_COLOUR: + { + wxColour colour = p->GetTextColour(); + *vp = ( colour == wxNullColour ) ? JSVAL_VOID + : Colour::CreateObject(cx, new wxColour(colour)); + break; + } + case P_BG_COLOUR: + { + wxColour colour = p->GetBackgroundColour(); + *vp = ( colour == wxNullColour ) ? JSVAL_VOID + : Colour::CreateObject(cx, new wxColour(colour)); + break; + } + case P_FONT: + { + wxFont font = p->GetFont(); + *vp = ( font == wxNullFont ) ? JSVAL_VOID + : Font::CreateObject(cx, new wxFont(font)); + break; + } + case P_HAS_TEXT_COLOUR: + *vp = ToJS(cx, p->HasTextColour()); + break; + case P_HAS_BG_COLOUR: + *vp = ToJS(cx, p->HasBackgroundColour()); + break; + case P_HAS_FONT: + *vp = ToJS(cx, p->HasFont()); + break; + } + return true; +} + +bool ListItemAttr::SetProperty(wxListItemAttr *p, JSContext *cx, JSObject *obj, int id, jsval *vp) +{ + switch (id) + { + case P_TEXT_COLOUR: + { + wxColour *colour = Colour::GetPrivate(cx, obj); + if ( colour != NULL ) + p->SetTextColour(*colour); + break; + } + case P_BG_COLOUR: + { + wxColour *colour = Colour::GetPrivate(cx, obj); + if ( colour != NULL ) + p->SetBackgroundColour(*colour); + break; + } + case P_FONT: + { + wxFont *font = Font::GetPrivate(cx, obj); + if ( font != NULL ) + p->SetFont(*font); + break; + } + } + return true; +} + +/*** + * + * + * + * Creates a new wxListItem object. + * + * + */ +wxListItemAttr *ListItemAttr::Construct(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, bool constructing) +{ + return new wxListItemAttr(); +} Property changes on: ps/trunk/source/tools/atlas/wxJS/gui/control/listitattr.cpp ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/gui/control/mdi.cpp =================================================================== --- ps/trunk/source/tools/atlas/wxJS/gui/control/mdi.cpp (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/gui/control/mdi.cpp (revision 5154) @@ -0,0 +1,347 @@ +#include "precompiled.h" + +#ifndef WX_PRECOMP + #include +#endif + +#include "../../common/main.h" +#include "../errors.h" + +#include "../misc/size.h" +#include "../misc/point.h" +#include "window.h" +#include "mdi.h" +#include "frame.h" +#include "toolbar.h" + +using namespace wxjs::gui; + +wxToolBar* MDIParentFrame::OnCreateToolBar(long style, + wxWindowID id, + const wxString& name) +{ + ToolBar *tbar = new ToolBar(); + tbar->Create(this, id, wxDefaultPosition, wxDefaultSize, style, name); + return tbar; +} + +/*** + * gui + * control/mdiparent + * + * An MDI (Multiple Document Interface) parent frame is a window which can + * contain MDI child frames in its own 'desktop'. It is a convenient way to + * avoid window clutter, and is used in many popular Windows applications, + * such as Microsoft Word(TM). + * + */ +WXJS_INIT_CLASS(MDIParentFrame, "wxMDIParentFrame", 3) + +bool MDIParentFrame::AddProperty(wxMDIParentFrame *p, + JSContext* WXUNUSED(cx), + JSObject* WXUNUSED(obj), + const wxString &prop, + jsval* WXUNUSED(vp)) +{ + if ( WindowEventHandler::ConnectEvent(p, prop, true) ) + return true; + + FrameEventHandler::ConnectEvent(p, prop, true); + + return true; +} + +bool MDIParentFrame::DeleteProperty(wxMDIParentFrame *p, + JSContext* WXUNUSED(cx), + JSObject* WXUNUSED(obj), + const wxString &prop) +{ + if ( WindowEventHandler::ConnectEvent(p, prop, false) ) + return true; + + FrameEventHandler::ConnectEvent(p, prop, false); + return true; +} + +/*** + * + * + * + * The parent window + * The window ID + * The title of the window + * + * + * + * + * + * Creates a new MDI parent frame. + * + * + */ +wxMDIParentFrame* MDIParentFrame::Construct(JSContext* cx, + JSObject* obj, + uintN argc, + jsval *argv, + bool WXUNUSED(constructing)) +{ + MDIParentFrame *p = new MDIParentFrame(); + SetPrivate(cx, obj, p); + + if ( argc > 0 ) + { + jsval rval; + create(cx, obj, argc, argv, &rval); + } + return p; +} + +/*** + * + * + * The active MDI child, if there is one. + * + * + */ +WXJS_BEGIN_PROPERTY_MAP(MDIParentFrame) + WXJS_READONLY_PROPERTY(P_ACTIVE_CHILD, "activeChild") +WXJS_END_PROPERTY_MAP() + +bool MDIParentFrame::GetProperty(wxMDIParentFrame *p, + JSContext *cx, + JSObject *obj, + int id, + jsval *vp) +{ + switch(id) + { + case P_ACTIVE_CHILD: + { + wxMDIChildFrame *child = p->GetActiveChild(); + if ( child != NULL ) + { + JavaScriptClientData *data + = dynamic_cast(child->GetClientObject()); + if ( data ) + { + *vp = OBJECT_TO_JSVAL(data->GetObject()); + } + } + } + } + return true; +} + +WXJS_BEGIN_METHOD_MAP(MDIParentFrame) + WXJS_METHOD("create", create, 3) + WXJS_METHOD("activateNext", activateNext, 0) + WXJS_METHOD("activatePrevious", activatePrevious, 0) + WXJS_METHOD("arrangeIcons", arrangeIcons, 0) + WXJS_METHOD("cascade", cascade, 0) +WXJS_END_METHOD_MAP() + +/*** + * + * + * The parent window + * The window ID + * The title of the window + * + * + * + * + * + * Sets a pixel to a particular color. + * + * + */ +JSBool MDIParentFrame::create(JSContext* cx, + JSObject* obj, + uintN argc, + jsval* argv, + jsval* rval) +{ + wxMDIParentFrame *p = GetPrivate(cx, obj); + *rval = JSVAL_FALSE; + + int style = wxDEFAULT_FRAME_STYLE | wxVSCROLL | wxHSCROLL; + const wxPoint* pos = &wxDefaultPosition; + const wxSize* size = &wxDefaultSize; + + if ( argc > 6 ) + { + argc = 6; + } + + switch(argc) + { + case 6: + if ( ! FromJS(cx, argv[5], style) ) + { + JS_ReportError(cx, WXJS_INVALID_ARG_TYPE, 6, "Integer"); + return JS_FALSE; + } + case 5: + size = Size::GetPrivate(cx, argv[4]); + if ( size == NULL ) + { + JS_ReportError(cx, WXJS_INVALID_ARG_TYPE, 5, "wxSize"); + return JS_FALSE; + } + case 4: + pos = Point::GetPrivate(cx, argv[3]); + if ( pos == NULL ) + { + JS_ReportError(cx, WXJS_INVALID_ARG_TYPE, 4, "wxPoint"); + return JS_FALSE; + } + default: + { + wxString title; + wxWindow *parent = NULL; + int id = -1; + + FromJS(cx, argv[2], title); + + if ( ! FromJS(cx, argv[1], id) ) + { + JS_ReportError(cx, WXJS_INVALID_ARG_TYPE, 2, "wxPoint"); + return JS_FALSE; + } + + if ( ! JSVAL_IS_NULL(argv[0]) ) + { + parent = Window::GetPrivate(cx, argv[0]); + if ( parent == NULL ) + { + JS_ReportError(cx, WXJS_INVALID_ARG_TYPE, 1, "wxWindow"); + return JS_FALSE; + } + } + + if ( p->Create(parent, id, title, *pos, *size, style) ) + { + *rval = JSVAL_TRUE; + p->SetClientObject(new JavaScriptClientData(cx, obj, true, false)); + p->Connect(wxID_ANY, wxID_ANY, wxEVT_COMMAND_MENU_SELECTED, + wxCommandEventHandler(FrameEventHandler::OnMenu)); + } + } + } + return JS_TRUE; +} + +/*** + * + * + * + * Activates the MDI child following the currently active one. + * + * + */ +JSBool MDIParentFrame::activateNext(JSContext* cx, + JSObject* obj, + uintN WXUNUSED(argc), + jsval* WXUNUSED(argv), + jsval* WXUNUSED(rval)) +{ + wxMDIParentFrame *p = GetPrivate(cx, obj); + + p->ActivateNext(); + return JS_TRUE; +} + +/*** + * + * + * + * Activates the MDI child preceding the currently active one. + * + * + */ +JSBool MDIParentFrame::activatePrevious(JSContext* cx, + JSObject* obj, + uintN WXUNUSED(argc), + jsval* WXUNUSED(argv), + jsval* WXUNUSED(rval)) +{ + wxMDIParentFrame *p = GetPrivate(cx, obj); + + p->ActivatePrevious(); + return JS_TRUE; +} + +/*** + * + * + * + * Arranges any iconized (minimized) MDI child windows. + * + * + */ +JSBool MDIParentFrame::arrangeIcons(JSContext* cx, + JSObject* obj, + uintN WXUNUSED(argc), + jsval* WXUNUSED(argv), + jsval* WXUNUSED(rval)) +{ + wxMDIParentFrame *p = GetPrivate(cx, obj); + + p->ArrangeIcons(); + return JS_TRUE; +} + +/*** + * + * + * + * Arranges the MDI child windows in a cascade. + * + * + */ +JSBool MDIParentFrame::cascade(JSContext* cx, + JSObject* obj, + uintN WXUNUSED(argc), + jsval* WXUNUSED(argv), + jsval* WXUNUSED(rval)) +{ + wxMDIParentFrame *p = GetPrivate(cx, obj); + + p->Cascade(); + return JS_TRUE; +} + +/*** + * + * + * + * + * + * Tiles the MDI child windows either horizontally or vertically. + * Currently only implemented for MSW, does nothing under the other platforms. + * + * + */ +JSBool MDIParentFrame::tile(JSContext* cx, + JSObject* obj, + uintN argc, + jsval* argv, + jsval* WXUNUSED(rval)) +{ + wxMDIParentFrame *p = GetPrivate(cx, obj); + + int orient = wxHORIZONTAL; + if ( argc > 0 ) + { + if ( ! FromJS(cx, argv[0], orient) ) + { + return JS_TRUE; + } + } + + p->Tile((wxOrientation) orient); + return JS_TRUE; +} Property changes on: ps/trunk/source/tools/atlas/wxJS/gui/control/mdi.cpp ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/gui/control/treectrl.cpp =================================================================== --- ps/trunk/source/tools/atlas/wxJS/gui/control/treectrl.cpp (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/gui/control/treectrl.cpp (revision 5154) @@ -0,0 +1,2675 @@ +#include "precompiled.h" + +/* + * wxJavaScript - treectrl.cpp + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: treectrl.cpp 734 2007-06-06 20:09:13Z fbraem $ + */ +// wxJSTreeCtrl.cpp + +#ifndef WX_PRECOMP + #include +#endif + +#include "../../common/main.h" + + +#include "../event/jsevent.h" +#include "../event/treeevt.h" + +#include "../misc/app.h" +#include "../misc/validate.h" +#include "../misc/point.h" +#include "../misc/size.h" +#include "../misc/rect.h" +#include "../misc/colour.h" +#include "../misc/imagelst.h" +#include "../misc/font.h" + +#include "treectrl.h" +#include "treeid.h" +#include "treeitem.h" +#include "treehit.h" +#include "window.h" +#include "textctrl.h" +#include "../errors.h" + +using namespace wxjs; +using namespace wxjs::gui; + +TreeCtrl::TreeCtrl() : wxTreeCtrl() +{ +} + +TreeCtrl::~TreeCtrl() +{ +} + +int TreeCtrl::OnCompareItems(const wxTreeItemId& item1, + const wxTreeItemId& item2) +{ + JavaScriptClientData *data + = dynamic_cast(GetClientObject()); + JSContext *cx = data->GetContext(); + + jsval rval; + jsval argv[] = { + TreeItemId::CreateObject(cx, new wxTreeItemId(item1)), + TreeItemId::CreateObject(cx, new wxTreeItemId(item2)) + }; + jsval fval; + if ( GetFunctionProperty(cx, data->GetObject(), + "onCompareItems", &fval) == JS_TRUE ) + { + if ( JS_CallFunctionValue(cx, data->GetObject(), + fval, 2, argv, &rval) == JS_TRUE ) + { + int rc; + if ( FromJS(cx, rval, rc) ) + return rc; + } + else + { + if ( JS_IsExceptionPending(cx) ) + { + JS_ReportPendingException(cx); + } + } + } + return wxTreeCtrl::OnCompareItems(item1, item2); +} + +/*** + * control/treectrl + * gui + * + * A tree control presents information as a hierarchy, with items that may be + * expanded to show further items. Items in a tree control are referenced by + * @wxTreeItemId handles. + * + */ +WXJS_INIT_CLASS(TreeCtrl, "wxTreeCtrl", 2) + +void TreeCtrl::InitClass(JSContext* WXUNUSED(cx), + JSObject* WXUNUSED(obj), + JSObject* WXUNUSED(proto)) +{ + TreeCtrlEventHandler::InitConnectEventMap(); +} + +/*** + * + * + * Get the total number of items in the control. + * + * + * Gets the first visible item. + * + * + * Get/Set the normal image list. + * + * + * Get/Set the indent. Indent is the number of pixels the children are indented relative to + * the parents position. Setting indent also redraws the control immediately. + * + * + * Set this to a function when you want to change the sort order of the items in the + * tree control. The function should return a negative, zero or positive value if the first + * item is less than, equal to or greater than the second one. The function gets two + * @wxTreeItemId objects as arguments. When not set, the items are sorted + * alphabetically. + * + * + * Gets the root item. + * + * + * Gets the selection. Use @wxTreeCtrl#selections when the tree can have more then + * one selected item (MULTIPLE style). + * + * + * Gets all selected items (An array with @wxTreeItemId objects). + * + * + * Get/Set the state image list. + * + * + */ +WXJS_BEGIN_PROPERTY_MAP(TreeCtrl) + WXJS_READONLY_PROPERTY(P_COUNT, "count") + WXJS_PROPERTY(P_INDENT, "indent") + WXJS_PROPERTY(P_IMAGE_LIST, "imageList") + WXJS_PROPERTY(P_STATE_IMAGE_LIST, "stateImageList") + WXJS_READONLY_PROPERTY(P_ROOT_ITEM, "rootItem") + WXJS_READONLY_PROPERTY(P_SELECTION, "selection") + WXJS_READONLY_PROPERTY(P_SELECTIONS, "selections") + WXJS_READONLY_PROPERTY(P_FIRST_VISIBLE, "firstVisibleItem") + WXJS_READONLY_PROPERTY(P_EDIT_CONTROL, "editControl") +WXJS_END_PROPERTY_MAP() + +bool TreeCtrl::GetProperty(wxTreeCtrl *p, + JSContext *cx, + JSObject* WXUNUSED(obj), + int id, + jsval *vp) +{ + switch(id) + { + case P_COUNT: + *vp = ToJS(cx, p->GetCount()); + break; + case P_INDENT: + *vp = ToJS(cx, p->GetIndent()); + break; + case P_IMAGE_LIST: + { + wxImageList *imgList = p->GetImageList(); + if ( imgList != NULL ) + { + JavaScriptClientData *data + = dynamic_cast(imgList); + if ( data != NULL ) + { + *vp = OBJECT_TO_JSVAL(data->GetObject()); + } + } + break; + } + case P_STATE_IMAGE_LIST: + { + wxImageList *imgList = p->GetStateImageList(); + if ( imgList != NULL ) + { + JavaScriptClientData *data + = dynamic_cast(imgList); + if ( data != NULL ) + { + *vp = OBJECT_TO_JSVAL(data->GetObject()); + } + } + break; + } + case P_ROOT_ITEM: + *vp = TreeItemId::CreateObject(cx, new wxTreeItemId(p->GetRootItem())); + break; + case P_SELECTION: + *vp = TreeItemId::CreateObject(cx, new wxTreeItemId(p->GetSelection())); + break; + case P_FIRST_VISIBLE: + *vp = TreeItemId::CreateObject(cx, new wxTreeItemId(p->GetFirstVisibleItem())); + break; + case P_EDIT_CONTROL: + { + wxTextCtrl *edit = p->GetEditControl(); + if ( edit != NULL ) + { + JavaScriptClientData *data + = dynamic_cast(edit->GetClientObject()); + if ( data != NULL ) + { + *vp = OBJECT_TO_JSVAL(data->GetObject()); + } + } + break; + } + case P_SELECTIONS: + { + wxArrayTreeItemIds selections; + jsint count = p->GetSelections(selections); + JSObject *objSelections = JS_NewArrayObject(cx, count, NULL); + + *vp = OBJECT_TO_JSVAL(objSelections); + + jsint i = 0; + for (; i < count; i++) + { + jsval el + = TreeItemId::CreateObject(cx, new wxTreeItemId(selections[i])); + JS_SetElement(cx, objSelections, i++, &el); + } + } + break; + } + return true; +} + +bool TreeCtrl::SetProperty(wxTreeCtrl *p, + JSContext *cx, + JSObject* WXUNUSED(obj), + int id, + jsval *vp) +{ + switch(id) + { + case P_INDENT: + { + int indent; + if ( FromJS(cx, p->GetIndent(), indent)) + p->SetIndent(indent); + break; + } + case P_IMAGE_LIST: + { + ImageList *imgList = ImageList::GetPrivate(cx, *vp); + if ( imgList != NULL ) + { + p->AssignImageList(imgList); + JavaScriptClientData *data + = dynamic_cast(imgList->GetClientObject()); + if ( data != NULL ) + { + data->Protect(true); + data->SetOwner(false); + } + } + break; + } + case P_STATE_IMAGE_LIST: + { + ImageList *imgList = ImageList::GetPrivate(cx, *vp); + if ( imgList != NULL ) + p->AssignStateImageList(imgList); + JavaScriptClientData *data + = dynamic_cast(imgList->GetClientObject()); + if ( data != NULL ) + { + data->Protect(true); + data->SetOwner(false); + } + break; + } + } + return true; +} + +bool TreeCtrl::AddProperty(wxTreeCtrl *p, + JSContext* WXUNUSED(cx), + JSObject* WXUNUSED(obj), + const wxString &prop, + jsval* WXUNUSED(vp)) +{ + if ( WindowEventHandler::ConnectEvent(p, prop, true) ) + return true; + + TreeCtrlEventHandler::ConnectEvent(p, prop, true); + + return true; +} + +bool TreeCtrl::DeleteProperty(wxTreeCtrl *p, + JSContext* WXUNUSED(cx), + JSObject* WXUNUSED(obj), + const wxString &prop) +{ + if ( WindowEventHandler::ConnectEvent(p, prop, false) ) + return true; + + TreeCtrlEventHandler::ConnectEvent(p, prop, false); + return true; +} + +/*** + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + */ +WXJS_BEGIN_CONSTANT_MAP(TreeCtrl) + WXJS_CONSTANT(wxTR_, NO_BUTTONS) + WXJS_CONSTANT(wxTR_, HAS_BUTTONS) + WXJS_CONSTANT(wxTR_, TWIST_BUTTONS) + WXJS_CONSTANT(wxTR_, NO_LINES) + WXJS_CONSTANT(wxTR_, LINES_AT_ROOT) + WXJS_CONSTANT(wxTR_, MAC_BUTTONS) + WXJS_CONSTANT(wxTR_, AQUA_BUTTONS) + WXJS_CONSTANT(wxTR_, SINGLE) + WXJS_CONSTANT(wxTR_, MULTIPLE) + WXJS_CONSTANT(wxTR_, EXTENDED) + WXJS_CONSTANT(wxTR_, FULL_ROW_HIGHLIGHT) + WXJS_CONSTANT(wxTR_, EDIT_LABELS) + WXJS_CONSTANT(wxTR_, ROW_LINES) + WXJS_CONSTANT(wxTR_, HIDE_ROOT) + WXJS_CONSTANT(wxTR_, HAS_VARIABLE_ROW_HEIGHT) + WXJS_CONSTANT(wxTR_, DEFAULT_STYLE) +WXJS_END_CONSTANT_MAP() + +/*** + * + * + * + * + * The parent of wxTreeCtrl. + * + * + * An window identifier. Use -1 when you don't need it. + * + * + * The position of the TreeCtrl control on the given parent. + * + * + * The size of the TreeCtrl control. + * + * + * The wxTreeCtrl style. + * + * + * Validator. + * + * + * + * Constructs a new wxTreeCtrl object. + * + * + */ +wxTreeCtrl* TreeCtrl::Construct(JSContext *cx, + JSObject *obj, + uintN argc, + jsval *argv, + bool WXUNUSED(constructing)) +{ + wxTreeCtrl *p = new wxTreeCtrl(); + SetPrivate(cx, obj, p); + + if ( argc > 0 ) + { + jsval rval; + create(cx, obj, argc, argv, &rval); + } + return p; +} + +WXJS_BEGIN_METHOD_MAP(TreeCtrl) + WXJS_METHOD("create", create, 2) + WXJS_METHOD("getItem", getItem, 1) + WXJS_METHOD("getItemText", getItemText, 1) + WXJS_METHOD("setItemText", setItemText, 2) + WXJS_METHOD("getItemImage", getItemImage, 2) + WXJS_METHOD("setItemImage", setItemImage, 3) + WXJS_METHOD("getItemData", getItemData, 1) + WXJS_METHOD("setItemData", setItemData, 2) + WXJS_METHOD("getItemTextColour", getItemTextColour, 1) + WXJS_METHOD("setItemTextColour", setItemTextColour, 2) + WXJS_METHOD("getItemBackgroundColour", getItemBackgroundColour, 1) + WXJS_METHOD("setItemBackgroundColour", setItemBackgroundColour, 2) + WXJS_METHOD("getItemFont", getItemFont, 1) + WXJS_METHOD("setItemFont", setItemFont, 2) + WXJS_METHOD("setItemHasChildren", setItemHasChildren, 1) + WXJS_METHOD("isBold", isBold, 1) + WXJS_METHOD("setItemBold", setItemBold, 1) + WXJS_METHOD("setItemDropHighlight", setItemDropHighlight, 1) + WXJS_METHOD("isVisible", isVisible, 1) + WXJS_METHOD("isExpanded", isExpanded, 1) + WXJS_METHOD("isSelected", isSelected, 1) + WXJS_METHOD("getChildrenCount", getChildrenCount, 1) + WXJS_METHOD("getItemParent", getItemParent, 1) + WXJS_METHOD("getFirstChild", getFirstChild, 2) + WXJS_METHOD("getNextChild", getNextChild, 2) + WXJS_METHOD("getPrevSibling", getPrevSibling, 1) + WXJS_METHOD("getNextSibling", getNextSibling, 1) + WXJS_METHOD("getPrevVisible", getPrevVisible, 1) + WXJS_METHOD("getNextVisible", getNextVisible, 1) + WXJS_METHOD("addRoot", addRoot, 1) + WXJS_METHOD("appendItem", appendItem, 2) + WXJS_METHOD("prependItem", prependItem, 2) + WXJS_METHOD("insertItem", insertItem, 3) + WXJS_METHOD("deleteItem", deleteItem, 1) + WXJS_METHOD("deleteChildren", deleteChildren, 1) + WXJS_METHOD("deleteAllItems", deleteAllItems, 0) + WXJS_METHOD("expand", expand, 1) + WXJS_METHOD("collapse", collapse, 1) + WXJS_METHOD("collapseAndReset", collapseAndReset, 1) + WXJS_METHOD("toggle", toggle, 1) + WXJS_METHOD("unselect", unselect, 0) + WXJS_METHOD("unselectAll", unselectAll, 0) + WXJS_METHOD("selectItem", selectItem, 1) + WXJS_METHOD("ensureVisible", ensureVisible, 1) + WXJS_METHOD("scrollTo", scrollTo, 1) + WXJS_METHOD("editLabel", editLabel, 1) + WXJS_METHOD("sortChildren", sortChildren, 1) +WXJS_END_METHOD_MAP() + +JSBool TreeCtrl::create(JSContext *cx, + JSObject *obj, + uintN argc, + jsval *argv, + jsval *rval) +{ + wxTreeCtrl *p = GetPrivate(cx, obj); + *rval = JSVAL_FALSE; + + if ( argc > 6 ) + argc = 6; + + int style = wxTR_HAS_BUTTONS | wxTR_LINES_AT_ROOT; + const wxPoint *pt = &wxDefaultPosition; + const wxSize *size = &wxDefaultSize; + const wxValidator *val = &wxDefaultValidator; + + switch(argc) + { + case 6: + val = Validator::GetPrivate(cx, argv[5]); + if ( val == NULL ) + { + JS_ReportError(cx, WXJS_INVALID_ARG_TYPE, 6, "wxValidator"); + return JS_FALSE; + } + case 5: + if ( ! FromJS(cx, argv[4], style) ) + { + JS_ReportError(cx, WXJS_INVALID_ARG_TYPE, 5, "Integer"); + return JS_FALSE; + } + // Fall through + case 4: + size = Size::GetPrivate(cx, argv[3]); + if ( size == NULL ) + { + JS_ReportError(cx, WXJS_INVALID_ARG_TYPE, 4, "wxSize"); + return JS_FALSE; + } + // Fall through + case 3: + pt = Point::GetPrivate(cx, argv[2]); + if ( pt == NULL ) + { + JS_ReportError(cx, WXJS_INVALID_ARG_TYPE, 3, "wxPoint"); + return JS_FALSE; + } + // Fall through + default: + + int id; + if ( ! FromJS(cx, argv[1], id) ) + { + JS_ReportError(cx, WXJS_INVALID_ARG_TYPE, 2, "Integer"); + return JS_FALSE; + } + + wxWindow *parent = Window::GetPrivate(cx, argv[0]); + if ( parent == NULL ) + { + JS_ReportError(cx, WXJS_NO_PARENT_ERROR, GetClass()->name); + return JS_FALSE; + } + JavaScriptClientData *clntParent = + dynamic_cast(parent->GetClientObject()); + if ( clntParent == NULL ) + { + JS_ReportError(cx, WXJS_NO_PARENT_ERROR, GetClass()->name); + return JS_FALSE; + } + JS_SetParent(cx, obj, clntParent->GetObject()); + + if ( p->Create(parent, id, *pt, *size, style, *val) ) + { + *rval = JSVAL_TRUE; + p->SetClientObject(new JavaScriptClientData(cx, obj, true, false)); + } + } + return JS_TRUE; +} + +/*** + * + * + * + * The id of the item + * + * + * + * Creates a @wxTreeItem from the given @wxTreeItemId. + * @wxTreeItem can be used to alter the item without + * always passing the id to the tree control. null is returned + * when the id is not valid. + * + * + */ +JSBool TreeCtrl::getItem(JSContext *cx, + JSObject *obj, + uintN argc, + jsval *argv, + jsval *rval) +{ + wxTreeCtrl *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + wxTreeItemId *id = TreeItemId::GetPrivate(cx, argv[0]); + if ( id != NULL ) + { + if ( id->IsOk() ) + *rval = TreeItem::CreateObject(cx, new wxTreeItemId(*id)); + else + *rval = JSVAL_VOID; + return JS_TRUE; + } + return JS_FALSE; +} + +/*** + * + * + * + * The id of the item + * + * + * + * Gets the text of the given item. + * See also @wxTreeItem @wxTreeItem#text property + * + * + */ +JSBool TreeCtrl::getItemText(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxTreeCtrl *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + wxTreeItemId *id = TreeItemId::GetPrivate(cx, argv[0]); + if ( id != NULL ) + { + *rval = ToJS(cx, p->GetItemText(*id)); + return JS_TRUE; + } + return JS_FALSE; +} + +/*** + * + * + * + * The id of the item + * + * + * The new text for the item. + * + * + * + * Sets the text of the given item. + * The example changes the text of the root. + * + * tree.setItemText(tree.rootItem, "root"); + * + * See @wxTreeItem @wxTreeItem#text property + * + * + */ +JSBool TreeCtrl::setItemText(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxTreeCtrl *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + wxTreeItemId *id = TreeItemId::GetPrivate(cx, argv[0]); + if ( id != NULL ) + { + wxString text; + FromJS(cx, argv[1], text); + p->SetItemText(*id, text); + return JS_TRUE; + } + return JS_FALSE; +} + +/*** + * + * + * + * The id of the item + * + * + * A @wxTreeItemIcon constant. + * + * + * + * Gets the specified item image. + * See @wxTreeItem @wxTreeItem#getImage method + * + * + */ +JSBool TreeCtrl::getItemImage(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxTreeCtrl *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + wxTreeItemId *id = TreeItemId::GetPrivate(cx, argv[0]); + int which; + + if ( id != NULL + && FromJS(cx, argv[1], which) ) + { + *rval = ToJS(cx, p->GetItemImage(*id, (wxTreeItemIcon) which)); + return JS_TRUE; + } + return JS_FALSE; +} + +/*** + * + * + * + * The id of the item + * + * + * The new image for the item. + * + * + * A @wxTreeItemIcon constant. + * + * + * + * Sets the image for the given item. + * See @wxTreeItem @wxTreeItem#setImage method + * + * + */ +JSBool TreeCtrl::setItemImage(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxTreeCtrl *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + wxTreeItemId *id = TreeItemId::GetPrivate(cx, argv[0]); + int image; + int which; + if ( id != NULL + && FromJS(cx, argv[1], image) + && FromJS(cx, argv[2], which) ) + { + p->SetItemImage(*id, image, (wxTreeItemIcon) which); + return JS_TRUE; + } + return JS_FALSE; +} + +/*** + * + * + * + * The id of the item + * + * + * + * Gets the associated object or value of the item. The item data + * can be any possible JavaScript type. + * See @wxTreeItem @wxTreeItem#data property, @wxTreeCtrl#setItemData + * + * + */ +JSBool TreeCtrl::getItemData(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxTreeCtrl *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + wxTreeItemId *id = TreeItemId::GetPrivate(cx, argv[0]); + if ( id != NULL ) + { + ObjectTreeData *data = (ObjectTreeData*) p->GetItemData(*id); + *rval = ( data == NULL ) ? JSVAL_VOID : data->GetJSVal(); + return JS_TRUE; + } + return JS_FALSE; +} + +/*** + * + * + * + * The id of the item + * + * + * The data to associate with this item. + * + * + * + * Sets the associated data for the given item. You can use + * any type: Integer, Object, Boolean, ... + *

+ * The following example shows that you can use an object as item data. + *

+ *    dlg = new wxDialog(null, -1, "Tree example");
+ *    dlg.tree = new wxTreeCtrl(dlg, 1);
+ *
+ *    var root = dlg.tree.addRoot("Root");
+ *    var id = dlg.tree.appendItem(root, "Child 1");
+ *
+ *    dlg.tree.setItemData(id, new Date());
+ *    id = dlg.tree.appendItem(root, "Child 2");
+ *    dlg.tree.setItemData(id, new Date());
+ *    id = dlg.tree.appendItem(root, "Child 3");
+ *    dlg.tree.setItemData(id, new Date());
+ *   
+ * See @wxTreeItem @wxTreeItem#data property, @wxTreeCtrl#getItemData + *
+ *
+ */ +JSBool TreeCtrl::setItemData(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxTreeCtrl *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + wxTreeItemId *id = TreeItemId::GetPrivate(cx, argv[0]); + if ( id != NULL ) + { + ObjectTreeData *data = new ObjectTreeData(cx, argv[1]); + p->SetItemData(*id, data); + return JS_TRUE; + } + return JS_FALSE; + +} + +/*** + * + * + * + * The id of the item + * + * + * + * Gets the text colour of the item. + * See @wxTreeItem @wxTreeItem#textColour property + * + * + */ +JSBool TreeCtrl::getItemTextColour(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxTreeCtrl *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + wxTreeItemId *id = TreeItemId::GetPrivate(cx, argv[0]); + if ( id != NULL ) + { + *rval = Colour::CreateObject(cx, new wxColour(p->GetItemTextColour(*id))); + return JS_TRUE; + } + return JS_FALSE; +} + +/*** + * + * + * + * The id of the item + * + * + * The new colour. + * + * + * + * Sets a new text colour for this item. + * The example sets red as the text colour of the root item. + * + * tree.setItemTextColour(tree.rootItem, wxRED); + * + * See @wxTreeItem @wxTreeItem#textColour property + * + * + */ +JSBool TreeCtrl::setItemTextColour(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxTreeCtrl *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + wxTreeItemId *id = TreeItemId::GetPrivate(cx, argv[0]); + wxColour *colour = Colour::GetPrivate(cx, argv[1]); + if ( id != NULL ) + { + p->SetItemTextColour(*id, *colour); + return JS_TRUE; + } + return JS_FALSE; + +} + +/*** + * + * + * + * The id of the item + * + * + * + * Gets the background colour of the item. + * See @wxTreeItem @wxTreeItem#backgroundColour property + * + * + */ +JSBool TreeCtrl::getItemBackgroundColour(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxTreeCtrl *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + wxTreeItemId *id = TreeItemId::GetPrivate(cx, argv[0]); + if ( id != NULL ) + { + *rval = Colour::CreateObject(cx, new wxColour(p->GetItemBackgroundColour(*id))); + return JS_TRUE; + } + return JS_FALSE; +} + +/*** + * + * + * + * The id of the item + * + * + * The new colour. + * + * + * + * Sets a new background colour for this item. + * The example sets the backgroundcolour of the root item to red. + * + * tree.setItemBackgroundColour(tree.rootItem, wxRED); + * + * See @wxTreeItem @wxTreeItem#backgroundColour property + * + * + */ +JSBool TreeCtrl::setItemBackgroundColour(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxTreeCtrl *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + wxTreeItemId *id = TreeItemId::GetPrivate(cx, argv[0]); + wxColour *colour = Colour::GetPrivate(cx, argv[1]); + if ( id != NULL ) + { + p->SetItemBackgroundColour(*id, *colour); + return JS_TRUE; + } + return JS_FALSE; +} + +/*** + * + * + * + * The id of the item + * + * + * + * Gets the font of the item. + * See @wxTreeItem @wxTreeItem#font property + * + * + */ +JSBool TreeCtrl::getItemFont(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxTreeCtrl *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + wxTreeItemId *id = TreeItemId::GetPrivate(cx, argv[0]); + if ( id != NULL ) + { + *rval = Font::CreateObject(cx, new wxFont(p->GetItemFont(*id))); + return JS_TRUE; + } + return JS_FALSE; +} + +/*** + * + * + * + * The id of the item + * + * + * The new font. + * + * + * + * Sets a new font for this item. + * See @wxTreeItem @wxTreeItem#font property. + * + * + */ +JSBool TreeCtrl::setItemFont(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxTreeCtrl *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + wxTreeItemId *id = TreeItemId::GetPrivate(cx, argv[0]); + wxFont *font = Font::GetPrivate(cx, argv[1]); + if ( id != NULL + && font != NULL ) + { + p->SetItemFont(*id, *font); + return JS_TRUE; + } + return JS_FALSE; + +} + +/*** + * + * + * + * The id of the item + * + * + * + * + * Force appearance of the button next to the item. This is useful to allow + * the user to expand the items which don't have any children now, but instead + * adding them only when needed, thus minimizing memory usage and loading time. + * See @wxTreeItem @wxTreeItem#hasChildren property + * + * + */ +JSBool TreeCtrl::setItemHasChildren(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxTreeCtrl *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + bool hasChildren; + if ( argc == 1 ) + hasChildren = true; + else if ( ! FromJS(cx, argv[1], hasChildren) ) + return JS_FALSE; + + wxTreeItemId *id = TreeItemId::GetPrivate(cx, argv[0]); + if ( id != NULL ) + { + p->SetItemHasChildren(*id, hasChildren); + return JS_TRUE; + } + return JS_FALSE; +} + + +/*** + * + * + * + * The id of the item + * + * + * + * Returns true when the item text is in bold. + * See @wxTreeItem @wxTreeItem#bold property + * + * + */ +JSBool TreeCtrl::isBold(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxTreeCtrl *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + wxTreeItemId *id = TreeItemId::GetPrivate(cx, argv[0]); + if ( id != NULL ) + { + *rval = ToJS(cx, p->IsBold(*id)); + return JS_TRUE; + } + return JS_FALSE; +} + +/*** + * + * + * + * The id of the item + * + * + * + * + * Makes item appear in bold font if bold parameter is true + * or resets it to the normal state. + * See @wxTreeItem @wxTreeItem#bold property + * + * + */ +JSBool TreeCtrl::setItemBold(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxTreeCtrl *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + wxTreeItemId *id = TreeItemId::GetPrivate(cx, argv[0]); + bool bold; + if ( argc == 1 ) + bold = true; + else if ( ! FromJS(cx, argv[1], bold) ) + return JS_FALSE; + + if ( id != NULL ) + { + p->SetItemBold(*id, bold); + return JS_TRUE; + } + return JS_FALSE; + +} + +/*** + * + * + * + * The id of the item + * + * + * + * + * The item will be shown with a drop highlight or not. + * + * + */ +JSBool TreeCtrl::setItemDropHighlight(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxTreeCtrl *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + wxTreeItemId *id = TreeItemId::GetPrivate(cx, argv[0]); + bool highlight; + if ( argc == 1 ) + highlight = true; + else if ( ! FromJS(cx, argv[1], highlight) ) + return JS_FALSE; + + if ( id != NULL ) + { + p->SetItemDropHighlight(*id, highlight); + return JS_TRUE; + } + return JS_FALSE; + +} + +/*** + * + * + * + * The id of the item + * + * + * + * Returns true when the item is visible. + * See @wxTreeItem @wxTreeItem#visible property + * + * + */ +JSBool TreeCtrl::isVisible(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxTreeCtrl *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + wxTreeItemId *id = TreeItemId::GetPrivate(cx, argv[0]); + if ( id != NULL ) + { + *rval = ToJS(cx, p->IsVisible(*id)); + return JS_TRUE; + } + return JS_FALSE; +} + +/*** + * + * + * + * The id of the item + * + * + * + * Returns true when the item is expanded. + * See @wxTreeItem @wxTreeItem#expanded property + * + * + */ +JSBool TreeCtrl::isExpanded(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxTreeCtrl *p = TreeCtrl::GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + wxTreeItemId *id = TreeItemId::GetPrivate(cx, argv[0]); + if ( id != NULL ) + { + *rval = ToJS(cx, p->IsExpanded(*id)); + return JS_TRUE; + } + return JS_FALSE; +} + +/*** + * + * + * + * The id of the item + * + * + * + * Returns true when the item is selected. + * See @wxTreeItem @wxTreeItem#selected property + * + * + */ +JSBool TreeCtrl::isSelected(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxTreeCtrl *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + wxTreeItemId *id = TreeItemId::GetPrivate(cx, argv[0]); + if ( id != NULL ) + { + *rval = ToJS(cx, p->IsSelected(*id)); + return JS_TRUE; + } + return JS_FALSE; +} + +/*** + * + * + * + * The id of the item + * + * + * If Recurse is true (the default), returns the total number of descendants, + * otherwise only one level of children is counted + * + * + * + * Returns the number of childrens of the item. + * See @wxTreeItem @wxTreeItem#bold property + * + * + */ +JSBool TreeCtrl::getChildrenCount(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxTreeCtrl *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + wxTreeItemId *id = TreeItemId::GetPrivate(cx, argv[0]); + bool recursive; + if ( argc == 1 ) + recursive = true; + else if ( ! FromJS(cx, argv[1], recursive) ) + return JS_FALSE; + + if ( id != NULL ) + { + *rval = ToJS(cx, p->GetChildrenCount(*id, recursive)); + return JS_TRUE; + } + return JS_FALSE; + +} + +/*** + * + * + * + * The id of the item + * + * + * + * Returns the parent of the item. + * See @wxTreeItem @wxTreeItem#parent property + * + * + */ +JSBool TreeCtrl::getItemParent(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxTreeCtrl *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + wxTreeItemId *id = TreeItemId::GetPrivate(cx, argv[0]); + + if ( id != NULL ) + { + *rval = TreeItemId::CreateObject(cx, new wxTreeItemId(p->GetItemParent(*id))); + return JS_TRUE; + } + return JS_FALSE; + +} + +/*** + * + * + * + * The id of the item + * + * + * For this enumeration function you must pass in a 'cookie' parameter + * which is opaque for the application but is necessary for the library + * to make these functions reentrant (i.e. allow more than one enumeration + * on one and the same object simultaneously). The cookie passed + * to getFirstChild and @wxTreeCtrl#getNextChild should be the same variable. + * + * + * + * Returns the first child item. An invalid item is returned when there is no child item. + * See @wxTreeItem @wxTreeItem#getFirstChild method + * + * + */ +JSBool TreeCtrl::getFirstChild(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxTreeCtrl *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + wxTreeItemId *id = TreeItemId::GetPrivate(cx, argv[0]); + long cookie; + if ( id != NULL + && FromJS(cx, argv[1], cookie) ) + { + wxTreeItemIdValue newCookie = (wxTreeItemIdValue) cookie; + *rval = TreeItemId::CreateObject(cx, new wxTreeItemId(p->GetFirstChild(*id, newCookie))); + return JS_TRUE; + } + return JS_FALSE; + +} + +/*** + * + * + * + * The id of the item + * + * + * For this enumeration function you must pass in a 'cookie' parameter + * which is opaque for the application but is necessary for the library + * to make these functions reentrant (i.e. allow more than one enumeration + * on one and the same object simultaneously). The cookie passed + * to @wxTreeCtrl#getNextChild and getNextChild should be the same variable. + * + * + * + * Returns the next child item. An invalid item is returned when there is no child item. + * See @wxTreeItem @wxTreeItem#getNextChild method + * + * + */ +JSBool TreeCtrl::getNextChild(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxTreeCtrl *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + wxTreeItemId *id = TreeItemId::GetPrivate(cx, argv[0]); + long cookie; + if ( id != NULL + && FromJS(cx, argv[1], cookie) ) + { + wxTreeItemIdValue newCookie = (wxTreeItemIdValue) cookie; + *rval = TreeItemId::CreateObject(cx, new wxTreeItemId(p->GetNextChild(*id, newCookie))); + return JS_TRUE; + } + return JS_FALSE; + +} + +/*** + * + * + * + * The id of the item + * + * + * + * Returns the previous sibling item. An invalid item is returned when there is no child item. + * See @wxTreeItem @wxTreeItem#prevSibling property + * + * + */ +JSBool TreeCtrl::getPrevSibling(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxTreeCtrl *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + wxTreeItemId *id = TreeItemId::GetPrivate(cx, argv[0]); + if ( id != NULL ) + { + *rval = TreeItemId::CreateObject(cx, new wxTreeItemId(p->GetPrevSibling(*id))); + return JS_TRUE; + } + return JS_FALSE; +} + +/*** + * + * + * + * The id of the item + * + * + * + * Returns the next sibling item. An invalid item is returned when there is no child item. + * See @wxTreeItem @wxTreeItem#nextSibling property + * + * + */ +JSBool TreeCtrl::getNextSibling(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxTreeCtrl *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + wxTreeItemId *id = TreeItemId::GetPrivate(cx, argv[0]); + if ( id != NULL ) + { + *rval = TreeItemId::CreateObject(cx, new wxTreeItemId(p->GetNextSibling(*id))); + return JS_TRUE; + } + return JS_FALSE; +} + +/*** + * + * + * + * The id of the item + * + * + * + * Returns the previous visible item. + * + * + */ +JSBool TreeCtrl::getPrevVisible(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxTreeCtrl *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + wxTreeItemId *id = TreeItemId::GetPrivate(cx, argv[0]); + if ( id != NULL ) + { + *rval = TreeItemId::CreateObject(cx, new wxTreeItemId(p->GetPrevVisible(*id))); + return JS_TRUE; + } + return JS_FALSE; +} + +/*** + * + * + * + * The id of the item + * + * + * + * Returns the next visible item. The item itself must also be visible. + * See @wxTreeItem @wxTreeItem#nextSibling property + * + * + */ +JSBool TreeCtrl::getNextVisible(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxTreeCtrl *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + wxTreeItemId *id = TreeItemId::GetPrivate(cx, argv[0]); + if ( id != NULL ) + { + *rval = TreeItemId::CreateObject(cx, new wxTreeItemId(p->GetNextVisible(*id))); + return JS_TRUE; + } + return JS_FALSE; +} + + +/*** + * + * + * + * The text for the root item. + * + * + * Index of the image for normal items. The default is -1 which means don't use. + * + * + * Index of the image for selected items. The default is -1 which means don't use. + * + * + * + * + * Adds the root node to the tree, returning the id of the new item. + * The Image and SelectedImage parameters are an index within the normal image list + * specifying the image to use for unselected and selected items, respectively. + * If Image > -1 and SelectedImage is -1, the same image is used for both selected + * and unselected items. + *

+ * The following example adds a root item and 3 childs to the root. + *

+ *     var dlg = new wxDialog(null, -1, "Tree example");
+ *     dlg.tree = new wxTreeCtrl(dlg, 1);
+ *
+ *     var root = dlg.tree.addRoot("Root");
+ *     dlg.tree.appendItem(root, "Child 1");
+ *     dlg.tree.appendItem(root, "Child 2");
+ *     dlg.tree.appendItem(root, "Child 3");
+ *    
+ *
+ *
+ */ +JSBool TreeCtrl::addRoot(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxTreeCtrl *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + if (argc > 4 ) + argc = 4; + + ObjectTreeData *data = NULL; + int selImage = -1; + int image = -1; + + switch(argc) + { + case 4: + data = new ObjectTreeData(cx, argv[3]); + // Fall through + case 3: + if ( ! FromJS(cx, argv[2], selImage) ) + break; + // Fall through + case 2: + if ( ! FromJS(cx, argv[1], image) ) + break; + // Fall through + default: + + wxString text; + FromJS(cx, argv[0], text); + *rval = TreeItemId::CreateObject(cx, new wxTreeItemId(p->AddRoot(text, image, selImage, data))); + return JS_TRUE; + } + return JS_FALSE; +} + +/*** + * + * + * + * The id of the parent item. + * + * + * The text for the root item. + * + * + * Index of the image for normal items. The default is -1 which means don't use. + * + * + * Index of the image for selected items. The default is -1 which means don't use. + * + * + * + * + * Appends an item to the end of the branch identified by parent, return a new item id. + * The Image and SelectedImage parameters are an index within the normal image list + * specifying the image to use for unselected and selected items, respectively. + * If Image > -1 and SelectedImage is -1, the same image is used for both selected + * and unselected items. + * + * + */ +JSBool TreeCtrl::appendItem(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxTreeCtrl *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + if (argc > 5 ) + argc = 5; + + ObjectTreeData *data = NULL; + int selImage = -1; + int image = -1; + + switch(argc) + { + case 5: + data = new ObjectTreeData(cx, argv[4]); + // Fall through + case 4: + if ( ! FromJS(cx, argv[3], selImage) ) + break; + // Fall through + case 3: + if ( ! FromJS(cx, argv[2], image) ) + break; + // Fall through + default: + + wxString text; + FromJS(cx, argv[1], text); + + wxTreeItemId *parent = TreeItemId::GetPrivate(cx, argv[0]); + if ( parent == NULL ) + break; + + wxTreeItemId newId = p->AppendItem(*parent, text, image, selImage, data); + *rval = TreeItemId::CreateObject(cx, new wxTreeItemId(newId)); + return JS_TRUE; + } + return JS_FALSE; +} + +/*** + * + * + * + * The id of the parent item. + * + * + * The text for the root item. + * + * + * Index of the image for normal items. The default is -1 which means don't use. + * + * + * Index of the image for selected items. The default is -1 which means don't use. + * + * + * + * + * Inserts a new item as the first child of the parent item, returns a new item id. + * The Image and SelectedImage parameters are an index within the normal image list + * specifying the image to use for unselected and selected items, respectively. + * If Image > -1 and SelectedImage is -1, the same image is used for both selected + * and unselected items. + * + * + */ +JSBool TreeCtrl::prependItem(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxTreeCtrl *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + if (argc > 5 ) + argc = 5; + + ObjectTreeData *data = NULL; + int selImage = -1; + int image = -1; + + switch(argc) + { + case 5: + data = new ObjectTreeData(cx, argv[4]); + // Fall through + case 4: + if ( ! FromJS(cx, argv[3], selImage) ) + break; + // Fall through + case 3: + if ( ! FromJS(cx, argv[2], image) ) + break; + // Fall through + default: + + wxString text; + FromJS(cx, argv[1], text); + + wxTreeItemId *parent = TreeItemId::GetPrivate(cx, argv[0]); + if ( parent == NULL ) + break; + + wxTreeItemId newId = p->PrependItem(*parent, text, image, selImage, data); + *rval = TreeItemId::CreateObject(cx, new wxTreeItemId(newId)); + return JS_TRUE; + } + return JS_FALSE; +} + +/*** + * + * + * + * The id of the parent item. + * + * + * The id of the item to use as previous sibling. + * + * + * The text for the root item. + * + * + * Index of the image for normal items. The default is -1 which means don't use. + * + * + * Index of the image for selected items. The default is -1 which means don't use. + * + * + * + * + * The id of the parent item. + * + * + * The position of the item to use as previous sibling. + * + * + * The text for the root item. + * + * + * Index of the image for normal items. The default is -1 which means don't use. + * + * + * Index of the image for selected items. The default is -1 which means don't use. + * + * + * + * Inserts an item after a given one (Prev) or before one identified by its position (Pos). + * The Image and SelectedImage parameters are an index within the normal image list + * specifying the image to use for unselected and selected items, respectively. + * If Image > -1 and SelectedImage is -1, the same image is used for both selected + * and unselected items. + * + * + */ +JSBool TreeCtrl::insertItem(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxTreeCtrl *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + if (argc > 6 ) + argc = 6; + + ObjectTreeData *data = NULL; + int selImage = -1; + int image = -1; + + switch(argc) + { + case 6: + data = new ObjectTreeData(cx, argv[5]); + // Fall through + case 5: + if ( ! FromJS(cx, argv[4], selImage) ) + break; + // Fall through + case 4: + if ( ! FromJS(cx, argv[3], image) ) + break; + // Fall through + default: + + wxString text; + FromJS(cx, argv[2], text); + + wxTreeItemId *parent = TreeItemId::GetPrivate(cx, argv[0]); + if ( parent == NULL ) + break; + + wxTreeItemId newId; + if ( JSVAL_IS_INT(argv[1]) ) + { + int pos; + FromJS(cx, argv[1], pos); + newId = p->InsertItem(*parent, pos, text, image, selImage, data); + } + else + { + wxTreeItemId *prevId = TreeItemId::GetPrivate(cx, argv[1]); + if ( prevId == NULL ) + break; + newId = p->InsertItem(*parent, prevId, text, image, selImage, data); + } + *rval = TreeItemId::CreateObject(cx, new wxTreeItemId(newId)); + return JS_TRUE; + } + return JS_FALSE; +} + +/*** + * + * + * + * The id of the item + * + * + * + * Deletes the item. + * You receive an event as @wxTreeCtrl#onDeleteItem. + * + * + */ +JSBool TreeCtrl::deleteItem(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxTreeCtrl *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + wxTreeItemId *id = TreeItemId::GetPrivate(cx, argv[0]); + if ( id != NULL ) + { + p->Delete(*id); + return JS_TRUE; + } + return JS_FALSE; +} + +/*** + * + * + * + * The id of the item + * + * + * + * Deletes all the children of the item. You don't get an event as @wxTreeCtrl#onDeleteItem + * event for the deleted items. + * + * + */ +JSBool TreeCtrl::deleteChildren(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxTreeCtrl *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + wxTreeItemId *id = TreeItemId::GetPrivate(cx, argv[0]); + if ( id != NULL ) + { + p->DeleteChildren(*id); + return JS_TRUE; + } + return JS_FALSE; +} + +/*** + * + * + * + * Deletes all items. You don't get an @wxTreeCtrl#onDeleteItem + * event for the deleted items. + * + * + */ +JSBool TreeCtrl::deleteAllItems(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxTreeCtrl *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + p->DeleteAllItems(); + return JS_TRUE; +} + +/*** + * + * + * + * The id of the item + * + * + * + * Expands the item. + * See @wxTreeItem @wxTreeItem#expanded property + * + * + */ +JSBool TreeCtrl::expand(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxTreeCtrl *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + wxTreeItemId *id = TreeItemId::GetPrivate(cx, argv[0]); + if ( id != NULL ) + { + p->Expand(*id); + return JS_TRUE; + } + return JS_FALSE; +} + +/*** + * + * + * + * The id of the item + * + * + * + * Collapses the item. + * See @wxTreeItem @wxTreeItem#expanded property + * + * + */ +JSBool TreeCtrl::collapse(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxTreeCtrl *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + wxTreeItemId *id = TreeItemId::GetPrivate(cx, argv[0]); + if ( id != NULL ) + { + p->Collapse(*id); + return JS_TRUE; + } + return JS_FALSE; +} + +/*** + * + * + * + * The id of the item + * + * + * + * Collapses the item and removes the children. + * + * + */ +JSBool TreeCtrl::collapseAndReset(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxTreeCtrl *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + wxTreeItemId *id = TreeItemId::GetPrivate(cx, argv[0]); + if ( id != NULL ) + { + p->CollapseAndReset(*id); + return JS_TRUE; + } + return JS_FALSE; +} + +/*** + * + * + * + * The id of the item + * + * + * + * Toggles the given item between collapsed and expanded states. + * See @wxTreeItem @wxTreeItem#expanded property + * + * + */ +JSBool TreeCtrl::toggle(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxTreeCtrl *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + wxTreeItemId *id = TreeItemId::GetPrivate(cx, argv[0]); + if ( id != NULL ) + { + p->Toggle(*id); + return JS_TRUE; + } + return JS_FALSE; +} + +/*** + * + * + * + * Unselects the selected item. + * See @wxTreeItem @wxTreeItem#selected property + * + * + */ +JSBool TreeCtrl::unselect(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxTreeCtrl *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + p->Unselect(); + return JS_TRUE; +} + +/*** + * + * + * + * Unselects all selected items. + * + * + */ +JSBool TreeCtrl::unselectAll(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxTreeCtrl *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + p->UnselectAll(); + return JS_TRUE; +} + +/*** + * + * + * + * The id of the item + * + * + * + * Selects the given item. + * See @wxTreeItem @wxTreeItem#selected property + * + * + */ +JSBool TreeCtrl::selectItem(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxTreeCtrl *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + wxTreeItemId *id = TreeItemId::GetPrivate(cx, argv[0]); + if ( id != NULL ) + { + p->SelectItem(*id); + return JS_TRUE; + } + return JS_FALSE; +} + +/*** + * + * + * + * The id of the item + * + * + * + * Make sure the item is visible (expanding the parent item and/or + * scrolling to this item if necessary) + * See @wxTreeItem @wxTreeItem#visible property + * + * + */ +JSBool TreeCtrl::ensureVisible(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxTreeCtrl *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + wxTreeItemId *id = TreeItemId::GetPrivate(cx, argv[0]); + if ( id != NULL ) + { + p->EnsureVisible(*id); + return JS_TRUE; + } + return JS_FALSE; +} + +/*** + * + * + * + * The id of the item + * + * + * + * Scroll to the item (but don't expand its parent) + * + * + */ +JSBool TreeCtrl::scrollTo(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxTreeCtrl *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + wxTreeItemId *id = TreeItemId::GetPrivate(cx, argv[0]); + if ( id != NULL ) + { + p->ScrollTo(*id); + return JS_TRUE; + } + return JS_FALSE; +} + +/*** + * + * + * + * The id of the item + * + * + * + * Start editing the label of the item. The item will be selected when + * it hadn't been before. + * + * + */ +JSBool TreeCtrl::editLabel(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxTreeCtrl *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + wxTreeItemId *id = TreeItemId::GetPrivate(cx, argv[0]); + if ( id != NULL ) + { + p->EditLabel(*id); + return JS_TRUE; + } + return JS_FALSE; +} + +/*** + * + * + * + * The id of the item + * + * + * Accept (false) or discard(true) the changes to the item label. Default is false. + * + * + * + * Ends editing the label of the item. Only on Windows + * + * + */ +JSBool TreeCtrl::endEditLabel(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxTreeCtrl *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + #ifdef __WXMSW__ + wxTreeItemId *id = TreeItemId::GetPrivate(cx, argv[0]); + bool discard = false; + if ( id != NULL ) + { + p->EditLabel(*id); + if ( argc > 1 ) + { + if ( ! FromJS(cx, argv[1], discard) ) + return JS_FALSE; + } + } + p->EndEditLabel(*id, discard); + #endif + + return JS_TRUE; +} + +/*** + * + * + * + * The id of the item + * + * + * + * Sorts the children of the given item using the function of @wxTreeCtrl#onCompareItems. + * When no function is set, the items are sorted alphabetically. + * + * + */ +JSBool TreeCtrl::sortChildren(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxTreeCtrl *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + wxTreeItemId *id = TreeItemId::GetPrivate(cx, argv[0]); + if ( id != NULL ) + { + p->SortChildren(*id); + return JS_TRUE; + } + return JS_FALSE; +} + +/*** + * + * + * + * The position to test. + * + * + * + * Determines which item (if any) is at the specified point. + * + * + */ +JSBool TreeCtrl::hitTest(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxTreeCtrl *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + wxPoint *pt = Point::GetPrivate(cx, argv[0]); + if ( pt != NULL ) + { + int flags; + wxTreeItemId item = p->HitTest(*pt, flags); + + *rval = TreeHitTest::CreateObject(cx, new wxTreeHitTest(item, flags)); + return JS_TRUE; + } + + return JS_FALSE; +} + +/*** + * + * + * This event is triggered when the user starts dragging with the left mouse button. + * The event can be vetoed using @wxNotifyEvent#veto or @wxNotifyEvent#allowed. + * The function receives a @wxTreeEvent as argument. + * + * + * This event is triggered when the user starts dragging with the right mouse button. + * The event can be vetoed using @wxNotifyEvent#veto or @wxNotifyEvent#allowed. + * The function receives a @wxTreeEvent as argument. + * + * + * This event is triggered when the user starts editing an item. + * The event can be vetoed using @wxNotifyEvent#veto or @wxNotifyEvent#allowed. + * The function receives a @wxTreeEvent as argument. + * + * + * This event is triggered when the user ends editing the label. + * The function receives a @wxTreeEvent as argument. + * The event can be vetoed using @wxNotifyEvent#veto or @wxNotifyEvent#allowed. + * + * + * This event is triggered when an item is deleted. + * See @wxTreeCtrl#deleteItem. + * The function receives a @wxTreeEvent as argument. + * + * + * This event is triggered when the application needs information. + * The function receives a @wxTreeEvent as argument. + * + * + * This event is triggered when information is supplied. + * The function receives a @wxTreeEvent as argument. + * + * + * This event is triggered when an item is expanded. + * The function receives a @wxTreeEvent as argument. + * + * + * This event is triggered when an item is about to expanded. + * The event can be vetoed using @wxNotifyEvent#veto or @wxNotifyEvent#allowed. + * The function receives a @wxTreeEvent as argument. + * + * + * This event is triggered when an item is collapsed. + * The function receives a @wxTreeEvent as argument. + * + * + * This event is triggered when an item is about to collapse. + * The event can be vetoed using @wxNotifyEvent#veto or @wxNotifyEvent#allowed. + * The function receives a @wxTreeEvent as argument. + * + * + * This event is triggered when the selection is changed. + * The function receives a @wxTreeEvent as argument. + * + * + * This event is triggered when the selection is about to change. + * The function receives a @wxTreeEvent as argument. + * + * + * This event is triggered when a key is pressed. + * The function receives a @wxTreeEvent as argument. + * + * + * This event is triggered when an item is activated. + * The function receives a @wxTreeEvent as argument. + * + * + * This event is triggered when an item is clicked with the right mousebutton. + * The function receives a @wxTreeEvent as argument. + * + * + * This event is triggered when an item is clicked with the middle mousebutton. + * The function receives a @wxTreeEvent as argument. + * + * + * This event is triggered when the user releases the mouse button. + * The function receives a @wxTreeEvent as argument. + * + * + */ +WXJS_INIT_EVENT_MAP(wxTreeCtrl) +const wxString WXJS_TREE_BEGIN_DRAG = wxT("onBeginDrag"); +const wxString WXJS_TREE_BEGIN_RDRAG = wxT("onBeginRDrag"); +const wxString WXJS_TREE_BEGIN_LABEL_EDIT = wxT("onBeginLabelEdit"); +const wxString WXJS_TREE_END_LABEL_EDIT = wxT("onEndLabelEdit"); +const wxString WXJS_TREE_DELETE_ITEM = wxT("onDeleteItem"); +const wxString WXJS_TREE_GET_INFO = wxT("onGetInfo"); +const wxString WXJS_TREE_SET_INFO = wxT("onSetInfo"); +const wxString WXJS_TREE_ITEM_EXPANDED = wxT("onItemExpanded"); +const wxString WXJS_TREE_ITEM_EXPANDING = wxT("onItemExpanding"); +const wxString WXJS_TREE_ITEM_COLLAPSED = wxT("onItemCollapsed"); +const wxString WXJS_TREE_ITEM_COLLAPSING = wxT("onItemCollapsing"); +const wxString WXJS_TREE_SEL_CHANGED = wxT("onSelChanged"); +const wxString WXJS_TREE_SEL_CHANGING = wxT("onSelChanging"); +const wxString WXJS_TREE_KEY_DOWN = wxT("onKeyDown"); +const wxString WXJS_TREE_ITEM_ACTIVATED = wxT("onItemActivated"); +const wxString WXJS_TREE_ITEM_RIGHT_CLICK = wxT("onItemRightClick"); +const wxString WXJS_TREE_ITEM_MIDDLE_CLICK = wxT("onItemMiddleClick"); +const wxString WXJS_TREE_END_DRAG = wxT("onEndDrag"); + +void TreeCtrlEventHandler::onBeginDrag(wxTreeEvent &event) +{ + PrivTreeEvent::Fire(event, WXJS_TREE_BEGIN_DRAG); +} + +void TreeCtrlEventHandler::onBeginRDrag(wxTreeEvent &event) +{ + PrivTreeEvent::Fire(event, WXJS_TREE_BEGIN_RDRAG); +} + +void TreeCtrlEventHandler::onBeginLabelEdit(wxTreeEvent &event) +{ + PrivTreeEvent::Fire(event, WXJS_TREE_BEGIN_LABEL_EDIT); +} + +void TreeCtrlEventHandler::onEndLabelEdit(wxTreeEvent &event) +{ + PrivTreeEvent::Fire(event, WXJS_TREE_END_LABEL_EDIT); +} + +void TreeCtrlEventHandler::onDeleteItem(wxTreeEvent &event) +{ + PrivTreeEvent::Fire(event, WXJS_TREE_DELETE_ITEM); +} + +void TreeCtrlEventHandler::onGetInfo(wxTreeEvent &event) +{ + PrivTreeEvent::Fire(event, WXJS_TREE_GET_INFO); +} + +void TreeCtrlEventHandler::onSetInfo(wxTreeEvent &event) +{ + PrivTreeEvent::Fire(event, WXJS_TREE_SET_INFO); +} + +void TreeCtrlEventHandler::onItemExpanded(wxTreeEvent &event) +{ + PrivTreeEvent::Fire(event, WXJS_TREE_ITEM_EXPANDED); +} + +void TreeCtrlEventHandler::onItemExpanding(wxTreeEvent &event) +{ + PrivTreeEvent::Fire(event, WXJS_TREE_ITEM_EXPANDING); +} + +void TreeCtrlEventHandler::onItemCollapsed(wxTreeEvent &event) +{ + PrivTreeEvent::Fire(event, WXJS_TREE_ITEM_COLLAPSED); +} + +void TreeCtrlEventHandler::onItemCollapsing(wxTreeEvent &event) +{ + PrivTreeEvent::Fire(event, WXJS_TREE_ITEM_COLLAPSING); +} + +void TreeCtrlEventHandler::onSelChanged(wxTreeEvent &event) +{ + PrivTreeEvent::Fire(event, WXJS_TREE_SEL_CHANGED); +} + +void TreeCtrlEventHandler::onSelChanging(wxTreeEvent &event) +{ + PrivTreeEvent::Fire(event, WXJS_TREE_SEL_CHANGING); +} + +void TreeCtrlEventHandler::onKeyDown(wxTreeEvent &event) +{ + PrivTreeEvent::Fire(event, WXJS_TREE_KEY_DOWN); +} + +void TreeCtrlEventHandler::onItemActivated(wxTreeEvent &event) +{ + PrivTreeEvent::Fire(event, WXJS_TREE_ITEM_ACTIVATED); +} + +void TreeCtrlEventHandler::onItemRightClick(wxTreeEvent &event) +{ + PrivTreeEvent::Fire(event, WXJS_TREE_ITEM_RIGHT_CLICK); +} + +void TreeCtrlEventHandler::onItemMiddleClick(wxTreeEvent &event) +{ + PrivTreeEvent::Fire(event, WXJS_TREE_ITEM_MIDDLE_CLICK); +} + +void TreeCtrlEventHandler::onEndDrag(wxTreeEvent &event) +{ + PrivTreeEvent::Fire(event, WXJS_TREE_END_DRAG); +} + +void TreeCtrlEventHandler::ConnectBeginDrag(wxTreeCtrl *p, bool connect) +{ + if ( connect ) + { + p->Connect(wxEVT_COMMAND_TREE_BEGIN_DRAG, + wxTreeEventHandler(onBeginDrag)); + } + else + { + p->Disconnect(wxEVT_COMMAND_TREE_BEGIN_DRAG, + wxTreeEventHandler(onBeginDrag)); + } +} + +void TreeCtrlEventHandler::ConnectBeginRDrag(wxTreeCtrl *p, bool connect) +{ + if ( connect ) + { + p->Connect(wxEVT_COMMAND_TREE_BEGIN_RDRAG, + wxTreeEventHandler(onBeginRDrag)); + } + else + { + p->Disconnect(wxEVT_COMMAND_TREE_BEGIN_RDRAG, + wxTreeEventHandler(onBeginRDrag)); + } +} + +void TreeCtrlEventHandler::ConnectBeginLabelEdit(wxTreeCtrl *p, bool connect) +{ + if ( connect ) + { + p->Connect(wxEVT_COMMAND_TREE_BEGIN_LABEL_EDIT, + wxTreeEventHandler(onBeginLabelEdit)); + } + else + { + p->Disconnect(wxEVT_COMMAND_TREE_BEGIN_LABEL_EDIT, + wxTreeEventHandler(onBeginLabelEdit)); + } +} + +void TreeCtrlEventHandler::ConnectEndLabelEdit(wxTreeCtrl *p, bool connect) +{ + if ( connect ) + { + p->Connect(wxEVT_COMMAND_TREE_END_LABEL_EDIT, + wxTreeEventHandler(onEndLabelEdit)); + } + else + { + p->Disconnect(wxEVT_COMMAND_TREE_END_LABEL_EDIT, + wxTreeEventHandler(onEndLabelEdit)); + } +} + +void TreeCtrlEventHandler::ConnectDeleteItem(wxTreeCtrl *p, bool connect) +{ + if ( connect ) + { + p->Connect(wxEVT_COMMAND_TREE_DELETE_ITEM, + wxTreeEventHandler(onDeleteItem)); + } + else + { + p->Disconnect(wxEVT_COMMAND_TREE_DELETE_ITEM, + wxTreeEventHandler(onDeleteItem)); + } +} + +void TreeCtrlEventHandler::ConnectGetInfo(wxTreeCtrl *p, bool connect) +{ + if ( connect ) + { + p->Connect(wxEVT_COMMAND_TREE_GET_INFO, + wxTreeEventHandler(onGetInfo)); + } + else + { + p->Disconnect(wxEVT_COMMAND_TREE_GET_INFO, + wxTreeEventHandler(onGetInfo)); + } +} + +void TreeCtrlEventHandler::ConnectSetInfo(wxTreeCtrl *p, bool connect) +{ + if ( connect ) + { + p->Connect(wxEVT_COMMAND_TREE_SET_INFO, + wxTreeEventHandler(onSetInfo)); + } + else + { + p->Disconnect(wxEVT_COMMAND_TREE_SET_INFO, + wxTreeEventHandler(onSetInfo)); + } +} + +void TreeCtrlEventHandler::ConnectItemExpanded(wxTreeCtrl *p, bool connect) +{ + if ( connect ) + { + p->Connect(wxEVT_COMMAND_TREE_ITEM_EXPANDED, + wxTreeEventHandler(onItemExpanded)); + } + else + { + p->Disconnect(wxEVT_COMMAND_TREE_ITEM_EXPANDED, + wxTreeEventHandler(onItemExpanded)); + } +} + +void TreeCtrlEventHandler::ConnectItemExpanding(wxTreeCtrl *p, bool connect) +{ + if ( connect ) + { + p->Connect(wxEVT_COMMAND_TREE_ITEM_EXPANDING, + wxTreeEventHandler(onItemExpanding)); + } + else + { + p->Disconnect(wxEVT_COMMAND_TREE_ITEM_EXPANDING, + wxTreeEventHandler(onItemExpanding)); + } +} + +void TreeCtrlEventHandler::ConnectItemCollapsed(wxTreeCtrl *p, bool connect) +{ + if ( connect ) + { + p->Connect(wxEVT_COMMAND_TREE_ITEM_COLLAPSED, + wxTreeEventHandler(onItemCollapsed)); + } + else + { + p->Disconnect(wxEVT_COMMAND_TREE_ITEM_COLLAPSED, + wxTreeEventHandler(onItemCollapsed)); + } +} + +void TreeCtrlEventHandler::ConnectItemCollapsing(wxTreeCtrl *p, bool connect) +{ + if ( connect ) + { + p->Connect(wxEVT_COMMAND_TREE_ITEM_COLLAPSING, + wxTreeEventHandler(onItemCollapsing)); + } + else + { + p->Disconnect(wxEVT_COMMAND_TREE_ITEM_COLLAPSING, + wxTreeEventHandler(onItemCollapsing)); + } +} + +void TreeCtrlEventHandler::ConnectSelChanged(wxTreeCtrl *p, bool connect) +{ + if ( connect ) + { + p->Connect(wxEVT_COMMAND_TREE_SEL_CHANGED, + wxTreeEventHandler(onSelChanged)); + } + else + { + p->Disconnect(wxEVT_COMMAND_TREE_SEL_CHANGED, + wxTreeEventHandler(onSelChanged)); + } +} + +void TreeCtrlEventHandler::ConnectSelChanging(wxTreeCtrl *p, bool connect) +{ + if ( connect ) + { + p->Connect(wxEVT_COMMAND_TREE_SEL_CHANGING, + wxTreeEventHandler(onSelChanging)); + } + else + { + p->Disconnect(wxEVT_COMMAND_TREE_SEL_CHANGING, + wxTreeEventHandler(onSelChanging)); + } +} + +void TreeCtrlEventHandler::ConnectKeyDown(wxTreeCtrl *p, bool connect) +{ + if ( connect ) + { + p->Connect(wxEVT_COMMAND_TREE_KEY_DOWN, + wxTreeEventHandler(onKeyDown)); + } + else + { + p->Disconnect(wxEVT_COMMAND_TREE_KEY_DOWN, + wxTreeEventHandler(onKeyDown)); + } +} + +void TreeCtrlEventHandler::ConnectItemActivated(wxTreeCtrl *p, bool connect) +{ + if ( connect ) + { + p->Connect(wxEVT_COMMAND_TREE_ITEM_ACTIVATED, + wxTreeEventHandler(onItemActivated)); + } + else + { + p->Disconnect(wxEVT_COMMAND_TREE_ITEM_ACTIVATED, + wxTreeEventHandler(onItemActivated)); + }} + +void TreeCtrlEventHandler::ConnectItemRightClick(wxTreeCtrl *p, bool connect) +{ + if ( connect ) + { + p->Connect(wxEVT_COMMAND_TREE_ITEM_RIGHT_CLICK, + wxTreeEventHandler(onItemRightClick)); + } + else + { + p->Disconnect(wxEVT_COMMAND_TREE_ITEM_RIGHT_CLICK, + wxTreeEventHandler(onItemRightClick)); + } +} + +void TreeCtrlEventHandler::ConnectItemMiddleClick(wxTreeCtrl *p, bool connect) +{ + if ( connect ) + { + p->Connect(wxEVT_COMMAND_TREE_ITEM_MIDDLE_CLICK, + wxTreeEventHandler(onItemMiddleClick)); + } + else + { + p->Disconnect(wxEVT_COMMAND_TREE_ITEM_MIDDLE_CLICK, + wxTreeEventHandler(onItemMiddleClick)); + } +} + +void TreeCtrlEventHandler::ConnectEndDrag(wxTreeCtrl *p, bool connect) +{ + if ( connect ) + { + p->Connect(wxEVT_COMMAND_TREE_END_DRAG, + wxTreeEventHandler(onEndDrag)); + } + else + { + p->Disconnect(wxEVT_COMMAND_TREE_END_DRAG, + wxTreeEventHandler(onEndDrag)); + } +} + +void TreeCtrlEventHandler::InitConnectEventMap() +{ + AddConnector(WXJS_TREE_BEGIN_DRAG, ConnectBeginDrag); + AddConnector(WXJS_TREE_BEGIN_RDRAG, ConnectBeginRDrag); + AddConnector(WXJS_TREE_BEGIN_LABEL_EDIT, ConnectBeginLabelEdit); + AddConnector(WXJS_TREE_END_LABEL_EDIT, ConnectEndLabelEdit); + AddConnector(WXJS_TREE_DELETE_ITEM, ConnectDeleteItem); + AddConnector(WXJS_TREE_GET_INFO, ConnectGetInfo); + AddConnector(WXJS_TREE_SET_INFO, ConnectSetInfo); + AddConnector(WXJS_TREE_ITEM_EXPANDED, ConnectItemExpanded); + AddConnector(WXJS_TREE_ITEM_EXPANDING, ConnectItemExpanding); + AddConnector(WXJS_TREE_ITEM_COLLAPSED, ConnectItemCollapsed); + AddConnector(WXJS_TREE_ITEM_COLLAPSING, ConnectItemCollapsing); + AddConnector(WXJS_TREE_SEL_CHANGED, ConnectSelChanged); + AddConnector(WXJS_TREE_SEL_CHANGING, ConnectSelChanging); + AddConnector(WXJS_TREE_KEY_DOWN, ConnectKeyDown); + AddConnector(WXJS_TREE_ITEM_ACTIVATED, ConnectItemActivated); + AddConnector(WXJS_TREE_ITEM_RIGHT_CLICK, ConnectItemRightClick); + AddConnector(WXJS_TREE_ITEM_MIDDLE_CLICK, ConnectItemMiddleClick); + AddConnector(WXJS_TREE_END_DRAG, ConnectEndDrag); +} Property changes on: ps/trunk/source/tools/atlas/wxJS/gui/control/treectrl.cpp ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/gui/control/bmpbtn.h =================================================================== --- ps/trunk/source/tools/atlas/wxJS/gui/control/bmpbtn.h (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/gui/control/bmpbtn.h (revision 5154) @@ -0,0 +1,80 @@ +/* + * wxJavaScript - bmpbtn.h + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: bmpbtn.h 678 2007-04-19 20:12:31Z fbraem $ + */ +#ifndef _WXJSBitmapButton_H +#define _WXJSBitmapButton_H + +namespace wxjs +{ + namespace gui + { + class BitmapButton : public ApiWrapper + { + public: + + static bool AddProperty(wxBitmapButton *p, + JSContext *cx, + JSObject *obj, + const wxString &prop, + jsval *vp); + static bool DeleteProperty(wxBitmapButton *p, + JSContext* cx, + JSObject* obj, + const wxString &prop); + static bool GetProperty(wxBitmapButton *p, + JSContext *cx, + JSObject *obj, + int id, + jsval *vp); + static bool SetProperty(wxBitmapButton *p, + JSContext *cx, + JSObject *obj, + int id, + jsval *vp); + + static wxBitmapButton* Construct(JSContext *cx, + JSObject *obj, + uintN argc, + jsval *argv, + bool constructing); + + WXJS_DECLARE_PROPERTY_MAP() + + /** + * Property Ids. + */ + enum + { + P_BITMAP_DISABLED + , P_BITMAP_FOCUS + , P_BITMAP_SELECTED + , P_BITMAP_LABEL + }; + + WXJS_DECLARE_METHOD_MAP() + WXJS_DECLARE_METHOD(create) + }; + }; // namespace gui +}; //namespace wxjs +#endif //_WXJSBitmapButton_H Property changes on: ps/trunk/source/tools/atlas/wxJS/gui/control/bmpbtn.h ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/gui/control/toolbar.cpp =================================================================== --- ps/trunk/source/tools/atlas/wxJS/gui/control/toolbar.cpp (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/gui/control/toolbar.cpp (revision 5154) @@ -0,0 +1,1376 @@ +#include "precompiled.h" + +/* + * wxJavaScript - toolbar.cpp + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: toolbar.cpp 708 2007-05-14 15:30:45Z fbraem $ + */ + +#include +#ifndef WX_PRECOMP + #include +#endif + +#include + +#include "../../common/main.h" + +#include "../misc/app.h" + +#include "../event/jsevent.h" + +#include "../event/command.h" + +#include "window.h" +#include "control.h" +#include "toolbar.h" +#include "tbartool.h" + +#include "../misc/point.h" +#include "../misc/bitmap.h" +#include "../misc/size.h" +#include "../errors.h" + +using namespace wxjs; +using namespace wxjs::gui; + +bool ToolBar::DoDeleteTool(size_t pos, wxToolBarToolBase *tool) +{ + if ( ! tool->IsControl() ) + { + ToolBarToolData *data + = dynamic_cast(tool->GetClientData()); + if ( data ) + { + delete data; + } + } + return wxToolBar::DoDeleteTool(pos, tool); +} + +/*** + * control/toolbar + * gui + * + * A toolbar.

+ * Event handling is done as follows: + * When the tool has a function set as @wxToolBarTool#onTool, then that + * function will be executed. + * When a menu exists with the same id of the selected tool, the menu action is executed. + * When there is no menu, the action associated with the toolbar is executed. + * See @wxToolBar#actions and @wxMenu#actions + *

+ * See also @wxFrame#createToolBar + *
+ */ +WXJS_INIT_CLASS(ToolBar, "wxToolBar", 2) + +/*** + * + * + * An array containing the function callbacks. A function will be called when a tool is selected. + * Use the id as index of the array. + * + * + * Gets/Sets the left/right and top/bottom margins, which are also used for inter-toolspacing. + * + * + * Gets/Sets the size of bitmap that the toolbar expects to have. + * The default bitmap size is 16 by 15 pixels. + * + * + * Gets/Sets the value used for spacing tools. The default value is 1. + * The packing is used for spacing in the vertical direction if the toolbar is horizontal, + * and for spacing in the horizontal direction if the toolbar is vertical. + * + * + * Gets/Sets the separator size. The default value is 5. + * + * + * Gets the size of a whole button, which is usually larger than a tool bitmap + * because of added 3D effects. + * + * + */ +WXJS_BEGIN_PROPERTY_MAP(ToolBar) + WXJS_PROPERTY(P_TOOL_SIZE, "margins") + WXJS_READONLY_PROPERTY(P_TOOL_SIZE, "toolSize") + WXJS_PROPERTY(P_TOOL_BITMAP_SIZE, "toolBitmapSize") + WXJS_PROPERTY(P_TOOL_PACKING, "toolPacking") + WXJS_PROPERTY(P_TOOL_SEPARATION, "toolSeparation") +WXJS_END_PROPERTY_MAP() + +bool ToolBar::GetProperty(wxToolBar* p, + JSContext* cx, + JSObject* WXUNUSED(obj), + int id, + jsval* vp) +{ + switch (id) + { + case P_TOOL_SIZE: + { + const wxSize &size = p->GetToolSize(); + *vp = Size::CreateObject(cx, new wxSize(size)); + break; + } + case P_TOOL_BITMAP_SIZE: + { + const wxSize &size = p->GetToolBitmapSize(); + *vp = Size::CreateObject(cx, new wxSize(size)); + break; + } + case P_MARGINS: + *vp = Size::CreateObject(cx, new wxSize(p->GetMargins())); + break; + case P_TOOL_PACKING: + *vp = ToJS(cx, p->GetToolPacking()); + break; + case P_TOOL_SEPARATION: + *vp = ToJS(cx, p->GetToolSeparation()); + break; + } + return true; +} + +bool ToolBar::SetProperty(wxToolBar* p, + JSContext* cx, + JSObject* WXUNUSED(obj), + int id, + jsval *vp) +{ + switch (id) + { + case P_TOOL_BITMAP_SIZE: + { + wxSize *size = Size::GetPrivate(cx, *vp); + if ( size != NULL ) + p->SetToolBitmapSize(*size); + break; + } + case P_MARGINS: + { + wxSize *size = Size::GetPrivate(cx, *vp); + if ( size != NULL ) + p->SetMargins(size->GetWidth(), size->GetHeight()); + break; + } + case P_TOOL_PACKING: + { + int pack; + if ( FromJS(cx, *vp, pack) ) + p->SetToolPacking(pack); + break; + } + case P_TOOL_SEPARATION: + { + int size; + if ( FromJS(cx, *vp, size) ) + p->SetToolSeparation(size); + break; + } + } + return true; +} + +/*** + * + * + * + * Gives the toolbar a flat look ('coolbar' or 'flatbar' style). + * Windows 95 and GTK 1.2 only. + * + * + * Makes the toolbar floatable and dockable. GTK only. + * + * Specifies horizontal layout. + * + * Specifies vertical layout (not available for the GTK and Windows + * 95 toolbar). + * + * + * Gives wxToolBarSimple a mild 3D look to its buttons. + * + * + * Show the text in the toolbar buttons; by default only icons are shown. + * + * + * Specifies no icons in the toolbar buttons; by default they are shown. + * + * + * Specifies no divider above the toolbar; by default it is shown. + * Windows only. + * + * + * Specifies no alignment with the parent window. Windows only. + * + * + * + */ +WXJS_BEGIN_CONSTANT_MAP(ToolBar) + WXJS_CONSTANT(wxTB_, FLAT) + WXJS_CONSTANT(wxTB_, DOCKABLE) + WXJS_CONSTANT(wxTB_, HORIZONTAL) + WXJS_CONSTANT(wxTB_, VERTICAL) + WXJS_CONSTANT(wxTB_, 3DBUTTONS) + WXJS_CONSTANT(wxTB_, TEXT) + WXJS_CONSTANT(wxTB_, NOICONS) + WXJS_CONSTANT(wxTB_, NODIVIDER) + WXJS_CONSTANT(wxTB_, NOALIGN) +WXJS_END_CONSTANT_MAP() + +/*** + * + * + * + * + * The parent of wxToolBar. + * + * + * An window identifier. Use -1 when you don't need it. + * + * + * The position of the ToolBar control on the given parent. + * + * + * The size of the ToolBar control. + * + * + * The wxToolBar style. + * + * + * + * Constructs a new wxToolBar object. + * + * + */ +wxToolBar* ToolBar::Construct(JSContext *cx, + JSObject *obj, + uintN argc, + jsval *argv, + bool WXUNUSED(constructing)) +{ + ToolBar *p = new ToolBar(); + SetPrivate(cx, obj, p); + + if ( argc > 0 ) + { + jsval rval; + create(cx, obj, argc, argv, &rval); + } + return p; +} + +WXJS_BEGIN_METHOD_MAP(ToolBar) + WXJS_METHOD("create", create, 2) + WXJS_METHOD("addControl", addControl, 1) + WXJS_METHOD("addSeparator", addSeparator, 0) + WXJS_METHOD("addTool", addTool, 3) + WXJS_METHOD("addCheckTool", addCheckTool, 4) + WXJS_METHOD("addRadioTool", addRadioTool, 4) + WXJS_METHOD("deleteTool", deleteTool, 1) + WXJS_METHOD("deleteToolByPos", deleteToolByPos, 1) + WXJS_METHOD("enableTool", enableTool, 2) + WXJS_METHOD("findControl", findControl, 1) + WXJS_METHOD("getToolEnabled", getToolEnabled, 1) + WXJS_METHOD("getToolLongHelp", getToolLongHelp, 1) + WXJS_METHOD("getToolShortHelp", getToolShortHelp, 1) + WXJS_METHOD("getToolState", getToolState, 1) + WXJS_METHOD("insertControl", insertControl, 2) + WXJS_METHOD("insertSeparator", insertSeparator, 1) + WXJS_METHOD("insertTool", insertTool, 3) + WXJS_METHOD("realize", realize, 0) + WXJS_METHOD("setToolLongHelp", setToolLongHelp, 2) + WXJS_METHOD("setToolShortHelp", setToolShortHelp, 2) + WXJS_METHOD("toggleTool", toggleTool, 2) +WXJS_END_METHOD_MAP() + +/*** + * + * + * + * The parent of wxToolBar. + * + * + * An window identifier. Use -1 when you don't need it. + * + * + * The position of the ToolBar control on the given parent. + * + * + * The size of the ToolBar control. + * + * + * The wxToolBar style. + * + * + * + * Constructs a new wxToolBar object. + * + * + */ +JSBool ToolBar::create(JSContext *cx, + JSObject *obj, + uintN argc, + jsval *argv, + jsval *rval) +{ + wxToolBar *p = GetPrivate(cx, obj); + *rval = JSVAL_FALSE; + + if ( argc > 5 ) + argc = 5; + + int style = wxTB_HORIZONTAL | wxNO_BORDER; + const wxPoint *pt = &wxDefaultPosition; + const wxSize *size = &wxDefaultSize; + + switch(argc) + { + case 5: + if ( ! FromJS(cx, argv[4], style) ) + { + JS_ReportError(cx, WXJS_INVALID_ARG_TYPE, 5, "Integer"); + return JS_FALSE; + } + // Fall through + case 4: + size = Size::GetPrivate(cx, argv[3]); + if ( size == NULL ) + { + JS_ReportError(cx, WXJS_INVALID_ARG_TYPE, 4, "wxSize"); + return JS_FALSE; + } + // Fall through + case 3: + pt = Point::GetPrivate(cx, argv[2]); + if ( pt == NULL ) + { + JS_ReportError(cx, WXJS_INVALID_ARG_TYPE, 4, "wxPoint"); + return JS_FALSE; + } + // Fall through + default: + + int id; + if ( ! FromJS(cx, argv[1], id) ) + { + JS_ReportError(cx, WXJS_INVALID_ARG_TYPE, 2, "Integer"); + return JS_FALSE; + } + + wxWindow *parent = Window::GetPrivate(cx, argv[0]); + if ( parent == NULL ) + { + JS_ReportError(cx, WXJS_NO_PARENT_ERROR, GetClass()->name); + return JS_FALSE; + } + + JavaScriptClientData *clntParent = + dynamic_cast(parent->GetClientObject()); + if ( clntParent == NULL ) + { + JS_ReportError(cx, WXJS_NO_PARENT_ERROR, GetClass()->name); + return JS_FALSE; + } + JS_SetParent(cx, obj, clntParent->GetObject()); + + if ( p->Create(parent, id, *pt, *size, style) ) + { + *rval = JS_TRUE; + p->SetClientObject(new JavaScriptClientData(cx, obj, true, false)); + JSObject *objActionArray = JS_NewArrayObject(cx, 0, NULL); + JS_DefineProperty(cx, obj, "actions", OBJECT_TO_JSVAL(objActionArray), + NULL, NULL, JSPROP_ENUMERATE |JSPROP_PERMANENT); + + p->Connect(wxID_ANY, wxID_ANY, wxEVT_COMMAND_TOOL_CLICKED, + wxCommandEventHandler(ToolEventHandler::OnTool)); + } + } + + return JS_TRUE; +} + +/*** + * + * + * + * + * + * Adds a control to the toolbar. + * + * + */ +JSBool ToolBar::addControl(JSContext *cx, + JSObject *obj, + uintN WXUNUSED(argc), + jsval *argv, + jsval* WXUNUSED(rval)) +{ + wxToolBar *p = ToolBar::GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + wxControl *control = Control::GetPrivate(cx, argv[0]); + if ( control != NULL ) + { + p->AddControl(control); + return JS_TRUE; + } + + return JS_FALSE; +} + +/*** + * + * + * + * Adds a separator for spacing groups of tools. + * + * + */ +JSBool ToolBar::addSeparator(JSContext *cx, + JSObject *obj, + uintN WXUNUSED(argc), + jsval* WXUNUSED(argv), + jsval* WXUNUSED(rval)) +{ + wxToolBar *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + p->AddSeparator(); + return JS_TRUE; +} + +/*** + * + * + * + * An integer that may be used to identify this tool + * + * + * + * The primary tool bitmap for toggle and button tools. + * + * + * Used for tooltips + * + * + * May be wxItemKind.NORMAL for a normal button (default), + * wxItemKind.CHECK for a checkable tool (such tool stays pressed after it had been toggled) + * or wxItemKind.RADIO for a checkable tool which makes part of a radio group of tools each + * of which is automatically unchecked whenever another button in the group is checked. + * + * + * + * + * An integer that may be used to identify this tool + * + * + * + * The primary tool bitmap for toggle and button tools. + * + * + * The second bitmap specifies the on-state bitmap for a toggle tool + * + * + * May be wxItemKind.NORMAL for a normal button (default), + * wxItemKind.CHECK for a checkable tool (such tool stays pressed after it had been toggled) + * or wxItemKind.RADIO for a checkable tool which makes part of a radio group of tools each + * of which is automatically unchecked whenever another button in the group is checked. + * + * + * Used for tooltips + * + * + * String shown in the statusbar. + * + * + * + * Adds a tool to the toolbar. + * + * + */ +JSBool ToolBar::addTool(JSContext* cx, + JSObject* obj, + uintN argc, + jsval* argv, + jsval* rval) +{ + wxToolBar *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + int id; + if ( ! FromJS(cx, argv[0], id) ) + return JS_FALSE; + + wxString label; + FromJS(cx, argv[1], label); + wxBitmap *bmp1 = Bitmap::GetPrivate(cx, argv[2]); + if ( bmp1 == NULL ) + { + JS_ReportError(cx, WXJS_INVALID_ARG_TYPE, 2, "wxBitmap"); + return JS_FALSE; + } + + wxToolBarToolBase *tool = NULL; + if ( argc > 3 ) + { + wxString shortHelp = wxEmptyString; + int kind = wxITEM_NORMAL; + wxBitmap *bmp2 = Bitmap::GetPrivate(cx, argv[3], false); + if ( bmp2 == NULL ) + { + if ( argc > 5 ) + argc = 5; + switch(argc) + { + case 5: + if ( ! FromJS(cx, argv[4], kind) ) + { + JS_ReportError(cx, WXJS_INVALID_ARG_TYPE, 2, "Integer"); + return JS_FALSE; + } + case 4: + FromJS(cx, argv[3], shortHelp); + } + tool = p->AddTool(id, label, *bmp1, shortHelp, (wxItemKind) kind); + } + else + { + wxString longHelp = wxEmptyString; + + if ( argc > 7 ) + argc = 7; + switch(argc) + { + case 7: + FromJS(cx, argv[6], longHelp); + case 6: + FromJS(cx, argv[5], shortHelp); + case 5: + if ( ! FromJS(cx, argv[4], kind) ) + { + JS_ReportError(cx, WXJS_INVALID_ARG_TYPE, 5, "Integer"); + return JS_FALSE; + } + } + tool = p->AddTool(id, label, *bmp1, *bmp2, (wxItemKind) kind, + shortHelp, longHelp); + } + } + else + tool = p->AddTool(id, label, *bmp1); + + if ( tool != NULL ) + { + *rval = ToolBarToolBase::CreateObject(cx, tool); + tool->SetClientData(new ToolBarToolData(cx, JSVAL_TO_OBJECT(*rval))); + } + + return JS_TRUE; +} + +/*** + * + * + * + * An integer that may be used to identify this tool + * + * + * + * The primary tool bitmap for toggle and button tools. + * + * + * The second bitmap specifies the on-state bitmap for a toggle tool + * + * + * Used for tooltips + * + * + * String shown in the statusbar. + * + * + * + * Adds a new check (or toggle) tool to the toolbar. + * + * + */ +JSBool ToolBar::addCheckTool(JSContext *cx, + JSObject *obj, + uintN argc, + jsval *argv, + jsval *rval) +{ + wxToolBar *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + wxString longHelp = wxEmptyString; + wxString shortHelp = wxEmptyString; + + if ( argc > 6 ) + argc = 6; + + switch(argc) + { + case 6: + FromJS(cx, argv[5], longHelp); + case 5: + FromJS(cx, argv[4], shortHelp); + default: + { + int id; + if ( ! FromJS(cx, argv[0], id) ) + { + JS_ReportError(cx, WXJS_INVALID_ARG_TYPE, 1, "Integer"); + return JS_FALSE; + } + + wxString label; + FromJS(cx, argv[1], label); + wxBitmap *bmp1 = Bitmap::GetPrivate(cx, argv[2]); + if ( bmp1 == NULL ) + { + JS_ReportError(cx, WXJS_INVALID_ARG_TYPE, 3, "wxBitmap"); + return JS_FALSE; + } + wxBitmap *bmp2 = Bitmap::GetPrivate(cx, argv[3]); + if ( bmp2 == NULL ) + { + JS_ReportError(cx, WXJS_INVALID_ARG_TYPE, 4, "wxBitmap"); + return JS_FALSE; + } + wxToolBarToolBase *tool = p->AddCheckTool(id, label, + *bmp1, *bmp2, + shortHelp, longHelp); + if ( tool != NULL ) + { + *rval = ToolBarToolBase::CreateObject(cx, tool); + tool->SetClientData(new ToolBarToolData(cx, JSVAL_TO_OBJECT(*rval))); + } + } + } + return JS_TRUE; +} + +/*** + * + * + * + * An integer that may be used to identify this tool + * + * + * + * The primary tool bitmap for toggle and button tools. + * + * + * The second bitmap specifies the on-state bitmap for a toggle tool + * + * + * Used for tooltips + * + * + * String shown in the statusbar. + * + * + * + * Adds a new radio tool to the toolbar. Consecutive radio tools form a radio group + * such that exactly one button in the group is pressed at any moment, in other words + * whenever a button in the group is pressed the previously pressed button is + * automatically released. You should avoid having the radio groups of only one + * element as it would be impossible for the user to use such button. + *

+ * By default, the first button in the radio group is initially pressed, the others are not. + *
+ *
+ */ +JSBool ToolBar::addRadioTool(JSContext *cx, + JSObject *obj, + uintN argc, + jsval *argv, + jsval *rval) +{ + wxToolBar *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + wxString longHelp = wxEmptyString; + wxString shortHelp = wxEmptyString; + + if ( argc > 6 ) + argc = 6; + switch(argc) + { + case 6: + FromJS(cx, argv[5], longHelp); + case 5: + FromJS(cx, argv[4], shortHelp); + default: + { + int id; + if ( ! FromJS(cx, argv[0], id) ) + { + JS_ReportError(cx, WXJS_INVALID_ARG_TYPE, 1, "Integer"); + return JS_FALSE; + } + + wxString label; + FromJS(cx, argv[1], label); + wxBitmap *bmp1 = Bitmap::GetPrivate(cx, argv[2]); + if ( bmp1 == NULL ) + { + JS_ReportError(cx, WXJS_INVALID_ARG_TYPE, 3, "wxBitmap"); + return JS_FALSE; + } + wxBitmap *bmp2 = Bitmap::GetPrivate(cx, argv[3]); + if ( bmp2 == NULL ) + { + JS_ReportError(cx, WXJS_INVALID_ARG_TYPE, 4, "wxBitmap"); + return JS_FALSE; + } + wxToolBarToolBase *tool = p->AddRadioTool(id, label, + *bmp1, *bmp2, + shortHelp, longHelp); + + if ( tool != NULL ) + { + *rval = ToolBarToolBase::CreateObject(cx, tool); + tool->SetClientData(new ToolBarToolData(cx, JSVAL_TO_OBJECT(*rval))); + } + } + } + return JS_TRUE; +} + +/*** + * + * + * + * + * + * Deletes the tool with the given id. + * + * + */ +JSBool ToolBar::deleteTool(JSContext *cx, + JSObject *obj, + uintN WXUNUSED(argc), + jsval *argv, + jsval *rval) +{ + wxToolBar *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + int id; + if ( FromJS(cx, argv[0], id) ) + { + *rval = ToJS(cx, p->DeleteTool(id)); + return JS_TRUE; + } + + return JS_FALSE; +} + +/*** + * + * + * + * + * + * Deletes the tool on the given position. + * + * + */ +JSBool ToolBar::deleteToolByPos(JSContext *cx, + JSObject *obj, + uintN WXUNUSED(argc), + jsval *argv, + jsval *rval) +{ + wxToolBar *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + int id; + if ( FromJS(cx, argv[0], id) ) + { + *rval = ToJS(cx, p->DeleteToolByPos(id)); + return JS_TRUE; + } + + return JS_FALSE; +} + +/*** + * + * + * + * The tool identifier + * + * + * Enable/disable the tool + * + * + * + * Enables/disables the tool with the given id. + * + * + */ +JSBool ToolBar::enableTool(JSContext *cx, + JSObject *obj, + uintN WXUNUSED(argc), + jsval *argv, + jsval *WXUNUSED(rval)) +{ + wxToolBar *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + int id; + bool enable; + if ( FromJS(cx, argv[0], id) + && FromJS(cx, argv[1], enable) ) + { + p->EnableTool(id, enable); + return JS_TRUE; + } + + return JS_FALSE; +} + +/*** + * + * + * + * The tool identifier + * + * + * + * Returns the control identified by Id or null when not found. + * + * + */ +JSBool ToolBar::findControl(JSContext *cx, + JSObject *obj, + uintN WXUNUSED(argc), + jsval *argv, + jsval *rval) +{ + wxToolBar *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + int id; + if ( FromJS(cx, argv[0], id) ) + { + wxControl *ctrl = p->FindControl(id); + if ( ctrl == NULL ) + { + *rval = JSVAL_VOID; + } + else + { + JavaScriptClientData *data + = dynamic_cast(ctrl->GetClientObject()); + if ( data ) + { + *rval = OBJECT_TO_JSVAL(data->GetObject()); + } + } + return JS_TRUE; + } + + return JS_FALSE; +} + +/*** + * + * + * + * The tool identifier + * + * + * + * Returns true when the tool with the given id is enabled. + * See @wxToolBar#enableTool + * + * + */ +JSBool ToolBar::getToolEnabled(JSContext *cx, + JSObject *obj, + uintN WXUNUSED(argc), + jsval *argv, + jsval *rval) +{ + wxToolBar *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + int id; + if ( FromJS(cx, argv[0], id) ) + { + *rval = ToJS(cx, p->GetToolEnabled(id)); + return JS_TRUE; + } + + return JS_FALSE; +} + +/*** + * + * + * + * The tool identifier + * + * + * + * Returns the long help from the tool with the given id. + * + * + */ +JSBool ToolBar::getToolLongHelp(JSContext *cx, + JSObject *obj, + uintN WXUNUSED(argc), + jsval *argv, + jsval *rval) +{ + wxToolBar *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + int id; + if ( FromJS(cx, argv[0], id) ) + { + *rval = ToJS(cx, p->GetToolLongHelp(id)); + return JS_TRUE; + } + + return JS_FALSE; +} + +/*** + * + * + * + * The tool identifier + * + * + * + * Returns the short help from the tool with the given id. + * + * + */ +JSBool ToolBar::getToolShortHelp(JSContext *cx, + JSObject *obj, + uintN WXUNUSED(argc), + jsval *argv, + jsval *rval) +{ + wxToolBar *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + int id; + if ( FromJS(cx, argv[0], id) ) + { + *rval = ToJS(cx, p->GetToolShortHelp(id)); + return JS_TRUE; + } + + return JS_FALSE; +} + +/*** + * + * + * + * The tool identifier + * + * + * + * Returns true when the tool with the given id is toggled on. + * + * + */ +JSBool ToolBar::getToolState(JSContext *cx, + JSObject *obj, + uintN WXUNUSED(argc), + jsval *argv, + jsval *rval) +{ + wxToolBar *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + int id; + if ( FromJS(cx, argv[0], id) ) + { + *rval = ToJS(cx, p->GetToolState(id)); + return JS_TRUE; + } + + return JS_FALSE; +} + +/*** + * + * + * + * + * + * + * Inserts the control into the toolbar at the given position. + * You must call @wxToolBar#realize for the change to take place. + * + * + */ +JSBool ToolBar::insertControl(JSContext *cx, + JSObject *obj, + uintN WXUNUSED(argc), + jsval *argv, + jsval* WXUNUSED(rval)) +{ + wxToolBar *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + int pos; + if ( FromJS(cx, argv[0], pos ) ) + { + wxControl *control = Control::GetPrivate(cx, argv[1]); + if ( control != NULL ) + { + p->InsertControl(pos, control); + return JS_TRUE; + } + } + return JS_FALSE; +} + +/*** + * + * + * + * + * + * Inserts a separator into the toolbar at the given position. + * You must call @wxToolBar#realize for the change to take place. + * + * + */ +JSBool ToolBar::insertSeparator(JSContext *cx, + JSObject *obj, + uintN WXUNUSED(argc), + jsval *argv, + jsval* WXUNUSED(rval)) +{ + wxToolBar *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + int pos; + if ( FromJS(cx, argv[0], pos ) ) + { + p->InsertSeparator(pos); + return JS_TRUE; + } + return JS_FALSE; +} + +/*** + * + * + * + * + * An integer that may be used to identify this tool + * + * + * + * The primary tool bitmap for toggle and button tools. + * + * + * The second bitmap specifies the on-state bitmap for a toggle tool + * + * + * Is the tool a toggle tool? + * + * + * Used for tooltips + * + * + * String shown in the statusbar. + * + * + * + * Inserts the tool to the toolbar at the given position. + * + * + */ +JSBool ToolBar::insertTool(JSContext *cx, + JSObject *obj, + uintN argc, + jsval *argv, + jsval* rval) +{ + wxToolBar *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + wxString longHelp = wxEmptyString; + wxString shortHelp = wxEmptyString; + bool toggle = false; + wxBitmap *bmp2 = NULL; + + switch(argc) + { + case 7: + FromJS(cx, argv[7], longHelp); + // Fall through + case 6: + FromJS(cx, argv[6], shortHelp); + // Fall through + case 5: + if ( ! FromJS(cx, argv[4], toggle) ) + { + JS_ReportError(cx, WXJS_INVALID_ARG_TYPE, 5, "Boolean"); + return JS_FALSE; + } + // Fall through + case 4: + bmp2 = Bitmap::GetPrivate(cx, argv[3]); + if ( bmp2 == NULL ) + { + JS_ReportError(cx, WXJS_INVALID_ARG_TYPE, 4, "wxBitmap"); + return JS_FALSE; + } + // Fall through + default: + wxBitmap *bmp1 = Bitmap::GetPrivate(cx, argv[2]); + if ( bmp1 == NULL ) + { + JS_ReportError(cx, WXJS_INVALID_ARG_TYPE, 3, "wxBitmap"); + return JS_FALSE; + } + int id; + int pos; + if ( ! FromJS(cx, argv[1], id) ) + { + JS_ReportError(cx, WXJS_INVALID_ARG_TYPE, 2, "Integer"); + return JS_FALSE; + } + + if ( ! FromJS(cx, argv[0], pos) ) + { + JS_ReportError(cx, WXJS_INVALID_ARG_TYPE, 1, "Integer"); + return JS_FALSE; + } + + wxToolBarToolBase *tool = p->InsertTool(pos, id, *bmp1, + bmp2 == NULL ? wxNullBitmap : *bmp2, + toggle, NULL, shortHelp, longHelp); + if ( tool != NULL ) + { + *rval = ToolBarToolBase::CreateObject(cx, tool); + tool->SetClientData(new ToolBarToolData(cx, JSVAL_TO_OBJECT(*rval))); + } + } + return JS_FALSE; +} + +/*** + * + * + * + * Call this method after you have added tools. + * + * + */ +JSBool ToolBar::realize(JSContext *cx, + JSObject *obj, + uintN WXUNUSED(argc), + jsval* WXUNUSED(argv), + jsval *rval) +{ + wxToolBar *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + *rval = ToJS(cx, p->Realize()); + return JS_TRUE; +} + +/*** + * + * + * + * The tool identifier + * + * + * + * + * Sets the long help from the tool with the given id. + * + * + */ +JSBool ToolBar::setToolLongHelp(JSContext *cx, + JSObject *obj, + uintN WXUNUSED(argc), + jsval* argv, + jsval* WXUNUSED(rval)) +{ + wxToolBar *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + int id; + if ( FromJS(cx, argv[0], id) ) + { + wxString longHelp; + FromJS(cx, argv[1], longHelp); + p->SetToolLongHelp(id, longHelp); + return JS_TRUE; + } + + return JS_FALSE; +} + +/*** + * + * + * + * The tool identifier + * + * + * + * + * Sets the short help for the tool with the given id. The short help will be used + * to show a tooltip. + * + * + */ +JSBool ToolBar::setToolShortHelp(JSContext *cx, + JSObject *obj, + uintN WXUNUSED(argc), + jsval *argv, + jsval* WXUNUSED(rval)) +{ + wxToolBar *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + int id; + if ( FromJS(cx, argv[0], id) ) + { + wxString longHelp; + FromJS(cx, argv[1], longHelp); + p->SetToolShortHelp(id, longHelp); + return JS_TRUE; + } + + return JS_FALSE; +} + +/*** + * + * + * + * The tool identifier + * + * + * + * + * Toggles a tool on or off. + * See @wxToolBar#getToolState. + * + * + */ +JSBool ToolBar::toggleTool(JSContext *cx, + JSObject *obj, + uintN WXUNUSED(argc), + jsval *argv, + jsval* WXUNUSED(rval)) +{ + wxToolBar *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + int id; + bool toggle; + if ( FromJS(cx, argv[0], id) + && FromJS(cx, argv[1], toggle) ) + { + p->ToggleTool(id, toggle); + return JS_TRUE; + } + + return JS_FALSE; +} + +void ToolEventHandler::OnTool(wxCommandEvent &event) +{ + ToolBar *p = dynamic_cast(event.GetEventObject()); + wxToolBarToolBase *tool = p->FindById(event.GetId()); + if ( tool == NULL ) + return; + + if ( tool->IsControl() ) + return; + + ToolBarToolData *data + = dynamic_cast(tool->GetClientData()); + + JSContext *cx = data->GetContext(); + + jsval jsAction; + if ( JS_GetProperty(cx, data->GetObject(), "onTool", &jsAction) == JS_TRUE ) + { + if ( jsAction == JSVAL_VOID ) + { + // No action found, skip the event and when a menu item with the same + // id exists, it will try to run the associated action of that item + event.Skip(); + } + else + { + JSFunction *fnAction = JS_ValueToFunction(cx, jsAction); + if ( fnAction != NULL ) + { + PrivCommandEvent *wxjsEvent = new PrivCommandEvent(event); + jsval argv[] = { CommandEvent::CreateObject(cx, wxjsEvent) }; + + jsval rval; + JSBool result = JS_CallFunction(cx, data->GetObject(), + fnAction, 1, argv, &rval); + if ( result == JS_FALSE ) + { + JS_ReportPendingException(cx); + } + } + } + } +} Property changes on: ps/trunk/source/tools/atlas/wxJS/gui/control/toolbar.cpp ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/gui/control/statbar.h =================================================================== --- ps/trunk/source/tools/atlas/wxJS/gui/control/statbar.h (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/gui/control/statbar.h (revision 5154) @@ -0,0 +1,74 @@ +/* + * wxJavaScript - statbar.h + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: statbar.h 694 2007-05-03 21:14:13Z fbraem $ + */ +#ifndef _WXJSStatusBar_H +#define _WXJSStatusBar_H + +namespace wxjs +{ + namespace gui + { + class StatusBar : public ApiWrapper + { + public: + + static bool GetProperty(wxStatusBar *p, + JSContext *cx, + JSObject *obj, + int id, + jsval *vp); + + static bool SetProperty(wxStatusBar *p, + JSContext *cx, + JSObject *obj, + int id, + jsval *vp); + + static wxStatusBar* Construct(JSContext *cx, + JSObject *obj, + uintN argc, + jsval *argv, + bool constructing); + + + WXJS_DECLARE_CONSTANT_MAP() + + WXJS_DECLARE_METHOD_MAP() + WXJS_DECLARE_METHOD(create) + WXJS_DECLARE_METHOD(getFieldRect) + WXJS_DECLARE_METHOD(setFieldsCount) + WXJS_DECLARE_METHOD(setStatusText) + WXJS_DECLARE_METHOD(getStatusText) + + WXJS_DECLARE_PROPERTY_MAP() + enum + { + P_FIELDS_COUNT + , P_STATUS_WIDTHS + }; + }; + }; // namespace gui +}; // namespace wxjs + +#endif //_WXJSStatusBar_H Property changes on: ps/trunk/source/tools/atlas/wxJS/gui/control/statbar.h ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/gui/control/radioboxit.h =================================================================== --- ps/trunk/source/tools/atlas/wxJS/gui/control/radioboxit.h (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/gui/control/radioboxit.h (revision 5154) @@ -0,0 +1,59 @@ +/* + * wxJavaScript - radioboxit.h + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: radioboxit.h 691 2007-05-01 20:00:49Z fbraem $ + */ +#ifndef _wxjs_gui_radioboxit_h +#define _wxjs_gui_radioboxit_h +namespace wxjs +{ + namespace gui + { + class RadioBoxItem : public ApiWrapper + { + public: + + static bool GetProperty(Index *p, + JSContext *cx, + JSObject *obj, + int id, + jsval *vp); + static bool SetProperty(Index *p, + JSContext *cx, + JSObject *obj, + int id, + jsval *vp); + + WXJS_DECLARE_PROPERTY_MAP() + + enum + { + P_ENABLE = WXJS_START_PROPERTY_ID + , P_STRING + , P_SELECTED + , P_SHOW + }; + }; + }; // namespace gui +}; // namespace wxjs + +#endif // _wxjs_gui_radioboxit_h Property changes on: ps/trunk/source/tools/atlas/wxJS/gui/control/radioboxit.h ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/gui/control/mdichild.cpp =================================================================== --- ps/trunk/source/tools/atlas/wxJS/gui/control/mdichild.cpp (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/gui/control/mdichild.cpp (revision 5154) @@ -0,0 +1,266 @@ +#include "precompiled.h" + +#ifndef WX_PRECOMP + #include +#endif + +#include "../../common/main.h" +#include "../errors.h" + +#include "../misc/size.h" +#include "../misc/point.h" +#include "mdi.h" +#include "mdichild.h" +#include "frame.h" +#include "window.h" +#include "toolbar.h" + +using namespace wxjs::gui; + +wxToolBar* MDIChildFrame::OnCreateToolBar(long style, + wxWindowID id, + const wxString& name) +{ + ToolBar *tbar = new ToolBar(); + tbar->Create(this, id, wxDefaultPosition, wxDefaultSize, style, name); + return tbar; +} + +/*** + * gui + * control/mdichild + * + * An MDI child frame is a frame that can only exist in a @wxMDIParentFrame + * + */ +WXJS_INIT_CLASS(MDIChildFrame, "wxMDIChildFrame", 3) + +bool MDIChildFrame::AddProperty(wxMDIChildFrame *p, + JSContext* WXUNUSED(cx), + JSObject* WXUNUSED(obj), + const wxString &prop, + jsval* WXUNUSED(vp)) +{ + if ( WindowEventHandler::ConnectEvent(p, prop, true) ) + return true; + + FrameEventHandler::ConnectEvent(p, prop, true); + + return true; +} + + +bool MDIChildFrame::DeleteProperty(wxMDIChildFrame *p, + JSContext* WXUNUSED(cx), + JSObject* WXUNUSED(obj), + const wxString &prop) +{ + if ( WindowEventHandler::ConnectEvent(p, prop, false) ) + return true; + + FrameEventHandler::ConnectEvent(p, prop, false); + return true; +} + +/*** + * + * + * + * + * The parent frame. This can't be null. + * + * The window ID + * The title of the window + * + * + * + * + * + * Creates a new MDI child frame. + * + * + */ +wxMDIChildFrame* MDIChildFrame::Construct(JSContext* cx, + JSObject* obj, + uintN argc, + jsval *argv, + bool WXUNUSED(constructing)) +{ + MDIChildFrame *p = new MDIChildFrame(); + SetPrivate(cx, obj, p); + + if ( argc > 0 ) + { + jsval rval; + create(cx, obj, argc, argv, &rval); + } + return p; +} + +WXJS_BEGIN_METHOD_MAP(MDIChildFrame) + WXJS_METHOD("create", create, 3) + WXJS_METHOD("activate", activate, 0) + WXJS_METHOD("maximize", maximize, 1) + WXJS_METHOD("restore", restore, 0) +WXJS_END_METHOD_MAP() + +/*** + * + * + * + * The parent frame. This can't be null. + * + * The window ID + * The title of the window + * + * + * + * + * + * Sets a pixel to a particular color. + * + * + */ +JSBool MDIChildFrame::create(JSContext* cx, + JSObject* obj, + uintN argc, + jsval* argv, + jsval* rval) +{ + wxMDIChildFrame *p = GetPrivate(cx, obj); + *rval = JSVAL_FALSE; + + int style = wxDEFAULT_FRAME_STYLE; + const wxPoint* pos = &wxDefaultPosition; + const wxSize* size = &wxDefaultSize; + + if ( argc > 6 ) + { + argc = 6; + } + + switch(argc) + { + case 6: + if ( ! FromJS(cx, argv[5], style) ) + { + JS_ReportError(cx, WXJS_INVALID_ARG_TYPE, 6, "Integer"); + return JS_FALSE; + } + case 5: + size = Size::GetPrivate(cx, argv[4]); + if ( size == NULL ) + { + JS_ReportError(cx, WXJS_INVALID_ARG_TYPE, 5, "wxSize"); + return JS_FALSE; + } + case 4: + pos = Point::GetPrivate(cx, argv[3]); + if ( pos == NULL ) + { + JS_ReportError(cx, WXJS_INVALID_ARG_TYPE, 4, "wxPoint"); + return JS_FALSE; + } + default: + { + wxString title; + wxMDIParentFrame *parent = NULL; + int id = -1; + + FromJS(cx, argv[2], title); + + if ( ! FromJS(cx, argv[1], id) ) + { + JS_ReportError(cx, WXJS_INVALID_ARG_TYPE, 2, "Integer"); + return JS_FALSE; + } + + parent = MDIParentFrame::GetPrivate(cx, argv[0]); + if ( parent == NULL +#ifdef __WXMSW__ + || parent->GetHWND() == NULL +#endif + ) + { + JS_ReportError(cx, WXJS_INVALID_ARG_TYPE, 1, "wxMDIParentFrame"); + return JS_FALSE; + } + + if ( p->Create(parent, id, title, *pos, *size, style) ) + { + *rval = JSVAL_TRUE; + p->SetClientObject(new JavaScriptClientData(cx, obj, true, false)); + p->Connect(wxID_ANY, wxID_ANY, wxEVT_COMMAND_MENU_SELECTED, + wxCommandEventHandler(FrameEventHandler::OnMenu)); + } + } + } + return JS_TRUE; +} + +/*** + * + * + * + * Activates this MDI child frame + * + * + */ +JSBool MDIChildFrame::activate(JSContext* cx, + JSObject* obj, + uintN WXUNUSED(argc), + jsval* WXUNUSED(argv), + jsval* WXUNUSED(rval)) +{ + wxMDIChildFrame *p = GetPrivate(cx, obj); + + p->Activate(); + return JS_TRUE; +} + +/*** + * + * + * + * + * + * Maximizes this MDI child frame + * + * + */ +JSBool MDIChildFrame::maximize(JSContext* cx, + JSObject* obj, + uintN WXUNUSED(argc), + jsval* argv, + jsval* WXUNUSED(rval)) +{ + wxMDIChildFrame *p = GetPrivate(cx, obj); + + bool sw = true; + FromJS(cx, argv[0], sw); + p->Maximize(sw); + + return JS_TRUE; +} + +/*** + * + * + * + * Restores this MDI child frame + * + * + */ +JSBool MDIChildFrame::restore(JSContext* cx, + JSObject* obj, + uintN WXUNUSED(argc), + jsval* WXUNUSED(argv), + jsval* WXUNUSED(rval)) +{ + wxMDIChildFrame *p = GetPrivate(cx, obj); + + p->Restore(); + return JS_TRUE; +} Property changes on: ps/trunk/source/tools/atlas/wxJS/gui/control/mdichild.cpp ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/gui/control/treeitem.cpp =================================================================== --- ps/trunk/source/tools/atlas/wxJS/gui/control/treeitem.cpp (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/gui/control/treeitem.cpp (revision 5154) @@ -0,0 +1,472 @@ +#include "precompiled.h" + +/* + * wxJavaScript - treeitem.cpp + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: treeitem.cpp 735 2007-06-06 20:22:54Z fbraem $ + */ +// wxJSTreeItem.cpp + +#ifndef WX_PRECOMP + #include +#endif + +#include + +#include "../../common/main.h" + +#include "../misc/app.h" + +#include "treectrl.h" +#include "treeid.h" +#include "treeitem.h" + +#include "../misc/colour.h" +#include "../misc/font.h" + +using namespace wxjs; +using namespace wxjs::gui; + +/*** + * control/treeitem + * gui + * + * wxTreeItem is not available in wxWidgets. It's main purpose is to concentrate + * item specific properties and methods in this class which will make it easier to work with + * tree items. + * See @wxTreeCtrl, @wxTreeItemId and @wxTreeCtrl#getItem + * + */ +WXJS_INIT_CLASS(TreeItem, "wxTreeItem", 0) + +/*** + * + * + * Gets the number of child items. It returns the total number + * of descendants. + * + * + * Get/Set the background colour of the item. + * + * + * Get/Set the item text in bold. + * + * + * Gets the number of child items. Only the children of one level is returned. + * + * + * Get/Set the associated data of the item. + * + * + * Returns true when the item is expanded. When set to true + * the items is expanded, collapsed when set to false. + * + * + * Get/Set the font of the item. + * + * + * Returns true when the item has children. When set + * to true you can force the appearance of the button next to the item. + * This is useful to allow the user to expand the items which don't have + * any children now, but instead adding them only when needed, thus minimizing + * memory usage and loading time. + * + * + * Get the last child item. Returns null when the item has no childs. + * + * + * Get the next sibling item. Returns null when there are no items left. + * + * + * Get the parent item. Returns null when this item is the root item. + * + * + * Get the previous sibling item. Returns null when there are no items left. + * + * + * Returns true when the item is selected. When set to true + * the items is selected, unselected when set to false. + * + * + * Get/Set the item text. + * + * + * Get/Set the colour of the text. + * + * + * Get/Set the visibility of the item. Setting visible to false + * doesn't do anything. + * + * + */ +WXJS_BEGIN_PROPERTY_MAP(TreeItem) + WXJS_PROPERTY(P_BOLD, "bold") + WXJS_PROPERTY(P_DATA, "data") + WXJS_PROPERTY(P_TEXT_COLOUR, "textColour") + WXJS_PROPERTY(P_TEXT, "text") + WXJS_PROPERTY(P_FONT, "font") + WXJS_PROPERTY(P_HAS_CHILDREN, "hasChildren") + WXJS_PROPERTY(P_VISIBLE, "visible") + WXJS_PROPERTY(P_EXPANDED, "expanded") + WXJS_PROPERTY(P_SELECTED, "selected") + WXJS_READONLY_PROPERTY(P_CHILDREN_COUNT, "childrenCount") + WXJS_READONLY_PROPERTY(P_ALL_CHILDREN_COUNT, "allChildrenCount") + WXJS_READONLY_PROPERTY(P_PARENT, "parent") + WXJS_READONLY_PROPERTY(P_LAST_CHILD, "lastChild") + WXJS_READONLY_PROPERTY(P_PREV_SIBLING, "prevSibling") + WXJS_READONLY_PROPERTY(P_NEXT_SIBLING, "nextSibling") +WXJS_END_PROPERTY_MAP() + +bool TreeItem::GetProperty(wxTreeItemId *p, + JSContext *cx, + JSObject *obj, + int id, + jsval *vp) +{ + JSObject *objParent = JS_GetParent(cx, obj); + wxTreeCtrl *tree = TreeCtrl::GetPrivate(cx, objParent); + if ( tree == NULL ) + return false; + + switch (id) + { + case P_TEXT: + *vp = ToJS(cx, tree->GetItemText(*p)); + break; + case P_DATA: + { + ObjectTreeData *data = (ObjectTreeData*) tree->GetItemData(*p); + *vp = data->GetJSVal(); + break; + } + case P_TEXT_COLOUR: + *vp = Colour::CreateObject(cx, new wxColour(tree->GetItemTextColour(*p))); + break; + case P_BACKGROUND_COLOUR: + *vp = Colour::CreateObject(cx, new wxColour(tree->GetItemBackgroundColour(*p))); + break; + case P_FONT: + *vp = Font::CreateObject(cx, new wxFont(tree->GetItemFont(*p))); + break; + case P_HAS_CHILDREN: + *vp = ToJS(cx, tree->GetChildrenCount(*p, FALSE) != 0); + break; + case P_BOLD: + *vp = ToJS(cx, tree->IsBold(*p)); + break; + case P_VISIBLE: + *vp = ToJS(cx, tree->IsVisible(*p)); + break; + case P_EXPANDED: + *vp = ToJS(cx, tree->IsExpanded(*p)); + break; + case P_SELECTED: + *vp = ToJS(cx, tree->IsSelected(*p)); + break; + case P_CHILDREN_COUNT: + *vp = ToJS(cx, tree->GetChildrenCount(*p, false)); + break; + case P_ALL_CHILDREN_COUNT: + *vp = ToJS(cx, tree->GetChildrenCount(*p)); + break; + case P_PARENT: + { + wxTreeItemId parentId = tree->GetItemParent(*p); + if ( parentId.IsOk() ) + *vp = TreeItem::CreateObject(cx, new wxTreeItemId(parentId)); + break; + } + case P_LAST_CHILD: + { + wxTreeItemId childId = tree->GetLastChild(*p); + if ( childId.IsOk() ) + *vp = TreeItem::CreateObject(cx, new wxTreeItemId(childId)); + break; + } + case P_PREV_SIBLING: + { + wxTreeItemId prevId = tree->GetPrevSibling(*p); + if ( prevId.IsOk() ) + *vp = TreeItem::CreateObject(cx, new wxTreeItemId(prevId)); + break; + } + case P_NEXT_SIBLING: + { + wxTreeItemId nextId = tree->GetNextSibling(*p); + if ( nextId.IsOk() ) + *vp = TreeItem::CreateObject(cx, new wxTreeItemId(nextId)); + break; + } + } + return true; +} + +bool TreeItem::SetProperty(wxTreeItemId *p, + JSContext *cx, + JSObject *obj, + int id, + jsval *vp) +{ + JSObject *objParent = JS_GetParent(cx, obj); + wxTreeCtrl *tree = TreeCtrl::GetPrivate(cx, objParent); + if ( tree == NULL ) + return false; + + switch (id) + { + case P_TEXT: + { + wxString text; + FromJS(cx, *vp, text); + tree->SetItemText(*p, text); + break; + } + case P_DATA: + tree->SetItemData(*p, new ObjectTreeData(cx, *vp)); + break; + case P_TEXT_COLOUR: + { + wxColour *colour = Colour::GetPrivate(cx, *vp); + if ( colour != NULL ) + tree->SetItemTextColour(*p, *colour); + } + break; + case P_BACKGROUND_COLOUR: + { + wxColour *colour = Colour::GetPrivate(cx, *vp); + if ( colour != NULL ) + tree->SetItemBackgroundColour(*p, *colour); + } + break; + case P_FONT: + { + wxFont *font = Font::GetPrivate(cx, *vp); + if ( font != NULL ) + tree->SetItemFont(*p, *font); + } + break; + case P_HAS_CHILDREN: + { + bool children; + if ( FromJS(cx, *vp, children) ) + tree->SetItemHasChildren(*p, children); + } + break; + case P_BOLD: + { + bool bold; + if ( FromJS(cx, *vp, bold) ) + tree->SetItemBold(*p, bold); + } + break; + case P_EXPANDED: + { + bool expand; + if ( FromJS(cx, *vp, expand) ) + { + if ( expand ) + tree->Expand(*p); + else + tree->Collapse(*p); + } + } + break; + case P_VISIBLE: + { + bool visible; + if ( FromJS(cx, *vp, visible) + && visible ) + { + tree->EnsureVisible(*p); + } + } + break; + case P_SELECTED: + { + bool select; + if ( FromJS(cx, *vp, select) ) + { + if ( select ) + tree->SelectItem(*p); + else + tree->Unselect(); + } + } + break; + } + return true; +} + +WXJS_BEGIN_METHOD_MAP(TreeItem) + WXJS_METHOD("getImage", getImage, 1) + WXJS_METHOD("setImage", setImage, 2) + WXJS_METHOD("getFirstChild", getFirstChild, 1) + WXJS_METHOD("getNextChild", getNextChild, 1) +WXJS_END_METHOD_MAP() + +/*** + * + * + * + * A @wxTreeItemIcon constant. + * + * + * + * Gets the specified item image. + * See @wxTreeCtrl @wxTreeCtrl#getItemImage method + * + * + */ +JSBool TreeItem::getImage(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxTreeItemId *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + JSObject *objParent = JS_GetParent(cx, obj); + wxTreeCtrl *tree = TreeCtrl::GetPrivate(cx, objParent); + if ( tree == NULL ) + return JS_FALSE; + + int which; + if ( FromJS(cx, argv[0], which) ) + { + *rval = ToJS(cx, tree->GetItemImage(*p, (wxTreeItemIcon) which)); + return JS_TRUE; + } + + return JS_FALSE; +} + +/*** + * + * + * + * Index of the image in the image list + * + * + * A @wxTreeItemIcon constant. + * + * + * + * Sets the specified item image. + * See @wxTreeCtrl @wxTreeCtrl#setItemImage method + * + * + */ +JSBool TreeItem::setImage(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxTreeItemId *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + wxTreeCtrl *tree = TreeCtrl::GetPrivate(cx, JS_GetParent(cx, obj)); + if ( tree == NULL ) + return JS_FALSE; + + int image; + int which; + if ( FromJS(cx, argv[0], image) + && FromJS(cx, argv[1], which) ) + { + tree->SetItemImage(*p, image, (wxTreeItemIcon) which); + return JS_TRUE; + } + + return JS_FALSE; +} + +/*** + * + * + * + * For this enumeration function you must pass in a 'cookie' parameter + * which is opaque for the application but is necessary for the library + * to make these functions reentrant (i.e. allow more than one enumeration + * on one and the same object simultaneously). The cookie passed + * to getFirstChild and @wxTreeItem#getNextChild should be the same variable. + * + * + * + * Returns the first child item. An invalid item is returned when there is no child item. + * See @wxTreeCtrl @wxTreeCtrl#getFirstChild method + * + * + */ +JSBool TreeItem::getFirstChild(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxTreeItemId *p = TreeItemId::GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + wxTreeCtrl *tree = TreeCtrl::GetPrivate(cx, JS_GetParent(cx, obj)); + if ( tree == NULL ) + return JS_FALSE; + + long cookie; + if ( FromJS(cx, argv[0], cookie) ) + { + wxTreeItemIdValue newCookie = (wxTreeItemIdValue) cookie; + *rval = TreeItem::CreateObject(cx, new wxTreeItemId(tree->GetFirstChild(*p, newCookie))); + return JS_TRUE; + } + return JS_FALSE; + +} + +/*** + * + * + * + * For this enumeration function you must pass in a 'cookie' parameter + * which is opaque for the application but is necessary for the library + * to make these functions reentrant (i.e. allow more than one enumeration + * on one and the same object simultaneously). The cookie passed + * to @wxTreeItem @wxTreeItem#getFirstChild and getNextChild should be the same variable. + * + * + * + * Returns the first child item. An invalid item is returned when there is no child item. + * See @wxTreeCtrl @wxTreeCtrl#getNextChild method + * + * + */ +JSBool TreeItem::getNextChild(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxTreeItemId *p = TreeItemId::GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + wxTreeCtrl *tree = TreeCtrl::GetPrivate(cx, JS_GetParent(cx, obj)); + if ( tree == NULL ) + return JS_FALSE; + + long cookie; + if ( FromJS(cx, argv[0], cookie) ) + { + wxTreeItemIdValue newCookie = (wxTreeItemIdValue) cookie; + *rval = TreeItem::CreateObject(cx, new wxTreeItemId(tree->GetNextChild(*p, newCookie))); + return JS_TRUE; + } + return JS_FALSE; + +} Property changes on: ps/trunk/source/tools/atlas/wxJS/gui/control/treeitem.cpp ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/gui/control/checkbox.cpp =================================================================== --- ps/trunk/source/tools/atlas/wxJS/gui/control/checkbox.cpp (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/gui/control/checkbox.cpp (revision 5154) @@ -0,0 +1,323 @@ +#include "precompiled.h" + +/* + * wxJavaScript - checkbox.cpp + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: checkbox.cpp 710 2007-05-14 20:05:10Z fbraem $ + */ + +#ifndef WX_PRECOMP + #include +#endif + +#include "../../common/main.h" + +#include "../event/jsevent.h" +#include "../event/command.h" + +#include "checkbox.h" +#include "window.h" + +#include "../misc/point.h" +#include "../misc/size.h" +#include "../misc/validate.h" +#include "../errors.h" + +using namespace wxjs; +using namespace wxjs::gui; + +/*** + * control/checkbox + * gui + * + * A checkbox is a labeled box which is either on + * (checkmark is visible) or off (no checkmark). + *
An example: + *

+ *   // dlg is a wxDialog
+ *   var chkbox = new wxCheckBox(dlg, -1, "Check me");
+ *   chkbox.onCheckBox = function(event)
+ *   {
+ *     if ( event.checked )
+ *       wxMessageBox("Checked");
+ *     else
+ *       wxMessageBox("Unchecked");
+ *   }
+ *  
+ *
+ */ +WXJS_INIT_CLASS(CheckBox, "wxCheckBox", 3) +void CheckBox::InitClass(JSContext* WXUNUSED(cx), + JSObject* WXUNUSED(obj), + JSObject* WXUNUSED(proto)) +{ + CheckBoxEventHandler::InitConnectEventMap(); +} + +/*** + * + * + * Checks/Unchecks the checkbox. + * + * + */ +WXJS_BEGIN_PROPERTY_MAP(CheckBox) + WXJS_PROPERTY(P_VALUE, "value") +WXJS_END_PROPERTY_MAP() + +bool CheckBox::GetProperty(wxCheckBox* p, + JSContext* cx, + JSObject* WXUNUSED(obj), + int id, + jsval* vp) +{ + if ( id == P_VALUE ) + { + *vp = ToJS(cx, p->GetValue()); + } + return true; +} + +bool CheckBox::SetProperty(wxCheckBox* p, + JSContext* cx, + JSObject* WXUNUSED(obj), + int id, + jsval* vp) +{ + if (id == P_VALUE ) + { + bool value; + if ( FromJS(cx, *vp, value) ) + p->SetValue(value); + } + return true; +} + +bool CheckBox::AddProperty(wxCheckBox *p, + JSContext* WXUNUSED(cx), + JSObject* WXUNUSED(obj), + const wxString &prop, + jsval* WXUNUSED(vp)) +{ + if ( WindowEventHandler::ConnectEvent(p, prop, true) ) + return true; + + CheckBoxEventHandler::ConnectEvent(p, prop, true); + return true; +} + +bool CheckBox::DeleteProperty(wxCheckBox *p, + JSContext* WXUNUSED(cx), + JSObject* WXUNUSED(obj), + const wxString &prop) +{ + if ( WindowEventHandler::ConnectEvent(p, prop, false) ) + return true; + + CheckBoxEventHandler::ConnectEvent(p, prop, false); + return true; +} + +/*** + * + * + * + * The parent of the checkbox + * A window identifier. Use -1 when you don't need it + * The label of the checkbox + * The position of the checkbox on the given parent + * The size of the checkbox + * The style of the checkbox + * A validator + * + * + * Constructs a new wxCheckBox object. + * + * + */ +wxCheckBox *CheckBox::Construct(JSContext *cx, + JSObject *obj, + uintN argc, + jsval *argv, + bool WXUNUSED(constructing)) +{ + wxCheckBox *p = new wxCheckBox(); + SetPrivate(cx, obj, p); + + if ( argc > 0 ) + { + jsval rval; + create(cx, obj, argc, argv, &rval); + } + return p; +} + +WXJS_BEGIN_METHOD_MAP(CheckBox) + WXJS_METHOD("create", create, 3) +WXJS_END_METHOD_MAP() + +/*** + * + * + * + * The parent of the checkbox + * + * A window identifier. Use -1 when you don't need it + * + * The label of the checkbox + * + * + * The position of the checkbox on the given parent. + * + * + * The size of the checkbox + * + * + * The style of the checkbox + * + * A validator + * + * + * Constructs a new wxCheckBox object. + * + * + */ +JSBool CheckBox::create(JSContext *cx, + JSObject *obj, + uintN argc, + jsval *argv, + jsval *rval) +{ + wxCheckBox *p = GetPrivate(cx, obj); + *rval = JSVAL_FALSE; + + const wxPoint *pt = &wxDefaultPosition; + const wxSize *size = &wxDefaultSize; + int style = 0; + const wxValidator *val = &wxDefaultValidator; + + if ( argc > 7 ) + argc = 7; + + switch(argc) + { + case 7: + val = Validator::GetPrivate(cx, argv[6]); + if ( val == NULL ) + { + JS_ReportError(cx, WXJS_INVALID_ARG_TYPE, 7, "wxValidator"); + return JS_FALSE; + } + case 6: + if ( ! FromJS(cx, argv[5], style) ) + { + JS_ReportError(cx, WXJS_INVALID_ARG_TYPE, 6, "Integer"); + return JS_FALSE; + } + case 5: + size = Size::GetPrivate(cx, argv[4]); + if ( size == NULL ) + { + JS_ReportError(cx, WXJS_INVALID_ARG_TYPE, 5, "wxSize"); + return JS_FALSE; + } + // Fall through + case 4: + pt = Point::GetPrivate(cx, argv[3]); + if ( pt == NULL ) + { + JS_ReportError(cx, WXJS_INVALID_ARG_TYPE, 4, "wxPoint"); + return JS_FALSE; + } + // Fall through + default: + wxString text; + FromJS(cx, argv[2], text); + + int id; + if ( ! FromJS(cx, argv[1], id) ) + { + JS_ReportError(cx, WXJS_INVALID_ARG_TYPE, 2, "Integer"); + return JS_FALSE; + } + + wxWindow *parent = Window::GetPrivate(cx, argv[0]); + if ( parent == NULL ) + { + JS_ReportError(cx, WXJS_NO_PARENT_ERROR, GetClass()->name); + return JS_FALSE; + } + JavaScriptClientData *clntParent = + dynamic_cast(parent->GetClientObject()); + if ( clntParent == NULL ) + { + JS_ReportError(cx, WXJS_NO_PARENT_ERROR, GetClass()->name); + return JS_FALSE; + } + JS_SetParent(cx, obj, clntParent->GetObject()); + + if ( p->Create(parent, id, text, *pt, *size, style, *val) ) + { + *rval = JSVAL_TRUE; + p->SetClientObject(new JavaScriptClientData(cx, obj, true, false)); + } + } + + return JS_TRUE; +} + +/*** + * + * + * Called when the checkbox is clicked. The type of the argument that your + * handler receives is @wxCommandEvent. + * + * + */ + +WXJS_INIT_EVENT_MAP(wxCheckBox) +const wxString WXJS_CHECKBOX_EVENT = wxT("onCheckBox"); + +void CheckBoxEventHandler::OnCheckBox(wxCommandEvent &event) +{ + PrivCommandEvent::Fire(event, WXJS_CHECKBOX_EVENT); +} + + +void CheckBoxEventHandler::ConnectCheckBox(wxCheckBox *p, bool connect) +{ + if ( connect ) + { + p->Connect(wxEVT_COMMAND_CHECKBOX_CLICKED, + wxCommandEventHandler(OnCheckBox)); + } + else + { + p->Disconnect(wxEVT_COMMAND_CHECKBOX_CLICKED, + wxCommandEventHandler(OnCheckBox)); + } +} + +void CheckBoxEventHandler::InitConnectEventMap() +{ + AddConnector(WXJS_CHECKBOX_EVENT, ConnectCheckBox); +} Property changes on: ps/trunk/source/tools/atlas/wxJS/gui/control/checkbox.cpp ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/gui/control/treectrl.h =================================================================== --- ps/trunk/source/tools/atlas/wxJS/gui/control/treectrl.h (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/gui/control/treectrl.h (revision 5154) @@ -0,0 +1,219 @@ +/* + * wxJavaScript - treectrl.h + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: treectrl.h 696 2007-05-07 21:16:23Z fbraem $ + */ +#ifndef _WXJSTreeCtrl_H +#define _WXJSTreeCtrl_H + +#include "../../common/evtconn.h" + +#include +namespace wxjs +{ + namespace gui + { + class TreeCtrl : public wxTreeCtrl + , public ApiWrapper + { + public: + TreeCtrl(); + virtual ~TreeCtrl(); + + virtual int OnCompareItems(const wxTreeItemId& item1, + const wxTreeItemId& item2); + static void InitClass(JSContext* cx, + JSObject* obj, + JSObject* proto); + static bool AddProperty(wxTreeCtrl *p, + JSContext *cx, + JSObject *obj, + const wxString &prop, + jsval *vp); + static bool DeleteProperty(wxTreeCtrl *p, + JSContext* cx, + JSObject* obj, + const wxString &prop); + static bool GetProperty(wxTreeCtrl *p, + JSContext *cx, + JSObject *obj, + int id, + jsval *vp); + static bool SetProperty(wxTreeCtrl *p, + JSContext *cx, + JSObject *obj, + int id, + jsval *vp); + + static wxTreeCtrl* Construct(JSContext *cx, + JSObject *obj, + uintN argc, + jsval *argv, + bool constructing); + + WXJS_DECLARE_PROPERTY_MAP() + enum + { + P_COUNT + , P_INDENT + , P_IMAGE_LIST + , P_STATE_IMAGE_LIST + , P_ROOT_ITEM + , P_SELECTION + , P_SELECTIONS + , P_FIRST_VISIBLE + , P_EDIT_CONTROL + }; + + WXJS_DECLARE_METHOD_MAP() + WXJS_DECLARE_METHOD(create) + WXJS_DECLARE_METHOD(getItem) + WXJS_DECLARE_METHOD(getItemText) + WXJS_DECLARE_METHOD(setItemText) + WXJS_DECLARE_METHOD(getItemImage) + WXJS_DECLARE_METHOD(setItemImage) + WXJS_DECLARE_METHOD(getItemData) + WXJS_DECLARE_METHOD(setItemData) + WXJS_DECLARE_METHOD(getItemTextColour) + WXJS_DECLARE_METHOD(setItemTextColour) + WXJS_DECLARE_METHOD(getItemBackgroundColour) + WXJS_DECLARE_METHOD(setItemBackgroundColour) + WXJS_DECLARE_METHOD(getItemFont) + WXJS_DECLARE_METHOD(setItemFont) + WXJS_DECLARE_METHOD(setItemHasChildren) + WXJS_DECLARE_METHOD(isBold) + WXJS_DECLARE_METHOD(setItemBold) + WXJS_DECLARE_METHOD(setItemDropHighlight) + WXJS_DECLARE_METHOD(isVisible) + WXJS_DECLARE_METHOD(isExpanded) + WXJS_DECLARE_METHOD(isSelected) + WXJS_DECLARE_METHOD(getChildrenCount) + WXJS_DECLARE_METHOD(getItemParent) + WXJS_DECLARE_METHOD(getFirstChild) + WXJS_DECLARE_METHOD(getNextChild) + WXJS_DECLARE_METHOD(getPrevSibling) + WXJS_DECLARE_METHOD(getNextSibling) + WXJS_DECLARE_METHOD(getPrevVisible) + WXJS_DECLARE_METHOD(getNextVisible) + WXJS_DECLARE_METHOD(addRoot) + WXJS_DECLARE_METHOD(appendItem) + WXJS_DECLARE_METHOD(prependItem) + WXJS_DECLARE_METHOD(insertItem) + WXJS_DECLARE_METHOD(deleteItem) + WXJS_DECLARE_METHOD(deleteChildren) + WXJS_DECLARE_METHOD(deleteAllItems) + WXJS_DECLARE_METHOD(expand) + WXJS_DECLARE_METHOD(collapse) + WXJS_DECLARE_METHOD(collapseAndReset) + WXJS_DECLARE_METHOD(toggle) + WXJS_DECLARE_METHOD(unselect) + WXJS_DECLARE_METHOD(unselectAll) + WXJS_DECLARE_METHOD(selectItem) + WXJS_DECLARE_METHOD(ensureVisible) + WXJS_DECLARE_METHOD(scrollTo) + WXJS_DECLARE_METHOD(editLabel) + WXJS_DECLARE_METHOD(endEditLabel) + WXJS_DECLARE_METHOD(sortChildren) + WXJS_DECLARE_METHOD(hitTest) + + WXJS_DECLARE_CONSTANT_MAP() + }; + + class TreeCtrlEventHandler : public EventConnector + , public wxEvtHandler + { + public: + // Events + void onBeginDrag(wxTreeEvent &event); + void onBeginRDrag(wxTreeEvent &event); + void onBeginLabelEdit(wxTreeEvent &event); + void onEndLabelEdit(wxTreeEvent &event); + void onDeleteItem(wxTreeEvent &event); + void onGetInfo(wxTreeEvent &event); + void onSetInfo(wxTreeEvent &event); + void onItemExpanded(wxTreeEvent &event); + void onItemExpanding(wxTreeEvent &event); + void onItemCollapsed(wxTreeEvent &event); + void onItemCollapsing(wxTreeEvent &event); + void onSelChanged(wxTreeEvent &event); + void onSelChanging(wxTreeEvent &event); + void onKeyDown(wxTreeEvent &event); + void onItemActivated(wxTreeEvent &event); + void onItemRightClick(wxTreeEvent &event); + void onItemMiddleClick(wxTreeEvent &event); + void onEndDrag(wxTreeEvent &event); + static void InitConnectEventMap(); + private: + static void ConnectBeginDrag(wxTreeCtrl *p, bool connect); + static void ConnectBeginRDrag(wxTreeCtrl *p, bool connect); + static void ConnectBeginLabelEdit(wxTreeCtrl *p, bool connect); + static void ConnectEndLabelEdit(wxTreeCtrl *p, bool connect); + static void ConnectDeleteItem(wxTreeCtrl *p, bool connect); + static void ConnectGetInfo(wxTreeCtrl *p, bool connect); + static void ConnectSetInfo(wxTreeCtrl *p, bool connect); + static void ConnectItemExpanded(wxTreeCtrl *p, bool connect); + static void ConnectItemExpanding(wxTreeCtrl *p, bool connect); + static void ConnectItemCollapsed(wxTreeCtrl *p, bool connect); + static void ConnectItemCollapsing(wxTreeCtrl *p, bool connect); + static void ConnectSelChanged(wxTreeCtrl *p, bool connect); + static void ConnectSelChanging(wxTreeCtrl *p, bool connect); + static void ConnectKeyDown(wxTreeCtrl *p, bool connect); + static void ConnectItemActivated(wxTreeCtrl *p, bool connect); + static void ConnectItemRightClick(wxTreeCtrl *p, bool connect); + static void ConnectItemMiddleClick(wxTreeCtrl *p, bool connect); + static void ConnectEndDrag(wxTreeCtrl *p, bool connect); + }; + + /** + * Wrapper class for a treeitem. This is necessary + * to protect the JavaScript objects from garbage collection + */ + class ObjectTreeData : public wxTreeItemData + { + public: + ObjectTreeData(JSContext *cx, jsval v) : wxTreeItemData() + , m_cx(cx) + , m_val(v) + { + if ( JSVAL_IS_GCTHING(m_val) ) + JS_AddRoot(m_cx, &m_val); + } + + virtual ~ObjectTreeData() + { + if ( JSVAL_IS_GCTHING(m_val) ) + JS_RemoveRoot(m_cx, &m_val); + } + + inline jsval GetJSVal() + { + return m_val; + } + protected: + private: + JSContext *m_cx; + jsval m_val; + }; + }; // namespace gui +}; // namespace wxjs + +#endif //_WXJSTreeCtrl_H Property changes on: ps/trunk/source/tools/atlas/wxJS/gui/control/treectrl.h ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/gui/control/coldlg.h =================================================================== --- ps/trunk/source/tools/atlas/wxJS/gui/control/coldlg.h (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/gui/control/coldlg.h (revision 5154) @@ -0,0 +1,61 @@ +/* + * wxJavaScript - coldlg.h + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: coldlg.h 672 2007-04-12 20:29:39Z fbraem $ + */ +#ifndef _WXJSColourDialog_H +#define _WXJSColourDialog_H + +#include + +namespace wxjs +{ + namespace gui + { + class ColourDialog : public ApiWrapper + { + public: + static bool GetProperty(wxColourDialog *p, + JSContext *cx, + JSObject *obj, + int id, + jsval *vp); + + static wxColourDialog* Construct(JSContext *cx, + JSObject *obj, + uintN argc, + jsval *argv, + bool constructing); + + static void Destruct(JSContext *cx, wxColourDialog *p); + + WXJS_DECLARE_PROPERTY_MAP() + + enum + { + P_COLOUR_DATA + }; + }; + }; // namespace gui +}; // namespace wxjs + +#endif //_WXJSColourDialog_H Property changes on: ps/trunk/source/tools/atlas/wxJS/gui/control/coldlg.h ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/gui/control/window.h =================================================================== --- ps/trunk/source/tools/atlas/wxJS/gui/control/window.h (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/gui/control/window.h (revision 5154) @@ -0,0 +1,209 @@ +/* + * wxJavaScript - window.h + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: window.h 709 2007-05-14 19:57:41Z fbraem $ + */ +#ifndef _WXJSWINDOW_H +#define _WXJSWINDOW_H + +#include "../../common/evtconn.h" + +namespace wxjs +{ + namespace gui + { + class Window : public ApiWrapper + { + public: + static void InitClass(JSContext* cx, + JSObject* obj, + JSObject* proto); + + static bool GetProperty(wxWindow *p, + JSContext *cx, + JSObject *obj, + int id, + jsval *vp); + static bool SetProperty(wxWindow *p, + JSContext *cx, + JSObject *obj, + int id, + jsval *vp); + static bool GetStaticProperty(JSContext *cx, + int id, + jsval *vp); + + WXJS_DECLARE_METHOD_MAP() + WXJS_DECLARE_METHOD(captureMouse) + WXJS_DECLARE_METHOD(centre) + WXJS_DECLARE_METHOD(clearBackground) + WXJS_DECLARE_METHOD(clientToScreen) + WXJS_DECLARE_METHOD(close) + WXJS_DECLARE_METHOD(move) + WXJS_DECLARE_METHOD(convertDialogToPixels) + WXJS_DECLARE_METHOD(convertPixelsToDialog) + WXJS_DECLARE_METHOD(destroy) + WXJS_DECLARE_METHOD(releaseMouse) + WXJS_DECLARE_METHOD(layout) + WXJS_DECLARE_METHOD(setSize) + WXJS_DECLARE_METHOD(raise) + WXJS_DECLARE_METHOD(lower) + WXJS_DECLARE_METHOD(centreOnParent) + WXJS_DECLARE_METHOD(fit) + WXJS_DECLARE_METHOD(setSizeHints) + WXJS_DECLARE_METHOD(show) + WXJS_DECLARE_METHOD(refresh) + WXJS_DECLARE_METHOD(setFocus) + WXJS_DECLARE_METHOD(findFocus) + WXJS_DECLARE_METHOD(findWindow) + WXJS_DECLARE_METHOD(initDialog) + WXJS_DECLARE_METHOD(transferDataToWindow) + WXJS_DECLARE_METHOD(transferDataFromWindow) + WXJS_DECLARE_METHOD(validate) + WXJS_DECLARE_METHOD(makeModal) + WXJS_DECLARE_METHOD(warpPointer) + WXJS_DECLARE_METHOD(update) + WXJS_DECLARE_METHOD(freeze) + WXJS_DECLARE_METHOD(thaw) + WXJS_DECLARE_METHOD(findWindowById) + WXJS_DECLARE_METHOD(findWindowByLabel) + + WXJS_DECLARE_STATIC_METHOD_MAP() + WXJS_DECLARE_STATIC_PROPERTY_MAP() + WXJS_DECLARE_CONSTANT_MAP() + + WXJS_DECLARE_PROPERTY_MAP() + enum + { + P_CLIENT_HEIGHT = -128 + , P_AUTO_LAYOUT + , P_CLIENT_WIDTH + , P_CLIENT_ORIGIN + , P_ENABLE + , P_HEIGHT + , P_TITLE + , P_VISIBLE + , P_WIDTH + , P_POSITION + , P_SIZE + , P_SIZER + , P_CLIENT_SIZE + , P_ID + , P_RECT + , P_CLIENT_RECT + , P_BEST_SIZE + , P_WINDOW_STYLE + , P_EXTRA_STYLE + , P_SHOWN + , P_TOP_LEVEL + , P_ACCEPTS_FOCUS + , P_ACCEPTS_FOCUS_KEYBOARD + , P_DEFAULT_ITEM + , P_CHILDREN + , P_PARENT + , P_VALIDATOR + , P_ACCELERATOR_TABLE + , P_CAPTURE + , P_HAS_CAPTURE + , P_UPDATE_REGION + , P_BACKGROUND_COLOUR + , P_FOREGROUND_COLOUR + , P_FONT + }; + }; + + class WindowEventHandler : public EventConnector + , public wxEvtHandler + { + public: + void OnChar(wxKeyEvent &event); + void OnKeyDown(wxKeyEvent &event); + void OnKeyUp(wxKeyEvent &event); + void OnCharHook(wxKeyEvent &event); + void OnActivate(wxActivateEvent &event); + void OnSetFocus(wxFocusEvent &event); + void OnKillFocus(wxFocusEvent &event); + void OnMouseEvents(wxMouseEvent &event); + void OnMove(wxMoveEvent &event); + void OnSize(wxSizeEvent &event); + void OnScrollTop(wxScrollWinEvent& event); + void OnScrollBottom(wxScrollWinEvent& event); + void OnScrollLineUp(wxScrollWinEvent& event); + void OnScrollLineDown(wxScrollWinEvent& event); + void OnScrollPageUp(wxScrollWinEvent& event); + void OnScrollPageDown(wxScrollWinEvent& event); + void OnScrollThumbTrack(wxScrollWinEvent& event); + void OnScrollThumbRelease(wxScrollWinEvent& event); + void OnHelp(wxHelpEvent &event); + void OnLeftDown(wxMouseEvent &event); + void OnLeftUp(wxMouseEvent &event); + void OnLeftDClick(wxMouseEvent &event); + void OnMiddleDown(wxMouseEvent &event); + void OnMiddleUp(wxMouseEvent &event); + void OnMiddleDClick(wxMouseEvent &event); + void OnRightDown(wxMouseEvent &event); + void OnRightUp(wxMouseEvent &event); + void OnRightDClick(wxMouseEvent &event); + void OnMotion(wxMouseEvent &event); + void OnEnterWindow(wxMouseEvent &event); + void OnLeaveWindow(wxMouseEvent &event); + void OnMouseWheel(wxMouseEvent &event); + static void InitConnectEventMap(void); + + private: + static void ConnectChar(wxWindow *p, bool connect); + static void ConnectKeyDown(wxWindow *p, bool connect); + static void ConnectKeyUp(wxWindow *p, bool connect); + static void ConnectCharHook(wxWindow *p, bool connect); + static void ConnectActivate(wxWindow *p, bool connect); + static void ConnectSetFocus(wxWindow *p, bool connect); + static void ConnectKillFocus(wxWindow *p, bool connect); + static void ConnectMouseEvents(wxWindow *p, bool connect); + static void ConnectMove(wxWindow *p, bool connect); + static void ConnectSize(wxWindow *p, bool connect); + static void ConnectScrollTop(wxWindow *p, bool connect); + static void ConnectScrollBottom(wxWindow *p, bool connect); + static void ConnectScrollLineUp(wxWindow *p, bool connect); + static void ConnectScrollLineDown(wxWindow *p, bool connect); + static void ConnectScrollPageUp(wxWindow *p, bool connect); + static void ConnectScrollPageDown(wxWindow *p, bool connect); + static void ConnectScrollThumbTrack(wxWindow *p, bool connect); + static void ConnectScrollThumbRelease(wxWindow *p, bool connect); + static void ConnectHelp(wxWindow *p, bool connect); + static void ConnectLeftDown(wxWindow *p, bool connect); + static void ConnectLeftUp(wxWindow *p, bool connect); + static void ConnectLeftDClick(wxWindow *p, bool connect); + static void ConnectMiddleDown(wxWindow *p, bool connect); + static void ConnectMiddleUp(wxWindow *p, bool connect); + static void ConnectMiddleDClick(wxWindow *p, bool connect); + static void ConnectRightDown(wxWindow *p, bool connect); + static void ConnectRightUp(wxWindow *p, bool connect); + static void ConnectRightDClick(wxWindow *p, bool connect); + static void ConnectMotion(wxWindow *p, bool connect); + static void ConnectEnterWindow(wxWindow *p, bool connect); + static void ConnectLeaveWindow(wxWindow *p, bool connect); + static void ConnectMouseWheel(wxWindow *p, bool connect); + }; + }; // namespace gui +}; // namespace wxjs + +#endif // _WXJSWINDOW_H Property changes on: ps/trunk/source/tools/atlas/wxJS/gui/control/window.h ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/gui/control/textctrl.h =================================================================== --- ps/trunk/source/tools/atlas/wxJS/gui/control/textctrl.h (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/gui/control/textctrl.h (revision 5154) @@ -0,0 +1,122 @@ +/* + * wxJavaScript - textctrl.h + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: textctrl.h 695 2007-05-04 20:51:28Z fbraem $ + */ +#ifndef _WXJSTEXTCTRL_H +#define _WXJSTEXTCTRL_H + +#include "../../common/evtconn.h" + +namespace wxjs +{ + namespace gui + { + class TextCtrl : public ApiWrapper + { + public: + static void InitClass(JSContext* cx, + JSObject* obj, + JSObject* proto); + static bool AddProperty(wxTextCtrl *p, + JSContext *cx, + JSObject *obj, + const wxString &prop, + jsval *vp); + static bool DeleteProperty(wxTextCtrl *p, + JSContext* cx, + JSObject* obj, + const wxString &prop); + static bool GetProperty(wxTextCtrl *p, + JSContext *cx, + JSObject *obj, + int id, + jsval *vp); + static bool SetProperty(wxTextCtrl *p, + JSContext *cx, + JSObject *obj, + int id, + jsval *vp); + + static wxTextCtrl* Construct(JSContext *cx, + JSObject *obj, + uintN argc, + jsval *argv, + bool constructing); + + WXJS_DECLARE_METHOD_MAP() + WXJS_DECLARE_METHOD(appendText) + WXJS_DECLARE_METHOD(clear) + WXJS_DECLARE_METHOD(create) + WXJS_DECLARE_METHOD(cut) + WXJS_DECLARE_METHOD(discardEdits) + WXJS_DECLARE_METHOD(getLineLength) + WXJS_DECLARE_METHOD(getLineText) + WXJS_DECLARE_METHOD(setSelection) + WXJS_DECLARE_METHOD(loadFile) + WXJS_DECLARE_METHOD(paste) + WXJS_DECLARE_METHOD(redo) + WXJS_DECLARE_METHOD(replace) + WXJS_DECLARE_METHOD(remove) + WXJS_DECLARE_METHOD(saveFile) + + WXJS_DECLARE_CONSTANT_MAP() + + WXJS_DECLARE_PROPERTY_MAP() + enum + { + P_CAN_COPY + , P_CAN_PASTE + , P_CAN_CUT + , P_CAN_REDO + , P_CAN_UNDO + , P_INSERTION_POINT + , P_NUMBER_OF_LINES + , P_SELECTION_FROM + , P_SELECTION_TO + , P_VALUE + , P_MODIFIED + , P_LAST_POSITION + , P_EDITABLE + }; + }; + + class TextCtrlEventHandler : public EventConnector + , public wxEvtHandler + { + public: + // Events + void OnText(wxCommandEvent &event); + void OnTextEnter(wxCommandEvent &event); + void OnTextURL(wxCommandEvent &event); + void OnTextMaxLen(wxCommandEvent &event); + static void InitConnectEventMap(); + private: + static void ConnectText(wxTextCtrl *p, bool connect); + static void ConnectTextEnter(wxTextCtrl *p, bool connect); + static void ConnectTextURL(wxTextCtrl *p, bool connect); + static void ConnectTextMaxLen(wxTextCtrl *p, bool connect); + }; + }; // namespace gui +}; // namespace wxjs + +#endif //_WXJSTEXTCTRL_H Property changes on: ps/trunk/source/tools/atlas/wxJS/gui/control/textctrl.h ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/gui/control/listbox.cpp =================================================================== --- ps/trunk/source/tools/atlas/wxJS/gui/control/listbox.cpp (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/gui/control/listbox.cpp (revision 5154) @@ -0,0 +1,448 @@ +#include "precompiled.h" + +/* + * wxJavaScript - listbox.cpp + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: listbox.cpp 710 2007-05-14 20:05:10Z fbraem $ + */ + +#ifndef WX_PRECOMP + #include +#endif + +#include "../../common/main.h" +#include "../../common/index.h" + + +#include "../event/jsevent.h" +#include "../event/command.h" + +#include "../misc/point.h" +#include "../misc/size.h" +#include "../misc/validate.h" + +#include "listbox.h" +#include "item.h" +#include "window.h" +#include "../errors.h" + +using namespace wxjs; +using namespace wxjs::gui; + +/*** + * control/listbox + * gui + * + * A listbox is used to select one or more of a list of strings. + * The strings are displayed in a scrolling box, with the selected + * string(s) marked in reverse video. A listbox can be single selection + * (if an item is selected, the previous selection is removed) or + * multiple selection (clicking an item toggles the item on or off + * independently of other selections). + * + */ +WXJS_INIT_CLASS(ListBox, "wxListBox", 2) + +void ListBox::InitClass(JSContext* WXUNUSED(cx), + JSObject* WXUNUSED(obj), + JSObject* WXUNUSED(proto)) +{ + ListBoxEventHandler::InitConnectEventMap(); +} + +/*** + * + * + * An array with all the indexes of the selected items + * + * + */ +WXJS_BEGIN_PROPERTY_MAP(ListBox) + WXJS_READONLY_PROPERTY(P_SELECTIONS, "selections") +WXJS_END_PROPERTY_MAP() + +bool ListBox::GetProperty(wxListBox* p, + JSContext *cx, + JSObject* WXUNUSED(obj), + int id, + jsval *vp) +{ + switch (id) + { + case P_SELECTIONS: + { + wxArrayInt selections; + jsint count = p->GetSelections(selections); + JSObject *objSelections = JS_NewArrayObject(cx, count, NULL); + *vp = OBJECT_TO_JSVAL(objSelections); + for(jsint i = 0; i < count; i++) + { + jsval element = ToJS(cx, selections[i]); + JS_SetElement(cx, objSelections, i, &element); + } + break; + } + } + return true; +} + +bool ListBox::AddProperty(wxListBox *p, + JSContext* WXUNUSED(cx), + JSObject* WXUNUSED(obj), + const wxString &prop, + jsval* WXUNUSED(vp)) +{ + if ( WindowEventHandler::ConnectEvent(p, prop, true) ) + return true; + + ListBoxEventHandler::ConnectEvent(p, prop, true); + + return true; +} + +bool ListBox::DeleteProperty(wxListBox *p, + JSContext* WXUNUSED(cx), + JSObject* WXUNUSED(obj), + const wxString &prop) +{ + if ( WindowEventHandler::ConnectEvent(p, prop, false) ) + return true; + + ListBoxEventHandler::ConnectEvent(p, prop, false); + return true; +} + +/*** + * + * + * + * + * + * + * + * + * + * + * + */ +WXJS_BEGIN_CONSTANT_MAP(ListBox) + WXJS_CONSTANT(wxLB_, SINGLE) + WXJS_CONSTANT(wxLB_, MULTIPLE) + WXJS_CONSTANT(wxLB_, EXTENDED) + WXJS_CONSTANT(wxLB_, HSCROLL) + WXJS_CONSTANT(wxLB_, ALWAYS_SB) + WXJS_CONSTANT(wxLB_, NEEDED_SB) + WXJS_CONSTANT(wxLB_, SORT) +WXJS_END_CONSTANT_MAP() + +/*** + * + * + * + * + * The parent of the wxListBox. null is not Allowed. + * + * + * The windows identifier. -1 can be used when you don't need a unique id. + * + * + * The position of the listbox. + * + * + * The size of the listbox. + * + * + * The items for the listbox. + * + * + * The style of listbox. You can use the @wxListBox#style. + * + * + * + * + * Creates a new wxListBox object + * + * + */ +wxListBox* ListBox::Construct(JSContext *cx, + JSObject *obj, + uintN argc, + jsval *argv, + bool WXUNUSED(constructing)) +{ + wxListBox *p = new wxListBox(); + SetPrivate(cx, obj, p); + + if ( argc > 0 ) + { + jsval rval; + create(cx, obj, argc, argv, &rval); + } + return p; +} + +WXJS_BEGIN_METHOD_MAP(ListBox) + WXJS_METHOD("create", create, 2) + WXJS_METHOD("setFirstItem", set_first_item, 1) + WXJS_METHOD("insertItems", insert_items, 1) +WXJS_END_METHOD_MAP() + +/*** + * + * + * + * The parent of the wxListBox. null is not Allowed. + * + * + * The windows identifier. -1 can be used when you don't need a unique id. + * + * + * The position of the listbox. + * + * + * The size of the listbox. + * + * + * The items for the listbox. + * + * + * The style of listbox. You can use the @wxListBox#style. + * + * + * + * + * Creates a wxListBox + * + * + */ +JSBool ListBox::create(JSContext *cx, + JSObject *obj, + uintN argc, + jsval *argv, + jsval *rval) +{ + wxListBox *p = GetPrivate(cx, obj); + *rval = JSVAL_FALSE; + + const wxPoint *pt = &wxDefaultPosition; + const wxSize *size = &wxDefaultSize; + int style = 0; + StringsPtr items; + const wxValidator *val = &wxDefaultValidator; + + if ( argc > 7 ) + argc = 7; + + switch(argc) + { + case 7: + val = Validator::GetPrivate(cx, argv[6]); + if ( val == NULL ) + break; + case 6: + if ( ! FromJS(cx, argv[5], style) ) + break; + // Fall through + case 5: + if ( ! FromJS(cx, argv[4], items) ) + break; + // Fall through + case 4: + size = Size::GetPrivate(cx, argv[3]); + if ( size == NULL ) + break; + // Fall through + case 3: + pt = Point::GetPrivate(cx, argv[2]); + if ( pt == NULL ) + break; + // Fall through + default: + int id; + if ( ! FromJS(cx, argv[1], id) ) + break; + + wxWindow *parent = Window::GetPrivate(cx, argv[0]); + if ( parent == NULL ) + { + JS_ReportError(cx, WXJS_NO_PARENT_ERROR, GetClass()->name); + return JS_FALSE; + } + JavaScriptClientData *clntParent = + dynamic_cast(parent->GetClientObject()); + if ( clntParent == NULL ) + { + JS_ReportError(cx, WXJS_NO_PARENT_ERROR, GetClass()->name); + return JS_FALSE; + } + JS_SetParent(cx, obj, clntParent->GetObject()); + + if ( p->Create(parent, id, *pt, *size, + items.GetCount(), items.GetStrings(), style, *val) ) + { + *rval = JSVAL_TRUE; + p->SetClientObject(new JavaScriptClientData(cx, obj, true, false)); + } + } + + return JS_TRUE; +} + +/*** + * + * + * + * The zero-based item index + * + * + * + * + * The string that should be visible + * + * + * + * Set the specified item to be the first visible item. Windows only. + * + * + */ +JSBool ListBox::set_first_item(JSContext *cx, + JSObject *obj, + uintN WXUNUSED(argc), + jsval *argv, + jsval* WXUNUSED(rval)) +{ + wxListBox *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + int idx; + if ( FromJS(cx, argv[0], idx) ) + p->SetFirstItem(idx); + else + { + wxString item; + FromJS(cx, argv[0], item); + p->SetFirstItem(item); + } + return JS_TRUE; +} + +/*** + * + * + * + * + * Position before which to insert the items: for example, if + * pos is 0 (= the default) the items will be inserted in the + * beginning of the listbox + * + * + * + * Inserts all the items + * + * + */ +JSBool ListBox::insert_items(JSContext *cx, + JSObject *obj, + uintN argc, + jsval *argv, + jsval* WXUNUSED(rval)) +{ + wxListBox *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + StringsPtr items; + if ( FromJS(cx, argv[0], items) ) + { + int pos = 0; + if ( argc > 0 + && ! FromJS(cx, argv[1], pos) ) + return JS_FALSE; + + p->InsertItems(items.GetCount(), items.GetStrings(), pos); + return JS_TRUE; + } + + return JS_FALSE; +} + +/*** + * + * + * Called when an item is selected. + * The type of the argument that your handler receives is @wxCommandEvent. + * + * + * Called when the listbox is double clicked. + * The type of the argument that your handler receives is @wxCommandEvent. + * + * + */ + +WXJS_INIT_EVENT_MAP(wxListBox) +const wxString WXJS_LISTBOX_EVENT = wxT("onListBox"); +const wxString WXJS_DOUBLECLICK_EVENT = wxT("onDoubleClicked"); + +void ListBoxEventHandler::OnListBox(wxCommandEvent &event) +{ + PrivCommandEvent::Fire(event, WXJS_LISTBOX_EVENT); +} + +void ListBoxEventHandler::OnDoubleClick(wxCommandEvent &event) +{ + PrivCommandEvent::Fire(event, WXJS_DOUBLECLICK_EVENT); +} + +void ListBoxEventHandler::ConnectListBox(wxListBox *p, bool connect) +{ + if ( connect ) + { + p->Connect(wxEVT_COMMAND_LISTBOX_SELECTED, + wxCommandEventHandler(OnListBox)); + } + else + { + p->Disconnect(wxEVT_COMMAND_LISTBOX_SELECTED, + wxCommandEventHandler(OnListBox)); + } +} + +void ListBoxEventHandler::ConnectDoubleClick(wxListBox *p, bool connect) +{ + if ( connect ) + { + p->Connect(wxEVT_COMMAND_LISTBOX_DOUBLECLICKED, + wxCommandEventHandler(OnListBox)); + } + else + { + p->Disconnect(wxEVT_COMMAND_LISTBOX_DOUBLECLICKED, + wxCommandEventHandler(OnListBox)); + } +} + +void ListBoxEventHandler::InitConnectEventMap() +{ + AddConnector(WXJS_LISTBOX_EVENT, ConnectListBox); + AddConnector(WXJS_DOUBLECLICK_EVENT, ConnectDoubleClick); +} Property changes on: ps/trunk/source/tools/atlas/wxJS/gui/control/listbox.cpp ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/gui/control/gauge.cpp =================================================================== --- ps/trunk/source/tools/atlas/wxJS/gui/control/gauge.cpp (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/gui/control/gauge.cpp (revision 5154) @@ -0,0 +1,339 @@ +#include "precompiled.h" + +/* + * wxJavaScript - gauge.cpp + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: gauge.cpp 708 2007-05-14 15:30:45Z fbraem $ + */ +// gauge.cpp + +#ifndef WX_PRECOMP + #include +#endif + +#include "../../common/main.h" + + + +#include "../misc/point.h" +#include "../misc/size.h" +#include "../misc/validate.h" + +#include "gauge.h" +#include "window.h" +#include "../errors.h" + +using namespace wxjs; +using namespace wxjs::gui; + +/*** + * control/gauge + * gui + * + * A gauge is a horizontal or vertical bar which shows a quantity (often time). + * + */ +WXJS_INIT_CLASS(Gauge, "wxGauge", 3) + +/*** + * + * + * Get/Set the width of the 3D bezel face. Windows only + * + * + * Get/Set the maximum position of the gauge. + * + * + * Get/Set the 3D shadow margin width. Windows only + * + * + * Get/Set the current value of the gauge. + * + * + */ +WXJS_BEGIN_PROPERTY_MAP(Gauge) + WXJS_PROPERTY(P_BEZEL_FACE, "bezelFace") + WXJS_PROPERTY(P_RANGE, "range") + WXJS_PROPERTY(P_SHADOW_WIDTH, "shadowWidth") + WXJS_PROPERTY(P_VALUE, "value") +WXJS_END_PROPERTY_MAP() + +bool Gauge::GetProperty(wxGauge *p, + JSContext *cx, + JSObject* WXUNUSED(obj), + int id, + jsval *vp) +{ + switch (id) + { + case P_BEZEL_FACE: + *vp = ToJS(cx, p->GetBezelFace()); + break; + case P_RANGE: + *vp = ToJS(cx, p->GetRange()); + break; + case P_SHADOW_WIDTH: + *vp = ToJS(cx, p->GetShadowWidth()); + break; + case P_VALUE: + *vp = ToJS(cx, p->GetValue()); + break; + } + return true; +} + +bool Gauge::SetProperty(wxGauge *p, + JSContext *cx, + JSObject* WXUNUSED(obj), + int id, + jsval *vp) +{ + switch (id) + { + case P_BEZEL_FACE: + { + int value; + if ( FromJS(cx, *vp, value) ) + p->SetBezelFace(value); + break; + } + case P_RANGE: + { + int value; + if ( FromJS(cx, *vp, value) ) + p->SetRange(value); + break; + } + case P_SHADOW_WIDTH: + { + int value; + if ( FromJS(cx, *vp, value) ) + p->SetShadowWidth(value); + break; + } + case P_VALUE: + { + int value; + if ( FromJS(cx, *vp, value) ) + p->SetValue(value); + break; + } + } + return true; +} + +bool Gauge::AddProperty(wxGauge *p, + JSContext* WXUNUSED(cx), + JSObject* WXUNUSED(obj), + const wxString &prop, + jsval* WXUNUSED(vp)) +{ + return WindowEventHandler::ConnectEvent(p, prop, true); +} + + +bool Gauge::DeleteProperty(wxGauge *p, + JSContext* WXUNUSED(cx), + JSObject* WXUNUSED(obj), + const wxString &prop) +{ + return WindowEventHandler::ConnectEvent(p, prop, false); +} + +/*** + * + * + * + * + * + * + * + * + */ +WXJS_BEGIN_CONSTANT_MAP(Gauge) + WXJS_CONSTANT(wxGA_, HORIZONTAL) + WXJS_CONSTANT(wxGA_, VERTICAL) + WXJS_CONSTANT(wxGA_, PROGRESSBAR) + WXJS_CONSTANT(wxGA_, SMOOTH) +WXJS_END_CONSTANT_MAP() + +/*** + * + * + * + * + * The parent of wxGauge. + * + * + * An window identifier. Use -1 when you don't need it. + * + * + * The maximum value of the gauge + * + * + * The position of the Gauge control on the given parent. + * + * + * The size of the Gauge control. + * + * + * The wxGauge style. + * + * + * + * + * Constructs a new wxGauge object. + * + * + */ +wxGauge *Gauge::Construct(JSContext *cx, + JSObject *obj, + uintN argc, + jsval *argv, + bool WXUNUSED(constructing)) +{ + wxGauge *p = new wxGauge(); + SetPrivate(cx, obj, p); + + if ( argc > 0 ) + { + jsval rval; + create(cx, obj, argc, argv, &rval); + } + return p; +} + +WXJS_BEGIN_METHOD_MAP(Gauge) + WXJS_METHOD("create", create, 3) +WXJS_END_METHOD_MAP() + +/*** + * + * + * + * The parent of wxGauge. + * + * + * An window identifier. Use -1 when you don't need it. + * + * + * The maximum value of the gauge + * + * + * The position of the Gauge control on the given parent. + * + * + * The size of the Gauge control. + * + * + * The wxGauge style. + * + * + * + * + * Creates a wxGauge + * + * + */ +JSBool Gauge::create(JSContext *cx, + JSObject *obj, + uintN argc, + jsval *argv, + jsval *rval) +{ + wxGauge *p = GetPrivate(cx, obj); + *rval = JSVAL_FALSE; + + int style = 0; + const wxPoint *pt = &wxDefaultPosition; + const wxSize *size = &wxDefaultSize; + const wxValidator *val = &wxDefaultValidator; + + switch(argc) + { + case 7: + val = Validator::GetPrivate(cx, argv[6]); + if ( val == NULL ) + { + JS_ReportError(cx, WXJS_INVALID_ARG_TYPE, 7, "wxValidator"); + return JS_FALSE; + } + case 6: + if ( ! FromJS(cx, argv[5], style) ) + { + JS_ReportError(cx, WXJS_INVALID_ARG_TYPE, 6, "Integer"); + return JS_FALSE; + } + // Fall through + case 5: + size = Size::GetPrivate(cx, argv[4]); + if ( size == NULL ) + { + JS_ReportError(cx, WXJS_INVALID_ARG_TYPE, 5, "wxSize"); + return JS_FALSE; + } + case 4: + pt = Point::GetPrivate(cx, argv[3]); + if ( pt == NULL ) + { + JS_ReportError(cx, WXJS_INVALID_ARG_TYPE, 4, "wxPoint"); + return JS_FALSE; + } + default: + int range; + if ( ! FromJS(cx, argv[2], range) ) + { + JS_ReportError(cx, WXJS_INVALID_ARG_TYPE, 3, "Integer"); + return JS_FALSE; + } + + int id; + if ( ! FromJS(cx, argv[1], id) ) + { + JS_ReportError(cx, WXJS_INVALID_ARG_TYPE, 2, "Integer"); + return JS_FALSE; + } + + wxWindow *parent = Window::GetPrivate(cx, argv[0]); + if ( parent == NULL ) + { + JS_ReportError(cx, WXJS_NO_PARENT_ERROR, GetClass()->name); + return JS_FALSE; + } + JavaScriptClientData *clntParent = + dynamic_cast(parent->GetClientObject()); + if ( clntParent == NULL ) + { + JS_ReportError(cx, WXJS_NO_PARENT_ERROR, GetClass()->name); + return JS_FALSE; + } + JS_SetParent(cx, obj, clntParent->GetObject()); + + if ( p->Create(parent, id, range, *pt, *size, style, *val) ) + { + *rval = JSVAL_TRUE; + p->SetClientObject(new JavaScriptClientData(cx, obj, true, false)); + } + } + + return JS_TRUE; +} Property changes on: ps/trunk/source/tools/atlas/wxJS/gui/control/gauge.cpp ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/gui/control/staticbx.h =================================================================== --- ps/trunk/source/tools/atlas/wxJS/gui/control/staticbx.h (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/gui/control/staticbx.h (revision 5154) @@ -0,0 +1,57 @@ +/* + * wxJavaScript - staticbx.h + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: staticbx.h 694 2007-05-03 21:14:13Z fbraem $ + */ +#ifndef _WXJSStaticBox_H +#define _WXJSStaticBox_H + +namespace wxjs +{ + namespace gui + { + class StaticBox : public ApiWrapper + { + public: + + static bool AddProperty(wxStaticBox *p, + JSContext *cx, + JSObject *obj, + const wxString &prop, + jsval *vp); + static bool DeleteProperty(wxStaticBox *p, + JSContext* cx, + JSObject* obj, + const wxString &prop); + static wxStaticBox* Construct(JSContext *cx, + JSObject *obj, + uintN argc, + jsval *argv, + bool constructing); + + WXJS_DECLARE_METHOD_MAP() + WXJS_DECLARE_METHOD(create) + }; + }; // namespace gui +}; // namespace wxjs + +#endif //_WXJSStaticBox_H Property changes on: ps/trunk/source/tools/atlas/wxJS/gui/control/staticbx.h ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/gui/control/listctrl.cpp =================================================================== --- ps/trunk/source/tools/atlas/wxJS/gui/control/listctrl.cpp (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/gui/control/listctrl.cpp (revision 5154) @@ -0,0 +1,3104 @@ +#include "precompiled.h" + +/* + * wxJavaScript - listctrl.cpp + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: listctrl.cpp 734 2007-06-06 20:09:13Z fbraem $ + */ +// ListCtrl.cpp +#include +#ifndef WX_PRECOMP + #include +#endif + +#ifdef __WXMSW__ + #include "commctrl.h" +#endif + +#include "../../common/main.h" + + +#include "../event/jsevent.h" +#include "../event/listevt.h" + +#include "../misc/app.h" +#include "../misc/validate.h" +#include "../misc/point.h" +#include "../misc/size.h" +#include "../misc/rect.h" +#include "../misc/colour.h" +#include "../misc/imagelst.h" + +#include "listctrl.h" +#include "listitem.h" +#include "listitattr.h" +#include "listhit.h" +#include "window.h" +#include "textctrl.h" +#include "../errors.h" + +using namespace wxjs; +using namespace wxjs::gui; + +ListCtrl::ListCtrl() : wxListCtrl() +{ +} + +ListCtrl::~ListCtrl() +{ + // Destroy all item data + int n = GetItemCount(); + long i = 0; + + for (i = 0; i < n; i++) + { + ListObjectData *wxjs_data = (ListObjectData*) GetItemData(i); + if ( wxjs_data != NULL ) + { + delete wxjs_data; + wxjs_data = NULL; + } + } +} + +int wxCALLBACK ListCtrl::SortFn(long item1, long item2, long data) +{ + ListSort *sortData = reinterpret_cast(data); + + ListObjectData *data1 = (ListObjectData*) item1; + ListObjectData *data2 = (ListObjectData*) item2; + + jsval rval; + jsval argv[] = { data1 == NULL ? JSVAL_VOID : data1->GetJSVal(), + data2 == NULL ? JSVAL_VOID : data2->GetJSVal(), + ToJS(sortData->GetContext(), sortData->GetData()) + }; + if ( JS_CallFunction(sortData->GetContext(), JS_GetGlobalObject(sortData->GetContext()), sortData->GetFn(), 3, argv, &rval) == JS_TRUE ) + { + int rc; + if ( FromJS(sortData->GetContext(), rval, rc) ) + return rc; + else + return 0; + } + else + { + JS_ReportError(sortData->GetContext(), "Error occurred while running sort function of wxListCtrl"); + } + return 0; +} + +/*** + * control/listctrl + * gui + * + * A list control presents lists in a number of formats: list view, report view, + * icon view and small icon view. In any case, elements are numbered from zero. + * For all these modes, the items are stored in the control and must be added to + * it using @wxListCtrl#insertItem method. + *

+ * A special case of report view quite different from the other modes of the + * list control is a virtual control in which the items data (including text, + * images and attributes) is managed by the main program and is requested by + * the control itself only when needed which allows to have controls with millions + * of items without consuming much memory. To use virtual list control you must set + * @wxListCtrl#itemCount first and set at least @wxListCtrl#onGetItemText + * (and optionally @wxListCtrl#onGetItemImage and @wxListCtrl#onGetItemAttr) + * to return the information about the items when the control requests it. + * Virtual list control can be used as a normal one except that no operations + * which can take time proportional to the number of items in the control happen + * -- this is required to allow having a practically infinite number of items. + * For example, in a multiple selection virtual list control, the selections won't be + * sent when many items are selected at once because this could mean iterating + * over all the items. + *

How to sort items?
+ * This example shows a dialog containing a wxListCtrl and two buttons. + * The list control contains 4 elements 'A', 'B', 'C' and 'D'. Clicking + * on one of the buttons, will sort the elements in + * descending or ascending order. First the dialog box is created. + * A @wxBoxSizer is used to layout + * the dialog. The list control will be shown above the buttons and centered + * horizontally. Above and below the listcontrol a space of 10 is placed. + *

+ *   dlg = new wxDialog(null, -1, "wxListCtrl sort example", 
+ *                      wxDefaultPosition, new wxSize(200, 200));
+ *   // The main sizer
+ *   dlg.sizer = new wxBoxSizer(wxOrientation.VERTICAL);
+ *
+ *   // Create the listcontrol and add it to the sizer.
+ *   list = new wxListCtrl(dlg, -1, wxDefaultPosition, new wxSize(100, 100));
+ *   dlg.sizer.add(list, 0, wxAlignment.CENTER | wxDirection.BOTTOM | wxDirection.TOP, 10);
+ *
+ *   // Create buttons and add them to a boxsizer.
+ *   var btn1 = new wxButton(dlg, -1, "Sort Descending");
+ *   btn1.onClicked = function()
+ *   {
+ *     list.sortItems(sort, 1);
+ *   };
+ *  
+ *   var btn2 = new wxButton(dlg, -2, "Sort Ascending");
+ *   btn2.onClicked = function()
+ *   {
+ *     list.sortItems(sort, 0);
+ *   };
+ *
+ *   boxsizer = new wxBoxSizer(wxOrientation.HORIZONTAL);
+ *   boxsizer.add(btn1, 0, wxDirection.RIGHT, 10);
+ *   boxsizer.add(btn2);
+ *
+ *   dlg.sizer.add(boxsizer, 0, wxAlignment.CENTER);
+ *   
+ * An array which hold the characters 'A', 'B', 'C' and 'D' is created. Each element is + * inserted. The itemdata is set to the letter. This is necessary + * because the sort function uses the itemdata. + *
 
+ *   var letter = new Array();
+ *   letter[0] = "A";
+ *   letter[1] = "B";
+ *   letter[2] = "C";
+ *   letter[3] = "D";
+ *   for(e in letter)
+ *   {
+ *     var idx = list.insertItem(e, letter[e]);
+ *     list.setItemData(idx, letter[e]);
+ *   }
+ *  
+ * Show the dialog. + *

+ *   dlg.layout();
+ *   dlg.showModal();
+ *  
+ * + * The function gets 3 arguments. The first two are the itemdata (which is the index + * of the corresponding array element) of the first item and the second item. Data + * is the data passed to @wxListCtrl#sortItems in the @wxButton#onClicked event + * of @wxButton. This way the sort function knows how to sort the items. + *

+ *   function sort(item1, item2, data)
+ *   {
+ *     if ( data == 1 )
+ *     {
+ *       if ( item1 > item2 )
+ *         return -1;
+ *       else if ( item1 < item2 )
+ *         return 1;
+ *       else return 0;
+ *     }
+ *     else
+ *     {
+ *       if ( item1 > item2 )
+ *         return 1;
+ *       else if ( item1 < item2 )
+ *         return -1;
+ *       else return 0;
+ *     }
+ *   }
+ *   
+ *
How to use virtual list controls ?
+ * This example shows how a virtual list control is built. + * First an array is create which will contain objects of type Car. + *

+ *   var cars = new Array();
+ *
+ *   function Car(brand, type, colour)
+ *   {
+ *     this.brand = brand;
+ *     this.type = type;
+ *     this.colour = colour;
+ *   }
+ *
+ *   cars[0] = new Car("Opel", "Astra", "Red");
+ *   cars[1] = new Car("Ford", "Focus", "Black");
+ *   cars[2] = new Car("Skoda", "Octavia", "Green");
+ *   cars[3] = new Car("Peugeot", "305", "White");
+ *   cars[4] = new Car("Citroen", "Picasso", "Green");
+ *   
+ * The init function will create a frame and a list control. The list control + * is the child of the frame and its style is REPORT and VIRTUAL. For each property + * of Car, a column is created. + * Because the list control is virtual, @wxListCtrl#onGetItemText and + * @wxListCtrl#itemCount must be set. + *

+ *   function init()
+ *   {
+ *     var frame = new wxFrame(null, -1, "wxListCtrl example");
+ *   
+ *     var listCtrl = new wxListCtrl(frame, -1, wxDefaultPosition,
+ *                                   wxDefaultSize, wxListCtrl.REPORT | wxListCtrl.VIRTUAL);
+ *     listCtrl.insertColumn(0, "Brand");
+ *     listCtrl.insertColumn(1, "Type");
+ *     listCtrl.insertColumn(2, "Colour");
+ *     listCtrl.onGetItemText = getItemText;
+ *     listCtrl.itemCount = cars.length;
+ *     
+ *     frame.visible = true;
+ *     topWindow = frame;
+ *     
+ *     return true;
+ *     }
+ *   
+ * The function getItemText will be called by wxWidgets whenever it needs + * to know the text of an item. This function gets two arguments: the item and the column + * index. The text that must be shown is returned. + *

+ *   function getItemText(item, col)
+ *   {
+ *     var car = cars[item];
+ *   
+ *     switch(col)
+ *     {
+ *       case 0: return car.brand;
+ *       case 1: return car.type;
+ *       case 2: return car.colour;    
+ *     }
+ *   }
+ *   
+ *   wxTheApp.onInit = init;
+ *   wxTheApp.mainLoop();
+ *  
+ *
+ */ +WXJS_INIT_CLASS(ListCtrl, "wxListCtrl", 2) + +/*** + * + * + * + * + * + * + * + * + * + * + * wxListMask is ported as a separate JavaScript class + * + * + * + * + * (Windows only) + * + * + * (Windows only) + * + * wxListState is ported as a separate JavaScript class + * + * + * + * Searches for an item above the specified item + * Searches for subsequent item by index + * Searches for an item below the specified item + * Searches for an item to the left of the specified item + * Searches for an item to the right of the specified item + * + * wxListNext is ported as a separate JavaScript class. See @wxListCtrl#getNextItem. + * + * + * + * + * + * + * + * + * wxListAlign is ported as a separate JavaScript class. + * + * + * + * + * + * + * + * + * wxListColumnFormat is ported as a separate JavaScript class. + * + * + * + * + * + * + * + * wxListRect is ported as a separate JavaScript class. + * + * + * + * + * + * + * + * + * wxListFind is ported as a separate JavaScript class. + * + * + * + * + * Multicolumn list view, with optional small icons. Columns are computed automatically, + * i.e. you don't set columns as in REPORT. In other words, the list wraps, unlike a + * wxListBox. + * + * Single or multicolumn report view, with optional header. + * + * Virtual control, may only be used with REPORT + * + * Large icon view, with optional labels. + * + * Small icon view, with optional labels. + * + * Icons align to the top. Win32 default, Win32 only. + * + * Icons align to the left. + * + * Icons arrange themselves. Win32 only. + * + * The application provides label text on demand, except for column headers. Win32 only. + * + * Labels are editable: the application will be notified when editing starts. + * + * No header in report mode. Win32 only. + * + * Single selection. + * + * Sort in ascending order (must still supply a comparison callback in SortItems). + * + * Sort in descending order (must still supply a comparison callback in SortItems). + * + * Draws light horizontal rules between rows in report mode. + * + * Draws light vertical rules between columns in report mode. + * + * + * + * Resize the column to the length of its longest item + * + * Resize the column to the length of the header (Win32) or 80 pixels (other platforms). + * These constants can be used with @wxListCtrl#setColumnWidth. + * + * + * + * The normal (large icon) image list. + * + * The small icon image list. + * + * The user-defined state image list (unimplemented). + * + * + */ +WXJS_BEGIN_CONSTANT_MAP(ListCtrl) + WXJS_CONSTANT(wxLC_, LIST) + WXJS_CONSTANT(wxLC_, REPORT) + WXJS_CONSTANT(wxLC_, VIRTUAL) + WXJS_CONSTANT(wxLC_, ICON) + WXJS_CONSTANT(wxLC_, SMALL_ICON) + WXJS_CONSTANT(wxLC_, ALIGN_TOP) + WXJS_CONSTANT(wxLC_, ALIGN_LEFT) + WXJS_CONSTANT(wxLC_, AUTOARRANGE) + WXJS_CONSTANT(wxLC_, USER_TEXT) + WXJS_CONSTANT(wxLC_, EDIT_LABELS) + WXJS_CONSTANT(wxLC_, NO_HEADER) + WXJS_CONSTANT(wxLC_, SINGLE_SEL) + WXJS_CONSTANT(wxLC_, SORT_ASCENDING) + WXJS_CONSTANT(wxLC_, SORT_DESCENDING) + WXJS_CONSTANT(wxLC_, HRULES) + WXJS_CONSTANT(wxLIST_, AUTOSIZE) + WXJS_CONSTANT(wxLIST_, AUTOSIZE_USEHEADER) + WXJS_CONSTANT(wxIMAGE_LIST_, NORMAL) + WXJS_CONSTANT(wxIMAGE_LIST_, SMALL) + WXJS_CONSTANT(wxIMAGE_LIST_, STATE) +WXJS_END_CONSTANT_MAP() + +void ListCtrl::InitClass(JSContext* cx, + JSObject* obj, + JSObject* WXUNUSED(proto)) +{ + ListCtrlEventHandler::InitConnectEventMap(); + + JSConstDoubleSpec wxListMaskMap[] = + { + WXJS_CONSTANT(wxLIST_MASK_, STATE) + WXJS_CONSTANT(wxLIST_MASK_, TEXT) + WXJS_CONSTANT(wxLIST_MASK_, IMAGE) + WXJS_CONSTANT(wxLIST_MASK_, DATA) + WXJS_CONSTANT(wxLIST_SET_, ITEM) + WXJS_CONSTANT(wxLIST_MASK_, WIDTH) + WXJS_CONSTANT(wxLIST_MASK_, FORMAT) + { 0 } + }; + JSObject *constObj = JS_DefineObject(cx, obj, "wxListMask", + NULL, NULL, + JSPROP_READONLY | JSPROP_PERMANENT); + JS_DefineConstDoubles(cx, constObj, wxListMaskMap); + + JSConstDoubleSpec wxListStateMap[] = + { + WXJS_CONSTANT(wxLIST_STATE_, DONTCARE) + WXJS_CONSTANT(wxLIST_STATE_, DROPHILITED) + WXJS_CONSTANT(wxLIST_STATE_, FOCUSED) + WXJS_CONSTANT(wxLIST_STATE_, SELECTED) + WXJS_CONSTANT(wxLIST_STATE_, CUT) + { 0 } + }; + constObj = JS_DefineObject(cx, obj, "wxListState", + NULL, NULL, + JSPROP_READONLY | JSPROP_PERMANENT); + JS_DefineConstDoubles(cx, constObj, wxListStateMap); + + JSConstDoubleSpec wxListNextMap[] = + { + WXJS_CONSTANT(wxLIST_NEXT_, ABOVE) + WXJS_CONSTANT(wxLIST_NEXT_, ALL) + WXJS_CONSTANT(wxLIST_NEXT_, BELOW) + WXJS_CONSTANT(wxLIST_NEXT_, LEFT) + WXJS_CONSTANT(wxLIST_NEXT_, RIGHT) + { 0 } + }; + constObj = JS_DefineObject(cx, obj, "wxListNext", + NULL, NULL, + JSPROP_READONLY | JSPROP_PERMANENT); + JS_DefineConstDoubles(cx, constObj, wxListNextMap); + + JSConstDoubleSpec wxListAlignMap[] = + { + WXJS_CONSTANT(wxLIST_ALIGN_, DEFAULT) + WXJS_CONSTANT(wxLIST_ALIGN_, LEFT) + WXJS_CONSTANT(wxLIST_ALIGN_, TOP) + WXJS_CONSTANT(wxLIST_ALIGN_, SNAP_TO_GRID) + { 0 } + }; + constObj = JS_DefineObject(cx, obj, "wxListAlign", + NULL, NULL, + JSPROP_READONLY | JSPROP_PERMANENT); + JS_DefineConstDoubles(cx, constObj, wxListAlignMap); + + JSConstDoubleSpec wxListColumnFormatMap[] = + { + WXJS_CONSTANT(wxLIST_FORMAT_, LEFT) + WXJS_CONSTANT(wxLIST_FORMAT_, RIGHT) + WXJS_CONSTANT(wxLIST_FORMAT_, CENTRE) + WXJS_CONSTANT(wxLIST_FORMAT_, CENTER) + { 0 } + }; + constObj = JS_DefineObject(cx, obj, "wxListColumnFormat", + NULL, NULL, + JSPROP_READONLY | JSPROP_PERMANENT); + JS_DefineConstDoubles(cx, constObj, wxListColumnFormatMap); + + JSConstDoubleSpec wxListRectMap[] = + { + WXJS_CONSTANT(wxLIST_RECT_, BOUNDS) + WXJS_CONSTANT(wxLIST_RECT_, ICON) + WXJS_CONSTANT(wxLIST_RECT_, LABEL) + { 0 } + }; + constObj = JS_DefineObject(cx, obj, "wxListRect", + NULL, NULL, + JSPROP_READONLY | JSPROP_PERMANENT); + JS_DefineConstDoubles(cx, constObj, wxListRectMap); + + JSConstDoubleSpec wxListFindMap[] = + { + WXJS_CONSTANT(wxLIST_FIND_, UP) + WXJS_CONSTANT(wxLIST_FIND_, DOWN) + WXJS_CONSTANT(wxLIST_FIND_, LEFT) + WXJS_CONSTANT(wxLIST_FIND_, RIGHT) + { 0 } + }; + constObj = JS_DefineObject(cx, obj, "wxListFind", + NULL, NULL, + JSPROP_READONLY | JSPROP_PERMANENT); + JS_DefineConstDoubles(cx, constObj, wxListFindMap); +} + + +/*** + * + * + * Gets the number of columns. + * + * + * Gets the number of items that can fit vertically in the visible area of the list control + * (list or report view) or the total number of items in the list control + * (icon or small icon view). + * + * + * Gets the textcontrol used for editing labels. + * + * + * Returns true when the list control is virtual. + * + * + * Gets/Sets the number of items. Setting the number of items is only allowed + * with virtual list controls. + * + * + * Assign a function that returns a @wxListItemAttr object. + * The function gets one argument: the index of the item. + * This can only be used in virtual list controls. + * + * + * Assign a function that returns the index of the image. + * The function gets one argument: the index of the item. + * This can only be used in virtual list controls. + * + * + * Assign a function that returns a String. This String is used as text of the item. + * The function gets two arguments: the index of the item and the index of the column. + * You must set this property for virtual list controls. + * + * + * Gets the number of selected items. + * + * + * Gets/Sets the text colour of the list control. + * + * + * Gets the index of the topmost visible item in report view. + * + * + * Gets/Sets the window style flag. + * + * + */ +WXJS_BEGIN_PROPERTY_MAP(ListCtrl) + WXJS_READONLY_PROPERTY(P_COLUMN_COUNT, "columnCount") + WXJS_READONLY_PROPERTY(P_COUNT_PER_PAGE, "countPerPage") + WXJS_READONLY_PROPERTY(P_EDIT_CONTROL, "editControl") + WXJS_PROPERTY(P_ITEM_COUNT, "itemCount") + WXJS_READONLY_PROPERTY(P_SELECTED_ITEM_COUNT, "selectedItemCount") + WXJS_PROPERTY(P_TEXT_COLOUR, "textColour") + WXJS_READONLY_PROPERTY(P_TOP_ITEM, "topItem") + WXJS_PROPERTY(P_WINDOW_STYLE, "windowStyleFlag") + WXJS_READONLY_PROPERTY(P_IS_VIRTUAL, "virtual") +WXJS_END_PROPERTY_MAP() + +wxString ListCtrl::OnGetItemText(long item, long column) const +{ + JavaScriptClientData *data + = dynamic_cast(GetClientObject()); + JSContext *cx = data->GetContext(); + JSObject *obj = data->GetObject(); + + jsval fval; + if ( GetFunctionProperty(cx, obj, "onGetItemText", &fval) == JS_FALSE ) + return wxEmptyString; + + jsval rval; + jsval argv[] = { ToJS(cx, item), ToJS(cx, column) }; + if ( JS_CallFunctionValue(cx, obj, fval, 2, argv, &rval) == JS_TRUE ) + { + wxString text; + FromJS(cx, rval, text); + return text; + } + else + { + if ( JS_IsExceptionPending(cx) ) + { + JS_ReportPendingException(cx); + } + } + return wxEmptyString; +} + +int ListCtrl::OnGetItemImage(long item) const +{ + JavaScriptClientData *data + = dynamic_cast(GetClientObject()); + JSContext *cx = data->GetContext(); + JSObject *obj = data->GetObject(); + + jsval fval; + if ( GetFunctionProperty(cx, obj, "onGetItemImage", &fval) == JS_FALSE ) + return -1; + + jsval rval; + jsval argv[] = { ToJS(cx, item) }; + if ( JS_CallFunctionValue(cx, obj, fval, 1, argv, &rval) == JS_TRUE ) + { + int img; + if ( FromJS(cx, rval, img) ) + return img; + else + return -1; + } + else + { + if ( JS_IsExceptionPending(cx) ) + { + JS_ReportPendingException(cx); + } + } + return -1; +} + +wxListItemAttr *ListCtrl::OnGetItemAttr(long item) const +{ + JavaScriptClientData *data + = dynamic_cast(GetClientObject()); + JSContext *cx = data->GetContext(); + JSObject *obj = data->GetObject(); + + jsval fval; + if ( GetFunctionProperty(cx, obj, "onGetItemText", &fval) == JS_FALSE ) + return NULL; + + jsval rval; + jsval argv[] = { ToJS(cx, item) }; + if ( JS_CallFunctionValue(cx, obj, fval, 1, argv, &rval) == JS_TRUE ) + { + wxListItemAttr *attr = ListItemAttr::GetPrivate(cx, rval); + return attr; + } + else + { + if ( JS_IsExceptionPending(cx) ) + { + JS_ReportPendingException(cx); + } + } + return NULL; +} + +bool ListCtrl::GetProperty(wxListCtrl *p, + JSContext *cx, + JSObject *obj, + int id, + jsval *vp) +{ + switch (id) + { + case P_COLUMN_COUNT: + *vp = ToJS(cx, p->GetColumnCount()); + break; + case P_COUNT_PER_PAGE: + *vp = ToJS(cx, p->GetCountPerPage()); + break; + case P_EDIT_CONTROL: + #ifdef __WXMSW__ + *vp = TextCtrl::CreateObject(cx, p->GetEditControl(), obj); + #endif + break; + case P_ITEM_COUNT: + *vp = ToJS(cx, p->GetColumnCount()); + break; + case P_SELECTED_ITEM_COUNT: + *vp = ToJS(cx, p->GetSelectedItemCount()); + break; + case P_TEXT_COLOUR: + *vp = Colour::CreateObject(cx, new wxColour(p->GetTextColour())); + break; + case P_TOP_ITEM: + *vp = ToJS(cx, p->GetTopItem()); + break; + case P_WINDOW_STYLE: + *vp = ToJS(cx, p->GetWindowStyleFlag()); + break; + case P_IS_VIRTUAL: + *vp = ToJS(cx, p->IsVirtual()); + break; + } + return true; +} + +bool ListCtrl::SetProperty(wxListCtrl *p, + JSContext *cx, + JSObject* WXUNUSED(obj), + int id, + jsval *vp) +{ + switch (id) + { + case P_ITEM_COUNT: + { + long count; + if ( p->IsVirtual() + && FromJS(cx, *vp, count) ) + p->SetItemCount(count); + break; + } + case P_TEXT_COLOUR: + { + wxColour *colour = Colour::GetPrivate(cx, *vp); + if ( colour != NULL ) + p->SetTextColour(*colour); + break; + } + case P_WINDOW_STYLE: + { + long style; + if ( FromJS(cx, *vp, style) ) + p->SetWindowStyleFlag(style); + break; + } + } + return true; +} + +bool ListCtrl::AddProperty(wxListCtrl *p, + JSContext* WXUNUSED(cx), + JSObject* WXUNUSED(obj), + const wxString &prop, + jsval* WXUNUSED(vp)) +{ + if ( WindowEventHandler::ConnectEvent(p, prop, true) ) + return true; + + ListCtrlEventHandler::ConnectEvent(p, prop, true); + + return true; +} + + +bool ListCtrl::DeleteProperty(wxListCtrl *p, + JSContext* WXUNUSED(cx), + JSObject* WXUNUSED(obj), + const wxString &prop) +{ + if ( WindowEventHandler::ConnectEvent(p, prop, false) ) + return true; + + ListCtrlEventHandler::ConnectEvent(p, prop, false); + return true; +} + + +/*** + * + * + * + * + * The parent of wxListCtrl. Can't be null. + * + * + * An window identifier. Use -1 when you don't need it. + * + * + * The position of the ListCtrl control on the given parent. + * + * + * The size of the ListCtrl control. + * + * + * The wxListCtrl style. + * + * + * Validator. + * + * + * + * Constructs a new wxListCtrl object. + * + * + */ +wxListCtrl* ListCtrl::Construct(JSContext *cx, + JSObject *obj, + uintN argc, + jsval *argv, + bool WXUNUSED(constructing)) +{ + wxListCtrl *p = new ListCtrl(); + SetPrivate(cx, obj, p); + if ( argc > 0 ) + { + jsval rval; + create(cx, obj, argc, argv, &rval); + } + return p; +} + +WXJS_BEGIN_METHOD_MAP(ListCtrl) + WXJS_METHOD("create", create, 2) + WXJS_METHOD("getColumn", getColumn, 2) + WXJS_METHOD("setColumn", setColumn, 2) + WXJS_METHOD("getColumnWidth", getColumnWidth, 1) + WXJS_METHOD("setColumnWidth", setColumnWidth, 2) + WXJS_METHOD("getItem", getItem, 1) + WXJS_METHOD("setItem", setItem, 1) + WXJS_METHOD("getItemState", getItemState, 2) + WXJS_METHOD("setItemState", setItemState, 3) + WXJS_METHOD("setItemImage", setItemImage, 3) + WXJS_METHOD("getItemText", getItemText, 1) + WXJS_METHOD("setItemText", setItemText, 2) + WXJS_METHOD("getItemData", getItemData, 1) + WXJS_METHOD("setItemData", setItemData, 2) + WXJS_METHOD("getItemRect", getItemRect, 2) + WXJS_METHOD("getItemPosition", getItemPosition, 1) + WXJS_METHOD("setItemPosition", setItemPosition, 2) + WXJS_METHOD("getItemSpacing", getItemSpacing, 1) + WXJS_METHOD("setSingleStyle", setSingleStyle, 1) + WXJS_METHOD("getNextItem", getNextItem, 1) + WXJS_METHOD("getImageList", getImageList, 1) + WXJS_METHOD("setImageList", setImageList, 2) + WXJS_METHOD("refreshItem", refreshItem, 1) + WXJS_METHOD("refreshItems", refreshItems, 2) + WXJS_METHOD("arrange", arrange, 0) + WXJS_METHOD("deleteItem", deleteItem, 1) + WXJS_METHOD("deleteAllItems", deleteAllItems, 0) + WXJS_METHOD("deleteColumn", deleteColumn, 1) + WXJS_METHOD("deleteAllColumns", deleteAllColumns, 0) + WXJS_METHOD("clearAll", clearAll, 0) + WXJS_METHOD("insertItem", insertItem, 1) + WXJS_METHOD("insertColumn", insertColumn, 2) + WXJS_METHOD("editLabel", editLabel, 1) + WXJS_METHOD("endEditLabel", endEditLabel, 1) + WXJS_METHOD("ensureVisible", ensureVisible, 1) + WXJS_METHOD("findItem", findItem, 2) + WXJS_METHOD("hitTest", hitTest, 1) + WXJS_METHOD("scrollList", scrollList, 2) + WXJS_METHOD("sortItems", sortItems, 1) +WXJS_END_METHOD_MAP() + +/*** + * + * + * + * The parent of wxListCtrl. Can't be null. + * + * + * An window identifier. Use -1 when you don't need it. + * + * + * The position of the ListCtrl control on the given parent. + * + * + * The size of the ListCtrl control. + * + * + * The wxListCtrl style. + * + * + * Validator. + * + * + * + * Constructs a new wxListCtrl object. + * + * + */ +JSBool ListCtrl::create(JSContext *cx, + JSObject *obj, + uintN argc, + jsval *argv, + jsval *rval) +{ + wxListCtrl *p = GetPrivate(cx, obj); + *rval = JSVAL_FALSE; + + if ( argc > 6 ) + argc = 6; + + int style = wxLC_ICON; + const wxPoint *pt = &wxDefaultPosition; + const wxSize *size = &wxDefaultSize; + const wxValidator *val = &wxDefaultValidator; + + switch(argc) + { + case 6: + val = Validator::GetPrivate(cx, argv[5]); + if ( val == NULL ) + { + JS_ReportError(cx, WXJS_INVALID_ARG_TYPE, 6, "wxValidator"); + return JS_FALSE; + } + case 5: + if ( ! FromJS(cx, argv[4], style) ) + { + JS_ReportError(cx, WXJS_INVALID_ARG_TYPE, 5, "Integer"); + return JS_FALSE; + } + case 4: + size = Size::GetPrivate(cx, argv[3]); + if ( size == NULL ) + { + JS_ReportError(cx, WXJS_INVALID_ARG_TYPE, 4, "wxSize"); + return JS_FALSE; + } + // Fall through +case 3: + pt = Point::GetPrivate(cx, argv[2]); + if ( pt == NULL ) + { + JS_ReportError(cx, WXJS_INVALID_ARG_TYPE, 3, "wxPoint"); + return JS_FALSE; + } + // Fall through + default: + + int id; + if ( ! FromJS(cx, argv[1], id) ) + { + JS_ReportError(cx, WXJS_INVALID_ARG_TYPE, 2, "Integer"); + return JS_FALSE; + } + + wxWindow *parent = Window::GetPrivate(cx, argv[0]); + if ( parent == NULL ) + { + JS_ReportError(cx, WXJS_NO_PARENT_ERROR, GetClass()->name); + return JS_FALSE; + } + JavaScriptClientData *clntParent = + dynamic_cast(parent->GetClientObject()); + if ( clntParent == NULL ) + { + JS_ReportError(cx, WXJS_NO_PARENT_ERROR, GetClass()->name); + return JS_FALSE; + } + JS_SetParent(cx, obj, clntParent->GetObject()); + + if ( p->Create(parent, id, *pt, *size, style, *val) ) + { + *rval = JSVAL_TRUE; + p->SetClientObject(new JavaScriptClientData(cx, obj, true, false)); + } + } + return JS_TRUE; +} + +/*** + * + * + * + * The column number + * + * + * The item index + * + * + * + * + * The column number + * + * + * The item info. Make sure that the id property is set. + * + * + * + * Gets the column information. The first form returns a @wxListItem object or + * undefined when the column is not found. The second form returns true when the + * column is found and puts the column information in the second argument. + * + * + */ +JSBool ListCtrl::getColumn(JSContext* cx, + JSObject* obj, + uintN WXUNUSED(argc), + jsval* argv, + jsval* rval) +{ + wxListCtrl *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + int col; + if ( FromJS(cx, argv[0], col) ) + { + if ( ListItem::HasPrototype(cx, argv[1]) ) + { + wxListItem *item = ListItem::GetPrivate(cx, argv[1], false); + *rval = ToJS(cx, p->GetColumn(col, *item)); + } + else + { + int idx; + if ( FromJS(cx, argv[1], idx) ) + { + wxListItem *item = new wxListItem(); + item->SetId(idx); + if ( p->GetColumn(col, *item) ) + { + *rval = ListItem::CreateObject(cx, item, obj); + } + else + { + delete item; + *rval = JSVAL_VOID; + } + } + else + { + return JS_FALSE; + } + } + } + else + { + return JS_FALSE; + } + + return JS_TRUE; +} + +/*** + * + * + * + * The column number + * + * + * The item index + * + * + * + * + * The column number + * + * + * The item info. Make sure that the id property is set. + * + * + * + * Sets the column information. False is returned when the column doesn't exist. + * + * + */ +JSBool ListCtrl::setColumn(JSContext *cx, + JSObject *obj, + uintN WXUNUSED(argc), + jsval *argv, + jsval* WXUNUSED(rval)) +{ + wxListCtrl *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + int col; + + if ( ! FromJS(cx, argv[0], col) ) + return JS_FALSE; + + wxListItem *item = ListItem::GetPrivate(cx, argv[1]); + if ( item == NULL ) + return JS_FALSE; + + p->SetColumn(col, *item); + + return JS_TRUE; +} + +/*** + * + * + * + * The column number + * + * + * + * Returns the width of the column. + * + * + */ +JSBool ListCtrl::getColumnWidth(JSContext *cx, + JSObject *obj, + uintN WXUNUSED(argc), + jsval *argv, + jsval *rval) +{ + wxListCtrl *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + int col; + if ( FromJS(cx, argv[0], col) ) + { + *rval = ToJS(cx, p->GetColumnWidth(col)); + return JS_TRUE; + } + + return JS_FALSE; +} + +/*** + * + * + * + * The column number. In small or normal icon view, col must be -1, and the column + * width is set for all columns. + * + * + * Width can be the width in pixels, AUTOSIZE or AUTOSIZE_USEHEADER. + * AUTOSIZE will resize the column to the length of the longest item. + * AUTOSIZE_USEHEADER will resize the column to the length of the header + * (on windows) or on 80 pixels (other platforms). + * + * + * + * Sets the columnwidth. Returns true on success, false on failure. + * See @wxListCtrl#autosize. + * + * + */ +JSBool ListCtrl::setColumnWidth(JSContext *cx, + JSObject *obj, + uintN WXUNUSED(argc), + jsval *argv, + jsval *rval) +{ + wxListCtrl *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + int col; + if ( ! FromJS(cx, argv[0], col) ) + return JS_FALSE; + + int width; + if ( ! FromJS(cx, argv[1], width) ) + return JS_FALSE; + + *rval = ToJS(cx, p->SetColumnWidth(col, width)); + return JS_TRUE; +} + +/*** + * + * + * + * The item index + * + * + * + * + * The item info. Make sure that the id property is set. + * + * + * + * Gets the item information. The first form returns a @wxListItem object or + * undefined when the item is not found. The second form returns true when the + * item is found and puts the item information in the argument. + * + * + */ +JSBool ListCtrl::getItem(JSContext *cx, + JSObject *obj, + uintN WXUNUSED(argc), + jsval *argv, + jsval *rval) +{ + wxListCtrl *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + if ( ListItem::HasPrototype(cx, argv[0]) ) + { + wxListItem *item = ListItem::GetPrivate(cx, argv[0], false); + *rval = ToJS(cx, p->GetItem(*item)); + } + else + { + int idx; + if ( FromJS(cx, argv[0], idx) ) + { + wxListItem *item = new wxListItem(); + item->SetId(idx); + if ( p->GetItem(*item) ) + { + *rval = ListItem::CreateObject(cx, item, obj); + } + else + { + delete item; + *rval = JSVAL_VOID; + } + } + else + return JS_FALSE; + } + + return JS_TRUE; +} + +/*** + * + * + * + * The item info + * + * + * + * + * The item index + * + * + * The column index + * + * + * The text of the item + * + * + * The zero-base index of an image list. + * + * + * + * Sets the item information. On success, true is returned. + * + * + */ +JSBool ListCtrl::setItem(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxListCtrl *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + if ( ListItem::HasPrototype(cx, argv[0]) ) + { + wxListItem *item = ListItem::GetPrivate(cx, argv[0], false); + *rval = ToJS(cx, p->SetItem(*item)); + } + else + { + if ( argc < 3 ) + return JS_FALSE; + + int imageId = -1; + if ( argc > 3 + && ! FromJS(cx, argv[3], imageId) ) + return JS_FALSE; + + wxString label; + FromJS(cx, argv[2], label); + + int idx; + int col; + + if ( FromJS(cx, argv[1], col) + && FromJS(cx, argv[0], idx) ) + { + *rval = ToJS(cx, p->SetItem(idx, col, label, imageId)); + } + else + return JS_FALSE; + } + return JS_TRUE; +} + +/*** + * + * + * + * The item index + * + * + * Indicates which state flags are valid. + * + * + * + * Gets the item state. See @wxListCtrl#wxListState. + * + * + */ +JSBool ListCtrl::getItemState(JSContext *cx, + JSObject *obj, + uintN WXUNUSED(argc), + jsval *argv, + jsval *rval) +{ + wxListCtrl *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + long item; + int stateMask; + + if ( FromJS(cx, argv[0], item) + && FromJS(cx, argv[1], stateMask) ) + { + *rval = ToJS(cx, p->GetItemState(item, stateMask)); + return JS_TRUE; + } + + return JS_FALSE; +} + +/*** + * + * + * + * The item index. + * + * + * The new state. + * + * + * Indicates which state flags are valid. + * + * + * + * Sets the new state of an item. See @wxListCtrl#wxListState. + * + * + */ +JSBool ListCtrl::setItemState(JSContext *cx, + JSObject *obj, + uintN WXUNUSED(argc), + jsval *argv, + jsval *rval) +{ + wxListCtrl *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + long item; + long state; + long stateMask; + + if ( FromJS(cx, argv[0], item) + && FromJS(cx, argv[1], state) + && FromJS(cx, argv[2], stateMask) ) + { + *rval = ToJS(cx, p->SetItemState(item, state, stateMask)); + return JS_TRUE; + } + + return JS_FALSE; +} + +/*** + * + * + * + * The item index. + * + * + * Index of the image to show for unselected items. + * + * + * Index of the image to show for selected items. + * + * + * + * Sets the unselected and selected images associated with the item. + * The images are indices into the image list associated with the list control. + * + * + */ +JSBool ListCtrl::setItemImage(JSContext *cx, + JSObject *obj, + uintN WXUNUSED(argc), + jsval *argv, + jsval *rval) +{ + wxListCtrl *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + long item; + int image; + int selImage; + + if ( FromJS(cx, argv[0], item) + && FromJS(cx, argv[1], image) + && FromJS(cx, argv[2], selImage) ) + { + *rval = ToJS(cx, p->SetItemImage(item, image, selImage)); + return JS_TRUE; + } + + return JS_FALSE; +} + +/*** + * + * + * + * The item index. + * + * + * + * Returns the text of the item. + * + * + */ +JSBool ListCtrl::getItemText(JSContext *cx, + JSObject *obj, + uintN WXUNUSED(argc), + jsval *argv, + jsval *rval) +{ + wxListCtrl *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + long item; + + if ( FromJS(cx, argv[0], item) ) + { + *rval = ToJS(cx, p->GetItemText(item)); + return JS_TRUE; + } + + return JS_FALSE; +} + +/*** + * + * + * + * The item index. + * + * + * The new text. + * + * + * + * Sets the text of an item. + * + * + */ +JSBool ListCtrl::setItemText(JSContext *cx, + JSObject *obj, + uintN WXUNUSED(argc), + jsval *argv, + jsval* WXUNUSED(rval)) +{ + wxListCtrl *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + long item; + wxString text; + + if ( FromJS(cx, argv[0], item) + && FromJS(cx, argv[1], text) ) + { + p->SetItemText(item, text); + return JS_TRUE; + } + + return JS_FALSE; +} + +/*** + * + * + * + * The item index. + * + * + * + * Returns the associated data of the item. The type of the data can be any type: + * integer, long, object, ... + * + * + */ +JSBool ListCtrl::getItemData(JSContext *cx, + JSObject *obj, + uintN WXUNUSED(argc), + jsval *argv, + jsval *rval) +{ + wxListCtrl *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + long item; + if ( FromJS(cx, argv[0], item) ) + { + ListObjectData *data = (ListObjectData*) p->GetItemData(item); + *rval = ( data == NULL ) ? JSVAL_VOID : data->GetJSVal(); + return JS_TRUE; + } + + return JS_FALSE; +} + +/*** + * + * + * + * The item index. + * + * + * The associated data. + * + * + * + * Sets the associated data of an item. The type of the data can + * be any type: integer, long, object, ... + * When the listcontrol is sortable, the item data must be set. + * + * + */ +JSBool ListCtrl::setItemData(JSContext *cx, + JSObject *obj, + uintN WXUNUSED(argc), + jsval *argv, + jsval *rval) +{ + wxListCtrl *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + long item; + + if ( FromJS(cx, argv[0], item) ) + { + ListObjectData *data = (ListObjectData*) p->GetItemData(item); + if ( data != NULL ) + { + delete data; + data = NULL; + } + + data = new ListObjectData(cx, argv[1]); + if ( p->SetItemData(item, (long) data) ) + { + *rval = JSVAL_TRUE; + } + else + { + *rval = JSVAL_FALSE; + delete data; + data = NULL; + } + return JS_TRUE; + } + + return JS_FALSE; +} + +/*** + * + * + * + * The item index. + * + * + * Indicates which rectangle to return. + * + * + * + * Returns the item rectangle. See @wxListCtrl#wxListRect. + * + * + */ +JSBool ListCtrl::getItemRect(JSContext *cx, + JSObject *obj, + uintN WXUNUSED(argc), + jsval *argv, + jsval *rval) +{ + wxListCtrl *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + long item; + int code; + + if ( FromJS(cx, argv[0], item) + && FromJS(cx, argv[1], code) ) + { + wxRect *rect = new wxRect(); + if ( p->GetItemRect(item, *rect, code) ) + { + *rval = Rect::CreateObject(cx, rect); + } + else + { + delete rect; + *rval = JSVAL_VOID; + } + return JS_TRUE; + } + + return JS_FALSE; +} + +/*** + * + * + * + * The item index. + * + * + * + * Returns the position of the item in icon or small icon view. + * Returns undefined on failure. + * + * + */ +JSBool ListCtrl::getItemPosition(JSContext *cx, + JSObject *obj, + uintN WXUNUSED(argc), + jsval *argv, + jsval *rval) +{ + wxListCtrl *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + long item; + + if ( FromJS(cx, argv[0], item) ) + { + wxPoint *pt = new wxPoint(); + if ( p->GetItemPosition(item, *pt) ) + { + *rval = Point::CreateObject(cx, pt); + } + else + { + delete pt; + *rval = JSVAL_VOID; + } + return JS_TRUE; + } + + return JS_FALSE; +} + +/*** + * + * + * + * The item index. + * + * + * The new position + * + * + * + * Sets the item position in icon or small icon view. Returns true on success. + * + * + */ +JSBool ListCtrl::setItemPosition(JSContext *cx, + JSObject *obj, + uintN WXUNUSED(argc), + jsval *argv, + jsval *rval) +{ + wxListCtrl *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + long item; + if ( FromJS(cx, argv[0], item) ) + { + wxPoint *pt = Point::GetPrivate(cx, argv[1]); + if ( pt != NULL ) + { + *rval = ToJS(cx, p->SetItemPosition(item, *pt)); + return JS_TRUE; + } + } + + return JS_FALSE; +} + +/*** + * + * + * + * When true, the item spacing for small icon view is returned. Otherwise + * the item spacing for large icon view is returned. + * + * + * + * Returns the item spacing used in icon view. + * + * + */ +JSBool ListCtrl::getItemSpacing(JSContext *cx, + JSObject *obj, + uintN WXUNUSED(argc), + jsval* WXUNUSED(argv), + jsval* rval) +{ + wxListCtrl *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + +#if wxCHECK_VERSION(2,7,0) + *rval = Size::CreateObject(cx, new wxSize(p->GetItemSpacing())); +#else + bool isSmall; + + if ( FromJS(cx, argv[0], isSmall) ) + { + *rval = ToJS(cx, p->GetItemSpacing(isSmall)); + } +#endif + return JS_TRUE; +} + +/*** + * + * + * + * A window style. + * + * + * When true (= default), the style is added. Otherwise the style is removed. + * + * + * + * Adds or removes a single window style. + * + * + */ +JSBool ListCtrl::setSingleStyle(JSContext *cx, + JSObject *obj, + uintN argc, + jsval *argv, + jsval* WXUNUSED(rval)) +{ + wxListCtrl *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + long style; + + if ( ! FromJS(cx, argv[0], style) ) + return JS_FALSE; + + bool add = true; + if ( argc > 1 + && ! FromJS(cx, argv[1], add) ) + return JS_FALSE; + + p->SetSingleStyle(style, add); + + return JS_TRUE; +} + +/*** + * + * + * + * The start item. Use -1 to start from the beginning. + * + * + * Search direction. Use one of the constants defined in @wxListCtrl#wxListNext. + * + * + * A state. Use one of the constants defined in @wxListCtrl#wxListState. + * + * + * + * Searches for an item with the given goemetry or state, starting from item but + * excluding the item itself. If item is -1, the first item that matches the specified + * flags will be returned.
+ * The following example iterates all selected items: + *

+ *    var item = -1;
+ *    do
+ *    {
+ *      item = listctrl.getNextItem(item, wxListNext.ALL, wxListState.SELECTED);
+ *    } 
+ *    while(item != -1);
+ *   
+ *
+ *
+ */ +JSBool ListCtrl::getNextItem(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxListCtrl *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + if ( argc > 3 ) + argc = 3; + + int state = wxLIST_STATE_DONTCARE; + int next = wxLIST_NEXT_ALL; + + switch(argc) + { + case 3: + if ( ! FromJS(cx, argv[2], state) ) + return JS_FALSE; + // Fall through + case 2: + if ( ! FromJS(cx, argv[1], next) ) + return JS_FALSE; + // Fall through + default: + long item; + if ( ! FromJS(cx, argv[0], item) ) + return JS_FALSE; + + *rval = ToJS(cx, p->GetNextItem(item, next, state)); + } + + return JS_TRUE; +} + +/*** + * + * + * + * Type of the imagelist. + * + * + * + * Returns the associated imagelist. + * + * + */ +JSBool ListCtrl::getImageList(JSContext *cx, + JSObject *obj, + uintN WXUNUSED(argc), + jsval *argv, + jsval *rval) +{ + wxListCtrl *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + int which; + if ( FromJS(cx, argv[0], which) ) + { + ImageList *imgList = dynamic_cast(p->GetImageList(which)); + JavaScriptClientData *data + = dynamic_cast(imgList->GetClientObject()); + if ( data != NULL ) + { + *rval = OBJECT_TO_JSVAL(data->GetObject()); + } + return JS_TRUE; + } + + return JS_FALSE; +} + +/*** + * + * + * + * + * Type of the imagelist. + * + * + * + * Sets the imagelist associated with the control. + * + * + */ +JSBool ListCtrl::setImageList(JSContext *cx, + JSObject *obj, + uintN WXUNUSED(argc), + jsval *argv, + jsval* WXUNUSED(rval)) +{ + wxListCtrl *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + ImageList *imgList = ImageList::GetPrivate(cx, argv[0]); + int which; + if ( FromJS(cx, argv[1], which) ) + { + p->AssignImageList(imgList, which); + JavaScriptClientData *data + = dynamic_cast(imgList->GetClientObject()); + if ( data != NULL ) + { + data->Protect(true); + data->SetOwner(false); + } + return JS_TRUE; + } + + return JS_FALSE; +} + +/*** + * + * + * + * The item index. + * + * + * + * Refreshes the item. Only useful for virtual list controls. + * + * + */ +JSBool ListCtrl::refreshItem(JSContext *cx, + JSObject *obj, + uintN WXUNUSED(argc), + jsval *argv, + jsval* WXUNUSED(rval)) +{ + wxListCtrl *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + long item; + if ( FromJS(cx, argv[0], item) ) + { + p->RefreshItem(item); + return JS_TRUE; + } + + return JS_FALSE; +} + +/*** + * + * + * + * The item index to start from. + * + * + * The item index of the last item to refresh. + * + * + * + * Refreshes a range of items. Only useful for virtual list controls. + * + * + */ +JSBool ListCtrl::refreshItems(JSContext *cx, + JSObject *obj, + uintN WXUNUSED(argc), + jsval* argv, + jsval* WXUNUSED(rval)) +{ + wxListCtrl *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + long start; + long end; + + if ( FromJS(cx, argv[0], start) + && FromJS(cx, argv[0], end) ) + { + p->RefreshItems(start, end); + return JS_TRUE; + } + + return JS_FALSE; +} + +/*** + * + * + * + * + * + * Arranges the items in icon or small icon view. (Windows only) + * See @wxListCtrl#wxListAlign + * + * + */ +JSBool ListCtrl::arrange(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxListCtrl *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + int flag = wxLIST_ALIGN_DEFAULT; + if ( argc > 0 + && !FromJS(cx, argv[0], flag) ) + return JS_FALSE; + + *rval = ToJS(cx, p->Arrange(flag)); + return JS_TRUE; +} + +/*** + * + * + * + * The item index. + * + * + * + * Deletes the item. Returns true on success. + * + * + */ +JSBool ListCtrl::deleteItem(JSContext *cx, + JSObject *obj, + uintN WXUNUSED(argc), + jsval *argv, + jsval *rval) +{ + wxListCtrl *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + long item; + + if ( FromJS(cx, argv[0], item) ) + { + *rval = ToJS(cx, p->DeleteItem(item)); + return JS_TRUE; + } + + return JS_FALSE; +} + +/*** + * + * + * + * Deletes all items. Returns true on success. + * + * + */ +JSBool ListCtrl::deleteAllItems(JSContext *cx, + JSObject *obj, + uintN WXUNUSED(argc), + jsval* WXUNUSED(argv), + jsval* rval) +{ + wxListCtrl *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + *rval = ToJS(cx, p->DeleteAllItems()); + return JS_TRUE; +} + +/*** + * + * + * + * The column index. + * + * + * + * Deletes the column. Returns true on success. + * + * + */ +JSBool ListCtrl::deleteColumn(JSContext *cx, + JSObject *obj, + uintN WXUNUSED(argc), + jsval* argv, + jsval *rval) +{ + wxListCtrl *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + long col; + + if ( FromJS(cx, argv[0], col) ) + { + *rval = ToJS(cx, p->DeleteColumn(col)); + return JS_TRUE; + } + + return JS_FALSE; +} + +/*** + * + * + * + * Deletes all columns. Returns true on success. + * + * + */ +JSBool ListCtrl::deleteAllColumns(JSContext *cx, + JSObject *obj, + uintN WXUNUSED(argc), + jsval* WXUNUSED(argv), + jsval *rval) +{ + wxListCtrl *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + *rval = ToJS(cx, p->DeleteAllColumns()); + return JS_TRUE; +} + +/*** + * + * + * + * Deletes all items and columns. + * + * + */ +JSBool ListCtrl::clearAll(JSContext *cx, + JSObject *obj, + uintN WXUNUSED(argc), + jsval* WXUNUSED(argv), + jsval* WXUNUSED(rval)) +{ + wxListCtrl *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + p->ClearAll(); + return JS_TRUE; +} + +/*** + * + * + * + * A column index + * + * + * The item + * + * + * + * + * A column index + * + * + * The name for the header. + * + * + * The format of the header. Use one of the constants of @wxListCtrl#wxListColumnFormat. + * + * + * The width of the column. + * + * + * + * Inserts a column. On success, the index of the new column is returned. On failure, -1 is returned. + * + * + */ +JSBool ListCtrl::insertColumn(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxListCtrl *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + long col; + if ( ! FromJS(cx, argv[0], col) ) + return JS_FALSE; + + if ( ListItem::HasPrototype(cx, argv[1]) ) + { + wxListItem *item = ListItem::GetPrivate(cx, argv[1], false); + *rval = ToJS(cx, p->InsertColumn(col, *item)); + } + else + { + wxString header; + FromJS(cx, argv[1], header); + + int format = wxLIST_FORMAT_LEFT; + int width = -1; + + if ( argc == 3 + && ! FromJS(cx, argv[2], format) ) + return JS_FALSE; + + if ( argc == 4 + && ! FromJS(cx, argv[3], width) ) + return JS_FALSE; + + *rval = ToJS(cx, p->InsertColumn(col, header, format, width)); + } + + return JS_TRUE; +} + +/*** + * + * + * + * Item information + * + * + * + * + * The item index. + * + * + * Label of the item + * + * + * The index of the image in the associated imagelist + * + * + * + * + * The item index. + * + * + * The index of the image in the associated imagelist. + * + * + * + * Inserts an item. On success, the index of the new item is returned. On failure, -1 is returned. + * + * + */ +JSBool ListCtrl::insertItem(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxListCtrl *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + if ( ListItem::HasPrototype(cx, argv[0]) ) + { + wxListItem *item = ListItem::GetPrivate(cx, argv[0], false); + *rval = ToJS(cx, p->InsertItem(*item)); + return JS_TRUE; + } + else if ( argc > 1 ) + { + long item; + if ( FromJS(cx, argv[0], item) ) + { + int imageIdx; + if ( JSVAL_IS_INT(argv[1]) ) + { + imageIdx = JSVAL_TO_INT(argv[1]); + *rval = ToJS(cx, p->InsertItem(item, imageIdx)); + return JS_TRUE; + } + else + { + wxString label; + FromJS(cx, argv[1], label); + if ( argc > 2 ) + { + if ( FromJS(cx, argv[2], imageIdx) ) + { + *rval = ToJS(cx, p->InsertItem(item, label, imageIdx)); + return JS_TRUE; + } + } + else + { + *rval = ToJS(cx, p->InsertItem(item, label)); + return JS_TRUE; + } + } + } + } + return JS_FALSE; +} + +/*** + * + * + * + * The item index. + * + * + * + * Edit the label. The text control is returned (on Windows). + * + * + */ +JSBool ListCtrl::editLabel(JSContext *cx, + JSObject *obj, + uintN WXUNUSED(argc), + jsval *argv, + jsval *rval) +{ + wxListCtrl *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + long item; + + if ( FromJS(cx, argv[0], item) ) + { + p->EditLabel(item); + #ifdef __WXMSW__ + *rval = TextCtrl::CreateObject(cx, p->GetEditControl()); + #endif + return JS_TRUE; + } + + return JS_FALSE; +} + +/*** + * + * + * + * Cancel the edit, or commit the changes. + * + * + * + * Ends editing the label. When Cancel is true, the label is left unchanged. + * Windows only + * + * + */ +JSBool ListCtrl::endEditLabel(JSContext *cx, + JSObject *obj, + uintN WXUNUSED(argc), + jsval *argv, + jsval *rval) +{ + wxListCtrl *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + #ifdef __WXMSW__ + bool cancel; + + if ( FromJS(cx, argv[0], cancel) ) + { + *rval = ToJS(cx, p->EndEditLabel(cancel)); + return JS_TRUE; + } + #endif + + return JS_FALSE; +} + +/*** + * + * + * + * The item index. + * + * + * + * Makes sure the item is visible. Returns true on success. + * + * + */ +JSBool ListCtrl::ensureVisible(JSContext *cx, + JSObject *obj, + uintN WXUNUSED(argc), + jsval *argv, + jsval *rval) +{ + wxListCtrl *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + long item; + + if ( FromJS(cx, argv[0], item) ) + { + *rval = ToJS(cx, p->EnsureVisible(item)); + return JS_TRUE; + } + + return JS_FALSE; +} + + +/*** + * + * + * + * The item to start the search or -1 to start from the beginning. + * + * + * The label to search + * + * + * The label must be exactly the same or may start with Str. Default is false. + * + * + * + * + * The item to start the search or -1 to start from the beginning. + * + * + * The associated data of an item. + * + * + * + * + * The item to start the search or -1 to start from the beginning. + * + * + * Find an item near this position. + * + * + * The direction of the search. See @wxListCtrl#wxListFind. + * + * + * + *
    + *
  1. Find an item whose label matches the string exact or partial.
  2. + *
  3. Find an item with the given associated data.
  4. + *
  5. Find an item nearest the position in the specified direction.
  6. + *
+ * The search starts from the given item, or at the beginning when start is -1. + *
+ *
+ */ +JSBool ListCtrl::findItem(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxListCtrl *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + long item; + + if ( FromJS(cx, argv[0], item) ) + { + if ( Point::HasPrototype(cx, argv[1]) ) + { + if ( argc < 3 ) + return JS_FALSE; + + wxPoint *pt = Point::GetPrivate(cx, argv[1], false); + int direction; + if ( FromJS(cx, argv[2], direction) ) + { + *rval = ToJS(cx, p->FindItem(item, *pt, direction)); + return JS_TRUE; + } + } + else if ( JSVAL_IS_INT(argv[1]) ) + { + long data = JSVAL_TO_INT(argv[1]); + *rval = ToJS(cx, p->FindItem(item, data)); + return JS_TRUE; + } + else + { + wxString str; + FromJS(cx, argv[1], str); + + bool partial = false; + if ( argc > 2 + && ! FromJS(cx, argv[2], partial) ) + return JS_FALSE; + + *rval = ToJS(cx, p->FindItem(item, str, partial)); + return JS_TRUE; + } + } + + return JS_FALSE; +} + +/*** + * + * + * + * The position to test. + * + * + * + * Determines which item (if any) is at the specified point. + * + * + */ +JSBool ListCtrl::hitTest(JSContext *cx, + JSObject *obj, + uintN WXUNUSED(argc), + jsval *argv, + jsval *rval) +{ + wxListCtrl *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + wxPoint *pt = Point::GetPrivate(cx, argv[0]); + if ( pt != NULL ) + { + int flags; + long item = p->HitTest(*pt, flags); + + *rval = ListHitTest::CreateObject(cx, new wxListHitTest(item, flags)); + return JS_TRUE; + } + + return JS_FALSE; +} + +/*** + * + * + * + * + * + * + * Scrolls the list control. If in icon, small icon or report view mode, + * X specifies the number of pixels to scroll. If in list view mode, X + * specifies the number of columns to scroll. + * If in icon, small icon or list view mode, Y specifies the number of pixels + * to scroll. If in report view mode, Y specifies the number of lines to scroll. + * + * + */ +JSBool ListCtrl::scrollList(JSContext *cx, + JSObject *obj, + uintN WXUNUSED(argc), + jsval *argv, + jsval *rval) +{ + wxListCtrl *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + int x; + int y; + + if ( FromJS(cx, argv[0], x) + && FromJS(cx, argv[1], y) ) + { + *rval = ToJS(cx, p->ScrollList(x, y)); + return JS_TRUE; + } + + return JS_FALSE; +} + +/*** + * + * + * + * A function which receives 3 arguments. The first argument is the associated data + * of the first item. The second argument is the associated data of the second item. + * The third arugment is the Data argument you specify with this method. The + * third argument may be omitted when you don't use it. The return value is an integer + * value. Return 0 when the items are equal, a negative value if the first item + * is less then the second item and a positive value when the first item is greater + * then the second item. + * + * + * A value passed as the third argument of the sort function. When not passed, 0 is used. + * + * + * + * Call this method to sort the items in the list control. Sorting is done using the + * specified SortFn.
+ * Remark: + * Notice that the control may only be sorted on client data associated with the items, + * so you must use @wxListCtrl#setItemData if you want to be able to sort the items + * in the control. + *
+ *
+ */ +JSBool ListCtrl::sortItems(JSContext *cx, + JSObject *obj, + uintN argc, + jsval *argv, + jsval* WXUNUSED(rval)) +{ + wxListCtrl *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + JSFunction *fun = JS_ValueToFunction(cx, argv[0]); + if ( fun == NULL ) + return JS_FALSE; + + long data = 0; + + if ( argc > 1 + && ! FromJS(cx, argv[1], data) ) + { + return JS_FALSE; + } + + ListSort *sortData = new ListSort(cx, fun, data); + p->SortItems(ListCtrl::SortFn, (long)((void *) sortData)); + delete sortData; + + return JS_TRUE; +} + +/*** + * + * + * This event is triggered when the user starts dragging with the left mouse button. + * The function receives a @wxListEvent. + * + * + * This event is triggered when the user starts dragging with the right mouse button. + * The function receives a @wxListEvent. + * + * + * This event is triggered when the user starts editing the label. This event + * can be prevented by setting @wxNotifyEvent#veto to true. + * The function receives a @wxListEvent. + * + * + * This event is triggered when the user ends editing the label. + * This event can be prevented by setting @wxNotifyEvent#veto to true. + * The function receives a @wxListEvent. + * + * + * This event is triggered when an item is deleted. + * The function receives a @wxListEvent. + * + * + * This event is triggered when all items are deleted. + * The function receives a @wxListEvent. + * + * + * This event is triggered when the user selects an item. + * The function receives a @wxListEvent. + * + * + * This event is triggered when the user deselects an item. + * The function receives a @wxListEvent. + * + * + * This event is triggered when the user activates an item by pressing Enter or double clicking. + * The function receives a @wxListEvent. + * + * + * This event is triggered when the currently focused item changes. + * The function receives a @wxListEvent. + * + * + * This event is triggered when the user starts right clicks an item. + * The function receives a @wxListEvent. + * + * + * This event is triggered when a key is pressed. + * The function receives a @wxListEvent. + * + * + * This event is triggered when an item is inserted. + * The function receives a @wxListEvent. + * + * + * This event is triggered when the user left-clicks a column. + * The function receives a @wxListEvent. + * + * + * This event is triggered when the user right-clicks a column. + * The function receives a @wxListEvent. + * + * + * This event is triggered when the user starts resizing a column. + * The function receives a @wxListEvent. + * + * + * This event is triggered when the divider between two columns is dragged. + * The function receives a @wxListEvent. + * + * + * This event is triggered when a column is resized. + * The function receives a @wxListEvent. + * + * + * This event is triggered so that the application can prepare a cache for a virtual list control. + * The function receives a @wxListEvent. + * + * + */ +WXJS_INIT_EVENT_MAP(wxListCtrl) +const wxString WXJS_LISTCTRL_BEGIN_DRAG = wxT("onBeginDrag"); +const wxString WXJS_LISTCTRL_BEGIN_RDRAG = wxT("onBeginRDrag"); +const wxString WXJS_LISTCTRL_BEGIN_LABELEDIT = wxT("onBeginLabelEdit"); +const wxString WXJS_LISTCTRL_END_LABELEDIT = wxT("onEndLabelEdit"); +const wxString WXJS_LISTCTRL_DELETE_ITEM = wxT("onDeleteItem"); +const wxString WXJS_LISTCTRL_DELETE_ALL_ITEMS = wxT("onDeleteAllItems"); +const wxString WXJS_LISTCTRL_ITEM_SELECTED = wxT("onItemSelected"); +const wxString WXJS_LISTCTRL_ITEM_DESELECTED = wxT("onItemDeselected"); +const wxString WXJS_LISTCTRL_ITEM_ACTIVATED = wxT("onItemActivated"); +const wxString WXJS_LISTCTRL_ITEM_FOCUSED = wxT("onItemFocused"); +const wxString WXJS_LISTCTRL_ITEM_RIGHT_CLICK = wxT("onItemRightClick"); +const wxString WXJS_LISTCTRL_KEY_DOWN = wxT("onListKeyDown"); +const wxString WXJS_LISTCTRL_INSERT_ITEM = wxT("onInsertItem"); +const wxString WXJS_LISTCTRL_COL_CLICK = wxT("onColClick"); +const wxString WXJS_LISTCTRL_COL_RCLICK = wxT("onColRightClick"); +const wxString WXJS_LISTCTRL_COL_BEGIN_DRAG = wxT("onColBeginDrag"); +const wxString WXJS_LISTCTRL_COL_DRAGGING = wxT("onColDragging"); +const wxString WXJS_LISTCTRL_COL_END_DRAG = wxT("onColEndDrag"); +const wxString WXJS_LISTCTRL_CACHE_HINT = wxT("onCacheHint"); + +void ListCtrlEventHandler::OnBeginDrag(wxListEvent &event) +{ + PrivListEvent::Fire(event, WXJS_LISTCTRL_BEGIN_DRAG); +} + +void ListCtrlEventHandler::OnBeginRDrag(wxListEvent &event) +{ + PrivListEvent::Fire(event, WXJS_LISTCTRL_BEGIN_RDRAG); +} + +void ListCtrlEventHandler::OnBeginLabelEdit(wxListEvent &event) +{ + PrivListEvent::Fire(event, WXJS_LISTCTRL_BEGIN_LABELEDIT); +} + +void ListCtrlEventHandler::OnEndLabelEdit(wxListEvent &event) +{ + PrivListEvent::Fire(event, WXJS_LISTCTRL_END_LABELEDIT); +} + +void ListCtrlEventHandler::OnDeleteItem(wxListEvent &event) +{ + PrivListEvent::Fire(event, WXJS_LISTCTRL_DELETE_ITEM); +} + +void ListCtrlEventHandler::OnDeleteAllItems(wxListEvent &event) +{ + PrivListEvent::Fire(event, WXJS_LISTCTRL_DELETE_ALL_ITEMS); +} + +void ListCtrlEventHandler::OnItemSelected(wxListEvent &event) +{ + PrivListEvent::Fire(event, WXJS_LISTCTRL_ITEM_SELECTED); +} + +void ListCtrlEventHandler::OnItemDeselected(wxListEvent &event) +{ + PrivListEvent::Fire(event, WXJS_LISTCTRL_ITEM_DESELECTED); +} + +void ListCtrlEventHandler::OnItemActivated(wxListEvent &event) +{ + PrivListEvent::Fire(event, WXJS_LISTCTRL_ITEM_ACTIVATED); +} + +void ListCtrlEventHandler::OnItemFocused(wxListEvent &event) +{ + PrivListEvent::Fire(event, WXJS_LISTCTRL_ITEM_FOCUSED); +} + +void ListCtrlEventHandler::OnItemRightClick(wxListEvent &event) +{ + PrivListEvent::Fire(event, WXJS_LISTCTRL_ITEM_RIGHT_CLICK); +} + +void ListCtrlEventHandler::OnListKeyDown(wxListEvent &event) +{ + PrivListEvent::Fire(event, WXJS_LISTCTRL_KEY_DOWN); +} + +void ListCtrlEventHandler::OnInsertItem(wxListEvent &event) +{ + PrivListEvent::Fire(event, WXJS_LISTCTRL_INSERT_ITEM); +} + +void ListCtrlEventHandler::OnColClick(wxListEvent &event) +{ + PrivListEvent::Fire(event, WXJS_LISTCTRL_COL_CLICK); +} + +void ListCtrlEventHandler::OnColRightClick(wxListEvent &event) +{ + PrivListEvent::Fire(event, WXJS_LISTCTRL_COL_RCLICK); +} + +void ListCtrlEventHandler::OnColBeginDrag(wxListEvent &event) +{ + PrivListEvent::Fire(event, WXJS_LISTCTRL_COL_BEGIN_DRAG); +} + +void ListCtrlEventHandler::OnColDragging(wxListEvent &event) +{ + PrivListEvent::Fire(event, WXJS_LISTCTRL_COL_DRAGGING); +} + +void ListCtrlEventHandler::OnColEndDrag(wxListEvent &event) +{ + PrivListEvent::Fire(event, WXJS_LISTCTRL_COL_END_DRAG); +} + +void ListCtrlEventHandler::OnCacheHint(wxListEvent &event) +{ + PrivListEvent::Fire(event, WXJS_LISTCTRL_CACHE_HINT); +} + +void ListCtrlEventHandler::ConnectBeginDrag(wxListCtrl *p, bool connect) +{ + if ( connect ) + { + p->Connect(wxEVT_COMMAND_LIST_BEGIN_DRAG, + wxListEventHandler(OnBeginDrag)); + } + else + { + p->Disconnect(wxEVT_COMMAND_LIST_BEGIN_DRAG, + wxListEventHandler(OnBeginDrag)); + } +} + +void ListCtrlEventHandler::ConnectBeginRDrag(wxListCtrl *p, bool connect) +{ + if ( connect ) + { + p->Connect(wxEVT_COMMAND_LIST_BEGIN_RDRAG, + wxListEventHandler(OnBeginRDrag)); + } + else + { + p->Disconnect(wxEVT_COMMAND_LIST_BEGIN_RDRAG, + wxListEventHandler(OnBeginRDrag)); + } +} + +void ListCtrlEventHandler::ConnectBeginLabelEdit(wxListCtrl *p, bool connect) +{ + if ( connect ) + { + p->Connect(wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT, + wxListEventHandler(OnBeginLabelEdit)); + } + else + { + p->Disconnect(wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT, + wxListEventHandler(OnBeginLabelEdit)); + } +} + +void ListCtrlEventHandler::ConnectEndLabelEdit(wxListCtrl *p, bool connect) +{ + if ( connect ) + { + p->Connect(wxEVT_COMMAND_LIST_END_LABEL_EDIT, + wxListEventHandler(OnEndLabelEdit)); + } + else + { + p->Disconnect(wxEVT_COMMAND_LIST_BEGIN_DRAG, + wxListEventHandler(OnEndLabelEdit)); + } +} + +void ListCtrlEventHandler::ConnectDeleteItem(wxListCtrl *p, bool connect) +{ + if ( connect ) + { + p->Connect(wxEVT_COMMAND_LIST_DELETE_ITEM, + wxListEventHandler(OnDeleteItem)); + } + else + { + p->Disconnect(wxEVT_COMMAND_LIST_DELETE_ITEM, + wxListEventHandler(OnDeleteItem)); + } +} + +void ListCtrlEventHandler::ConnectDeleteAllItems(wxListCtrl *p, bool connect) +{ + if ( connect ) + { + p->Connect(wxEVT_COMMAND_LIST_DELETE_ALL_ITEMS, + wxListEventHandler(OnDeleteAllItems)); + } + else + { + p->Disconnect(wxEVT_COMMAND_LIST_DELETE_ALL_ITEMS, + wxListEventHandler(OnDeleteAllItems)); + } +} + +void ListCtrlEventHandler::ConnectItemSelected(wxListCtrl *p, bool connect) +{ + if ( connect ) + { + p->Connect(wxEVT_COMMAND_LIST_ITEM_SELECTED, + wxListEventHandler(OnItemSelected)); + } + else + { + p->Disconnect(wxEVT_COMMAND_LIST_ITEM_SELECTED, + wxListEventHandler(OnItemSelected)); + } +} + +void ListCtrlEventHandler::ConnectItemDeselected(wxListCtrl *p, bool connect) +{ + if ( connect ) + { + p->Connect(wxEVT_COMMAND_LIST_ITEM_DESELECTED, + wxListEventHandler(OnItemDeselected)); + } + else + { + p->Disconnect(wxEVT_COMMAND_LIST_ITEM_DESELECTED, + wxListEventHandler(OnItemDeselected)); + } +} + +void ListCtrlEventHandler::ConnectItemActivated(wxListCtrl *p, bool connect) +{ + if ( connect ) + { + p->Connect(wxEVT_COMMAND_LIST_ITEM_ACTIVATED, + wxListEventHandler(OnItemActivated)); + } + else + { + p->Disconnect(wxEVT_COMMAND_LIST_ITEM_ACTIVATED, + wxListEventHandler(OnItemActivated)); + } +} + +void ListCtrlEventHandler::ConnectItemFocused(wxListCtrl *p, bool connect) +{ + if ( connect ) + { + p->Connect(wxEVT_COMMAND_LIST_ITEM_FOCUSED, + wxListEventHandler(OnItemFocused)); + } + else + { + p->Disconnect(wxEVT_COMMAND_LIST_ITEM_FOCUSED, + wxListEventHandler(OnItemFocused)); + } +} + +void ListCtrlEventHandler::ConnectItemRightClick(wxListCtrl *p, bool connect) +{ + if ( connect ) + { + p->Connect(wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK, + wxListEventHandler(OnItemRightClick)); + } + else + { + p->Disconnect(wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK, + wxListEventHandler(OnItemRightClick)); + } +} + +void ListCtrlEventHandler::ConnectListKeyDown(wxListCtrl *p, bool connect) +{ + if ( connect ) + { + p->Connect(wxEVT_COMMAND_LIST_KEY_DOWN, + wxListEventHandler(OnListKeyDown)); + } + else + { + p->Disconnect(wxEVT_COMMAND_LIST_KEY_DOWN, + wxListEventHandler(OnListKeyDown)); + } +} + +void ListCtrlEventHandler::ConnectInsertItem(wxListCtrl *p, bool connect) +{ + if ( connect ) + { + p->Connect(wxEVT_COMMAND_LIST_INSERT_ITEM, + wxListEventHandler(OnInsertItem)); + } + else + { + p->Disconnect(wxEVT_COMMAND_LIST_INSERT_ITEM, + wxListEventHandler(OnInsertItem)); + } +} + +void ListCtrlEventHandler::ConnectColClick(wxListCtrl *p, bool connect) +{ + if ( connect ) + { + p->Connect(wxEVT_COMMAND_LIST_COL_CLICK, + wxListEventHandler(OnColClick)); + } + else + { + p->Disconnect(wxEVT_COMMAND_LIST_COL_CLICK, + wxListEventHandler(OnColClick)); + } +} + +void ListCtrlEventHandler::ConnectColRightClick(wxListCtrl *p, bool connect) +{ + if ( connect ) + { + p->Connect(wxEVT_COMMAND_LIST_COL_RIGHT_CLICK, + wxListEventHandler(OnColRightClick)); + } + else + { + p->Disconnect(wxEVT_COMMAND_LIST_COL_RIGHT_CLICK, + wxListEventHandler(OnColRightClick)); + } +} + +void ListCtrlEventHandler::ConnectColBeginDrag(wxListCtrl *p, bool connect) +{ + if ( connect ) + { + p->Connect(wxEVT_COMMAND_LIST_COL_BEGIN_DRAG, + wxListEventHandler(OnColBeginDrag)); + } + else + { + p->Disconnect(wxEVT_COMMAND_LIST_COL_BEGIN_DRAG, + wxListEventHandler(OnColBeginDrag)); + } +} + +void ListCtrlEventHandler::ConnectColDragging(wxListCtrl *p, bool connect) +{ + if ( connect ) + { + p->Connect(wxEVT_COMMAND_LIST_COL_DRAGGING, + wxListEventHandler(OnColDragging)); + } + else + { + p->Disconnect(wxEVT_COMMAND_LIST_COL_DRAGGING, + wxListEventHandler(OnColDragging)); + } +} + +void ListCtrlEventHandler::ConnectColEndDrag(wxListCtrl *p, bool connect) +{ + if ( connect ) + { + p->Connect(wxEVT_COMMAND_LIST_COL_END_DRAG, + wxListEventHandler(OnColEndDrag)); + } + else + { + p->Disconnect(wxEVT_COMMAND_LIST_COL_END_DRAG, + wxListEventHandler(OnColEndDrag)); + } +} + +void ListCtrlEventHandler::ConnectCacheHint(wxListCtrl *p, bool connect) +{ + if ( connect ) + { + p->Connect(wxEVT_COMMAND_LIST_CACHE_HINT, + wxListEventHandler(OnCacheHint)); + } + else + { + p->Disconnect(wxEVT_COMMAND_LIST_CACHE_HINT, + wxListEventHandler(OnCacheHint)); + } +} + +void ListCtrlEventHandler::InitConnectEventMap() +{ + AddConnector(WXJS_LISTCTRL_BEGIN_DRAG, ConnectBeginDrag); + AddConnector(WXJS_LISTCTRL_BEGIN_RDRAG, ConnectBeginRDrag); + AddConnector(WXJS_LISTCTRL_BEGIN_LABELEDIT, ConnectBeginLabelEdit); + AddConnector(WXJS_LISTCTRL_END_LABELEDIT, ConnectEndLabelEdit); + AddConnector(WXJS_LISTCTRL_DELETE_ITEM, ConnectDeleteItem); + AddConnector(WXJS_LISTCTRL_DELETE_ALL_ITEMS, ConnectDeleteAllItems); + AddConnector(WXJS_LISTCTRL_ITEM_SELECTED, ConnectItemSelected); + AddConnector(WXJS_LISTCTRL_ITEM_DESELECTED, ConnectItemDeselected); + AddConnector(WXJS_LISTCTRL_ITEM_ACTIVATED, ConnectItemActivated); + AddConnector(WXJS_LISTCTRL_ITEM_FOCUSED, ConnectItemFocused); + AddConnector(WXJS_LISTCTRL_ITEM_RIGHT_CLICK, ConnectItemRightClick); + AddConnector(WXJS_LISTCTRL_KEY_DOWN, ConnectListKeyDown); + AddConnector(WXJS_LISTCTRL_INSERT_ITEM, ConnectInsertItem); + AddConnector(WXJS_LISTCTRL_COL_CLICK, ConnectColClick); + AddConnector(WXJS_LISTCTRL_COL_RCLICK, ConnectColRightClick); + AddConnector(WXJS_LISTCTRL_COL_BEGIN_DRAG, ConnectBeginDrag); + AddConnector(WXJS_LISTCTRL_COL_DRAGGING, ConnectColDragging); + AddConnector(WXJS_LISTCTRL_COL_END_DRAG, ConnectColEndDrag); + AddConnector(WXJS_LISTCTRL_CACHE_HINT, ConnectCacheHint); +} Property changes on: ps/trunk/source/tools/atlas/wxJS/gui/control/listctrl.cpp ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/gui/control/panel.h =================================================================== --- ps/trunk/source/tools/atlas/wxJS/gui/control/panel.h (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/gui/control/panel.h (revision 5154) @@ -0,0 +1,92 @@ +/* + * wxJavaScript - panel.h + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: panel.h 688 2007-04-27 20:45:09Z fbraem $ + */ +#ifndef _WXJSPanel_H +#define _WXJSPanel_H + +#include "../../common/evtconn.h" + +namespace wxjs +{ + namespace gui + { + class Panel : public ApiWrapper + { + public: + static void InitClass(JSContext* cx, + JSObject* obj, + JSObject* proto); + static bool AddProperty(wxPanel *p, + JSContext *cx, + JSObject *obj, + const wxString &prop, + jsval *vp); + static bool DeleteProperty(wxPanel *p, + JSContext* cx, + JSObject* obj, + const wxString &prop); + static bool GetProperty(wxPanel *p, + JSContext *cx, + JSObject *obj, + int id, + jsval *vp); + static bool SetProperty(wxPanel *p, + JSContext *cx, + JSObject *obj, + int id, + jsval *vp); + + static wxPanel* Construct(JSContext *cx, + JSObject *obj, + uintN argc, + jsval *argv, + bool constructing); + + WXJS_DECLARE_PROPERTY_MAP() + + /** + * Property Ids. + */ + enum + { + P_DEFAULT_ITEM + }; + + WXJS_DECLARE_METHOD_MAP() + WXJS_DECLARE_METHOD(create) + }; + + class PanelEventHandler : public EventConnector + , public wxEvtHandler + { + public: + // Events + void OnSysColourChanged(wxSysColourChangedEvent &event); + static void InitConnectEventMap(); + private: + static void ConnectSysColourChanged(wxPanel *p, bool connect); + }; + }; // namespace gui +}; // namespace wxjs +#endif //_WXJSPanel_H Property changes on: ps/trunk/source/tools/atlas/wxJS/gui/control/panel.h ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/gui/control/calendar.cpp =================================================================== --- ps/trunk/source/tools/atlas/wxJS/gui/control/calendar.cpp (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/gui/control/calendar.cpp (revision 5154) @@ -0,0 +1,847 @@ +#include "precompiled.h" + +/* + * wxJavaScript - calendar.cpp + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: calendar.cpp 708 2007-05-14 15:30:45Z fbraem $ + */ +// calendar.cpp + +#ifndef WX_PRECOMP + #include +#endif + +#include + +#include "../../common/main.h" +#include "../../common/index.h" + +#include "../event/jsevent.h" +#include "../event/cal.h" + +#include "../misc/point.h" +#include "../misc/size.h" +#include "../misc/colour.h" + +#include "calendar.h" +#include "caldate.h" +#include "window.h" +#include "../errors.h" + +using namespace wxjs; +using namespace wxjs::gui; + +/*** + * control/calendar + * gui + * + * The calendar control allows the user to pick a date. For this, + * it displays a window containing several parts: a control at the top to pick + * the month and the year (either or both of them may be disabled), + * and a month area below them which shows all the days in the month. + * The user can move the current selection using the keyboard and select the +* date (generating @wxCalendarCtrl#onCalendar event) + * by pressing return or double clicking it. + *

+ * It has advanced possibilities for the customization of its display. + * All global settings (such as colours and fonts used) can, of course, be + * changed. But also, the display style for each day in the month can be set + * independently using @wxCalendarDateAttr. + *
+ */ +WXJS_INIT_CLASS(CalendarCtrl, "wxCalendarCtrl", 2) + +void CalendarCtrl::InitClass(JSContext* WXUNUSED(cx), + JSObject* WXUNUSED(obj), + JSObject* WXUNUSED(proto)) +{ + CalendarEventHandler::InitConnectEventMap(); +} + +/*** + * + * + * Get the attributes of a day. The array index must be between 1 and 31. + * + * Get/Set the current date + * + * Show/hide holidays (write only) + * + * + * Enable/Disable month changing (write only) + * + * + * Enable/Disable year changing (write only) + * + * + * Get/Set the background colour of the header. + * See @wxCalendarCtrl#setHeaderColours and @wxCalendarCtrl#headerColourFg + * + * + * Get/Set the foreground colour of the header. + * See @wxCalendarCtrl#setHeaderColours and @wxCalendarCtrl#headerColourBg + * + * + * Get/Set the background colour of the selected date. + * See @wxCalendarCtrl#setHighlightColours + * and @wxCalendarCtrl#highlightColourFg + * + * + * Get/Set the foreground colour of the selected date. + * See @wxCalendarCtrl#setHighlightColours and + * @wxCalendarCtrl#highlightColourBg + * + * + * Get/Set the background colour of a holiday. + * See @wxCalendarCtrl#setHolidayColours and @wxCalendarCtrl#holidayColourFg + * + * + * Get/Set the foreground colour of a holiday. + * See @wxCalendarCtrl#setHolidayColours and @wxCalendarCtrl#holidayColourBg + * + * + * Get/Set the lower date limit in which selection might occur. + * Set to null to remove the lower limit. See @wxCalendarCtrl#upperDateLimit + * and @wxCalendarCtrl#setDateRange + * + * + * Get/Set the upper date limit in which selection might occur. + * Set to null to remove the upper limit. See @wxCalendarCtrl#lowerDateLimit + * and @wxCalendarCtrl#setDateRange + * + * + */ +WXJS_BEGIN_PROPERTY_MAP(CalendarCtrl) + WXJS_PROPERTY(P_DATE, "date") + WXJS_PROPERTY(P_LOWER_DATE_LIMIT, "lowerDateLimit") + WXJS_PROPERTY(P_UPPER_DATE_LIMIT, "upperDateLimit") + WXJS_PROPERTY(P_ENABLE_HOLIDAY_DISPLAY, "enableHolidayDisplay") + WXJS_PROPERTY(P_ENABLE_MONTH_CHANGE, "enableMonthChange") + WXJS_PROPERTY(P_ENABLE_YEAR_CHANGE, "enableYearChange") + WXJS_PROPERTY(P_HEADER_COLOUR_FG, "headerColourFg") + WXJS_PROPERTY(P_HEADER_COLOUR_BG, "headerColourBg") + WXJS_PROPERTY(P_HIGHLIGHT_COLOUR_FG, "highlightColourFg") + WXJS_PROPERTY(P_HIGHLIGHT_COLOUR_BG, "highlightColourBg") + WXJS_PROPERTY(P_HOLIDAY_COLOUR_FG, "holidayColourFg") + WXJS_PROPERTY(P_HOLIDAY_COLOUR_BG, "holidayColourBg") + WXJS_READONLY_PROPERTY(P_ATTR, "attr") +WXJS_END_PROPERTY_MAP() + +bool CalendarCtrl::GetProperty(wxCalendarCtrl *p, + JSContext *cx, + JSObject *obj, + int id, + jsval *vp) +{ + switch (id) + { + case P_ATTR: + *vp = CalendarDateAttr::CreateObject(cx, NULL, obj); + break; + case P_DATE: + *vp = ToJS(cx, p->GetDate()); + break; + case P_LOWER_DATE_LIMIT: + *vp = ToJS(cx, p->GetLowerDateLimit()); + break; + case P_UPPER_DATE_LIMIT: + *vp = ToJS(cx, p->GetUpperDateLimit()); + break; + case P_HEADER_COLOUR_FG: + *vp = Colour::CreateObject(cx, new wxColour(p->GetHeaderColourFg())); + break; + case P_HEADER_COLOUR_BG: + *vp = Colour::CreateObject(cx, new wxColour(p->GetHeaderColourBg())); + break; + case P_HIGHLIGHT_COLOUR_FG: + *vp = Colour::CreateObject(cx, new wxColour(p->GetHighlightColourFg())); + break; + case P_HIGHLIGHT_COLOUR_BG: + *vp = Colour::CreateObject(cx, new wxColour(p->GetHighlightColourBg())); + break; + case P_HOLIDAY_COLOUR_FG: + *vp = Colour::CreateObject(cx, new wxColour(p->GetHolidayColourFg())); + break; + case P_HOLIDAY_COLOUR_BG: + *vp = Colour::CreateObject(cx, new wxColour(p->GetHolidayColourBg())); + break; + } + return true; +} + +bool CalendarCtrl::SetProperty(wxCalendarCtrl *p, + JSContext *cx, + JSObject* WXUNUSED(obj), + int id, + jsval *vp) +{ + switch (id) + { + case P_DATE: + { + wxDateTime date; + if ( FromJS(cx, *vp, date) ) + p->SetDate(date); + break; + } + case P_LOWER_DATE_LIMIT: + { + if ( JSVAL_IS_NULL(*vp) ) + p->SetLowerDateLimit(); + else if ( JSVAL_IS_OBJECT(*vp) ) + { + wxDateTime date; + if ( FromJS(cx, *vp, date) ) + p->SetLowerDateLimit(date); + } + break; + } + case P_UPPER_DATE_LIMIT: + { + if ( JSVAL_IS_NULL(*vp) ) + p->SetLowerDateLimit(); + else if ( JSVAL_IS_OBJECT(*vp) ) + { + wxDateTime date; + if ( FromJS(cx, *vp, date) ) + p->SetUpperDateLimit(date); + } + break; + } + case P_ENABLE_HOLIDAY_DISPLAY: + { + bool enable; + if ( FromJS(cx, *vp, enable) ) + p->EnableHolidayDisplay(enable); + break; + } + case P_ENABLE_YEAR_CHANGE: + { + bool enable; + if ( FromJS(cx, *vp, enable) ) + p->EnableYearChange(enable); + break; + } + case P_ENABLE_MONTH_CHANGE: + { + bool enable; + if ( FromJS(cx, *vp, enable) ) + p->EnableMonthChange(enable); + break; + } + case P_HEADER_COLOUR_FG: + { + wxColour *colour = Colour::GetPrivate(cx, *vp); + if ( colour != NULL ) + { + wxColour bg = p->GetHeaderColourBg(); + p->SetHeaderColours(*colour, bg); + } + break; + } + case P_HEADER_COLOUR_BG: + { + wxColour *colour = Colour::GetPrivate(cx, *vp); + if ( colour != NULL ) + { + wxColour fg = p->GetHeaderColourFg(); + p->SetHeaderColours(fg, *colour); + } + break; + } + case P_HIGHLIGHT_COLOUR_FG: + { + wxColour *colour = Colour::GetPrivate(cx, *vp); + if ( colour != NULL ) + { + wxColour bg = p->GetHighlightColourBg(); + p->SetHighlightColours(*colour, bg); + } + break; + } + case P_HIGHLIGHT_COLOUR_BG: + { + wxColour *colour = Colour::GetPrivate(cx, *vp); + if ( colour != NULL ) + { + wxColour fg = p->GetHighlightColourBg(); + p->SetHighlightColours(fg, *colour); + } + break; + } + case P_HOLIDAY_COLOUR_FG: + { + wxColour *colour = Colour::GetPrivate(cx, *vp); + if ( colour != NULL ) + { + wxColour bg = p->GetHolidayColourBg(); + p->SetHolidayColours(*colour, bg); + } + break; + } + case P_HOLIDAY_COLOUR_BG: + { + wxColour *colour = Colour::GetPrivate(cx, *vp); + if ( colour != NULL ) + { + wxColour fg = p->GetHolidayColourBg(); + p->SetHolidayColours(fg, *colour); + } + break; + } + } + return true; +} + +bool CalendarCtrl::AddProperty(wxCalendarCtrl *p, + JSContext* WXUNUSED(cx), + JSObject* WXUNUSED(obj), + const wxString &prop, + jsval* WXUNUSED(vp)) +{ + if ( WindowEventHandler::ConnectEvent(p, prop, true) ) + return true; + + CalendarEventHandler::ConnectEvent(p, prop, true); + return true; +} + +bool CalendarCtrl::DeleteProperty(wxCalendarCtrl *p, + JSContext* WXUNUSED(cx), + JSObject* WXUNUSED(obj), + const wxString &prop) +{ + if ( WindowEventHandler::ConnectEvent(p, prop, false) ) + return true; + + CalendarEventHandler::ConnectEvent(p, prop, false); + return true; +} + +/*** + * + * + * + * Show Sunday as the first day in the week + * + * + * Show Monday as the first day in the week + * + * + * Highlight holidays in the calendar + * + * + * Disable the year changing + * + * + * Disable the month (and, implicitly, the year) changing + * + * + * Show the neighbouring weeks in the previous and next months + * + * + * Use alternative, more compact, style for the month + * and year selection controls. + * + * + * + */ +WXJS_BEGIN_CONSTANT_MAP(CalendarCtrl) + WXJS_CONSTANT(wxCAL_, SUNDAY_FIRST) + WXJS_CONSTANT(wxCAL_, MONDAY_FIRST) + WXJS_CONSTANT(wxCAL_, SHOW_HOLIDAYS) + WXJS_CONSTANT(wxCAL_, NO_YEAR_CHANGE) + WXJS_CONSTANT(wxCAL_, NO_MONTH_CHANGE) + WXJS_CONSTANT(wxCAL_, SHOW_SURROUNDING_WEEKS) + WXJS_CONSTANT(wxCAL_, SEQUENTIAL_MONTH_SELECTION) +WXJS_END_CONSTANT_MAP() + +/*** + * + * + * + * The parent of wxCalendarCtrl. + * + * A window identifier. Use -1 when you don't need it. + * + * + * The date to select when the control is shown. Use null to use + * the default. + * + * + * The position of the CalendarCtrl control on the given parent. + * + * + * The size of the CalendarCtrl control. + * + * + * The wxCalendarCtrl style. + * + * + * + * Constructs a new wxCalendarCtrl object. + * + * + */ +wxCalendarCtrl *CalendarCtrl::Construct(JSContext *cx, + JSObject *obj, + uintN argc, + jsval *argv, + bool WXUNUSED(constructing)) +{ + wxCalendarCtrl *p = new wxCalendarCtrl(); + SetPrivate(cx, obj, p); + + if ( argc > 0 ) + { + jsval rval; + create(cx, obj, argc, argv, &rval); + } + return p; +} + +WXJS_BEGIN_METHOD_MAP(CalendarCtrl) + WXJS_METHOD("create", create, 2) + WXJS_METHOD("setDateRange", setDateRange, 2) + WXJS_METHOD("setHeaderColours", setHeaderColours, 2) + WXJS_METHOD("setHighlightColours", setHighlightColours, 2) + WXJS_METHOD("setHolidayColours", setHolidayColours, 2) +WXJS_END_METHOD_MAP() + +/*** + * + * + * The parent of wxCalendarCtrl. + * + * A window identifier. Use -1 when you don't need it. + * + * + * The date to select when the control is shown. Use null to use + * the default. + * + * + * The position of the CalendarCtrl control on the given parent. + * + * + * The size of the CalendarCtrl control. + * + * + * The wxCalendarCtrl style. + * + * + * + * Creates a calendar control. + * + * + */ +JSBool CalendarCtrl::create(JSContext *cx, + JSObject *obj, + uintN argc, + jsval *argv, + jsval *rval) +{ + wxCalendarCtrl *p = GetPrivate(cx, obj); + *rval = JSVAL_FALSE; + + if ( argc > 6 ) + argc = 6; + + int style = 0; + const wxSize *size = &wxDefaultSize; + const wxPoint *pt= &wxDefaultPosition; + wxDateTime date; + + switch(argc) + { + case 6: // style + if ( ! FromJS(cx, argv[5], style) ) + { + JS_ReportError(cx, WXJS_INVALID_ARG_TYPE, 6, "Integer"); + return JS_FALSE; + } + case 5: + size = Size::GetPrivate(cx, argv[4]); + if ( size == NULL ) + { + JS_ReportError(cx, WXJS_INVALID_ARG_TYPE, 5, "wxSize"); + return JS_FALSE; + } + case 4: + pt = Point::GetPrivate(cx, argv[3]); + if ( pt == NULL ) + { + JS_ReportError(cx, WXJS_INVALID_ARG_TYPE, 4, "wxPoint"); + return JS_FALSE; + } + case 3: + if ( ! FromJS(cx, argv[2], date) ) + { + JS_ReportError(cx, WXJS_INVALID_ARG_TYPE, 3, "Date"); + return JS_FALSE; + } + default: + int id; + if ( ! FromJS(cx, argv[1], id) ) + { + JS_ReportError(cx, WXJS_INVALID_ARG_TYPE, 2, "Integer"); + return JS_FALSE; + } + + wxWindow *parent = Window::GetPrivate(cx, argv[0]); + if ( parent == NULL ) + { + JS_ReportError(cx, WXJS_NO_PARENT_ERROR, GetClass()->name); + return JS_FALSE; + } + + JavaScriptClientData *clntParent = + dynamic_cast(parent->GetClientObject()); + if ( clntParent == NULL ) + { + JS_ReportError(cx, WXJS_NO_PARENT_ERROR, GetClass()->name); + return JS_FALSE; + } + JS_SetParent(cx, obj, clntParent->GetObject()); + + if ( p->Create(parent, id, date, *pt, *size, style) ) + { + *rval = JSVAL_TRUE; + p->SetClientObject(new JavaScriptClientData(cx, obj, true, false)); + } + } + return JS_TRUE; +} + +/*** + * + * + * + * The lower limit of the selection. Use null to reset this. + * + * + * The upper limit of the selection. Use null to reset this. + * + * + * + * Set the range in which selection can occur. + * See @wxCalendarCtrl#lowerDateLimit and + * @wxCalendarCtrl#upperDateLimit + * + * + */ +JSBool CalendarCtrl::setDateRange(JSContext *cx, + JSObject *obj, + uintN WXUNUSED(argc), + jsval *argv, + jsval* WXUNUSED(rval)) +{ + wxCalendarCtrl *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + wxDateTime minDate; + wxDateTime maxDate; + if ( FromJS(cx, argv[0], minDate) + && FromJS(cx, argv[1], maxDate) ) + p->SetDateRange(minDate, maxDate); + + return JS_TRUE; +} + +/*** + * + * + * + * The foreground colour of the header + * + * The background colour of the header + * + * + * Sets the colours of the header. + * See @wxCalendarCtrl#headerColourFg and @wxCalendarCtrl#headerColourBg + * + * + */ +JSBool CalendarCtrl::setHeaderColours(JSContext *cx, + JSObject *obj, + uintN WXUNUSED(argc), + jsval *argv, + jsval* WXUNUSED(rval)) +{ + wxCalendarCtrl *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + wxColour *fg = Colour::GetPrivate(cx, argv[0]); + wxColour *bg = Colour::GetPrivate(cx, argv[1]); + + if ( fg != NULL + && bg != NULL ) + { + p->SetHeaderColours(*fg, *bg); + return JS_TRUE; + } + + return JS_FALSE; +} + +/*** + * + * + * + * The foreground colour of the highlighted date + * + * + * The background colour of the highlighted date + * + * + * + * Sets the colours of the highlighted date. + * See @wxCalendarCtrl#highlightColourFg + * and @wxCalendarCtrl#highlightColourBg + * + * + */ +JSBool CalendarCtrl::setHighlightColours(JSContext *cx, + JSObject *obj, + uintN WXUNUSED(argc), + jsval *argv, + jsval* WXUNUSED(rval)) +{ + wxCalendarCtrl *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + wxColour *fg = Colour::GetPrivate(cx, argv[0]); + wxColour *bg = Colour::GetPrivate(cx, argv[1]); + + if ( fg != NULL + && bg != NULL ) + { + p->SetHighlightColours(*fg, *bg); + return JS_TRUE; + } + + return JS_FALSE; +} + +/*** + * + * + * + * The foreground colour of a holiday + * + * + * The background colour of a holiday + * + * + * + * Sets the colours of a holiday. + * See @wxCalendarCtrl#holidayColourFg and @wxCalendarCtrl#holidayColourBg + * + * + */ +JSBool CalendarCtrl::setHolidayColours(JSContext *cx, + JSObject *obj, + uintN WXUNUSED(argc), + jsval *argv, + jsval* WXUNUSED(rval)) +{ + wxCalendarCtrl *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + wxColour *fg = Colour::GetPrivate(cx, argv[0]); + wxColour *bg = Colour::GetPrivate(cx, argv[1]); + + if ( fg != NULL + && bg != NULL ) + { + p->SetHolidayColours(*fg, *bg); + return JS_TRUE; + } + + return JS_FALSE; +} + +WXJS_INIT_EVENT_MAP(wxCalendarCtrl) +const wxString WXJS_CAL_EVENT = wxT("onCalendar"); +const wxString WXJS_CAL_SELCHANGED_EVENT = wxT("onCalendarSelChanged"); +const wxString WXJS_CAL_DAY_EVENT = wxT("onCalendarDay"); +const wxString WXJS_CAL_MONTH_EVENT = wxT("onCalendarMonth"); +const wxString WXJS_CAL_YEAR_EVENT = wxT("onCalendarYear"); +const wxString WXJS_CAL_WEEKDAY_CLICKED_EVENT = wxT("onCalendarWeekDayClicked"); + +/*** + * + * + * A day is double clicked. The function gets a @wxCalendarEvent as argument. + * + * + * The selected date is changed. + * The function gets a @wxCalendarEvent as argument. + * + * + * The selected day is changed. + * The function gets a @wxCalendarEvent as argument. + * + * + * The selected month is changed. + * The function gets a @wxCalendarEvent as argument. + * + * + * The selected year is changed. + * The function gets a @wxCalendarEvent as argument. + * + * + * The user clicked on the week day header. + * The function gets a @wxCalendarEvent as argument. + * + * + */ + +void CalendarEventHandler::OnCalendar(wxCalendarEvent &event) +{ + PrivCalendarEvent::Fire(event, WXJS_CAL_EVENT); +} + +void CalendarEventHandler::OnCalendarSelChanged(wxCalendarEvent &event) +{ + PrivCalendarEvent::Fire(event, WXJS_CAL_SELCHANGED_EVENT); +} + +void CalendarEventHandler::OnCalendarDay(wxCalendarEvent &event) +{ + PrivCalendarEvent::Fire(event, WXJS_CAL_DAY_EVENT); +} + +void CalendarEventHandler::OnCalendarMonth(wxCalendarEvent &event) +{ + PrivCalendarEvent::Fire(event, WXJS_CAL_MONTH_EVENT); +} + +void CalendarEventHandler::OnCalendarYear(wxCalendarEvent &event) +{ + PrivCalendarEvent::Fire(event, WXJS_CAL_YEAR_EVENT); +} + +void CalendarEventHandler::OnCalendarWeekDayClicked(wxCalendarEvent &event) +{ + PrivCalendarEvent::Fire(event, WXJS_CAL_WEEKDAY_CLICKED_EVENT); +} + +void CalendarEventHandler::ConnectCalendar(wxCalendarCtrl *p, + bool connect) +{ + if ( connect ) + { + p->Connect(wxEVT_CALENDAR_DOUBLECLICKED, + wxCalendarEventHandler(OnCalendar)); + } + else + { + p->Disconnect(wxEVT_CALENDAR_DOUBLECLICKED, + wxCalendarEventHandler(OnCalendar)); + } +} + +void CalendarEventHandler::ConnectCalendarDay(wxCalendarCtrl *p, bool connect) +{ + if ( connect ) + { + p->Connect(wxEVT_CALENDAR_DAY_CHANGED, + wxCalendarEventHandler(OnCalendarDay)); + } + else + { + p->Disconnect(wxEVT_CALENDAR_DAY_CHANGED, + wxCalendarEventHandler(OnCalendarDay)); + } +} + +void CalendarEventHandler::ConnectCalendarSelChanged(wxCalendarCtrl *p, + bool connect) +{ + if ( connect ) + { + p->Connect(wxEVT_CALENDAR_SEL_CHANGED, + wxCalendarEventHandler(OnCalendarSelChanged)); + } + else + { + p->Disconnect(wxEVT_CALENDAR_SEL_CHANGED, + wxCalendarEventHandler(OnCalendarSelChanged)); + } +} + +void CalendarEventHandler::ConnectCalendarMonth(wxCalendarCtrl *p, bool connect) +{ + if ( connect ) + { + p->Connect(wxEVT_CALENDAR_MONTH_CHANGED, + wxCalendarEventHandler(OnCalendarMonth)); + } + else + { + p->Disconnect(wxEVT_CALENDAR_MONTH_CHANGED, + wxCalendarEventHandler(OnCalendarMonth)); + } +} + +void CalendarEventHandler::ConnectCalendarYear(wxCalendarCtrl *p, bool connect) +{ + if ( connect ) + { + p->Connect(wxEVT_CALENDAR_YEAR_CHANGED, + wxCalendarEventHandler(OnCalendarYear)); + } + else + { + p->Disconnect(wxEVT_CALENDAR_YEAR_CHANGED, + wxCalendarEventHandler(OnCalendarYear)); + } +} + +void CalendarEventHandler::ConnectCalendarWeekDayClicked(wxCalendarCtrl *p, + bool connect) +{ + if ( connect ) + { + p->Connect(wxEVT_CALENDAR_WEEKDAY_CLICKED, + wxCalendarEventHandler(OnCalendarWeekDayClicked)); + } + else + { + p->Disconnect(wxEVT_CALENDAR_WEEKDAY_CLICKED, + wxCalendarEventHandler(OnCalendarWeekDayClicked)); + } +} + +void CalendarEventHandler::InitConnectEventMap() +{ + AddConnector(WXJS_CAL_EVENT, ConnectCalendar); + AddConnector(WXJS_CAL_DAY_EVENT, ConnectCalendarDay); + AddConnector(WXJS_CAL_MONTH_EVENT, ConnectCalendarMonth); + AddConnector(WXJS_CAL_YEAR_EVENT, ConnectCalendarYear); + AddConnector(WXJS_CAL_SELCHANGED_EVENT, ConnectCalendarSelChanged); + AddConnector(WXJS_CAL_WEEKDAY_CLICKED_EVENT, ConnectCalendarWeekDayClicked); +} Property changes on: ps/trunk/source/tools/atlas/wxJS/gui/control/calendar.cpp ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/gui/control/filedlg.h =================================================================== --- ps/trunk/source/tools/atlas/wxJS/gui/control/filedlg.h (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/gui/control/filedlg.h (revision 5154) @@ -0,0 +1,71 @@ +/* + * wxJavaScript - filedlg.h + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: filedlg.h 672 2007-04-12 20:29:39Z fbraem $ + */ +#ifndef _WXJSFileDialog_H +#define _WXJSFileDialog_H + +namespace wxjs +{ + namespace gui + { + class FileDialog : public ApiWrapper + { + public: + static bool GetProperty(wxFileDialog *p, + JSContext *cx, + JSObject *obj, + int id, + jsval *vp); + static bool SetProperty(wxFileDialog *p, + JSContext *cx, + JSObject *obj, + int id, + jsval *vp); + + static wxFileDialog *Construct(JSContext *cx, + JSObject *obj, + uintN argc, + jsval *argv, + bool constructing); + static void Destruct(JSContext *cx, wxFileDialog *p); + + WXJS_DECLARE_PROPERTY_MAP() + WXJS_DECLARE_CONSTANT_MAP() + + enum + { + P_DIRECTORY + , P_FILENAME + , P_FILENAMES + , P_FILTER_INDEX + , P_MESSAGE + , P_PATH + , P_PATHS + , P_WILDCARD + }; + }; + }; // namespace gui +}; // namespace wxjs + +#endif //_WXJSFileDialog_H Property changes on: ps/trunk/source/tools/atlas/wxJS/gui/control/filedlg.h ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/gui/control/combobox.h =================================================================== --- ps/trunk/source/tools/atlas/wxJS/gui/control/combobox.h (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/gui/control/combobox.h (revision 5154) @@ -0,0 +1,112 @@ +/* + * wxJavaScript - combobox.h + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: combobox.h 682 2007-04-24 20:38:18Z fbraem $ + */ +#ifndef _WXJSComboBox_H +#define _WXJSComboBox_H + +#include "../../common/evtconn.h" + +namespace wxjs +{ + namespace gui + { + class ComboBox : public ApiWrapper + { + public: + static void InitClass(JSContext* cx, + JSObject* obj, + JSObject* proto); + + static bool AddProperty(wxComboBox *p, + JSContext *cx, + JSObject *obj, + const wxString &prop, + jsval *vp); + static bool DeleteProperty(wxComboBox *p, + JSContext* cx, + JSObject* obj, + const wxString &prop); + + static bool GetProperty(wxComboBox *p, + JSContext *cx, + JSObject *obj, + int id, + jsval *vp); + static bool SetProperty(wxComboBox *p, + JSContext *cx, + JSObject *obj, + int id, + jsval *vp); + + static wxComboBox* Construct(JSContext *cx, + JSObject *obj, + uintN argc, + jsval *argv, + bool constructing); + + WXJS_DECLARE_CONSTANT_MAP() + + WXJS_DECLARE_PROPERTY_MAP() + enum + { + P_VALUE + , P_INSERTION_POINT + , P_LAST_POSITION + , P_CAN_COPY + , P_CAN_CUT + , P_CAN_PASTE + , P_CAN_REDO + , P_CAN_UNDO + }; + + WXJS_DECLARE_METHOD_MAP() + WXJS_DECLARE_METHOD(create) + WXJS_DECLARE_METHOD(copy) + WXJS_DECLARE_METHOD(cut) + WXJS_DECLARE_METHOD(paste) + WXJS_DECLARE_METHOD(replace) + WXJS_DECLARE_METHOD(remove) + WXJS_DECLARE_METHOD(redo) + WXJS_DECLARE_METHOD(undo) + }; + + class ComboBoxEventHandler : public EventConnector + , public wxEvtHandler + { + public: + // Events + void OnText(wxCommandEvent &event); + void OnTextEnter(wxCommandEvent &event); + void OnComboBox(wxCommandEvent &event); + static void InitConnectEventMap(); + private: + static void ConnectText(wxComboBox *p, bool connect); + static void ConnectTextEnter(wxComboBox *p, bool connect); + static void ConnectComboBox(wxComboBox *p, bool connect); + }; + + }; // namespace gui +}; // namespace wxjs + +#endif //_WXJSComboBox_H Property changes on: ps/trunk/source/tools/atlas/wxJS/gui/control/combobox.h ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/gui/control/staticbx.cpp =================================================================== --- ps/trunk/source/tools/atlas/wxJS/gui/control/staticbx.cpp (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/gui/control/staticbx.cpp (revision 5154) @@ -0,0 +1,225 @@ +#include "precompiled.h" + +/* + * wxJavaScript - staticbx.cpp + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: staticbx.cpp 708 2007-05-14 15:30:45Z fbraem $ + */ + +#ifndef WX_PRECOMP + #include +#endif + +#include "../../common/main.h" + + + +#include "staticbx.h" +#include "window.h" + +#include "../misc/point.h" +#include "../misc/size.h" +#include "../errors.h" + +using namespace wxjs; +using namespace wxjs::gui; + +/*** + * control/staticbox + * gui + * + * A static box is a rectangle drawn around other panel items to denote a + * logical grouping of items. + * + */ +WXJS_INIT_CLASS(StaticBox, "wxStaticBox", 3) + +bool StaticBox::AddProperty(wxStaticBox *p, + JSContext* WXUNUSED(cx), + JSObject* WXUNUSED(obj), + const wxString &prop, + jsval* WXUNUSED(vp)) +{ + WindowEventHandler::ConnectEvent(p, prop, true); + return true; +} + +bool StaticBox::DeleteProperty(wxStaticBox *p, + JSContext* WXUNUSED(cx), + JSObject* WXUNUSED(obj), + const wxString &prop) +{ + WindowEventHandler::ConnectEvent(p, prop, false); + return true; +} + +/*** + * + * + * + * + * The parent of the staticbox + * + * + * The unique identifier. + * + * + * The text of the staticbox + * + * + * The position of the staticbox. + * + * + * The size of the staticBox. + * + * + * The style of the staticbox. + * + * + * + * Constructs a new wxStaticBox object + * + * + */ +wxStaticBox* StaticBox::Construct(JSContext *cx, + JSObject *obj, + uintN argc, + jsval *argv, + bool WXUNUSED(constructing)) +{ + wxStaticBox *p = new wxStaticBox(); + SetPrivate(cx, obj, p); + + if ( argc > 0 ) + { + jsval rval; + create(cx, obj, argc, argv, &rval); + } + return p; +} + +WXJS_BEGIN_METHOD_MAP(StaticBox) + WXJS_METHOD("create", create, 3) +WXJS_END_METHOD_MAP() + +/*** + * + * + * + * The parent of the staticbox + * + * + * The unique identifier. + * + * + * The text of the staticbox + * + * + * The position of the staticbox. + * + * + * The size of the staticBox. + * + * + * The style of the staticbox. + * + * + * + * Constructs a new wxStaticBox object + * + * + */ +JSBool StaticBox::create(JSContext *cx, + JSObject *obj, + uintN argc, + jsval *argv, + jsval *rval) +{ + wxStaticBox *p = GetPrivate(cx, obj); + *rval = JSVAL_FALSE; + + if ( argc > 6 ) + argc = 6; + + const wxPoint *pt = &wxDefaultPosition; + const wxSize *size = &wxDefaultSize; + int style = 0; + + switch(argc) + { + case 6: + if ( ! FromJS(cx, argv[5], style) ) + { + JS_ReportError(cx, WXJS_INVALID_ARG_TYPE, 6, "Integer"); + return JS_FALSE; + } + // Fall through + case 5: + size = Size::GetPrivate(cx, argv[4]); + if ( size == NULL ) + { + JS_ReportError(cx, WXJS_INVALID_ARG_TYPE, 5, "wxSize"); + return JS_FALSE; + } + // Fall through + case 4: + pt = Point::GetPrivate(cx, argv[3]); + if ( pt == NULL ) + { + JS_ReportError(cx, WXJS_INVALID_ARG_TYPE, 4, "wxPoint"); + return JS_FALSE; + } + // Fall through + default: + wxString text; + FromJS(cx, argv[2], text); + + int id; + if ( ! FromJS(cx, argv[1], id) ) + { + JS_ReportError(cx, WXJS_INVALID_ARG_TYPE, 2, "Integer"); + return JS_FALSE; + } + + wxWindow *parent = Window::GetPrivate(cx, argv[0]); + if ( parent == NULL ) + { + JS_ReportError(cx, WXJS_NO_PARENT_ERROR, GetClass()->name); + return JS_FALSE; + } + JavaScriptClientData *clntParent = + dynamic_cast(parent->GetClientObject()); + if ( clntParent == NULL ) + { + JS_ReportError(cx, WXJS_NO_PARENT_ERROR, GetClass()->name); + return JS_FALSE; + } + JS_SetParent(cx, obj, clntParent->GetObject()); + + if ( p->Create(parent, id, text, *pt, *size, style) ) + { + *rval = JSVAL_TRUE; + p->SetClientObject(new JavaScriptClientData(cx, obj, true, false)); + } + } + return JS_TRUE; +} Property changes on: ps/trunk/source/tools/atlas/wxJS/gui/control/staticbx.cpp ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/gui/control/slider.h =================================================================== --- ps/trunk/source/tools/atlas/wxJS/gui/control/slider.h (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/gui/control/slider.h (revision 5154) @@ -0,0 +1,121 @@ +/* + * wxJavaScript - slider.h + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: slider.h 692 2007-05-02 21:30:16Z fbraem $ + */ +#ifndef _WXJSSlider_H +#define _WXJSSlider_H + +#include "../../common/evtconn.h" + +namespace wxjs +{ + namespace gui + { + class Slider : public ApiWrapper + { + public: + + static void InitClass(JSContext* cx, + JSObject* obj, + JSObject* proto); + static bool AddProperty(wxSlider *p, + JSContext *cx, + JSObject *obj, + const wxString &prop, + jsval *vp); + static bool DeleteProperty(wxSlider *p, + JSContext* cx, + JSObject* obj, + const wxString &prop); + static bool GetProperty(wxSlider *p, + JSContext *cx, + JSObject *obj, + int id, + jsval *vp); + static bool SetProperty(wxSlider *p, + JSContext *cx, + JSObject *obj, + int id, + jsval *vp); + + static wxSlider* Construct(JSContext *cx, + JSObject *obj, + uintN argc, + jsval *argv, + bool constructing); + + WXJS_DECLARE_PROPERTY_MAP() + enum + { + P_LINESIZE + , P_MAX + , P_MIN + , P_PAGESIZE + , P_SEL_END + , P_SEL_START + , P_THUMB_LENGTH + , P_TICK + , P_VALUE + }; + + WXJS_DECLARE_CONSTANT_MAP() + + WXJS_DECLARE_METHOD_MAP() + WXJS_DECLARE_METHOD(create) + WXJS_DECLARE_METHOD(clearSel) + WXJS_DECLARE_METHOD(clearTicks) + WXJS_DECLARE_METHOD(setRange) + WXJS_DECLARE_METHOD(setSelection) + WXJS_DECLARE_METHOD(setTickFreq) + }; + + class SliderEventHandler : public EventConnector + , public wxEvtHandler + { + public: + // Events + void OnScrollChanged(wxScrollEvent& event); + void OnScrollTop(wxScrollEvent& event); + void OnScrollBottom(wxScrollEvent& event); + void OnScrollLineUp(wxScrollEvent& event); + void OnScrollLineDown(wxScrollEvent& event); + void OnScrollPageUp(wxScrollEvent& event); + void OnScrollPageDown(wxScrollEvent& event); + void OnScrollThumbTrack(wxScrollEvent& event); + void OnScrollThumbRelease(wxScrollEvent& event); + static void InitConnectEventMap(); + private: + static void ConnectScrollChanged(wxSlider *p, bool connect); + static void ConnectScrollTop(wxSlider *p, bool connect); + static void ConnectScrollBottom(wxSlider *p, bool connect); + static void ConnectScrollLineUp(wxSlider *p, bool connect); + static void ConnectScrollLineDown(wxSlider *p, bool connect); + static void ConnectScrollPageUp(wxSlider *p, bool connect); + static void ConnectScrollPageDown(wxSlider *p, bool connect); + static void ConnectScrollThumbTrack(wxSlider *p, bool connect); + static void ConnectScrollThumbRelease(wxSlider *p, bool connect); + }; + }; // namespace gui +}; // namespace wxjs + +#endif //_WXJSSlider_H Property changes on: ps/trunk/source/tools/atlas/wxJS/gui/control/slider.h ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/gui/control/choice.cpp =================================================================== --- ps/trunk/source/tools/atlas/wxJS/gui/control/choice.cpp (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/gui/control/choice.cpp (revision 5154) @@ -0,0 +1,353 @@ +#include "precompiled.h" + +/* + * wxJavaScript - choice.cpp + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: choice.cpp 708 2007-05-14 15:30:45Z fbraem $ + */ + +#ifndef WX_PRECOMP + #include +#endif + +#include "../../common/main.h" +#include "../../common/index.h" + +#include "../event/jsevent.h" +#include "../event/command.h" + +#include "window.h" +#include "choice.h" +#include "item.h" + +#include "../misc/point.h" +#include "../misc/size.h" +#include "../misc/validate.h" +#include "../errors.h" + +using namespace wxjs; +using namespace wxjs::gui; + +/*** + * control/choice + * gui + * + * A choice item is used to select one of a list of strings. + * Unlike a listbox, only the selection is visible until the + * user pulls down the menu of choices. An example: + *

+ *	 var items = new Array();
+ *	 items[0] = "Opel";
+ *	 items[1] = "Ford";
+ *	 items[2] = "BMW";
+ *	 // dlg is a wxDialog
+ *	 var choice = new wxChoice(dlg, -1, wxDefaultPosition, wxDefaultSize, items);
+ *   
+ *
+ */ +WXJS_INIT_CLASS(Choice, "wxChoice", 2) + +void Choice::InitClass(JSContext* WXUNUSED(cx), + JSObject* WXUNUSED(obj), + JSObject* WXUNUSED(proto)) +{ + ChoiceEventHandler::InitConnectEventMap(); +} + +/*** + * + * + * Gets/Sets the number of columns + * + * + */ + +WXJS_BEGIN_PROPERTY_MAP(Choice) + WXJS_PROPERTY(P_COLUMNS, "columns") +WXJS_END_PROPERTY_MAP() + +bool Choice::GetProperty(wxChoice *p, + JSContext *cx, + JSObject* WXUNUSED(obj), + int id, + jsval *vp) +{ + switch (id) + { + case P_COLUMNS: + *vp = ToJS(cx, p->GetColumns()); + break; + } + return true; +} + +bool Choice::SetProperty(wxChoice *p, + JSContext *cx, + JSObject* WXUNUSED(obj), + int id, + jsval *vp) +{ + switch (id) + { + case P_COLUMNS: + { + int columns; + if ( FromJS(cx, *vp, columns) ) + p->SetColumns(columns); + break; + } + } + return true; +} + +bool Choice::AddProperty(wxChoice *p, + JSContext* WXUNUSED(cx), + JSObject* WXUNUSED(obj), + const wxString &prop, + jsval* WXUNUSED(vp)) +{ + if ( WindowEventHandler::ConnectEvent(p, prop, true) ) + return true; + + ChoiceEventHandler::ConnectEvent(p, prop, true); + + return true; +} + +bool Choice::DeleteProperty(wxChoice *p, + JSContext* WXUNUSED(cx), + JSObject* WXUNUSED(obj), + const wxString &prop) +{ + if ( WindowEventHandler::ConnectEvent(p, prop, false) ) + return true; + + ChoiceEventHandler::ConnectEvent(p, prop, false); + return true; +} + +/*** + * + * + * + * + * The parent of the control + * + * + * An window identifier. Use -1 when you don't need it. + * + * + * The position of the choice control on the given parent. + * + * + * The size of the choice control. + * + * + * An array of Strings to initialize the control. + * + * + * The style of the control + * + * + * A validator + * + * + * + * Constructs a new wxChoice object. + * + * + */ +wxChoice* Choice::Construct(JSContext *cx, + JSObject *obj, + uintN argc, + jsval *argv, + bool WXUNUSED(constructing)) +{ + wxChoice *p = new wxChoice(); + SetPrivate(cx, obj, p); + + if ( argc > 0 ) + { + jsval rval; + create(cx, obj, argc, argv, &rval); + } + return p; +} + +WXJS_BEGIN_METHOD_MAP(Choice) + WXJS_METHOD("create", create, 2) +WXJS_END_METHOD_MAP() + +/*** + * + * + * + * The parent of the control + * + * + * An window identifier. Use -1 when you don't need it. + * + * + * The position of the choice control on the given parent. + * + * + * The size of the choice control. + * + * + * An array of Strings to initialize the control. + * + * + * The style of the control + * + * + * A validator + * + * + * + * Creates a wxChoice + * + * + */ +JSBool Choice::create(JSContext *cx, + JSObject *obj, + uintN argc, + jsval *argv, + jsval *rval) +{ + wxChoice *p = GetPrivate(cx, obj); + *rval = JSVAL_FALSE; + + const wxPoint *pt = &wxDefaultPosition; + const wxSize *size = &wxDefaultSize; + int style = 0; + StringsPtr items; + const wxValidator *val = &wxDefaultValidator; + + if ( argc > 7 ) + argc = 7; + + switch(argc) + { + case 7: + val = Validator::GetPrivate(cx, argv[6]); + if ( val == NULL ) + { + JS_ReportError(cx, WXJS_INVALID_ARG_TYPE, 7, "wxValidator"); + return JS_FALSE; + } + case 6: + if ( ! FromJS(cx, argv[5], style) ) + { + JS_ReportError(cx, WXJS_INVALID_ARG_TYPE, 6, "Integer"); + return JS_FALSE; + } + // Fall through + case 5: + if ( ! FromJS(cx, argv[4], items) ) + { + JS_ReportError(cx, WXJS_INVALID_ARG_TYPE, 5, "Array"); + return JS_FALSE; + } + case 4: + size = Size::GetPrivate(cx, argv[3]); + if ( size == NULL ) + { + JS_ReportError(cx, WXJS_INVALID_ARG_TYPE, 4, "wxSize"); + return JS_FALSE; + } + // Fall through + case 3: + pt = Point::GetPrivate(cx, argv[2]); + if ( pt == NULL ) + { + JS_ReportError(cx, WXJS_INVALID_ARG_TYPE, 3, "wxPoint"); + return JS_FALSE; + } + // Fall through + default: + int id; + if ( ! FromJS(cx, argv[1], id) ) + { + JS_ReportError(cx, WXJS_INVALID_ARG_TYPE, 2, "Integer"); + return JS_FALSE; + } + + wxWindow *parent = Window::GetPrivate(cx, argv[0]); + if ( parent == NULL ) + { + JS_ReportError(cx, WXJS_NO_PARENT_ERROR, GetClass()->name); + return JS_FALSE; + } + JavaScriptClientData *clntParent = + dynamic_cast(parent->GetClientObject()); + if ( clntParent == NULL ) + { + JS_ReportError(cx, WXJS_NO_PARENT_ERROR, GetClass()->name); + return JS_FALSE; + } + JS_SetParent(cx, obj, clntParent->GetObject()); + + if ( p->Create(parent, id, *pt, *size, + items.GetCount(), items.GetStrings(), style, *val) ) + { + *rval = JSVAL_TRUE; + p->SetClientObject(new JavaScriptClientData(cx, obj, true, false)); + } + } + + return JS_TRUE; +} + +/*** + * + * + * Called when an item is selected. The type of the argument that your handler receives + * is @wxCommandEvent. + * + * + */ +WXJS_INIT_EVENT_MAP(wxChoice) +const wxString WXJS_CHOICE_EVENT = wxT("onChoice"); + +void ChoiceEventHandler::OnChoice(wxCommandEvent &event) +{ + PrivCommandEvent::Fire(event, WXJS_CHOICE_EVENT); +} + +void ChoiceEventHandler::ConnectChoice(wxChoice *p, bool connect) +{ + if ( connect ) + { + p->Connect(wxEVT_COMMAND_CHOICE_SELECTED, + wxCommandEventHandler(OnChoice)); + } + else + { + p->Disconnect(wxEVT_COMMAND_CHOICE_SELECTED, + wxCommandEventHandler(OnChoice)); + } +} + +void ChoiceEventHandler::InitConnectEventMap() +{ + AddConnector(WXJS_CHOICE_EVENT, ConnectChoice); +} Property changes on: ps/trunk/source/tools/atlas/wxJS/gui/control/choice.cpp ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/gui/event/listevt.h =================================================================== --- ps/trunk/source/tools/atlas/wxJS/gui/event/listevt.h (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/gui/event/listevt.h (revision 5154) @@ -0,0 +1,75 @@ +/* + * wxJavaScript - listevt.h + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: listevt.h 598 2007-03-07 20:13:28Z fbraem $ + */ +#ifndef _WXJSListEvent_H +#define _WXJSListEvent_H + +///////////////////////////////////////////////////////////////////////////// +// Name: listevt.h +// Purpose: Ports wxListEvent to JavaScript +// Author: Franky Braem +// Modified by: +// Created: 04.10.02 +// Copyright: (c) 2001-2002 Franky Braem +// Licence: LGPL +///////////////////////////////////////////////////////////////////////////// + +#include + +namespace wxjs +{ + namespace gui + { + typedef JSEvent PrivListEvent; + class ListEvent : public ApiWrapper + { + public: + static bool GetProperty(PrivListEvent *p, JSContext *cx, JSObject *obj, int id, jsval *vp); + + virtual ~ListEvent() + { + } + + enum + { + P_CODE + , P_INDEX + , P_COLUMN + , P_POINT + , P_LABEL + , P_TEXT + , P_IMAGE + , P_DATA + , P_MASK + , P_ITEM + , P_CACHE_FROM + , P_CACHE_TO + }; + + WXJS_DECLARE_PROPERTY_MAP() + }; + }; // namespace gui +}; // namespace wxjs + +#endif //_WXJSCalendarEvent_H Property changes on: ps/trunk/source/tools/atlas/wxJS/gui/event/listevt.h ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/gui/event/activate.h =================================================================== --- ps/trunk/source/tools/atlas/wxJS/gui/event/activate.h (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/gui/event/activate.h (revision 5154) @@ -0,0 +1,62 @@ +/* + * wxJavaScript - activate.h + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: activate.h 598 2007-03-07 20:13:28Z fbraem $ + */ +#ifndef _WXJSActivateEvent_H +#define _WXJSActivateEvent_H + +///////////////////////////////////////////////////////////////////////////// +// Name: activate.h +// Purpose: Ports wxActivateEvent to JavaScript +// Author: Franky Braem +// Modified by: +// Created: 06.01.02 +// Copyright: (c) 2001-2002 Franky Braem +// Licence: LGPL +///////////////////////////////////////////////////////////////////////////// +namespace wxjs +{ + namespace gui + { + typedef JSEvent PrivActivateEvent; + + class ActivateEvent : + public ApiWrapper + { + public: + static bool GetProperty(PrivActivateEvent *p, JSContext *cx, JSObject *obj, int id, jsval *vp); + + virtual ~ActivateEvent() + { + } + + enum + { + P_ACTIVE + }; + + WXJS_DECLARE_PROPERTY_MAP() + }; + }; // namespace gui +}; // namespace wxjs +#endif //_WXJSActivateEvent_H Property changes on: ps/trunk/source/tools/atlas/wxJS/gui/event/activate.h ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/gui/event/close.h =================================================================== --- ps/trunk/source/tools/atlas/wxJS/gui/event/close.h (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/gui/event/close.h (revision 5154) @@ -0,0 +1,64 @@ +/* + * wxJavaScript - close.h + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: close.h 598 2007-03-07 20:13:28Z fbraem $ + */ +#ifndef _WXJSCloseEvent_H +#define _WXJSCloseEvent_H + +///////////////////////////////////////////////////////////////////////////// +// Name: close.h +// Purpose: Ports wxCloseEvent to JavaScript +// Author: Franky Braem +// Modified by: +// Created: 08.02.02 +// Copyright: (c) 2001-2002 Franky Braem +// Licence: LGPL +///////////////////////////////////////////////////////////////////////////// +namespace wxjs +{ + namespace gui + { + typedef JSEvent PrivCloseEvent; + class CloseEvent : public ApiWrapper + { + public: + static bool GetProperty(PrivCloseEvent *p, JSContext *cx, JSObject *obj, int id, jsval *vp); + static bool SetProperty(PrivCloseEvent *p, JSContext *cx, JSObject *obj, int id, jsval *vp); + + virtual ~CloseEvent() + { + } + + enum + { + P_CAN_VETO + , P_LOGGING_OFF + , P_VETO + }; + + WXJS_DECLARE_PROPERTY_MAP() + }; + }; // namespace gui +}; // namespace wxjs + +#endif //_WXJSCloseEvent_H Property changes on: ps/trunk/source/tools/atlas/wxJS/gui/event/close.h ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/gui/control/helpbtn.cpp =================================================================== --- ps/trunk/source/tools/atlas/wxJS/gui/control/helpbtn.cpp (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/gui/control/helpbtn.cpp (revision 5154) @@ -0,0 +1,116 @@ +#include "precompiled.h" + +/* + * wxJavaScript - helpbtn.cpp + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: helpbtn.cpp 708 2007-05-14 15:30:45Z fbraem $ + */ +#ifndef WX_PRECOMP + #include +#endif + +#include "../../common/main.h" + + +#include "../event/jsevent.h" +#include "../event/command.h" + +#include "../misc/size.h" +#include "../misc/point.h" +#include "helpbtn.h" +#include "button.h" +#include "window.h" +#include "../errors.h" + +using namespace wxjs; +using namespace wxjs::gui; + +/*** + * control/helpbtn + * gui + * + * Instances of this class may be used to add a question mark button that + * when pressed, puts the application into context-help mode. It does this by + * creating a @wxContextHelp object which itself generates a @wxHelpEvent event + * when the user clicks on a window. + * + */ +WXJS_INIT_CLASS(ContextHelpButton, "wxContextHelpButton", 1) + +bool ContextHelpButton::AddProperty(wxContextHelpButton *p, + JSContext* WXUNUSED(cx), + JSObject* WXUNUSED(obj), + const wxString &prop, + jsval* WXUNUSED(vp)) +{ + return ButtonEventHandler::ConnectEvent(p, prop, true); +} + +bool ContextHelpButton::DeleteProperty(wxContextHelpButton *p, + JSContext* WXUNUSED(cx), + JSObject* WXUNUSED(obj), + const wxString &prop) +{ + return ButtonEventHandler::ConnectEvent(p, prop, false); +} + +/*** + * + * + * + * The parent of wxContextHelpButton. + * + * + * + * Constructs a new wxContextHelpButton object. + * + * + */ +wxContextHelpButton* ContextHelpButton::Construct(JSContext *cx, + JSObject *obj, + uintN argc, + jsval *argv, + bool WXUNUSED(constructing)) +{ + if ( argc > 0 ) + { + wxWindow *parent = Window::GetPrivate(cx, argv[0]); + if ( parent == NULL ) + { + JS_ReportError(cx, WXJS_NO_PARENT_ERROR, GetClass()->name); + return NULL; + } + JavaScriptClientData *clntParent = + dynamic_cast(parent->GetClientObject()); + if ( clntParent == NULL ) + { + JS_ReportError(cx, WXJS_NO_PARENT_ERROR, GetClass()->name); + return JS_FALSE; + } + JS_SetParent(cx, obj, clntParent->GetObject()); + + wxContextHelpButton *p = new wxContextHelpButton(parent); + p->SetClientObject(new JavaScriptClientData(cx, obj, true, false)); + return p; + } + return NULL; +} Property changes on: ps/trunk/source/tools/atlas/wxJS/gui/control/helpbtn.cpp ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/gui/event/scroll.h =================================================================== --- ps/trunk/source/tools/atlas/wxJS/gui/event/scroll.h (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/gui/event/scroll.h (revision 5154) @@ -0,0 +1,63 @@ +/* + * wxJavaScript - scroll.h + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: scroll.h 598 2007-03-07 20:13:28Z fbraem $ + */ +#ifndef _WXJSScrollEvent_H +#define _WXJSScrollEvent_H + +///////////////////////////////////////////////////////////////////////////// +// Name: ScrollEvent.h +// Purpose: ScrollEvent ports wxScrollEvent to JavaScript +// Author: Franky Braem +// Modified by: +// Created: 22.08.2002 +// Copyright: (c) 2001-2002 Franky Braem +// Licence: LGPL +///////////////////////////////////////////////////////////////////////////// + +namespace wxjs +{ + namespace gui + { + typedef JSEvent PrivScrollEvent; + class ScrollEvent : public ApiWrapper + { + public: + virtual ~ScrollEvent() + { + } + + static bool GetProperty(PrivScrollEvent *p, JSContext *cx, JSObject *obj, int id, jsval *vp); + + enum + { + P_ORIENTATION + , P_POSITION + }; + + WXJS_DECLARE_PROPERTY_MAP() + }; + }; // namespace gui +}; // namespace wxjs + +#endif //_WXJSScrollEvent_H Property changes on: ps/trunk/source/tools/atlas/wxJS/gui/event/scroll.h ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/gui/event/notify.cpp =================================================================== --- ps/trunk/source/tools/atlas/wxJS/gui/event/notify.cpp (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/gui/event/notify.cpp (revision 5154) @@ -0,0 +1,113 @@ +#include "precompiled.h" + +/* + * wxJavaScript - notify.cpp + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: notify.cpp 598 2007-03-07 20:13:28Z fbraem $ + */ +// notify.cpp + +#ifndef WX_PRECOMP + #include +#endif + +#include "../../common/main.h" + +#include "jsevent.h" +#include "notify.h" + +using namespace wxjs; +using namespace wxjs::gui; + +/*** + * event/notify + * gui + * + * This class is a prototype for several events. + * See @wxListEvent. + * + */ +WXJS_INIT_CLASS(NotifyEvent, "wxNotifyEvent", 0) + +/*** + * + * + * Allow/Disallow the change. Setting allowed to false, is the same as setting veto to true. + * + * + * When set to true, prevents the change announced by this event from happening. + * Setting veto to false, is the same as setting allow to true. + * + * + */ +WXJS_BEGIN_PROPERTY_MAP(NotifyEvent) + WXJS_READONLY_PROPERTY(P_ALLOWED, "allowed") + WXJS_PROPERTY(P_VETO, "veto") +WXJS_END_PROPERTY_MAP() + +bool NotifyEvent::GetProperty(PrivNotifyEvent *p, JSContext *cx, JSObject *obj, int id, jsval *vp) +{ + wxNotifyEvent *event = p->GetEvent(); + switch (id) + { + case P_ALLOWED: + *vp = ToJS(cx, event->IsAllowed()); + break; + case P_VETO: + *vp = ToJS(cx, ! event->IsAllowed()); + break; + } + return true; +} + +bool NotifyEvent::SetProperty(PrivNotifyEvent *p, JSContext *cx, JSObject *obj, int id, jsval *vp) +{ + wxNotifyEvent *event = p->GetEvent(); + switch (id) + { + case P_ALLOWED: + { + bool allow; + if ( FromJS(cx, *vp, allow) ) + { + if ( allow ) + event->Allow(); + else + event->Veto(); + } + break; + } + case P_VETO: + { + bool veto; + if ( FromJS(cx, *vp, veto) ) + { + if ( veto ) + event->Veto(); + else + event->Allow(); + } + break; + } + } + return true; +} Property changes on: ps/trunk/source/tools/atlas/wxJS/gui/event/notify.cpp ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/gui/event/treeevt.cpp =================================================================== --- ps/trunk/source/tools/atlas/wxJS/gui/event/treeevt.cpp (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/gui/event/treeevt.cpp (revision 5154) @@ -0,0 +1,132 @@ +#include "precompiled.h" + +/* + * wxJavaScript - treeevt.cpp + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: treeevt.cpp 598 2007-03-07 20:13:28Z fbraem $ + */ +// treeevt.cpp + +/** + * @if JS + * @page wxTreeEvent wxTreeEvent + * @since version 0.6 + * @endif + */ + +#ifndef WX_PRECOMP + #include +#endif + +#include + +#include "../../common/main.h" + +#include "../misc/point.h" + +#include "../control/treeid.h" + +#include "jsevent.h" +#include "treeevt.h" +#include "key.h" + +using namespace wxjs; +using namespace wxjs::gui; + +/*** + * event/treeevt + * gui + * + * This object is passed to a function that is set to a @wxTreeCtrl event property. + * + */ +WXJS_INIT_CLASS(TreeEvent, "wxTreeEvent", 0) + +/*** + * + * + * Returns true when the edit is cancelled. + * + * + * The item. + * + * + * Keycode when the event is a keypress event. See @wxKeyCode. + * + * + * A key event. + * + * + * The label. + * + * + * Get the previously selected item. + * + * + * The position of the mouse pointer when the event is a drag event. + * + * + */ +WXJS_BEGIN_PROPERTY_MAP(TreeEvent) + WXJS_READONLY_PROPERTY(P_ITEM, "item") + WXJS_READONLY_PROPERTY(P_OLD_ITEM, "oldItem") + WXJS_READONLY_PROPERTY(P_POINT, "point") + WXJS_READONLY_PROPERTY(P_KEY_CODE, "keyCode") + WXJS_READONLY_PROPERTY(P_KEY_EVENT, "keyEvent") + WXJS_READONLY_PROPERTY(P_LABEL, "label") + WXJS_READONLY_PROPERTY(P_IS_CANCELLED, "isEditCancelled") +WXJS_END_PROPERTY_MAP() + +bool TreeEvent::GetProperty(PrivTreeEvent *p, JSContext *cx, JSObject *obj, int id, jsval *vp) +{ + wxTreeEvent *event = p->GetEvent(); + switch (id) + { + case P_KEY_CODE: + *vp = ToJS(cx, event->GetKeyCode()); + break; + case P_KEY_EVENT: + { + wxKeyEvent evt(event->GetKeyEvent()); + PrivKeyEvent *jsEvent = new PrivKeyEvent(evt); + jsEvent->SetScoop(false); + *vp = KeyEvent::CreateObject(cx, jsEvent); + break; + } + case P_POINT: + *vp = Point::CreateObject(cx, new wxPoint(event->GetPoint())); + break; + case P_LABEL: + *vp = ToJS(cx, event->GetLabel()); + break; + case P_IS_CANCELLED: + *vp = ToJS(cx, event->IsEditCancelled()); + break; + case P_ITEM: + *vp = TreeItemId::CreateObject(cx, new wxTreeItemId(event->GetItem())); + break; + case P_OLD_ITEM: + *vp = TreeItemId::CreateObject(cx, new wxTreeItemId(event->GetOldItem())); + break; + } + return true; +} Property changes on: ps/trunk/source/tools/atlas/wxJS/gui/event/treeevt.cpp ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/gui/control/splitwin.cpp =================================================================== --- ps/trunk/source/tools/atlas/wxJS/gui/control/splitwin.cpp (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/gui/control/splitwin.cpp (revision 5154) @@ -0,0 +1,764 @@ +#include "precompiled.h" + +/* + * wxJavaScript - splitwin.cpp + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: splitwin.cpp 708 2007-05-14 15:30:45Z fbraem $ + */ + +#ifndef WX_PRECOMP + #include +#endif + +#include "../../common/main.h" + +#include "../misc/size.h" +#include "../misc/point.h" + + +#include "../event/jsevent.h" +#include "../event/split.h" + +#include "window.h" +#include "splitwin.h" +#include "../errors.h" + +using namespace wxjs; +using namespace wxjs::gui; + +/*** + * control/splitwin + * gui + * + * This class manages up to two subwindows. The current view can be split into two + * programmatically, and unsplit either programmatically or via the wxSplitterWindow + * user interface. + *

+ * The following example shows a frame that contains a @wxTreeCtrl and a @wxListCtrl. + * The frame is splitted horizontally. + *

+ *   wxTheApp.onInit = function()
+ *   {
+ *     var frame = new wxFrame(null, -1, "wxSplitterWindow Example");
+ *     var split = new wxSplitterWindow(frame, -1);
+ *     var tree = new wxTreeCtrl(split, -1);
+ *     var list = new wxListCtrl(split, -1);
+ *   
+ *     split.splitHorizontally(tree, list);
+ *   
+ *     topWindow = frame;
+ *     frame.show();
+ *   
+ *     return true;
+ *   };
+ *   
+ *   wxTheApp.mainLoop();
+ *  
+ *
+ */ +WXJS_INIT_CLASS(SplitterWindow, "wxSplitterWindow", 2) + +/*** + * + * + * Get/Set the minimum pane size. + * + * + * Get/Set the sash position in pixels. When set the panes, sash and border are redrawn. + * See @wxSplitterWindow#setSashPosition. + * + * + * Get/Set the split mode. + * + * + * Returns the left/top or only pane. + * + * + * Returns the right/bottom or only pane. + * + * + */ +WXJS_BEGIN_PROPERTY_MAP(SplitterWindow) + WXJS_PROPERTY(P_MIN_PANE_SIZE, "minimumPaneSize") + WXJS_PROPERTY(P_SASH_POS, "sashPosition") + WXJS_PROPERTY(P_SPLIT_MODE, "splitMode") + WXJS_READONLY_PROPERTY(P_WINDOW1, "window1") + WXJS_READONLY_PROPERTY(P_WINDOW2, "window2") + WXJS_READONLY_PROPERTY(P_IS_SPLIT, "isSplit") +WXJS_END_PROPERTY_MAP() + +bool SplitterWindow::GetProperty(wxSplitterWindow *p, + JSContext *cx, + JSObject* WXUNUSED(obj), + int id, + jsval *vp) +{ + switch (id) + { + case P_MIN_PANE_SIZE: + *vp = ToJS(cx, p->GetMinimumPaneSize()); + break; + case P_SASH_POS: + *vp = ToJS(cx, p->GetSashPosition()); + break; + case P_WINDOW1: + { + wxWindow *win = p->GetWindow1(); + if ( win == NULL ) + { + *vp = JSVAL_VOID; + } + else + { + JavaScriptClientData *data + = dynamic_cast(win->GetClientObject()); + *vp = ( data == NULL ) ? JSVAL_VOID + : OBJECT_TO_JSVAL(data->GetObject()); + } + break; + } + case P_WINDOW2: + { + wxWindow *win = p->GetWindow2(); + if ( win == NULL ) + { + *vp = JSVAL_VOID; + } + else + { + JavaScriptClientData *data + = dynamic_cast(win->GetClientObject()); + *vp = ( data == NULL ) ? JSVAL_VOID + : OBJECT_TO_JSVAL(data->GetObject()); + } + break; + } + case P_SPLIT_MODE: + *vp = ToJS(cx, (int) p->GetSplitMode()); + break; + case P_IS_SPLIT: + *vp = ToJS(cx, p->IsSplit()); + break; + } + return true; +} + +bool SplitterWindow::SetProperty(wxSplitterWindow *p, + JSContext *cx, + JSObject* WXUNUSED(obj), + int id, + jsval *vp) +{ + switch (id) + { + case P_MIN_PANE_SIZE: + { + int size; + if ( FromJS(cx, *vp, size) ) + p->SetMinimumPaneSize(size); + break; + } + case P_SASH_POS: + { + int pos; + if ( FromJS(cx, *vp, pos) ) + p->SetSashPosition(pos); + break; + } + } + return true; +} + +bool SplitterWindow::AddProperty(wxSplitterWindow *p, + JSContext* WXUNUSED(cx), + JSObject* WXUNUSED(obj), + const wxString &prop, + jsval* WXUNUSED(vp)) +{ + if ( WindowEventHandler::ConnectEvent(p, prop, true) ) + return true; + + SplitterEventHandler::ConnectEvent(p, prop, true); + + return true; +} + +bool SplitterWindow::DeleteProperty(wxSplitterWindow *p, + JSContext* WXUNUSED(cx), + JSObject* WXUNUSED(obj), + const wxString &prop) +{ + if ( WindowEventHandler::ConnectEvent(p, prop, false) ) + return true; + + SplitterEventHandler::ConnectEvent(p, prop, false); + return true; +} + +/*** + * + * + * Draws a 3D effect border and sash. + * Draws a 3D effect sash. + * Draws a 3D effect border. + * Draws the ends of the sash (so the window can be used without a border). + * Draws a thin black border around the window. + * No border, and a black sash. + * Always allow to unsplit, even with the minimum pane size other than zero. + * Don't draw XOR line but resize the child windows immediately. + * + * + * + * + * wxSplitMode is ported as a separate class + * + * + */ +WXJS_BEGIN_CONSTANT_MAP(SplitterWindow) + WXJS_CONSTANT(wxSP_, 3D) + WXJS_CONSTANT(wxSP_, 3DSASH) + WXJS_CONSTANT(wxSP_, 3DBORDER) + WXJS_CONSTANT(wxSP_, FULLSASH) + WXJS_CONSTANT(wxSP_, BORDER) + WXJS_CONSTANT(wxSP_, NOBORDER) + WXJS_CONSTANT(wxSP_, PERMIT_UNSPLIT) + WXJS_CONSTANT(wxSP_, LIVE_UPDATE) +WXJS_END_CONSTANT_MAP() + +void SplitterWindow::InitClass(JSContext *cx, + JSObject *obj, + JSObject* WXUNUSED(proto)) +{ + JSConstDoubleSpec wxSplitModeMap[] = + { + WXJS_CONSTANT(wxSPLIT_, VERTICAL) + WXJS_CONSTANT(wxSPLIT_, HORIZONTAL) + { 0 } + }; + JSObject *constObj = JS_DefineObject(cx, obj, "wxSplitMode", + NULL, NULL, + JSPROP_READONLY | JSPROP_PERMANENT); + JS_DefineConstDoubles(cx, constObj, wxSplitModeMap); + + SplitterEventHandler::InitConnectEventMap(); +} + +/*** + * + * + * + * + * The parent of wxSplitterWindow. + * + * + * An window identifier. Use -1 when you don't need it. + * + * + * The position of the SplitterWindow control on the given parent. + * + * + * The size of the SplitterWindow control. + * + * + * The wxSplitterWindow style. + * + * + * + * Constructs a new wxSplitterWindow object. + * + * + */ +wxSplitterWindow* SplitterWindow::Construct(JSContext *cx, + JSObject *obj, + uintN argc, + jsval *argv, + bool WXUNUSED(constructing)) +{ + wxSplitterWindow *p = new wxSplitterWindow(); + SetPrivate(cx, obj, p); + + if ( argc > 0 ) + { + jsval rval; + create(cx, obj, argc, argv, &rval); + } + return p; +} + +WXJS_BEGIN_METHOD_MAP(SplitterWindow) + WXJS_METHOD("create", create, 2) + WXJS_METHOD("setSashPosition", setSashPosition, 1) + WXJS_METHOD("initialize", initialize, 1) + WXJS_METHOD("replaceWindow", replaceWindow, 2) + WXJS_METHOD("splitHorizontally", splitHorizontally, 2) + WXJS_METHOD("splitVertically", splitVertically, 2) + WXJS_METHOD("unsplit", unsplit, 0) +WXJS_END_METHOD_MAP() + +/*** + * + * + * + * The parent of wxSplitterWindow. + * + * + * An window identifier. Use -1 when you don't need it. + * + * + * The position of the SplitterWindow control on the given parent. + * + * + * The size of the SplitterWindow control. + * + * + * The wxSplitterWindow style. + * + * + * + * Constructs a new wxSplitterWindow object. + * + * + */ +JSBool SplitterWindow::create(JSContext *cx, + JSObject *obj, + uintN argc, + jsval *argv, + jsval *rval) +{ + wxSplitterWindow *p = GetPrivate(cx, obj); + *rval = JSVAL_FALSE; + + if ( argc > 5 ) + argc = 5; + + int style = wxSP_3D; + const wxPoint *pt = &wxDefaultPosition; + const wxSize *size = &wxDefaultSize; + + switch(argc) + { + case 5: + if ( ! FromJS(cx, argv[4], style) ) + { + JS_ReportError(cx, WXJS_INVALID_ARG_TYPE, 5, "Integer"); + return JS_FALSE; + } + // Fall through + case 4: + size = Size::GetPrivate(cx, argv[3]); + if ( size == NULL ) + { + JS_ReportError(cx, WXJS_INVALID_ARG_TYPE, 4, "wxSize"); + return JS_FALSE; + } + // Fall through + case 3: + pt = Point::GetPrivate(cx, argv[2]); + if ( pt == NULL ) + { + JS_ReportError(cx, WXJS_INVALID_ARG_TYPE, 3, "wxPoint"); + return JS_FALSE; + } + // Fall through + default: + + int id; + if ( ! FromJS(cx, argv[1], id) ) + { + JS_ReportError(cx, WXJS_INVALID_ARG_TYPE, 2, "Integer"); + return JS_FALSE; + } + + wxWindow *parent = Window::GetPrivate(cx, argv[0]); + if ( parent == NULL ) + { + JS_ReportError(cx, WXJS_NO_PARENT_ERROR, GetClass()->name); + return JS_FALSE; + } + JavaScriptClientData *clntParent = + dynamic_cast(parent->GetClientObject()); + if ( clntParent == NULL ) + { + JS_ReportError(cx, WXJS_NO_PARENT_ERROR, GetClass()->name); + return JS_FALSE; + } + JS_SetParent(cx, obj, clntParent->GetObject()); + + if ( p->Create(parent, id, *pt, *size, style) ) + { + *rval = JSVAL_TRUE; + p->SetClientObject(new JavaScriptClientData(cx, obj, true, false)); + } + } + return JS_TRUE; +} + +/*** + * + * + * + * The sash position in pixels. + * + * + * When true (the default) resizes the panes and redraws the sash and border. + * + * + * + * Sets the sash position. + * + * + */ +JSBool SplitterWindow::setSashPosition(JSContext *cx, + JSObject *obj, + uintN argc, + jsval *argv, + jsval* WXUNUSED(rval)) +{ + wxSplitterWindow *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + int pos; + if ( ! FromJS(cx, argv[0], pos) ) + return JS_FALSE; + + bool redraw = true; + if ( argc > 1 + && ! FromJS(cx, argv[1], redraw) ) + return JS_FALSE; + + p->SetSashPosition(pos, redraw); + return JS_TRUE; +} + +/*** + * + * + * + * + * + * Initializes the splitter window to have one pane. + * This should be called if you wish to initially view + * only a single pane in the splitter window. + * + * + */ +JSBool SplitterWindow::initialize(JSContext *cx, + JSObject *obj, + uintN WXUNUSED(argc), + jsval *argv, + jsval* WXUNUSED(rval)) +{ + wxSplitterWindow *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + wxWindow *win = Window::GetPrivate(cx, argv[0]); + if ( win != NULL ) + { + p->Initialize(win); + return JS_TRUE; + } + return JS_FALSE; +} + +/*** + * + * + * + * + * + * + * This function replaces one of the windows managed by the wxSplitterWindow + * with another one. It is in general better to use it instead of calling + * @wxSplitterWindow#unsplit and then resplitting the window back because + * it will provoke much less flicker (if any). It is valid to call this function + * whether the splitter has two windows or only one. + *

+ * OldWindow must specify one of the windows managed by the splitter. + * If the parameters are incorrect or the window couldn't be replaced, false + * is returned. Otherwise the function will return true, but please notice that + * it will not destroy the replaced window and you may wish to do it yourself. + *
+ *
+ */ +JSBool SplitterWindow::replaceWindow(JSContext *cx, + JSObject *obj, + uintN WXUNUSED(argc), + jsval *argv, + jsval *rval) +{ + wxSplitterWindow *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + wxWindow *oldWin = Window::GetPrivate(cx, argv[0]); + if ( oldWin == NULL ) + return JS_FALSE; + + wxWindow *newWin = Window::GetPrivate(cx, argv[1]); + if ( newWin == NULL ) + return JS_FALSE; + + *rval = ToJS(cx, p->ReplaceWindow(oldWin, newWin)); + + return JS_TRUE; +} + +/*** + * + * + * + * The top pane + * + * + * The bottom pane + * + * + * The initial position of the sash. If this value is positive, it specifies + * the size of the upper pane. If it is negative, it is absolute value gives + * the size of the lower pane. Finally, specify 0 (default) to choose the + * default position (half of the total window height). + * + * + * + * Initializes the top and bottom panes of the splitter window. + * This should be called if you wish to initially view two panes. It can also + * be called at any subsequent time, but the application should check that the + * window is not currently split using @wxSplitterWindow#isSplit. + * + * + */ +JSBool SplitterWindow::splitHorizontally(JSContext *cx, + JSObject *obj, + uintN argc, + jsval *argv, + jsval *rval) +{ + wxSplitterWindow *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + wxWindow *win1 = Window::GetPrivate(cx, argv[0]); + if ( win1 == NULL ) + return JS_FALSE; + + wxWindow *win2 = Window::GetPrivate(cx, argv[1]); + if ( win2 == NULL ) + return JS_FALSE; + + int pos = 0; + if ( argc > 2 + && FromJS(cx, argv[2], pos) ) + return JS_FALSE; + + *rval = ToJS(cx, p->SplitHorizontally(win1, win2, pos)); + return JS_TRUE; +} + +/*** + * + * + * + * The top pane + * + * + * The bottom pane + * + * + * The initial position of the sash. If this value is positive, it specifies + * the size of the left pane. If it is negative, it is absolute value gives + * the size of the right pane. Finally, specify 0 (default) to choose the + * default position (half of the total window width). + * + * + * + * Initializes the left and right panes of the splitter window. + * This should be called if you wish to initially view two panes. It can also + * be called at any subsequent time, but the application should check that the + * window is not currently split using @wxSplitterWindow#isSplit. + * + * + */ +JSBool SplitterWindow::splitVertically(JSContext *cx, + JSObject *obj, + uintN argc, + jsval *argv, + jsval *rval) +{ + wxSplitterWindow *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + wxWindow *win1 = Window::GetPrivate(cx, argv[0]); + if ( win1 == NULL ) + return JS_FALSE; + + wxWindow *win2 = Window::GetPrivate(cx, argv[1]); + if ( win2 == NULL ) + return JS_FALSE; + + int pos = 0; + if ( argc > 2 + && FromJS(cx, argv[2], pos) ) + return JS_FALSE; + + *rval = ToJS(cx, p->SplitVertically(win1, win2, pos)); + return JS_TRUE; +} + +/*** + * + * + * + * The pane to hide. When not specified, the right or bottom pane is hidden. + * + * + * + * Unsplits the window. + * + * + */ +JSBool SplitterWindow::unsplit(JSContext *cx, + JSObject *obj, + uintN argc, + jsval *argv, + jsval *rval) +{ + wxSplitterWindow *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + if ( argc == 1 ) + { + wxWindow *win = Window::GetPrivate(cx, argv[0]); + if ( win != NULL ) + { + *rval = ToJS(cx, p->Unsplit(win)); + return JS_TRUE; + } + } + else + { + *rval = ToJS(cx, p->Unsplit()); + return JS_TRUE; + } + return JS_FALSE; +} + +/*** + * + * + */ +WXJS_INIT_EVENT_MAP(wxSplitterWindow) +const wxString WXJS_SASH_POS_CHANGING_EVENT = wxT("onSashPosChanging"); +const wxString WXJS_SASH_POS_CHANGED_EVENT = wxT("onSashPosChanged"); +const wxString WXJS_UNSPLIT_EVENT = wxT("onUnsplit"); +const wxString WXJS_DCLICK_EVENT = wxT("onDClick"); + +void SplitterEventHandler::OnSashPosChanging(wxSplitterEvent &event) +{ + PrivSplitterEvent::Fire(event, WXJS_SASH_POS_CHANGING_EVENT); +} + +void SplitterEventHandler::OnSashPosChanged(wxSplitterEvent &event) +{ + PrivSplitterEvent::Fire(event, WXJS_SASH_POS_CHANGED_EVENT); +} + +void SplitterEventHandler::OnUnsplit(wxSplitterEvent &event) +{ + PrivSplitterEvent::Fire(event, WXJS_UNSPLIT_EVENT); +} + +void SplitterEventHandler::OnDClick(wxSplitterEvent &event) +{ + PrivSplitterEvent::Fire(event, WXJS_DCLICK_EVENT); +} + +void SplitterEventHandler::ConnectSashPosChanging(wxSplitterWindow *p, + bool connect) +{ + if ( connect ) + { + p->Connect(wxEVT_COMMAND_SPLITTER_SASH_POS_CHANGING, + wxSplitterEventHandler(OnSashPosChanging)); + } + else + { + p->Disconnect(wxEVT_COMMAND_SPLITTER_SASH_POS_CHANGING, + wxSplitterEventHandler(OnSashPosChanging)); + } +} + +void SplitterEventHandler::ConnectSashPosChanged(wxSplitterWindow *p, + bool connect) +{ + if ( connect ) + { + p->Connect(wxEVT_COMMAND_SPLITTER_SASH_POS_CHANGED, + wxSplitterEventHandler(OnSashPosChanged)); + } + else + { + p->Disconnect(wxEVT_COMMAND_SPLITTER_SASH_POS_CHANGED, + wxSplitterEventHandler(OnSashPosChanged)); + } +} + +void SplitterEventHandler::ConnectUnsplit(wxSplitterWindow *p, + bool connect) +{ + if ( connect ) + { + p->Connect(wxEVT_COMMAND_SPLITTER_UNSPLIT, + wxSplitterEventHandler(OnUnsplit)); + } + else + { + p->Disconnect(wxEVT_COMMAND_SPLITTER_UNSPLIT, + wxSplitterEventHandler(OnUnsplit)); + } +} + +void SplitterEventHandler::ConnectDClick(wxSplitterWindow *p, + bool connect) +{ + if ( connect ) + { + p->Connect(wxEVT_COMMAND_SPLITTER_DOUBLECLICKED, + wxSplitterEventHandler(OnDClick)); + } + else + { + p->Disconnect(wxEVT_COMMAND_SPLITTER_DOUBLECLICKED, + wxSplitterEventHandler(OnDClick)); + } +} + +void SplitterEventHandler::InitConnectEventMap() +{ + AddConnector(WXJS_SASH_POS_CHANGING_EVENT, ConnectSashPosChanging); + AddConnector(WXJS_SASH_POS_CHANGED_EVENT, ConnectSashPosChanged); + AddConnector(WXJS_UNSPLIT_EVENT, ConnectUnsplit); + AddConnector(WXJS_DCLICK_EVENT, ConnectDClick); +} Property changes on: ps/trunk/source/tools/atlas/wxJS/gui/control/splitwin.cpp ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/gui/control/chklstbxchk.h =================================================================== --- ps/trunk/source/tools/atlas/wxJS/gui/control/chklstbxchk.h (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/gui/control/chklstbxchk.h (revision 5154) @@ -0,0 +1,49 @@ +/* + * wxJavaScript - chklstbxchk.h + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: chklstbxchk.h 711 2007-05-14 20:59:29Z fbraem $ + */ +#ifndef _wxjs_gui_chklstbxchk_h +#define _wxjs_gui_chklstbxchk_h + +namespace wxjs +{ + namespace gui + { + class CheckListBoxItem : public ApiWrapper + { + public: + static bool GetProperty(Index *p, + JSContext *cx, + JSObject *obj, + int id, + jsval *vp); + static bool SetProperty(Index *p, + JSContext *cx, + JSObject *obj, + int id, + jsval *vp); + }; + }; // namespace gui +}; // namespace wxjs + +#endif // _wxjs_gui_chklstbxchk_h Property changes on: ps/trunk/source/tools/atlas/wxJS/gui/control/chklstbxchk.h ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/gui/control/control.cpp =================================================================== --- ps/trunk/source/tools/atlas/wxJS/gui/control/control.cpp (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/gui/control/control.cpp (revision 5154) @@ -0,0 +1,101 @@ +#include "precompiled.h" + +/* + * wxJavaScript - control.cpp + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: control.cpp 672 2007-04-12 20:29:39Z fbraem $ + */ + +#ifndef WX_PRECOMP + #include +#endif + +#include "../../common/main.h" + +#include "control.h" + +using namespace wxjs; +using namespace wxjs::gui; + +/*** + * control/control + * gui + * + * This is the prototype for a control or 'widget'. + * A control is generally a small window which processes user input + * and/or displays one or more item of data. + * + */ +WXJS_INIT_CLASS(Control, "wxControl", 0) + +/*** + * + * + * Get/Set the label + * + * + */ +WXJS_BEGIN_PROPERTY_MAP(Control) + WXJS_PROPERTY(P_LABEL, "label") +WXJS_END_PROPERTY_MAP() + +bool Control::GetProperty(wxControl *p, + JSContext *cx, + JSObject* WXUNUSED(obj), + int id, + jsval *vp) +{ + if ( id == P_LABEL ) + *vp = ToJS(cx, p->GetLabel()); + return true; +} + +bool Control::SetProperty(wxControl *p, + JSContext *cx, + JSObject* WXUNUSED(obj), + int id, + jsval *vp) +{ + if ( id == P_LABEL ) + { + wxString label; + FromJS(cx, *vp, label); + p->SetLabel(label); + } + return true; +} + +WXJS_BEGIN_METHOD_MAP(Control) +WXJS_END_METHOD_MAP() + +//TODO: An event can't be created yet, so this function is not used. +JSBool Control::command(JSContext *cx, + JSObject *obj, + uintN WXUNUSED(argc), + jsval* WXUNUSED(argv), + jsval* WXUNUSED(rval)) +{ + wxControl *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + return JS_TRUE; +} Property changes on: ps/trunk/source/tools/atlas/wxJS/gui/control/control.cpp ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/gui/control/htmlwin.h =================================================================== --- ps/trunk/source/tools/atlas/wxJS/gui/control/htmlwin.h (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/gui/control/htmlwin.h (revision 5154) @@ -0,0 +1,121 @@ +/* + * wxJavaScript - htmlwin.h + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: htmlwin.h 682 2007-04-24 20:38:18Z fbraem $ + */ +#ifndef _WXJSHtmlWindow_H +#define _WXJSHtmlWindow_H + +#include + +#include "../../common/evtconn.h" + +namespace wxjs +{ + namespace gui + { + class HtmlWindow : public ApiWrapper + { + public: + + static void InitClass(JSContext* cx, + JSObject* obj, + JSObject* proto); + + static bool AddProperty(wxHtmlWindow *p, + JSContext *cx, + JSObject *obj, + const wxString &prop, + jsval *vp); + static bool DeleteProperty(wxHtmlWindow *p, + JSContext* cx, + JSObject* obj, + const wxString &prop); + + static bool GetProperty(wxHtmlWindow *p, + JSContext *cx, + JSObject *obj, + int id, + jsval *vp); + static bool SetProperty(wxHtmlWindow *p, + JSContext *cx, + JSObject *obj, + int id, + jsval *vp); + + static wxHtmlWindow* Construct(JSContext *cx, + JSObject *obj, + uintN argc, + jsval *argv, + bool constructing); + + WXJS_DECLARE_PROPERTY_MAP() + + /** + * Property Ids. + */ + enum + { + P_OPENED_ANCHOR + , P_OPENED_PAGE + , P_OPENED_PAGE_TITLE + , P_RELATED_FRAME + , P_HISTORY_CAN_BACK + , P_HISTORY_CAN_FORWARD + , P_TEXT + , P_SELECTION_TEXT + }; + + WXJS_DECLARE_METHOD_MAP() + WXJS_DECLARE_METHOD(create); + WXJS_DECLARE_METHOD(appendToPage); + WXJS_DECLARE_METHOD(historyBack); + WXJS_DECLARE_METHOD(historyForward); + WXJS_DECLARE_METHOD(historyClear); + WXJS_DECLARE_METHOD(loadFile); + WXJS_DECLARE_METHOD(loadPage); + WXJS_DECLARE_METHOD(setPage); + WXJS_DECLARE_METHOD(setRelatedFrame); + WXJS_DECLARE_METHOD(setRelatedStatusBar); + WXJS_DECLARE_METHOD(selectAll); + WXJS_DECLARE_METHOD(selectLine); + WXJS_DECLARE_METHOD(selectWord); + WXJS_DECLARE_METHOD(setBorders); + WXJS_DECLARE_METHOD(setFonts); + + WXJS_DECLARE_CONSTANT_MAP() + }; + + class HtmlLinkEventHandler : public EventConnector + , public wxEvtHandler + { + public: + // Events + void OnLinkClicked(wxHtmlLinkEvent &event); + static void InitConnectEventMap(); + private: + static void ConnectLinkClicked(wxHtmlWindow *p, bool connect); + }; + + }; // namespace gui +}; //namespace wxjs +#endif //_WXJSHtmlWindow_H Property changes on: ps/trunk/source/tools/atlas/wxJS/gui/control/htmlwin.h ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/gui/control/listitem.cpp =================================================================== --- ps/trunk/source/tools/atlas/wxJS/gui/control/listitem.cpp (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/gui/control/listitem.cpp (revision 5154) @@ -0,0 +1,327 @@ +#include "precompiled.h" + +/* + * wxJavaScript - listitem.cpp + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: listitem.cpp 688 2007-04-27 20:45:09Z fbraem $ + */ +// listitem.cpp +#include +#ifndef WX_PRECOMP + #include +#endif +#include + +#include "../../common/main.h" + +#include "../misc/app.h" +#include "../misc/font.h" +#include "../misc/colour.h" + +#include "listitem.h" +#include "listctrl.h" + +using namespace wxjs; +using namespace wxjs::gui; + +/*** + * control/listitem + * gui + * + * This class stores information about a @wxListCtrl item or column. + * + */ +WXJS_INIT_CLASS(ListItem, "wxListItem", 0) + +/*** + * + * + * The column alignment. See @wxListCtrl#wxListColumnFormat. + * + * + * Get/Set the background colour of the item. + * + * + * Get/Set the column. + * + * + * Get/Set the associated data. + * + * + * Get/Set the font of the item. + * + * + * Returns true when the item has attributes. + * + * + * Get/Set index of the item. + * + * + * Get/Set the index of the image in the associated imagelist of the list control. + * + * + * Get/Set the mask. The mask indicates which fields of wxListItem are valid. + * See @wxListMask + * + * + * Get/Set the state. See @wxListState + * + * + * Get/Set the state mask. This indicates which state is valid. See @wxListState + * + * + * Get/Set the text of the item. + * + * + * Get/Set the text colour. + * + * + * Get/Set the width. + * + * + */ +WXJS_BEGIN_PROPERTY_MAP(ListItem) + WXJS_PROPERTY(P_ALIGN, "align") + WXJS_PROPERTY(P_BG_COLOUR, "backgroundColour") + WXJS_PROPERTY(P_COLUMN, "column") + WXJS_PROPERTY(P_DATA, "data") + WXJS_PROPERTY(P_FONT, "font") + WXJS_READONLY_PROPERTY(P_HAS_ATTR, "hasAttributes") + WXJS_PROPERTY(P_ID, "id") + WXJS_PROPERTY(P_IMAGE, "image") + WXJS_PROPERTY(P_MASK, "mask") + WXJS_PROPERTY(P_STATE, "state") + WXJS_PROPERTY(P_STATE_MASK, "stateMask") + WXJS_PROPERTY(P_TEXT, "text") + WXJS_PROPERTY(P_TEXT_COLOUR, "textColour") + WXJS_PROPERTY(P_WIDTH, "width") +WXJS_END_PROPERTY_MAP() + +bool ListItem::GetProperty(wxListItem *p, + JSContext *cx, + JSObject* WXUNUSED(obj), + int id, + jsval *vp) +{ + switch (id) + { + case P_MASK: + *vp = ToJS(cx, p->GetMask()); + break; + case P_ID: + *vp = ToJS(cx, p->GetId()); + break; + case P_COLUMN: + *vp = ToJS(cx, p->GetColumn()); + break; + case P_STATE: + *vp = ToJS(cx, p->GetState()); + break; + case P_TEXT: + *vp = ToJS(cx, p->GetText()); + break; + case P_IMAGE: + *vp = ToJS(cx, p->GetImage()); + break; + case P_DATA: + { + ListObjectData *data = (ListObjectData*) p->GetData(); + *vp = ( data == NULL ) ? JSVAL_VOID : data->GetJSVal(); + break; + } + case P_WIDTH: + *vp = ToJS(cx, p->GetWidth()); + break; + case P_ALIGN: + *vp = ToJS(cx, (int) p->GetAlign()); + break; + case P_TEXT_COLOUR: + { + wxColour colour = p->GetTextColour(); + *vp = ( colour == wxNullColour ) ? JSVAL_VOID + : Colour::CreateObject(cx, new wxColour(colour)); + break; + } + case P_BG_COLOUR: + { + wxColour colour = p->GetBackgroundColour(); + *vp = ( colour == wxNullColour ) ? JSVAL_VOID + : Colour::CreateObject(cx, new wxColour(colour)); + break; + } + case P_FONT: + { + wxFont font = p->GetFont(); + *vp = ( font == wxNullFont ) ? JSVAL_VOID + : Font::CreateObject(cx, new wxFont(font)); + break; + } + case P_HAS_ATTR: + *vp = ToJS(cx, p->HasAttributes()); + break; + } + return true; +} + +bool ListItem::SetProperty(wxListItem *p, + JSContext *cx, + JSObject* WXUNUSED(obj), + int id, + jsval *vp) +{ + switch (id) + { + case P_MASK: + { + long mask; + if ( FromJS(cx, *vp, mask) ) + p->SetMask(mask); + break; + } + case P_ID: + { + long id; + if ( FromJS(cx, *vp, id) ) + p->SetId(id); + break; + } + case P_COLUMN: + { + int column; + if ( FromJS(cx, *vp, column) ) + p->SetColumn(column); + break; + } + case P_STATE: + { + long state; + if ( FromJS(cx, *vp, state) ) + p->SetState(state); + break; + } + case P_STATE_MASK: + { + long stateMask; + if ( FromJS(cx, *vp, stateMask) ) + p->SetStateMask(stateMask); + break; + } + case P_TEXT: + { + wxString text; + FromJS(cx, *vp, text); + p->SetText(text); + break; + } + case P_IMAGE: + { + int img; + if ( FromJS(cx, *vp, img) ) + p->SetImage(img); + break; + } + case P_DATA: + { + ListObjectData *data = (ListObjectData*) p->GetData(); + if ( data != NULL ) + { + delete data; + data = NULL; + } + + data = new ListObjectData(cx, *vp); + p->SetData((long) data); + break; + } + case P_WIDTH: + { + int width; + if ( FromJS(cx, *vp, width) ) + p->SetWidth(width); + break; + } + case P_ALIGN: + { + int align; + if ( FromJS(cx, *vp, align) ) + p->SetAlign((wxListColumnFormat) align); + break; + } + case P_TEXT_COLOUR: + { + wxColour *colour = Colour::GetPrivate(cx, *vp); + if ( colour != NULL ) + p->SetTextColour(*colour); + break; + } + case P_BG_COLOUR: + { + wxColour *colour = Colour::GetPrivate(cx, *vp); + if ( colour != NULL ) + p->SetBackgroundColour(*colour); + break; + } + case P_FONT: + { + wxFont *font = Font::GetPrivate(cx, *vp); + if ( font != NULL ) + p->SetFont(*font); + break; + } + } + return true; +} + +/*** + * + * + * + * The index of the item + * + * + * + * Creates a new wxListItem object. + * See @wxListCtrl#getItem and @wxListCtrl#setItem + * + * + */ +wxListItem *ListItem::Construct(JSContext *cx, + JSObject* WXUNUSED(obj), + uintN argc, + jsval *argv, + bool WXUNUSED(constructing)) +{ + if ( argc == 0 ) + return new wxListItem(); + else if ( argc == 1 ) + { + int id; + if ( FromJS(cx, argv[0], id) ) + { + wxListItem *p = new wxListItem(); + p->SetId(id); + return p; + } + } + return NULL; +} + Property changes on: ps/trunk/source/tools/atlas/wxJS/gui/control/listitem.cpp ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/gui/event/cal.cpp =================================================================== --- ps/trunk/source/tools/atlas/wxJS/gui/event/cal.cpp (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/gui/event/cal.cpp (revision 5154) @@ -0,0 +1,77 @@ +#include "precompiled.h" + +/* + * wxJavaScript - cal.cpp + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: cal.cpp 598 2007-03-07 20:13:28Z fbraem $ + */ +// cal.cpp + +#ifndef WX_PRECOMP + #include +#endif + +#include "../../common/main.h" + +#include "jsevent.h" +#include "cal.h" + +using namespace wxjs; +using namespace wxjs::gui; + +/*** + * event/cal + * gui + * + * This object is passed to a function that is set to a @wxCalendarCtrl event property. + * + */ +WXJS_INIT_CLASS(CalendarEvent, "wxCalendarEvent", 0) + +/*** + * + * + * Returns the date. + * + * + * Returns the weekday + * + * + */ +WXJS_BEGIN_PROPERTY_MAP(CalendarEvent) + WXJS_READONLY_PROPERTY(P_DATE, "date") + WXJS_READONLY_PROPERTY(P_WEEKDAY, "weekDay") +WXJS_END_PROPERTY_MAP() + +bool CalendarEvent::GetProperty(PrivCalendarEvent *p, JSContext *cx, JSObject *obj, int id, jsval *vp) +{ + switch (id) + { + case P_DATE: + *vp = ToJS(cx, p->GetEvent()->GetDate()); + break; + case P_WEEKDAY: + *vp = ToJS(cx, (int) p->GetEvent()->GetWeekDay()); + break; + } + return true; +} Property changes on: ps/trunk/source/tools/atlas/wxJS/gui/event/cal.cpp ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/gui/event/move.cpp =================================================================== --- ps/trunk/source/tools/atlas/wxJS/gui/event/move.cpp (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/gui/event/move.cpp (revision 5154) @@ -0,0 +1,74 @@ +#include "precompiled.h" + +/* + * wxJavaScript - move.cpp + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: move.cpp 598 2007-03-07 20:13:28Z fbraem $ + */ +// move.cpp + +#ifndef WX_PRECOMP + #include +#endif + +#include "../../common/main.h" +#include "../../common/apiwrap.h" + +#include "jsevent.h" +#include "../misc/point.h" +#include "move.h" + +using namespace wxjs; +using namespace wxjs::gui; + +/*** + * event/move + * gui + * + * A move event holds information about move change events. + * Handle this event by setting a function to the @wxWindow#onMove + * property on a @wxWindow object. + * + */ +WXJS_INIT_CLASS(MoveEvent, "wxMoveEvent", 0) + +/*** + * + * + * Returns the position of the window generating this event. + * + * + */ +WXJS_BEGIN_PROPERTY_MAP(MoveEvent) + WXJS_READONLY_PROPERTY(P_POSITION, "position") +WXJS_END_PROPERTY_MAP() + +bool MoveEvent::GetProperty(PrivMoveEvent *p, JSContext *cx, JSObject *obj, int id, jsval *vp) +{ + wxMoveEvent *event = p->GetEvent(); + + if ( id == P_POSITION ) + { + *vp = Point::CreateObject(cx, new wxPoint(event->GetPosition())); + } + return true; +} Property changes on: ps/trunk/source/tools/atlas/wxJS/gui/event/move.cpp ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/gui/event/jsevent.cpp =================================================================== --- ps/trunk/source/tools/atlas/wxJS/gui/event/jsevent.cpp (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/gui/event/jsevent.cpp (revision 5154) @@ -0,0 +1,176 @@ +#include "precompiled.h" + +/* + * wxJavaScript - jsevent.cpp + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: jsevent.cpp 693 2007-05-03 20:37:24Z fbraem $ + */ +#ifndef WX_PRECOMP + #include +#endif + +#include "../../common/main.h" + +#include "jsevent.h" +#include "event.h" +#include "command.h" +#include "iconize.h" +#include "close.h" +#include "key.h" +#include "activate.h" +#include "mouse.h" +#include "move.h" +#include "cal.h" +#include "findr.h" +#include "scroll.h" +#include "scrollwin.h" +#include "help.h" +#include "sizeevt.h" +#include "htmllink.h" +#include "split.h" + +#include "notify.h" +#include "listevt.h" +#include "treeevt.h" + +using namespace wxjs; +using namespace wxjs::gui; + +bool wxjs::gui::InitEventClasses(JSContext *cx, JSObject *global) +{ + JSObject *obj = Event::JSInit(cx, global); + wxASSERT_MSG(obj != NULL, wxT("wxEvent creation prototype failed")); + if ( !obj ) + return false; + + obj = CommandEvent::JSInit(cx, global, Event::GetClassPrototype()); + wxASSERT_MSG(obj != NULL, wxT("wxCommandEvent prototype creation failed")); + if (! obj ) + return false; + + obj = KeyEvent::JSInit(cx, global, Event::GetClassPrototype()); + wxASSERT_MSG(obj != NULL, wxT("wxKeyEvent prototype creation failed")); + if (! obj ) + return false; + + obj = ActivateEvent::JSInit(cx, global, Event::GetClassPrototype()); + wxASSERT_MSG(obj != NULL, wxT("wxActivateEvent prototype creation failed")); + if (! obj ) + return false; + + obj = CloseEvent::JSInit(cx, global, Event::GetClassPrototype()); + wxASSERT_MSG(obj != NULL, wxT("wxCloseEvent prototype creation failed")); + if (! obj ) + return false; + + obj = FocusEvent::JSInit(cx, global, Event::GetClassPrototype()); + wxASSERT_MSG(obj != NULL, wxT("wxFocusEvent prototype creation failed")); + if (! obj ) + return false; + + obj = InitDialogEvent::JSInit(cx, global, Event::GetClassPrototype()); + wxASSERT_MSG(obj != NULL, wxT("wxInitDialogEvent prototype creation failed")); + if (! obj ) + return false; + + obj = MouseEvent::JSInit(cx, global, Event::GetClassPrototype()); + wxASSERT_MSG(obj != NULL, wxT("wxMouseEvent prototype creation failed")); + if (! obj ) + return false; + + obj = MoveEvent::JSInit(cx, global, Event::GetClassPrototype()); + wxASSERT_MSG(obj != NULL, wxT("wxMoveEvent prototype creation failed")); + if (! obj ) + return false; + + obj = SizeEvent::JSInit(cx, global, Event::GetClassPrototype()); + wxASSERT_MSG(obj != NULL, wxT("wxSizeEvent prototype creation failed")); + if (! obj ) + return false; + + obj = CalendarEvent::JSInit(cx, global, Event::GetClassPrototype()); + wxASSERT_MSG(obj != NULL, wxT("wxCalendarEvent prototype creation failed")); + if (! obj ) + return false; + + obj = IconizeEvent::JSInit(cx, global, Event::GetClassPrototype()); + wxASSERT_MSG(obj != NULL, wxT("wxIconizeEvent prototype creation failed")); + if (! obj ) + return false; + + obj = MaximizeEvent::JSInit(cx, global, Event::GetClassPrototype()); + wxASSERT_MSG(obj != NULL, wxT("wxMaximizeEvent prototype creation failed")); + if (! obj ) + return false; + + obj = FindDialogEvent::JSInit(cx, global, Event::GetClassPrototype()); + wxASSERT_MSG(obj != NULL, wxT("wxFindDialogEvent prototype creation failed")); + if (! obj ) + return false; + + obj = ScrollEvent::JSInit(cx, global, CommandEvent::GetClassPrototype()); + wxASSERT_MSG(obj != NULL, wxT("wxScrollEvent prototype creation failed")); + if (! obj ) + return false; + + obj = ScrollWinEvent::JSInit(cx, global, Event::GetClassPrototype()); + wxASSERT_MSG(obj != NULL, wxT("wxScrollWinEvent prototype creation failed")); + if (! obj ) + return false; + + obj = SysColourChangedEvent::JSInit(cx, global, Event::GetClassPrototype()); + wxASSERT_MSG(obj != NULL, wxT("wxSysColourChangedEvent prototype creation failed")); + if (! obj ) + return false; + + obj = HelpEvent::JSInit(cx, global, CommandEvent::GetClassPrototype()); + wxASSERT_MSG(obj != NULL, wxT("wxHelpEvent prototype creation failed")); + if (! obj ) + return false; + + obj = NotifyEvent::JSInit(cx, global, CommandEvent::GetClassPrototype()); + wxASSERT_MSG(obj != NULL, wxT("wxNotifyEvent prototype creation failed")); + if (! obj ) + return false; + + obj = ListEvent::JSInit(cx, global, NotifyEvent::GetClassPrototype()); + wxASSERT_MSG(obj != NULL, wxT("wxListEvent prototype creation failed")); + if (! obj ) + return false; + + obj = TreeEvent::JSInit(cx, global, NotifyEvent::GetClassPrototype()); + wxASSERT_MSG(obj != NULL, wxT("wxTreeEvent prototype creation failed")); + if (! obj ) + return false; + + obj = HtmlLinkEvent::JSInit(cx, global, CommandEvent::GetClassPrototype()); + wxASSERT_MSG(obj != NULL, wxT("wxHtmlLinkEvent prototype creation failed")); + if (! obj ) + return false; + + obj = SplitterEvent::JSInit(cx, global, NotifyEvent::GetClassPrototype()); + wxASSERT_MSG(obj != NULL, wxT("wxSplitterEvent prototype creation failed")); + if (! obj ) + return false; + + return true; +} Property changes on: ps/trunk/source/tools/atlas/wxJS/gui/event/jsevent.cpp ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/gui/event/focus.cpp =================================================================== --- ps/trunk/source/tools/atlas/wxJS/gui/event/focus.cpp (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/gui/event/focus.cpp (revision 5154) @@ -0,0 +1,48 @@ +#include "precompiled.h" + +/* + * wxJavaScript - focus.cpp + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: focus.cpp 598 2007-03-07 20:13:28Z fbraem $ + */ +// jsevent.cpp +#ifndef WX_PRECOMP + #include +#endif + +#include "../../common/main.h" +#include "jsevent.h" +#include "event.h" + +using namespace wxjs; +using namespace wxjs::gui; + +/*** + * event/focus + * gui + * + * A focus event is sent when a window's focus changes. + * See @wxWindow#onSetFocus and @wxWindow#onKillFocus. + * + */ +WXJS_INIT_CLASS(FocusEvent, "wxFocusEvent", 0) + Property changes on: ps/trunk/source/tools/atlas/wxJS/gui/event/focus.cpp ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/gui/event/htmllink.h =================================================================== --- ps/trunk/source/tools/atlas/wxJS/gui/event/htmllink.h (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/gui/event/htmllink.h (revision 5154) @@ -0,0 +1,56 @@ +/* + * wxJavaScript - htmllink.h + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: htmllink.h 598 2007-03-07 20:13:28Z fbraem $ + */ +#ifndef _wxjs_htmllink_h +#define _wxjs_htmllink_h + +#include +#include + +namespace wxjs +{ + namespace gui + { + typedef JSEvent PrivHtmlLinkEvent; + class HtmlLinkEvent : public ApiWrapper + { + public: + static bool GetProperty(PrivHtmlLinkEvent *p, JSContext *cx, JSObject *obj, int id, jsval *vp); + + virtual ~HtmlLinkEvent() + { + } + + enum + { + P_HREF + , P_TARGET + }; + + WXJS_DECLARE_PROPERTY_MAP() + }; + }; // namespace gui +}; // namespace wxjs + +#endif //_wxjs_htmllink_h Property changes on: ps/trunk/source/tools/atlas/wxJS/gui/event/htmllink.h ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/gui/event/listevt.cpp =================================================================== --- ps/trunk/source/tools/atlas/wxJS/gui/event/listevt.cpp (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/gui/event/listevt.cpp (revision 5154) @@ -0,0 +1,157 @@ +#include "precompiled.h" + +/* + * wxJavaScript - listevt.cpp + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: listevt.cpp 598 2007-03-07 20:13:28Z fbraem $ + */ +// listevt.cpp + +#ifndef WX_PRECOMP + #include +#endif + +#include + +#include "../../common/main.h" + +#include "../misc/point.h" + +#include "../control/listitem.h" + +#include "jsevent.h" +#include "listevt.h" + +using namespace wxjs; +using namespace wxjs::gui; + +/*** + * event/listevt + * gui + * + * This object is passed to a function that is set to a @wxListCtrl event property. + * + */ +WXJS_INIT_CLASS(ListEvent, "wxListEvent", 0) + +/*** + * + * + * The first item which the list control advises us to cache. + * + * + * The lasst item which the list control advises us to cache. + * + * + * The column index. For the column dragging events, it is the column to the left of + * the divider being dragged, for the column click events it may be -1 if the user + * clicked in the list control header outside any column. + * + * + * The associated data of the item. + * + * + * The image index of the item. + * + * + * The item index. + * + * + * The item. + * + * + * Keycode when the event is a keypress event. + * See @wxKeyCode + * + * + * The label. + * + * + * The mask. + * + * + * The position of the mouse pointer when the event is a drag event. + * + * + * The text. + * + * + */ +WXJS_BEGIN_PROPERTY_MAP(ListEvent) + WXJS_READONLY_PROPERTY(P_CODE, "keyCode") + WXJS_READONLY_PROPERTY(P_INDEX, "index") + WXJS_READONLY_PROPERTY(P_COLUMN, "column") + WXJS_READONLY_PROPERTY(P_POINT, "point") + WXJS_READONLY_PROPERTY(P_LABEL, "label") + WXJS_READONLY_PROPERTY(P_TEXT, "text") + WXJS_READONLY_PROPERTY(P_IMAGE, "image") + WXJS_READONLY_PROPERTY(P_DATA, "data") + WXJS_READONLY_PROPERTY(P_MASK, "mask") + WXJS_READONLY_PROPERTY(P_ITEM, "item") + WXJS_READONLY_PROPERTY(P_CACHE_FROM, "cacheFrom") + WXJS_READONLY_PROPERTY(P_CACHE_TO, "cacheTo") +WXJS_END_PROPERTY_MAP() + +bool ListEvent::GetProperty(PrivListEvent *p, JSContext *cx, JSObject *obj, int id, jsval *vp) +{ + wxListEvent *event = p->GetEvent(); + switch (id) + { + case P_CODE: + *vp = ToJS(cx, event->GetKeyCode()); + break; + case P_INDEX: + *vp = ToJS(cx, event->GetIndex()); + break; + case P_COLUMN: + *vp = ToJS(cx, event->GetColumn()); + break; + case P_POINT: + *vp = Point::CreateObject(cx, new wxPoint(event->GetPoint())); + break; + case P_LABEL: + *vp = ToJS(cx, event->GetLabel()); + break; + case P_TEXT: + *vp = ToJS(cx, event->GetText()); + break; + case P_IMAGE: + *vp = ToJS(cx, event->GetImage()); + break; + case P_DATA: + *vp = ToJS(cx, event->GetData()); + break; + case P_MASK: + *vp = ToJS(cx, event->GetMask()); + break; + case P_ITEM: + *vp = ListItem::CreateObject(cx, new wxListItem(event->GetItem())); + break; + case P_CACHE_FROM: + *vp = ToJS(cx, event->GetCacheFrom()); + break; + case P_CACHE_TO: + *vp = ToJS(cx, event->GetCacheTo()); + break; + } + return true; +} Property changes on: ps/trunk/source/tools/atlas/wxJS/gui/event/listevt.cpp ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/gui/event/activate.cpp =================================================================== --- ps/trunk/source/tools/atlas/wxJS/gui/event/activate.cpp (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/gui/event/activate.cpp (revision 5154) @@ -0,0 +1,65 @@ +#include "precompiled.h" + +/* + * wxJavaScript - activate.cpp + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: activate.cpp 598 2007-03-07 20:13:28Z fbraem $ + */ +// activate.cpp + +#ifndef WX_PRECOMP + #include +#endif + +#include "../../common/main.h" +#include "jsevent.h" +#include "activate.h" +using namespace wxjs; +using namespace wxjs::gui; + +/*** + * event/activate + * gui + * + * This object is passed to a function that handles an activate event. + * Handle this event by setting the @wxWindow#onActivate property on a @wxWindow object. + * + */ +WXJS_INIT_CLASS(ActivateEvent, "wxActivateEvent", 0) + +/*** + * + * + * Returns true when the control is active, false when it's not. + * + * + */ +WXJS_BEGIN_PROPERTY_MAP(ActivateEvent) + WXJS_READONLY_PROPERTY(P_ACTIVE, "active") +WXJS_END_PROPERTY_MAP() + +bool ActivateEvent::GetProperty(PrivActivateEvent *p, JSContext *cx, JSObject *obj, int id, jsval *vp) +{ + if ( id == P_ACTIVE ) + *vp = ToJS(cx, p->GetEvent()->GetActive()); + return true; +} Property changes on: ps/trunk/source/tools/atlas/wxJS/gui/event/activate.cpp ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/gui/event/iconize.h =================================================================== --- ps/trunk/source/tools/atlas/wxJS/gui/event/iconize.h (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/gui/event/iconize.h (revision 5154) @@ -0,0 +1,62 @@ +/* + * wxJavaScript - iconize.h + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: iconize.h 598 2007-03-07 20:13:28Z fbraem $ + */ +#ifndef _WXJSIconizeEvent_H +#define _WXJSIconizeEvent_H + +///////////////////////////////////////////////////////////////////////////// +// Name: iconize.h +// Purpose: IconizeEvent ports wxIconizeEvent to JavaScript. +// Author: Franky Braem +// Modified by: +// Created: 11.08.2002 +// Copyright: (c) 2001-2002 Franky Braem +// Licence: LGPL +///////////////////////////////////////////////////////////////////////////// + +namespace wxjs +{ + namespace gui + { + typedef JSEvent PrivIconizeEvent; + class IconizeEvent : public ApiWrapper + { + public: + static bool GetProperty(PrivIconizeEvent *p, JSContext *cx, JSObject *obj, int id, jsval *vp); + + virtual ~IconizeEvent() + { + } + + enum + { + P_ICONIZED + }; + + WXJS_DECLARE_PROPERTY_MAP() + }; + }; // namespace gui +}; // namespace wxjs + +#endif //_WXJSIconizeEvent_H Property changes on: ps/trunk/source/tools/atlas/wxJS/gui/event/iconize.h ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/gui/event/syscol.cpp =================================================================== --- ps/trunk/source/tools/atlas/wxJS/gui/event/syscol.cpp (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/gui/event/syscol.cpp (revision 5154) @@ -0,0 +1,48 @@ +#include "precompiled.h" + +/* + * wxJavaScript - syscol.cpp + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: syscol.cpp 598 2007-03-07 20:13:28Z fbraem $ + */ +// jsevent.cpp +#ifndef WX_PRECOMP + #include +#endif + +#include "../../common/main.h" + +#include "jsevent.h" +#include "event.h" + +using namespace wxjs; +using namespace wxjs::gui; + +/*** + * event/syscol + * gui + * + * An event being sent when a system colour is changed. + * See @wxPanel. + * + */ +WXJS_INIT_CLASS(SysColourChangedEvent, "wxSysColourChangedEvent", 0) Property changes on: ps/trunk/source/tools/atlas/wxJS/gui/event/syscol.cpp ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/gui/event/command.h =================================================================== --- ps/trunk/source/tools/atlas/wxJS/gui/event/command.h (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/gui/event/command.h (revision 5154) @@ -0,0 +1,63 @@ +/* + * wxJavaScript - command.h + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: command.h 598 2007-03-07 20:13:28Z fbraem $ + */ +#ifndef _WXJSCommandEvent_H +#define _WXJSCommandEvent_H + +///////////////////////////////////////////////////////////////////////////// +// Name: command.h +// Purpose: CommandEvent ports wxCommandEvent to JavaScript +// Author: Franky Braem +// Modified by: +// Created: 01.02.2002 +// Copyright: (c) 2001-2002 Franky Braem +// Licence: LGPL +///////////////////////////////////////////////////////////////////////////// +namespace wxjs +{ + namespace gui + { + typedef JSEvent PrivCommandEvent; + class CommandEvent : public ApiWrapper + { + public: + static bool GetProperty(PrivCommandEvent *p, JSContext *cx, JSObject *obj, int id, jsval *vp); + + virtual ~CommandEvent() + { + } + + enum + { + P_CHECKED + , P_SELECTION + , P_STRING + }; + + WXJS_DECLARE_PROPERTY_MAP() + }; + }; // namespace gui +}; // namespace wxjs + +#endif //_WXJSCommandEvent_H Property changes on: ps/trunk/source/tools/atlas/wxJS/gui/event/command.h ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/gui/event/maximize.cpp =================================================================== --- ps/trunk/source/tools/atlas/wxJS/gui/event/maximize.cpp (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/gui/event/maximize.cpp (revision 5154) @@ -0,0 +1,48 @@ +#include "precompiled.h" + +/* + * wxJavaScript - maximize.cpp + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: maximize.cpp 598 2007-03-07 20:13:28Z fbraem $ + */ +// jsevent.cpp +#ifndef WX_PRECOMP + #include +#endif + +#include "../../common/main.h" + +#include "jsevent.h" +#include "event.h" + +using namespace wxjs; +using namespace wxjs::gui; + +/*** + * event/maximize + * gui + * + * An event being sent when the frame is maximized (minimized) or restored. + * See @wxFrame. + * + */ +WXJS_INIT_CLASS(MaximizeEvent, "wxMaximizeEvent", 0) Property changes on: ps/trunk/source/tools/atlas/wxJS/gui/event/maximize.cpp ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/gui/event/help.cpp =================================================================== --- ps/trunk/source/tools/atlas/wxJS/gui/event/help.cpp (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/gui/event/help.cpp (revision 5154) @@ -0,0 +1,101 @@ +#include "precompiled.h" + +/* + * wxJavaScript - help.cpp + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: help.cpp 598 2007-03-07 20:13:28Z fbraem $ + */ +// move.cpp + +#ifndef WX_PRECOMP + #include +#endif + +#include "../../common/main.h" + +#include "jsevent.h" +#include "help.h" + +#include "../misc/point.h" + +using namespace wxjs; +using namespace wxjs::gui; + +/*** + * event/help + * gui + * + * A help event is sent when the user has requested context-sensitive help. + * This can either be caused by the application requesting context-sensitive + * help mode via @wxContextHelp, or (on MS Windows) by the system generating + * a WM_HELP message when the user pressed F1 or clicked on the query button in + * a dialog caption. + *

+ * A help event is sent to the window that the user clicked on, and is propagated up + * the window hierarchy until the event is processed or there are no more event handlers. + * The application should use @wxEvent#id to check the identity of the clicked-on window, + * and then either show some suitable help or set @wxEvent#skip to true if the identifier is + * unrecognised. Setting @wxEvent#skip to true is important because it allows wxWindows to + * generate further events for ancestors of the clicked-on window. Otherwise it would be + * impossible to show help for container windows, since processing would stop after the + * first window found. + *

+ * See @wxWindow#onHelp, @wxContextHelp and @wxContextHelpButton + *
+ */ +WXJS_INIT_CLASS(HelpEvent, "wxHelpEvent", 0) + +/*** + * + * + * Get/Set the left-click position of the mouse in screen-coordinates. + * This helps the application to position the help appropriately. + * + * + */ +WXJS_BEGIN_PROPERTY_MAP(HelpEvent) + WXJS_PROPERTY(P_POSITION, "position") +WXJS_END_PROPERTY_MAP() + +bool HelpEvent::GetProperty(PrivHelpEvent *p, JSContext *cx, JSObject *obj, int id, jsval *vp) +{ + wxHelpEvent *event = p->GetEvent(); + + if ( id == P_POSITION ) + { + *vp = Point::CreateObject(cx, new wxPoint(event->GetPosition())); + } + return true; +} + +bool HelpEvent::SetProperty(PrivHelpEvent *p, JSContext *cx, JSObject *obj, int id, jsval *vp) +{ + wxHelpEvent *event = p->GetEvent(); + + if ( id == P_POSITION ) + { + wxPoint *pt = Point::GetPrivate(cx, *vp); + if ( pt != NULL ) + event->SetPosition(*pt); + } + return true; +} Property changes on: ps/trunk/source/tools/atlas/wxJS/gui/event/help.cpp ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/gui/event/sizeevt.h =================================================================== --- ps/trunk/source/tools/atlas/wxJS/gui/event/sizeevt.h (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/gui/event/sizeevt.h (revision 5154) @@ -0,0 +1,62 @@ +/* + * wxJavaScript - sizeevt.h + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: sizeevt.h 598 2007-03-07 20:13:28Z fbraem $ + */ +#ifndef _WXJSSizeEvent_H +#define _WXJSSizeEvent_H + +///////////////////////////////////////////////////////////////////////////// +// Name: move.h +// Purpose: SizeEvent ports wxSizeEvent to JavaScript. +// Author: Franky Braem +// Modified by: +// Created: 14.01.2003 +// Copyright: (c) 2001-2002 Franky Braem +// Licence: LGPL +///////////////////////////////////////////////////////////////////////////// + +namespace wxjs +{ + namespace gui + { + typedef JSEvent PrivSizeEvent; + class SizeEvent : public ApiWrapper + { + public: + virtual ~SizeEvent() + { + } + + static bool GetProperty(PrivSizeEvent *p, JSContext *cx, JSObject *obj, int id, jsval *vp); + + enum + { + P_SIZE + }; + + WXJS_DECLARE_PROPERTY_MAP() + }; + }; // namespace gui +}; // namespace wxjs + +#endif //_WXJSSizeEvent_H Property changes on: ps/trunk/source/tools/atlas/wxJS/gui/event/sizeevt.h ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/gui/event/cal.h =================================================================== --- ps/trunk/source/tools/atlas/wxJS/gui/event/cal.h (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/gui/event/cal.h (revision 5154) @@ -0,0 +1,64 @@ +/* + * wxJavaScript - cal.h + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: cal.h 598 2007-03-07 20:13:28Z fbraem $ + */ +#ifndef _WXJSCalendarEvent_H +#define _WXJSCalendarEvent_H + +///////////////////////////////////////////////////////////////////////////// +// Name: cal.h +// Purpose: Ports wxCalendarEvent to JavaScript +// Author: Franky Braem +// Modified by: +// Created: 23.07.02 +// Copyright: (c) 2001-2002 Franky Braem +// Licence: LGPL +///////////////////////////////////////////////////////////////////////////// + +#include +namespace wxjs +{ + namespace gui + { + typedef JSEvent PrivCalendarEvent; + + class CalendarEvent : public ApiWrapper + { + public: + static bool GetProperty(PrivCalendarEvent *p, JSContext *cx, JSObject *obj, int id, jsval *vp); + + virtual ~CalendarEvent() + { + } + + enum + { + P_DATE + , P_WEEKDAY + }; + + WXJS_DECLARE_PROPERTY_MAP() + }; + }; // namespace gui +}; // namespace wxjs +#endif //_WXJSCalendarEvent_H Property changes on: ps/trunk/source/tools/atlas/wxJS/gui/event/cal.h ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/gui/event/scrollwin.cpp =================================================================== --- ps/trunk/source/tools/atlas/wxJS/gui/event/scrollwin.cpp (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/gui/event/scrollwin.cpp (revision 5154) @@ -0,0 +1,83 @@ +#include "precompiled.h" + +/* + * wxJavaScript - scrollwin.cpp + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: scrollwin.cpp 598 2007-03-07 20:13:28Z fbraem $ + */ +/** + * @if JS + * @page wxScrollWinEvent wxScrollWinEvent + * @since version 0.4 + * @endif + */ + +#ifndef WX_PRECOMP + #include +#endif + +#include "../../common/main.h" + +#include "jsevent.h" +#include "scrollwin.h" + +using namespace wxjs; +using namespace wxjs::gui; + +/*** + * event/scrollwin + * gui + * + * A scroll event holds information about events sent from scrolling windows. + * + */ +WXJS_INIT_CLASS(ScrollWinEvent, "wxScrollWinEvent", 0) + +/*** + * + * + * Returns wxDirection.HORIZONTAL or wxDirection.VERTICAL + * + * + * Returns the position of the ScrollWinbar + * + * + */ +WXJS_BEGIN_PROPERTY_MAP(ScrollWinEvent) + WXJS_READONLY_PROPERTY(P_ORIENTATION, "orientation") + WXJS_READONLY_PROPERTY(P_POSITION, "position") +WXJS_END_PROPERTY_MAP() + +bool ScrollWinEvent::GetProperty(PrivScrollWinEvent *p, JSContext *cx, JSObject *obj, int id, jsval *vp) +{ + wxScrollWinEvent *event = p->GetEvent(); + switch(id) + { + case P_ORIENTATION: + *vp = ToJS(cx, event->GetOrientation()); + break; + case P_POSITION: + *vp = ToJS(cx, event->GetPosition()); + break; + } + return true; +} Property changes on: ps/trunk/source/tools/atlas/wxJS/gui/event/scrollwin.cpp ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/gui/event/jsevent.h =================================================================== --- ps/trunk/source/tools/atlas/wxJS/gui/event/jsevent.h (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/gui/event/jsevent.h (revision 5154) @@ -0,0 +1,122 @@ +/* + * wxJavaScript - jsevent.h + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: jsevent.h 702 2007-05-10 22:01:44Z fbraem $ + */ + +#ifndef wxJS_Event_H +#define wxJS_Event_H + +#include "../misc/app.h" +#include "../../common/jsutil.h" + +namespace wxjs +{ + namespace gui + { + template + class JSEvent + { + public: + JSEvent(E &event) : m_event(event), m_inScoop(true), m_clonedEvent(NULL) + { + } + + virtual ~JSEvent() + { + delete m_clonedEvent; + } + + E* GetEvent() + { + if ( InScoop() ) + return &m_event; + else + return m_clonedEvent; + } + + inline bool InScoop() const + { + return m_inScoop; + } + + E &m_event; + bool m_inScoop; + E *m_clonedEvent; + + inline void SetScoop(bool scoop) + { + m_inScoop = scoop; + if ( ! scoop ) + m_clonedEvent = (E *) m_event.Clone(); + } + + template + static void Fire(E &event, const wxString &property) + { + wxEvtHandler *evtHandler = dynamic_cast(event.GetEventObject()); + JavaScriptClientData *obj = dynamic_cast(evtHandler->GetClientObject()); + + JSContext *cx = obj->GetContext(); + wxASSERT_MSG(cx != NULL, wxT("No application context")); + jsval fval; + if ( GetFunctionProperty(cx, obj->GetObject(), property.ToAscii(), &fval) == JS_TRUE ) + { + jsval rval; + + JSEvent *jsEvent = new JSEvent(event); + + jsval argv[] = { T::CreateObject(cx, jsEvent) }; + + JSBool result = JS_CallFunctionValue(cx, obj->GetObject(), fval, 1, argv, &rval); + jsEvent->SetScoop(false); + + if ( result == JS_FALSE ) + { + if ( JS_IsExceptionPending(cx) ) + { + JS_ReportPendingException(cx); + } + } + } + } + }; + + // Define the simple event classes: classes without properties and methods. + // Remove the wx from the wxClass when using this macro + #define WXJS_DECLARE_SIMPLE_EVENT(name, wxClass) \ + typedef JSEvent Priv##wxClass; \ + class name : public ApiWrapper > \ + { \ + }; + + WXJS_DECLARE_SIMPLE_EVENT(FocusEvent, FocusEvent) + WXJS_DECLARE_SIMPLE_EVENT(SysColourChangedEvent, SysColourChangedEvent) + WXJS_DECLARE_SIMPLE_EVENT(MaximizeEvent, MaximizeEvent) + WXJS_DECLARE_SIMPLE_EVENT(InitDialogEvent, InitDialogEvent) + + // Initialize the event prototypes + bool InitEventClasses(JSContext *cx, JSObject *global); + }; // namespace gui +}; // namespace wxjs + +#endif // wxJS_Event_H Property changes on: ps/trunk/source/tools/atlas/wxJS/gui/event/jsevent.h ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/gui/event/iconize.cpp =================================================================== --- ps/trunk/source/tools/atlas/wxJS/gui/event/iconize.cpp (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/gui/event/iconize.cpp (revision 5154) @@ -0,0 +1,69 @@ +#include "precompiled.h" + +/* + * wxJavaScript - iconize.cpp + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: iconize.cpp 598 2007-03-07 20:13:28Z fbraem $ + */ +// iconize.cpp + +#ifndef WX_PRECOMP + #include +#endif + +#include "../../common/main.h" + +#include "jsevent.h" +#include "iconize.h" + +using namespace wxjs; +using namespace wxjs::gui; + +/*** + * event/iconize + * gui + * + * An event being sent when the frame is iconized (minimized) or restored. + * Currently only Windows and GTK generate such events. + * See @wxFrame. + * + */ +WXJS_INIT_CLASS(IconizeEvent, "wxIconizeEvent", 0) + +/*** + * + * + * Returns true when the frame is iconized, false when it's not. + * + * + */ +WXJS_BEGIN_PROPERTY_MAP(IconizeEvent) + WXJS_READONLY_PROPERTY(P_ICONIZED, "iconized") +WXJS_END_PROPERTY_MAP() + +bool IconizeEvent::GetProperty(PrivIconizeEvent *p, JSContext *cx, JSObject *obj, int id, jsval *vp) +{ + wxIconizeEvent *event = p->GetEvent(); + if ( id == P_ICONIZED ) + *vp = ToJS(cx, event->Iconized()); + return true; +} Property changes on: ps/trunk/source/tools/atlas/wxJS/gui/event/iconize.cpp ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/gui/event/findr.h =================================================================== --- ps/trunk/source/tools/atlas/wxJS/gui/event/findr.h (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/gui/event/findr.h (revision 5154) @@ -0,0 +1,67 @@ +/* + * wxJavaScript - findr.h + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: findr.h 598 2007-03-07 20:13:28Z fbraem $ + */ +#ifndef _WXJSFindDialogEvent_H +#define _WXJSFindDialogEvent_H + +///////////////////////////////////////////////////////////////////////////// +// Name: findr.h +// Purpose: Ports wxFindDialogEvent to JavaScript +// Author: Franky Braem +// Modified by: +// Created: 06.08.2002 +// Copyright: (c) 2001-2002 Franky Braem +// Licence: LGPL +///////////////////////////////////////////////////////////////////////////// + +#include + +namespace wxjs +{ + namespace gui + { + typedef JSEvent PrivFindDialogEvent; + class FindDialogEvent : public ApiWrapper + { + public: + static bool GetProperty(PrivFindDialogEvent *p, JSContext *cx, JSObject *obj, int id, jsval *vp); + + virtual ~FindDialogEvent() + { + } + + enum + { + P_FLAGS + , P_FINDSTRING + , P_REPLACESTRING + , P_DIALOG + }; + + WXJS_DECLARE_PROPERTY_MAP() + }; + }; // namespace gui +}; // namespace wxjs + +#endif //_WXJSFindDialogEvent_H Property changes on: ps/trunk/source/tools/atlas/wxJS/gui/event/findr.h ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/gui/event/command.cpp =================================================================== --- ps/trunk/source/tools/atlas/wxJS/gui/event/command.cpp (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/gui/event/command.cpp (revision 5154) @@ -0,0 +1,86 @@ +#include "precompiled.h" + +/* + * wxJavaScript - command.cpp + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: command.cpp 598 2007-03-07 20:13:28Z fbraem $ + */ +// command.cpp + +#ifndef WX_PRECOMP + #include +#endif + +#include "../../common/main.h" +#include "jsevent.h" +#include "command.h" + +using namespace wxjs; +using namespace wxjs::gui; + +/*** + * event/command + * gui + * + * This event class contains information about command events, + * which originate from a variety of simple controls. + * + */ +WXJS_INIT_CLASS(CommandEvent, "wxCommandEvent", 0) + +/*** + * + * + * This can be used for menus or checkboxes to check if they are checked or not + * + * + * This can be used to know which item is selected in a @wxListBox or @wxChoice control + * + * + * This can be used to know the string of the item selected in a + * @wxListBox or @wxChoice control. + * + * + */ +WXJS_BEGIN_PROPERTY_MAP(CommandEvent) + WXJS_READONLY_PROPERTY(P_CHECKED, "checked") + WXJS_READONLY_PROPERTY(P_SELECTION, "selection") + WXJS_READONLY_PROPERTY(P_STRING, "string") +WXJS_END_PROPERTY_MAP() + +bool CommandEvent::GetProperty(PrivCommandEvent *p, JSContext *cx, JSObject *obj, int id, jsval *vp) +{ + wxCommandEvent *event = p->GetEvent(); + switch(id) + { + case P_CHECKED: + *vp = ToJS(cx, event->IsChecked()); + break; + case P_SELECTION: + *vp = ToJS(cx, event->GetSelection()); + break; + case P_STRING: + *vp = ToJS(cx, event->GetString()); + break; + } + return true; +} Property changes on: ps/trunk/source/tools/atlas/wxJS/gui/event/command.cpp ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/gui/event/scrollwin.h =================================================================== --- ps/trunk/source/tools/atlas/wxJS/gui/event/scrollwin.h (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/gui/event/scrollwin.h (revision 5154) @@ -0,0 +1,64 @@ +/* + * wxJavaScript - scrollwin.h + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: scrollwin.h 598 2007-03-07 20:13:28Z fbraem $ + */ +#ifndef _WXJSScrollWinEvent_H +#define _WXJSScrollWinEvent_H + +///////////////////////////////////////////////////////////////////////////// +// Name: ScrollWinEvent.h +// Purpose: ScrollWinEvent ports wxScrollWinEvent to JavaScript +// Author: Franky Braem +// Modified by: +// Created: 24.08.2002 +// Copyright: (c) 2001-2002 Franky Braem +// Licence: LGPL +///////////////////////////////////////////////////////////////////////////// + +namespace wxjs +{ + namespace gui + { + typedef JSEvent PrivScrollWinEvent; + + class ScrollWinEvent : public ApiWrapper + { + public: + virtual ~ScrollWinEvent() + { + } + + static bool GetProperty(PrivScrollWinEvent *p, JSContext *cx, JSObject *obj, int id, jsval *vp); + + enum + { + P_ORIENTATION + , P_POSITION + }; + + WXJS_DECLARE_PROPERTY_MAP() + }; + }; // namespace gui +}; // namespace wxjs + +#endif //_WXJSScrollWinEvent_H Property changes on: ps/trunk/source/tools/atlas/wxJS/gui/event/scrollwin.h ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/gui/event/key.cpp =================================================================== --- ps/trunk/source/tools/atlas/wxJS/gui/event/key.cpp (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/gui/event/key.cpp (revision 5154) @@ -0,0 +1,123 @@ +#include "precompiled.h" + +/* + * wxJavaScript - key.cpp + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: key.cpp 598 2007-03-07 20:13:28Z fbraem $ + */ +// key.cpp + +#ifndef WX_PRECOMP + #include +#endif + +#include "../../common/main.h" + +#include "jsevent.h" +#include "key.h" + +using namespace wxjs; +using namespace wxjs::gui; + +/*** + * event/key + * gui + * + * This event class contains information about keypress (character) events. Look + * at @wxWindow#onChar for an example. See @wxWindow#onChar, + * @wxWindow#onCharHook, @wxWindow#onKeyDown, @wxWindow#onKeyUp + * + */ +WXJS_INIT_CLASS(KeyEvent, "wxKeyEvent", 0) + +/*** + * + * + * True when the ALT key was pressed at the time of the event. + * + * + * True when the CTRL key was pressed at the time of the event. + * + * + * True when META, CTRL or ALT key was down at the time of the event. + * + * + * The code of the key. See @wxKeyCode + * + * + * True when the META key was down at the time of the event. + * + * + * True when the SHIFT key was down at the time of the event. + * + * + * The x position of the event + * + * + * The y position of the event + * + * + */ + + WXJS_BEGIN_PROPERTY_MAP(KeyEvent) + WXJS_READONLY_PROPERTY(P_ALT_DOWN, "altDown") + WXJS_READONLY_PROPERTY(P_CONTROL_DOWN, "controlDown") + WXJS_READONLY_PROPERTY(P_KEY_CODE, "keyCode") + WXJS_READONLY_PROPERTY(P_META_DOWN, "metaDown") + WXJS_READONLY_PROPERTY(P_SHIFT_DOWN, "shiftDown") + WXJS_READONLY_PROPERTY(P_HAS_MODIFIERS, "hasModifiers") + WXJS_READONLY_PROPERTY(P_X, "x") + WXJS_READONLY_PROPERTY(P_Y, "y") +WXJS_END_PROPERTY_MAP() + +bool KeyEvent::GetProperty(PrivKeyEvent *p, JSContext *cx, JSObject *obj, int id, jsval *vp) +{ + wxKeyEvent *event = ((wxKeyEvent*) p->GetEvent()); + switch (id) + { + case P_ALT_DOWN: + *vp = ToJS(cx, event->AltDown()); + break; + case P_CONTROL_DOWN: + *vp = ToJS(cx, event->ControlDown()); + break; + case P_KEY_CODE: + *vp = ToJS(cx, event->GetKeyCode()); + break; + case P_META_DOWN: + *vp = ToJS(cx, event->MetaDown()); + break; + case P_SHIFT_DOWN: + *vp = ToJS(cx, event->ShiftDown()); + break; + case P_X: + *vp = ToJS(cx, event->GetX()); + break; + case P_Y: + *vp = ToJS(cx, event->GetY()); + break; + case P_HAS_MODIFIERS: + *vp = ToJS(cx, event->HasModifiers()); + break; + } + return true; +} Property changes on: ps/trunk/source/tools/atlas/wxJS/gui/event/key.cpp ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/gui/event/scroll.cpp =================================================================== --- ps/trunk/source/tools/atlas/wxJS/gui/event/scroll.cpp (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/gui/event/scroll.cpp (revision 5154) @@ -0,0 +1,81 @@ +#include "precompiled.h" + +/* + * wxJavaScript - scroll.cpp + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: scroll.cpp 598 2007-03-07 20:13:28Z fbraem $ + */ +// scroll.cpp + +#ifndef WX_PRECOMP + #include +#endif + +#include "../../common/main.h" +#include "../../common/type.h" + +#include "jsevent.h" +#include "scroll.h" + +using namespace wxjs; +using namespace wxjs::gui; + +/*** + * event/scroll + * gui + * + * A scroll event holds information about events sent from stand-alone scrollbars, + * spin-buttons and sliders. Note that scrolled windows send the @wxScrollWinEvent + * don't confuse these two kinds of events, and use this event only for the scrollbar-like controls. + * + */ +WXJS_INIT_CLASS(ScrollEvent, "wxScrollEvent", 0) + +/*** + * + * + * Returns wxDirection.HORIZONTAL or wxDirection.VERTICAL + * + * + * Returns the position of the scrollbar + * + * + */ +WXJS_BEGIN_PROPERTY_MAP(ScrollEvent) + WXJS_READONLY_PROPERTY(P_ORIENTATION, "orientation") + WXJS_READONLY_PROPERTY(P_POSITION, "position") +WXJS_END_PROPERTY_MAP() + +bool ScrollEvent::GetProperty(PrivScrollEvent *p, JSContext *cx, JSObject *obj, int id, jsval *vp) +{ + wxScrollEvent *event = p->GetEvent(); + switch(id) + { + case P_ORIENTATION: + *vp = ToJS(cx, event->GetOrientation()); + break; + case P_POSITION: + *vp = ToJS(cx, event->GetPosition()); + break; + } + return true; +} Property changes on: ps/trunk/source/tools/atlas/wxJS/gui/event/scroll.cpp ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/gui/event/findr.cpp =================================================================== --- ps/trunk/source/tools/atlas/wxJS/gui/event/findr.cpp (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/gui/event/findr.cpp (revision 5154) @@ -0,0 +1,96 @@ +#include "precompiled.h" + +/* + * wxJavaScript - findr.cpp + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: findr.cpp 714 2007-05-16 20:24:49Z fbraem $ + */ +// findr.cpp + +#ifndef WX_PRECOMP + #include +#endif + +#include "../../common/main.h" +#include "../../common/type.h" + +#include "jsevent.h" +#include "findr.h" + +using namespace wxjs; +using namespace wxjs::gui; + +/*** + * event/findr + * gui + * + * This event class contains the information about + * all @wxFindReplaceDialog events: @wxFindReplaceDialog#onFind + * @wxFindReplaceDialog#onFindNext, @wxFindReplaceDialog#onFindReplace, + * @wxFindReplaceDialog#onFindReplaceAll, @wxFindReplaceDialog#onFindClose. + * + */ +WXJS_INIT_CLASS(FindDialogEvent, "wxFindDialogEvent", 0) + +/*** + * + * + * + * + * + */ +WXJS_BEGIN_PROPERTY_MAP(FindDialogEvent) + WXJS_READONLY_PROPERTY(P_FLAGS, "flags") + WXJS_READONLY_PROPERTY(P_FINDSTRING, "findString") + WXJS_READONLY_PROPERTY(P_REPLACESTRING, "replaceString") + WXJS_READONLY_PROPERTY(P_DIALOG, "dialog") +WXJS_END_PROPERTY_MAP() + +bool FindDialogEvent::GetProperty(PrivFindDialogEvent *p, JSContext *cx, JSObject *obj, int id, jsval *vp) +{ + wxFindDialogEvent *event = p->GetEvent(); + switch (id) + { + case P_FLAGS: + *vp = ToJS(cx, event->GetFlags()); + break; + case P_FINDSTRING: + *vp = ToJS(cx, event->GetFindString()); + break; + case P_REPLACESTRING: + *vp = ToJS(cx, event->GetReplaceString()); + break; + case P_DIALOG: + { + wxWindow *win = event->GetDialog(); + if ( win != NULL ) + { + JavaScriptClientData *data + = dynamic_cast(win->GetClientObject()); + if ( data != NULL ) + *vp = OBJECT_TO_JSVAL(data->GetObject()); + } + break; + } + } + return true; +} Property changes on: ps/trunk/source/tools/atlas/wxJS/gui/event/findr.cpp ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/gui/event/move.h =================================================================== --- ps/trunk/source/tools/atlas/wxJS/gui/event/move.h (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/gui/event/move.h (revision 5154) @@ -0,0 +1,62 @@ +/* + * wxJavaScript - move.h + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: move.h 598 2007-03-07 20:13:28Z fbraem $ + */ +#ifndef _WXJSMoveEvent_H +#define _WXJSMoveEvent_H + +///////////////////////////////////////////////////////////////////////////// +// Name: move.h +// Purpose: MoveEvent ports wxMoveEvent to JavaScript. +// Author: Franky Braem +// Modified by: +// Created: 02.07.2002 +// Copyright: (c) 2001-2002 Franky Braem +// Licence: LGPL +///////////////////////////////////////////////////////////////////////////// + +namespace wxjs +{ + namespace gui + { + typedef JSEvent PrivMoveEvent; + class MoveEvent : public ApiWrapper + { + public: + virtual ~MoveEvent() + { + } + + static bool GetProperty(PrivMoveEvent *p, JSContext *cx, JSObject *obj, int id, jsval *vp); + + enum + { + P_POSITION + }; + + WXJS_DECLARE_PROPERTY_MAP() + }; + }; // namespace gui +}; // namespace wxjs + +#endif //_WXJSMoveEvent_H Property changes on: ps/trunk/source/tools/atlas/wxJS/gui/event/move.h ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/gui/event/htmllink.cpp =================================================================== --- ps/trunk/source/tools/atlas/wxJS/gui/event/htmllink.cpp (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/gui/event/htmllink.cpp (revision 5154) @@ -0,0 +1,76 @@ +#include "precompiled.h" + +/* + * wxJavaScript - htmllink.cpp + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: htmllink.cpp 612 2007-03-12 22:08:35Z fbraem $ + */ +#ifndef WX_PRECOMP + #include +#endif + +#include "../../common/main.h" +#include "jsevent.h" +#include "htmllink.h" + +using namespace wxjs; +using namespace wxjs::gui; + +/*** + * event/htmllink + * gui + * + * This event class is used for the events generated by @wxHtmlWindow. + * + */ +WXJS_INIT_CLASS(HtmlLinkEvent, "wxHtmlLinkEvent", 0) + +/*** + * + * + * Return HREF value of the <a> tag. + * + * + * Return TARGET value of the <a> tag. + * + * + */ +WXJS_BEGIN_PROPERTY_MAP(HtmlLinkEvent) + WXJS_READONLY_PROPERTY(P_HREF, "href") + WXJS_READONLY_PROPERTY(P_TARGET, "target") +WXJS_END_PROPERTY_MAP() + +bool HtmlLinkEvent::GetProperty(PrivHtmlLinkEvent *p, JSContext *cx, JSObject* WXUNUSED(obj), int id, jsval *vp) +{ + wxHtmlLinkEvent *event = p->GetEvent(); + wxHtmlLinkInfo info = event->GetLinkInfo(); + switch(id) + { + case P_HREF: + *vp = ToJS(cx, info.GetHref()); + break; + case P_TARGET: + *vp = ToJS(cx, info.GetTarget()); + break; + } + return true; +} Property changes on: ps/trunk/source/tools/atlas/wxJS/gui/event/htmllink.cpp ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/gui/event/event.h =================================================================== --- ps/trunk/source/tools/atlas/wxJS/gui/event/event.h (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/gui/event/event.h (revision 5154) @@ -0,0 +1,51 @@ +/* + * wxJavaScript - event.h + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: event.h 653 2007-04-03 21:03:38Z fbraem $ + */ +#ifndef _WXJSEvent_H +#define _WXJSEvent_H + +namespace wxjs +{ + namespace gui + { + typedef JSEvent PrivEvent; + class Event : public ApiWrapper + { + public: + static bool GetProperty(PrivEvent *p, JSContext *cx, JSObject *obj, int id, jsval *vp); + static bool SetProperty(PrivEvent *p, JSContext *cx, JSObject *obj, int id, jsval *vp); + + WXJS_DECLARE_PROPERTY_MAP() + + enum + { + P_ID + , P_SKIP + , P_TIMESTAMP + }; + }; + }; // namespace gui +}; // namespace wxjs + +#endif //_WXJSEvent_H Property changes on: ps/trunk/source/tools/atlas/wxJS/gui/event/event.h ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/gui/event/split.cpp =================================================================== --- ps/trunk/source/tools/atlas/wxJS/gui/event/split.cpp (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/gui/event/split.cpp (revision 5154) @@ -0,0 +1,140 @@ +#include "precompiled.h" + +/* + * wxJavaScript - split.cpp + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id$ + */ + +#ifndef WX_PRECOMP + #include +#endif + +#include "../../common/main.h" +#include "../../common/apiwrap.h" + +#include "jsevent.h" +#include "../misc/point.h" +#include "split.h" + +using namespace wxjs; +using namespace wxjs::gui; + +/*** + * event/split + * gui + * + * This class represents the events generated by a @wxSplitterWindow. + * + */ +WXJS_INIT_CLASS(SplitterEvent, "wxSplitterEvent", 0) + +/*** + * + * + * Returns the new sash position. + * + * + * Returns the x coordinate of the double-click point. + * + * + * Returns the y coordinate of the double-click point. + * + * + * Returns the window being removed when a splitter window is unsplit. + * + * + */ +WXJS_BEGIN_PROPERTY_MAP(SplitterEvent) + WXJS_PROPERTY(P_SASH_POSITION, "sashPosition") + WXJS_READONLY_PROPERTY(P_X, "x") + WXJS_READONLY_PROPERTY(P_Y, "y") + WXJS_READONLY_PROPERTY(P_WINDOW_BEING_REMOVED, "windowBeingRemoved") +WXJS_END_PROPERTY_MAP() + +bool SplitterEvent::GetProperty(PrivSplitterEvent* p, + JSContext* cx, + JSObject* WXUNUSED(obj), + int id, + jsval* vp) +{ + wxSplitterEvent *event = p->GetEvent(); + + switch(id) + { + case P_SASH_POSITION: + { + *vp = event->GetSashPosition(); + break; + } + case P_X: + { + *vp = event->GetX(); + break; + } + case P_Y: + { + *vp = event->GetY(); + break; + } + case P_WINDOW_BEING_REMOVED: + { + wxWindow *win = event->GetWindowBeingRemoved(); + if ( win == NULL ) + { + *vp = JSVAL_VOID; + } + else + { + JavaScriptClientData *data + = dynamic_cast(win->GetClientObject()); + *vp = ( data == NULL ) ? JSVAL_VOID + : OBJECT_TO_JSVAL(data->GetObject()); + } + break; + } + } + return true; +} + +bool SplitterEvent::SetProperty(PrivSplitterEvent* p, + JSContext* cx, + JSObject* WXUNUSED(obj), + int id, + jsval* vp) +{ + wxSplitterEvent *event = p->GetEvent(); + + switch(id) + { + case P_SASH_POSITION: + { + int pos; + if ( FromJS(cx, *vp, pos) ) + { + event->SetSashPosition(pos); + } + break; + } + } + return true; +} Property changes on: ps/trunk/source/tools/atlas/wxJS/gui/event/split.cpp ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/gui/errors.h =================================================================== --- ps/trunk/source/tools/atlas/wxJS/gui/errors.h (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/gui/errors.h (revision 5154) @@ -0,0 +1,32 @@ +/* + * wxJavaScript - errors.h + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id$ + */ + +#ifndef _wxjs_gui_errors_h +#define _wxjs_gui_errors_h + +extern const char* WXJS_NO_PARENT_ERROR; +extern const char* WXJS_INVALID_ARG_TYPE; + +#endif // _wxjs_gui_errors_h \ No newline at end of file Property changes on: ps/trunk/source/tools/atlas/wxJS/gui/errors.h ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/gui/misc/acctable.cpp =================================================================== --- ps/trunk/source/tools/atlas/wxJS/gui/misc/acctable.cpp (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/gui/misc/acctable.cpp (revision 5154) @@ -0,0 +1,151 @@ +#include "precompiled.h" + +/* + * wxJavaScript - acctable.cpp + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: acctable.cpp 598 2007-03-07 20:13:28Z fbraem $ + */ +// acctable.cpp + +#ifndef WX_PRECOMP + #include +#endif + +#include "../../common/main.h" +#include "../../common/apiwrap.h" + +#include "acctable.h" +#include "accentry.h" + +using namespace wxjs; +using namespace wxjs::gui; + +/*** + * misc/acctable + * gui + * + * An accelerator table allows the application to specify a table + * of keyboard shortcuts for menus or other commands. On Windows, + * menu or button commands are supported; on GTK, + * only menu commands are supported. + * The following example adds an accelerator to a frame. When CTRL-F1 is pressed + * the menu action associated with id 1 is executed. + *

+ *    wxTheApp.onInit = init;
+ *    wxTheApp.mainLoop();
+ *
+ *    function init()
+ *    {
+ *      var frame = new wxFrame(null, -1, "Accelerator Test");
+ *      var menuBar = new wxMenuBar();
+ *      var menu = new wxMenu();
+ *      var idInfoAbout = 1;
+ *
+ *      menu = new wxMenu();
+ *      menu.append(idInfoAbout, "About", infoAboutMenu);
+ *      menuBar.append(menu, "Info");
+ *
+ *      frame.menuBar = menuBar;
+ *
+ *      var entries = new Array();
+ *      entries[0] = new wxAcceleratorEntry(wxAcceleratorEntry.CTRL,
+ *                                          wxKeyCode.F1,
+ *                                          idInfoAbout);
+ *      frame.acceleratorTable = new wxAcceleratorTable(entries);
+ *
+ *      menu.getItem(idInfoAbout).accel = entries[0];
+ *
+ *      topWindow = frame;
+ *      frame.visible = true;
+ *
+ *      return true;
+ *    }
+ *
+ *    function infoAboutMenu(event)
+ *    {
+ *      wxMessageBox("Accelerator Test Version 1.0");
+ *    }
+ *   
+ *
+ */ +WXJS_INIT_CLASS(AcceleratorTable, "wxAcceleratorTable", 1) + +/*** + * + * + * Returns true when the accelerator table is valid + * + * + */ +WXJS_BEGIN_PROPERTY_MAP(AcceleratorTable) + WXJS_READONLY_PROPERTY(P_OK, "ok") +WXJS_END_PROPERTY_MAP() + +bool AcceleratorTable::GetProperty(wxAcceleratorTable *p, JSContext *cx, JSObject *obj, int id, jsval *vp) +{ + if ( id == P_OK ) + { + *vp = ToJS(cx, p->Ok()); + } + return true; +} + +/*** + * + * + * + * An array of @wxAcceleratorEntry objects + * + * + * + * Constructs a new wxAcceleratorTable object. + * + * + */ +wxAcceleratorTable *AcceleratorTable::Construct(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, bool constructing) +{ + if ( JSVAL_IS_OBJECT(argv[0]) ) + { + JSObject *objEntries = JSVAL_TO_OBJECT(argv[0]); + if ( JS_IsArrayObject(cx, objEntries) ) + { + jsuint length = 0; + JS_GetArrayLength(cx, objEntries, &length); + int n = length; + wxAcceleratorEntry **items = new wxAcceleratorEntry*[n]; + for(jsint i =0; i < n; i++) + { + jsval element; + JS_GetElement(cx, objEntries, i, &element); + items[i] = AcceleratorEntry::GetPrivate(cx, element); + } + + wxAcceleratorTable *p = new wxAcceleratorTable(n, *items); + + delete[] items; + + return p; + } + } + + return NULL; +} Property changes on: ps/trunk/source/tools/atlas/wxJS/gui/misc/acctable.cpp ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/gui/event/sizeevt.cpp =================================================================== --- ps/trunk/source/tools/atlas/wxJS/gui/event/sizeevt.cpp (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/gui/event/sizeevt.cpp (revision 5154) @@ -0,0 +1,78 @@ +#include "precompiled.h" + +/* + * wxJavaScript - sizeevt.cpp + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: sizeevt.cpp 598 2007-03-07 20:13:28Z fbraem $ + */ +// sizeevt.cpp + +#ifndef WX_PRECOMP + #include +#endif + +#include "../../common/main.h" +#include "../../common/apiwrap.h" + +#include "jsevent.h" +#include "../misc/size.h" +#include "sizeevt.h" + +using namespace wxjs; +using namespace wxjs::gui; + +/*** + * event/sizeevt + * gui + * + * A size event holds information about size change events. + * Handle this event by setting a function to the @wxWindow#onSize + * property on a @wxWindow object. + *

+ * The size retrieved with size property is the size of the whole window. + * Use @wxWindow#clientSize for the area which may be used by the application. + *
+ */ +WXJS_INIT_CLASS(SizeEvent, "wxSizeEvent", 0) + +/*** + * + * + * Returns the size of the window generating this event. + * + * + */ +WXJS_BEGIN_PROPERTY_MAP(SizeEvent) + WXJS_READONLY_PROPERTY(P_SIZE, "size") +WXJS_END_PROPERTY_MAP() + +bool SizeEvent::GetProperty(PrivSizeEvent *p, JSContext *cx, JSObject *obj, int id, jsval *vp) +{ + wxSizeEvent *event = (wxSizeEvent*) p->GetEvent(); + + if ( id == P_SIZE ) + { + *vp = Size::CreateObject(cx, new wxSize(event->GetSize())); + } + return true; +} + Property changes on: ps/trunk/source/tools/atlas/wxJS/gui/event/sizeevt.cpp ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/gui/event/help.h =================================================================== --- ps/trunk/source/tools/atlas/wxJS/gui/event/help.h (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/gui/event/help.h (revision 5154) @@ -0,0 +1,64 @@ +/* + * wxJavaScript - help.h + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: help.h 598 2007-03-07 20:13:28Z fbraem $ + */ +#ifndef _WXJSHelpEvent_H +#define _WXJSHelpEvent_H + +///////////////////////////////////////////////////////////////////////////// +// Name: help.h +// Purpose: HelpEvent ports wxHelpEvent to JavaScript. +// Author: Franky Braem +// Modified by: +// Created: 28.09.2002 +// Copyright: (c) 2001-2002 Franky Braem +// Licence: LGPL +///////////////////////////////////////////////////////////////////////////// + +namespace wxjs +{ + namespace gui + { + typedef JSEvent PrivHelpEvent; + + class HelpEvent : public ApiWrapper + { + public: + virtual ~HelpEvent() + { + } + + static bool GetProperty(PrivHelpEvent *p, JSContext *cx, JSObject *obj, int id, jsval *vp); + static bool SetProperty(PrivHelpEvent *p, JSContext *cx, JSObject *obj, int id, jsval *vp); + + enum + { + P_POSITION + }; + + WXJS_DECLARE_PROPERTY_MAP() + }; + }; // namespace gui +}; // namespace wxjs + +#endif //_WXJSMoveEvent_H Property changes on: ps/trunk/source/tools/atlas/wxJS/gui/event/help.h ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/gui/init.h =================================================================== --- ps/trunk/source/tools/atlas/wxJS/gui/init.h (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/gui/init.h (revision 5154) @@ -0,0 +1,40 @@ +/* + * wxJavaScript - init.h + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id$ + */ +#ifndef _wxJS_GUI_init_h +#define _wxJS_GUI_init_h + +// Use this to initialize the IO module + +namespace wxjs +{ + namespace gui + { + bool InitClass(JSContext *cx, JSObject *global); + bool InitObject(JSContext *cx, JSObject *obj); + void Destroy(); + }; // namespace gui +}; // namespace wxjs + +#endif // _wxJS_GUI_init_h Property changes on: ps/trunk/source/tools/atlas/wxJS/gui/init.h ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/gui/misc/flexgrid.h =================================================================== --- ps/trunk/source/tools/atlas/wxJS/gui/misc/flexgrid.h (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/gui/misc/flexgrid.h (revision 5154) @@ -0,0 +1,45 @@ +/* + * wxJavaScript - flexgrid.h + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: flexgrid.h 715 2007-05-18 20:38:04Z fbraem $ + */ +#ifndef _WXJSFlexGridSizer_H +#define _WXJSFlexGridSizer_H + +namespace wxjs +{ + namespace gui + { + class FlexGridSizer : public ApiWrapper + { + public: + + static wxFlexGridSizer* Construct(JSContext *cx, + JSObject *obj, + uintN argc, + jsval *argv, + bool constructing); + }; + }; // namespace gui +}; // namespace wxjs + +#endif //_WXJSFlexGridSizer_H Property changes on: ps/trunk/source/tools/atlas/wxJS/gui/misc/flexgrid.h ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/gui/event/event.cpp =================================================================== --- ps/trunk/source/tools/atlas/wxJS/gui/event/event.cpp (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/gui/event/event.cpp (revision 5154) @@ -0,0 +1,92 @@ +#include "precompiled.h" + +/* + * wxJavaScript - event.cpp + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: event.cpp 598 2007-03-07 20:13:28Z fbraem $ + */ +// event.cpp +#ifndef WX_PRECOMP + #include +#endif + +#include "../../common/main.h" +#include "../../common/type.h" + +#include "jsevent.h" +#include "event.h" + +using namespace wxjs; +using namespace wxjs::gui; + +/*** + * event/event + * gui + * + * wxEvent is the prototype for the following event objects. + * + */ +WXJS_INIT_CLASS(Event, "wxEvent", 0) + +/*** + * + * + * The identifier of the associated window + * + * + * Set this to true when you want to tell the system to skip the current event handler + * and to use the next valid handler. + * + * + */ +WXJS_BEGIN_PROPERTY_MAP(Event) + WXJS_READONLY_PROPERTY(P_ID, "id") + WXJS_PROPERTY(P_SKIP, "skip") +WXJS_END_PROPERTY_MAP() + +bool Event::GetProperty(PrivEvent *p, JSContext *cx, JSObject *obj, int id, jsval *vp) +{ + wxEvent *event = p->GetEvent(); + + switch (id) + { + case P_ID: + *vp = ToJS(cx, event->GetId()); + break; + case P_SKIP: + *vp = ToJS(cx, event->GetSkipped()); + break; + } + return true; +} + +bool Event::SetProperty(PrivEvent *p, JSContext *cx, JSObject *obj, int id, jsval *vp) +{ + wxEvent *event = p->GetEvent(); + if ( id == P_SKIP ) + { + bool skip; + if ( FromJS(cx, *vp, skip) ) + event->Skip(skip); + } + return true; +} Property changes on: ps/trunk/source/tools/atlas/wxJS/gui/event/event.cpp ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/gui/event/mouse.cpp =================================================================== --- ps/trunk/source/tools/atlas/wxJS/gui/event/mouse.cpp (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/gui/event/mouse.cpp (revision 5154) @@ -0,0 +1,393 @@ +#include "precompiled.h" + +/* + * wxJavaScript - mouse.cpp + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: mouse.cpp 598 2007-03-07 20:13:28Z fbraem $ + */ +// mouse.cpp + +#ifndef WX_PRECOMP + #include +#endif + +#include "../../common/main.h" +#include "../../common/type.h" +#include "../../common/apiwrap.h" + +#include "jsevent.h" +#include "mouse.h" +#include "../misc/point.h" + +using namespace wxjs; +using namespace wxjs::gui; + +/*** + * event/mouse + * gui + * + * This event class contains information about mouse events. + *

+ * Note the difference between methods like @wxMouseEvent#leftDown + * and @wxMouseEvent#leftIsDown: the formet returns true when the event corresponds + * to the left mouse button click while the latter returns true if the left mouse button + * is currently being pressed. For example, when the user is dragging the mouse you can use + * @wxMouseEvent#leftIsDown to test whether the left mouse button is (still) depressed. + * Also, by convention, if @wxMouseEvent#leftDown returns true, @wxMouseEvent#leftIsDown + * will also return true in wxWindows whatever the underlying GUI + * behaviour is (which is platform-dependent). + * The same applies, of course, to other mouse buttons as well. + *

+ * See @wxWindow#onMouseEvents, @wxWindow#onEnterWindow, @wxWindow#onLeaveWindow, + * @wxWindow#onLeftUp, @wxWindow#onLeftDown, @wxWindow#onLeftDClick, + * @wxWindow#onMiddleUp, @wxWindow#onMiddleDown, @wxWindow#onMiddleDClick, + * @wxWindow#onRightUp, @wxWindow#onRightDown, @wxWindow#onRightDClick. + *
+ */ +WXJS_INIT_CLASS(MouseEvent, "wxMouseEvent", 0) + +/*** + * + * + * Returns true when the alt key is down at the time of the key event. + * + * + * Get the button which is changing state + * + * + * Returns true when the control key is down at the time of the event. + * + * + * Returns true when this is a dragging event. + * + * + * Returns true when the mouse was entering the window. + * See @wxMouseEvent#leaving + * + * + * Returns true when the mouse was leaving the window. + * See @wxMouseEvent#entering. + * + * + * Returns true when the event is a left double click event (wxEVT_LEFT_DCLICK). + * + * + * Returns true when the event is a left down event (wxEVT_LEFT_DOWN). + * + * + * Returns true if the left mouse button is currently down, independent of the current event type. + * Please notice that it is not the same as @wxMouseEvent#leftDown which returns true + * if the left mouse button was just pressed. Rather, it describes the state of the mouse button + * before the event happened. + * + * + * Returns the configured number of lines (or whatever) + * to be scrolled per wheel action. Defaults to 1. + * + * + * Returns true when the meta key was down at the time of the event. + * + * + * Returns true when the event is a middle double click event (wxEVT_MIDDLE_DCLICK). + * + * + * Returns true when the event is a middle down event (wxEVT_MIDDLE_DOWN). + * + * + * Returns true if the middle mouse button is currently down, independent of the current event type. + * + * + * Returns true when this was a moving event (wxEVT_MOTION) + * + * + * Returns the physical mouse position in pixels. + * + * + * Returns true when the event is a right double click event (wxEVT_RIGHT_DCLICK). + * + * + * Returns true when the event is a right down event (wxEVT_RIGHT_DOWN). + * + * + * Returns true if the right mouse button is currently down, independent of the current event type. + * + * + * Returns true when the shift key was down at the time of the event. + * + * + * Get wheel delta, normally 120. This is the threshold for action to be + * taken, and one such action (for example, scrolling one increment) + * should occur for each delta. + * + * + * Get wheel rotation, positive or negative indicates direction of + * rotation. Current devices all send an event when rotation is equal to + * +/-WheelDelta, but this allows for finer resolution devices to be + * created in the future. Because of this you shouldn't assume that one + * event is equal to 1 line or whatever, but you should be able to either + * do partial line scrolling or wait until +/-WheelDelta rotation values + * have been accumulated before scrolling. + * + * + * Returns the x-coordinate of the physical mouse position. + * See @wxMouseEvent#position and @wxMouseEvent#y + * + * + * Returns the y-coordinate of the physical mouse position. + * See @wxMouseEvent#position and @wxMouseEvent#x + * + * + */ + +WXJS_BEGIN_PROPERTY_MAP(MouseEvent) + WXJS_READONLY_PROPERTY(P_ALTDOWN, "altDown") + WXJS_READONLY_PROPERTY(P_CONTROLDOWN, "controlDown") + WXJS_READONLY_PROPERTY(P_DRAGGING, "dragging") + WXJS_READONLY_PROPERTY(P_ENTERING, "entering") + WXJS_READONLY_PROPERTY(P_POSITION, "position") + WXJS_READONLY_PROPERTY(P_LINES_PER_ACTION, "linesPerAction") + WXJS_READONLY_PROPERTY(P_BUTTON, "button") + WXJS_READONLY_PROPERTY(P_METADOWN, "metaDown") + WXJS_READONLY_PROPERTY(P_SHIFTDOWN, "shiftDown") + WXJS_READONLY_PROPERTY(P_LEFT_DOWN, "leftDown") + WXJS_READONLY_PROPERTY(P_MIDDLE_DOWN, "middleDown") + WXJS_READONLY_PROPERTY(P_RIGHT_DOWN, "rightDown") + WXJS_READONLY_PROPERTY(P_LEFT_UP, "leftUp") + WXJS_READONLY_PROPERTY(P_MIDDLE_UP, "middleUp") + WXJS_READONLY_PROPERTY(P_RIGHT_UP, "rightUp") + WXJS_READONLY_PROPERTY(P_LEFT_DCLICK, "leftDClick") + WXJS_READONLY_PROPERTY(P_MIDDLE_DCLICK, "middleDClick") + WXJS_READONLY_PROPERTY(P_RIGHT_DCLICK, "rightDClick") + WXJS_READONLY_PROPERTY(P_LEFT_IS_DOWN, "leftIsDown") + WXJS_READONLY_PROPERTY(P_MIDDLE_IS_DOWN, "middleIsDown") + WXJS_READONLY_PROPERTY(P_RIGHT_IS_DOWN, "rightIsDown") + WXJS_READONLY_PROPERTY(P_MOVING, "moving") + WXJS_READONLY_PROPERTY(P_LEAVING, "leaving") + WXJS_READONLY_PROPERTY(P_X, "x") + WXJS_READONLY_PROPERTY(P_Y, "y") + WXJS_READONLY_PROPERTY(P_WHEELROTATION, "wheelRotation") + WXJS_READONLY_PROPERTY(P_WHEELDELTA, "wheelDelta") +WXJS_END_PROPERTY_MAP() + +bool MouseEvent::GetProperty(PrivMouseEvent *p, JSContext *cx, JSObject *obj, int id, jsval *vp) +{ + wxMouseEvent *event = (wxMouseEvent*) p->GetEvent(); + switch (id) + { + case P_ALTDOWN: + *vp = ToJS(cx, event->AltDown()); + break; + case P_CONTROLDOWN: + *vp = ToJS(cx, event->ControlDown()); + break; + case P_DRAGGING: + *vp = ToJS(cx, event->Dragging()); + break; + case P_ENTERING: + *vp = ToJS(cx, event->Entering()); + break; + case P_POSITION: + *vp = Point::CreateObject(cx, new wxPoint(event->GetPosition())); + break; + case P_LINES_PER_ACTION: + *vp = ToJS(cx, event->GetLinesPerAction()); + break; + case P_BUTTON: + *vp = ToJS(cx, event->GetButton()); + break; + case P_METADOWN: + *vp = ToJS(cx, event->MetaDown()); + break; + case P_SHIFTDOWN: + *vp = ToJS(cx, event->ShiftDown()); + break; + case P_LEFT_DOWN: + *vp = ToJS(cx, event->LeftDown()); + break; + case P_MIDDLE_DOWN: + *vp = ToJS(cx, event->MiddleDown()); + break; + case P_RIGHT_DOWN: + *vp = ToJS(cx, event->RightDown()); + break; + case P_LEFT_UP: + *vp = ToJS(cx, event->LeftUp()); + break; + case P_MIDDLE_UP: + *vp = ToJS(cx, event->MiddleUp()); + break; + case P_RIGHT_UP: + *vp = ToJS(cx, event->RightUp()); + break; + case P_LEFT_DCLICK: + *vp = ToJS(cx, event->LeftDClick()); + break; + case P_MIDDLE_DCLICK: + *vp = ToJS(cx, event->MiddleDClick()); + break; + case P_RIGHT_DCLICK: + *vp = ToJS(cx, event->RightDClick()); + break; + case P_LEFT_IS_DOWN: + *vp = ToJS(cx, event->LeftIsDown()); + break; + case P_MIDDLE_IS_DOWN: + *vp = ToJS(cx, event->MiddleIsDown()); + break; + case P_RIGHT_IS_DOWN: + *vp = ToJS(cx, event->RightIsDown()); + break; + case P_MOVING: + *vp = ToJS(cx, event->Moving()); + break; + case P_LEAVING: + *vp = ToJS(cx, event->Leaving()); + break; + case P_X: + *vp = ToJS(cx, event->GetX()); + break; + case P_Y: + *vp = ToJS(cx, event->GetY()); + break; + case P_WHEELROTATION: + *vp = ToJS(cx, event->GetWheelRotation()); + break; + case P_WHEELDELTA: + *vp = ToJS(cx, event->GetWheelDelta()); + break; + } + return true; +} + +WXJS_BEGIN_METHOD_MAP(MouseEvent) + WXJS_METHOD("button", button, 1) + WXJS_METHOD("buttonDClick", buttonDClick, 1) + WXJS_METHOD("buttonDown", buttonDown, 1) + WXJS_METHOD("buttonUp", buttonUp, 1) +// Waiting for wxDC +// WXJS_METHOD("getLogicalPosition", getLogicalPosition, 1) +WXJS_END_METHOD_MAP() + +/*** + * + * + * + * The mouse button. + * + * + * + * Returns true if the identified mouse button is changing state. + * Valid values of button are 1, 2 or 3 for left, middle and right buttons respectively. + * + * + */ +JSBool MouseEvent::button(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + PrivMouseEvent *p = (PrivMouseEvent*) JS_GetPrivate(cx, obj); + wxASSERT_MSG(p != NULL, wxT("No private data associated with wxMouseEvent")); + + int button; + if ( FromJS(cx, argv[0], button) ) + { + *rval = ToJS(cx, p->GetEvent()->Button(button)); + return JS_TRUE; + } + else + { + return JS_FALSE; + } +} + +/*** + * + * + * + * The mouse button. + * + * + * + * If the argument is omitted, this returns true if the event was a mouse double click event. + * Otherwise the argument specifies which double click event was generated (1, 2 or 3 for left, middle and right buttons respectively). + * + * + */ +JSBool MouseEvent::buttonDClick(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + PrivMouseEvent *p = (PrivMouseEvent*) JS_GetPrivate(cx, obj); + wxASSERT_MSG(p != NULL, wxT("No private data associated with wxMouseEvent")); + + int button = -1; + FromJS(cx, argv[0], button); + *rval = ToJS(cx, p->GetEvent()->ButtonDClick(button)); + + return JS_TRUE; +} + +/*** + * + * + * + * The mouse button. + * + * + * + * If the argument is omitted, this returns true if the event was a mouse button down event. + * Otherwise the argument specifies which button-down event was generated (1, 2 or 3 for left, middle and right buttons respectively). + * + * + */ +JSBool MouseEvent::buttonDown(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + PrivMouseEvent *p = (PrivMouseEvent*) JS_GetPrivate(cx, obj); + wxASSERT_MSG(p != NULL, wxT("No private data associated with wxMouseEvent")); + + int button = -1; + FromJS(cx, argv[0], button); + *rval = ToJS(cx, p->GetEvent()->ButtonDown(button)); + + return JS_TRUE; +} + +/*** + * + * + * + * The mouse button. + * + * + * + * If the argument is omitted, this returns true if the event was a mouse button up event. + * Otherwise the argument specifies which button-up event was generated (1, 2 or 3 for left, middle and right buttons respectively). + * + * + */ +JSBool MouseEvent::buttonUp(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + PrivMouseEvent *p = (PrivMouseEvent*) JS_GetPrivate(cx, obj); + wxASSERT_MSG(p != NULL, wxT("No private data associated with wxMouseEvent")); + + int button = -1; + FromJS(cx, argv[0], button); + *rval = ToJS(cx, p->GetEvent()->ButtonUp(button)); + + return JS_TRUE; +} Property changes on: ps/trunk/source/tools/atlas/wxJS/gui/event/mouse.cpp ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/gui/event/initdlg.cpp =================================================================== --- ps/trunk/source/tools/atlas/wxJS/gui/event/initdlg.cpp (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/gui/event/initdlg.cpp (revision 5154) @@ -0,0 +1,49 @@ +#include "precompiled.h" + +/* + * wxJavaScript - initdlg.cpp + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: initdlg.cpp 598 2007-03-07 20:13:28Z fbraem $ + */ +// jsevent.cpp +#ifndef WX_PRECOMP + #include +#endif + +#include "../../common/main.h" + +#include "jsevent.h" +#include "event.h" + +using namespace wxjs; +using namespace wxjs::gui; + +/*** + * event/initdlg + * gui + * + * A wxInitDialogEvent is sent as a dialog or panel is being initialised. + * Handlers for this event can transfer data to the window. + * See @wxWindow#onInitDialog. + * + */ +WXJS_INIT_CLASS(InitDialogEvent, "wxInitDialogEvent", 0) Property changes on: ps/trunk/source/tools/atlas/wxJS/gui/event/initdlg.cpp ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/gui/event/split.h =================================================================== --- ps/trunk/source/tools/atlas/wxJS/gui/event/split.h (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/gui/event/split.h (revision 5154) @@ -0,0 +1,67 @@ +/* + * wxJavaScript - split.h + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id$ + */ +#ifndef _WXJSSplitterEvent_H +#define _WXJSSplitterEvent_H + +#include + +namespace wxjs +{ + namespace gui + { + typedef JSEvent PrivSplitterEvent; + class SplitterEvent : public ApiWrapper + { + public: + virtual ~SplitterEvent() + { + } + + static bool GetProperty(PrivSplitterEvent *p, + JSContext *cx, + JSObject *obj, + int id, + jsval *vp); + static bool SetProperty(PrivSplitterEvent *p, + JSContext *cx, + JSObject *obj, + int id, + jsval *vp); + + enum + { + P_SASH_POSITION + , P_X + , P_Y + , P_WINDOW_BEING_REMOVED + }; + + WXJS_DECLARE_PROPERTY_MAP() + }; + }; // namespace gui +}; // namespace wxjs + +#endif //_WXJSSplitterEvent_H Property changes on: ps/trunk/source/tools/atlas/wxJS/gui/event/split.h ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/gui/event/close.cpp =================================================================== --- ps/trunk/source/tools/atlas/wxJS/gui/event/close.cpp (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/gui/event/close.cpp (revision 5154) @@ -0,0 +1,117 @@ +#include "precompiled.h" + +/* + * wxJavaScript - close.cpp + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: close.cpp 598 2007-03-07 20:13:28Z fbraem $ + */ +// close.cpp + +#ifndef WX_PRECOMP + #include +#endif + +#include "../../common/main.h" + +#include "jsevent.h" +#include "close.h" + +using namespace wxjs; +using namespace wxjs::gui; + +/*** + * event/close + * gui + * + * This object is passed to a function that is set to an onClose property of a + * @wxFrame or @wxDialog. The following example vetoes the close event + * because the text control was changed. + *

+ *	frame.onclose = close;
+ *
+ *	function close(closeEvent)
+ *	{
+ *	  if ( closeEvent.canVeto )
+ *	  {
+ *		if ( textCtrl.modified )
+ *		{
+ *		  wxMessageBox("Can't close because you didn't save the contents");
+ *		  closeEvent.veto = true;
+ *		}
+ *	  }
+ *	}
+ *  
+ *
+ */ +WXJS_INIT_CLASS(CloseEvent, "wxCloseEvent", 0) + +/*** + * + * + * Returns true when the close event can be vetoed. + * + * + * Returns true when the user is logging off. + * + * + * Set this to true when you don't want to close the window. + * + * + */ +WXJS_BEGIN_PROPERTY_MAP(CloseEvent) + WXJS_READONLY_PROPERTY(P_CAN_VETO, "canVeto") + WXJS_READONLY_PROPERTY(P_LOGGING_OFF, "loggingOff") + WXJS_PROPERTY(P_VETO, "veto") +WXJS_END_PROPERTY_MAP() + +bool CloseEvent::GetProperty(PrivCloseEvent *p, JSContext *cx, JSObject *obj, int id, jsval *vp) +{ + wxCloseEvent *event = p->GetEvent(); + switch (id) + { + case P_CAN_VETO: + *vp = ToJS(cx, event->CanVeto()); + break; + case P_LOGGING_OFF: + *vp = ToJS(cx, event->GetLoggingOff()); + break; + case P_VETO: + *vp = ToJS(cx, event->GetVeto()); + break; + } + return true; +} + +bool CloseEvent::SetProperty(PrivCloseEvent *p, JSContext *cx, JSObject *obj, int id, jsval *vp) +{ + wxCloseEvent *event = p->GetEvent(); + if ( id == P_VETO + && event->CanVeto() ) + { + bool veto; + if ( FromJS(cx, *vp, veto) ) + { + event->Veto(veto); + } + } + return true; +} Property changes on: ps/trunk/source/tools/atlas/wxJS/gui/event/close.cpp ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/gui/event/notify.h =================================================================== --- ps/trunk/source/tools/atlas/wxJS/gui/event/notify.h (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/gui/event/notify.h (revision 5154) @@ -0,0 +1,64 @@ +/* + * wxJavaScript - notify.h + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: notify.h 598 2007-03-07 20:13:28Z fbraem $ + */ +#ifndef _WXJSNotifyEvent_H +#define _WXJSNotifyEvent_H + +///////////////////////////////////////////////////////////////////////////// +// Name: notify.h +// Purpose: Ports wxNotifyEvent to JavaScript +// Author: Franky Braem +// Modified by: +// Created: 04.10.02 +// Copyright: (c) 2001-2002 Franky Braem +// Licence: LGPL +///////////////////////////////////////////////////////////////////////////// + +namespace wxjs +{ + namespace gui + { + typedef JSEvent PrivNotifyEvent; + class NotifyEvent : public ApiWrapper + { + public: + static bool GetProperty(PrivNotifyEvent *p, JSContext *cx, JSObject *obj, int id, jsval *vp); + static bool SetProperty(PrivNotifyEvent *p, JSContext *cx, JSObject *obj, int id, jsval *vp); + + virtual ~NotifyEvent() + { + } + + enum + { + P_ALLOWED + , P_VETO + }; + + WXJS_DECLARE_PROPERTY_MAP() + }; + }; // namespace gui +}; // namespace wxjs + +#endif //_WXJSNotifyEvent_H Property changes on: ps/trunk/source/tools/atlas/wxJS/gui/event/notify.h ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/gui/event/treeevt.h =================================================================== --- ps/trunk/source/tools/atlas/wxJS/gui/event/treeevt.h (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/gui/event/treeevt.h (revision 5154) @@ -0,0 +1,69 @@ +/* + * wxJavaScript - treeevt.h + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: treeevt.h 598 2007-03-07 20:13:28Z fbraem $ + */ +#ifndef _WXJSTreeEvent_H +#define _WXJSTreeEvent_H + +///////////////////////////////////////////////////////////////////////////// +// Name: cal.h +// Purpose: Ports wxTreeEvent to JavaScript +// Author: Franky Braem +// Modified by: +// Created: 03.01.2003 +// Copyright: (c) 2001-2003 Franky Braem +// Licence: LGPL +///////////////////////////////////////////////////////////////////////////// + +#include +namespace wxjs +{ + namespace gui + { + typedef JSEvent PrivTreeEvent; + class TreeEvent : public ApiWrapper + { + public: + static bool GetProperty(PrivTreeEvent *p, JSContext *cx, JSObject *obj, int id, jsval *vp); + + virtual ~TreeEvent() + { + } + + enum + { + P_ITEM + , P_OLD_ITEM + , P_POINT + , P_KEY_CODE + , P_KEY_EVENT + , P_LABEL + , P_IS_CANCELLED + }; + + WXJS_DECLARE_PROPERTY_MAP() + }; + }; // namespace gui +}; // namespace wxjs + +#endif //_WXJSCalendarEvent_H Property changes on: ps/trunk/source/tools/atlas/wxJS/gui/event/treeevt.h ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/gui/event/mouse.h =================================================================== --- ps/trunk/source/tools/atlas/wxJS/gui/event/mouse.h (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/gui/event/mouse.h (revision 5154) @@ -0,0 +1,95 @@ +/* + * wxJavaScript - mouse.h + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: mouse.h 598 2007-03-07 20:13:28Z fbraem $ + */ +///////////////////////////////////////////////////////////////////////////// +// Name: mouse.h +// Purpose: MouseEvent ports wxMouseEvent to JavaScript. +// Author: Franky Braem +// Modified by: +// Created: 01.07.2002 +// Copyright: (c) 2001-2002 Franky Braem +// Licence: LGPL +///////////////////////////////////////////////////////////////////////////// + +#ifndef _WXJSMouseEvent_H +#define _WXJSMouseEvent_H + +namespace wxjs +{ + namespace gui + { + typedef JSEvent PrivMouseEvent; + + class MouseEvent : public ApiWrapper + { + public: + virtual ~MouseEvent() + { + } + + static bool GetProperty(PrivMouseEvent *p, JSContext *cx, JSObject *obj, int id, jsval *vp); + + // Property ID's + enum + { + P_ALTDOWN + , P_CONTROLDOWN + , P_DRAGGING + , P_ENTERING + , P_POSITION + , P_LINES_PER_ACTION + , P_BUTTON + , P_METADOWN + , P_SHIFTDOWN + , P_LEFT_DOWN + , P_MIDDLE_DOWN + , P_RIGHT_DOWN + , P_LEFT_UP + , P_MIDDLE_UP + , P_RIGHT_UP + , P_LEFT_DCLICK + , P_MIDDLE_DCLICK + , P_RIGHT_DCLICK + , P_LEFT_IS_DOWN + , P_MIDDLE_IS_DOWN + , P_RIGHT_IS_DOWN + , P_MOVING + , P_LEAVING + , P_X + , P_Y + , P_WHEELROTATION + , P_WHEELDELTA + }; + + WXJS_DECLARE_PROPERTY_MAP() + WXJS_DECLARE_METHOD_MAP() + + static JSBool button(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval); + static JSBool buttonDClick(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval); + static JSBool buttonDown(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval); + static JSBool buttonUp(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval); + }; + }; // namespace gui +}; // namespace wxjs +#endif //_WXJSMouseEvent_H Property changes on: ps/trunk/source/tools/atlas/wxJS/gui/event/mouse.h ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/gui/gui_init.cpp =================================================================== --- ps/trunk/source/tools/atlas/wxJS/gui/gui_init.cpp (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/gui/gui_init.cpp (revision 5154) @@ -0,0 +1,657 @@ +#include "precompiled.h" + +/* + * wxJavaScript - init.cpp + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id$ + */ +// main.cpp +#include + +#ifndef WX_PRECOMP + #include +#endif +#include + +#if defined(__WXMSW__) + #include +#endif +#include + +#if defined(__WXMSW__) + #include +#endif + +#include +#include "../common/wxjs.h" +#include "../common/main.h" +#include "../common/jsutil.h" +#include "../common/index.h" + +// All wxJS objects +#include "misc/app.h" +#include "control/window.h" +#include "control/toplevel.h" +#include "control/frame.h" +#include "control/mdi.h" +#include "control/mdichild.h" +#include "control/dialog.h" +#include "control/menu.h" +#include "control/menuitem.h" +#include "control/menubar.h" + +// Controls +#include "control/control.h" +#include "control/textctrl.h" +#include "control/button.h" +#include "control/bmpbtn.h" +#include "control/sttext.h" +#include "control/staticbx.h" +#include "control/checkbox.h" +#include "control/ctrlitem.h" +#include "control/item.h" +#include "control/listbox.h" +#include "control/chklstbx.h" +#include "control/chklstbxchk.h" +#include "control/choice.h" +#include "control/combobox.h" +#include "control/calendar.h" +#include "control/caldate.h" +#include "control/gauge.h" +#include "control/radiobox.h" +#include "control/radiobtn.h" +#include "control/slider.h" +#include "control/helpbtn.h" +#include "control/splitwin.h" +#include "control/statbar.h" +#include "control/toolbar.h" +#include "control/txtdlg.h" +#include "control/pwdlg.h" +#include "control/scrollwnd.h" +#include "control/htmlwin.h" + +// Validators +#include "misc/validate.h" +#include "misc/genval.h" +#include "misc/textval.h" + +// Sizers +#include "misc/sizer.h" +#include "misc/gridszr.h" +#include "misc/flexgrid.h" +#include "misc/boxsizer.h" +#include "misc/stsizer.h" + +// Dialogs +#include "control/panel.h" +#include "control/filedlg.h" +#include "control/dirdlg.h" +#include "control/coldata.h" +#include "control/coldlg.h" +#include "control/fontdata.h" +#include "control/fontdlg.h" +#include "control/findrdlg.h" +#include "control/finddata.h" + +// Miscellaneous wxWindow classes +#include "misc/point.h" +#include "misc/size.h" +#include "misc/rect.h" +#include "misc/accentry.h" +#include "misc/acctable.h" +#include "misc/colour.h" +#include "misc/font.h" +#include "misc/fontenum.h" +#include "misc/fontlist.h" +#include "misc/bitmap.h" +#include "misc/image.h" +#include "misc/imghand.h" +#include "misc/icon.h" +#include "misc/colourdb.h" +#include "misc/cshelp.h" +#include "misc/constant.h" +#if defined(__WXMSW__) + #include "misc/autoobj.h" +#endif + +// Events +#include "event/jsevent.h" + +// Common Controls +#include "misc/cmnconst.h" +#include "misc/imagelst.h" +#include "control/listctrl.h" +#include "control/listhit.h" +#include "control/listitem.h" +#include "control/listitattr.h" +#include "control/treectrl.h" +#include "control/treeitem.h" +#include "control/treeid.h" +#include "control/treehit.h" + +#include "misc/globfun.h" +#include "init.h" + +using namespace wxjs; +using namespace wxjs::gui; + +bool wxjs::gui::InitClass(JSContext *cx, JSObject *global) +{ + InitGuiConstants(cx, global); + + JSObject *obj; + + // Only create the wxApp prototype when no mainloop is running + // which would mean that there is already a wxApp Instance which is the + // case when embedding wxJS into a wxWidgets application + if ( ! wxApp::IsMainLoopRunning() ) + { + obj = App::JSInit(cx, global); + wxASSERT_MSG(obj != NULL, wxT("wxApp prototype creation failed")); + if (! obj ) + return false; + } + + // Initialize wxJS JavaScript objects + obj = Window::JSInit(cx, global); + wxASSERT_MSG(obj != NULL, wxT("wxWindow prototype creation failed")); + if (! obj) + return false; + + obj = Control::JSInit(cx, global, Window::GetClassPrototype()); + wxASSERT_MSG(obj != NULL, wxT("wxControl prototype creation failed")); + if (! obj) + return false; + + obj = TopLevelWindow::JSInit(cx, global, Window::GetClassPrototype()); + wxASSERT_MSG(obj != NULL, wxT("wxTopLevelWindow prototype creation failed")); + if (! obj ) + return false; + + obj = Frame::JSInit(cx, global, TopLevelWindow::GetClassPrototype()); + wxASSERT_MSG(obj != NULL, wxT("wxFrame prototype creation failed")); + if (! obj ) + return false; + + obj = MDIParentFrame::JSInit(cx, global, Frame::GetClassPrototype()); + wxASSERT_MSG(obj != NULL, wxT("wxMDIParentFrame prototype creation failed")); + if (! obj ) + return false; + + obj = MDIChildFrame::JSInit(cx, global, Frame::GetClassPrototype()); + wxASSERT_MSG(obj != NULL, wxT("wxMDIChildFrame prototype creation failed")); + if (! obj ) + return false; + + obj = Menu::JSInit(cx, global); + wxASSERT_MSG(obj != NULL, wxT("wxMenu prototype creation failed")); + if (! obj ) + return false; + + obj = MenuItem::JSInit(cx, global); + wxASSERT_MSG(obj != NULL, wxT("wxMenuItem prototype creation failed")); + if (! obj ) + return false; + + obj = MenuBar::JSInit(cx, global); + wxASSERT_MSG(obj != NULL, wxT("wxMenuBar prototype creation failed")); + if (! obj ) + return false; + + obj = TextCtrl::JSInit(cx, global, Control::GetClassPrototype()); + wxASSERT_MSG(obj != NULL, wxT("wxTextCtrl prototype creation failed")); + if (! obj ) + return false; + + obj = Button::JSInit(cx, global, Control::GetClassPrototype()); + wxASSERT_MSG(obj != NULL, wxT("wxButton prototype creation failed")); + if (! obj ) + return false; + + obj = BitmapButton::JSInit(cx, global, Button::GetClassPrototype()); + wxASSERT_MSG(obj != NULL, wxT("wxBitmapButton prototype creation failed")); + if (! obj ) + return false; + + obj = ContextHelpButton::JSInit(cx, global, BitmapButton::GetClassPrototype()); + wxASSERT_MSG(obj != NULL, wxT("wxContextHelptButton prototype creation failed")); + if (! obj ) + return false; + + obj = StaticText::JSInit(cx, global, Control::GetClassPrototype()); + wxASSERT_MSG(obj != NULL, wxT("wxStaticText prototype creation failed")); + if (! obj ) + return false; + + obj = StaticBox::JSInit(cx, global, Control::GetClassPrototype()); + wxASSERT_MSG(obj != NULL, wxT("wxStaticBox prototype creation failed")); + if (! obj ) + return false; + + obj = CheckBox::JSInit(cx, global, Control::GetClassPrototype()); + wxASSERT_MSG(obj != NULL, wxT("wxCheckBox prototype creation failed")); + if (! obj ) + return false; + + obj = ControlWithItems::JSInit(cx, global, Control::GetClassPrototype()); + wxASSERT_MSG(obj != NULL, wxT("wxControlWithItems prototype creation failed")); + if (! obj ) + return false; + + obj = ListBox::JSInit(cx, global, ControlWithItems::GetClassPrototype()); + wxASSERT_MSG(obj != NULL, wxT("wxListBox prototype creation failed")); + if (! obj ) + return false; + + obj = CheckListBox::JSInit(cx, global, ListBox::GetClassPrototype()); + wxASSERT_MSG(obj != NULL, wxT("wxCheckListBox prototype creation failed")); + if (! obj ) + return false; + + obj = CheckListBoxItem::JSInit(cx, global); + wxASSERT_MSG(obj != NULL, wxT("wxCheckListBoxItem prototype creation failed")); + if (! obj ) + return false; + + obj = Choice::JSInit(cx, global, ControlWithItems::GetClassPrototype()); + wxASSERT_MSG(obj != NULL, wxT("wxChoice prototype creation failed")); + if (! obj ) + return false; + + obj = CalendarCtrl::JSInit(cx, global, Control::GetClassPrototype()); + wxASSERT_MSG(obj != NULL, wxT("wxCalendarCtrl prototype creation failed")); + if (! obj ) + return false; + + obj = Gauge::JSInit(cx, global, Control::GetClassPrototype()); + wxASSERT_MSG(obj != NULL, wxT("wxGauge prototype creation failed")); + if (! obj ) + return false; + + obj = RadioBox::JSInit(cx, global, Control::GetClassPrototype()); + wxASSERT_MSG(obj != NULL, wxT("wxRadioBox prototype creation failed")); + if (! obj ) + return false; + + obj = RadioButton::JSInit(cx, global, Control::GetClassPrototype()); + wxASSERT_MSG(obj != NULL, wxT("wxRadioButton prototype creation failed")); + if (! obj ) + return false; + + obj = Panel::JSInit(cx, global, Window::GetClassPrototype()); + wxASSERT_MSG(obj != NULL, wxT("wxPanel prototype creation failed")); + if (! obj ) + return false; + + obj = Dialog::JSInit(cx, global, TopLevelWindow::GetClassPrototype()); + wxASSERT_MSG(obj != NULL, wxT("wxDialog prototype creation failed")); + if (! obj ) + return false; + + obj = CalendarDateAttr::JSInit(cx, global); + wxASSERT_MSG(obj != NULL, wxT("wxCalendarDateAttr prototype creation failed")); + if (! obj ) + return false; + + obj = ComboBox::JSInit(cx, global, ControlWithItems::GetClassPrototype()); + wxASSERT_MSG(obj != NULL, wxT("wxComboBox prototype creation failed")); + if (! obj ) + return false; + + obj = Slider::JSInit(cx, global, Control::GetClassPrototype()); + wxASSERT_MSG(obj != NULL, wxT("wxSlider prototype creation failed")); + if (! obj ) + return false; + + obj = Point::JSInit(cx, global); + wxASSERT_MSG(obj != NULL, wxT("wxPoint prototype creation failed")); + if (! obj ) + return false; + + obj = Size::JSInit(cx, global); + wxASSERT_MSG(obj != NULL, wxT("wxSize prototype creation failed")); + if (! obj ) + return false; + + obj = Rect::JSInit(cx, global); + wxASSERT_MSG(obj != NULL, wxT("wxRect prototype creation failed")); + if (! obj ) + return false; + + obj = FileDialog::JSInit(cx, global, Dialog::GetClassPrototype()); + wxASSERT_MSG(obj != NULL, wxT("wxFileDialog prototype creation failed")); + if (! obj ) + return false; + + if ( ! InitEventClasses(cx, global) ) + return false; + + obj = Sizer::JSInit(cx, global); + wxASSERT_MSG(obj != NULL, wxT("wxSizer prototype creation failed")); + if (! obj ) + return false; + + obj = GridSizer::JSInit(cx, global, Sizer::GetClassPrototype()); + wxASSERT_MSG(obj != NULL, wxT("wxGridSizer prototype creation failed")); + if (! obj ) + return false; + + obj = FlexGridSizer::JSInit(cx, global, GridSizer::GetClassPrototype()); + wxASSERT_MSG(obj != NULL, wxT("wxFlexGridSizer prototype creation failed")); + if (! obj ) + return false; + + obj = BoxSizer::JSInit(cx, global, Sizer::GetClassPrototype()); + wxASSERT_MSG(obj != NULL, wxT("wxBoxSizer prototype creation failed")); + if (! obj ) + return false; + + obj = StaticBoxSizer::JSInit(cx, global, BoxSizer::GetClassPrototype()); + wxASSERT_MSG(obj != NULL, wxT("wxStaticBoxSizer prototype creation failed")); + if (! obj ) + return false; + + obj = Validator::JSInit(cx, global); + wxASSERT_MSG(obj != NULL, wxT("wxValidator prototype creation failed")); + if (! obj ) + return false; + + obj = GenericValidator::JSInit(cx, global, Validator::GetClassPrototype()); + wxASSERT_MSG(obj != NULL, wxT("wxGenericValidator prototype creation failed")); + if (! obj ) + return false; + + obj = TextValidator::JSInit(cx, global, Validator::GetClassPrototype()); + wxASSERT_MSG(obj != NULL, wxT("wxTextValidator prototype creation failed")); + if (! obj ) + return false; + + obj = AcceleratorEntry::JSInit(cx, global); + wxASSERT_MSG(obj != NULL, wxT("wxAcceleratorEntry prototype creation failed")); + if (! obj ) + return false; + + obj = AcceleratorTable::JSInit(cx, global); + wxASSERT_MSG(obj != NULL, wxT("wxAcceleratorTable prototype creation failed")); + if (! obj ) + return false; + + obj = Colour::JSInit(cx, global); + wxASSERT_MSG(obj != NULL, wxT("wxColour prototype creation failed")); + if (! obj ) + return false; + + obj = ColourDatabase::JSInit(cx, global); + wxASSERT_MSG(obj != NULL, wxT("wxColourDatabase prototype creation failed")); + if (! obj ) + return false; + + obj = Font::JSInit(cx, global); + wxASSERT_MSG(obj != NULL, wxT("wxFont prototype creation failed")); + if (! obj ) + return false; + + obj = ColourData::JSInit(cx, global); + wxASSERT_MSG(obj != NULL, wxT("wxColourData prototype creation failed")); + if (! obj ) + return false; + + obj = ColourDialog::JSInit(cx, global, Dialog::GetClassPrototype()); + wxASSERT_MSG(obj != NULL, wxT("wxColourDialog prototype creation failed")); + if (! obj ) + return false; + + obj = FontData::JSInit(cx, global); + wxASSERT_MSG(obj != NULL, wxT("wxFontData prototype creation failed")); + if (! obj ) + return false; + + obj = FontDialog::JSInit(cx, global, Dialog::GetClassPrototype()); + wxASSERT_MSG(obj != NULL, wxT("wxFontDialog prototype creation failed")); + if (! obj ) + return false; + + obj = FontList::JSInit(cx, global); + wxASSERT_MSG(obj != NULL, wxT("wxFontList prototype creation failed")); + if (! obj ) + return false; + + obj = DirDialog::JSInit(cx, global, Dialog::GetClassPrototype()); + wxASSERT_MSG(obj != NULL, wxT("wxDirDialog prototype creation failed")); + if (! obj ) + return false; + + obj = FindReplaceData::JSInit(cx, global); + wxASSERT_MSG(obj != NULL, wxT("wxFindReplaceData prototype creation failed")); + if (! obj ) + return false; + + obj = FindReplaceDialog::JSInit(cx, global, Dialog::GetClassPrototype()); + wxASSERT_MSG(obj != NULL, wxT("wxFindReplaceDialog prototype creation failed")); + if (! obj ) + return false; + + obj = FontEnumerator::JSInit(cx, global); + wxASSERT_MSG(obj != NULL, wxT("wxFontEnumerator prototype creation failed")); + if (! obj ) + return false; + + obj = Bitmap::JSInit(cx, global); + wxASSERT_MSG(obj != NULL, wxT("wxBitmap prototype creation failed")); + if (! obj ) + return false; + + obj = Icon::JSInit(cx, global, Bitmap::GetClassPrototype()); + wxASSERT_MSG(obj != NULL, wxT("wxIcon prototype creation failed")); + if (! obj ) + return false; + + obj = ContextHelp::JSInit(cx, global); + wxASSERT_MSG(obj != NULL, wxT("wxFile prototype creation failed")); + if (! obj ) + return false; + + InitCommonConst(cx, global); + + obj = ImageList::JSInit(cx, global); + wxASSERT_MSG(obj != NULL, wxT("wxImageList prototype creation failed")); + if (! obj ) + return false; + + obj = ListCtrl::JSInit(cx, global, Control::GetClassPrototype()); + wxASSERT_MSG(obj != NULL, wxT("wxListCtrl prototype creation failed")); + if (! obj ) + return false; + + obj = ListItem::JSInit(cx, global); + wxASSERT_MSG(obj != NULL, wxT("wxListItem prototype creation failed")); + if (! obj ) + return false; + + obj = ListItemAttr::JSInit(cx, global); + wxASSERT_MSG(obj != NULL, wxT("wxListItemAttr prototype creation failed")); + if (! obj ) + return false; + + obj = ListHitTest::JSInit(cx, global); + wxASSERT_MSG(obj != NULL, wxT("wxListHitTest prototype creation failed")); + if (! obj ) + return false; + + obj = TreeCtrl::JSInit(cx, global, Control::GetClassPrototype()); + wxASSERT_MSG(obj != NULL, wxT("wxTreeCtrl prototype creation failed")); + if (! obj ) + return false; + + obj = TreeItem::JSInit(cx, global); + wxASSERT_MSG(obj != NULL, wxT("wxTreeItem prototype creation failed")); + if (! obj ) + return false; + + obj = TreeItemId::JSInit(cx, global); + wxASSERT_MSG(obj != NULL, wxT("wxTreeItemId prototype creation failed")); + if (! obj ) + return false; + + obj = TreeHitTest::JSInit(cx, global); + wxASSERT_MSG(obj != NULL, wxT("wxTreeHitTest prototype creation failed")); + if (! obj ) + return false; + + obj = SplitterWindow::JSInit(cx, global, Window::GetClassPrototype()); + wxASSERT_MSG(obj != NULL, wxT("wxSplitterWindow prototype creation failed")); + if (! obj ) + return false; + + obj = StatusBar::JSInit(cx, global, Window::GetClassPrototype()); + wxASSERT_MSG(obj != NULL, wxT("wxStatusBar prototype creation failed")); + if (! obj ) + return false; + + obj = ToolBar::JSInit(cx, global, Control::GetClassPrototype()); + wxASSERT_MSG(obj != NULL, wxT("wxToolBar prototype creation failed")); + if (! obj ) + return false; + +#ifdef __WXMSW__ + obj = AutomationObject::JSInit(cx, global); + wxASSERT_MSG(obj != NULL, wxT("wxAutomationObject prototype creation failed")); + if (! obj ) + return false; +#endif + + obj = Image::JSInit(cx, global); + wxASSERT_MSG(obj != NULL, wxT("wxImage prototype creation failed")); + if (! obj ) + return false; + + obj = ImageHandler::JSInit(cx, global); + wxASSERT_MSG(obj != NULL, wxT("wxImageHandler prototype creation failed")); + if (! obj ) + return false; + + obj = BMPHandler::JSInit(cx, global, ImageHandler::GetClassPrototype()); + wxASSERT_MSG(obj != NULL, wxT("wxBMPHandler prototype creation failed")); + if (! obj ) + return false; + + obj = GIFHandler::JSInit(cx, global, ImageHandler::GetClassPrototype()); + wxASSERT_MSG(obj != NULL, wxT("wxGIFHandler prototype creation failed")); + if (! obj ) + return false; + + obj = ICOHandler::JSInit(cx, global, ImageHandler::GetClassPrototype()); + wxASSERT_MSG(obj != NULL, wxT("wxICOHandler prototype creation failed")); + if (! obj ) + return false; + + obj = JPEGHandler::JSInit(cx, global, ImageHandler::GetClassPrototype()); + wxASSERT_MSG(obj != NULL, wxT("wxJPEGHandler prototype creation failed")); + if (! obj ) + return false; + + obj = PCXHandler::JSInit(cx, global, ImageHandler::GetClassPrototype()); + wxASSERT_MSG(obj != NULL, wxT("wxPCXHandler prototype creation failed")); + if (! obj ) + return false; + + obj = PNGHandler::JSInit(cx, global, ImageHandler::GetClassPrototype()); + wxASSERT_MSG(obj != NULL, wxT("wxPNGHandler prototype creation failed")); + if (! obj ) + return false; + + obj = PNMHandler::JSInit(cx, global, ImageHandler::GetClassPrototype()); + wxASSERT_MSG(obj != NULL, wxT("wxPNMHandler prototype creation failed")); + if (! obj ) + return false; + + obj = TIFFHandler::JSInit(cx, global, ImageHandler::GetClassPrototype()); + wxASSERT_MSG(obj != NULL, wxT("wxTIFFHandler prototype creation failed")); + if (! obj ) + return false; + + obj = XPMHandler::JSInit(cx, global, ImageHandler::GetClassPrototype()); + wxASSERT_MSG(obj != NULL, wxT("wxXPMHandler prototype creation failed")); + if (! obj ) + return false; + + obj = TextEntryDialog::JSInit(cx, global, Dialog::GetClassPrototype()); + wxASSERT_MSG(obj != NULL, wxT("wxTextEntryDialog prototype creation failed")); + if (! obj ) + return false; + + obj = PasswordEntryDialog::JSInit(cx, global, TextEntryDialog::GetClassPrototype()); + wxASSERT_MSG(obj != NULL, wxT("wxPasswordEntryDialog prototype creation failed")); + if (! obj ) + return false; + + obj = ScrolledWindow::JSInit(cx, global, Panel::GetClassPrototype()); + wxASSERT_MSG(obj != NULL, wxT("wxScrollWindow prototype creation failed")); + if (! obj ) + return false; + + obj = HtmlWindow::JSInit(cx, global, ScrolledWindow::GetClassPrototype()); + wxASSERT_MSG(obj != NULL, wxT("wxHtmlWindow prototype creation failed")); + if (! obj ) + return false; + + // Define the global functions + InitFunctions(cx, global); + + DefineGlobals(cx, global); + return true; +} + +bool wxjs::gui::InitObject(JSContext *cx, JSObject *obj) +{ + // Only create wxTheApp, if there is no running mainloop, becuase in this + // case there exists already an instance of wxApp, which is the case when embedding + // wxJS into a wxWidgets application + if ( ! wxApp::IsMainLoopRunning() ) + { + JSObject *jsApp = JS_NewObject(cx, App::GetClass(), NULL, NULL); + JS_SetPrivate(cx, jsApp, wxTheApp); + wxTheApp->SetClientObject(new JavaScriptClientData(cx, jsApp, true, false)); + //JSObject *jsApp = JS_ConstructObject(cx, App::GetClass(), App::GetClassPrototype(), NULL); + JS_DefineProperty(cx, obj, "wxTheApp", OBJECT_TO_JSVAL(jsApp), NULL, NULL, 0); + } + + return true; + +} + +void wxjs::gui::Destroy() +{ + if ( ! wxApp::IsMainLoopRunning() ) + { + wxClassInfo *cInfo = wxTheApp->GetClassInfo(); + wxString t_strClassName( cInfo->GetClassName() ); + + // Make sure the object is unrooted by cleaning up the client object + JavaScriptClientData *data + = dynamic_cast(wxTheApp->GetClientObject()); + if ( data != NULL ) + { + wxTheApp->SetClientObject(NULL); + } + } +} Property changes on: ps/trunk/source/tools/atlas/wxJS/gui/gui_init.cpp ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/gui/misc/fontenum.h =================================================================== --- ps/trunk/source/tools/atlas/wxJS/gui/misc/fontenum.h (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/gui/misc/fontenum.h (revision 5154) @@ -0,0 +1,77 @@ +/* + * wxJavaScript - fontenum.h + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: fontenum.h 715 2007-05-18 20:38:04Z fbraem $ + */ +#ifndef _WXJSFontEnumerator_H +#define _WXJSFontEnumerator_H + +#include + +namespace wxjs +{ + namespace gui + { + + class FontEnumerator : public wxFontEnumerator + , public ApiWrapper + { + public: + /** + * Constructor + */ + FontEnumerator(JSContext *cx, JSObject *obj); + + /** + * Destructor + */ + virtual ~FontEnumerator(); + + static bool GetStaticProperty(JSContext *cx, int id, jsval *vp); + + static FontEnumerator *Construct(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, bool constructing); + + static JSBool enumerateFacenames(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval); + static JSBool enumerateEncodings(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval); + + bool OnFacename(const wxString &faceName); + + bool OnFontencoding(const wxString &faceName, const wxString &encoding); + + WXJS_DECLARE_STATIC_PROPERTY_MAP() + WXJS_DECLARE_METHOD_MAP() + + /** + * Property Ids. + */ + enum + { + P_FACENAMES + , P_ENCODINGS + }; + private: + JavaScriptClientData *m_data; + }; + }; // namespace gui +}; // namespace wxjs + +#endif //_WXJSFontEnumerator_H Property changes on: ps/trunk/source/tools/atlas/wxJS/gui/misc/fontenum.h ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/gui/misc/font.h =================================================================== --- ps/trunk/source/tools/atlas/wxJS/gui/misc/font.h (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/gui/misc/font.h (revision 5154) @@ -0,0 +1,74 @@ +/* + * wxJavaScript - font.h + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: font.h 598 2007-03-07 20:13:28Z fbraem $ + */ +#ifndef _WXJSFont_H +#define _WXJSFont_H + +///////////////////////////////////////////////////////////////////////////// +// Name: font.h +// Purpose: Font ports wxFont to JavaScript. +// Author: Franky Braem +// Modified by: +// Created: 05.07.02 +// Copyright: (c) 2001-2002 Franky Braem +// Licence: LGPL +///////////////////////////////////////////////////////////////////////////// +namespace wxjs +{ + namespace gui + { + class Font : public ApiWrapper + { + public: + static bool GetProperty(wxFont *p, JSContext *cx, JSObject *obj, int id, jsval *vp); + static bool SetProperty(wxFont *p, JSContext *cx, JSObject *obj, int id, jsval *vp); + + static bool GetStaticProperty(JSContext *cx, int id, jsval *vp); + static bool SetStaticProperty(JSContext *cx, int id, jsval *vp); + + static wxFont* Construct(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, bool constructing); + + WXJS_DECLARE_PROPERTY_MAP() + WXJS_DECLARE_STATIC_PROPERTY_MAP() + WXJS_DECLARE_CONSTANT_MAP() + + /** + * Property Ids. + */ + enum + { + P_DEFAULT_ENCODING + , P_FACE_NAME + , P_FAMILY + , P_POINT_SIZE + , P_STYLE + , P_UNDERLINED + , P_WEIGHT + , P_OK + }; + }; + }; // namespace gui +}; // namespace wxjs + +#endif //_WXJSFont_H Property changes on: ps/trunk/source/tools/atlas/wxJS/gui/misc/font.h ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/gui/misc/app.h =================================================================== --- ps/trunk/source/tools/atlas/wxJS/gui/misc/app.h (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/gui/misc/app.h (revision 5154) @@ -0,0 +1,95 @@ +/* + * wxJavaScript - app.h + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: app.h 716 2007-05-20 17:57:22Z fbraem $ + */ +#ifndef _WXJSApp_H +#define _WXJSApp_H + +namespace wxjs +{ + namespace gui + { + class App : public wxApp + , public ApiWrapper + { + public: + + /** + * Constructor + */ + App() : wxApp() + { + } + + /** + * Destructor + */ + virtual ~App(); + + static bool GetProperty(wxApp *p, + JSContext *cx, + JSObject *obj, + int id, + jsval *vp); + static bool SetProperty(wxApp *p, + JSContext *cx, + JSObject *obj, + int id, + jsval *vp); + + /** + * MainLoop is overridden to make sure, we only enter the mainloop + * when a window is created + */ + int MainLoop(); + + /** + * Runs the mainloop + */ + static JSBool mainLoop(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval); + + WXJS_DECLARE_PROPERTY_MAP() + WXJS_DECLARE_METHOD_MAP() + + /** + * Property Ids. + */ + enum + { + P_APPLICATION_NAME + , P_TOP_WINDOW + , P_INITIALIZED + , P_CLASS_NAME + , P_VENDOR_NAME + }; + + virtual int OnExit(); + bool OnInit(); + + private: + void DestroyTopWindows(); + }; + }; // namespace gui +}; // namespace wxjs + +#endif //_WXJSApp_H Property changes on: ps/trunk/source/tools/atlas/wxJS/gui/misc/app.h ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/gui/misc/cmnconst.h =================================================================== --- ps/trunk/source/tools/atlas/wxJS/gui/misc/cmnconst.h (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/gui/misc/cmnconst.h (revision 5154) @@ -0,0 +1,40 @@ +/* + * wxJavaScript - cmnconst.h + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: cmnconst.h 598 2007-03-07 20:13:28Z fbraem $ + */ +#ifndef _WXJSCmnConst_H +#define _WXJSCmnConst_H + +///////////////////////////////////////////////////////////////////////////// +// Name: cmnconst.h +// Purpose: Defines constants for common controls (like wxListCtrl) +// Author: Franky Braem +// Modified by: +// Created: 30.09.2002 +// Copyright: (c) 2001-2002 Franky Braem +// Licence: LGPL +///////////////////////////////////////////////////////////////////////////// + +void InitCommonConst(JSContext *cx, JSObject *obj); + +#endif //_WXJSCmnConst_H Property changes on: ps/trunk/source/tools/atlas/wxJS/gui/misc/cmnconst.h ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/gui/misc/point.h =================================================================== --- ps/trunk/source/tools/atlas/wxJS/gui/misc/point.h (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/gui/misc/point.h (revision 5154) @@ -0,0 +1,63 @@ +/* + * wxJavaScript - point.h + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: point.h 598 2007-03-07 20:13:28Z fbraem $ + */ +///////////////////////////////////////////////////////////////////////////// +// Name: point.h +// Purpose: Ports wxPoint to JavaScript +// Author: Franky Braem +// Modified by: +// Created: 16.12.01 +// Copyright: (c) 2001-2002 Franky Braem +// Licence: LGPL +///////////////////////////////////////////////////////////////////////////// + +#ifndef _WXJSPoint_H +#define _WXJSPoint_H + +namespace wxjs +{ + namespace gui + { + class Point : public ApiWrapper + { + public: + + static bool GetProperty(wxPoint *p, JSContext *cx, JSObject *obj, int id, jsval *vp); + + static bool SetProperty(wxPoint *p, JSContext *cx, JSObject *obj, int id, jsval *vp); + + static wxPoint *Construct(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, bool constructing); + + enum + { + P_X + , P_Y + }; + + WXJS_DECLARE_PROPERTY_MAP() + }; + }; // namespace gui +}; // namespace wxjs + +#endif //_WXJSPoint_H Property changes on: ps/trunk/source/tools/atlas/wxJS/gui/misc/point.h ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/gui/misc/pnmhdlr.cpp =================================================================== --- ps/trunk/source/tools/atlas/wxJS/gui/misc/pnmhdlr.cpp (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/gui/misc/pnmhdlr.cpp (revision 5154) @@ -0,0 +1,54 @@ +#include "precompiled.h" + +/* + * wxJavaScript - pnmhdlr.cpp + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: pnmhdlr.cpp 598 2007-03-07 20:13:28Z fbraem $ + */ +#ifndef WX_PRECOMP + #include +#endif + +#include "../../common/main.h" +#include "../../common/type.h" +#include "../../common/jsutil.h" + +#include "imghand.h" +using namespace wxjs; +using namespace wxjs::gui; + +/*** + * misc/pnmhdlr + * gui + * + * Image handler for PNM images. + * Loading PNMs only works for ASCII or raw RGB images. When saving in PNM format, + * wxPNMHandler will always save as raw RGB. + * + */ +WXJS_INIT_CLASS(PNMHandler, "wxPNMHandler", 0) + +ImageHandlerPrivate* PNMHandler::Construct(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, bool constructing) +{ + return new ImageHandlerPrivate(new wxPNMHandler(), true); +}; + Property changes on: ps/trunk/source/tools/atlas/wxJS/gui/misc/pnmhdlr.cpp ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/gui/misc/imagelst.h =================================================================== --- ps/trunk/source/tools/atlas/wxJS/gui/misc/imagelst.h (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/gui/misc/imagelst.h (revision 5154) @@ -0,0 +1,78 @@ +/* + * wxJavaScript - imagelst.h + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: imagelst.h 715 2007-05-18 20:38:04Z fbraem $ + */ +#ifndef _WXJSImageList_H +#define _WXJSImageList_H + +#include + +namespace wxjs +{ + namespace gui + { + class ImageList : public ApiWrapper + , public wxImageList + , public wxClientDataContainer + { + public: + + ImageList(); + virtual ~ImageList() {} + + static bool GetProperty(wxImageList *p, + JSContext *cx, + JSObject *obj, + int id, + jsval *vp); + static ImageList* Construct(JSContext *cx, + JSObject *obj, + uintN argc, + jsval *argv, + bool constructing); + + WXJS_DECLARE_PROPERTY_MAP() + + /** + * Property Ids. + */ + enum + { + P_IMAGE_COUNT + }; + + WXJS_DECLARE_METHOD_MAP() + WXJS_DECLARE_METHOD(add) + WXJS_DECLARE_METHOD(create) + WXJS_DECLARE_METHOD(draw) + WXJS_DECLARE_METHOD(getSize) + WXJS_DECLARE_METHOD(remove) + WXJS_DECLARE_METHOD(replace) + WXJS_DECLARE_METHOD(removeAll) + + }; + }; // namespace gui +}; // namespace wxjs + +#endif //_WXJSImageList_H + Property changes on: ps/trunk/source/tools/atlas/wxJS/gui/misc/imagelst.h ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/gui/misc/cshelp.cpp =================================================================== --- ps/trunk/source/tools/atlas/wxJS/gui/misc/cshelp.cpp (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/gui/misc/cshelp.cpp (revision 5154) @@ -0,0 +1,154 @@ +#include "precompiled.h" + +/* + * wxJavaScript - cshelp.cpp + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: cshelp.cpp 598 2007-03-07 20:13:28Z fbraem $ + */ +// cshelp.cpp + +#ifndef WX_PRECOMP + #include +#endif + +#include "../../common/main.h" + +#include "../control/window.h" + +#include "cshelp.h" + +using namespace wxjs; +using namespace wxjs::gui; + +/*** + * misc/cshelp + * gui + * + * This class changes the cursor to a query and puts the application into a + * 'context-sensitive help mode'. When the user left-clicks on a window within + * the specified window, a wxEVT_HELP event is sent to that control, and the + * application may respond to it by popping up some help. + * + */ +WXJS_INIT_CLASS(ContextHelp, "wxContextHelp", 0) + +/*** + * + * + * + * The window that will get the @wxHelpEvent . When the object + * is null, the top level window will be used. + * + * + * When true (= default), the application will enter the 'context-sensitive help mode' + * immediately. Otherwise @wxContextHelp#beginContextHelp needs to be called. + * + * + * + * Constructs a new wxContextHelp object. + * + * + */ +wxContextHelp* ContextHelp::Construct(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, bool constructing) +{ + if ( argc > 2 ) + argc = 2; + + wxWindow *win = NULL; + bool now = true; + + switch(argc) + { + case 2: + if ( ! FromJS(cx, argv[1], now) ) + return NULL; + // Fall through + case 1: + if ( ! JSVAL_IS_VOID(argv[0]) ) + { + win = Window::GetPrivate(cx, argv[0]); + if ( win == NULL ) + return NULL; + } + } + + return new wxContextHelp(win, now); +} + +WXJS_BEGIN_METHOD_MAP(ContextHelp) + WXJS_METHOD("beginContextHelp", beginContextHelp, 0) + WXJS_METHOD("endContextHelp", endContextHelp, 0) +WXJS_END_METHOD_MAP() + +/*** + * + * + * + * The window that will get the @wxHelpEvent. When the object + * is null, the top level window will be used. + * + * + * + * Puts the application into context-sensitive help mode. + * Returns true, when the application was put successfully into context-sensitive help mode. + * This function only returns when the event loop has finished. + * + * + */ +JSBool ContextHelp::beginContextHelp(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxContextHelp *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + if ( argc > 1 ) + argc = 1; + + wxWindow *win = NULL; + if ( argc == 1 ) + { + win = Window::GetPrivate(cx, argv[0]); + if ( win == NULL ) + return JS_FALSE; + } + + *rval = ToJS(cx, p->BeginContextHelp(win)); + return JS_TRUE; +} + +/*** + * + * + * + * Ends context-sensitive help mode. Not normally called by the application. + * + * + */ +JSBool ContextHelp::endContextHelp(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxContextHelp *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + p->EndContextHelp(); + return JS_TRUE; +} Property changes on: ps/trunk/source/tools/atlas/wxJS/gui/misc/cshelp.cpp ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/gui/misc/gridszr.h =================================================================== --- ps/trunk/source/tools/atlas/wxJS/gui/misc/gridszr.h (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/gui/misc/gridszr.h (revision 5154) @@ -0,0 +1,48 @@ +/* + * wxJavaScript - gridszr.h + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: gridszr.h 715 2007-05-18 20:38:04Z fbraem $ + */ +#ifndef _WXJSGridSizer_H +#define _WXJSGridSizer_H + +namespace wxjs +{ + class Object; + + namespace gui + { + + class GridSizer : public ApiWrapper + { + public: + + static wxGridSizer* Construct(JSContext *cx, + JSObject *obj, + uintN argc, + jsval *argv, + bool constructing); + }; + }; // namespace gui +}; // namespace wxjs + +#endif //_WXJSGridSizer_H Property changes on: ps/trunk/source/tools/atlas/wxJS/gui/misc/gridszr.h ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/gui/misc/sizer.cpp =================================================================== --- ps/trunk/source/tools/atlas/wxJS/gui/misc/sizer.cpp (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/gui/misc/sizer.cpp (revision 5154) @@ -0,0 +1,675 @@ +#include "precompiled.h" + +/* + * wxJavaScript - sizer.cpp + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: sizer.cpp 733 2007-06-05 21:17:25Z fbraem $ + */ +// sizer.cpp + +#ifndef WX_PRECOMP + #include +#endif + +#include "../../common/main.h" +#include "../../common/apiwrap.h" + +#include "../control/window.h" + +#include "sizer.h" +#include "size.h" +#include "point.h" + +using namespace wxjs; +using namespace wxjs::gui; + +/*** + * misc/sizer + * gui + * + * wxSizer is the prototype for all sizer objects : + * @wxBoxSizer, @wxFlexGridSizer, @wxGridSizer and @wxStaticBoxSizer. + * See also following wxWindow properties: @wxWindow#sizer, and @wxWindow#autoLayout. + *

+ * The example will show a dialog box that asks the user to enter a name and a password. + * The labels, text controls and buttons are placed dynamically on the dialog using sizers. + *

+ *    // The wxSizer example
+ *    wxTheApp.onInit = init;
+ *    wxTheApp.mainLoop();
+ *   
+ *    function init()
+ *    {
+ *      //Create a dialog box
+ *
+ *      var dlg = new wxDialog(null, -1, "wxSizer Example",
+ *                             wxDefaultPosition, new wxSize(200, 150));
+ *      // Create a wxBoxSizer for the dialog. 
+ *      // The main direction of this sizer is vertical. 
+ *      // This means that when an item is added to this sizer, it will be added below the previous item.
+ *
+ *      dlg.sizer = new wxBoxSizer(wxOrientation.VERTICAL);
+ *  
+ *      // Use a wxFlexGridSizer to layout the labels with their corresponding text controls.
+ *      // The sizer is created with 2 rows and 2 columns. The first column is used for the label, 
+ *      // while the second column is used for the text controls. The space between the rows and 
+ *      // columns is set to 10.
+ *
+ *      var sizer1 = new wxFlexGridSizer(2, 2, 10, 10);
+ *
+ *      // Add the labels and text controls to sizer1. A label is centered vertically. 
+ *      // A grid sizer is filled from left to right, top to bottom.
+ *
+ *      sizer1.add(new wxStaticText(dlg, -1, "Username"), 0, wxAlignment.CENTER_VERTICAL);
+ *      sizer1.add(new wxTextCtrl(dlg, -1, "<user>"));
+ *      sizer1.add(new wxStaticText(dlg, -1, "Password"), 0, wxAlignment.CENTER_VERTICAL);
+ *      sizer1.add(new wxTextCtrl(dlg, -1, "<pwd>"));
+ *
+ *      // Add this sizer to the sizer of the dialog. The flag argument is 0 which means 
+ *      // that this item is not allowed to grow in the main direction (which is vertically).
+ *      // The item is centered. Above (wxDirection.TOP) and below (wxDirection.BOTTOM) the item, 
+ *      // a border is created with a size of 10.
+ *
+ *      dlg.sizer.add(sizer1, 0, wxAlignment.CENTER | wxDirection.TOP | wxDirection.BOTTOM, 10);
+ *
+ *      // Create a new wxBoxSizer and assign it to sizer1. The main direction of this sizer 
+ *      // is horizontally. This means that when an item is added it will be shown on the same row.
+ *
+ *      sizer1 = new wxBoxSizer(wxOrientation.HORIZONTAL);
+ *
+ *      // Add the Ok button to the sizer and make sure that it has a right border of size 10. 
+ *      // This way there's a space between the ok button and the cancel button.
+ *
+ *      sizer1.add(new wxButton(dlg, wxId.OK, "Ok"), 0, wxDirection.RIGHT, 10);
+ *
+ *      // Add the Cancel button to the sizer.
+ *
+ *      sizer1.add(new wxButton(dlg, wxId.CANCEL, "Cancel"));
+ *
+ *      // Add the sizer to the sizer of the dialog. The item is centered.
+ *
+ *      dlg.sizer.add(sizer1, 0, wxAlignment.CENTER);
+ *
+ *      // Before showing the dialog, set the autoLayout property to true and call 
+ *      // layout to layout the controls. When the dialog is resized, the controls
+ *      // will be automaticcally resized.
+ *
+ *      dlg.autoLayout = true;
+ *      dlg.layout();
+ *      dlg.showModal();
+ *      return false;
+ *    }
+ *  
+ *
+ */ +WXJS_INIT_CLASS(Sizer, "wxSizer", 0) + +/*** + * + * + * Get/Set the minimal size of the sizer. + * See @wxSizer#setMinSize + * + * + * Gets the position of the sizer. + * + * + * Gets the current size of the sizer. + * + * + */ +WXJS_BEGIN_PROPERTY_MAP(Sizer) + WXJS_PROPERTY(P_MIN_SIZE, "minSize") + WXJS_READONLY_PROPERTY(P_POSITION, "position") + WXJS_READONLY_PROPERTY(P_SIZE, "size") +WXJS_END_PROPERTY_MAP() + +WXJS_BEGIN_METHOD_MAP(Sizer) + WXJS_METHOD("add", add, 1) + WXJS_METHOD("layout", layout, 0) + WXJS_METHOD("prepend", prepend, 5) + WXJS_METHOD("remove", remove, 1) + WXJS_METHOD("setDimension", setDimension, 4) + WXJS_METHOD("setMinSize", setMinSize, 4) + WXJS_METHOD("setItemMinSize", setItemMinSize, 3) +WXJS_END_METHOD_MAP() + +bool Sizer::GetProperty(wxSizer *p, JSContext *cx, JSObject *obj, int id, jsval *vp) +{ + switch(id) + { + case P_MIN_SIZE: + *vp = Size::CreateObject(cx, new wxSize(p->GetMinSize())); + break; + case P_SIZE: + *vp = Size::CreateObject(cx, new wxSize(p->GetSize())); + break; + case P_POSITION: + *vp = Point::CreateObject(cx, new wxPoint(p->GetPosition())); + break; + } + return true; +} + +bool Sizer::SetProperty(wxSizer *p, JSContext *cx, JSObject *obj, int id, jsval *vp) +{ + if ( id == P_MIN_SIZE ) + { + wxSize *size = Size::GetPrivate(cx, *vp); + if ( size != NULL ) + { + p->SetMinSize(*size); + } + } + return true; +} + +/*** + * + * + * + * An object with a @wxWindow as its prototype. + * + * + * Option is used together with @wxBoxSizer. 0 means that the size of the control + * is not allowed to change in the main orientation of the sizer. 1 means that the + * size of the control may grow or shrink in the main orientation of the sizer + * + * + * This parameter is used to set a number of flags. One main behaviour of a flag is to + * set a border around the window. Another behaviour is to determine the child window's + * behaviour when the size of the sizer changes. You can use the constants of @wxDirection + * and @wxStretch. + * + * + * The border width. Use this when you used a border(@wxDirection) flag. + * + * + * + * + * An object with a @wxWindow as its prototype. + * An object which prototype is wxSizer. + * + * + * Option is used together with @wxBoxSizer. 0 means that the size of the control + * is not allowed to change in the main orientation of the sizer. 1 means that the + * size of the control may grow or shrink in the main orientation of the sizer + * + * + * This parameter is used to set a number of flags. One main behaviour of a flag is to + * set a border around the window. Another behaviour is to determine the child window's + * behaviour when the size of the sizer changes. You can use the constants of @wxDirection + * and @wxStretch. + * + * + * The border width. Use this when you used a border(@wxDirection) flag. + * + * + * + * + * The width of the spacer. + * + * + * The height of the spacer. + * + * + * Option is used together with @wxBoxSizer. 0 means that the size of the control + * is not allowed to change in the main orientation of the sizer. 1 means that the + * size of the control may grow or shrink in the main orientation of the sizer + * + * + * This parameter is used to set a number of flags. One main behaviour of a flag is to + * set a border around the window. Another behaviour is to determine the child window's + * behaviour when the size of the sizer changes. You can use the constants of @wxDirection + * and @wxStretch. + * + * + * The border width. Use this when you used a border(@wxDirection) flag. + * + * + * + * Adds a window, another sizer or a spacer to the sizer. + * + * + */ +JSBool Sizer::add(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxSizer *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + int option = 0; + int flag = 0; + int border = 0; + + if ( Window::HasPrototype(cx, argv[0]) ) + { + wxWindow *win = Window::GetPrivate(cx, argv[0], false); + switch(argc) + { + case 4: + if ( ! FromJS(cx, argv[3], border) ) + return JS_FALSE; + case 3: + if ( ! FromJS(cx, argv[2], flag) ) + return JS_FALSE; + case 2: + if ( ! FromJS(cx, argv[1], option) ) + return JS_FALSE; + } + p->Add(win, option, flag, border); + } + else if (HasPrototype(cx, argv[0]) ) + { + wxSizer *sizer = GetPrivate(cx, argv[0], false); + switch(argc) + { + case 4: + if ( ! FromJS(cx, argv[3], border) ) + return JS_FALSE; + case 3: + if ( ! FromJS(cx, argv[2], flag) ) + return JS_FALSE; + case 2: + if ( ! FromJS(cx, argv[1], option) ) + return JS_FALSE; + } + p->Add(sizer, option, flag, border); + + // Protect the sizer + JavaScriptClientData *data + = dynamic_cast(sizer->GetClientObject()); + if ( data != NULL ) + { + data->Protect(true); + data->SetOwner(false); + } + } + else + { + if ( argc < 2 ) + return JS_FALSE; + + switch(argc) + { + case 5: + if ( ! FromJS(cx, argv[3], border) ) + return JS_FALSE; + case 4: + if ( ! FromJS(cx, argv[2], flag) ) + return JS_FALSE; + case 3: + if ( ! FromJS(cx, argv[1], option) ) + return JS_FALSE; + } + + int height; + if ( ! FromJS(cx, argv[1], height) ) + return JS_FALSE; + + int width; + if ( ! FromJS(cx, argv[0], width) ) + return JS_FALSE; + + p->Add(width, height, option, flag, border); + } + + return JS_TRUE; +} + +/*** + * + * + * + * Call this to force layout of the children. + * + * + */ +JSBool Sizer::layout(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxSizer *p = (wxSizer *) GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + p->Layout(); + + return JS_TRUE; +} + +/*** + * + * + * + * An object with a @wxWindow as its prototype. + * + * + * Option is used together with @wxBoxSizer. 0 means that the size of the control + * is not allowed to change in the main orientation of the sizer. 1 means that the + * size of the control may grow or shrink in the main orientation of the sizer + * + * + * This parameter is used to set a number of flags. One main behaviour of a flag is to + * set a border around the window. Another behaviour is to determine the child window's + * behaviour when the size of the sizer changes. You can use the constants of @wxDirection + * and @wxStretch. + * + * + * The border width. Use this when you used a border(@wxDirection) flag. + * + * + * + * + * An object with a @wxWindow as its prototype. + * An object which prototype is wxSizer. + * + * + * Option is used together with @wxBoxSizer. 0 means that the size of the control + * is not allowed to change in the main orientation of the sizer. 1 means that the + * size of the control may grow or shrink in the main orientation of the sizer + * + * + * This parameter is used to set a number of flags. One main behaviour of a flag is to + * set a border around the window. Another behaviour is to determine the child window's + * behaviour when the size of the sizer changes. You can use the constants of @wxDirection + * and @wxStretch. + * + * + * The border width. Use this when you used a border(@wxDirection) flag. + * + * + * + * + * The width of the spacer. + * + * + * The height of the spacer. + * + * + * Option is used together with @wxBoxSizer. 0 means that the size of the control + * is not allowed to change in the main orientation of the sizer. 1 means that the + * size of the control may grow or shrink in the main orientation of the sizer + * + * + * This parameter is used to set a number of flags. One main behaviour of a flag is to + * set a border around the window. Another behaviour is to determine the child window's + * behaviour when the size of the sizer changes. You can use the constants of @wxDirection + * and @wxStretch. + * + * + * The border width. Use this when you used a border(@wxDirection) flag. + * + * + * + * Prepends a window, another sizer or a spacer to the beginning of the list of items + * owned by this sizer. See @wxSizer#add. + * + * + */ +JSBool Sizer::prepend(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxSizer *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + int option = 0; + int flag = 0; + int border = 0; + + if ( Window::HasPrototype(cx, argv[0]) ) + { + wxWindow *win = Window::GetPrivate(cx, argv[0], false); + switch(argc) + { + case 4: + if ( ! FromJS(cx, argv[3], border) ) + return JS_FALSE; + case 3: + if ( ! FromJS(cx, argv[2], flag) ) + return JS_FALSE; + case 2: + if ( ! FromJS(cx, argv[1], option) ) + return JS_FALSE; + } + p->Prepend(win, option, flag, border); + } + else if (HasPrototype(cx, argv[0]) ) + { + wxSizer *sizer = GetPrivate(cx, argv[0], false); + switch(argc) + { + case 4: + if ( ! FromJS(cx, argv[3], border) ) + return JS_FALSE; + case 3: + if ( ! FromJS(cx, argv[2], flag) ) + return JS_FALSE; + case 2: + if ( ! FromJS(cx, argv[1], option) ) + return JS_FALSE; + } + p->Prepend(sizer, option, flag, border); + } + else + { + if ( argc < 2 ) + return JS_FALSE; + + switch(argc) + { + case 5: + if ( ! FromJS(cx, argv[3], border) ) + return JS_FALSE; + case 4: + if ( ! FromJS(cx, argv[2], flag) ) + return JS_FALSE; + case 3: + if ( ! FromJS(cx, argv[1], option) ) + return JS_FALSE; + } + + int height; + if ( ! FromJS(cx, argv[1], height) ) + return JS_FALSE; + + int width; + if ( ! FromJS(cx, argv[0], width) ) + return JS_FALSE; + + p->Prepend(width, height, option, flag, border); + } + + return JS_TRUE; +} + +/*** + * + * + * + * The index of the item to remove from the sizer. + * + * + * + * + * Window to remove from the sizer. + * + * + * + * + * Sizer to remove from this sizer. + * + * + * + * Removes the item from the sizer. Call @wxSizer#layout to update the screen. + * + * + */ +JSBool Sizer::remove(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxSizer *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + if ( Window::HasPrototype(cx, argv[0]) ) + { + wxWindow *win = Window::GetPrivate(cx, argv[0], false); + p->Remove(win); + } + else if ( HasPrototype(cx, argv[0]) ) + { + wxSizer *sizer = GetPrivate(cx, argv[0], false); + p->Remove(sizer); + } + else + { + int idx; + if ( ! FromJS(cx, argv[0], idx) ) + return JS_FALSE; + p->Remove(idx); + } + + return JS_TRUE; +} + +/*** + * + * + * + * + * + * + * + * + * Call this to force the sizer to take the given dimension and thus force the items + * owned by the sizer to resize themselves according to the rules defined by the parameters + * in the @wxSizer#add and @wxSizer#prepend methods. + * + * + */ +JSBool Sizer::setDimension(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxSizer *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + int x; + int y; + int width; + int height; + + if ( FromJS(cx, argv[0], x) + && FromJS(cx, argv[1], y) + && FromJS(cx, argv[2], width) + && FromJS(cx, argv[3], height) ) + { + p->SetDimension(x, y, width, height); + return JS_TRUE; + } + + return JS_FALSE; +} + +/*** + * + * + * + * + * + * + * Sets the minimal size of the sizer. + * See @wxSizer#minSize. + * + * + */ +JSBool Sizer::setMinSize(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxSizer *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + int width; + int height; + + if ( FromJS(cx, argv[0], width) + && FromJS(cx, argv[1], height) ) + { + p->SetMinSize(width, height); + return JS_TRUE; + } + return JS_FALSE; +} + +/*** + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * Sets an item minimal size. + * + * + */ +JSBool Sizer::setItemMinSize(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxSizer *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + int width = 0; + int height = 0; + + if ( FromJS(cx, argv[1], width) + && FromJS(cx, argv[2], height) ) + { + if ( Window::HasPrototype(cx, argv[0]) ) + { + p->SetItemMinSize(Window::GetPrivate(cx, argv[0], false), width, height); + } + else if ( HasPrototype(cx, argv[1]) ) + { + p->SetItemMinSize(GetPrivate(cx, argv[0], false), width, height); + } + else + { + int idx; + if ( FromJS(cx, argv[0], idx) ) + p->SetItemMinSize(idx, width, height); + else + return JS_FALSE; + } + } + else + return JS_FALSE; + + return JS_TRUE; +} Property changes on: ps/trunk/source/tools/atlas/wxJS/gui/misc/sizer.cpp ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/gui/misc/acctable.h =================================================================== --- ps/trunk/source/tools/atlas/wxJS/gui/misc/acctable.h (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/gui/misc/acctable.h (revision 5154) @@ -0,0 +1,66 @@ +/* + * wxJavaScript - acctable.h + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: acctable.h 598 2007-03-07 20:13:28Z fbraem $ + */ +#ifndef _WXJSAcceleratorTable_H +#define _WXJSAcceleratorTable_H + +///////////////////////////////////////////////////////////////////////////// +// Name: acctable.h +// Purpose: AcceleratorTable ports wxAcceleratorTable to JavaScript. +// Author: Franky Braem +// Modified by: +// Created: 06.06.02 +// Copyright: (c) 2001-2002 Franky Braem +// Licence: LGPL +///////////////////////////////////////////////////////////////////////////// + +namespace wxjs +{ + namespace gui + { + class AcceleratorTable : public ApiWrapper + { + public: + + static bool GetProperty(wxAcceleratorTable *p, JSContext *cx, JSObject *obj, int id, jsval *vp); + + /** + * Callback for when a wxAcceleratorTable object is created + */ + static wxAcceleratorTable* Construct(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, bool constructing); + + WXJS_DECLARE_PROPERTY_MAP() + + /** + * Property Ids. + */ + enum + { + P_OK + }; + }; + }; // namespace gui +}; // namespace wxjs + +#endif //_WXJSAcceleratorTable_H Property changes on: ps/trunk/source/tools/atlas/wxJS/gui/misc/acctable.h ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/gui/misc/colour.h =================================================================== --- ps/trunk/source/tools/atlas/wxJS/gui/misc/colour.h (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/gui/misc/colour.h (revision 5154) @@ -0,0 +1,70 @@ +/* + * wxJavaScript - colour.h + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: colour.h 598 2007-03-07 20:13:28Z fbraem $ + */ +#ifndef _WXJSColour_H +#define _WXJSColour_H + +///////////////////////////////////////////////////////////////////////////// +// Name: colour.h +// Purpose: Ports wxColour to JavaScript +// Author: Franky Braem +// Modified by: +// Created: 04.07.02 +// Copyright: (c) 2001-2002 Franky Braem +// Licence: LGPL +///////////////////////////////////////////////////////////////////////////// + + +namespace wxjs +{ + namespace gui + { + class Colour : public ApiWrapper + { + public: + + static bool GetProperty(wxColour *p, JSContext *cx, JSObject *obj, int id, jsval *vp); + static wxColour *Construct(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, bool constructing); + + enum + { + P_RED + , P_GREEN + , P_BLUE + , P_OK + }; + + WXJS_DECLARE_PROPERTY_MAP() + WXJS_DECLARE_METHOD_MAP() + + static JSBool set(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval); + }; + + void DefineGlobalColours(JSContext *cx, JSObject *obj); + void DefineGlobalColour(JSContext *cx, JSObject *obj, + const char *name, const wxColour *colour); + }; // namespace gui +}; // namespace wxjs + +#endif //_WXJSColour_H Property changes on: ps/trunk/source/tools/atlas/wxJS/gui/misc/colour.h ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/gui/event/key.h =================================================================== --- ps/trunk/source/tools/atlas/wxJS/gui/event/key.h (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/gui/event/key.h (revision 5154) @@ -0,0 +1,69 @@ +/* + * wxJavaScript - key.h + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: key.h 598 2007-03-07 20:13:28Z fbraem $ + */ +#ifndef _WXJSKeyEvent_H +#define _WXJSKeyEvent_H + +///////////////////////////////////////////////////////////////////////////// +// Name: key.h +// Purpose: Ports wxKeyEvent to JavaScript +// Author: Franky Braem +// Modified by: +// Created: 25.12.01 +// Copyright: (c) 2001-2002 Franky Braem +// Licence: LGPL +///////////////////////////////////////////////////////////////////////////// + +namespace wxjs +{ + namespace gui + { + typedef JSEvent PrivKeyEvent; + + class KeyEvent : public ApiWrapper + { + public: + static bool GetProperty(PrivKeyEvent *p, JSContext *cx, JSObject *obj, int id, jsval *vp); + + virtual ~KeyEvent() + { + } + + enum + { + P_ALT_DOWN + , P_CONTROL_DOWN + , P_KEY_CODE + , P_META_DOWN + , P_SHIFT_DOWN + , P_X + , P_Y + , P_HAS_MODIFIERS + }; + + WXJS_DECLARE_PROPERTY_MAP() + }; + }; // namespace gui +}; // namespace wxjs +#endif //_WXJSKeyEvent_H Property changes on: ps/trunk/source/tools/atlas/wxJS/gui/event/key.h ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/gui/gui_main.cpp =================================================================== --- ps/trunk/source/tools/atlas/wxJS/gui/gui_main.cpp (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/gui/gui_main.cpp (revision 5154) @@ -0,0 +1,91 @@ +#include "precompiled.h" + +/* + * wxJavaScript - main.cpp + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id$ + */ +// main.cpp +#include + +#ifndef WX_PRECOMP + #include +#endif +#include + +#ifdef __WXMSW__ + #include +#endif + +#include +#include "../common/wxjs.h" +#include "../common/main.h" + +#include "init.h" + +#if defined( __WXMSW__) + void WXDLLEXPORT wxEntryCleanup(); + extern "C" + { + WXJSAPI BOOL APIENTRY DllMain(HINSTANCE, DWORD, LPVOID); + } + + WXJSAPI BOOL APIENTRY DllMain(HINSTANCE hinstDLL, + DWORD fdwReason, + LPVOID WXUNUSED(lpvReserved)) + { + BOOL result = TRUE; + + switch(fdwReason) + { + case DLL_PROCESS_ATTACH: + { + wxSetInstance(hinstDLL); + DisableThreadLibraryCalls(hinstDLL); + int app_argc = 0; + char **app_argv = NULL; + wxEntryStart(app_argc, app_argv); + break; + } + case DLL_PROCESS_DETACH: + wxEntryCleanup(); + break; + } + + return result; + } +#endif + +WXJSAPI bool wxJS_InitClass(JSContext *cx, JSObject *global) +{ + return wxjs::gui::InitClass(cx, global); +} + +WXJSAPI bool wxJS_InitObject(JSContext *cx, JSObject *obj) +{ + return wxjs::gui::InitObject(cx, obj); +} + +WXJSAPI void wxJS_Destroy() +{ + wxjs::gui::Destroy(); +} Property changes on: ps/trunk/source/tools/atlas/wxJS/gui/gui_main.cpp ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/gui/misc/colourdb.cpp =================================================================== --- ps/trunk/source/tools/atlas/wxJS/gui/misc/colourdb.cpp (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/gui/misc/colourdb.cpp (revision 5154) @@ -0,0 +1,110 @@ +#include "precompiled.h" + +/* + * wxJavaScript - colourdb.cpp + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: colourdb.cpp 598 2007-03-07 20:13:28Z fbraem $ + */ +// colourdb.cpp + +#ifndef WX_PRECOMP + #include "wx/wx.h" +#endif + +#include "../../common/main.h" + +#include "colourdb.h" +#include "colour.h" + +using namespace wxjs; +using namespace wxjs::gui; + +/*** + * file/colourdb + * gui + * + * wxWindows maintains a database of standard RGB colours for a predefined set + * of named colours (such as "BLACK", "LIGHT GREY"). wxColourDatabase is a singleton + * and is instantiated when the application starts: wxTheColourDatabase. + * An example: + * + * var colour = wxTheColourDatabase.findColour("RED"); + * + */ +WXJS_INIT_CLASS(ColourDatabase, "wxColourDatabase", 0) + +WXJS_BEGIN_METHOD_MAP(ColourDatabase) + WXJS_METHOD("find", find, 1) + WXJS_METHOD("findName", findName, 1) +WXJS_END_METHOD_MAP() + +/*** + * + * + * The name of a colour. + * + * + * Returns the colour with the given name. undefined is returned + * when the colour does not exist. + * + * + */ +JSBool ColourDatabase::find(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxColourDatabase *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + wxString name; + FromJS(cx, argv[0], name); + + // Create a copy of the colour, because the colour pointer is owned by wxWindows. + *rval = Colour::CreateObject(cx, new wxColour(p->Find(name))); + + return JS_TRUE; +} + +/*** + * + * + * + * + * + * Returns the name of the colour. undefined is returned when the colour has no name. + * + * + */ +JSBool ColourDatabase::findName(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxColourDatabase *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + wxColour *colour = Colour::GetPrivate(cx, argv[0]); + if ( colour == NULL ) + return JS_FALSE; + + wxString name = p->FindName(*colour); + *rval = ( name.Length() == 0 ) ? JSVAL_VOID : ToJS(cx, name); + + return JS_TRUE; +} Property changes on: ps/trunk/source/tools/atlas/wxJS/gui/misc/colourdb.cpp ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/gui/misc/bitmap.cpp =================================================================== --- ps/trunk/source/tools/atlas/wxJS/gui/misc/bitmap.cpp (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/gui/misc/bitmap.cpp (revision 5154) @@ -0,0 +1,233 @@ +#include "precompiled.h" + +/* + * wxJavaScript - bitmap.cpp + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: bitmap.cpp 598 2007-03-07 20:13:28Z fbraem $ + */ +// bitmap.cpp + +#ifndef WX_PRECOMP + #include +#endif + +#include "../../common/main.h" +#include "bitmap.h" + +using namespace wxjs; +using namespace wxjs::gui; + +/*** + * misc/bitmap + * gui + * + * This class encapsulates the concept of a platform-dependent bitmap, either monochrome or colour. + * See @wxIcon and @wxBitmapType + * + */ +WXJS_INIT_CLASS(Bitmap, "wxBitmap", 0) + +/*** + * + * + * Get/Set the colour depth of the bitmap. A value of 1 indicates a monochrome bitmap. + * + * + * Get/Set the height of the bitmap in pixels. + * + * + * Returns true when the bitmap data is available. + * + * + * Get/Set the width of the bitmap in pixels. + * + * + */ +WXJS_BEGIN_PROPERTY_MAP(Bitmap) + WXJS_PROPERTY(P_DEPTH, "depth") + WXJS_PROPERTY(P_HEIGHT, "height") + WXJS_READONLY_PROPERTY(P_OK, "ok") + WXJS_PROPERTY(P_WIDTH, "width") +WXJS_END_PROPERTY_MAP() + +WXJS_BEGIN_METHOD_MAP(Bitmap) + WXJS_METHOD("create", create, 2) + WXJS_METHOD("loadFile", loadFile, 2) +WXJS_END_METHOD_MAP() + +bool Bitmap::GetProperty(wxBitmap *p, JSContext *cx, JSObject *obj, int id, jsval *vp) +{ + switch(id) + { + case P_DEPTH: + *vp = ToJS(cx, p->GetDepth()); + break; + case P_HEIGHT: + *vp = ToJS(cx, p->GetHeight()); + break; + case P_WIDTH: + *vp = ToJS(cx, p->GetWidth()); + break; + case P_OK: + *vp = ToJS(cx, p->Ok()); + break; + } + return true; +} + +bool Bitmap::SetProperty(wxBitmap *p, JSContext *cx, JSObject *obj, int id, jsval *vp) +{ + switch (id) + { + case P_DEPTH: + { + int value; + if ( FromJS(cx, *vp, value) ) + p->SetDepth(value); + break; + } + case P_HEIGHT: + { + int value; + if ( FromJS(cx, *vp, value) ) + p->SetHeight(value); + break; + } + case P_WIDTH: + { + int value; + if ( FromJS(cx, *vp, value) ) + p->SetWidth(value); + break; + } + } + return true; +} + +/*** + * + * + * + * Filename + * The type of the bitmap. + * + * + * Constructs a new wxBitmap object. + * See @wxBitmapType + * + * + */ +wxBitmap* Bitmap::Construct(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, bool constructing) +{ + if ( argc > 2 ) + argc = 2; + + switch(argc) + { + case 0: + return new wxBitmap(); + case 2: + { + wxString name; + int type; + FromJS(cx, argv[0], name); + if ( FromJS(cx, argv[1], type) ) + return new wxBitmap(name, (wxBitmapType) type); + } + } + return NULL; +} + +/*** + * + * + * + * The width of the bitmap in pixels. + * + * + * The height of the bitmap in pixels. + * + * + * The depth of the bitmap in pixels. When omitted (or a value -1) , the screen depth is used. + * + * + * + * Creates a fresh bitmap. + * + * + */ +JSBool Bitmap::create(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxBitmap *p = GetPrivate(cx, obj); + + int width = 0; + int height = 0; + int depth = -1; + + if ( FromJS(cx, argv[0], width) + && FromJS(cx, argv[1], height) ) + { + if ( argc > 2 ) + { + if ( ! FromJS(cx, argv[2], depth) ) + { + return JS_FALSE; + } + } + + *rval = ToJS(cx, p->Create(width, height, depth)); + return JS_TRUE; + } + + return JS_FALSE; +} + +/*** + * + * + * + * The name of the file. + * + * + * The type of the bitmap. + * + * + * + * Loads a bitmap from a file. + * + * + */ +JSBool Bitmap::loadFile(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxBitmap *p = GetPrivate(cx, obj); + + wxString name; + int type; + FromJS(cx, argv[0], name); + if ( FromJS(cx, argv[1], type) ) + { + *rval = ToJS(cx, p->LoadFile(name, (wxBitmapType) type)); + return JS_TRUE; + } + + return JS_FALSE; +} Property changes on: ps/trunk/source/tools/atlas/wxJS/gui/misc/bitmap.cpp ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/gui/misc/icon.cpp =================================================================== --- ps/trunk/source/tools/atlas/wxJS/gui/misc/icon.cpp (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/gui/misc/icon.cpp (revision 5154) @@ -0,0 +1,144 @@ +#include "precompiled.h" + +/* + * wxJavaScript - icon.cpp + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: icon.cpp 598 2007-03-07 20:13:28Z fbraem $ + */ +// icon.cpp + +#ifndef WX_PRECOMP + #include +#endif + +#include "../../common/main.h" + +#include "icon.h" +using namespace wxjs; +using namespace wxjs::gui; + +/*** + * misc/icon + * gui + * + * An icon is a small rectangular bitmap usually used for denoting a minimized application. + * It differs from a wxBitmap in always having a mask associated with it for transparent drawing. + * On some platforms, icons and bitmaps are implemented identically, + * since there is no real distinction between a wxBitmap with a mask and an icon; + * and there is no specific icon format on some platforms + * (X-based applications usually standardize on XPMs for small bitmaps and icons). + * However, some platforms (such as Windows) make the distinction, so a separate class is provided. + * See @wxBitmap, wxFrame @wxFrame#icon property and @wxBitmapType + * + */ +WXJS_INIT_CLASS(Icon, "wxIcon", 0) + +WXJS_BEGIN_METHOD_MAP(Icon) + WXJS_METHOD("loadFile", loadFile, 2) +WXJS_END_METHOD_MAP() + +/*** + * + * + * + * + * Filename + * + * + * The type of the Icon. Use the bitmap types. + * + * + * + * + * + * Constructs a new wxIcon object. The first constructor creates + * an icon without data. Use @wxIcon#loadFile to load an icon. + * + * + */ +wxIcon* Icon::Construct(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, bool constructing) +{ + if ( argc == 0 ) + return new wxIcon(); + + if ( JSVAL_IS_STRING(argv[0]) ) + { + if ( argc > 4 ) + argc = 4; + + int desiredWidth = -1; + int desiredHeight = -1; + + switch(argc) + { + case 4: + if ( ! FromJS(cx, argv[3], desiredHeight) ) + return NULL; + // Fall through + case 3: + if ( ! FromJS(cx, argv[2], desiredWidth) ) + return NULL; + // Fall through + default: + wxString name; + int type; + + if ( FromJS(cx, argv[1], type) ) + { + FromJS(cx, argv[0], name); + return new wxIcon(name, (wxBitmapType) type, desiredWidth, desiredHeight); + } + } + } + + return NULL; +} + +/*** + * + * + * + * The name of the file. + * + * + * The type of the Icon. + * + * + * + * Loads an icon from a file. + * + * + */ +JSBool Icon::loadFile(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxIcon *p = GetPrivate(cx, obj); + + wxString name; + int type; + FromJS(cx, argv[0], name); + if ( FromJS(cx, argv[1], type) ) + { + *rval = ToJS(cx, p->LoadFile(name, (wxBitmapType) type)); + return JS_TRUE; + } + return JS_FALSE; +} Property changes on: ps/trunk/source/tools/atlas/wxJS/gui/misc/icon.cpp ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/gui/misc/textval.h =================================================================== --- ps/trunk/source/tools/atlas/wxJS/gui/misc/textval.h (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/gui/misc/textval.h (revision 5154) @@ -0,0 +1,90 @@ +/* + * wxJavaScript - textval.h + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: textval.h 738 2007-06-08 18:47:56Z fbraem $ + */ +#ifndef _WXJSTextValidator_H +#define _WXJSTextValidator_H + +namespace wxjs +{ + namespace gui + { + class TextValidator : public wxTextValidator + , public ApiWrapper + { + public: + + TextValidator(long style = wxFILTER_NONE, + const wxString &value = wxEmptyString); + TextValidator(const TextValidator ©); + virtual wxObject* Clone() const; + + virtual ~TextValidator() {} + + /** + * Callback for retrieving properties of wxTextValidator + */ + static bool GetProperty(wxTextValidator *p, + JSContext *cx, + JSObject *obj, + int id, + jsval *vp); + + /** + * Callback for setting properties + */ + static bool SetProperty(wxTextValidator *p, + JSContext *cx, + JSObject *obj, + int id, + jsval *vp); + + /** + * Callback for when a wxTextValidator object is created + */ + static wxTextValidator* Construct(JSContext *cx, + JSObject *obj, + uintN argc, + jsval *argv, + bool constructing); + + WXJS_DECLARE_PROPERTY_MAP() + + /** + * Property Ids. + */ + enum + { + P_EXCLUDE_LIST + , P_INCLUDE_LIST + , P_STYLE + , P_VALUE + }; + + private: + wxString m_value; + }; + }; // namespace gui +}; // namespace wxjs + +#endif //_WXJSTextValidator_H Property changes on: ps/trunk/source/tools/atlas/wxJS/gui/misc/textval.h ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/gui/misc/globfun.h =================================================================== --- ps/trunk/source/tools/atlas/wxJS/gui/misc/globfun.h (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/gui/misc/globfun.h (revision 5154) @@ -0,0 +1,54 @@ +/* + * wxJavaScript - globfun.h + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: globfun.h 598 2007-03-07 20:13:28Z fbraem $ + */ +/** + * (c) 2001-2002 Franky Braem (S.A.W.) + * + * This file is part of wxJS. wxJS ports wxWindows to JavaScript + * + * File : wxJSGlobFun.h + * Desc. : This file defines all the global functions. + * Created : 24-05-2001 + * L. Update : + * + */ + +namespace wxjs +{ + namespace gui + { + /** + * Initializes the global functions + */ + bool InitFunctions(JSContext *cx, JSObject *global); + + /** + * Implements wxMessageBox + */ + JSBool MessageBox(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval); + JSBool InitAllImageHandlers(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval); + + void DefineGlobals(JSContext *cx, JSObject *global); + }; // namespace gui +}; // namespace wxjs Property changes on: ps/trunk/source/tools/atlas/wxJS/gui/misc/globfun.h ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/gui/misc/stsizer.h =================================================================== --- ps/trunk/source/tools/atlas/wxJS/gui/misc/stsizer.h (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/gui/misc/stsizer.h (revision 5154) @@ -0,0 +1,67 @@ +/* + * wxJavaScript - stsizer.h + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: stsizer.h 715 2007-05-18 20:38:04Z fbraem $ + */ +/** + * (c) 2001-2002 Franky Braem (S.A.W.) + * + * This file is part of wxJS. wxJS ports wxWindows to JavaScript + * + */ + +#ifndef _wxJSStaticBoxSizer_H +#define _wxJSStaticBoxSizer_H + +namespace wxjs +{ + class Object; + + namespace gui + { + class StaticBoxSizer : public ApiWrapper + { + public: + static wxStaticBoxSizer* Construct(JSContext *cx, + JSObject *obj, + uintN argc, + jsval *argv, + bool constructing); + + static bool GetProperty(wxStaticBoxSizer *p, + JSContext *cx, + JSObject *obj, + int id, + jsval *vp); + + WXJS_DECLARE_PROPERTY_MAP() + + enum + { + P_STATIC_BOX + }; + }; + }; // namespace gui +}; // namespace wxjs + +#endif //_wxJSStaticBoxSizer_H + Property changes on: ps/trunk/source/tools/atlas/wxJS/gui/misc/stsizer.h ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/gui/misc/cshelp.h =================================================================== --- ps/trunk/source/tools/atlas/wxJS/gui/misc/cshelp.h (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/gui/misc/cshelp.h (revision 5154) @@ -0,0 +1,58 @@ +/* + * wxJavaScript - cshelp.h + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: cshelp.h 598 2007-03-07 20:13:28Z fbraem $ + */ +#ifndef _WXJSContextHelp_H +#define _WXJSContextHelp_H + +///////////////////////////////////////////////////////////////////////////// +// Name: cshelp.h +// Purpose: ContextHelp ports wxContextHelp to JavaScript +// Author: Franky Braem +// Modified by: +// Created: 27.09.2002 +// Copyright: (c) 2001-2002 Franky Braem +// Licence: LGPL +///////////////////////////////////////////////////////////////////////////// +#include + +namespace wxjs +{ + namespace gui + { + class ContextHelp : public ApiWrapper + { + public: + /** + * Callback for when a wxContextHelp object is created + */ + static wxContextHelp* Construct(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, bool constructing); + + WXJS_DECLARE_METHOD_MAP() + static JSBool beginContextHelp(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval); + static JSBool endContextHelp(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval); + }; + }; // namespace gui +}; // namespace wxjs +#endif //_WXJSContextHelp_H + Property changes on: ps/trunk/source/tools/atlas/wxJS/gui/misc/cshelp.h ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/gui/misc/sizer.h =================================================================== --- ps/trunk/source/tools/atlas/wxJS/gui/misc/sizer.h (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/gui/misc/sizer.h (revision 5154) @@ -0,0 +1,68 @@ +/* + * wxJavaScript - sizer.h + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: sizer.h 733 2007-06-05 21:17:25Z fbraem $ + */ +#ifndef _WXJSSIZER_H +#define _WXJSSIZER_H + +namespace wxjs +{ + namespace gui + { + class Sizer : public ApiWrapper + { + public: + /** + * Callback for retrieving properties. + * @param vp Contains the value of the property. + */ + static bool GetProperty(wxSizer *p, JSContext *cx, JSObject *obj, int id, jsval *vp); + + /** + * Callback for setting properties + * @param vp Contains the new value of the property. + */ + static bool SetProperty(wxSizer *p, JSContext *cx, JSObject *obj, int id, jsval *vp); + + static JSBool add(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval); + static JSBool layout(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval); + static JSBool prepend(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval); + static JSBool remove(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval); + static JSBool setDimension(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval); + static JSBool setMinSize(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval); + static JSBool setItemMinSize(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval); + + WXJS_DECLARE_PROPERTY_MAP() + WXJS_DECLARE_METHOD_MAP() + + enum + { + P_MIN_SIZE + , P_POSITION + , P_SIZE + }; + }; + }; // namespace gui +}; // namespace wxjs + +#endif //_WXJSSIZER_H Property changes on: ps/trunk/source/tools/atlas/wxJS/gui/misc/sizer.h ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/gui/misc/colour.cpp =================================================================== --- ps/trunk/source/tools/atlas/wxJS/gui/misc/colour.cpp (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/gui/misc/colour.cpp (revision 5154) @@ -0,0 +1,203 @@ +#include "precompiled.h" + +/* + * wxJavaScript - colour.cpp + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: colour.cpp 598 2007-03-07 20:13:28Z fbraem $ + */ +// colour.cpp + +#ifndef WX_PRECOMP + #include +#endif + +#include "../../common/main.h" + +#include "colour.h" + +using namespace wxjs; +using namespace wxjs::gui; + +/*** + * misc/colour + * gui + * + * A colour is an object representing a combination of Red, Green, and Blue (RGB) intensity values. + * This is a list of predefined colour objects: + * wxBLACK, wxWHITE, wxRED, wxBLUE, wxGREEN, wxCYAN and wxLIGHT_GREY + * + * + * + * Gets the Blue value + * + * + * Gets the Green value + * + * + * Returns true when the colour is valid + * + * + * Gets the Red value + * + * + */ +WXJS_INIT_CLASS(Colour, "wxColour", 1) + +WXJS_BEGIN_PROPERTY_MAP(Colour) + WXJS_READONLY_PROPERTY(P_BLUE, "blue") + WXJS_READONLY_PROPERTY(P_GREEN, "green") + WXJS_READONLY_PROPERTY(P_RED, "red") + WXJS_READONLY_PROPERTY(P_OK, "ok") +WXJS_END_PROPERTY_MAP() + +WXJS_BEGIN_METHOD_MAP(Colour) + WXJS_METHOD("set", set, 3) +WXJS_END_METHOD_MAP() + +bool Colour::GetProperty(wxColour *p, JSContext *cx, JSObject *obj, int id, jsval *vp) +{ + switch(id) + { + case P_BLUE: + *vp = ToJS(cx, p->Blue()); + break; + case P_GREEN: + *vp = ToJS(cx, p->Green()); + break; + case P_RED: + *vp = ToJS(cx, p->Red()); + break; + case P_OK: + *vp = ToJS(cx, p->Ok()); + break; + } + return true; +} + +/*** + * + * + * + * The red value + * + * + * The green value + * + * + * The blue value + * + * + * + * + * The name used to retrieve the colour from wxTheColourDatabase + * + * + * + * Constructs a new wxColour object. + * + * + */ +wxColour *Colour::Construct(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, bool constructing) +{ + if ( argc == 3 ) // RGB + { + int R; + int G; + int B; + if ( FromJS(cx, argv[0], R) + && FromJS(cx, argv[1], G) + && FromJS(cx, argv[2], B) ) + { + return new wxColour(R, G, B); + } + } + else if ( argc == 1 ) + { + wxString name; + FromJS(cx, argv[0], name); + return new wxColour(name); + } + return NULL; +} + +/*** + * + * + * + * The red value + * + * + * The green value + * + * + * The blue value + * + * + * + * Sets the RGB values. + * + * + */ +JSBool Colour::set(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxColour *p = GetPrivate(cx, obj); + wxASSERT_MSG(p != NULL, wxT("No private data associated with wxColour")); + + int R; + int G; + int B; + if ( FromJS(cx, argv[0], R) + && FromJS(cx, argv[1], G) + && FromJS(cx, argv[2], B) ) + { + p->Set((unsigned char) R, + (unsigned char) G, + (unsigned char) B); + } + else + { + return JS_FALSE; + } + + return JS_TRUE; +} + +void wxjs::gui::DefineGlobalColours(JSContext *cx, JSObject *obj) +{ + DefineGlobalColour(cx, obj, "wxRED", wxRED); + DefineGlobalColour(cx, obj, "wxBLACK", wxBLACK); + DefineGlobalColour(cx, obj, "wxWHITE", wxWHITE); + DefineGlobalColour(cx, obj, "wxRED", wxRED); + DefineGlobalColour(cx, obj, "wxBLUE", wxBLUE); + DefineGlobalColour(cx, obj, "wxGREEN", wxGREEN); + DefineGlobalColour(cx, obj, "wxCYAN", wxCYAN); + DefineGlobalColour(cx, obj, "wxLIGHT_GREY", wxLIGHT_GREY); +} + +void wxjs::gui::DefineGlobalColour(JSContext *cx, JSObject *obj, + const char*name, const wxColour *colour) +{ + wxASSERT_MSG(colour != NULL, wxT("wxColour can't be NULL")); + // Create a new colour object, because wxWindows destroys the global + // colour objects and wxJSColour does the same. + Colour::DefineObject(cx, obj, name, new wxColour(*colour)); +} Property changes on: ps/trunk/source/tools/atlas/wxJS/gui/misc/colour.cpp ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/gui/misc/accentry.cpp =================================================================== --- ps/trunk/source/tools/atlas/wxJS/gui/misc/accentry.cpp (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/gui/misc/accentry.cpp (revision 5154) @@ -0,0 +1,241 @@ +#include "precompiled.h" + +/* + * wxJavaScript - accentry.cpp + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: accentry.cpp 598 2007-03-07 20:13:28Z fbraem $ + */ +// accentry.cpp + +#ifndef WX_PRECOMP + #include +#endif + +#include "../../common/main.h" + +#include "accentry.h" + +using namespace wxjs; +using namespace wxjs::gui; + +/*** + * misc/accentry + * gui + * + * An object used by an application wishing to create an accelerator table. + * See @wxAcceleratorTable, wxMenuItem @wxMenuItem#accel property. + * + */ +WXJS_INIT_CLASS(AcceleratorEntry, "wxAcceleratorEntry", 0) + +/*** + * + * See @wxAcceleratorEntry#flag + * + * See @wxKeyCode + * + * + * The menu or control command identifier. + * + * + */ +WXJS_BEGIN_PROPERTY_MAP(AcceleratorEntry) + WXJS_PROPERTY(P_FLAG, "flags") + WXJS_PROPERTY(P_KEYCODE, "keyCode") + WXJS_PROPERTY(P_COMMAND, "command") +WXJS_END_PROPERTY_MAP() + +/*** + * + * + * + * + * + * + * + * + */ +WXJS_BEGIN_CONSTANT_MAP(AcceleratorEntry) + WXJS_CONSTANT(wxACCEL_, NORMAL) + WXJS_CONSTANT(wxACCEL_, ALT) + WXJS_CONSTANT(wxACCEL_, CTRL) + WXJS_CONSTANT(wxACCEL_, SHIFT) +WXJS_END_CONSTANT_MAP() + +bool AcceleratorEntry::GetProperty(wxAcceleratorEntry *p, JSContext *cx, JSObject *obj, int id, jsval *vp) +{ + switch (id) + { + case P_FLAG: + *vp = ToJS(cx, p->GetFlags()); + break; + case P_KEYCODE: + *vp = ToJS(cx, p->GetKeyCode()); + break; + case P_COMMAND: + *vp = ToJS(cx, p->GetCommand()); + break; + } + return true; +} + +bool AcceleratorEntry::SetProperty(wxAcceleratorEntry *p, JSContext *cx, JSObject *obj, int id, jsval *vp) +{ + switch(id) + { + case P_FLAG: + { + int flag; + if ( FromJS(cx, *vp, flag) ) + p->Set(flag, p->GetKeyCode(), p->GetCommand()); + break; + } + case P_KEYCODE: + { + int keycode; + if ( FromJS(cx, *vp, keycode) ) + p->Set(p->GetFlags(), keycode, p->GetCommand()); + break; + } + case P_COMMAND: + { + int command; + if ( FromJS(cx, *vp, command) ) + p->Set(p->GetFlags(), p->GetKeyCode(), command); + break; + } + } + return true; +} + +/*** + * + * + * + * + * Indicates which modifier key is pressed. See @wxAcceleratorEntry#constants + * for the possible values. + * + * + * The keycode. See @wxKeyCode + * + * + * The menu or command id. + * + * + * + * Constructs a new wxAcceleratorEntry object. + * + * + */ +wxAcceleratorEntry* AcceleratorEntry::Construct(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, bool constructing) +{ + int flag = 0; + int key = 0; + int id = 0; + + if ( argc == 0 ) + return new wxAcceleratorEntry(); + + if ( argc > 3 ) + argc = 3; + + switch(argc) + { + case 3: + if ( ! FromJS(cx, argv[2], id) ) + break; + // Walk through + case 2: + if ( ! FromJS(cx, argv[1], key) ) + break; + // Walk through + case 1: + if ( ! FromJS(cx, argv[0], flag) ) + break; + // Walk through + default: + { + return new wxAcceleratorEntry(flag, key, id); + } + } + + return NULL; +} + +WXJS_BEGIN_METHOD_MAP(AcceleratorEntry) + WXJS_METHOD("set", set, 0) +WXJS_END_METHOD_MAP() + +/*** + * + * + * + * Indicates which modifier key is pressed. See @wxAcceleratorEntry#constants + * for the possible values. + * + * + * The keycode. See @wxKeyCode + * + * + * The menu or command id. + * + * + * + * See @wxAcceleratorEntry#ctor for the explanation of the arguments. + * + * + */ +JSBool AcceleratorEntry::set(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + if ( argc > 3 ) + argc = 3; + + wxAcceleratorEntry *p = GetPrivate(cx, obj); + + int flag = p->GetFlags(); + int key = p->GetKeyCode(); + int id = p->GetCommand(); + + switch(argc) + { + case 3: + if ( ! FromJS(cx, argv[2], id) ) + break; + // Walk through + case 2: + if ( ! FromJS(cx, argv[1], key) ) + break; + // Walk through + case 1: + if ( ! FromJS(cx, argv[0], flag) ) + break; + // Walk through + default: + { + p->Set(flag, key, id); + return JS_TRUE; + } + } + + return JS_FALSE; +} Property changes on: ps/trunk/source/tools/atlas/wxJS/gui/misc/accentry.cpp ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/gui/misc/jpghdlr.cpp =================================================================== --- ps/trunk/source/tools/atlas/wxJS/gui/misc/jpghdlr.cpp (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/gui/misc/jpghdlr.cpp (revision 5154) @@ -0,0 +1,52 @@ +#include "precompiled.h" + +/* + * wxJavaScript - jpghdlr.cpp + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: jpghdlr.cpp 598 2007-03-07 20:13:28Z fbraem $ + */ +#ifndef WX_PRECOMP + #include +#endif + +#include "../../common/main.h" +#include "../../common/type.h" +#include "../../common/jsutil.h" + +#include "imghand.h" + +using namespace wxjs; +using namespace wxjs::gui; + +/*** + * misc/jpghdlr + * gui + * + * Image handler for JPEG images. + * + */ +WXJS_INIT_CLASS(JPEGHandler, "wxJPEGHandler", 0) + +ImageHandlerPrivate* JPEGHandler::Construct(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, bool constructing) +{ + return new ImageHandlerPrivate(new wxJPEGHandler(), true); +}; Property changes on: ps/trunk/source/tools/atlas/wxJS/gui/misc/jpghdlr.cpp ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/gui/misc/bitmap.h =================================================================== --- ps/trunk/source/tools/atlas/wxJS/gui/misc/bitmap.h (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/gui/misc/bitmap.h (revision 5154) @@ -0,0 +1,68 @@ +/* + * wxJavaScript - bitmap.h + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: bitmap.h 598 2007-03-07 20:13:28Z fbraem $ + */ +#ifndef _WXJSBitmap_H +#define _WXJSBitmap_H + +///////////////////////////////////////////////////////////////////////////// +// Name: bitmap.h +// Purpose: Ports wxBitmap to JavaScript +// Author: Franky Braem +// Modified by: +// Created: 09.08.02 +// Copyright: (c) 2001-2002 Franky Braem +// Licence: LGPL +// Since: version 0.4 +///////////////////////////////////////////////////////////////////////////// + +namespace wxjs +{ + namespace gui + { + class Bitmap : public ApiWrapper + { + public: + + static bool GetProperty(wxBitmap *p, JSContext *cx, JSObject *obj, int id, jsval *vp); + static bool SetProperty(wxBitmap *p, JSContext *cx, JSObject *obj, int id, jsval *vp); + static wxBitmap *Construct(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, bool constructing); + + enum + { + P_DEPTH + , P_HEIGHT + , P_OK + , P_WIDTH + }; + + WXJS_DECLARE_PROPERTY_MAP() + WXJS_DECLARE_METHOD_MAP() + + static JSBool create(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval); + static JSBool loadFile(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval); + }; + }; // namespace gui +}; // namespace wxjs + +#endif //_WXJSBitmap_H Property changes on: ps/trunk/source/tools/atlas/wxJS/gui/misc/bitmap.h ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/gui/misc/icon.h =================================================================== --- ps/trunk/source/tools/atlas/wxJS/gui/misc/icon.h (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/gui/misc/icon.h (revision 5154) @@ -0,0 +1,58 @@ +/* + * wxJavaScript - icon.h + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: icon.h 598 2007-03-07 20:13:28Z fbraem $ + */ +#ifndef _WXJSIcon_H +#define _WXJSIcon_H + +///////////////////////////////////////////////////////////////////////////// +// Name: icon.h +// Purpose: Icon ports wxIcon to JavaScript +// Author: Franky Braem +// Modified by: +// Created: 09.08.02 +// Copyright: (c) 2001-2002 Franky Braem +// Licence: LGPL +///////////////////////////////////////////////////////////////////////////// + +namespace wxjs +{ + namespace gui + { + class Icon : public ApiWrapper + { + public: + + /** + * Callback for when a wxIcon object is created + */ + static wxIcon* Construct(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, bool constructing); + + static JSBool loadFile(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval); + + WXJS_DECLARE_METHOD_MAP() + }; + }; // namespace gui +}; // namespace wxjs + +#endif //_WXJSIcon_H Property changes on: ps/trunk/source/tools/atlas/wxJS/gui/misc/icon.h ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/gui/misc/stsizer.cpp =================================================================== --- ps/trunk/source/tools/atlas/wxJS/gui/misc/stsizer.cpp (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/gui/misc/stsizer.cpp (revision 5154) @@ -0,0 +1,128 @@ +#include "precompiled.h" + +/* + * wxJavaScript - stsizer.cpp + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: stsizer.cpp 733 2007-06-05 21:17:25Z fbraem $ + */ +// stsizer.cpp + +#ifndef WX_PRECOMP + #include +#endif + +#include "../../common/main.h" + +#include "../control/staticbx.h" +#include "sizer.h" +#include "stsizer.h" +using namespace wxjs; +using namespace wxjs::gui; + +/*** + * misc/stsizer + * gui + * + * wxStaticBoxSizer is a sizer derived from wxBoxSizer but adds + * a static box around the sizer. Note that this static box has to be created separately. + * See @wxBoxSizer, @wxSizer and @wxStaticBox + * + */ +WXJS_INIT_CLASS(StaticBoxSizer, "wxStaticBoxSizer", 2) + +/*** + * + * + * The associated static box. + * + * + */ + +WXJS_BEGIN_PROPERTY_MAP(StaticBoxSizer) + WXJS_READONLY_PROPERTY(P_STATIC_BOX, "staticBox") +WXJS_END_PROPERTY_MAP() + +bool StaticBoxSizer::GetProperty(wxStaticBoxSizer *p, + JSContext *cx, + JSObject *obj, + int id, + jsval *vp) +{ + if ( id == P_STATIC_BOX ) + { + wxStaticBox *staticBox = p->GetStaticBox(); + if ( staticBox != NULL ) + { + JavaScriptClientData *data + = dynamic_cast(staticBox->GetClientObject()); + *vp = data == NULL ? JSVAL_VOID + : OBJECT_TO_JSVAL(data->GetObject()); + } + } + return true; +} + +/*** + * + * + * + * The staticbox associated with the sizer. + * + * + * Orientation wxVERTICAL or wxHORIZONTAL for creating either a column + * or row sizer. See @wxOrientation + * + * + * + * Constructs a new wxStaticBoxSizer object. + * + * + */ +wxStaticBoxSizer* StaticBoxSizer::Construct(JSContext *cx, + JSObject *obj, + uintN argc, + jsval *argv, + bool constructing) +{ + wxStaticBoxSizer *p = NULL; + + if ( argc > 2 ) + argc = 2; + + wxStaticBox *box = StaticBox::GetPrivate(cx, argv[0]); + if ( box == NULL ) + return NULL; + + int orient; + + if ( FromJS(cx, argv[1], orient) ) + { + p = new wxStaticBoxSizer(box, orient); + } + + if ( p != NULL ) + { + p->SetClientObject(new JavaScriptClientData(cx, obj, false, true)); + } + + return p; +} Property changes on: ps/trunk/source/tools/atlas/wxJS/gui/misc/stsizer.cpp ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/gui/misc/autoobj.h =================================================================== --- ps/trunk/source/tools/atlas/wxJS/gui/misc/autoobj.h (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/gui/misc/autoobj.h (revision 5154) @@ -0,0 +1,73 @@ +/* + * wxJavaScript - autoobj.h + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: autoobj.h 598 2007-03-07 20:13:28Z fbraem $ + */ +#if defined(__WXMSW__) + +#ifndef _WXJSAutomationObject_H +#define _WXJSAutomationObject_H + +///////////////////////////////////////////////////////////////////////////// +// Name: autoobj.h +// Purpose: AutomationObject ports wxAutomationObject to JavaScript +// Author: Franky Braem +// Modified by: +// Created: 28-12-2002 +// Copyright: (c) 2001-2002 Franky Braem +// Licence: LGPL +///////////////////////////////////////////////////////////////////////////// + +namespace wxjs +{ + namespace gui + { + class AutomationObject : public ApiWrapper + { + public: + /** + * Callback for when a wxAutomationObject object is created + */ + static wxAutomationObject* Construct(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, bool constructing); + static void Destruct(JSContext *cx, wxAutomationObject *p) + { + p->SetDispatchPtr(NULL); + delete p; + } + static wxVariant* CreateVariant(JSContext *cx, jsval v); + static jsval CreateJSVal(JSContext *cx, const wxVariant &var); + + WXJS_DECLARE_METHOD_MAP() + + static JSBool createInstance(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval); + static JSBool callMethod(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval); + static JSBool getInstance(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval); + static JSBool getObject(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval); + static JSBool putProperty(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval); + static JSBool getProperty(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval); + }; + }; // namespace gui +}; // namespace wxjs + +#endif //_WXJSAutomationObject_H + +#endif // __WXMSW__ Property changes on: ps/trunk/source/tools/atlas/wxJS/gui/misc/autoobj.h ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/gui/misc/genval.h =================================================================== --- ps/trunk/source/tools/atlas/wxJS/gui/misc/genval.h (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/gui/misc/genval.h (revision 5154) @@ -0,0 +1,85 @@ +/* + * wxJavaScript - genval.h + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: genval.h 715 2007-05-18 20:38:04Z fbraem $ + */ +#include + +///////////////////////////////////////////////////////////////////////////// +// Name: genval.h +// Purpose: GenericValidator ports wxGenericValidator to JavaScript +// Author: Franky Braem +// Modified by: +// Created: 29.01.02 +// Copyright: (c) 2001-2002 Franky Braem +// Licence: LGPL +///////////////////////////////////////////////////////////////////////////// + +namespace wxjs +{ + namespace gui + { + class GenericValidator : public wxGenericValidator + , public ApiWrapper + { + DECLARE_CLASS(GenericValidator) + public: + + GenericValidator(bool val); + GenericValidator(int val); + GenericValidator(wxString val); + GenericValidator(wxArrayInt val); + + GenericValidator(const GenericValidator ©); + virtual wxObject* Clone() const; + virtual ~GenericValidator() + { + } + + /** + * Validate forwards the validation to the validate method of the JavaScript object. + */ + virtual bool Validate(wxWindow *parent); + + static bool GetProperty(wxGenericValidator *p, JSContext *cx, JSObject *obj, int id, jsval *vp); + + static GenericValidator* Construct(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, bool constructing); + + WXJS_DECLARE_PROPERTY_MAP() + + /** + * Property Ids. + */ + enum + { + P_VALUE + }; + + private: + bool m_boolValue; + int m_intValue; + wxString m_stringValue; + wxArrayInt m_arrayIntValue; + }; + }; // namespace gui +}; // namespace wxjs Property changes on: ps/trunk/source/tools/atlas/wxJS/gui/misc/genval.h ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/gui/misc/imghand.h =================================================================== --- ps/trunk/source/tools/atlas/wxJS/gui/misc/imghand.h (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/gui/misc/imghand.h (revision 5154) @@ -0,0 +1,159 @@ +/* + * wxJavaScript - imghand.h + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: imghand.h 734 2007-06-06 20:09:13Z fbraem $ + */ +#ifndef _WXJSImageHandler_H +#define _WXJSImageHandler_H + +#include + +namespace wxjs +{ + namespace gui + { + // A class that handles the destruction of an imagehandler. + // Ounce the handler is added to the image handler list, wxWindows destroys + // the handler for us. So when the handler is not in a list, wxJS must destroy + // the handler. + class ImageHandlerPrivate + { + public: + ImageHandlerPrivate(wxImageHandler *handler, bool ours) : m_handler(handler), m_ours(ours) + { + } + + ~ImageHandlerPrivate() + { + if ( IsOurs() ) + delete m_handler; + } + + bool IsOurs() const + { + return m_ours; + } + + void SetOurs(bool ours) + { + m_ours = ours; + } + + wxImageHandler* GetHandler() const + { + return m_handler; + } + + private: + wxImageHandler *m_handler; + bool m_ours; + }; + + class ImageHandler : public ApiWrapper + { + public: + + /** + * Callback for retrieving properties of wxImageHandler + */ + static bool GetProperty(ImageHandlerPrivate *p, JSContext *cx, JSObject *obj, int id, jsval *vp); + + /** + * Callback for setting properties + */ + static bool SetProperty(ImageHandlerPrivate *p, JSContext *cx, JSObject *obj, int id, jsval *vp); + + WXJS_DECLARE_PROPERTY_MAP() + + /** + * Property Ids. + */ + enum + { + P_NAME + , P_EXTENSION + , P_TYPE + , P_MIME_TYPE + }; + + WXJS_DECLARE_METHOD_MAP() + static JSBool getImageCount(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval); + static JSBool loadFile(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval); + static JSBool saveFile(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval); + }; + + class BMPHandler : public ApiWrapper + { + public: + static ImageHandlerPrivate* Construct(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, bool constructing); + }; + + class ICOHandler : public ApiWrapper + { + public: + static ImageHandlerPrivate* Construct(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, bool constructing); + }; + + class GIFHandler : public ApiWrapper + { + public: + static ImageHandlerPrivate* Construct(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, bool constructing); + }; + + class JPEGHandler : public ApiWrapper + { + public: + static ImageHandlerPrivate* Construct(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, bool constructing); + }; + + class PCXHandler : public ApiWrapper + { + public: + static ImageHandlerPrivate* Construct(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, bool constructing); + }; + + class PNGHandler : public ApiWrapper + { + public: + static ImageHandlerPrivate* Construct(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, bool constructing); + }; + + class PNMHandler : public ApiWrapper + { + public: + static ImageHandlerPrivate* Construct(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, bool constructing); + }; + + class TIFFHandler : public ApiWrapper + { + public: + static ImageHandlerPrivate* Construct(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, bool constructing); + }; + + class XPMHandler : public ApiWrapper + { + public: + static ImageHandlerPrivate* Construct(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, bool constructing); + }; + }; // namespace gui +}; // namespace wxjs +#endif //_WXJSImageHandler_H Property changes on: ps/trunk/source/tools/atlas/wxJS/gui/misc/imghand.h ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/gui/misc/image.h =================================================================== --- ps/trunk/source/tools/atlas/wxJS/gui/misc/image.h (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/gui/misc/image.h (revision 5154) @@ -0,0 +1,126 @@ +/* + * wxJavaScript - image.h + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: image.h 598 2007-03-07 20:13:28Z fbraem $ + */ +#ifndef _WXJSImage_H +#define _WXJSImage_H + +///////////////////////////////////////////////////////////////////////////// +// Name: image.h +// Purpose: Image ports wxImage to JavaScript +// Author: Franky Braem +// Modified by: +// Created: 07-10-2002 +// Copyright: (c) 2001-2002 Franky Braem +// Licence: LGPL +///////////////////////////////////////////////////////////////////////////// + +#include + +namespace wxjs +{ + namespace gui + { + class Image : public ApiWrapper + { + public: + /** + * Callback for retrieving properties of wxImage + */ + static bool GetProperty(wxImage *p, JSContext *cx, JSObject *obj, int id, jsval *vp); + + /** + * Callback for setting properties + */ + static bool SetProperty(wxImage *p, JSContext *cx, JSObject *obj, int id, jsval *vp); + + /** + * Callback for when a wxImage object is created + */ + static wxImage* Construct(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, bool constructing); + + WXJS_DECLARE_PROPERTY_MAP() + + /** + * Property Ids. + */ + enum + { + P_OK + , P_MASK_RED + , P_MASK_GREEN + , P_MASK_BLUE + , P_WIDTH + , P_HEIGHT + , P_MASK + , P_HAS_PALETTE + , P_HAS_MASK + , P_PALETTE + , P_SIZE + , P_HANDLERS + }; + + WXJS_DECLARE_STATIC_PROPERTY_MAP() + bool GetStaticProperty(JSContext *cx, int id, jsval *vp); + + WXJS_DECLARE_METHOD_MAP() + static JSBool create(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval); + static JSBool destroy(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval); + static JSBool copy(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval); + static JSBool getSubImage(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval); + static JSBool paste(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval); + static JSBool scale(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval); + static JSBool rescale(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval); + static JSBool rotate(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval); + static JSBool rotate90(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval); + static JSBool mirror(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval); + static JSBool replace(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval); + static JSBool convertToMono(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval); + static JSBool setRGB(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval); + static JSBool getRed(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval); + static JSBool getGreen(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval); + static JSBool getBlue(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval); + static JSBool getColour(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval); + static JSBool findFirstUnusedColour(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval); + static JSBool setMaskFromImage(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval); + static JSBool setMaskColour(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval); + static JSBool saveFile(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval); + static JSBool loadFile(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval); + static JSBool setOption(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval); + static JSBool getOption(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval); + static JSBool getOptionInt(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval); + static JSBool hasOption(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval); + + WXJS_DECLARE_STATIC_METHOD_MAP() + static JSBool canRead(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval); + static JSBool addHandler(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval); + static JSBool cleanUpHandlers(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval); + static JSBool findHandler(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval); + static JSBool removeHandler(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval); + static JSBool findHandlerMime(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval); + static JSBool insertHandler(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval); + }; + }; // namespace gui +}; // namespace wxjs + +#endif //_WXJSImage_H Property changes on: ps/trunk/source/tools/atlas/wxJS/gui/misc/image.h ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/gui/misc/fontenum.cpp =================================================================== --- ps/trunk/source/tools/atlas/wxJS/gui/misc/fontenum.cpp (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/gui/misc/fontenum.cpp (revision 5154) @@ -0,0 +1,300 @@ +#include "precompiled.h" + +/* + * wxJavaScript - fontenum.cpp + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: fontenum.cpp 715 2007-05-18 20:38:04Z fbraem $ + */ +// fontenum.cpp + +#ifndef WX_PRECOMP + #include +#endif + +#include "../../common/main.h" +#include "../../common/jsutil.h" + +#include "fontenum.h" +#include "app.h" + +using namespace wxjs; +using namespace wxjs::gui; + +/*** + * misc/fontenum + * gui + * + * Use wxFontEnumerator to enumerate all available fonts. + * See @wxFont, @wxFontEncoding + *

+ * The following example shows a dialog which contains a listbox with the names of all the available fonts. + *

+ *   var dlg = new wxDialog(null,
+ *                          -1,
+ *                         "Font Enumerating example");
+ *
+ *   // Create a wxFontEnumerator
+ *   var enumerator = new wxFontEnumerator();
+ *   // Set a funtion to onFacename. To get all available fonts return true. 
+ *   // No arguments need to be specified, because they are not used.
+ *
+ *   enumerator.onFacename = function()
+ *   {
+ *     return true;
+ *   };
+ *
+ *   // Use enumerateFaceNames to start the enumeration.
+ *   enumerator.enumerateFacenames();
+ *
+ *   // Now the property facenames contains all the font names.
+ *   var listbox = new wxListBox(dlg, -1, wxDefaultPosition, wxDefaultSize, enumerator.facenames);
+ *  
+ *
+ */ + +WXJS_INIT_CLASS(FontEnumerator, "wxFontEnumerator", 0) + +/*** + * + * + * Array of strings containing all encodings found by @wxFontEnumerator#enumerateEncodings. + * Returns undefined when this function is not called. + * + * + * Array of strings containing all facenames found by @wxFontEnumerator#enumerateFacenames. + * Returns undefined when this function is not called. + * + * + * A function which receives the encoding as argument. The encoding is added + * to @wxFontEnumerator#encodings when the function returns true. + * + * + * A function which receives the font and encoding as arguments. + * When the function returns true, the font is added to @wxFontEnumerator#facenames. + * When no function is set, all available fonts are added. + * + * + */ +WXJS_BEGIN_STATIC_PROPERTY_MAP(FontEnumerator) + WXJS_READONLY_STATIC_PROPERTY(P_FACENAMES, "facenames") + WXJS_READONLY_STATIC_PROPERTY(P_ENCODINGS, "encodings") +WXJS_END_PROPERTY_MAP() + +FontEnumerator::FontEnumerator(JSContext *cx, JSObject *obj) +{ + m_data = new JavaScriptClientData(cx, obj, false); +} + +FontEnumerator::~FontEnumerator() +{ + delete m_data; +} + +bool FontEnumerator::OnFacename(const wxString& faceName) +{ + JSObject *enumObj = m_data->GetObject(); + + jsval fval; + JSContext *cx = m_data->GetContext(); + if ( GetFunctionProperty(cx, enumObj, "onFacename", &fval) == JS_TRUE ) + { + jsval rval; + jsval argv[] = { ToJS(cx, faceName) }; + JSBool result = JS_CallFunctionValue(cx, enumObj, fval, 1, argv, &rval); + if ( result == JS_FALSE ) + { + if ( JS_IsExceptionPending(cx) ) + { + JS_ReportPendingException(cx); + } + return false; + } + else + { + bool ret; + if ( ! FromJS(cx, rval, ret) + || ! ret ) + return false; + } + } + + return wxFontEnumerator::OnFacename(faceName); +} + +bool FontEnumerator::OnFontencoding(const wxString& faceName, const wxString &encoding) +{ + JSObject *enumObj = m_data->GetObject(); + JSContext *cx = m_data->GetContext(); + + jsval fval; + if ( GetFunctionProperty(cx, enumObj, "onFontEncoding", &fval) == JS_TRUE ) + { + jsval rval; + jsval argv[] = { ToJS(cx, faceName) + , ToJS(cx, encoding) }; + JSBool result = JS_CallFunctionValue(cx, enumObj, fval, 2, argv, &rval); + if ( result == JS_FALSE ) + { + if ( JS_IsExceptionPending(cx) ) + { + JS_ReportPendingException(cx); + } + return false; + } + else + { + bool ret; + if ( ! FromJS(cx, rval, ret) + || ! ret ) + return false; + } + } + + return wxFontEnumerator::OnFontEncoding(faceName, encoding); +} + +bool FontEnumerator::GetStaticProperty(JSContext *cx, int id, jsval *vp) +{ + switch (id) + { + case P_FACENAMES: + { + wxArrayString faceNames = wxFontEnumerator::GetFacenames(); + *vp = ( faceNames == NULL ) ? JSVAL_VOID : ToJS(cx, faceNames); + } + break; + case P_ENCODINGS: + { + wxArrayString encodings = wxFontEnumerator::GetEncodings(); + *vp = ( encodings == NULL ) ? JSVAL_VOID : ToJS(cx, encodings); + } + break; + } + return true; +} + +/*** + * + * + * + * Creates a wxFontEnumerator object. + * + * + */ +FontEnumerator* FontEnumerator::Construct(JSContext *cx, + JSObject *obj, + uintN argc, + jsval *argv, + bool constructing) +{ + return new FontEnumerator(cx, obj); +} + +WXJS_BEGIN_METHOD_MAP(FontEnumerator) + WXJS_METHOD("enumerateFacenames", enumerateFacenames, 2) + WXJS_METHOD("enumerateEncodings", enumerateEncodings, 1) +WXJS_END_METHOD_MAP() + +/*** + * + * + * + * The encoding. + * + * + * Only report fonts with fixed width or not. + * + * + * + * This will call the function which is set to the @wxFontEnumerator#onFacename property + * for each font which supports the given encoding. When this function returns true for the + * the given font, it will be added to @wxFontEnumerator#facenames. + * When no function is specified, all fonts will be added to @wxFontEnumerator#facenames. + * See also @wxFontEncoding, @wxFontEnumerator#facenames, @wxFontEnumerator#onFacename + * + * + */ +JSBool FontEnumerator::enumerateFacenames(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + FontEnumerator *p = GetPrivate(cx, obj); + wxASSERT_MSG(p != NULL, wxT("No private data for wxFontEnumerator")); + + if ( argc == 0 ) + { + p->EnumerateFacenames(); + return JS_TRUE; + } + + int encoding; + if ( FromJS(cx, argv[0], encoding) ) + { + if ( argc > 1 ) + { + bool fixedWidth; + if ( FromJS(cx, argv[1], fixedWidth) ) + { + p->EnumerateFacenames((wxFontEncoding)encoding, fixedWidth); + return JS_TRUE; + } + } + else + { + p->EnumerateFacenames((wxFontEncoding)encoding); + return JS_TRUE; + } + } + + return JS_FALSE; +} + +/*** + * + * + * + * A font name. + * + * + * + * The function set on the @wxFontEnumerator#onFontEncoding is called for each + * encoding supported by the given font. + * When no function is set all encodings are reported. + * See @wxFontEnumerator#onFontEncoding, @wxFontEnumerator#encodings + * + * + */ +JSBool FontEnumerator::enumerateEncodings(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + FontEnumerator *p = GetPrivate(cx, obj); + wxASSERT_MSG(p != NULL, wxT("No private data for wxFontEnumerator")); + + if ( argc == 0 ) + { + p->EnumerateEncodings(); + return JS_TRUE; + } + + wxString font; + FromJS(cx, argv[0], font); + p->EnumerateEncodings(font); + + return JS_TRUE; +} Property changes on: ps/trunk/source/tools/atlas/wxJS/gui/misc/fontenum.cpp ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/gui/misc/pnghdlr.cpp =================================================================== --- ps/trunk/source/tools/atlas/wxJS/gui/misc/pnghdlr.cpp (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/gui/misc/pnghdlr.cpp (revision 5154) @@ -0,0 +1,52 @@ +#include "precompiled.h" + +/* + * wxJavaScript - pnghdlr.cpp + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: pnghdlr.cpp 598 2007-03-07 20:13:28Z fbraem $ + */ +#ifndef WX_PRECOMP + #include +#endif + +#include "../../common/main.h" +#include "../../common/type.h" +#include "../../common/jsutil.h" + +#include "imghand.h" +using namespace wxjs; +using namespace wxjs::gui; + +/*** + * misc/pnghdlr + * gui + * + * Image handler for PNG images. + * + */ +WXJS_INIT_CLASS(PNGHandler, "wxPNGHandler", 0) + +ImageHandlerPrivate* PNGHandler::Construct(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, bool constructing) +{ + return new ImageHandlerPrivate(new wxPNGHandler(), true); +}; + Property changes on: ps/trunk/source/tools/atlas/wxJS/gui/misc/pnghdlr.cpp ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/gui/misc/imghand.cpp =================================================================== --- ps/trunk/source/tools/atlas/wxJS/gui/misc/imghand.cpp (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/gui/misc/imghand.cpp (revision 5154) @@ -0,0 +1,304 @@ +#include "precompiled.h" + +/* + * wxJavaScript - imghand.cpp + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: imghand.cpp 598 2007-03-07 20:13:28Z fbraem $ + */ +// imghand.cpp + +#ifndef WX_PRECOMP + #include +#endif + +#include "../../common/main.h" +#include "../../common/type.h" +#include "../../common/jsutil.h" + +#include "../../io/jsstream.h" + +#include "image.h" +#include "imghand.h" + +using namespace wxjs; +using namespace wxjs::gui; + +/*** + * misc/imghand + * gui + * + * wxImageHandler is the prototype for several image handlers. + * See @wxImage, @wxBMPHandler, @wxGIFHandler, @wxICOHandler, + * @wxJPEGHandler, @wxPCXHandler, @wxPNGHandler, @wxPNMHandler, + * @wxTIFFHandler, @wxXPMHandler + * + */ +WXJS_INIT_CLASS(ImageHandler, "wxImageHandler", 0) + +/*** + * + * + * Get/Set the handler extension. + * + * + * Get/Set the handler MIME type. + * + * + * Get/Set the handler name. + * + * + * Get/Set the handler type. + * + * + */ +WXJS_BEGIN_PROPERTY_MAP(ImageHandler) + WXJS_PROPERTY(P_NAME, "name") + WXJS_PROPERTY(P_EXTENSION, "extension") + WXJS_PROPERTY(P_TYPE, "type") + WXJS_PROPERTY(P_MIME_TYPE, "mimeType") +WXJS_END_PROPERTY_MAP() + +bool ImageHandler::GetProperty(ImageHandlerPrivate *p, JSContext *cx, JSObject *obj, int id, jsval *vp) +{ + wxImageHandler *handler = p->GetHandler(); + switch (id) + { + case P_NAME: + *vp = ToJS(cx, handler->GetName()); + break; + case P_EXTENSION: + *vp = ToJS(cx, handler->GetExtension()); + break; + case P_TYPE: + *vp = ToJS(cx, handler->GetType()); + break; + case P_MIME_TYPE: + *vp = ToJS(cx, handler->GetMimeType()); + break; + } + return true; +} + +bool ImageHandler::SetProperty(ImageHandlerPrivate *p, JSContext *cx, JSObject *obj, int id, jsval *vp) +{ + wxImageHandler *handler = p->GetHandler(); + + switch (id) + { + case P_NAME: + { + wxString name; + FromJS(cx, *vp, name); + handler->SetName(name); + break; + } + case P_EXTENSION: + { + wxString ext; + FromJS(cx, *vp, ext); + handler->SetName(ext); + break; + } + case P_TYPE: + { + long type; + if ( FromJS(cx, *vp, type) ) + handler->SetType(type); + break; + } + case P_MIME_TYPE: + { + wxString mime; + FromJS(cx, *vp, mime); + handler->SetName(mime); + break; + } + } + return true; +} + +WXJS_BEGIN_METHOD_MAP(ImageHandler) + WXJS_METHOD("getImageCount", getImageCount, 1) + WXJS_METHOD("loadFile", loadFile, 2) + WXJS_METHOD("saveFile", saveFile, 2) +WXJS_END_METHOD_MAP() + +/*** + * + * + * + * Opened input stream for reading image data. Currently, the stream must support seeking. + * + * + * + * If the image file contains more than one image and the image handler is capable + * of retrieving these individually, this function will return the number of available images. + * Most imagehandlers return 1. + * + * + */ +JSBool ImageHandler::getImageCount(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + ImageHandlerPrivate *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + io::Stream *stream = NULL; + if ( wxjs::HasPrototype(cx, argv[0], "wxInputStream") ) + stream = (io::Stream *) JS_GetPrivate(cx, JSVAL_TO_OBJECT(argv[0])); + else + return JS_FALSE; + + wxInputStream *in = dynamic_cast(stream->GetStream()); + if ( in == NULL ) + { + // TODO: error reporting + return JS_FALSE; + } + + *rval = ToJS(cx, p->GetHandler()->GetImageCount(*in)); + + return JS_FALSE; +} + +/*** + * + * + * + * The object that gets the loaded image. + * + * + * Opened input stream for reading image data. + * + * + * When true the image handler will report errors using wxLog + * + * + * The index of the image in the file (zero-based). + * + * + * + * Loads a image from a stream, putting the resulting data into image. + * If the image file contains more than one image and the image handler is capable + * of retrieving these individually, index indicates which image to read from the stream. + * Returns true when successful, false otherwise. + * + * + */ +JSBool ImageHandler::loadFile(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + ImageHandlerPrivate *p = ImageHandler::GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + int idx = 0; + bool verbose = true; + + switch(argc) + { + case 4: + if ( ! FromJS(cx, argv[3], idx) ) + return JS_FALSE; + case 3: + if ( ! FromJS(cx, argv[2], verbose) ) + return JS_FALSE; + default: + wxImage *img = Image::GetPrivate(cx, argv[0]); + if ( img == NULL ) + return JS_FALSE; + + io::Stream *stream = NULL; + if ( wxjs::HasPrototype(cx, argv[0], "wxInputStream") ) + stream = (io::Stream *) JS_GetPrivate(cx, JSVAL_TO_OBJECT(argv[0])); + else + return JS_FALSE; + + wxInputStream *in = dynamic_cast(stream->GetStream()); + if ( in == NULL ) + { + // TODO: error reporting + return JS_FALSE; + } + + *rval = ToJS(cx, p->GetHandler()->LoadFile(img, *in, verbose, idx)); + } + + return JS_TRUE; +} + +/*** + * + * + * + * The object that gets the loaded image. + * + * + * Opened output stream for writing the image data. + * + * + * When true the image handler will report errors using wxLog + * + * + * + * Saves a image in the output stream. Returns true on success, false otherwise. + * + * + */ +JSBool ImageHandler::saveFile(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + ImageHandlerPrivate *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + if ( argc > 3 ) + argc = 3; + + bool verbose = true; + + switch(argc) + { + case 3: + if ( ! FromJS(cx, argv[2], verbose) ) + return JS_FALSE; + default: + wxImage *img = Image::GetPrivate(cx, argv[0]); + if ( img == NULL ) + return JS_FALSE; + + io::Stream *stream = NULL; + if ( wxjs::HasPrototype(cx, argv[0], "wxOutputStream") ) + stream = (io::Stream *) JS_GetPrivate(cx, JSVAL_TO_OBJECT(argv[0])); + else + return JS_FALSE; + + wxOutputStream *out = dynamic_cast(stream->GetStream()); + if ( out == NULL ) + { + // TODO: error reporting + return JS_FALSE; + } + + *rval = ToJS(cx, p->GetHandler()->SaveFile(img, *out, verbose)); + } + + return JS_TRUE; +} Property changes on: ps/trunk/source/tools/atlas/wxJS/gui/misc/imghand.cpp ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/gui/misc/genval.cpp =================================================================== --- ps/trunk/source/tools/atlas/wxJS/gui/misc/genval.cpp (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/gui/misc/genval.cpp (revision 5154) @@ -0,0 +1,291 @@ +#include "precompiled.h" + +/* + * wxJavaScript - genval.cpp + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: genval.cpp 723 2007-05-31 19:59:50Z fbraem $ + */ +// validator.cpp + +#ifndef WX_PRECOMP + #include +#endif + +#include "../../common/main.h" +#include "../../common/jsutil.h" + +#include "../control/window.h" + +#include "genval.h" +#include "app.h" + +using namespace wxjs; +using namespace wxjs::gui; + +IMPLEMENT_CLASS(GenericValidator, wxGenericValidator) + +/*** + * misc/genval + * gui + * + * wxGenericValidator performs data transfer (but not validation or filtering) + * for the following basic controls: @wxButton, @wxCheckBox, @wxListBox, + * @wxStaticText, @wxRadioButton, @wxRadioBox, @wxChoice, @wxComboBox, + * @wxGauge, @wxSlider, @wxScrollBar, @wxSpinButton, @wxTextCtrl, + * @wxCheckListBox. + *

+ * There's a difference between the wxWidgets implementation and the wxJS implementation: + * wxWidgets automatically transfer the data to the given pointer variable when validation + * succeeds. In JavaScript this is not possible. wxJS solves this with the + * @wxGenericValidator#value property. This property returns the value of the control. + * The type of this value is the same as the type of the argument of the constructor. + *

+ * The following example shows how to use this class: + *

+ *   var user = "Demo";
+ *   var pwd = "";
+ *
+ *   function Application()
+ *   {
+ *      var dlg = new wxDialog(null, -1, "wxValidator Example",
+ *                            wxDefaultPosition, new wxSize(200, 150));
+ *
+ *      var userText = new wxTextCtrl(dlg, -1);
+ *      var pwdText = new wxTextCtrl(dlg, -1);
+ *      var okButton = new wxButton(dlg, wxId.OK, "Ok");
+ *      var cancelButton = new wxButton(dlg, wxId.CANCEL, "Cancel");
+ *
+ *      dlg.sizer = new wxFlexGridSizer(4, 2, 10, 10);
+ *      dlg.sizer.add(new wxStaticText(dlg, -1, "Username"));
+ *      dlg.sizer.add(userText);
+ *      dlg.sizer.add(new wxStaticText(dlg, -1, "Password"));
+ *      dlg.sizer.add(pwdText);
+ *      dlg.sizer.add(okButton);
+ *      dlg.sizer.add(cancelButton);
+ *
+ *      // Create validator
+ *      var validator = new wxGenericValidator(user);
+ *
+ *      validator.validate = function()
+ *      {
+ *        if ( this.window.value.length == 0 )
+ *        {
+ *          wxMessageBox("Please give a username");
+ *          return false;
+ *      }
+ *      return true;
+ *   }
+ *   userText.validator = validator; 
+ *
+ *   dlg.autoLayout = true;
+ *   dlg.layout();
+ *   dlg.showModal();
+ * 
+ *   user = validator.value;
+ *
+ *   return false;
+ *  }
+ *
+ *  wxTheApp.onInit = Application;
+ *  wxTheApp.mainLoop();
+ *  
+ *
+ */ +GenericValidator::GenericValidator(bool val) : m_boolValue(val) + , wxGenericValidator(&m_boolValue) +{ +} + +GenericValidator::GenericValidator(int val) : m_intValue(val) + , wxGenericValidator(&m_intValue) +{ +} + +GenericValidator::GenericValidator(wxString val) : m_stringValue(val) + , wxGenericValidator(&m_stringValue) +{ +} + +GenericValidator::GenericValidator(wxArrayInt val) : m_arrayIntValue(val) + , wxGenericValidator(&m_arrayIntValue) +{ +} + +GenericValidator::GenericValidator(const GenericValidator ©) : wxGenericValidator(copy) +{ + JavaScriptClientData *data + = dynamic_cast(copy.GetClientObject()); + if ( data != NULL ) + { + SetClientObject(new JavaScriptClientData(*data)); + data->Protect(false); + } +} + +wxObject* GenericValidator::Clone() const +{ + return new GenericValidator(*this); +} + +bool GenericValidator::Validate(wxWindow *parent) +{ + JavaScriptClientData *data + = dynamic_cast(GetClientObject()); + if ( data == NULL ) + { + return false; + } + + JSContext *cx = data->GetContext(); + wxASSERT_MSG(cx != NULL, wxT("No application object available")); + + JavaScriptClientData *winParentData + = dynamic_cast(parent->GetClientObject()); + + jsval fval; + if ( GetFunctionProperty(cx, data->GetObject(), + "validate", &fval) == JS_TRUE ) + { + jsval argv[] = + { + winParentData == NULL ? JSVAL_VOID + : OBJECT_TO_JSVAL(winParentData->GetObject()) + }; + + jsval rval; + JSBool result = JS_CallFunctionValue(cx, data->GetObject(), + fval, 1, argv, &rval); + if ( result == JS_FALSE ) + { + if ( JS_IsExceptionPending(cx) ) + { + JS_ReportPendingException(cx); + } + return false; + } + else + return JSVAL_IS_BOOLEAN(rval) ? JSVAL_TO_BOOLEAN(rval) == JS_TRUE : false; + } + + return false; +} + +WXJS_INIT_CLASS(GenericValidator, "wxGenericValidator", 1) + +/*** + * + * + * Gets the value. The same type as the argument of the @wxGenericValidator#ctor. + * + * + * Assign a function to this property that checks the content of the associated window. The function + * can have one argument: the parent of the associated window. This function should return false + * when the content is invalid, true when it is valid. To get the associated window, + * use this.window. + * + * + */ +WXJS_BEGIN_PROPERTY_MAP(GenericValidator) + WXJS_READONLY_PROPERTY(P_VALUE, "value") +WXJS_END_PROPERTY_MAP() + +bool GenericValidator::GetProperty(wxGenericValidator *p, + JSContext *cx, + JSObject *obj, + int id, + jsval *vp) +{ + GenericValidator *val = dynamic_cast(p); + + if ( val != NULL + && id == P_VALUE ) + { + if ( val->m_pBool != NULL ) + { + *vp = ToJS(cx, val->m_boolValue); + } + else if ( val->m_pInt != NULL ) + { + *vp = ToJS(cx, val->m_intValue); + } + else if ( val->m_pString != NULL ) + { + *vp = ToJS(cx, val->m_stringValue); + } + else if ( val->m_pArrayInt != NULL ) + { + // TODO + } + else + *vp = JSVAL_VOID; + } + return true; +} + +/*** + * + * + * + * This value is used to transfer to the control. + * The type of value is important. + *
  • Boolean: used for @wxCheckBox and @wxRadioBox.
  • + *
  • String: used for @wxButton, @wxComboBox, @wxStaticText and @wxTextCtrl.
  • + *
  • Integer: used for @wxGauge, @wxScrollBar, @wxRadioBox, @wxSpinButton and @wxChoice.
  • + *
  • Array of Integers: used for @wxListBox and @wxCheckListBox.
  • + *
+ *
+ *
+ * + * Constructs a new wxGenericValidator object + * + *
+ */ +GenericValidator *GenericValidator::Construct(JSContext *cx, + JSObject *obj, + uintN argc, + jsval *argv, + bool constructing) +{ + GenericValidator *v = NULL; + if ( JSVAL_IS_BOOLEAN(argv[0]) ) + { + bool value; + FromJS(cx, argv[0], value); + v = new GenericValidator(value); + } + else if ( JSVAL_IS_INT(argv[0]) ) + { + int value; + FromJS(cx, argv[0], value); + v = new GenericValidator(value); + } + + if ( v == NULL ) + { + // Default: assume a string value + wxString value; + FromJS(cx, argv[0], value); + v = new GenericValidator(value); + } + + return v; +} Property changes on: ps/trunk/source/tools/atlas/wxJS/gui/misc/genval.cpp ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/gui/misc/textval.cpp =================================================================== --- ps/trunk/source/tools/atlas/wxJS/gui/misc/textval.cpp (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/gui/misc/textval.cpp (revision 5154) @@ -0,0 +1,222 @@ +#include "precompiled.h" + +/* + * wxJavaScript - textval.cpp + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: textval.cpp 738 2007-06-08 18:47:56Z fbraem $ + */ + +#ifndef WX_PRECOMP + #include +#endif + +#include "../../common/main.h" +#include "../../common/type.h" + +#include "validate.h" +#include "textval.h" +using namespace wxjs; +using namespace wxjs::gui; + +TextValidator::TextValidator(long style, + const wxString &value) : wxTextValidator(style) +{ + m_value = value; + m_stringValue = &m_value; +} + +TextValidator::TextValidator(const TextValidator ©) : wxTextValidator(copy) +{ + JavaScriptClientData *data + = dynamic_cast(copy.GetClientObject()); + if ( data != NULL ) + { + SetClientObject(new JavaScriptClientData(*data)); + data->Protect(false); + } +} + +wxObject* TextValidator::Clone() const +{ + return new TextValidator(*this); +} + +/*** + * misc/textval + * gui + * + * wxTextValidator validates text controls, providing a variety of filtering + * behaviours. The following example shows a dialog with a textfield. It's + * only allowed to enter numeric characters. The textfield is initialised + * using the validator. + *

+ *   function init()
+ *   {
+ *     var dlg = new wxDialog(null, -1);
+ *     var txtField = new wxTextCtrl(dlg, -1);
+ *
+ *     txtField.validator = new wxTextValidator(wxFilter.NUMERIC, "10");
+ *
+ *     dlg.fit();
+ *     dlg.showModal();
+ *
+ *     wxMessageBox("You have entered: " + txtField.value);
+ *
+ *     return false;
+ *   }
+ *
+ *   wxTheApp.onInit = init;
+ *   wxTheApp.mainLoop();
+ *  
+ *
+ */ +WXJS_INIT_CLASS(TextValidator, "wxTextValidator", 0) + +/*** + * + * + * Get/Set an array of invalid values. + * + * + * Get/Set an array of valid values. + * + * + * Get/Set the filter style. See @wxFilter + * + * + * Get the value entered in the textfield. + * + * + */ +WXJS_BEGIN_PROPERTY_MAP(TextValidator) + WXJS_PROPERTY(P_EXCLUDE_LIST, "excludes") + WXJS_PROPERTY(P_INCLUDE_LIST, "includes") + WXJS_PROPERTY(P_STYLE, "style") + WXJS_READONLY_PROPERTY(P_STYLE, "value") +WXJS_END_PROPERTY_MAP() + +bool TextValidator::GetProperty(wxTextValidator *p, + JSContext *cx, + JSObject *obj, + int id, + jsval *vp) +{ + switch (id) + { + case P_EXCLUDE_LIST: + *vp = ToJS(cx, p->GetExcludes()); + break; + case P_INCLUDE_LIST: + *vp = ToJS(cx, p->GetIncludes()); + break; + case P_STYLE: + *vp = ToJS(cx, p->GetStyle()); + break; + case P_VALUE: + { + TextValidator *val = dynamic_cast(p); + if ( val ) + *vp = ToJS(cx, val->m_value); + } + break; + } + return true; +} + +bool TextValidator::SetProperty(wxTextValidator *p, + JSContext *cx, + JSObject *obj, + int id, + jsval *vp) +{ + switch (id) + { + case P_EXCLUDE_LIST: + { + wxArrayString list; + if ( FromJS(cx, *vp, list) ) + p->SetExcludes(list); + } + break; + case P_INCLUDE_LIST: + { + wxArrayString list; + if ( FromJS(cx, *vp, list) ) + p->SetIncludes(list); + } + break; + case P_STYLE: + { + long style; + if ( FromJS(cx, *vp, style) ) + p->SetStyle(style); + } + break; + } + return true; +} + +/*** + * + * + * + * + * Value used to initialize the textfield. + * + * + * + * Constructs a new wxTextValidator object. + * + * + */ +wxTextValidator* TextValidator::Construct(JSContext *cx, + JSObject *obj, + uintN argc, + jsval *argv, + bool constructing) +{ + long filter = wxFILTER_NONE; + + wxTextValidator *p = NULL; + switch(argc) + { + case 0: + p = new TextValidator(); + break; + case 1: + if ( FromJS(cx, argv[0], filter) ) + { + p = new TextValidator(filter); + } + break; + case 2: + if ( FromJS(cx, argv[0], filter) ) + { + wxString value; + FromJS(cx, argv[1], value); + p = new TextValidator(filter, value); + } + break; + } + + return p; +} Property changes on: ps/trunk/source/tools/atlas/wxJS/gui/misc/textval.cpp ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/gui/misc/tiffhdlr.cpp =================================================================== --- ps/trunk/source/tools/atlas/wxJS/gui/misc/tiffhdlr.cpp (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/gui/misc/tiffhdlr.cpp (revision 5154) @@ -0,0 +1,54 @@ +#include "precompiled.h" + +/* + * wxJavaScript - tiffhdlr.cpp + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: tiffhdlr.cpp 598 2007-03-07 20:13:28Z fbraem $ + */ +// imghand.cpp + +#ifndef WX_PRECOMP + #include +#endif + +#include "../../common/main.h" +#include "../../common/type.h" +#include "../../common/jsutil.h" + +#include "imghand.h" +using namespace wxjs; +using namespace wxjs::gui; + +/*** + * misc/tiffhdlr + * gui + * + * Image handler for TIFF images. + * + */ +WXJS_INIT_CLASS(TIFFHandler, "wxTIFFHandler", 0) + +ImageHandlerPrivate* TIFFHandler::Construct(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, bool constructing) +{ + return new ImageHandlerPrivate(new wxTIFFHandler(), true); +}; + Property changes on: ps/trunk/source/tools/atlas/wxJS/gui/misc/tiffhdlr.cpp ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/gui/misc/pcxhdlr.cpp =================================================================== --- ps/trunk/source/tools/atlas/wxJS/gui/misc/pcxhdlr.cpp (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/gui/misc/pcxhdlr.cpp (revision 5154) @@ -0,0 +1,56 @@ +#include "precompiled.h" + +/* + * wxJavaScript - pcxhdlr.cpp + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: pcxhdlr.cpp 598 2007-03-07 20:13:28Z fbraem $ + */ +#ifndef WX_PRECOMP + #include +#endif + +#include "../../common/main.h" +#include "../../common/type.h" +#include "../../common/jsutil.h" + +#include "imghand.h" + +using namespace wxjs; +using namespace wxjs::gui; + +/*** + * misc/pcxhdlr + * gui + * + * Image handler for PNG images. + * When saving in PCX format, wxPCXHandler will count the number of different colours + * in the image; if there are 256 or less colours, it will save as 8 bit, else it will + * save as 24 bit. + * + */ +WXJS_INIT_CLASS(PCXHandler, "wxPCXHandler", 0) + +ImageHandlerPrivate* PCXHandler::Construct(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, bool constructing) +{ + return new ImageHandlerPrivate(new wxPCXHandler(), true); +}; + Property changes on: ps/trunk/source/tools/atlas/wxJS/gui/misc/pcxhdlr.cpp ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/gui/misc/size.cpp =================================================================== --- ps/trunk/source/tools/atlas/wxJS/gui/misc/size.cpp (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/gui/misc/size.cpp (revision 5154) @@ -0,0 +1,131 @@ +#include "precompiled.h" + +/* + * wxJavaScript - size.cpp + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: size.cpp 598 2007-03-07 20:13:28Z fbraem $ + */ +// size.cpp + +#ifndef WX_PRECOMP + #include +#endif + +#include "../../common/main.h" + +#include "size.h" +using namespace wxjs; +using namespace wxjs::gui; + +/*** + * misc/size + * gui + * + * A wxSize is a useful data structure for graphics operations. + * It simply contains integer width and height members. + * + */ +WXJS_INIT_CLASS(Size, "wxSize", 0) + +/*** + * + * + * The height property. + * + * + * The width property. + * + * + */ +WXJS_BEGIN_PROPERTY_MAP(Size) + WXJS_PROPERTY(P_WIDTH, "width") + WXJS_PROPERTY(P_HEIGHT, "height") +WXJS_END_PROPERTY_MAP() + +bool Size::GetProperty(wxSize *p, JSContext *cx, JSObject *obj, int id, jsval *vp) +{ + switch (id) + { + case P_WIDTH: + *vp = ToJS(cx, p->GetHeight()); + break; + case P_HEIGHT: + *vp = ToJS(cx, p->GetWidth()); + break; + } + return true; +} + +bool Size::SetProperty(wxSize *p, JSContext *cx, JSObject *obj, int id, jsval *vp) +{ + switch (id) + { + case P_WIDTH: + { + int value; + if ( FromJS(cx, *vp, value) ) + p->SetWidth(value); + break; + } + case P_HEIGHT: + { + int value; + if ( FromJS(cx, *vp, value) ) + p->SetHeight(value); + break; + } + } + return true; +} + +/*** + * + * + * + * The width + * + * + * The height. When not specified and Width is specified the value will be 0. + * + * + * + * Creates a new wxSize. When no arguments are given then wxSize gets the same value + * as wxDefaultSize. + * + * + */ +wxSize* Size::Construct(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, bool constructing) +{ + int x = -1; + int y = -1; + + if ( argc > 0 + && ! FromJS(cx, argv[0], x) ) + return NULL; + + if ( argc > 1 + && ! FromJS(cx, argv[1], y) ) + return NULL; + + return new wxSize(x, y); +} + Property changes on: ps/trunk/source/tools/atlas/wxJS/gui/misc/size.cpp ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/gui/misc/constant.h =================================================================== --- ps/trunk/source/tools/atlas/wxJS/gui/misc/constant.h (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/gui/misc/constant.h (revision 5154) @@ -0,0 +1,44 @@ +/* + * wxJavaScript - constant.h + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: constant.h 598 2007-03-07 20:13:28Z fbraem $ + */ +/** + * @if API + * (c) 2001-2002 Franky Braem (S.A.W.) + * + * This file is part of wxJS. wxJS ports wxWindows to JavaScript + * + * File : constant.h + * Desc. : Ports all wxWindow enumerations and constants to JavaScript + * Created : 06-04-2002 + * L. Update : + * @endif + */ + +namespace wxjs +{ + namespace gui + { + void InitGuiConstants(JSContext *cx, JSObject *obj); + }; // namespace gui +}; // namespace wxjs Property changes on: ps/trunk/source/tools/atlas/wxJS/gui/misc/constant.h ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/gui/misc/autoobj.cpp =================================================================== --- ps/trunk/source/tools/atlas/wxJS/gui/misc/autoobj.cpp (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/gui/misc/autoobj.cpp (revision 5154) @@ -0,0 +1,496 @@ +#include "precompiled.h" + +/* + * wxJavaScript - autoobj.cpp + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: autoobj.cpp 598 2007-03-07 20:13:28Z fbraem $ + */ +// wxJSAutomationObject.cpp +#ifdef __WXMSW__ + +#ifndef WX_PRECOMP + #include +#endif +#include + +#include "../../common/main.h" + +#include "autoobj.h" + +using namespace wxjs; +using namespace wxjs::gui; + +/*** + * misc/autoobj + * gui + * + * The wxAutomationObject class represents an OLE automation object containing + * a single data member, an IDispatch pointer. It contains a number of functions + * that make it easy to perform automation operations, and set and get properties. + * The wxVariant class will not be ported, because wxJS translates every type to + * the corresponding JavaScript type. + * This class is only available on a Windows platform. + * + */ +WXJS_INIT_CLASS(AutomationObject, "wxAutomationObject", 0) + +/*** + * + * + * + * Constructs a new wxAutomationObject object. Unlike + * wxWidgets, this constructor can't take an + * IDispatch pointer because this type can't be used in + * JavaScript. + * + * + */ +wxAutomationObject* AutomationObject::Construct(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, bool constructing) +{ + return new wxAutomationObject(); +} + +WXJS_BEGIN_METHOD_MAP(AutomationObject) + WXJS_METHOD("callMethod", callMethod, 1) + WXJS_METHOD("createInstance", createInstance, 1) + WXJS_METHOD("getInstance", getInstance, 1) + WXJS_METHOD("getObject", getObject, 2) + WXJS_METHOD("getProperty", getProperty, 1) + WXJS_METHOD("putProperty", putProperty, 2) +WXJS_END_METHOD_MAP() + +/*** + * + * + * + * The name of the method to call. + * + * + * A variable list of arguments passed to the method. + * + * + * + * Calls an automation method for this object. When the method + * returns a value it is not returned as a wxVariant but it is converted + * to its corresponding JavaScript type. + *

+ * The following example opens a workbook into Microsoft Excel: + *

+ *   var objExcel = new wxAutomationObject();
+ *
+ *   if ( objExcel.createInstance("Excel.Application") )
+ *   {
+ *      objExcel.putProperty("visible", true);
+ *      var objBooks = new wxAutomationObject();
+ *      objExcel.getObject(objBooks, "workbooks");
+ *      objBooks.callMethod("open", "c:\\temp\\wxjs.xls");
+ *   }
+ *  
+ * The name of the method can contain dot-separated property names, + * to save the application needing to call @wxAutomationObject#getProperty + * several times using several temporary objects. + * For example: + * objExcel.callMethod("workbooks.open", "c:\\temp\\wxjs.xls"); + *
+ *
+ */ +JSBool AutomationObject::callMethod(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxAutomationObject *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + wxString method; + FromJS(cx, argv[0], method); + + wxVariant res; + if ( argc == 0 ) + { + res = p->CallMethod(method); + } + else + { + const wxVariant **vars = new const wxVariant*[argc - 1]; + uint i; + for(i = 1; i < argc; i++) + { + vars[i-1] = CreateVariant(cx, argv[i]); + } + + *rval = CreateJSVal(cx, p->CallMethodArray(method, argc - 1, vars)); + + for(i = 0; i < argc - 1; i++) + delete vars[i]; + delete[] vars; + } + + return JS_FALSE; +} + +/*** + * + * + * + * + * + * Creates a new object based on the class id, returning true if the + * object was successfully created, or false if not. + *

+ * The following example starts Microsoft Excel: + *

+ *  var obj = new wxAutomationObject();
+ *  if ( obj.createInstance("Excel.Application") )
+ *  {
+ *    // Excel object is created
+ *  }
+ *  
+ *
+ *
+ */ +JSBool AutomationObject::createInstance(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxAutomationObject *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + wxString classId; + if ( FromJS(cx, argv[0], classId) ) + { + *rval = ToJS(cx, p->CreateInstance(classId)); + return JS_TRUE; + } + return JS_FALSE; +} + +/*** + * + * + * + * + * + * Retrieves the current object associated with a class id, and attaches + * the IDispatch pointer to this object. Returns true if a pointer was + * successfully retrieved, false otherwise. + * + * + */ +JSBool AutomationObject::getInstance(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxAutomationObject *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + wxString classId; + if ( FromJS(cx, argv[0], classId) ) + { + *rval = ToJS(cx, p->GetInstance(classId)); + return JS_TRUE; + } + return JS_FALSE; +} + +/*** + * + * + * + * The name of the property. + * + * + * + * + * Puts a property value into this object. + * The following example starts Microsoft Excel and makes it visible. + *

+ *  var obj = new wxAutomationObject();
+ *  if ( obj.createInstance("Excel.Application") )
+ *  {
+ *     obj.putProperty("visible", true);
+ *  }
+ *  
+ * The name of the property can contain dot-separated property names, + * to save the application needing to call @wxAutomationObject#getProperty + * several times using several temporary objects. + *
+ *
+ */ +JSBool AutomationObject::putProperty(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxAutomationObject *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + wxString prop; + FromJS(cx, argv[0], prop); + + const wxVariant **vars = new const wxVariant*[argc - 1]; + uint i; + for(i = 1; i < argc; i++) + { + vars[i-1] = CreateVariant(cx, argv[i]); + } + + wxVariant res = p->PutPropertyArray(prop, argc - 1, vars); + + for(i = 0; i < argc - 1; i++) + delete vars[i]; + delete[] vars; + + return JS_TRUE; +} + +/*** + * + * + * + * The name of the property. + * + * + * + * + * Gets a property from this object. The return type depends on the type of the property. + * Use @wxAutomationObject#getObject when the property is an object. + * + * The name of the method can contain dot-separated property names, + * to save the application needing to call @wxAutomationObject#getProperty + * several times using several temporary objects. + * + * + */ +JSBool AutomationObject::getProperty(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxAutomationObject *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + wxString prop; + FromJS(cx, argv[0], prop); + + const wxVariant **vars = new const wxVariant*[argc - 1]; + uint i; + for(i = 1; i < argc; i++) + { + vars[i-1] = CreateVariant(cx, argv[i]); + } + + wxVariant res = p->GetPropertyArray(prop, argc - 1, vars); + *rval = CreateJSVal(cx, res); + + for(i = 0; i < argc - 1; i++) + delete vars[i]; + delete[] vars; + + return JS_TRUE; +} + +/*** + * + * + * + * The automation object that receives the property. + * + * + * The name of the property. + * + * + * + * + * Gets a property from this object. The type of the property is also an object. + * The following example retrieves the object Workbooks from an Excel application: + *

+ *  var objExcel = new wxAutomationObject();
+ *  if ( objExcel.createInstance("Excel.Application") )
+ *  {
+ *    objExcel.putProperty("visible", true);
+ *    var objBooks = new wxAutomationObject();
+ *    objExcel.getObject(objBooks, "workbooks");
+ *  }
+ *  
+ * The name of the method can contain dot-separated property names, + * to save the application needing to call @wxAutomationObject#getProperty + * several times using several temporary objects. + *
+ *
+ */ +JSBool AutomationObject::getObject(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxAutomationObject *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + wxAutomationObject *autoObj = GetPrivate(cx, argv[0]); + if ( autoObj == NULL ) + return JS_FALSE; + + wxString prop; + FromJS(cx, argv[1], prop); + + if ( argc > 2 ) + { + const wxVariant **vars = new const wxVariant*[argc - 2]; + uint i; + for(i = 2; i < argc; i++) + { + vars[i-2] = CreateVariant(cx, argv[i]); + } + + *rval = ToJS(cx, p->GetObject(*autoObj, prop, argc - 2, vars)); + + for(i = 0; i < argc - 2; i++) + { + delete vars[i]; + } + delete[] vars; + } + else + *rval = ToJS(cx, p->GetObject(*autoObj, prop)); + + + return JS_TRUE; +} + +wxVariant *AutomationObject::CreateVariant(JSContext *cx, jsval v) +{ + switch(JS_TypeOfValue(cx, v)) + { + case JSTYPE_VOID: + break; + case JSTYPE_OBJECT: + { + JSObject *obj = JSVAL_TO_OBJECT(v); + if ( js_DateIsValid(cx, obj) ) + { + wxDateTime date; + FromJS(cx, v, date); + return new wxVariant(date); + } + + wxAutomationObject *o = GetPrivate(cx, obj); + if ( o != NULL ) + { + return new wxVariant((void *) o); + } + + if ( JS_IsArrayObject(cx, obj) == JS_TRUE ) + { + } + break; + } + case JSTYPE_FUNCTION: + break; + case JSTYPE_STRING: + { + wxString str; + FromJS(cx, v, str); + return new wxVariant(str); + break; + } + case JSTYPE_NUMBER: + if ( JSVAL_IS_INT(v) ) + { + long value; + FromJS(cx, v, value); + return new wxVariant(value); + } + else if ( JSVAL_IS_DOUBLE(v) ) + { + double value; + FromJS(cx, v, value); + return new wxVariant(value); + } + break; + case JSTYPE_BOOLEAN: + { + bool b; + FromJS(cx, v, b); + return new wxVariant(b); + } + } + + return new wxVariant(); +} + +jsval AutomationObject::CreateJSVal(JSContext *cx, const wxVariant &var) +{ + if ( var.IsNull() ) + return JSVAL_VOID; + + wxString type(var.GetType()); + + if ( type.CompareTo(wxT("string")) == 0 ) + { + return ToJS(cx, var.GetString()); + } + else if ( type.CompareTo(wxT("bool")) == 0 ) + { + return ToJS(cx, var.GetBool()); + } + else if ( type.CompareTo(wxT("list")) == 0 ) + { + wxLogDebug(wxT("List")); + } + else if ( type.CompareTo(wxT("long")) == 0 ) + { + return ToJS(cx, var.GetLong()); + } + else if ( type.CompareTo(wxT("double")) == 0 ) + { + return ToJS(cx, var.GetDouble()); + } + else if ( type.CompareTo(wxT("char")) == 0 ) + { + return ToJS(cx, wxString::FromAscii(var.GetChar())); + } + else if ( type.CompareTo(wxT("time")) == 0 ) + { + return ToJS(cx, var.GetDateTime()); + } + else if ( type.CompareTo(wxT("date")) == 0 ) + { + return ToJS(cx, var.GetDateTime()); + } + else if ( type.CompareTo(wxT("void*")) == 0 ) + { + // void* means an object + void* p = var.GetVoidPtr(); + if ( p != NULL ) + { + // We need to create a new wxAutomationObject because + // otherwise the object is released to early. + wxAutomationObject *o = static_cast(p); + wxAutomationObject *newObj = new wxAutomationObject(); + newObj->SetDispatchPtr(o->GetDispatchPtr()); + return CreateObject(cx, newObj); + } + } + else if ( type.CompareTo(wxT("datetime")) == 0 ) + { + return ToJS(cx, var.GetDateTime()); + } + else if ( type.CompareTo(wxT("arrstring")) == 0 ) + { + return ToJS(cx, var.GetArrayString()); + } + + return JSVAL_VOID; +} + +#endif // WXJS_FOR_UNIX Property changes on: ps/trunk/source/tools/atlas/wxJS/gui/misc/autoobj.cpp ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/gui/misc/fontlist.h =================================================================== --- ps/trunk/source/tools/atlas/wxJS/gui/misc/fontlist.h (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/gui/misc/fontlist.h (revision 5154) @@ -0,0 +1,55 @@ +/* + * wxJavaScript - fontlist.h + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: fontlist.h 598 2007-03-07 20:13:28Z fbraem $ + */ +#ifndef _WXJSFontList_H +#define _WXJSFontList_H + +///////////////////////////////////////////////////////////////////////////// +// Name: fontlist.h +// Purpose: FontList ports wxFontList to JavaScript. +// Author: Franky Braem +// Modified by: +// Created: 08.08.02 +// Copyright: (c) 2001-2002 Franky Braem +// Licence: LGPL +///////////////////////////////////////////////////////////////////////////// + +namespace wxjs +{ + namespace gui + { + class FontList : public ApiWrapper + { + public: + + static JSBool findOrCreate(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval); + + static void Destruct(JSContext *cx, wxFontList *p); + + WXJS_DECLARE_METHOD_MAP() + }; + }; // namespace gui +}; // namespace wxjs + +#endif //_WXJSFontList_H Property changes on: ps/trunk/source/tools/atlas/wxJS/gui/misc/fontlist.h ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/gui/misc/size.h =================================================================== --- ps/trunk/source/tools/atlas/wxJS/gui/misc/size.h (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/gui/misc/size.h (revision 5154) @@ -0,0 +1,63 @@ +/* + * wxJavaScript - size.h + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: size.h 598 2007-03-07 20:13:28Z fbraem $ + */ +///////////////////////////////////////////////////////////////////////////// +// Name: size.h +// Purpose: Ports wxSize to JavaScript +// Author: Franky Braem +// Modified by: +// Created: 30.12.01 +// Copyright: (c) 2001-2002 Franky Braem +// Licence: LGPL +///////////////////////////////////////////////////////////////////////////// + +#ifndef _WXJSSize_H +#define _WXJSSize_H + +namespace wxjs +{ + namespace gui + { + + class Size : public ApiWrapper + { + public: + + static bool GetProperty(wxSize *p, JSContext *cx, JSObject *obj, int id, jsval *vp); + static bool SetProperty(wxSize *p, JSContext *cx, JSObject *obj, int id, jsval *vp); + static wxSize *Construct(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, bool constructing); + enum + { + P_WIDTH + , P_HEIGHT + }; + + WXJS_DECLARE_PROPERTY_MAP() + }; + + void DefineSizeConst(JSContext *cx, JSObject *obj); + }; // namespace gui +}; // namespace wxjs + +#endif //_WXJSSize_H Property changes on: ps/trunk/source/tools/atlas/wxJS/gui/misc/size.h ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/gui/misc/rect.h =================================================================== --- ps/trunk/source/tools/atlas/wxJS/gui/misc/rect.h (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/gui/misc/rect.h (revision 5154) @@ -0,0 +1,82 @@ +/* + * wxJavaScript - rect.h + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: rect.h 598 2007-03-07 20:13:28Z fbraem $ + */ +#ifndef _WXJSRect_H +#define _WXJSRect_H + +///////////////////////////////////////////////////////////////////////////// +// Name: rect.h +// Purpose: Ports wxRect to JavaScript +// Author: Franky Braem +// Modified by: +// Created: 25.05.02 +// Copyright: (c) 2001-2002 Franky Braem +// Licence: LGPL +///////////////////////////////////////////////////////////////////////////// + +namespace wxjs +{ + namespace gui + { + class Rect : public ApiWrapper + { + public: + + static bool GetProperty(wxRect *p, JSContext *cx, JSObject *obj, int id, jsval *vp); + static bool SetProperty(wxRect *p, JSContext *cx, JSObject *obj, int id, jsval *vp); + + static wxRect* Construct(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, bool constructing); + + static JSBool inflate(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval); + static JSBool deflate(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval); + static JSBool offset(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval); + static JSBool intersect(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval); + static JSBool inside(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval); + static JSBool intersects(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval); + + WXJS_DECLARE_PROPERTY_MAP() + WXJS_DECLARE_METHOD_MAP() + + /** + * Property Ids. + */ + enum + { + P_WIDTH + , P_HEIGHT + , P_BOTTOM + , P_LEFT + , P_POSITION + , P_RIGHT + , P_SIZE + , P_TOP + , P_X + , P_Y + }; + }; + }; // namespace gui +}; // namespace wxjs + +#endif //_WXJSRect_H + Property changes on: ps/trunk/source/tools/atlas/wxJS/gui/misc/rect.h ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/gui/misc/font.cpp =================================================================== --- ps/trunk/source/tools/atlas/wxJS/gui/misc/font.cpp (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/gui/misc/font.cpp (revision 5154) @@ -0,0 +1,322 @@ +#include "precompiled.h" + +/* + * wxJavaScript - font.cpp + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: font.cpp 689 2007-04-27 20:45:43Z fbraem $ + */ +// font.cpp + +#ifndef WX_PRECOMP + #include +#endif + +#include "../../common/main.h" +#include "../../common/apiwrap.h" + +#include "font.h" + +using namespace wxjs; +using namespace wxjs::gui; + +/*** + * misc/font + * gui + * + * A font is an object which determines the appearance of text. + * Fonts are used for drawing text to a device context, and setting the + * appearance of a window's text. + * + */ +WXJS_INIT_CLASS(Font, "wxFont", 0) + +/*** + * + * + * + * Get/Set the actual typeface to be used. + * + * + * Font family, a generic way of referring to fonts without specifying an actual facename. + * + * + * Returns true when the font is ok. + * + * + * Get/Set size in points + * + * + * Get/Set the font style + * + * + * Get/Set underline. + * + * + * Get/Set the weight of the font + * + * + */ +WXJS_BEGIN_PROPERTY_MAP(Font) + WXJS_PROPERTY(P_FACE_NAME, "faceName") + WXJS_PROPERTY(P_FAMILY, "family") + WXJS_PROPERTY(P_POINT_SIZE, "pointSize") + WXJS_PROPERTY(P_STYLE, "style") + WXJS_PROPERTY(P_UNDERLINED, "underlined") + WXJS_PROPERTY(P_WEIGHT, "weight") + WXJS_PROPERTY(P_OK, "ok") +WXJS_END_PROPERTY_MAP() + +bool Font::GetProperty(wxFont *p, JSContext *cx, JSObject *obj, int id, jsval *vp) +{ + switch (id) + { + case P_FACE_NAME: + if ( p->Ok() ) + *vp = ToJS(cx, p->GetFaceName()); + break; + case P_FAMILY: + if ( p->Ok() ) + *vp = ToJS(cx, p->GetFamily()); + break; + case P_POINT_SIZE: + if ( p->Ok() ) + *vp = ToJS(cx, p->GetPointSize()); + break; + case P_STYLE: + if ( p->Ok() ) + *vp = ToJS(cx, p->GetStyle()); + break; + case P_UNDERLINED: + if ( p->Ok() ) + *vp = ToJS(cx, p->GetUnderlined()); + break; + case P_WEIGHT: + if ( p->Ok() ) + *vp = ToJS(cx, p->GetWeight()); + break; + case P_OK: + *vp = ToJS(cx, p->Ok()); + break; + } + return true; +} + +bool Font::SetProperty(wxFont *p, JSContext *cx, JSObject *obj, int id, jsval *vp) +{ + switch (id) + { + case P_FACE_NAME: + { + wxString name; + FromJS(cx, *vp, name); + p->SetFaceName(name); + break; + } + case P_FAMILY: + { + int family; + if ( FromJS(cx, *vp, family) ) + p->SetFamily(family); + break; + } + case P_POINT_SIZE: + { + int size; + if ( FromJS(cx, *vp, size) ) + p->SetPointSize(size); + break; + } + case P_STYLE: + { + int style; + if ( FromJS(cx, *vp, style) ) + p->SetStyle(style); + break; + } + case P_UNDERLINED: + { + bool underlined; + if ( FromJS(cx, *vp, underlined) ) + p->SetUnderlined(underlined); + break; + } + case P_WEIGHT: + { + int weight; + if ( FromJS(cx, *vp, weight) ) + p->SetWeight(weight); + break; + } + } + + return true; +} + +/*** + * + * + * Get/Set the default encoding + * + * + */ +WXJS_BEGIN_STATIC_PROPERTY_MAP(Font) + WXJS_STATIC_PROPERTY(P_DEFAULT_ENCODING, "defaultEncoding") +WXJS_END_PROPERTY_MAP() + +bool Font::GetStaticProperty(JSContext *cx, int id, jsval *vp) +{ + if ( id == P_DEFAULT_ENCODING ) + { + *vp = ToJS(cx, (int)wxFont::GetDefaultEncoding()); + } + return true; +} + +bool Font::SetStaticProperty(JSContext *cx, int id, jsval *vp) +{ + if ( id == P_DEFAULT_ENCODING ) + { + int encoding; + FromJS(cx, *vp, encoding); + wxFont::SetDefaultEncoding((wxFontEncoding) encoding); + } + return true; +} + +/*** + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + */ +WXJS_BEGIN_CONSTANT_MAP(Font) + // Family constants + WXJS_CONSTANT(wx, DEFAULT) + WXJS_CONSTANT(wx, DECORATIVE) + WXJS_CONSTANT(wx, ROMAN) + WXJS_CONSTANT(wx, SCRIPT) + WXJS_CONSTANT(wx, SWISS) + WXJS_CONSTANT(wx, MODERN) + // Style constants + WXJS_CONSTANT(wx, NORMAL) + WXJS_CONSTANT(wx, SLANT) + WXJS_CONSTANT(wx, ITALIC) + // Weight constants + WXJS_CONSTANT(wx, LIGHT) + WXJS_CONSTANT(wx, BOLD) +WXJS_END_CONSTANT_MAP() + +/*** + * + * + * + * + * Size in points + * + * + * Font family, a generic way of referring to fonts without specifying actual facename. + * + * + * Font style + * + * + * Font weight + * + * + * + * An optional string specifying the actual typeface to be used. + * When not specified, a default typeface will chosen based on the family. + * + * + * + * + * Constructs a new wxFont object. + * + * + */ +wxFont* Font::Construct(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, bool constructing) +{ + if ( argc == 0 ) + { + return new wxFont(); + } + else if ( argc > 7 ) + argc = 7; + + int pointSize = 0; + int family = 0; + int style = 0; + int weight = 0; + bool underline = false; + wxString faceName; + int encoding = wxFONTENCODING_DEFAULT; + + switch(argc) + { + case 7: + if ( ! FromJS(cx, argv[6], encoding) ) + break; + // Walk through + case 6: + FromJS(cx, argv[5], faceName); + // Walk through + case 5: + if ( ! FromJS(cx, argv[4], underline) ) + break; + // Walk through + case 4: + if ( ! FromJS(cx, argv[3], weight) ) + break; + // Walk through + case 3: + if ( ! FromJS(cx, argv[2], style) ) + break; + // Walk through + case 2: + if ( ! FromJS(cx, argv[1], family) ) + break; + // Walk through + case 1: + if ( ! FromJS(cx, argv[0], pointSize) ) + break; + return new wxFont(pointSize, family, style, + weight, underline, + faceName, (wxFontEncoding) encoding); + } + return NULL; +} Property changes on: ps/trunk/source/tools/atlas/wxJS/gui/misc/font.cpp ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/gui/misc/xpmhdlr.cpp =================================================================== --- ps/trunk/source/tools/atlas/wxJS/gui/misc/xpmhdlr.cpp (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/gui/misc/xpmhdlr.cpp (revision 5154) @@ -0,0 +1,53 @@ +#include "precompiled.h" + +/* + * wxJavaScript - xpmhdlr.cpp + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: xpmhdlr.cpp 598 2007-03-07 20:13:28Z fbraem $ + */ +// imghand.cpp + +#ifndef WX_PRECOMP + #include +#endif + +#include "../../common/main.h" +#include "../../common/type.h" +#include "../../common/jsutil.h" + +#include "imghand.h" +using namespace wxjs; +using namespace wxjs::gui; + +/*** + * misc/xpmhdlr + * gui + * + * Image handler for XPM images. + * + */ +WXJS_INIT_CLASS(XPMHandler, "wxXPMHandler", 0) + +ImageHandlerPrivate* XPMHandler::Construct(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, bool constructing) +{ + return new ImageHandlerPrivate(new wxXPMHandler(), true); +}; Property changes on: ps/trunk/source/tools/atlas/wxJS/gui/misc/xpmhdlr.cpp ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/gui/misc/icohdlr.cpp =================================================================== --- ps/trunk/source/tools/atlas/wxJS/gui/misc/icohdlr.cpp (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/gui/misc/icohdlr.cpp (revision 5154) @@ -0,0 +1,51 @@ +#include "precompiled.h" + +/* + * wxJavaScript - icohdlr.cpp + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: icohdlr.cpp 598 2007-03-07 20:13:28Z fbraem $ + */ +#ifndef WX_PRECOMP + #include +#endif + +#include "../../common/main.h" +#include "../../common/type.h" +#include "../../common/jsutil.h" + +#include "imghand.h" +using namespace wxjs; +using namespace wxjs::gui; + +/*** + * misc/icohdlr + * gui + * + * Image handler for icons. + * + */ +WXJS_INIT_CLASS(ICOHandler, "wxICOHandler", 0) + +ImageHandlerPrivate* ICOHandler::Construct(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, bool constructing) +{ + return new ImageHandlerPrivate(new wxICOHandler(), true); +} Property changes on: ps/trunk/source/tools/atlas/wxJS/gui/misc/icohdlr.cpp ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/gui/misc/gifhdlr.cpp =================================================================== --- ps/trunk/source/tools/atlas/wxJS/gui/misc/gifhdlr.cpp (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/gui/misc/gifhdlr.cpp (revision 5154) @@ -0,0 +1,54 @@ +#include "precompiled.h" + +/* + * wxJavaScript - gifhdlr.cpp + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: gifhdlr.cpp 598 2007-03-07 20:13:28Z fbraem $ + */ +#ifndef WX_PRECOMP + #include +#endif + +#include "../../common/main.h" +#include "../../common/type.h" +#include "../../common/jsutil.h" + +#include "imghand.h" + +using namespace wxjs; +using namespace wxjs::gui; + +/*** + * misc/gifhdlr + * gui + * + * Image handler for PNG images. + * Image handler for GIF images. Due to legal issues, writing a gif image is not available. + * + */ +WXJS_INIT_CLASS(GIFHandler, "wxGIFHandler", 0) + +ImageHandlerPrivate* GIFHandler::Construct(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, bool constructing) +{ + return new ImageHandlerPrivate(new wxGIFHandler(), true); +}; + Property changes on: ps/trunk/source/tools/atlas/wxJS/gui/misc/gifhdlr.cpp ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/gui/misc/point.cpp =================================================================== --- ps/trunk/source/tools/atlas/wxJS/gui/misc/point.cpp (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/gui/misc/point.cpp (revision 5154) @@ -0,0 +1,129 @@ +#include "precompiled.h" + +/* + * wxJavaScript - point.cpp + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: point.cpp 598 2007-03-07 20:13:28Z fbraem $ + */ +// point.cpp + +#ifndef WX_PRECOMP + #include +#endif + +#include "../../common/main.h" + +#include "point.h" +using namespace wxjs; +using namespace wxjs::gui; + +/*** + * misc/point + * gui + * + * A wxPoint is a useful data structure for graphics operations. + * It simply contains integer x and y members. + * + */ +WXJS_INIT_CLASS(Point, "wxPoint", 0) + +/*** + * + * + * The x-coordinate. + * + * + * The y-coordinate. + * + * + */ +WXJS_BEGIN_PROPERTY_MAP(Point) + WXJS_PROPERTY(P_X, "x") + WXJS_PROPERTY(P_Y, "y") +WXJS_END_PROPERTY_MAP() + +bool Point::GetProperty(wxPoint *p, JSContext *cx, JSObject *obj, int id, jsval *vp) +{ + switch (id) + { + case P_X: + *vp = ToJS(cx, p->x); + break; + case P_Y: + *vp = ToJS(cx, p->y); + break; + } + return true; +} + +bool Point::SetProperty(wxPoint *p, JSContext *cx, JSObject *obj, int id, jsval *vp) +{ + switch (id) + { + case P_X: + FromJS(cx, *vp, p->x); + break; + case P_Y: + FromJS(cx, *vp, p->y); + break; + } + return true; +} + +/*** + * + * + * + * The X-coordinate + * + * + * The Y-coordinate. + * + * + * + * Creates a new wxPoint. When no arguments are given then wxPoint gets the same value + * as wxDefaultPosition. + * + * + */ +wxPoint* Point::Construct(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, bool constructing) +{ + if ( argc == 0 ) + { + return new wxPoint(); + } + else + { + int x = 0; + int y = 0; + if ( argc > 0 ) + { + FromJS(cx, argv[0], x); + } + + if ( argc > 1 ) + { + FromJS(cx, argv[1], y); + } + return new wxPoint(x, y); + } +} Property changes on: ps/trunk/source/tools/atlas/wxJS/gui/misc/point.cpp ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/gui/misc/fontlist.cpp =================================================================== --- ps/trunk/source/tools/atlas/wxJS/gui/misc/fontlist.cpp (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/gui/misc/fontlist.cpp (revision 5154) @@ -0,0 +1,114 @@ +#include "precompiled.h" + +/* + * wxJavaScript - fontlist.cpp + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: fontlist.cpp 598 2007-03-07 20:13:28Z fbraem $ + */ +// fontlist.cpp +#ifndef WX_PRECOMP + #include +#endif + +#include "../../common/main.h" + +#include "font.h" +#include "fontlist.h" + +using namespace wxjs; +using namespace wxjs::gui; + +/*** + * misc/fontlist + * gui + * + * A font list is a list containing all fonts which have been created. + * There is only one instance of this class: wxTheFontList. Use this object + * to search for a previously created font of the desired type and create it + * if not already found. In some windowing systems, the font may be a scarce resource, + * so it is best to reuse old resources if possible. + * When an application finishes, all fonts will be deleted and their resources freed, + * eliminating the possibility of 'memory leaks'. + * See @wxFont, @wxFontEncoding and @wxFontEnumerator + * + */ +WXJS_INIT_CLASS(FontList, "wxFontList", 0) + +// To avoid delete of wxTheFontList +void FontList::Destruct(JSContext *cx, wxFontList *p) +{ +} + +WXJS_BEGIN_METHOD_MAP(FontList) + WXJS_METHOD("findOrCreateFont", findOrCreate, 7) +WXJS_END_METHOD_MAP() + +/*** + * + * + * + * + * + * + * + * + * + * + * + * Finds a font of the given specification, or creates one and adds it to the list. + * The following code shows an example: + * + * var font = wxTheFontList.findOrCreateFont(10, wxFont.DEFAULT, wxFont.NORMAL, wxFont.NORMAL); + * + * + * + */ +JSBool FontList::findOrCreate(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + int point; + int family; + int style; + int weight; + bool underline = false; + JSString *faceName = NULL; + int encoding = wxFONTENCODING_DEFAULT; + + if ( JS_ConvertArguments(cx, argc, argv, "iiii/bSi", &point, &family, &style, + &weight, &underline, &faceName, &encoding) == JS_TRUE ) + { + wxString face; + if ( faceName == NULL ) + { + face = wxEmptyString; + } + else + { + face = (wxChar *) JS_GetStringChars(faceName); + } + *rval = Font::CreateObject(cx, wxTheFontList->FindOrCreateFont(point, family, style, + weight, underline, face, + (wxFontEncoding) encoding)); + return JS_TRUE; + } + else + return JS_FALSE; +} Property changes on: ps/trunk/source/tools/atlas/wxJS/gui/misc/fontlist.cpp ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/gui/misc/imagelst.cpp =================================================================== --- ps/trunk/source/tools/atlas/wxJS/gui/misc/imagelst.cpp (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/gui/misc/imagelst.cpp (revision 5154) @@ -0,0 +1,440 @@ +#include "precompiled.h" + +/* + * wxJavaScript - imagelst.cpp + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: imagelst.cpp 734 2007-06-06 20:09:13Z fbraem $ + */ +// imagelst.cpp + +#ifndef WX_PRECOMP + #include +#endif + +/** + * @if JS + * @page wxImageList wxImageList + * @since version 0.5 + * @endif + */ + +#include "../../common/main.h" + +#include "imagelst.h" +#include "bitmap.h" +#include "colour.h" +#include "icon.h" +#include "size.h" + +using namespace wxjs; +using namespace wxjs::gui; + +ImageList::ImageList() : wxClientDataContainer() +{ +} + +/*** + * control/imagelst + * gui + * + * A wxImageList contains a list of images, which are stored in an unspecified form. + * Images can have masks for transparent drawing, and can be made from a variety of + * sources including bitmaps and icons. + *

+ * wxImageList is used principally in conjunction with @wxTreeCtrl and + * @wxListCtrl classes. + *
+ */ +WXJS_INIT_CLASS(ImageList, "wxImageList", 2) + +/*** + * + * + * Returns the number of the images. + * + * + */ +WXJS_BEGIN_PROPERTY_MAP(ImageList) + WXJS_READONLY_PROPERTY(P_IMAGE_COUNT, "imageCount") +WXJS_END_PROPERTY_MAP() + +bool ImageList::GetProperty(wxImageList *p, + JSContext *cx, + JSObject* WXUNUSED(obj), + int id, + jsval *vp) +{ + if ( id == P_IMAGE_COUNT ) + *vp = ToJS(cx, p->GetImageCount()); + return true; +} + +/*** + * + * + * + * + * The width of the images in the list + * + * + * The height of the images in the list. + * + * + * When true (default) a mask is created for each image. + * + * + * The size of the list. + * + * + * + * Constructs a new wxImageList object. + * + * + */ +ImageList* ImageList::Construct(JSContext *cx, + JSObject *obj, + uintN argc, + jsval *argv, + bool WXUNUSED(constructing)) +{ + ImageList *p = new ImageList(); + SetPrivate(cx, obj, p); + + if ( argc > 0 ) + { + jsval rval; + create(cx, obj, argc, argv, &rval); + } + return p; +} + +WXJS_BEGIN_METHOD_MAP(ImageList) + WXJS_METHOD("create", create, 2) + WXJS_METHOD("add", add, 1) + WXJS_METHOD("draw", draw, 4) + WXJS_METHOD("getSize", getSize, 2) + WXJS_METHOD("remove", remove, 1) + WXJS_METHOD("removeAll", removeAll, 0) + WXJS_METHOD("replace", replace, 2) +WXJS_END_METHOD_MAP() + +/*** + * + * + * + * The width of the images in the list + * + * + * The height of the images in the list. + * + * + * When true (default) a mask is created for each image. + * + * + * The size of the list. + * + * + * + * Creates an image list. Width and Height specify the size of the images + * in the list (all the same). Mask specifies whether the images have masks or not. + * Count is the initial number of images to reserve. + * + * + */ +JSBool ImageList::create(JSContext *cx, + JSObject *obj, + uintN argc, + jsval *argv, + jsval *rval) +{ + ImageList *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + if ( argc > 4 ) + argc = 4; + + bool mask = true; + int count = 1; + + switch(argc) + { + case 4: + if ( ! FromJS(cx, argv[3], count) ) + break; + // Fall through + case 3: + if ( ! FromJS(cx, argv[2], mask) ) + break; + // Fall through + default: + int width; + int height; + + if ( FromJS(cx, argv[1], height) + && FromJS(cx, argv[0], width) ) + { + p->Create(width, height, mask, count); + p->SetClientObject(new JavaScriptClientData(cx, obj, false, false)); + return JS_TRUE; + } + } + return JS_FALSE; +} + +/*** + * + * + * + * + * + * + * + * + * + * + * + * + * + * Adds a new image using a bitmap and an optional mask bitmap + * or adds a new image using a bitmap and a mask colour + * or adds a new image using an icon. + * Returns the new zero-based index of the image. + * + * + */ +JSBool ImageList::add(JSContext *cx, + JSObject *obj, + uintN argc, + jsval *argv, + jsval *rval) +{ + wxImageList *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + if ( Icon::HasPrototype(cx, argv[0]) ) + { + wxIcon *ico = Icon::GetPrivate(cx, argv[0]); + if ( ico != NULL ) + { + *rval = ToJS(cx, p->Add(*ico)); + return JS_TRUE; + } + } + else + { + wxBitmap *bmp = Bitmap::GetPrivate(cx, argv[0], false); + const wxBitmap *mask = &wxNullBitmap; + if ( argc == 2 ) + { + if ( Colour::HasPrototype(cx, argv[1]) ) + { + wxColour *colour = Colour::GetPrivate(cx, argv[1]); + if ( colour != NULL ) + { + *rval = ToJS(cx, p->Add(*bmp, *colour)); + return JS_TRUE; + } + } + else + { + mask = Bitmap::GetPrivate(cx, argv[1]); + if ( mask == NULL ) + return JS_FALSE; + } + } + *rval = ToJS(cx, p->Add(*bmp, *mask)); + return JS_TRUE; + } + return JS_FALSE; +} + +JSBool ImageList::draw(JSContext *cx, + JSObject *obj, + uintN argc, + jsval *argv, + jsval *rval) +{ + wxImageList *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + return JS_FALSE; +} + +/*** + * + * + * + * The index parameter is ignored as all images in the list have the same size. + * + * + * Receives the size of the image. + * + * + * + * The size is put in the Size argument. This method differs from the wxWindow function + * GetSize which uses 3 arguments: index, width and height. wxJS uses @wxSize because JavaScript + * can't pass primitive types by reference. + * + * + */ +JSBool ImageList::getSize(JSContext *cx, + JSObject *obj, + uintN argc, + jsval *argv, + jsval *rval) +{ + wxImageList *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + int index = 0; + wxSize *size = Size::GetPrivate(cx, argv[1]); + if ( size != NULL ) + { + int width; + int height; + *rval = ToJS(cx, p->GetSize(index, width, height)); + size->SetWidth(width); + size->SetHeight(height); + return JS_TRUE; + } + + return JS_FALSE; +} + +/*** + * + * + * + * The index of the image. + * + * + * + * Removes the image with the given index. Returns true on success. + * + * + */ +JSBool ImageList::remove(JSContext *cx, + JSObject *obj, + uintN argc, + jsval *argv, + jsval *rval) +{ + wxImageList *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + int index; + if ( FromJS(cx, argv[0], index) ) + { + *rval = ToJS(cx, p->Remove(index)); + return JS_TRUE; + } + + return JS_FALSE; +} + +/*** + * + * + * + * Removes all images. Returns true on success. + * + * + */ +JSBool ImageList::removeAll(JSContext *cx, + JSObject *obj, + uintN argc, + jsval *argv, + jsval *rval) +{ + wxImageList *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + *rval = ToJS(cx, p->RemoveAll()); + return JS_TRUE; +} + +/*** + * + * + * + * The index of the image to replace. + * + * + * The new bitmap. + * + * + * Monochrome mask bitmap, representing the transparent areas of the image. + * Windows only. + * + * + * + * + * The index of the image to replace. + * + * + * Icon to use as image. + * + * + * + * Replaces the image at the given index with a new image. + * + * + */ +JSBool ImageList::replace(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxImageList *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + int index; + if ( ! FromJS(cx, argv[0], index) ) + return JS_FALSE; + + if ( Bitmap::HasPrototype(cx, argv[1]) ) + { + #ifdef __WXMSW__ + wxBitmap *bmp = Bitmap::GetPrivate(cx, argv[1], false); + const wxBitmap *mask = &wxNullBitmap; + if ( argc == 3 + && (mask = Bitmap::GetPrivate(cx, argv[2])) == NULL ) + return JS_FALSE; + *rval = ToJS(cx, p->Replace(index, *bmp, *mask)); + #endif + return JS_TRUE; + } + else + { + wxIcon *ico = Icon::GetPrivate(cx, argv[0]); + if ( ico != NULL ) + { + *rval = ToJS(cx, p->Replace(index, *ico)); + return JS_TRUE; + } + } + return JS_FALSE; +} Property changes on: ps/trunk/source/tools/atlas/wxJS/gui/misc/imagelst.cpp ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/gui/misc/boxsizer.h =================================================================== --- ps/trunk/source/tools/atlas/wxJS/gui/misc/boxsizer.h (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/gui/misc/boxsizer.h (revision 5154) @@ -0,0 +1,61 @@ +/* + * wxJavaScript - boxsizer.h + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: boxsizer.h 715 2007-05-18 20:38:04Z fbraem $ + */ +#ifndef _WXJSBoxSizer_H +#define _WXJSBoxSizer_H + +namespace wxjs +{ + namespace gui + { + class BoxSizer : public ApiWrapper + { + public: + + /** + * Callback for when a wxBoxSizer object is created + */ + static wxBoxSizer* Construct(JSContext *cx, + JSObject *obj, + uintN argc, + jsval *argv, + bool constructing); + + static bool GetProperty(wxBoxSizer *p, + JSContext *cx, + JSObject *obj, + int id, + jsval *vp); + + WXJS_DECLARE_PROPERTY_MAP() + + enum + { + P_ORIENTATION + }; + }; + }; // namespace gui +}; // namespace wxjs + +#endif //_WXJSBoxSizer_H Property changes on: ps/trunk/source/tools/atlas/wxJS/gui/misc/boxsizer.h ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/gui/misc/validate.h =================================================================== --- ps/trunk/source/tools/atlas/wxJS/gui/misc/validate.h (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/gui/misc/validate.h (revision 5154) @@ -0,0 +1,96 @@ +/* + * wxJavaScript - validate.h + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: validate.h 739 2007-06-08 20:51:47Z fbraem $ + */ +#ifndef _WXJSValidator_H +#define _WXJSValidator_H + +namespace wxjs +{ + namespace gui + { + class Validator : public wxValidator + , public ApiWrapper + { + public: + + Validator(); + + Validator(const Validator ©); + + virtual wxObject *Clone() const + { + return new Validator(*this); + } + + virtual ~Validator() + { + } + + /** + * Validate forwards the validation to the validate method of the JavaScript object. + */ + virtual bool Validate(wxWindow *parent); + + /** + * TransferToWindow forwards this to the transferToWindow method of the JavaScript object. + */ + virtual bool TransferToWindow(); + + /** + * TransferFromWindow forwards this to the transferFromWindow method of the JavaScript object. + */ + virtual bool TransferFromWindow(); + + static bool GetProperty(wxValidator *p, + JSContext *cx, + JSObject *obj, + int id, + jsval *vp); + static bool SetProperty(wxValidator *p, + JSContext *cx, + JSObject *obj, + int id, + jsval *vp); + + static wxValidator* Construct(JSContext *cx, + JSObject *obj, + uintN argc, + jsval *argv, + bool constructing); + + WXJS_DECLARE_PROPERTY_MAP() + + /** + * Property Ids. + */ + enum + { + P_WINDOW + , P_BELL_ON_ERROR + }; + }; + }; // namespace gui +}; // namespace wxjs + +#endif //_WXJSValidator_H Property changes on: ps/trunk/source/tools/atlas/wxJS/gui/misc/validate.h ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/gui/misc/boxsizer.cpp =================================================================== --- ps/trunk/source/tools/atlas/wxJS/gui/misc/boxsizer.cpp (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/gui/misc/boxsizer.cpp (revision 5154) @@ -0,0 +1,99 @@ +#include "precompiled.h" + +/* + * wxJavaScript - boxsizer.cpp + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: boxsizer.cpp 733 2007-06-05 21:17:25Z fbraem $ + */ +// boxsizer.cpp +#ifndef WX_PRECOMP + #include +#endif + +#include "../../common/main.h" +#include "../../common/apiwrap.h" + +#include "sizer.h" +#include "boxsizer.h" + +using namespace wxjs; +using namespace wxjs::gui; + +/*** + * misc/boxsizer + * gui + * + * The basic idea behind a box sizer is that windows will most often be laid out in + * rather simple basic geometry, typically in a row or a column or several hierarchies of either. + * + */ +WXJS_INIT_CLASS(BoxSizer, "wxBoxSizer", 1) + +/*** + * + * + * Gets the orientation. See @wxOrientation + * + * + */ +WXJS_BEGIN_PROPERTY_MAP(BoxSizer) + WXJS_READONLY_PROPERTY(P_ORIENTATION, "orientation") +WXJS_END_PROPERTY_MAP() + +bool BoxSizer::GetProperty(wxBoxSizer *p, JSContext *cx, JSObject *obj, int id, jsval *vp) +{ + if ( id == P_ORIENTATION ) + { + *vp = ToJS(cx, p->GetOrientation()); + } + return true; +} + +/*** + * + * + * + * Orientation VERTICAL or HORIZONTAL for creating either a column + * or row sizer. See @wxOrientation + * + * + * + * Creates a new wxBoxSizer object + * + * + */ +wxBoxSizer *BoxSizer::Construct(JSContext *cx, + JSObject *obj, + uintN argc, + jsval *argv, + bool constructing) +{ + int orient = wxVERTICAL; + + if ( FromJS(cx, argv[0], orient) ) + { + wxBoxSizer *p = new wxBoxSizer(orient); + p->SetClientObject(new JavaScriptClientData(cx, obj, false, true)); + return p; + } + return NULL; +} Property changes on: ps/trunk/source/tools/atlas/wxJS/gui/misc/boxsizer.cpp ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/gui/misc/colourdb.h =================================================================== --- ps/trunk/source/tools/atlas/wxJS/gui/misc/colourdb.h (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/gui/misc/colourdb.h (revision 5154) @@ -0,0 +1,59 @@ +/* + * wxJavaScript - colourdb.h + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: colourdb.h 598 2007-03-07 20:13:28Z fbraem $ + */ +#ifndef _WXJSColourDatabase_H +#define _WXJSColourDatabase_H + +///////////////////////////////////////////////////////////////////////////// +// Name: colourdb.h +// Purpose: ColourDatabase ports wxColourDatabase to JavaScript +// Author: Franky Braem +// Modified by: +// Created: 26.09.2002 +// Copyright: (c) 2001-2002 Franky Braem +// Licence: LGPL +///////////////////////////////////////////////////////////////////////////// + +namespace wxjs +{ + namespace gui + { + class ColourDatabase : public ApiWrapper + { + public: + WXJS_DECLARE_METHOD_MAP() + + // Empty, to avoid deleting the colour database. + // This is automatically done by wxWindows + static void Destruct(JSContext *cx, wxColourDatabase *p) + { + } + + static JSBool find(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval); + static JSBool findName(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval); + }; + }; // namespace gui +}; // namespace wxjs + +#endif //_WXJSColourDatabase_H Property changes on: ps/trunk/source/tools/atlas/wxJS/gui/misc/colourdb.h ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/gui/misc/image.cpp =================================================================== --- ps/trunk/source/tools/atlas/wxJS/gui/misc/image.cpp (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/gui/misc/image.cpp (revision 5154) @@ -0,0 +1,1624 @@ +#include "precompiled.h" + +/* + * wxJavaScript - image.cpp + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: image.cpp 598 2007-03-07 20:13:28Z fbraem $ + */ +// image.cpp + +#ifndef WX_PRECOMP + #include +#endif + +#include "../../common/main.h" +#include "../../common/jsutil.h" + +#include "image.h" +#include "size.h" +#include "rect.h" +#include "point.h" +#include "colour.h" +#include "imghand.h" + +#include "../../io/jsstream.h" + +using namespace wxjs; +using namespace wxjs::gui; + +/*** + * misc/image + * gui + * + * This class encapsulates a platform-independent image. An image can be loaded from a + * file in a variety of formats. + * + */ +WXJS_INIT_CLASS(Image, "wxImage", 0) + +/*** + * + * + * Returns true when a mask is active. + * + * + * Returns true when a palette is used. + * + * + * Gets the height of the image in pixels. + * + * + * Specifies whether there is a mask or not. The area of the mask is determined + * by the current mask colour. + * + * + * Returns the blue value of the mask colour. + * + * + * Returns the green value of the mask colour. + * + * + * Returns the red value of the mask colour. + * + * + * Returns true when the image data is available. + * + * + * Returns the size of the image in pixels. + * + * + * Returns the width of the image in pixels. + * + * + */ +WXJS_BEGIN_PROPERTY_MAP(Image) + WXJS_READONLY_PROPERTY(P_OK, "ok") + WXJS_PROPERTY(P_MASK_RED, "maskRed") + WXJS_PROPERTY(P_MASK_GREEN, "maskGreen") + WXJS_PROPERTY(P_MASK_BLUE, "maskBlue") + WXJS_PROPERTY(P_WIDTH, "width") + WXJS_PROPERTY(P_HEIGHT, "height") + WXJS_PROPERTY(P_MASK, "mask") + WXJS_READONLY_PROPERTY(P_HAS_MASK, "hasMask") + WXJS_READONLY_PROPERTY(P_HAS_PALETTE, "hasPalette") + WXJS_PROPERTY(P_PALETTE, "palette") + WXJS_READONLY_PROPERTY(P_SIZE, "size") +WXJS_END_PROPERTY_MAP() + +bool Image::GetProperty(wxImage *p, JSContext *cx, JSObject *obj, int id, jsval *vp) +{ + switch (id) + { + case P_OK: + *vp = ToJS(cx, p->Ok()); + break; + case P_MASK_RED: + *vp = ToJS(cx, (int) p->GetMaskRed()); + break; + case P_MASK_GREEN: + *vp = ToJS(cx, (int) p->GetMaskGreen()); + break; + case P_MASK_BLUE: + *vp = ToJS(cx, (int) p->GetMaskBlue()); + break; + case P_WIDTH: + *vp = ToJS(cx, p->GetWidth()); + break; + case P_HEIGHT: + *vp = ToJS(cx, p->GetHeight()); + break; + case P_MASK: + case P_HAS_MASK: + *vp = ToJS(cx, p->HasMask()); + break; + case P_HAS_PALETTE: + *vp = ToJS(cx, p->HasPalette()); + break; + case P_PALETTE: + *vp = JSVAL_VOID; + break; + case P_SIZE: + *vp = Size::CreateObject(cx, new wxSize(p->GetWidth(), p->GetHeight())); + break; + } + return true; +} + +bool Image::SetProperty(wxImage *p, JSContext *cx, JSObject *obj, int id, jsval *vp) +{ + switch (id) + { + case P_MASK_RED: + { + int maskRed; + if ( FromJS(cx, *vp, maskRed) ) + { + unsigned char g = p->GetMaskGreen(); + unsigned char b = p->GetMaskBlue(); + p->SetMaskColour((unsigned char) maskRed, g, b); + } + break; + } + case P_MASK_GREEN: + { + int maskGreen; + if ( FromJS(cx, *vp, maskGreen) ) + { + unsigned char r = p->GetMaskRed(); + unsigned char b = p->GetMaskBlue(); + p->SetMaskColour(r, (unsigned char) maskGreen, b); + } + break; + } + case P_MASK_BLUE: + { + int maskBlue; + if ( FromJS(cx, *vp, maskBlue) ) + { + unsigned char r = p->GetMaskRed(); + unsigned char g = p->GetMaskGreen(); + p->SetMaskColour(r, g, (unsigned char) maskBlue); + } + break; + } + case P_MASK: + { + bool mask; + if ( FromJS(cx, *vp, mask) ) + p->SetMask(mask); + break; + } + case P_PALETTE: + break; + } + return true; +} + +/*** + * + * + * Array of @wxImageHandler elements. Get the available list of image handlers. + * + * + */ +WXJS_BEGIN_STATIC_PROPERTY_MAP(Image) + WXJS_READONLY_PROPERTY(P_HANDLERS, "handlers") +WXJS_END_PROPERTY_MAP() + +bool Image::GetStaticProperty(JSContext *cx, int id, jsval *vp) +{ + if ( id == P_HANDLERS ) + { + wxList handlers = wxImage::GetHandlers(); + jsint count = handlers.GetCount(); + JSObject *objHandlers = JS_NewArrayObject(cx, count, NULL); + + *vp = OBJECT_TO_JSVAL(objHandlers); + + jsint i = 0; + for ( wxNode *node = handlers.GetFirst(); node; node = node->GetNext() ) + { + wxImageHandler *handler = (wxImageHandler*) node->GetData(); + ImageHandlerPrivate *priv = new ImageHandlerPrivate(handler, false); + jsval element = ImageHandler::CreateObject(cx, priv, NULL); + JS_SetElement(cx, objHandlers, i++, &element); + } + } + return true; +} + +/*** + * + * + * + * + * The width of the image. + * + * + * The height of the image. + * + * + * + * + * The size of the image. + * + * + * + * + * The name of a file from which to load the image. + * + * + * The type of the image. + * + * + * + * + * The name of a file from which to load the image. + * + * + * The MIME type of the image. + * + * + * + */ +wxImage* Image::Construct(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, bool constructing) +{ + if ( argc == 0 ) + return new wxImage(); + + if ( Size::HasPrototype(cx, argv[0]) ) + { + wxSize *size = Size::GetPrivate(cx, argv[0], false); + return new wxImage(size->GetWidth(), size->GetHeight()); + } + + if ( JSVAL_IS_INT(argv[0]) ) + { + int width; + int height; + + if ( FromJS(cx, argv[0], width) + && FromJS(cx, argv[1], height) ) + return new wxImage(width, height); + + return NULL; + } + + wxString name; + FromJS(cx, argv[0], name); + + long type = wxBITMAP_TYPE_ANY; + + if ( argc > 1 ) + { + if ( JSVAL_IS_INT(argv[1]) ) + { + if ( ! FromJS(cx, argv[1], type) ) + return NULL; + } + else + { + wxString mimetype; + FromJS(cx, argv[1], mimetype); + return new wxImage(name, mimetype); + } + } + + return new wxImage(name, type); +} + +WXJS_BEGIN_METHOD_MAP(Image) + WXJS_METHOD("create", create, 1) + WXJS_METHOD("destroy", destroy, 0) + WXJS_METHOD("copy", copy, 0) + WXJS_METHOD("getSubImage", getSubImage, 1) + WXJS_METHOD("paste", paste, 3) + WXJS_METHOD("scale", scale, 1) + WXJS_METHOD("rescale", rescale, 1) + WXJS_METHOD("rotate", rotate, 2) + WXJS_METHOD("rotate90", rotate90, 0) + WXJS_METHOD("mirror", mirror, 0) + WXJS_METHOD("replace", replace, 2) + WXJS_METHOD("convertToMono", convertToMono, 1) + WXJS_METHOD("setRGB", setRGB, 3) + WXJS_METHOD("getRed", getRed, 2) + WXJS_METHOD("getGreen", getGreen, 2) + WXJS_METHOD("getBlue", getBlue, 2) + WXJS_METHOD("getColour", getColour, 2) + WXJS_METHOD("findFirstUnusedColour", findFirstUnusedColour, 2) + WXJS_METHOD("setMaskFromImage", setMaskFromImage, 2) + WXJS_METHOD("loadFile", loadFile, 1) + WXJS_METHOD("saveFile", saveFile, 2) + WXJS_METHOD("setMaskColour", setMaskColour, 1) + WXJS_METHOD("setOption", setOption, 2) + WXJS_METHOD("getOption", getOption, 1) + WXJS_METHOD("getOptionInt", getOptionInt, 1) + WXJS_METHOD("hasOption", hasOption, 1) +WXJS_END_METHOD_MAP() + +/*** + * + * + * + * The width of the image. + * + * + * The height of the image. + * + * + * + * + * The size of the image. + * + * + * + * Creates a fresh image with the given size. + * + * + */ +JSBool Image::create(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxImage *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + if ( Size::HasPrototype(cx, argv[0]) ) + { + wxSize *size = Size::GetPrivate(cx, argv[0], false); + p->Create(size->GetWidth(), size->GetHeight()); + return JS_TRUE; + } + else if ( argc == 2 ) + { + int width; + int height; + if ( FromJS(cx, argv[0], width) + && FromJS(cx, argv[1], height) ) + { + p->Create(width, height); + return JS_TRUE; + } + } + return JS_FALSE; +} + +/*** + * + * + * + * Destroys the image data. + * + * + */ +JSBool Image::destroy(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxImage *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + p->Destroy(); + return JS_TRUE; +} + +/*** + * + * + * + * Returns an identical copy of image. + * + * + */ +JSBool Image::copy(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxImage *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + *rval = CreateObject(cx, new wxImage(p->Copy())); + return JS_TRUE; +} + +/*** + * + * + * + * + * + * Returns a sub image of the current one as long as the rect belongs entirely to the image. + * + * + */ +JSBool Image::getSubImage(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxImage *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + wxRect *rect = Rect::GetPrivate(cx, argv[0]); + if ( rect != NULL ) + { + *rval = CreateObject(cx, new wxImage(p->GetSubImage(*rect))); + return JS_TRUE; + } + return JS_FALSE; +} + +/*** + * + * + * + * The image to paste. + * + * + * The x position. + * + * + * The y position. + * + * + * + * Pastes image into this instance and takes care of + * the mask colour and out of bounds problems. + * + * + */ +JSBool Image::paste(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxImage *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + wxImage *img = GetPrivate(cx, argv[0]); + if ( img == NULL ) + return JS_FALSE; + + int x; + int y; + + if ( FromJS(cx, argv[1], x) + && FromJS(cx, argv[2], y) ) + { + p->Paste(*img, x, y); + return JS_TRUE; + } + return JS_FALSE; +} + +/*** + * + * + * + * The width of the new image. + * + * + * The height of the new image. + * + * + * + * + * The size of the new image. + * + * + * + * Returns a scaled version of the image with size Width * Height. + * + * + */ +JSBool Image::scale(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxImage *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + if ( Size::HasPrototype(cx, argv[0]) ) + { + wxSize *size = Size::GetPrivate(cx, argv[0], false); + *rval = CreateObject(cx, new wxImage(p->Scale(size->GetWidth(), size->GetHeight()))); + return JS_TRUE; + } + else if ( argc == 2 ) + { + int width; + int height; + if ( FromJS(cx, argv[0], width) + && FromJS(cx, argv[1], height) ) + { + *rval = CreateObject(cx, new wxImage(p->Scale(width, height))); + return JS_TRUE; + } + } + return JS_FALSE; +} + +/*** + * + * + * + * The width of the new image. + * + * + * The height of the new image. + * + * + * + * + * The size of the new image. + * + * + * + * Changes the size of the image in-place: after a call to this function, + * the image will have the given width and height. + * Returns the (modified) image itself. + * + * + */ +JSBool Image::rescale(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxImage *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + if ( Size::HasPrototype(cx, argv[0]) ) + { + wxSize *size = Size::GetPrivate(cx, argv[0], false); + *rval = CreateObject(cx, new wxImage(p->Rescale(size->GetWidth(), size->GetHeight()))); + return JS_TRUE; + } + else if ( argc == 2 ) + { + int width; + int height; + if ( FromJS(cx, argv[0], width) + && FromJS(cx, argv[1], height) ) + { + *rval = CreateObject(cx, new wxImage(p->Rescale(width, height))); + return JS_TRUE; + } + } + return JS_FALSE; +} + +/*** + * + * + * + * The rotation angle. + * + * + * The height of the new image. + * + * + * Interpolates the new image. + * + * + * + * + * Rotates the image about the given point, by angle radians. Passing true for interpolating + * results in better image quality, but is slower. If the image has a mask, then the mask colour + * is used for the uncovered pixels in the rotated image background. Else, black will be used. + * Returns the rotated image, leaving this image intact. + * + * + */ +JSBool Image::rotate(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxImage *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + if ( argc > 4 ) + argc = 4; + + wxPoint *offset = NULL; + bool interpol = true; + + switch(argc) + { + case 4: + offset = Point::GetPrivate(cx, argv[3]); + if ( offset == NULL ) + break; + // Fall through + case 3: + if ( ! FromJS(cx, argv[2], interpol) ) + break; + default: + wxPoint *center = Point::GetPrivate(cx, argv[1]); + if ( center == NULL ) + break; + + double angle; + if ( ! FromJS(cx, argv[0], angle) ) + break; + + *rval = CreateObject(cx, new wxImage(p->Rotate(angle, *center, interpol, offset))); + return JS_TRUE; + } + + return JS_FALSE; +} + +/*** + * + * + * + * The direction of the rotation. Default is true. + * + * + * + * Returns a copy of the image rotated 90 degrees in the direction indicated by clockwise. + * + * + */ +JSBool Image::rotate90(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxImage *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + bool clockwise = true; + if ( argc > 0 + && ! FromJS(cx, argv[0], clockwise) ) + return JS_FALSE; + + *rval = CreateObject(cx, new wxImage(p->Rotate90(clockwise))); + return JS_TRUE; +} + +/*** + * + * + * + * The orientation. + * + * + * + * Returns a mirrored copy of the image. The parameter horizontally indicates the orientation. + * + * + */ +JSBool Image::mirror(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxImage *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + bool hor = true; + if ( argc > 0 + && ! FromJS(cx, argv[0], hor) ) + return JS_FALSE; + + *rval = CreateObject(cx, new wxImage(p->Mirror(hor))); + return JS_TRUE; +} + +/*** + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * Replaces the colour with another colour. + * + * + */ +JSBool Image::replace(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxImage *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + if ( argc == 2 ) + { + wxColour *colour1; + wxColour *colour2; + + if ( (colour1 = Colour::GetPrivate(cx, argv[0])) != NULL + && (colour2 = Colour::GetPrivate(cx, argv[1])) != NULL ) + { + p->Replace(colour1->Red(), colour1->Green(), colour1->Blue(), + colour2->Red(), colour2->Green(), colour2->Blue()); + return JS_TRUE; + } + } + else if ( argc == 6 ) + { + int r1, g1, b1, r2, g2, b2; + if ( FromJS(cx, argv[0], r1) + && FromJS(cx, argv[1], g1) + && FromJS(cx, argv[2], b1) + && FromJS(cx, argv[3], r2) + && FromJS(cx, argv[4], g2) + && FromJS(cx, argv[5], b2) ) + { + p->Replace(r1, g1, b1, r2, g2, b2); + return JS_TRUE; + } + } + + return JS_FALSE; +} + +/*** + * + * + * + * + * + * + * + * + * + * + * Converts to a monochrome image. The returned image has white colour where the original has (r,g,b) + * colour and black colour everywhere else. + * + * + */ +JSBool Image::convertToMono(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxImage *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + if ( argc == 1 ) + { + wxColour *colour = Colour::GetPrivate(cx, argv[0]); + + if ( colour != NULL ) + { + *rval = CreateObject(cx, new wxImage(p->ConvertToMono(colour->Red(), colour->Green(), colour->Blue()))); + return JS_TRUE; + } + } + else if ( argc == 3 ) + { + int r, g, b; + if ( FromJS(cx, argv[0], r) + && FromJS(cx, argv[1], g) + && FromJS(cx, argv[2], b) ) + { + *rval = CreateObject(cx, new wxImage(p->ConvertToMono(r, g, b))); + return JS_TRUE; + } + } + + return JS_FALSE; +} + +/*** + * + * + * The x position + * The y position + * + * + * + * + * + * The x position + * The y position + * + * + * + * Sets the colour of the pixel at the given coordinate. + * This routine performs bounds-checks for the coordinate so it can be considered a safe way + * to manipulate the data, but in some cases this might be too slow. + * + * + */ +JSBool Image::setRGB(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxImage *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + int x = 0; + int y = 0; + + if ( ! FromJS(cx, argv[0], x) + && ! FromJS(cx, argv[1], y) ) + return JS_FALSE; + + if ( Colour::HasPrototype(cx, argv[2]) ) + { + wxColour *colour = Colour::GetPrivate(cx, argv[2], false); + p->SetRGB(x, y, colour->Red(), colour->Green(), colour->Blue()); + return JS_TRUE; + } + else if ( argc == 5 ) + { + int r, g, b; + if ( FromJS(cx, argv[2], r) + && FromJS(cx, argv[3], g) + && FromJS(cx, argv[4], b) ) + { + p->SetRGB(x, y, r, g, b); + return JS_TRUE; + } + } + + return JS_FALSE; +} + +/*** + * + * + * The x position + * The y position + * + * + * Returns the red intensity at the given coordinate. + * + * + */ +JSBool Image::getRed(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxImage *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + int x = 0; + int y = 0; + + if ( ! FromJS(cx, argv[0], x) + && ! FromJS(cx, argv[1], y) ) + return JS_FALSE; + + *rval = ToJS(cx, (int) p->GetRed(x, y)); + return JS_TRUE; +} + +/*** + * + * + * The x position + * The y position + * + * + * Returns the green intensity at the given coordinate. + * + * + */ +JSBool Image::getGreen(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxImage *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + int x = 0; + int y = 0; + + if ( ! FromJS(cx, argv[0], x) + && ! FromJS(cx, argv[1], y) ) + return JS_FALSE; + + *rval = ToJS(cx, (int) p->GetGreen(x, y)); + return JS_TRUE; +} + +/*** + * + * + * The x position + * The y position + * + * + * Returns the blue intensity at the given coordinate. + * + * + */ +JSBool Image::getBlue(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxImage *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + int x = 0; + int y = 0; + + if ( ! FromJS(cx, argv[0], x) + && ! FromJS(cx, argv[1], y) ) + return JS_FALSE; + + *rval = ToJS(cx, (int) p->GetBlue(x, y)); + return JS_TRUE; +} + +/*** + * + * + * The x position + * The y position + * + * + * Returns the colour of the given coordinate. + * + * + */ +JSBool Image::getColour(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxImage *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + int x = 0; + int y = 0; + + if ( ! FromJS(cx, argv[0], x) + && ! FromJS(cx, argv[1], y) ) + return JS_FALSE; + + *rval = Colour::CreateObject(cx, new wxColour(p->GetRed(x, y), p->GetGreen(x, y), p->GetBlue(x, y))); + return JS_TRUE; +} + +/*** + * + * + * + * The colour found. Only updated when a colour is found. + * + * + * The start colour. + * + * + * + * Finds the first colour that is never used in the image. The search begins at given start + * colour and continues by increasing R, G and B components (in this order) by 1 until an + * unused colour is found or the colour space exhausted. + * Returns true on success. False when there are no colours left. + * JavaScript can't pass primitive values by reference, so this method uses @wxColour + * instead of separate r, g, b arguments. + * + * + */ +JSBool Image::findFirstUnusedColour(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxImage *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + wxColour *colour = Colour::GetPrivate(cx, argv[0]); + if ( colour == NULL ) + return JS_FALSE; + + wxColour *start = Colour::GetPrivate(cx, argv[1]); + if ( start == NULL ) + return JS_FALSE; + + unsigned char r, g, b; + + if ( p->FindFirstUnusedColour(&r, &g, &b, start->Red(), start->Green(), start->Blue()) ) + { + *rval = JSVAL_TRUE; + colour->Set(r, g, b); + } + else + { + *rval = JSVAL_FALSE; + } + return JS_TRUE; +} + +/*** + * + * + * + * The mask image to extract mask shape from. Must have same dimensions as the image. + * + * + * + * + * + * + * + * The mask image to extract mask shape from. Must have same dimensions as the image. + * + * + * + * + * Sets image's mask so that the pixels that have RGB value of r,g,b (or colour) in mask + * will be masked in the image. This is done by first finding an unused colour in the image, + * setting this colour as the mask colour and then using this colour to draw all pixels in + * the image whose corresponding pixel in mask has given RGB value. + * Returns false if mask does not have same dimensions as the image or if there is no unused + * colour left. Returns true if the mask was successfully applied. + * + * + */ +JSBool Image::setMaskFromImage(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxImage *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + wxImage *mask = GetPrivate(cx, argv[0]); + if ( mask == NULL ) + return JS_FALSE; + + if ( argc == 2 ) + { + wxColour *colour = Colour::GetPrivate(cx, argv[1]); + if ( colour != NULL ) + { + *rval = ToJS(cx, p->SetMaskFromImage(*mask, colour->Red(), colour->Green(), colour->Blue())); + return JS_TRUE; + } + } + else if ( argc == 4 ) + { + int r, g, b; + if ( FromJS(cx, argv[1], r) + && FromJS(cx, argv[2], g) + && FromJS(cx, argv[3], b) ) + { + *rval = ToJS(cx, p->SetMaskFromImage(*mask, r, g, b)); + return JS_TRUE; + } + } + + return JS_FALSE; +} + +/*** + * + * + * The name of a file + * + * The type of the image. + * + * + * + * The name of a file + * + * The MIME type of the image. + * + * + * + * + * Opened input stream from which to load the image. Currently, the stream must support seeking. + * + * + * The type of the image. + * + * + * + * + * Opened input stream from which to load the image. Currently, the stream must support seeking. + * + * + * The MIME type of the image. + * + * + * + * Loads an image from a file. + * + * + */ +JSBool Image::loadFile(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxImage *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + if ( wxjs::HasPrototype(cx, argv[0], "wxInputStream") ) + { + if ( argc != 2 ) + return JS_FALSE; + + io::Stream *stream = (io::Stream *) JS_GetPrivate(cx, JSVAL_TO_OBJECT(argv[0])); + if ( stream == NULL ) + return JS_FALSE; + + wxInputStream *in = dynamic_cast(stream->GetStream()); + if ( in == NULL ) + { + // TODO: error reporting + return JS_FALSE; + } + + if ( JSVAL_IS_INT(argv[1]) ) + { + long type = wxBITMAP_TYPE_ANY; + if ( ! FromJS(cx, argv[1], type) ) + return JS_FALSE; + + *rval = ToJS(cx, p->LoadFile(*in, type)); + } + else + { + wxString mimetype; + FromJS(cx, argv[1], mimetype); + *rval = ToJS(cx, p->LoadFile(*in, mimetype)); + } + } + else + { + wxString name; + FromJS(cx, argv[0], name); + + if ( argc > 1 ) + { + if ( JSVAL_IS_INT(argv[1]) ) + { + long type = wxBITMAP_TYPE_ANY; + if ( ! FromJS(cx, argv[1], type) ) + return JS_FALSE; + *rval = ToJS(cx, p->LoadFile(name, type)); + } + else + { + wxString mimetype; + FromJS(cx, argv[1], mimetype); + *rval = ToJS(cx, p->LoadFile(name, mimetype)); + } + } + else + *rval = ToJS(cx, p->LoadFile(name)); + } + return JS_TRUE; +} + +/*** + * + * + * The name of a file + * + * The type of the image. + * + * + * + * The name of a file + * + * The MIME type of the image. + * + * + * + * + * Opened input stream from which to load the image. Currently, the stream must support seeking. + * + * + * The type of the image. + * + * + * + * + * Opened input stream from which to load the image. Currently, the stream must support seeking. + * + * + * The MIME type of the image. + * + * + * + * Saves an image to a file. + * + * + */ +JSBool Image::saveFile(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxImage *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + if ( wxjs::HasPrototype(cx, argv[0], "wxOutputStream") ) + { + if ( argc != 2 ) + return JS_FALSE; + + io::Stream *stream = (io::Stream *) JS_GetPrivate(cx, JSVAL_TO_OBJECT(argv[0])); + if ( stream == NULL ) + return JS_FALSE; + + wxOutputStream *out = dynamic_cast(stream->GetStream()); + if ( out == NULL ) + { + // TODO: error reporting + return JS_FALSE; + } + + if ( JSVAL_IS_INT(argv[1]) ) + { + long type = wxBITMAP_TYPE_ANY; + if ( ! FromJS(cx, argv[1], type) ) + return JS_FALSE; + + *rval = ToJS(cx, p->SaveFile(*out, type)); + } + else + { + wxString mimetype; + FromJS(cx, argv[1], mimetype); + *rval = ToJS(cx, p->SaveFile(*out, mimetype)); + } + } + else + { + wxString name; + FromJS(cx, argv[0], name); + + if ( JSVAL_IS_INT(argv[1]) ) + { + long type; + if ( ! FromJS(cx, argv[1], type) ) + return JS_FALSE; + *rval = ToJS(cx, p->SaveFile(name, type)); + } + else + { + wxString mimetype; + FromJS(cx, argv[1], mimetype); + *rval = ToJS(cx, p->SaveFile(name, mimetype)); + } + } + return JS_TRUE; +} + +/*** + * + * + * + * + * + * + * + * + * + * + * Sets the mask colour for this image (and tells the image to use the mask). + * + * + */ +JSBool Image::setMaskColour(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxImage *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + if ( Colour::HasPrototype(cx, argv[0]) ) + { + wxColour *colour = Colour::GetPrivate(cx, argv[0], false); + p->SetMaskColour(colour->Red(), colour->Green(), colour->Blue()); + return JS_TRUE; + } + else if ( argc == 3 ) + { + int r, g, b; + if ( FromJS(cx, argv[0], r) + && FromJS(cx, argv[1], g) + && FromJS(cx, argv[2], b) ) + { + p->SetMaskColour(r, g, b); + return JS_TRUE; + } + } + + return JS_FALSE; +} + +/*** + * + * + * Name of the option + * Value of the option + * + * + * Name of the option + * Value of the option + * + * + * Sets a user-defined option. The function is case-insensitive to name. + * For example, when saving as a JPEG file, the option quality is used, + * which is a number between 0 and 100 (0 is terrible, 100 is very good). + * See @wxImage#getOption, @wxImage#getOptionInt, @wxImage#hasOption. + * + * + */ +JSBool Image::setOption(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxImage *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + wxString name; + FromJS(cx, argv[0], name); + + if ( JSVAL_IS_INT(argv[1]) ) + { + int value; + FromJS(cx, argv[1], value); + p->SetOption(name, value); + return JS_TRUE; + } + + wxString value; + FromJS(cx, argv[1], value); + p->SetOption(name, value); + + return JS_TRUE; +} + +/*** + * + * + * + * The name of the option. + * + * + * + * Gets a user-defined option. The function is case-insensitive to name. + * See @wxImage#setOption, @wxImage#getOptionInt, @wxImage#hasOption + * + * + */ +JSBool Image::getOption(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxImage *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + wxString name; + FromJS(cx, argv[0], name); + + *rval = ToJS(cx, p->GetOption(name)); + return JS_TRUE; +} + +/*** + * + * + * + * The name of the option. + * + * + * + * Gets a user-defined option. The function is case-insensitive to name. + * See @wxImage#setOption, @wxImage#getOptionString, @wxImage#hasOption + * + * + */ +JSBool Image::getOptionInt(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxImage *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + wxString name; + FromJS(cx, argv[0], name); + + *rval = ToJS(cx, p->GetOptionInt(name)); + return JS_TRUE; +} + +/*** + * + * + * + * The name of the option. + * + * + * + * Returns true if the given option is present. The function is case-insensitive to name. + * See @wxImage#setOption, @wxImage#getOptionInt, @wxImage#hasOption + * + * + */ +JSBool Image::hasOption(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxImage *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + wxString name; + FromJS(cx, argv[0], name); + + *rval = ToJS(cx, p->HasOption(name)); + return JS_TRUE; +} + +WXJS_BEGIN_STATIC_METHOD_MAP(Image) + WXJS_METHOD("canRead", canRead, 1) + WXJS_METHOD("addHandler", addHandler, 1) + WXJS_METHOD("cleanUpHandlers", cleanUpHandlers, 0) + WXJS_METHOD("removeHandler", removeHandler, 1) + WXJS_METHOD("findHandler", findHandler, 1) + WXJS_METHOD("findHandlerMime", findHandlerMime, 1) + WXJS_METHOD("insertHandler", insertHandler, 1) +WXJS_END_METHOD_MAP() + +/*** + * + * + * + * + * + * Adds a handler to the end of the static list of format handlers. + * There is usually only one instance of a given handler class in an application session. + * See @wxImage#handlers and @wxInitAllImageHandlers + * + * + */ +JSBool Image::addHandler(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + ImageHandlerPrivate *p = ImageHandler::GetPrivate(cx, argv[0]); + if ( p == NULL ) + return JS_FALSE; + + p->SetOurs(false); + wxImage::AddHandler(p->GetHandler()); + + return JS_TRUE; +} + +/*** + * + * + * + * A filename. + * + * + * + * Returns true when the file can be read. + * + * + */ +JSBool Image::canRead(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxString name; + FromJS(cx, argv[0], name); + *rval = ToJS(cx, wxImage::CanRead(name)); + return JS_TRUE; +} + +/*** + * + * + * + * Removes all handlers. Is called automatically by wxWindows. + * + * + */ +JSBool Image::cleanUpHandlers(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxImage::CleanUpHandlers(); + return JS_TRUE; +} + +/*** + * + * + * + * + * + * + * + * + * + * + * + * + * Searches a handler + * + * + */ +JSBool Image::findHandler(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxImageHandler *handler = NULL; + if ( JSVAL_IS_STRING(argv[0]) ) + { + wxString str; + FromJS(cx, argv[0], str); + + if ( argc == 2 ) + { + long type; + if ( FromJS(cx, argv[1], type) ) + { + handler = wxImage::FindHandler(str, type); + } + else + return JS_FALSE; + } + else + handler = wxImage::FindHandler(str); + } + else + { + long type; + if ( FromJS(cx, argv[1], type) ) + { + handler = wxImage::FindHandler(type); + } + else + return JS_FALSE; + } + + if ( handler == NULL ) + *rval = JSVAL_VOID; + else + { + *rval = ImageHandler::CreateObject(cx, new ImageHandlerPrivate(handler, false)); + } + + return JS_TRUE; +} + +/*** + * + * + * + * A mime type. + * + * + * + * Finds the handler associated with the given MIME type. + * + * + */ +JSBool Image::findHandlerMime(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxString mime; + FromJS(cx, argv[0], mime); + + wxImageHandler *handler = wxImage::FindHandlerMime(mime); + if ( handler == NULL ) + *rval = JSVAL_VOID; + else + { + *rval = ImageHandler::CreateObject(cx, new ImageHandlerPrivate(handler, false)); + } + return JS_TRUE; +} + +/*** + * + * + * + * The name of the handler. + * + * + * + * Remove the given handler. + * + * + */ +JSBool Image::removeHandler(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxString name; + FromJS(cx, argv[0], name); + + *rval = ToJS(cx, wxImage::RemoveHandler(name)); + return JS_TRUE; +} + +/*** + * + * + * + * + * + * Adds a handler at the start of the static list of format handlers. + * There is usually only one instance of a given handler class in an application session. + * See @wxImage#handlers + * + * + */ +JSBool Image::insertHandler(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + ImageHandlerPrivate *p = ImageHandler::GetPrivate(cx, argv[0]); + if ( p == NULL ) + return JS_FALSE; + + p->SetOurs(false); + wxImage::InsertHandler(p->GetHandler()); + + return JS_TRUE; +} Property changes on: ps/trunk/source/tools/atlas/wxJS/gui/misc/image.cpp ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/gui/misc/gridszr.cpp =================================================================== --- ps/trunk/source/tools/atlas/wxJS/gui/misc/gridszr.cpp (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/gui/misc/gridszr.cpp (revision 5154) @@ -0,0 +1,134 @@ +#include "precompiled.h" + +/* + * wxJavaScript - gridszr.cpp + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: gridszr.cpp 733 2007-06-05 21:17:25Z fbraem $ + */ +// gridszr.cpp + +#ifndef WX_PRECOMP + #include +#endif + +#include "../../common/main.h" +#include "../../common/apiwrap.h" + +#include "sizer.h" +#include "gridszr.h" + +using namespace wxjs; +using namespace wxjs::gui; + +/*** + * misc/gridszr + * gui + * + * A grid sizer is a sizer which lays out its children in a two-dimensional table with + * all table fields having the same size, i.e. the width of each field is the width of + * the widest child, the height of each field is the height of the tallest child. + * + */ +WXJS_INIT_CLASS(GridSizer, "wxGridSizer", 4) + +/*** + * + * + * + * The number of rows. + * + * + * The number of columns. + * + * + * The space between the columns + * + * + * The space between the rows + * + * + * + * + * The number of columns. + * + * + * The space between the columns + * + * + * The space between the rows + * + * + * + * Constructs a new wxGridSizer object. + * + * + */ +wxGridSizer *GridSizer::Construct(JSContext *cx, + JSObject *obj, + uintN argc, + jsval *argv, + bool constructing) +{ + wxGridSizer *p = NULL; + + int cols = 0; + int rows = 0; + int vgap = 0; + int hgap = 0; + + if ( argc > 4 ) + argc = 4; + + if ( argc == 4 ) + { + if ( FromJS(cx, argv[0], rows) + && FromJS(cx, argv[1], cols) + && FromJS(cx, argv[2], vgap) + && FromJS(cx, argv[3], hgap) ) + { + p = new wxGridSizer(rows, cols, vgap, hgap); + } + } + else if ( argc < 4 ) + { + switch(argc) + { + case 3: + if ( ! FromJS(cx, argv[2], hgap) ) + break; + case 2: + if ( ! FromJS(cx, argv[1], vgap) ) + break; + case 1: + if ( ! FromJS(cx, argv[0], cols) ) + break; + p = new wxGridSizer(cols, vgap, hgap); + } + } + + if ( p != NULL ) + { + p->SetClientObject(new JavaScriptClientData(cx, obj, false, true)); + } + + return p; +} Property changes on: ps/trunk/source/tools/atlas/wxJS/gui/misc/gridszr.cpp ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/gui/misc/constant.cpp =================================================================== --- ps/trunk/source/tools/atlas/wxJS/gui/misc/constant.cpp (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/gui/misc/constant.cpp (revision 5154) @@ -0,0 +1,867 @@ +#include "precompiled.h" + +/* + * wxJavaScript - constant.cpp + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: constant.cpp 598 2007-03-07 20:13:28Z fbraem $ + */ +// constant.cpp + +#ifndef WX_PRECOMP + #include +#endif +#include +#include +#include + +#include "../../common/main.h" + +#include "constant.h" + +using namespace wxjs; +using namespace wxjs::gui; + +/*** + * misc/constants + * gui + * + * The following list shows all the constants that are defined on the Global object. + * + */ + +JSConstDoubleSpec wxGlobalMap[] = +{ + WXJS_SIMPLE_CONSTANT(wxNOT_FOUND) + WXJS_SIMPLE_CONSTANT(wxInvalidOffset) + { 0 } +}; + +/*** + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * See @wxSizer, @wxBoxSizer, @wxFlexGridSizer, @wxGridSizer + * + * + */ +JSConstDoubleSpec wxDirectionMap[] = +{ + WXJS_CONSTANT(wx, TOP) + WXJS_CONSTANT(wx, BOTTOM) + WXJS_CONSTANT(wx, LEFT) + WXJS_CONSTANT(wx, TOP) + WXJS_CONSTANT(wx, UP) + WXJS_CONSTANT(wx, DOWN) + WXJS_CONSTANT(wx, RIGHT) + WXJS_CONSTANT(wx, NORTH) + WXJS_CONSTANT(wx, SOUTH) + WXJS_CONSTANT(wx, WEST) + WXJS_CONSTANT(wx, EAST) + WXJS_CONSTANT(wx, ALL) + { 0 } +}; + +/*** + * + * + * + * + * + * + * + * See @wxSizer, @wxBoxSizer, @wxFlexGridSizer, @wxGridSizer + * + * + */ +JSConstDoubleSpec wxStretchMap[] = +{ + WXJS_CONSTANT(wxSTRETCH_, NOT) + WXJS_CONSTANT(wx, SHRINK) + WXJS_CONSTANT(wx, GROW) + WXJS_CONSTANT(wx, EXPAND) + WXJS_CONSTANT(wx, SHAPED) + { 0 } +}; + +/*** + * + * + * + * + * + * See @wxSizer, @wxBoxSizer, @wxFlexGridSizer, @wxGridSizer, + * wxWindow @wxWindow#centre, wxWindow @wxWindow#centreOnParent, + * wxWindow @wxWindow#centreOnScreen + * + * + */ +JSConstDoubleSpec wxOrientationMap[] = +{ + WXJS_CONSTANT(wx, HORIZONTAL) + WXJS_CONSTANT(wx, VERTICAL) + WXJS_CONSTANT(wx, BOTH) + { 0 } +}; + +/*** + * + * + * + * + * + * + * + * + * + * + * + * + * + * See @wxSizer, @wxBoxSizer, @wxFlexGridSizer, @wxGridSizer + * + * + */ +JSConstDoubleSpec wxAlignmentMap[] = +{ + WXJS_CONSTANT(wxALIGN_, NOT) + WXJS_CONSTANT(wxALIGN_, CENTER_HORIZONTAL) + WXJS_CONSTANT(wxALIGN_, CENTRE_HORIZONTAL) + WXJS_CONSTANT(wxALIGN_, LEFT) + WXJS_CONSTANT(wxALIGN_, TOP) + WXJS_CONSTANT(wxALIGN_, RIGHT) + WXJS_CONSTANT(wxALIGN_, BOTTOM) + WXJS_CONSTANT(wxALIGN_, CENTER_VERTICAL) + WXJS_CONSTANT(wxALIGN_, CENTRE_VERTICAL) + WXJS_CONSTANT(wxALIGN_, CENTER) + WXJS_CONSTANT(wxALIGN_, CENTRE) + { 0 } +}; + +/*** + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + */ +JSConstDoubleSpec wxIdMap[] = +{ + WXJS_CONSTANT(wxID_, LOWEST) + WXJS_CONSTANT(wxID_, HIGHEST) + + WXJS_CONSTANT(wxID_, SEPARATOR) + WXJS_CONSTANT(wxID_, OPEN) + WXJS_CONSTANT(wxID_, CLOSE) + WXJS_CONSTANT(wxID_, NEW) + WXJS_CONSTANT(wxID_, SAVE) + WXJS_CONSTANT(wxID_, SAVEAS) + WXJS_CONSTANT(wxID_, REVERT) + WXJS_CONSTANT(wxID_, EXIT) + WXJS_CONSTANT(wxID_, UNDO) + WXJS_CONSTANT(wxID_, REDO) + WXJS_CONSTANT(wxID_, HELP) + WXJS_CONSTANT(wxID_, PRINT) + WXJS_CONSTANT(wxID_, PRINT_SETUP) + WXJS_CONSTANT(wxID_, PREVIEW) + WXJS_CONSTANT(wxID_, ABOUT) + WXJS_CONSTANT(wxID_, HELP_CONTENTS) + WXJS_CONSTANT(wxID_, HELP_COMMANDS) + WXJS_CONSTANT(wxID_, HELP_PROCEDURES) + WXJS_CONSTANT(wxID_, HELP_CONTEXT) + + WXJS_CONSTANT(wxID_, CUT) + WXJS_CONSTANT(wxID_, COPY) + WXJS_CONSTANT(wxID_, PASTE) + WXJS_CONSTANT(wxID_, CLEAR) + WXJS_CONSTANT(wxID_, FIND) + WXJS_CONSTANT(wxID_, DUPLICATE) + WXJS_CONSTANT(wxID_, SELECTALL) + + WXJS_CONSTANT(wxID_, FILE1) + WXJS_CONSTANT(wxID_, FILE2) + WXJS_CONSTANT(wxID_, FILE3) + WXJS_CONSTANT(wxID_, FILE4) + WXJS_CONSTANT(wxID_, FILE5) + WXJS_CONSTANT(wxID_, FILE6) + WXJS_CONSTANT(wxID_, FILE7) + WXJS_CONSTANT(wxID_, FILE8) + WXJS_CONSTANT(wxID_, FILE9) + +// Standard button IDs + WXJS_CONSTANT(wxID_, OK) + WXJS_CONSTANT(wxID_, CANCEL) + WXJS_CONSTANT(wxID_, APPLY) + WXJS_CONSTANT(wxID_, YES) + WXJS_CONSTANT(wxID_, NO) + WXJS_CONSTANT(wxID_, STATIC) + WXJS_CONSTANT(wxID_, FORWARD) + WXJS_CONSTANT(wxID_, BACKWARD) + WXJS_CONSTANT(wxID_, DEFAULT) + WXJS_CONSTANT(wxID_, MORE) + WXJS_CONSTANT(wxID_, SETUP) + WXJS_CONSTANT(wxID_, RESET) + WXJS_CONSTANT(wxID_, CONTEXT_HELP) + WXJS_CONSTANT(wxID_, YESTOALL) + WXJS_CONSTANT(wxID_, NOTOALL) + WXJS_CONSTANT(wxID_, ABORT) + WXJS_CONSTANT(wxID_, RETRY) + WXJS_CONSTANT(wxID_, IGNORE) + + WXJS_CONSTANT(wxID_, FILEDLGG) + { 0 } +}; + +/*** + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * See @wxKeyEvent + * + * + * @endif + */ +JSConstDoubleSpec wxKeyCodeMap[] = +{ + WXJS_CONSTANT(WXK_, BACK) + WXJS_CONSTANT(WXK_, TAB) + WXJS_CONSTANT(WXK_, RETURN) + WXJS_CONSTANT(WXK_, ESCAPE) + WXJS_CONSTANT(WXK_, SPACE) + WXJS_CONSTANT(WXK_, DELETE) + WXJS_CONSTANT(WXK_, START) + WXJS_CONSTANT(WXK_, LBUTTON) + WXJS_CONSTANT(WXK_, RBUTTON) + WXJS_CONSTANT(WXK_, CANCEL) + WXJS_CONSTANT(WXK_, MBUTTON) + WXJS_CONSTANT(WXK_, CLEAR) + WXJS_CONSTANT(WXK_, SHIFT) + WXJS_CONSTANT(WXK_, ALT) + WXJS_CONSTANT(WXK_, CONTROL) + WXJS_CONSTANT(WXK_, MENU) + WXJS_CONSTANT(WXK_, PAUSE) + WXJS_CONSTANT(WXK_, CAPITAL) + WXJS_CONSTANT(WXK_, PRIOR) + WXJS_CONSTANT(WXK_, NEXT) + WXJS_CONSTANT(WXK_, END) + WXJS_CONSTANT(WXK_, HOME) + WXJS_CONSTANT(WXK_, LEFT) + WXJS_CONSTANT(WXK_, UP) + WXJS_CONSTANT(WXK_, RIGHT) + WXJS_CONSTANT(WXK_, DOWN) + WXJS_CONSTANT(WXK_, SELECT) + WXJS_CONSTANT(WXK_, PRINT) + WXJS_CONSTANT(WXK_, EXECUTE) + WXJS_CONSTANT(WXK_, SNAPSHOT) + WXJS_CONSTANT(WXK_, INSERT) + WXJS_CONSTANT(WXK_, HELP) + WXJS_CONSTANT(WXK_, NUMPAD0) + WXJS_CONSTANT(WXK_, NUMPAD1) + WXJS_CONSTANT(WXK_, NUMPAD2) + WXJS_CONSTANT(WXK_, NUMPAD3) + WXJS_CONSTANT(WXK_, NUMPAD4) + WXJS_CONSTANT(WXK_, NUMPAD5) + WXJS_CONSTANT(WXK_, NUMPAD6) + WXJS_CONSTANT(WXK_, NUMPAD7) + WXJS_CONSTANT(WXK_, NUMPAD8) + WXJS_CONSTANT(WXK_, NUMPAD9) + WXJS_CONSTANT(WXK_, MULTIPLY) + WXJS_CONSTANT(WXK_, ADD) + WXJS_CONSTANT(WXK_, SEPARATOR) + WXJS_CONSTANT(WXK_, SUBTRACT) + WXJS_CONSTANT(WXK_, DECIMAL) + WXJS_CONSTANT(WXK_, DIVIDE) + WXJS_CONSTANT(WXK_, F1) + WXJS_CONSTANT(WXK_, F2) + WXJS_CONSTANT(WXK_, F3) + WXJS_CONSTANT(WXK_, F4) + WXJS_CONSTANT(WXK_, F5) + WXJS_CONSTANT(WXK_, F6) + WXJS_CONSTANT(WXK_, F7) + WXJS_CONSTANT(WXK_, F8) + WXJS_CONSTANT(WXK_, F9) + WXJS_CONSTANT(WXK_, F10) + WXJS_CONSTANT(WXK_, F11) + WXJS_CONSTANT(WXK_, F12) + WXJS_CONSTANT(WXK_, F13) + WXJS_CONSTANT(WXK_, F14) + WXJS_CONSTANT(WXK_, F15) + WXJS_CONSTANT(WXK_, F16) + WXJS_CONSTANT(WXK_, F17) + WXJS_CONSTANT(WXK_, F18) + WXJS_CONSTANT(WXK_, F19) + WXJS_CONSTANT(WXK_, F20) + WXJS_CONSTANT(WXK_, F21) + WXJS_CONSTANT(WXK_, F22) + WXJS_CONSTANT(WXK_, F23) + WXJS_CONSTANT(WXK_, F24) + WXJS_CONSTANT(WXK_, NUMLOCK) + WXJS_CONSTANT(WXK_, SCROLL) + WXJS_CONSTANT(WXK_, PAGEUP) + WXJS_CONSTANT(WXK_, PAGEDOWN) + WXJS_CONSTANT(WXK_, NUMPAD_SPACE) + WXJS_CONSTANT(WXK_, NUMPAD_TAB) + WXJS_CONSTANT(WXK_, NUMPAD_ENTER) + WXJS_CONSTANT(WXK_, NUMPAD_F1) + WXJS_CONSTANT(WXK_, NUMPAD_F2) + WXJS_CONSTANT(WXK_, NUMPAD_F3) + WXJS_CONSTANT(WXK_, NUMPAD_F4) + WXJS_CONSTANT(WXK_, NUMPAD_HOME) + WXJS_CONSTANT(WXK_, NUMPAD_LEFT) + WXJS_CONSTANT(WXK_, NUMPAD_UP) + WXJS_CONSTANT(WXK_, NUMPAD_RIGHT) + WXJS_CONSTANT(WXK_, NUMPAD_DOWN) + WXJS_CONSTANT(WXK_, NUMPAD_PRIOR) + WXJS_CONSTANT(WXK_, NUMPAD_PAGEUP) + WXJS_CONSTANT(WXK_, NUMPAD_NEXT) + WXJS_CONSTANT(WXK_, NUMPAD_PAGEDOWN) + WXJS_CONSTANT(WXK_, NUMPAD_END) + WXJS_CONSTANT(WXK_, NUMPAD_BEGIN) + WXJS_CONSTANT(WXK_, NUMPAD_INSERT) + WXJS_CONSTANT(WXK_, NUMPAD_DELETE) + WXJS_CONSTANT(WXK_, NUMPAD_EQUAL) + WXJS_CONSTANT(WXK_, NUMPAD_MULTIPLY) + WXJS_CONSTANT(WXK_, NUMPAD_ADD) + WXJS_CONSTANT(WXK_, NUMPAD_SEPARATOR) + WXJS_CONSTANT(WXK_, NUMPAD_SUBTRACT) + WXJS_CONSTANT(WXK_, NUMPAD_DECIMAL) + WXJS_CONSTANT(WXK_, NUMPAD_DIVIDE) + { 0 } +}; + +/*** + * + * + * + * + * + * See @wxCalendarDateAttr, @wxCalendarCtrl + * + * + */ +JSConstDoubleSpec wxCalendarDateBorderMap[] = +{ + WXJS_CONSTANT(wxCAL_BORDER_, NONE) + WXJS_CONSTANT(wxCAL_BORDER_, SQUARE) + WXJS_CONSTANT(wxCAL_BORDER_, ROUND) + { 0 } +}; + +/*** + * + * system default + * current default encoding + * West European (Latin1) + * Central and East European (Latin2) + * Esperanto (Latin3) + * Baltic (old) (Latin4) + * Cyrillic + * Arabic + * Greek + * Hebrew + * Turkish (Latin5) + * Variation of Latin4 (Latin6) + * Thai + * Doesn't exist currently, but put it + * here anyhow to make all ISO8859 + * consecutive numbers + * Baltic (Latin7) + * Latin8 + * Latin9 (a.k.a. Latin0, includes euro) + * + * We don't support any of KOI8 variants + * same as MS-DOS CP866 + * used under Linux in Bulgaria + * original MS-DOS codepage + * CP437 merged with Latin1 + * CP437 merged with Latin2 + * another cyrillic encoding + * and another one and for Windows + * WinThai + * Japanese (shift-JIS) + * Chinese simplified (GB) + * Korean (Hangul charset) + * Chinese (traditional - Big5) + * WinLatin2 + * WinCyrillic + * WinLatin1 + * WinGreek (8859-7) + * WinTurkish + * WinHebrew + * WinArabic + * WinBaltic (same as Latin 7) + * + * UTF-7 Unicode encoding + * UTF-8 Unicode encoding + * Unicode - currently used only by wxEncodingConverter class + * + * + */ +JSConstDoubleSpec wxFontEncodingMap[] = +{ + WXJS_CONSTANT(wxFONTENCODING_, SYSTEM) + WXJS_CONSTANT(wxFONTENCODING_, DEFAULT) + WXJS_CONSTANT(wxFONTENCODING_, ISO8859_1) + WXJS_CONSTANT(wxFONTENCODING_, ISO8859_2) + WXJS_CONSTANT(wxFONTENCODING_, ISO8859_3) + WXJS_CONSTANT(wxFONTENCODING_, ISO8859_4) + WXJS_CONSTANT(wxFONTENCODING_, ISO8859_5) + WXJS_CONSTANT(wxFONTENCODING_, ISO8859_6) + WXJS_CONSTANT(wxFONTENCODING_, ISO8859_7) + WXJS_CONSTANT(wxFONTENCODING_, ISO8859_8) + WXJS_CONSTANT(wxFONTENCODING_, ISO8859_9) + WXJS_CONSTANT(wxFONTENCODING_, ISO8859_10) + WXJS_CONSTANT(wxFONTENCODING_, ISO8859_11) + WXJS_CONSTANT(wxFONTENCODING_, ISO8859_12) + WXJS_CONSTANT(wxFONTENCODING_, ISO8859_13) + WXJS_CONSTANT(wxFONTENCODING_, ISO8859_14) + WXJS_CONSTANT(wxFONTENCODING_, ISO8859_15) + WXJS_CONSTANT(wxFONTENCODING_, ISO8859_MAX) + WXJS_CONSTANT(wxFONTENCODING_, KOI8) + WXJS_CONSTANT(wxFONTENCODING_, ALTERNATIVE) + WXJS_CONSTANT(wxFONTENCODING_, BULGARIAN) + WXJS_CONSTANT(wxFONTENCODING_, CP437) + WXJS_CONSTANT(wxFONTENCODING_, CP850) + WXJS_CONSTANT(wxFONTENCODING_, CP852) + WXJS_CONSTANT(wxFONTENCODING_, CP855) + WXJS_CONSTANT(wxFONTENCODING_, CP866) + WXJS_CONSTANT(wxFONTENCODING_, CP874) + WXJS_CONSTANT(wxFONTENCODING_, CP932) + WXJS_CONSTANT(wxFONTENCODING_, CP936) + WXJS_CONSTANT(wxFONTENCODING_, CP949) + WXJS_CONSTANT(wxFONTENCODING_, CP950) + WXJS_CONSTANT(wxFONTENCODING_, CP1250) + WXJS_CONSTANT(wxFONTENCODING_, CP1251) + WXJS_CONSTANT(wxFONTENCODING_, CP1252) + WXJS_CONSTANT(wxFONTENCODING_, CP1253) + WXJS_CONSTANT(wxFONTENCODING_, CP1254) + WXJS_CONSTANT(wxFONTENCODING_, CP1255) + WXJS_CONSTANT(wxFONTENCODING_, CP1256) + WXJS_CONSTANT(wxFONTENCODING_, CP1257) + WXJS_CONSTANT(wxFONTENCODING_, CP12_MAX) + WXJS_CONSTANT(wxFONTENCODING_, UTF7) + WXJS_CONSTANT(wxFONTENCODING_, UTF8) + WXJS_CONSTANT(wxFONTENCODING_, UNICODE) + WXJS_CONSTANT(wxFONTENCODING_, MAX) + { 0 } +}; + +/*** + * + * + * The validity of these flags depends on the platform and wxWidgets configuration. + * If all possible wxWidgets settings are used, the Windows platform supports BMP file, + * BMP resource, XPM data, and XPM. Under wxGTK, the available formats are BMP file, + * XPM data, XPM file, and PNG file. Under wxMotif, the available formats are XBM data, + * XBM file, XPM data, XPM file. + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + */ +JSConstDoubleSpec wxBitmapTypeMap[] = +{ + WXJS_CONSTANT(wxBITMAP_TYPE_, INVALID) + WXJS_CONSTANT(wxBITMAP_TYPE_, BMP) + WXJS_CONSTANT(wxBITMAP_TYPE_, BMP_RESOURCE) + WXJS_CONSTANT(wxBITMAP_TYPE_, RESOURCE) + WXJS_CONSTANT(wxBITMAP_TYPE_, ICO) + WXJS_CONSTANT(wxBITMAP_TYPE_, ICO_RESOURCE) + WXJS_CONSTANT(wxBITMAP_TYPE_, CUR) + WXJS_CONSTANT(wxBITMAP_TYPE_, CUR_RESOURCE) + WXJS_CONSTANT(wxBITMAP_TYPE_, XBM) + WXJS_CONSTANT(wxBITMAP_TYPE_, XBM_DATA) + WXJS_CONSTANT(wxBITMAP_TYPE_, XPM) + WXJS_CONSTANT(wxBITMAP_TYPE_, XPM_DATA) + WXJS_CONSTANT(wxBITMAP_TYPE_, TIF) + WXJS_CONSTANT(wxBITMAP_TYPE_, TIF_RESOURCE) + WXJS_CONSTANT(wxBITMAP_TYPE_, GIF) + WXJS_CONSTANT(wxBITMAP_TYPE_, GIF_RESOURCE) + WXJS_CONSTANT(wxBITMAP_TYPE_, PNG) + WXJS_CONSTANT(wxBITMAP_TYPE_, PNG_RESOURCE) + WXJS_CONSTANT(wxBITMAP_TYPE_, JPEG) + WXJS_CONSTANT(wxBITMAP_TYPE_, JPEG_RESOURCE) + WXJS_CONSTANT(wxBITMAP_TYPE_, PNM) + WXJS_CONSTANT(wxBITMAP_TYPE_, PNM_RESOURCE) + WXJS_CONSTANT(wxBITMAP_TYPE_, PCX) + WXJS_CONSTANT(wxBITMAP_TYPE_, PCX_RESOURCE) + WXJS_CONSTANT(wxBITMAP_TYPE_, PICT) + WXJS_CONSTANT(wxBITMAP_TYPE_, PICT_RESOURCE) + WXJS_CONSTANT(wxBITMAP_TYPE_, ICON) + WXJS_CONSTANT(wxBITMAP_TYPE_, ICON_RESOURCE) + WXJS_CONSTANT(wxBITMAP_TYPE_, MACCURSOR) + WXJS_CONSTANT(wxBITMAP_TYPE_, MACCURSOR_RESOURCE) + WXJS_CONSTANT(wxBITMAP_TYPE_, ANY) + { 0 } +}; + +/*** + * + * + * No filtering + * + * + * Non-ASCII characters are filtered out. + * + * + * Non-alpha characters are filtered out. + * + * + * Non-alphanumeric characters are filtered out. + * + * + * Non-numeric characters are filtered out. + * + * + * Use an include list. The validator checks if the user input is on the list, + * complaining if not. + * + * + * Use an exclude list. The validator checks if the user input is on the list, + * complaining if it is. + * + * + * Use an include list. The validator checks if each input character is in + * the list (one character per list element), complaining if not. + * + * + * Use an include list. The validator checks if each input character is + * in the list (one character per list element), complaining if it is. + * + * + * See @wxTextValidator + * + * + */ +JSConstDoubleSpec wxFilterMap[] = +{ + WXJS_CONSTANT(wxFILTER_, NONE) + WXJS_CONSTANT(wxFILTER_, ASCII) + WXJS_CONSTANT(wxFILTER_, ALPHA) + WXJS_CONSTANT(wxFILTER_, ALPHANUMERIC) + WXJS_CONSTANT(wxFILTER_, NUMERIC) + WXJS_CONSTANT(wxFILTER_, INCLUDE_LIST) + WXJS_CONSTANT(wxFILTER_, EXCLUDE_LIST) + WXJS_CONSTANT(wxFILTER_, INCLUDE_CHAR_LIST) + WXJS_CONSTANT(wxFILTER_, EXCLUDE_CHAR_LIST) + { 0 } +}; + +/*** + * + * + * + * + * + * + * + * See @wxMenuBar, @wxMenu, @wxToolBar + * + * + * + */ +JSConstDoubleSpec wxItemKindMap[] = +{ + WXJS_CONSTANT(wxITEM_, SEPARATOR) + WXJS_CONSTANT(wxITEM_, NORMAL) + WXJS_CONSTANT(wxITEM_, CHECK) + WXJS_CONSTANT(wxITEM_, RADIO) + WXJS_CONSTANT(wxITEM_, MAX) + { 0 } +}; + +JSConstDoubleSpec wxBorderMap[] = +{ + WXJS_CONSTANT(wxBORDER_, DEFAULT) + WXJS_CONSTANT(wxBORDER_, NONE) + WXJS_CONSTANT(wxBORDER_, STATIC) + WXJS_CONSTANT(wxBORDER_, SIMPLE) + WXJS_CONSTANT(wxBORDER_, RAISED) + WXJS_CONSTANT(wxBORDER_, SUNKEN) + WXJS_CONSTANT(wxBORDER_, DOUBLE) + WXJS_CONSTANT(wxBORDER_, MASK) + { 0 } +}; + +void wxjs::gui::InitGuiConstants(JSContext *cx, JSObject *obj) +{ + // Define the global constants + + JS_DefineConstDoubles(cx, obj, wxGlobalMap); + + // Create all the separate constant objects. + + JSObject *constObj = JS_DefineObject(cx, obj, "wxDirection", + NULL, NULL, + JSPROP_READONLY | JSPROP_PERMANENT); + JS_DefineConstDoubles(cx, constObj, wxDirectionMap); + + constObj = JS_DefineObject(cx, obj, "wxStretch", + NULL, NULL, + JSPROP_READONLY | JSPROP_PERMANENT); + JS_DefineConstDoubles(cx, constObj, wxStretchMap); + + constObj = JS_DefineObject(cx, obj, "wxOrientation", + NULL, NULL, + JSPROP_READONLY | JSPROP_PERMANENT); + JS_DefineConstDoubles(cx, constObj, wxOrientationMap); + + constObj = JS_DefineObject(cx, obj, "wxAlignment", + NULL, NULL, + JSPROP_READONLY | JSPROP_PERMANENT); + JS_DefineConstDoubles(cx, constObj, wxAlignmentMap); + + constObj = JS_DefineObject(cx, obj, "wxId", + NULL, NULL, + JSPROP_READONLY | JSPROP_PERMANENT); + JS_DefineConstDoubles(cx, constObj, wxIdMap); + + constObj = JS_DefineObject(cx, obj, "wxKeyCode", + NULL, NULL, + JSPROP_READONLY | JSPROP_PERMANENT); + JS_DefineConstDoubles(cx, constObj, wxKeyCodeMap); + + constObj = JS_DefineObject(cx, obj, "wxCalendarDateBorder", + NULL, NULL, + JSPROP_READONLY | JSPROP_PERMANENT); + JS_DefineConstDoubles(cx, constObj, wxCalendarDateBorderMap); + + constObj = JS_DefineObject(cx, obj, "wxFontEncoding", + NULL, NULL, + JSPROP_READONLY | JSPROP_PERMANENT); + JS_DefineConstDoubles(cx, constObj, wxCalendarDateBorderMap); + + constObj = JS_DefineObject(cx, obj, "wxBitmapType", + NULL, NULL, + JSPROP_READONLY | JSPROP_PERMANENT); + JS_DefineConstDoubles(cx, constObj, wxBitmapTypeMap); + + constObj = JS_DefineObject(cx, obj, "wxFilter", + NULL, NULL, + JSPROP_READONLY | JSPROP_PERMANENT); + + JS_DefineConstDoubles(cx, constObj, wxFilterMap); + + constObj = JS_DefineObject(cx, obj, "wxItemKind", + NULL, NULL, + JSPROP_READONLY | JSPROP_PERMANENT); + JS_DefineConstDoubles(cx, constObj, wxItemKindMap); + + constObj = JS_DefineObject(cx, obj, "wxBorder", + NULL, NULL, + JSPROP_READONLY | JSPROP_PERMANENT); + JS_DefineConstDoubles(cx, constObj, wxBorderMap); +} Property changes on: ps/trunk/source/tools/atlas/wxJS/gui/misc/constant.cpp ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/precompiled.cpp =================================================================== --- ps/trunk/source/tools/atlas/wxJS/precompiled.cpp (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/precompiled.cpp (revision 5154) @@ -0,0 +1 @@ +#include "precompiled.h" Property changes on: ps/trunk/source/tools/atlas/wxJS/precompiled.cpp ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/io/fn.cpp =================================================================== --- ps/trunk/source/tools/atlas/wxJS/io/fn.cpp (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/io/fn.cpp (revision 5154) @@ -0,0 +1,576 @@ +#include "precompiled.h" + +/* + * wxJavaScript - fn.cpp + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: fn.cpp 732 2007-06-05 19:39:26Z fbraem $ + */ +#include +#ifndef WX_PRECOMP + #include +#endif + +#include "../common/main.h" +#include "fn.h" +#include "process.h" + +using namespace wxjs; + +/*** + * fn + * io + * + * A list of global IO functions + * + */ + +/*** + * + * + * + * + * + * + * + * Concatenates file1 and file2 to file3, returning true if successful. + * + * + */ +JSBool io::concatFiles(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxString file1; + wxString file2; + wxString file3; + + FromJS(cx, argv[2], file3); + FromJS(cx, argv[1], file2); + FromJS(cx, argv[0], file1); + + *rval = ToJS(cx, wxConcatFiles(file1, file2, file3)); + return JS_TRUE; +} + +/*** + * + * + * + * + * + * + * + * Copies SourceFile to TargetFile, returning true if successful. + * If overwrite parameter is true (default), the destination file + * is overwritten if it exists, but if overwrite is false, the + * functions fails in this case. + * + * + */ +JSBool io::copyFile(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxString file1; + wxString file2; + bool overwrite = true; + + if ( argc == 3 ) + { + if ( ! FromJS(cx, argv[2], overwrite) ) + { + return JS_FALSE; + } + } + + FromJS(cx, argv[1], file2); + FromJS(cx, argv[0], file1); + + *rval = ToJS(cx, wxCopyFile(file1, file2, overwrite)); + return JS_TRUE; +} + +/*** + * + * + * + * + * + * Returns true if the directory exists + * + * + */ +JSBool io::dirExists(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxString file; + FromJS(cx, argv[0], file); + *rval = ToJS(cx, wxDirExists(file)); + return JS_TRUE; +} + +/*** + * + * + * + * Returns a string containing the current (or working) directory. + * + * + */ +JSBool io::getCwd(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + *rval = ToJS(cx, wxGetCwd()); + return JS_TRUE; +} + +/*** + * + * + * + * + * + * Returns the free diskspace. Returns -1 if the path doesn't exist. + * Unlike wxWidgets, which implements this function as wxGetDiskSpace, + * wxJS has to separate this into two functions. + * + * + */ +JSBool io::getFreeDiskSpace(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxString path; + FromJS(cx, argv[0], path); + + wxLongLong free; + if ( wxGetDiskSpace(path, NULL, &free) ) + { + *rval = ToJS(cx, free.ToDouble()); + } + else + { + *rval = ToJS(cx, (double) -1); + } + return JS_TRUE; +} + +/*** + * + * + * + * + * + * Returns the free diskspace. Returns -1 if the path doesn't exist. + * Unlike wxWidgets, which implements this function as wxGetDiskSpace, + * wxJS has to separate this into two functions. + * + * + */ +JSBool io::getTotalDiskSpace(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxString path; + FromJS(cx, argv[0], path); + + wxLongLong total; + if ( wxGetDiskSpace(path, &total) ) + { + *rval = ToJS(cx, total.ToDouble()); + } + else + { + *rval = ToJS(cx, (double) -1); + } + return JS_TRUE; +} + +/*** + * + * + * + * + * + * Returns true if the file exists. + * + * + */ +JSBool io::fileExists(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxString file1; + FromJS(cx, argv[0], file1); + + *rval = ToJS(cx, wxFileExists(file1)); + return JS_TRUE; +} + +/*** + * + * + * + * Returns the Windows directory under Windows; on other platforms returns the empty string. + * + * + */ +JSBool io::getOSDirectory(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + *rval = ToJS(cx, wxGetOSDirectory()); + return JS_TRUE; +} + +/*** + * + * + * + * + * + * Returns true if the argument is an absolute filename, i.e. with a slash or drive name at the beginning. + * + * + */ +JSBool io::isAbsolutePath(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxString file; + FromJS(cx, argv[0], file); + *rval = ToJS(cx, wxIsAbsolutePath(file)); + return JS_TRUE; +} + +/*** + * + * + * + * + * + * Returns true if the pattern contains wildcards. + * + * + */ +JSBool io::isWild(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxString pattern; + FromJS(cx, argv[0], pattern); + + *rval = ToJS(cx, wxIsWild(pattern)); + return JS_TRUE; +} + + +/*** + * + * + * + * + * + * + * + * Returns true if the pattern matches the text; if DotSpecial is true, filenames beginning with + * a dot are not matched with wildcard characters. + * + * + */ +JSBool io::matchWild(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxString pattern; + wxString text; + bool dotSpecial; + + FromJS(cx, argv[2], dotSpecial); + FromJS(cx, argv[1], text); + FromJS(cx, argv[0], pattern); + + *rval = ToJS(cx, wxMatchWild(pattern, text, dotSpecial)); + return JS_TRUE; +} + +/*** + * + * + * + * + * + * + * Makes the directory dir, returning true if successful. + * perm is the access mask for the directory for the systems on which it is + * supported (Unix) and doesn't have effect for the other ones. + * + * + */ +JSBool io::mkDir(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxString dir; + int perm = 777; + + if ( argc > 0 ) + { + if ( ! FromJS(cx, argv[1], perm) ) + return JS_FALSE; + } + + *rval = ToJS(cx, wxMkdir(dir, perm)); + return JS_TRUE; +} + +/*** + * + * + * + * + * + * + * Renames the file From to To, returning true if successful. + * + * + */ +JSBool io::renameFile(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxString file1; + wxString file2; + + FromJS(cx, argv[1], file2); + FromJS(cx, argv[0], file1); + + *rval = ToJS(cx, wxRenameFile(file1, file2)); + return JS_TRUE; +} + +/*** + * + * + * + * + * + * Removes the file, return true on success. + * + * + */ +JSBool io::removeFile(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxString file; + + FromJS(cx, argv[0], file); + + *rval = ToJS(cx, wxRemoveFile(file)); + return JS_TRUE; +} + +/*** + * + * + * + * + * + * Removes the directory. Returns true on success. + * + * + */ +JSBool io::rmDir(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxString dir; + FromJS(cx, argv[0], dir); + #if defined( __WXMAC__) || defined(__WXGTK__) + *rval = ToJS(cx, wxRmDir(dir.mb_str())); + #else + *rval = ToJS(cx, wxRmDir(dir)); + #endif + return JS_TRUE; +} + +/*** + * + * + * + * + * + * Sets the current working directory, returning true if the operation succeeded. + * Under MS Windows, the current drive is also changed if dir contains a drive specification. + * + * + */ +JSBool io::setWorkingDirectory(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxString dir; + + FromJS(cx, argv[0], dir); + + *rval = ToJS(cx, wxSetWorkingDirectory(dir)); + return JS_TRUE; +} + +/*** + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + */ +JSBool io::execute(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + int flags = wxEXEC_ASYNC; + wxString cmd; + + if ( JSVAL_IS_STRING(argv[0]) ) + { + FromJS(cx, argv[0], cmd); + if ( argc == 1 ) + { + *rval = ToJS(cx, wxExecute(cmd)); + return JS_TRUE; + } + + if ( JSVAL_IS_INT(argv[1]) ) + { + wxProcess *p = NULL; + if ( argc > 2 ) + { + p = Process::GetPrivate(cx, argv[2]); + } + if ( FromJS(cx, argv[1], flags) ) + { + *rval = ToJS(cx, wxExecute(cmd, flags, p)); + } + return JS_TRUE; + } + else if ( JSVAL_IS_OBJECT(argv[1]) ) + { + wxArrayString output; + wxArrayString error; + + if ( argc > 3 ) + { + if ( ! FromJS(cx, argv[3], flags) ) + return JS_FALSE; + } + if ( argc > 2 + && JSVAL_IS_INT(argv[2]) ) + { + if ( ! FromJS(cx, argv[2], flags) ) + return JS_FALSE; + } + *rval = ToJS(cx, wxExecute(cmd, output, error, flags)); + + if ( argc > 2 && JSVAL_IS_OBJECT(argv[2]) ) + { + JSObject *objArr = JSVAL_TO_OBJECT(argv[2]); + if ( JS_IsArrayObject(cx, objArr) ) + { + for(wxArrayString::size_type i = 0; i < error.size(); i++) + { + jsval element = ToJS(cx, error[i]); + JS_SetElement(cx, objArr, i, &element); + } + } + } + + if ( argc > 1 && JSVAL_IS_OBJECT(argv[1]) ) + { + JSObject *objArr = JSVAL_TO_OBJECT(argv[1]); + if ( JS_IsArrayObject(cx, objArr) ) + { + for(wxArrayString::size_type i = 0; i < output.size(); i++) + { + jsval element = ToJS(cx, output[i]); + JS_SetElement(cx, objArr, i, &element); + } + } + } + return JS_TRUE; + } + } + else if ( JSVAL_IS_OBJECT(argv[0]) ) + { + JSObject *objArr = JSVAL_TO_OBJECT(argv[0]); + if ( JS_IsArrayObject(cx, objArr) ) + { + wxProcess *p = NULL; + switch(argc) + { + case 3: + p = (wxProcess *) Process::GetPrivate(cx, argv[2]); + // Fall through + case 2: + if ( ! FromJS(cx, argv[1], flags) ) + break; + // Fall through + default: + { + jsuint length; + JS_GetArrayLength(cx, objArr, &length); + if ( length > 0 ) + { + wxChar **cmdArgv = new wxChar*[length + 1]; + for(jsuint i = 0; i < length; i++) + { + jsval element; + if ( JS_GetElement(cx, objArr, i, &element) == JS_TRUE ) + { + wxString arg; + FromJS(cx, element, arg); + + cmdArgv[i] = new wxChar[arg.Length() + 1]; + wxStrncpy(cmdArgv[i], arg.c_str(), arg.Length()); + cmdArgv[i][arg.Length()] = '\0'; + } + } + cmdArgv[length] = NULL; + *rval = ToJS(cx, wxExecute(cmdArgv, flags, p)); + delete[] cmdArgv; + } + return JS_TRUE; + } + } + } + } + return JS_FALSE; +} + +/*** + * + * + * + * + * + * Executes a command in an interactive shell window. If no command is specified, + * then just the shell is spawned. + * + * + */ +JSBool io::shell(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxString cmd; + + FromJS(cx, argv[0], cmd); + + *rval = ToJS(cx, wxShell(cmd)); + return JS_TRUE; +} Property changes on: ps/trunk/source/tools/atlas/wxJS/io/fn.cpp ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/io/zostream.h =================================================================== --- ps/trunk/source/tools/atlas/wxJS/io/zostream.h (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/io/zostream.h (revision 5154) @@ -0,0 +1,67 @@ +/* + * wxJavaScript - zostream.h + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: zostream.h 598 2007-03-07 20:13:28Z fbraem $ + */ +#ifndef wxjs_io_zostream_h +#define wxjs_io_zostream_h + +#include + +namespace wxjs +{ + namespace io + { + class ZipOutputStream : public wxZipOutputStream, + public ApiWrapper + { + public: + + ZipOutputStream(wxOutputStream &str, int level); + + static Stream* Construct(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, bool constructing); + static void Destruct(JSContext *cx, Stream *p); + + /** + * Callback for retrieving properties of wxInputStream + */ + static bool GetProperty(Stream *p, JSContext *cx, JSObject *obj, int id, jsval *vp); + + WXJS_DECLARE_PROPERTY_MAP() + + /** + * Property Ids. + */ + enum + { + P_LEVEL + }; + + WXJS_DECLARE_METHOD_MAP() + static JSBool setComment(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval); + + // Keep a reference to the stream to avoid deletion. + Stream m_refStream; + }; + }; // namespace io +}; // namespace wxjs +#endif // wxjs_io_zostream_h Property changes on: ps/trunk/source/tools/atlas/wxJS/io/zostream.h ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/io/file.cpp =================================================================== --- ps/trunk/source/tools/atlas/wxJS/io/file.cpp (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/io/file.cpp (revision 5154) @@ -0,0 +1,647 @@ +#include "precompiled.h" + +/* + * wxJavaScript - file.cpp + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: file.cpp 598 2007-03-07 20:13:28Z fbraem $ + */ +// file.cpp +#include +#ifndef WX_PRECOMP + #include +#endif + +#include "../common/main.h" +#include "../ext/wxjs_ext.h" + +#include "file.h" + +using namespace wxjs; +using namespace wxjs::io; + +/*** + * file + * io + * + * A wxFile performs raw file I/O. + * This is a very small class designed to minimize the overhead of using it - + * in fact, there is hardly any overhead at all, but using it brings you + * automatic error checking and hides differences between platforms. + * wxFile is a wrapper around a file descriptor, while @wxFFile is a wrapper + * around the FILE structure. + * + */ +WXJS_INIT_CLASS(File, "wxFile", 0) + +/*** + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * wxSeekMode is ported as a separate JavaScript object. + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + */ +WXJS_BEGIN_CONSTANT_MAP(File) + WXJS_CONSTANT(wxFILE_, KIND_UNKNOWN) + WXJS_CONSTANT(wxFILE_, KIND_DISK) + WXJS_CONSTANT(wxFILE_, KIND_TERMINAL) + WXJS_CONSTANT(wxFILE_, KIND_PIPE) + { wxFile::read, "read", WXJS_READONLY }, + { wxFile::write, "write", WXJS_READONLY }, + { wxFile::read_write, "read_write", WXJS_READONLY }, + { wxFile::write_append, "write_append", WXJS_READONLY }, + { wxFile::write_excl, "write_excl", WXJS_READONLY }, + { wxFile::fd_stdin, "fd_stdin", WXJS_READONLY }, + { wxFile::fd_stdout, "fd_stdout", WXJS_READONLY }, + { wxFile::fd_stderr, "fd_stderr", WXJS_READONLY }, + WXJS_CONSTANT(wxS_, IRUSR) + WXJS_CONSTANT(wxS_, IWUSR) + WXJS_CONSTANT(wxS_, IXUSR) + WXJS_CONSTANT(wxS_, IRGRP) + WXJS_CONSTANT(wxS_, IWGRP) + WXJS_CONSTANT(wxS_, IXGRP) + WXJS_CONSTANT(wxS_, IROTH) + WXJS_CONSTANT(wxS_, IWOTH) + WXJS_CONSTANT(wxS_, IXOTH) + WXJS_CONSTANT(wxS_, DEFAULT) +WXJS_END_CONSTANT_MAP() + +void File::InitClass(JSContext *cx, JSObject *obj, JSObject *proto) +{ + JSConstDoubleSpec wxPathFormatMap[] = + { + WXJS_CONSTANT(wx, FromCurrent) + WXJS_CONSTANT(wx, FromStart) + WXJS_CONSTANT(wx, FromEnd) + { 0 } + }; + + JSObject *constObj = JS_DefineObject(cx, obj, "wxSeekMode", + NULL, NULL, + JSPROP_READONLY | JSPROP_PERMANENT); + JS_DefineConstDoubles(cx, constObj, wxPathFormatMap); +} + +/*** + * + * + * Returns true when end of file is reached. + * When the file is not open, undefined is returned. + * + * + * Returns true when the file is open. + * + * + * Returns the length of the file. + * When the file is not open, undefined is returned. + * + * + * Returns the current position or -1. + * When the file is not open, undefined is returned. + * + * + */ +WXJS_BEGIN_PROPERTY_MAP(File) + WXJS_READONLY_PROPERTY(P_EOF, "eof") + WXJS_READONLY_PROPERTY(P_OPENED, "opened") + WXJS_READONLY_PROPERTY(P_LENGTH, "length") + WXJS_READONLY_PROPERTY(P_TELL, "tell") + WXJS_READONLY_PROPERTY(P_KIND, "kind") +WXJS_END_PROPERTY_MAP() + +bool File::GetProperty(wxFile *p, JSContext *cx, JSObject *obj, int id, jsval *vp) +{ + switch(id) + { + case P_EOF: + *vp = p->IsOpened() ? ToJS(cx, p->Eof()) : JSVAL_VOID; + break; + case P_OPENED: + *vp = ToJS(cx, p->IsOpened()); + break; + case P_LENGTH: + *vp = p->IsOpened() ? ToJS(cx, (long) p->Length()) : JSVAL_VOID; + break; + case P_TELL: + *vp = p->IsOpened() ? ToJS(cx, (long) p->Tell()) : JSVAL_VOID; + break; + case P_KIND: + *vp = p->IsOpened() ? ToJS(cx, (int) p->GetKind()) : JSVAL_VOID; + break; + } + return true; +} + +/*** + * + * + * + * The filename + * + * The mode in which to open the file. See @wxFile#Mode. + * + * + * + * Constructs a new wxFile object. When a filename is passed, + * The file is opened, and you can check whether the operation +* was successful or not by checking @wxFile#opened. + * + * + */ +wxFile *File::Construct(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, bool constructing) +{ + if ( argc > 2 ) + argc = 2; + + wxString fileName; + + int mode = wxFile::read; + + switch(argc) + { + case 2: + if ( ! FromJS(cx, argv[1], mode) ) + break; + // Walk through + case 1: + FromJS(cx, argv[0], fileName); + return new wxFile(fileName, (wxFile::OpenMode) mode); + break; + case 0: + return new wxFile(); + break; + } + return NULL; +} + +WXJS_BEGIN_METHOD_MAP(File) + WXJS_METHOD("attach", attach, 1) + WXJS_METHOD("detach", detach, 0) + WXJS_METHOD("close", close, 0) + WXJS_METHOD("create", create, 3) + WXJS_METHOD("flush", flush, 0) + WXJS_METHOD("open", open, 2) + WXJS_METHOD("read", read, 1) + WXJS_METHOD("seek", seek, 2) + WXJS_METHOD("seekEnd", seekEnd, 1) + WXJS_METHOD("write", write, 1) +WXJS_END_METHOD_MAP() + +/*** + * + * + * + * A file descriptor + * + * + * + * Attaches an existing file descriptor to the wxFile object. + * Example of predefined file descriptors are 0, 1 and 2 which correspond to + * stdin, stdout and stderr (and have symbolic names of wxFile.fd_stdin, wxFile.fd_stdout + * and wxFile.fd_stderr). + * + * + */ +JSBool File::attach(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxFile *p = GetPrivate(cx, obj); + wxASSERT_MSG(p != NULL, wxT("No private data associated with wxFile")); + + if ( ! p->IsOpened() ) + { + return JS_FALSE; + } + + int fd; + if ( FromJS(cx, argv[0], fd) ) + { + p->Attach(fd); + return JS_TRUE; + } + + return JS_FALSE; +} + +/*** + * + * + * + * Closes the file. + * + * + */ +JSBool File::close(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxFile *p = GetPrivate(cx, obj); + wxASSERT_MSG(p != NULL, wxT("No private data associated with wxFile")); + + if ( p->IsOpened() ) + p->Close(); + + return JS_TRUE; +} + +/*** + * + * + * + * Get back a file descriptor from wxFile object - the caller is responsible for closing + * the file if this descriptor is opened. @wxFile#opened will return false + * after call to detach. + * + * + */ +JSBool File::detach(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxFile *p = GetPrivate(cx, obj); + wxASSERT_MSG(p != NULL, wxT("No private data associated with wxFile")); + + if ( ! p->IsOpened() ) + { + return JS_FALSE; + } + + p->Detach(); + + return JS_TRUE; +} + +/*** + * + * + * The name of the file to create. + * + * Overwrite the file when it already exist? The default is false. + * + * + * + * + * Creates a file for writing. + * + * + */ +JSBool File::create(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxFile *p = GetPrivate(cx, obj); + wxASSERT_MSG(p != NULL, wxT("No private data associated with wxFile")); + + wxString fileName; + bool overwrite = false; + int access = wxS_DEFAULT; + + FromJS(cx, argv[0], fileName); + if ( argc > 1 + && ! FromJS(cx, argv[1], overwrite) ) + { + return JS_FALSE; + } + + if ( argc > 2 + && ! FromJS(cx, argv[2], access) ) + { + return JS_FALSE; + } + + *rval = p->Create(fileName, overwrite, access); + + return JS_TRUE; +} + +/*** + * + * + * + * Flushes the file. + * + * + */ +JSBool File::flush(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxFile *p = GetPrivate(cx, obj); + wxASSERT_MSG(p != NULL, wxT("No private data associated with wxFile")); + + if ( ! p->IsOpened() ) + { + return JS_FALSE; + } + + p->Flush(); + + return JS_TRUE; +} + +/*** + * + * + * The name of the file to open + * + * + * + * Opens a file. + * + * + */ +JSBool File::open(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxFile *p = GetPrivate(cx, obj); + wxASSERT_MSG(p != NULL, wxT("No private data associated with wxFile")); + + wxString fileName; + bool result = false; + FromJS(cx, argv[0], fileName); + + if ( argc > 1 ) + { + int mode; + if ( FromJS(cx, argv[1], mode) ) + { + result = p->Open(fileName, (wxFile::OpenMode) mode); + } + else + { + return JS_FALSE; + } + } + else + result = p->Open(fileName); + + *rval = result ? JSVAL_TRUE : JSVAL_FALSE; + + return JS_TRUE; +} + +/*** + * + * + * The number of bytes to read. + * + * + * Reads the specified number of bytes and returns a buffer. + * + * + */ +JSBool File::read(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxFile *p = GetPrivate(cx, obj); + wxASSERT_MSG(p != NULL, wxT("No private data associated with wxFile")); + + if ( ! p->IsOpened() ) + { + return JS_FALSE; + } + int count; + if ( FromJS(cx, argv[0], count) + && count > 0 ) + { + unsigned char *buffer = new unsigned char[count]; + int readCount = p->Read(buffer, count); + if ( readCount == wxInvalidOffset ) + { + *rval = JSVAL_VOID; + } + else + { + *rval = OBJECT_TO_JSVAL(wxjs::ext::CreateMemoryBuffer(cx, buffer, count)); + } + delete[] buffer; + + return JS_TRUE; + } + return JS_FALSE; +} + +/*** + * + * + * Offset to seek to. + * + * + * + * Seeks the offset. Returns the actual position or -1. + * See also @wxFile#seekEnd. + * + * + */ +JSBool File::seek(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxFile *p = GetPrivate(cx, obj); + wxASSERT_MSG(p != NULL, wxT("No private data associated with wxFile")); + + if ( ! p->IsOpened() ) + { + return JS_FALSE; + } + + int offset; + if ( ! FromJS(cx, argv[0], offset) ) + { + return JS_FALSE; + } + + int pos; + + if ( argc > 1 ) + { + int mode; + if ( FromJS(cx, argv[1], mode) ) + { + pos = p->Seek(offset, (wxSeekMode) mode); + } + else + { + return JS_FALSE; + } + } + else + pos = p->Seek(offset); + + *rval = ToJS(cx, pos); + return JS_TRUE; +} + +/*** + * + * + * Offset to seek to. + * + * + * Moves the file pointer to the specified number of bytes before the end of the file. + * Returns the actual position or -1 on error. + *

Remark: Is the same as calling seek(Offset, wxFile.FromEnd) + *
+ *
+ */ +JSBool File::seekEnd(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxFile *p = GetPrivate(cx, obj); + wxASSERT_MSG(p != NULL, wxT("No private data associated with wxFile")); + + if ( ! p->IsOpened() ) + { + return JS_FALSE; + } + + int offset; + if ( FromJS(cx, argv[0], offset) ) + { + *rval = ToJS(cx, (int) p->SeekEnd(offset)); + return JS_TRUE; + } + + return JS_FALSE; +} + +/*** + * + * + * + * + * + * + * + * + * + * Writes the string or buffer to the file. A String + * is written in the specified encoding. The default is + * UTF-8 because most files are still written as UTF-8 + * or ASCII. Returns the actual number of bytes written to the file. + * + * + */ +JSBool File::write(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxFile *p = GetPrivate(cx, obj); + wxASSERT_MSG(p != NULL, wxT("No private data associated with wxFFile")); + + if ( ! p->IsOpened() ) + { + return JS_FALSE; + } + + if ( JSVAL_IS_OBJECT(argv[0]) ) + { + wxMemoryBuffer* buffer = wxjs::ext::GetMemoryBuffer(cx, JSVAL_TO_OBJECT(argv[0])); + if ( buffer != NULL ) + { + *rval = ToJS(cx, p->Write(buffer->GetData(), buffer->GetDataLen())); + return JS_TRUE; + } + } + + wxString encoding(wxJS_EXTERNAL_ENCODING); + if ( argc > 1 ) + { + FromJS(cx, argv[1], encoding); + } + wxCSConv conv(encoding); + + wxString content; + FromJS(cx, argv[0], content); + *rval = ToJS(cx, (int) p->Write(content, conv)); + + return JS_TRUE; +} + +WXJS_BEGIN_STATIC_METHOD_MAP(File) + WXJS_METHOD("access", access, 2) + WXJS_METHOD("exists", exists, 1) +WXJS_END_METHOD_MAP() + +/*** + * + * + * Filename to check + * File mode + * + * + * This function verifies if we may access the given file in specified mode. + * Only values of @wxFile#read or @wxFile#write really make sense here. + * + * + */ +JSBool File::access(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxString filename; + FromJS(cx, argv[0], filename); + + int mode; + + if ( FromJS(cx, argv[1], mode) ) + { + *rval = ToJS(cx, wxFile::Access(filename, (wxFile::OpenMode) mode)); + return JS_TRUE; + } + return JS_FALSE; +} + +/*** + * + * + * + * + * + * Returns true when the file exists. + * + * + */ +JSBool File::exists(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxString filename; + FromJS(cx, argv[0], filename); + *rval = ToJS(cx, wxFile::Exists(filename)); + return JS_TRUE; +} + Property changes on: ps/trunk/source/tools/atlas/wxJS/io/file.cpp ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/io/http.h =================================================================== --- ps/trunk/source/tools/atlas/wxJS/io/http.h (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/io/http.h (revision 5154) @@ -0,0 +1,53 @@ +/* + * wxJavaScript - http.h + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: http.h 598 2007-03-07 20:13:28Z fbraem $ + */ +#ifndef _wxjs_io_http_h +#define _wxjs_io_http_h + +#include + +namespace wxjs +{ + namespace io + { + class SocketBasePrivate; + + class HTTP : public ApiWrapper + { + public: + + static SocketBasePrivate *Construct(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, bool constructing); + static void Destruct(JSContext *cx, SocketBasePrivate *p); + static bool GetProperty(SocketBasePrivate *p, JSContext *cx, JSObject *obj, int id, jsval *vp); + + WXJS_DECLARE_PROPERTY_MAP() + enum + { + P_RESPONSE = WXJS_START_PROPERTY_ID + , P_HEADERS + }; + }; + }; // namespace io +}; // namespace wxjs +#endif // _wxjs_io_http_h Property changes on: ps/trunk/source/tools/atlas/wxJS/io/http.h ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/gui/misc/bmphdlr.cpp =================================================================== --- ps/trunk/source/tools/atlas/wxJS/gui/misc/bmphdlr.cpp (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/gui/misc/bmphdlr.cpp (revision 5154) @@ -0,0 +1,52 @@ +#include "precompiled.h" + +/* + * wxJavaScript - bmphdlr.cpp + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: bmphdlr.cpp 598 2007-03-07 20:13:28Z fbraem $ + */ +#ifndef WX_PRECOMP + #include +#endif + +#include "../../common/main.h" +#include "../../common/type.h" +#include "../../common/jsutil.h" + +#include "imghand.h" + +using namespace wxjs; +using namespace wxjs::gui; + +/*** + * misc/bmphdlr + * gui + * + * Image handler for bitmaps. + * + */ +WXJS_INIT_CLASS(BMPHandler, "wxBMPHandler", 0) + +ImageHandlerPrivate* BMPHandler::Construct(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, bool constructing) +{ + return new ImageHandlerPrivate(new wxBMPHandler(), true); +} Property changes on: ps/trunk/source/tools/atlas/wxJS/gui/misc/bmphdlr.cpp ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/gui/errors.cpp =================================================================== --- ps/trunk/source/tools/atlas/wxJS/gui/errors.cpp (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/gui/errors.cpp (revision 5154) @@ -0,0 +1,31 @@ +#include "precompiled.h" + +/* + * wxJavaScript - errors.cpp + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id$ + */ + +#include "errors.h" + +const char *WXJS_NO_PARENT_ERROR = "%s needs a valid parent window"; +const char *WXJS_INVALID_ARG_TYPE = "argument %d must be of type %s"; \ No newline at end of file Property changes on: ps/trunk/source/tools/atlas/wxJS/gui/errors.cpp ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/io/protocol.cpp =================================================================== --- ps/trunk/source/tools/atlas/wxJS/io/protocol.cpp (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/io/protocol.cpp (revision 5154) @@ -0,0 +1,255 @@ +#include "precompiled.h" + +/* + * wxJavaScript - protocol.cpp + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: protocol.cpp 598 2007-03-07 20:13:28Z fbraem $ + */ +#include +#ifndef WX_PRECOMP + #include +#endif + +#include "../common/main.h" +#include "jsstream.h" +#include "sistream.h" +#include "sockbase.h" +#include "protocol.h" + +using namespace wxjs; +using namespace wxjs::io; + +/*** + * protocol + * io + * + * Prototype for all protocol classes. + * + */ +WXJS_INIT_CLASS(Protocol, "wxProtocol", 0) + +/*** + * + * + * No error + * A generic network error occurred. + * An error occurred during negotiation. + * The client failed to connect the server. + * Invalid value. + * + * The remote file doesn't exist. + * Last action aborted. + * An error occurred during reconnection. + * Someone tried to send a command during a transfer. + * + * wxProtocolError is ported to JavaScript as a separate class. Note that this + * class doesn't exist in wxWidgets. + * + * + * + */ +void Protocol::InitClass(JSContext *cx, JSObject *obj, JSObject *proto) +{ + JSConstDoubleSpec wxProtocolErrorMap[] = + { + WXJS_CONSTANT(wxPROTO_, NOERR) + WXJS_CONSTANT(wxPROTO_, NETERR) + WXJS_CONSTANT(wxPROTO_, PROTERR) + WXJS_CONSTANT(wxPROTO_, CONNERR) + WXJS_CONSTANT(wxPROTO_, INVVAL) + WXJS_CONSTANT(wxPROTO_, NOHNDLR) + WXJS_CONSTANT(wxPROTO_, NOFILE) + WXJS_CONSTANT(wxPROTO_, ABRT) + WXJS_CONSTANT(wxPROTO_, RCNCT) + WXJS_CONSTANT(wxPROTO_, STREAMING) + { 0 } + }; + + JSObject *constObj = JS_DefineObject(cx, obj, "wxProtocolError", + NULL, NULL, + JSPROP_READONLY | JSPROP_PERMANENT); + JS_DefineConstDoubles(cx, constObj, wxProtocolErrorMap); +} + +/*** + * + * + * Returns the type of the content of the last opened stream. It is a mime-type + * + * + * Returns the last occurred error. See @wxProtocol#wxProtocolError. + * + * + */ +WXJS_BEGIN_PROPERTY_MAP(Protocol) + WXJS_READONLY_PROPERTY(P_CONTENT_TYPE, "contentType") + WXJS_READONLY_PROPERTY(P_ERROR, "error") +WXJS_END_PROPERTY_MAP() + +bool Protocol::GetProperty(SocketBasePrivate *p, JSContext *cx, JSObject *obj, int id, jsval *vp) +{ + wxProtocol *protocol = dynamic_cast(p->GetBase()); + + switch(id) + { + case P_CONTENT_TYPE: + *vp = ToJS(cx, protocol->GetContentType()); + break; + case P_ERROR: + *vp = ToJS(cx, protocol->GetError()); + break; + } + return true; +} + +WXJS_BEGIN_METHOD_MAP(Protocol) + WXJS_METHOD("abort", abort, 0) + WXJS_METHOD("getInputStream", getInputStream, 1) + WXJS_METHOD("reconnect", reconnect, 0) + WXJS_METHOD("setPassword", setPassword, 1) + WXJS_METHOD("setUser", setUser, 1) +WXJS_END_METHOD_MAP() + +/*** + * + * + * + * Abort the current stream. + * + * + */ +JSBool Protocol::abort(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + SocketBasePrivate *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + wxProtocol *protocol = dynamic_cast(p->GetBase()); + *rval = ToJS(cx, protocol->Abort()); + return JS_TRUE; +} + +/*** + * + * + * + * + * + * Creates a new input stream on the specified path. + * You can use all but seek functionality of wxStream. + * @wxInputStream#seekI isn't available on all stream. For example, http or + * ftp streams doesn't deal with it. Other functions like + * @wxStreamBase#size aren't available for the moment for + * this sort of stream. You will be notified when the EOF + * is reached by an error. + * + * + */ +JSBool Protocol::getInputStream(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + SocketBasePrivate *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + wxProtocol *protocol = dynamic_cast(p->GetBase()); + + wxString path; + FromJS(cx, argv[0], path); + + wxInputStream *stream = protocol->GetInputStream(path); + if ( stream != NULL ) + { + Stream *js_stream = new Stream(stream, false); + p->AddStream(js_stream); + *rval = SocketInputStream::CreateObject(cx, js_stream, NULL); + js_stream->SetObject(JSVAL_TO_OBJECT(*rval)); + } + return JS_TRUE; +} + +/*** + * + * + * + * Tries to reestablish a previous opened connection (close and renegotiate connection). + * + * + */ +JSBool Protocol::reconnect(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + SocketBasePrivate *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + wxProtocol *protocol = dynamic_cast(p->GetBase()); + + *rval = ToJS(cx, protocol->Reconnect()); + return JS_TRUE; +} + +/*** + * + * + * + * + * + * Sets the authentication password. It is mainly useful when FTP is used. + * + * + */ +JSBool Protocol::setPassword(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + SocketBasePrivate *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + wxProtocol *protocol = dynamic_cast(p->GetBase()); + + wxString pwd; + FromJS(cx, argv[0], pwd); + protocol->SetPassword(pwd); + return JS_TRUE; +} + +/*** + * + * + * + * + * + * Sets the authentication user. It is mainly useful when FTP is used. + * + * + */ +JSBool Protocol::setUser(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + SocketBasePrivate *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + wxProtocol *protocol = dynamic_cast(p->GetBase()); + + wxString user; + FromJS(cx, argv[0], user); + protocol->SetUser(user); + return JS_TRUE; +} Property changes on: ps/trunk/source/tools/atlas/wxJS/io/protocol.cpp ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/io/distream.cpp =================================================================== --- ps/trunk/source/tools/atlas/wxJS/io/distream.cpp (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/io/distream.cpp (revision 5154) @@ -0,0 +1,256 @@ +#include "precompiled.h" + +/* + * wxJavaScript - distream.cpp + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: distream.cpp 598 2007-03-07 20:13:28Z fbraem $ + */ +#include +#ifndef WX_PRECOMP + #include +#endif + +#include "../common/main.h" + +#include "stream.h" +#include "istream.h" +#include "distream.h" + +using namespace wxjs; +using namespace wxjs::io; + +/*** + * distream + * io + * + * This class provides functions that read binary data types in a portable way. + * Data can be read in either big-endian or little-endian format, little-endian being + * the default on all architectures. + *

+ * If you want to read data from text files (or streams) use @wxTextInputStream instead. + *

+ * Remark :This class is not thoroughly tested. If you find problems let + * it know on the project forum. + *
+ */ + +WXJS_INIT_CLASS(DataInputStream, "wxDataInputStream", 1) +/*** + * + * + * An input stream + * + * + * Constructs a new wxDataInputStream object. + * + * + */ +wxDataInputStream* DataInputStream::Construct(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, bool constructing) +{ + Stream *in = InputStream::GetPrivate(cx, argv[0]); + if ( in == NULL ) + return NULL; + + // This is needed, because otherwise the stream can be garbage collected. + // Another method could be to root the stream, but how are we going to unroot it? + JS_DefineProperty(cx, obj, "__stream__", argv[0], NULL, NULL, JSPROP_READONLY); + + return new wxDataInputStream(*dynamic_cast(in->GetStream())); +} + +WXJS_BEGIN_METHOD_MAP(DataInputStream) + WXJS_METHOD("bigEndianOrdered", bigEndianOrdered, 1) + WXJS_METHOD("read64", read64, 0) + WXJS_METHOD("read32", read32, 0) + WXJS_METHOD("read16", read16, 0) + WXJS_METHOD("read8", read8, 0) + WXJS_METHOD("readString", readString, 0) +WXJS_END_METHOD_MAP() + +/*** + * + * + * + * + * + * If Ordered is true, all data will be read in big-endian order, + * such as written by programs on a big endian architecture (e.g. Sparc) + * or written by Java-Streams (which always use big-endian order). + * + * + */ + JSBool DataInputStream::bigEndianOrdered(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxDataInputStream *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + bool ordered; + if ( FromJS(cx, argv[0], ordered) ) + { + p->BigEndianOrdered(ordered); + return JS_TRUE; + } + return JS_FALSE; +} + +/*** + * + * + * + * Reads a 64 bit integer from the stream. + * + * + */ +JSBool DataInputStream::read64(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxDataInputStream *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + wxUint64 value = p->Read64(); + +// Check this for other platforms! +#ifdef __WXMSW__ + *rval = ToJS(cx, (long) value); +#else + *rval = ToJS(cx, (int) value); +#endif + + return JS_TRUE; +} + +/*** + * + * + * + * Reads a 32 bit integer from the stream. + * + * + */ +JSBool DataInputStream::read32(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxDataInputStream *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + wxUint32 value = p->Read32(); + +// Check this for other platforms! +#ifdef __WXMSW__ + *rval = ToJS(cx, (int) value); +#else + *rval = ToJS(cx, (int) value); +#endif + + return JS_TRUE; +} + +/*** + * + * + * + * Reads a 16 bit integer from the stream. + * + * + */ +JSBool DataInputStream::read16(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxDataInputStream *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + wxUint16 value = p->Read16(); + +// Check this for other platforms! +#ifdef __WXMSW__ + *rval = ToJS(cx, (int) value); +#else + *rval = ToJS(cx, (int) value); +#endif + + return JS_TRUE; +} + +/*** + * + * + * + * Reads a 8 bit integer from the stream. + * + * + */ +JSBool DataInputStream::read8(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxDataInputStream *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + wxUint8 value = p->Read8(); + +// Check this for other platforms! +#ifdef __WXMSW__ + *rval = ToJS(cx, (int) value); +#else + *rval = ToJS(cx, (int) value); +#endif + + return JS_TRUE; +} + +/*** + * + * + * + * Reads a double (IEEE encoded) from a stream. + * + * + */ +JSBool DataInputStream::readDouble(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxDataInputStream *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + *rval = ToJS(cx, p->ReadDouble()); + + return JS_TRUE; +} + +/*** + * + * + * + * Reads a string from a stream. Actually, this function first reads a long integer + * specifying the length of the string (without the last null character) and then reads the string. + * + * + */ +JSBool DataInputStream::readString(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxDataInputStream *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + *rval = ToJS(cx, p->ReadString()); + return JS_TRUE; +} Property changes on: ps/trunk/source/tools/atlas/wxJS/io/distream.cpp ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/io/dostream.cpp =================================================================== --- ps/trunk/source/tools/atlas/wxJS/io/dostream.cpp (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/io/dostream.cpp (revision 5154) @@ -0,0 +1,277 @@ +#include "precompiled.h" + +/* + * wxJavaScript - dostream.cpp + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: dostream.cpp 598 2007-03-07 20:13:28Z fbraem $ + */ +#include +#ifndef WX_PRECOMP + #include +#endif + +#include "../common/main.h" +#include "constant.h" +#include "stream.h" +#include "ostream.h" +#include "dostream.h" + +using namespace wxjs; +using namespace wxjs::io; + +/*** + * dostream + * io + * + * This class provides functions that write binary data types in a portable way. + * Data can be written in either big-endian or little-endian format, little-endian + * being the default on all architectures. + * If you want to write data to text files (or streams) use @wxTextOutputStream instead. + *

+ * Remark :This class is not thoroughly tested. If you find problems let + * it know on the project forum. + *
+ */ +WXJS_INIT_CLASS(DataOutputStream, "wxDataOutputStream", 1) + +/*** + * + * + * An output stream + * + * + * Constructs a new wxDataOutputStream object. + * + * + */ +wxDataOutputStream* DataOutputStream::Construct(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, bool constructing) +{ + Stream *out = OutputStream::GetPrivate(cx, argv[0]); + if ( out == NULL ) + return NULL; + + // This is needed, because otherwise the stream can be garbage collected. + // Another method could be to root the stream, but how are we going to unroot it? + JS_DefineProperty(cx, obj, "__stream__", argv[0], NULL, NULL, JSPROP_READONLY); + + return new wxDataOutputStream(*dynamic_cast(out->GetStream())); +} + +WXJS_BEGIN_METHOD_MAP(DataOutputStream) + WXJS_METHOD("bigEndianOrdered", bigEndianOrdered, 1) + WXJS_METHOD("write64", write64, 1) + WXJS_METHOD("write32", write32, 1) + WXJS_METHOD("write16", write16, 1) + WXJS_METHOD("write8", write8, 1) + WXJS_METHOD("writeString", writeString, 1) + WXJS_METHOD("writeDouble", writeDouble, 1) +WXJS_END_METHOD_MAP() + +/*** + * + * + * + * + * + * If Ordered is true, all data will be read in big-endian order, + * such as written by programs on a big endian architecture (e.g. Sparc) + * or written by Java-Streams (which always use big-endian order). + * + * + */ + JSBool DataOutputStream::bigEndianOrdered(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxDataOutputStream *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + bool ordered; + if ( FromJS(cx, argv[0], ordered) ) + { + p->BigEndianOrdered(ordered); + return JS_TRUE; + } + return JS_FALSE; +} + +/*** + * + * + * + * + * + * Writes a 64 bit integer to the stream. + * + * + */ +JSBool DataOutputStream::write64(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxDataOutputStream *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + +// Check for other platforms !!! +#ifdef __WXMSW__ + long value; + if ( FromJS(cx, argv[0], value) ) + { + p->Write64((wxUint64) value); + return JS_TRUE; + } +#endif + + return JS_FALSE; +} + +/*** + * + * + * + * + * + * Writes a 32 bit integer to the stream. + * + * + */ +JSBool DataOutputStream::write32(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxDataOutputStream *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + +// Check for other platforms !!! +#ifdef __WXMSW__ + int value; + if ( FromJS(cx, argv[0], value) ) + { + p->Write32(value); + return JS_TRUE; + } +#endif + + return JS_FALSE; +} + +/*** + * + * + * + * + * + * Writes a 16 bit integer to the stream. + * + * + */ +JSBool DataOutputStream::write16(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxDataOutputStream *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + +// TODO: Check for other platforms !!! +#ifdef __WXMSW__ + int value; + if ( FromJS(cx, argv[0], value) ) + { + p->Write16(value); + return JS_TRUE; + } +#endif + return JS_FALSE; +} + +/*** + * + * + * + * + * + * Writes a 8 bit integer to the stream. + * + * + */ +JSBool DataOutputStream::write8(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxDataOutputStream *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + +// TODO: Check for other platforms !!! +#ifdef __WXMSW__ + int value; + if ( FromJS(cx, argv[0], value) ) + { + p->Write8(value); + return JS_TRUE; + } +#endif + return JS_FALSE; +} + +/*** + * + * + * + * + * + * Writes a double (IEEE encoded) to a stream. + * + * + */ +JSBool DataOutputStream::writeDouble(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxDataOutputStream *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + double value; + if ( FromJS(cx, argv[0], value) ) + { + p->WriteDouble(value); + return JS_TRUE; + } + return JS_FALSE; +} + +/*** + * + * + * + * + * + * Writes string as a line. Depending on the end-of-line mode the end of line + * ('\n') characters in the string are converted to the correct line + * ending terminator. + * + * + */ +JSBool DataOutputStream::writeString(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxDataOutputStream *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + wxString value; + FromJS(cx, argv[0], value); + p->WriteString(value); + return JS_TRUE; +} Property changes on: ps/trunk/source/tools/atlas/wxJS/io/dostream.cpp ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/io/process.h =================================================================== --- ps/trunk/source/tools/atlas/wxJS/io/process.h (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/io/process.h (revision 5154) @@ -0,0 +1,77 @@ +/* + * wxJavaScript - process.h + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: process.h 598 2007-03-07 20:13:28Z fbraem $ + */ +#ifndef _wxJS_io_process_h +#define _wxJS_io_process_h + +#include + +namespace wxjs +{ + namespace io + { + class Process : public ApiWrapper + , public wxProcess + { + public: + Process(JSContext *cx, JSObject *obj, int flags); + virtual ~Process(); + + static Process *Construct(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, bool constructing); + static void Destruct(JSContext *cx, Process *p); + static void InitClass(JSContext *cx, JSObject *obj, JSObject *proto); + + static bool GetProperty(Process *p, JSContext *cx, JSObject *obj, int id, jsval *vp); + //static bool SetProperty(Process *p, JSContext *cx, JSObject *obj, int id, jsval *vp); + + WXJS_DECLARE_PROPERTY_MAP() + WXJS_DECLARE_CONSTANT_MAP() + WXJS_DECLARE_METHOD_MAP() + + enum + { + P_ERROR_STREAM = WXJS_START_PROPERTY_ID + , P_INPUT_STREAM + , P_OUTPUT_STREAM + , P_ERROR_AVAILABLE + , P_INPUT_AVAILABLE + , P_INPUT_OPENED + , P_PID + }; + + static JSBool closeOutput(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval); + static JSBool detach(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval); + static JSBool redirect(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval); + + WXJS_DECLARE_STATIC_METHOD_MAP() + static JSBool kill(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval); + static JSBool exists(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval); + static JSBool open(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval); + + }; + + }; // namespace io +}; // namespace wxjs + +#endif //_wxJS_io_process_h Property changes on: ps/trunk/source/tools/atlas/wxJS/io/process.h ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/gui/misc/flexgrid.cpp =================================================================== --- ps/trunk/source/tools/atlas/wxJS/gui/misc/flexgrid.cpp (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/gui/misc/flexgrid.cpp (revision 5154) @@ -0,0 +1,134 @@ +#include "precompiled.h" + +/* + * wxJavaScript - flexgrid.cpp + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: flexgrid.cpp 733 2007-06-05 21:17:25Z fbraem $ + */ +// flexgrid.cpp + +#ifndef WX_PRECOMP + #include +#endif + +#include "../../common/main.h" +#include "../../common/apiwrap.h" + +#include "sizer.h" +#include "flexgrid.h" + +using namespace wxjs; +using namespace wxjs::gui; + +/*** + * misc/flexgrid + * gui + * + * A flex grid sizer is a sizer which lays out its children in a two-dimensional + * table with all table fields in one row having the same height and all fields + * in one column having the same width. + * + */ +WXJS_INIT_CLASS(FlexGridSizer, "wxFlexGridSizer", 4) + +/*** + * + * + * + * The number of rows. + * + * + * The number of columns. + * + * + * The space between the columns + * + * + * The space between the rows + * + * + * + * + * The number of columns. + * + * + * The space between the columns + * + * + * The space between the rows + * + * + * + * Constructs a new wxFlexGridSizer object. + * + * + */ +wxFlexGridSizer* FlexGridSizer::Construct(JSContext *cx, + JSObject *obj, + uintN argc, + jsval *argv, + bool constructing) +{ + wxFlexGridSizer *p = NULL; + + int cols = 0; + int rows = 0; + int vgap = 0; + int hgap = 0; + + if ( argc > 4 ) + argc = 4; + + if ( argc == 4 ) + { + if ( FromJS(cx, argv[0], rows) + && FromJS(cx, argv[1], cols) + && FromJS(cx, argv[2], vgap) + && FromJS(cx, argv[3], hgap) ) + { + p = new wxFlexGridSizer(rows, cols, vgap, hgap); + } + } + else if ( argc < 4 ) + { + switch(argc) + { + case 3: + if ( ! FromJS(cx, argv[2], hgap) ) + break; + case 2: + if ( ! FromJS(cx, argv[1], vgap) ) + break; + case 1: + if ( ! FromJS(cx, argv[0], cols) ) + break; + p = new wxFlexGridSizer(cols, vgap, hgap); + } + } + + if ( p != NULL ) + { + p->SetClientObject(new JavaScriptClientData(cx, obj, false, true)); + } + + return p; +} Property changes on: ps/trunk/source/tools/atlas/wxJS/gui/misc/flexgrid.cpp ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/gui/misc/accentry.h =================================================================== --- ps/trunk/source/tools/atlas/wxJS/gui/misc/accentry.h (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/gui/misc/accentry.h (revision 5154) @@ -0,0 +1,73 @@ +/* + * wxJavaScript - accentry.h + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: accentry.h 598 2007-03-07 20:13:28Z fbraem $ + */ +#ifndef _WXJSAcceleratorEntry_H +#define _WXJSAcceleratorEntry_H + +///////////////////////////////////////////////////////////////////////////// +// Name: accentry.h +// Purpose: AcceleratorEntry ports wxAcceleratorEntry to JavaScript +// Author: Franky Braem +// Modified by: +// Created: 06.06.02 +// Copyright: (c) 2001-2002 Franky Braem +// Licence: LGPL +///////////////////////////////////////////////////////////////////////////// + +namespace wxjs +{ + namespace gui + { + class AcceleratorEntry : public ApiWrapper + { + public: + + static bool GetProperty(wxAcceleratorEntry *p, JSContext *cx, JSObject *obj, int id, jsval *vp); + static bool SetProperty(wxAcceleratorEntry *p, JSContext *cx, JSObject *obj, int id, jsval *vp); + + /** + * Callback for when a wxAcceleratorEntry object is created + */ + static wxAcceleratorEntry* Construct(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, bool constructing); + + WXJS_DECLARE_PROPERTY_MAP() + WXJS_DECLARE_METHOD_MAP() + WXJS_DECLARE_CONSTANT_MAP() + + /** + * Property Ids. + */ + enum + { + P_FLAG + , P_KEYCODE + , P_COMMAND + }; + + static JSBool set(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval); + }; + }; // namespace gui +}; // namespace wxjs + +#endif //_WXJSAcceleratorEntry_H Property changes on: ps/trunk/source/tools/atlas/wxJS/gui/misc/accentry.h ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/gui/misc/app.cpp =================================================================== --- ps/trunk/source/tools/atlas/wxJS/gui/misc/app.cpp (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/gui/misc/app.cpp (revision 5154) @@ -0,0 +1,303 @@ +#include "precompiled.h" + +/* + * wxJavaScript - app.cpp + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: app.cpp 716 2007-05-20 17:57:22Z fbraem $ + */ +// app.cpp + +#include +#ifndef WX_PRECOMP + #include +#endif +#ifdef __WXMSW__ + #include +#endif +#include + +#include "../../common/main.h" +#include "../../common/jsutil.h" + +#include "../control/window.h" + +#include "app.h" + +using namespace wxjs; +using namespace wxjs::gui; + +// IMPLEMENT_APP_NO_MAIN(App) + +/*** + * misc/app + * gui + * + * wxApp represents the GUI application. wxJS instantiates + * an object of this type and stores it in the global + * variable wxTheApp. The script is responsible for calling + * @wxApp#mainLoop. Before the main loop is entered, + * the function that is put in @wxApp#onInit is called. This + * function must create a top-level window, make it visible + * and return true. Otherwise the main loop is immediately + * ended.

+ * Remark:When the application is dialog based + * and the dialog is a modal dialog, the onInit function + * must return false. + *
+ */ +WXJS_INIT_CLASS(App, "wxApp", 0) + +App::~App() +{ +} + +/*** + * + * Get/Set the application name + * Get/Set the classname + * Get/Set the top window of your application. + * Get/Set the vendor name + * + */ +WXJS_BEGIN_PROPERTY_MAP(App) + WXJS_PROPERTY(P_APPLICATION_NAME, "appName") + WXJS_PROPERTY(P_CLASS_NAME, "className") + WXJS_PROPERTY(P_VENDOR_NAME, "vendorName") + WXJS_PROPERTY(P_TOP_WINDOW, "topWindow") +WXJS_END_PROPERTY_MAP() + +void App::DestroyTopWindows() +{ + while ( !wxTopLevelWindows.empty() ) + { + // do not use Destroy() here as it only puts the TLW in pending list + // but we want to delete them now + delete wxTopLevelWindows.GetFirst()->GetData(); + } +} + +bool App::GetProperty(wxApp *p, JSContext *cx, JSObject *obj, int id, jsval *vp) +{ + switch (id) + { + case P_APPLICATION_NAME: + *vp = ToJS(cx, p->GetAppName()); + break; + case P_CLASS_NAME: + *vp = ToJS(cx, p->GetClassName()); + break; + case P_VENDOR_NAME: + *vp = ToJS(cx, p->GetVendorName()); + break; + case P_TOP_WINDOW: + { + wxWindow *win = p->GetTopWindow(); + if ( win != NULL ) + { + JavaScriptClientData *data + = dynamic_cast(win->GetClientObject()); + if ( data != NULL ) + *vp = OBJECT_TO_JSVAL(data->GetObject()); + } + break; + } +/* case P_USE_BEST_VISUAL: + *vp = BOOLEAN_TO_JSVAL(p->GetUseBestVisual()); + break; +*/ } + + return true; +} + +bool App::SetProperty(wxApp *p, JSContext *cx, JSObject *obj, int id, jsval *vp) +{ + switch (id) + { + case P_APPLICATION_NAME: + { + wxString name; + FromJS(cx, *vp, name); + p->SetAppName(name); + break; + } + case P_CLASS_NAME: + { + wxString name; + FromJS(cx, *vp, name); + p->SetClassName(name); + break; + } + case P_VENDOR_NAME: + { + wxString name; + FromJS(cx, *vp, name); + p->SetVendorName(name); + break; + } + case P_TOP_WINDOW: + { + wxWindow *win = Window::GetPrivate(cx, *vp); + if ( win != NULL ) + p->SetTopWindow(win); + break; + } + } + + return true; +} + +WXJS_BEGIN_METHOD_MAP(App) + WXJS_METHOD("mainLoop", mainLoop, 0) +WXJS_END_METHOD_MAP() + +/*** + * + * + * + * Enters the main loop (meaning it starts your application). Before the application + * is started it will call the function you've set in the @wxApp#onInit event. + * You don't have to use mainLoop for executing a script. You only need this function + * when you want to block the execution of the script (i.e. when not using + * modal dialogs). + * + * + */ +JSBool App::mainLoop(JSContext *cx, + JSObject *obj, + uintN argc, + jsval *argv, + jsval *rval) +{ + wxApp *p = GetPrivate(cx, obj); + + p->OnRun(); + + return JS_TRUE; +} + +int App::MainLoop() +{ + int retval = 0; + + SetExitOnFrameDelete(TRUE); + if ( CallOnInit() ) + { + bool initialized = (wxTopLevelWindows.GetCount() != 0); + if ( initialized ) + { + if ( GetTopWindow()->IsShown() ) + { + retval = wxApp::MainLoop(); + } + } + } + + DestroyTopWindows(); + return retval; +} + +bool App::OnInit() +{ + JavaScriptClientData *data + = dynamic_cast(GetClientObject()); + if ( data == NULL ) + return false; + + jsval fval; + if ( GetFunctionProperty(data->GetContext(), data->GetObject(), + "onInit", &fval) == JS_TRUE ) + { + jsval rval; + if ( JS_CallFunctionValue(data->GetContext(), data->GetObject(), + fval, 0, NULL, &rval) == JS_TRUE ) + { + if ( JSVAL_IS_BOOLEAN(rval) ) + { + if ( JSVAL_TO_BOOLEAN(rval) == JS_TRUE ) + { + return true; + } + return false; + } + } + else + { + JS_ReportPendingException(data->GetContext()); + return false; + } + } + + return true; +} + +int App::OnExit() +{ + JavaScriptClientData *data + = dynamic_cast(GetClientObject()); + if ( data == NULL ) + return false; + + jsval fval; + if ( GetFunctionProperty(data->GetContext(), data->GetObject(), + "onExit", &fval) == JS_TRUE ) + { + jsval rval; + JSBool result = JS_CallFunctionValue(data->GetContext(), data->GetObject(), + fval, 0, NULL, &rval); + if ( result == JS_TRUE ) + { + if ( rval == JSVAL_VOID ) + return 0; + + int rc; + if ( FromJS(data->GetContext(), rval, rc) ) + { + return rc; + } + else + { + if ( JS_IsExceptionPending(data->GetContext()) ) + { + JS_ReportPendingException(data->GetContext()); + } + } + } + } + + return 0; +} + +/*** + * + * + * Called when the application needs to be initialized. Set a function + * that returns a boolean. When it returns false the application will stop (onExit + * isn't called!). + * Remark:When your application is dialog based and the dialog is modal, + * you must return false, otherwise the application keeps running. + * + * + * This function is executed when the application exits. + * The function doesn't get any parameters and must return an Integer. + * + * + */ Property changes on: ps/trunk/source/tools/atlas/wxJS/gui/misc/app.cpp ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/gui/misc/cmnconst.cpp =================================================================== --- ps/trunk/source/tools/atlas/wxJS/gui/misc/cmnconst.cpp (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/gui/misc/cmnconst.cpp (revision 5154) @@ -0,0 +1,71 @@ +#include "precompiled.h" + +/* + * wxJavaScript - cmnconst.cpp + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: cmnconst.cpp 598 2007-03-07 20:13:28Z fbraem $ + */ +// cmnconst.cpp + +#ifndef WX_PRECOMP + #include +#endif +#include + +#include "../../common/main.h" +#include "cmnconst.h" + +/*** + * misc/cmnconst + * gui + * + * + * + * + * wxTreeItemIcon is used to associated different kind of images + * to a treectrl item. wxTreeItemIcon contains the following constants: + * See @wxTreeCtrl and @wxTreeItem. + * + * Not selected, Not expanded + * Selected, Not expanded + * Not selected, Expanded + * Selected, Expanded + * + * + */ +JSConstDoubleSpec wxTreeItemIconMap[] = +{ + WXJS_CONSTANT(wxTreeItemIcon_, Normal) + WXJS_CONSTANT(wxTreeItemIcon_, Selected) + WXJS_CONSTANT(wxTreeItemIcon_, Expanded) + WXJS_CONSTANT(wxTreeItemIcon_, SelectedExpanded) + { 0 } +}; + +void InitCommonConst(JSContext *cx, JSObject *obj) +{ + JSObject *constObj = JS_DefineObject(cx, obj, "wxTreeItemIcon", + NULL, NULL, + JSPROP_READONLY | JSPROP_PERMANENT); + JS_DefineConstDoubles(cx, constObj, wxTreeItemIconMap); +} + Property changes on: ps/trunk/source/tools/atlas/wxJS/gui/misc/cmnconst.cpp ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/gui/misc/globfun.cpp =================================================================== --- ps/trunk/source/tools/atlas/wxJS/gui/misc/globfun.cpp (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/gui/misc/globfun.cpp (revision 5154) @@ -0,0 +1,127 @@ +#include "precompiled.h" + +/* + * wxJavaScript - globfun.cpp + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: globfun.cpp 598 2007-03-07 20:13:28Z fbraem $ + */ +// globfun.cpp +#ifndef WX_PRECOMP + #include +#endif +#include + +#include "../../common/main.h" +#include "globfun.h" +#include "point.h" +#include "colour.h" +#include "size.h" +#include "fontlist.h" +#include "colourdb.h" + +/*** + * misc/globfun + * gui + * + * On this page you can find all the functions that are defined on the global object. + * + */ +static JSFunctionSpec Functions[] = +{ + { "wxMessageBox", wxjs::gui::MessageBox, 1 }, + { "wxInitAllImageHandlers", wxjs::gui::InitAllImageHandlers, 0 }, + { 0 } +}; + +/*** + * + * + * + * + * + * Shows a modal message box with the given text. + * + * + */ +JSBool wxjs::gui::MessageBox(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + if ( argc == 1 ) + { + wxString msg; + FromJS(cx, argv[0], msg); + wxMessageBox(msg); + return JS_TRUE; + } + return JS_FALSE; +} + +/*** + * + * + * + * Initializes all available image handlers. When wxJS is started, + * only @wxBMPHandler is instantiated. When you only need one + * image handler you can also use @wxImage#addHandler. + *

+ * See @wxImage, @wxBMPHandler, @wxGIFHandler, @wxICOHandler, + * @wxJPEGHandler, @wxPCXHandler, @wxPNGHandler, @wxPNMHandler, + * @wxTIFFHandler, @wxXPMHandler + *
+ *
+ */ +JSBool wxjs::gui::InitAllImageHandlers(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxInitAllImageHandlers(); + return JS_TRUE; +} + +bool wxjs::gui::InitFunctions(JSContext *cx, JSObject *global) +{ + JS_DefineFunctions(cx, global, Functions); + return true; +} + +/*** + * + * + * The default position + * + * + * The default size + * + * + * The one and only font list object. + * + * + * The one and only colour database. + * + * + */ +void wxjs::gui::DefineGlobals(JSContext *cx, JSObject *global) +{ + wxjs::gui::Point::DefineObject(cx, global, "wxDefaultPosition", new wxPoint(wxDefaultPosition)); + wxjs::gui::Size::DefineObject(cx, global, "wxDefaultSize", new wxSize(wxDefaultSize)); + wxjs::gui::FontList::DefineObject(cx, global, "wxTheFontList", wxTheFontList); + wxjs::gui::ColourDatabase::DefineObject(cx, global, "wxTheColourDatabase", wxTheColourDatabase); + + wxjs::gui::DefineGlobalColours(cx, global); +} Property changes on: ps/trunk/source/tools/atlas/wxJS/gui/misc/globfun.cpp ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/io/sockaddr.h =================================================================== --- ps/trunk/source/tools/atlas/wxJS/io/sockaddr.h (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/io/sockaddr.h (revision 5154) @@ -0,0 +1,43 @@ +/* + * wxJavaScript - sockaddr.h + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: sockaddr.h 598 2007-03-07 20:13:28Z fbraem $ + */ +#ifndef _wxjs_io_sockaddr_h +#define _wxjs_io_sockaddr_h + +#include + +namespace wxjs +{ + namespace io + { + class SockAddress : public ApiWrapper + { + public: + WXJS_DECLARE_METHOD_MAP() + + static JSBool clear(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval); + }; + }; // namespace io +}; // namespace wxjs +#endif // _wxjs_io_sockaddr_h Property changes on: ps/trunk/source/tools/atlas/wxJS/io/sockaddr.h ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/io/zistream.h =================================================================== --- ps/trunk/source/tools/atlas/wxJS/io/zistream.h (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/io/zistream.h (revision 5154) @@ -0,0 +1,65 @@ +/* + * wxJavaScript - zistream.h + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: zistream.h 598 2007-03-07 20:13:28Z fbraem $ + */ +#ifndef wxjs_io_zistream_h +#define wxjs_io_zistream_h + +#include + +namespace wxjs +{ + namespace io + { + class ZipInputStream : public wxZipInputStream, + public ApiWrapper + { + public: + + ZipInputStream(wxInputStream &str); + + static Stream* Construct(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, bool constructing); + static void Destruct(JSContext *cx, Stream *p); + /** + * Callback for retrieving properties of wxInputStream + */ + static bool GetProperty(Stream *p, JSContext *cx, JSObject *obj, int id, jsval *vp); + + WXJS_DECLARE_PROPERTY_MAP() + + /** + * Property Ids. + */ + enum + { + P_COMMENT + , P_TOTAL_ENTRIES + , P_NEXT_ENTRY + }; + + // Keep a reference to the stream to avoid deletion. + Stream m_refStream; + }; + }; // namespace io +}; // namespace wxjs +#endif // wxjs_io_zistream_h Property changes on: ps/trunk/source/tools/atlas/wxJS/io/zistream.h ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/io/tempfile.h =================================================================== --- ps/trunk/source/tools/atlas/wxJS/io/tempfile.h (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/io/tempfile.h (revision 5154) @@ -0,0 +1,70 @@ +/* + * wxJavaScript - tempfile.h + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: tempfile.h 598 2007-03-07 20:13:28Z fbraem $ + */ +#ifndef _WXJS_TEMPFILE_H +#define _WXJS_TEMPFILE_H + +///////////////////////////////////////////////////////////////////////////// +// Name: tempfile.h +// Purpose: Ports wxFile to JavaScript +// Author: Franky Braem +// Modified by: +// Created: 25.12.05 +// Copyright: (c) 2001-2005 Franky Braem +// Licence: LGPL +///////////////////////////////////////////////////////////////////////////// + +#include + +namespace wxjs +{ + namespace io + { + class TempFile : public ApiWrapper + { + public: + + static bool GetProperty(wxTempFile *f, JSContext *cx, JSObject *obj, int id, jsval *vp); + + enum + { + P_OPENED + , P_LENGTH + , P_TELL + }; + + WXJS_DECLARE_PROPERTY_MAP() + WXJS_DECLARE_METHOD_MAP() + + static wxTempFile *Construct(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, bool constructing); + + static JSBool commit(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval); + static JSBool open(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval); + static JSBool seek(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval); + static JSBool write(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval); + static JSBool discard(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval); + }; + }; // namespace io +}; // namespace wxjs +#endif Property changes on: ps/trunk/source/tools/atlas/wxJS/io/tempfile.h ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/io/dirtrav.h =================================================================== --- ps/trunk/source/tools/atlas/wxJS/io/dirtrav.h (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/io/dirtrav.h (revision 5154) @@ -0,0 +1,72 @@ +/* + * wxJavaScript - dirtrav.h + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: dirtrav.h 715 2007-05-18 20:38:04Z fbraem $ + */ +#ifndef _WXJSDirTraverser_H +#define _WXJSDirTraverser_H + +///////////////////////////////////////////////////////////////////////////// +// Name: dirtrav.h +// Purpose: wxJSDirTraverser ports wxDirTraverser to JavaScript +// Author: Franky Braem +// Modified by: +// Created: +// Copyright: (c) 2001-2002 Franky Braem +// Licence: LGPL +///////////////////////////////////////////////////////////////////////////// + +#include + +namespace wxjs +{ + namespace io + { + class DirTraverser : public wxDirTraverser + , public ApiWrapper + , public wxClientDataContainer + { + public: + + DirTraverser(); + + virtual ~DirTraverser() + { + } + + wxDirTraverseResult OnFile(const wxString& name); + wxDirTraverseResult OnDir(const wxString& name); + + WXJS_DECLARE_CONSTANT_MAP() + + /** + * Callback for when a wxDirTraverser object is created + */ + static DirTraverser* Construct(JSContext *cx, + JSObject *obj, + uintN argc, + jsval *argv, + bool constructing); + }; + }; // namespace io +}; // namespace wxjs +#endif //_WXJSDirTraverser_H Property changes on: ps/trunk/source/tools/atlas/wxJS/io/dirtrav.h ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/io/sockevth.h =================================================================== --- ps/trunk/source/tools/atlas/wxJS/io/sockevth.h (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/io/sockevth.h (revision 5154) @@ -0,0 +1,56 @@ +/* + * wxJavaScript - sockevth.h + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: sockevth.h 716 2007-05-20 17:57:22Z fbraem $ + */ +#ifndef _wxJS_SockEventHandler_H +#define _wxJS_SockEventHandler_H + +#include + +namespace wxjs +{ + namespace io + { + class SocketEventHandler : public wxEvtHandler + { + public: + + /** + * Constructors + */ + SocketEventHandler() : wxEvtHandler() + { + } + + virtual ~SocketEventHandler() + { + } + + protected: + DECLARE_EVENT_TABLE() + + void OnSocketEvent(wxSocketEvent &event); + }; + }; // namespace io +}; // namespace wxjs +#endif // _wxJS_EventHandler_H Property changes on: ps/trunk/source/tools/atlas/wxJS/io/sockevth.h ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/io/tostream.cpp =================================================================== --- ps/trunk/source/tools/atlas/wxJS/io/tostream.cpp (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/io/tostream.cpp (revision 5154) @@ -0,0 +1,303 @@ +#include "precompiled.h" + +/* + * wxJavaScript - tostream.cpp + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: tostream.cpp 598 2007-03-07 20:13:28Z fbraem $ + */ +#include +#ifndef WX_PRECOMP + #include +#endif + +#include "../common/main.h" +#include "stream.h" +#include "ostream.h" +#include "tostream.h" + +using namespace wxjs; +using namespace wxjs::io; + +/*** + * tostream + * io + * + * This class provides functions that write text datas using an output stream. + * So, you can write text, floats and integers. + * + * An example: + *

+ *   textout.writeString("The value of x:");
+ *   textout.write32(x);
+ *  
+ * This example can also be written as follows: + * + * textout.writeString("The value of x:" + x); + *
+ */ +WXJS_INIT_CLASS(TextOutputStream, "wxTextOutputStream", 1) + +/*** + * + * + * + * + * + * + * + * + * wxEol is ported as a separate JavaScript object. + * + * + */ +void TextOutputStream::InitClass(JSContext *cx, JSObject *obj, JSObject *proto) +{ + JSConstDoubleSpec wxEolMap[] = + { + WXJS_CONSTANT(wxEOL_, NATIVE) + WXJS_CONSTANT(wxEOL_, UNIX) + WXJS_CONSTANT(wxEOL_, MAC) + WXJS_CONSTANT(wxEOL_, DOS) + { 0 } + }; + + JSObject *constObj = JS_DefineObject(cx, obj, "wxEol", + NULL, NULL, + JSPROP_READONLY | JSPROP_PERMANENT); + JS_DefineConstDoubles(cx, constObj, wxEolMap); +} + +/*** + * + * + * An output stream + * The end-of-line mode + * The encoding to use + * + * + * Constructs a new wxTextOutputStream object. + * + * + */ +wxTextOutputStream* TextOutputStream::Construct(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, bool constructing) +{ + if ( argc > 3 ) + argc = 3; + + wxString encoding(wxJS_EXTERNAL_ENCODING); + int mode = wxEOL_NATIVE; + switch(argc) + { + case 3: + FromJS(cx, argv[2], encoding); + // Fall through + case 2: + if ( ! FromJS(cx, argv[1], mode) ) + return NULL; + // Fall through + default: + Stream *out = OutputStream::GetPrivate(cx, argv[0]); + if ( out == NULL ) + return NULL; + + // This is needed, because otherwise the stream can be garbage collected. + // Another method could be to root the stream, but how are we going to unroot it? + JS_DefineProperty(cx, obj, "__stream__", argv[0], NULL, NULL, JSPROP_READONLY); + wxCSConv conv(encoding); + return new wxTextOutputStream(*(wxOutputStream *) out->GetStream(), (wxEOL) mode, conv); + } +} + +/*** + * + * + * Gets/Sets the end-of-line mode. See @wxTextOutputStream#wxEol. + * + * + */ +WXJS_BEGIN_PROPERTY_MAP(TextOutputStream) + WXJS_PROPERTY(P_MODE, "mode") +WXJS_END_PROPERTY_MAP() + +bool TextOutputStream::GetProperty(wxTextOutputStream *p, JSContext *cx, JSObject *obj, int id, jsval *vp) +{ + if ( id == P_MODE ) + { + *vp = ToJS(cx, (int) p->GetMode()); + } + return true; +} + +bool TextOutputStream::SetProperty(wxTextOutputStream *p, JSContext *cx, JSObject *obj, int id, jsval *vp) +{ + if ( id == P_MODE ) + { + int mode; + if ( FromJS(cx, *vp, mode) ) + { + p->SetMode((wxEOL) mode); + } + } + return true; +} + +WXJS_BEGIN_METHOD_MAP(TextOutputStream) + WXJS_METHOD("write32", write32, 1) + WXJS_METHOD("write16", write16, 1) + WXJS_METHOD("write8", write8, 1) + WXJS_METHOD("writeString", writeString, 1) + WXJS_METHOD("writeDouble", writeDouble, 1) +WXJS_END_METHOD_MAP() + +/*** + * + * + * + * + * + * Writes a 32 bit integer to the stream. + * + * + */ +JSBool TextOutputStream::write32(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxTextOutputStream *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + +// Check for other platforms !!! +#ifdef __WXMSW__ + int value; + if ( FromJS(cx, argv[0], value) ) + { + p->Write32(value); + return JS_TRUE; + } +#endif + + return JS_FALSE; +} + +/*** + * + * + * + * + * + * Writes a 16 bit integer to the stream. + * + * + */ +JSBool TextOutputStream::write16(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxTextOutputStream *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + +// TODO: Check for other platforms !!! +#ifdef __WXMSW__ + int value; + if ( FromJS(cx, argv[0], value) ) + { + p->Write16(value); + return JS_TRUE; + } +#endif + return JS_FALSE; +} + +/*** + * + * + * + * + * + * Writes a 8 bit integer to the stream. + * + * + */ +JSBool TextOutputStream::write8(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxTextOutputStream *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + +// TODO: Check for other platforms !!! +#ifdef __WXMSW__ + int value; + if ( FromJS(cx, argv[0], value) ) + { + p->Write8(value); + return JS_TRUE; + } +#endif + return JS_FALSE; +} + +/*** + * + * + * + * + * + * Writes a double (IEEE encoded) to a stream. + * + * + */ +JSBool TextOutputStream::writeDouble(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxTextOutputStream *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + double value; + if ( FromJS(cx, argv[0], value) ) + { + p->WriteDouble(value); + return JS_TRUE; + } + return JS_FALSE; +} + +/*** + * + * + * + * + * + * Writes string as a line. Depending on the end-of-line mode the end of line + * ('\n') characters in the string are converted to the correct line + * ending terminator. + * + * + */ +JSBool TextOutputStream::writeString(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxTextOutputStream *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + wxString value; + FromJS(cx, argv[0], value); + p->WriteString(value); + return JS_TRUE; +} Property changes on: ps/trunk/source/tools/atlas/wxJS/io/tostream.cpp ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/io/uri.h =================================================================== --- ps/trunk/source/tools/atlas/wxJS/io/uri.h (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/io/uri.h (revision 5154) @@ -0,0 +1,73 @@ +/* + * wxJavaScript - uri.h + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: uri.h 598 2007-03-07 20:13:28Z fbraem $ + */ +#ifndef _wxjs_io_uri_h +#define _wxjs_io_uri_h + +#include + +namespace wxjs +{ + namespace io + { + class URI : public ApiWrapper + { + public: + + static wxURI *Construct(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, bool constructing); + static bool GetProperty(wxURI *p, JSContext *cx, JSObject *obj, int id, jsval *vp); + + WXJS_DECLARE_CONSTANT_MAP() + WXJS_DECLARE_PROPERTY_MAP() + enum + { + P_FRAGMENT = WXJS_START_PROPERTY_ID + , P_HOST_TYPE + , P_PASSWORD + , P_PATH + , P_PORT + , P_QUERY + , P_SCHEME + , P_SERVER + , P_USER + , P_USERINFO + , P_HAS_PATH + , P_HAS_PORT + , P_HAS_QUERY + , P_HAS_SCHEME + , P_HAS_SERVER + , P_HAS_USER + , P_IS_REFERENCE + }; + + WXJS_DECLARE_METHOD_MAP() + static JSBool buildURI(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval); + static JSBool buildUnescapedURI(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval); + static JSBool create(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval); + static JSBool resolve(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval); + static JSBool unescape(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval); + }; + }; // namespace io +}; // namespace wxjs +#endif // _wxjs_io_uri_h Property changes on: ps/trunk/source/tools/atlas/wxJS/io/uri.h ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/io/zipentry.h =================================================================== --- ps/trunk/source/tools/atlas/wxJS/io/zipentry.h (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/io/zipentry.h (revision 5154) @@ -0,0 +1,71 @@ +/* + * wxJavaScript - zipentry.h + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: zipentry.h 598 2007-03-07 20:13:28Z fbraem $ + */ +#ifndef wxjs_io_zipentry_h +#define wxjs_io_zipentry_h + +#include + +namespace wxjs +{ + namespace io + { + class ZipEntry : public ApiWrapper + { + public: + + static wxZipEntry* Construct(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, bool constructing); + + /** + * Callback for retrieving properties + */ + static bool GetProperty(wxZipEntry *p, JSContext *cx, JSObject *obj, int id, jsval *vp); + static bool SetProperty(wxZipEntry *p, JSContext *cx, JSObject *obj, int id, jsval *vp); + + static void InitClass(JSContext *cx, JSObject *obj, JSObject *proto); + + WXJS_DECLARE_PROPERTY_MAP() + + /** + * Property Ids. + */ + enum + { + P_COMMENT + , P_COMPRESSED_SIZE + , P_CRC + , P_EXTERNAL_ATTR + , P_EXTRA + , P_FLAGS + , P_LOCAL_EXTRA + , P_MODE + , P_METHOD + , P_SYSTEM_MADE_BY + , P_MADE_BY_UNIX + , P_TEXT + }; + }; + }; // namespace io +}; // namespace wxjs +#endif // wxjs_io_zipentry_h Property changes on: ps/trunk/source/tools/atlas/wxJS/io/zipentry.h ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/io/sockclient.cpp =================================================================== --- ps/trunk/source/tools/atlas/wxJS/io/sockclient.cpp (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/io/sockclient.cpp (revision 5154) @@ -0,0 +1,185 @@ +#include "precompiled.h" + +/* + * wxJavaScript - sockclient.cpp + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: sockclient.cpp 716 2007-05-20 17:57:22Z fbraem $ + */ +#include +#ifndef WX_PRECOMP + #include +#endif + +#include "../common/main.h" +#include "../common/jsutil.h" +#include "sockaddr.h" +#include "sockclient.h" +#include "sockevth.h" + +using namespace wxjs; +using namespace wxjs::io; + +SocketClient::SocketClient( JSContext *cx + , JSObject *obj + , wxSocketFlags flags) : wxSocketClient(flags) +{ + m_evtHandler = new SocketEventHandler(); + m_evtHandler->SetClientObject(new JavaScriptClientData(cx, obj, false, true)); + SetEventHandler(*m_evtHandler, -1); +} + +SocketClient::~SocketClient() +{ + delete m_evtHandler; +} + +/*** + * sockclient + * io + * + * This class implements client sockets. + * + */ +WXJS_INIT_CLASS(SocketClient, "wxSocketClient", 0) + +/*** + * + * + * + * + * + * Constructs a new wxSocketClient. + * + * + */ +SocketBasePrivate *SocketClient::Construct(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, bool constructing) +{ + if ( argc == 0 ) + { + return new SocketBasePrivate(new SocketClient(cx, obj)); + } + else + { + int flags; + if ( FromJS(cx, argv[0], flags) ) + { + return new SocketBasePrivate(new SocketClient(cx, obj, flags)); + } + } + return NULL; +} + +void SocketClient::Destruct(JSContext *cx, SocketBasePrivate *p) +{ + p->GetBase()->Destroy(); + delete p; +} + +WXJS_BEGIN_METHOD_MAP(SocketClient) + WXJS_METHOD("connect", connect, 1) + WXJS_METHOD("waitForConnect", waitOnConnect, 0) +WXJS_END_METHOD_MAP() + +/*** + * + * + * Address of the server + * Wait for the connection to complete? + * + * + * Connects to a server using the specified address. + * Returns true if the connection is established and no error occurs. + * If Wait is false, connect will try to establish the connection and return + * immediately, without blocking the GUI. When used this way, even if connect + * returns false, the connection request can be completed later. To detect this, + * use @wxSocketClient#waitOnConnect, or catch socket events. + * + * + */ +JSBool SocketClient::connect(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + SocketBasePrivate *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + wxSockAddress *addr = SockAddress::GetPrivate(cx, argv[0]); + if ( addr != NULL ) + { + bool wait = true; + if ( argc > 1 ) + { + if ( ! FromJS(cx, argv[1], wait) ) + return JS_FALSE; + } + wxSocketClient *sockClient = dynamic_cast(p->GetBase()); + *rval = ToJS(cx, sockClient->Connect(*addr, wait)); + return JS_TRUE; + } + return JS_FALSE; +} + +/*** + * + * + * + * + * + * + * Wait until a connection request completes, or until the specified timeout + * elapses. Use this function after issuing a call to Connect with wait set to false. + * waitOnConnect returns true if the connection request completes. This does not necessarily + * mean that the connection was successfully established; it might also happen that the + * connection was refused by the peer. Use @wxSocketBase#connected to distinguish between + * these two situations. + * + * + */ +JSBool SocketClient::waitOnConnect(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + SocketBasePrivate *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + long secs = -1; + long ms = 0; + + if ( argc > 2 ) + argc = 2; + + switch(argc) + { + case 2: + if ( ! FromJS(cx, argv[1], ms) ) + return JS_FALSE; + // Fall through + case 1: + if ( ! FromJS(cx, argv[0], secs) ) + return JS_FALSE; + // Fall through + default: + { + wxSocketClient *sockClient = dynamic_cast(p->GetBase()); + *rval = ToJS(cx, sockClient->WaitOnConnect(secs, ms)); + } + } + return JS_TRUE; +} Property changes on: ps/trunk/source/tools/atlas/wxJS/io/sockclient.cpp ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/io/archentry.h =================================================================== --- ps/trunk/source/tools/atlas/wxJS/io/archentry.h (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/io/archentry.h (revision 5154) @@ -0,0 +1,63 @@ +/* + * wxJavaScript - archentry.h + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: archentry.h 598 2007-03-07 20:13:28Z fbraem $ + */ +#ifndef wxjs_io_archentry_h +#define wxjs_io_archentry_h + +#include + +namespace wxjs +{ + namespace io + { + class ArchiveEntry : public ApiWrapper + { + public: + + /** + * Callback for retrieving properties + */ + static bool GetProperty(wxArchiveEntry *p, JSContext *cx, JSObject *obj, int id, jsval *vp); + static bool SetProperty(wxArchiveEntry *p, JSContext *cx, JSObject *obj, int id, jsval *vp); + + WXJS_DECLARE_PROPERTY_MAP() + + /** + * Property Ids. + */ + enum + { + P_DATE_TIME, + P_INTERNAL_FMT, + P_INTERNAL_NAME, + P_NAME, + P_OFFSET, + P_SIZE, + P_DIR, + P_READ_ONLY, + }; + }; + }; // namespace io +}; // namespace wxjs +#endif // wxjs_io_archentry_h Property changes on: ps/trunk/source/tools/atlas/wxJS/io/archentry.h ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/gui/misc/validator.cpp =================================================================== --- ps/trunk/source/tools/atlas/wxJS/gui/misc/validator.cpp (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/gui/misc/validator.cpp (revision 5154) @@ -0,0 +1,262 @@ +#include "precompiled.h" + +/* + * wxJavaScript - validator.cpp + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: validator.cpp 739 2007-06-08 20:51:47Z fbraem $ + */ +// validator.cpp + +#ifndef WX_PRECOMP + #include +#endif + +#include "../../common/main.h" +#include "../../common/jsutil.h" + +#include "../control/window.h" + +#include "validate.h" +#include "app.h" + +using namespace wxjs; +using namespace wxjs::gui; + +Validator::Validator() : wxValidator() +{ +} + +Validator::Validator(const Validator ©) : wxValidator() +{ + JavaScriptClientData *data + = dynamic_cast(copy.GetClientObject()); + if ( data != NULL ) + { + SetClientObject(new JavaScriptClientData(*data)); + data->Protect(false); + } +} + +bool Validator::TransferToWindow() +{ + JavaScriptClientData *data + = dynamic_cast(GetClientObject()); + if ( data == NULL ) + return true; + + JSContext *cx = data->GetContext(); + JSObject *obj = data->GetObject(); + + jsval fval; + if ( GetFunctionProperty(cx, obj, "transferToWindow", &fval) == JS_TRUE ) + { + jsval rval; + if ( JS_CallFunctionValue(cx, obj, fval, 0, NULL, &rval) == JS_FALSE ) + { + if ( JS_IsExceptionPending(cx) ) + { + JS_ReportPendingException(cx); + } + return false; + } + else + { + return JSVAL_IS_BOOLEAN(rval) ? JSVAL_TO_BOOLEAN(rval) == JS_TRUE : false; + } + } + + return true; +} + +bool Validator::TransferFromWindow() +{ + JavaScriptClientData *data + = dynamic_cast(GetClientObject()); + if ( data == NULL ) + return true; + + JSContext *cx = data->GetContext(); + JSObject *obj = data->GetObject(); + + jsval fval; + if ( GetFunctionProperty(cx, obj, "transferFromWindow", &fval) == JS_TRUE ) + { + jsval rval; + if ( JS_CallFunctionValue(cx, obj, fval, 0, NULL, &rval) == JS_FALSE ) + { + if ( JS_IsExceptionPending(cx) ) + { + JS_ReportPendingException(cx); + } + return false; + } + else + { + return JSVAL_IS_BOOLEAN(rval) ? JSVAL_TO_BOOLEAN(rval) == JS_TRUE : false; + } + } + return true; +} + +bool Validator::Validate(wxWindow *parent) +{ + JavaScriptClientData *data + = dynamic_cast(GetClientObject()); + if ( data == NULL ) + return true; + + JSContext *cx = data->GetContext(); + JSObject *obj = data->GetObject(); + + JavaScriptClientData *parentData = NULL; + if ( parent != NULL ) + { + parentData = dynamic_cast(parent->GetClientObject()); + } + + jsval fval; + if ( GetFunctionProperty(cx, obj, "validate", &fval) == JS_TRUE ) + { + jsval argv[] = + { + parentData == NULL ? JSVAL_VOID + : OBJECT_TO_JSVAL(parentData->GetObject()) + }; + + jsval rval; + if ( JS_CallFunctionValue(cx, obj, fval, 1, argv, &rval) == JS_FALSE ) + { + if ( JS_IsExceptionPending(cx) ) + { + JS_ReportPendingException(cx); + } + return false; + } + else + { + return JSVAL_IS_BOOLEAN(rval) ? JSVAL_TO_BOOLEAN(rval) == JS_TRUE : false; + } + } + + return false; +} + +/*** + * misc/validator + * gui + * + * Use wxValidator to create your own validators. + * + */ + +WXJS_INIT_CLASS(Validator, "wxValidator", 0) + +/*** + * + * + * + * Assign a function to this property that transfers the content of the window + * to a variable. You must return true on success, false on failure. + * + * + * Assign a function to this property that transfers the variable to the window. + * You must return true on success, false on failure. + * + * + * Assign a function to this property that checks the content of the associated window. The function + * can have one argument: the parent of the associated window. This function should return false + * when the content is invalid, true when it is valid. + * + * + * The window associated with this validator. + * + * + */ +WXJS_BEGIN_PROPERTY_MAP(Validator) + WXJS_PROPERTY(P_WINDOW, "window") + WXJS_PROPERTY(P_BELL_ON_ERROR, "bellOnError") +WXJS_END_PROPERTY_MAP() + +bool Validator::GetProperty(wxValidator *p, JSContext *cx, JSObject *obj, int id, jsval *vp) +{ + switch (id) + { + case P_BELL_ON_ERROR: + *vp = ToJS(cx, p->IsSilent()); + break; + case P_WINDOW: + { + wxWindow *win = p->GetWindow(); + if ( win != NULL ) + { + JavaScriptClientData *data + = dynamic_cast(win->GetClientObject()); + *vp = data == NULL ? JSVAL_VOID + : OBJECT_TO_JSVAL(data->GetObject()); + } + break; + } + } + return true; +} + +bool Validator::SetProperty(wxValidator *p, JSContext *cx, JSObject *obj, int id, jsval *vp) +{ + switch (id) + { + case P_BELL_ON_ERROR: + { + bool bell; + if ( FromJS(cx, *vp, bell) ) + p->SetBellOnError(bell); + break; + } + case P_WINDOW: + { + wxWindow *win = Window::GetPrivate(cx, *vp); + if ( win != NULL ) + p->SetWindow(win); + } + break; + } + + return true; +} + +/** + * + * + * + * Constructs a new wxValidator object + * + * + */ +wxValidator *Validator::Construct(JSContext *cx, + JSObject *obj, + uintN argc, + jsval *argv, + bool constructing) +{ + Validator *v = new Validator(); + v->SetClientObject(new JavaScriptClientData(cx, obj, false, true)); + return v; +} Property changes on: ps/trunk/source/tools/atlas/wxJS/gui/misc/validator.cpp ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/gui/misc/rect.cpp =================================================================== --- ps/trunk/source/tools/atlas/wxJS/gui/misc/rect.cpp (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/gui/misc/rect.cpp (revision 5154) @@ -0,0 +1,514 @@ +#include "precompiled.h" + +/* + * wxJavaScript - rect.cpp + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: rect.cpp 598 2007-03-07 20:13:28Z fbraem $ + */ +// rect.cpp + +#ifndef WX_PRECOMP + #include +#endif + +#include "../../common/main.h" +#include "../../common/apiwrap.h" + +#include "rect.h" +#include "point.h" +#include "size.h" + +using namespace wxjs; +using namespace wxjs::gui; + +/*** + * misc/rect + * gui + * + * A class for manipulating rectangles + * + */ +WXJS_INIT_CLASS(Rect, "wxRect", 0) + +/*** + * + * + * The width of the rectangle + * + * + * The height of the rectangle + * + * + * The bottom + * + * + * + * + * + * + * + * + * + */ +WXJS_BEGIN_PROPERTY_MAP(Rect) + WXJS_PROPERTY(P_WIDTH, "width") + WXJS_PROPERTY(P_HEIGHT, "height") + WXJS_PROPERTY(P_BOTTOM, "bottom") + WXJS_READONLY_PROPERTY(P_LEFT, "left") + WXJS_PROPERTY(P_POSITION, "position") + WXJS_PROPERTY(P_RIGHT, "right") + WXJS_READONLY_PROPERTY(P_SIZE, "size") + WXJS_PROPERTY(P_TOP, "top") + WXJS_PROPERTY(P_X, "x") + WXJS_PROPERTY(P_Y, "y") +WXJS_END_PROPERTY_MAP() + +bool Rect::GetProperty(wxRect *p, JSContext *cx, JSObject *obj, int id, jsval *vp) +{ + switch (id) + { + case P_WIDTH: + *vp = ToJS(cx, p->GetWidth()); + break; + case P_HEIGHT: + *vp = ToJS(cx, p->GetHeight()); + break; + case P_BOTTOM: + *vp = ToJS(cx, p->GetBottom()); + break; + case P_LEFT: + *vp = ToJS(cx, p->GetLeft()); + break; + case P_POSITION: + *vp = Point::CreateObject(cx, new wxPoint(p->GetPosition())); + break; + case P_RIGHT: + *vp = ToJS(cx, p->GetRight()); + break; + case P_SIZE: + *vp = Size::CreateObject(cx, new wxSize(p->GetSize())); + break; + case P_TOP: + *vp = ToJS(cx, p->GetTop()); + break; + case P_X: + *vp = ToJS(cx, p->GetX()); + break; + case P_Y: + *vp = ToJS(cx, p->GetY()); + break; + } + return true; +} + +bool Rect::SetProperty(wxRect *p, JSContext *cx, JSObject *obj, int id, jsval *vp) +{ + switch (id) + { + case P_WIDTH: + { + int width; + if ( FromJS(cx, *vp, width) ) + p->SetWidth(width); + break; + } + case P_HEIGHT: + { + int height; + if ( FromJS(cx, *vp, height) ) + p->SetHeight(height); + break; + } + case P_BOTTOM: + { + int bottom; + if ( FromJS(cx, *vp, bottom) ) + p->SetBottom(bottom); + break; + } + case P_LEFT: + { + int left; + if ( FromJS(cx, *vp, left) ) + p->SetLeft(left); + break; + } + case P_RIGHT: + { + int right; + if ( FromJS(cx, *vp, right) ) + p->SetRight(right); + break; + } + case P_TOP: + { + int top; + if ( FromJS(cx, *vp, top) ) + p->SetTop(top); + break; + } + case P_X: + { + int x; + if ( FromJS(cx, *vp, x ) ) + p->SetX(x); + break; + } + case P_Y: + { + int y; + if ( FromJS(cx, *vp, y) ) + p->SetY(y); + break; + } + } + return true; +} + +/*** + * + * + * + * X-coordinate of the top level corner + * + * + * Y-coordinate of the top level corner + * + * + * The width of the rectangle + * + * + * The height of the rectangle + * + * + * + * + * The top-left corner + * + * + * The bottom-right corner + * + * + * + * + * + * + * + * Constructs a new wxRect object. + * + * + */ +wxRect* Rect::Construct(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, bool constructing) +{ + if ( argc == 0 ) + return new wxRect(); + + if ( argc >= 4 ) + { + int x; + int y; + int width; + int height; + + if ( FromJS(cx, argv[0], x) + && FromJS(cx, argv[1], y) + && FromJS(cx, argv[2], width) + && FromJS(cx, argv[3], height) ) + { + return new wxRect(x, y, width, height); + } + } + else if ( argc == 2 ) + { + wxPoint *pt1 = Point::GetPrivate(cx, argv[0]); + if ( pt1 != NULL ) + { + wxPoint *pt2 = Point::GetPrivate(cx, argv[1]); + if ( pt2 != NULL ) + { + return new wxRect(*pt1, *pt2); + } + else + { + wxSize *size = Size::GetPrivate(cx, argv[1]); + if ( size != NULL ) + return new wxRect(*pt1, *size); + } + } + } + return NULL; +} + +WXJS_BEGIN_METHOD_MAP(Rect) + WXJS_METHOD("inflate", inflate, 1) + WXJS_METHOD("deflate", deflate, 1) + WXJS_METHOD("offset", offset, 1) + WXJS_METHOD("intersect", intersect, 1) + WXJS_METHOD("inside", inside, 1) + WXJS_METHOD("intersects", intersects, 1) +WXJS_END_METHOD_MAP() + +/*** + * + * + * + * + * + * + * Increases the rectangle size by X in x direction and by Y in y direction. + * When Y is not specified then the value of X is used. You can use negative + * values to decrease the size. + * + * + */ +JSBool Rect::inflate(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + if ( argc > 2 ) + argc = 2; + + wxCoord x = 0; + wxCoord y = 0; + + if ( FromJS(cx, argv[0], x) ) + { + if ( argc > 1 ) + { + if ( ! FromJS(cx, argv[1], y) ) + { + return JS_FALSE; + } + } + else + { + y = x; + } + } + else + { + return JS_FALSE; + } + + wxRect *p = Rect::GetPrivate(cx, obj); + p->Inflate(x, y); + return JS_TRUE; +} + +/*** + * + * + * + * + * + * + * Decreases the rectangle size by X in x direction and by Y in y direction. + * When Y is not specified then the value of X is used. You can use negative + * values to decrease the size. + * + * + */ +JSBool Rect::deflate(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + if ( argc > 2 ) + argc = 2; + + wxCoord x = 0; + wxCoord y = 0; + + if ( FromJS(cx, argv[0], x) ) + { + if ( argc > 1 ) + { + if ( ! FromJS(cx, argv[1], y) ) + { + return JS_FALSE; + } + } + else + { + y = x; + } + } + else + { + return JS_FALSE; + } + + wxRect *p = Rect::GetPrivate(cx, obj); + p->Deflate(x, y); + + return JS_TRUE; +} + +/*** + * + * + * + * + * + * + * + * + * + * Moves the rectangle. + * + * + */ +JSBool Rect::offset(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxRect *p = GetPrivate(cx, obj); + + switch (argc) + { + case 2: + { + int x; + int y; + if ( FromJS(cx, argv[0], x) + && FromJS(cx, argv[1], y) ) + { + p->Offset(x, y); + } + else + { + return JS_FALSE; + } + break; + } + case 1: + { + wxPoint *pt = Point::GetPrivate(cx, argv[0]); + if ( pt != NULL ) + { + p->Offset(*pt); + } + else + { + return JS_FALSE; + } + break; + } + default: + return JS_FALSE; + } + + return JS_TRUE; +} + +/*** + * + * + * + * + * + */ +JSBool Rect::intersect(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxRect *p = GetPrivate(cx, obj); + + wxRect *argRect = GetPrivate(cx, argv[0]); + if ( argRect != NULL ) + { + *rval = CreateObject(cx, new wxRect(p->Intersect(*argRect))); + return JS_TRUE; + } + + return JS_FALSE; +} + +/*** + * + * + * + * + * + * + * + * + * + * Returns true when the given coordinates are in the rectangle area. + * + * + */ +JSBool Rect::inside(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxRect *p = GetPrivate(cx, obj); + + switch(argc) + { + case 2: + { + int x; + int y; + if ( FromJS(cx, argv[0], x) + && FromJS(cx, argv[1], y) ) + { + *rval = ToJS(cx, p->Inside(x, y)); + } + else + { + return JS_FALSE; + } + break; + } + case 1: + { + wxPoint *pt = Point::GetPrivate(cx, argv[0]); + if ( pt != NULL ) + { + *rval = ToJS(cx, p->Inside(*pt)); + } + else + { + return JS_FALSE; + } + break; + } + default: + return JS_FALSE; + } + + return JS_TRUE; +} + +/*** + * + * + * + * + * + * Returns true when the rectangles have a non empty intersection + * + * + */ +JSBool Rect::intersects(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxRect *p = GetPrivate(cx, obj); + + wxRect *argRect = GetPrivate(cx, argv[0]); + if ( argRect != NULL ) + { + *rval = ToJS(cx, p->Intersects(*argRect)); + return JS_TRUE; + } + + return JS_FALSE; +} Property changes on: ps/trunk/source/tools/atlas/wxJS/gui/misc/rect.cpp ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/io/sockbase.h =================================================================== --- ps/trunk/source/tools/atlas/wxJS/io/sockbase.h (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/io/sockbase.h (revision 5154) @@ -0,0 +1,119 @@ +/* + * wxJavaScript - sockbase.h + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: sockbase.h 716 2007-05-20 17:57:22Z fbraem $ + */ +#ifndef _wxjs_io_sockbase_h +#define _wxjs_io_sockbase_h + +#include + +#include + +#include "jsstream.h" + +namespace wxjs +{ + namespace io + { + class SocketBasePrivate + { + public: + SocketBasePrivate(wxSocketBase *base) : m_base(base) + { + } + + virtual ~SocketBasePrivate() + { + } + + void DestroyStreams(JSContext *cx) + { + for(std::vector::iterator it = m_streams.begin(); it != m_streams.end(); it++) + { + JSObject *obj = (*it)->GetObject(); + if ( obj != NULL ) + JS_SetPrivate(cx, obj, NULL); // To avoid deletion + delete *it; + } + } + + wxSocketBase* GetBase() { return m_base; } + + void AddStream(Stream *stream) + { + m_streams.push_back(stream); + } + + private: + wxSocketBase *m_base; + std::vector m_streams; + }; + + class SocketBase : public ApiWrapper + { + public: + static bool GetProperty(SocketBasePrivate *p, + JSContext *cx, + JSObject *obj, + int id, + jsval *vp); + + static void InitClass(JSContext *cx, + JSObject *obj, + JSObject *proto); + + WXJS_DECLARE_PROPERTY_MAP() + enum + { + P_ERROR = WXJS_START_PROPERTY_ID + , P_CONNECTED + , P_DATA + , P_DISCONNECTED + , P_LASTCOUNT + , P_LASTERROR + , P_OK + }; + + WXJS_DECLARE_METHOD_MAP() + + WXJS_DECLARE_METHOD(close) + WXJS_DECLARE_METHOD(discard) + WXJS_DECLARE_METHOD(interruptWait) + WXJS_DECLARE_METHOD(notify) + WXJS_DECLARE_METHOD(peek) + WXJS_DECLARE_METHOD(read) + WXJS_DECLARE_METHOD(readMsg) + WXJS_DECLARE_METHOD(restoreState) + WXJS_DECLARE_METHOD(saveState) + WXJS_DECLARE_METHOD(setTimeout) + WXJS_DECLARE_METHOD(unread) + WXJS_DECLARE_METHOD(wait) + WXJS_DECLARE_METHOD(waitForLost) + WXJS_DECLARE_METHOD(waitForRead) + WXJS_DECLARE_METHOD(waitForWrite) + WXJS_DECLARE_METHOD(write) + WXJS_DECLARE_METHOD(writeMsg) + }; + }; // namespace io +}; // namespace wxjs +#endif // _wxjs_io_sockbase_h Property changes on: ps/trunk/source/tools/atlas/wxJS/io/sockbase.h ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/io/init.h =================================================================== --- ps/trunk/source/tools/atlas/wxJS/io/init.h (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/io/init.h (revision 5154) @@ -0,0 +1,39 @@ +/* + * wxJavaScript - init.h + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: init.h 598 2007-03-07 20:13:28Z fbraem $ + */ +#ifndef _wxJS_IO_init_h +#define _wxJS_IO_init_h + +// Use this to initialize the IO module + +namespace wxjs +{ + namespace io + { + bool InitClass(JSContext *cx, JSObject *global); + bool InitObject(JSContext *cx, JSObject *obj); + void Destroy(); + }; // namespace io +}; // namespace wxjs +#endif // _wxJS_IO_init_h Property changes on: ps/trunk/source/tools/atlas/wxJS/io/init.h ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/io/ipv4addr.cpp =================================================================== --- ps/trunk/source/tools/atlas/wxJS/io/ipv4addr.cpp (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/io/ipv4addr.cpp (revision 5154) @@ -0,0 +1,50 @@ +#include "precompiled.h" + +/* + * wxJavaScript - ipv4addr.cpp + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: ipv4addr.cpp 598 2007-03-07 20:13:28Z fbraem $ + */ +#include +#ifndef WX_PRECOMP + #include +#endif + +#include "../common/main.h" +#include "ipv4addr.h" + +using namespace wxjs; +using namespace wxjs::io; + +/*** + * ipv4addr + * io + * + * Implements the IPV4 of the internet protocal. + * + */ +WXJS_INIT_CLASS(IPV4address, "wxIPV4address", 0) + +wxIPV4address* IPV4address::Construct(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, bool constructing) +{ + return new wxIPV4address(); +} Property changes on: ps/trunk/source/tools/atlas/wxJS/io/ipv4addr.cpp ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/io/costream.h =================================================================== --- ps/trunk/source/tools/atlas/wxJS/io/costream.h (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/io/costream.h (revision 5154) @@ -0,0 +1,39 @@ +/* + * wxJavaScript - costream.h + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: costream.h 598 2007-03-07 20:13:28Z fbraem $ + */ +#ifndef wxjs_io_costream_h +#define wxjs_io_costream_h + +namespace wxjs +{ + namespace io + { + class CountingOutputStream : public ApiWrapper + { + public: + static Stream* Construct(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, bool constructing); + }; + }; // namespace io +}; // namespace wxjs +#endif // wxjs_io_costream_h Property changes on: ps/trunk/source/tools/atlas/wxJS/io/costream.h ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/io/tistream.cpp =================================================================== --- ps/trunk/source/tools/atlas/wxJS/io/tistream.cpp (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/io/tistream.cpp (revision 5154) @@ -0,0 +1,288 @@ +#include "precompiled.h" + +/* + * wxJavaScript - tistream.cpp + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: tistream.cpp 598 2007-03-07 20:13:28Z fbraem $ + */ +#include +#ifndef WX_PRECOMP + #include +#endif + +#include "../common/main.h" + +#include "stream.h" +#include "istream.h" +#include "tistream.h" + +using namespace wxjs; +using namespace wxjs::io; + +/*** + * tistream + * io + * + * This class provides functions that read text datas using an input stream. + * So, you can read text, floats and integers. wxTextInputStream correctly reads + * text files (or streams) in DOS, Macintosh and Unix formats and reports a + * single newline char as a line ending. + *

The following example uses a @wxMemoryInputStream and makes an array which + * contains all words of the given string. + * + *

+ *  var m = new wxMemoryInputStream("This is a test");
+ *  var t = new wxTextInputStream(m);
+ *  var words = new Array();
+ *  for(var i = 0; ! m.eof; i++)
+ *  {
+ *    words[i] = t.readWord();
+ *  }
+ *  
+ *
+ */ +WXJS_INIT_CLASS(TextInputStream, "wxTextInputStream", 1) + +TextInputStream::TextInputStream(wxInputStream &stream, + const wxString &sep, + wxMBConv& conv) : wxTextInputStream(stream, sep, conv) +{ +} + +/*** + * + * + * An input stream + * The initial string separator + * The encoding used to convert bytes + * + * + * Constructs a new wxTextInputStream object. + * + * + */ +TextInputStream* TextInputStream::Construct(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, bool constructing) +{ + if ( argc > 3 ) + argc = 3; + + wxString encoding(wxJS_EXTERNAL_ENCODING); + wxString sep = wxT("\t"); + switch(argc) + { + case 3: + FromJS(cx, argv[2], encoding); + // Fall through + case 2: + FromJS(cx, argv[1], sep); + // Fall through + default: + { + wxCSConv conv(encoding); + Stream *in = InputStream::GetPrivate(cx, argv[0]); + if ( in == NULL ) + return NULL; + + JS_DefineProperty(cx, obj, "__stream__", argv[0], NULL, NULL, 0); + + return new TextInputStream(*(wxInputStream *) in->GetStream(), sep, conv); + } + } + + return NULL; +} + +/*** + * + * + * Gets/Sets the characters which are used to define the word boundaries in + * See @wxTextInputStream#readWord. The default separators are the space and TAB characters. + * + * + */ +WXJS_BEGIN_PROPERTY_MAP(TextInputStream) + WXJS_PROPERTY(P_STRING_SEPARATORS, "stringSeparators") +WXJS_END_PROPERTY_MAP() + +bool TextInputStream::GetProperty(TextInputStream *p, JSContext *cx, JSObject *obj, int id, jsval *vp) +{ + if ( id == P_STRING_SEPARATORS ) + { + *vp = ToJS(cx, p->GetStringSeparators()); + } + return true; +} + +bool TextInputStream::SetProperty(TextInputStream *p, JSContext *cx, JSObject *obj, int id, jsval *vp) +{ + if ( id == P_STRING_SEPARATORS ) + { + wxString sep; + FromJS(cx, *vp, sep); + p->SetStringSeparators(sep); + } + return true; +} + +WXJS_BEGIN_METHOD_MAP(TextInputStream) + WXJS_METHOD("read32", read32, 0) + WXJS_METHOD("read16", read16, 0) + WXJS_METHOD("read8", read8, 0) + WXJS_METHOD("readLine", readLine, 0) + WXJS_METHOD("readDouble", readDouble, 0) + WXJS_METHOD("readWord", readWord, 0) +WXJS_END_METHOD_MAP() + +/*** + * + * + * + * Reads a 32 bit integer from the stream. + * + * + */ +JSBool TextInputStream::read32(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxTextInputStream *p = TextInputStream::GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + wxUint32 value = p->Read32(); + +// Check this for other platforms! +#ifdef __WXMSW__ + *rval = ToJS(cx, (int) value); +#else + *rval = ToJS(cx, (int) value); +#endif + + return JS_TRUE; +} + +/*** + * + * + * + * Reads a 16 bit integer from the stream. + * + * + */ +JSBool TextInputStream::read16(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxTextInputStream *p = TextInputStream::GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + wxUint16 value = p->Read16(); + +// Check this for other platforms! +#ifdef __WXMSW__ + *rval = ToJS(cx, (int) value); +#else + *rval = ToJS(cx, (int) value); +#endif + + return JS_TRUE; +} + +/*** + * + * + * + * Reads a 8 bit integer from the stream. + * + * + */ +JSBool TextInputStream::read8(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxTextInputStream *p = TextInputStream::GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + wxUint8 value = p->Read8(); + +// Check this for other platforms! +#ifdef __WXMSW__ + *rval = ToJS(cx, (int) value); +#else + *rval = ToJS(cx, (int) value); +#endif + + return JS_TRUE; +} + +/*** + * + * + * + * Reads a double (IEEE encoded) from a stream. + * + * + */ +JSBool TextInputStream::readDouble(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxTextInputStream *p = TextInputStream::GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + *rval = ToJS(cx, p->ReadDouble()); + + return JS_TRUE; +} + +/*** + * + * + * + * Reads from the input stream until an end-of-line character is read. + * The end-of-line character is not returned. + * + * + */ +JSBool TextInputStream::readLine(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + TextInputStream *p = TextInputStream::GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + *rval = ToJS(cx, p->ReadLine()); + return JS_TRUE; +} + +/*** + * + * + * + * Reads a word (a sequence of characters until the next separator) from the input stream. + * See @wxTextInputStream#stringSeparators. + * + * + */ +JSBool TextInputStream::readWord(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxTextInputStream *p = TextInputStream::GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + *rval = ToJS(cx, p->ReadWord()); + return JS_TRUE; +} Property changes on: ps/trunk/source/tools/atlas/wxJS/io/tistream.cpp ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/io/textline.cpp =================================================================== --- ps/trunk/source/tools/atlas/wxJS/io/textline.cpp (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/io/textline.cpp (revision 5154) @@ -0,0 +1,268 @@ +#include "precompiled.h" + +/* + * wxJavaScript - textline.cpp + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: textline.cpp 598 2007-03-07 20:13:28Z fbraem $ + */ +#include +#ifndef WX_PRECOMP + #include +#endif + +#include "../common/main.h" +#include "../common/index.h" +#include "textline.h" +#include "textfile.h" + +using namespace wxjs; +using namespace wxjs::io; + +/*** + * textline + * io + * + * wxTextLine is a helper class. It doesn't exist in wxWidgets, + * but wxJS needs it, so you can access lines in @wxTextFile as + * an array: + *

+ *   var i;
+ *   for(i = 0; i < file.lineCount; i++)
+ *   {
+ *     file.lines[i].content = ...
+ *   }
+ *   
+ * or as: + *

+ *   for each(line in textfile.lines)
+ *   {
+ *      line.content = ...
+ *   }
+ *
+ */ +WXJS_INIT_CLASS(TextLine, "wxTextLine", 0) + +bool TextLine::Resolve(JSContext *cx, JSObject *obj, jsval id) +{ + if ( JSVAL_IS_INT(id) + && JSVAL_TO_INT(id) >= 0 ) + { + return JS_DefineElement(cx, obj, JSVAL_TO_INT(id), INT_TO_JSVAL(0), NULL, NULL, 0) == JS_TRUE; + } + return true; +} + +/*** + * + * + * Get/Set the content of the line.

+ * Remark: When you access this object as an array of @wxTextFile + * you don't need this property. You can write: + * + * textfile.lines[1] = 'Text'; + *
+ * + * Get the type of the line + * + *
+ */ +WXJS_BEGIN_PROPERTY_MAP(TextLine) + WXJS_READONLY_PROPERTY(P_LINE_TYPE, "lineType") + WXJS_PROPERTY(P_CONTENT, "content") +WXJS_END_PROPERTY_MAP() + +bool TextLine::GetProperty(Index *p, JSContext *cx, JSObject *obj, int id, jsval *vp) +{ + JSObject *parent = JS_GetParent(cx, obj); + wxASSERT_MSG(parent != NULL, wxT("No parent found for TextLine")); + + wxTextFile *file = TextFile::GetPrivate(cx, parent); + if ( file == NULL ) + return false; + + if ( id >= 0 && id < file->GetLineCount() ) + { + p->SetIndex(id); + *vp = OBJECT_TO_JSVAL(obj); //ToJS(cx, file->GetLine(id)); + } + else + { + switch(id) + { + case P_LINE_TYPE: + *vp = ToJS(cx, (int) file->GetLineType(p->GetIndex())); + break; + case P_CONTENT: + *vp = ToJS(cx, file->GetLine(p->GetIndex())); + break; + default: + *vp = JSVAL_VOID; + } + } + + return true; +} + +bool TextLine::SetProperty(Index *p, JSContext *cx, JSObject *obj, int id, jsval *vp) +{ + JSObject *parent = JS_GetParent(cx, obj); + wxASSERT_MSG(parent != NULL, wxT("No parent found for TextLine")); + + wxTextFile *file = TextFile::GetPrivate(cx, parent); + if ( file == NULL ) + return false; + + if ( id >= 0 && id < file->GetLineCount() ) + { + p->SetIndex(id); + wxString content; + FromJS(cx, *vp, content); + file->GetLine(id) = content; + } + else + { + if ( id == P_CONTENT ) + { + wxString content; + FromJS(cx, *vp, content); + file->GetLine(p->GetIndex()) = content; + } + } + return true; +} + +bool TextLine::Enumerate(Index *p, JSContext *cx, JSObject *obj, JSIterateOp enum_op, jsval *statep, jsid *idp) +{ + JSObject *parent = JS_GetParent(cx, obj); + if ( parent == NULL ) + { + *statep = JSVAL_NULL; + if (idp) + *idp = INT_TO_JSVAL(0); + return true; + } + + wxTextFile *file = TextFile::GetPrivate(cx, parent); + if ( file == NULL ) + { + *statep = JSVAL_NULL; + if (idp) + *idp = INT_TO_JSVAL(0); + return true; + } + + bool ok = true; + + switch(enum_op) + { + case JSENUMERATE_INIT: + *statep = ToJS(cx, 0); + if ( idp ) + *idp = INT_TO_JSVAL(file->GetLineCount()); + break; + case JSENUMERATE_NEXT: + { + int pos; + FromJS(cx, *statep, pos); + if ( pos < file->GetLineCount() ) + { + JS_ValueToId(cx, ToJS(cx, pos), idp); + *statep = ToJS(cx, ++pos); + break; + } + // Fall through + } + case JSENUMERATE_DESTROY: + *statep = JSVAL_NULL; + break; + default: + ok = false; + } + return ok; +} + +WXJS_BEGIN_METHOD_MAP(TextLine) + WXJS_METHOD("insert", insertLine, 1) + WXJS_METHOD("remove", removeLine, 0) +WXJS_END_METHOD_MAP() + +/*** + * + * + * The line to insert (without the end-of-line character(s)). + * + * + * + * Insert a line before this line. + * + * + */ +JSBool TextLine::insertLine(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + Index *p = GetPrivate(cx, obj); + wxASSERT_MSG(p != NULL, wxT("No private data associated with wxTextLine")); + + JSObject *objParent = JS_GetParent(cx, obj); + if ( objParent == NULL ) + return JS_FALSE; + + wxTextFile *file = TextFile::GetPrivate(cx, objParent); + + wxString line; + FromJS(cx, argv[0], line); + + if ( argc > 1 ) + { + int type; + if ( ! FromJS(cx, argv[1], type) ) + return JS_FALSE; + file->InsertLine(line, p->GetIndex(), (wxTextFileType) type); + } + else + { + file->InsertLine(line, p->GetIndex()); + } + return JS_TRUE; +} + +/*** + * + * + * + * Removes this line from the file + * + * + */ +JSBool TextLine::removeLine(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + Index *p = GetPrivate(cx, obj); + wxASSERT_MSG(p != NULL, wxT("No private data associated with wxTextLine")); + + JSObject *objParent = JS_GetParent(cx, obj); + if ( objParent == NULL ) + return JS_FALSE; + + wxTextFile *file = TextFile::GetPrivate(cx, objParent); + + file->RemoveLine(p->GetIndex()); + return JS_TRUE; +} Property changes on: ps/trunk/source/tools/atlas/wxJS/io/textline.cpp ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/io/istream.cpp =================================================================== --- ps/trunk/source/tools/atlas/wxJS/io/istream.cpp (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/io/istream.cpp (revision 5154) @@ -0,0 +1,302 @@ +#include "precompiled.h" + +/* + * wxJavaScript - istream.cpp + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: istream.cpp 598 2007-03-07 20:13:28Z fbraem $ + */ +#include +#ifndef WX_PRECOMP + #include +#endif + +#include "../common/main.h" +#include "../ext/wxjs_ext.h" + +#include "stream.h" +#include "ostream.h" +#include "istream.h" + +using namespace wxjs; +using namespace wxjs::io; + +/*** + * istream + * io + * + * wxInputStream is a prototype for input streams. You can't construct it directly. + * See @wxMemoryInputStream, @wxFileInputStream and @wxFFileInputStream. + * + */ +WXJS_INIT_CLASS(InputStream, "wxInputStream", 0) + +/*** + * + * + * Returns the first character in the input queue and removes it. + * When set it puts back the character or full String in the input queue. + * + * + * Returns true when end-of-file occurred. + * + * + * Returns the last number of bytes read. + * + * + * Returns the first character in the input queue without removing it. + * + * + */ +WXJS_BEGIN_PROPERTY_MAP(InputStream) + WXJS_PROPERTY(P_C, "c") + WXJS_READONLY_PROPERTY(P_EOF, "eof") + WXJS_READONLY_PROPERTY(P_LAST_READ, "lastRead") + WXJS_READONLY_PROPERTY(P_PEEK, "peek") + WXJS_READONLY_PROPERTY(P_TELL_I, "tellI") +WXJS_END_PROPERTY_MAP() + +bool InputStream::GetProperty(Stream *p, JSContext *cx, JSObject *obj, int id, jsval *vp) +{ + wxInputStream *stream = (wxInputStream*) p->GetStream(); + switch (id) + { + case P_C: + *vp = ToJS(cx, wxString::FromAscii(stream->GetC())); + break; + case P_EOF: + *vp = ToJS(cx, stream->Eof()); + break; + case P_LAST_READ: + *vp = ToJS(cx, (int) stream->LastRead()); + break; + case P_PEEK: + *vp = ToJS(cx, wxString::FromAscii(stream->Peek())); + break; + } + return true; +} + +bool InputStream::SetProperty(Stream *p, JSContext *cx, JSObject *obj, int id, jsval *vp) +{ + if ( id == P_C ) + { + wxInputStream *stream = (wxInputStream*) p->GetStream(); + wxString s; + FromJS(cx, *vp, s); + if ( s.length() > 0 ) + { + stream->Ungetch(s, s.length()); + } + } + return true; +} + +WXJS_BEGIN_METHOD_MAP(InputStream) + WXJS_METHOD("getC", getC, 0) + WXJS_METHOD("peek", peek, 0) + WXJS_METHOD("read", read, 1) + WXJS_METHOD("seekI", seekI, 1) + WXJS_METHOD("ungetch", ungetch, 1) +WXJS_END_METHOD_MAP() + +/*** + * + * + * + * Returns the next character from the input queue and removes it. + * + * + */ +JSBool InputStream::getC(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + Stream *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + wxInputStream *in = (wxInputStream *) p->GetStream(); + *rval = ToJS(cx, wxString::FromAscii(in->GetC())); + return JS_TRUE; +} + +/*** + * + * + * + * Returns the next character from the input queue without removing it. + * + * + */ +JSBool InputStream::peek(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + Stream *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + wxInputStream *in = (wxInputStream *) p->GetStream(); + + *rval = ToJS(cx, wxString::FromAscii(in->Peek())); + return JS_TRUE; +} + +/*** + * + * + * + * + * + * + * The outputstream that gets the data from the input queue. + * + * + * + * Reads the specified number of bytes (the size of the buffer) and stores them in the buffer. + *

+ * Reads data from the input queue and stores it in the specified output stream. + * The data is read until an error is raised by one of the two streams. + *
+ *
+ */ +JSBool InputStream::read(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + Stream *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + wxInputStream *in = (wxInputStream *) p->GetStream(); + + if ( OutputStream::HasPrototype(cx, argv[0]) ) + { + Stream *p_out = OutputStream::GetPrivate(cx, argv[0], false); + wxOutputStream *out = (wxOutputStream *) p_out->GetStream(); + in->Read(*out); + *rval = OBJECT_TO_JSVAL(obj); + return JS_TRUE; + } + else + { + wxMemoryBuffer *buffer = wxjs::ext::GetMemoryBuffer(cx, JSVAL_TO_OBJECT(argv[0])); + + if ( buffer != NULL ) + { + in->Read(buffer->GetData(), buffer->GetBufSize()); + buffer->SetDataLen(in->LastRead()); + *rval = OBJECT_TO_JSVAL(obj); + return JS_TRUE; + } + } + return JS_FALSE; +} + +/*** + * + * + * + * Offset to seek to + * + * + * + * + * Seeks the offset. Returns the actual position or -1 on error. + * + * + */ +JSBool InputStream::seekI(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + Stream *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + wxInputStream *in = (wxInputStream *) p->GetStream(); + + int offset; + if ( ! FromJS(cx, argv[0], offset) ) + return JS_FALSE; + + int pos; + + if ( argc > 1 ) + { + int mode; + if ( FromJS(cx, argv[1], mode) ) + { + pos = in->SeekI(offset, (wxSeekMode) mode); + } + else + return JS_FALSE; + } + else + pos = in->SeekI(offset); + + *rval = ToJS(cx, pos); + return JS_TRUE; +} + +/*** + * + * + * + * + * + * + * + * + * This function is only useful in read mode. It is the manager of the "Write-Back" buffer. + * This buffer acts like a temporary buffer where datas which has to be read during the next + * read IO call are put. This is useful when you get a big block of data which you didn't want + * to read: you can replace them at the top of the input queue by this way. + *

+ * Be very careful about this call in connection with calling @wxInputStream#seekI on the + * same stream. Any call to @wxInputStream#seekI will invalidate any previous call to this + * method (otherwise you could @wxInputStream#seekI to one position, "unread" a few bytes + * there, @wxInputStream#seekI to another position and data would be either lost or corrupted). + *
+ *
+ */ +JSBool InputStream::ungetch(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + Stream *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + wxInputStream *in = (wxInputStream *) p->GetStream(); + + if ( JSVAL_IS_OBJECT(argv[0]) ) + { + wxMemoryBuffer* buffer = wxjs::ext::GetMemoryBuffer(cx, JSVAL_TO_OBJECT(argv[0])); + if ( buffer != NULL ) + { + *rval = ToJS(cx, (int) in->Ungetch(buffer->GetData(), buffer->GetDataLen())); + return JS_TRUE; + } + } + + wxString s; + FromJS(cx, argv[0], s); + if ( s.length() > 0 ) + { + *rval = ToJS(cx, (int) in->Ungetch(s, s.length())); + } + else + *rval = ToJS(cx, 0); + + return JS_TRUE; +} Property changes on: ps/trunk/source/tools/atlas/wxJS/io/istream.cpp ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/io/ostream.cpp =================================================================== --- ps/trunk/source/tools/atlas/wxJS/io/ostream.cpp (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/io/ostream.cpp (revision 5154) @@ -0,0 +1,267 @@ +#include "precompiled.h" + +/* + * wxJavaScript - ostream.cpp + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: ostream.cpp 598 2007-03-07 20:13:28Z fbraem $ + */ +#include +#ifndef WX_PRECOMP + #include +#endif + +#include "../common/main.h" +#include "../ext/wxjs_ext.h" + + +#include "stream.h" +#include "istream.h" +#include "ostream.h" + +using namespace wxjs; +using namespace wxjs::io; + +/*** + * ostream + * io + * + * wxOutputStream is a prototype for output streams. You can't construct it directly. + * See @wxMemoryOutputStream, @wxFileOutputStream, @wxFFileOutputStream. + * + */ +WXJS_INIT_CLASS(OutputStream, "wxOutputStream", 0) + +/*** + * + * + * Gets the last number of bytes written. + * + * + * Returns the current position. + * + * + */ +WXJS_BEGIN_PROPERTY_MAP(OutputStream) + WXJS_READONLY_PROPERTY(P_LAST_WRITE, "lastWrite") + WXJS_READONLY_PROPERTY(P_TELL_O, "tellO") +WXJS_END_PROPERTY_MAP() + +bool OutputStream::GetProperty(Stream *p, JSContext *cx, JSObject *obj, int id, jsval *vp) +{ + wxOutputStream *stream = (wxOutputStream *) p->GetStream(); + switch (id) + { + case P_LAST_WRITE: + *vp = ToJS(cx, (long) stream->LastWrite()); + break; + case P_TELL_O: + *vp = ToJS(cx, (long) stream->TellO()); + break; + } + return true; +} + +WXJS_BEGIN_METHOD_MAP(OutputStream) + WXJS_METHOD("close", close, 0) + WXJS_METHOD("putC", putC, 1) + WXJS_METHOD("write", write, 1) + WXJS_METHOD("seekO", seekO, 1) + WXJS_METHOD("sync", sync, 0) +WXJS_END_METHOD_MAP() + +/*** + * + * + * + * Closes the stream + * + * + */ +JSBool OutputStream::close(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + Stream *p = GetPrivate(cx, obj); + if ( p != NULL ) + { + wxOutputStream *out = (wxOutputStream *) p->GetStream(); + *rval = ToJS(cx, out->Close()); + } + return JS_TRUE; +} + +/*** + * + * + * + * + * + * The first character of the String is written to the output stream. + * + * + */ +JSBool OutputStream::putC(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + Stream *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + wxOutputStream *out = (wxOutputStream *) p->GetStream(); + + wxString Buffer; + FromJS(cx, argv[0], Buffer); + if ( Buffer.length() > 0 ) + { + out->PutC(Buffer.at(0)); + } + return JS_TRUE; +} + +/*** + * + * + * + * The number of characters to write. Default is the length of buffer. + * + * + * + * + * + * + * + * + * 1. Writes the buffer to the outputstream. Unlike wxWindows, the size of the buffer must not + * be specified. If ommitted then the full buffer is written. + *

+ * 2. Reads data from the specified input stream and stores them in the current stream. + * The data is read until an error is raised by one of the two streams. + *

+ * Unlike wxWidgets, this method returns the number of bytes written. + *
+ *
+ */ +JSBool OutputStream::write(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + Stream *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + wxOutputStream *out = (wxOutputStream *) p->GetStream(); + + if ( InputStream::HasPrototype(cx, argv[0]) ) + { + Stream *p_in = InputStream::GetPrivate(cx, argv[0], false); + wxInputStream *in = (wxInputStream *) p_in->GetStream(); + out->Write(*in); + } + else + { + if ( JSVAL_IS_OBJECT(argv[0]) ) + { + wxMemoryBuffer* buffer = wxjs::ext::GetMemoryBuffer(cx, JSVAL_TO_OBJECT(argv[0])); + if ( buffer != NULL ) + { + *rval = ToJS(cx, out->Write(buffer->GetData(), buffer->GetDataLen()).LastWrite()); + return JS_TRUE; + } + } + + wxString buffer; + FromJS(cx, argv[0], buffer); + + int count = buffer.length(); + if ( argc > 1 ) + { + if ( FromJS(cx, argv[1], count) ) + { + if ( count > (int) buffer.length() ) + count = buffer.length(); + } + else + return JS_FALSE; + } + + *rval = ToJS(cx, out->Write(buffer, count).LastWrite()); + } + return JS_TRUE; +} + +/*** + * + * + * Offset to seek to + * + * + * + * Seeks the offset. Returns the actual position or -1 on error. + * + * + */ +JSBool OutputStream::seekO(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + Stream *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + wxOutputStream *out = (wxOutputStream *) p->GetStream(); + + int offset; + if ( ! FromJS(cx, argv[0], offset) ) + return JS_FALSE; + + int pos; + + if ( argc > 1 ) + { + int mode; + if ( FromJS(cx, argv[1], mode) ) + { + pos = out->SeekO(offset, (wxSeekMode) mode); + } + else + return JS_FALSE; + } + else + pos = out->SeekO(offset); + + *rval = ToJS(cx, pos); + return JS_TRUE; +} + +/*** + * + * + * + * Flushes the buffer. + * + * + */ +JSBool OutputStream::sync(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + Stream *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + wxOutputStream *out = (wxOutputStream *) p->GetStream(); + + out->Sync(); + return JS_TRUE; +} + Property changes on: ps/trunk/source/tools/atlas/wxJS/io/ostream.cpp ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/io/dirtrav.cpp =================================================================== --- ps/trunk/source/tools/atlas/wxJS/io/dirtrav.cpp (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/io/dirtrav.cpp (revision 5154) @@ -0,0 +1,189 @@ +#include "precompiled.h" + +/* + * wxJavaScript - dirtrav.cpp + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: dirtrav.cpp 716 2007-05-20 17:57:22Z fbraem $ + */ +// wxJSDirTraverser.cpp + +#include +#ifndef WX_PRECOMP + #include +#endif + +#include "../common/main.h" +#include "../common/jsutil.h" + +#include "dirtrav.h" + +using namespace wxjs; +using namespace wxjs::io; + +DirTraverser::DirTraverser() + : wxDirTraverser() +{ +} + +wxDirTraverseResult DirTraverser::OnFile(const wxString& filename) +{ + JavaScriptClientData *data + = dynamic_cast(GetClientObject()); + JSContext *cx = data->GetContext(); + jsval fval; + if ( GetFunctionProperty(cx, data->GetObject(), "onFile", &fval) == JS_TRUE ) + { + jsval rval; + jsval argv[] = { ToJS(cx, filename) }; + if ( JS_CallFunctionValue(cx, data->GetObject(), fval, 1, argv, &rval) == JS_TRUE ) + { + int result; + if ( FromJS(cx, rval, result ) ) + { + return (wxDirTraverseResult) result; + } + } + else + { + if ( JS_IsExceptionPending(cx) ) + { + JS_ReportPendingException(cx); + } + } + return wxDIR_STOP; + } + + // No function set, we return continue + return wxDIR_CONTINUE; +} + +wxDirTraverseResult DirTraverser::OnDir(const wxString& filename) +{ + JavaScriptClientData *data + = dynamic_cast(GetClientObject()); + + JSContext *cx = data->GetContext(); + jsval fval; + if ( GetFunctionProperty(cx, data->GetObject(), "onDir", &fval) == JS_TRUE ) + { + jsval rval; + jsval argv[] = { ToJS(cx, filename) }; + if ( JS_CallFunctionValue(cx, data->GetObject(), fval, 1, argv, &rval) == JS_TRUE ) + { + int result; + if ( FromJS(cx, rval, result) ) + { + return (wxDirTraverseResult) result; + } + } + else + { + if ( JS_IsExceptionPending(cx) ) + { + JS_ReportPendingException(cx); + } + } + return wxDIR_STOP; + } + + // No function set, we return continue + return wxDIR_CONTINUE; +} + +/*** + * dirtrav + * io + * + * wxDirTraverser can be used to traverse into directories to retrieve filenames and subdirectories. + *

+ * See also @wxDir + *

+ * The following example counts all subdirectories of the temporary directory. + * Counting the direct subdirectories of temp is possible by returning + * IGNORE in @wxDirTraverser#onDir. + *

+ *  var dir = new wxDir("c:\\temp");
+ *  var trav = new wxDirTraverser();
+ *  subdir = 0; // Don't use var, it doesn't seem to work with closures
+ *  
+ *  trav.onDir = function(filename)
+ *  {
+ *    subdir = subdir + 1;
+ *    return wxDirTraverser.CONTINUE;
+ *  }
+ * 
+ *  dir.traverse(trav);
+ *
+ *  wxMessageBox("Number of subdirectories: " + subdir);
+ *  
+ *
+ */ +WXJS_INIT_CLASS(DirTraverser, "wxDirTraverser", 0) + +/*** + * + * + * + * + * + * + * + */ +WXJS_BEGIN_CONSTANT_MAP(DirTraverser) + WXJS_CONSTANT(wxDIR_, IGNORE) + WXJS_CONSTANT(wxDIR_, STOP) + WXJS_CONSTANT(wxDIR_, CONTINUE) +WXJS_END_CONSTANT_MAP() + +/*** + * + * + * Function which will be called for each file. The function + * gets a filename and should return a constant @wxDirTraverser#wxDirTraverseResult except + * for IGNORE. When no function is set, it will return + * CONTINUE. This makes it possible to enumerate the subdirectories. + * + * + * Function which will be called for each directory. The function + * gets a directoryname and should return a constant @wxDirTraverser#wxDirTraverseResult. + * It may return STOP to abort traversing completely, IGNORE to skip this directory but continue with + * others or CONTINUE to enumerate all files and subdirectories + * in this directory. When no function is set, it will return CONTINUE. + * This makes it possible to enumerate all files. + * + * + */ + +/*** + * + * + * + * Constructs a new wxDirTraverser object. + * + * + */ +DirTraverser* DirTraverser::Construct(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, bool constructing) +{ + DirTraverser *p = new DirTraverser(); + p->SetClientObject(new JavaScriptClientData(cx, obj, false, true)); + return p; +} Property changes on: ps/trunk/source/tools/atlas/wxJS/io/dirtrav.cpp ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/io/ffistream.cpp =================================================================== --- ps/trunk/source/tools/atlas/wxJS/io/ffistream.cpp (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/io/ffistream.cpp (revision 5154) @@ -0,0 +1,86 @@ +#include "precompiled.h" + +/* + * wxJavaScript - ffistream.cpp + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: ffistream.cpp 598 2007-03-07 20:13:28Z fbraem $ + */ +#include +#ifndef WX_PRECOMP + #include +#endif + +#include "wx/wfstream.h" +#include "../common/main.h" + +#include "ffile.h" +#include "stream.h" +#include "ffistream.h" + +using namespace wxjs; +using namespace wxjs::io; + +/*** + * ffistream + * io + * + * This class represents data read in from a file. There are actually two such groups of classes: + * this one is based on @wxFFile whereas @wxFileInputStream is based on the @wxFile class. + * + */ +WXJS_INIT_CLASS(FFileInputStream, "wxFFileInputStream", 1) + +/*** + * + * + * The name of a file + * + * + * + * + * + * A file descriptor + * + * + * Constructs a new wxFFileInputStream object. A wxFFileInputStream is always opened in read-only mode. + * + * + */ +Stream* FFileInputStream::Construct(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, bool constructing) +{ + if ( FFile::HasPrototype(cx, argv[0]) ) + { + wxFFile *file = FFile::GetPrivate(cx, argv[0], false); + // This is needed, because otherwise the file can be garbage collected. + // Another method could be to root ffile, but how are we going to unroot it? + JS_DefineProperty(cx, obj, "__ffile__", argv[0], NULL, NULL, JSPROP_READONLY); + + return new Stream(new wxFFileInputStream(*file)); + } + else if ( JSVAL_IS_STRING(argv[0]) ) + { + wxString name; + FromJS(cx, argv[0], name); + return new Stream(new wxFFileInputStream(name)); + } + return NULL; +} Property changes on: ps/trunk/source/tools/atlas/wxJS/io/ffistream.cpp ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/io/sound.cpp =================================================================== --- ps/trunk/source/tools/atlas/wxJS/io/sound.cpp (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/io/sound.cpp (revision 5154) @@ -0,0 +1,179 @@ +#include "precompiled.h" + +/* + * wxJavaScript - sound.cpp + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: sound.cpp 598 2007-03-07 20:13:28Z fbraem $ + */ +#include +#ifndef WX_PRECOMP + #include +#endif + +#include "../common/main.h" + +#include "sound.h" + +using namespace wxjs; +using namespace wxjs::io; + +/*** + * sound + * io + * + * This class represents a short sound (loaded from Windows WAV file), that can be stored in memory and played. + * + */ +WXJS_INIT_CLASS(Sound, "wxSound", 0) + +/*** + * + * + * + * + * + * + * + */ +WXJS_BEGIN_CONSTANT_MAP(Sound) + WXJS_CONSTANT(wxSOUND_, SYNC) + WXJS_CONSTANT(wxSOUND_, ASYNC) + WXJS_CONSTANT(wxSOUND_, LOOP) +WXJS_END_CONSTANT_MAP() + +WXJS_BEGIN_STATIC_METHOD_MAP(Sound) + WXJS_METHOD("stop", stop, 0) +WXJS_END_METHOD_MAP() + +/*** + * + * + * + * Stops the sound + * + * + */ +JSBool Sound::stop(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxSound::Stop(); + return JS_TRUE; +} + +/*** + * + * + * + * The name of the soundfile. + * + * + * Constructs a new wxSound object. When no argument is specified, use @wxSound#create + * afterwards. + * + * + */ +wxSound* Sound::Construct(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, bool constructing) +{ + if ( argc == 0 ) + return new wxSound(); + + if ( argc == 1 ) + { + wxString f; + FromJS(cx, argv[0], f); + return new wxSound(f); + } + + return NULL; +} + +/*** + * + * + * Returns true when the soundfile is successfully loaded. + * + * + */ +WXJS_BEGIN_PROPERTY_MAP(Sound) + WXJS_READONLY_PROPERTY(P_OK, "ok") +WXJS_END_PROPERTY_MAP() + +bool Sound::GetProperty(wxSound *p, JSContext *cx, JSObject *obj, int id, jsval *vp) +{ + if ( id == P_OK ) + *vp = ToJS(cx, p->IsOk()); + return true; +} + +WXJS_BEGIN_METHOD_MAP(Sound) + WXJS_METHOD("play", play, 0) + WXJS_METHOD("create", create, 1) +WXJS_END_METHOD_MAP() + +/*** + * + * + * The name of the soundfile + * + * + * Constructs a sound object. + * + * + */ +JSBool Sound::create(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxSound *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + wxString file; + FromJS(cx, argv[0], file); + *rval = ToJS(cx, p->Create(file)); + + return JS_TRUE; +} + +/*** + * + * + * + * + * + * Plays the sound. + * + * + */ +JSBool Sound::play(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxSound *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + int flag = wxSOUND_ASYNC; + if ( argc > 0 ) + { + if ( ! FromJS(cx, argv[0], flag) ) + return JS_FALSE; + } + *rval = ToJS(cx, p->Play((unsigned int) flag)); + + return JS_TRUE; +} Property changes on: ps/trunk/source/tools/atlas/wxJS/io/sound.cpp ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/io/tistream.h =================================================================== --- ps/trunk/source/tools/atlas/wxJS/io/tistream.h (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/io/tistream.h (revision 5154) @@ -0,0 +1,66 @@ +/* + * wxJavaScript - tistream.h + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: tistream.h 598 2007-03-07 20:13:28Z fbraem $ + */ +#ifndef _WXJSTextInputStream_H +#define _WXJSTextInputStream_H + +#include + +namespace wxjs +{ + namespace io + { + class TextInputStream: public ApiWrapper, + public wxTextInputStream + { + public: + TextInputStream(wxInputStream &stream, const wxString &sep, wxMBConv& conv); + /** + * Callback for when a wxTextInputStream object is created + */ + static TextInputStream* Construct(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, bool constructing); + + static bool GetProperty(TextInputStream *p, JSContext *cx, JSObject *obj, int id, jsval *vp); + static bool SetProperty(TextInputStream *p, JSContext *cx, JSObject *obj, int id, jsval *vp); + WXJS_DECLARE_PROPERTY_MAP() + + /** + * Property Ids. + */ + enum + { + P_STRING_SEPARATORS + }; + + WXJS_DECLARE_METHOD_MAP() + static JSBool read32(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval); + static JSBool read16(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval); + static JSBool read8(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval); + static JSBool readDouble(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval); + static JSBool readLine(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval); + static JSBool readWord(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval); + }; + }; // namespace io +}; // namespace wxjs +#endif //_WXJSTextInputStream_H Property changes on: ps/trunk/source/tools/atlas/wxJS/io/tistream.h ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/io/url.cpp =================================================================== --- ps/trunk/source/tools/atlas/wxJS/io/url.cpp (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/io/url.cpp (revision 5154) @@ -0,0 +1,187 @@ +#include "precompiled.h" + +/* + * wxJavaScript - url.cpp + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: url.cpp 598 2007-03-07 20:13:28Z fbraem $ + */ +#include +#ifndef WX_PRECOMP + #include +#endif + +#include "../common/main.h" +#include "jsstream.h" +#include "istream.h" +#include "url.h" + +using namespace wxjs; +using namespace wxjs::io; + +/*** + * url + * io + * + * Parses URLs. + * + */ +WXJS_INIT_CLASS(URL, "wxURL", 1) + +/*** + * + * + * No error. + * Syntax error in the URL string. + * Found no protocol which can get this URL. + * An host name is required for this protocol. + * A path is required for this protocol. + * Connection error. + * An error occurred during negotiation. + * + * wxURLError is ported to JavaScript as a separate class. Note that this + * class doesn't exist in wxWidgets. + * + * + * + */ +void URL::InitClass(JSContext *cx, JSObject *obj, JSObject *proto) +{ + JSConstDoubleSpec wxURLErrorMap[] = + { + WXJS_CONSTANT(wxURL_, NOERR) + WXJS_CONSTANT(wxURL_, SNTXERR) + WXJS_CONSTANT(wxURL_, NOPROTO) + WXJS_CONSTANT(wxURL_, NOHOST) + WXJS_CONSTANT(wxURL_, NOPATH) + WXJS_CONSTANT(wxURL_, CONNERR) + WXJS_CONSTANT(wxURL_, PROTOERR) + { 0 } + }; + + JSObject *constObj = JS_DefineObject(cx, obj, "wxURLError", + NULL, NULL, + JSPROP_READONLY | JSPROP_PERMANENT); + JS_DefineConstDoubles(cx, constObj, wxURLErrorMap); +} + +/*** + * + * + * + * + * + * Constructs a URL object from the string. The URL must be valid according to RFC 1738. + * In particular, file URLs must be of the format 'file://hostname/path/to/file'. It is valid + * to leave out the hostname but slashes must remain in place-- i.e. a file URL without a + * hostname must contain three consecutive slashes. + * + * + */ +wxURL *URL::Construct(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, bool constructing) +{ + wxString url; + FromJS(cx, argv[0], url); + return new wxURL(url); +} + +/*** + * + * + * Returns the last occurred error. See @wxURL#wxURLError. + * + * + * Creates a new input stream on the specified URL. You can use all but + * seek functionality of a stream. Seek isn't available on all streams. + * For example, http or ftp streams doesn't deal with it. + * + * + */ +WXJS_BEGIN_PROPERTY_MAP(URL) + WXJS_READONLY_PROPERTY(P_ERROR, "error") + WXJS_READONLY_PROPERTY(P_INPUT_STREAM, "inputStream") +WXJS_END_PROPERTY_MAP() + +bool URL::GetProperty(wxURL *p, JSContext *cx, JSObject *obj, int id, jsval *vp) +{ + switch(id) + { + case P_ERROR: + *vp = ToJS(cx, p->GetError()); + break; + case P_INPUT_STREAM: + { + wxInputStream *stream = p->GetInputStream(); + *vp = InputStream::CreateObject(cx, new Stream(stream), NULL); + break; + } + } + return true; +} + +WXJS_BEGIN_METHOD_MAP(URL) + WXJS_METHOD("setProxy", setProxy, 1) +WXJS_END_METHOD_MAP() + +/*** + * + * + * + * + * + * Sets the proxy to use for this URL. + * + * + */ +JSBool URL::setProxy(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxURL *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + wxString proxy; + FromJS(cx, argv[0], proxy); + p->SetProxy(proxy); + return JS_TRUE; +} + +WXJS_BEGIN_STATIC_METHOD_MAP(URL) + WXJS_METHOD("setDefaultProxy", setDefaultProxy, 1) +WXJS_END_METHOD_MAP() + +/*** + * + * + * + * + * + * Sets the default proxy server to use to get the URL. + * The string specifies the proxy like this: <hostname>:<port number>. + * + * + */ +JSBool URL::setDefaultProxy(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxString proxy; + FromJS(cx, argv[0], proxy); + wxURL::SetDefaultProxy(proxy); + return JS_TRUE; +} Property changes on: ps/trunk/source/tools/atlas/wxJS/io/url.cpp ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/io/io_main.cpp =================================================================== --- ps/trunk/source/tools/atlas/wxJS/io/io_main.cpp (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/io/io_main.cpp (revision 5154) @@ -0,0 +1,88 @@ +#include "precompiled.h" + +/* + * wxJavaScript - main.cpp + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: main.cpp 598 2007-03-07 20:13:28Z fbraem $ + */ +// main.cpp +#ifdef __WXMSW__ + #include + #include +#endif +#include + +#include "../common/main.h" +#include "../common/wxjs.h" +#include "init.h" + +using namespace wxjs; +using namespace wxjs::io; + +// A wxApp is needed by wxSocketBase +class wxJSIOApp : public wxAppConsole +{ + virtual int OnRun() { return 0; } +}; + +IMPLEMENT_APP_NO_MAIN(wxJSIOApp) + +#ifdef __WXMSW__ + BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) + { + BOOL result = TRUE; + + switch(fdwReason) + { + case DLL_PROCESS_ATTACH: + { + wxSetInstance(hinstDLL); + wxAppConsole *app = new wxJSIOApp(); + int app_argc = 0; + char **app_argv = NULL; + wxEntryStart(app_argc, app_argv); + DisableThreadLibraryCalls(hinstDLL); + break; + } + case DLL_PROCESS_DETACH: + wxEntryCleanup(); + break; + } + + return result; + } +#endif + +WXJSAPI bool wxJS_InitClass(JSContext *cx, JSObject *global) +{ + return InitClass(cx, global); +} + +WXJSAPI bool wxJS_InitObject(JSContext *cx, JSObject *global) +{ + return InitObject(cx, global); +} + +WXJSAPI void wxJS_Destroy() +{ + Destroy(); +} Property changes on: ps/trunk/source/tools/atlas/wxJS/io/io_main.cpp ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/io/http.cpp =================================================================== --- ps/trunk/source/tools/atlas/wxJS/io/http.cpp (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/io/http.cpp (revision 5154) @@ -0,0 +1,99 @@ +#include "precompiled.h" + +/* + * wxJavaScript - http.cpp + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: http.cpp 598 2007-03-07 20:13:28Z fbraem $ + */ +#include +#ifndef WX_PRECOMP + #include +#endif + +#include "../common/main.h" +#include "constant.h" +#include "jsstream.h" +#include "sockbase.h" +#include "http.h" +#include "httphdr.h" +#include "sockaddr.h" + +using namespace wxjs; +using namespace wxjs::io; + +/*** + * http + * io + * + * Implements the HTTP protocol. + * + */ +WXJS_INIT_CLASS(HTTP, "wxHTTP", 0) + +/*** + * + * + * + * Creates a new wxHTTP object + * + * + */ +SocketBasePrivate *HTTP::Construct(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, bool constructing) +{ + return new SocketBasePrivate(new wxHTTP()); +} + +void HTTP::Destruct(JSContext *cx, SocketBasePrivate *p) +{ + p->DestroyStreams(cx); + delete p; +} + +/*** + * + * + * Contains the headers. Access the elements of the array with String keys. + * + * + * Returns the HTTP response code returned by the server. + * + * + */ +WXJS_BEGIN_PROPERTY_MAP(HTTP) + WXJS_READONLY_PROPERTY(P_RESPONSE, "response") + WXJS_READONLY_PROPERTY(P_HEADERS, "headers") +WXJS_END_PROPERTY_MAP() + +bool HTTP::GetProperty(SocketBasePrivate *p, JSContext *cx, JSObject *obj, int id, jsval *vp) +{ + wxHTTP *http = dynamic_cast(p->GetBase()); + switch(id) + { + case P_RESPONSE: + *vp = ToJS(cx, http->GetResponse()); + break; + case P_HEADERS: + *vp = HTTPHeader::CreateObject(cx, new HTTPHeader(), obj); + break; + } + return true; +} Property changes on: ps/trunk/source/tools/atlas/wxJS/io/http.cpp ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/io/sistream.cpp =================================================================== --- ps/trunk/source/tools/atlas/wxJS/io/sistream.cpp (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/io/sistream.cpp (revision 5154) @@ -0,0 +1,85 @@ +#include "precompiled.h" + +/* + * wxJavaScript - sistream.cpp + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: sistream.cpp 598 2007-03-07 20:13:28Z fbraem $ + */ +#include +#ifndef WX_PRECOMP + #include +#endif + +#include "../common/main.h" +#include "stream.h" +#include "sockbase.h" +#include "sistream.h" + +using namespace wxjs; +using namespace wxjs::io; + +/*** + * sistream + * io + * + * This class implements an input stream which reads data from a connected socket. + * Note that this stream is purely sequential and it does not support seeking. + * + */ +WXJS_INIT_CLASS(SocketInputStream, "wxSocketInputStream", 1) + +/*** + * + * + * A socket + * + * + * Constructs a new wxSocketInputStream object. + * + * + */ +Stream* SocketInputStream::Construct(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, bool constructing) +{ + if ( SocketBase::HasPrototype(cx, argv[0]) ) + { + SocketBasePrivate *p = SocketBase::GetPrivate(cx, argv[0], false); + wxSocketBase *base = p->GetBase(); + // This is needed, because otherwise the socket can be garbage collected. + // Another method could be to root socket, but how are we going to unroot it? + JS_DefineProperty(cx, obj, "__socket__", argv[0], NULL, NULL, JSPROP_READONLY); + + return new Stream(new wxSocketInputStream(*base)); + } + return NULL; +} + +void SocketInputStream::Destruct(JSContext *cx, Stream *p) +{ + if ( p->IsOwner() ) + { + delete p; + } + else + { + p->SetObject(NULL); + } +} Property changes on: ps/trunk/source/tools/atlas/wxJS/io/sistream.cpp ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/io/sostream.cpp =================================================================== --- ps/trunk/source/tools/atlas/wxJS/io/sostream.cpp (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/io/sostream.cpp (revision 5154) @@ -0,0 +1,72 @@ +#include "precompiled.h" + +/* + * wxJavaScript - sostream.cpp + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: sostream.cpp 598 2007-03-07 20:13:28Z fbraem $ + */ +#include +#ifndef WX_PRECOMP + #include +#endif + +#include "../common/main.h" +#include "stream.h" +#include "sockbase.h" +#include "sostream.h" + +using namespace wxjs; +using namespace wxjs::io; + +/*** + * sostream + * io + * + * This class implements an output stream which writes data from a connected socket. + * Note that this stream is purely sequential and it does not support seeking. + * + */ +WXJS_INIT_CLASS(SocketOutputStream, "wxSocketOutputStream", 1) + +/*** + * + * + * A socket + * + * + * Constructs a new wxSocketOutputStream object. + * + * + */ +Stream* SocketOutputStream::Construct(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, bool constructing) +{ + if ( SocketBase::HasPrototype(cx, argv[0]) ) + { + SocketBasePrivate *base = SocketBase::GetPrivate(cx, argv[0], false); + // This is needed, because otherwise the socket can be garbage collected. + // Another method could be to root socket, but how are we going to unroot it? + JS_DefineProperty(cx, obj, "__socket__", argv[0], NULL, NULL, JSPROP_READONLY); + + return new Stream(new wxSocketOutputStream(*base->GetBase())); + } + return NULL; +} Property changes on: ps/trunk/source/tools/atlas/wxJS/io/sostream.cpp ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/io/textline.h =================================================================== --- ps/trunk/source/tools/atlas/wxJS/io/textline.h (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/io/textline.h (revision 5154) @@ -0,0 +1,57 @@ +/* + * wxJavaScript - textline.h + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: textline.h 598 2007-03-07 20:13:28Z fbraem $ + */ +#ifndef _wxjs_io_textline_h +#define _wxjs_io_textline_h + +// Helper class for text lines +namespace wxjs +{ + namespace io + { + class TextLine : public ApiWrapper + { + public: + + static bool GetProperty(Index *p, JSContext *cx, JSObject *obj, int id, jsval *vp); + static bool SetProperty(Index *p, JSContext *cx, JSObject *obj, int id, jsval *vp); + + static bool Enumerate(Index *p, JSContext *cx, JSObject *obj, JSIterateOp enum_op, jsval *statep, jsid *idp); + static bool Resolve(JSContext *cx, JSObject *obj, jsval id); + + WXJS_DECLARE_PROPERTY_MAP() + WXJS_DECLARE_METHOD_MAP() + + enum + { + P_LINE_TYPE = WXJS_START_PROPERTY_ID + , P_CONTENT + }; + + static JSBool removeLine(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval); + static JSBool insertLine(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval); + }; + }; // namespace io +}; // namespace wxjs +#endif // _wxjs_io_textline_h Property changes on: ps/trunk/source/tools/atlas/wxJS/io/textline.h ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/io/bistream.cpp =================================================================== --- ps/trunk/source/tools/atlas/wxJS/io/bistream.cpp (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/io/bistream.cpp (revision 5154) @@ -0,0 +1,103 @@ +#include "precompiled.h" + +/* + * wxJavaScript - bistream.cpp + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: bistream.cpp 715 2007-05-18 20:38:04Z fbraem $ + */ +#include +#ifndef WX_PRECOMP + #include +#endif + +#include "../common/main.h" + +#include "stream.h" +#include "istream.h" +#include "bistream.h" + +using namespace wxjs; +using namespace wxjs::io; + +/*** + * bistream + * io + * + * An inputstream that caches the input. + * + */ +BufferedInputStream::BufferedInputStream(wxInputStream &s + , wxStreamBuffer *buffer) + : wxBufferedInputStream(s, buffer) +{ +} + +WXJS_INIT_CLASS(BufferedInputStream, "wxBufferedInputStream", 1) + +/*** + * + * + * + * + * + * Creates a new wxBufferedInputStream object. + * + * + */ +Stream* BufferedInputStream::Construct(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, bool constructing) +{ + if ( argc == 0 + || argc > 2 ) + return NULL; + + Stream *in = InputStream::GetPrivate(cx, argv[0]); + if ( in == NULL ) + return NULL; + + // This is needed, because otherwise the stream can be garbage collected. + // Another method could be to root the stream, but how are we going to unroot it? + JS_DefineProperty(cx, obj, "__stream__", argv[0], NULL, NULL, JSPROP_READONLY); + + wxStreamBuffer *buffer = NULL; + + BufferedInputStream *stream = new BufferedInputStream(*((wxInputStream*) in->GetStream()), buffer); + stream->SetClientObject(new JavaScriptClientData(cx, obj, false, true)); + + stream->m_refStream = *in; + + return new Stream(stream); +} + +void BufferedInputStream::Destruct(JSContext *cx, Stream *p) +{ + if ( p != NULL ) + { + BufferedInputStream *stream = (BufferedInputStream*) p->GetStream(); + + // Keep stream alive for a moment, so that the base class wxBufferedOutputStream + // doesn't crash when it flushes the stream. + Stream tempRefStream(stream->m_refStream); + + delete p; + p = NULL; + } +} Property changes on: ps/trunk/source/tools/atlas/wxJS/io/bistream.cpp ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/io/textfile.cpp =================================================================== --- ps/trunk/source/tools/atlas/wxJS/io/textfile.cpp (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/io/textfile.cpp (revision 5154) @@ -0,0 +1,615 @@ +#include "precompiled.h" + +/* + * wxJavaScript - textfile.cpp + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: textfile.cpp 598 2007-03-07 20:13:28Z fbraem $ + */ +#include +#ifndef WX_PRECOMP + #include +#endif + +#include "../common/main.h" +#include "../common/index.h" +#include "../ext/wxjs_ext.h" +#include "textfile.h" +#include "textline.h" + +using namespace wxjs; +using namespace wxjs::io; + +/*** + * textfile + * io + * + * The wxTextFile is a simple class which allows to work with text files on line by line basis. + * It also understands the differences in line termination characters under different platforms + * and will not do anything bad to files with "non native" line termination sequences - in fact, + * it can be also used to modify the text files and change the line termination characters from + * one type (say DOS) to another (say Unix). + *

+ * One word of warning: the class is not at all optimized for big files and thus it will load the + * file entirely into memory when opened. Of course, you should not work in this way with large files + * (as an estimation, anything over 1 Megabyte is surely too big for this class). On the other hand, + * it is not a serious limitation for small files like configuration files or program sources which + * are well handled by wxTextFile. + *

+ * The typical things you may do with wxTextFile in order are: + *
    + *
  • + * Create and open it: this is done with either @wxTextFile#create or @wxTextFile#open function + * which opens the file (name may be specified either as the argument to these functions or in + * the constructor), reads its contents in memory (in the case of open) and closes it. + *
  • + *
  • + * Work with the lines in the file: this may be done either with "direct access" properties + * like @wxTextFile#lines or with "sequential access" properties which include + * @wxTextFile#firstLine/@wxTextFile#nextLine and also @wxTextFile#lastLine/@wxTextFile#prevLine. + * For the sequential access properties the current line number is maintained: @wxTextFile#currentLine + * and may be changed with @wxTextFile#goToLine. + *
  • + *
  • + * Add/remove lines to the file: @wxTextFile#addLine and @wxTextFile#insertLine add new lines while + * @wxTextFile#removeLine deletes the existing ones. @wxTextFile#clear resets the file to empty. + *
  • + *
  • + * Save your changes: notice that the changes you make to the file will not be saved automatically; + * calling @wxTextFile#close or doing nothing discards them! To save the changes you must explicitly + * call @wxTextFile#write - here, you may also change the line termination type if you wish + *
  • + *
+ * Remark :wxJS adds the @wxTextLine class. In wxWidgets, lines can be changed because + * most methods return a reference. This is not possible in JavaScript, but this can be solved by + * returning an object: @wxTextLine. This class can be used to access the lines like they were + * an array and you can change them directly: + *

+ *   var file = new wxTextFile("text.txt");
+ *   file.line[0] = "This is the first line";
+ *  
+ *
+ */ +WXJS_INIT_CLASS(TextFile, "wxTextFile", 0) + +/*** + * + * + * + * + * + * + * + * + */ + +void TextFile::InitClass(JSContext *cx, JSObject *obj, JSObject *proto) +{ + JSConstDoubleSpec wxTextFileType[] = + { + WXJS_CONSTANT(wxTextFileType_, None) + WXJS_CONSTANT(wxTextFileType_, Unix) + WXJS_CONSTANT(wxTextFileType_, Dos) + WXJS_CONSTANT(wxTextFileType_, Mac) + { 0 } + }; + + JSObject *constObj = JS_DefineObject(cx, obj, "wxTextFileType", + NULL, NULL, + JSPROP_READONLY | JSPROP_PERMANENT); + JS_DefineConstDoubles(cx, constObj, wxTextFileType); +} + +/*** + * + * + * + * The filename + * + * + * Constructs a new wxTextFile object. The file is not loaded + * into memory. Use @wxTextFile#open to do it. + * + * + */ +wxTextFile *TextFile::Construct(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, bool constructing) +{ + wxString fileName; + + switch(argc) + { + case 1: + { + FromJS(cx, argv[0], fileName); + wxTextFile *file = new wxTextFile(fileName); + return file; + } + case 0: + return new wxTextFile(); + } + return NULL; +} + +/*** + * + * + * Returns the current line: it has meaning only when you're using + * @wxTextFile#firstLine/@wxTextFile#nextLine properties, it doesn't get updated when you're + * using "direct access" property @wxTextFile#lines. @wxTextFile#firstLine and @wxTextFile#lastLine + * also change the value of the current line, as well as @wxTextFile#goToLine. + * + * + * Returns true when end of file is reached. + * When the file is not open, undefined is returned. + * + * + * Get the first line. + * + * + * Guess the type of file (which is supposed to be opened). If sufficiently many lines of the file + * are in DOS/Unix/Mac format, the corresponding value will be returned. If the detection mechanism fails wxTextFileType_None is returned + * + * + * Is the file open? + * + * + * Get the last line + * + * + * Number of lines in the file. + * + * + * Get an array of lines + * + * + * Get the nextline + * + * + * Get the previous line + * + * + */ +WXJS_BEGIN_PROPERTY_MAP(TextFile) + WXJS_READONLY_PROPERTY(P_CURRENT_LINE, "currentLine") + WXJS_READONLY_PROPERTY(P_EOF, "eof") + WXJS_READONLY_PROPERTY(P_FIRST_LINE, "firstLine") + WXJS_READONLY_PROPERTY(P_LAST_LINE, "lastLine") + WXJS_READONLY_PROPERTY(P_NEXT_LINE, "nextLine") + WXJS_READONLY_PROPERTY(P_PREV_LINE, "prevLine") + WXJS_READONLY_PROPERTY(P_OPENED, "opened") + WXJS_READONLY_PROPERTY(P_LINE_COUNT, "lineCount") + WXJS_READONLY_PROPERTY(P_NAME, "name") + WXJS_READONLY_PROPERTY(P_GUESS_TYPE, "guessType") + WXJS_READONLY_PROPERTY(P_LINES, "lines") +WXJS_END_PROPERTY_MAP() + +bool TextFile::GetProperty(wxTextFile *p, JSContext *cx, JSObject *obj, int id, jsval *vp) +{ + switch(id) + { + case P_EOF: + *vp = p->IsOpened() ? ToJS(cx, p->Eof()) : JSVAL_VOID; + break; + case P_OPENED: + *vp = ToJS(cx, p->IsOpened()); + break; + case P_LINE_COUNT: + *vp = ToJS(cx, p->GetLineCount()); + break; + case P_CURRENT_LINE: + *vp = ToJS(cx, p->GetCurrentLine()); + break; + case P_FIRST_LINE: + p->GetFirstLine(); + *vp = TextLine::CreateObject(cx, new Index(0), obj); + break; + case P_NEXT_LINE: + if ( ! p->Eof() ) + { + p->GetNextLine(); + *vp = TextLine::CreateObject(cx, new Index(p->GetCurrentLine()), obj); + } + else + { + *vp = JSVAL_VOID; + } + break; + case P_PREV_LINE: + if ( p->GetCurrentLine() == 0 ) + { + *vp = JSVAL_VOID; + } + else + { + p->GetPrevLine(); + *vp = TextLine::CreateObject(cx, new Index(p->GetCurrentLine()), obj); + } + break; + case P_LAST_LINE: + p->GetLastLine(); + *vp = TextLine::CreateObject(cx, new Index(p->GetCurrentLine()), obj); + break; + case P_GUESS_TYPE: + *vp = ToJS(cx, (int) p->GuessType()); + break; + case P_LINES: + *vp = TextLine::CreateObject(cx, new Index(0), obj); + break; + case P_NAME: + *vp = ToJS(cx, wxString(p->GetName())); + break; + } + return true; +} + +WXJS_BEGIN_METHOD_MAP(TextFile) + WXJS_METHOD("addLine", addLine, 1) + WXJS_METHOD("close", close, 0) + WXJS_METHOD("clear", clear, 0) + WXJS_METHOD("create", create, 1) + WXJS_METHOD("exists", exists, 0) + WXJS_METHOD("gotoLine", gotoLine, 1) + WXJS_METHOD("open", open, 2) + WXJS_METHOD("insertLine", insertLine, 2) + WXJS_METHOD("removeLine", removeLine, 1) + WXJS_METHOD("write", write, 2) +WXJS_END_METHOD_MAP() + +/*** + * + * + * + * The line to add + * + * + * + * + * Adds a line to the end of file. When Type is omitted + * the native default is used. + * + * + */ +JSBool TextFile::addLine(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxTextFile *p = GetPrivate(cx, obj); + wxASSERT_MSG(p != NULL, wxT("No private data associated with wxTextFile")); + + wxString line; + FromJS(cx, argv[0], line); + + if ( argc == 1 ) + { + p->AddLine(line); + return JS_TRUE; + } + else + { + int type; + if ( FromJS(cx, argv[1], type) ) + { + p->AddLine(line, (wxTextFileType) type); + return JS_TRUE; + } + } + + return JS_FALSE; +} + +/*** + * + * + * + * Removes all lines + * + * + */ +JSBool TextFile::clear(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxTextFile *p = GetPrivate(cx, obj); + wxASSERT_MSG(p != NULL, wxT("No private data associated with wxTextFile")); + + p->Clear(); + + return JS_TRUE; +} + +/*** + * + * + * + * Closes the file and frees memory, losing all changes. Use @wxTextFile#write if you want to save them. + * + * + */ +JSBool TextFile::close(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxTextFile *p = GetPrivate(cx, obj); + wxASSERT_MSG(p != NULL, wxT("No private data associated with wxFile")); + + *rval = ToJS(cx, p->Close()); + + return JS_TRUE; +} + +/*** + * + * + * + * The name of the file to create. + * + * + * Creates the file with the given name or the name which was given in the constructor. + * The array of file lines is initially empty. + * It will fail if the file already exists, @wxTextFile#open should be used in this case. + * + * + */ +JSBool TextFile::create(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxTextFile *p = GetPrivate(cx, obj); + wxASSERT_MSG(p != NULL, wxT("No private data associated with wxTextFile")); + + if ( argc != 0 ) + { + wxString fileName; + FromJS(cx, argv[0], fileName); + *rval = ToJS(cx, p->Create(fileName)); + return JS_TRUE; + } + + *rval = ToJS(cx, p->Create()); + return JS_TRUE; +} + +/*** + * + * + * + * Return true if file exists - the name of the file should have been specified in the + * constructor before calling exists(). + * + * + */ +JSBool TextFile::exists(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxTextFile *p = GetPrivate(cx, obj); + wxASSERT_MSG(p != NULL, wxT("No private data associated with wxTextFile")); + + *rval = ToJS(cx, p->Exists()); + + return JS_TRUE; +} + +/*** + * + * + * + * + * + * Changes the value returned by @wxTextFile#currentLine. + * + * + */ +JSBool TextFile::gotoLine(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxTextFile *p = GetPrivate(cx, obj); + wxASSERT_MSG(p != NULL, wxT("No private data associated with wxTextFile")); + + int line; + if ( FromJS(cx, argv[0], line) ) + { + p->GoToLine(line); + return JS_TRUE; + } + + return JS_FALSE; +} + +/*** + * + * + * The line to insert (without the end-of-line character(s)). + * The line position + * + * + * + * Insert a line before the line number Pos. + * + * + */ +JSBool TextFile::insertLine(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxTextFile *p = GetPrivate(cx, obj); + wxASSERT_MSG(p != NULL, wxT("No private data associated with wxTextFile")); + + wxString line; + int pos; + + FromJS(cx, argv[0], line); + if ( ! FromJS(cx, argv[1], pos) ) + return JS_FALSE; + + if ( argc > 2 ) + { + int type; + if ( ! FromJS(cx, argv[2], type) ) + return JS_FALSE; + p->InsertLine(line, pos, (wxTextFileType) type); + } + else + { + p->InsertLine(line, pos); + } + return JS_TRUE; +} + +/*** + * + * + * + * + * The name of the file to open + * + * + * Opens the file with the given name or the name which was given in the constructor + * and also loads file in memory on success. It will fail if the file does not exist, + * @wxTextFile#create should be used in this case. When no encoding is specified + * the file is opened in UTF-8. + * + * + */ +JSBool TextFile::open(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxTextFile *p = GetPrivate(cx, obj); + wxASSERT_MSG(p != NULL, wxT("No private data associated with wxTextFile")); + + if ( p->IsOpened() ) + return JS_TRUE; + + if ( argc == 0 ) + { + *rval = ToJS(cx, p->Open()); + return JS_TRUE; + } + + wxString encoding(wxJS_EXTERNAL_ENCODING); + FromJS(cx, argv[0], encoding); + wxCSConv conv(encoding); + + bool ok = false; + if ( argc > 1 ) + { + wxString fileName; + FromJS(cx, argv[1], fileName); + ok = p->Open(fileName, conv); + } + else + { + ok = p->Open(conv); + } + + if ( ok ) + { + // Convert all lines, because internally we want another encoding + if ( ! encoding.IsSameAs(wxJS_INTERNAL_ENCODING, false) ) + { + wxCSConv internalConv(wxJS_INTERNAL_ENCODING); + for (wxString str = p->GetFirstLine(); !p->Eof(); str = p->GetNextLine() ) + { + str = wxString(str.mb_str(conv), internalConv); + } + p->GoToLine(0); + } + } + + *rval = ToJS(cx, ok); + + return JS_TRUE; +} + +/*** + * + * + * The line to remove. + * + * + * Removes the line from the file + * + * + */ +JSBool TextFile::removeLine(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxTextFile *p = GetPrivate(cx, obj); + wxASSERT_MSG(p != NULL, wxT("No private data associated with wxFile")); + + int line; + if ( ! FromJS(cx, argv[0], line) ) + { + return JS_FALSE; + } + + p->RemoveLine(line); + return JS_TRUE; +} + +/*** + * + * + * + * + * + * + * Change the file on disk. The Type parameter allows you to change the file format + * (default argument means "don't change type") and may be used to convert, for example, + * DOS files to Unix. + * + * + */ +JSBool TextFile::write(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxTextFile *p = GetPrivate(cx, obj); + wxASSERT_MSG(p != NULL, wxT("No private data associated with wxTextFile")); + + int type = wxTextFileType_None; + if ( argc > 0 ) + { + if ( ! FromJS(cx, argv[0], type) ) + return JS_FALSE; + } + wxString encoding(wxJS_EXTERNAL_ENCODING); + if ( argc > 1 ) + { + FromJS(cx, argv[1], encoding); + } + wxCSConv conv(encoding); + *rval = ToJS(cx, p->Write((wxTextFileType) type, conv)); + + return JS_TRUE; +} + +WXJS_BEGIN_STATIC_METHOD_MAP(TextFile) + WXJS_METHOD("getEOL", getEOL, 1) +WXJS_END_METHOD_MAP() + +/*** + * + * + * + * + * + * Get the line termination string corresponding to given constant. + * typeDefault is the value defined during the compilation and corresponds to the + * native format of the platform, i.e. it will be wxTextFileType.Dos under Windows, + * wxTextFileType.Unix under Unix (including Mac OS X when compiling with the Apple + * Developer Tools) and wxTextFileType.Mac under Mac OS + * (including Mac OS X when compiling with CodeWarrior). + * + * + */ +JSBool TextFile::getEOL(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + int type; + if ( ! FromJS(cx, argv[0], type) ) + return JS_FALSE; + + *rval = ToJS(cx, wxString(wxTextFile::GetEOL((wxTextFileType) type))); + return JS_TRUE; +} Property changes on: ps/trunk/source/tools/atlas/wxJS/io/textfile.cpp ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/io/sistream.h =================================================================== --- ps/trunk/source/tools/atlas/wxJS/io/sistream.h (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/io/sistream.h (revision 5154) @@ -0,0 +1,47 @@ +/* + * wxJavaScript - sistream.h + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: sistream.h 598 2007-03-07 20:13:28Z fbraem $ + */ +#ifndef _wxjs_io_sistream_h +#define _wxjs_io_sistream_h + +#include + +namespace wxjs +{ + namespace io + { + class SocketInputStream : public wxSocketInputStream, + public ApiWrapper + { + public: + #ifdef __MINGW32__ + // MingW needs a default constructor + SocketInputStream() {} + #endif + static Stream* Construct(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, bool constructing); + static void Destruct(JSContext *cx, Stream *p); + }; + }; // namespace io +}; // namespace wxjs +#endif // _wxjs_io_sistream_h Property changes on: ps/trunk/source/tools/atlas/wxJS/io/sistream.h ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/io/sostream.h =================================================================== --- ps/trunk/source/tools/atlas/wxJS/io/sostream.h (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/io/sostream.h (revision 5154) @@ -0,0 +1,41 @@ +/* + * wxJavaScript - sostream.h + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: sostream.h 598 2007-03-07 20:13:28Z fbraem $ + */ +#ifndef _wxjs_io_sostream_h +#define _wxjs_io_sostream_h + +#include + +namespace wxjs +{ + namespace io + { + class SocketOutputStream : public ApiWrapper + { + public: + static Stream* Construct(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, bool constructing); + }; + }; // namespace io +}; // namespace wxjs +#endif // _wxjs_io_sostream_h Property changes on: ps/trunk/source/tools/atlas/wxJS/io/sostream.h ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/io/tempfile.cpp =================================================================== --- ps/trunk/source/tools/atlas/wxJS/io/tempfile.cpp (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/io/tempfile.cpp (revision 5154) @@ -0,0 +1,302 @@ +#include "precompiled.h" + +/* + * wxJavaScript - tempfile.cpp + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: tempfile.cpp 598 2007-03-07 20:13:28Z fbraem $ + */ +#include +#ifndef WX_PRECOMP + #include +#endif + +#include "../common/main.h" +#include "../ext/wxjs_ext.h" +#include "tempfile.h" + +using namespace wxjs; +using namespace wxjs::io; + +/*** + * tempfile + * io + * + * wxTempFile provides a relatively safe way to replace the contents of the existing file. + * The name is explained by the fact that it may be also used as just a temporary file if + * you don't replace the old file contents. + *

+ * Usually, when a program replaces the contents of some file it first opens it for writing, + * thus losing all of the old data and then starts recreating it. This approach is not very safe + * because during the regeneration of the file bad things may happen: the program may find that + * there is an internal error preventing it from completing file generation, the user may interrupt + * it (especially if file generation takes long time) and, finally, any other external interrupts + * (power supply failure or a disk error) will leave you without either the original file or the new one. + *

+ * wxTempFile addresses this problem by creating a temporary file which is meant to replace the original file + * - but only after it is fully written. So, if the user interrupts the program during the file generation, + * the old file won't be lost. Also, if the program discovers itself that it doesn't want to replace the + * old file there is no problem - in fact, wxTempFile will not replace the old file by default, you should + * explicitly call @wxTempFile#commit to do it. Calling @wxTempFile#discard explicitly discards any modifications: + * it closes and deletes the temporary file and leaves the original file unchanged. If you don't call + * neither of @wxTempFile#commit and @wxTempFile#discard, the destructor will call @wxTempFile#discard + * automatically. + *

+ * To summarize: if you want to replace another file, create an instance of wxTempFile passing + * the name of the file to be replaced to the constructor (you may also use default constructor + * and pass the file name to @wxTempFile#open). Then you can write to wxTempFile using wxFile-like + * functions and later call @wxTempFile#commit to replace the old file (and close this one) + * or call @wxTempFile#discard to cancel the modifications. + *
+ */ +WXJS_INIT_CLASS(TempFile, "wxTempFile", 0) + +/*** + * + * + * Returns true when the file is open. + * + * + * Returns the length of the file. + * When the file is not open, undefined is returned. + * + * + * Returns the current position or -1. + * When the file is not open, undefined is returned. + * + * + */ +WXJS_BEGIN_PROPERTY_MAP(TempFile) + WXJS_READONLY_PROPERTY(P_OPENED, "opened") + WXJS_READONLY_PROPERTY(P_LENGTH, "length") + WXJS_READONLY_PROPERTY(P_TELL, "tell") +WXJS_END_PROPERTY_MAP() + +bool TempFile::GetProperty(wxTempFile *p, JSContext *cx, JSObject *obj, int id, jsval *vp) +{ + switch(id) + { + case P_OPENED: + *vp = ToJS(cx, p->IsOpened()); + break; + case P_LENGTH: + *vp = p->IsOpened() ? ToJS(cx, (long) p->Length()) : JSVAL_VOID; + break; + case P_TELL: + *vp = p->IsOpened() ? ToJS(cx, (long) p->Tell()) : JSVAL_VOID; + break; + } + return true; +} + +/*** + * + * + * + * The filename + * + * + * Constructs a new wxTempFile object. When a filename is passed, + * The file is opened, and you can check whether the operation +* was successful or not by checking @wxTempFile#opened. + * + * + */ +wxTempFile *TempFile::Construct(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, bool constructing) +{ + wxString fileName; + + switch(argc) + { + case 1: + FromJS(cx, argv[0], fileName); + return new wxTempFile(fileName); + break; + case 0: + return new wxTempFile(); + break; + } + return NULL; +} + +WXJS_BEGIN_METHOD_MAP(TempFile) + WXJS_METHOD("open", open, 2) + WXJS_METHOD("seek", seek, 2) + WXJS_METHOD("write", write, 1) + WXJS_METHOD("commit", commit, 0) + WXJS_METHOD("discard", discard, 0) +WXJS_END_METHOD_MAP() + +/*** + * + * + * + * Validate changes: deletes the old file and renames the new file to the old name. + * Returns true if both actions succeeded. If false is returned it may unfortunately + * mean two quite different things: either that either the old file couldn't be deleted or + * that the new file couldn't be renamed to the old name. + * + * + */ +JSBool TempFile::commit(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxTempFile *p = GetPrivate(cx, obj); + wxASSERT_MSG(p != NULL, wxT("No private data associated with wxTempFile")); + + *rval = ToJS(cx, p->Commit()); + return JS_TRUE; +} + +/*** + * + * + * + * Discard changes: the old file contents is not changed, temporary file is deleted. + * + * + */ +JSBool TempFile::discard(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxTempFile *p = GetPrivate(cx, obj); + wxASSERT_MSG(p != NULL, wxT("No private data associated with wxTempFile")); + + p->Discard(); + + return JS_TRUE; +} + +/*** + * + * + * The name of the file + * + * + * Open the temporary file, returns true on success, false if an error occurred. + * FileName is the name of file to be replaced. The temporary file is always created + * in the directory where FileName is. In particular, if FileName doesn't include + * the path, it is created in the current directory and the program should have write access + * to it for the function to succeed. + * + * + */ +JSBool TempFile::open(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxTempFile *p = GetPrivate(cx, obj); + wxASSERT_MSG(p != NULL, wxT("No private data associated with wxTempFile")); + + wxString fileName; + FromJS(cx, argv[0], fileName); + + *rval = ToJS(cx, p->Open(fileName)); + + return JS_TRUE; +} + +/*** + * + * + * Offset to seek to. + * + * + * + * Seeks the offset. Returns the actual position or -1. + * See also @wxFile#seekEnd. + * + * + */ +JSBool TempFile::seek(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxTempFile *p = GetPrivate(cx, obj); + wxASSERT_MSG(p != NULL, wxT("No private data associated with wxTempFile")); + + if ( ! p->IsOpened() ) + { + return JS_FALSE; + } + + int offset; + if ( ! FromJS(cx, argv[0], offset) ) + { + return JS_FALSE; + } + + int pos; + + if ( argc > 1 ) + { + int mode; + if ( FromJS(cx, argv[1], mode) ) + { + pos = p->Seek(offset, (wxSeekMode) mode); + } + else + { + return JS_FALSE; + } + } + else + pos = p->Seek(offset); + + *rval = ToJS(cx, pos); + return JS_TRUE; +} + +/*** + * + * + * + * + * + * + * + * + * Writes the string or buffer to the file. + * Returns the actual number of bytes written to the file. + * + * + */ +JSBool TempFile::write(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxTempFile *p = GetPrivate(cx, obj); + wxASSERT_MSG(p != NULL, wxT("No private data associated with wxTempFile")); + + if ( ! p->IsOpened() ) + { + return JS_FALSE; + } + + if ( JSVAL_IS_OBJECT(argv[0]) ) + { + wxMemoryBuffer* buffer = wxjs::ext::GetMemoryBuffer(cx, JSVAL_TO_OBJECT(argv[0])); + if ( buffer != NULL ) + { + *rval = ToJS(cx, p->Write(buffer->GetData(), buffer->GetDataLen())); + return JS_TRUE; + } + } + + wxString content; + FromJS(cx, argv[0], content); + int count = content.length(); + *rval = ToJS(cx, (int) p->Write(content.c_str(), count)); + + return JS_TRUE; +} Property changes on: ps/trunk/source/tools/atlas/wxJS/io/tempfile.cpp ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/io/costream.cpp =================================================================== --- ps/trunk/source/tools/atlas/wxJS/io/costream.cpp (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/io/costream.cpp (revision 5154) @@ -0,0 +1,70 @@ +#include "precompiled.h" + +/* + * wxJavaScript - costream.cpp + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: costream.cpp 598 2007-03-07 20:13:28Z fbraem $ + */ +// stream.cpp + +#include +#ifndef WX_PRECOMP + #include +#endif + +#include "../common/main.h" + +#include "stream.h" +#include "costream.h" + +using namespace wxjs; +using namespace wxjs::io; + +/*** + * costream + * io + * + * wxCountingOutputStream is a specialized output stream which does not write any data anyway, + * instead it counts how many bytes would get written if this were a normal stream. + * This can sometimes be useful or required if some data gets serialized to a stream or + * compressed by using stream compression and thus the final size of the stream cannot be + * known other than pretending to write the stream. One case where the resulting size would + * have to be known is if the data has to be written to a piece of memory and the memory has + * to be allocated before writing to it (which is probably always the case when writing to a + * memory stream). + * + */ + +WXJS_INIT_CLASS(CountingOutputStream, "wxCountingOutputStream", 0) + +/*** + * + * + * + * Creates a new wxCountingOutputStream object. + * + * + */ +Stream* CountingOutputStream::Construct(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, bool constructing) +{ + return new Stream(new wxCountingOutputStream()); +} Property changes on: ps/trunk/source/tools/atlas/wxJS/io/costream.cpp ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/io/dostream.h =================================================================== --- ps/trunk/source/tools/atlas/wxJS/io/dostream.h (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/io/dostream.h (revision 5154) @@ -0,0 +1,54 @@ +/* + * wxJavaScript - dostream.h + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: dostream.h 598 2007-03-07 20:13:28Z fbraem $ + */ +#ifndef _WXJSDataOutputStream_H +#define _WXJSDataOutputStream_H + +#include + +namespace wxjs +{ + namespace io + { + class DataOutputStream : public ApiWrapper + { + public: + + /** + * Callback for when a wxDataOutputStream object is created + */ + static wxDataOutputStream* Construct(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, bool constructing); + + WXJS_DECLARE_METHOD_MAP() + static JSBool bigEndianOrdered(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval); + static JSBool write64(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval); + static JSBool write32(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval); + static JSBool write16(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval); + static JSBool write8(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval); + static JSBool writeDouble(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval); + static JSBool writeString(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval); + }; + }; // namespace io +}; // namespace wxjs +#endif //_WXJSTextOutputStream_H Property changes on: ps/trunk/source/tools/atlas/wxJS/io/dostream.h ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/io/textfile.h =================================================================== --- ps/trunk/source/tools/atlas/wxJS/io/textfile.h (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/io/textfile.h (revision 5154) @@ -0,0 +1,88 @@ +/* + * wxJavaScript - textfile.h + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: textfile.h 598 2007-03-07 20:13:28Z fbraem $ + */ +#ifndef _WXJS_TEXTFILE_H +#define _WXJS_TEXTFILE_H + +///////////////////////////////////////////////////////////////////////////// +// Name: file.h +// Purpose: Ports wxFile to JavaScript +// Author: Franky Braem +// Modified by: +// Created: 30.08.02 +// Copyright: (c) 2001-2002 Franky Braem +// Licence: LGPL +///////////////////////////////////////////////////////////////////////////// + +#include + +namespace wxjs +{ + namespace io + { + class TextFile : public ApiWrapper + { + public: + + static bool GetProperty(wxTextFile *f, JSContext *cx, JSObject *obj, int id, jsval *vp); + + enum + { + P_CURRENT_LINE + , P_EOF + , P_OPENED + , P_LINE_COUNT + , P_FIRST_LINE + , P_NEXT_LINE + , P_GUESS_TYPE + , P_NAME + , P_LAST_LINE + , P_PREV_LINE + , P_LINES + }; + + WXJS_DECLARE_PROPERTY_MAP() + WXJS_DECLARE_METHOD_MAP() + WXJS_DECLARE_STATIC_METHOD_MAP() + + static void InitClass(JSContext *cx, JSObject *obj, JSObject *proto); + + static wxTextFile *Construct(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, bool constructing); + + static JSBool addLine(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval); + static JSBool clear(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval); + static JSBool close(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval); + static JSBool create(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval); + static JSBool exists(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval); + static JSBool open(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval); + static JSBool gotoLine(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval); + static JSBool removeLine(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval); + static JSBool insertLine(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval); + static JSBool write(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval); + + static JSBool getEOL(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval); + }; + }; // namespace io +}; // namespace wxjs +#endif // _WXJS_TEXTFILE Property changes on: ps/trunk/source/tools/atlas/wxJS/io/textfile.h ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/io/archentry.cpp =================================================================== --- ps/trunk/source/tools/atlas/wxJS/io/archentry.cpp (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/io/archentry.cpp (revision 5154) @@ -0,0 +1,171 @@ +#include "precompiled.h" + +/* + * wxJavaScript - archentry.cpp + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: archentry.cpp 598 2007-03-07 20:13:28Z fbraem $ + */ +#include +#ifndef WX_PRECOMP + #include +#endif + +#include "../common/main.h" +#include "archentry.h" + +using namespace wxjs; +using namespace wxjs::io; + +/*** + * archentry + * io + * + * A prototype class used for entries in an archive. + * + */ + +WXJS_INIT_CLASS(ArchiveEntry, "wxArchiveEntry", 0) + +/*** + * + * + * Get/Set the timestamp of the entryset + * + * + * Returns the path format used internally within the archive to store filenames. + * + * + * Returns the entry's filename in the internal format used within the archive. + * The name can include directory components, i.e. it can be a full path. + *

+ * The names of directory entries are returned without any trailing path separator. + * This gives a canonical name that can be used in comparisons. + *
+ * + * True if this is a directory entry. + *

+ * Directory entries are entries with no data, which are used to store the + * meta-data of directories. They also make it possible for completely empty + * directories to be stored. + *

+ * The names of entries within an archive can be complete paths, and unarchivers + * typically create whatever directories are necessary as they restore files, + * even if the archive contains no explicit directory entries. + *
+ * + * True if the entry is a read-only file. + * + * + * Returns a numeric value unique to the entry within the archive. + * + * + * Get/Set the size of the entry's data in bytes. + * + *
+ */ +WXJS_BEGIN_PROPERTY_MAP(ArchiveEntry) + WXJS_PROPERTY(P_DATE_TIME, "dateTime") + WXJS_READONLY_PROPERTY(P_INTERNAL_FMT, "internalFormat") + WXJS_READONLY_PROPERTY(P_INTERNAL_NAME, "internalName") + WXJS_PROPERTY(P_DIR, "dir") + WXJS_PROPERTY(P_READ_ONLY, "readOnly") + WXJS_PROPERTY(P_NAME, "name") + WXJS_READONLY_PROPERTY(P_OFFSET, "offset") + WXJS_PROPERTY(P_SIZE, "size") +WXJS_END_PROPERTY_MAP() + +bool ArchiveEntry::GetProperty(wxArchiveEntry *p, JSContext *cx, JSObject *obj, int id, jsval *vp) +{ + switch (id) + { + case P_DATE_TIME: + *vp = ToJS(cx, p->GetDateTime()); + break; + case P_INTERNAL_FMT: + *vp = ToJS(cx, p->GetInternalFormat()); + break; + case P_INTERNAL_NAME: + *vp = ToJS(cx, p->GetInternalName()); + break; + case P_DIR: + *vp = ToJS(cx, p->IsDir()); + break; + case P_READ_ONLY: + *vp = ToJS(cx, p->IsReadOnly()); + break; + case P_NAME: + *vp = ToJS(cx, p->GetName()); + break; + case P_OFFSET: + *vp = ToJS(cx, p->GetOffset()); + break; + case P_SIZE: + *vp = ToJS(cx, p->GetSize()); + break; + } + return true; +} + +bool ArchiveEntry::SetProperty(wxArchiveEntry *p, JSContext *cx, JSObject *obj, int id, jsval *vp) +{ + switch (id) + { + case P_DATE_TIME: + { + wxDateTime date; + if ( FromJS(cx, *vp, date) ) + p->SetDateTime(date); + } + break; + case P_DIR: + { + bool dir; + if ( FromJS(cx, *vp, dir) ) + p->SetIsDir(dir); + } + break; + case P_READ_ONLY: + { + bool readonly; + if ( FromJS(cx, *vp, readonly) ) + p->SetIsReadOnly(readonly); + } + break; + case P_NAME: + { + wxString name; + FromJS(cx, *vp, name); + p->SetName(name); + } + break; + case P_SIZE: + { + long size; + if ( FromJS(cx, *vp, size) ) + { + p->SetSize(size); + } + } + break; + } + return true; +} Property changes on: ps/trunk/source/tools/atlas/wxJS/io/archentry.cpp ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/io/sockclient.h =================================================================== --- ps/trunk/source/tools/atlas/wxJS/io/sockclient.h (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/io/sockclient.h (revision 5154) @@ -0,0 +1,59 @@ +/* + * wxJavaScript - sockclient.h + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: sockclient.h 716 2007-05-20 17:57:22Z fbraem $ + */ +#ifndef _wxjs_io_sockclient_h +#define _wxjs_io_sockclient_h + +#include +#include + +#include "sockbase.h" + +namespace wxjs +{ + namespace io + { + class SocketEventHandler; + + class SocketClient : public ApiWrapper + , public wxSocketClient + { + public: + SocketClient(JSContext *cx, JSObject *obj, wxSocketFlags flags = wxSOCKET_NONE); + virtual ~SocketClient(); + + static SocketBasePrivate *Construct(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, bool constructing); + static void Destruct(JSContext *cx, SocketBasePrivate *p); + + WXJS_DECLARE_METHOD_MAP() + + static JSBool connect(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval); + static JSBool waitOnConnect(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval); + + private: + SocketEventHandler *m_evtHandler; + }; + }; // namespace io +}; // namespace wxjs +#endif // _wxjs_io_sockclient_h Property changes on: ps/trunk/source/tools/atlas/wxJS/io/sockclient.h ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/io/ipaddr.h =================================================================== --- ps/trunk/source/tools/atlas/wxJS/io/ipaddr.h (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/io/ipaddr.h (revision 5154) @@ -0,0 +1,56 @@ +/* + * wxJavaScript - ipaddr.h + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: ipaddr.h 598 2007-03-07 20:13:28Z fbraem $ + */ +#ifndef _wxjs_io_ipaddr_h +#define _wxjs_io_ipaddr_h + +#include + +namespace wxjs +{ + namespace io + { + class IPaddress : public ApiWrapper + { + public: + static bool GetProperty(wxIPaddress *p, JSContext *cx, JSObject *obj, int id, jsval *vp); + static bool SetProperty(wxIPaddress *p, JSContext *cx, JSObject *obj, int id, jsval *vp); + + WXJS_DECLARE_PROPERTY_MAP() + WXJS_DECLARE_METHOD_MAP() + + static JSBool anyAddress(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval); + static JSBool localhost(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval); + + enum + { + P_HOSTNAME = WXJS_START_PROPERTY_ID + , P_LOCALHOST + , P_IPADDRESS + , P_SERVICE + }; + }; + }; // namespace io +}; // namespace wxjs +#endif // _wxjs_io_ipaddr_h Property changes on: ps/trunk/source/tools/atlas/wxJS/io/ipaddr.h ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/io/bostream.cpp =================================================================== --- ps/trunk/source/tools/atlas/wxJS/io/bostream.cpp (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/io/bostream.cpp (revision 5154) @@ -0,0 +1,104 @@ +#include "precompiled.h" + +/* + * wxJavaScript - bostream.cpp + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: bostream.cpp 715 2007-05-18 20:38:04Z fbraem $ + */ +#include +#ifndef WX_PRECOMP + #include +#endif + +#include "../common/main.h" +#include "stream.h" +#include "ostream.h" +#include "bostream.h" + +using namespace wxjs; +using namespace wxjs::io; + +/*** + * bostream + * io + * + * This stream acts as a cache. It caches the bytes to be written + * to the specified output stream. + * + */ +BufferedOutputStream::BufferedOutputStream(wxOutputStream &s + , wxStreamBuffer *buffer) + : wxBufferedOutputStream(s, buffer) +{ +} + +WXJS_INIT_CLASS(BufferedOutputStream, "wxBufferedOutputStream", 1) + +/*** + * + * + * + * + * + * Creates a new wxBufferedOutputStream object. + * + * + */ +Stream* BufferedOutputStream::Construct(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, bool constructing) +{ + if ( argc == 0 + || argc > 2 ) + return NULL; + + Stream *out = OutputStream::GetPrivate(cx, argv[0]); + if ( out == NULL ) + return NULL; + + // This is needed, because otherwise the stream can be garbage collected. + // Another method could be to root the stream, but how are we going to unroot it? + JS_DefineProperty(cx, obj, "__stream__", argv[0], NULL, NULL, JSPROP_READONLY); + + wxStreamBuffer *buffer = NULL; + + BufferedOutputStream *stream = new BufferedOutputStream(*((wxOutputStream*)(out->GetStream())), buffer); + stream->SetClientObject(new JavaScriptClientData(cx, obj, false, true)); + + stream->m_refStream = *out; + + return new Stream(stream); +} + +void BufferedOutputStream::Destruct(JSContext *cx, Stream *p) +{ + if ( p != NULL ) + { + BufferedOutputStream *stream = (BufferedOutputStream*) p->GetStream(); + + // Keep stream alive for a moment, so that the base class wxBufferedOutputStream + // doesn't crash when it flushes the stream. + Stream tempRefStream(stream->m_refStream); + + delete p; + p = NULL; + } +} + Property changes on: ps/trunk/source/tools/atlas/wxJS/io/bostream.cpp ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/io/fostream.cpp =================================================================== --- ps/trunk/source/tools/atlas/wxJS/io/fostream.cpp (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/io/fostream.cpp (revision 5154) @@ -0,0 +1,91 @@ +#include "precompiled.h" + +/* + * wxJavaScript - fostream.cpp + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: fostream.cpp 598 2007-03-07 20:13:28Z fbraem $ + */ +#include +#ifndef WX_PRECOMP + #include +#endif +#include "wx/wfstream.h" + +#include "../common/main.h" + +#include "file.h" +#include "stream.h" +#include "fostream.h" + +using namespace wxjs; +using namespace wxjs::io; + +/*** + * fostream + * io + * + * This class represents data written to a file. There are actually two such groups of classes: + * this one is based on @wxFile whereas @wxFFileOutputStream is based on the @wxFFile class. + * + */ +WXJS_INIT_CLASS(FileOutputStream, "wxFileOutputStream", 1) + +/*** + * + * + * The name of a file + * + * + * + * + * + * A file descriptor + * + * + * Constructs a new wxFileOutputStream object. A wxFileOutputStream is always opened in write-only mode. + * + * + */ +Stream* FileOutputStream::Construct(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, bool constructing) +{ + if ( File::HasPrototype(cx, argv[0]) ) + { + wxFile *file = File::GetPrivate(cx, argv[0], false); + // This is needed, because otherwise the file can be garbage collected. + // Another method could be to root file, but how are we going to unroot it? + JS_DefineProperty(cx, obj, "__file__", argv[0], NULL, NULL, JSPROP_READONLY); + return new Stream(new wxFileOutputStream(*file)); + } + else if ( JSVAL_IS_STRING(argv[0]) ) + { + wxString name; + FromJS(cx, argv[0], name); + return new Stream(new wxFileOutputStream(name)); + } + else if ( JSVAL_IS_INT(argv[0]) ) + { + int fd; + if ( FromJS(cx, argv[0], fd) ) + return new Stream(new wxFileOutputStream(fd)); + } + return NULL; +} Property changes on: ps/trunk/source/tools/atlas/wxJS/io/fostream.cpp ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/io/ffistream.h =================================================================== --- ps/trunk/source/tools/atlas/wxJS/io/ffistream.h (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/io/ffistream.h (revision 5154) @@ -0,0 +1,42 @@ +/* + * wxJavaScript - ffistream.h + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: ffistream.h 598 2007-03-07 20:13:28Z fbraem $ + */ +#ifndef _wxjs_io_ffistream_h +#define _wxjs_io_ffistream_h + +namespace wxjs +{ + namespace io + { + class FFileInputStream : public ApiWrapper + { + public: + /** + * Callback for when a wxFFileInputStream object is created + */ + static Stream* Construct(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, bool constructing); + }; + }; // namespace io +}; // namespace wxjs +#endif // _wxjs_io_ffistream_h Property changes on: ps/trunk/source/tools/atlas/wxJS/io/ffistream.h ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/io/sockbase.cpp =================================================================== --- ps/trunk/source/tools/atlas/wxJS/io/sockbase.cpp (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/io/sockbase.cpp (revision 5154) @@ -0,0 +1,816 @@ +#include "precompiled.h" + +/* + * wxJavaScript - sockbase.cpp + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: sockbase.cpp 598 2007-03-07 20:13:28Z fbraem $ + */ +// file.cpp +#include +#ifndef WX_PRECOMP + #include +#endif + +#include "../common/main.h" +#include "../ext/wxjs_ext.h" + +#include "sockbase.h" + +using namespace wxjs; +using namespace wxjs::io; + +/*** + * sockbase + * io + * + * wxSocketBase is the property class for all socket-related objects, + * and it defines all basic IO functionality. + * + */ +WXJS_INIT_CLASS(SocketBase, "wxSocketBase", 0) + +/*** + * + * + * No error happened. + * Invalid operation. + * Input/Output error. + * Invalid address. + * Invalid socket (uninitialized). + * No corresponding host. + * Invalid port. + * The socket is non-blocking and the operation would block. + * The timeout for this operation expired. + * Memory exhausted. + * + * wxSocketError is ported to JavaScript as a separate class. Note that this + * class doesn't exist in wxWidgets. + * + * + * + * There is data available for reading. + * The socket is ready to be written to. + * Incoming connection request (server), or successful connection establishment (client). + * The connection has been closed. + * + * wxSocketEventType is ported to JavaScript as a separate class. Note that this + * class doesn't exist in wxWidgets. + * + * + * + * Normal functionality. + * Read/write as much data as possible and return immediately. + * Wait for all required data to be read/written unless an error occurs. + * Block the GUI (do not yield) while reading/writing data. + * Allows the use of an in-use port (wxServerSocket only) + * + * wxSocketFlags is ported to JavaScript as a separate class. Note that this + * class doesn't exist in wxWidgets. + * + * + * + */ +void SocketBase::InitClass(JSContext *cx, JSObject *obj, JSObject *proto) +{ + JSConstDoubleSpec wxSocketErrorMap[] = + { + WXJS_CONSTANT(wxSOCKET_, NOERROR) + WXJS_CONSTANT(wxSOCKET_, INVOP) + WXJS_CONSTANT(wxSOCKET_, IOERR) + WXJS_CONSTANT(wxSOCKET_, INVADDR) + WXJS_CONSTANT(wxSOCKET_, INVSOCK) + WXJS_CONSTANT(wxSOCKET_, NOHOST) + WXJS_CONSTANT(wxSOCKET_, INVPORT) + WXJS_CONSTANT(wxSOCKET_, WOULDBLOCK) + WXJS_CONSTANT(wxSOCKET_, TIMEDOUT) + WXJS_CONSTANT(wxSOCKET_, MEMERR) + { 0 } + }; + + JSObject *constObj = JS_DefineObject(cx, obj, "wxSocketError", + NULL, NULL, + JSPROP_READONLY | JSPROP_PERMANENT); + JS_DefineConstDoubles(cx, constObj, wxSocketErrorMap); + + JSConstDoubleSpec wxSocketEventTypeMap[] = + { + WXJS_CONSTANT(wxSOCKET_, INPUT) + WXJS_CONSTANT(wxSOCKET_, OUTPUT) + WXJS_CONSTANT(wxSOCKET_, CONNECTION) + WXJS_CONSTANT(wxSOCKET_, LOST) + { 0 } + }; + constObj = JS_DefineObject(cx, obj, "wxSocketEventType", + NULL, NULL, + JSPROP_READONLY | JSPROP_PERMANENT); + JS_DefineConstDoubles(cx, constObj, wxSocketEventTypeMap); + + JSConstDoubleSpec wxSocketFlagMap[] = + { + WXJS_CONSTANT(wxSOCKET_, NONE) + WXJS_CONSTANT(wxSOCKET_, NOWAIT) + WXJS_CONSTANT(wxSOCKET_, WAITALL) + WXJS_CONSTANT(wxSOCKET_, BLOCK) + WXJS_CONSTANT(wxSOCKET_, REUSEADDR) + { 0 } + }; + constObj = JS_DefineObject(cx, obj, "wxSocketFlags", + NULL, NULL, + JSPROP_READONLY | JSPROP_PERMANENT); + JS_DefineConstDoubles(cx, constObj, wxSocketFlagMap); +} + +/*** + * + * + * Returns true if the socket is connected. + * + * + * This property waits until the socket is readable. This might mean that queued data + * is available for reading or, for streamed sockets, that the connection has been closed, + * so that a read operation will complete immediately without blocking + * (unless the wxSocketFlags.WAITALL flag is set, in which case the operation might still block). + * + * + * Returns true if the socket is disconnected. + * + * + * Returns true if an error occurred in the last IO operation. + * + * + * Returns the number of bytes read or written by the last IO call + * + * + * Returns the last wxSocket error. + * Please note that this property merely returns the last error code, but it should not + * be used to determine if an error has occurred (this is because successful operations + * do not change the lastError value). Use @wxSocketBase#error first, in order to determine + * if the last IO call failed. If this returns true, use lastError to discover the cause of the error. + * + * + * Returns true if the socket is initialized and ready and false in other cases. + *
Remark/Warning:
+ * For @wxSocketClient, ok won't return true unless the client is connected to a server. + * For @wxSocketServer, ok will return true if the server could bind to the specified + * address and is already listening for new connections. + * ok does not check for IO errors; use @wxSocketBase#error instead for that purpose. + *
+ *
+ */ +WXJS_BEGIN_PROPERTY_MAP(SocketBase) + WXJS_READONLY_PROPERTY(P_CONNECTED, "connected") + WXJS_READONLY_PROPERTY(P_DATA, "data") + WXJS_READONLY_PROPERTY(P_DISCONNECTED, "disconnected") + WXJS_READONLY_PROPERTY(P_ERROR, "error") + WXJS_READONLY_PROPERTY(P_LASTCOUNT, "lastCount") + WXJS_READONLY_PROPERTY(P_LASTCOUNT, "lastError") + WXJS_READONLY_PROPERTY(P_OK, "ok") +WXJS_END_PROPERTY_MAP() + +bool SocketBase::GetProperty(SocketBasePrivate *p, JSContext *cx, JSObject *obj, int id, jsval *vp) +{ + switch(id) + { + case P_CONNECTED: + *vp = ToJS(cx, p->GetBase()->IsConnected()); + break; + case P_DATA: + *vp = ToJS(cx, p->GetBase()->IsData()); + break; + case P_DISCONNECTED: + *vp = ToJS(cx, p->GetBase()->IsDisconnected()); + break; + case P_ERROR: + *vp = ToJS(cx, p->GetBase()->Error()); + break; + case P_LASTCOUNT: + { + long count = p->GetBase()->LastCount(); + *vp = ToJS(cx, count); + break; + } + case P_LASTERROR: + { + int error = p->GetBase()->LastError(); + *vp = ToJS(cx, error); + break; + } + case P_OK: + *vp = ToJS(cx, p->GetBase()->Ok()); + break; + } + return true; +} + +WXJS_BEGIN_METHOD_MAP(SocketBase) + WXJS_METHOD("close", close, 0) + WXJS_METHOD("discard", discard, 0) + WXJS_METHOD("interruptWait", interruptWait, 0) + WXJS_METHOD("notify", notify, 1) + WXJS_METHOD("peek", peek, 1) + WXJS_METHOD("read", read, 1) + WXJS_METHOD("readMsg", readMsg, 1) + WXJS_METHOD("restoreState", restoreState, 0) + WXJS_METHOD("saveState", saveState, 0) + WXJS_METHOD("setTimeout", setTimeout, 1) + WXJS_METHOD("unread", unread, 1) + WXJS_METHOD("wait", wait, 0) + WXJS_METHOD("waitForLost", waitForLost, 0) + WXJS_METHOD("waitForRead", waitForRead, 0) + WXJS_METHOD("waitForWrite", waitForWrite, 0) + WXJS_METHOD("write", write, 1) + WXJS_METHOD("writeMsg", writeMsg, 1) +WXJS_END_METHOD_MAP() + +/*** + * + * + * + * This function shuts down the socket, disabling further transmission and reception of data; + * it also disables events for the socket and frees the associated system resources. + * Upon socket destruction, close is automatically called, so in most cases you won't need to + * do it yourself, unless you explicitly want to shut down the socket, typically to notify + * the peer that you are closing the connection. + *

+ * Remark/Warning: Although close immediately disables events for the socket, + * it is possible that event messages may be waiting in the application's event queue. + * The application must therefore be prepared to handle socket event messages even after calling close. + *
+ *
+ */ +JSBool SocketBase::close(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + SocketBasePrivate *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + p->GetBase()->Close(); + + return JS_TRUE; +} + +/*** + * + * + * + * This function simply deletes all bytes in the incoming queue. + * This function always returns immediately and its operation is not affected by IO flags. + * Use @wxSocketBase#lastCount to verify the number of bytes actually discarded. + * If you use @wxSocketBase#error, it will always return false. + * + * + */ +JSBool SocketBase::discard(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + SocketBasePrivate *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + p->GetBase()->Discard(); + + return JS_TRUE; +} + +/*** + * + * + * + * Use this method to interrupt any wait operation currently in progress. Note that this is not intended + * as a regular way to interrupt a @wxSocketBase#wait call, but only as an escape mechanism for + * exceptional situations where it is absolutely necessary to use it, for example to abort + * an operation due to some exception or abnormal problem. InterruptWait is automatically called when + * you @wxSocketBase#close a socket (and thus also upon socket destruction), so you don't need + * to use it in these cases. + * + * + */ +JSBool SocketBase::interruptWait(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + SocketBasePrivate *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + p->GetBase()->InterruptWait(); + + return JS_TRUE; +} + +/*** + * + * + * + * + * + * According to the Flag value, this function enables or disables socket events. + * If Flag is true, the events configured with @wxSocketBase#setNotify will be sent + * to the application. If Flag is false; no events will be sent. + * + * + */ +JSBool SocketBase::notify(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + SocketBasePrivate *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + bool notify; + if ( FromJS(cx, argv[0], notify) ) + { + p->GetBase()->Notify(notify); + return JS_TRUE; + } + return JS_FALSE; +} + +/*** + * + * + * + * + * + * This function peeks a buffer (with the given size of the buffer) from the socket. + * Peeking a buffer doesn't delete it from the socket input queue. + * Use @wxSocketBase#lastCount to verify the number of bytes actually peeked. + * Use @wxSocketBase#error to determine if the operation succeeded. + * Returns a reference to the current object. + *

+ * Remark/Warning: The exact behaviour of peek depends on the combination + * of flags being used. + *
+ *
+ */ +JSBool SocketBase::peek(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + SocketBasePrivate *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + if ( JSVAL_IS_OBJECT(argv[0]) ) + { + wxMemoryBuffer *buffer = wxjs::ext::GetMemoryBuffer(cx, JSVAL_TO_OBJECT(argv[0])); + + if ( buffer != NULL ) + { + p->GetBase()->Peek(buffer->GetData(), buffer->GetBufSize()); + + *rval = OBJECT_TO_JSVAL(obj); + return JS_TRUE; + } + } + return JS_FALSE; +} + +/*** + * + * + * + * + * + * This function reads a buffer (with the given size of the buffer) from the socket. + * Use @wxSocketBase#lastCount to verify the number of bytes actually read. + * Use @wxSocketBase#error to determine if the operation succeeded. + * Returns a reference to the current object. + *

+ * Remark/Warning: The exact behaviour of read depends on the combination + * of flags being used. + *
+ *
+ */ +JSBool SocketBase::read(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + SocketBasePrivate *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + if ( JSVAL_IS_OBJECT(argv[0]) ) + { + wxMemoryBuffer *buffer = wxjs::ext::GetMemoryBuffer(cx, JSVAL_TO_OBJECT(argv[0])); + + if ( buffer != NULL ) + { + p->GetBase()->Read(buffer->GetData(), buffer->GetBufSize()); + + *rval = OBJECT_TO_JSVAL(obj); + return JS_TRUE; + } + } + return JS_FALSE; +} + +/*** + * + * + * + * + * + * This method reads a buffer sent by @wxSocketBase#writeMsg on a socket. + * If the buffer passed to the function isn't big enough, the remaining bytes + * will be discarded. This function always waits for the buffer to be entirely filled, + * unless an error occurs. + * Use @wxSocketBase#lastCount to verify the number of bytes actually read. + * Use @wxSocketBase#error to determine if the operation succeeded. + * Returns a reference to the current object. + *

+ * Remark/Warning: readMsg will behave as if the wxSocketFlag.WAITALL flag was always + * set and it will always ignore the wxSocketFlag.NOWAIT flag. + *
+ *
+ */ +JSBool SocketBase::readMsg(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + SocketBasePrivate *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + if ( JSVAL_IS_OBJECT(argv[0]) ) + { + wxMemoryBuffer *buffer = wxjs::ext::GetMemoryBuffer(cx, JSVAL_TO_OBJECT(argv[0])); + + if ( buffer != NULL ) + { + p->GetBase()->ReadMsg(buffer->GetData(), buffer->GetBufSize()); + + *rval = OBJECT_TO_JSVAL(obj); + return JS_TRUE; + } + } + return JS_FALSE; +} + +/*** + * + * + * + * + * + * This function unreads a buffer. That is, the data in the buffer is put back in the incoming queue. + * This function is not affected by wxSocketFlag. + * Use @wxSocketBase#lastCount to verify the number of bytes actually read. + * Use @wxSocketBase#error to determine if the operation succeeded. + * Returns a reference to the current object. + * + * + */ +JSBool SocketBase::unread(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + SocketBasePrivate *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + if ( JSVAL_IS_OBJECT(argv[0]) ) + { + wxMemoryBuffer *buffer = wxjs::ext::GetMemoryBuffer(cx, JSVAL_TO_OBJECT(argv[0])); + if ( buffer != NULL ) + { + p->GetBase()->Unread(buffer->GetData(), buffer->GetDataLen()); + + *rval = OBJECT_TO_JSVAL(obj); + return JS_TRUE; + } + } + return JS_FALSE; +} + +/*** + * + * + * + * This function restores the previous state of the socket, as saved with @wxSocketBase#saveState. + * Calls to saveState and restoreState can be nested. + * + * + */ +JSBool SocketBase::restoreState(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + SocketBasePrivate *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + p->GetBase()->RestoreState(); + + return JS_TRUE; +} + +/*** + * + * + * + * This method saves the current state of the socket in a stack. + * Socket state includes flags, as set with @wxSocketBase#flags, + * event mask, as set with @wxSocketBase#setNotify and @wxSocketBase#notify, + * user data, as set with @wxSocketBase#clientData. + * Calls to saveState and restoreState can be nested. + * + * + */ +JSBool SocketBase::saveState(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + SocketBasePrivate *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + p->GetBase()->SaveState(); + + return JS_TRUE; +} + +/*** + * + * + * + * + * + * This function sets the default socket timeout in seconds. + * This timeout applies to all IO calls, and also to the Wait + * family of functions if you don't specify a wait interval. Initially, + * the default timeout is 10 minutes. + * + * + */ +JSBool SocketBase::setTimeout(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + SocketBasePrivate *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + long secs; + if ( FromJS(cx, argv[0], secs) ) + { + p->GetBase()->SetTimeout(secs); + return JS_TRUE; + } + + return JS_FALSE; +} + +/*** + * + * + * + * + * + * + * This function waits until any of the following conditions is true: + *
    + *
  • The socket becomes readable.
  • + *
  • The socket becomes writable.
  • + *
  • An ongoing connection request has completed (@wxSocketClient only)
  • + *
  • An incoming connection request has arrived (@wxSocketServer only)
  • + *
  • The connection has been closed.
  • + *
+ * Note that it is recommended to use the individual wait functions to wait for + * the required condition, instead of this one. + *
Returns true when any of the above conditions is satisfied, false if the timeout was reached. + *
+ *
+ */ +JSBool SocketBase::wait(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + SocketBasePrivate *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + long secs = -1; + long ms = 0; + + if ( argc > 2 ) + argc = 2; + + switch(argc) + { + case 2: + if ( ! FromJS(cx, argv[1], ms) ) + return JS_FALSE; + // Fall through + case 1: + if ( ! FromJS(cx, argv[0], secs) ) + return JS_FALSE; + // Fall through + default: + *rval = ToJS(cx, p->GetBase()->Wait(secs, ms)); + } + return JS_TRUE; +} + +/*** + * + * + * + * + * + * + * This function waits until the connection is lost. + * This may happen if the peer gracefully closes the connection or if the connection breaks. + * Returns true if the connection was lost, false if the timeout was reached. + * + * + */ +JSBool SocketBase::waitForLost(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + SocketBasePrivate *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + long secs = -1; + long ms = 0; + + if ( argc > 2 ) + argc = 2; + + switch(argc) + { + case 2: + if ( ! FromJS(cx, argv[1], ms) ) + return JS_FALSE; + // Fall through + case 1: + if ( ! FromJS(cx, argv[0], secs) ) + return JS_FALSE; + // Fall through + default: + *rval = ToJS(cx, p->GetBase()->WaitForLost(secs, ms)); + } + return JS_TRUE; +} + +/*** + * + * + * + * + * + * + * This function waits until the socket is readable. This might mean that queued data + * is available for reading or, for streamed sockets, that the connection has been closed, + * so that a read operation will complete immediately without blocking (unless the + * wxSocketFlag.WAITALL flag is set, in which case the operation might still block). + * Returns true if the socket becomes readable, false on timeout. + * + * + */ +JSBool SocketBase::waitForRead(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + SocketBasePrivate *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + long secs = -1; + long ms = 0; + + if ( argc > 2 ) + argc = 2; + + switch(argc) + { + case 2: + if ( ! FromJS(cx, argv[1], ms) ) + return JS_FALSE; + // Fall through + case 1: + if ( ! FromJS(cx, argv[0], secs) ) + return JS_FALSE; + // Fall through + default: + *rval = ToJS(cx, p->GetBase()->WaitForRead(secs, ms)); + } + return JS_TRUE; +} + +/*** + * + * + * + * + * + * + * This function waits until the socket becomes writable. + * This might mean that the socket is ready to send new data, + * or for streamed sockets, that the connection has been closed, + * so that a write operation is guaranteed to complete immediately + * (unless the wxSocketFlag.WAITALL flag is set, in which case the operation might still block) + * Returns true if the socket becomes writable, false on timeout. + * + * + */ +JSBool SocketBase::waitForWrite(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + SocketBasePrivate *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + long secs = -1; + long ms = 0; + + if ( argc > 2 ) + argc = 2; + + switch(argc) + { + case 2: + if ( ! FromJS(cx, argv[1], ms) ) + return JS_FALSE; + // Fall through + case 1: + if ( ! FromJS(cx, argv[0], secs) ) + return JS_FALSE; + // Fall through + default: + *rval = ToJS(cx, p->GetBase()->WaitForWrite(secs, ms)); + } + return JS_TRUE; +} + +/*** + * + * + * + * + * + * This function writes a buffer (with the given size of the buffer) to the socket. + * Use @wxSocketBase#lastCount to verify the number of bytes actually written. + * Use @wxSocketBase#error to determine if the operation succeeded. + * Returns a reference to the current object. + *

+ * Remark/Warning: The exact behaviour of write depends on the combination + * of flags being used. + *
+ *
+ */ +JSBool SocketBase::write(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + SocketBasePrivate *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + if ( JSVAL_IS_OBJECT(argv[0]) ) + { + wxMemoryBuffer *buffer = wxjs::ext::GetMemoryBuffer(cx, JSVAL_TO_OBJECT(argv[0])); + + if ( buffer != NULL ) + { + p->GetBase()->Write(buffer->GetData(), buffer->GetDataLen()); + *rval = OBJECT_TO_JSVAL(obj); + return JS_TRUE; + } + } + return JS_FALSE; +} + +/*** + * + * + * + * + * + * This function writes a buffer to the socket, but it writes a short header + * before so that @wxSocketBase#readMsg knows how much data should it actually read. + * So, a buffer sent with writeMsg must be read with @wxSocketBase#readMsg. + * This function always waits for the entire buffer to be sent, unless an error occurs. + * Use @wxSocketBase#lastCount to verify the number of bytes actually read. + * Use @wxSocketBase#error to determine if the operation succeeded. + * Returns a reference to the current object. + *

+ * Remark/Warning: writeMsg will behave as if the wxSocketFlag.WAITALL flag was always + * set and it will always ignore the wxSocketFlag.NOWAIT flag. + *
+ *
+ */ +JSBool SocketBase::writeMsg(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + SocketBasePrivate *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + if ( JSVAL_IS_OBJECT(argv[0]) ) + { + wxMemoryBuffer *buffer = wxjs::ext::GetMemoryBuffer(cx, JSVAL_TO_OBJECT(argv[0])); + + if ( buffer != NULL ) + { + p->GetBase()->WriteMsg(buffer->GetData(), buffer->GetDataLen()); + + *rval = OBJECT_TO_JSVAL(obj); + return JS_TRUE; + } + } + return JS_FALSE; +} Property changes on: ps/trunk/source/tools/atlas/wxJS/io/sockbase.cpp ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/io/constant.h =================================================================== --- ps/trunk/source/tools/atlas/wxJS/io/constant.h (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/io/constant.h (revision 5154) @@ -0,0 +1,31 @@ +/* + * wxJavaScript - constant.h + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: constant.h 598 2007-03-07 20:13:28Z fbraem $ + */ +namespace wxjs +{ + namespace io + { + void InitConstants(JSContext *cx, JSObject *obj); + }; // namespace io +}; // namespace wxjs Property changes on: ps/trunk/source/tools/atlas/wxJS/io/constant.h ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/io/fistream.cpp =================================================================== --- ps/trunk/source/tools/atlas/wxJS/io/fistream.cpp (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/io/fistream.cpp (revision 5154) @@ -0,0 +1,105 @@ +#include "precompiled.h" + +/* + * wxJavaScript - fistream.cpp + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: fistream.cpp 598 2007-03-07 20:13:28Z fbraem $ + */ +#include +#ifndef WX_PRECOMP + #include +#endif + +#include "../common/main.h" + +#include "file.h" +#include "stream.h" +#include "fistream.h" + +using namespace wxjs; +using namespace wxjs::io; + +/*** + * fistream + * io + * + * This class represents data read in from a file. There are actually two such groups of classes: + * this one is based on @wxFile whereas @wxFFileInputStream is based on the @wxFFile class. + * An example: + *

+ *   var fis = new wxFileInputStream("c:\\temp\\test.txt");
+ *   if ( fis.ok )
+ *   {
+ *     var bis = new wxBufferedInputStream(fis);
+ *     while(! bis.eof )
+ *     {
+ *       var buffer = new wxMemoryBuffer(100);
+ *       bis.read(buffer);
+ *       buffer.dataLength = bis.lastRead;
+ *       ...
+ *     }
+ *   }
+ *
+ */ +WXJS_INIT_CLASS(FileInputStream, "wxFileInputStream", 1) + +/*** + * + * + * The name of a file + * + * + * + * + * + * A file descriptor + * + * + * Constructs a new wxFileInputStream object. A wxFileInputStream is + * always opened in read-only mode. + * + * + */ +Stream* FileInputStream::Construct(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, bool constructing) +{ + if ( File::HasPrototype(cx, argv[0]) ) + { + wxFile *file = File::GetPrivate(cx, argv[0], false); + // This is needed, because otherwise the file can be garbage collected. + // Another method could be to root file, but how are we going to unroot it? + JS_DefineProperty(cx, obj, "__file__", argv[0], NULL, NULL, JSPROP_READONLY); + return new Stream(new wxFileInputStream(*file)); + } + else if ( JSVAL_IS_STRING(argv[0]) ) + { + wxString name; + FromJS(cx, argv[0], name); + return new Stream(new wxFileInputStream(name)); + } + else if ( JSVAL_IS_INT(argv[0]) ) + { + int fd; + if ( FromJS(cx, argv[0], fd) ) + return new Stream(new wxFileInputStream(fd)); + } + return NULL; +} Property changes on: ps/trunk/source/tools/atlas/wxJS/io/fistream.cpp ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/io/io_constant.cpp =================================================================== --- ps/trunk/source/tools/atlas/wxJS/io/io_constant.cpp (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/io/io_constant.cpp (revision 5154) @@ -0,0 +1,148 @@ +#include "precompiled.h" + +/* + * wxJavaScript - constant.cpp + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: constant.cpp 598 2007-03-07 20:13:28Z fbraem $ + */ +// constant.cpp + +#ifndef WX_PRECOMP + #include +#endif +#include +#include +#include + +#include "../common/main.h" + +#include "constant.h" + +using namespace wxjs; + +/*** + * constant + * io + * + * The following list shows all the constants that are defined on the Global object. + *
  • wxNOT_FOUND
+ * Used by several find methods to indicate that nothing is found. + *
+ */ +extern JSConstDoubleSpec wxGlobalMap[]; +/*JSConstDoubleSpec wxGlobalMap[] = +{ + WXJS_SIMPLE_CONSTANT(wxNOT_FOUND) + { 0 } +};*/ + +/*** + * + * + * + * No error occurred. + * + * + * An End-OF-File occurred. + * + * + * An error occurred in the last write operation. + * + * + * An error occurred in the last read operation. + * + * See @wxStreamBase + * + */ +JSConstDoubleSpec wxStreamErrorMap[] = +{ + WXJS_CONSTANT(wxSTREAM_, NO_ERROR) + WXJS_CONSTANT(wxSTREAM_, EOF) + WXJS_CONSTANT(wxSTREAM_, WRITE_ERROR) + WXJS_CONSTANT(wxSTREAM_, READ_ERROR) + { 0 } +}; + +/*** + * + * + * + * + * See @wxInputStream#seekI and @wxFile#seek + * + */ +JSConstDoubleSpec wxSeekModeMap[] = +{ + WXJS_CONSTANT(wx, FromCurrent) + WXJS_CONSTANT(wx, FromStart) + WXJS_CONSTANT(wx, FromEnd) + { 0 } +}; + +/*** + * + * + * execute the process asynchronously + * execute it synchronously, i.e. wait until it finishes + * under Windows, don't hide the child even if it's IO is redirected (this + * is done by default) + * + * under Unix, if the process is the group leader then passing true to @wxProcess#kill + * kills all children as well as pid + * + * by default synchronous execution disables all program windows to avoid + * that the user interacts with the program while the child process is + * running, you can use this flag to prevent this from happening + * See @wxExecute and @wxProcess + * + * + */ +JSConstDoubleSpec wxExecFlagsMap[] = +{ + WXJS_CONSTANT(wxEXEC_, ASYNC) + WXJS_CONSTANT(wxEXEC_, SYNC) + WXJS_CONSTANT(wxEXEC_, NOHIDE) + WXJS_CONSTANT(wxEXEC_, MAKE_GROUP_LEADER) + WXJS_CONSTANT(wxEXEC_, NODISABLE) + { 0 } +}; + +void io::InitConstants(JSContext *cx, JSObject *obj) +{ + // Define the global constants + JS_DefineConstDoubles(cx, obj, wxGlobalMap); + + JSObject *constObj = JS_DefineObject(cx, obj, "wxStreamError", + NULL, NULL, + JSPROP_READONLY | JSPROP_PERMANENT); + JS_DefineConstDoubles(cx, constObj, wxStreamErrorMap); + + constObj = JS_DefineObject(cx, obj, "wxSeekMode", + NULL, NULL, + JSPROP_READONLY | JSPROP_PERMANENT); + JS_DefineConstDoubles(cx, constObj, wxSeekModeMap); + + constObj = JS_DefineObject(cx, obj, "wxExecFlag", + NULL, NULL, + JSPROP_READONLY | JSPROP_PERMANENT); + JS_DefineConstDoubles(cx, constObj, wxExecFlagsMap); +} Property changes on: ps/trunk/source/tools/atlas/wxJS/io/io_constant.cpp ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/io/httphdr.h =================================================================== --- ps/trunk/source/tools/atlas/wxJS/io/httphdr.h (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/io/httphdr.h (revision 5154) @@ -0,0 +1,43 @@ +/* + * wxJavaScript - httphdr.h + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: httphdr.h 598 2007-03-07 20:13:28Z fbraem $ + */ +#ifndef _wxjs_io_httphdr_h +#define _wxjs_io_httphdr_h + +namespace wxjs +{ + namespace io + { + class HTTPHeader : public ApiWrapper + { + public: + + static bool AddProperty(HTTPHeader *p, JSContext *cx, JSObject *obj, + const wxString& prop, jsval *vp); + static bool GetStringProperty(HTTPHeader *p, JSContext *cx, JSObject *obj, + const wxString &propertyName, jsval *vp); + }; + }; // namespace io +}; // namespace wxjs +#endif // _wxjs_io_url_h Property changes on: ps/trunk/source/tools/atlas/wxJS/io/httphdr.h ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/io/sockaddr.cpp =================================================================== --- ps/trunk/source/tools/atlas/wxJS/io/sockaddr.cpp (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/io/sockaddr.cpp (revision 5154) @@ -0,0 +1,67 @@ +#include "precompiled.h" + +/* + * wxJavaScript - sockaddr.cpp + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: sockaddr.cpp 598 2007-03-07 20:13:28Z fbraem $ + */ +#include +#ifndef WX_PRECOMP + #include +#endif + +#include "../common/main.h" +#include "sockaddr.h" + +using namespace wxjs; +using namespace wxjs::io; + +/*** + * sockaddr + * io + * + * Prototype class for socket addresses. + * + */ +WXJS_INIT_CLASS(SockAddress, "wxSockAddress", 0) + +WXJS_BEGIN_METHOD_MAP(SockAddress) + WXJS_METHOD("clear", clear, 0) +WXJS_END_METHOD_MAP() + +/*** + * + * + * + * Delete all information of the address. + * + * + */ +JSBool SockAddress::clear(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxSockAddress *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + p->Clear(); + return JS_TRUE; +} Property changes on: ps/trunk/source/tools/atlas/wxJS/io/sockaddr.cpp ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/io/sound.h =================================================================== --- ps/trunk/source/tools/atlas/wxJS/io/sound.h (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/io/sound.h (revision 5154) @@ -0,0 +1,67 @@ +/* + * wxJavaScript - sound.h + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: sound.h 598 2007-03-07 20:13:28Z fbraem $ + */ +#ifndef _WXJSSound_H +#define _WXJSSound_H + +#include + +namespace wxjs +{ + namespace io + { + class Sound : public ApiWrapper + { + public: + /** + * Callback for retrieving properties of wxDir + */ + static bool GetProperty(wxSound *p, JSContext *cx, JSObject *obj, int id, jsval *vp); + + /** + * Callback for when a wxDir object is created + */ + static wxSound* Construct(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, bool constructing); + + static JSBool create(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval); + static JSBool play(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval); + static JSBool stop(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval); + + WXJS_DECLARE_PROPERTY_MAP() + WXJS_DECLARE_CONSTANT_MAP() + WXJS_DECLARE_METHOD_MAP() + WXJS_DECLARE_STATIC_METHOD_MAP() + + /** + * Property Ids. + */ + enum + { + P_OK + }; + }; + }; // namespace io +}; // namespace wxjs +#endif //_WXJSSound_H + Property changes on: ps/trunk/source/tools/atlas/wxJS/io/sound.h ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/io/distream.h =================================================================== --- ps/trunk/source/tools/atlas/wxJS/io/distream.h (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/io/distream.h (revision 5154) @@ -0,0 +1,54 @@ +/* + * wxJavaScript - distream.h + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: distream.h 598 2007-03-07 20:13:28Z fbraem $ + */ +#ifndef _WXJSDataInputStream_H +#define _WXJSDataInputStream_H + +#include + +namespace wxjs +{ + namespace io + { + class DataInputStream: public ApiWrapper + { + public: + /** + * Callback for when a wxTextInputStream object is created + */ + static wxDataInputStream *Construct(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, bool constructing); + + WXJS_DECLARE_METHOD_MAP() + static JSBool bigEndianOrdered(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval); + static JSBool read64(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval); + static JSBool read32(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval); + static JSBool read16(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval); + static JSBool read8(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval); + static JSBool readDouble(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval); + static JSBool readString(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval); + + }; + }; // namespace io +}; // namespace wxjs +#endif //_WXJSDataInputStream_H Property changes on: ps/trunk/source/tools/atlas/wxJS/io/distream.h ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/io/ffostream.cpp =================================================================== --- ps/trunk/source/tools/atlas/wxJS/io/ffostream.cpp (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/io/ffostream.cpp (revision 5154) @@ -0,0 +1,83 @@ +#include "precompiled.h" + +/* + * wxJavaScript - ffostream.cpp + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: ffostream.cpp 598 2007-03-07 20:13:28Z fbraem $ + */ +#include +#ifndef WX_PRECOMP + #include +#endif + +#include "wx/wfstream.h" + +#include "../common/main.h" + +#include "ffile.h" +#include "stream.h" +#include "ffostream.h" + +using namespace wxjs; +using namespace wxjs::io; + +/*** + * ffostream + * io + * + * This class represents data written to a file. There are actually two such groups of classes: + * this one is based on @wxFFile whereas @wxFileOutputStream is based on the @wxFile class. + * + */ +WXJS_INIT_CLASS(FFileOutputStream, "wxFFileOutputStream", 1) + +/*** + * + * + * The name of a file + * + * + * + * + * + * Constructs a new wxFFileOutputStream object. A wxFFileOutputStream is always opened in write-only mode. + * + * + */ +Stream* FFileOutputStream::Construct(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, bool constructing) +{ + if ( FFile::HasPrototype(cx, argv[0]) ) + { + wxFFile *file = FFile::GetPrivate(cx, argv[0], false); + // This is needed, because otherwise the file can be garbage collected. + // Another method could be to root ffile, but how are we going to unroot it? + JS_DefineProperty(cx, obj, "__ffile__", argv[0], NULL, NULL, JSPROP_READONLY); + return new Stream(new wxFFileOutputStream(*file)); + } + else if ( JSVAL_IS_STRING(argv[0]) ) + { + wxString name; + FromJS(cx, argv[0], name); + return new Stream(new wxFFileOutputStream(name)); + } + return NULL; +} Property changes on: ps/trunk/source/tools/atlas/wxJS/io/ffostream.cpp ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/io/socksrv.cpp =================================================================== --- ps/trunk/source/tools/atlas/wxJS/io/socksrv.cpp (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/io/socksrv.cpp (revision 5154) @@ -0,0 +1,224 @@ +#include "precompiled.h" + +/* + * wxJavaScript - socksrv.cpp + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: socksrv.cpp 716 2007-05-20 17:57:22Z fbraem $ + */ +#include +#ifndef WX_PRECOMP + #include +#endif + +#include "../common/main.h" +#include "../common/jsutil.h" +#include "sockbase.h" +#include "sockaddr.h" +#include "socksrv.h" +#include "sockevth.h" + +using namespace wxjs; +using namespace wxjs::io; + +SocketServer::SocketServer(JSContext *cx + , JSObject *obj + , wxSockAddress &address + , wxSocketFlags flags) : wxSocketServer(address, flags) +{ + m_evtHandler = new SocketEventHandler(); + m_evtHandler->SetClientObject(new JavaScriptClientData(cx, obj, false, true)); + SetEventHandler(*m_evtHandler, -1); +} + +SocketServer::~SocketServer() +{ + delete m_evtHandler; +} + +/*** + * socksrv + * io + * + * This class implements server sockets. A server socket waits for requests + * to come in over the network. + * + */ +WXJS_INIT_CLASS(SocketServer, "wxSocketServer", 1) + +/*** + * + * + * + * + * + * + * Constructs a new wxSocketServer. + * + * + */ +wxSocketServer *SocketServer::Construct(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, bool constructing) +{ + int flags = wxSOCKET_NONE; + if ( argc > 1 ) + { + if ( ! FromJS(cx, argv[0], flags) ) + { + return NULL; + } + } + + wxSockAddress *address = SockAddress::GetPrivate(cx, argv[0]); + if ( address != NULL ) + { + return new SocketServer(cx, obj, *address, flags); + } + return NULL; +} + +void SocketServer::Destruct(JSContext *cx, wxSocketServer *p) +{ + p->Destroy(); +} + +WXJS_BEGIN_METHOD_MAP(SocketServer) + WXJS_METHOD("accept", accept, 0) + WXJS_METHOD("acceptWith", acceptWith, 1) + WXJS_METHOD("waitForAccept", waitForAccept, 0) +WXJS_END_METHOD_MAP() + +/*** + * + * + * + * If wait is true and there are no pending connections to be accepted, + * it will wait for the next incoming connection to arrive. + * + * + * Accepts an incoming connection request, and creates a new @wxSocketBase object + * which represents the server-side of the connection. + * Returns an opened socket connection, or NULL if an error occurred or if the + * wait parameter was false and there were no pending connections. + * + * + */ +JSBool SocketServer::accept(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxSocketServer *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + bool wait = true; + if ( argc > 1 ) + { + if ( ! FromJS(cx, argv[1], wait) ) + return JS_FALSE; + } + + wxSocketBase *client = p->Accept(wait); + if ( client == NULL ) + { + *rval = JSVAL_VOID; + } + else + { + *rval = SocketBase::CreateObject(cx, new SocketBasePrivate(client)); + } + return JS_TRUE; +} + +/*** + * + * + * + * + * If wait is true and there are no pending connections to be accepted, + * it will wait for the next incoming connection to arrive. + * + * + * Accept an incoming connection using the specified socket object. + * + * + */ +JSBool SocketServer::acceptWith(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxSocketServer *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + SocketBasePrivate *base = SocketBase::GetPrivate(cx, argv[0]); + if ( ! base ) + { + return JS_FALSE; + } + + bool wait = true; + if ( argc > 1 ) + { + if ( ! FromJS(cx, argv[1], wait) ) + return JS_FALSE; + } + + *rval = ToJS(cx, p->AcceptWith(*base->GetBase(), wait)); + return JS_TRUE; +} + +/*** + * + * + * + * + * + * + * This function waits for an incoming connection. Use it if you want to call + * accept or acceptWith with wait set to false, to detect when an incoming connection + * is waiting to be accepted. + * Returns true if an incoming connection arrived, false if the timeout elapsed. + * + * + */ +JSBool SocketServer::waitForAccept(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxSocketServer *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + long secs = -1; + long ms = 0; + + if ( argc > 2 ) + argc = 2; + + switch(argc) + { + case 2: + if ( ! FromJS(cx, argv[1], ms) ) + return JS_FALSE; + // Fall through + case 1: + if ( ! FromJS(cx, argv[0], secs) ) + return JS_FALSE; + // Fall through + default: + *rval = ToJS(cx, p->WaitForAccept(secs, ms)); + } + return JS_TRUE; +} Property changes on: ps/trunk/source/tools/atlas/wxJS/io/socksrv.cpp ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/io/uri.cpp =================================================================== --- ps/trunk/source/tools/atlas/wxJS/io/uri.cpp (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/io/uri.cpp (revision 5154) @@ -0,0 +1,339 @@ +#include "precompiled.h" + +/* + * wxJavaScript - uri.cpp + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: uri.cpp 598 2007-03-07 20:13:28Z fbraem $ + */ +#include +#ifndef WX_PRECOMP + #include +#endif + +#include "../common/main.h" +#include "uri.h" + +using namespace wxjs; +using namespace wxjs::io; + +/*** + * uri + * io + * + * wxURI is used to extract information from a URI (Uniform Resource Identifier). + * + */ +WXJS_INIT_CLASS(URI, "wxURI", 1) + +/*** + * + * + * Server is a host name, or the Server component itself is undefined. + * Server is a IP version 4 address (XXX.XXX.XXX.XXX) + * Server is a IP version 6 address ((XXX:)XXX::(XXX)XXX:XXX + * Server is an IP address, but not versions 4 or 6 + * + * + */ +WXJS_BEGIN_CONSTANT_MAP(URI) + WXJS_CONSTANT(wxURI_, REGNAME) + WXJS_CONSTANT(wxURI_, IPV4ADDRESS) + WXJS_CONSTANT(wxURI_, IPV6ADDRESS) + WXJS_CONSTANT(wxURI_, IPVFUTURE) +WXJS_END_CONSTANT_MAP() + +/*** + * + * + * + * + * + * Creates a new wxURI object + * + * + */ +wxURI *URI::Construct(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, bool constructing) +{ + wxString uri; + FromJS(cx, argv[0], uri); + return new wxURI(uri); +} + +/*** + * + * + * The fragment of a URI is the last value of the URI. + * + * + * Obtains the host type of this URI, which is of type @wxURI#HostType. + * + * + * Returns the password part of the userinfo component of this URI. + * Note that this is explicitly depreciated by RFC 1396 and should generally be avoided if possible. + * + * + * Returns the (normalized) path of the URI. + * + * + * Returns a string representation of the URI's port. + * + * + * Returns the Query component of the URI. + * + * + * Returns the Scheme component of the URI. + * + * + * Returns the Server component of the URI. + * + * + * Returns the username component of the URI. + * + * + * Returns the userinfo component of the URI. + * + * + * Returns true if the path component of the URI exists. + * + * + * Returns true if the port component of the URI exists. + * + * + * Returns true if the query component of the URI exists. + * + * + * Returns true if the scheme component of the URI exists. + * + * + * Returns true if the server component of the URI exists. + * + * + * Returns true if the user component of the URI exists. + * + * + * Returns true if a valid [absolute] URI, otherwise this URI + * is a URI reference and not a full URI, and IsReference returns false. + * + * + */ +WXJS_BEGIN_PROPERTY_MAP(URI) + WXJS_READONLY_PROPERTY(P_FRAGMENT, "fragment") + WXJS_READONLY_PROPERTY(P_HOST_TYPE, "hostType") + WXJS_READONLY_PROPERTY(P_PASSWORD, "password") + WXJS_READONLY_PROPERTY(P_PATH, "path") + WXJS_READONLY_PROPERTY(P_PORT, "port") + WXJS_READONLY_PROPERTY(P_QUERY, "query") + WXJS_READONLY_PROPERTY(P_SCHEME, "scheme") + WXJS_READONLY_PROPERTY(P_SERVER, "server") + WXJS_READONLY_PROPERTY(P_USER, "user") + WXJS_READONLY_PROPERTY(P_USERINFO, "userInfo") + WXJS_READONLY_PROPERTY(P_HAS_PATH, "hasPath") + WXJS_READONLY_PROPERTY(P_HAS_PORT, "hasPort") + WXJS_READONLY_PROPERTY(P_HAS_QUERY, "hasQuery") + WXJS_READONLY_PROPERTY(P_HAS_SCHEME, "hasScheme") + WXJS_READONLY_PROPERTY(P_HAS_SERVER, "hasServer") + WXJS_READONLY_PROPERTY(P_HAS_USER, "hasUser") + WXJS_READONLY_PROPERTY(P_IS_REFERENCE, "isReference") +WXJS_END_PROPERTY_MAP() + +bool URI::GetProperty(wxURI *p, JSContext *cx, JSObject *obj, int id, jsval *vp) +{ + switch(id) + { + case P_FRAGMENT: + *vp = ToJS(cx, p->GetFragment()); + break; + case P_HOST_TYPE: + *vp = ToJS(cx, p->GetHostType()); + break; + case P_PASSWORD: + *vp = ToJS(cx, p->GetPassword()); + break; + case P_PATH: + *vp = ToJS(cx, p->GetPath()); + break; + case P_PORT: + *vp = ToJS(cx, p->GetPort()); + break; + case P_QUERY: + *vp = ToJS(cx, p->GetQuery()); + break; + case P_SCHEME: + *vp = ToJS(cx, p->GetScheme()); + break; + case P_USER: + *vp = ToJS(cx, p->GetUser()); + break; + case P_USERINFO: + *vp = ToJS(cx, p->GetUserInfo()); + break; + case P_HAS_PATH: + *vp = ToJS(cx, p->HasPath()); + break; + case P_HAS_PORT: + *vp = ToJS(cx, p->HasPort()); + break; + case P_HAS_QUERY: + *vp = ToJS(cx, p->HasQuery()); + break; + case P_HAS_SCHEME: + *vp = ToJS(cx, p->HasScheme()); + break; + case P_HAS_USER: + *vp = ToJS(cx, p->HasUserInfo()); + break; + case P_IS_REFERENCE: + *vp = ToJS(cx, p->IsReference()); + break; + } + return true; +} + +WXJS_BEGIN_METHOD_MAP(URI) + WXJS_METHOD("buildURI", buildURI, 0) + WXJS_METHOD("buildUnescapedURI", buildUnescapedURI, 0) + WXJS_METHOD("create", create, 1) + WXJS_METHOD("resolve", resolve, 2) + WXJS_METHOD("unescape", unescape, 1) +WXJS_END_METHOD_MAP() + +/*** + * + * + * + * Builds the URI from its individual components and adds proper separators. + * + * + */ +JSBool URI::buildURI(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxURI *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + *rval = ToJS(cx, p->BuildURI()); + return JS_TRUE; +} + +/*** + * + * + * + * Builds the URI from its individual components, + * adds proper separators, and returns escape sequences to normal characters. + * + * + */ +JSBool URI::buildUnescapedURI(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxURI *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + *rval = ToJS(cx, p->BuildUnescapedURI()); + return JS_TRUE; +} + +/*** + * + * + * + * + * + * Creates this URI from the string uri + * + * + */ +JSBool URI::create(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxURI *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + wxString uri; + FromJS(cx, argv[0], uri); + p->Create(uri); + return JS_TRUE; +} + +/*** + * + * + * + * + * + * + * Inherits this URI from a base URI - components that do not exist in this URI are + * copied from the base, and if this URI's path is not an absolute path (prefixed by a '/'), + * then this URI's path is merged with the base's path. + *

+ * For instance, resolving "../mydir" from "http://mysite.com/john/doe" results in the scheme + * (http) and server (mysite.com) being copied into this URI, since they do not exist. + * In addition, since the path of this URI is not absolute (does not begin with '/'), + * the path of the base's is merged with this URI's path, resulting in the + * URI "http://mysite.com/john/mydir". + *
+ *
+ */ +JSBool URI::resolve(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxURI *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + wxURI *uri = GetPrivate(cx, argv[0]); + if ( uri == NULL ) + return JS_FALSE; + + bool strict = true; + if ( argc > 1 + && !FromJS(cx, argv[1], strict) ) + { + return JS_FALSE; + } + + p->Resolve(*uri, strict ? wxURI_STRICT : 0); + return JS_TRUE; +} + +/*** + * + * + * + * + * + * Translates all escape sequences (normal characters and returns the result + * + * + */ +JSBool URI::unescape(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxURI *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + wxString uri; + FromJS(cx, argv[0], uri); + *rval = ToJS(cx, p->Unescape(uri)); + return JS_TRUE; +} + Property changes on: ps/trunk/source/tools/atlas/wxJS/io/uri.cpp ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/io/tostream.h =================================================================== --- ps/trunk/source/tools/atlas/wxJS/io/tostream.h (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/io/tostream.h (revision 5154) @@ -0,0 +1,64 @@ +/* + * wxJavaScript - tostream.h + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: tostream.h 598 2007-03-07 20:13:28Z fbraem $ + */ +#ifndef _WXJSTextOutputStream_H +#define _WXJSTextOutputStream_H + +#include + +namespace wxjs +{ + namespace io + { + class TextOutputStream : public ApiWrapper + { + public: + + /** + * Callback for when a wxTextOutputStream object is created + */ + static wxTextOutputStream* Construct(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, bool constructing); + static void InitClass(JSContext *cx, JSObject *obj, JSObject *proto); + + static bool GetProperty(wxTextOutputStream *p, JSContext *cx, JSObject *obj, int id, jsval *vp); + static bool SetProperty(wxTextOutputStream *p, JSContext *cx, JSObject *obj, int id, jsval *vp); + WXJS_DECLARE_PROPERTY_MAP() + + /** + * Property Ids. + */ + enum + { + P_MODE + }; + WXJS_DECLARE_METHOD_MAP() + static JSBool write32(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval); + static JSBool write16(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval); + static JSBool write8(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval); + static JSBool writeDouble(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval); + static JSBool writeString(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval); + }; + }; // namespace io +}; // namespace wxjs +#endif //_WXJSTextOutputStream_H Property changes on: ps/trunk/source/tools/atlas/wxJS/io/tostream.h ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/io/aistream.h =================================================================== --- ps/trunk/source/tools/atlas/wxJS/io/aistream.h (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/io/aistream.h (revision 5154) @@ -0,0 +1,42 @@ +/* + * wxJavaScript - aistream.h + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: aistream.h 598 2007-03-07 20:13:28Z fbraem $ + */ +#ifndef wxjs_io_aistream_h +#define wxjs_io_aistream_h + +namespace wxjs +{ + namespace io + { + class ArchiveInputStream : public ApiWrapper + { + public: + + WXJS_DECLARE_METHOD_MAP() + static JSBool closeentry(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval); + static JSBool openEntry(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval); + }; + }; // namespace io +}; // namespace wxjs +#endif // wxjs_io_aistream_h Property changes on: ps/trunk/source/tools/atlas/wxJS/io/aistream.h ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/io/ostream.h =================================================================== --- ps/trunk/source/tools/atlas/wxJS/io/ostream.h (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/io/ostream.h (revision 5154) @@ -0,0 +1,57 @@ +/* + * wxJavaScript - ostream.h + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: ostream.h 598 2007-03-07 20:13:28Z fbraem $ + */ +#ifndef wxjs_io_ostream_h +#define wxjs_io_ostream_h + +namespace wxjs +{ + namespace io + { + class OutputStream : public ApiWrapper + { + public: + static bool GetProperty(Stream *p, JSContext *cx, JSObject *obj, int id, jsval *vp); + + WXJS_DECLARE_PROPERTY_MAP() + + /** + * Property Ids. + */ + enum + { + P_LAST_WRITE + , P_TELL_O + }; + + WXJS_DECLARE_METHOD_MAP() + static JSBool close(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval); + static JSBool putC(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval); + static JSBool write(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval); + static JSBool seekO(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval); + static JSBool sync(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval); + }; + }; // namespace io +}; // namespace wxjs +#endif //wxjs_io_ostream_h Property changes on: ps/trunk/source/tools/atlas/wxJS/io/ostream.h ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/io/filename.cpp =================================================================== --- ps/trunk/source/tools/atlas/wxJS/io/filename.cpp (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/io/filename.cpp (revision 5154) @@ -0,0 +1,1724 @@ +#include "precompiled.h" + +/* + * wxJavaScript - filename.cpp + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: filename.cpp 730 2007-06-05 19:29:52Z fbraem $ + */ +// filename.cpp + +#include +#ifndef WX_PRECOMP + #include +#endif + +#include "../common/main.h" +#include "../common/jsutil.h" + +#include "filename.h" +#include "file.h" + +using namespace wxjs; +using namespace wxjs::io; + +/*** + * filename + * io + * + * wxFileName encapsulates a file name. This class serves two purposes: first, it provides + * the functions to split the file names into components and to recombine these components + * in the full file name which can then be passed to the OS file functions (and wxWindows + * functions wrapping them). Second, it includes the functions for working with the files + * itself. + *

+ * Remark: To change the file data you should use @wxFile class instead. + * wxFileName provides functions for working with the file attributes. + *

+ * Remark: Some of the properties of wxFileName causes IO processing. For example: + * @wxFileName#accessTime will execute an IO API to retrieve the last access time + * of the file. This can result in performance issues when you use this property + * frequently. The best solution for this is to put the property in a variable and + * use that variable instead of the property: + *

+ *   // Do this
+ *   var fileName = new wxFileName("test.txt");
+ *   var acc = fileName.accessTime;
+ *   // From now on use var acc instead of fileName.accessTime
+ *  
+ *
+ */ +WXJS_INIT_CLASS(FileName, "wxFileName", 0) + +/*** + * + * + * + * + * + * + * + * + * + * + * + * wxPathFormat is ported as a separate JavaScript object. + * Many wxFileName methods accept the path format argument which is + * wxPathFormat.NATIVE by default meaning to use the path format native for + * the current platform. + *

+ * The path format affects the operation of wxFileName functions in + * several ways: first and foremost, it defines the path separator character + * to use, but it also affects other things such as whether the path has + * the drive part or not. + *
+ *
+ * + * Replace env vars with their values + * Squeeze all .. and . and prepend cwd + * Unix only: replace ~ and ~user + * Case insensitive => tolower + * Make the path absolute + * Make the path the long form + * Resolve if it is a shortcut (Windows only) + * + * + * wxPathNormalize is ported as a separate JavaScript object. + * The kind of normalization to do with the file name: these values can be or'd + * together to perform several operations at once in @wxFileName#normalize. + * + * + * + * Return the path with the volume (does nothing for the filename formats without volumes) + * Return the path with the trailing separator, if this flag is not given + * there will be no separator at the end of the path. + * + * wxPathGet is ported as a separate JavaScript object. + * + * + * + * Try to create each directory in the path and also don't return an error + * if the target directory already exists. + * + * wxPathMkDir is ported as a separate JavaScript object. + * + * + *
+ */ +void FileName::InitClass(JSContext *cx, JSObject *obj, JSObject *proto) +{ + JSConstDoubleSpec wxPathFormatMap[] = + { + WXJS_CONSTANT(wxPATH_, NATIVE) + WXJS_CONSTANT(wxPATH_, UNIX) + WXJS_CONSTANT(wxPATH_, MAC) + WXJS_CONSTANT(wxPATH_, DOS) + WXJS_CONSTANT(wxPATH_, VMS) + WXJS_CONSTANT(wxPATH_, BEOS) + WXJS_CONSTANT(wxPATH_, WIN) + WXJS_CONSTANT(wxPATH_, OS2) + { 0 } + }; + + JSObject *constObj = JS_DefineObject(cx, obj, "wxPathFormat", + NULL, NULL, + JSPROP_READONLY | JSPROP_PERMANENT); + JS_DefineConstDoubles(cx, constObj, wxPathFormatMap); + + JSConstDoubleSpec wxPathNormalizeMap[] = + { + WXJS_CONSTANT(wxPATH_NORM_, ENV_VARS) + WXJS_CONSTANT(wxPATH_NORM_, DOTS) + WXJS_CONSTANT(wxPATH_NORM_, TILDE) + WXJS_CONSTANT(wxPATH_NORM_, CASE) + WXJS_CONSTANT(wxPATH_NORM_, ABSOLUTE) + WXJS_CONSTANT(wxPATH_NORM_, LONG) + WXJS_CONSTANT(wxPATH_NORM_, SHORTCUT) + WXJS_CONSTANT(wxPATH_NORM_, ALL) + { 0 } + }; + constObj = JS_DefineObject(cx, obj, "wxPathNormalize", + NULL, NULL, + JSPROP_READONLY | JSPROP_PERMANENT); + JS_DefineConstDoubles(cx, constObj, wxPathNormalizeMap); + + JSConstDoubleSpec wxPathGetMap[] = + { + WXJS_CONSTANT(wxPATH_GET_, VOLUME) + WXJS_CONSTANT(wxPATH_GET_, SEPARATOR) + { 0 } + }; + constObj = JS_DefineObject(cx, obj, "wxPathGet", + NULL, NULL, + JSPROP_READONLY | JSPROP_PERMANENT); + JS_DefineConstDoubles(cx, constObj, wxPathGetMap); + + JSConstDoubleSpec wxPathMkdirMap[] = + { + WXJS_CONSTANT(wxPATH_MKDIR_, FULL) + { 0 } + }; + constObj = JS_DefineObject(cx, obj, "wxPathMkdir", + NULL, NULL, + JSPROP_READONLY | JSPROP_PERMANENT); + JS_DefineConstDoubles(cx, constObj, wxPathMkdirMap); +} + +/*** + * + * Get/Set the current working directory. + * Get/Set the home directory. + * + * Returns the usually used path separator for the native platform. + * For all platforms but DOS and Windows there is only one path separator anyhow, + * but for DOS and Windows there are two of them. + * + * + * Gets the path separator of the native platform + * + * + * Gets the string separating the volume from the path for the native format. + * + * + */ +WXJS_BEGIN_STATIC_PROPERTY_MAP(FileName) + WXJS_STATIC_PROPERTY(P_CWD, "cwd") + WXJS_STATIC_PROPERTY(P_HOME_DIR, "homeDir") + WXJS_READONLY_STATIC_PROPERTY(P_PATH_SEPARATOR, "pathSeparator") + WXJS_READONLY_STATIC_PROPERTY(P_PATH_SEPARATORS, "pathSeparators") + WXJS_READONLY_STATIC_PROPERTY(P_VOLUME_SEPARATOR, "volumeSeparator") +WXJS_END_PROPERTY_MAP() + +bool FileName::GetStaticProperty(JSContext *cx, int id, jsval *vp) +{ + switch(id) + { + case P_CWD: + *vp = ToJS(cx, wxFileName::GetCwd()); + break; + case P_HOME_DIR: + *vp = ToJS(cx, wxFileName::GetHomeDir()); + break; + case P_PATH_SEPARATOR: + *vp = ToJS(cx, wxString(wxFileName::GetPathSeparator())); + break; + case P_PATH_SEPARATORS: + *vp = ToJS(cx, wxFileName::GetPathSeparators()); + break; + case P_VOLUME_SEPARATOR: + *vp = ToJS(cx, wxFileName::GetVolumeSeparator()); + break; + } + return true; +} + +bool FileName::SetStaticProperty(JSContext *cx, int id, jsval *vp) +{ + switch(id) + { + case P_CWD: + { + wxString cwd; + FromJS(cx, *vp, cwd); + wxFileName::SetCwd(cwd); + } + } + return JS_TRUE; +} + +/*** + * + * Get/Set the last access time + * Get/Set the creation time + * Returns the number of directories in the file name. + * Returns true when the directory exists. + * Get/Set the extension + * Returns true when the file exists. + * Get/Set the full name (including extension but without directories). + * Returns the full path with name and extension for the native platform. + * Returns true when an extension is present. + * Returns true if this object represents a directory, false otherwise (i.e. if it is a file). + * This property doesn't test whether the directory or file really exists, + * you should use @wxFileName#dirExists or @wxFileName#fileExists for this. + * Return the long form of the path (returns identity on non-Windows platforms). + * Get/Set the time the file was last modified + * + * Returns true if the filename is valid, false if it is not initialized yet. + * The assignment functions and @wxFileName#clear may reset the object to + * the uninitialized, invalid state. + * + * Return the short form of the path (returns identity on non-Windows platforms). + * + * Get/Set the volume name for this file name. + * + */ +WXJS_BEGIN_PROPERTY_MAP(FileName) + WXJS_READONLY_PROPERTY(P_DIR_COUNT, "dirCount") + WXJS_READONLY_PROPERTY(P_DIRS, "dirs") + WXJS_READONLY_PROPERTY(P_DIR_EXISTS, "dirExists") + WXJS_PROPERTY(P_EXT, "ext") + WXJS_READONLY_PROPERTY(P_FILE_EXISTS, "fileExists") + WXJS_READONLY_PROPERTY(P_FULL_NAME, "fullName") + WXJS_READONLY_PROPERTY(P_FULL_PATH, "fullPath") + WXJS_READONLY_PROPERTY(P_HAS_EXT, "hasExt") + WXJS_READONLY_PROPERTY(P_LONG_PATH, "longPath") + WXJS_PROPERTY(P_MODIFICATION_TIME, "modificationTime") + WXJS_PROPERTY(P_NAME, "name") + WXJS_READONLY_PROPERTY(P_SHORT_PATH, "shortPath") + WXJS_PROPERTY(P_ACCESS_TIME, "accessTime") + WXJS_PROPERTY(P_CREATE_TIME, "createTime") + WXJS_PROPERTY(P_VOLUME, "volume") + WXJS_READONLY_PROPERTY(P_OK, "ok") + WXJS_READONLY_PROPERTY(P_IS_DIR, "isDir") +WXJS_END_PROPERTY_MAP() + +bool FileName::GetProperty(wxFileName *p, JSContext *cx, JSObject *obj, int id, jsval *vp) +{ + switch (id) + { + case P_DIR_COUNT: + *vp = ToJS(cx, p->GetDirCount()); + break; + case P_DIR_EXISTS: + *vp = ToJS(cx, p->DirExists()); + break; + case P_DIRS: + *vp = ToJS(cx, p->GetDirs()); + break; + case P_EXT: + *vp = ToJS(cx, p->GetExt()); + break; + case P_FILE_EXISTS: + *vp = ToJS(cx, p->FileExists()); + break; + case P_FULL_NAME: + *vp = ToJS(cx, p->GetFullName()); + break; + case P_FULL_PATH: + *vp = ToJS(cx, p->GetFullPath()); + break; + case P_HAS_EXT: + *vp = ToJS(cx, p->HasExt()); + break; + case P_LONG_PATH: + *vp = ToJS(cx, p->GetLongPath()); + break; + case P_MODIFICATION_TIME: + *vp = ToJS(cx, p->GetModificationTime()); + break; + case P_NAME: + *vp = ToJS(cx, p->GetName()); + break; + case P_SHORT_PATH: + *vp = ToJS(cx, p->GetShortPath()); + break; + case P_ACCESS_TIME: + { + wxDateTime date; + p->GetTimes(&date, NULL, NULL); + *vp = ToJS(cx, date); + break; + } + case P_CREATE_TIME: + { + wxDateTime date; + p->GetTimes(NULL, NULL, &date); + *vp = ToJS(cx, date); + break; + } + case P_VOLUME: + *vp = ToJS(cx, p->GetVolume()); + break; + case P_OK: + *vp = ToJS(cx, p->IsOk()); + break; + case P_IS_DIR: + *vp = ToJS(cx, p->IsDir()); + break; + } + return true; +} + +bool FileName::SetProperty(wxFileName *p, JSContext *cx, JSObject *obj, int id, jsval *vp) +{ + switch (id) + { + case P_EXT: + { + wxString ext; + FromJS(cx, *vp, ext); + p->SetExt(ext); + break; + } + case P_FULL_NAME: + { + wxString fullName; + FromJS(cx, *vp, fullName); + p->SetFullName(fullName); + break; + } + case P_NAME: + { + wxString name; + FromJS(cx, *vp, name); + p->SetName(name); + break; + } + case P_ACCESS_TIME: + { + wxDateTime date; + if ( FromJS(cx, *vp, date) ) + p->SetTimes(&date, NULL, NULL); + break; + } + case P_CREATE_TIME: + { + wxDateTime date; + if ( FromJS(cx, *vp, date) ) + p->SetTimes(NULL, NULL, &date); + break; + } + case P_MODIFICATION_TIME: + { + wxDateTime date; + if ( FromJS(cx, *vp, date) ) + p->SetTimes(NULL, &date, NULL); + break; + } + case P_VOLUME: + { + wxString vol; + FromJS(cx, *vp, vol); + p->SetVolume(vol); + break; + } + } + return true; +} + +/*** + * + * + * + * + * + * + * + * A full path. When it terminates with a pathseparator, a directory path is constructed, + * otherwise a filename and extension is extracted from it. + * + * + * + * + * A directory name + * A filename + * + * + * + * A directory name + * A filename + * An extension + * + * + * + * A volume name + * A directory name + * A filename + * An extension + * + * + * + * Constructs a new wxFileName object. + * + * + */ +wxFileName* FileName::Construct(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, bool constructing) +{ + if ( argc == 0 ) + return new wxFileName(); + + if ( argc == 1 ) + { + if ( FileName::HasPrototype(cx, argv[0]) ) + { + return new wxFileName(*GetPrivate(cx, argv[0], false)); + } + + wxString filename; + FromJS(cx, argv[0], filename); + return new wxFileName(filename); + } + + wxFileName *p = NULL; + + // Argc > 1 + int format = wxPATH_NATIVE; + uintN stringCount = argc; + if ( JSVAL_IS_INT(argv[argc-1]) ) + { + FromJS(cx, argv[argc-1], format); + stringCount--; + } + + wxString *str = new wxString[stringCount]; + for(uintN i = 0; i < stringCount; i++) + FromJS(cx, argv[i], str[i]); + + switch(stringCount) + { + case 1: + p = new wxFileName(str[0], (wxPathFormat) format); + break; + case 2: + p = new wxFileName(str[0], str[1], (wxPathFormat) format); + break; + case 3: + p = new wxFileName(str[0], str[1], str[2], (wxPathFormat) format); + break; + case 4: + p = new wxFileName(str[0], str[1], str[2], str[3], (wxPathFormat) format); + break; + } + + delete[] str; + + return p; +} + +WXJS_BEGIN_METHOD_MAP(FileName) + WXJS_METHOD("appendDir", appendDir, 1) + WXJS_METHOD("assign", assign, 1) + WXJS_METHOD("assignDir", assignDir, 1) + WXJS_METHOD("assignHomeDir", assignHomeDir, 0) + WXJS_METHOD("assignTempFileName", assignTempFileName, 1) + WXJS_METHOD("clear", clear, 0) + WXJS_METHOD("getFullPath", getFullPath, 0) + WXJS_METHOD("getPath", getPath, 0) + WXJS_METHOD("getPathSeparator", getPathSeparator, 0) + WXJS_METHOD("getPathSeparators", getPathSeparators, 0) + WXJS_METHOD("getTimes", getTimes, 3) + WXJS_METHOD("setTimes", setTimes, 3) + WXJS_METHOD("getVolumeSeparator", getVolumeSeparator, 0) + WXJS_METHOD("insertDir", insertDir, 2) + WXJS_METHOD("isAbsolute", isAbsolute, 0) + WXJS_METHOD("isPathSeparator", isPathSeparator, 1) + WXJS_METHOD("isRelative", isRelative, 0) + WXJS_METHOD("makeRelativeTo", makeRelativeTo, 0) + WXJS_METHOD("mkdir", mkdir, 0) + WXJS_METHOD("normalize", normalize, 0) + WXJS_METHOD("prependDir", prependDir, 1) + WXJS_METHOD("removeDir", removeDir, 1) + WXJS_METHOD("removeLastDir", removeLastDir, 0) + WXJS_METHOD("rmdir", rmdir, 0) + WXJS_METHOD("sameAs", sameAs, 1) + WXJS_METHOD("setCwd", setCwd, 0) + WXJS_METHOD("touch", touch, 0) +WXJS_END_METHOD_MAP() + +/*** + * + * + * + * + * + * Appends a directory component to the path. This component + * should contain a single directory name level, i.e. not contain + * any path or volume separators nor should it be empty, otherwise the function does nothing + * + * + */ +JSBool FileName::appendDir(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxFileName *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + wxString dir; + FromJS(cx, argv[0], dir); + p->AppendDir(dir); + return JS_TRUE; +} + +/*** + * + * + * + * + * + * + * A full path. When it terminates with a pathseparator, a directory path is constructed, + * otherwise a filename and extension is extracted from it. + * + * + * + * + * A directory name + * A filename + * + * + * + * A directory name + * A filename + * An extension + * + * + * + * A volume name + * A directory name + * A filename + * An extension + * + * + * + * Creates the file name from various combinations of data. + * + * + */ +JSBool FileName::assign(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxFileName *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + if ( argc == 1 ) + { + if ( HasPrototype(cx, argv[0]) ) + { + p->Assign(*GetPrivate(cx, argv[0], false)); + return JS_TRUE; + } + + wxString filename; + FromJS(cx, argv[0], filename); + p->Assign(filename); + return JS_TRUE; + } + + // Argc > 1 + int format = wxPATH_NATIVE; + uintN stringCount = argc; + if ( JSVAL_IS_INT(argv[argc-1]) ) + { + FromJS(cx, argv[argc-1], format); + stringCount--; + } + + wxString *str = new wxString[stringCount]; + for(uintN i = 0; i < stringCount; i++) + FromJS(cx, argv[i], str[i]); + + switch(stringCount) + { + case 1: + p->Assign(str[0], (wxPathFormat) format); + break; + case 2: + p->Assign(str[0], str[1], (wxPathFormat) format); + break; + case 3: + p->Assign(str[0], str[1], str[2], (wxPathFormat) format); + break; + case 4: + p->Assign(str[0], str[1], str[2], str[3], (wxPathFormat) format); + break; + } + + delete[] str; + + return JS_TRUE; +} + +/*** + * + * + * + * + * + * + * Sets this file name object to the given directory name. + * The name and extension will be empty. + * + * + */ +JSBool FileName::assignDir(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxFileName *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + wxString dir; + FromJS(cx, argv[0], dir); + + int format = wxPATH_NATIVE; + if ( argc > 1 + && ! FromJS(cx, argv[1], format) ) + return JS_FALSE; + + p->AssignDir(dir, (wxPathFormat) format); + return JS_TRUE; +} + +/*** + * + * + * + * Sets this file name object to the home directory. + * + * + */ +JSBool FileName::assignHomeDir(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxFileName *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + p->AssignHomeDir(); + return JS_TRUE; +} + +/*** + * + * + * + * + * Object with wil get the file pointer to the temp file. + * + * + * + * The function calls @wxFileName#createTempFileName to create + * a temporary file and sets this object to the name of the file. + * If a temporary file couldn't be created, the object is put into the invalid state. + * See also @wxFile. + *

+ * The following sample shows how to create a file with a temporary filename: + *

+ *    var name = new wxFileName();
+ *    var file = new wxFile();
+ * 
+ *    name.assignTempFileName('wxjs', file);
+ *    file.write('This is a test');
+ *    file.close();
+ *
+ *    wxMessageBox('Filename: ' + name.fullPath);
+ *   
+ *
+ *
+ */ +JSBool FileName::assignTempFileName(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxFileName *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + wxString prefix; + FromJS(cx, argv[0], prefix); + + wxFile *file = NULL; + if ( argc > 1 + && (file = File::GetPrivate(cx, argv[1])) == NULL ) + return JS_FALSE; + + p->AssignTempFileName(prefix, file); + return JS_TRUE; +} + +/*** + * + * + * Reset all components to default, uninitialized state. + * + */ +JSBool FileName::clear(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxFileName *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + p->Clear(); + return JS_TRUE; +} + +/*** + * + * + * + * + * + * Returns the full path with name and extension. + * + * + */ +JSBool FileName::getFullPath(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxFileName *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + int format = wxPATH_NATIVE; + if ( argc > 0 + && ! FromJS(cx, argv[0], format) ) + return JS_FALSE; + + *rval = ToJS(cx, p->GetFullPath((wxPathFormat) format)); + return JS_TRUE; +} + +/*** + * + * + * + * + * + * + * Returns the path part of the filename (without the name or extension). + * + * + */ +JSBool FileName::getPath(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxFileName *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + int flag = wxPATH_GET_VOLUME; + int format = wxPATH_NATIVE; + if ( argc > 0 + && ! FromJS(cx, argv[0], flag) ) + return JS_FALSE; + + if ( argc > 1 + && ! FromJS(cx, argv[0], format) ) + return JS_FALSE; + + *rval = ToJS(cx, p->GetPath(flag, (wxPathFormat) format)); + return JS_TRUE; +} + +/*** + * + * + * + * + * + * + * + * Gets the last access, last modification and creation times. + * The last access time is updated whenever the file is read + * or written (or executed in the case of Windows), last modification + * time is only changed when the file is written to. Finally, + * the creation time is indeed the time when the file was created under + * Windows and the inode change time under Unix (as it is impossible to + * retrieve the real file creation time there anyhow) which can also be + * changed by many operations after the file creation. + *

+ * Any of the arguments may be null if the corresponding time is not needed. + *
+ *
+ */ +JSBool FileName::getTimes(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxFileName *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + wxDateTime access; + wxDateTime mod; + wxDateTime create; + + if ( p->GetTimes(&access, &mod, &create) ) + { + if ( argv[0] != JSVAL_VOID ) + { + if ( ! SetDate(cx, argv[0], access) ) + return JS_FALSE; + } + + if ( argv[1] != JSVAL_VOID ) + { + if ( ! SetDate(cx, argv[1], mod) ) + return JS_FALSE; + } + + if ( argv[2] != JSVAL_VOID ) + { + if ( ! SetDate(cx, argv[2], create) ) + return JS_FALSE; + } + *rval = JSVAL_TRUE; + } + else + *rval = JSVAL_FALSE; + + return JS_TRUE; +} + +/*** + * + * + * + * + * + * + * + * Sets the file creation and last access/modification times. + * Any of the arguments may be null if the corresponding time is not needed. + * + * + */ +JSBool FileName::setTimes(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxFileName *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + wxDateTime acc; + wxDateTime mod; + wxDateTime create; + + if ( argv[0] == JSVAL_VOID ) + { + if ( ! FromJS(cx, argv[0], acc) ) + return JS_FALSE; + } + + if ( argv[1] != JSVAL_VOID ) + { + if ( ! FromJS(cx, argv[1], mod) ) + return JS_FALSE; + } + + if ( argv[2] != JSVAL_VOID ) + { + if ( ! FromJS(cx, argv[2], create) ) + return JS_FALSE; + } + + *rval = ToJS(cx, p->SetTimes(acc.IsValid() ? &acc : NULL, + mod.IsValid() ? &mod : NULL, + create.IsValid() ? &create : NULL)); + return JS_TRUE; +} + +/*** + * + * + * + * + * + * + * Inserts a directory before the zero-based position in the directory list. + * + * + */ +JSBool FileName::insertDir(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxFileName *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + int pos; + wxString dir; + + if ( FromJS(cx, argv[0], pos) + && FromJS(cx, argv[1], dir) ) + p->InsertDir(pos, dir); + else + return JS_FALSE; + + return JS_TRUE; +} + +/*** + * + * + * + * + * + * Returns true if this filename is absolute. + * + * + */ +JSBool FileName::isAbsolute(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxFileName *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + int format = wxPATH_NATIVE; + if ( argc > 0 + && ! FromJS(cx, argv[0], format) ) + return JS_FALSE; + + *rval = ToJS(cx, p->IsAbsolute((wxPathFormat) format)); + return JS_TRUE; +} + +/*** + * + * + * + * + * + * Returns true if this filename is not absolute. + * + * + */ +JSBool FileName::isRelative(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxFileName *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + int format = wxPATH_NATIVE; + if ( argc > 0 + && ! FromJS(cx, argv[0], format) ) + return JS_FALSE; + + *rval = ToJS(cx, p->IsRelative((wxPathFormat) format)); + return JS_TRUE; +} + +/*** + * + * + * + * The directory to use as root. When not given, the current directory is used. + * + * + * + * + * This function tries to put this file name in a form relative to Base. + * In other words, it returns the file name which should be used to access + * this file if the current directory were Base. + *

+ * Returns true if the file name has been changed, false if we failed to do anything + * with it (currently this only happens if the file name is on a volume different from + * the volume specified by Base). + *
+ *
+ */ +JSBool FileName::makeRelativeTo(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxFileName *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + wxString base = wxEmptyString; + int format = wxPATH_NATIVE; + switch(argc) + { + case 2: + if ( ! FromJS(cx, argv[1], format) ) + return JS_FALSE; + // Fall through + case 1: + FromJS(cx, argv[0], base); + } + + *rval = ToJS(cx, p->MakeRelativeTo(base, (wxPathFormat) format)); + return JS_TRUE; +} + +/*** + * + * + * Permission for the directory + * + * Default is 0. If the flags contain wxPathMkdir.FULL flag, + * try to create each directory in the path and also don't return + * an error if the target directory already exists. + * + * + * + * Creates a directory. Returns true on success. + * + * + */ +JSBool FileName::mkdir(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxFileName *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + int perm = 777; + int flag = 0; + switch(argc) + { + case 2: + if ( ! FromJS(cx, argv[1], flag) ) + return JS_FALSE; + // Fall through + case 1: + if ( ! FromJS(cx, argv[1], perm) ) + return JS_FALSE; + } + + *rval = ToJS(cx, p->Mkdir(perm, flag)); + return JS_TRUE; +} + +/*** + * + * + * + * + * + * + * + * Normalize the path: with the default flags value, the path will be made absolute, + * without any ".." and "." and all environment variables will be expanded in it this + * may be done using another (than current) value of cwd. + * + * + */ +JSBool FileName::normalize(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxFileName *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + wxString cwd = wxEmptyString; + int format = wxPATH_NATIVE; + int flag = wxPATH_NORM_ALL; + + switch(argc) + { + case 3: + if ( ! FromJS(cx, argv[2], format) ) + return JS_FALSE; + // Fall through + case 2: + FromJS(cx, argv[1], cwd); + // Fall through + case 1: + // Fall through + if ( ! FromJS(cx, argv[0], flag) ) + return JS_FALSE; + case 0: + *rval = ToJS(cx, p->Normalize(flag, cwd, (wxPathFormat) format)); + return JS_TRUE; + } + + return JS_FALSE; +} + +/*** + * + * + * + * + * + * Prepends a directory name. + * + * + */ +JSBool FileName::prependDir(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxFileName *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + wxString dir; + + FromJS(cx, argv[1], dir); + p->PrependDir(dir); + + return JS_TRUE; +} + +/*** + * + * + * + * + * + * Removes a directory name. + * + * + */ +JSBool FileName::removeDir(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxFileName *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + int pos; + + if ( FromJS(cx, argv[0], pos) ) + p->RemoveDir(pos); + else + return JS_FALSE; + + return JS_TRUE; +} + +/*** + * + * + * + * Removes the last directory component from the path. + * + * + */ +JSBool FileName::removeLastDir(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxFileName *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + p->RemoveLastDir(); + + return JS_TRUE; +} + +/*** + * + * + * + * Deletes the directory from the file system. + * + * + */ +JSBool FileName::rmdir(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxFileName *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + p->Rmdir(); + + return JS_TRUE; +} + +/*** + * + * + * + * + * + * + * Compares the filename using the rules of the format. + * + * + */ +JSBool FileName::sameAs(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxFileName *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + wxFileName *compareTo = GetPrivate(cx, argv[0]); + if ( compareTo == NULL ) + return JS_FALSE; + + int format = wxPATH_NATIVE; + if ( argc > 1 + && ! FromJS(cx, argv[1], format) ) + return JS_FALSE; + + *rval = ToJS(cx, p->SameAs(*compareTo, (wxPathFormat) format)); + return JS_TRUE; +} + +/*** + * + * + * + * Set this to the current directory. + * + * + */ +JSBool FileName::setCwd(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxFileName *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + p->SetCwd(); + + return JS_TRUE; +} + +/*** + * + * + * + * Sets the access and modification times to the current moment. + * + * + */ +JSBool FileName::touch(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxFileName *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + p->Touch(); + + return JS_TRUE; +} + +WXJS_BEGIN_STATIC_METHOD_MAP(FileName) + WXJS_METHOD("assignCwd", assignCwd, 0) + WXJS_METHOD("createTempFileName", createTempFileName, 2) + WXJS_METHOD("dirExists", dirExists, 1) + WXJS_METHOD("dirName", dirName, 1) + WXJS_METHOD("fileExists", fileExists, 1) + WXJS_METHOD("fileName", fileName, 1) + WXJS_METHOD("getCwd", getCwd, 0) + WXJS_METHOD("getFormat", getFormat, 0) + WXJS_METHOD("mkdir", smkdir, 1) + WXJS_METHOD("rmdir", srmdir, 1) + WXJS_METHOD("splitPath", splitPath, 1) + WXJS_METHOD("getPathSeparator", getPathSeparator, 0) + WXJS_METHOD("getPathSeparators", getPathSeparators, 0) + WXJS_METHOD("getVolumeSeparator", getVolumeSeparator, 0) + WXJS_METHOD("isCaseSensitive", isAbsolute, 0) + WXJS_METHOD("isPathSeparator", isPathSeparator, 1) +WXJS_END_METHOD_MAP() + +/*** + * + * + * + * + * + * Makes this object refer to the current working directory on the + * specified volume (or current volume if volume is not specified). + * + * + */ +JSBool FileName::assignCwd(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxFileName *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + wxString volume = wxEmptyString; + if ( argc > 0 ) + FromJS(cx, argv[0], volume); + + p->AssignCwd(volume); + return JS_TRUE; +} + +/*** + * + * + * + * + * Object which wil get the file pointer to the temp file. + * + * + * + * Returns a temporary file name starting with the given prefix. + * If the prefix is an absolute path, the temporary file is created + * in this directory, otherwise it is created in the default system + * directory for the temporary files or in the current directory. + *

+ * If the function succeeds, the temporary file is actually created. + * When File is not omitted, this file will be opened using the name + * of the temporary file. When possible, this is done in an atomic way ensuring + * that no race condition occurs between the temporary file name generation and + * opening it which could often lead to security compromise on the multiuser systems. + * If file is omitted, the file is only created, but not opened. + *

+ * Under Unix, the temporary file will have read and write permissions for the owner + * only to minimize the security problems. + *
+ *
+ */ +JSBool FileName::createTempFileName(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxString prefix; + FromJS(cx, argv[0], prefix); + + wxFile *file = NULL; + if ( argc > 1 + && (file = File::GetPrivate(cx, argv[1])) == NULL ) + return JS_FALSE; + + wxFileName::CreateTempFileName(prefix, file); + return JS_TRUE; +} + +/*** + * + * + * + * + * + * Returns true when the directory exists. + * + * + */ +JSBool FileName::dirExists(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxString dir; + FromJS(cx, argv[0], dir); + + *rval = ToJS(cx, wxFileName::DirExists(dir)); + return JS_TRUE; +} + +/*** + * + * + * + * + * + * Creates a new wxFileName object based on the given directory. + * + * + */ +JSBool FileName::dirName(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxString dir; + FromJS(cx, argv[0], dir); + + *rval = CreateObject(cx, new wxFileName(wxFileName::DirName(dir))); + return JS_TRUE; +} + +/*** + * + * + * + * + * + * Returns true when the file exists. + * + * + */ +JSBool FileName::fileExists(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxString file; + FromJS(cx, argv[0], file); + + *rval = ToJS(cx, wxFileName::FileExists(file)); + return JS_TRUE; +} + +/*** + * + * + * + * + * + * Creates a new wxFileName object based on the given file. + * + * + */ +JSBool FileName::fileName(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxString file; + FromJS(cx, argv[0], file); + + *rval = CreateObject(cx, new wxFileName(wxFileName::FileName(file))); + return JS_TRUE; +} + +/*** + * + * + * + * + * + * Retrieves the value of the current working directory on the specified volume. + * When the volume is omitted, the programs current working directory is returned + * for the current volume. + * + * + */ +JSBool FileName::getCwd(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxString vol = wxEmptyString; + if ( argc > 0 ) + FromJS(cx, argv[0], vol); + + *rval = ToJS(cx, wxFileName::GetCwd(vol)); + return JS_TRUE; +} + +/*** + * + * + * + * + * + * Returns the canonical path format for this platform. + * + * + */ +JSBool FileName::getFormat(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + int format = wxPATH_NATIVE; + if ( argc > 0 ) + FromJS(cx, argv[0], format); + + *rval = ToJS(cx, wxFileName::GetFormat((wxPathFormat) format)); + return JS_TRUE; +} + +/*** + * + * + * + * + * + * Returns the usually used path separator for this format. + * For all formats but wxPathFormat.DOS there is only one path + * separator anyhow, but for DOS there are two of them and the + * native one, i.e. the backslash is returned by this method. + * + * + */ +JSBool FileName::getPathSeparator(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + int format = wxPATH_NATIVE; + if ( argc > 0 + && ! FromJS(cx, argv[0], format) ) + return JS_FALSE; + + *rval = ToJS(cx, wxString(wxFileName::GetPathSeparator((wxPathFormat) format))); + return JS_TRUE; +} + +/*** + * + * + * + * + * + * Returns the string containing all the path separators for this format. + * For all formats but wxPathFormat.DOS this string contains only one character + * but for DOS and Windows both '/' and '\' may be used as separators. + * + * + */ +JSBool FileName::getPathSeparators(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + int format = wxPATH_NATIVE; + if ( argc > 0 + && ! FromJS(cx, argv[0], format) ) + return JS_FALSE; + + *rval = ToJS(cx, wxFileName::GetPathSeparators((wxPathFormat) format)); + return JS_TRUE; +} + +/*** + * + * + * + * + * + * Returns the string separating the volume from the path for this format. + * + * + */ +JSBool FileName::getVolumeSeparator(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + int format = wxPATH_NATIVE; + if ( argc > 0 + && ! FromJS(cx, argv[0], format) ) + return JS_FALSE; + + *rval = ToJS(cx, wxString(wxFileName::GetVolumeSeparator((wxPathFormat) format))); + return JS_TRUE; +} + +/*** + * + * + * + * + * + * Returns true if filenames for the given format are case-sensitive. + * + * + */ +JSBool FileName::isCaseSensitive(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + int format = wxPATH_NATIVE; + if ( argc > 0 + && ! FromJS(cx, argv[0], format) ) + return JS_FALSE; + + *rval = ToJS(cx, wxFileName::IsCaseSensitive((wxPathFormat) format)); + return JS_TRUE; +} + +/*** + * + * + * A path separator + * + * + * + * Returns true if the given string (only the first character is checked!) + * is a separator on the format. + * + * + */ +JSBool FileName::isPathSeparator(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxString sep; + FromJS(cx, argv[0], sep); + if ( sep.Length() == 0 ) + return JS_TRUE; + + int format = wxPATH_NATIVE; + if ( argc > 1 + && ! FromJS(cx, argv[1], format) ) + return JS_FALSE; + + *rval = ToJS(cx, wxFileName::IsPathSeparator(sep[0], (wxPathFormat) format)); + return JS_TRUE; +} + +/*** + * + * + * Name of the directory + * Permissions + * + * Default is 0. If the flags contain wxPathMkdir.FULL flag, + * try to create each directory in the path and also don't return + * an error if the target directory already exists. + * + * + * + * Creates a directory. Returns true on success. + * + * + */ +JSBool FileName::smkdir(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + if ( argc > 3 ) + argc = 3; + + wxString dir; + int perm = 777; + int flag = 0; + + switch(argc) + { + case 3: + if ( ! FromJS(cx, argv[2], flag) ) + return JS_FALSE; + // Fall through + case 2: + if ( ! FromJS(cx, argv[1], perm) ) + return JS_FALSE; + default: + FromJS(cx, argv[0], dir); + *rval = ToJS(cx, wxFileName::Mkdir(dir, perm, flag)); + } + return JS_TRUE; +} + +/*** + * + * + * + * + * + * Deletes the directory from the file system. + * + * + */ +JSBool FileName::srmdir(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxString dir; + FromJS(cx, argv[0], dir); + wxFileName::Rmdir(dir); + + return JS_TRUE; +} + +/*** + * + * + * + * + * + * + * This function splits a full file name into components: the volume, path, + * the base name and the extension. + *

Remark: In wxWindows the arguments are passed as + * pointers. Because this is not possible in JavaScript, wxJS returns an array containing + * the parts of the path. + *

+ * The following code illustrates how splitPath works in JavaScript. parts[0] contains "C", + * parts[1] contains "\\", parts[2] contains "Temp" and parts[3] is empty. + *

+ *    var parts = wxFileName.splitPath("C:\\Temp");
+ *    for(element in parts)
+ *    {
+ *      ...
+ *    }
+ *    
+ *
+ *
+ */ +JSBool FileName::splitPath(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxString path; + FromJS(cx, argv[0], path); + + int format = wxPATH_NATIVE; + if ( argc > 1 + && ! FromJS(cx, argv[1], format) ) + return JS_FALSE; + + wxString parts[4]; + wxFileName::SplitPath(path, &parts[0], &parts[1], &parts[2], &parts[3], (wxPathFormat) format); + + JSObject *objArray = JS_NewArrayObject(cx, 4, NULL); + *rval = OBJECT_TO_JSVAL(objArray); + for(int i = 0; i < 4; i++) + { + jsval element = ToJS(cx, parts[i]); + JS_SetElement(cx, objArray, i, &element); + } + + return JS_TRUE; +} + +bool FileName::SetDate(JSContext *cx, jsval v, const wxDateTime &date) +{ + if ( JSVAL_IS_OBJECT(v) ) + { + JSObject *obj = JSVAL_TO_OBJECT(v); + if ( js_DateIsValid(cx, obj) ) + { + js_DateSetYear(cx, obj, date.GetYear()); + js_DateSetMonth(cx, obj, date.GetMonth()); + js_DateSetDate(cx, obj, date.GetDay()); + js_DateSetHours(cx, obj, date.GetHour()); + js_DateSetMinutes(cx, obj, date.GetMinute()); + js_DateSetSeconds(cx, obj, date.GetSecond()); + return true; + } + } + return false; +} Property changes on: ps/trunk/source/tools/atlas/wxJS/io/filename.cpp ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/io/ffile.h =================================================================== --- ps/trunk/source/tools/atlas/wxJS/io/ffile.h (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/io/ffile.h (revision 5154) @@ -0,0 +1,75 @@ +/* + * wxJavaScript - ffile.h + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: ffile.h 598 2007-03-07 20:13:28Z fbraem $ + */ +#ifndef _WXJS_FFILE_H +#define _WXJS_FFILE_H + +///////////////////////////////////////////////////////////////////////////// +// Name: file.h +// Purpose: Ports wxFFile to JavaScript +// Author: Franky Braem +// Modified by: +// Created: 18.10.02 +// Copyright: (c) 2001-2002 Franky Braem +// Licence: LGPL +///////////////////////////////////////////////////////////////////////////// + +#include +namespace wxjs +{ + namespace io + { + class FFile : public ApiWrapper + { + public: + + static bool GetProperty(wxFFile *f, JSContext *cx, JSObject *obj, int id, jsval *vp); + + enum + { + P_EOF + , P_KIND + , P_OPENED + , P_LENGTH + , P_TELL + }; + + WXJS_DECLARE_PROPERTY_MAP() + WXJS_DECLARE_METHOD_MAP() + WXJS_DECLARE_CONSTANT_MAP() + + static wxFFile *Construct(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, bool constructing); + + static JSBool close(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval); + static JSBool flush(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval); + static JSBool open(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval); + static JSBool read(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval); + static JSBool readAll(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval); + static JSBool seek(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval); + static JSBool seekEnd(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval); + static JSBool write(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval); + }; + }; // namespace io +}; // namespace wxjs +#endif Property changes on: ps/trunk/source/tools/atlas/wxJS/io/ffile.h ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/io/mostream.h =================================================================== --- ps/trunk/source/tools/atlas/wxJS/io/mostream.h (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/io/mostream.h (revision 5154) @@ -0,0 +1,63 @@ +/* + * wxJavaScript - mostream.h + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: mostream.h 715 2007-05-18 20:38:04Z fbraem $ + */ +#ifndef _WXJSMemoryOutputStream_H +#define _WXJSMemoryOutputStream_H + +#include + +namespace wxjs +{ + namespace io + { + class MemoryOutputStream : public wxMemoryOutputStream + , public ApiWrapper + , public wxClientDataContainer + { + public: + + MemoryOutputStream(char *data, size_t len); + virtual ~MemoryOutputStream(); + /** + * Callback for when a wxMemoryOutputStream object is created + */ + static Stream* Construct(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, bool constructing); + + static bool GetProperty(Stream *p, JSContext *cx, JSObject *obj, int id, jsval *vp); + WXJS_DECLARE_PROPERTY_MAP() + + /** + * Property Ids. + */ + enum + { + P_DATA + }; + + private: + char *m_data; + }; + }; // namespace io +}; // namespace wxjs +#endif Property changes on: ps/trunk/source/tools/atlas/wxJS/io/mostream.h ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/io/ipaddr.cpp =================================================================== --- ps/trunk/source/tools/atlas/wxJS/io/ipaddr.cpp (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/io/ipaddr.cpp (revision 5154) @@ -0,0 +1,156 @@ +#include "precompiled.h" + +/* + * wxJavaScript - ipaddr.cpp + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: ipaddr.cpp 598 2007-03-07 20:13:28Z fbraem $ + */ +#include +#ifndef WX_PRECOMP + #include +#endif + +#include "../common/main.h" +#include "ipaddr.h" + +using namespace wxjs; +using namespace wxjs::io; + +/*** + * ipaddr + * io + * + * wxIPaddress is an prototype class for all internet protocol address objects. + * Currently, only @wxIPV4address is implemented. + * + */ +WXJS_INIT_CLASS(IPaddress, "wxIPaddress", 0) + +/*** + * + * + * Get/Set the hostname. + * + * + * Returns a string containing the IP address. + * + * + * Returns true when the hostname is localhost. + * + * + * Get/Set the current service. + * + * + */ +WXJS_BEGIN_PROPERTY_MAP(IPaddress) + WXJS_PROPERTY(P_HOSTNAME, "hostname") + WXJS_READONLY_PROPERTY(P_IPADDRESS, "IPAddress") + WXJS_READONLY_PROPERTY(P_LOCALHOST, "localhost") + WXJS_PROPERTY(P_SERVICE, "service") +WXJS_END_PROPERTY_MAP() + +bool IPaddress::GetProperty(wxIPaddress *p, JSContext *cx, JSObject *obj, int id, jsval *vp) +{ + switch(id) + { + case P_HOSTNAME: + *vp = ToJS(cx, p->Hostname()); + break; + case P_IPADDRESS: + *vp = ToJS(cx, p->IPAddress()); + break; + case P_LOCALHOST: + *vp = ToJS(cx, p->IsLocalHost()); + break; + case P_SERVICE: + *vp = ToJS(cx, p->Service()); + break; + default: + *vp = JSVAL_VOID; + } + return true; +} + +bool IPaddress::SetProperty(wxIPaddress *p, JSContext *cx, JSObject *obj, int id, jsval *vp) +{ + switch(id) + { + case P_HOSTNAME: + { + wxString hostname; + FromJS(cx, *vp, hostname); + p->Hostname(hostname); + break; + } + case P_SERVICE: + { + int service; + if ( FromJS(cx, *vp, service) ) + p->Service(service); + break; + } + } + return true; +} + +WXJS_BEGIN_METHOD_MAP(IPaddress) + WXJS_METHOD("anyAddress", anyAddress, 0) + WXJS_METHOD("localhost", localhost, 0) +WXJS_END_METHOD_MAP() + +/*** + * + * + * + * Internally, this is the same as setting the IP address to INADDR_ANY. + * Returns true on success, false if something went wrong. + * + * + */ +JSBool IPaddress::anyAddress(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxIPaddress *p = GetPrivate(cx, obj); + wxASSERT_MSG(p != NULL, wxT("No private data associated with wxIPaddress")); + + *rval = ToJS(cx, p->AnyAddress()); + + return JS_TRUE; +} + +/*** + * + * + * + * Set the address to localhost. + * Returns true on success, false if something went wrong. + * + * + */ +JSBool IPaddress::localhost(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxIPaddress *p = GetPrivate(cx, obj); + wxASSERT_MSG(p != NULL, wxT("No private data associated with wxIPaddress")); + + *rval = ToJS(cx, p->LocalHost()); + + return JS_TRUE; +} Property changes on: ps/trunk/source/tools/atlas/wxJS/io/ipaddr.cpp ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/io/url.h =================================================================== --- ps/trunk/source/tools/atlas/wxJS/io/url.h (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/io/url.h (revision 5154) @@ -0,0 +1,58 @@ +/* + * wxJavaScript - url.h + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: url.h 598 2007-03-07 20:13:28Z fbraem $ + */ +#ifndef _wxjs_io_url_h +#define _wxjs_io_url_h + +#include + +namespace wxjs +{ + namespace io + { + class URL : public ApiWrapper + { + public: + + static wxURL *Construct(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, bool constructing); + static void InitClass(JSContext *cx, JSObject *obj, JSObject *proto); + + static bool GetProperty(wxURL *p, JSContext *cx, JSObject *obj, int id, jsval *vp); + + WXJS_DECLARE_PROPERTY_MAP() + enum + { + P_INPUT_STREAM = WXJS_START_PROPERTY_ID + , P_ERROR + }; + + WXJS_DECLARE_METHOD_MAP() + WXJS_DECLARE_STATIC_METHOD_MAP() + + static JSBool setDefaultProxy(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval); + static JSBool setProxy(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval); + }; + }; // namespace io +}; // namespace wxjs +#endif // _wxjs_io_url_h Property changes on: ps/trunk/source/tools/atlas/wxJS/io/url.h ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/io/httphdr.cpp =================================================================== --- ps/trunk/source/tools/atlas/wxJS/io/httphdr.cpp (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/io/httphdr.cpp (revision 5154) @@ -0,0 +1,70 @@ +#include "precompiled.h" + +/* + * wxJavaScript - httphdr.cpp + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: httphdr.cpp 598 2007-03-07 20:13:28Z fbraem $ + */ +#include +#ifndef WX_PRECOMP + #include +#endif + +#include "../common/main.h" +#include "http.h" +#include "sockbase.h" +#include "httphdr.h" + +using namespace wxjs; +using namespace wxjs::io; + +WXJS_INIT_CLASS(HTTPHeader, "wxHTTPHeader", 0) + +bool HTTPHeader::AddProperty(HTTPHeader *p, JSContext *cx, JSObject *obj, + const wxString &prop, jsval *vp) +{ + JSObject *objParent = JS_GetParent(cx, obj); + SocketBasePrivate *base = HTTP::GetPrivate(cx, objParent); + wxHTTP *http = dynamic_cast(base->GetBase()); + if ( http ) + { + wxString value; + FromJS(cx, *vp, value); + http->SetHeader(prop, value); + } + return true; +} + +bool HTTPHeader::GetStringProperty(HTTPHeader *p, JSContext *cx, JSObject *obj, + const wxString &propertyName, jsval *vp) +{ + JSObject *objParent = JS_GetParent(cx, obj); + SocketBasePrivate *base = HTTP::GetPrivate(cx, objParent); + wxHTTP *http = dynamic_cast(base->GetBase()); + + if ( http ) + { + wxString value = http->GetHeader(propertyName); + *vp = ToJS(cx, value); + } + return true; +} Property changes on: ps/trunk/source/tools/atlas/wxJS/io/httphdr.cpp ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/io/stream.h =================================================================== --- ps/trunk/source/tools/atlas/wxJS/io/stream.h (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/io/stream.h (revision 5154) @@ -0,0 +1,66 @@ +/* + * wxJavaScript - stream.h + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: stream.h 598 2007-03-07 20:13:28Z fbraem $ + */ +#ifndef _WXJSStream_H +#define _WXJSStream_H + +///////////////////////////////////////////////////////////////////////////// +// Name: stream.h +// Author: Franky Braem +// Modified by: +// Created: 08-10-2002 +// Copyright: (c) 2001-2002 Franky Braem +// Licence: LGPL +///////////////////////////////////////////////////////////////////////////// + +#include "jsstream.h" + +namespace wxjs +{ + namespace io + { + + class StreamBase : public ApiWrapper + { + public: + /** + * Callback for retrieving properties of wxInputStream + */ + static bool GetProperty(Stream *p, JSContext *cx, JSObject *obj, int id, jsval *vp); + + WXJS_DECLARE_PROPERTY_MAP() + + /** + * Property Ids. + */ + enum + { + P_OK + , P_SIZE + , P_LAST_ERROR + }; + }; + }; // namespace io +}; // namespace wxjs +#endif //_WXJSStream_H Property changes on: ps/trunk/source/tools/atlas/wxJS/io/stream.h ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/io/protocol.h =================================================================== --- ps/trunk/source/tools/atlas/wxJS/io/protocol.h (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/io/protocol.h (revision 5154) @@ -0,0 +1,56 @@ +/* + * wxJavaScript - protocol.h + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: protocol.h 598 2007-03-07 20:13:28Z fbraem $ + */ +#ifndef _wxjs_io_protocol_h +#define _wxjs_io_protocol_h + +#include +namespace wxjs +{ + namespace io + { + class Protocol : public ApiWrapper + { + public: + static void InitClass(JSContext *cx, JSObject *obj, JSObject *proto); + + static bool GetProperty(SocketBasePrivate *p, JSContext *cx, JSObject *obj, int id, jsval *vp); + + WXJS_DECLARE_PROPERTY_MAP() + enum + { + P_CONTENT_TYPE = WXJS_START_PROPERTY_ID + , P_ERROR + }; + WXJS_DECLARE_METHOD_MAP() + + static JSBool abort(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval); + static JSBool getInputStream(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval); + static JSBool reconnect(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval); + static JSBool setUser(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval); + static JSBool setPassword(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval); + }; + }; // namespace io +}; // namespace wxjs +#endif // _wxjs_io_protocol_h Property changes on: ps/trunk/source/tools/atlas/wxJS/io/protocol.h ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/io/aostream.cpp =================================================================== --- ps/trunk/source/tools/atlas/wxJS/io/aostream.cpp (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/io/aostream.cpp (revision 5154) @@ -0,0 +1,241 @@ +#include "precompiled.h" + +/* + * wxJavaScript - aostream.cpp + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: aostream.cpp 598 2007-03-07 20:13:28Z fbraem $ + */ +#include +#ifndef WX_PRECOMP + #include +#endif +#include + +#include "../common/main.h" +#include "stream.h" +#include "aostream.h" +#include "aistream.h" +#include "archentry.h" + +using namespace wxjs; +using namespace wxjs::io; + +/*** + * aostream + * io + * + * wxArchiveOutputStream is a prototype object for archive output streams such + * as @wxZipOutputStream. + * + */ + +WXJS_INIT_CLASS(ArchiveOutputStream, "wxArchiveOutputStream", 0) + +WXJS_BEGIN_METHOD_MAP(ArchiveOutputStream) + WXJS_METHOD("closeEntry", closeentry, 0) + WXJS_METHOD("copyEntry", copyEntry, 2) + WXJS_METHOD("copyArchiveMetaData", copyArchiveMetaData, 1) + WXJS_METHOD("putNextEntry", putNextEntry, 1) + WXJS_METHOD("putNextDirEntry", putNextDirEntry, 1) +WXJS_END_METHOD_MAP() + +/*** + * + * + * + * Closes the current entry. On a non-seekable stream reads to the end of the current entry first. + * + * + */ +JSBool ArchiveOutputStream::closeentry(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + Stream *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + *rval = ToJS(cx, ((wxArchiveOutputStream *)p->GetStream())->CloseEntry()); + return JS_TRUE; +} + +/*** + * + * + * + * + * + * Transfers the zip comment from the @wxArchiveInputStream to this output stream. + * + * + */ +JSBool ArchiveOutputStream::copyArchiveMetaData(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + Stream *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + wxArchiveOutputStream *aos = dynamic_cast(p->GetStream()); + + Stream *in = ArchiveInputStream::GetPrivate(cx, obj); + if ( in != NULL ) + { + *rval = ToJS(cx, aos->CopyArchiveMetaData(*dynamic_cast(in->GetStream()))); + return JS_TRUE; + } + + return JS_FALSE; +} + +/*** + * + * + * + * + * + * + * Takes ownership of entry and uses it to create a new entry in the zip. + * Entry is then opened in inputStream and its contents copied to this stream. + * copyEntry() is much more efficient than transferring the data using read() + * and write() since it will copy them without decompressing and recompressing them. + * Creates a new entry in the archive. + * + * + */ +JSBool ArchiveOutputStream::copyEntry(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + Stream *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + wxArchiveOutputStream *aos = dynamic_cast(p->GetStream()); + + wxArchiveEntry *entry = ArchiveEntry::GetPrivate(cx, argv[0]); + if ( entry != NULL ) + { + Stream *str = ArchiveInputStream::GetPrivate(cx, argv[1]); + if ( str != NULL ) + { + *rval = ToJS(cx, aos->CopyEntry(entry, *dynamic_cast(str->GetStream()))); + return JS_TRUE; + } + } + + return JS_FALSE; +} + +/*** + * + * + * + * + * + * + * Creates a new directory entry in the archive with the given name and timestamp. + * + * + */ +JSBool ArchiveOutputStream::putNextDirEntry(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + Stream *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + wxArchiveOutputStream *zos = dynamic_cast(p->GetStream()); + + wxDateTime dt = wxDateTime::Now(); + switch(argc) + { + case 2: + if ( ! FromJS(cx, argv[1], dt) ) + break; + // Fall through + default: + { + wxString name; + FromJS(cx, argv[0], name); + *rval = ToJS(cx, zos->PutNextDirEntry(name, dt)); + return JS_TRUE; + } + } + + return JS_FALSE; +} + +/*** + * + * + * + * + * + * + * + * + * + * + * Creates a new entry in the archive + * + * + */ +JSBool ArchiveOutputStream::putNextEntry(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + Stream *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + wxArchiveOutputStream *aos = dynamic_cast(p->GetStream()); + + if ( JSVAL_IS_OBJECT(argv[0]) ) + { + wxArchiveEntry *entry = ArchiveEntry::GetPrivate(cx, argv[0]); + if ( entry != NULL ) + { + // Clone the entry, because wxArchiveOutputStream manages the deletion + // and we don't want to delete our JavaScript object + *rval = ToJS(cx, aos->PutNextEntry(entry->Clone())); + return JS_TRUE; + } + } + else + { + off_t size = wxInvalidOffset; + wxDateTime dt = wxDateTime::Now(); + switch(argc) + { + case 3: + if ( ! FromJS(cx, argv[2], size) ) + break; + // Fall through + case 2: + if ( ! FromJS(cx, argv[1], dt) ) + break; + // Fall through + default: + { + wxString name; + FromJS(cx, argv[0], name); + *rval = ToJS(cx, aos->PutNextEntry(name, dt, size)); + return JS_TRUE; + } + } + } + + return JS_FALSE; +} Property changes on: ps/trunk/source/tools/atlas/wxJS/io/aostream.cpp ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/io/istream.h =================================================================== --- ps/trunk/source/tools/atlas/wxJS/io/istream.h (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/io/istream.h (revision 5154) @@ -0,0 +1,68 @@ +/* + * wxJavaScript - istream.h + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: istream.h 598 2007-03-07 20:13:28Z fbraem $ + */ +#ifndef wxjs_io_istream_h +#define wxjs_io_istream_h + +namespace wxjs +{ + namespace io + { + class InputStream : public ApiWrapper + { + public: + /** + * Callback for retrieving properties of wxInputStream + */ + static bool GetProperty(Stream *p, JSContext *cx, JSObject *obj, int id, jsval *vp); + + /** + * Callback for setting properties + */ + static bool SetProperty(Stream *p, JSContext *cx, JSObject *obj, int id, jsval *vp); + + WXJS_DECLARE_PROPERTY_MAP() + + /** + * Property Ids. + */ + enum + { + P_EOF + , P_LAST_READ + , P_TELL_I + , P_C + , P_PEEK + }; + + WXJS_DECLARE_METHOD_MAP() + static JSBool getC(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval); + static JSBool peek(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval); + static JSBool read(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval); + static JSBool seekI(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval); + static JSBool ungetch(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval); + }; + }; // namespace io +}; // namespace wxjs +#endif // wxjs_io_istream_h Property changes on: ps/trunk/source/tools/atlas/wxJS/io/istream.h ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/io/dir.cpp =================================================================== --- ps/trunk/source/tools/atlas/wxJS/io/dir.cpp (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/io/dir.cpp (revision 5154) @@ -0,0 +1,407 @@ +#include "precompiled.h" + +/* + * wxJavaScript - dir.cpp + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: dir.cpp 598 2007-03-07 20:13:28Z fbraem $ + */ +// wxJSDir.cpp + +#include +#ifndef WX_PRECOMP + #include +#endif + +#include "../common/main.h" + +#include "dir.h" +#include "dirtrav.h" + +using namespace wxjs; +using namespace wxjs::io; + +/*** + * dir + * io + * + * wxDir is a portable equivalent of Unix open/read/closedir functions which allow + * enumerating of the files in a directory. wxDir can enumerate files as well as directories. + *

+ * The following example checks if the temp-directory exists, + * and when it does, it retrieves all files with ".tmp" as extension. + *

+ *   if ( wxDir.exists("c:\\temp") )
+ *   {
+ *     files = wxDir.getAllFiles("c:\\temp", "*.tmp");
+ *     for(e in files)
+ *       wxMessageBox(files[e]);
+ *   }
+ *  
+ * See also @wxDirTraverser + *
+ */ +WXJS_INIT_CLASS(Dir, "wxDir", 0) + +/*** + * + * + * + * + * + * + * + * Constants used for filtering files. The default: FILES | DIRS | HIDDEN. + * + * + */ +WXJS_BEGIN_CONSTANT_MAP(Dir) + WXJS_CONSTANT(wxDIR_, FILES) + WXJS_CONSTANT(wxDIR_, DIRS) + WXJS_CONSTANT(wxDIR_, HIDDEN) + WXJS_CONSTANT(wxDIR_, DOTDOT) + WXJS_CONSTANT(wxDIR_, DEFAULT) +WXJS_END_CONSTANT_MAP() + +WXJS_BEGIN_STATIC_METHOD_MAP(Dir) + WXJS_METHOD("getAllFiles", getAllFiles, 1) + WXJS_METHOD("exists", exists, 1) +WXJS_END_METHOD_MAP() + +/*** + * + * + * + * + * + * Returns true when the directory exists. + * + * + */ +JSBool Dir::exists(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxString dir; + FromJS(cx, argv[0], dir); + + *rval = ToJS(cx, wxDir::Exists(dir)); + return JS_TRUE; +} + +/*** + * + * + * + * + * + * + * + * This function returns an array of all filenames under directory DirName + * Only files matching FileSpec are taken. When an empty spec is given, + * all files are given. + *

+ * Remark: when wxDir.DIRS is specified in Flags then + * getAllFiles recurses into subdirectories. So be carefull when using this method + * on a root directory. + *
+ *
+ */ +JSBool Dir::getAllFiles(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + if ( argc > 3 ) + argc = 3; + + wxString filespec = wxEmptyString; + int flags = wxDIR_DEFAULT; + wxArrayString files; + + switch(argc) + { + case 3: + if ( ! FromJS(cx, argv[2], flags) ) + return JS_FALSE; + // Fall through + case 2: + FromJS(cx, argv[1], filespec); + // Fall through + default: + wxString dir; + FromJS(cx, argv[0], dir); + + wxArrayString files; + wxDir::GetAllFiles(dir, &files, filespec, flags); + + *rval = ToJS(cx, files); + } + + return JS_TRUE; +} + +/*** + * + * + * The name of the directory. + * + * + * Constructs a new wxDir object. When no argument is specified, use @wxDir#open + * afterwards. When a directory is passed, use @wxDir#isOpened to test for errors. + * + * + */ +wxDir* Dir::Construct(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, bool constructing) +{ + if ( argc == 0 ) + return new wxDir(); + + if ( argc == 1 ) + { + wxString dir; + FromJS(cx, argv[0], dir); + return new wxDir(dir); + } + + return NULL; +} + +/*** + * + * + * Returns true when the directory was opened by calling @wxDir#open. + * + * + * Returns the name of the directory itself. The returned string + * does not have the trailing path separator (slash or backslash). + * + * + */ +WXJS_BEGIN_PROPERTY_MAP(Dir) + WXJS_READONLY_PROPERTY(P_OPENED, "opened") + WXJS_READONLY_PROPERTY(P_NAME, "name") +WXJS_END_PROPERTY_MAP() + +bool Dir::GetProperty(wxDir *p, JSContext *cx, JSObject *obj, int id, jsval *vp) +{ + if ( id == P_OPENED ) + *vp = ToJS(cx, p->IsOpened()); + else if ( id == P_NAME ) + *vp = ToJS(cx, p->GetName()); + return true; +} + +WXJS_BEGIN_METHOD_MAP(Dir) + WXJS_METHOD("getFirst", getFirst, 0) + WXJS_METHOD("getNext", getNext, 0) + WXJS_METHOD("hasFiles", hasFiles, 0) + WXJS_METHOD("hasSubDirs", hasSubDirs, 0) + WXJS_METHOD("open", open, 1) + WXJS_METHOD("traverse", traverse, 1) +WXJS_END_METHOD_MAP() + +/*** + * + * + * + * + * + * + * Starts the enumerating. All files matching FileSpec + * (or all files when not specified or empty) and Flags will be + * enumerated. Use @wxDir#getNext for the next file. + *

+ * An empty String is returned when there's no file found. + *
+ *
+ */ +JSBool Dir::getFirst(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxDir *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + if ( argc > 2 ) + { + return JS_FALSE; + } + + wxString filespec = wxEmptyString; + int flags = wxDIR_DEFAULT; + + switch(argc) + { + case 2: + if ( ! FromJS(cx, argv[1], flags) ) + return JS_FALSE; + // Fall through + case 1: + FromJS(cx, argv[0], filespec); + // Fall through + default: + wxString fileName = wxEmptyString; + p->GetFirst(&fileName, filespec, flags); + *rval = ToJS(cx, fileName); + } + + return JS_TRUE; +} + +/*** + * + * + * + * Continues to enumerate files and/or directories which satisfy + * the criteria specified in @wxDir#getFirst. An empty String + * is returned when there are no more files. + * + * + */ +JSBool Dir::getNext(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxDir *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + wxString next = wxEmptyString; + p->GetNext(&next); + *rval = ToJS(cx, next); + + return JS_TRUE; +} + +/*** + * + * + * + * + * + * Returns true if the directory contains any files matching the given FileSpec. + * When no argument is given, it will look if there are files in the directory. + * + * + */ +JSBool Dir::hasFiles(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxDir *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + wxString filespec = wxEmptyString; + if ( argc == 1 ) + FromJS(cx, argv[0], filespec); + + *rval = ToJS(cx, p->HasFiles(filespec)); + + return JS_TRUE; +} + +/*** + * + * + * + * + * + * Returns true if the directory contains any subdirectories matching the given DirSpec. + * When no argument is given, it will look if there are any subdirectories in the directory. + * + * + */ +JSBool Dir::hasSubDirs(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxDir *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + wxString dirspec = wxEmptyString; + if ( argc == 1 ) + FromJS(cx, argv[0], dirspec); + + *rval = ToJS(cx, p->HasSubDirs(dirspec)); + + return JS_TRUE; +} + +/*** + * + * + * + * + * + * Open directory for enumerating files and subdirectories. Returns true + * on success, or false on failure. + * + * + */ +JSBool Dir::open(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxDir *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + wxString dir; + FromJS(cx, argv[0], dir); + + *rval = ToJS(cx, p->Open(dir)); + return JS_TRUE; +} + +/*** + * + * + * + * + * + * + * + * Open directory for enumerating files and subdirectories. Returns true + * on success, or false on failure. For an example see @wxDirTraverser. + * + * + */ +JSBool Dir::traverse(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxDir *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + if ( argc > 3 ) + argc = 3; + + int flags = wxDIR_DEFAULT; + wxString filespec = wxEmptyString; + + switch(argc) + { + case 3: + if ( ! FromJS(cx, argv[2], flags) ) + return JS_FALSE; + // Fall through + case 2: + FromJS(cx, argv[1], filespec); + default: + DirTraverser *traverser = DirTraverser::GetPrivate(cx, argv[0]); + if ( traverser == NULL ) + { + return JS_FALSE; + } + + *rval = ToJS(cx, p->Traverse(*traverser, filespec, flags)); + } + + return JS_TRUE; +} Property changes on: ps/trunk/source/tools/atlas/wxJS/io/dir.cpp ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/io/aostream.h =================================================================== --- ps/trunk/source/tools/atlas/wxJS/io/aostream.h (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/io/aostream.h (revision 5154) @@ -0,0 +1,45 @@ +/* + * wxJavaScript - aostream.h + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: aostream.h 598 2007-03-07 20:13:28Z fbraem $ + */ +#ifndef wxjs_io_aostream_h +#define wxjs_io_aostream_h + +namespace wxjs +{ + namespace io + { + class ArchiveOutputStream : public ApiWrapper + { + public: + + WXJS_DECLARE_METHOD_MAP() + static JSBool closeentry(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval); + static JSBool putNextDirEntry(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval); + static JSBool copyArchiveMetaData(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval); + static JSBool putNextEntry(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval); + static JSBool copyEntry(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval); + }; + }; // namespace io +}; // namespace wxjs +#endif // wxjs_io_aostream_h Property changes on: ps/trunk/source/tools/atlas/wxJS/io/aostream.h ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/io/mistream.h =================================================================== --- ps/trunk/source/tools/atlas/wxJS/io/mistream.h (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/io/mistream.h (revision 5154) @@ -0,0 +1,68 @@ +/* + * wxJavaScript - mistream.h + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: mistream.h 715 2007-05-18 20:38:04Z fbraem $ + */ +#ifndef _WXJSMemoryInputStream_H +#define _WXJSMemoryInputStream_H + +///////////////////////////////////////////////////////////////////////////// +// Name: .h +// Purpose: Ports the memory streams +// wxJSMemoryInputStream ports wxMemoryInputStream to JavaScript +// wxJSMemoryOutputStream ports wxMemoryOutputStream to JavaScript +// Author: Franky Braem +// Modified by: +// Created: 22-10-2002 +// Copyright: (c) 2001-2002 Franky Braem +// Licence: LGPL +///////////////////////////////////////////////////////////////////////////// + +#include + +namespace wxjs +{ + namespace io + { + class MemoryInputStream : public wxMemoryInputStream + , public ApiWrapper + , public wxClientDataContainer + { + public: + MemoryInputStream(char *data, size_t len); + virtual ~MemoryInputStream(); + + /** + * Callback for when a wxMemoryInputStream object is created + */ + static Stream* Construct(JSContext *cx, + JSObject *obj, + uintN argc, + jsval *argv, + bool constructing); + + private: + char *m_data; + }; + }; // namespace io +}; // namespace wxjs +#endif //_WXJSMemoryInputStream_H Property changes on: ps/trunk/source/tools/atlas/wxJS/io/mistream.h ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/io/ffostream.h =================================================================== --- ps/trunk/source/tools/atlas/wxJS/io/ffostream.h (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/io/ffostream.h (revision 5154) @@ -0,0 +1,42 @@ +/* + * wxJavaScript - ffostream.h + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: ffostream.h 598 2007-03-07 20:13:28Z fbraem $ + */ +#ifndef _wxjs_io_ffostream_h +#define _wxjs_io_ffostream_h + +namespace wxjs +{ + namespace io + { + class FFileOutputStream : public ApiWrapper + { + public: + /** + * Callback for when a wxFFileOutputStream object is created + */ + static Stream* Construct(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, bool constructing); + }; + }; // namespace io +}; // namespace wxjs +#endif // _wxjs_io_ffostream_h Property changes on: ps/trunk/source/tools/atlas/wxJS/io/ffostream.h ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/io/zistream.cpp =================================================================== --- ps/trunk/source/tools/atlas/wxJS/io/zistream.cpp (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/io/zistream.cpp (revision 5154) @@ -0,0 +1,144 @@ +#include "precompiled.h" + +/* + * wxJavaScript - zistream.cpp + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: zistream.cpp 598 2007-03-07 20:13:28Z fbraem $ + */ +#include +#ifndef WX_PRECOMP + #include +#endif + +#include "../common/main.h" +#include "../ext/wxjs_ext.h" + +#include "stream.h" +#include "istream.h" +#include "zistream.h" +#include "zipentry.h" + +using namespace wxjs; +using namespace wxjs::io; + +ZipInputStream::ZipInputStream(wxInputStream &str) : wxZipInputStream(str) +{ +} + +/*** + * zistream + * io + * + * Input stream for reading zip files. + * + */ +WXJS_INIT_CLASS(ZipInputStream, "wxZipInputStream", 1) + +/*** + * + * + * An input stream + * + * + * Constructs a new wxZipInputStream object. + * + * + */ +Stream* ZipInputStream::Construct(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, bool constructing) +{ + if ( InputStream::HasPrototype(cx, argv[0]) ) + { + Stream *in = InputStream::GetPrivate(cx, argv[0], false); + + // This is needed, because otherwise the stream can be garbage collected. + // Another method could be to root the stream, but how are we going to unroot it? + JS_DefineProperty(cx, obj, "__stream__", argv[0], NULL, NULL, JSPROP_READONLY); + + ZipInputStream *stream = new ZipInputStream(*(wxInputStream*) in->GetStream()); + stream->m_refStream = *in; + return new Stream(stream); + } + return NULL; +} + +void ZipInputStream::Destruct(JSContext *cx, Stream *p) +{ + if ( p != NULL ) + { + ZipInputStream *stream = (ZipInputStream*) p->GetStream(); + + // Keep stream alive for a moment, so that the base class + // doesn't crash when it flushes the stream. + Stream tempRefStream(stream->m_refStream); + + delete p; + p = NULL; + } +} + +/*** + * + * + * The comment of the zip file + * + * + * Closes the current entry if one is open, then reads the meta-data for the next + * entry and returns it in a @wxZipEntry object. The stream is then open and can be read. + * + * + * The number of entries in the zip file + * + * + */ +WXJS_BEGIN_PROPERTY_MAP(ZipInputStream) + WXJS_READONLY_PROPERTY(P_COMMENT, "comment") + WXJS_READONLY_PROPERTY(P_TOTAL_ENTRIES, "totalEntries") + WXJS_READONLY_PROPERTY(P_NEXT_ENTRY, "nextEntry") +WXJS_END_PROPERTY_MAP() + +bool ZipInputStream::GetProperty(Stream *p, JSContext *cx, JSObject *obj, int id, jsval *vp) +{ + wxZipInputStream *in = (wxZipInputStream*) p->GetStream(); + switch(id) + { + case P_COMMENT: + *vp = ToJS(cx, in->GetComment()); + break; + case P_TOTAL_ENTRIES: + *vp = ToJS(cx, in->GetTotalEntries()); + break; + case P_NEXT_ENTRY: + { + wxZipEntry *entry = in->GetNextEntry(); + if ( entry == NULL ) + { + *vp = JSVAL_VOID; + } + else + { + *vp = ZipEntry::CreateObject(cx, entry); + } + } + break; + } + return true; +} Property changes on: ps/trunk/source/tools/atlas/wxJS/io/zistream.cpp ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/io/zostream.cpp =================================================================== --- ps/trunk/source/tools/atlas/wxJS/io/zostream.cpp (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/io/zostream.cpp (revision 5154) @@ -0,0 +1,192 @@ +#include "precompiled.h" + +/* + * wxJavaScript - zostream.cpp + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: zostream.cpp 598 2007-03-07 20:13:28Z fbraem $ + */ +#include +#ifndef WX_PRECOMP + #include +#endif + +#include "../common/main.h" +#include "../ext/wxjs_ext.h" + + +#include "stream.h" +#include "ostream.h" +#include "zostream.h" +#include "zistream.h" +#include "zipentry.h" + +using namespace wxjs; +using namespace wxjs::io; + +ZipOutputStream::ZipOutputStream(wxOutputStream &str, int level) : wxZipOutputStream(str, level) +{ +} + +/*** + * zostream + * io + * + * Output stream for writing zip files. The following sample shows how easy it is + * to create a zip archive with files from one directory: + *

+ *   var zos = new wxZipOutputStream(new wxFileOutputStream("temp.zip"));
+ *   zos.setComment("This archive is created as test");
+ *   var dir = new wxDir("c:\\temp");
+ *
+ *   var trav = new wxDirTraverser();
+ *   trav.onFile = function(filename)
+ *   {
+ *     var entry = new wxZipEntry(filename);
+ *     zos.putNextEntry(entry);
+ *     var fis = new wxFileInputStream(filename);
+ *     var bfs = new wxBufferedOutputStream(zos);
+ *     fis.read(bfs);
+ *
+ *     // Don't forget to sync (flush), otherwise you loose content
+ *     bfs.sync();
+ *
+ *     return wxDirTraverser.CONTINUE;
+ *   }
+ *   dir.traverse(trav);
+ *  
+ *
+ */ +WXJS_INIT_CLASS(ZipOutputStream, "wxZipOutputStream", 1) + +/*** + * + * + * An Output stream + * + * Level is the compression level to use. It can be a value between 0 and 9 + * or -1 to use the default value which currently is equivalent to 6. + * + * + * + * Constructs a new wxZipOutputStream object. + * + * + */ +Stream* ZipOutputStream::Construct(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, bool constructing) +{ + if ( OutputStream::HasPrototype(cx, argv[0]) ) + { + Stream *out = OutputStream::GetPrivate(cx, argv[0], false); + + int level = -1; + if ( argc > 1 ) + { + if ( ! FromJS(cx, argv[1], level) ) + return NULL; + } + + // This is needed, because otherwise the stream can be garbage collected. + // Another method could be to root the stream, but how are we going to unroot it? + JS_DefineProperty(cx, obj, "__stream__", argv[0], NULL, NULL, JSPROP_READONLY); + + ZipOutputStream *stream = new ZipOutputStream(*(wxOutputStream*) out->GetStream(), level); + stream->m_refStream = *out; + return new Stream(stream); + } + return NULL; +} + +void ZipOutputStream::Destruct(JSContext *cx, Stream *p) +{ + if ( p != NULL ) + { + ZipOutputStream *stream = (ZipOutputStream*) p->GetStream(); + stream->Close(); + + // Keep stream alive for a moment, so that the base class + // doesn't crash when it flushes the stream. + Stream tempRefStream(stream->m_refStream); + + delete p; + p = NULL; + } +} + +/*** + * + * + * The comment of the zip file + * + * + * Closes the current entry if one is open, then reads the meta-data for the next + * entry and returns it in a @wxZipEntry object. The stream is then open and can be read. + * + * + * The number of entries in the zip file + * + * + */ +WXJS_BEGIN_PROPERTY_MAP(ZipOutputStream) + WXJS_PROPERTY(P_LEVEL, "level") +WXJS_END_PROPERTY_MAP() + +bool ZipOutputStream::GetProperty(Stream *p, JSContext *cx, JSObject *obj, int id, jsval *vp) +{ + wxZipOutputStream *out = (wxZipOutputStream*) p->GetStream(); + switch(id) + { + case P_LEVEL: + *vp = ToJS(cx, out->GetLevel()); + break; + } + return true; +} + +WXJS_BEGIN_METHOD_MAP(ZipOutputStream) + WXJS_METHOD("setComment", setComment, 1) +WXJS_END_METHOD_MAP() + + +/*** + * + * + * + * + * + * Sets the comment on the archive + * + * + */ +JSBool ZipOutputStream::setComment(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + Stream *p = ZipOutputStream::GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + wxZipOutputStream *zos = (wxZipOutputStream *) p->GetStream(); + + wxString comment; + FromJS(cx, argv[0], comment); + zos->SetComment(comment); + + return JS_TRUE; +} Property changes on: ps/trunk/source/tools/atlas/wxJS/io/zostream.cpp ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/io/fn.h =================================================================== --- ps/trunk/source/tools/atlas/wxJS/io/fn.h (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/io/fn.h (revision 5154) @@ -0,0 +1,56 @@ +/* + * wxJavaScript - fn.h + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: fn.h 598 2007-03-07 20:13:28Z fbraem $ + */ +#ifndef wxjs_io_fn_h +#define wxjs_io_fn_h + +// Common functions + +namespace wxjs +{ + namespace io + { + JSBool concatFiles(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval); + JSBool copyFile(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval); + JSBool renameFile(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval); + JSBool removeFile(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval); + JSBool fileExists(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval); + JSBool getCwd(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval); + JSBool getFreeDiskSpace(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval); + JSBool getTotalDiskSpace(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval); + JSBool getOSDirectory(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval); + JSBool isAbsolutePath(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval); + JSBool isWild(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval); + JSBool dirExists(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval); + JSBool matchWild(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval); + JSBool mkDir(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval); + JSBool rmDir(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval); + JSBool setWorkingDirectory(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval); + + // Process functions + JSBool execute(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval); + JSBool shell(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval); + }; // namespace io +}; // namespace wxjs +#endif //wxjs_io_fn_h Property changes on: ps/trunk/source/tools/atlas/wxJS/io/fn.h ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/io/process.cpp =================================================================== --- ps/trunk/source/tools/atlas/wxJS/io/process.cpp (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/io/process.cpp (revision 5154) @@ -0,0 +1,403 @@ +#include "precompiled.h" + +/* + * wxJavaScript - process.cpp + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: process.cpp 598 2007-03-07 20:13:28Z fbraem $ + */ +#include +#ifndef WX_PRECOMP + #include +#endif + +#include "../common/main.h" +#include "process.h" +#include "stream.h" +#include "istream.h" +#include "ostream.h" + +using namespace wxjs; +using namespace wxjs::io; + +Process::Process( JSContext *cx + , JSObject *obj + , int flags) : wxProcess(flags) +{ +} + +Process::~Process() +{ +} + +/*** + * process + * io + * + * The objects of this class are used in conjunction with the @wxExecute function. + * When a wxProcess object is passed to @wxExecute(), its @wxProcess#onTerminate event + * is called when the process terminates. This allows the program to be (asynchronously) + * notified about the process termination and also retrieve its exit status which is + * unavailable from @wxExecute in the case of asynchronous execution. + *

+ * wxProcess also supports IO redirection of the child process. For this, you have to call + * its @wxProcess#redirect method before passing it to @wxExecute. If the child process was launched successfully, + * @wxProcess#inputStream, @wxProcess#outputStream and @wxProcess#errorStream can then be used to retrieve the + * streams corresponding to the child process standard output, input and error output respectively. + *
+ */ +WXJS_INIT_CLASS(Process, "wxProcess", 1) + +/*** + * + * + * + * Turn on redirection + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * no error + * no such signal + * permission denied + * no such process + * another, unspecified error + * + * + */ +WXJS_BEGIN_CONSTANT_MAP(Process) + WXJS_CONSTANT(wxPROCESS_, DEFAULT) + WXJS_CONSTANT(wxPROCESS_, REDIRECT) +WXJS_END_CONSTANT_MAP() + +void Process::InitClass(JSContext *cx, JSObject *obj, JSObject *proto) +{ + JSConstDoubleSpec wxSignalType[] = + { + WXJS_CONSTANT(wx, SIGNONE) + WXJS_CONSTANT(wx, SIGHUP) + WXJS_CONSTANT(wx, SIGINT) + WXJS_CONSTANT(wx, SIGQUIT) + WXJS_CONSTANT(wx, SIGILL) + WXJS_CONSTANT(wx, SIGTRAP) + WXJS_CONSTANT(wx, SIGABRT) + WXJS_CONSTANT(wx, SIGEMT) + WXJS_CONSTANT(wx, SIGFPE) + WXJS_CONSTANT(wx, SIGKILL) + WXJS_CONSTANT(wx, SIGBUS) + WXJS_CONSTANT(wx, SIGSEGV) + WXJS_CONSTANT(wx, SIGSYS) + WXJS_CONSTANT(wx, SIGPIPE) + WXJS_CONSTANT(wx, SIGALRM) + WXJS_CONSTANT(wx, SIGTERM) + { 0 } + }; + + JSObject *constObj = JS_DefineObject(cx, obj, "wxSignal", + NULL, NULL, + JSPROP_READONLY | JSPROP_PERMANENT); + JS_DefineConstDoubles(cx, constObj, wxSignalType); + + JSConstDoubleSpec wxKillErrorType[] = + { + WXJS_CONSTANT(wxKILL_, OK) + WXJS_CONSTANT(wxKILL_, BAD_SIGNAL) + WXJS_CONSTANT(wxKILL_, ACCESS_DENIED) + WXJS_CONSTANT(wxKILL_, NO_PROCESS) + WXJS_CONSTANT(wxKILL_, ERROR) + { 0 } + }; + constObj = JS_DefineObject(cx, obj, "wxKillError", + NULL, NULL, + JSPROP_READONLY | JSPROP_PERMANENT); + JS_DefineConstDoubles(cx, constObj, wxKillErrorType); +} + +/*** + * + * + * Returns an input stream which corresponds to the standard error output (stderr) of the child process. + * + * + * It returns an input stream corresponding to the standard output stream of the subprocess. + * If it is null, you have not turned on the redirection + * + * + * It returns an output stream corresponding to the input stream of the subprocess. + * If it is null, you have not turned on the redirection. + * + * + * Returns true if there is data to be read on the child process standard error stream. + * + * + * Returns true if there is data to be read on the child process standard output stream. + * + * + * Returns true if the child process standard output stream is opened. + * + * + * Returns the process ID of the process launched by @wxProcess#open. + * + * + */ +WXJS_BEGIN_PROPERTY_MAP(Process) + WXJS_READONLY_PROPERTY(P_ERROR_STREAM, "errorStream") + WXJS_READONLY_PROPERTY(P_INPUT_STREAM, "inputStream") + WXJS_READONLY_PROPERTY(P_OUTPUT_STREAM, "outputStream") + WXJS_READONLY_PROPERTY(P_ERROR_AVAILABLE, "errorAvailable") + WXJS_READONLY_PROPERTY(P_INPUT_AVAILABLE, "inputAvailable") + WXJS_READONLY_PROPERTY(P_INPUT_OPENED, "inputOpened") + WXJS_READONLY_PROPERTY(P_PID, "pid") +WXJS_END_PROPERTY_MAP() + +bool Process::GetProperty(Process *p, JSContext *cx, JSObject *obj, int id, jsval *vp) +{ + switch(id) + { + case P_ERROR_STREAM: + { + wxInputStream *in = p->GetErrorStream(); + if ( in != NULL ) + { + *vp = InputStream::CreateObject(cx, new Stream(in)); + } + } + break; + case P_INPUT_STREAM: + { + wxInputStream *in = p->GetInputStream(); + if ( in != NULL ) + { + *vp = InputStream::CreateObject(cx, new Stream(in)); + } + } + break; + case P_OUTPUT_STREAM: + { + wxOutputStream *out = p->GetOutputStream(); + if ( out != NULL ) + { + *vp = OutputStream::CreateObject(cx, new Stream(out)); + } + } + break; + case P_ERROR_AVAILABLE: + *vp = ToJS(cx, p->IsErrorAvailable()); + break; + case P_INPUT_AVAILABLE: + *vp = ToJS(cx, p->IsInputAvailable()); + break; + case P_INPUT_OPENED: + *vp = ToJS(cx, p->IsInputOpened()); + break; + case P_PID: + *vp = ToJS(cx, p->GetPid()); + break; + } + return true; +} + +/*** + * + * + * + * + * + * Constructs a new wxProcess object. + * + * + */ +Process *Process::Construct(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, bool constructing) +{ + int flags = wxPROCESS_DEFAULT; + if ( argc == 1 ) + { + if ( ! FromJS(cx, argv[0], flags) ) + return NULL; + } + return new Process(cx, obj, flags); +} + +void Process::Destruct(JSContext *cx, Process *p) +{ +} + +WXJS_BEGIN_METHOD_MAP(Process) + WXJS_METHOD("closeOutput", closeOutput, 0) + WXJS_METHOD("detach", detach, 0) + WXJS_METHOD("redirect", redirect, 0) +WXJS_END_METHOD_MAP() + +/*** + * + * + * + * Closes the output stream (the one connected to the stdin of the child process). + * This function can be used to indicate to the child process that there is no more + * data to be read - usually, a filter program will only terminate when the input stream is closed. + * + * + */ +JSBool Process::closeOutput(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + Process *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + p->CloseOutput(); + + return JS_TRUE; +} + +/*** + * + * + * + * Normally, a wxProcess object is destroyed when it receives the notification about the process termination. + * However, it might happen that the parent application ends before the external process is terminated + * (e.g. a window from which this external process was launched is closed by the user) and in this case + * it should detach. + * + * + */ +JSBool Process::detach(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + Process *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + p->Detach(); + + return JS_TRUE; +} + +/*** + * + * + * + * Turns on redirection. @wxExecute will try to open a couple of pipes to catch the subprocess stdio. + * The caught input stream is returned by @wxProcess#outputStream as a non-seekable stream. The caught + * output stream is returned by @wxProcess#inputStream as a non-seekable stream. + * + * + */ +JSBool Process::redirect(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + Process *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + p->Redirect(); + + return JS_TRUE; +} + +WXJS_BEGIN_STATIC_METHOD_MAP(Process) + WXJS_METHOD("kill", kill, 1) + WXJS_METHOD("exists", exists, 1) +WXJS_END_METHOD_MAP() + +/*** + * + * + * The process ID + * The signal to send to the process + * Kill child processes? + * + * + * Send the specified signal to the given process. + * + * + */ +JSBool Process::kill(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + Process *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + if ( argc > 3 ) + argc = 3; + + int signal = wxSIGNONE; + bool killChildren = false; + switch(argc) + { + case 3: + if ( ! FromJS(cx, argv[2], killChildren) ) + break; + // Fall through + case 2: + if ( ! FromJS(cx, argv[1], signal ) ) + break; + // Fall through + default: + { + long pid; + if ( FromJS(cx, argv[0], pid) ) + { + *rval = ToJS(cx, (int) wxProcess::Kill(pid, (wxSignal) signal, killChildren ? wxKILL_CHILDREN : wxKILL_NOCHILDREN)); + return JS_TRUE; + } + } + } + return JS_FALSE; +} + +/*** + * + * + * Process ID + * + * + * Returns true if the given process exists in the system + * + * + */ +JSBool Process::exists(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + Process *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + int pid; + if ( FromJS(cx, argv[0], pid) ) + { + *rval = ToJS(cx, wxProcess::Exists(pid)); + return JS_TRUE; + } + return JS_FALSE; +} Property changes on: ps/trunk/source/tools/atlas/wxJS/io/process.cpp ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/lib/sysdep/unix/udbg_bfd.cpp =================================================================== --- ps/trunk/source/lib/sysdep/unix/udbg_bfd.cpp (revision 5153) +++ ps/trunk/source/lib/sysdep/unix/udbg_bfd.cpp (revision 5154) Property changes on: ps/trunk/source/lib/sysdep/unix/udbg_bfd.cpp ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/io/bostream.h =================================================================== --- ps/trunk/source/tools/atlas/wxJS/io/bostream.h (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/io/bostream.h (revision 5154) @@ -0,0 +1,51 @@ +/* + * wxJavaScript - bostream.h + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: bostream.h 716 2007-05-20 17:57:22Z fbraem $ + */ +#ifndef wxjs_io_bostream_h +#define wxjs_io_bostream_h + +namespace wxjs +{ + namespace io + { + + class BufferedOutputStream : public wxBufferedOutputStream + , public ApiWrapper + , public wxClientDataContainer + { + public: + BufferedOutputStream(wxOutputStream &s, wxStreamBuffer *buffer = NULL); + virtual ~BufferedOutputStream() + { + } + + static Stream* Construct(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, bool constructing); + static void Destruct(JSContext *cx, Stream *p); + + // Keep a reference to the stream to avoid deletion. + Stream m_refStream; + }; + }; // namespace io +}; // namespace wxjs +#endif // wxjs_io_bostream_h Property changes on: ps/trunk/source/tools/atlas/wxJS/io/bostream.h ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/io/zipentry.cpp =================================================================== --- ps/trunk/source/tools/atlas/wxJS/io/zipentry.cpp (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/io/zipentry.cpp (revision 5154) @@ -0,0 +1,406 @@ +#include "precompiled.h" + +/* + * wxJavaScript - zipentry.cpp + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: zipentry.cpp 598 2007-03-07 20:13:28Z fbraem $ + */ +#include +#ifndef WX_PRECOMP + #include +#endif + +#include "../common/main.h" +#include "zipentry.h" + +using namespace wxjs; +using namespace wxjs::io; + +/*** + * zipentry + * io + * + * Holds the meta-data for an entry in a zip. + * + */ + +WXJS_INIT_CLASS(ZipEntry, "wxZipEntry", 0) + +/*** + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * Compression Mode. wxZipMethod is ported as a separate JavaScript class. + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * Originating File-System. wxZipSystem is ported as a separate JavaScript object. + * + * + * + * + * + * + * + * + * + * + * wxZipAttributes is ported as a separate JavaScript object + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * wxZipFlags is ported as a separate JavaScript object. + * + * + * + * + */ +void ZipEntry::InitClass(JSContext *cx, JSObject *obj, JSObject *proto) +{ + JSConstDoubleSpec wxZipMethodMap[] = + { + WXJS_CONSTANT(wxZIP_METHOD_, STORE) + WXJS_CONSTANT(wxZIP_METHOD_, SHRINK) + WXJS_CONSTANT(wxZIP_METHOD_, REDUCE1) + WXJS_CONSTANT(wxZIP_METHOD_, REDUCE2) + WXJS_CONSTANT(wxZIP_METHOD_, REDUCE3) + WXJS_CONSTANT(wxZIP_METHOD_, REDUCE4) + WXJS_CONSTANT(wxZIP_METHOD_, IMPLODE) + WXJS_CONSTANT(wxZIP_METHOD_, TOKENIZE) + WXJS_CONSTANT(wxZIP_METHOD_, DEFLATE) + WXJS_CONSTANT(wxZIP_METHOD_, DEFLATE64) + WXJS_CONSTANT(wxZIP_METHOD_, BZIP2) + WXJS_CONSTANT(wxZIP_METHOD_, DEFAULT) + { 0 } + }; + + JSObject *constObj = JS_DefineObject(cx, obj, "wxZipMethod", + NULL, NULL, + JSPROP_READONLY | JSPROP_PERMANENT); + JS_DefineConstDoubles(cx, constObj, wxZipMethodMap); + + JSConstDoubleSpec wxZipSystemMap[] = + { + WXJS_CONSTANT(wxZIP_SYSTEM_, MSDOS) + WXJS_CONSTANT(wxZIP_SYSTEM_, AMIGA) + WXJS_CONSTANT(wxZIP_SYSTEM_, OPENVMS) + WXJS_CONSTANT(wxZIP_SYSTEM_, UNIX) + WXJS_CONSTANT(wxZIP_SYSTEM_, VM_CMS) + WXJS_CONSTANT(wxZIP_SYSTEM_, ATARI_ST) + WXJS_CONSTANT(wxZIP_SYSTEM_, OS2_HPFS) + WXJS_CONSTANT(wxZIP_SYSTEM_, MACINTOSH) + WXJS_CONSTANT(wxZIP_SYSTEM_, Z_SYSTEM) + WXJS_CONSTANT(wxZIP_SYSTEM_, CPM) + WXJS_CONSTANT(wxZIP_SYSTEM_, WINDOWS_NTFS) + WXJS_CONSTANT(wxZIP_SYSTEM_, MVS) + WXJS_CONSTANT(wxZIP_SYSTEM_, VSE) + WXJS_CONSTANT(wxZIP_SYSTEM_, ACORN_RISC) + WXJS_CONSTANT(wxZIP_SYSTEM_, VFAT) + WXJS_CONSTANT(wxZIP_SYSTEM_, ALTERNATE_MVS) + WXJS_CONSTANT(wxZIP_SYSTEM_, BEOS) + WXJS_CONSTANT(wxZIP_SYSTEM_, TANDEM) + WXJS_CONSTANT(wxZIP_SYSTEM_, OS_400) + { 0 } + }; + + constObj = JS_DefineObject(cx, obj, "wxZipSystem", + NULL, NULL, + JSPROP_READONLY | JSPROP_PERMANENT); + JS_DefineConstDoubles(cx, constObj, wxZipSystemMap); + + JSConstDoubleSpec wxZipAttributes[] = + { + WXJS_CONSTANT(wxZIP_A_, RDONLY) + WXJS_CONSTANT(wxZIP_A_, HIDDEN) + WXJS_CONSTANT(wxZIP_A_, SYSTEM) + WXJS_CONSTANT(wxZIP_A_, SUBDIR) + WXJS_CONSTANT(wxZIP_A_, ARCH) + WXJS_CONSTANT(wxZIP_A_, MASK) + { 0 } + }; + constObj = JS_DefineObject(cx, obj, "wxZipAttributes", + NULL, NULL, + JSPROP_READONLY | JSPROP_PERMANENT); + JS_DefineConstDoubles(cx, constObj, wxZipAttributes); + + JSConstDoubleSpec wxZipFlags[] = + { + WXJS_CONSTANT(wxZIP_, ENCRYPTED) + WXJS_CONSTANT(wxZIP_, DEFLATE_NORMAL) + WXJS_CONSTANT(wxZIP_, DEFLATE_EXTRA) + WXJS_CONSTANT(wxZIP_, DEFLATE_FAST) + WXJS_CONSTANT(wxZIP_, DEFLATE_SUPERFAST) + WXJS_CONSTANT(wxZIP_, DEFLATE_MASK) + WXJS_CONSTANT(wxZIP_, SUMS_FOLLOW) + WXJS_CONSTANT(wxZIP_, ENHANCED) + WXJS_CONSTANT(wxZIP_, PATCH) + WXJS_CONSTANT(wxZIP_, STRONG_ENC) + WXJS_CONSTANT(wxZIP_, UNUSED) + WXJS_CONSTANT(wxZIP_, RESERVED) + { 0 } + }; + constObj = JS_DefineObject(cx, obj, "wxZipFlags", + NULL, NULL, + JSPROP_READONLY | JSPROP_PERMANENT); + JS_DefineConstDoubles(cx, constObj, wxZipFlags); +} + +/*** + * + * + * + * + * + * + * + * Creates a new wxZipEntry + * + * + */ +wxZipEntry* ZipEntry::Construct(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, bool constructing) +{ + off_t size = wxInvalidOffset; + wxDateTime dt = wxDateTime::Now(); + wxString name = wxEmptyString; + + switch(argc) + { + case 3: + if ( ! FromJS(cx, argv[2], size) ) + return NULL; + // Fall through + case 2: + if ( ! FromJS(cx, argv[1], dt) ) + return NULL; + // Fall through + case 1: + FromJS(cx, argv[0], name); + break; + } + + wxZipEntry* entry = new wxZipEntry(name, dt, size); + entry->SetMethod(wxZIP_METHOD_DEFAULT); + return entry; +} + +/*** + * + * + * Get/Set a short comment for this entry. + * + * + * The compressed size of this entry in bytes. + * + * + * CRC32 for this entry's data. + * + * + * Attributes of the entry. See @wxZipEntry#wxZipAttributes. + * + * + * The extra field is used to store platform or application specific data. + * See Pkware's document 'appnote.txt' for information on its format. + * + * + * see @wxZipEntry#wxZipFlags + * + * + * The extra field is used to store platform or application specific data. + * See Pkware's document 'appnote.txt' for information on its format. + * + * + * The compression method. See @wxZipEntry#wxZipMethod. + * + * + * + * The originating file-system. The default constructor sets this to + * wxZipSystem.MSDOS. Set it to wxZipSystem.UNIX in order to be able + * to store unix permissions using @wxZipEntry#mode. + * + * + * Returns true if @wxZipEntry#systemMadeBy is a flavour of unix. + * + * + * Indicates that this entry's data is text in an 8-bit encoding. + * + * + */ +WXJS_BEGIN_PROPERTY_MAP(ZipEntry) + WXJS_PROPERTY(P_COMMENT, "comment") + WXJS_READONLY_PROPERTY(P_COMPRESSED_SIZE, "compressedSize") + WXJS_READONLY_PROPERTY(P_CRC, "crc") + WXJS_READONLY_PROPERTY(P_EXTERNAL_ATTR, "externalAttributes") + WXJS_PROPERTY(P_EXTRA, "extra") + WXJS_READONLY_PROPERTY(P_FLAGS, "flags") + WXJS_PROPERTY(P_LOCAL_EXTRA, "localExtra") + WXJS_PROPERTY(P_MODE, "mode") + WXJS_PROPERTY(P_METHOD, "method") + WXJS_PROPERTY(P_SYSTEM_MADE_BY, "systemMadeBy") + WXJS_READONLY_PROPERTY(P_MADE_BY_UNIX, "madeByUnix") + WXJS_PROPERTY(P_TEXT, "text") +WXJS_END_PROPERTY_MAP() + +bool ZipEntry::GetProperty(wxZipEntry *p, JSContext *cx, JSObject *obj, int id, jsval *vp) +{ + switch (id) + { + case P_COMMENT: + *vp = ToJS(cx, p->GetComment()); + break; + case P_COMPRESSED_SIZE: + *vp = ToJS(cx, p->GetCompressedSize()); + break; + case P_CRC: + *vp = ToJS(cx, p->GetCrc()); + break; + case P_EXTERNAL_ATTR: + *vp = ToJS(cx, p->GetExternalAttributes()); + break; + case P_EXTRA: + *vp = ToJS(cx, wxString::FromAscii(p->GetExtra())); + break; + case P_FLAGS: + *vp = ToJS(cx, p->GetFlags()); + break; + case P_LOCAL_EXTRA: + *vp = ToJS(cx, wxString::FromAscii(p->GetLocalExtra())); + break; + case P_METHOD: + *vp = ToJS(cx, p->GetMethod()); + break; + case P_MODE: + *vp = ToJS(cx, p->GetMode()); + break; + case P_SYSTEM_MADE_BY: + *vp = ToJS(cx, p->GetSystemMadeBy()); + break; + case P_MADE_BY_UNIX: + *vp = ToJS(cx, p->IsMadeByUnix()); + break; + case P_TEXT: + *vp = ToJS(cx, p->IsText()); + break; + } + return true; +} + +bool ZipEntry::SetProperty(wxZipEntry *p, JSContext *cx, JSObject *obj, int id, jsval *vp) +{ + switch (id) + { + case P_EXTRA: + { + wxString extra; + FromJS(cx, *vp, extra); + p->SetExtra(extra.ToAscii(), extra.Length()); + } + break; + case P_LOCAL_EXTRA: + { + wxString extra; + FromJS(cx, *vp, extra); + p->SetLocalExtra(extra.ToAscii(), extra.Length()); + } + break; + case P_MODE: + { + int mode; + if ( FromJS(cx, *vp, mode) ) + { + p->SetMode(mode); + } + break; + } + case P_METHOD: + { + int method; + if ( FromJS(cx, *vp, method) ) + { + p->SetMethod(method); + } + } + case P_SYSTEM_MADE_BY: + { + int madeBy; + if ( FromJS(cx, *vp, madeBy) ) + { + p->SetSystemMadeBy(madeBy); + } + break; + } + case P_TEXT: + { + bool text; + if ( FromJS(cx, *vp, text) ) + { + p->SetIsText(text); + } + break; + } + } + return true; +} Property changes on: ps/trunk/source/tools/atlas/wxJS/io/zipentry.cpp ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/io/sockevth.cpp =================================================================== --- ps/trunk/source/tools/atlas/wxJS/io/sockevth.cpp (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/io/sockevth.cpp (revision 5154) @@ -0,0 +1,67 @@ +#include "precompiled.h" + +/* + * wxJavaScript - sockevth.cpp + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: sockevth.cpp 716 2007-05-20 17:57:22Z fbraem $ + */ +#include +#ifndef WX_PRECOMP + #include +#endif +#include + +#include "../common/main.h" +#include "../common/jsutil.h" + +#include "sockevth.h" + +using namespace wxjs; +using namespace wxjs::io; + +BEGIN_EVENT_TABLE (SocketEventHandler, wxEvtHandler) + EVT_SOCKET(-1, SocketEventHandler::OnSocketEvent) +END_EVENT_TABLE() + +void SocketEventHandler::OnSocketEvent(wxSocketEvent &event) +{ + JavaScriptClientData *data + = dynamic_cast(GetClientObject()); + if ( data == NULL ) + return; + + JSContext *cx = data->GetContext(); + JSObject *obj = data->GetObject(); + jsval rval; + switch(event.GetSocketEvent()) + { + case wxSOCKET_INPUT : + CallFunctionProperty(cx, obj, "onInput", 0, NULL, &rval); + break; + case wxSOCKET_LOST : + CallFunctionProperty(cx, obj, "onLost", 0, NULL, &rval); + break; + case wxSOCKET_CONNECTION : + CallFunctionProperty(cx, obj, "onConnection", 0, NULL, &rval); + break; + } +} Property changes on: ps/trunk/source/tools/atlas/wxJS/io/sockevth.cpp ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/io/jsstream.h =================================================================== --- ps/trunk/source/tools/atlas/wxJS/io/jsstream.h (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/io/jsstream.h (revision 5154) @@ -0,0 +1,129 @@ +/* + * wxJavaScript - jsstream.h + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: jsstream.h 598 2007-03-07 20:13:28Z fbraem $ + */ +#ifndef _wxjs_io_jsstream_h +#define _wxjs_io_jsstream_h + +#include + +namespace wxjs +{ + namespace io + { + + // Reference counting for stream classes. + // Why? because some streams are members of other streams. When + // these streams are gc'ed by SpiderMonkey before the stream that owns a stream, + // access violations can be the result. This is the case in wxBufferedOutputStream + // where the stream is flushed in the destructor. + class StreamRef : public wxObjectRefData + { + public: + StreamRef(wxStreamBase *stream) : wxObjectRefData(), m_stream(stream) + { + } + virtual ~StreamRef() + { + delete m_stream; + } + + wxStreamBase *GetStream() + { + return m_stream; + } + private: + wxStreamBase *m_stream; + }; + + // This class will be the private data for each stream JavaScript object. + class Stream : public wxObject + { + public: + inline Stream(bool owner = true) : m_owner(owner), m_obj(NULL) + { + } + + inline Stream(wxStreamBase *stream, bool owner = true) : m_owner(owner), m_obj(NULL) + { + m_refData = new StreamRef(stream); + } + + inline Stream(const Stream& stream) : wxObject(stream) + { + Ref(stream); + m_owner = stream.m_owner; + m_obj = stream.m_obj; + } + + inline bool operator == (const Stream& stream) const + { + return m_refData == stream.m_refData; + } + inline bool operator != (const Stream& stream) const + { + return m_refData != stream.m_refData; + } + + inline Stream& operator = (const Stream& stream) + { + if ( *this == stream ) + return (*this); + else + { + Ref(stream); + return *this; + } + } + + inline void SetObject(JSObject *obj) + { + m_obj = obj; + } + + inline JSObject *GetObject() + { + return m_obj; + } + + virtual ~Stream() + { + } + + wxStreamBase* GetStream() + { + return ((StreamRef *) m_refData)->GetStream(); + } + + // Do we own the stream (=default)? Or is another class + // responsible for destroying me? (like wxHTTP for example) + bool IsOwner() const { return m_owner; } + + private: + bool m_owner; + + JSObject *m_obj; + }; + }; // namespace io +}; // namespace wxjs +#endif // _wxjs_io_jsstream_h Property changes on: ps/trunk/source/tools/atlas/wxJS/io/jsstream.h ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/common/evtconn.h =================================================================== --- ps/trunk/source/tools/atlas/wxJS/common/evtconn.h (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/common/evtconn.h (revision 5154) @@ -0,0 +1,77 @@ +/* + * wxJavaScript - evtconn.h + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: evtconn.h 680 2007-04-20 10:13:02Z jupeters $ + */ +#ifndef _wxjs_evt_conn_h +#define _wxjs_evt_conn_h + +// A helper class to connect an event to a method of a class +// This is used to avoid a big if-statement for selecting +// the correct event connector +// An event connector is a function that connects an event + +#include + +namespace wxjs +{ + template + class EventConnector + { + public: + typedef void (*ConnectEventFn)(T_Priv *p, bool connect); + typedef std::map ConnectEventMap; + + static void AddConnector(const wxString &event, ConnectEventFn fun) + { + m_eventMap[event] = fun; + } + + static bool ConnectEvent(T_Priv *p, const wxString &name, bool connect) + { + #if (__GNUC__ >= 4) + typename ConnectEventMap::iterator it = m_eventMap.find(name); + #else + ConnectEventMap::iterator it = m_eventMap.find(name); + #endif + if ( it != m_eventMap.end() ) + { + it->second(p, connect); + return true; + } + return false; + } + + static ConnectEventMap m_eventMap; + }; + +#if (__GNUC__ >= 4) + #define WXJS_INIT_EVENT_MAP(class) template<> EventConnector::ConnectEventMap \ + EventConnector::m_eventMap = EventConnector::ConnectEventMap(); +#else + #define WXJS_INIT_EVENT_MAP(class) EventConnector::ConnectEventMap \ + EventConnector::m_eventMap; +#endif + +} // end namespace wxjs + +#endif // _wxjs_evt_conn_h Property changes on: ps/trunk/source/tools/atlas/wxJS/common/evtconn.h ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/common/strsptr.h =================================================================== --- ps/trunk/source/tools/atlas/wxJS/common/strsptr.h (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/common/strsptr.h (revision 5154) @@ -0,0 +1,97 @@ +/* + * wxJavaScript - strsptr.h + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: strsptr.h 598 2007-03-07 20:13:28Z fbraem $ + */ +#ifndef _STRINGSPTR_H +#define _STRINGSPTR_H + +///////////////////////////////////////////////////////////////////////////// +// Name: strsptr.h +// Purpose: Proxy for a pointer to an array of wxString elements. +// Use this class to convert a JavaScript array of strings into +// a wxString array. +// +// The pointer returned to the array is only valid in the scoop +// of this object. When the object goes out of scoop, the array +// will be destroyed. +// +// Author: Franky Braem +// Modified by: +// Created: 11.09.02 +// Copyright: (c) 2001-2002 Franky Braem +// Licence: LGPL +///////////////////////////////////////////////////////////////////////////// + +namespace wxjs +{ + + class StringsPtr + { + public: + + StringsPtr() : m_strings(NULL), m_count(0) + { + } + + virtual ~StringsPtr() + { + delete[] m_strings; + } + + unsigned int GetCount() const + { + return m_count; + } + + const wxString* GetStrings() const + { + return m_strings; + } + + private: + + wxString& operator[](unsigned int i) + { + return m_strings[i]; + } + + void Allocate(unsigned int count) + { + if ( m_strings != NULL ) + delete[] m_strings; + + m_count = count; + m_strings = new wxString[m_count]; + } + + template friend bool FromJS(JSContext*cx, jsval v, T &to); + + // Avoid copying + StringsPtr(const StringsPtr&); + + wxString *m_strings; + unsigned int m_count; + }; +}; + +#endif //_STRINGSPTR_H Property changes on: ps/trunk/source/tools/atlas/wxJS/common/strsptr.h ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/common/script.h =================================================================== --- ps/trunk/source/tools/atlas/wxJS/common/script.h (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/common/script.h (revision 5154) @@ -0,0 +1,76 @@ +/* + * wxJavaScript - script.h + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: script.h 598 2007-03-07 20:13:28Z fbraem $ + */ +#ifndef _wxjs_script_h +#define _wxjs_script_h + +#include + +namespace wxjs +{ + class ScriptSource + { + public: + ScriptSource() + { + } + + ScriptSource(const ScriptSource ©); + + virtual ~ScriptSource() + { + } + + virtual void SetSource(const wxString &source); + + wxString GetName() const + { + return m_name; + } + + void SetName(const wxString &name) + { + m_name = name; + } + + virtual wxString GetSource() const; + + wxString GetFile() const + { + return m_file; + } + + // Sets the filename and reads the source from it + virtual void SetFile(const wxString &file, wxMBConv &conv = wxConvUTF8); + + // Sets the filename + virtual void SetFilename(const wxString &name) { m_file = name; } + + private: + wxString m_file; + wxString m_source; + wxString m_name; + }; +}; // namespace wxjs +#endif // _wxjs_script_h Property changes on: ps/trunk/source/tools/atlas/wxJS/common/script.h ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/io/mistream.cpp =================================================================== --- ps/trunk/source/tools/atlas/wxJS/io/mistream.cpp (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/io/mistream.cpp (revision 5154) @@ -0,0 +1,109 @@ +#include "precompiled.h" + +/* + * wxJavaScript - mistream.cpp + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: mistream.cpp 716 2007-05-20 17:57:22Z fbraem $ + */ +#include +#ifndef WX_PRECOMP + #include +#endif + +#include "../common/main.h" + +#include "stream.h" +#include "mistream.h" + +#include "../ext/wxjs_ext.h" + +using namespace wxjs; +using namespace wxjs::io; + +MemoryInputStream::MemoryInputStream(char *data + , size_t len) : wxMemoryInputStream(data, len) + , m_data(data) +{ +} + +MemoryInputStream::~MemoryInputStream() +{ + delete[] m_data; +} + +/*** + * mistream + * io + * + * wxMemoryInputStream allows an application to create an input stream + * in which the bytes read are supplied by a memory buffer or a string. + * See also @wxMemoryOutputStream. + * + */ +WXJS_INIT_CLASS(MemoryInputStream, "wxMemoryInputStream", 1) + +/*** + * + * + * + * + * + * + * + * + * Constructs a new wxMemoryInputStream object. A copy is created + * of the data and passed to the stream. + *

+ * When a String is used, the string is stored as UTF-16! + *
+ *
+ */ +Stream* MemoryInputStream::Construct(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, bool constructing) +{ + if ( JSVAL_IS_OBJECT(argv[0]) ) + { + wxMemoryBuffer* buffer = wxjs::ext::GetMemoryBuffer(cx, JSVAL_TO_OBJECT(argv[0])); + if ( buffer != NULL ) + { + char *dataPtr = new char[buffer->GetDataLen()]; + memcpy(dataPtr, buffer->GetData(), buffer->GetDataLen()); + MemoryInputStream *mis = new MemoryInputStream(dataPtr, (size_t) buffer->GetDataLen()); + mis->SetClientObject(new JavaScriptClientData(cx, obj, false, true)); + return new Stream(mis); + } + } + + wxString data; + FromJS(cx, argv[0], data); + + wxMBConvUTF16 utf16; + int length = utf16.WC2MB(NULL, data, 0); + if ( length > 0 ) + { + char *buffer = new char[length + utf16.GetMBNulLen()]; + length = utf16.WC2MB(buffer, data, length + utf16.GetMBNulLen()); + MemoryInputStream *mis = new MemoryInputStream(buffer, length); + mis->SetClientObject(new JavaScriptClientData(cx, obj, false, true)); + return new Stream(mis); + } + return NULL; +} Property changes on: ps/trunk/source/tools/atlas/wxJS/io/mistream.cpp ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/io/file.h =================================================================== --- ps/trunk/source/tools/atlas/wxJS/io/file.h (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/io/file.h (revision 5154) @@ -0,0 +1,83 @@ +/* + * wxJavaScript - file.h + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: file.h 598 2007-03-07 20:13:28Z fbraem $ + */ +#ifndef _WXJS_FILE_H +#define _WXJS_FILE_H + +///////////////////////////////////////////////////////////////////////////// +// Name: file.h +// Purpose: Ports wxFile to JavaScript +// Author: Franky Braem +// Modified by: +// Created: 30.08.02 +// Copyright: (c) 2001-2002 Franky Braem +// Licence: LGPL +///////////////////////////////////////////////////////////////////////////// + +#include + +namespace wxjs +{ + namespace io + { + class File : public ApiWrapper + { + public: + + static bool GetProperty(wxFile *f, JSContext *cx, JSObject *obj, int id, jsval *vp); + + enum + { + P_EOF + , P_OPENED + , P_LENGTH + , P_TELL + , P_KIND + }; + + WXJS_DECLARE_PROPERTY_MAP() + WXJS_DECLARE_METHOD_MAP() + WXJS_DECLARE_CONSTANT_MAP() + WXJS_DECLARE_STATIC_METHOD_MAP() + + static void InitClass(JSContext *cx, JSObject *obj, JSObject *proto); + + static wxFile *Construct(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, bool constructing); + + static JSBool attach(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval); + static JSBool detach(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval); + static JSBool close(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval); + static JSBool create(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval); + static JSBool flush(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval); + static JSBool open(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval); + static JSBool read(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval); + static JSBool seek(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval); + static JSBool seekEnd(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval); + static JSBool write(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval); + static JSBool exists(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval); + static JSBool access(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval); + }; + }; // namespace io +}; // namespace wxjs +#endif Property changes on: ps/trunk/source/tools/atlas/wxJS/io/file.h ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/io/filename.h =================================================================== --- ps/trunk/source/tools/atlas/wxJS/io/filename.h (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/io/filename.h (revision 5154) @@ -0,0 +1,148 @@ +/* + * wxJavaScript - filename.h + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: filename.h 598 2007-03-07 20:13:28Z fbraem $ + */ +#ifndef _WXJSFileName_H +#define _WXJSFileName_H + +///////////////////////////////////////////////////////////////////////////// +// Name: filename.h +// Purpose: wxJSFileName ports wxFileName to JavaScript +// Author: Franky Braem +// Modified by: +// Created: 14-01-2003 +// Copyright: (c) 2001-2003 Franky Braem +// Licence: LGPL +///////////////////////////////////////////////////////////////////////////// + +#include + +namespace wxjs +{ + namespace io + { + class FileName : public ApiWrapper + { + public: + /** + * Callback for retrieving properties of wxFileName + */ + static bool GetProperty(wxFileName *p, JSContext *cx, JSObject *obj, int id, jsval *vp); + + /** + * Callback for setting properties + */ + static bool SetProperty(wxFileName *p, JSContext *cx, JSObject *obj, int id, jsval *vp); + + static bool GetStaticProperty(JSContext *cx, int id, jsval *vp); + static bool SetStaticProperty(JSContext *cx, int id, jsval *vp); + + static void InitClass(JSContext *cx, JSObject *obj, JSObject *proto); + + /** + * Callback for when a wxFileName object is created + */ + static wxFileName* Construct(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, bool constructing); + + static JSBool appendDir(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval); + static JSBool assign(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval); + static JSBool assignCwd(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval); + static JSBool assignDir(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval); + static JSBool assignHomeDir(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval); + static JSBool assignTempFileName(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval); + static JSBool clear(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval); + static JSBool getFullPath(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval); + static JSBool getPath(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval); + static JSBool getPathSeparator(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval); + static JSBool getPathSeparators(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval); + static JSBool getTimes(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval); + static JSBool setTimes(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval); + static JSBool getVolumeSeparator(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval); + static JSBool insertDir(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval); + static JSBool isAbsolute(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval); + static JSBool isCaseSensitive(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval); + static JSBool isPathSeparator(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval); + static JSBool isRelative(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval); + static JSBool makeRelativeTo(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval); + static JSBool mkdir(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval); + static JSBool normalize(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval); + static JSBool prependDir(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval); + static JSBool removeDir(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval); + static JSBool removeLastDir(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval); + static JSBool rmdir(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval); + static JSBool sameAs(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval); + static JSBool setCwd(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval); + static JSBool touch(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval); + + WXJS_DECLARE_PROPERTY_MAP() + WXJS_DECLARE_METHOD_MAP() + WXJS_DECLARE_STATIC_PROPERTY_MAP() + WXJS_DECLARE_STATIC_METHOD_MAP() + + static JSBool createTempFileName(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval); + static JSBool dirExists(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval); + static JSBool dirName(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval); + static JSBool fileExists(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval); + static JSBool fileName(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval); + static JSBool getCwd(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval); + static JSBool getFormat(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval); + static JSBool smkdir(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval); + static JSBool srmdir(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval); + static JSBool splitPath(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval); + + /** + * Property Ids. + */ + enum + { + P_CWD = -128 + , P_DIRS + , P_DIR_COUNT + , P_DIR_EXISTS + , P_EXT + , P_HAS_EXT + , P_HAS_NAME + , P_HAS_VOLUME + , P_FILE_EXISTS + , P_FULL_NAME + , P_FULL_PATH + , P_HOME_DIR + , P_LONG_PATH + , P_MODIFICATION_TIME + , P_NAME + , P_PATH_SEPARATOR + , P_PATH_SEPARATORS + , P_SHORT_PATH + , P_ACCESS_TIME + , P_CREATE_TIME + , P_VOLUME + , P_VOLUME_SEPARATOR + , P_OK + , P_IS_DIR + }; + + static bool SetDate(JSContext *cx, jsval v, const wxDateTime &date); + }; + }; // namespace io +}; // namespace wxjs +#endif //_WXJSFileName_H Property changes on: ps/trunk/source/tools/atlas/wxJS/io/filename.h ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/io/stream.cpp =================================================================== --- ps/trunk/source/tools/atlas/wxJS/io/stream.cpp (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/io/stream.cpp (revision 5154) @@ -0,0 +1,88 @@ +#include "precompiled.h" + +/* + * wxJavaScript - stream.cpp + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: stream.cpp 598 2007-03-07 20:13:28Z fbraem $ + */ +// stream.cpp + +#include +#ifndef WX_PRECOMP + #include +#endif + +#include "../common/main.h" + +#include "stream.h" + +using namespace wxjs; +using namespace wxjs::io; + +/*** + * streambase + * io + * + * wxStreamBase is a prototype class. It's the prototype of the Stream classes. + * See @wxInputStream, @wxOutputStream. + * + */ +WXJS_INIT_CLASS(StreamBase, "wxStreamBase", 0) + +/*** + * + * + * Returns the last error. + * + * + * Returns true if no error occurred. + * + * + * Returns the size of the stream. For example, for a file it is the size of the file. + * There are streams which do not have size by definition, such as socket streams. + * In these cases, size returns 0. + * + * + */ +WXJS_BEGIN_PROPERTY_MAP(StreamBase) + WXJS_READONLY_PROPERTY(P_OK, "ok") + WXJS_READONLY_PROPERTY(P_SIZE, "size") + WXJS_READONLY_PROPERTY(P_LAST_ERROR, "lastError") +WXJS_END_PROPERTY_MAP() + +bool StreamBase::GetProperty(Stream *p, JSContext *cx, JSObject *obj, int id, jsval *vp) +{ + wxStreamBase *stream = p->GetStream(); + switch (id) + { + case P_OK: + *vp = ToJS(cx, stream->IsOk()); + break; + case P_SIZE: + *vp = ToJS(cx, (long) stream->GetSize()); + break; + case P_LAST_ERROR: + *vp = ToJS(cx, (int) stream->GetLastError()); + break; + } + return true; +} Property changes on: ps/trunk/source/tools/atlas/wxJS/io/stream.cpp ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/common/wxjs.h =================================================================== --- ps/trunk/source/tools/atlas/wxJS/common/wxjs.h (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/common/wxjs.h (revision 5154) @@ -0,0 +1,38 @@ +/* + * wxJavaScript - wxjs.h + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: wxjs.h 598 2007-03-07 20:13:28Z fbraem $ + */ +#ifndef WXJS_H_ +#define WXJS_H_ + +#include +#ifdef WXJSDLL_BUILD + #define WXJSAPI WXEXPORT +#else + #define WXJSAPI WXIMPORT +#endif +extern "C" WXJSAPI bool wxJS_InitClass(JSContext *cx, JSObject *global); +extern "C" WXJSAPI bool wxJS_InitObject(JSContext *cx, JSObject *obj); +extern "C" WXJSAPI void wxJS_Destroy(); + +#endif /*WXJS_H_*/ Property changes on: ps/trunk/source/tools/atlas/wxJS/common/wxjs.h ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/common/defs.h =================================================================== --- ps/trunk/source/tools/atlas/wxJS/common/defs.h (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/common/defs.h (revision 5154) @@ -0,0 +1,38 @@ +/* + * wxJavaScript - defs.h + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: defs.h 714 2007-05-16 20:24:49Z fbraem $ + */ +#ifndef _wxjs_defs_h +#define _wxjs_defs_h + +#define wxJS_MAJOR_VERSION 0 +#define wxJS_MINOR_VERSION 9 +#define wxJS_RELEASE_NUMBER 7 +#define wxJS_STR_VERSION wxT("0.9.7") + +// Encoding used internally. SpiderMonkey uses UTF-16 +#define wxJS_INTERNAL_ENCODING wxT("UTF-16") +// Default encoding to use when reading files, ... +#define wxJS_EXTERNAL_ENCODING wxT("UTF-8") + +#endif // _wxjs_defs_h Property changes on: ps/trunk/source/tools/atlas/wxJS/common/defs.h ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/common/main.h =================================================================== --- ps/trunk/source/tools/atlas/wxJS/common/main.h (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/common/main.h (revision 5154) @@ -0,0 +1,45 @@ +/* + * wxJavaScript - main.h + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: main.h 714 2007-05-16 20:24:49Z fbraem $ + */ +#ifndef _wxJS_H +#define _wxJS_H + +#ifdef _MSC_VER + // Turn off identifier was truncated warning + #pragma warning(disable:4786) + // Turn off deprecated warning + #pragma warning(disable:4996) +#endif + +#include + +#include "defs.h" +#include "clntdata.h" +#include "apiwrap.h" +#include "type.h" + +static const int WXJS_CONTEXT_SIZE = 32768; +static const int WXJS_START_PROPERTY_ID = -128; + +#endif //_wxJS_H Property changes on: ps/trunk/source/tools/atlas/wxJS/common/main.h ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/io/socksrv.h =================================================================== --- ps/trunk/source/tools/atlas/wxJS/io/socksrv.h (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/io/socksrv.h (revision 5154) @@ -0,0 +1,58 @@ +/* + * wxJavaScript - socksrv.h + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: socksrv.h 598 2007-03-07 20:13:28Z fbraem $ + */ +#ifndef _wxjs_io_sockserver_h +#define _wxjs_io_sockserver_h + +#include +#include + +namespace wxjs +{ + namespace io + { + class SocketEventHandler; + + class SocketServer : public ApiWrapper + , public wxSocketServer + { + public: + SocketServer(JSContext *cx, JSObject *obj, wxSockAddress &address, wxSocketFlags flags = wxSOCKET_NONE); + virtual ~SocketServer(); + + static wxSocketServer *Construct(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, bool constructing); + static void Destruct(JSContext *cx, wxSocketServer *p); + + WXJS_DECLARE_METHOD_MAP() + + static JSBool accept(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval); + static JSBool acceptWith(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval); + static JSBool waitForAccept(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval); + + private: + SocketEventHandler *m_evtHandler; + }; + }; // namespace io +}; // namespace wxjs +#endif // _wxjs_io_sockserver_h Property changes on: ps/trunk/source/tools/atlas/wxJS/io/socksrv.h ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/io/aistream.cpp =================================================================== --- ps/trunk/source/tools/atlas/wxJS/io/aistream.cpp (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/io/aistream.cpp (revision 5154) @@ -0,0 +1,102 @@ +#include "precompiled.h" + +/* + * wxJavaScript - aistream.cpp + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: aistream.cpp 598 2007-03-07 20:13:28Z fbraem $ + */ +#include +#ifndef WX_PRECOMP + #include +#endif +#include + +#include "../common/main.h" +#include "stream.h" +#include "aistream.h" +#include "archentry.h" + +using namespace wxjs; +using namespace wxjs::io; + +/*** + * aistream + * io + * + * wxArchiveInputStream is a prototype object for archive input streams such + * as @wxZipInputStream. + * + */ + +WXJS_INIT_CLASS(ArchiveInputStream, "wxArchiveInputStream", 0) + +WXJS_BEGIN_METHOD_MAP(ArchiveInputStream) + WXJS_METHOD("closeEntry", closeentry, 0) + WXJS_METHOD("openEntry", openEntry, 1) +WXJS_END_METHOD_MAP() + +/*** + * + * + * + * Closes the current entry. On a non-seekable stream reads to the end of the current entry first. + * + * + */ +JSBool ArchiveInputStream::closeentry(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + Stream *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + *rval = ToJS(cx, ((wxArchiveInputStream *)p->GetStream())->CloseEntry()); + return JS_TRUE; +} + +/*** + * + * + * + * + * + * Closes the current entry if one is open, then opens the entry specified by the entry object. + * entry should be from the same zip file, and the zip should be on a seekable stream. + * + * + */ +JSBool ArchiveInputStream::openEntry(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + Stream *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + wxArchiveInputStream *ais = dynamic_cast(p->GetStream()); + + wxArchiveEntry *entry = ArchiveEntry::GetPrivate(cx, argv[0]); + if ( entry != NULL ) + { + *rval = ToJS(cx, ais->OpenEntry(*entry)); + return JS_TRUE; + } + + return JS_FALSE; +} Property changes on: ps/trunk/source/tools/atlas/wxJS/io/aistream.cpp ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/io/ipv4addr.h =================================================================== --- ps/trunk/source/tools/atlas/wxJS/io/ipv4addr.h (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/io/ipv4addr.h (revision 5154) @@ -0,0 +1,41 @@ +/* + * wxJavaScript - ipv4addr.h + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: ipv4addr.h 598 2007-03-07 20:13:28Z fbraem $ + */ +#ifndef _wxjs_io_ipv4addr_h +#define _wxjs_io_ipv4addr_h + +#include + +namespace wxjs +{ + namespace io + { + class IPV4address : public ApiWrapper + { + public: + static wxIPV4address* Construct(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, bool constructing); + }; + }; // namespace io +}; // namespace wxjs +#endif // _wxjs_io_ipv4addr_h Property changes on: ps/trunk/source/tools/atlas/wxJS/io/ipv4addr.h ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/io/fostream.h =================================================================== --- ps/trunk/source/tools/atlas/wxJS/io/fostream.h (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/io/fostream.h (revision 5154) @@ -0,0 +1,43 @@ +/* + * wxJavaScript - fostream.h + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: fostream.h 598 2007-03-07 20:13:28Z fbraem $ + */ +#ifndef _wxjs_io_fostream_h +#define _wxjs_io_fostream_h + +namespace wxjs +{ + namespace io + { + class FileOutputStream : public ApiWrapper + { + public: + + /** + * Callback for when a wxFileOutputStream object is created + */ + static Stream* Construct(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, bool constructing); + }; + }; // namespace io +}; // namespace wxjs +#endif // _wxjs_io_fostream_h Property changes on: ps/trunk/source/tools/atlas/wxJS/io/fostream.h ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/io/mostream.cpp =================================================================== --- ps/trunk/source/tools/atlas/wxJS/io/mostream.cpp (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/io/mostream.cpp (revision 5154) @@ -0,0 +1,134 @@ +#include "precompiled.h" + +/* + * wxJavaScript - mostream.cpp + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: mostream.cpp 715 2007-05-18 20:38:04Z fbraem $ + */ +#include +#ifndef WX_PRECOMP + #include +#endif + +#include "../common/main.h" + +#include "stream.h" +#include "mostream.h" + +#include "../ext/wxjs_ext.h" + + +using namespace wxjs; +using namespace wxjs::io; + +MemoryOutputStream::MemoryOutputStream(char *data + , size_t len) : wxMemoryOutputStream(data, len) + , m_data(data) +{ + if ( m_data == NULL ) + GetOutputStreamBuffer()->SetBufferIO(1024); +} + +MemoryOutputStream::~MemoryOutputStream() +{ + delete[] m_data; +} + +/*** + * mostream + * io + * + * wxMemoryOutputStream collects its output in a buffer which can be converted to a String. + * See also @wxMemoryInputStream. + * An example: + *

+ *   var mos = new wxMemoryOutputStream();
+ *   mos.write("This is a test");
+ *  
+ *
+ */ +WXJS_INIT_CLASS(MemoryOutputStream, "wxMemoryOutputStream", 0) + +/*** + * + * + * + * The length of the buffer used in memory. + * + * + * + * Constructs a new wxMemoryOutputStream object. When no length is specified, a buffer is + * created with size 1024. If necessary it will grow. + * + * + */ +Stream* MemoryOutputStream::Construct(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, bool constructing) +{ + if ( argc == 0 ) + { + MemoryOutputStream *mos = new MemoryOutputStream(NULL, 0); + mos->SetClientObject(new JavaScriptClientData(cx, obj, false, true)); + return new Stream(mos); + } + + int length; + if ( FromJS(cx, argv[0], length) ) + { + char *dataPtr = new char[length]; + MemoryOutputStream *mos = new MemoryOutputStream(dataPtr, length); + mos->SetClientObject(new JavaScriptClientData(cx, obj, false, true)); + return new Stream(mos); + } + + return NULL; +} + +/*** + * + * + * Gets the buffer. + * + * + */ +WXJS_BEGIN_PROPERTY_MAP(MemoryOutputStream) + WXJS_READONLY_PROPERTY(P_DATA, "data") +WXJS_END_PROPERTY_MAP() + +bool MemoryOutputStream::GetProperty(Stream *p, JSContext *cx, JSObject *obj, int id, jsval *vp) +{ + MemoryOutputStream *mstream = (MemoryOutputStream *) p->GetStream(); + + switch(id) + { + case P_DATA: + { + int size = mstream->GetOutputStreamBuffer()->GetIntPosition(); + char* buffer = new char[size]; + mstream->CopyTo(buffer, size); + + *vp = OBJECT_TO_JSVAL(wxjs::ext::CreateMemoryBuffer(cx, buffer, size)); + delete[] buffer; + break; + } + } + return true; +} Property changes on: ps/trunk/source/tools/atlas/wxJS/io/mostream.cpp ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/common/clntdata.h =================================================================== --- ps/trunk/source/tools/atlas/wxJS/common/clntdata.h (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/common/clntdata.h (revision 5154) @@ -0,0 +1,109 @@ +/* + * wxJavaScript - clntdata.h + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id$ + */ +#ifndef _wxjs_clientdata_h +#define _wxjs_clientdata_h + +#include + +namespace wxjs +{ + class JavaScriptClientData : public wxClientData + { + public: + JavaScriptClientData(JSContext *cx, + JSObject *obj, + bool protect, + bool owner = true) : m_cx(cx) + , m_obj(obj) + , m_protected(false) + , m_owner(owner) + { + Protect(protect); + } + + JavaScriptClientData(const JavaScriptClientData ©) + { + m_cx = copy.m_cx; + m_obj = copy.m_obj; + Protect(copy.m_protected); + SetOwner(copy.m_owner); + } + + inline bool IsProtected() const + { + return m_protected; + } + + inline bool IsOwner() const + { + return m_owner; + } + + void Protect(bool protect) + { + if ( protect == m_protected ) + return; // Don't protect/unprotect twice + + if ( m_protected + && ! protect ) + { + JS_RemoveRoot(m_cx, &m_obj); + } + else if ( protect + && ! m_protected ) + { + JS_AddRoot(m_cx, &m_obj); + } + m_protected = protect; + } + + virtual ~JavaScriptClientData() + { + Protect(false); + + // When wxJavaScript is not the owner of the object, the + // private data will be set to NULL, so that the js-destructor + // doesn't destroy the data twice. + if ( ! m_owner ) + { + JS_SetPrivate(m_cx, m_obj, NULL); + } + } + + void SetOwner(bool owner) { m_owner = owner; } + + inline JSObject* GetObject() { return m_obj; } + inline JSContext* GetContext() { return m_cx; } + + private: + + JSContext *m_cx; + JSObject* m_obj; + bool m_protected; + bool m_owner; + }; +}; + +#endif // _wxjs_clientdata_h Property changes on: ps/trunk/source/tools/atlas/wxJS/common/clntdata.h ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/common/type.cpp =================================================================== --- ps/trunk/source/tools/atlas/wxJS/common/type.cpp (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/common/type.cpp (revision 5154) @@ -0,0 +1,349 @@ +#include "precompiled.h" + +/* + * wxJavaScript - type.cpp + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: type.cpp 600 2007-03-07 22:08:44Z fbraem $ + */ +#include +#ifndef WX_PRECOMP + #include +#endif + +#include "type.h" + +//template +//bool FromJS(JSContext *cx, jsval v, T& to); + +template<> +bool wxjs::FromJS(JSContext *cx, jsval v, int &to) +{ + int32 temp; + if ( JS_ValueToInt32(cx, v, &temp) == JS_TRUE ) + { + to = temp; + return true; + } + else + return false; +} + +template<> +bool wxjs::FromJS(JSContext *cx, jsval v, unsigned int &to) +{ + int32 temp; + if ( JS_ValueToInt32(cx, v, &temp) == JS_TRUE ) + { + to = temp; + return true; + } + else + return false; +} + + +template<> +bool wxjs::FromJS(JSContext *cx, jsval v, long &to) +{ + int32 temp; + if ( JS_ValueToInt32(cx, v, &temp) ) + { + to = temp; + return JS_TRUE; + } + return JS_FALSE; +} + +template<> +bool wxjs::FromJS(JSContext *cx, jsval v, double &to) +{ + jsdouble d; + if ( JS_ValueToNumber(cx, v, &d) == JS_TRUE ) + { + to = d; + return true; + } + else + return false; +} + +template<> +bool wxjs::FromJS(JSContext *cx, jsval v, bool &to) +{ + JSBool b; + if ( JS_ValueToBoolean(cx, v, &b) == JS_TRUE ) + { + to = (b == JS_TRUE); + return true; + } + else + return false; +} + +template<> +bool wxjs::FromJS(JSContext *cx, jsval v, wxString &to) +{ + wxMBConvUTF16 conv; + JSString *str = JS_ValueToString(cx, v); + jschar *s = JS_GetStringChars(str); + to = wxString(conv.cMB2WX((char *) s)); + return true; +} + +template<> +bool wxjs::FromJS(JSContext *cx, jsval v, wxDateTime& to) +{ + to.SetToCurrent(); // To avoid invalid date asserts. + + JSObject *obj = JSVAL_TO_OBJECT(v); + if ( js_DateIsValid(cx, obj) ) + { + to.SetYear(js_DateGetYear(cx, obj)); + to.SetMonth((wxDateTime::Month) js_DateGetMonth(cx, obj)); + to.SetDay((unsigned short) js_DateGetDate(cx, obj)); + to.SetHour((unsigned short) js_DateGetHours(cx, obj)); + to.SetMinute((unsigned short) js_DateGetMinutes(cx, obj)); + to.SetSecond((unsigned short) js_DateGetSeconds(cx, obj)); + return true; + } + else + return false; +} + +template<> +bool wxjs::FromJS(JSContext*cx, jsval v, StringsPtr &to) +{ + if ( JSVAL_IS_OBJECT(v) ) + { + JSObject *objItems = JSVAL_TO_OBJECT(v); + if ( objItems != (JSObject *) NULL + && JS_IsArrayObject(cx, objItems) ) + { + jsuint length = 0; + JS_GetArrayLength(cx, objItems, &length); + to.Allocate(length); + for(jsuint i =0; i < length; i++) + { + jsval element; + JS_GetElement(cx, objItems, i, &element); + wxjs::FromJS(cx, element, to[i]); + } + } + return true; + } + else + return false; +} + +template<> +bool wxjs::FromJS(JSContext *cx, jsval v, wxArrayString &to) +{ + if ( JSVAL_IS_OBJECT(v) ) + { + JSObject *obj = JSVAL_TO_OBJECT(v); + if ( obj != NULL + && JS_IsArrayObject(cx, obj) ) + { + jsuint length = 0; + JS_GetArrayLength(cx, obj, &length); + for(jsuint i =0; i < length; i++) + { + jsval element; + JS_GetElement(cx, obj, i, &element); + wxString stringElement; + if ( FromJS(cx, element, stringElement) ) + to.Add(stringElement); + } + return true; + } + else + return false; + } + else + return false; +} + +template<> +bool wxjs::FromJS(JSContext *cx, jsval v, wxStringList &to) +{ + if ( JSVAL_IS_OBJECT(v) ) + { + JSObject *obj = JSVAL_TO_OBJECT(v); + if ( obj != NULL + && JS_IsArrayObject(cx, obj) ) + { + jsuint length = 0; + JS_GetArrayLength(cx, obj, &length); + for(jsuint i =0; i < length; i++) + { + jsval element; + JS_GetElement(cx, obj, i, &element); + wxString stringElement; + if ( FromJS(cx, element, stringElement) ) + to.Add(stringElement); + } + return true; + } + else + return false; + } + else + return false; +} + +template<> +bool wxjs::FromJS(JSContext *cx, jsval v, long long &to) +{ + int32 temp; + if ( JS_ValueToInt32(cx, v, &temp) == JS_TRUE ) + { + to = temp; + return true; + } + else + return false; +} + +//template +//jsval ToJS(JSContext *cx, T wx); + +template<> +jsval wxjs::ToJS(JSContext* WXUNUSED(cx), const int &from) +{ + return INT_TO_JSVAL(from); +} + +template<> +jsval wxjs::ToJS(JSContext* WXUNUSED(cx), const unsigned int&from) +{ + return INT_TO_JSVAL(from); +} + +template<> +jsval wxjs::ToJS(JSContext* WXUNUSED(cx), const long &from) +{ + return INT_TO_JSVAL(from); +} + +template<> +jsval wxjs::ToJS(JSContext* cx, const unsigned long&from) +{ + jsval v; + JS_NewDoubleValue(cx, from, &v); + return v; +} + +template<> +jsval wxjs::ToJS(JSContext* cx, const float &from) +{ + jsval v; + JS_NewDoubleValue(cx, from, &v); + return v; +} + +template<> +jsval wxjs::ToJS(JSContext* cx, const double &from) +{ + jsval v; + JS_NewDoubleValue(cx, from, &v); + return v; +} + +template<> +jsval wxjs::ToJS(JSContext* WXUNUSED(cx), const bool &from) +{ + return BOOLEAN_TO_JSVAL(from); +} + +template<> +jsval wxjs::ToJS(JSContext* cx, const wxString &from) +{ + if ( from.Length() == 0 ) + { + return STRING_TO_JSVAL(JS_NewUCStringCopyN(cx, (jschar *) "", 0)); + } + jsval val = JSVAL_VOID; + + wxMBConvUTF16 utf16; + int jsLength = utf16.WC2MB(NULL, from, 0); + if ( jsLength > 0 ) + { + char *jsValue = new char[jsLength + utf16.GetMBNulLen()]; + jsLength = utf16.WC2MB(jsValue, from, jsLength + utf16.GetMBNulLen()); + + val = STRING_TO_JSVAL(JS_NewUCStringCopyN(cx, (jschar *) jsValue, jsLength / utf16.GetMBNulLen())); + delete[] jsValue; + } + return val; +} + +template<> +jsval wxjs::ToJS(JSContext *cx, const wxDateTime &from) +{ + if ( from.IsValid() ) + { + return OBJECT_TO_JSVAL(js_NewDateObject(cx, + from.GetYear(), + from.GetMonth(), + from.GetDay(), + from.GetHour(), + from.GetMinute(), + from.GetSecond())); + } + else + return JSVAL_VOID; +} + +template<> +jsval wxjs::ToJS(JSContext *cx, const wxArrayString &from) +{ + JSObject *objArray = JS_NewArrayObject(cx, 0, NULL); + JS_AddRoot(cx, &objArray); + for(size_t i = 0; i < from.GetCount(); i++) + { + jsval element = ToJS(cx, from.Item(i)); + JS_SetElement(cx, objArray, i, &element); + } + JS_RemoveRoot(cx, &objArray); + return OBJECT_TO_JSVAL(objArray); +} + +template<> +jsval wxjs::ToJS(JSContext *cx, const wxStringList &from) +{ + JSObject *objArray = JS_NewArrayObject(cx, 0, NULL); + JS_AddRoot(cx, &objArray); + + int i = 0; + wxStringListNode *node = from.GetFirst(); + while(node) + { + wxString s(node->GetData()); + + jsval element = ToJS(cx, s); + JS_SetElement(cx, objArray, i++, &element); + + node = node->GetNext(); + } + JS_RemoveRoot(cx, &objArray); + return OBJECT_TO_JSVAL(objArray); +} Property changes on: ps/trunk/source/tools/atlas/wxJS/common/type.cpp ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/common/type.h =================================================================== --- ps/trunk/source/tools/atlas/wxJS/common/type.h (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/common/type.h (revision 5154) @@ -0,0 +1,113 @@ +/* + * wxJavaScript - type.h + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: type.h 600 2007-03-07 22:08:44Z fbraem $ + */ +#ifndef _wxJS_Type_H +#define _wxJS_Type_H + +#include +#include + +#include +#include "strsptr.h" + +class wxStringList; +class wxArrayString; + +namespace wxjs +{ + template + bool FromJS(JSContext *cx, jsval v, T& to); + + template<> + bool FromJS(JSContext *cx, jsval v, int &to); + + template<> + bool FromJS(JSContext *cx, jsval v, unsigned int &to); + + template<> + bool FromJS(JSContext *cx, jsval v, long &to); + + template<> + bool FromJS(JSContext *cx, jsval v, double &to); + + template<> + bool FromJS(JSContext *cx, jsval v, long long &to); + + template<> + bool FromJS(JSContext *cx, jsval v, bool &to); + + template<> + bool FromJS(JSContext *cx, jsval v, wxString &to); + + template<> + bool FromJS(JSContext *cx, jsval v, wxDateTime& to); + + template<> + bool FromJS(JSContext *cx, jsval v, StringsPtr &to); + + template<> + bool FromJS(JSContext *cx, jsval v, wxArrayString &to); + + template<> + bool FromJS(JSContext *cx, jsval v, wxStringList &to); + + template + jsval ToJS(JSContext *cx, const T &wx); + + template<> + jsval ToJS(JSContext *cx, const int &from); + + template<> + jsval ToJS(JSContext *cx, const unsigned int &from); + + template<> + jsval ToJS(JSContext *cx, const long &from); + + template<> + jsval ToJS(JSContext *cx, const unsigned long&from); + + template<> + jsval ToJS(JSContext *cx, const float& from); + + template<> + jsval ToJS(JSContext *cx, const double &from); + + template<> + jsval ToJS(JSContext *cx, const bool &from); + + template<> + jsval ToJS(JSContext *cx, const wxString &from); + + template<> + jsval ToJS(JSContext *cx, const wxDateTime &from); + + template<> + jsval ToJS(JSContext *cx, const wxArrayString &from); + + template<> + jsval ToJS(JSContext *cx, const wxStringList &from); + +}; // Namespace wxjs + +#endif // _wxJS_Type_H Property changes on: ps/trunk/source/tools/atlas/wxJS/common/type.h ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/common/jsutil.cpp =================================================================== --- ps/trunk/source/tools/atlas/wxJS/common/jsutil.cpp (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/common/jsutil.cpp (revision 5154) @@ -0,0 +1,122 @@ +#include "precompiled.h" + +/* + * wxJavaScript - jsutil.cpp + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: jsutil.cpp 603 2007-03-08 20:36:17Z fbraem $ + */ + +#include +#ifndef WX_PRECOMP + #include +#endif + +#include "jsutil.h" + +JSBool wxjs::GetFunctionProperty(JSContext *cx, JSObject *obj, const char *propertyName, jsval *property) +{ + if ( JS_GetProperty(cx, obj, propertyName, property) == JS_TRUE + && JS_TypeOfValue(cx, *property) == JSTYPE_FUNCTION ) + { + return JS_TRUE; + } + else + { + return JS_FALSE; + } +} + +JSBool wxjs::CallFunctionProperty(JSContext *cx, JSObject *obj, const char *propertyName, uintN argc, jsval* args, jsval *rval) +{ + jsval property; + if ( ( GetFunctionProperty(cx, obj, propertyName, &property) == JS_TRUE ) ) + { + if ( JS_CallFunctionValue(cx, obj, property, argc, args, rval) == JS_FALSE ) + { + if ( JS_IsExceptionPending(cx) ) + { + JS_ReportPendingException(cx); + } + return JS_FALSE; + } + return JS_TRUE; + } + return JS_FALSE; +} + +JSClass* wxjs::GetClass(JSContext *cx, const char* className) +{ + jsval ctor, proto; + + if (JS_LookupProperty(cx, JS_GetGlobalObject(cx), className, &ctor) == JS_FALSE) + return NULL; + + if (JS_LookupProperty(cx, JSVAL_TO_OBJECT(ctor), "prototype", &proto) == JS_FALSE) + return NULL; + + JSObject *protoObj = JSVAL_TO_OBJECT(proto); + + return JS_GET_CLASS(cx, protoObj); +} + +bool wxjs::HasPrototype(JSContext *cx, JSObject *obj, const char *className) +{ + JSClass *jsclass = GetClass(cx, className); + if ( jsclass == NULL ) + return false; + + JSObject *prototype = JS_GetPrototype(cx, obj); + while( prototype != NULL + && JS_InstanceOf(cx, prototype, jsclass, NULL) == JS_FALSE ) + { + prototype = JS_GetPrototype(cx, prototype); + } + return prototype != NULL; +} + +bool wxjs::HasPrototype(JSContext *cx, jsval v, const char *className) +{ + if ( JSVAL_IS_OBJECT(v) ) + return HasPrototype(cx, JSVAL_TO_OBJECT(v), className); + else + return false; +} + +bool wxjs::GetScriptRoot(JSContext *cx, jsval *v) +{ + return JS_GetProperty(cx, JS_GetGlobalObject(cx), "scriptRoot", v) == JS_TRUE; +} + +JSBool wxjs::DefineUnicodeProperty(JSContext *cx, + JSObject *obj, + const wxString &propertyName, + jsval *propertyValue) +{ + wxMBConvUTF16 utf16; + int jsLength = utf16.WC2MB(NULL, propertyName, 0); + char *jsValue = new char[jsLength + utf16.GetMBNulLen()]; + jsLength = utf16.WC2MB(jsValue, propertyName, jsLength + utf16.GetMBNulLen()); + JSBool ret = JS_DefineUCProperty(cx, obj, (jschar *) jsValue, jsLength / utf16.GetMBNulLen(), + *propertyValue, NULL, NULL, JSPROP_ENUMERATE); + delete[] jsValue; + return ret; +} Property changes on: ps/trunk/source/tools/atlas/wxJS/common/jsutil.cpp ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/README.txt =================================================================== --- ps/trunk/source/tools/atlas/wxJS/README.txt (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/README.txt (revision 5154) @@ -0,0 +1,36 @@ +Based on wxJavaScript r741, with some modifications: + +# Fix line endings +for i in `find . -name '*.cpp' -or -name '*.h'`; do dos2unix $i; done +for i in `find . -name '*.cpp' -or -name '*.h'`; do svn propset svn:eol-style native $i; done + +# Add '#include "precompiled.h"' to every .cpp file +for i in `find common ext gui io -name '*.cpp'`; do mv $i $i~; ( echo -e "#include \"precompiled.h\"\n" ; cat $i~ ) >$i; rm $i~; done + +# Fix JS include paths +for i in `grep -lr '' .`; do sed -i 's///' $i; done +for i in `grep -lr '' .`; do sed -i 's///' $i; done + +# Rename common filenames to prevent naming conflicts when we compile everything together +for i in io ext gui; do + for j in init constant main; do + mv $i/$j.cpp $i/${i}_$j.cpp 2>/dev/null; + done; +done + + + +gui/misc/app.cpp: delete + "IMPLEMENT_APP_NO_MAIN(App)" + +io/io_constant.cpp: replace + "JSConstDoubleSpec wxGlobalMap[] = + { + WXJS_SIMPLE_CONSTANT(wxNOT_FOUND) + { 0 } + };" +with + "extern JSConstDoubleSpec wxGlobalMap[];" + + +...and some other minor things \ No newline at end of file Index: ps/trunk/source/lib/sysdep/unix/bsd.cpp =================================================================== --- ps/trunk/source/lib/sysdep/unix/bsd.cpp (revision 5153) +++ ps/trunk/source/lib/sysdep/unix/bsd.cpp (revision 5154) @@ -1,30 +1,30 @@ -#include "precompiled.h" -#include "bsd.h" - -#if OS_BSD - -#include - -static int SysctlFromMemType(CpuMemoryIndicators mem_type) -{ - switch(mem_type) - { - case CPU_MEM_TOTAL: - return HW_PHYSMEM; - case CPU_MEM_AVAILABLE: - return HW_USERMEM; - } - UNREACHABLE; -} - -size_t bsd_MemorySize(CpuMemoryIndicators mem_type) -{ - size_t memory_size = 0; - size_t len = sizeof(memory_size); - // Argh, the API doesn't seem to be const-correct - /*const*/ int mib[2] = { CTL_HW, SysctlFromMemType(mem_type) }; - sysctl(mib, 2, &memory_size, &len, 0, 0); - return memory_size; -} - -#endif +#include "precompiled.h" +#include "bsd.h" + +#if OS_BSD + +#include + +static int SysctlFromMemType(CpuMemoryIndicators mem_type) +{ + switch(mem_type) + { + case CPU_MEM_TOTAL: + return HW_PHYSMEM; + case CPU_MEM_AVAILABLE: + return HW_USERMEM; + } + UNREACHABLE; +} + +size_t bsd_MemorySize(CpuMemoryIndicators mem_type) +{ + size_t memory_size = 0; + size_t len = sizeof(memory_size); + // Argh, the API doesn't seem to be const-correct + /*const*/ int mib[2] = { CTL_HW, SysctlFromMemType(mem_type) }; + sysctl(mib, 2, &memory_size, &len, 0, 0); + return memory_size; +} + +#endif Property changes on: ps/trunk/source/lib/sysdep/unix/bsd.cpp ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/precompiled.h =================================================================== --- ps/trunk/source/tools/atlas/wxJS/precompiled.h (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/precompiled.h (revision 5154) @@ -0,0 +1,24 @@ +#ifndef INCLUDED_STDAFX +#define INCLUDED_STDAFX + +// Global definitions, since this is a convenient place: + +#ifdef _WIN32 +# define XP_WIN +#else +# define XP_UNIX +#endif // (we don't support XP_OS2 or XP_BEOS) + +#define JS_THREADSAFE + +// Precompiled headers: + +#ifdef USING_PCH + +#define WX_PRECOMP +#include "common/main.h" +#include "wx/wxprec.h" + +#endif + +#endif // INCLUDED_STDAFX Property changes on: ps/trunk/source/tools/atlas/wxJS/precompiled.h ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/lib/sysdep/unix/ucpu.h =================================================================== --- ps/trunk/source/lib/sysdep/unix/ucpu.h (revision 5153) +++ ps/trunk/source/lib/sysdep/unix/ucpu.h (revision 5154) @@ -1,11 +1,11 @@ -#ifndef INCLUDED_UCPU -#define INCLUDED_UCPU - -#include "lib/sysdep/cpu.h" - -extern int ucpu_IsThrottlingPossible(); -extern int ucpu_NumPackages(); -extern double ucpu_ClockFrequency(); -extern LibError ucpu_CallByEachCPU(CpuCallback cb, void* param); - -#endif // #ifndef INCLUDED_UCPU +#ifndef INCLUDED_UCPU +#define INCLUDED_UCPU + +#include "lib/sysdep/cpu.h" + +extern int ucpu_IsThrottlingPossible(); +extern int ucpu_NumPackages(); +extern double ucpu_ClockFrequency(); +extern LibError ucpu_CallByEachCPU(CpuCallback cb, void* param); + +#endif // #ifndef INCLUDED_UCPU Property changes on: ps/trunk/source/lib/sysdep/unix/ucpu.h ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/scripting/SpiderMonkey.h =================================================================== --- ps/trunk/source/scripting/SpiderMonkey.h (revision 5153) +++ ps/trunk/source/scripting/SpiderMonkey.h (revision 5154) @@ -1,40 +1,43 @@ // Master header for the SpiderMonkey Javascript library. // // Include this instead of accessing any headers directly. // Rationale: they require an OS macro to be set (XP_*). // Since this is specific to SpiderMonkey, we don't want to saddle // another obscure header with it (would make reuse harder). // Instead, do it here where the purpose is clear. // // This doesn't go in ScriptingHost.h because some other files // (notably precompiled.h and i18n/ScriptInterface.cpp) want only these // definitions without pulling in the whole of ScriptingHost. // jstypes.h (included via jsapi.h) requires we define // "one of XP_BEOS, XP_MAC, XP_OS2, XP_WIN or XP_UNIX". #include "lib/config.h" #if OS_WIN # define XP_WIN #elif OS_MAC # define XP_MAC #elif OS_BEOS # define XP_BEOS #else # define XP_UNIX #endif +#define JS_THREADSAFE + #include -#include + #ifndef NDEBUG +// Used by ScriptingHost::jshook_{script,function} # include #endif // include any further required headers here #include "JSUtil.h" // Make JS debugging a little easier by automatically naming GC roots // Don't simply #define NAME_ALL_GC_ROOTS, because jsapi.h is horridly broken #ifndef NDEBUG # define JS_AddRoot(cx, rp) JS_AddNamedRoot((cx), (rp), __FILE__ ) #endif Index: ps/trunk/source/lib/sysdep/unix/ucpu.cpp =================================================================== --- ps/trunk/source/lib/sysdep/unix/ucpu.cpp (revision 5153) +++ ps/trunk/source/lib/sysdep/unix/ucpu.cpp (revision 5154) @@ -1,66 +1,66 @@ -#include "precompiled.h" - -#include "ucpu.h" - -#if OS_MACOSX -#include -#endif - -int ucpu_IsThrottlingPossible() -{ - return -1; // don't know -} - -int ucpu_NumPackages() -{ -#if OS_MACOSX - int mib[]={CTL_HW, HW_NCPU}; - int ncpus; - size_t len = sizeof(ncpus); - if (sysctl(mib, 2, &ncpus, &len, NULL, 0) == -1) - return -1; // don't know - else - return ncpus; -#else - long res = sysconf(_SC_NPROCESSORS_CONF); - if (res == -1) - return 1; - else - return (int)res; -#endif -} - -double ucpu_ClockFrequency() -{ - return -1; // don't know -} - - -// apparently not possible on non-Windows OSes because they seem to lack -// a CPU affinity API. see sysdep.h comment. -LibError ucpu_CallByEachCPU(CpuCallback cb, void* param) -{ - UNUSED2(cb); - -/* -cpu_set_t currentCPU; - -while ( j < sysNumProcs ) - -{ - -CPU_ZERO(¤tCPU); - -CPU_SET(j, ¤tCPU); - -if ( sched_setaffinity (0, sizeof (currentCPU), ¤tCPU) - -== 0 ) - -{ - -sleep(0); // Ensure system to switch to the right -*/ - - return ERR::NO_SYS; -} +#include "precompiled.h" + +#include "ucpu.h" + +#if OS_MACOSX +#include +#endif + +int ucpu_IsThrottlingPossible() +{ + return -1; // don't know +} + +int ucpu_NumPackages() +{ +#if OS_MACOSX + int mib[]={CTL_HW, HW_NCPU}; + int ncpus; + size_t len = sizeof(ncpus); + if (sysctl(mib, 2, &ncpus, &len, NULL, 0) == -1) + return -1; // don't know + else + return ncpus; +#else + long res = sysconf(_SC_NPROCESSORS_CONF); + if (res == -1) + return 1; + else + return (int)res; +#endif +} + +double ucpu_ClockFrequency() +{ + return -1; // don't know +} + + +// apparently not possible on non-Windows OSes because they seem to lack +// a CPU affinity API. see sysdep.h comment. +LibError ucpu_CallByEachCPU(CpuCallback cb, void* param) +{ + UNUSED2(cb); + +/* +cpu_set_t currentCPU; + +while ( j < sysNumProcs ) + +{ + +CPU_ZERO(¤tCPU); + +CPU_SET(j, ¤tCPU); + +if ( sched_setaffinity (0, sizeof (currentCPU), ¤tCPU) + +== 0 ) + +{ + +sleep(0); // Ensure system to switch to the right +*/ + + return ERR::NO_SYS; +} Property changes on: ps/trunk/source/lib/sysdep/unix/ucpu.cpp ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/io/bistream.h =================================================================== --- ps/trunk/source/tools/atlas/wxJS/io/bistream.h (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/io/bistream.h (revision 5154) @@ -0,0 +1,48 @@ +/* + * wxJavaScript - bistream.h + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: bistream.h 715 2007-05-18 20:38:04Z fbraem $ + */ +#ifndef wxjs_io_bistream_h +#define wxjs_io_bistream_h + +namespace wxjs +{ + namespace io + { + class BufferedInputStream : public wxBufferedInputStream + , public ApiWrapper + , public wxClientDataContainer + { + public: + BufferedInputStream(wxInputStream &s, wxStreamBuffer *buffer = NULL); + virtual ~BufferedInputStream() + { + } + static Stream* Construct(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, bool constructing); + static void Destruct(JSContext *cx, Stream *p); + + Stream m_refStream; + }; + }; // namespace io +}; // namespace wxjs +#endif // wxjs_io_bistream_h Property changes on: ps/trunk/source/tools/atlas/wxJS/io/bistream.h ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/io/fistream.h =================================================================== --- ps/trunk/source/tools/atlas/wxJS/io/fistream.h (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/io/fistream.h (revision 5154) @@ -0,0 +1,43 @@ +/* + * wxJavaScript - fistream.h + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: fistream.h 598 2007-03-07 20:13:28Z fbraem $ + */ +#ifndef _wxjs_io_fistream_h +#define _wxjs_io_fistream_h + +#include +namespace wxjs +{ + namespace io + { + class FileInputStream : public ApiWrapper + { + public: + /** + * Callback for when a wxFileInputStream object is created + */ + static Stream* Construct(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, bool constructing); + }; + }; // namespace io +}; // namespace wxjs +#endif //_wxjs_io_fistream_h Property changes on: ps/trunk/source/tools/atlas/wxJS/io/fistream.h ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/io/dir.h =================================================================== --- ps/trunk/source/tools/atlas/wxJS/io/dir.h (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/io/dir.h (revision 5154) @@ -0,0 +1,84 @@ +/* + * wxJavaScript - dir.h + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: dir.h 598 2007-03-07 20:13:28Z fbraem $ + */ +#ifndef _WXJSDir_H +#define _WXJSDir_H + +///////////////////////////////////////////////////////////////////////////// +// Name: dir.h +// Purpose: wxJSDir ports wxDir to JavaScript +// Author: Franky Braem +// Modified by: +// Created: 27.09.2002 +// Copyright: (c) 2001-2002 Franky Braem +// Licence: LGPL +///////////////////////////////////////////////////////////////////////////// + +#include + +namespace wxjs +{ + namespace io + { + + class Dir : public ApiWrapper + { + public: + /** + * Callback for retrieving properties of wxDir + */ + static bool GetProperty(wxDir *p, JSContext *cx, JSObject *obj, int id, jsval *vp); + + /** + * Callback for when a wxDir object is created + */ + static wxDir* Construct(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, bool constructing); + + static JSBool open(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval); + static JSBool getFirst(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval); + static JSBool getNext(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval); + static JSBool hasFiles(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval); + static JSBool hasSubDirs(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval); + static JSBool traverse(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval); + static JSBool exists(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval); + static JSBool getAllFiles(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval); + + WXJS_DECLARE_PROPERTY_MAP() + WXJS_DECLARE_CONSTANT_MAP() + WXJS_DECLARE_METHOD_MAP() + WXJS_DECLARE_STATIC_METHOD_MAP() + + /** + * Property Ids. + */ + enum + { + P_OPENED, + P_NAME + }; + }; + }; // namespace io +}; // namespace wxjs +#endif //_WXJSDir_H + Property changes on: ps/trunk/source/tools/atlas/wxJS/io/dir.h ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/io/ffile.cpp =================================================================== --- ps/trunk/source/tools/atlas/wxJS/io/ffile.cpp (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/io/ffile.cpp (revision 5154) @@ -0,0 +1,468 @@ +#include "precompiled.h" + +/* + * wxJavaScript - ffile.cpp + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: ffile.cpp 671 2007-04-11 21:03:11Z fbraem $ + */ +// file.cpp +#include + +#include "../common/main.h" +#include "../common/apiwrap.h" +#include "../common/type.h" +#include "../ext/wxjs_ext.h" + +#include "ffile.h" + +using namespace wxjs; +using namespace wxjs::io; + +/*** + * ffile + * io + * + * A wxFFile performs raw file I/O. + * This is a very small class designed to minimize the overhead of using it - + * in fact, there is hardly any overhead at all, but using it brings you + * automatic error checking and hides differences between platforms. + * It wraps inside it a FILE * handle used by standard C IO library (also known as stdio). + *

Remark : + * A FILE* structure can't be used directly in JavaScript. That's why some methods are not + * ported. + *
+ */ +WXJS_INIT_CLASS(FFile, "wxFFile", 0) + +/*** + * + * + * + * + * + * + * + * + * + * + * + * + * + */ +WXJS_BEGIN_CONSTANT_MAP(FFile) + WXJS_CONSTANT(wxFILE_, KIND_UNKNOWN) + WXJS_CONSTANT(wxFILE_, KIND_DISK) + WXJS_CONSTANT(wxFILE_, KIND_TERMINAL) + WXJS_CONSTANT(wxFILE_, KIND_PIPE) + WXJS_CONSTANT(wx, FromCurrent) + WXJS_CONSTANT(wx, FromStart) + WXJS_CONSTANT(wx, FromEnd) +WXJS_END_CONSTANT_MAP() + +/*** + * + * + * True when end of file is reached. When the file is not open, undefined is returned. + * + * + * Returns the type of the file + * + * + * True when the file is open. + * + * + * Returns the length of the file. When the file is not open, undefined is returned. + * + * + * Returns the current position or -1 (invalid offset). + * When the file is not open, undefined is returned. + * + * + */ +WXJS_BEGIN_PROPERTY_MAP(FFile) + WXJS_READONLY_PROPERTY(P_EOF, "eof") + WXJS_READONLY_PROPERTY(P_KIND, "kind") + WXJS_READONLY_PROPERTY(P_OPENED, "opened") + WXJS_READONLY_PROPERTY(P_LENGTH, "length") + WXJS_READONLY_PROPERTY(P_TELL, "tell") +WXJS_END_PROPERTY_MAP() + +bool FFile::GetProperty(wxFFile *p, JSContext *cx, JSObject *obj, int id, jsval *vp) +{ + switch(id) + { + case P_EOF: + if ( p->IsOpened() ) + *vp = ToJS(cx, p->Eof()); + else + *vp = JSVAL_VOID; + break; + case P_KIND: + *vp = ToJS(cx, (int) p->GetKind()); + break; + case P_OPENED: + *vp = ToJS(cx, p->IsOpened()); + break; + case P_LENGTH: + if ( p->IsOpened() ) + *vp = ToJS(cx, (int) p->Length()); + else + *vp = JSVAL_VOID; + break; + case P_TELL: + if ( p->IsOpened() ) + *vp = ToJS(cx, (int) p->Tell()); + else + *vp = JSVAL_VOID; + break; + } + return true; +} + +/*** + * + * + * Filename + * + * The mode in which to open the file + * + * + * + * Creates a new wxFFile object + * + * + */ +wxFFile *FFile::Construct(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, bool constructing) +{ + if ( argc > 2 ) + argc = 2; + + if ( argc == 0 ) + return new wxFFile(); + + wxString fileName; + wxString mode = wxT("r"); + if ( argc == 2 ) + FromJS(cx, argv[1], mode); + + FromJS(cx, argv[0], fileName); + + return new wxFFile(fileName, mode); +} + +WXJS_BEGIN_METHOD_MAP(FFile) + WXJS_METHOD("close", close, 0) + WXJS_METHOD("flush", flush, 0) + WXJS_METHOD("open", open, 2) + WXJS_METHOD("read", read, 1) + WXJS_METHOD("readAll", readAll, 0) + WXJS_METHOD("seek", seek, 2) + WXJS_METHOD("seekEnd", seekEnd, 1) + WXJS_METHOD("write", write, 1) +WXJS_END_METHOD_MAP() + +/*** + * + * + * + * Closes the file. + * + * + */ +JSBool FFile::close(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxFFile *p = GetPrivate(cx, obj); + wxASSERT_MSG(p != NULL, wxT("No private data associated with wxFFile")); + + if ( p->IsOpened() ) + *rval = ToJS(cx, p->Close()); + else + *rval = JSVAL_FALSE; + + return JS_TRUE; +} + +/*** + * + * + * + * Flushes the file. + * + * + */ +JSBool FFile::flush(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxFFile *p = GetPrivate(cx, obj); + wxASSERT_MSG(p != NULL, wxT("No private data associated with wxFFile")); + + if ( p->IsOpened() ) + *rval = ToJS(cx, p->Flush()); + else + *rval = JSVAL_FALSE; + + return JS_TRUE; +} + +/*** + * + * + * Name of the file + * The mode in which to open the file + * + * + * Opens a file. + * + * + */ +JSBool FFile::open(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxFFile *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + wxString fileName; + wxString mode = wxT("r"); + if ( argc == 2 ) + FromJS(cx, argv[1], mode); + + FromJS(cx, argv[0], fileName); + + *rval = ToJS(cx, p->Open(fileName, mode)); + return JS_TRUE; +} + +/*** + * + * + * The number of bytes to read. + * + * + * Reads the specified number of bytes. + * + * + */ +JSBool FFile::read(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxFFile *p = GetPrivate(cx, obj); + wxASSERT_MSG(p != NULL, wxT("No private data associated with wxFFile")); + + if ( ! p->IsOpened() ) + { + return JS_FALSE; + } + int count; + if ( FromJS(cx, argv[0], count) + && count > 0 ) + { + unsigned char *buffer = new unsigned char[count]; + int readCount = p->Read(buffer, count); + if ( readCount == wxInvalidOffset ) + { + *rval = JSVAL_VOID; + } + else + { + *rval = OBJECT_TO_JSVAL(wxjs::ext::CreateMemoryBuffer(cx, buffer, count)); + } + delete[] buffer; + + + return JS_TRUE; + } + + return JS_FALSE; +} + +/*** + * + * + * + * The encoding of the file. + * + * + * + * Reads all the data and return it in a String. Internally JavaScript + * stores the Strings as UTF-16. But because most files are stored + * in UTF-8 or ASCII, the default of the encoding is UTF-8. + * + * + */ +JSBool FFile::readAll(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxFFile *p = GetPrivate(cx, obj); + if ( p == NULL ) + return JS_FALSE; + + if ( ! p->IsOpened() ) + { + return JS_FALSE; + } + + wxString encoding(wxJS_EXTERNAL_ENCODING); + if ( argc > 0 ) + { + FromJS(cx, argv[0], encoding); + } + wxCSConv conv(encoding); + + wxString data; + if ( p->ReadAll(&data, conv) ) + { + *rval = ToJS(cx, data); + return JS_TRUE; + } + + return JS_FALSE; +} + +/*** + * + * + * Offset to seek to + * + * + * + * Seeks the offset. Returns the actual position or -1 on error. + * + * + */ +JSBool FFile::seek(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxFFile *p = GetPrivate(cx, obj); + wxASSERT_MSG(p != NULL, wxT("No private data associated with wxFFile")); + + if ( ! p->IsOpened() ) + { + return JS_FALSE; + } + + int offset; + if ( ! FromJS(cx, argv[0], offset) ) + { + return JS_FALSE; + } + + int pos; + + if ( argc > 1 ) + { + int mode; + if ( FromJS(cx, argv[1], mode) ) + { + pos = p->Seek((wxFileOffset) offset, (wxSeekMode) mode); + } + else + { + return JS_FALSE; + } + } + else + { + pos = p->Seek((wxFileOffset) offset); + } + *rval = ToJS(cx, pos); + return JS_TRUE; +} + +/*** + * + * + * Offset to seek to. + * + * + * Moves the file pointer to the specified number of bytes before the end of the file. + * Returns true on success. + * + * + */ +JSBool FFile::seekEnd(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxFFile *p = GetPrivate(cx, obj); + wxASSERT_MSG(p != NULL, wxT("No private data associated with wxFFile")); + + if ( ! p->IsOpened() ) + { + return JS_FALSE; + } + + int offset; + if ( FromJS(cx, argv[0], offset) ) + { + *rval = ToJS(cx, p->SeekEnd((wxFileOffset) offset)); + return JS_TRUE; + } + + return JS_FALSE; +} + +/*** + * + * + * + * + * + * + * + * + * + * Writes the string or buffer to the file. When you write + * a String you can specify an encoding. Because most files + * are still written as UTF-8 or ASCII, UTF-8 is the default + * (wxJS uses UTF-16 internally). + * Returns the actual number of bytes written to the file when + * a buffer is used. Otherwise a boolean indicating + * success or failure is returned. + * + * + */ +JSBool FFile::write(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + wxFFile *p = GetPrivate(cx, obj); + wxASSERT_MSG(p != NULL, wxT("No private data associated with wxFFile")); + + if ( ! p->IsOpened() ) + { + return JS_FALSE; + } + + if ( JSVAL_IS_OBJECT(argv[0]) ) + { + wxMemoryBuffer* buffer = wxjs::ext::GetMemoryBuffer(cx, JSVAL_TO_OBJECT(argv[0])); + if ( buffer != NULL ) + { + *rval = ToJS(cx, p->Write(buffer->GetData(), buffer->GetDataLen())); + } + } + else + { + wxString encoding(wxJS_EXTERNAL_ENCODING); + if ( argc > 1 ) + { + FromJS(cx, argv[1], encoding); + } + wxCSConv conv(encoding); + wxString content; + FromJS(cx, argv[0], content); + *rval = ToJS(cx, (int) p->Write(content, conv)); + } + return JS_TRUE; +} Property changes on: ps/trunk/source/tools/atlas/wxJS/io/ffile.cpp ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/io/io_init.cpp =================================================================== --- ps/trunk/source/tools/atlas/wxJS/io/io_init.cpp (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/io/io_init.cpp (revision 5154) @@ -0,0 +1,333 @@ +#include "precompiled.h" + +/* + * wxJavaScript - init.cpp + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: init.cpp 598 2007-03-07 20:13:28Z fbraem $ + */ +// main.cpp +#include + +#include "../common/main.h" +#include "init.h" +#include "../common/index.h" +#include "../common/jsutil.h" + +#include "constant.h" +#include "file.h" +#include "ffile.h" +#include "dir.h" +#include "dirtrav.h" +#include "stream.h" +#include "istream.h" +#include "ostream.h" +#include "fistream.h" +#include "fostream.h" +#include "ffistream.h" +#include "ffostream.h" +#include "costream.h" +#include "mistream.h" +#include "mostream.h" +#include "bostream.h" +#include "bistream.h" +#include "tistream.h" +#include "tostream.h" +#include "filename.h" +#include "aistream.h" +#include "archentry.h" +#include "zipentry.h" +#include "zistream.h" +#include "aostream.h" +#include "zostream.h" +#include "tempfile.h" +#include "textfile.h" +#include "textline.h" +#include "distream.h" +#include "dostream.h" +#include "sockaddr.h" +#include "sockbase.h" +#include "sockclient.h" +#include "socksrv.h" +#include "sostream.h" +#include "sistream.h" +#include "ipaddr.h" +#include "ipv4addr.h" +#include "protocol.h" +#include "uri.h" +#include "url.h" +#include "http.h" +#include "httphdr.h" +#include "sound.h" +#include "fn.h" +#include "process.h" + +using namespace wxjs; + +bool io::InitClass(JSContext *cx, JSObject *global) +{ + InitConstants(cx, global); + + JSObject *obj = File::JSInit(cx, global, NULL); + wxASSERT_MSG(obj != NULL, wxT("wxFile prototype creation failed")); + if (! obj ) + return false; + + obj = FFile::JSInit(cx, global, NULL); + wxASSERT_MSG(obj != NULL, wxT("wxFFile prototype creation failed")); + if (! obj ) + return false; + + obj = TempFile::JSInit(cx, global, NULL); + wxASSERT_MSG(obj != NULL, wxT("wxTempFile prototype creation failed")); + if (! obj ) + return false; + + obj = Dir::JSInit(cx, global, NULL); + wxASSERT_MSG(obj != NULL, wxT("wxDir prototype creation failed")); + if (! obj ) + return false; + + obj = DirTraverser::JSInit(cx, global, NULL); + wxASSERT_MSG(obj != NULL, wxT("wxDirTraverser prototype creation failed")); + if (! obj ) + return false; + + obj = StreamBase::JSInit(cx, global, NULL); + wxASSERT_MSG(obj != NULL, wxT("wxStreamBase prototype creation failed")); + if (! obj ) + return false; + + obj = InputStream::JSInit(cx, global, StreamBase::GetClassPrototype()); + wxASSERT_MSG(obj != NULL, wxT("wxInputStream prototype creation failed")); + if (! obj ) + return false; + + obj = BufferedInputStream::JSInit(cx, global, InputStream::GetClassPrototype()); + wxASSERT_MSG(obj != NULL, wxT("wxBufferedInputStream prototype creation failed")); + if (! obj ) + return false; + + obj = OutputStream::JSInit(cx, global, StreamBase::GetClassPrototype()); + wxASSERT_MSG(obj != NULL, wxT("wxOutputStream prototype creation failed")); + if (! obj ) + return false; + + obj = BufferedOutputStream::JSInit(cx, global, OutputStream::GetClassPrototype()); + wxASSERT_MSG(obj != NULL, wxT("wxBufferedOutputStream prototype creation failed")); + if (! obj ) + return false; + + obj = CountingOutputStream::JSInit(cx, global, OutputStream::GetClassPrototype()); + wxASSERT_MSG(obj != NULL, wxT("wxCountingOutputStream prototype creation failed")); + if (! obj ) + return false; + + obj = FileInputStream::JSInit(cx, global, InputStream::GetClassPrototype()); + wxASSERT_MSG(obj != NULL, wxT("wxFileInputStream prototype creation failed")); + if (! obj ) + return false; + + obj = FileOutputStream::JSInit(cx, global, OutputStream::GetClassPrototype()); + wxASSERT_MSG(obj != NULL, wxT("wxFileOutputStream prototype creation failed")); + if (! obj ) + return false; + + obj = MemoryInputStream::JSInit(cx, global, InputStream::GetClassPrototype()); + wxASSERT_MSG(obj != NULL, wxT("wxMemoryInputStream prototype creation failed")); + if (! obj ) + return false; + + obj = MemoryOutputStream::JSInit(cx, global, OutputStream::GetClassPrototype()); + wxASSERT_MSG(obj != NULL, wxT("wxMemoryOutputStream prototype creation failed")); + if (! obj ) + return false; + + obj = TextInputStream::JSInit(cx, global); + wxASSERT_MSG(obj != NULL, wxT("wxTextInputStream prototype creation failed")); + if (! obj ) + return false; + + obj = TextOutputStream::JSInit(cx, global); + wxASSERT_MSG(obj != NULL, wxT("wxTextOutputStream prototype creation failed")); + if (! obj ) + return false; + + obj = FileName::JSInit(cx, global); + wxASSERT_MSG(obj != NULL, wxT("wxFileName prototype creation failed")); + if (! obj ) + return false; + + obj = ArchiveInputStream::JSInit(cx, global, InputStream::GetClassPrototype()); + wxASSERT_MSG(obj != NULL, wxT("wxArchiveInputStream prototype creation failed")); + if (! obj ) + return false; + + obj = ArchiveOutputStream::JSInit(cx, global, OutputStream::GetClassPrototype()); + wxASSERT_MSG(obj != NULL, wxT("wxArchiveOutputStream prototype creation failed")); + if (! obj ) + return false; + + obj = ArchiveEntry::JSInit(cx, global, NULL); + wxASSERT_MSG(obj != NULL, wxT("wxArchiveEntry prototype creation failed")); + if (! obj ) + return false; + + obj = ZipEntry::JSInit(cx, global, ArchiveEntry::GetClassPrototype()); + wxASSERT_MSG(obj != NULL, wxT("wxZipEntry prototype creation failed")); + if (! obj ) + return false; + + obj = ZipInputStream::JSInit(cx, global, ArchiveInputStream::GetClassPrototype()); + wxASSERT_MSG(obj != NULL, wxT("wxZipInputStream prototype creation failed")); + if (! obj ) + return false; + + obj = ZipOutputStream::JSInit(cx, global, ArchiveOutputStream::GetClassPrototype()); + wxASSERT_MSG(obj != NULL, wxT("wxZipOutputStream")); + if (! obj ) + return false; + + obj = TextFile::JSInit(cx, global); + wxASSERT_MSG(obj != NULL, wxT("wxTextFile")); + if (! obj ) + return false; + + obj = TextLine::JSInit(cx, global); + wxASSERT_MSG(obj != NULL, wxT("wxTextLine")); + if (! obj ) + return false; + + obj = DataInputStream::JSInit(cx, global); + wxASSERT_MSG(obj != NULL, wxT("wxDataInputStream prototype creation failed")); + if (! obj ) + return false; + + obj = DataOutputStream::JSInit(cx, global); + wxASSERT_MSG(obj != NULL, wxT("wxDataOutputStream prototype creation failed")); + if (! obj ) + return false; + + obj = SocketBase::JSInit(cx, global); + wxASSERT_MSG(obj != NULL, wxT("wxSocketBase prototype creation failed")); + if (! obj ) + return false; + + obj = SockAddress::JSInit(cx, global); + wxASSERT_MSG(obj != NULL, wxT("wxSocketAddr prototype creation failed")); + if (! obj ) + return false; + + obj = SocketClient::JSInit(cx, global, SocketBase::GetClassPrototype()); + wxASSERT_MSG(obj != NULL, wxT("wxSocketClient prototype creation failed")); + if (! obj ) + return false; + + obj = SocketServer::JSInit(cx, global, SocketBase::GetClassPrototype()); + wxASSERT_MSG(obj != NULL, wxT("wxSocketServer prototype creation failed")); + if (! obj ) + return false; + + obj = SocketInputStream::JSInit(cx, global, InputStream::GetClassPrototype()); + wxASSERT_MSG(obj != NULL, wxT("wxSocketInputStream prototype creation failed")); + if (! obj ) + return false; + + obj = SocketOutputStream::JSInit(cx, global, OutputStream::GetClassPrototype()); + wxASSERT_MSG(obj != NULL, wxT("wxSocketOutputStream prototype creation failed")); + if (! obj ) + return false; + + obj = IPaddress::JSInit(cx, global, SockAddress::GetClassPrototype()); + wxASSERT_MSG(obj != NULL, wxT("wxIPaddress prototype creation failed")); + if (! obj ) + return false; + + obj = IPV4address::JSInit(cx, global, IPaddress::GetClassPrototype()); + wxASSERT_MSG(obj != NULL, wxT("wxIPV4address prototype creation failed")); + if (! obj ) + return false; + + obj = Protocol::JSInit(cx, global, SocketClient::GetClassPrototype()); + wxASSERT_MSG(obj != NULL, wxT("wxProtocol prototype creation failed")); + if (! obj ) + return false; + + obj = URI::JSInit(cx, global); + wxASSERT_MSG(obj != NULL, wxT("wxURI prototype creation failed")); + if (! obj ) + return false; + + obj = HTTP::JSInit(cx, global, Protocol::GetClassPrototype()); + wxASSERT_MSG(obj != NULL, wxT("wxHTTP prototype creation failed")); + if (! obj ) + return false; + + obj = HTTPHeader::JSInit(cx, global); + wxASSERT_MSG(obj != NULL, wxT("wxHTTPHeader prototype creation failed")); + if (! obj ) + return false; + + obj = URL::JSInit(cx, global); + wxASSERT_MSG(obj != NULL, wxT("wxURL prototype creation failed")); + if (! obj ) + return false; + + obj = Sound::JSInit(cx, global); + wxASSERT_MSG(obj != NULL, wxT("wxSound prototype creation failed")); + if (! obj ) + return false; + + obj = Process::JSInit(cx, global); + wxASSERT_MSG(obj != NULL, wxT("wxProcess prototype creation failed")); + if (! obj ) + return false; + + JS_DefineFunction(cx, global, "wxConcatFiles", concatFiles, 3, 0); + JS_DefineFunction(cx, global, "wxCopyFile", copyFile, 2, 0); + JS_DefineFunction(cx, global, "wxFileExists", fileExists, 1, 0); + JS_DefineFunction(cx, global, "wxRenameFile", renameFile, 2, 0); + JS_DefineFunction(cx, global, "wxGetCwd", getCwd, 0, 0); + JS_DefineFunction(cx, global, "wxGetFreeDiskSpace", getFreeDiskSpace, 1, 0); + JS_DefineFunction(cx, global, "wxGetTotalDiskSpace", getTotalDiskSpace, 1, 0); + JS_DefineFunction(cx, global, "wxGetOSDirectory", getOSDirectory, 0, 0); + JS_DefineFunction(cx, global, "wxIsAbsolutePath", isAbsolutePath, 1, 0); + JS_DefineFunction(cx, global, "wxIsWild", isWild, 1, 0); + JS_DefineFunction(cx, global, "wxDirExists", dirExists, 1, 0); + JS_DefineFunction(cx, global, "wxMatchWild", matchWild, 3, 0); + JS_DefineFunction(cx, global, "wxMkDir", mkDir, 2, 0); + JS_DefineFunction(cx, global, "wxRemoveFile", removeFile, 1, 0); + JS_DefineFunction(cx, global, "wxRmDir", rmDir, 1, 0); + JS_DefineFunction(cx, global, "wxSetWorkingDirectory", setWorkingDirectory, 1, 0); + JS_DefineFunction(cx, global, "wxExecute", execute, 1, 0); + JS_DefineFunction(cx, global, "wxShell", shell, 1, 0); + + return true; +} + +bool io::InitObject(JSContext *cx, JSObject *obj) +{ + return true; +} + +void io::Destroy() +{ +} Property changes on: ps/trunk/source/tools/atlas/wxJS/io/io_init.cpp ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/common/jsutil.h =================================================================== --- ps/trunk/source/tools/atlas/wxJS/common/jsutil.h (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/common/jsutil.h (revision 5154) @@ -0,0 +1,46 @@ +/* + * wxJavaScript - jsutil.h + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: jsutil.h 603 2007-03-08 20:36:17Z fbraem $ + */ +#ifndef _wxjs_util_h +#define _wxjs_util_h + +namespace wxjs +{ + // Returns a function from a property + JSBool GetFunctionProperty(JSContext *cx, JSObject *obj, const char *propertyName, jsval *property); + JSBool CallFunctionProperty(JSContext *cx, JSObject *obj, const char *propertyName, uintN argc, jsval* args, jsval *rval); + + // Returns the JSClass structure for the given classname + JSClass *GetClass(JSContext *cx, const char* className); + + // Returns true when the object has class as its prototype + bool HasPrototype(JSContext *cx, JSObject *obj, const char *className); + bool HasPrototype(JSContext *cx, jsval v, const char *className); + + bool GetScriptRoot(JSContext *cx, jsval *v); + + // Define a UNICODE property + JSBool DefineUnicodeProperty(JSContext *cx, JSObject *obj, const wxString &propertyName, jsval *propertyValue); +}; +#endif //wxjs_util_h Property changes on: ps/trunk/source/tools/atlas/wxJS/common/jsutil.h ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/common/script.cpp =================================================================== --- ps/trunk/source/tools/atlas/wxJS/common/script.cpp (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/common/script.cpp (revision 5154) @@ -0,0 +1,72 @@ +#include "precompiled.h" + +/* + * wxJavaScript - script.cpp + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: script.cpp 631 2007-03-23 20:14:28Z fbraem $ + */ +#include +#include +#include +#include "script.h" + +using namespace wxjs; + +wxString ScriptSource::GetSource() const +{ + return m_source; +} + +void ScriptSource::SetFile(const wxString &file, wxMBConv &conv) +{ + m_file = file; + wxFileInputStream fis(file); + if ( fis.IsOk() ) + { + wxTextInputStream tis(fis, wxT("\t"), conv); + bool first = true; + while(! fis.Eof()) + { + wxString line = tis.ReadLine(); + if ( first + && line.StartsWith(wxT("#!")) ) // The first line can hold a shebang + { + first = false; + continue; + } + first = false; + m_source.Append(line); + m_source.Append(wxTextFile::GetEOL()); + } + } +} + +ScriptSource::ScriptSource(const ScriptSource ©) : m_file(copy.m_file) + , m_source(copy.m_source) + , m_name(copy.m_name) +{ +} + +void ScriptSource::SetSource(const wxString &source) +{ + m_source.append(source); +} Property changes on: ps/trunk/source/tools/atlas/wxJS/common/script.cpp ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/common/apiwrap.h =================================================================== --- ps/trunk/source/tools/atlas/wxJS/common/apiwrap.h (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/common/apiwrap.h (revision 5154) @@ -0,0 +1,786 @@ +/* + * wxJavaScript - apiwrap.h + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: apiwrap.h 676 2007-04-18 20:27:39Z fbraem $ + */ + +// ApiWrapper uses the Barton and Nackman trick (also known as +// "Curiously Recursive Template Pattern") + +#ifndef _WXJS_APIWRAPPER_H +#define _WXJS_APIWRAPPER_H + +#include +#include "../common/type.h" + +namespace wxjs +{ + + template + class ApiWrapper + { + public: + typedef ApiWrapper TOBJECT; + + /** + * Creates an object for the given WX class. From now + * on wxJS owns the pointer to the WX class. So don't delete it. + */ + static jsval CreateObject(JSContext *cx, + T_Priv *p, + JSObject *parent = NULL) + { + JSObject *obj = JS_NewObject(cx, &wxjs_class, m_classProto, parent); + JS_SetPrivate(cx, obj, p); + return OBJECT_TO_JSVAL(obj); + } + + // A type-safe SetPrivate method + static void SetPrivate(JSContext *cx, JSObject *obj, T_Priv *p) + { + JS_SetPrivate(cx, obj, p); + } + + /** + * Creates an object for the given WX class and defines it as a + * property of the given object. From now on wxJS owns the pointer + * to the WX class. So don't delete it. + */ + static JSObject* DefineObject(JSContext *cx, + JSObject *obj, + const char *name, + T_Priv *p) + { + JSObject *propObj = JS_DefineObject(cx, obj, name, + &wxjs_class, m_classProto, + JSPROP_READONLY | JSPROP_PERMANENT); + JS_SetPrivate(cx, propObj, p); + return propObj; + } + + /** + * Returns the ported class from the private data of an object. + * When check is true, it will check the type of the class and + * returns NULL, when the class is not of the correct type. + */ + static T_Priv* GetPrivate(JSContext *cx, + JSObject *obj, + bool check = true) + { + T_Priv *p = NULL; + if ( check ) + { + if ( + ! ( JS_InstanceOf(cx, obj, &wxjs_class, NULL) + || HasPrototype(cx, obj)) + ) + { + JS_ReportError(cx, + "The object should be an instance of %s", + m_jsClassName); + return NULL; + } + } + + JSClass *clazz = JS_GetClass(cx, obj); + while((clazz->flags & JSCLASS_HAS_PRIVATE) != JSCLASS_HAS_PRIVATE) + { + obj = JS_GetPrototype(cx, obj); + if ( obj == NULL ) + return NULL; + clazz = JS_GetClass(cx, obj); + } + + p = (T_Priv*) JS_GetPrivate(cx, obj); + + return p; + } + + /** + * Returns the ported class from the private data of an object. + * Does the same as above, but for an object which is stored in a jsval. + */ + static T_Priv* GetPrivate(JSContext *cx, jsval v, bool check = true) + { + if ( JSVAL_IS_VOID(v) + || JSVAL_IS_NULL(v) ) + { + return NULL; + } + + return JSVAL_IS_OBJECT(v) ? GetPrivate(cx, JSVAL_TO_OBJECT(v), check) + : NULL; + } + + /** + * Returns true when the prototype of the object is this class. + */ + static bool HasPrototype(JSContext *cx, JSObject *obj) + { + JSObject *prototype = JS_GetPrototype(cx, obj); + while( prototype != NULL + && JS_InstanceOf(cx, prototype, &wxjs_class, NULL)== JS_FALSE ) + { + prototype = JS_GetPrototype(cx, prototype); + } + return prototype != NULL; + } + + /** + * Same as above, but for an object that is stored in a jsval + */ + static bool HasPrototype(JSContext *cx, jsval v) + { + return JSVAL_IS_OBJECT(v) ? HasPrototype(cx, JSVAL_TO_OBJECT(v)) + : false; + } + + /** + * Initializes the class. + */ + static JSObject* JSInit(JSContext *cx, + JSObject *obj, + JSObject *proto = NULL) + { + m_classProto = JS_InitClass(cx, obj, proto, &wxjs_class, + T_Port::JSConstructor, m_ctorArguments, + NULL, NULL, NULL, NULL); + if ( m_classProto != NULL ) + { + T_Port::DefineProperties(cx, m_classProto); + T_Port::DefineMethods(cx, m_classProto); + + JSObject *ctor = JS_GetConstructor(cx, m_classProto); + if ( ctor != NULL ) + { + T_Port::DefineConstants(cx, ctor); + T_Port::DefineStaticProperties(cx, ctor); + T_Port::DefineStaticMethods(cx, ctor); + } + T_Port::InitClass(cx, obj, m_classProto); + } + return m_classProto; + } + + /** + * Default implementation for adding a property + * Returning false, will end the execution of the script. + * The default implementation returns true. + */ + static bool AddProperty(T_Priv* WXUNUSED(p), + JSContext* WXUNUSED(cx), + JSObject* WXUNUSED(obj), + const wxString& WXUNUSED(prop), + jsval* WXUNUSED(vp)) + { + return true; + } + + /** + * Default implementation for deleting a property + * Returning false, will end the execution of the script. + * The default implementation returns true. + */ + static bool DeleteProperty(T_Priv* WXUNUSED(p), + JSContext* WXUNUSED(cx), + JSObject* WXUNUSED(obj), + const wxString& WXUNUSED(prop)) + { + return true; + } + + /** + * The default implementation of the Get method for a ported object. + * Overwrite this method when your object has properties. + * Returning false, will end the execution of the script. + * The default implementation returns true. + */ + static bool GetProperty(T_Priv* WXUNUSED(p), + JSContext* WXUNUSED(cx), + JSObject* WXUNUSED(obj), + int WXUNUSED(id), + jsval* WXUNUSED(vp)) + { + return true; + } + + /** + * The default implementation of the Get method for a ported object. + * Overwrite this method when your object has properties. + * Returning false, will end the execution of the script. + * The default implementation returns true. + */ + static bool GetStringProperty(T_Priv* WXUNUSED(p), + JSContext* WXUNUSED(cx), + JSObject* WXUNUSED(obj), + const wxString& WXUNUSED(propertyName), + jsval* WXUNUSED(vp)) + { + return true; + } + + /** + * The default implementation of the Set method for a ported object. + * Overwrite this method when your object has properties. + * @remark Returning false, will end the execution of the script. + * The default implementation returns true. + */ + static bool SetProperty(T_Priv* WXUNUSED(p), + JSContext* WXUNUSED(cx), + JSObject* WXUNUSED(obj), + int WXUNUSED(id), + jsval* WXUNUSED(vp)) + { + return true; + } + + static bool SetStringProperty(T_Priv* WXUNUSED(p), + JSContext* WXUNUSED(cx), + JSObject* WXUNUSED(obj), + const wxString& WXUNUSED(propertyName), + jsval* WXUNUSED(vp)) + { + return true; + } + + static bool Resolve(JSContext* WXUNUSED(cx), + JSObject* WXUNUSED(obj), + jsval WXUNUSED(id)) + { + return true; + } + + /** + * The default implementation of the Destruct method. Overwrite this + * when you need to do some cleanup before the object is destroyed. + * The default implementation calls the destructor of the private + * object. + */ + static void Destruct(JSContext* WXUNUSED(cx), + T_Priv* p) + { + delete p; + p = NULL; + } + + /** + * The default implementation of the Construct method. Overwrite this + * when a script is allowed to create an object with the new statement. + * The default implementation returns NULL, which means that is not + * allowed to create an object. + */ + static T_Priv* Construct(JSContext* WXUNUSED(cx), + JSObject* WXUNUSED(obj), + uintN WXUNUSED(argc), + jsval* WXUNUSED(argv), + bool WXUNUSED(constructing)) + { + return NULL; + } + + /** + * Default implementation for defining properties. + * Use the WXJS_DECLARE_PROPERTY_MAP, WXJS_BEGIN_PROPERTY_MAP and + * WXJS_END_PROPERTY_MAP macro's for hiding the complexity of + * defining properties. The default implementation does nothing. + */ + static void DefineProperties(JSContext* WXUNUSED(cx), + JSObject* WXUNUSED(obj)) + { + } + + /** + * InitClass is called when the prototype object is created + * It can be used for example to initialize constants related to + * this class. + * The argument obj is normally the global object. + * The default implementation does nothing. + */ + static void InitClass(JSContext* WXUNUSED(cx), + JSObject* WXUNUSED(obj), + JSObject* WXUNUSED(proto)) + { + } + + /** + * Default implementation for defining methods. + * Use the WXJS_DECLARE_METHOD_MAP, WXJS_BEGIN_METHOD_MAP and + * WXJS_END_METHOD_MAP macro's for hiding the complexity of + * defining methods. + * The default implementation does nothing. + */ + static void DefineMethods(JSContext* WXUNUSED(cx), + JSObject* WXUNUSED(obj)) + { + } + + /** + * Default implementation for defining constants. + * Use the WXJS_DECLARE_CONSTANT_MAP, WXJS_BEGIN_CONSTANT_MAP and + * WXJS_END_CONSTANT_MAP macro's for hiding the complexity of + * defining constants. + * The default implementation does nothing. + * Only numeric constants are allowed. + */ + static void DefineConstants(JSContext* WXUNUSED(cx), + JSObject* WXUNUSED(obj)) + { + } + + /** + * Default implementation for defining static(class) properties. + * Use the WXJS_DECLARE_STATIC_PROPERTY_MAP, + * WXJS_BEGIN_STATIC_PROPERTY_MAP and WXJS_END_PROPERTY_MAP macro's + * for hiding the complexity of defining properties. + * The default implementation does nothing. + */ + static void DefineStaticProperties(JSContext* WXUNUSED(cx), + JSObject* WXUNUSED(obj)) + { + } + + /** + * Default implementation for defining static(class) methods. + * Use the WXJS_DECLARE_STATIC_METHOD_MAP, WXJS_BEGIN_STATIC_METHOD_MAP + * and WXJS_END_METHOD_MAP macro's for hiding the complexity of + * defining methods. + * The default implementation does nothing. + */ + static void DefineStaticMethods(JSContext* WXUNUSED(cx), + JSObject* WXUNUSED(obj)) + { + } + + /** + * Returns the JSClass of the object + */ + static JSClass* GetClass() + { + return &wxjs_class; + } + + /** + * The default implementation of the static Get method for a ported + * object. Overwrite this method when your object has static + * properties. + * Returning false, will end the execution of the script. + * The default implementation returns true. + */ + static bool GetStaticProperty(JSContext* WXUNUSED(cx), + int WXUNUSED(id), + jsval* WXUNUSED(vp)) + { + return true; + } + + /** + * The default implementation of the static Set method for a ported + * object. + * Overwrite this method when your object has static properties. + * Returning false, will end the execution of the script. + * The default implementation returns true. + */ + static bool SetStaticProperty(JSContext* WXUNUSED(cx), + int WXUNUSED(id), + jsval* WXUNUSED(vp)) + { + return true; + } + + static bool Enumerate(T_Priv* WXUNUSED(p), + JSContext* WXUNUSED(cx), + JSObject* WXUNUSED(obj), + JSIterateOp WXUNUSED(enum_op), + jsval* WXUNUSED(statep), + jsid* WXUNUSED(idp)) + { + return true; + } + + // The JS API callbacks + + static JSBool JSGetStaticProperty(JSContext* cx, + JSObject* WXUNUSED(obj), + jsval id, + jsval* vp) + { + if ( JSVAL_IS_INT(id) ) + { + return T_Port::GetStaticProperty(cx, JSVAL_TO_INT(id), vp) ? JS_TRUE + : JS_FALSE; + } + return JS_TRUE; + } + + static JSBool JSSetStaticProperty(JSContext* cx, + JSObject* WXUNUSED(obj), + jsval id, + jsval *vp) + { + if ( JSVAL_IS_INT(id) ) + { + return T_Port::SetStaticProperty(cx, JSVAL_TO_INT(id), vp) ? JS_TRUE + : JS_FALSE; + } + return JS_TRUE; + } + + static JSObject *GetClassPrototype() + { + return m_classProto; + } + + private: + /** + * Contains the number of arguments that a constructor can receive. + * This doesn't mean that the constructor always receives these number + * of arguments. SpiderMonkey makes sure that the constructor receives + * a correct number of arguments. When not all arguments are given, + * SpiderMonkey will create arguments of the 'undefined' type. It's + * also possible that the constructor receives more arguments. + * It's up to you to decide what happens with these arguments. + * A rule of thumb: Set this value to the number of required arguments. + * This way you never have to check the number of arguments when you + * check the type of these arguments. When argc is greater + * then this value, you know there are optional values passed. + * You can use the WXJS_INIT_CLASS macro, to initialize this. + */ + static int m_ctorArguments; + + /** + * The prototype object of the class + */ + static JSObject *m_classProto; + + /** + * The name of the class. + * You can use the WXJS_INIT_CLASS macro, to initialize this. + */ + static const char* m_jsClassName; + + /** + * The JSClass structure + */ + static JSClass wxjs_class; + + /** + * Enumeration callback + */ + static JSBool JSEnumerate(JSContext *cx, JSObject *obj, + JSIterateOp enum_op, + jsval *statep, jsid *idp) + { + JSBool res = JS_TRUE; + T_Priv *p = (T_Priv *) GetPrivate(cx, obj, false); + if ( p != NULL ) + { + res = T_Port::Enumerate(p, cx, obj, enum_op, statep, idp) + ? JS_TRUE : JS_FALSE; + } + return res; + } + + /** + * AddProperty callback. This will call the AddProperty method of + * the ported object. + */ + static JSBool JSAddProperty(JSContext *cx, + JSObject *obj, + jsval id, + jsval *vp) + { + if (JSVAL_IS_STRING(id)) + { + T_Priv *p = (T_Priv *) GetPrivate(cx, obj, false); + if ( p != NULL ) + { + wxString str; + FromJS(cx, id, str); + JSBool res = T_Port::AddProperty(p, cx, obj, str, vp) ? JS_TRUE + : JS_FALSE; + return res; + } + } + return JS_TRUE; + } + + /** + * AddProperty callback. This will call the AddProperty method of + * the ported object. + */ + static JSBool JSDeleteProperty(JSContext *cx, + JSObject *obj, + jsval id, + jsval* WXUNUSED(vp)) + { + if (JSVAL_IS_STRING(id)) + { + T_Priv *p = (T_Priv *) GetPrivate(cx, obj, false); + if ( p != NULL ) + { + wxString str; + FromJS(cx, id, str); + JSBool res = T_Port::DeleteProperty(p, cx, obj, str) ? JS_TRUE + : JS_FALSE; + return res; + } + } + return JS_TRUE; + } + + /** + * GetProperty callback. This will call the Get method of the + * ported object. + */ + static JSBool JSGetProperty(JSContext *cx, + JSObject *obj, + jsval id, + jsval *vp) + { + T_Priv *p = (T_Priv *) GetPrivate(cx, obj, false); + if (JSVAL_IS_INT(id)) + { + return T_Port::GetProperty(p, cx, obj, JSVAL_TO_INT(id), vp) + ? JS_TRUE : JS_FALSE; + } + else + { + if (JSVAL_IS_STRING(id)) + { + wxString s; + FromJS(cx, id, s); + JSBool res = T_Port::GetStringProperty(p, cx, obj, s, vp) ? JS_TRUE + : JS_FALSE; + return res; + } + } + return JS_TRUE; + } + + /** + * SetProperty callback. This will call the Set method of the ported + * object. + */ + static JSBool JSSetProperty(JSContext *cx, + JSObject *obj, + jsval id, + jsval *vp) + { + T_Priv *p = (T_Priv *) GetPrivate(cx, obj, false); + if (JSVAL_IS_INT(id)) + { + return T_Port::SetProperty(p, cx, obj, JSVAL_TO_INT(id), vp) + ? JS_TRUE : JS_FALSE; + } + else + { + if (JSVAL_IS_STRING(id)) + { + wxString s; + FromJS(cx, id, s); + JSBool res = T_Port::SetStringProperty(p, cx, obj, s, vp) + ? JS_TRUE : JS_FALSE; + return res; + } + } + return JS_TRUE; + } + + static JSBool JSResolve(JSContext *cx, JSObject *obj, jsval id) + { + return T_Port::Resolve(cx, obj, id) ? JS_TRUE : JS_FALSE; + } + + /** + * Constructor callback. This will call the static Construct + * method of the ported object. + * When this is not available, the ported object can't be created + * with a new statement in JavaScript. + */ + static JSBool JSConstructor(JSContext *cx, + JSObject *obj, + uintN argc, + jsval *argv, + jsval* WXUNUSED(rval)) + { + T_Priv *p = T_Port::Construct(cx, obj, argc, argv, + JS_IsConstructing(cx) == JS_TRUE); + if ( p == NULL ) + { + JS_ReportError(cx, "Class %s can't be constructed", m_jsClassName); + return JS_FALSE; + } + JS_SetPrivate(cx, obj, p); + return JS_TRUE; + } + + /** + * Destructor callback. This will call the Destruct method of the + * ported object. + */ + static void JSDestructor(JSContext *cx, JSObject *obj) + { + T_Priv *p = (T_Priv *) JS_GetPrivate(cx, obj); + if ( p != NULL ) + { + T_Port::Destruct(cx, p); + } + } + }; +}; + +// The initialisation of wxjs_class +template +JSClass wxjs::ApiWrapper::wxjs_class = +{ + wxjs::ApiWrapper::m_jsClassName, + JSCLASS_HAS_PRIVATE | JSCLASS_NEW_ENUMERATE, + wxjs::ApiWrapper::JSAddProperty, + wxjs::ApiWrapper::JSDeleteProperty, + wxjs::ApiWrapper::JSGetProperty, + wxjs::ApiWrapper::JSSetProperty, + (JSEnumerateOp) wxjs::ApiWrapper::JSEnumerate, + wxjs::ApiWrapper::JSResolve, + JS_ConvertStub, + wxjs::ApiWrapper::JSDestructor, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL +}; + +// Some usefull macro's that makes the use of ApiWrapper easy +// PROPERTY MACROS +#define WXJS_NORMAL JSPROP_ENUMERATE | JSPROP_PERMANENT +#define WXJS_READONLY JSPROP_ENUMERATE | JSPROP_PERMANENT | JSPROP_READONLY + +// Declare a property map (use it in headers) +#define WXJS_DECLARE_PROPERTY_MAP() \ + static void DefineProperties(JSContext *cx, JSObject *obj); + +// Declare a static property map (use it in headers) +#define WXJS_DECLARE_STATIC_PROPERTY_MAP() \ + static void DefineStaticProperties(JSContext *cx, JSObject *obj); + +// Begins a property map (use it in source files) +#define WXJS_BEGIN_PROPERTY_MAP(className) \ + void className::DefineProperties(JSContext *cx, JSObject *obj) \ + { \ + JSPropertySpec props[] = \ + { +// Ends a property map (use it in source files) +#define WXJS_END_PROPERTY_MAP() \ + { 0, 0, 0, 0, 0 } \ + }; \ + JS_DefineProperties(cx, obj, props); \ + } +// Begins a static property map +#define WXJS_BEGIN_STATIC_PROPERTY_MAP(className) \ + void className::DefineStaticProperties(JSContext *cx, JSObject *obj) \ + { \ + JSPropertySpec props[] = \ + { + +// Defines a property +#define WXJS_PROPERTY(id, name) \ + { name, id, WXJS_NORMAL, 0, 0 }, + +// Defines a static property +#define WXJS_STATIC_PROPERTY(id, name) \ + { name, id, WXJS_NORMAL, JSGetStaticProperty, JSSetStaticProperty }, + +// Defines a readonly property +#define WXJS_READONLY_PROPERTY(id, name) \ + { name, id, WXJS_READONLY, 0, 0 }, + +// Defines a readonly static property +#define WXJS_READONLY_STATIC_PROPERTY(id, name) \ + { name, id, WXJS_READONLY, JSGetStaticProperty, 0 }, + +// Declares a constant map +#define WXJS_DECLARE_CONSTANT_MAP() \ + static void DefineConstants(JSContext *cx, JSObject *obj); + +// Begins a constant map +#define WXJS_BEGIN_CONSTANT_MAP(className) \ + void className::DefineConstants(JSContext *cx, JSObject *obj) \ + { \ + JSConstDoubleSpec consts[] = \ + { + +// Ends a constant map +#define WXJS_END_CONSTANT_MAP() \ + { 0, 0, 0, 0 } \ + }; \ + JS_DefineConstDoubles(cx, obj, consts); \ + } + +// Defines a constant with a prefix +#define WXJS_CONSTANT(prefix, name) { prefix##name, #name, WXJS_READONLY, 0, 0 }, +// Defines a constant +#define WXJS_SIMPLE_CONSTANT(name) { name, #name, WXJS_READONLY, 0, 0 }, + +// METHOD MACROS +#define WXJS_DECLARE_METHOD_MAP() \ + static void DefineMethods(JSContext *cx, JSObject *obj); + +#define WXJS_BEGIN_METHOD_MAP(className) \ + void className::DefineMethods(JSContext *cx, JSObject *obj) \ + { \ + JSFunctionSpec methods[] = \ + { + +#define WXJS_END_METHOD_MAP() \ + { 0, 0, 0, 0, 0 } \ + }; \ + JS_DefineFunctions(cx, obj, methods); \ + } + +#define WXJS_METHOD(name, fun, args) \ + { name, fun, args, 0, 0 }, + +// A macro to reduce the size of the ported classes header. +#define WXJS_DECLARE_METHOD(name) static JSBool name(JSContext *cx, \ + JSObject *obj, \ + uintN argc, \ + jsval *argv, \ + jsval *rval); + +#define WXJS_DECLARE_STATIC_METHOD_MAP() \ + static void DefineStaticMethods(JSContext *cx, JSObject *obj); + +#define WXJS_BEGIN_STATIC_METHOD_MAP(className) \ + void className::DefineStaticMethods(JSContext *cx, JSObject *obj) \ + { \ + JSFunctionSpec methods[] = \ + { + +// CLASS MACROS +#define WXJS_INIT_CLASS(type, name, ctor) \ + template<> JSObject *type::TOBJECT::m_classProto = NULL; \ + template<> int type::TOBJECT::m_ctorArguments = ctor; \ + template<> const char* type::TOBJECT::m_jsClassName = name; +#endif // _JSOBJECT_H Property changes on: ps/trunk/source/tools/atlas/wxJS/common/apiwrap.h ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/tools/atlas/wxJS/common/index.h =================================================================== --- ps/trunk/source/tools/atlas/wxJS/common/index.h (nonexistent) +++ ps/trunk/source/tools/atlas/wxJS/common/index.h (revision 5154) @@ -0,0 +1,62 @@ +/* + * wxJavaScript - index.h + * + * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project + * + * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * $Id: index.h 598 2007-03-07 20:13:28Z fbraem $ + */ +#ifndef _wxJS_Index_h +#define _wxJS_Index_h + +///////////////////////////////////////////////////////////////////////////// +// Name: index.h +// Purpose: wxJS_Index is used to keep information about indexed objects +// Author: Franky Braem +// Modified by: +// Created: 23.09.02 +// Copyright: (c) 2001-2002 Franky Braem +// Licence: LGPL +///////////////////////////////////////////////////////////////////////////// + +namespace wxjs +{ + class Index + { + public: + + Index(int idx) : m_index(idx) + { + } + + inline int GetIndex() const + { + return m_index; + } + + inline void SetIndex(int idx) + { + m_index = idx; + } + + private: + int m_index; + }; +}; +#endif // _wxJS_Index_h Property changes on: ps/trunk/source/tools/atlas/wxJS/common/index.h ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: ps/trunk/source/scripting/ScriptGlue.cpp =================================================================== --- ps/trunk/source/scripting/ScriptGlue.cpp (revision 5153) +++ ps/trunk/source/scripting/ScriptGlue.cpp (revision 5154) @@ -1,1618 +1,1618 @@ // This module defines the table of all functions callable from JS. // it's required by the interpreter; we make use of the opportunity to // document them all in one spot. we thus obviate having to dig through // all the other headers. most of the functions are implemented here; // as for the rest, we only link to their docs (duplication is bad). #include "precompiled.h" #include "ScriptGlue.h" #include "JSConversions.h" #include "GameEvents.h" #include "graphics/GameView.h" #include "graphics/LightEnv.h" #include "graphics/MapWriter.h" #include "graphics/Unit.h" #include "graphics/UnitManager.h" #include "graphics/scripting/JSInterface_Camera.h" #include "graphics/scripting/JSInterface_LightEnv.h" #include "gui/CGUI.h" #include "lib/timer.h" #include "maths/scripting/JSInterface_Vector3D.h" #include "network/Client.h" #include "network/Server.h" #include "ps/CConsole.h" #include "ps/CLogger.h" #include "ps/CStr.h" #include "ps/Game.h" #include "ps/GameSetup/GameSetup.h" #include "ps/Hotkey.h" #include "ps/Interact.h" #include "ps/ProfileViewer.h" #include "ps/i18n.h" #include "ps/scripting/JSCollection.h" #include "ps/scripting/JSInterface_Console.h" #include "ps/scripting/JSInterface_Selection.h" #include "ps/scripting/JSInterface_VFS.h" #include "renderer/Renderer.h" #include "renderer/SkyManager.h" #include "renderer/WaterManager.h" #include "simulation/Entity.h" #include "simulation/EntityFormation.h" #include "simulation/EntityHandles.h" #include "simulation/EntityManager.h" #include "simulation/EntityTemplate.h" #include "simulation/EntityTemplateCollection.h" #include "simulation/FormationManager.h" #include "simulation/LOSManager.h" #include "simulation/Scheduler.h" #include "simulation/Simulation.h" #include "simulation/TechnologyCollection.h" #include "simulation/TriggerManager.h" #ifndef NO_GUI # include "gui/scripting/JSInterface_IGUIObject.h" #endif extern bool g_TerrainModified; // rationale: the function table is now at the end of the source file to // avoid the need for forward declarations for every function. // all normal function wrappers have the following signature: // JSBool func(JSContext* cx, JSObject* globalObject, uint argc, jsval* argv, jsval* rval); // all property accessors have the following signature: // JSBool accessor(JSContext* cx, JSObject* globalObject, jsval id, jsval* vp); //----------------------------------------------------------------------------- // Output //----------------------------------------------------------------------------- // Write values to the log file. // params: any number of any type. // returns: // notes: // - Each argument is converted to a string and then written to the log. // - Output is in NORMAL style (see LOG). JSBool WriteLog(JSContext* cx, JSObject*, uint argc, jsval* argv, jsval* rval) { JSU_REQUIRE_PARAMS(1); CStr logMessage; for (int i = 0; i < (int)argc; i++) { try { CStr arg = g_ScriptingHost.ValueToString( argv[i] ); logMessage += arg; } catch( PSERROR_Scripting_ConversionFailed ) { // Do nothing. } } // We should perhaps unicodify (?) the logger at some point. LOG( NORMAL, "script", logMessage ); *rval = JSVAL_TRUE; return JS_TRUE; } //----------------------------------------------------------------------------- // Entity //----------------------------------------------------------------------------- // Retrieve the entity currently occupying the specified handle. // params: handle [int] // returns: entity JSBool GetEntityByUnitID( JSContext* cx, JSObject*, uint argc, jsval* argv, jsval* rval ) { JSU_REQUIRE_PARAMS(1); *rval = JSVAL_NULL; int uid; try { uid = ToPrimitive( argv[0] ); } catch( PSERROR_Scripting_ConversionFailed ) { JS_ReportError( cx, "Invalid parameter" ); return( JS_TRUE ); } CUnit* unit = g_Game->GetWorld()->GetUnitManager().FindByID( uid ); if( !unit || !unit->GetEntity() ) { *rval = JSVAL_NULL; return( JS_TRUE ); } *rval = OBJECT_TO_JSVAL( unit->GetEntity()->GetScript() ); return( JS_TRUE ); } // Look up an EntityTemplate by name. // params: template name [wstring] // returns: entity template object JSBool GetEntityTemplate( JSContext* cx, JSObject*, uint argc, jsval* argv, jsval* rval ) { JSU_REQUIRE_PARAM_RANGE(1, 2); *rval = JSVAL_NULL; CStrW templateName; CPlayer* player = 0; try { templateName = g_ScriptingHost.ValueToUCString( argv[0] ); if( argc == 2 ) { player = ToNative( argv[1] ); } } catch( PSERROR_Scripting_ConversionFailed ) { JS_ReportError( cx, "Invalid template identifier" ); return( JS_TRUE ); } CEntityTemplate* v = g_EntityTemplateCollection.GetTemplate( templateName, player ); if( !v ) { JS_ReportError( cx, "No such template: %s", CStr(templateName).c_str() ); return( JS_TRUE ); } *rval = OBJECT_TO_JSVAL( v->GetScript() ); return( JS_TRUE ); } JSBool GetPlayerUnitCount( JSContext* cx, JSObject*, uint argc, jsval* argv, jsval* rval ) { JSU_REQUIRE_PARAMS(2); int unitCount, playerNum = ToPrimitive( argv[0] ); CStrW unitName = ToPrimitive( argv[1] ); unitCount = g_EntityManager.GetPlayerUnitCount((size_t)playerNum, unitName); *rval = ToJSVal( unitCount ); return JS_TRUE; } //Used to create net messages for formations--msgList.front() is the original message. see IssueCommand void CreateFormationMessage( std::vector& msgList, CNetMessage* msg, CEntityList& formation ) { CNetMessage* retMsg; const int type = msg->GetType(); if ( type == NMT_Goto ) { //formationEnt->GetFormation()->BaseToMovement(); CGoto* tmp = static_cast(msg); retMsg = CNetMessage::CreatePositionMessage( formation, NMT_FormationGoto, CVector2D(tmp->m_TargetX, tmp->m_TargetY) ); } else if( type == NMT_Run ) { CGoto* tmp = static_cast(msg); retMsg = CNetMessage::CreatePositionMessage( formation, NMT_FormationGoto, CVector2D(tmp->m_TargetX, tmp->m_TargetY) ); } else if ( type == NMT_Generic ) { CGeneric* tmp = static_cast(msg); retMsg = CNetMessage::CreateEntityIntMessage(formation, NMT_FormationGeneric, tmp->m_Target, tmp->m_Action); } else return; msgList.push_back(retMsg); } // Issue a command (network message) to an entity or collection. // params: either an entity- or entity collection object, message ID [int], // any further params needed by CNetMessage::CommandFromJSArgs // returns: command in serialized form [string] JSBool IssueCommand( JSContext* cx, JSObject*, uint argc, jsval* argv, jsval* rval ) { // at least one for target object, one for isQueued, and then 1 or more for the CommandFromJSArgs JSU_REQUIRE_MIN_PARAMS(3); JSU_ASSERT(JSVAL_IS_OBJECT(argv[0]), "Argument 0 must be an entity collection."); *rval = JSVAL_NULL; CEntityList entities, msgEntities; - if (JS_GetClass(JSVAL_TO_OBJECT(argv[0])) == &CEntity::JSI_class) + if (JS_GetClass(cx, JSVAL_TO_OBJECT(argv[0])) == &CEntity::JSI_class) entities.push_back( (ToNative(argv[0])) ->me); else entities = *EntityCollection::RetrieveSet(cx, JSVAL_TO_OBJECT(argv[0])); std::map entityStore; bool isQueued = ToPrimitive(argv[1]); //Destroy old notifiers if we're explicitly being reassigned for ( size_t i=0; i < entities.size(); i++) { if ( entities[i]->entf_get(ENTF_DESTROY_NOTIFIERS)) entities[i]->DestroyAllNotifiers(); } std::vector messages; //Generate messages for formations for (size_t i=0; i < entities.size(); i++ ) { if ( entities[i]->m_formation >= 0) { CEntityFormation* formation = entities[i]->GetFormation(); bool duplicate = formation->IsDuplication(); if ( formation->IsLocked() && !duplicate) { formation->SelectAllUnits(); entityStore[entities[i]->m_formation] = formation->GetEntityList(); formation->SetDuplication(true); } } else msgEntities.push_back( entities[i] ); } CNetMessage* msg = CNetMessage::CommandFromJSArgs(msgEntities, cx, argc-2, argv+2, isQueued); if (!msg) { delete msg; return JS_TRUE; } messages.push_back(msg); for ( std::map::iterator it=entityStore.begin(); it!=entityStore.end(); it++) CreateFormationMessage(messages, msg, it->second); for ( std::vector::iterator it=messages.begin(); it != messages.end(); it++ ) { g_Console->InsertMessage(L"IssueCommand: %hs", (*it)->GetString().c_str()); *rval = g_ScriptingHost.UCStringToValue((*it)->GetString()); g_Game->GetSimulation()->QueueLocalCommand(*it); } return JS_TRUE; } // Get the state of a given hotkey (from the hotkeys file) JSBool isOrderQueued( JSContext* cx, JSObject* UNUSED(obj), uint argc, jsval* argv, jsval* rval ) { JSU_REQUIRE_NO_PARAMS(); *rval = ToJSVal(hotkeys[HOTKEY_ORDER_QUEUE]); return JS_TRUE; } //----------------------------------------------------------------------------- // formations //----------------------------------------------------------------------------- JSBool CreateEntityFormation( JSContext* cx, JSObject* UNUSED(obj), uint argc, jsval* argv, jsval* rval ) { JSU_REQUIRE_PARAMS(2); CEntityList entities = *EntityCollection::RetrieveSet(cx, JSVAL_TO_OBJECT(argv[0])); CStrW name = ToPrimitive( argv[1] ); g_FormationManager.CreateFormation( entities, name ); *rval = JSVAL_VOID; return JS_TRUE; } JSBool RemoveFromFormation( JSContext* cx, JSObject* UNUSED(obj), uint argc, jsval* argv, jsval* rval ) { JSU_REQUIRE_PARAMS(1); CEntityList entities; - if (JS_GetClass(JSVAL_TO_OBJECT(argv[0])) == &CEntity::JSI_class) + if (JS_GetClass(cx, JSVAL_TO_OBJECT(argv[0])) == &CEntity::JSI_class) entities.push_back( (ToNative(argv[0])) ->me); else entities = *EntityCollection::RetrieveSet(cx, JSVAL_TO_OBJECT(argv[0])); *rval = g_FormationManager.RemoveUnitList(entities) ? JS_TRUE : JS_FALSE; return JS_TRUE; } JSBool LockEntityFormation( JSContext* cx, JSObject* UNUSED(obj), uint argc, jsval* argv, jsval* rval ) { JSU_REQUIRE_PARAMS(1); CEntity* entity = ToNative( argv[0] ); entity->GetFormation()->SetLock( ToPrimitive( argv[1] ) ); *rval = JSVAL_VOID; return JS_TRUE; } JSBool IsFormationLocked( JSContext* cx, JSObject* UNUSED(obj), uint argc, jsval* argv, jsval* rval ) { JSU_REQUIRE_PARAMS(1); CEntity* entity = ToNative( argv[0] ); *rval = entity->GetFormation()->IsLocked() ? JS_TRUE : JS_FALSE; return JS_TRUE; } //----------------------------------------------------------------------------- // Techs //----------------------------------------------------------------------------- JSBool GetTechnology( JSContext* cx, JSObject* UNUSED(obj), uint argc, jsval* argv, jsval* rval ) { JSU_REQUIRE_PARAMS(2); CStrW name; CPlayer* player; try { name = g_ScriptingHost.ValueToUCString( argv[0] ); player = ToNative( argv[1] ); } catch( PSERROR_Scripting_ConversionFailed ) { JS_ReportError( cx, "Invalid parameters for GetTechnology (expected name and player)" ); return( JS_TRUE ); } *rval = JSVAL_NULL; CTechnology* tech = g_TechnologyCollection.GetTechnology( name, player ); if ( tech ) *rval = ToJSVal( tech ); else g_Console->InsertMessage( L"Warning: Invalid tech template name \"%ls\" passed for GetTechnology()", name.c_str() ); return JS_TRUE; } //----------------------------------------------------------------------------- // Events //----------------------------------------------------------------------------- // Register a global handler for the specified DOM event. // params: event type name [wstring], handler [fragment or function] // returns: whether it was actually newly registered [bool] JSBool AddGlobalHandler( JSContext* cx, JSObject* UNUSED(obj), uint argc, jsval* argv, jsval* rval ) { JSU_REQUIRE_PARAMS(2); *rval = BOOLEAN_TO_JSVAL( g_JSGameEvents.AddHandlerJS( cx, argc, argv ) ); return( JS_TRUE ); } // Remove a previously registered global handler for the specified DOM event. // params: event type name [wstring], handler [fragment or function] // returns: whether it was successfully removed [bool] JSBool RemoveGlobalHandler( JSContext* cx, JSObject* UNUSED(obj), uint argc, jsval* argv, jsval* rval ) { JSU_REQUIRE_PARAMS(2); *rval = BOOLEAN_TO_JSVAL( g_JSGameEvents.RemoveHandlerJS( cx, argc, argv ) ); return( JS_TRUE ); } //----------------------------------------------------------------------------- // Timer //----------------------------------------------------------------------------- // Request a callback be executed after the specified delay. // params: callback [fragment or function], delay in milliseconds [int] // returns: // notes: // - Scripts and functions registered this way are called on the first // simulation frame after the specified period has elapsed. If this causes // multiple segments of code to be executed in the same frame, // relative timing is maintained. Delays of 0 milliseconds cause code to be // executed on the following simulation frame. If more than one script or // function is scheduled to execute in the same millisecond, the order of // execution is undefined. Code is scheduled in simulation time, and is // therefore suspended while the game is paused or frozen. Granularity of // timing is also limited to 1/(Simulation frame rate); currently 100ms. // The called function or script executes in the same scope as the // code that called SetTimeout (amongst other things, the // 'this' reference is usually maintained) JSBool SetTimeout( JSContext* cx, JSObject*, uint argc, jsval* argv, jsval* rval ) { JSU_REQUIRE_PARAM_RANGE(2, 3); size_t delay; try { delay = ToPrimitive( argv[1] ); } catch( PSERROR_Scripting_ConversionFailed ) { JS_ReportError( cx, "Invalid timer parameters" ); return( JS_TRUE ); } JSObject* scope; if( argc == 3 ) { if( !JSVAL_IS_OBJECT( argv[2] ) ) { JS_ReportError( cx, "Invalid timer parameters" ); return( JS_TRUE ); } scope = JSVAL_TO_OBJECT( argv[2] ); } else { scope = JS_GetScopeChain( cx ); } switch( JS_TypeOfValue( cx, argv[0] ) ) { case JSTYPE_STRING: { CStrW fragment = g_ScriptingHost.ValueToUCString( argv[0] ); int id = g_Scheduler.PushTime( delay, fragment, scope ); *rval = INT_TO_JSVAL( id ); return( JS_TRUE ); } case JSTYPE_FUNCTION: { JSFunction* fn = JS_ValueToFunction( cx, argv[0] ); int id = g_Scheduler.PushTime( delay, fn, scope ); *rval = INT_TO_JSVAL( id ); return( JS_TRUE ); } default: JS_ReportError( cx, "Invalid timer script" ); return( JS_TRUE ); } } // Request a callback be executed periodically. // params: callback [fragment or function], initial delay in ms [int], period in ms [int] // OR callback [fragment or function], period in ms [int] (initial delay = period) // returns: // notes: // - SetTimeout's notes apply here as well. JSBool SetInterval( JSContext* cx, JSObject*, uint argc, jsval* argv, jsval* rval ) { JSU_REQUIRE_PARAM_RANGE(2, 3); size_t first, interval; try { first = ToPrimitive( argv[1] ); if( argc == 3 ) { // toDo, first, interval interval = ToPrimitive( argv[2] ); } else { // toDo, interval (first = interval) interval = first; } } catch( PSERROR_Scripting_ConversionFailed ) { JS_ReportError( cx, "Invalid timer parameters" ); return( JS_TRUE ); } switch( JS_TypeOfValue( cx, argv[0] ) ) { case JSTYPE_STRING: { CStrW fragment = g_ScriptingHost.ValueToUCString( argv[0] ); int id = g_Scheduler.PushInterval( first, interval, fragment, JS_GetScopeChain( cx ) ); *rval = INT_TO_JSVAL( id ); return( JS_TRUE ); } case JSTYPE_FUNCTION: { JSFunction* fn = JS_ValueToFunction( cx, argv[0] ); int id = g_Scheduler.PushInterval( first, interval, fn, JS_GetScopeChain( cx ) ); *rval = INT_TO_JSVAL( id ); return( JS_TRUE ); } default: JS_ReportError( cx, "Invalid timer script" ); return( JS_TRUE ); } } // Cause all periodic functions registered via SetInterval to // no longer be called. // params: // returns: // notes: // - Execution continues until the end of the triggered function or // script fragment, but is not triggered again. JSBool CancelInterval( JSContext* cx, JSObject*, uint argc, jsval* argv, jsval* rval ) { JSU_REQUIRE_NO_PARAMS(); g_Scheduler.m_abortInterval = true; return( JS_TRUE ); } // Cause the scheduled task (timeout or interval) with the given ID to // no longer be called. // params: // returns: // notes: // - Execution continues until the end of the triggered function or // script fragment, but is not triggered again. JSBool CancelTimer( JSContext* cx, JSObject*, uint argc, jsval* argv, jsval* rval ) { JSU_REQUIRE_PARAMS(1); try { int id = ToPrimitive( argv[0] ); g_Scheduler.CancelTask( id ); } catch( PSERROR_Scripting_ConversionFailed ) { JS_ReportError( cx, "Invalid ID parameter" ); return( JS_TRUE ); } return( JS_TRUE ); } //Set the simulation rate scalar-time becomes time * SimRate. //Params: rate [float] : sets SimRate JSBool SetSimRate(JSContext* cx, JSObject*, uint argc, jsval* argv, jsval* rval) { JSU_REQUIRE_PARAMS(1); g_Game->SetSimRate( ToPrimitive(argv[0]) ); return JS_TRUE; } //Generate a random float in [0, 1) using the simulation's random generator JSBool SimRand(JSContext* cx, JSObject*, uint argc, jsval* argv, jsval* rval) { JSU_REQUIRE_NO_PARAMS(); *rval = ToJSVal( g_Game->GetSimulation()->RandFloat() ); return JS_TRUE; } //Generate a random float int between 0 and the given number - 1 using the simulation's RNG JSBool SimRandInt(JSContext* cx, JSObject*, uint argc, jsval* argv, jsval* rval) { JSU_REQUIRE_PARAMS(1); JSU_ASSERT(JSVAL_IS_INT(argv[0]), "SimRandInt(): first parameter must be an int"); *rval = ToJSVal( g_Game->GetSimulation()->RandInt(ToPrimitive(argv[0])) ); return JS_TRUE; } // Script profiling functions: Begin timing a piece of code with StartJsTimer(num) // and stop timing with StopJsTimer(num). The results will be printed to stdout // when the game exits. static const uint MAX_JS_TIMERS = 20; static Timer js_timer; static TimerUnit js_start_times[MAX_JS_TIMERS]; static TimerUnit js_timer_overhead; static TimerClient js_timer_clients[MAX_JS_TIMERS]; static char js_timer_descriptions_buf[MAX_JS_TIMERS * 12]; // depends on MAX_JS_TIMERS and format string below static void InitJsTimers() { char* pos = js_timer_descriptions_buf; for(uint i = 0; i < MAX_JS_TIMERS; i++) { const char* description = pos; pos += sprintf(pos, "js_timer %d", i)+1; timer_add_client(&js_timer_clients[i], description); } // call several times to get a good approximation of 'hot' performance. // note: don't use a separate timer slot to warm up and then judge // overhead from another: that causes worse results (probably some // caching effects inside JS, but I don't entirely understand why). static const char* calibration_script = "startXTimer(0);\n" "stopXTimer (0);\n" "startXTimer(0);\n" "stopXTimer (0);\n" "startXTimer(0);\n" "stopXTimer (0);\n" "startXTimer(0);\n" "stopXTimer (0);\n" "\n"; g_ScriptingHost.RunMemScript(calibration_script, strlen(calibration_script)); js_timer_overhead = js_timer_clients[0].sum/4; } JSBool StartJsTimer(JSContext* cx, JSObject*, uint argc, jsval* argv, jsval* rval) { ONCE(InitJsTimers()); JSU_REQUIRE_PARAMS(1); uint slot = ToPrimitive(argv[0]); if (slot >= MAX_JS_TIMERS) return JS_FALSE; debug_assert(js_start_times[slot] == 0); js_start_times[slot] = js_timer.get_timestamp(); return JS_TRUE; } JSBool StopJsTimer(JSContext* cx, JSObject*, uint argc, jsval* argv, jsval* rval) { JSU_REQUIRE_PARAMS(1); uint slot = ToPrimitive(argv[0]); if (slot >= MAX_JS_TIMERS) return JS_FALSE; debug_assert(js_start_times[slot] != 0); TimerUnit dt = js_timer.get_timestamp() - js_start_times[slot] - js_timer_overhead; js_start_times[slot] = 0; timer_bill_client(&js_timer_clients[slot], dt); return JS_TRUE; } //----------------------------------------------------------------------------- // Game Setup //----------------------------------------------------------------------------- // Create a new network server object. // params: // returns: net server object JSBool CreateServer(JSContext* cx, JSObject*, uint argc, jsval* argv, jsval* rval) { JSU_REQUIRE_NO_PARAMS(); if( !g_Game ) g_Game = new CGame(); if( !g_NetServer ) g_NetServer = new CNetServer(g_Game, &g_GameAttributes); *rval = OBJECT_TO_JSVAL(g_NetServer->GetScript()); return( JS_TRUE ); } // Create a new network client object. // params: // returns: net client object JSBool CreateClient(JSContext* cx, JSObject*, uint argc, jsval* argv, jsval* rval) { JSU_REQUIRE_NO_PARAMS(); if( !g_Game ) g_Game = new CGame(); if( !g_NetClient ) g_NetClient = new CNetClient(g_Game, &g_GameAttributes); *rval = OBJECT_TO_JSVAL(g_NetClient->GetScript()); return( JS_TRUE ); } // Begin the process of starting a game. // params: // returns: success [bool] // notes: // - Performs necessary initialization while calling back into the // main loop, so the game remains responsive to display+user input. // - When complete, the engine calls the reallyStartGame JS function. // TODO: Replace StartGame with Create(Game|Server|Client)/game.start() - // after merging CGame and CGameAttributes JSBool StartGame(JSContext* cx, JSObject*, uint argc, jsval* argv, jsval* rval) { JSU_REQUIRE_NO_PARAMS(); *rval = BOOLEAN_TO_JSVAL(JS_TRUE); // Hosted MP Game if (g_NetServer) { *rval = BOOLEAN_TO_JSVAL(g_NetServer->StartGame() == 0); } // Joined MP Game else if (g_NetClient) { *rval = BOOLEAN_TO_JSVAL(g_NetClient->StartGame() == 0); } // Start an SP Game Session else if (!g_Game) { g_Game = new CGame(); PSRETURN ret = g_Game->StartGame(&g_GameAttributes); if (ret != PSRETURN_OK) { // Failed to start the game - destroy it, and return false delete g_Game; g_Game = NULL; *rval = BOOLEAN_TO_JSVAL(JS_FALSE); return( JS_TRUE ); } } else { *rval = BOOLEAN_TO_JSVAL(JS_FALSE); } return( JS_TRUE ); } // Immediately ends the current game (if any). // params: // returns: JSBool EndGame(JSContext* cx, JSObject*, uint argc, jsval* argv, jsval* rval) { JSU_REQUIRE_NO_PARAMS(); EndGame(); return JS_TRUE; } JSBool GetGameMode(JSContext* cx, JSObject*, uint argc, jsval* argv, jsval* rval) { JSU_REQUIRE_NO_PARAMS(); *rval = ToJSVal( g_GameAttributes.GetGameMode() ); return JS_TRUE; } //----------------------------------------------------------------------------- // Internationalization //----------------------------------------------------------------------------- // these remain here instead of in the i18n tree because they are // really related to the engine's use of them, as opposed to i18n itself. // contrariwise, translate() cannot be moved here because that would // make i18n dependent on this code and therefore harder to reuse. // Replaces the current language (locale) with a new one. // params: language id [string] as in I18n::LoadLanguage // returns: JSBool LoadLanguage(JSContext* cx, JSObject*, uint argc, jsval* argv, jsval* rval) { JSU_REQUIRE_PARAMS(1); CStr lang = g_ScriptingHost.ValueToString(argv[0]); I18n::LoadLanguage(lang); return JS_TRUE; } // Return identifier of the current language (locale) in use. // params: // returns: language id [string] as in I18n::LoadLanguage JSBool GetLanguageID(JSContext* cx, JSObject*, uint argc, jsval* argv, jsval* rval) { JSU_REQUIRE_NO_PARAMS(); *rval = JSVAL_NULL; JSString* s = JS_NewStringCopyZ(cx, I18n::CurrentLanguageName()); if (!s) { JS_ReportError(cx, "Error creating string"); return JS_FALSE; } *rval = STRING_TO_JSVAL(s); return JS_TRUE; } //----------------------------------------------------------------------------- // Debug //----------------------------------------------------------------------------- // Deliberately cause the game to crash. // params: // returns: // notes: // - currently implemented via access violation (read of address 0) // - useful for testing the crashlog/stack trace code. JSBool ProvokeCrash(JSContext* cx, JSObject*, uint argc, jsval* argv, jsval* rval) { JSU_REQUIRE_NO_PARAMS(); MICROLOG(L"Crashing at user's request."); return *(JSBool*)0; } // Force a JS garbage collection cycle to take place immediately. // params: // returns: true [bool] // notes: // - writes an indication of how long this took to the console. JSBool ForceGarbageCollection(JSContext* cx, JSObject* UNUSED(obj), uint argc, jsval* argv, jsval* rval) { JSU_REQUIRE_NO_PARAMS(); double time = get_time(); JS_GC(cx); time = get_time() - time; g_Console->InsertMessage(L"Garbage collection completed in: %f", time); *rval = JSVAL_TRUE; return JS_TRUE ; } //----------------------------------------------------------------------------- // GUI //----------------------------------------------------------------------------- // Returns the sort-of-global object associated with the current GUI. // params: // returns: global object // notes: // - Useful for accessing an object from another scope. JSBool GetGuiGlobal(JSContext* cx, JSObject*, uint argc, jsval* argv, jsval* rval) { JSU_REQUIRE_NO_PARAMS(); *rval = OBJECT_TO_JSVAL(g_GUI.GetScriptObject()); return JS_TRUE; } // Resets the entire GUI state and reloads the XML files. // params: // returns: JSBool ResetGui(JSContext* cx, JSObject*, uint argc, jsval* argv, jsval* rval) { JSU_REQUIRE_NO_PARAMS(); // Slightly unpleasant code, because CGUI is a Singleton but we don't really // want it to be g_GUI.Destroy(); delete &g_GUI; new CGUI; GUI_Init(); g_GUI.SendEventToAll("load"); return JS_TRUE; } //----------------------------------------------------------------------------- // Misc. Engine Interface //----------------------------------------------------------------------------- // Return the global frames-per-second value. // params: // returns: FPS [int] // notes: // - This value is recalculated once a frame. We take special care to // filter it, so it is both accurate and free of jitter. JSBool GetFps( JSContext* cx, JSObject*, uint argc, jsval* argv, jsval* rval ) { JSU_REQUIRE_NO_PARAMS(); *rval = INT_TO_JSVAL(fps); return JS_TRUE; } // Cause the game to exit gracefully. // params: // returns: // notes: // - Exit happens after the current main loop iteration ends // (since this only sets a flag telling it to end) JSBool ExitProgram( JSContext* cx, JSObject*, uint argc, jsval* argv, jsval* rval ) { JSU_REQUIRE_NO_PARAMS(); kill_mainloop(); return JS_TRUE; } // Write an indication of total/available video RAM to console. // params: // returns: // notes: // - Not supported on all platforms. // - Only a rough approximation; do not base low-level decisions // ("should I allocate one more texture?") on this. JSBool WriteVideoMemToConsole( JSContext* cx, JSObject*, uint argc, jsval* argv, jsval* rval ) { JSU_REQUIRE_NO_PARAMS(); #if OS_WIN int left, total; if (GetVRAMInfo(left, total)) g_Console->InsertMessage(L"VRAM: used %d, total %d, free %d", total-left, total, left); else g_Console->InsertMessage(L"VRAM: failed to detect"); #else g_Console->InsertMessage(L"VRAM: [not available on non-Windows]"); #endif return JS_TRUE; } // Change the mouse cursor. // params: cursor name [string] (i.e. basename of definition file and texture) // returns: // notes: // - Cursors are stored in "art\textures\cursors" JSBool SetCursor( JSContext* cx, JSObject*, uint argc, jsval* argv, jsval* rval ) { JSU_REQUIRE_PARAMS(1); g_CursorName = g_ScriptingHost.ValueToString(argv[0]); return JS_TRUE; } JSBool GetCursorName( JSContext* UNUSED(cx), JSObject*, uint UNUSED(argc), jsval* UNUSED(argv), jsval* rval ) { *rval = ToJSVal(g_CursorName); return JS_TRUE; } // Trigger a rewrite of all maps. // params: // returns: // notes: // - Usefulness is unclear. If you need it, consider renaming this and updating the docs. JSBool _RewriteMaps( JSContext* cx, JSObject*, uint argc, jsval* argv, jsval* rval ) { JSU_REQUIRE_NO_PARAMS(); g_Game->GetWorld()->RewriteMap(); return JS_TRUE; } // Change the LOD bias. // params: LOD bias [float] // returns: // notes: // - value is as required by GL_TEXTURE_LOD_BIAS. // - useful for adjusting image "sharpness" (since it affects which mipmap level is chosen) JSBool _LodBias( JSContext* cx, JSObject*, uint argc, jsval* argv, jsval* rval ) { JSU_REQUIRE_PARAMS(1); g_Renderer.SetOptionFloat(CRenderer::OPT_LODBIAS, ToPrimitive(argv[0])); return JS_TRUE; } // Focus the game camera on a given position. // params: target position vector [CVector3D] // returns: success [bool] JSBool SetCameraTarget( JSContext* cx, JSObject* UNUSED(obj), uint argc, jsval* argv, jsval* rval ) { JSU_REQUIRE_PARAMS(1); *rval = JSVAL_NULL; CVector3D* target = ToNative( argv[0] ); if(!target) { JS_ReportError( cx, "Invalid camera target" ); return( JS_TRUE ); } g_Game->GetView()->SetCameraTarget( *target ); *rval = JSVAL_TRUE; return( JS_TRUE ); } //----------------------------------------------------------------------------- // Miscellany //----------------------------------------------------------------------------- // Return the date/time at which the current executable was compiled. // params: none (-> "date time") OR // what to display [int]: 0 (-> "date"); 1 (-> "time") // returns: date and/or time [string] // notes: // - Displayed on main menu screen; tells non-programmers which auto-build // they are running. Could also be determined via .EXE file properties, // but that's a bit more trouble. // - To be exact, the date/time returned is when scriptglue.cpp was // last compiled; since the auto-build does full rebuilds, that is moot. JSBool GetBuildTimestamp( JSContext* cx, JSObject*, uint argc, jsval* argv, jsval* rval ) { JSU_REQUIRE_PARAM_RANGE(0, 1); // no param => "date time" // param = 0 => "date" // param = 1 => "time" JSString* s = JS_NewStringCopyZ(cx, argc && argv[0]==JSVAL_ONE ? __TIME__ : argc ? __DATE__ : __DATE__" "__TIME__ ); *rval = STRING_TO_JSVAL(s); return JS_TRUE; } // Return distance between 2 points. // params: 2 position vectors [CVector3D] // returns: Euclidean distance [float] JSBool ComputeDistanceBetweenTwoPoints( JSContext* cx, JSObject* UNUSED(obj), uint argc, jsval* argv, jsval* rval ) { JSU_REQUIRE_PARAMS(2); CVector3D* a = ToNative( argv[0] ); CVector3D* b = ToNative( argv[1] ); float dist = ( *a - *b ).Length(); *rval = ToJSVal( dist ); return( JS_TRUE ); } // Returns the global object. // params: // returns: global object // notes: // - Useful for accessing an object from another scope. JSBool GetGlobal( JSContext* cx, JSObject* globalObject, uint argc, jsval* argv, jsval* rval ) { JSU_REQUIRE_NO_PARAMS(); *rval = OBJECT_TO_JSVAL( globalObject ); return( JS_TRUE ); } // Saves the current profiling data to the logs/profile.txt file JSBool SaveProfileData( JSContext* cx, JSObject* UNUSED(globalObject), uint argc, jsval* argv, jsval* rval ) { JSU_REQUIRE_NO_PARAMS(); g_ProfileViewer.SaveToFile(); return( JS_TRUE ); } // Activates the building placement cursor for placing a building. The currently selected units // are then ordered to construct the building if it is placed. // params: templateName - the name of the entity to place. // returns: true if cursor was activated, false if cursor was already active. JSBool StartPlacing( JSContext* cx, JSObject* UNUSED(globalObject), uint argc, jsval* argv, jsval* rval ) { CStrW name; if(argc == 0) { name = L"hele_ho"; // save some typing during testing } else { if(!ToPrimitive( g_ScriptingHost.GetContext(), argv[0], name )) { JS_ReportError( cx, "Invalid template name argument" ); *rval = JSVAL_NULL; return( JS_FALSE ); } } *rval = g_BuildingPlacer.Activate(name) ? JS_TRUE : JS_FALSE; return( JS_TRUE ); } // Toggles drawing the sky JSBool ToggleSky( JSContext* cx, JSObject* UNUSED(globalObject), uint argc, jsval* argv, jsval* rval ) { JSU_REQUIRE_NO_PARAMS(); g_Renderer.GetSkyManager()->m_RenderSky = !g_Renderer.GetSkyManager()->m_RenderSky; *rval = JSVAL_VOID; return( JS_TRUE ); } // Toggles drawing territory outlines JSBool ToggleTerritoryRendering( JSContext* cx, JSObject* UNUSED(globalObject), uint argc, jsval* argv, jsval* rval ) { JSU_REQUIRE_NO_PARAMS(); g_Renderer.m_RenderTerritories = !g_Renderer.m_RenderTerritories; *rval = JSVAL_VOID; return( JS_TRUE ); } //----------------------------------------------------------------------------- // water // Toggles drawing the water plane JSBool ToggleWater( JSContext* cx, JSObject* UNUSED(globalObject), uint argc, jsval* argv, jsval* rval ) { JSU_REQUIRE_NO_PARAMS(); g_Renderer.GetWaterManager()->m_RenderWater = !g_Renderer.GetWaterManager()->m_RenderWater; *rval = JSVAL_VOID; return( JS_TRUE ); } // Sets the water plane height JSBool SetWaterHeight( JSContext* cx, JSObject* UNUSED(globalObject), uint argc, jsval* argv, jsval* rval ) { JSU_REQUIRE_PARAMS( 1 ); float newHeight; if(!ToPrimitive( g_ScriptingHost.GetContext(), argv[0], newHeight )) { JS_ReportError( cx, "Invalid water height argument" ); *rval = JSVAL_VOID; return( JS_FALSE ); } g_Renderer.GetWaterManager()->m_WaterHeight = newHeight; g_TerrainModified = true; *rval = JSVAL_VOID; return( JS_TRUE ); } // Gets the water plane height JSBool GetWaterHeight( JSContext* cx, JSObject* UNUSED(globalObject), uint argc, jsval* argv, jsval* rval ) { JSU_REQUIRE_NO_PARAMS(); *rval = ToJSVal(g_Renderer.GetWaterManager()->m_WaterHeight); return( JS_TRUE ); } // Sets the water color JSBool SetWaterColor( JSContext* cx, JSObject* UNUSED(globalObject), uint argc, jsval* argv, jsval* rval ) { JSU_REQUIRE_PARAMS( 3 ); float r,g,b; if(!ToPrimitive( g_ScriptingHost.GetContext(), argv[0], r ) || !ToPrimitive( g_ScriptingHost.GetContext(), argv[1], g ) || !ToPrimitive( g_ScriptingHost.GetContext(), argv[2], b )) { JS_ReportError( cx, "Invalid arguments" ); *rval = JSVAL_VOID; return( JS_FALSE ); } g_Renderer.GetWaterManager()->m_WaterColor = CColor(r, g, b, 1.0f); *rval = JSVAL_VOID; return( JS_TRUE ); } // Sets the water tint (used to tint reflections in fancy water) JSBool SetWaterTint( JSContext* cx, JSObject* UNUSED(globalObject), uint argc, jsval* argv, jsval* rval ) { JSU_REQUIRE_PARAMS( 3 ); float r,g,b; if(!ToPrimitive( g_ScriptingHost.GetContext(), argv[0], r ) || !ToPrimitive( g_ScriptingHost.GetContext(), argv[1], g ) || !ToPrimitive( g_ScriptingHost.GetContext(), argv[2], b )) { JS_ReportError( cx, "Invalid arguments" ); *rval = JSVAL_VOID; return( JS_FALSE ); } g_Renderer.GetWaterManager()->m_WaterTint = CColor(r, g, b, 1.0f); *rval = JSVAL_VOID; return( JS_TRUE ); } // Sets the water tint (used to tint reflections in fancy water) JSBool SetReflectionTint( JSContext* cx, JSObject* UNUSED(globalObject), uint argc, jsval* argv, jsval* rval ) { JSU_REQUIRE_PARAMS( 3 ); float r,g,b; if(!ToPrimitive( g_ScriptingHost.GetContext(), argv[0], r ) || !ToPrimitive( g_ScriptingHost.GetContext(), argv[1], g ) || !ToPrimitive( g_ScriptingHost.GetContext(), argv[2], b )) { JS_ReportError( cx, "Invalid arguments" ); *rval = JSVAL_VOID; return( JS_FALSE ); } g_Renderer.GetWaterManager()->m_ReflectionTint = CColor(r, g, b, 1.0f); *rval = JSVAL_VOID; return( JS_TRUE ); } // Sets the max water alpha (achieved when it is at WaterFullDepth or deeper) JSBool SetWaterMaxAlpha( JSContext* cx, JSObject* UNUSED(globalObject), uint argc, jsval* argv, jsval* rval ) { JSU_REQUIRE_PARAMS( 1 ); float val; if(!ToPrimitive( g_ScriptingHost.GetContext(), argv[0], val )) { JS_ReportError( cx, "Invalid argument" ); *rval = JSVAL_VOID; return( JS_FALSE ); } g_Renderer.GetWaterManager()->m_WaterMaxAlpha = val; *rval = JSVAL_VOID; return( JS_TRUE ); } // Sets the water full depth (when it is colored WaterMaxAlpha) JSBool SetWaterFullDepth( JSContext* cx, JSObject* UNUSED(globalObject), uint argc, jsval* argv, jsval* rval ) { JSU_REQUIRE_PARAMS( 1 ); float val; if(!ToPrimitive( g_ScriptingHost.GetContext(), argv[0], val )) { JS_ReportError( cx, "Invalid argument" ); *rval = JSVAL_VOID; return( JS_FALSE ); } g_Renderer.GetWaterManager()->m_WaterFullDepth = val; *rval = JSVAL_VOID; return( JS_TRUE ); } // Sets the water alpha offset (added to tweak water alpha near the shore) JSBool SetWaterAlphaOffset( JSContext* cx, JSObject* UNUSED(globalObject), uint argc, jsval* argv, jsval* rval ) { JSU_REQUIRE_PARAMS( 1 ); float val; if(!ToPrimitive( g_ScriptingHost.GetContext(), argv[0], val )) { JS_ReportError( cx, "Invalid argument" ); *rval = JSVAL_VOID; return( JS_FALSE ); } g_Renderer.GetWaterManager()->m_WaterAlphaOffset = val; *rval = JSVAL_VOID; return( JS_TRUE ); } //----------------------------------------------------------------------------- // Is the game paused? JSBool IsPaused( JSContext* cx, JSObject* UNUSED(globalObject), uint argc, jsval* argv, jsval* rval ) { JSU_REQUIRE_NO_PARAMS(); if( !g_Game ) { JS_ReportError( cx, "Game is not started" ); return JS_FALSE; } *rval = g_Game->m_Paused ? JSVAL_TRUE : JSVAL_FALSE; return JS_TRUE ; } // Pause/unpause the game JSBool SetPaused( JSContext* cx, JSObject* UNUSED(globalObject), uint argc, jsval* argv, jsval* rval ) { JSU_REQUIRE_PARAMS( 1 ); if( !g_Game ) { JS_ReportError( cx, "Game is not started" ); return JS_FALSE; } try { g_Game->m_Paused = ToPrimitive( argv[0] ); } catch( PSERROR_Scripting_ConversionFailed ) { JS_ReportError( cx, "Invalid parameter to SetPaused" ); } return JS_TRUE; } // Get game time JSBool GetGameTime( JSContext* cx, JSObject* UNUSED(globalObject), uint argc, jsval* argv, jsval* rval ) { JSU_REQUIRE_NO_PARAMS(); if( !g_Game ) { JS_ReportError( cx, "Game is not started" ); return JS_FALSE; } *rval = ToJSVal(g_Game->GetTime()); return JS_TRUE; } JSBool RegisterTrigger( JSContext* cx, JSObject* UNUSED(globalObject), uint argc, jsval* argv, jsval* rval ) { JSU_REQUIRE_PARAMS_CPP(1); CTrigger* trigger = ToNative( argv[0] ); debug_assert( trigger ); g_TriggerManager.AddTrigger( trigger ); *rval = JSVAL_NULL; return JS_TRUE; } JSBool GetTrigger( JSContext* cx, JSObject* UNUSED(globalObject), uint argc, jsval* argv, jsval* rval ) { JSU_REQUIRE_PARAMS_CPP(1); CStrW name = ToPrimitive( argv[0] ); if ( g_TriggerManager.m_TriggerMap.find(name) != g_TriggerManager.m_TriggerMap.end() ) *rval = ToJSVal( g_TriggerManager.m_TriggerMap[name] ); else { debug_printf("Invalid trigger name %ws", name.c_str()); *rval = JSVAL_NULL; } return JS_TRUE; } // Reveal map JSBool RevealMap( JSContext* cx, JSObject* UNUSED(globalObject), uint argc, jsval* argv, jsval* rval ) { JSU_REQUIRE_PARAM_RANGE(0, 1); uint newValue; if(argc == 0) { newValue = 2; } else if(!ToPrimitive( g_ScriptingHost.GetContext(), argv[0], newValue ) || newValue > 2) { JS_ReportError( cx, "Invalid argument (should be 0, 1 or 2)" ); *rval = JSVAL_VOID; return( JS_FALSE ); } g_Game->GetWorld()->GetLOSManager()->m_LOSSetting = newValue; *rval = JSVAL_VOID; return( JS_TRUE ); } //----------------------------------------------------------------------------- // function table //----------------------------------------------------------------------------- // the JS interpreter expects the table to contain 5-tuples as follows: // - name the function will be called as from script; // - function which will be called; // - number of arguments this function expects // - Flags (deprecated, always zero) // - Extra (reserved for future use, always zero) // // we simplify this a bit with a macro: #define JS_FUNC(script_name, cpp_function, min_params) { script_name, cpp_function, min_params, 0, 0 }, JSFunctionSpec ScriptFunctionTable[] = { // Console JS_FUNC("writeConsole", JSI_Console::writeConsole, 1) // external // Entity JS_FUNC("getEntityByUnitID", GetEntityByUnitID, 1) JS_FUNC("GetPlayerUnitCount", GetPlayerUnitCount, 1) JS_FUNC("getEntityTemplate", GetEntityTemplate, 1) JS_FUNC("issueCommand", IssueCommand, 2) JS_FUNC("startPlacing", StartPlacing, 1) // Formation JS_FUNC("createEntityFormation", CreateEntityFormation, 2) JS_FUNC("removeFromFormation", RemoveFromFormation, 1) JS_FUNC("lockEntityFormation", LockEntityFormation, 1) JS_FUNC("isFormationLocked", IsFormationLocked, 1) // Trigger JS_FUNC("registerTrigger", RegisterTrigger, 1) // Tech JS_FUNC("getTechnology", GetTechnology, 2) // Camera JS_FUNC("setCameraTarget", SetCameraTarget, 1) // Sky JS_FUNC("toggleSky", ToggleSky, 0) // Water JS_FUNC("toggleWater", ToggleWater, 0) JS_FUNC("setWaterHeight", SetWaterHeight, 1) JS_FUNC("getWaterHeight", GetWaterHeight, 0) JS_FUNC("setWaterColor", SetWaterColor, 3) JS_FUNC("setWaterTint", SetWaterTint, 3) JS_FUNC("setReflectionTint", SetReflectionTint, 3) JS_FUNC("setWaterMaxAlpha", SetWaterMaxAlpha, 0) JS_FUNC("setWaterFullDepth", SetWaterFullDepth, 0) JS_FUNC("setWaterAlphaOffset", SetWaterAlphaOffset, 0) // Territory rendering JS_FUNC("toggleTerritoryRendering", ToggleTerritoryRendering, 0) // GUI #ifndef NO_GUI JS_FUNC("getGUIObjectByName", JSI_IGUIObject::getByName, 1) // external JS_FUNC("getGUIGlobal", GetGuiGlobal, 0) JS_FUNC("resetGUI", ResetGui, 0) #endif // Events JS_FUNC("addGlobalHandler", AddGlobalHandler, 2) JS_FUNC("removeGlobalHandler", RemoveGlobalHandler, 2) // Timer JS_FUNC("setTimeout", SetTimeout, 2) JS_FUNC("setInterval", SetInterval, 2) JS_FUNC("cancelInterval", CancelInterval, 0) JS_FUNC("cancelTimer", CancelTimer, 0) JS_FUNC("setSimRate", SetSimRate, 1) // Random number generator JS_FUNC("simRand", SimRand, 0) JS_FUNC("simRandInt", SimRandInt, 1) // Profiling JS_FUNC("startXTimer", StartJsTimer, 1) JS_FUNC("stopXTimer", StopJsTimer, 1) // Game Setup JS_FUNC("startGame", StartGame, 0) JS_FUNC("endGame", EndGame, 0) JS_FUNC("getGameMode", GetGameMode, 0) JS_FUNC("createClient", CreateClient, 0) JS_FUNC("createServer", CreateServer, 0) // VFS (external) JS_FUNC("buildDirEntList", JSI_VFS::BuildDirEntList, 1) JS_FUNC("getFileMTime", JSI_VFS::GetFileMTime, 1) JS_FUNC("getFileSize", JSI_VFS::GetFileSize, 1) JS_FUNC("readFile", JSI_VFS::ReadFile, 1) JS_FUNC("readFileLines", JSI_VFS::ReadFileLines, 1) JS_FUNC("archiveBuilderCancel", JSI_VFS::ArchiveBuilderCancel, 1) // Internationalization JS_FUNC("loadLanguage", LoadLanguage, 1) JS_FUNC("getLanguageID", GetLanguageID, 0) // note: i18n/ScriptInterface.cpp registers translate() itself. // rationale: see implementation section above. // Debug JS_FUNC("crash", ProvokeCrash, 0) JS_FUNC("forceGC", ForceGarbageCollection, 0) JS_FUNC("revealMap", RevealMap, 1) // Misc. Engine Interface JS_FUNC("writeLog", WriteLog, 1) JS_FUNC("exit", ExitProgram, 0) JS_FUNC("isPaused", IsPaused, 0) JS_FUNC("setPaused", SetPaused, 1) JS_FUNC("getGameTime", GetGameTime, 0) JS_FUNC("vmem", WriteVideoMemToConsole, 0) JS_FUNC("_rewriteMaps", _RewriteMaps, 0) JS_FUNC("_lodBias", _LodBias, 0) JS_FUNC("setCursor", SetCursor, 1) JS_FUNC("getCursorName", GetCursorName, 0) JS_FUNC("getFPS", GetFps, 0) JS_FUNC("isOrderQueued", isOrderQueued, 1) // Miscellany JS_FUNC("v3dist", ComputeDistanceBetweenTwoPoints, 2) JS_FUNC("buildTime", GetBuildTimestamp, 0) JS_FUNC("getGlobal", GetGlobal, 0) JS_FUNC("saveProfileData", SaveProfileData, 0) // end of table marker {0, 0, 0, 0, 0} }; #undef JS_FUNC //----------------------------------------------------------------------------- // property accessors //----------------------------------------------------------------------------- JSBool GetEntitySet( JSContext* UNUSED(cx), JSObject* UNUSED(obj), jsval UNUSED(argv), jsval* vp ) { std::vector extant; g_EntityManager.GetExtantAsHandles(extant); *vp = OBJECT_TO_JSVAL(EntityCollection::Create(extant)); return JS_TRUE; } JSBool GetPlayerSet( JSContext* UNUSED(cx), JSObject* UNUSED(obj), jsval UNUSED(id), jsval* vp ) { std::vector* players = g_Game->GetPlayers(); *vp = OBJECT_TO_JSVAL( PlayerCollection::Create( *players ) ); return( JS_TRUE ); } JSBool GetLocalPlayer( JSContext* UNUSED(cx), JSObject* UNUSED(obj), jsval UNUSED(id), jsval* vp ) { *vp = OBJECT_TO_JSVAL( g_Game->GetLocalPlayer()->GetScript() ); return( JS_TRUE ); } JSBool GetGaiaPlayer( JSContext* UNUSED(cx), JSObject* UNUSED(obj), jsval UNUSED(id), jsval* vp ) { *vp = OBJECT_TO_JSVAL( g_Game->GetPlayer( 0 )->GetScript() ); return( JS_TRUE ); } JSBool SetLocalPlayer( JSContext* cx, JSObject* UNUSED(obj), jsval UNUSED(id), jsval* vp ) { CPlayer* newLocalPlayer = ToNative( *vp ); if( !newLocalPlayer ) { JS_ReportError( cx, "Not a valid Player." ); return( JS_TRUE ); } g_Game->SetLocalPlayer( newLocalPlayer ); return( JS_TRUE ); } JSBool GetGameView( JSContext* UNUSED(cx), JSObject* UNUSED(obj), jsval UNUSED(id), jsval* vp ) { if (g_Game) *vp = OBJECT_TO_JSVAL( g_Game->GetView()->GetScript() ); else *vp = JSVAL_NULL; return( JS_TRUE ); } JSBool GetRenderer( JSContext* UNUSED(cx), JSObject* UNUSED(obj), jsval UNUSED(id), jsval* vp ) { if (CRenderer::IsInitialised()) *vp = OBJECT_TO_JSVAL( g_Renderer.GetScript() ); else *vp = JSVAL_NULL; return( JS_TRUE ); } enum ScriptGlobalTinyIDs { GLOBAL_SELECTION, GLOBAL_GROUPSARRAY, GLOBAL_CAMERA, GLOBAL_CONSOLE, GLOBAL_LIGHTENV }; // shorthand #define PERM JSPROP_PERMANENT #define CONST JSPROP_READONLY JSPropertySpec ScriptGlobalTable[] = { { "selection" , GLOBAL_SELECTION, PERM, JSI_Selection::getSelection, JSI_Selection::SetSelection }, { "groups" , GLOBAL_GROUPSARRAY, PERM, JSI_Selection::getGroups, JSI_Selection::setGroups }, { "camera" , GLOBAL_CAMERA, PERM, JSI_Camera::getCamera, JSI_Camera::setCamera }, { "console" , GLOBAL_CONSOLE, PERM | CONST, JSI_Console::getConsole, 0 }, { "lightenv" , GLOBAL_LIGHTENV, PERM, JSI_LightEnv::getLightEnv, JSI_LightEnv::setLightEnv }, { "entities" , 0, PERM | CONST, GetEntitySet, 0 }, { "players" , 0, PERM | CONST, GetPlayerSet, 0 }, { "localPlayer", 0, PERM , GetLocalPlayer, SetLocalPlayer }, { "gaiaPlayer" , 0, PERM | CONST, GetGaiaPlayer, 0 }, { "gameView" , 0, PERM | CONST, GetGameView, 0 }, { "renderer" , 0, PERM | CONST, GetRenderer, 0 }, // end of table marker { 0, 0, 0, 0, 0 }, }; Index: ps/trunk/source/lib/sysdep/unix/bsd.h =================================================================== --- ps/trunk/source/lib/sysdep/unix/bsd.h (revision 5153) +++ ps/trunk/source/lib/sysdep/unix/bsd.h (revision 5154) @@ -1,8 +1,8 @@ -#ifndef INCLUDED_BSD -#define INCLUDED_BSD - -#include "../cpu.h" - -extern size_t bsd_MemorySize(CpuMemoryIndicators mem_type); - -#endif // #ifndef INCLUDED_BSD +#ifndef INCLUDED_BSD +#define INCLUDED_BSD + +#include "../cpu.h" + +extern size_t bsd_MemorySize(CpuMemoryIndicators mem_type); + +#endif // #ifndef INCLUDED_BSD Property changes on: ps/trunk/source/lib/sysdep/unix/bsd.h ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property