1
1
forked from 0ad/0ad

Atlas: Updated wxJS to latest SVN version. Made the JS runtime have a greater lifetime than all the wx windows, to avoid garbage collection problems.

IGUIObject: Cache the JSObject*, to prevent some frequent allocation
while running GUI scripts.
JSInterface_IGUIObject: Fixed garbage collection issues.
JSInterface_IGUIObject, ScriptGlue: Changed to the JS_THREADSAFE form of
JS_GetClass.
Util: Avoid startup warnings on Linux caused by using unimplemented
cpu_* functions that aren't needed for anything important yet.
sysdep/unix: Changed to native line endings.

This was SVN commit r5154.
This commit is contained in:
Ykkrosh 2007-06-08 22:56:01 +00:00
parent d416b6ac83
commit 53bcba3368
363 changed files with 69026 additions and 165 deletions

View File

@ -27,7 +27,8 @@ using namespace std;
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");
@ -78,6 +79,9 @@ IGUIObject::~IGUIObject()
delete it->second;
}
}
if (m_JSObject)
JS_RemoveRoot(g_ScriptingHost.getContext(), &m_JSObject);
}
//-------------------------------------------------------------------
@ -495,6 +499,20 @@ void IGUIObject::ScriptEvent(const CStr& Action)
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

View File

@ -272,6 +272,11 @@ public:
* @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:
@ -521,6 +526,9 @@ private:
// Internal storage for registered script handlers.
std::map<CStr, JSObject**> m_ScriptHandlers;
// Cached JSObject representing this GUI object
JSObject *m_JSObject;
};

View File

@ -131,6 +131,7 @@ JSBool JSI_IGUIObject::getProperty(JSContext* cx, JSObject* obj, jsval id, jsval
CColor colour;
GUI<CColor>::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)
@ -140,7 +141,6 @@ JSBool JSI_IGUIObject::getProperty(JSContext* cx, JSObject* obj, jsval id, jsval
P(a);
#undef P
*vp = OBJECT_TO_JSVAL(obj);
break;
}
@ -149,7 +149,7 @@ JSBool JSI_IGUIObject::getProperty(JSContext* cx, JSObject* obj, jsval id, jsval
CClientArea area;
GUI<CClientArea>::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)
@ -166,12 +166,9 @@ JSBool JSI_IGUIObject::getProperty(JSContext* cx, JSObject* obj, jsval id, jsval
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;
}
@ -245,18 +242,16 @@ JSBool JSI_IGUIObject::getProperty(JSContext* cx, JSObject* obj, jsval id, jsval
CGUIList value;
GUI<CGUIList>::GetSetting(e, propName, value);
jsval *vector = new jsval[value.m_Items.size()];
for (size_t i=0; i<value.m_Items.size(); ++i)
JSObject *obj = JS_NewArrayObject(cx, 0, NULL);
*vp = OBJECT_TO_JSVAL(obj); // root it
for (size_t i = 0; i < value.m_Items.size(); ++i)
{
JSString* s = StringConvert::wchars_to_jsstring(cx, value.m_Items[i].GetRawString().c_str());
vector[i] = STRING_TO_JSVAL(s);
// TODO: Make sure these strings never get garbage-collected
jsval val = STRING_TO_JSVAL(s);
JS_SetElement(cx, obj, i, &val);
}
JSObject *obj = JS_NewArrayObject(cx, (jsint)value.m_Items.size(), vector);
delete[] vector;
*vp = OBJECT_TO_JSVAL(obj);
break;
}
@ -421,7 +416,7 @@ JSBool JSI_IGUIObject::setProperty(JSContext* cx, JSObject* obj, jsval id, jsval
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<CClientArea>::GetSetting(e, propName, area);
@ -458,7 +453,7 @@ JSBool JSI_IGUIObject::setProperty(JSContext* cx, JSObject* obj, jsval id, jsval
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);
@ -490,10 +485,15 @@ JSBool JSI_IGUIObject::setProperty(JSContext* cx, JSObject* obj, jsval id, jsval
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);
@ -555,9 +555,7 @@ JSBool JSI_IGUIObject::getByName(JSContext* cx, JSObject* UNUSED(obj), uint argc
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;
}

View File

@ -1,30 +1,30 @@
#include "precompiled.h"
#include "bsd.h"
#if OS_BSD
#include <sys/sysctl.h>
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 <sys/sysctl.h>
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

View File

@ -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

View File

@ -1,66 +1,66 @@
#include "precompiled.h"
#include "ucpu.h"
#if OS_MACOSX
#include <sys/sysctl.h>
#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(&currentCPU);
CPU_SET(j, &currentCPU);
if ( sched_setaffinity (0, sizeof (currentCPU), &currentCPU)
== 0 )
{
sleep(0); // Ensure system to switch to the right
*/
return ERR::NO_SYS;
}
#include "precompiled.h"
#include "ucpu.h"
#if OS_MACOSX
#include <sys/sysctl.h>
#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(&currentCPU);
CPU_SET(j, &currentCPU);
if ( sched_setaffinity (0, sizeof (currentCPU), &currentCPU)
== 0 )
{
sleep(0); // Ensure system to switch to the right
*/
return ERR::NO_SYS;
}

View File

@ -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

View File

@ -74,7 +74,14 @@ void WriteSystemInfo()
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)
{

View File

@ -233,7 +233,7 @@ JSBool IssueCommand( JSContext* cx, JSObject*, uint argc, jsval* argv, jsval* rv
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<CEntity>(argv[0])) ->me);
else
entities = *EntityCollection::RetrieveSet(cx, JSVAL_TO_OBJECT(argv[0]));
@ -322,7 +322,7 @@ JSBool RemoveFromFormation( JSContext* cx, JSObject* UNUSED(obj), uint argc, jsv
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<CEntity>(argv[0])) ->me);
else
entities = *EntityCollection::RetrieveSet(cx, JSVAL_TO_OBJECT(argv[0]));

View File

@ -23,9 +23,12 @@
# define XP_UNIX
#endif
#define JS_THREADSAFE
#include <js/jsapi.h>
#include <js/jsatom.h>
#ifndef NDEBUG
// Used by ScriptingHost::jshook_{script,function}
# include <js/jsdbgapi.h>
#endif

View File

@ -10,7 +10,7 @@
#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"
@ -70,6 +70,14 @@ template<> bool ScriptInterface::FromJSVal<std::wstring>(JSContext* cx, jsval v,
return true;
}
template<> bool ScriptInterface::FromJSVal<std::string>(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<float>(JSContext* cx, const float& val)
{
@ -130,9 +138,10 @@ namespace
}
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)
@ -157,6 +166,24 @@ namespace
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()
@ -185,9 +212,12 @@ ScriptInterface_impl::ScriptInterface_impl()
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);
}
@ -227,16 +257,6 @@ 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);
@ -244,13 +264,15 @@ void ScriptInterface::LoadScript(const wxString& filename, const wxString& 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;

View File

@ -16,6 +16,8 @@
#include "GameInterface/MessagePasser.h"
#include "AtlasScript/ScriptInterface.h"
#include "wx/config.h"
#include "wx/debugrpt.h"
#include "wx/file.h"
@ -130,6 +132,15 @@ ATLASDLLIMPEXP void Atlas_ReportError()
class AtlasDLLApp : public wxApp
{
public:
AtlasDLLApp()
: m_ScriptInterface(NULL)
{
}
~AtlasDLLApp()
{
delete m_ScriptInterface;
}
virtual bool OnInit()
{
@ -154,9 +165,14 @@ public:
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;
@ -221,6 +237,7 @@ public:
*/
private:
ScriptInterface* m_ScriptInterface;
bool OpenDirectory(const wxString& dir)
{

View File

@ -262,9 +262,9 @@ 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:
@ -280,7 +280,7 @@ ScenarioEditor::ScenarioEditor(wxWindow* parent)
//////////////////////////////////////////////////////////////////////////
// Script interface functions
m_ScriptInterface->RegisterFunction<wxString, Datafile::GetDataDirectory>("GetDataDirectory");
GetScriptInterface().RegisterFunction<wxString, Datafile::GetDataDirectory>("GetDataDirectory");
{
const wxString relativePath (_T("tools/atlas/scripts/main.js"));

View File

@ -10,7 +10,7 @@ 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);
@ -37,13 +37,14 @@ public:
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<ScriptInterface> m_ScriptInterface;
void SetOpenFilename(const wxString& filename);
wxString m_OpenFilename;

View File

@ -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 '<jsapi.h>' .`; do sed -i 's/<jsapi.h>/<js\/jsapi.h>/' $i; done
for i in `grep -lr '<jsdate.h>' .`; do sed -i 's/<jsdate.h>/<js\/jsdate.h>/' $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

View File

@ -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 <wx/string.h>
#include "../common/type.h"
namespace wxjs
{
template<class T_Port, class T_Priv>
class ApiWrapper
{
public:
typedef ApiWrapper<T_Port, T_Priv> 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<class T_Port, class T_Priv>
JSClass wxjs::ApiWrapper<T_Port, T_Priv>::wxjs_class =
{
wxjs::ApiWrapper<T_Port, T_Priv>::m_jsClassName,
JSCLASS_HAS_PRIVATE | JSCLASS_NEW_ENUMERATE,
wxjs::ApiWrapper<T_Port, T_Priv>::JSAddProperty,
wxjs::ApiWrapper<T_Port, T_Priv>::JSDeleteProperty,
wxjs::ApiWrapper<T_Port, T_Priv>::JSGetProperty,
wxjs::ApiWrapper<T_Port, T_Priv>::JSSetProperty,
(JSEnumerateOp) wxjs::ApiWrapper<T_Port, T_Priv>::JSEnumerate,
wxjs::ApiWrapper<T_Port, T_Priv>::JSResolve,
JS_ConvertStub,
wxjs::ApiWrapper<T_Port, T_Priv>::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

View File

@ -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 <wx/clntdata.h>
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 &copy)
{
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

View File

@ -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

View File

@ -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 <map>
namespace wxjs
{
template<class T_Priv>
class EventConnector
{
public:
typedef void (*ConnectEventFn)(T_Priv *p, bool connect);
typedef std::map<wxString, ConnectEventFn> 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<class>::ConnectEventMap \
EventConnector<class>::m_eventMap = EventConnector<class>::ConnectEventMap();
#else
#define WXJS_INIT_EVENT_MAP(class) EventConnector<class>::ConnectEventMap \
EventConnector<class>::m_eventMap;
#endif
} // end namespace wxjs
#endif // _wxjs_evt_conn_h

View File

@ -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

View File

@ -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 <js/jsapi.h>
#ifndef WX_PRECOMP
#include <wx/wx.h>
#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;
}

View File

@ -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

View File

@ -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 <js/jsapi.h>
#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

View File

@ -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 <wx/txtstrm.h>
#include <wx/wfstream.h>
#include <wx/textfile.h>
#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 &copy) : 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);
}

View File

@ -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 <wx/string.h>
namespace wxjs
{
class ScriptSource
{
public:
ScriptSource()
{
}
ScriptSource(const ScriptSource &copy);
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

View File

@ -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<typename T> friend bool FromJS(JSContext*cx, jsval v, T &to);
// Avoid copying
StringsPtr(const StringsPtr&);
wxString *m_strings;
unsigned int m_count;
};
};
#endif //_STRINGSPTR_H

View File

@ -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 <wx/wxprec.h>
#ifndef WX_PRECOMP
#include <wx/wx.h>
#endif
#include "type.h"
//template<class T>
//bool FromJS(JSContext *cx, jsval v, T& to);
template<>
bool wxjs::FromJS<int>(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<unsigned int>(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<long>(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<double>(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<bool>(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<wxString>(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<wxDateTime>(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<wxjs::StringsPtr>(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<wxArrayString>(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<wxStringList>(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<long long>(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<class T>
//jsval ToJS(JSContext *cx, T wx);
template<>
jsval wxjs::ToJS<int>(JSContext* WXUNUSED(cx), const int &from)
{
return INT_TO_JSVAL(from);
}
template<>
jsval wxjs::ToJS<unsigned int>(JSContext* WXUNUSED(cx), const unsigned int&from)
{
return INT_TO_JSVAL(from);
}
template<>
jsval wxjs::ToJS<long>(JSContext* WXUNUSED(cx), const long &from)
{
return INT_TO_JSVAL(from);
}
template<>
jsval wxjs::ToJS<unsigned long>(JSContext* cx, const unsigned long&from)
{
jsval v;
JS_NewDoubleValue(cx, from, &v);
return v;
}
template<>
jsval wxjs::ToJS<float>(JSContext* cx, const float &from)
{
jsval v;
JS_NewDoubleValue(cx, from, &v);
return v;
}
template<>
jsval wxjs::ToJS<double>(JSContext* cx, const double &from)
{
jsval v;
JS_NewDoubleValue(cx, from, &v);
return v;
}
template<>
jsval wxjs::ToJS<bool>(JSContext* WXUNUSED(cx), const bool &from)
{
return BOOLEAN_TO_JSVAL(from);
}
template<>
jsval wxjs::ToJS<wxString>(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<wxDateTime>(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<wxArrayString>(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<wxStringList>(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);
}

View File

@ -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 <js/jsapi.h>
#include <js/jsdate.h>
#include <wx/datetime.h>
#include "strsptr.h"
class wxStringList;
class wxArrayString;
namespace wxjs
{
template<class T>
bool FromJS(JSContext *cx, jsval v, T& to);
template<>
bool FromJS<int>(JSContext *cx, jsval v, int &to);
template<>
bool FromJS<unsigned int>(JSContext *cx, jsval v, unsigned int &to);
template<>
bool FromJS<long>(JSContext *cx, jsval v, long &to);
template<>
bool FromJS<double>(JSContext *cx, jsval v, double &to);
template<>
bool FromJS<long long>(JSContext *cx, jsval v, long long &to);
template<>
bool FromJS<bool>(JSContext *cx, jsval v, bool &to);
template<>
bool FromJS<wxString>(JSContext *cx, jsval v, wxString &to);
template<>
bool FromJS<wxDateTime>(JSContext *cx, jsval v, wxDateTime& to);
template<>
bool FromJS<StringsPtr>(JSContext *cx, jsval v, StringsPtr &to);
template<>
bool FromJS<wxArrayString>(JSContext *cx, jsval v, wxArrayString &to);
template<>
bool FromJS<wxStringList>(JSContext *cx, jsval v, wxStringList &to);
template<class T>
jsval ToJS(JSContext *cx, const T &wx);
template<>
jsval ToJS<int>(JSContext *cx, const int &from);
template<>
jsval ToJS<unsigned int>(JSContext *cx, const unsigned int &from);
template<>
jsval ToJS<long>(JSContext *cx, const long &from);
template<>
jsval ToJS<unsigned long>(JSContext *cx, const unsigned long&from);
template<>
jsval ToJS<float>(JSContext *cx, const float& from);
template<>
jsval ToJS<double>(JSContext *cx, const double &from);
template<>
jsval ToJS<bool>(JSContext *cx, const bool &from);
template<>
jsval ToJS<wxString>(JSContext *cx, const wxString &from);
template<>
jsval ToJS<wxDateTime>(JSContext *cx, const wxDateTime &from);
template<>
jsval ToJS<wxArrayString>(JSContext *cx, const wxArrayString &from);
template<>
jsval ToJS<wxStringList>(JSContext *cx, const wxStringList &from);
}; // Namespace wxjs
#endif // _wxJS_Type_H

View File

@ -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 <wx/dlimpexp.h>
#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_*/

View File

@ -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 <windows.h>
#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;
}

View File

@ -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 <wx/string.h>
using namespace wxjs;
using namespace ext;
/***
* <file>memorybuffer</file>
* <module>ext</module>
* <class name="wxMemoryBuffer">
* A wxMemoryBuffer is a useful data structure for storing arbitrary sized blocks of memory.
* <br />
* <br />
* You can access the data of the buffer as a JavaScript array.
* For example:<br />
* <pre><code class="whjs">
* var buffer = new wxMemoryBuffer(10);
* buffer[0] = 10;
* buffer[1] = 'a';
* </code></pre>
* </class>
*/
WXJS_INIT_CLASS(MemoryBuffer, "wxMemoryBuffer", 0)
/***
* <properties>
* <property name="isNull" type="Boolean" readonly="Y">
* Is the buffer null? (dataLen and bufSize are 0).
* </property>
* <property name="dataLen" type="Integer">
* Get/Set the length of the data in the buffer. The length of the data
* can be less then the length of the buffer.
* </property>
* <property name="bufSize" type="Integer">
* Get/Set the size of the buffer.
* </property>
* </properties>
*/
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;
}
/***
* <ctor>
* <function>
* <arg name="Size" type="Integer" default="0">The size of the buffer</arg>
* </function>
* <function>
* <arg name="Str" type="String">A string to fill the buffer</arg>
* <arg name="Encoding" type="String" default="UTF-16">The encoding to use to put this string in the buffer</arg>
* </function>
* <desc>
* Creates a new wxMemoryBuffer object with the given size or with
* string as content.
* </desc>
* </ctor>
*/
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()
/***
* <method name="append">
* <function>
* <arg name="Byte" type="integer">The byte to add</arg>
* </function>
* <function>
* <arg name="Buffer" type="wxMemoryBuffer">The buffer to add</arg>
* <arg name="Size" type="Integer" default="Buffer.size">The size of the buffer to add. When not set, the full buffer is added.</arg>
* </function>
* <desc>
* Concatenate a byte or buffer to this buffer.
* </desc>
* </method>
*/
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;
}
/***
* <method name="toString">
* <function returns="String">
* <arg name="Encoding" type="String" default="UTF-16">
* The encoding of the string in this buffer.
* </arg>
* </function>
* <desc>
* 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.
* </desc>
* </method>
*/
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;
}

View File

@ -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 <wx/buffer.h>
namespace wxjs
{
namespace ext
{
class MemoryBuffer : public ApiWrapper<MemoryBuffer, wxMemoryBuffer>
{
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

View File

@ -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 <js/jsapi.h>
#include <wx/dlimpexp.h>
#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

View File

@ -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 <wx/wx.h>
#endif
/***
* <file>control/bmpbtn</file>
* <module>gui</module>
* <class name="wxBitmapButton" prototype="@wxButton">
* A button that contains a bitmap.
* </class>
*/
#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)
/***
* <properties>
* <property name="bitmapDisabled" type="@wxBitmap">Bitmap to show when the button is disabled.</property>
* <property name="bitmapFocus" type="@wxBitmap">Bitmap to show when the button has the focus.</property>
* <property name="bitmapLabel" type="@wxBitmap">The default bitmap.</property>
* <property name="bitmapSelected" type="@wxBitmap">Bitmap to show when the button is selected.</property>
* </properties>
*/
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;
}
/***
* <ctor>
* <function />
* <function>
* <arg name="Parent" type="@wxWindow">The parent window</arg>
* <arg name="Id" type="Integer">A windows identifier. Use -1 when you don't need it.</arg>
* <arg name="Bitmap" type="@wxBitmap">The bitmap to display</arg>
* <arg name="Position" type="@wxPoint" default="wxDefaultPosition">The position of the control on the given parent</arg>
* <arg name="Size" type="@wxSize" default="wxDefaultSize">The size of the control</arg>
* <arg name="Style" type="Integer" default="wxButton.AUTO_DRAW">The style of the control</arg>
* </function>
* <desc>
* Constructs a new wxBitmapButton object.
* </desc>
* </ctor>
*/
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()
/***
* <method name="create">
* <function returns="Boolean">
* <arg name="Parent" type="@wxWindow">The parent window</arg>
* <arg name="Id" type="Integer">A windows identifier.
* Use -1 when you don't need it.</arg>
* <arg name="Bitmap" type="@wxBitmap">The bitmap to display</arg>
* <arg name="Position" type="@wxPoint" default="wxDefaultPosition">
* The position of the control on the given parent</arg>
* <arg name="Size" type="@wxSize" default="wxDefaultSize">
* The size of the control</arg>
* <arg name="Style" type="Integer" default="wxButton.AUTO_DRAW">
* The style of the control</arg>
* </function>
* <desc>
* Creates a bitmap button.
* </desc>
* </method>
*/
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<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, *bmp, *pt, *size, style) )
{
*rval = JSVAL_TRUE;
p->SetClientObject(new JavaScriptClientData(cx, obj, true, false));
}
}
return JS_TRUE;
}

View File

@ -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<BitmapButton, wxBitmapButton>
{
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

View File

@ -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 $
*/
/***
* <file>control/button</file>
* <module>gui</module>
* <class name="wxButton" prototype="@wxControl">
* 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:
* <pre><code class="whjs">// dlg is a wxDialog
* var button = new wxButton(dlg, -1, "Click me");
* button.onClicked = function(event)
* {
* wxMessageBox("You've clicked me");
* }</code></pre><br />
* </class>
*/
#ifndef WX_PRECOMP
#include <wx/wx.h>
#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();
}
/***
* <properties>
* <property name="label" type="String">
* Get/Set the label of the button.
* </property>
* </properties>
*/
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;
}
/***
* <class_properties>
* <property name="defaultSize" type="Integer" readonly="Y">
* Gets the default size of a button.
* </property>
* </class_properties>
*/
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;
}
/***
* <constants>
* <type name="Style">
* <constant name="LEFT">
* Left-justifies the label. Windows and GTK+ only.
* </constant>
* <constant name="RIGHT">
* Right-justifies the bitmap label. Windows and GTK+ only.
* </constant>
* <constant name="TOP">
* Aligns the label to the top of the button. Windows and GTK+ only.
* </constant>
* <constant name="BOTTOM">
* Aligns the label to the bottom of the button. Windows and GTK+ only.
* </constant>
* <constant name="EXACTFIT">
* Creates the button as small as possible instead of making it of the
* standard size (which is the default behaviour ).
* </constant>
* <constant name="NO_BORDER">
* Creates a flat button. Windows and GTK+ only.
* </constant>
* <constant name="AUTODRAW">
* 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.
* </constant>
* </type>
* </constants>
*/
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()
/***
* <ctor>
* <function />
* <function>
* <arg name="Parent" type="@wxWindow">The parent of the button.</arg>
* <arg name="Id" type="Integer">
* An window identifier. Use -1 when you don't need it.
* </arg>
* <arg name="Text" type="String">The label of the button</arg>
* <arg name="Pos" type="@wxPoint" default="wxDefaultPosition">
* The position of the button on the given parent.
* </arg>
* <arg name="Size" type="@wxSize" default="wxDefaultSize">
* The size of the button.
* </arg>
* <arg name="Style" type="Integer" default="wxButton.AUTODRAW">
* The button style
* </arg>
* <arg name="Validator" type="@wxValidator" default="wxDefaultValidator" />
* </function>
* <desc>
* Constructs a new wxButton object.
* </desc>
* </ctor>
*/
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()
/***
* <method name="create">
* <function returns="Boolean">
* <arg name="Parent" type="@wxWindow">The parent of the button.</arg>
* <arg name="Id" type="Integer">
* An window identifier. Use -1 when you don't need it.
* </arg>
* <arg name="Text" type="String">The label of the button</arg>
* <arg name="Pos" type="@wxPoint" default="wxDefaultPosition">
* The position of the button on the given parent.
* </arg>
* <arg name="Size" type="@wxSize" default="wxDefaultSize">
* The size of the button.
* </arg>
* <arg name="Style" type="Integer" default="wxButton.AUTODRAW">
* The button style
* </arg>
* <arg name="Validator" type="@wxValidator" default="wxDefaultValidator" />
* </function>
* <desc>
* Creates a button.
* </desc>
* </method>
*/
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<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, text, *pt, *size, style, *val) )
{
*rval = JSVAL_TRUE;
p->SetClientObject(new JavaScriptClientData(cx, obj, true, false));
}
}
return JS_TRUE;
}
/***
* <method name="setDefault">
* <function />
* <desc>
* This sets the button to be the default item for the panel or dialog box.
* see @wxPanel#defaultItem.
* </desc>
* </method>
*/
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;
}
/***
* <events>
* <event name="onClicked">
* Called when the button is clicked. The type of the argument that your
* handler receives is @wxCommandEvent.
* </event>
* </events>
*/
WXJS_INIT_EVENT_MAP(wxButton)
const wxString WXJS_BUTTON_CLICKED_EVENT = wxT("onClicked");
void ButtonEventHandler::OnClicked(wxCommandEvent &event)
{
PrivCommandEvent::Fire<CommandEvent>(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);
}

View File

@ -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<Button, wxButton>
{
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<wxButton>
, 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

View File

@ -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 <wx/wx.h>
#endif
#include <wx/calctrl.h>
/***
* <file>control/caldate</file>
* <module>gui</module>
* <class name="wxCalendarDateAttr">
* wxCalendarDateAttr contains all attributes for a calendar date.
* See @wxCalendarCtrl.
* </class>
*/
#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)
/***
* <properties>
* <property name="backgroundColour" type="@wxColour">
* The background colour
* </property>
* <property name="border" type="Integer">Type of the border.
* See @wxCalendarDateBorder.
* </property>
* <property name="borderColour" type="#wxColour">
* The colour of the border
* </property>
* <property name="font" type="@wxFont">The font of the text</property>
* <property name="holiday" type="boolean">Is the day a holiday?</property>
* <property name="textColour" type="@wxColour">
* The colour of the text
* </property>
* </properties>
*/
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<int>(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<int>(cx, *vp, border) )
p->SetBorder((wxCalendarDateBorder)border);
break;
}
case P_HOLIDAY:
{
bool holiday;
if ( FromJS(cx, *vp, holiday) )
p->SetHoliday(holiday);
break;
}
}
}
return true;
}
/***
* <ctor>
* <function />
* <function>
* <arg name="TextColour" type="@wxColour">Colour of the text</arg>
* <arg name="BackgroundColour" type="@wxColour" default="null">
* Backgroundcolour
* </arg>
* <arg name="BorderColour" type="@wxColour" default="null">BorderColour</arg>
* <arg name="Font" type="@wxFont" default="null">The font</arg>
* <arg name="Border" type="Integer" default="0">The border type</arg>
* </function>
* <function>
* <arg name="Border" type="Integer">The border type</arg>
* <arg name="BorderColour" type="@wxColour">BorderColour</arg>
* </function>
* <desc>
* Constructs a new wxCalendarDateAttr object.
* </desc>
* </ctor>
*/
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);
}
}

View File

@ -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<CalendarDateAttr,
wxCalendarDateAttr>
{
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

View File

@ -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 <wx/wx.h>
#endif
#include <wx/calctrl.h>
#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;
/***
* <file>control/calendar</file>
* <module>gui</module>
* <class name="wxCalendarCtrl" prototype="@wxControl">
* 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.
* <br /><br />
* 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.
* </class>
*/
WXJS_INIT_CLASS(CalendarCtrl, "wxCalendarCtrl", 2)
void CalendarCtrl::InitClass(JSContext* WXUNUSED(cx),
JSObject* WXUNUSED(obj),
JSObject* WXUNUSED(proto))
{
CalendarEventHandler::InitConnectEventMap();
}
/***
* <properties>
* <property name="attr" type="@wxCalendarDateAttr array" readonly="Y">
* Get the attributes of a day. The array index must be between 1 and 31.
* </property>
* <property name="date" type="Date">Get/Set the current date</property>
* <property name="enableHolidayDisplay" type="Boolean">
* Show/hide holidays (write only)
* </property>
* <property name="enableMonthChange" type="Boolean">
* Enable/Disable month changing (write only)
* </property>
* <property name="enableYearChange" type="Boolean">
* Enable/Disable year changing (write only)
* </property>
* <property name="headerColourBg" type="@wxColour">
* Get/Set the background colour of the header.
* See @wxCalendarCtrl#setHeaderColours and @wxCalendarCtrl#headerColourFg
* </property>
* <property name="headerColourFg" type="@wxColour">
* Get/Set the foreground colour of the header.
* See @wxCalendarCtrl#setHeaderColours and @wxCalendarCtrl#headerColourBg
* </property>
* <property name="highlightColourBg" type="@wxColour">
* Get/Set the background colour of the selected date.
* See @wxCalendarCtrl#setHighlightColours
* and @wxCalendarCtrl#highlightColourFg
* </property>
* <property name="highlightColourFg" type="@wxColour">
* Get/Set the foreground colour of the selected date.
* See @wxCalendarCtrl#setHighlightColours and
* @wxCalendarCtrl#highlightColourBg
* </property>
* <property name="holidayColourBg" type="@wxColour">
* Get/Set the background colour of a holiday.
* See @wxCalendarCtrl#setHolidayColours and @wxCalendarCtrl#holidayColourFg
* </property>
* <property name="holidayColourFg" type="@wxColour">
* Get/Set the foreground colour of a holiday.
* See @wxCalendarCtrl#setHolidayColours and @wxCalendarCtrl#holidayColourBg
* </property>
* <property name="lowerDateLimit" type="Date">
* 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
* </property>
* <property name="upperDateLimit" type="Date">
* 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
* </property>
* </properties>
*/
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;
}
/***
* <constants>
* <type name="Styles">
* <constant name="SUNDAY_FIRST">
* Show Sunday as the first day in the week
* </constant>
* <constant name="MONDAY_FIRST">
* Show Monday as the first day in the week
* </constant>
* <constant name="SHOW_HOLIDAYS">
* Highlight holidays in the calendar
* </constant>
* <constant name="NO_YEAR_CHANGE">
* Disable the year changing
* </constant>
* <constant name="NO_MONTH_CHANGE">
* Disable the month (and, implicitly, the year) changing
* </constant>
* <constant name="SHOW_SURROUNDING_WEEKS">
* Show the neighbouring weeks in the previous and next months
* </constant>
* <constant name="SEQUENTIAL_MONTH_SELECTION">
* Use alternative, more compact, style for the month
* and year selection controls.
* </constant>
* </type>
* </constants>
*/
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()
/***
* <ctor>
* <function />
* <function>
* <arg name="Parent" type="@wxWindow">The parent of wxCalendarCtrl.</arg>
* <arg name="Id" type="Integer">
* A window identifier. Use -1 when you don't need it.
* </arg>
* <arg name="DefaultDate" type="Date">
* The date to select when the control is shown. Use null to use
* the default.
* </arg>
* <arg name="Pos" type="@wxPoint" default="wxDefaultPosition">
* The position of the CalendarCtrl control on the given parent.
* </arg>
* <arg name="Size" type="@wxSize" default="wxDefaultSize">
* The size of the CalendarCtrl control.
* </arg>
* <arg name="Style" type="Integer" default="wxCalendarCtrl.SHOW_HOLIDAYS">
* The wxCalendarCtrl style.
* </arg>
* </function>
* <desc>
* Constructs a new wxCalendarCtrl object.
* </desc>
* </ctor>
*/
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()
/***
* <method name="create">
* <function returns="Boolean">
* <arg name="Parent" type="@wxWindow">The parent of wxCalendarCtrl.</arg>
* <arg name="Id" type="Integer">
* A window identifier. Use -1 when you don't need it.
* </arg>
* <arg name="DefaultDate" type="Date">
* The date to select when the control is shown. Use null to use
* the default.
* </arg>
* <arg name="Pos" type="@wxPoint" default="wxDefaultPosition">
* The position of the CalendarCtrl control on the given parent.
* </arg>
* <arg name="Size" type="@wxSize" default="wxDefaultSize">
* The size of the CalendarCtrl control.
* </arg>
* <arg name="Style" type="Integer" default="wxCalendarCtrl.SHOW_HOLIDAYS">
* The wxCalendarCtrl style.
* </arg>
* </function>
* <desc>
* Creates a calendar control.
* </desc>
* </method>
*/
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<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, date, *pt, *size, style) )
{
*rval = JSVAL_TRUE;
p->SetClientObject(new JavaScriptClientData(cx, obj, true, false));
}
}
return JS_TRUE;
}
/***
* <method name="setDateRange">
* <function>
* <arg name="LowerLimit" type="Date" default="null">
* The lower limit of the selection. Use null to reset this.
* </arg>
* <arg name="UpperLimit" type="Date" default="null">
* The upper limit of the selection. Use null to reset this.
* </arg>
* </function>
* <desc>
* Set the range in which selection can occur.
* See @wxCalendarCtrl#lowerDateLimit and
* @wxCalendarCtrl#upperDateLimit
* </desc>
* </method>
*/
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;
}
/***
* <method name="setHeaderColours">
* <function>
* <arg name="ForegroundColour" type="@wxColour">
* The foreground colour of the header</arg>
* <arg name="BackgroundColour" type="@wxColour">
* The background colour of the header</arg>
* </function>
* <desc>
* Sets the colours of the header.
* See @wxCalendarCtrl#headerColourFg and @wxCalendarCtrl#headerColourBg
* </desc>
* </method>
*/
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;
}
/***
* <method name="setHighlightColours">
* <function>
* <arg name="ForegroundColour" type="@wxColour">
* The foreground colour of the highlighted date
* </arg>
* <arg name="BackgroundColour" type="@wxColour">
* The background colour of the highlighted date
* </arg>
* </function>
* <desc>
* Sets the colours of the highlighted date.
* See @wxCalendarCtrl#highlightColourFg
* and @wxCalendarCtrl#highlightColourBg
* </desc>
* </method>
*/
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;
}
/***
* <method name="setHolidayColours">
* <function>
* <arg name="ForegroundColour" type="@wxColour">
* The foreground colour of a holiday
* </arg>
* <arg name="BackgroundColour" type="@wxColour">
* The background colour of a holiday
* </arg>
* </function>
* <desc>
* Sets the colours of a holiday.
* See @wxCalendarCtrl#holidayColourFg and @wxCalendarCtrl#holidayColourBg
* </desc>
* </method>
*/
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");
/***
* <events>
* <event name="onCalendar">
* A day is double clicked. The function gets a @wxCalendarEvent as argument.
* </event>
* <event name="onCalendarSelChanged">
* The selected date is changed.
* The function gets a @wxCalendarEvent as argument.
* </event>
* <event name="onCalendarDay">
* The selected day is changed.
* The function gets a @wxCalendarEvent as argument.
* </event>
* <event name="onCalendarMonth">
* The selected month is changed.
* The function gets a @wxCalendarEvent as argument.
* </event>
* <event name="onCalendarYear">
* The selected year is changed.
* The function gets a @wxCalendarEvent as argument.
* </event>
* <event name="onCalendarWeekDayClicked">
* The user clicked on the week day header.
* The function gets a @wxCalendarEvent as argument.
* </event>
* </events>
*/
void CalendarEventHandler::OnCalendar(wxCalendarEvent &event)
{
PrivCalendarEvent::Fire<CalendarEvent>(event, WXJS_CAL_EVENT);
}
void CalendarEventHandler::OnCalendarSelChanged(wxCalendarEvent &event)
{
PrivCalendarEvent::Fire<CalendarEvent>(event, WXJS_CAL_SELCHANGED_EVENT);
}
void CalendarEventHandler::OnCalendarDay(wxCalendarEvent &event)
{
PrivCalendarEvent::Fire<CalendarEvent>(event, WXJS_CAL_DAY_EVENT);
}
void CalendarEventHandler::OnCalendarMonth(wxCalendarEvent &event)
{
PrivCalendarEvent::Fire<CalendarEvent>(event, WXJS_CAL_MONTH_EVENT);
}
void CalendarEventHandler::OnCalendarYear(wxCalendarEvent &event)
{
PrivCalendarEvent::Fire<CalendarEvent>(event, WXJS_CAL_YEAR_EVENT);
}
void CalendarEventHandler::OnCalendarWeekDayClicked(wxCalendarEvent &event)
{
PrivCalendarEvent::Fire<CalendarEvent>(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);
}

View File

@ -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<CalendarCtrl, wxCalendarCtrl>
{
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<wxCalendarCtrl>
, 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

View File

@ -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 <wx/wx.h>
#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;
/***
* <file>control/checkbox</file>
* <module>gui</module>
* <class name="wxCheckBox" prototype="@wxControl">
* A checkbox is a labeled box which is either on
* (checkmark is visible) or off (no checkmark).
* <br />An example:
* <pre><code class="whjs">
* // dlg is a wxDialog
* var chkbox = new wxCheckBox(dlg, -1, "Check me");
* chkbox.onCheckBox = function(event)
* {
* if ( event.checked )
* wxMessageBox("Checked");
* else
* wxMessageBox("Unchecked");
* }
* </code></pre>
* </class>
*/
WXJS_INIT_CLASS(CheckBox, "wxCheckBox", 3)
void CheckBox::InitClass(JSContext* WXUNUSED(cx),
JSObject* WXUNUSED(obj),
JSObject* WXUNUSED(proto))
{
CheckBoxEventHandler::InitConnectEventMap();
}
/***
* <properties>
* <property name="value" type="Boolean">
* Checks/Unchecks the checkbox.
* </property>
* </properties>
*/
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;
}
/***
* <ctor>
* <function />
* <function>
* <arg name="Parent" type="@wxWindow">The parent of the checkbox</arg>
* <arg name="Id" type="Integer">A window identifier. Use -1 when you don't need it</arg>
* <arg name="Text" type="String">The label of the checkbox</arg>
* <arg name="Pos" type="@wxPoint" default="wxDefaultPosition">The position of the checkbox on the given parent</arg>
* <arg name="Size" type="@wxSize" default="wxDefaultSize">The size of the checkbox</arg>
* <arg name="Style" type="Integer" default="0">The style of the checkbox</arg>
* <arg name="Validator" type="@wxValidator" default="null">A validator</arg>
* </function>
* <desc>
* Constructs a new wxCheckBox object.
* </desc>
* </ctor>
*/
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()
/***
* <method name="create">
* <function returns="Boolean">
* <arg name="Parent" type="@wxWindow">
* The parent of the checkbox</arg>
* <arg name="Id" type="Integer">
* A window identifier. Use -1 when you don't need it
* </arg>
* <arg name="Text" type="String">The label of the checkbox
* </arg>
* <arg name="Pos" type="@wxPoint" default="wxDefaultPosition">
* The position of the checkbox on the given parent.
* </arg>
* <arg name="Size" type="@wxSize" default="wxDefaultSize">
* The size of the checkbox
* </arg>
* <arg name="Style" type="Integer" default="0">
* The style of the checkbox
* </arg>
* <arg name="Validator" type="@wxValidator" default="null">A validator</arg>
* </function>
* <desc>
* Constructs a new wxCheckBox object.
* </desc>
* </method>
*/
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<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, text, *pt, *size, style, *val) )
{
*rval = JSVAL_TRUE;
p->SetClientObject(new JavaScriptClientData(cx, obj, true, false));
}
}
return JS_TRUE;
}
/***
* <events>
* <event name="onCheckBox">
* Called when the checkbox is clicked. The type of the argument that your
* handler receives is @wxCommandEvent.
* </event>
* </events>
*/
WXJS_INIT_EVENT_MAP(wxCheckBox)
const wxString WXJS_CHECKBOX_EVENT = wxT("onCheckBox");
void CheckBoxEventHandler::OnCheckBox(wxCommandEvent &event)
{
PrivCommandEvent::Fire<CommandEvent>(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);
}

View File

@ -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<CheckBox, wxCheckBox>
{
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<wxCheckBox>
, 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

View File

@ -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 <wx/wx.h>
#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;
/***
* <file>control/chklstbx</file>
* <module>gui</module>
* <class name="wxCheckListBox" prototype="@wxListBox">
* A checklistbox is like a listbox, but allows items to be checked
* or unchecked.
* </class>
*/
WXJS_INIT_CLASS(CheckListBox, "wxCheckListBox", 2)
void CheckListBox::InitClass(JSContext* WXUNUSED(cx),
JSObject* WXUNUSED(obj),
JSObject* WXUNUSED(proto))
{
CheckListBoxEventHandler::InitConnectEventMap();
}
/***
* <properties>
* <property name="checked" type="Array" readonly="Y">
* Array with @wxCheckListBoxItem elements.
* Use it to check/uncheck a specific item.
* </property>
* </properties>
*/
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;
}
/***
* <ctor>
* <function />
* <function>
* <arg name="Parent" type="@wxWindow">The parent of this control</arg>
* <arg name="Id" type="Integer">
* A window identifier. Use -1 when you don't need it.
* </arg>
* <arg name="Position" type="@wxPoint" default="wxDefaultPosition">
* The position of the CheckListBox control on the given parent.
* </arg>
* <arg name="Size" type="wxSize" default="wxDefaultSize">
* The size of the CheckListBox control.
* </arg>
* <arg name="Items" type="Array" default="null">
* An array of Strings to initialize the control
* </arg>
* <arg name="Style" type="Integer" default="0">
* The wxCheckListBox style.
* </arg>
* <arg name="Validator" type="@wxValidator" default="null">A validator</arg>
* </function>
* <desc>
* Constructs a new wxCheckListBox object.
* </desc>
* </ctor>
*/
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()
/***
* <method name="create">
* <function returns="Boolean">
* <arg name="Parent" type="@wxWindow">The parent of this control</arg>
* <arg name="Id" type="Integer">
* A window identifier. Use -1 when you don't need it.
* </arg>
* <arg name="Position" type="@wxPoint" default="wxDefaultPosition">
* The position of the CheckListBox control on the given parent.
* </arg>
* <arg name="Size" type="wxSize" default="wxDefaultSize">
* The size of the CheckListBox control.
* </arg>
* <arg name="Items" type="Array" default="null">
* An array of Strings to initialize the control
* </arg>
* <arg name="Style" type="Integer" default="0">
* The wxCheckListBox style.
* </arg>
* <arg name="Validator" type="@wxValidator" default="null">A validator</arg>
* </function>
* <desc>
* Creates wxCheckListBox.
* </desc>
* </method>
*/
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<JavaScriptClientData *>(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;
}
/***
* <events>
* <event name="onCheckListBox">
* Called when an item is checked or unchecked.
* The function that is called gets a @wxCommandEvent
* object.</event>
* </events>
*/
WXJS_INIT_EVENT_MAP(wxCheckListBox)
const wxString WXJS_CHECKLISTBOX_EVENT = wxT("onCheckListBox");
void CheckListBoxEventHandler::OnCheckListBox(wxCommandEvent &event)
{
PrivCommandEvent::Fire<CommandEvent>(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);
}

View File

@ -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<CheckListBox, wxCheckListBox>
{
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<wxCheckListBox>
, 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

View File

@ -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 <wx/wx.h>
#endif
#include "../../common/main.h"
#include "../../common/index.h"
#include "chklstbxchk.h"
#include "chklstbx.h"
using namespace wxjs;
using namespace wxjs::gui;
/***
* <file>control/chklstbxchk</file>
* <module>gui</module>
* <class name="wxCheckListBoxItem">
* 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.
* <pre><code class="whjs">
* 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();
* </code></pre>
* </class>
*/
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;
}

View File

@ -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<CheckListBoxItem, Index>
{
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

View File

@ -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 <wx/wx.h>
#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;
/***
* <file>control/choice</file>
* <module>gui</module>
* <class name="wxChoice" prototype="@wxControlWithItems">
* 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:
* <pre><code class="whjs">
* 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);
* </code></pre>
* </class>
*/
WXJS_INIT_CLASS(Choice, "wxChoice", 2)
void Choice::InitClass(JSContext* WXUNUSED(cx),
JSObject* WXUNUSED(obj),
JSObject* WXUNUSED(proto))
{
ChoiceEventHandler::InitConnectEventMap();
}
/***
* <properties>
* <property name="columns" type="Integer">
* Gets/Sets the number of columns
* </property>
* </properties>
*/
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;
}
/***
* <ctor>
* <function />
* <function>
* <arg name="Parent" type="@wxWindow">
* The parent of the control
* </arg>
* <arg name="Id" type="Integer">
* An window identifier. Use -1 when you don't need it.
* </arg>
* <arg name="Position" type="@wxPoint" default="wxDefaultPosition">
* The position of the choice control on the given parent.
* </arg>
* <arg name="Size" type="@wxSize" default="wxDefaultSize">
* The size of the choice control.
* </arg>
* <arg name="Items" type="Array" default="null">
* An array of Strings to initialize the control.
* </arg>
* <arg name="Style" type="Integer" default="0">
* The style of the control
* </arg>
* <arg name="Validator" type="@wxValidator" default="null">
* A validator
* </arg>
* </function>
* <desc>
* Constructs a new wxChoice object.
* </desc>
* </ctor>
*/
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()
/***
* <method name="create">
* <function returns="Boolean">
* <arg name="Parent" type="@wxWindow">
* The parent of the control
* </arg>
* <arg name="Id" type="Integer">
* An window identifier. Use -1 when you don't need it.
* </arg>
* <arg name="Position" type="@wxPoint" default="wxDefaultPosition">
* The position of the choice control on the given parent.
* </arg>
* <arg name="Size" type="@wxSize" default="wxDefaultSize">
* The size of the choice control.
* </arg>
* <arg name="Items" type="Array" default="null">
* An array of Strings to initialize the control.
* </arg>
* <arg name="Style" type="Integer" default="0">
* The style of the control
* </arg>
* <arg name="Validator" type="@wxValidator" default="null">
* A validator
* </arg>
* </function>
* <desc>
* Creates a wxChoice
* </desc>
* </method>
*/
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<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, *pt, *size,
items.GetCount(), items.GetStrings(), style, *val) )
{
*rval = JSVAL_TRUE;
p->SetClientObject(new JavaScriptClientData(cx, obj, true, false));
}
}
return JS_TRUE;
}
/***
* <events>
* <event name="onChoice">
* Called when an item is selected. The type of the argument that your handler receives
* is @wxCommandEvent.
* </event>
* </events>
*/
WXJS_INIT_EVENT_MAP(wxChoice)
const wxString WXJS_CHOICE_EVENT = wxT("onChoice");
void ChoiceEventHandler::OnChoice(wxCommandEvent &event)
{
PrivCommandEvent::Fire<CommandEvent>(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);
}

View File

@ -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<Choice, wxChoice>
{
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<wxChoice>
, 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

View File

@ -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 <wx/wx.h>
#endif
#include "../../common/main.h"
#include "../../common/index.h"
#include "../misc/colour.h"
#include "coldata.h"
using namespace wxjs;
using namespace wxjs::gui;
/***
* <file>control/colourdata</file>
* <module>gui</module>
* <class name="wxColourData">
* This class holds a variety of information related to colour dialogs.
* See @wxColourDialog.
* </class>
*/
WXJS_INIT_CLASS(ColourData, "wxColourData", 0)
/***
* <properties>
* <property name="chooseFull" type="Boolean">
* Under Windows, determines whether the Windows colour dialog will
* display the full dialog with custom colour selection controls.
* Has no meaning under other platforms.
* </property>
* <property name="colour" type="@wxColour">
* Get/Set the current colour associated with the colour dialog.
* </property>
* <property name="customColour" type="Array">
* Get/Set the ith custom colour associated with the colour dialog.
* The index must be between 0 and 15. The element is a @wxColour.
* </property>
* </properties>
*/
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;
}
/***
* <ctor>
* <function />
* <desc>
* Constructs a new wxColourData object.
* The selected colour is black. And @wxColourData#chooseFull is true.
* </desc>
* </ctor>
*/
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;
}

View File

@ -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<ColourData, wxColourData>
{
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<CustomColour, Index>
{
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

View File

@ -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 <wx/wx.h>
#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;
/***
* <file>control/coldlg</file>
* <module>gui</module>
* <class name="wxColourDialog" prototype="@wxDialog">
* The wxColourDialog presents a colour selector to the user.
* See also @wxColourData. The following sample shows this
* dialog:
* <pre><code class="whjs">
* 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();
* </code></pre>
* </class>
*/
WXJS_INIT_CLASS(ColourDialog, "wxColourDialog", 1)
/***
* <properties>
* <property name="colourData" type="@wxColourData" readonly="Y">
* Gets the colour data.
* </property>
* </properties>
*/
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;
}
/***
* <ctor>
* <function>
* <arg name="Parent" type="@wxWindow">
* The parent of wxColourDialog.
* </arg>
* <arg name="ColourData" type="@wxColourData">
* The colour data.
* </arg>
* </function>
* <desc>
* Constructs a new wxColourDialog object
* </desc>
* </ctor>
*/
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<JavaScriptClientData *>(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();
}

View File

@ -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 <wx/colordlg.h>
namespace wxjs
{
namespace gui
{
class ColourDialog : public ApiWrapper<ColourDialog, wxColourDialog>
{
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

View File

@ -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 <wx/wx.h>
#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;
/***
* <file>control/combobox</file>
* <module>gui</module>
* <class name="wxComboBox" prototype="@wxControlWithItems">
* 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.
* </class>
*/
WXJS_INIT_CLASS(ComboBox, "wxComboBox", 2)
void ComboBox::InitClass(JSContext* WXUNUSED(cx),
JSObject* WXUNUSED(obj),
JSObject* WXUNUSED(proto))
{
ComboBoxEventHandler::InitConnectEventMap();
}
/***
* <properties>
* <property name="canCopy" type="Boolean" readonly="Y">
* Returns true if the combobox is editable and there is a text
* selection to copy to the clipboard. Only available on Windows.
* </property>
* <property name="canCut" type="Boolean" readonly="Y">
* Returns true if the combobox is editable and there is a text selection
* to cut to the clipboard. Only available on Windows.
* </property>
* <property name="canPaste" type="Boolean" readonly="Y">
* Returns true if the combobox is editable and there is text to paste
* from the clipboard. Only available on Windows.
* </property>
* <property name="canRedo" type="Boolean" readonly="Y">
* Returns true if the combobox is editable and the last undo can be redone.
* Only available on Windows.
* </property>
* <property name="canUndo" type="Boolean" readonly="Y">
* Returns true if the combobox is editable and the last edit can be undone.
* Only available on Windows.
* </property>
* <property name="value" type="String">
* Gets/Sets the text field
* </property>
* <property name="insertionPoint" type="Integer">
* Gets/Sets the insertion point of the text field
* </property>
* <property name="lastPosition" type="Integer" readonly="Y">
* Gets the last position of the text field
* </property>
* </properties>
*/
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;
}
/***
* <constants>
* <type name="Style">
* <constant>SIMPLE</constant>
* <constant>DROPDOWN</constant>
* <constant>READONLY</constant>
* <constant>SORT</constant>
* </type>
* </constants>
*/
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()
/***
* <ctor>
* <function />
* <function>
* <arg name="Parent" type="@wxWindow">
* The parent of the wxComboBox
* </arg>
* <arg name="Id" type="Integer">
* A window identifier. Use -1 when you don't need it
* </arg>
* <arg name="Text" type="String" default="">
* The default text of the text field
* </arg>
* <arg name="Position" type="@wxPoint" default="wxDefaultPosition">
* The position of the control on the given parent.
* </arg>
* <arg name="Size" type="@wxSize" default="wxDefaultSize">
* The size of the control.
* </arg>
* <arg name="Items" type="Array" default="null">
* An array of Strings to initialize the control.
* </arg>
* <arg name="Style" type="Integer" default="0">
* The window style.
* </arg>
* <arg name="Validator" type="@wxValidator" default="null">
* A validator
* </arg>
* </function>
* <desc>
* Constructs a new wxComboBox object
* </desc>
* </ctor>
*/
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()
/***
* <method name="create">
* <function>
* <arg name="Parent" type="@wxWindow">
* The parent of the wxComboBox
* </arg>
* <arg name="Id" type="Integer">
* A window identifier. Use -1 when you don't need it
* </arg>
* <arg name="Text" type="String" default="">
* The default text of the text field
* </arg>
* <arg name="Position" type="@wxPoint" default="wxDefaultPosition">
* The position of the control on the given parent.
* </arg>
* <arg name="Size" type="@wxSize" default="wxDefaultSize">
* The size of the control.
* </arg>
* <arg name="Items" type="Array" default="null">
* An array of Strings to initialize the control.
* </arg>
* <arg name="Style" type="Integer" default="0">
* The window style.
* </arg>
* <arg name="Validator" type="@wxValidator" default="null">
* A validator
* </arg>
* </function>
* <desc>
* Creates a wxComboBox
* </desc>
* </method>
*/
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<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, text, *pt, *size,
items.GetCount(), items.GetStrings(), style, *val) )
{
*rval = JSVAL_TRUE;
p->SetClientObject(new JavaScriptClientData(cx, obj, true, false));
}
}
return JS_TRUE;
}
/***
* <method name="copy">
* <function />
* <desc>
* Copies the selected text to the clipboard
* </desc>
* </method>
*/
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;
}
/***
* <method name="cut">
* <function />
* <desc>
* Copies the selected text to the clipboard and removes the selected text
* </desc>
* </method>
*/
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;
}
/***
* <method name="paste">
* <function />
* <desc>
* Pastes the content of the clipboard in the text field.
* </desc>
* </method>
*/
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;
}
/***
* <method name="redo">
* <function />
* <desc>
* Redoes the last undo in the text field. Windows only.
* </desc>
* </method>
*/
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;
}
/***
* <method name="remove">
* <function>
* <arg name="From" type="Integer" />
* <arg name="To" type="Integer" />
* </function>
* <desc>
* Removes the text between From and To
* </desc>
* </method>
*/
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;
}
/***
* <method name="replace">
* <function>
* <arg name="From" type="Integer" />
* <arg name="To" type="Integer" />
* <arg name="Text" type="String" />
* </function>
* <desc>
* Replaces the text between From and To with the given text
* </desc>
* </method>
*/
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;
}
/***
* <method name="undo">
* <function />
* <desc>
* Undoes the last edit in the text field. Windows only.
* </desc>
* </method>
*/
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;
}
/***
* <events>
* <event name="onText">
* Called when the text of the textfield is changed.
* The type of the argument that your handler receives is @wxCommandEvent.
* </event>
* <event name="onComboBox">
* Called when an item is selected. The type of the argument
* that your handler receives is @wxCommandEvent.
* </event>
* </events>
*/
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<CommandEvent>(event, WXJS_TEXT_EVENT);
}
void ComboBoxEventHandler::OnTextEnter(wxCommandEvent &event)
{
PrivCommandEvent::Fire<CommandEvent>(event, WXJS_TEXT_ENTER_EVENT);
}
void ComboBoxEventHandler::OnComboBox(wxCommandEvent &event)
{
PrivCommandEvent::Fire<CommandEvent>(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);
}

View File

@ -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<ComboBox, wxComboBox>
{
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<wxComboBox>
, 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

View File

@ -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 <wx/wx.h>
#endif
#include "../../common/main.h"
#include "control.h"
using namespace wxjs;
using namespace wxjs::gui;
/***
* <file>control/control</file>
* <module>gui</module>
* <class name="wxControl" prototype="@wxWindow">
* 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.
* </class>
*/
WXJS_INIT_CLASS(Control, "wxControl", 0)
/***
* <properties>
* <property name="label" type="String">
* Get/Set the label
* </property>
* </properties>
*/
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;
}

View File

@ -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<Control, wxControl>
{
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

View File

@ -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 <wx/wx.h>
#endif
#include "../../common/main.h"
#include "../../common/index.h"
#include "ctrlitem.h"
#include "item.h"
using namespace wxjs;
using namespace wxjs::gui;
/***
* <file>control/ctrlitem</file>
* <module>gui</module>
* <class name="wxControlWithItems" prototype="@wxControl">
* This class is a prototype for some wxWidgets controls which contain
* several items, such as @wxListBox, @wxCheckListBox, @wxChoice and
* @wxComboBox.
* <br /><br />
* It defines the methods for accessing the controls items.
* </class>
*/
WXJS_INIT_CLASS(ControlWithItems, "wxControlWithItems", 0)
/***
* <properties>
* <property name="count" type="Integer" readonly="Y">
* The number of items
* </property>
* <property name="empty" type="Boolean" readonly="Y">
* Returns true when the control has no items
* </property>
* <property name="item" type="@wxControlItem">
* This is an 'array' property. This means that you have to specify an index
* to retrieve the actual item. An example:
* <code class="whjs">
* choice.item[0].value = "BMW";
* </code>
* </property>
* <property name="selection" type="Integer">
* Get/Set the selected item
* </property>
* <property name="stringSelection" type="String">
* Get the label of the selected item or an empty string when no item is
* selected. Or select the item with the given string.
* </property>
* </properties>
*/
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()
/***
* <method name="append">
* <function returns="Integer">
* <arg name="Item" type="String" />
* </function>
* <function>
* <arg name="Items" type="Array" />
* </function>
* <desc>
* 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.
* </desc>
* </method>
*/
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;
}
/***
* <method name="clear">
* <function />
* <desc>
* Removes all items from the control.
* </desc>
* </method>
*/
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;
}
/***
* <method name="deleteItem">
* <function>
* <arg name="Index" type="Integer" />
* </function>
* <desc>
* Removes the item with the given index (zero-based).
* </desc>
* </method>
*/
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;
}
/***
* <method name="findString">
* <function returns="Integer">
* <arg name="Search" type="String" />
* </function>
* <desc>
* Returns the zero-based index of the item with the given search text.
* -1 is returned when the string was not found.
* </desc>
* </method>
*/
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;
}
/***
* <method name="insert">
* <function returns="Integer">
* <arg name="Item" type="String" />
* <arg name="Pos" type="Integer" />
* </function>
* <desc>
* 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.
* </desc>
* </method>
*/
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;
}

View File

@ -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<ControlWithItems,
wxControlWithItems>
{
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

View File

@ -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 <wx/wx.h>
#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;
/***
* <file>control/dialog</file>
* <module>gui</module>
* <class name="wxDialog" prototype="@wxTopLevelWindow">
* 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.
* <br /><br />
* The following sample shows a simple dialog:
* <pre><code class="whjs">// 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();</code></pre>
* </class>
*/
WXJS_INIT_CLASS(Dialog, "wxDialog", 3)
void Dialog::InitClass(JSContext* WXUNUSED(cx),
JSObject* WXUNUSED(obj),
JSObject* WXUNUSED(proto))
{
DialogEventHandler::InitConnectEventMap();
}
/***
* <properties>
* <property name="returnCode" type="Integer" readonly="Y">
* The returncode of the modal dialog
* </property>
* <property name="modal" type="Boolean" readonly="Y">
* Returns true when the dialog is a modal dialog
* </property>
* </properties>
*/
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;
}
/***
* <constants>
* <type name="Style">
* <constant name="DIALOG_MODAL" />
* <constant name="CAPTION" />
* <constant name="DEFAULT_DIALOG_STYLE" />
* <constant name="RESIZE_BORDER" />
* <constant name="SYSTEM_MENU" />
* <constant name="THICK_FRAME" />
* <constant name="STAY_ON_TOP" />
* <constant name="NO_3D" />
* <constant name="DIALOG_EX_CONTEXTHELP" />
* </type>
* </constants>
*/
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()
/***
* <ctor>
* <function />
* <function>
* <arg name="Parent" type="@wxWindow">
* The parent of the dialog. null is Allowed.
* </arg>
* <arg name="Id" type="Integer">
* The window identifier
* </arg>
* <arg name="title" type="String">
* The title of the dialog
* </arg>
* <arg name="Position" type="@wxPoint" default="wxDefaultPosition">
* The position of the dialog.
* </arg>
* <arg name="Size" type="@wxSize" default="wxDefaultSize">
* The size of the dialog
* </arg>
* <arg name="Style" type="Integer" default="wxDialog.DEFAULT_DIALOG_STYLE">
* The window style
* </arg>
* </function>
* <desc>
* Creates a dialog
* </desc>
* </ctor>
*/
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()
/***
* <method name="create">
* <function returns="Boolean">
* <arg name="Parent" type="@wxWindow">
* The parent of the dialog. null is Allowed.
* </arg>
* <arg name="Id" type="Integer">
* The window identifier
* </arg>
* <arg name="title" type="String">
* The title of the dialog
* </arg>
* <arg name="Position" type="@wxPoint" default="wxDefaultPosition">
* The position of the dialog.
* </arg>
* <arg name="Size" type="@wxSize" default="wxDefaultSize">
* The size of the dialog
* </arg>
* <arg name="Style" type="Integer" default="wxDialog.DEFAULT_DIALOG_STYLE">
* The window style
* </arg>
* </function>
* <desc>
* Creates a dialog.
* </desc>
* </method>
*/
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<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, title, *pt, *size, style) )
{
*rval = JSVAL_TRUE;
p->SetClientObject(new JavaScriptClientData(cx, obj, true, false));
}
}
return JS_TRUE;
}
/***
* <method name="endModal">
* <function returns="Integer">
* <arg name="ReturnCode" type="Integer">
* The value to be returned from @wxDialog#showModal
* </arg>
* </function>
* <desc>
* Ends a modal dialog.
* </desc>
* </method>
*/
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;
}
/***
* <method name="showModal">
* <function returns="Integer" />
* <desc>
* Shows a modal dialog.
* The value returned is the return code set by @wxDialog#endModal.
* </desc>
* </method>
*/
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;
}
/***
* <events>
* <event name="onClose">
* Called when the dialog is closed. The type of the argument that your
* handler receives is @wxCloseEvent.
* </event>
* <event name="onInitDialog">
* 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
* </event>
* </events>
*/
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<InitDialogEvent>(event, WXJS_INIT_DIALOG_EVENT);
}
void DialogEventHandler::OnClose(wxCloseEvent &event)
{
PrivCloseEvent::Fire<CloseEvent>(event, WXJS_CLOSE_EVENT);
/*
bool destroy = true;
wxDialog *p = dynamic_cast<wxDialog*>(event.GetEventObject());
if ( PrivCloseEvent::Fire<CloseEvent>(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);
}

View File

@ -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<Dialog, wxDialog>
{
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<wxDialog>
, 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

View File

@ -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 <wx/wx.h>
#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;
/***
* <file>control/dirdlg</file>
* <module>gui</module>
* <class name="wxDirDialog" prototype="wxDialog">
* This class represents the directory chooser dialog.
* </class>
*/
WXJS_INIT_CLASS(DirDialog, "wxDirDialog", 1)
/***
* <properties>
* <property name="message" type="String">
* Get/Set the message of the dialog
* </property>
* <property name="path" type="String">
* Get/Set the full path of the selected file
* </property>
* </properties>
*/
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;
}
/***
* <ctor>
* <function>
* <arg name="Parent" type="@wxWindow">
* The parent of wxDirDialog
* </arg>
* <arg name="Message" type="String" default="'Choose a directory'">
* The title of the dialog
* </arg>
* <arg name="DefaultPath" type="String" default="">
* The default directory
* </arg>
* <arg name="Style" type="Integer" default="0">
* Unused
* </arg>
* <arg name="Position" type="@wxPoint" default="wxDefaultPosition">
* The position of the dialog.
* </arg>
* </function>
* <desc>
* Constructs a new wxDirDialog object
* </desc>
* </ctor>
*/
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<JavaScriptClientData *>(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();
}

View File

@ -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 <wx/dirdlg.h>
namespace wxjs
{
namespace gui
{
class DirDialog : public ApiWrapper<DirDialog, wxDirDialog>
{
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

View File

@ -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 <wx/wx.h>
#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;
/***
* <file>control/filedlg</file>
* <module>gui</module>
* <class name="wxFileDialog" prototype="@wxDialog">
* A dialog for saving or opening a file. The following shows a save dialog:
* <pre><code class="whjs">
* var dlg = new wxFileDialog(frame, "Save a file");
* dlg.style = wxFileDialog.SAVE;
* dlg.showModal();
* </code></pre>
* </class>
*/
WXJS_INIT_CLASS(FileDialog, "wxFileDialog", 1)
/***
* <properties>
* <property name="directory" type="String">
* Get/Set the default directory
* </property>
* <property name="filename" type="String">
* Get/Set the default filename
* </property>
* <property name="filenames" type="Array" readonly="Y">
* Get an array of the selected file names
* </property>
* <property name="filterIndex" type="Integer">
* Get/Set the filter index (wildcards)
* </property>
* <property name="message" type="String">
* Get/Set the message of the dialog
* </property>
* <property name="path" type="String">
* Get/Set the full path of the selected file
* </property>
* <property name="paths" type="Array" readonly="Y">
* Gets the full path of all selected files
* </property>
* <property name="wildcard" type="String">
* Gets/Sets the wildcard such as "*.*" or
* "BMP files (*.bmp)|*.bmp|GIF files (*.gif)|*.gif".
* </property>
* </properties>
*/
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;
}
/***
* <constants>
* <type name="Style">
* <constant name="OPEN" />
* <constant name="SAVE" />
* <constant name="OVERWRITE_PROMPT" />
* <constant name="MULTIPLE" />
* </type>
* </constants>
*/
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()
/***
* <ctor>
* <function>
* <arg name="Parent" type="@wxWindow">
* The parent of wxFileDialog.
* </arg>
* <arg name="Message" type="String" default="'Choose a file'">
* The title of the dialog
* </arg>
* <arg name="DefaultDir" type="String" default="''">
* The default directory
* </arg>
* <arg name="DefaultFile" type="String" default="''">
* The default file
* </arg>
* <arg name="WildCard" type="String" default="'*.*'">
* A wildcard, such as "*.*"
* or "BMP files (*.bmp)|*.bmp|GIF files (*.gif)|*.gif".
* </arg>
* <arg name="Style" type="Integer" default="0">
* The style
* </arg>
* <arg name="Position" type="@wxPoint" default="wxDefaultPosition">
* The position of the dialog.
* </arg>
* </function>
* <desc>
* Constructs a new wxFileDialog object
* </desc>
* </ctor>
*/
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<JavaScriptClientData *>(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();
}

View File

@ -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<FileDialog, wxFileDialog>
{
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

View File

@ -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 <wx/wx.h>
#endif
#include "../../common/main.h"
#include "finddata.h"
using namespace wxjs;
using namespace wxjs::gui;
/***
* <file>control/finddata</file>
* <module>gui</module>
* <class name="wxFindReplaceData">
* 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.
* </class>
*/
WXJS_INIT_CLASS(FindReplaceData, "wxFindReplaceData", 0)
/***
* <properties>
* <property name="findString" type="String">
* Get/Set the string to find
* </property>
* <property name="flags" type="Integer">
* Get/Set the flags.
* </property>
* <property name="replaceString" type="String">
* Get/Set the replacement string
* </property>
* </properties>
*/
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;
}
/***
* <constants>
* <type name="Flags">
* <constant name="FR_DOWN" />
* <constant name="FR_WHOLEWORD" />
* <constant name="FR_MATCHCASE" />
* </type>
* </constants>
*/
WXJS_BEGIN_CONSTANT_MAP(FindReplaceData)
WXJS_CONSTANT(wx, FR_DOWN)
WXJS_CONSTANT(wx, FR_WHOLEWORD)
WXJS_CONSTANT(wx, FR_MATCHCASE)
WXJS_END_CONSTANT_MAP()
/***
* <ctor>
* <function>
* <arg name="Flags" type="Integer" default="0" />
* </function>
* <desc>
* Constructs a new wxFindReplaceData object.
* </desc>
* </ctor>
*/
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;
}

View File

@ -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 <wx/fdrepdlg.h>
namespace wxjs
{
namespace gui
{
class FindReplaceData : public ApiWrapper<FindReplaceData,
wxFindReplaceData>
{
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

View File

@ -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 <wx/wx.h>
#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;
/***
* <file>control/findrdlg</file>
* <module>gui</module>
* <class name="wxFindReplaceDialog" prototype="@wxDialog">
* 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.
* </class>
*/
//TODO: add a sample!
WXJS_INIT_CLASS(FindReplaceDialog, "wxFindReplaceDialog", 0)
void FindReplaceDialog::InitClass(JSContext* WXUNUSED(cx),
JSObject* WXUNUSED(obj),
JSObject* WXUNUSED(proto))
{
FindReplaceEventHandler::InitConnectEventMap();
}
/***
* <properties>
* <property name="data" type="@wxFindReplaceData">
* Get/Set the data
* </property>
* </properties>
*/
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<FindReplaceClientData *>(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;
}
/***
* <constants>
* <type name="Styles">
* <constant name="REPLACEDIALOG" />
* <constant name="NOUPDOWN" />
* <constant name="NOMACTHCASE" />
* <constant name="NOWHOLEWORD" />
* </type>
* </constants>
*/
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()
/***
* <ctor>
* <function>
* <arg name="Parent" type="@wxWindow">
* The parent of wxFindReplaceDialog. Can't be null.
* </arg>
* <arg name="Data" type="@wxFindReplaceData" />
* <arg name="Title" type="String">
* The title of the dialog
* </arg>
* <arg name="Style" type="Integer" default="0" />
* </function>
* <function />
* <desc>
* Constructs a new wxFindReplaceDialog object
* </desc>
* </ctor>
*/
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()
/***
* <method name="create">
* <function>
* <arg name="Parent" type="@wxWindow">
* The parent of wxFindReplaceDialog. Can't be null.
* </arg>
* <arg name="Data" type="@wxFindReplaceData" />
* <arg name="Title" type="String">
* The title of the dialog
* </arg>
* <arg name="Style" type="Integer" default="0" />
* </function>
* <desc>
* Creates a wxFindReplaceDialog.
* </desc>
* </method>
*/
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;
}
/***
* <events>
* <event name="onFind">
* The find button was pressed.
* The argument passed to the function is a @wxFindDialogEvent
* </event>
* <event name="onFindNext">
* The find next button was pressed.
* The argument passed to the function is a @wxFindDialogEvent
* </event>
* <event name="onFindReplace">
* The replace button was pressed.
* The argument passed to the function is a @wxFindDialogEvent
* </event>
* <event name="onFindReplaceAll">
* The replace all button was pressed.
* The argument passed to the function is a @wxFindDialogEvent
* </event>
* <event name="onFindClose">
* The dialog is being destroyed.
* The argument passed to the function is a @wxFindDialogEvent
* </event>
* </events>
*/
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<FindDialogEvent>(event, WXJS_FIND_EVENT);
}
void FindReplaceEventHandler::OnFindNext(wxFindDialogEvent& event)
{
PrivFindDialogEvent::Fire<FindDialogEvent>(event, WXJS_FIND_NEXT_EVENT);
}
void FindReplaceEventHandler::OnReplace(wxFindDialogEvent& event)
{
PrivFindDialogEvent::Fire<FindDialogEvent>(event, WXJS_FIND_REPLACE_EVENT);
}
void FindReplaceEventHandler::OnReplaceAll(wxFindDialogEvent& event)
{
PrivFindDialogEvent::Fire<FindDialogEvent>(event,
WXJS_FIND_REPLACE_ALL_EVENT);
}
void FindReplaceEventHandler::OnFindClose(wxFindDialogEvent& event)
{
PrivFindDialogEvent::Fire<FindDialogEvent>(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);
}

View File

@ -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 <wx/fdrepdlg.h>
#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<FindReplaceDialog,
wxFindReplaceDialog>
{
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<wxFindReplaceDialog>
, 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

View File

@ -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 <wx/wx.h>
#endif
#include "../../common/main.h"
#include "fontdata.h"
#include "../misc/font.h"
#include "../misc/colour.h"
using namespace wxjs;
using namespace wxjs::gui;
/***
* <file>control/fontdata</file>
* <module>gui</module>
* <class name="wxFontData">
* This class holds a variety of information related to font dialogs.
* See @wxFontDialog
* </class>
*/
WXJS_INIT_CLASS(FontData, "wxFontData", 0)
/***
* <properties>
* <property name="allowSymbols" type="Boolean">
* Under MS Windows, get/set a flag determining whether symbol fonts can be selected.
* Has no effect on other platforms
* </property>
* <property name="enableEffects" type="Boolean">
* Get/Set whether 'effects' are enabled under Windows. This refers to the controls for
* manipulating colour, strikeout and underline properties.
* </property>
* <property name="chosenFont" type="@wxFont">
* Get the selected font
* </property>
* <property name="colour" type="@wxColour" />
* <property name="initialFont" type="@wxFont">
* Get/Set the font that will be initially used by the font dialog
* </property>
* <property name="showHelp" type="boolean">
* Show the help button? Windows only.
* </property>
* </properties>
*/
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;
}
/***
* <ctor>
* <function />
* <desc>
* Constructs a new wxFontData object.
* </desc>
* </ctor>
*/
wxFontData* FontData::Construct(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, bool constructing)
{
return new wxFontData();
}

View File

@ -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<FontData, wxFontData>
{
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

View File

@ -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 <wx/wx.h>
#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;
/***
* <file>control/fontdlg</file>
* <module>gui</module>
* <class name="wxFontDialog" prototype="@wxDialog">
* The wxFontDialog presents a Font selector to the user.
* </class>
*/
WXJS_INIT_CLASS(FontDialog, "wxFontDialog", 1)
/***
* <properties>
* <property name="FontData" type="@wxFontData" readonly="Y">
* Gets the Font data.
* </property>
* </properties>
*/
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;
}
/***
* <ctor>
* <function>
* <arg name="Parent" type="@wxWindow">
* The parent of wxFontDialog.
* </arg>
* <arg name="FontData" type="@wxFontData">
* The Font data.
* </arg>
* </function>
* <desc>
* Constructs a new wxFontDialog object
* </desc>
* </ctor>
*/
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<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 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();
}

View File

@ -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 <wx/fontdlg.h>
namespace wxjs
{
namespace gui
{
class FontDialog : public ApiWrapper<FontDialog, wxFontDialog>
{
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

View File

@ -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 <wx/wx.h>
#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;
}
/***
* <file>control/frame</file>
* <module>gui</module>
* <class name="wxFrame" prototype="@wxTopLevelWindow">
* 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.
* </class>
*/
WXJS_INIT_CLASS(Frame, "wxFrame", 3)
void Frame::InitClass(JSContext* WXUNUSED(cx),
JSObject* WXUNUSED(obj),
JSObject* WXUNUSED(proto))
{
FrameEventHandler::InitConnectEventMap();
}
/***
* <properties>
* <property name="menuBar" type="@wxMenuBar">
* Set/Get the menubar
* </property>
* <property name="statusBar" type="@wxStatusBar">
* Set/Get the statusbar
* </property>
* <property name="statusBarFields" type="Integer">
* Set/Get the number of statusbar fields. A statusbar
* is created when there isn't a statusbar created yet.
* </property>
* <property name="statusBarPane" type="Integer">
* Set/Get the pane used to display menu and toolbar help. -1
* disables help display.
* </property>
* <property name="toolBar" type="@wxToolBar">
* Set/Get the toolbar
* </property>
* </properties>
*/
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<JavaScriptClientData *>(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<JavaScriptClientData *>(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<JavaScriptClientData *>(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;
}
/***
* <constants>
* <type name="Style">
* <constant name="DEFAULT_FRAME_STYLE" />
* <constant name="ICONIZE" />
* <constant name="CAPTION" />
* <constant name="MINIMIZE" />
* <constant name="MINIMIZE_BOX" />
* <constant name="MAXIMIZE" />
* <constant name="MAXIMIZE_BOX" />
* <constant name="STAY_ON_TOP" />
* <constant name="SYSTEM_MENU" />
* <constant name="SIMPLE_BORDER" />
* <constant name="RESIZE_BORDER" />
* <constant name="FRAME_FLOAT_ON_PARENT" />
* <constant name="FRAME_TOOL_WINDOW" />
* </type>
* </constants>
*/
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()
/***
* <ctor>
* <function />
* <function>
* <arg name="Parent" type="@wxWindow">
* The parent of the wxFrame. Pass null, when you don't have a parent.
* </arg>
* <arg name="Id" type="Integer">
* The windows identifier. -1 can be used when you don't need a unique id.
* </arg>
* <arg name="Title" type="String">
* The caption of the frame.
* </arg>
* <arg name="Position" type="@wxPoint" default="wxDefaultPosition">
* The position of the frame.
* </arg>
* <arg name="Size" type="@wxSize" default="wxDefaultSize">
* The size of the frame.
* </arg>
* <arg name="Style" type="Integer" default="0">
* The style of the frame.
* </arg>
* </function>
* <desc>
* Creates a new wxFrame object
* </desc>
* </ctor>
*/
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()
/***
* <method name="create">
* <function returns="Boolean">
* <arg name="Parent" type="@wxWindow">
* The parent of the wxFrame. Pass null, when you don't have a parent.
* </arg>
* <arg name="Id" type="Integer">
* The windows identifier. -1 can be used when you don't need a unique id.
* </arg>
* <arg name="Title" type="String">
* The caption of the frame.
* </arg>
* <arg name="Position" type="@wxPoint" default="wxDefaultPosition">
* The position of the frame.
* </arg>
* <arg name="Size" type="@wxSize" default="wxDefaultSize">
* The size of the frame.
* </arg>
* <arg name="Style" type="Integer" default="0">
* The style of the frame.
* </arg>
* </function>
* <desc>
* Creates a new wxFrame object
* </desc>
* </method>
*/
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<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, 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;
}
/***
* <method name="processCommand">
* <function>
* <arg name="Id" type="Integer">
* Identifier of a menu.
* </arg>
* </function>
* <desc>
* Simulates a menu command.
* </desc>
* </method>
*/
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;
}
/***
* <method name="createStatusBar">
* <function returns="@wxStatusBar">
* <arg name="Field" type="Integer" default="1">
* The number of fields. Default is 1.
* </arg>
* <arg name="Style" type="Integer" default="0">
* The style of the statusbar.
* </arg>
* <arg name="Id" type="Integer" default="-1">
* A unique id for the statusbar.
* </arg>
* </function>
* <desc>
* Creates a status bar at the bottom of the frame.
* <br /><b>Remark:</b>
* 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
* </desc>
* </method>
*/
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;
}
/***
* <method name="createToolBar">
* <function returns="@wxToolBar">
* <arg name="Style" type="Integer" default="wxBorder.NONE | wxToolBar.HORIZONTAL">
* The toolbar style
* </arg>
* <arg name="Id" type="Integer" default="-1">
* A unique id for the toolbar
* </arg>
* </function>
* <desc>
* Creates a toolbar at the top or left of the frame.
* </desc>
* </method>
*/
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;
}
/***
* <method name="setStatusText">
* <function>
* <arg name="Text" type="String">
* The text to set in the status field
* </arg>
* <arg name="Field" type="Integer" default="0">
* The number of the field (zero indexed)
* </arg>
* </function>
* <desc>
* Sets the text of the given status field. When no field is specified,
* the first one is used.
* </desc>
* </method>
*/
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;
}
/***
* <method name="setStatusWidths">
* <function>
* <arg name="Widths" type="Array">
* 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.
* </arg>
* </function>
* <desc>
* 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.
* </desc>
* </method>
*/
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;
}
/***
* <events>
* <event name="onClose">
* Called when the frame is closed. The type of the argument that your
* handler receives is @wxCloseEvent.
* </event>
* <event name="onIconize">
* 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.
* </event>
* <event name="onMaximize">
* 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.
* </event>
* </events>
*/
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<wxWindow *>(event.GetEventObject());
wxFrame *frame = dynamic_cast<wxFrame*>(eventObject);
if ( frame == NULL )
{
// It can be a toolbar
frame = dynamic_cast<wxFrame*>(eventObject->GetParent());
if ( frame == NULL )
return;
}
JavaScriptClientData *clientData
= dynamic_cast<JavaScriptClientData*>(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<JavaScriptClientData*>(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<CloseEvent>(event, WXJS_CLOSE_EVENT);
}
void FrameEventHandler::OnIconize(wxIconizeEvent &event)
{
PrivIconizeEvent::Fire<IconizeEvent>(event, WXJS_ICONIZE_EVENT);
}
void FrameEventHandler::OnMaximize(wxMaximizeEvent &event)
{
PrivMaximizeEvent::Fire<MaximizeEvent>(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);
}

View File

@ -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<Frame, wxFrame>
, 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<wxFrame>
, 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

View File

@ -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 <wx/wx.h>
#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;
/***
* <file>control/gauge</file>
* <module>gui</module>
* <class name="wxGauge" prototype="@wxControl">
* A gauge is a horizontal or vertical bar which shows a quantity (often time).
* </class>
*/
WXJS_INIT_CLASS(Gauge, "wxGauge", 3)
/***
* <properties>
* <property name="bezelFace" type="Integer">
* Get/Set the width of the 3D bezel face. <I>Windows only</I>
* </property>
* <property name="range" type="Integer">
* Get/Set the maximum position of the gauge.
* </property>
* <property name="shadowWidth" type="Integer">
* Get/Set the 3D shadow margin width. <I>Windows only</I>
* </property>
* <property name="value" type="Integer">
* Get/Set the current value of the gauge.
* </property>
* </properties>
*/
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);
}
/***
* <constants>
* <type name="Style">
* <constant name="HORIZONTAL" />
* <constant name="VERTICAL" />
* <constant name="PROGRESSBAR" />
* <constant name="SMOOTH" />
* </type>
* </constants>
*/
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()
/***
* <ctor>
* <function />
* <function>
* <arg name="Parent" type="@wxWindow">
* The parent of wxGauge.
* </arg>
* <arg name="Id" type="Integer">
* An window identifier. Use -1 when you don't need it.
* </arg>
* <arg name="Range" type="Integer">
* The maximum value of the gauge
* </arg>
* <arg name="Position" type="@wxPoint" default="wxDefaultPosition">
* The position of the Gauge control on the given parent.
* </arg>
* <arg name="Size" type="@wxSize" default="wxDefaultSize">
* The size of the Gauge control.
* </arg>
* <arg name="Style" type="Integer" default="wxGauge.HORIZONTAL">
* The wxGauge style.
* </arg>
* <arg name="Validator" type="@wxValidator" default="null" />
* </function>
* <desc>
* Constructs a new wxGauge object.
* </desc>
* </ctor>
*/
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()
/***
* <method name="create">
* <function returns="Boolean">
* <arg name="Parent" type="@wxWindow">
* The parent of wxGauge.
* </arg>
* <arg name="Id" type="Integer">
* An window identifier. Use -1 when you don't need it.
* </arg>
* <arg name="Range" type="Integer">
* The maximum value of the gauge
* </arg>
* <arg name="Position" type="@wxPoint" default="wxDefaultPosition">
* The position of the Gauge control on the given parent.
* </arg>
* <arg name="Size" type="@wxSize" default="wxDefaultSize">
* The size of the Gauge control.
* </arg>
* <arg name="Style" type="Integer" default="wxGauge.HORIZONTAL">
* The wxGauge style.
* </arg>
* <arg name="Validator" type="@wxValidator" default="null" />
* </function>
* <desc>
* Creates a wxGauge
* </desc>
* </method>
*/
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<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, range, *pt, *size, style, *val) )
{
*rval = JSVAL_TRUE;
p->SetClientObject(new JavaScriptClientData(cx, obj, true, false));
}
}
return JS_TRUE;
}

View File

@ -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<Gauge, wxGauge>
{
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

View File

@ -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 <wx/wx.h>
#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;
/***
* <file>control/helpbtn</file>
* <module>gui</module>
* <class name="wxContextHelpButton" prototype="@wxBitmapButton">
* 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.
* </class>
*/
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);
}
/***
* <ctor>
* <function>
* <arg name="Parent" type="@wxWindow">
* The parent of wxContextHelpButton.
* </arg>
* </function>
* <desc>
* Constructs a new wxContextHelpButton object.
* </desc>
* </ctor>
*/
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<JavaScriptClientData *>(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;
}

View File

@ -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 <wx/cshelp.h>
namespace wxjs
{
namespace gui
{
class ContextHelpButton : public ApiWrapper<ContextHelpButton,
wxContextHelpButton>
{
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

View File

@ -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 <wx/wx.h>
#endif
#include <wx/filename.h>
/***
* <file>control/htmlwin</file>
* <module>gui</module>
* <class name="wxHtmlWindow" prototype="@wxScrolledWindow">
* 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.
* </class>
*/
#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();
}
/***
* <constants>
* <type name="styles">
* <constant name="SCROLLBAR_NEVER">
* Never display scrollbars, not even when the page is larger
* than the window.</constant>
* <constant name="SCROLLBAR_AUTO">
* Display scrollbars only if page's size exceeds window's size.
* </constant>
* <constant name="NO_SELECTION">
* Don't allow the user to select text.
* </constant>
* <constant name="DEFAULT_STYLE" />
* </type>
* </constants>
*/
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()
/***
* <properties>
* <property name="historyCanBack" type="String" readonly="Y">
* Returns true if it is possible to go back in the history
* (i.e. @wxHtmlWindow#historyBack won't fail).
* </property>
* <property name="historyCanForward" type="String" readonly="Y">
* Returns true if it is possible to go forward in the history
* (i.e. @wxHtmlWindow#historyForward won't fail).
* </property>
* <property name="openedAnchor" type="String" readonly="Y">
* 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.
* </property>
* <property name="openedPage" type="String" readonly="Y">
* 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.
* </property>
* <property name="openedPageTitle" type="String" readonly="Y">
* Returns title of the opened page or wxEmptyString if current page does
* not contain &lt;title&gt; tag.
* </property>
* <property name="relatedFrame" type="@wxFrame">
* Gets/Sets the frame in which page title will be displayed.
* </property>
* <property name="text" type="String">
* Returns content of currently displayed page as plain text.
* </property>
* </properties>
*/
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;
}
/***
* <ctor>
* <function />
* <function>
* <arg name="Parent" type="@wxWindow">The parent window</arg>
* <arg name="Id" type="Integer">A windows identifier. Use -1 when you don't need it.</arg>
* <arg name="Position" type="@wxPoint" default="wxDefaultPosition">The position of the control on the given parent</arg>
* <arg name="Size" type="@wxSize" default="wxDefaultSize">The size of the control</arg>
* <arg name="Style" type="Integer" default="wxHtmlWindow.DEFAULT_STYLE">The style of the control</arg>
* </function>
* <desc>
* Constructs a new wxHtmlWindow object. See also @wxHtmlWindow#create.
* </desc>
* </ctor>
*/
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
/***
* <method name="create">
* <function returns="Boolean">
* <arg name="Parent" type="@wxWindow">The parent window</arg>
* <arg name="Id" type="Integer">A windows identifier. Use -1 when you don't need it.</arg>
* <arg name="Position" type="@wxPoint" default="wxDefaultPosition">The position of the control on the given parent</arg>
* <arg name="Size" type="@wxSize" default="wxDefaultSize">The size of the control</arg>
* <arg name="Style" type="Integer" default="wxHtmlWindow.DEFAULT_STYLE">The style of the control</arg>
* </function>
* <desc>
* Creates an HTML window.
* </desc>
* </method>
*/
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<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, *pt, *size, style) )
{
*rval = JSVAL_TRUE;
p->SetClientObject(new JavaScriptClientData(cx, obj, true, false));
}
}
return JS_TRUE;
}
/***
* <method name="appendToPage">
* <function returns="Boolean">
* <arg name="Source" type="String">HTML fragment</arg>
* </function>
* <desc>
* Appends HTML fragment to currently displayed text and refreshes the window.
* False is returned on failure.
* </desc>
* </method>
*/
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;
}
/***
* <method name="historyBack">
* <function returns="Boolean" />
* <desc>
* Moves back to the previous page. (each page displayed using
* @wxHtmlWindow#loadPage is stored in history list.)
* </desc>
* </method>
*/
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;
}
/***
* <method name="historyClear">
* <function />
* <desc>
* Clears the history.
* </desc>
* </method>
*/
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;
}
/***
* <method name="historyForward">
* <function returns="Boolean" />
* <desc>
* Moves forward to the next page. (each page displayed using
* @wxHtmlWindow#loadPage is stored in history list.)
* </desc>
* </method>
*/
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;
}
/***
* <method name="loadFile">
* <function returns="Boolean">
* <arg name="filename" type="@wxFileName">The file to load</arg>
* </function>
* <function returns="Boolean">
* <arg name="filename" type="String">The file to load</arg>
* </function>
* <desc>
* Loads HTML page from file and displays it. Returns false on failure.
* </desc>
* </method>
*/
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;
}
/***
* <method name="loadPage">
* <function returns="Boolean">
* <arg name="Location" type="String">The address of document</arg>
* </function>
* <desc>
* Unlike @wxHtmlWindow#setPage this function first loads HTML page
* from location and then displays it.
* </desc>
* </method>
*/
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
/***
* <method name="selectAll">
* <function />
* <desc>
* Selects all text in the window.
* </desc>
* </method>
*/
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;
}
/***
* <method name="selectLine">
* <function>
* <arg name="Pos" type="@wxPoint" />
* </function>
* <desc>
* 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.
* </desc>
* </method>
*/
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;
}
/***
* <method name="selectWord">
* <function>
* <arg name="Pos" type="@wxPoint" />
* </function>
* <desc>
* 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.
* </desc>
* </method>
*/
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;
}
/***
* <method name="setBorders">
* <function>
* <arg name="Border" type="Integer" />
* </function>
* <desc>
* This function sets the space between border of window and HTML contents.
* </desc>
* </method>
*/
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;
}
/***
* <method name="setFonts">
* <function>
* <arg name="NormalFace" type="String">
* 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.
* </arg>
* <arg name="FixedFace" type="String">
* The same thing for fixed face
* </arg>
* <arg name="Sizes" type="Array" default="null">
* This is an array of 7 items of Integer type. The values represent size
* of font with HTML size from -2 to +4 ( &lt;FONT SIZE=-2&gt; to
* &lt;FONT SIZE=+4&gt; ). Default sizes are used if sizes is null.
* </arg>
* </function>
* <desc>
* This function sets font sizes and faces
* </desc>
* </method>
*/
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;
}
/***
* <method name="setPage">
* <function returns="Boolean">
* <arg name="Source" type="String">The HTML source</arg>
* </function>
* <desc>
* Sets HTML page and display it. This won't load the page!!
* It will display the source
* </desc>
* </method>
*/
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;
}
/***
* <method name="setRelatedFrame">
* <function>
* <arg name="Frame" type="@wxFrame" />
* <arg name="Format" type="String" />
* </function>
* <desc>
* 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.
* </desc>
* </method>
*/
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;
}
/***
* <method name="setRelatedStatusBar">
* <function>
* <arg name="Bar" type="Integer" default="-1" />
* </function>
* <desc>
* After calling @wxHtmlWindow#setRelatedFrame, this sets statusbar slot
* where messages will be displayed. (Default is -1 = no messages.)
* </desc>
* </method>
*/
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");
/***
* <events>
* <event name="onLinkClicked">
* This event is triggered when a hyperlinck is clicked. The function receives
* a @wxHtmlLinkEvent as argument.
* </event>
* </events>
*/
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<HtmlLinkEvent>(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);
}

View File

@ -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 <wx/html/htmlwin.h>
#include "../../common/evtconn.h"
namespace wxjs
{
namespace gui
{
class HtmlWindow : public ApiWrapper<HtmlWindow, wxHtmlWindow>
{
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<wxHtmlWindow>
, 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

View File

@ -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 <wx/wx.h>
#endif
#include "../../common/main.h"
#include "../../common/index.h"
#include "item.h"
#include "ctrlitem.h"
using namespace wxjs;
using namespace wxjs::gui;
/***
* <file>control/item</file>
* <module>gui</module>
* <class name="wxControlItem">
* wxControlItem represents an item in a @wxControlWithItems control.
* <br /><br /><b>Remark:</b> 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.
* </class>
*/
WXJS_INIT_CLASS(ControlItem, "wxControlItem", 0)
/***
* <properties>
* <property name="value" type="String">
* Get/Set the value of the item.
* </property>
* </properties>
*/
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;
}
/***
* <method name="remove">
* <function />
* <desc>
* removes the item from the control.
* </desc>
* </method>
*/
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;
}
/***
* <method name="select">
* <function />
* <desc>
* Selects/unselects the item.
* </desc>
* </method>
*/
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;
}

View File

@ -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<ControlItem, Index>
{
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

View File

@ -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 <wx/wx.h>
#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;
/***
* <file>control/listbox</file>
* <module>gui</module>
* <class name="wxListBox" prototype="@wxControlWithItems">
* 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).
* </class>
*/
WXJS_INIT_CLASS(ListBox, "wxListBox", 2)
void ListBox::InitClass(JSContext* WXUNUSED(cx),
JSObject* WXUNUSED(obj),
JSObject* WXUNUSED(proto))
{
ListBoxEventHandler::InitConnectEventMap();
}
/***
* <properties>
* <property name="selections" type="Array" readonly="Y">
* An array with all the indexes of the selected items
* </property>
* </properties>
*/
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;
}
/***
* <constants>
* <type name="Style">
* <constant name="SINGLE" />
* <constant name="MULTIPLE" />
* <constant name="EXTENDED" />
* <constant name="HSCROLL" />
* <constant name="ALWAYS_SB" />
* <constant name="NEEDED_SB" />
* <constant name="SORT" />
* </type>
* </constants>
*/
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()
/***
* <ctor>
* <function />
* <function>
* <arg name="Parent" type="@wxWindow">
* The parent of the wxListBox. null is not Allowed.
* </arg>
* <arg name="Id" type="Integer">
* The windows identifier. -1 can be used when you don't need a unique id.
* </arg>
* <arg name="Position" type="@wxPoint" default="wxDefaultPosition">
* The position of the listbox.
* </arg>
* <arg name="Size" type="@wxSize" default="wxDefaultSize">
* The size of the listbox.
* </arg>
* <arg name="Items" type="Array" default="null">
* The items for the listbox.
* </arg>
* <arg name="Style" type="Integer" default="0">
* The style of listbox. You can use the @wxListBox#style.
* </arg>
* <arg name="Validator" type="@wxValidator" default="null" />
* </function>
* <desc>
* Creates a new wxListBox object
* </desc>
* </ctor>
*/
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()
/***
* <method name="create">
* <function returns="Boolean">
* <arg name="Parent" type="@wxWindow">
* The parent of the wxListBox. null is not Allowed.
* </arg>
* <arg name="Id" type="Integer">
* The windows identifier. -1 can be used when you don't need a unique id.
* </arg>
* <arg name="Position" type="@wxPoint" default="wxDefaultPosition">
* The position of the listbox.
* </arg>
* <arg name="Size" type="@wxSize" default="wxDefaultSize">
* The size of the listbox.
* </arg>
* <arg name="Items" type="Array" default="null">
* The items for the listbox.
* </arg>
* <arg name="Style" type="Integer" default="0">
* The style of listbox. You can use the @wxListBox#style.
* </arg>
* <arg name="Validator" type="@wxValidator" default="null" />
* </function>
* <desc>
* Creates a wxListBox
* </desc>
* </method>
*/
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<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, *pt, *size,
items.GetCount(), items.GetStrings(), style, *val) )
{
*rval = JSVAL_TRUE;
p->SetClientObject(new JavaScriptClientData(cx, obj, true, false));
}
}
return JS_TRUE;
}
/***
* <method name="setFirstItem">
* <function>
* <arg name="Idx" type="Integer">
* The zero-based item index
* </arg>
* </function>
* <function>
* <arg name="Str" type="String">
* The string that should be visible
* </arg>
* </function>
* <desc>
* Set the specified item to be the first visible item. Windows only.
* </desc>
* </method>
*/
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;
}
/***
* <method name="insertItems">
* <function>
* <arg name="Items" type="Array" />
* <arg name="Index" type="Integer">
* 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
* </arg>
* </function>
* <desc>
* Inserts all the items
* </desc>
* </method>
*/
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;
}
/***
* <events>
* <event name="onListBox">
* Called when an item is selected.
* The type of the argument that your handler receives is @wxCommandEvent.
* </event>
* <event name="onDoubleClicked">
* Called when the listbox is double clicked.
* The type of the argument that your handler receives is @wxCommandEvent.
* </event>
* </events>
*/
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<CommandEvent>(event, WXJS_LISTBOX_EVENT);
}
void ListBoxEventHandler::OnDoubleClick(wxCommandEvent &event)
{
PrivCommandEvent::Fire<CommandEvent>(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);
}

View File

@ -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<ListBox, wxListBox>
{
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<wxListBox>
, 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

File diff suppressed because it is too large Load Diff

View File

@ -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 <wx/listctrl.h>
#include "../../common/evtconn.h"
namespace wxjs
{
namespace gui
{
class ListCtrl : public wxListCtrl
, public ApiWrapper<ListCtrl, wxListCtrl>
{
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<wxListCtrl>
, 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

View File

@ -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 <wx/wxprec.h>
#ifndef WX_PRECOMP
#include <wx/wx.h>
#endif
#include "../../common/main.h"
#include "listhit.h"
#include "../misc/constant.h"
using namespace wxjs;
using namespace wxjs::gui;
/***
* <file>control/listhit</file>
* <module>gui</module>
* <class name="wxListHitTest">
* Helper class for returning information from @wxListCtrl#hitTest.
* This class is specific for wxJavaScript. It doesn't exist in wxWidgets.
* </class>
*/
WXJS_INIT_CLASS(ListHitTest, "wxListHitTest", 0)
/***
* <properties>
* <property name="item" type="Integer" readonly="Y">
* Get the item.
* </property>
* <property name="flags" type="Integer" readonly="Y">
* Get the flags. These flags give details about the position and the list
* control item.
* </property>
* </properties>
*/
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;
}
/***
* <constants>
* <type name="HitTest">
* <constant name="ABOVE">Above the client area.</constant>
* <constant name="BELOW">Below the client area.</constant>
* <constant name="NOWHERE">In the client area but below the last item.</constant>
* <constant name="ONITEMICON">On the bitmap associated with an item.</constant>
* <constant name="ONITEMLABEL">On the label (string) associated with an item.</constant>
* <constant name="ONITEMRIGHT">In the area to the right of an item.</constant>
* <constant name="ONITEMSTATEICON">On the state icon for a tree view item that is in a user-defined state.</constant>
* <constant name="TOLEFT">To the left of the client area.</constant>
* <constant name="TORIGHT">To the right of the client area.</constant>
* <constant name="ONITEM">(ONITEMICON | ONITEMLABEL | ONITEMSTATEICON)</constant>
* </type>
* </constants>
*/
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()

View File

@ -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 <wx/listctrl.h>
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<ListHitTest, wxListHitTest>
{
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

View File

@ -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 <wx/wxprec.h>
#ifndef WX_PRECOMP
#include <wx/wx.h>
#endif
#include <wx/listctrl.h>
#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;
/***
* <file>control/listitattr</file>
* <module>gui</module>
* <class name="wxListItemAttr">
* wxListItemAttr is used in virtual list controls.
* See @wxListCtrl#onGetItemAttr property
* </class>
*/
WXJS_INIT_CLASS(ListItemAttr, "wxListItemAttr", 0)
/***
* <properties>
* <property name="textColour" type="@wxColour">
* The colour used for displaying text.
* </property>
* <property name="backgroundColour" type="@wxColour">
* The colour used as background.
* </property>
* <property name="font" type="@wxFont">
* The font used for displaying text.
* </property>
* <property name="hasTextColour" type="Boolean" readonly="Y">
* Indicates that this attribute defines the text colour.
* </property>
* <property name="hasBackgroundColour" type="Boolean" readonly="Y">
* Indicates that this attribute defines the background colour.
* </property>
* <property name="hasFont" type="Boolean" readonly="Y">
* Indicates that this attributes defines a font.
* </property>
* </properties>
*/
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;
}
/***
* <ctor>
* <function />
* <desc>
* Creates a new wxListItem object.
* </desc>
* </ctor>
*/
wxListItemAttr *ListItemAttr::Construct(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, bool constructing)
{
return new wxListItemAttr();
}

View File

@ -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<ListItemAttr, wxListItemAttr>
{
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

View File

@ -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 <wx/wxprec.h>
#ifndef WX_PRECOMP
#include <wx/wx.h>
#endif
#include <wx/listctrl.h>
#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;
/***
* <file>control/listitem</file>
* <module>gui</module>
* <class name="wxListItem">
* This class stores information about a @wxListCtrl item or column.
* </class>
*/
WXJS_INIT_CLASS(ListItem, "wxListItem", 0)
/***
* <properties>
* <property name="align" type="Integer">
* The column alignment. See @wxListCtrl#wxListColumnFormat.
* </property>
* <property name="backgroundColour" type="@wxColour">
* Get/Set the background colour of the item.
* </property>
* <property name="column" type="Integer">
* Get/Set the column.
* </property>
* <property name="data" type="Integer">
* Get/Set the associated data.
* </property>
* <property name="font" type="@wxFont">
* Get/Set the font of the item.
* </property>
* <property name="hasAttributes" type="Boolean" readonly="Y">
* Returns true when the item has attributes.
* </property>
* <property name="id" type="Integer">
* Get/Set index of the item.
* </property>
* <property name="image" type="Integer">
* Get/Set the index of the image in the associated imagelist of the list control.
* </property>
* <property name="mask" type="Integer">
* Get/Set the mask. The mask indicates which fields of wxListItem are valid.
* See @wxListMask
* </property>
* <property name="state" type="Integer">
* Get/Set the state. See @wxListState
* </property>
* <property name="stateMask" type="Integer">
* Get/Set the state mask. This indicates which state is valid. See @wxListState
* </property>
* <property name="text" type="String">
* Get/Set the text of the item.
* </property>
* <property name="textColour" type="@wxColour">
* Get/Set the text colour.
* </property>
* <property name="width" type="Integer">
* Get/Set the width.
* </property>
* </properties>
*/
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;
}
/***
* <ctor>
* <function>
* <arg name="Index" type="Integer">
* The index of the item
* </arg>
* </function>
* <desc>
* Creates a new wxListItem object.
* See @wxListCtrl#getItem and @wxListCtrl#setItem
* </desc>
* </ctor>
*/
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;
}

View File

@ -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<ListItem, wxListItem>
{
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

View File

@ -0,0 +1,347 @@
#include "precompiled.h"
#ifndef WX_PRECOMP
#include <wx/wx.h>
#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;
}
/***
* <module>gui</module>
* <file>control/mdiparent</file>
* <class name="wxMDIParentFrame" prototype="@wxFrame">
* 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).
* </class>
*/
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;
}
/***
* <ctor>
* <function />
* <function>
* <arg name="Parent" type="@wxWindow">The parent window</arg>
* <arg name="Id" type="Integer">The window ID</arg>
* <arg name="Title" type="String">The title of the window</arg>
* <arg name="Pos" type="@wxPoint" default="wxDefaultPosition" />
* <arg name="Size" type="@wxSize" default="wxDefaultSize" />
* <arg name="Style" type="Integer"
* default="wxDEFAULT_FRAME_STYLE | wxVSCROLL | wxHSCROLL" />
* </function>
* <desc>
* Creates a new MDI parent frame.
* </desc>
* </ctor>
*/
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;
}
/***
* <properties>
* <property name="activeChild" type="@wxMDIChildFrame" readonly="Y">
* The active MDI child, if there is one.
* </property>
* </properties>
*/
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<JavaScriptClientData*>(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()
/***
* <method name="create">
* <function returns="Boolean">
* <arg name="Parent" type="@wxWindow">The parent window</arg>
* <arg name="Id" type="Integer">The window ID</arg>
* <arg name="Title" type="String">The title of the window</arg>
* <arg name="Pos" type="@wxPoint" default="wxDefaultPosition" />
* <arg name="Size" type="@wxSize" default="wxDefaultSize" />
* <arg name="Style" type="Integer"
* default="wxDEFAULT_FRAME_STYLE | wxVSCROLL | wxHSCROLL" />
* </function>
* <desc>
* Sets a pixel to a particular color.
* </desc>
* </method>
*/
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;
}
/***
* <method name="activeNext">
* <function />
* <desc>
* Activates the MDI child following the currently active one.
* </desc>
* </method>
*/
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;
}
/***
* <method name="activePrevious">
* <function />
* <desc>
* Activates the MDI child preceding the currently active one.
* </desc>
* </method>
*/
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;
}
/***
* <method name="arrangeIcons">
* <function />
* <desc>
* Arranges any iconized (minimized) MDI child windows.
* </desc>
* </method>
*/
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;
}
/***
* <method name="cascade">
* <function />
* <desc>
* Arranges the MDI child windows in a cascade.
* </desc>
* </method>
*/
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;
}
/***
* <method name="cascade">
* <function>
* <arg name="Orientation" type="@wxOrientation"
* default="wxOrientation.HORIZONTAL" />
* </function>
* <desc>
* Tiles the MDI child windows either horizontally or vertically.
* Currently only implemented for MSW, does nothing under the other platforms.
* </desc>
* </method>
*/
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;
}

View File

@ -0,0 +1,59 @@
#ifndef _wxjs_gui_mdi_h
#define _wxjs_gui_mdi_h
namespace wxjs
{
namespace gui
{
class MDIParentFrame : public ApiWrapper<MDIParentFrame, wxMDIParentFrame>
, 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

View File

@ -0,0 +1,266 @@
#include "precompiled.h"
#ifndef WX_PRECOMP
#include <wx/wx.h>
#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;
}
/***
* <module>gui</module>
* <file>control/mdichild</file>
* <class name="wxMDIChildFrame" prototype="@wxFrame">
* An MDI child frame is a frame that can only exist in a @wxMDIParentFrame
* </class>
*/
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;
}
/***
* <ctor>
* <function />
* <function>
* <arg name="Parent" type="@wxMDIParentFrame">
* The parent frame. This can't be null.
* </arg>
* <arg name="Id" type="Integer">The window ID</arg>
* <arg name="Title" type="String">The title of the window</arg>
* <arg name="Pos" type="@wxPoint" default="wxDefaultPosition" />
* <arg name="Size" type="@wxSize" default="wxDefaultSize" />
* <arg name="Style" type="Integer"
* default="wxDEFAULT_FRAME_STYLE" />
* </function>
* <desc>
* Creates a new MDI child frame.
* </desc>
* </ctor>
*/
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()
/***
* <method name="create">
* <function returns="Boolean">
* <arg name="Parent" type="@wxMDIParentFrame">
* The parent frame. This can't be null.
* </arg>
* <arg name="Id" type="Integer">The window ID</arg>
* <arg name="Title" type="String">The title of the window</arg>
* <arg name="Pos" type="@wxPoint" default="wxDefaultPosition" />
* <arg name="Size" type="@wxSize" default="wxDefaultSize" />
* <arg name="Style" type="Integer"
* default="wxDEFAULT_FRAME_STYLE | wxVSCROLL | wxHSCROLL" />
* </function>
* <desc>
* Sets a pixel to a particular color.
* </desc>
* </method>
*/
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;
}
/***
* <method name="activate">
* <function />
* <desc>
* Activates this MDI child frame
* </desc>
* </method>
*/
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;
}
/***
* <method name="maximize">
* <function>
* <arg name="Maximize" type="Boolean" />
* </function>
* <desc>
* Maximizes this MDI child frame
* </desc>
* </method>
*/
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;
}
/***
* <method name="restore">
* <function />
* <desc>
* Restores this MDI child frame
* </desc>
* </method>
*/
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;
}

View File

@ -0,0 +1,50 @@
#ifndef _wxjs_gui_mdi_child_h
#define _wxjs_gui_mdi_child_h
namespace wxjs
{
namespace gui
{
class MDIChildFrame : public ApiWrapper<MDIChildFrame, wxMDIChildFrame>
, 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

View File

@ -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 <wx/wx.h>
#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);
}
}
*/
/***
* <file>control/menu</file>
* <module>gui</module>
* <class name="wxMenu">
* 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.
* </class>
*/
WXJS_INIT_CLASS(Menu, "wxMenu", 0)
/***
* <properties>
* <property name="actions" type="Array">
* 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.
* </property>
* <property name="menuItemCount" type="Integer" readonly="Y">
* Returns the number of menu items.
* </property>
* <property name="menuItems" type="Array" readonly="Y">
* Returns all the menu items.
* </property>
* <property name="title" type="String">
* Get/Set the title of the menu
* </property>
* </properties>
*/
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;
}
/***
* <constants>
* <type name="Styles">
* <constant name="TEAROFF">(wxGTK only)</constant>
* </type>
* </constants>
*/
WXJS_BEGIN_CONSTANT_MAP(Menu)
// Style constants
WXJS_CONSTANT(wxMENU_, TEAROFF)
WXJS_END_CONSTANT_MAP()
/***
* <ctor>
* <function>
* <arg name="Title" type="String" default="">
* A title for the popup menu
* </arg>
* <arg name="Style" type="Integer" default="0">
* A menu style
* </arg>
* </function>
* <function>
* <arg name="Style" type="Integer" default="0">
* A menu style
* </arg>
* </function>
* <desc>
* Creates a new wxMenu object
* </desc>
* </ctor>
*/
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()
/***
* <method name="append">
* <function>
* <arg name="Id" type="Integer">
* The id of the menu item.
* </arg>
* <arg name="Name" type="String">
* The name of the menu item.
* </arg>
* <arg name="Action" type="Function">
* The function that is called when the menu item is selected. The argument to the
* function will be @wxCommandEvent.
* </arg>
* <arg name="HelpString" type="String" default="">
* Message which is shown in the statusbar.
* </arg>
* <arg name="Checkable" type="Boolean" default="false">
* Indicates if the menu item can be checked or not.
* </arg>
* </function>
* <desc>
* Appends a new menu item to the menu.
* </desc>
* </method>
*/
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;
}
/***
* <method name="check">
* <function>
* <arg name="Id" type="Integer">
* The id of the menu item.
* </arg>
* <arg name="Check" type="Boolean">
* Check (true) or uncheck (false) the item
* </arg>
* </function>
* <desc>
* Checks or unchecks the menu item.
* </desc>
* </method>
*/
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;
}
/***
* <method name="enable">
* <function>
* <arg name="Id" type="Integer">
* The id of the menu item.
* </arg>
* <arg name="Enable" type="Boolean">
* Enables (true) or disables (false) the item
* </arg>
* </function>
* <desc>
* Enables or disables the menu item.
* </desc>
* </method>
*/
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;
}
/***
* <method name="deleteItem">
* <function>
* <arg name="Id" type="Integer">
* The id of the menu item.
* </arg>
* </function>
* <function>
* <arg name="MenuItem" type="@wxMenuItem">
* A menu item.
* </arg>
* </function>
* <desc>
* 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.
* </desc>
* </method>
*/
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;
}
/***
* <method name="findItem">
* <function returns="Integer">
* <arg name="Search" type="String">
* The search string
* </arg>
* </function>
* <desc>
* 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.
* </desc>
* </method>
*/
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;
}
/***
* <method name="break">
* <function />
* <desc>
* Adds a new column
* </desc>
* </method>
*/
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;
}
/***
* <method name="appendSeparator">
* <function />
* <desc>
* Adds a separator
* </desc>
* </method>
*/
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;
}
/***
* <method name="getHelpString">
* <function returns="String">
* <arg name="Id" type="Integer">
* The id of the menu item
* </arg>
* </function>
* <desc>
* Returns the helpstring of the menu item with the given id.
* See @wxMenu#setHelpString and @wxMenuItem#help property
* </desc>
* </method>
*/
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;
}
/***
* <method name="getLabel">
* <function returns="String">
* <arg name="Id" type="Integer">
* The id of the menu item
* </arg>
* </function>
* <desc>
* Returns the label of the menu item with the given id.
* See @wxMenu#setLabel and @wxMenuItem#label property.
* </desc>
* </method>
*/
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;
}
/***
* <method name="getItem">
* <function returns="@wxMenuItem">
* <arg name="Id" type="Integer">
* The id of the menu item
* </arg>
* </function>
* <desc>
* Returns the @wxMenuItem object of the menu item with the given id.
* </desc>
* </method>
*/
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;
}
/***
* <method name="destroy">
* <function>
* <arg name="Id" type="Integer">
* The id of the menu item
* </arg>
* </function>
* <function>
* <arg name="MenuItem" type="@wxMenuItem" />
* </function>
* <desc>
* 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).
* </desc>
* </method>
*/
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;
}
/***
* <method name="insert">
* <function>
* <arg name="Pos" type="Integer" />
* <arg name="MenuItem" type="@wxMenuItem" />
* </function>
* <desc>
* Inserts the given item before the position pos.
* Inserting the item at the position @wxMenu#menuItemCount
* is the same as appending it.
* </desc>
* </method>
*/
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;
}
/***
* <method name="isChecked">
* <function returns="Boolean">
* <arg name="Id" type="Integer">
* A menu item identifier.
* </arg>
* </function>
* <desc>
* Returns true when the menu item is checked.
* </desc>
* </method>
*/
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;
}
/***
* <method name="isEnabled">
* <function returns="Boolean">
* <arg name="Id" type="Integer">
* A menu item identifier.
* </arg>
* </function>
* <desc>
* Returns true when the menu item is enabled.
* </desc>
* </method>
*/
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;
}
/***
* <method name="remove">
* <function returns="@wxMenuItem">
* <arg name="Id" type="Integer">
* An identifier of a menu item.
* </arg>
* </function>
* <function returns="@wxMenuItem">
* <arg name="MenuItem" type="@wxMenuItem" />
* </function>
* <desc>
* 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).
* </desc>
* </method>
*/
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;
}
/***
* <method name="setHelpString">
* <function>
* <arg name="Id" type="Integer">
* A menu item identifier.
* </arg>
* <arg name="Help" type="String">
* The help text
* </arg>
* </function>
* <desc>
* Sets the help associated with a menu item.
* See @wxMenuItem#help property and @wxMenuBar#setHelpString method.
* </desc>
* </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;
}
/***
* <method name="setLabel">
* <function>
* <arg name="Id" type="Integer">
* A menu item identifier.
* </arg>
* <arg name="Label" type="String">
* A new label
* </arg>
* </function>
* <desc>
* Sets the label of a menu item.
* See @wxMenuItem#label property and @wxMenuBar#setLabel method
* </desc>
* </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;
}

View File

@ -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<Menu, wxMenu>
{
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

View File

@ -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 <wx/wx.h>
#endif
#include "../../common/main.h"
#include "menubar.h"
#include "menu.h"
#include "../misc/app.h"
using namespace wxjs;
using namespace wxjs::gui;
/***
* <file>control/menubar</file>
* <module>gui</module>
* <class name="wxMenuBar">
* A menu bar is a series of menus accessible from the top of a frame.
* See @wxFrame#menuBar property, @wxMenu and @wxMenuItem.
* </class>
*/
WXJS_INIT_CLASS(MenuBar, "wxMenuBar", 0)
/***
* <properties>
* <property name="menuCount" type="Integer" readonly="Y">
* The number of menus
* </property>
* <property name="menus" type="Array" readonly="Y">
* Returns all the menus belonging to the menubar.
* </property>
* </properties>
*/
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<JavaScriptClientData*>(p->GetMenu(i));
if ( data != NULL )
{
jsval element = OBJECT_TO_JSVAL(data->GetObject());
JS_SetElement(cx, objMenus, i++, &element);
}
}
break;
}
}
return true;
}
/***
* <constants>
* <type name="Styles">
* <constant name="DOCKABLE">(wxGTK only)</constant>
* </type>
* </constants>
*/
WXJS_BEGIN_CONSTANT_MAP(MenuBar)
// Style constants
WXJS_CONSTANT(wxMB_, DOCKABLE)
WXJS_END_CONSTANT_MAP()
/***
* <ctor>
* <function>
* <arg name="Style" type="Integer" default="0" />
* </function>
* <desc>
* Constructs a new wxMenuBar object.
* </desc>
* </ctor>
*/
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()
/***
* <method name="append">
* <function>
* <arg name="Menu" type="@wxMenu" />
* <arg name="Name" type="String" />
* </function>
* <desc>
* Adds the menu to the menubar
* </desc>
* </method>
*/
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;
}
/***
* <method name="check">
* <function>
* <arg name="Id" type="Integer">
* The menu item identifier
* </arg>
* <arg name="Switch" type="Boolean">
* If true, checks the menu item, otherwise the item is unchecked
* </arg>
* </function>
* <desc>
* 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.
* </desc>
* </method>
*/
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;
}
/***
* <method name="enable">
* <function>
* <arg name="Id" type="Integer">
* The menu item identifier
* </arg>
* <arg name="Switch" type="Boolean">
* If true, enables the menu item, otherwise the item is disabled
* </arg>
* </function>
* <desc>
* 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.
* </desc>
* </method>
*/
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;
}
/***
* <method name="enableTop">
* <function>
* <arg name="Pos" type="Integer">
* The position of the menu, starting from zero
* </arg>
* <arg name="Switch" type="Boolean">
* If true, enables the menu, otherwise the menu is disabled
* </arg>
* </function>
* <desc>
* Enables or disables a whole menu.
* Only use this when the menu bar has been associated with a @wxFrame.
* </desc>
* </method>
*/
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;
}
/***
* <method name="findMenu">
* <function returns="Integer">
* <arg name="Name" type="String">
* The name of the menu
* </arg>
* </function>
* <desc>
* Returns the index of the menu with the given name. -1
* is returned when the menu is not found.
* </desc>
* </method>
*/
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;
}
/***
* <method name="findMenuItem">
* <function returns="Integer">
* <arg name="MenuName" type="String">
* The name of the menu
* </arg>
* <arg name="ItemName" type="String">
* The name of the menuitem.
* </arg>
* </function>
* <desc>
* Finds the menu item id for a menu name/menu item string pair.
* -1 is returned when nothing is found.
* </desc>
* </method>
*/
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;
}
/***
* <method name="getHelpString">
* <function returns="String">
* <arg name="Id" type="Integer">
* A menu item identifier.
* </arg>
* </function>
* <desc>
* 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.
* </desc>
* </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;
}
/***
* <method name="getLabel">
* <function returns="String">
* <arg name="Id" type="Integer">
* A menu item identifier.
* </arg>
* </function>
* <desc>
* 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.
* </desc>
* </method>
*/
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;
}
/***
* <method name="getLabelTop">
* <function returns="String">
* <arg name="Index" type="Integer">
* Position of the menu on the menu bar, starting from zero.
* </arg>
* </function>
* <desc>
* 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
* </desc>
* </method>
*/
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;
}
/***
* <method name="getMenu">
* <function returns="@wxMenu">
* <arg name="Index" type="Integer" />
* </function>
* <desc>
* Returns the @wxMenu at the given index (zero-indexed).
* </desc>
* </method>
*/
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<JavaScriptClientData*>(menu->GetClientObject());
if ( data != NULL )
{
*rval = OBJECT_TO_JSVAL(data->GetObject());
}
return JS_TRUE;
}
}
return JS_FALSE;
}
/***
* <method name="insert">
* <function returns="Boolean">
* <arg name="Pos" type="Integer">
* The position of the new menu in the menu bar
* </arg>
* <arg name="Menu" type="@wxMenu">
* The menu to add.
* </arg>
* <arg name="Title" type="String">
* The title of the menu.
* </arg>
* </function>
* <desc>
* 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.
* </desc>
* </method>
*/
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;
}
/***
* <method name="isChecked">
* <function returns="Boolean">
* <arg name="Id" type="Integer">
* A menu item identifier.
* </arg>
* </function>
* <desc>
* Returns true when the menu item is checked.
* See @wxMenu#check method, @wxMenu#isChecked and @wxMenuItem#check property.
* </desc>
* </method>
*/
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;
}
/***
* <method name="isEnabled">
* <function returns="Boolean">
* <arg name="Id" type="Integer">
* A menu item identifier.
* </arg>
* </function>
* <desc>
* Returns true when the menu item is enabled.
* @wxMenu#enable method, @wxMenuItem#enable property and @wxMenuBar#enable
* </desc>
* </method>
*/
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;
}
/***
* <method name="refresh">
* <function />
* <desc>
* Redraw the menu bar.
* </desc>
* </method>
*/
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;
}
/***
* <method name="remove">
* <function returns="Boolean">
* <arg name="Index" type="Integer">
* The index of the menu to remove (zero-indexed).
* </arg>
* </function>
* <desc>
* 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.
* </desc>
* </method>
*/
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<JavaScriptClientData*>(menu->GetClientObject());
if ( data != NULL )
*rval = OBJECT_TO_JSVAL(data->GetObject());
}
return JS_TRUE;
}
return JS_FALSE;
}
/***
* <method name="replace">
* <function returns="@wxMenu">
* <arg name="Index" type="Integer">
* The index of the menu to replace (zero-indexed).
* </arg>
* <arg name="Menu" type="@wxMenu">
* The new menu
* </arg>
* <arg name="Title" type="String">
* The title of the menu
* </arg>
* </function>
* <desc>
* Replaces the menu at the given position with the new one.
* </desc>
* </method>
*/
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<JavaScriptClientData*>(oldMenu->GetClientObject());
*rval = ( data == NULL ) ? JSVAL_VOID
: OBJECT_TO_JSVAL(data->GetObject());
}
return JS_TRUE;
}
/***
* <method name="setHelpString">
* <function>
* <arg name="Id" type="Integer">
* A menu item identifier.
* </arg>
* <arg name="Help" type="String">
* The help text
* </arg>
* </function>
* <desc>
* Sets the help associated with a menu item.
* See @wxMenuItem#help property, @wxMenu#setHelpString method
* </desc>
* </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;
}
/***
* <method name="setLabel">
* <function>
* <arg name="Id" type="Integer">
* A menu item identifier.
* </arg>
* <arg name="Label" type="String">
* A new label
* </arg>
* </function>
* <desc>
* Sets the label of a menu item.
* Only use this when the menubar is associated with a @wxFrame
* @wxMenuItem#label property, @wxMenu#setLabel method
* </desc>
* </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;
}
/***
* <method name="setLabelTop">
* <function>
* <arg name="Index" type="Integer">
* A menu index (zero-indexed)
* </arg>
* <arg name="Label" type="String">
* A label for a menu
* </arg>
* </function>
* <desc>
* Sets the label of a menu.
* Only use this when the menubar is associated with a @wxFrame
* See @wxMenu#title property
* </desc>
* </method>
*/
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;
}

Some files were not shown because too many files have changed in this diff Show More