1
0
forked from 0ad/0ad

wxJS: Added wxSpinCtrl. Added wxWindow::DestroyChildren.

Disabled in-game cursor in Atlas on Linux.

This was SVN commit r5164.
This commit is contained in:
Ykkrosh 2007-06-10 23:15:14 +00:00
parent 69404654bf
commit 5b904a69c9
17 changed files with 636 additions and 53 deletions

View File

@ -442,7 +442,10 @@ void Render()
// Draw the cursor (or set the Windows cursor, on Windows)
CStr cursorName = g_BuildingPlacer.m_active ? "action-build" : g_CursorName;
cursor_draw(cursorName, g_mouse_x, g_mouse_y);
if (cursorName.empty())
cursor_draw(NULL, g_mouse_x, g_mouse_y);
else
cursor_draw(cursorName, g_mouse_x, g_mouse_y);
// restore
glMatrixMode(GL_PROJECTION);

View File

@ -113,7 +113,7 @@ struct ScriptInterface_impl
{
ScriptInterface_impl();
~ScriptInterface_impl();
void LoadScript(const wxString& filename, const wxString& code);
static JSBool LoadScript(JSContext* cx, const jschar* chars, uintN length, const char* filename, jsval* rval);
void RegisterMessages(JSObject* parent);
void Register(const char* name, JSNative fptr, uintN nargs);
@ -156,19 +156,9 @@ namespace
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), (uintN)JS_GetStringLength(code),
JS_GetStringBytes(name), 1, &scriptRval);
if (! ok)
return JS_FALSE;
return JS_TRUE;
return ScriptInterface_impl::LoadScript(cx,
JS_GetStringChars(code), (uintN)JS_GetStringLength(code),
JS_GetStringBytes(name), rval);
}
JSBool ForceGC(JSContext* cx, JSObject* WXUNUSED(obj), uintN WXUNUSED(argc), jsval* WXUNUSED(argv), jsval* WXUNUSED(rval))
@ -186,6 +176,7 @@ namespace
return JS_FALSE;
printf("%s", str.c_str());
}
fflush(stdout);
return JS_TRUE;
}
}
@ -211,6 +202,8 @@ ScriptInterface_impl::ScriptInterface_impl()
m_glob = JS_NewObject(m_cx, &global_class, NULL, NULL);
ok = JS_InitStandardClasses(m_cx, m_glob);
JS_DefineProperty(m_cx, m_glob, "global", OBJECT_TO_JSVAL(m_glob), NULL, NULL, JSPROP_ENUMERATE|JSPROP_READONLY|JSPROP_PERMANENT);
wxjs::gui::InitClass(m_cx, m_glob);
wxjs::io::InitClass(m_cx, m_glob);
@ -232,13 +225,19 @@ ScriptInterface_impl::~ScriptInterface_impl()
JS_DestroyRuntime(m_rt);
}
void ScriptInterface_impl::LoadScript(const wxString& filename, const wxString& code)
JSBool ScriptInterface_impl::LoadScript(JSContext* cx, const jschar* chars, uintN length, const char* filename, jsval* rval)
{
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<jschar*>(codeUTF16.data()), (uintN)(codeLength/2), filename.ToAscii(), 1, &rval);
JSObject* scriptObj = JS_NewObject(cx, NULL, NULL, NULL);
if (! scriptObj)
return JS_FALSE;
*rval = OBJECT_TO_JSVAL(scriptObj);
jsval scriptRval;
JSBool ok = JS_EvaluateUCScript(cx, scriptObj, chars, length, filename, 1, &scriptRval);
if (! ok)
return JS_FALSE;
return JS_TRUE;
}
void ScriptInterface_impl::Register(const char* name, JSNative fptr, uintN nargs)
@ -263,7 +262,11 @@ void ScriptInterface::Register(const char* name, JSNative fptr, size_t nargs)
void ScriptInterface::LoadScript(const wxString& filename, const wxString& code)
{
m->LoadScript(filename, code);
size_t codeLength;
wxMBConvUTF16 conv;
wxCharBuffer codeUTF16 = conv.cWC2MB(code.c_str(), code.length()+1, &codeLength);
jsval rval;
m->LoadScript(m->m_cx, reinterpret_cast<jschar*>(codeUTF16.data()), (uintN)(codeLength/2), filename.ToAscii(), &rval);
}
wxPanel* ScriptInterface::LoadScriptAsPanel(const wxString& name, wxWindow* parent)

View File

@ -7,7 +7,9 @@
#include "SnapSplitterWindow/SnapSplitterWindow.h"
#include "Sections/Map/Map.h"
#include "ScenarioEditor.h"
#include "AtlasScript/ScriptInterface.h"
#include "Sections/Terrain/Terrain.h"
#include "Sections/Object/Object.h"
#include "Sections/Environment/Environment.h"
@ -226,6 +228,16 @@ void SidebarButton::OnClick(wxCommandEvent& WXUNUSED(event))
//////////////////////////////////////////////////////////////////////////
class ScriptedSidebar : public Sidebar
{
public:
ScriptedSidebar(const wxString& name, ScenarioEditor& scenarioEditor, wxWindow* sidebarContainer, wxWindow* bottomBarContainer)
: Sidebar(scenarioEditor, sidebarContainer, bottomBarContainer)
{
wxPanel* panel = m_ScenarioEditor.GetScriptInterface().LoadScriptAsPanel(_T("section/") + name, this);
m_MainSizer->Add(panel, wxSizerFlags(1).Expand());
}
};
SectionLayout::SectionLayout()
@ -267,10 +279,18 @@ void SectionLayout::Build(ScenarioEditor& scenarioEditor)
m_SidebarBook->AddPage(sidebar, icon, tooltip); \
m_PageMappings.insert(std::make_pair(L###classname, (int)m_SidebarBook->GetPageCount()-1));
ADD_SIDEBAR(MapSidebar, _T("map.png"), _("Map"));
ADD_SIDEBAR(TerrainSidebar, _T("terrain.png"), _("Terrain"));
ADD_SIDEBAR(ObjectSidebar, _T("object.png"), _("Object"));
ADD_SIDEBAR(EnvironmentSidebar, _T("environment.png"), _("Environment"));
#define ADD_SIDEBAR_SCRIPT(name, icon, tooltip) \
sidebar = new ScriptedSidebar(name, scenarioEditor, m_SidebarBook->GetContentWindow(), m_VertSplitter); \
if (sidebar->GetBottomBar()) \
sidebar->GetBottomBar()->Show(false); \
m_SidebarBook->AddPage(sidebar, icon, tooltip); \
m_PageMappings.insert(std::make_pair(name, (int)m_SidebarBook->GetPageCount()-1));
ADD_SIDEBAR_SCRIPT(_T("map"), _T("map.png"), _("Map"));
ADD_SIDEBAR_SCRIPT(_T("terrain"), _T("terrain.png"), _("Terrain"));
ADD_SIDEBAR(TerrainSidebar, _T("terrain.png"), _("Terrain"));
ADD_SIDEBAR(ObjectSidebar, _T("object.png"), _("Object"));
ADD_SIDEBAR(EnvironmentSidebar, _T("environment.png"), _("Environment"));
#ifndef ATLAS_PUBLIC_RELEASE
ADD_SIDEBAR(CinematicSidebar, _T("cinematic.png"), _("Cinema"));

View File

@ -1,17 +0,0 @@
#include "precompiled.h"
#include "Map.h"
#include "General/Datafile.h"
#include "ScenarioEditor/Tools/Common/Tools.h"
#include "AtlasScript/ScriptInterface.h"
#include "wx/filename.h"
MapSidebar::MapSidebar(ScenarioEditor& scenarioEditor, wxWindow* sidebarContainer, wxWindow* bottomBarContainer)
: Sidebar(scenarioEditor, sidebarContainer, bottomBarContainer)
{
wxPanel* panel = m_ScenarioEditor.GetScriptInterface().LoadScriptAsPanel(_T("section/map"), this);
m_MainSizer->Add(panel, wxSizerFlags().Expand());
}

View File

@ -1,7 +0,0 @@
#include "../Common/Sidebar.h"
class MapSidebar : public Sidebar
{
public:
MapSidebar(ScenarioEditor& scenarioEditor, wxWindow* sidebarContainer, wxWindow* bottomBarContainer);
};

View File

@ -113,6 +113,10 @@ bool BeginAtlas(const CmdLineArgs& args, const DllLoader& dll)
AppHooks hooks = {0};
hooks.display_error = AtlasDisplayError;
app_hooks_update(&hooks);
// Disable the game's cursor rendering
extern CStr g_CursorName;
g_CursorName = "";
state.args = args;
state.running = true;

View File

@ -0,0 +1,377 @@
#include "precompiled.h"
#ifndef WX_PRECOMP
#include <wx/wx.h>
#endif
#include <wx/file.h>
#include "../../common/main.h"
#include "../event/jsevent.h"
#include "../event/command.h"
#include "../event/spinevt.h"
#include "spinctrl.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;
WXJS_INIT_CLASS(SpinCtrl, "wxSpinCtrl", 1)
void SpinCtrl::InitClass(JSContext* WXUNUSED(cx),
JSObject* WXUNUSED(obj),
JSObject* WXUNUSED(proto))
{
SpinCtrlEventHandler::InitConnectEventMap();
}
WXJS_BEGIN_PROPERTY_MAP(SpinCtrl)
WXJS_PROPERTY(P_VALUE, "value")
WXJS_READONLY_PROPERTY(P_MIN, "min")
WXJS_READONLY_PROPERTY(P_MAX, "max")
WXJS_END_PROPERTY_MAP()
WXJS_BEGIN_CONSTANT_MAP(SpinCtrl)
WXJS_CONSTANT(wxSP_, ARROW_KEYS)
WXJS_CONSTANT(wxSP_, WRAP)
WXJS_END_CONSTANT_MAP()
bool SpinCtrl::GetProperty(wxSpinCtrl *p, JSContext *cx, JSObject *obj, int id, jsval *vp)
{
switch (id)
{
case P_VALUE:
*vp = ToJS(cx, p->GetValue());
break;
case P_MIN:
*vp = ToJS(cx, p->GetMin());
break;
case P_MAX:
*vp = ToJS(cx, p->GetMax());
break;
}
return true;
}
bool SpinCtrl::SetProperty(wxSpinCtrl *p, JSContext *cx, JSObject *obj, int id, jsval *vp)
{
switch (id)
{
case P_VALUE:
{
wxString value;
FromJS(cx, *vp, value);
p->SetValue(value);
break;
}
}
return true;
}
bool SpinCtrl::AddProperty(wxSpinCtrl *p,
JSContext* WXUNUSED(cx),
JSObject* WXUNUSED(obj),
const wxString &prop,
jsval* WXUNUSED(vp))
{
if ( WindowEventHandler::ConnectEvent(p, prop, true) )
return true;
SpinCtrlEventHandler::ConnectEvent(p, prop, true);
return true;
}
bool SpinCtrl::DeleteProperty(wxSpinCtrl *p,
JSContext* WXUNUSED(cx),
JSObject* WXUNUSED(obj),
const wxString &prop)
{
if ( WindowEventHandler::ConnectEvent(p, prop, false) )
return true;
SpinCtrlEventHandler::ConnectEvent(p, prop, false);
return true;
}
wxSpinCtrl* SpinCtrl::Construct(JSContext *cx,
JSObject *obj,
uintN argc,
jsval *argv,
bool WXUNUSED(constructing))
{
wxSpinCtrl *p = new wxSpinCtrl();
SetPrivate(cx, obj, p);
if ( argc > 0 )
{
jsval rval;
if ( ! create(cx, obj, argc, argv, &rval) )
return NULL;
}
return p;
}
WXJS_BEGIN_METHOD_MAP(SpinCtrl)
WXJS_METHOD("setRange", setRange, 2)
WXJS_METHOD("setSelection", setSelection, 2)
WXJS_END_METHOD_MAP()
JSBool SpinCtrl::create(JSContext *cx,
JSObject *obj,
uintN argc,
jsval *argv,
jsval *rval)
{
wxSpinCtrl *p = GetPrivate(cx, obj);
*rval = JSVAL_FALSE;
if ( argc > 9 )
argc = 9;
wxWindowID id = -1;
wxString value = wxEmptyString;
const wxPoint *pt = &wxDefaultPosition;
const wxSize *size = &wxDefaultSize;
int style = wxSP_ARROW_KEYS;
int min = 0;
int max = 100;
int initial = 0;
switch(argc)
{
case 9:
if ( ! FromJS(cx, argv[8], initial) )
{
JS_ReportError(cx, WXJS_INVALID_ARG_TYPE, 9, "Integer");
return JS_FALSE;
}
// Fall through
case 8:
if ( ! FromJS(cx, argv[7], max) )
{
JS_ReportError(cx, WXJS_INVALID_ARG_TYPE, 8, "Integer");
return JS_FALSE;
}
// Fall through
case 7:
if ( ! FromJS(cx, argv[6], min) )
{
JS_ReportError(cx, WXJS_INVALID_ARG_TYPE, 7, "Integer");
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;
}
// 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], value);
// Fall through
case 2:
if ( ! FromJS(cx, argv[1], id) )
{
JS_ReportError(cx, WXJS_INVALID_ARG_TYPE, 2, "Integer");
return JS_FALSE;
}
// Fall 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<JavaScriptClientData *>(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, *pt, *size, style, min, max, initial) )
{
*rval = JSVAL_TRUE;
p->SetClientObject(new JavaScriptClientData(cx, obj, true, false));
}
}
return JS_TRUE;
}
JSBool SpinCtrl::setSelection(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
wxSpinCtrl *p = GetPrivate(cx, obj);
if ( p == NULL )
return JS_FALSE;
long from, to;
if (! FromJS(cx, argv[0], from))
return JS_FALSE;
if (! FromJS(cx, argv[1], to))
return JS_FALSE;
p->SetSelection(from, to);
return JS_TRUE;
}
JSBool SpinCtrl::setRange(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
wxSpinCtrl *p = GetPrivate(cx, obj);
if ( p == NULL )
return JS_FALSE;
int minVal, maxVal;
if (! FromJS(cx, argv[0], minVal))
return JS_FALSE;
if (! FromJS(cx, argv[1], maxVal))
return JS_FALSE;
p->SetRange(minVal, maxVal);
return JS_TRUE;
}
WXJS_INIT_EVENT_MAP(wxSpinCtrl)
const wxString WXJS_TEXT_EVENT = wxT("onText");
const wxString WXJS_SPIN_CTRL_EVENT = wxT("onSpinCtrl");
const wxString WXJS_SPIN_EVENT = wxT("onSpin");
const wxString WXJS_SPIN_UP_EVENT = wxT("onSpinUp");
const wxString WXJS_SPIN_DOWN_EVENT = wxT("onSpinDown");
void SpinCtrlEventHandler::OnText(wxCommandEvent &event)
{
PrivCommandEvent::Fire<CommandEvent>(event, WXJS_TEXT_EVENT);
}
void SpinCtrlEventHandler::OnSpinCtrl(wxSpinEvent &event)
{
PrivSpinEvent::Fire<SpinEvent>(event, WXJS_SPIN_CTRL_EVENT);
}
void SpinCtrlEventHandler::OnSpin(wxSpinEvent &event)
{
PrivSpinEvent::Fire<SpinEvent>(event, WXJS_SPIN_EVENT);
}
void SpinCtrlEventHandler::OnSpinUp(wxSpinEvent &event)
{
PrivSpinEvent::Fire<SpinEvent>(event, WXJS_SPIN_UP_EVENT);
}
void SpinCtrlEventHandler::OnSpinDown(wxSpinEvent &event)
{
PrivSpinEvent::Fire<SpinEvent>(event, WXJS_SPIN_DOWN_EVENT);
}
void SpinCtrlEventHandler::ConnectText(wxSpinCtrl *p, bool connect)
{
if ( connect )
{
p->Connect(wxEVT_COMMAND_TEXT_UPDATED,
wxCommandEventHandler(OnText));
}
else
{
p->Disconnect(wxEVT_COMMAND_TEXT_UPDATED,
wxCommandEventHandler(OnText));
}
}
void SpinCtrlEventHandler::ConnectSpinCtrl(wxSpinCtrl *p, bool connect)
{
if ( connect )
{
p->Connect(wxEVT_COMMAND_SPINCTRL_UPDATED,
wxSpinEventHandler(OnSpinCtrl));
}
else
{
p->Disconnect(wxEVT_COMMAND_SPINCTRL_UPDATED,
wxSpinEventHandler(OnSpinCtrl));
}
}
void SpinCtrlEventHandler::ConnectSpin(wxSpinCtrl *p, bool connect)
{
if ( connect )
{
p->Connect(wxEVT_SCROLL_THUMBTRACK,
wxSpinEventHandler(OnSpin));
}
else
{
p->Disconnect(wxEVT_SCROLL_THUMBTRACK,
wxSpinEventHandler(OnSpin));
}
}
void SpinCtrlEventHandler::ConnectSpinUp(wxSpinCtrl *p, bool connect)
{
if ( connect )
{
p->Connect(wxEVT_SCROLL_LINEUP,
wxSpinEventHandler(OnSpinUp));
}
else
{
p->Disconnect(wxEVT_SCROLL_LINEUP,
wxSpinEventHandler(OnSpinUp));
}
}
void SpinCtrlEventHandler::ConnectSpinDown(wxSpinCtrl *p, bool connect)
{
if ( connect )
{
p->Connect(wxEVT_SCROLL_LINEDOWN,
wxSpinEventHandler(OnSpinDown));
}
else
{
p->Disconnect(wxEVT_SCROLL_LINEDOWN,
wxSpinEventHandler(OnSpinDown));
}
}
void SpinCtrlEventHandler::InitConnectEventMap()
{
AddConnector(WXJS_TEXT_EVENT, ConnectText);
AddConnector(WXJS_SPIN_CTRL_EVENT, ConnectSpinCtrl);
AddConnector(WXJS_SPIN_EVENT, ConnectSpin);
AddConnector(WXJS_SPIN_UP_EVENT, ConnectSpinUp);
AddConnector(WXJS_SPIN_DOWN_EVENT, ConnectSpinDown);
}

View File

@ -0,0 +1,81 @@
#ifndef _WXJSSPINCTRL_H
#define _WXJSSPINCTRL_H
#include "../../common/evtconn.h"
#include <wx/spinctrl.h>
namespace wxjs
{
namespace gui
{
class SpinCtrl : public ApiWrapper<SpinCtrl, wxSpinCtrl>
{
public:
static void InitClass(JSContext* cx,
JSObject* obj,
JSObject* proto);
static bool AddProperty(wxSpinCtrl *p,
JSContext *cx,
JSObject *obj,
const wxString &prop,
jsval *vp);
static bool DeleteProperty(wxSpinCtrl *p,
JSContext* cx,
JSObject* obj,
const wxString &prop);
static bool GetProperty(wxSpinCtrl *p,
JSContext *cx,
JSObject *obj,
int id,
jsval *vp);
static bool SetProperty(wxSpinCtrl *p,
JSContext *cx,
JSObject *obj,
int id,
jsval *vp);
static wxSpinCtrl* Construct(JSContext *cx,
JSObject *obj,
uintN argc,
jsval *argv,
bool constructing);
WXJS_DECLARE_METHOD_MAP()
WXJS_DECLARE_METHOD(create)
WXJS_DECLARE_METHOD(setRange)
WXJS_DECLARE_METHOD(setSelection)
WXJS_DECLARE_CONSTANT_MAP()
WXJS_DECLARE_PROPERTY_MAP()
enum
{
P_VALUE
, P_MIN
, P_MAX
};
};
class SpinCtrlEventHandler : public EventConnector<wxSpinCtrl>
, public wxEvtHandler
{
public:
// Events
void OnText(wxCommandEvent &event);
void OnSpinCtrl(wxSpinEvent &event);
void OnSpin(wxSpinEvent &event);
void OnSpinUp(wxSpinEvent &event);
void OnSpinDown(wxSpinEvent &event);
static void InitConnectEventMap();
private:
static void ConnectText(wxSpinCtrl *p, bool connect);
static void ConnectSpinCtrl(wxSpinCtrl *p, bool connect);
static void ConnectSpin(wxSpinCtrl *p, bool connect);
static void ConnectSpinUp(wxSpinCtrl *p, bool connect);
static void ConnectSpinDown(wxSpinCtrl *p, bool connect);
};
}; // namespace gui
}; // namespace wxjs
#endif //_WXJSSPINCTRL_H

View File

@ -112,7 +112,8 @@ wxStaticBox* StaticBox::Construct(JSContext *cx,
if ( argc > 0 )
{
jsval rval;
create(cx, obj, argc, argv, &rval);
if (! create(cx, obj, argc, argv, &rval))
return NULL;
}
return p;
}

View File

@ -656,6 +656,7 @@ WXJS_BEGIN_METHOD_MAP(Window)
WXJS_METHOD("convertDialogToPixels", convertDialogToPixels, 1)
WXJS_METHOD("convertPixelsToDialog", convertPixelsToDialog, 1)
WXJS_METHOD("destroy", destroy, 0)
WXJS_METHOD("destroyChildren", destroyChildren, 0)
WXJS_METHOD("releaseMouse", releaseMouse, 0)
WXJS_METHOD("layout", layout, 0)
WXJS_METHOD("move", move, 2)
@ -928,6 +929,25 @@ JSBool Window::destroy(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, js
return JS_TRUE;
}
/***
* <method name="destroyChildren">
* <function />
* <desc>
* Destroys all children of the window.
* </desc>
* </method>
*/
JSBool Window::destroyChildren(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
wxWindow *p = GetPrivate(cx, obj);
if ( p == NULL )
return JS_FALSE;
p->DestroyChildren();
return JS_TRUE;
}
/***
* <method name="releaseMouse">
* <function />

View File

@ -62,6 +62,7 @@ namespace wxjs
WXJS_DECLARE_METHOD(convertDialogToPixels)
WXJS_DECLARE_METHOD(convertPixelsToDialog)
WXJS_DECLARE_METHOD(destroy)
WXJS_DECLARE_METHOD(destroyChildren)
WXJS_DECLARE_METHOD(releaseMouse)
WXJS_DECLARE_METHOD(layout)
WXJS_DECLARE_METHOD(setSize)

View File

@ -65,6 +65,7 @@ WXJS_BEGIN_PROPERTY_MAP(CommandEvent)
WXJS_READONLY_PROPERTY(P_CHECKED, "checked")
WXJS_READONLY_PROPERTY(P_SELECTION, "selection")
WXJS_READONLY_PROPERTY(P_STRING, "string")
WXJS_READONLY_PROPERTY(P_INTEGER, "integer")
WXJS_END_PROPERTY_MAP()
bool CommandEvent::GetProperty(PrivCommandEvent *p, JSContext *cx, JSObject *obj, int id, jsval *vp)
@ -81,6 +82,9 @@ bool CommandEvent::GetProperty(PrivCommandEvent *p, JSContext *cx, JSObject *obj
case P_STRING:
*vp = ToJS(cx, event->GetString());
break;
case P_INTEGER:
*vp = ToJS(cx, event->GetInt());
break;
}
return true;
}

View File

@ -53,6 +53,7 @@ namespace wxjs
P_CHECKED
, P_SELECTION
, P_STRING
, P_INTEGER
};
WXJS_DECLARE_PROPERTY_MAP()

View File

@ -51,6 +51,7 @@
#include "notify.h"
#include "listevt.h"
#include "treeevt.h"
#include "spinevt.h"
using namespace wxjs;
using namespace wxjs::gui;
@ -172,5 +173,10 @@ bool wxjs::gui::InitEventClasses(JSContext *cx, JSObject *global)
if (! obj )
return false;
return true;
obj = SpinEvent::JSInit(cx, global, NotifyEvent::GetClassPrototype());
wxASSERT_MSG(obj != NULL, wxT("wxSpinEvent prototype creation failed"));
if (! obj )
return false;
return true;
}

View File

@ -0,0 +1,53 @@
#include "precompiled.h"
#ifndef WX_PRECOMP
#include <wx/wx.h>
#endif
#include "../../common/main.h"
#include "../../common/apiwrap.h"
#include <wx/spinctrl.h>
#include "jsevent.h"
#include "../misc/size.h"
#include "spinevt.h"
using namespace wxjs;
using namespace wxjs::gui;
WXJS_INIT_CLASS(SpinEvent, "wxSpinEvent", 0)
WXJS_BEGIN_PROPERTY_MAP(SpinEvent)
WXJS_PROPERTY(P_POSITION, "position")
WXJS_END_PROPERTY_MAP()
bool SpinEvent::GetProperty(PrivSpinEvent *p, JSContext *cx, JSObject *obj, int id, jsval *vp)
{
wxSpinEvent *event = (wxSpinEvent*) p->GetEvent();
switch ( id )
{
case P_POSITION:
*vp = ToJS(cx, event->GetPosition());
break;
}
return true;
}
bool SpinEvent::SetProperty(PrivSpinEvent *p, JSContext *cx, JSObject *obj, int id, jsval *vp)
{
wxSpinEvent *event = (wxSpinEvent*) p->GetEvent();
switch ( id )
{
case P_POSITION:
{
int pos;
if ( FromJS(cx, *vp, pos) )
event->SetPosition(pos);
break;
}
}
return true;
}

View File

@ -0,0 +1,27 @@
#ifndef _WXJSSpinEvent_H
#define _WXJSSpinEvent_H
class wxSpinEvent;
namespace wxjs
{
namespace gui
{
typedef JSEvent<wxSpinEvent> PrivSpinEvent;
class SpinEvent : public ApiWrapper<SpinEvent, PrivSpinEvent>
{
public:
static bool GetProperty(PrivSpinEvent *p, JSContext *cx, JSObject *obj, int id, jsval *vp);
static bool SetProperty(PrivSpinEvent *p, JSContext *cx, JSObject *obj, int id, jsval *vp);
enum
{
P_POSITION
};
WXJS_DECLARE_PROPERTY_MAP()
};
}; // namespace gui
}; // namespace wxjs
#endif //_WXJSSpinEvent_H

View File

@ -62,6 +62,7 @@
// Controls
#include "control/control.h"
#include "control/textctrl.h"
#include "control/spinctrl.h"
#include "control/button.h"
#include "control/bmpbtn.h"
#include "control/sttext.h"
@ -223,6 +224,11 @@ bool wxjs::gui::InitClass(JSContext *cx, JSObject *global)
if (! obj )
return false;
obj = SpinCtrl::JSInit(cx, global, Control::GetClassPrototype());
wxASSERT_MSG(obj != NULL, wxT("wxSpinCtrl 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 )