1
0
forked from 0ad/0ad

Removing old wxJavaScript

This was SVN commit r5153.
This commit is contained in:
Ykkrosh 2007-06-08 22:15:11 +00:00
parent 4fbaea3780
commit d416b6ac83
341 changed files with 0 additions and 62458 deletions

View File

@ -1,15 +0,0 @@
Based on wxJavaScript 0.9.6, with some modifications:
Added #include "precompiled.h" to every .cpp file
Changed #include <jsapi.h> into #include <js/jsapi.h>
Renamed io/{init,constant}.cpp to io/io_{init,constant}.cpp (to prevent naming conflicts when we compile everything together)
Renamed ext/main.cpp to ext/ext_main.cpp
Removed wxGlobalMap from io/io_constant.cpp
Removed everything except wxjs::ext:: definitions from ext/main.cpp
Fixed warnings from common/apiwrap.h
Fixed bugs:
http://sourceforge.net/tracker/index.php?func=detail&aid=1730754&group_id=50913&atid=461416
http://sourceforge.net/tracker/index.php?func=detail&aid=1730960&group_id=50913&atid=461416

View File

@ -1,703 +0,0 @@
/*
* 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 634 2007-03-24 22:34:20Z fbraem $
*/
/////////////////////////////////////////////////////////////////////////////
// Name: apiwrap.h
// Purpose: Templates for reducing code in ported classes.
// It tries to hide the complexity of porting classes as much
// as possible.
// Author: Franky Braem
// Modified by:
// Created: 30.08.02
// Copyright: (c) 2001-2002 Franky Braem
// Licence: LGPL
//
// 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;
}
}
#ifdef JS_THREADSAFE
JSClass *clazz = JS_GetClass(cx, obj);
#else
JSClass *clazz = JS_GetClass(obj);
#endif
while((clazz->flags & JSCLASS_HAS_PRIVATE) != JSCLASS_HAS_PRIVATE)
{
obj = JS_GetPrototype(cx, obj);
if ( obj == NULL )
return NULL;
#ifdef JS_THREADSAFE
clazz = JS_GetClass(cx, obj);
#else
clazz = JS_GetClass(obj);
#endif
}
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)
{
if ( JSVAL_IS_OBJECT(v) )
return HasPrototype(cx, JSVAL_TO_OBJECT(v));
else
return 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;
}
/**
* 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 *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 *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 <I>argc</I> is greater
* then this value, you know there are optional values passed.
* You can use the WXJS_INIT_CLASS macro, to initialize this.
* @endif
*/
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;
}
/**
* 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);
}
}
};
}; // namespace wxjs
// 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,
JS_PropertyStub,
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 } \
}; \
JS_DefineConstDoubles(cx, obj, consts); \
}
// Defines a constant with a prefix
#define WXJS_CONSTANT(prefix, name) { prefix##name, #name, WXJS_READONLY },
// Defines a constant
#define WXJS_SIMPLE_CONSTANT(name) { name, #name, WXJS_READONLY },
// 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 },
#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

@ -1,38 +0,0 @@
/*
* 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 598 2007-03-07 20:13:28Z fbraem $
*/
#ifndef _wxjs_defs_h
#define _wxjs_defs_h
#define wxJS_MAJOR_VERSION 0
#define wxJS_MINOR_VERSION 9
#define wxJS_RELEASE_NUMBER 6
#define wxJS_STR_VERSION wxT("0.9.6")
// 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

@ -1,78 +0,0 @@
/*
* 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 598 2007-03-07 20:13:28Z fbraem $
*/
#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);
typedef std::map<wxString, ConnectEventFn> ConnectEventMap;
protected:
static bool ConnectEvent(T_Priv *p, const wxString &name)
{
#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);
return true;
}
return false;
}
static ConnectEventMap m_eventMap;
};
} // end namespace wxjs
// Some macro's
#if (__GNUC__ >= 4)
#define WXJS_INIT_EVT_CONNECTOR_MAP(priv) template <> EventConnector<priv>::ConnectEventMap EventConnector<priv>::m_eventMap = EventConnector< priv >::ConnectEventMap();
#else
#define WXJS_INIT_EVT_CONNECTOR_MAP(priv) EventConnector<priv>::ConnectEventMap EventConnector<priv>::m_eventMap;
#endif
#define WXJS_BEGIN_EVT_CONNECTOR_MAP(cl) \
void cl::InitConnectEventMap() \
{
#define WXJS_EVT_CONNECTOR(name, fun) m_eventMap[name] = fun;
#define WXJS_END_EVT_CONNECTOR_MAP() }
#endif // _wxjs_evt_conn_h

View File

@ -1,62 +0,0 @@
/*
* 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

@ -1,122 +0,0 @@
#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

@ -1,46 +0,0 @@
/*
* 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

@ -1,55 +0,0 @@
/*
* 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 598 2007-03-07 20:13:28Z fbraem $
*/
/////////////////////////////////////////////////////////////////////////////
// Name: main.h
// Purpose: Global definitions for wxJS
// Author: Franky Braem
// Modified by:
// Created: 18.01.02
// Copyright: (c) 2001-2002 Franky Braem
// Licence: LGPL
/////////////////////////////////////////////////////////////////////////////
#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 "object.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

@ -1,42 +0,0 @@
#include "precompiled.h"
/*
* wxJavaScript - object.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: object.cpp 598 2007-03-07 20:13:28Z fbraem $
*/
// object.cpp
#include <js/jsapi.h>
#include "object.h"
wxjs::Object::Object(JSObject *obj, JSContext *cx) : m_obj(obj), m_cx(cx)
{
}
wxjs::Object::Object(const wxjs::Object &copy) : m_obj(copy.m_obj), m_cx(copy.m_cx)
{
}
wxjs::Object::~Object()
{
}

View File

@ -1,89 +0,0 @@
/*
* wxJavaScript - object.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: object.h 598 2007-03-07 20:13:28Z fbraem $
*/
/**
* (c) 2001-2002 Franky Braem (S.A.W.)
*
* This file is part of wxJS. wxJS ports wxWindows to JavaScript
*
* File : object.h
* Desc. : Keeps a pointer to the associated JSObject.
* Created : 06-01-2002
*/
#ifndef _Object_H
#define _Object_H
namespace wxjs
{
class Object
{
public:
/**
* Constructor
*/
Object() : m_obj(NULL), m_cx(NULL)
{
}
Object(JSObject *obj, JSContext *cx);
Object(const Object &copy);
/**
* Destructor
*/
virtual ~Object();
/**
* Returns the JavaScript object
*/
inline JSObject* GetObject() const
{
return m_obj;
}
inline JSContext *GetContext() const
{
return m_cx;
}
inline void SetObject(JSObject *obj)
{
m_obj = obj;
}
private:
// The actual JSObject. We don't have to root this
// because it is stored in the private data of the JSObject.
// The private data will only be destroyed together with the object
// when it is garbage collected.
JSObject *m_obj;
JSContext *m_cx;
};
}; // namespace wxjs
#endif

View File

@ -1,97 +0,0 @@
/*
* 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

@ -1,349 +0,0 @@
#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

@ -1,113 +0,0 @@
/*
* 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

@ -1,38 +0,0 @@
/*
* 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

@ -1,92 +0,0 @@
#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;
#if 0
#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()
{
}
#endif
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

@ -1,323 +0,0 @@
#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 598 2007-03-07 20:13:28Z 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);
}
wxMemoryBuffer *buffer = new wxMemoryBuffer();
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

@ -1,68 +0,0 @@
/*
* 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

@ -1,383 +0,0 @@
#include "precompiled.h"
/*
* wxJavaScript - membuf.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: membuf.cpp 598 2007-03-07 20:13:28Z fbraem $
*/
#include "membuf.h"
// 09/14/2005: Initialize the global null memory buffer pointers
unsigned char MemoryBufferNULLPtr::MemoryBufferNUllChar = '\0';
unsigned char MemoryBufferNULLPtr::MemoryBufferNUllBuf[1] = { '\0' };
MemoryBuffer::MemoryBuffer(const void *buf, __MEMBUF_INT__ bytes)
{
mptr = 0;
l_length = d_length = 0;
// PC-lint 09/14/2005: Possibly passing a null pointer
if(buf) {
if(Alloc(bytes)) {
if(mptr) {
memmove(mptr, buf, bytes);
}
}
}
}
MemoryBuffer::MemoryBuffer(const MemoryBuffer &buf)
{
mptr = 0;
l_length = d_length = 0;
// PC-lint 09/14/2005: Possibly passing a null pointer
if(buf.mptr) {
if(Alloc(buf.l_length)) {
if(mptr) {
memmove(mptr, buf.mptr, buf.l_length);
}
}
}
}
MemoryBuffer &MemoryBuffer::operator=(const MemoryBuffer &buf)
{
if(this != &buf) { // Prevent self assignment
if(Alloc(buf.l_length)) {
// PC-lint 09/14/2005: Possible use of null pointer
if(!mptr) return *this;
memmove(mptr, buf.mptr, buf.l_length);
}
}
return *this;
}
void *MemoryBuffer::Alloc(__MEMBUF_INT__ bytes)
// Allocate a specified number of bytes for this memory buffer.
// This function will try to re-use the current memory segment
// allocated for this buffer before re-allocating memory for
// the buffer. Returns a void pointer to the buffer or a null
// value if a memory allocation error occurs.
{
if(mptr) { // Memory was previously allocated for this object
if(d_length >= bytes) { // Try to reuse this space
l_length = bytes;
return (void *)mptr;
}
else { // Must resize the buffer
delete[] mptr;// Delete the previous copy and re-allocate memory
l_length = d_length = 0;
}
}
// Allocate the specified number of bytes
mptr = new unsigned char[bytes];
if(!mptr) return 0; // Memory allocation error
// Set the logical and dimensioned length of the buffer
l_length = d_length = bytes;
return (void *)mptr; // Return a pointer to the buffer
}
void *MemoryBuffer::Realloc(__MEMBUF_INT__ bytes, int keep, int reuse)
// Resize the logical length of the buffer. If the
// "keep" variable is true the old data will be
// copied into the new space. By default the old
// data will not be deleted. Returns a pointer to the
// buffer or a null value if an error occurs.
{
// Try to reuse the memory allocated for this object
if((reuse == 1) && (mptr != 0)) {
if(d_length >= bytes) { // No additional memory has to be allocated
l_length = bytes;
return (void *)mptr;
}
}
unsigned char *nmptr = new unsigned char[bytes];
if(!nmptr) return 0;
if((keep == 1) && (mptr != 0)) { // Copy old data into the new memory segment
if(bytes < l_length) l_length = bytes;
memmove(nmptr, mptr, l_length);
}
if(mptr) delete[] mptr; // Free the previously allocated memory
mptr = nmptr; // Point to new memory buffer
l_length = d_length = bytes; // Record new allocated length
return (void *)mptr;
}
void MemoryBuffer::Destroy()
// Frees the memory allocated for the buffer and resets the
// length variables.
{
if(mptr) delete[] mptr;
mptr = 0;
l_length = d_length = 0;
}
void *MemoryBuffer::FreeBytes()
// Free any unused bytes allocated for this buffer. Returns
// a pointer to the re-allocated memory buffer or a null
// value if an error occurs.
{
// Check for unused bytes
if(d_length == l_length) return (void *)mptr;
return Realloc(l_length, 1, 0);
}
int MemoryBuffer::resize(__MEMBUF_INT__ bytes, int keep)
// Resize the logical length of the buffer. If the
// "keep" variable is true the old data will be
// copied into the new space. By default the old
// data will not be deleted. Returns true if
// successful or false if an error occurs.
{
if(!Realloc(bytes, keep)) return 0;
return 1;
}
__MEMBUF_INT__ MemoryBuffer::Find(void *buf, __MEMBUF_INT__ offset)
// Returns index of first occurrence of pattern void *buf.
// Returns __MEMBUF_NO_MATCH__ if the pattern is not found.
{
// PC-lint 09/14/2005: Possible use of null pointer
if(!mptr) return __MEMBUF_NO_MATCH__;
unsigned char *start = mptr + offset; // Start of buffer data
unsigned char *next = start; // Next buffer element
unsigned char *pattern = (unsigned char *)buf; // Next pattern element
__MEMBUF_INT__ i = offset; // Next buffer element index
while(i < l_length && *pattern) {
if (*next == *pattern) {
pattern++;
if(*pattern == 0) return i; // Pattern was found
next++;
}
else {
i++;
start++;
next = start;
pattern = (unsigned char *)buf;
}
}
return __MEMBUF_NO_MATCH__; // No match was found
}
__MEMBUF_INT__ MemoryBuffer::Find(const void *buf, __MEMBUF_INT__ bytes,
__MEMBUF_INT__ offset) const
// Returns index of first occurrence of pattern void *buf.
// Returns __MEMBUF_NO_MATCH__ if the pattern is not found.
{
// PC-lint 09/14/2005: Possible use of null pointer
if(!mptr) return __MEMBUF_NO_MATCH__;
unsigned char *start = (unsigned char *)mptr + offset; // Start of buf data
unsigned char *next = start; // Next buffer element
unsigned char *pattern = (unsigned char *)buf; // Next pattern element
__MEMBUF_INT__ i = offset, j = 1; // Buffer and pattern indexes
while(i < l_length && j <= bytes) {
if (*next == *pattern) { // Matching character
if(j == bytes) return i; // Entire match was found
next++; pattern++; j++;
}
else { // Try next spot in buffer
i++;
start++;
next = start;
pattern = (unsigned char *)buf; j = 1;
}
}
return __MEMBUF_NO_MATCH__; // No match was found
}
__MEMBUF_INT__ MemoryBuffer::DeleteAt(__MEMBUF_INT__ position,
__MEMBUF_INT__ bytes)
{
__MEMBUF_INT__ buf;
__MEMBUF_INT__ end;
if(position < l_length && bytes !=0) {
buf = position + bytes;
if(buf > l_length) buf = l_length;
end = unsigned(buf);
bytes = end - position;
// PC-lint 09/14/2005: Possible use of null pointer
if(!mptr) return (__MEMBUF_INT__)0;
memmove(mptr+position, mptr+end, l_length-end);
l_length -= bytes;
}
else
bytes = 0;
return bytes;
}
__MEMBUF_INT__ MemoryBuffer::InsertAt(__MEMBUF_INT__ position, const void *buf,
__MEMBUF_INT__ bytes)
// Insert a specified number of bytes a the current position, keeping
// the current buffer intact. Returns the number of bytes inserted or
// zero if an error occurs.
{
__MEMBUF_INT__ old_length = l_length; // Record the current buffer length
// Ensure that there are enough bytes to hold the insertion
if(!resize(bytes+l_length)) return 0;
// PC-lint 09/14/2005: Possible use of null pointer
if(!mptr) return (__MEMBUF_INT__)0;
if(position < old_length) { // Move the data in the middle of the buffer
memmove(mptr+position+bytes, mptr+position, old_length-position);
}
if(position > l_length) position = l_length; // Stay in bounds
memmove(mptr+position, buf, bytes);
return bytes;
}
__MEMBUF_INT__ MemoryBuffer::ReplaceAt(__MEMBUF_INT__ position,
const void *buf,
__MEMBUF_INT__ bytes)
// Replace a specified number of bytes at the specified position. Returns
// the number of bytes replaced or zero if an error occurs.
{
if(position > l_length) position = l_length; // Stay in bounds
__MEMBUF_INT__ end = l_length-position;
if(bytes > end) { // There are not enough bytes to hold the replacement
__MEMBUF_INT__ needed = bytes-end;
if(!resize(l_length + needed)) return 0;
}
// PC-lint 09/14/2005: Possible use of null pointer
if(!mptr) return (__MEMBUF_INT__)0;
memmove(mptr+position, buf , bytes);
return bytes;
}
int BufferCompare(const MemoryBuffer &a, const MemoryBuffer &b)
// Returns -1 if a < b, 0 if a == b, and 1 if a > b
{
__MEMBUF_INT__ an = a.l_length;
__MEMBUF_INT__ bn = b.l_length;
__MEMBUF_INT__ sn = (an < bn) ? an : bn;
unsigned char *ap = (unsigned char *)a.mptr;
unsigned char *bp = (unsigned char *)b.mptr;
for(__MEMBUF_INT__ i = 0; i < sn; i++) {
if(*ap < *bp) return -1;
if(*ap++ > *bp++) return 1;
}
if(an == bn) return 0;
if(an < bn) return -1;
return 1;
}
int MemoryBuffer::Load(const void *buf, __MEMBUF_INT__ bytes)
// Load this object with a unique copy of the specified buffer.
// Returns true if successful or false if an error occurs.
{
if(!mptr) { // Ensure that this buffer has been initialized
if(!Alloc(bytes)) return 0;
}
if(d_length < bytes) { // Ensure enough byte have been allocated
if(!Realloc(bytes, 0, 0)) return 0;
}
else { // Reuse the current memory segment
l_length = bytes;
}
// PC-lint 09/14/2005: Possible use of null pointer
if(!mptr) return 0;
memmove(mptr, (unsigned char *)buf, l_length);
return 1;
}
void MemoryBuffer::Clear(int clean_buf)
// Clear the buffer. If the "clean_buf" variable is
// true the contents of the buffer will be cleared,
// otherwise the logical length will be set to
// zero and the contents of the buffer will not
// cleared.
{
if(l_length > 0) {
if(clean_buf) DeleteAt(0, l_length);
}
l_length = 0;
}
int MemoryBuffer::MemSet(const char c, __MEMBUF_INT__ offset,
__MEMBUF_INT__ num)
// Public member function used to fill the memory buffer
// starting at the specified offset. Returns false if the
// buffer is null or the offset is out of range. The "num"
// variable is used to limit fills to a specified number
// of bytes.
{
if(is_null()) return 0; // This buffer is null
// PC-lint 09/14/2005: Possible use of null pointer
if(!mptr) return 0;
// Test the offset before filling the memory buffer
if((offset + num) > d_length) return 0;
unsigned char *ptr = mptr+offset;
__MEMBUF_INT__ pos = d_length - offset;
for(__MEMBUF_INT__ i = 0; i < pos; i++) {
if((num > 0) && (num == i)) break;
*ptr++ = c;
}
return 1;
}
MemoryBuffer operator+(const MemoryBuffer &a,
const MemoryBuffer &b)
{
MemoryBuffer buf(a.l_length + b.l_length);
buf += a;
buf += b;
return buf;
}
unsigned char &MemoryBuffer::operator[](__MEMBUF_INT__ i)
{
// PC-lint 09/14/2005: Possible use of null pointer
if(!mptr) return MemoryBufferNULLPtr::MemoryBufferNUllChar;
if(i >= l_length) i = l_length; // If not in bounds truncate to l_length
return mptr[i];
}
unsigned char &MemoryBuffer::operator[](__MEMBUF_INT__ i) const
{
// PC-lint 09/14/2005: Possible use of null pointer
if(!mptr) return MemoryBufferNULLPtr::MemoryBufferNUllChar;
if(i >= l_length) i = l_length; // If not in bounds truncate to l_length
return mptr[i];
}

View File

@ -1,169 +0,0 @@
/*
* wxJavaScript - membuf.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: membuf.h 598 2007-03-07 20:13:28Z fbraem $
*/
#ifndef __MEMBUF_H__
#define __MEMBUF_H__
#include <string>
typedef unsigned __MEMBUF_INT__; // Buffer size for 32-bit compilers
const __MEMBUF_INT__ __MEMBUF_NO_MATCH__ = 0xFFFFFFFF;
// 09/14/2005: Added null buffer class used to reserve address space
// for null memory buffers
class MemoryBufferNULLPtr
{
public:
MemoryBufferNULLPtr() { }
~MemoryBufferNULLPtr() { }
public: // Global null memory buffer pointers
static unsigned char MemoryBufferNUllChar;
static unsigned char MemoryBufferNUllBuf[1];
};
// Memory buffer class
class MemoryBuffer
{
public:
MemoryBuffer() { mptr = 0; l_length = d_length = 0; }
MemoryBuffer(__MEMBUF_INT__ bytes) {
mptr = 0; l_length = d_length = 0; Alloc(bytes);
}
MemoryBuffer(const void *buf, __MEMBUF_INT__ bytes);
~MemoryBuffer() { if(mptr) delete mptr; }
MemoryBuffer(const MemoryBuffer &buf);
MemoryBuffer &operator=(const MemoryBuffer &buf);
public: // Pointer and length functions
__MEMBUF_INT__ length() const { return l_length; } // Returns logical length
__MEMBUF_INT__ dlength() const { return d_length; } // Returns actual length
int resize(__MEMBUF_INT__ bytes, int keep = 1);
unsigned char *m_buf() { return mptr; }
const unsigned char *m_buf() const { return mptr; }
int is_null() { return ((mptr == 0) || (l_length == 0)); }
int is_null() const { return ((mptr == 0) || (l_length == 0)); }
int Load(const void *buf, __MEMBUF_INT__ bytes);
void Clear(int clean_buf = 1);
int MemSet(const char c, __MEMBUF_INT__ offset = 0, __MEMBUF_INT__ num = 0);
std::string toString() { return std::string((char *) mptr, l_length); }
public: // Append, Insert, delete, and remove functions
void Cat(const void *buf, __MEMBUF_INT__ bytes) {
InsertAt(l_length, buf, bytes);
}
void Cat(unsigned char byte) { Cat((void *)&byte, 1); }
void Cat(char byte) { Cat((void *)&byte, 1); }
__MEMBUF_INT__ DeleteAt(__MEMBUF_INT__ position, __MEMBUF_INT__ bytes);
__MEMBUF_INT__ InsertAt(__MEMBUF_INT__ position, const void *buf,
__MEMBUF_INT__ bytes);
__MEMBUF_INT__ InsertAt(__MEMBUF_INT__ position, const MemoryBuffer &buf) {
return InsertAt(position, (const void *)buf.mptr, buf.l_length);
}
__MEMBUF_INT__ ReplaceAt(__MEMBUF_INT__ position, const void *buf,
__MEMBUF_INT__ bytes);
__MEMBUF_INT__ ReplaceAt(__MEMBUF_INT__ position, const MemoryBuffer &buf) {
return ReplaceAt(position, (const void *)buf.mptr, buf.l_length);
}
public: // Search functions
__MEMBUF_INT__ Find(void *buf, __MEMBUF_INT__ offset = 0);
__MEMBUF_INT__ Find(const void *buf, __MEMBUF_INT__ bytes,
__MEMBUF_INT__ offset = 0) const;
__MEMBUF_INT__ Find(MemoryBuffer &buf,
__MEMBUF_INT__ offset = 0) {
return Find(buf.mptr, buf.l_length, offset);
}
__MEMBUF_INT__ Find(const MemoryBuffer &buf,
__MEMBUF_INT__ offset = 0) const {
return Find(buf.mptr, buf.l_length, offset);
}
public: // Memory allocation/de-allocation routines
void *Alloc(__MEMBUF_INT__ bytes);
void *Realloc(__MEMBUF_INT__ bytes, int keep = 1, int reuse = 1);
void Destroy();
void *FreeBytes();
public: // Conversion functions
operator char *() const { return (char *)mptr; }
operator const char *() const { return (const char*)mptr; }
operator const int () const { return ((mptr != 0) && (l_length != 0)); }
operator int () { return ((mptr != 0) && (l_length != 0)); }
public: // Overloaded operators
int operator!() { return ((mptr == 0) || (l_length == 0)); }
int operator!() const { return ((mptr == 0) || (l_length == 0)); }
unsigned char &operator[](__MEMBUF_INT__ i);
unsigned char &operator[](__MEMBUF_INT__ i) const;
void operator+=(const MemoryBuffer &buf) { Cat(buf.mptr, buf.l_length); }
void operator+=(const unsigned char &byte) { Cat(byte); }
void operator+=(const char &byte) { Cat(byte); }
friend MemoryBuffer operator+(const MemoryBuffer &a,
const MemoryBuffer &b);
friend int operator==(const MemoryBuffer &a,
const MemoryBuffer &b) {
return BufferCompare(a, b) == 0;
}
friend int operator!=(const MemoryBuffer &a,
const MemoryBuffer &b) {
return BufferCompare(a, b) != 0;
}
friend int operator>(const MemoryBuffer &a,
const MemoryBuffer &b) {
return BufferCompare(a, b) > 0;
}
friend int operator>=(const MemoryBuffer &a,
const MemoryBuffer &b) {
return BufferCompare(a, b) >= 0;
}
friend int operator<(const MemoryBuffer &a,
const MemoryBuffer &b) {
return BufferCompare(a, b) < 0;
}
friend int operator<=(const MemoryBuffer &a,
const MemoryBuffer &b) {
return BufferCompare(a, b) <= 0;
}
public: // Friend functions
// Returns -1 if a < b, 0 if a == b, and 1 if a > b
friend int BufferCompare(const MemoryBuffer &a,
const MemoryBuffer &b);
private:
unsigned char *mptr; // Pointer to start of buffer
__MEMBUF_INT__ d_length; // Number of bytes allocated for the buffer
__MEMBUF_INT__ l_length; // Logical length of the buffer
};
#endif // __MEMBUF_H__

View File

@ -1,52 +0,0 @@
/*
* 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

@ -1,221 +0,0 @@
#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 598 2007-03-07 20:13:28Z 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 "../event/evthand.h"
#include "../event/jsevent.h"
#include "../event/command.h"
#include "../misc/size.h"
#include "../misc/point.h"
#include "bmpbtn.h"
#include "../misc/bitmap.h"
#include "window.h"
using namespace wxjs;
using namespace wxjs::gui;
WXJS_INIT_CLASS(BitmapButton, "wxBitmapButton", 3)
BitmapButton::BitmapButton(JSContext *cx, JSObject *obj)
: wxBitmapButton()
, Object(obj, cx)
{
PushEventHandler(new EventHandler(this));
}
BitmapButton::~BitmapButton()
{
PopEventHandler(true);
}
/***
* <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 *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 *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;
}
/***
* <ctor>
* <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 constructing)
{
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) )
break;
// Walk through
case 5:
size = Size::GetPrivate(cx, argv[4]);
if ( size == NULL )
break;
// Walk through
case 4:
pt = Point::GetPrivate(cx, argv[3]);
if ( pt == NULL )
break;
// Walk through
default:
wxBitmap *bmp = Bitmap::GetPrivate(cx, argv[2]);
if ( bmp == NULL )
break;
int id;
if ( ! FromJS(cx, argv[1], id) )
break;
wxWindow *parent = Window::GetPrivate(cx, argv[0]);
if ( parent == NULL )
return NULL;
Object *wxjsParent = dynamic_cast<Object *>(parent);
JS_SetParent(cx, obj, wxjsParent->GetObject());
BitmapButton *p = new BitmapButton(cx, obj);
p->Create(parent, id, *bmp, *pt, *size, style);
return p;
}
return NULL;
}
/***
* <events>
* <event name="onClicked">
* This event is triggered when the button is clicked. The function receives
* a @wxCommandEvent as argument.
* </event>
* </events>
*/
void BitmapButton::OnClicked(wxCommandEvent &event)
{
PrivCommandEvent::Fire<CommandEvent>(this, event, "onClicked");
}
BEGIN_EVENT_TABLE(BitmapButton, wxBitmapButton)
EVT_BUTTON(-1, BitmapButton::OnClicked)
END_EVENT_TABLE()

View File

@ -1,85 +0,0 @@
/*
* 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 598 2007-03-07 20:13:28Z fbraem $
*/
#ifndef _WXJSBitmapButton_H
#define _WXJSBitmapButton_H
/////////////////////////////////////////////////////////////////////////////
// Name: bmpbtn.h
// Purpose: BitmapButton ports wxBitmapButton to JavaScript.
// Author: Franky Braem
// Modified by:
// Created: 01.08.02
// Copyright: (c) 2001-2002 Franky Braem
// Licence: LGPL
/////////////////////////////////////////////////////////////////////////////
namespace wxjs
{
namespace gui
{
class BitmapButton : public wxBitmapButton
, public ApiWrapper<BitmapButton, wxBitmapButton>
, public Object
{
public:
/**
* Constructor
*/
BitmapButton(JSContext *cx, JSObject *obj);
/**
* Destructor
*/
virtual ~BitmapButton();
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);
// Empty to avoid deleting. (It will be deleted by wxWindows).
static void Destruct(JSContext *cx, wxBitmapButton *p)
{
}
WXJS_DECLARE_PROPERTY_MAP()
/**
* Property Ids.
*/
enum
{
P_BITMAP_DISABLED
, P_BITMAP_FOCUS
, P_BITMAP_SELECTED
, P_BITMAP_LABEL
};
void OnClicked(wxCommandEvent &event);
DECLARE_EVENT_TABLE()
};
}; // namespace gui
}; //namespace wxjs
#endif //_WXJSBitmapButton_H

View File

@ -1,267 +0,0 @@
#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 598 2007-03-07 20:13:28Z fbraem $
*/
// button.cpp
/***
* <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>
* </class>
*/
#ifndef WX_PRECOMP
#include <wx/wx.h>
#endif
#include "../../common/main.h"
#include "../event/evthand.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"
using namespace wxjs;
using namespace wxjs::gui;
WXJS_INIT_CLASS(Button, "wxButton", 3)
/***
* <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 *obj, int id, jsval *vp)
{
if ( id == P_LABEL )
*vp = ToJS(cx, p->GetLabel());
return true;
}
bool Button::SetProperty(wxButton *p, JSContext *cx, JSObject *obj, int id, jsval *vp)
{
if ( id == P_LABEL )
{
wxString label;
FromJS(cx, *vp, label);
p->SetLabel(label);
}
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()
WXJS_BEGIN_METHOD_MAP(Button)
WXJS_METHOD("setDefault", setDefault, 0)
WXJS_END_METHOD_MAP()
Button::Button(JSContext *cx, JSObject *obj)
: wxButton()
, Object(obj, cx)
{
PushEventHandler(new EventHandler(this));
}
Button::~Button()
{
PopEventHandler(true);
}
/***
* <ctor>
* <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 constructing)
{
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 )
break;
case 6:
if ( ! FromJS(cx, argv[5], style) )
break;
// Fall through
case 5:
size = Size::GetPrivate(cx, argv[4]);
if ( size == NULL )
break;
// Fall through
case 4:
pt = Point::GetPrivate(cx, argv[3]);
if ( pt == NULL )
break;
// Fall through
default:
wxString text;
FromJS(cx, argv[2], text);
int id;
if ( ! FromJS(cx, argv[1], id) )
break;
wxWindow *parent = Window::GetPrivate(cx, argv[0]);
if ( parent == NULL )
return NULL;
Object *wxjsParent = dynamic_cast<Object *>(parent);
JS_SetParent(cx, obj, wxjsParent->GetObject());
wxButton *p = new Button(cx, obj);
p->Create(parent, id, text, *pt, *size, style, *val);
return p;
}
return NULL;
}
/***
* <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 argc, jsval *argv, jsval *rval)
{
wxButton *p = GetPrivate(cx, obj);
if ( p == NULL )
return JS_FALSE;
p->SetDefault();
return JS_TRUE;
}
/***
* <event name="onClicked">
* Called when the button is clicked. The type of the argument that your handler receives
* is @wxCommandEvent.
* </event>
*/
void Button::OnClicked(wxCommandEvent &event)
{
PrivCommandEvent::Fire<CommandEvent>(this, event, "onClicked");
}
BEGIN_EVENT_TABLE(Button, wxButton)
EVT_BUTTON(-1, Button::OnClicked)
END_EVENT_TABLE()

View File

@ -1,96 +0,0 @@
/*
* 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 598 2007-03-07 20:13:28Z fbraem $
*/
#ifndef _WXJSButton_H
#define _WXJSButton_H
/////////////////////////////////////////////////////////////////////////////
// Name: button.h
// Purpose: wxJSButton ports wxButton to JavaScript.
// Author: Franky Braem
// Modified by:
// Created: 29.01.02
// Copyright: (c) 2001-2002 Franky Braem
// Licence: LGPL
/////////////////////////////////////////////////////////////////////////////
namespace wxjs
{
namespace gui
{
class Button : public wxButton
, public ApiWrapper<Button, wxButton>
, public Object
{
public:
/**
* Constructor
*/
Button(JSContext *cx, JSObject *obj);
/**
* Destructor
*/
virtual ~Button();
/**
* Callback for retrieving properties
*/
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);
/**
* Callback for retrieving static properties
*/
static bool GetStaticProperty(JSContext *cx, int id, jsval *vp);
/**
* Callback for when a wxButton object is created
*/
static wxButton *Construct(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, bool constructing);
// Empty to avoid deleting. (It will be deleted by wxWindows).
static void Destruct(JSContext *cx, wxButton *p)
{
}
static JSBool setDefault(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval);
WXJS_DECLARE_PROPERTY_MAP()
WXJS_DECLARE_STATIC_PROPERTY_MAP()
WXJS_DECLARE_CONSTANT_MAP()
WXJS_DECLARE_METHOD_MAP()
enum
{
P_LABEL
, P_DEFAULT_SIZE
};
void OnClicked(wxCommandEvent &event);
DECLARE_EVENT_TABLE()
};
}; // namespace gui
}; // namespace wxjs
#endif //_WXJSButton_H

View File

@ -1,284 +0,0 @@
#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 598 2007-03-07 20:13:28Z 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 *obj, uintN argc, jsval *argv, bool 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

@ -1,68 +0,0 @@
/*
* 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 598 2007-03-07 20:13:28Z 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()
/**
* Property Ids.
*/
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

@ -1,550 +0,0 @@
#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 598 2007-03-07 20:13:28Z 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/evthand.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"
using namespace wxjs;
using namespace wxjs::gui;
CalendarCtrl::CalendarCtrl(JSContext *cx, JSObject *obj)
: wxCalendarCtrl()
, Object(obj, cx)
{
PushEventHandler(new EventHandler(this));
}
CalendarCtrl::~CalendarCtrl()
{
PopEventHandler(true);
}
/***
* <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)
/***
* <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 *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;
}
/***
* <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>
* <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 constructing)
{
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) )
break;
// Fall through
case 5:
size = Size::GetPrivate(cx, argv[4]);
if ( size == NULL )
break;
// Fall through
case 4:
pt = Point::GetPrivate(cx, argv[3]);
if ( pt == NULL )
break;
// Fall through
case 3:
if ( ! FromJS(cx, argv[2], date) )
break;
// Fall through
default:
int id;
if ( ! FromJS(cx, argv[1], id) )
break;
wxWindow *parent = Window::GetPrivate(cx, argv[0]);
if ( parent == NULL )
break;
Object *wxjsParent = dynamic_cast<Object *>(parent);
JS_SetParent(cx, obj, wxjsParent->GetObject());
wxCalendarCtrl *p = new CalendarCtrl(cx, obj);
p->Create(parent, id, date, *pt, *size, style);
return p;
}
return NULL;
}
WXJS_BEGIN_METHOD_MAP(CalendarCtrl)
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="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 argc, jsval *argv, jsval *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 argc, jsval *argv, jsval *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 argc, jsval *argv, jsval *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 argc, jsval *argv, jsval *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;
}
/***
* <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 CalendarCtrl::OnCalendar(wxCalendarEvent &event)
{
PrivCalendarEvent::Fire<CalendarEvent>(this, event, "onCalendar");
}
void CalendarCtrl::OnCalendarSelChanged(wxCalendarEvent &event)
{
PrivCalendarEvent::Fire<CalendarEvent>(this, event, "onCalendarSelChanged");
}
void CalendarCtrl::OnCalendarDay(wxCalendarEvent &event)
{
PrivCalendarEvent::Fire<CalendarEvent>(this, event, "onCalendarDay");
}
void CalendarCtrl::OnCalendarMonth(wxCalendarEvent &event)
{
PrivCalendarEvent::Fire<CalendarEvent>(this, event, "onCalendarMonth");
}
void CalendarCtrl::OnCalendarYear(wxCalendarEvent &event)
{
PrivCalendarEvent::Fire<CalendarEvent>(this, event, "onCalendarYear");
}
void CalendarCtrl::OnCalendarWeekDayClicked(wxCalendarEvent &event)
{
PrivCalendarEvent::Fire<CalendarEvent>(this, event, "onCalendarWeekDayClicked");
}
BEGIN_EVENT_TABLE(CalendarCtrl, wxCalendarCtrl)
EVT_CALENDAR(-1, CalendarCtrl::OnCalendar)
EVT_CALENDAR_SEL_CHANGED(-1, CalendarCtrl::OnCalendarSelChanged)
EVT_CALENDAR_DAY(-1, CalendarCtrl::OnCalendarDay)
EVT_CALENDAR_MONTH(-1, CalendarCtrl::OnCalendarMonth)
EVT_CALENDAR_YEAR(-1, CalendarCtrl::OnCalendarYear)
EVT_CALENDAR_WEEKDAY_CLICKED(-1, CalendarCtrl::OnCalendarWeekDayClicked)
END_EVENT_TABLE()

View File

@ -1,107 +0,0 @@
/*
* 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 598 2007-03-07 20:13:28Z fbraem $
*/
#ifndef _WXJSCalendarCtrl_H
#define _WXJSCalendarCtrl_H
/////////////////////////////////////////////////////////////////////////////
// Name: calendar.h
// Purpose: CalendarCtrl ports wxCalendar to JavaScript.
// Author: Franky Braem
// Modified by:
// Created: 02.07.02
// Copyright: (c) 2001-2002 Franky Braem
// Licence: LGPL
/////////////////////////////////////////////////////////////////////////////
namespace wxjs
{
namespace gui
{
class CalendarCtrl : public wxCalendarCtrl
, public ApiWrapper<CalendarCtrl, wxCalendarCtrl>
, public Object
{
public:
/**
* Constructor
*/
CalendarCtrl(JSContext *cx, JSObject *obj);
/**
* Destructor
*/
virtual ~CalendarCtrl();
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);
// Empty to avoid deleting. (It will be deleted by wxWindows).
static void Destruct(JSContext *cx, wxCalendarCtrl *p)
{
}
static JSBool setDateRange(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval);
static JSBool setHeaderColours(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval);
static JSBool setHighlightColours(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval);
static JSBool setHolidayColours(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval);
WXJS_DECLARE_PROPERTY_MAP()
WXJS_DECLARE_CONSTANT_MAP()
WXJS_DECLARE_METHOD_MAP()
/**
* Property Ids.
*/
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
};
DECLARE_EVENT_TABLE()
void OnCalendar(wxCalendarEvent &event);
void OnCalendarSelChanged(wxCalendarEvent &event);
void OnCalendarDay(wxCalendarEvent &event);
void OnCalendarMonth(wxCalendarEvent &event);
void OnCalendarYear(wxCalendarEvent &event);
void OnCalendarWeekDayClicked(wxCalendarEvent &event);
};
}; // namespace gui
}; // namespace wxjs
#endif //_WXJSCalendarCtrl_H

View File

@ -1,197 +0,0 @@
#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 598 2007-03-07 20:13:28Z fbraem $
*/
// checkbox.cpp
#ifndef WX_PRECOMP
#include <wx/wx.h>
#endif
#include "../../common/main.h"
#include "../event/evthand.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"
using namespace wxjs;
using namespace wxjs::gui;
CheckBox::CheckBox(JSContext *cx, JSObject *obj)
: wxCheckBox()
, Object(obj, cx)
{
PushEventHandler(new EventHandler(this));
}
CheckBox::~CheckBox()
{
PopEventHandler(true);
}
/***
* <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)
/***
* <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 *obj, int id, jsval *vp)
{
if ( id == P_VALUE )
{
*vp = ToJS(cx, p->GetValue());
}
return true;
}
bool CheckBox::SetProperty(wxCheckBox *p, JSContext *cx, JSObject *obj, int id, jsval *vp)
{
if (id == P_VALUE )
{
bool value;
if ( FromJS(cx, *vp, value) )
p->SetValue(value);
}
return true;
}
/***
* <ctor>
* <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 constructing)
{
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 )
break;
case 6:
if ( ! FromJS(cx, argv[5], style) )
break;
// Fall through
case 5:
size = Size::GetPrivate(cx, argv[4]);
if ( size == NULL )
break;
// Fall through
case 4:
pt = Point::GetPrivate(cx, argv[3]);
if ( pt == NULL )
break;
// Fall through
default:
wxString text;
FromJS(cx, argv[2], text);
int id;
if ( ! FromJS(cx, argv[1], id) )
break;
wxWindow *parent = Window::GetPrivate(cx, argv[0]);
if ( parent == NULL )
break;
Object *wxjsParent = dynamic_cast<Object *>(parent);
JS_SetParent(cx, obj, wxjsParent->GetObject());
CheckBox *p = new CheckBox(cx, obj);
p->Create(parent, id, text, *pt, *size, style, *val);
return p;
}
return NULL;
}
/***
* <events>
* <event name="onCheckBox">
* Called when the checkbox is clicked. The type of the argument that your handler receives
* is @wxCommandEvent.
* </event>
* </events>
*/
void CheckBox::OnCheckBox(wxCommandEvent &event)
{
PrivCommandEvent::Fire<CommandEvent>(this, event, "onCheckBox");
}
BEGIN_EVENT_TABLE(CheckBox, wxCheckBox)
EVT_CHECKBOX(-1, CheckBox::OnCheckBox)
END_EVENT_TABLE()

View File

@ -1,79 +0,0 @@
/*
* 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 598 2007-03-07 20:13:28Z fbraem $
*/
#ifndef _WXJSCheckBox_H
#define _WXJSCheckBox_H
/////////////////////////////////////////////////////////////////////////////
// Name: checkbox.h
// Purpose: CheckBox ports wxCheckBox to JavaScript.
// Author: Franky Braem
// Modified by:
// Created: 06.02.02
// Copyright: (c) 2001-2002 Franky Braem
// Licence: LGPL
/////////////////////////////////////////////////////////////////////////////
namespace wxjs
{
namespace gui
{
class CheckBox : public wxCheckBox
, public ApiWrapper<CheckBox, wxCheckBox>
, public Object
{
public:
/**
* Constructor
*/
CheckBox(JSContext *cx, JSObject *obj);
/**
* Destructor
*/
virtual ~CheckBox();
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);
// Empty to avoid deleting. (It will be deleted by wxWindows).
static void Destruct(JSContext *cx, wxCheckBox *p)
{
}
WXJS_DECLARE_PROPERTY_MAP()
enum
{
P_VALUE
};
DECLARE_EVENT_TABLE()
void OnCheckBox(wxCommandEvent &event);
};
}; // namespace gui
}; // namespace wxjs
#endif //_WXJSCheckBox_H

View File

@ -1,185 +0,0 @@
#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 598 2007-03-07 20:13:28Z fbraem $
*/
// chklstbx.cpp
#ifndef WX_PRECOMP
#include <wx/wx.h>
#endif
#include "../../common/main.h"
#include "../../common/strsptr.h"
#include "../../common/index.h"
#include "../event/evthand.h"
#include "../event/jsevent.h"
#include "../event/command.h"
#include "chklstbx.h"
#include "chklstbxchk.h"
#include "window.h"
#include "../misc/point.h"
#include "../misc/size.h"
#include "../misc/validate.h"
using namespace wxjs;
using namespace wxjs::gui;
CheckListBox::CheckListBox(JSContext *cx, JSObject *obj)
: wxCheckListBox()
, Object(obj, cx)
{
PushEventHandler(new EventHandler(this));
}
CheckListBox::~CheckListBox()
{
PopEventHandler(true);
}
/***
* <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)
/***
* <properties>
* <property name="checked" type="Array" readonly="Y">
* Array with @wxCheckListBoxChecked 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 *p, JSContext *cx, JSObject *obj, int id, jsval *vp)
{
if ( id == P_CHECKED )
{
*vp = CheckListBoxChecked::CreateObject(cx, new Index(0), obj);
}
return true;
}
/***
* <ctor>
* <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 constructing)
{
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 )
break;
Object *wxjsParent = dynamic_cast<Object *>(parent);
JS_SetParent(cx, obj, wxjsParent->GetObject());
CheckListBox *p = new CheckListBox(cx, obj);
// Don't forget the wxLB_OWNERDRAW, because Create is called on wxListBox
p->Create(parent, id, *pt, *size, items.GetCount(), items.GetStrings(), style | wxLB_OWNERDRAW, *val);
return p;
}
return NULL;
}
/***
* <events>
* <event name="onCheckListBox">
* Called when an item is checked or unchecked. The function that is called gets a @CommandEvent
* object.</event>
* </events>
*/
void CheckListBox::OnCheckListBox(wxCommandEvent &event)
{
PrivCommandEvent::Fire<CommandEvent>(this, event, "onCheckListBox");
}
BEGIN_EVENT_TABLE(CheckListBox, wxCheckListBox)
EVT_CHECKLISTBOX(-1, CheckListBox::OnCheckListBox)
END_EVENT_TABLE()

View File

@ -1,80 +0,0 @@
/*
* 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 598 2007-03-07 20:13:28Z fbraem $
*/
#ifndef _WXJSCheckListBox_H
#define _WXJSCheckListBox_H
/////////////////////////////////////////////////////////////////////////////
// Name: chklstbx.h
// Purpose: CheckListBox ports wxCheckListBox to JavaScript.
// Author: Franky Braem
// Modified by:
// Created: 24.07.02
// Copyright: (c) 2001-2002 Franky Braem
// Licence: LGPL
/////////////////////////////////////////////////////////////////////////////
namespace wxjs
{
namespace gui
{
class CheckListBox : public wxCheckListBox
, public ApiWrapper<CheckListBox, wxCheckListBox>
, public Object
{
public:
/**
* Constructor
*/
CheckListBox(JSContext *cx, JSObject *obj);
/**
* Destructor
*/
virtual ~CheckListBox();
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);
// Empty to avoid deleting. (It will be deleted by wxWindows).
static void Destruct(JSContext *cx, wxCheckListBox *p)
{
}
WXJS_DECLARE_PROPERTY_MAP()
/**
* Property Ids.
*/
enum
{
P_CHECKED = WXJS_START_PROPERTY_ID
};
void OnCheckListBox(wxCommandEvent &event);
DECLARE_EVENT_TABLE()
};
}; // namespace gui
}; // namespace wxjs
#endif //_WXJSCheckListBox_H

View File

@ -1,96 +0,0 @@
#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 598 2007-03-07 20:13:28Z 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(CheckListBoxChecked, "wxCheckListBoxChecked", 0)
bool CheckListBoxChecked::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 CheckListBoxChecked"));
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 CheckListBoxChecked::SetProperty(Index *p, JSContext *cx, JSObject *obj, int id, jsval *vp)
{
JSObject *parent = JS_GetParent(cx, obj);
wxASSERT_MSG(parent != NULL, wxT("No parent found for CheckListBoxChecked"));
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

@ -1,41 +0,0 @@
/*
* 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 598 2007-03-07 20:13:28Z fbraem $
*/
#ifndef _wxjs_gui_chklstbxchk_h
#define _wxjs_gui_chklstbxchk_h
namespace wxjs
{
namespace gui
{
class CheckListBoxChecked : public ApiWrapper<CheckListBoxChecked, 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

@ -1,221 +0,0 @@
#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 598 2007-03-07 20:13:28Z fbraem $
*/
//choice.cpp
#ifndef WX_PRECOMP
#include <wx/wx.h>
#endif
#include "../../common/main.h"
#include "../../common/index.h"
#include "../event/evthand.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"
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)
/***
* <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()
Choice::Choice(JSContext *cx,
JSObject *obj) : wxChoice()
, Object(obj, cx)
{
PushEventHandler(new EventHandler(this));
}
Choice::~Choice()
{
PopEventHandler(true);
}
bool Choice::GetProperty(wxChoice *p, JSContext *cx, JSObject *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 *obj, int id, jsval *vp)
{
switch (id)
{
case P_COLUMNS:
{
int columns;
if ( FromJS(cx, *vp, columns) )
p->SetColumns(columns);
break;
}
}
return true;
}
/***
* <ctor>
* <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 constructing)
{
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 )
break;
Object *wxjsParent = dynamic_cast<Object *>(parent);
JS_SetParent(cx, obj, wxjsParent->GetObject());
Choice *p = new Choice(cx, obj);
p->Create(parent, id, *pt, *size, items.GetCount(), items.GetStrings(), style, *val);
return p;
}
return NULL;
}
/***
* <events>
* <event name="onChoice">
* Called when an item is selected. The type of the argument that your handler receives
* is @wxCommandEvent.
* </event>
* </events>
*/
void Choice::OnChoice(wxCommandEvent &event)
{
PrivCommandEvent::Fire<CommandEvent>(this, event, "onChoice");
}
BEGIN_EVENT_TABLE(Choice, wxChoice)
EVT_CHOICE(-1, Choice::OnChoice)
END_EVENT_TABLE()

View File

@ -1,78 +0,0 @@
/*
* 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 598 2007-03-07 20:13:28Z fbraem $
*/
#ifndef _WXJSChoice_H
#define _WXJSChoice_H
/////////////////////////////////////////////////////////////////////////////
// Name: choice.h
// Purpose: Choice ports wxChoice to JavaScript.
// Author: Franky Braem
// Modified by:
// Created: 24.02.02
// Copyright: (c) 2001-2002 Franky Braem
// Licence: LGPL
/////////////////////////////////////////////////////////////////////////////
namespace wxjs
{
namespace gui
{
class Choice : public wxChoice
, public ApiWrapper<Choice, wxChoice>
, public Object
{
public:
/**
* Constructor
*/
Choice(JSContext *cx, JSObject *obj);
/**
* Destructor
*/
virtual ~Choice();
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);
// Empty to avoid deleting. (It will be deleted by wxWindows).
static void Destruct(JSContext *cx, wxChoice *p)
{
}
WXJS_DECLARE_PROPERTY_MAP()
enum
{
P_COLUMNS
};
void OnChoice(wxCommandEvent &event);
DECLARE_EVENT_TABLE()
};
}; // namespace gui
}; // namespace wxjs
#endif //_WXJSChoice_H

View File

@ -1,163 +0,0 @@
#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 598 2007-03-07 20:13:28Z fbraem $
*/
// coldata.cpp
#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 *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 *cx, JSObject *obj, uintN argc, jsval *argv, bool 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 *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

@ -1,73 +0,0 @@
/*
* 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 598 2007-03-07 20:13:28Z fbraem $
*/
#ifndef _WXJSColourData_H
#define _WXJSColourData_H
/////////////////////////////////////////////////////////////////////////////
// Name: coldata.h
// Purpose: ColourData ports wxColourData to JavaScript.
// Author: Franky Braem
// Modified by:
// Created: 29.07.02
// Copyright: (c) 2001-2002 Franky Braem
// Licence: LGPL
/////////////////////////////////////////////////////////////////////////////
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

@ -1,135 +0,0 @@
#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 598 2007-03-07 20:13:28Z fbraem $
*/
// coldlg.cpp
#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"
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 *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 constructing)
{
if ( argc > 2 )
argc = 2;
wxColourData *data = NULL;
if ( argc == 2 )
{
data = ColourData::GetPrivate(cx, argv[1]);
if ( data == NULL )
return NULL;
}
wxWindow *parent = Window::GetPrivate(cx, argv[0]);
if ( parent != NULL )
{
Object *wxjsParent = dynamic_cast<Object *>(parent);
JS_SetParent(cx, obj, wxjsParent->GetObject());
}
return new wxColourDialog(parent, data);
}
void ColourDialog::Destruct(JSContext *cx, wxColourDialog *p)
{
p->Destroy();
}

View File

@ -1,63 +0,0 @@
/*
* 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 598 2007-03-07 20:13:28Z fbraem $
*/
#ifndef _WXJSColourDialog_H
#define _WXJSColourDialog_H
/////////////////////////////////////////////////////////////////////////////
// Name: coldlg.h
// Purpose: ColourDialog ports wxColourDialog to JavaScript.
// Author: Franky Braem
// Modified by:
// Created: 29.07.02
// Copyright: (c) 2001-2002 Franky Braem
// Licence: LGPL
/////////////////////////////////////////////////////////////////////////////
#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

@ -1,475 +0,0 @@
#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 598 2007-03-07 20:13:28Z fbraem $
*/
// combobox.cpp
#ifndef WX_PRECOMP
#include <wx/wx.h>
#endif
#include "../../common/main.h"
#include "../../common/index.h"
#include "../event/evthand.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"
using namespace wxjs;
using namespace wxjs::gui;
ComboBox::ComboBox(JSContext *cx, JSObject *obj)
: wxComboBox()
, Object(obj, cx)
{
PushEventHandler(new EventHandler(this));
}
ComboBox::~ComboBox()
{
PopEventHandler(true);
}
/***
* <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)
/***
* <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 *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 *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;
}
/***
* <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>
* <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 constructing)
{
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 )
break;
case 7:
if ( ! FromJS(cx, argv[6], style) )
break;
// Fall through
case 6:
if ( ! FromJS(cx, argv[5], items) )
break;
// Fall through
case 5:
size = Size::GetPrivate(cx, argv[4]);
if ( size == NULL )
break;
// Fall through
case 4:
pt = Point::GetPrivate(cx, argv[3]);
if ( pt == NULL )
break;
// Fall through
default:
wxString text;
FromJS(cx, argv[2], text);
int id;
if ( ! FromJS(cx, argv[1], id) )
break;
wxWindow *parent = Window::GetPrivate(cx, argv[0]);
if ( parent == NULL )
break;
Object *wxjsParent = dynamic_cast<Object *>(parent);
JS_SetParent(cx, obj, wxjsParent->GetObject());
ComboBox *p = new ComboBox(cx, obj);
p->Create(parent, id, text, *pt, *size, items.GetCount(), items.GetStrings(), style, *val);
return p;
}
return NULL;
}
WXJS_BEGIN_METHOD_MAP(ComboBox)
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="copy">
* <function />
* <desc>
* Copies the selected text to the clipboard
* </desc>
* </method>
*/
JSBool ComboBox::copy(JSContext *cx, JSObject *obj,
uintN argc, jsval *argv, jsval *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 argc, jsval *argv, jsval *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 argc, jsval *argv, jsval *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 argc, jsval *argv, jsval *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 argc, jsval *argv, jsval *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 argc, jsval *argv, jsval *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 argc, jsval *argv, jsval *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>
*/
void ComboBox::OnText(wxCommandEvent &event)
{
PrivCommandEvent::Fire<CommandEvent>(this, event, "onText");
}
void ComboBox::OnComboBox(wxCommandEvent &event)
{
PrivCommandEvent::Fire<CommandEvent>(this, event, "onComboBox");
}
BEGIN_EVENT_TABLE(ComboBox, wxComboBox)
EVT_TEXT(-1, ComboBox::OnText)
EVT_COMBOBOX(-1, ComboBox::OnComboBox)
END_EVENT_TABLE()

View File

@ -1,97 +0,0 @@
/*
* 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 598 2007-03-07 20:13:28Z fbraem $
*/
#ifndef _WXJSComboBox_H
#define _WXJSComboBox_H
/////////////////////////////////////////////////////////////////////////////
// Name: combobox.h
// Purpose: ComboBox ports wxComboBox to JavaScript.
// Author: Franky Braem
// Modified by:
// Created: 23.02.02
// Copyright: (c) 2001-2002 Franky Braem
// Licence: LGPL
/////////////////////////////////////////////////////////////////////////////
namespace wxjs
{
namespace gui
{
class ComboBox : public wxComboBox
, public ApiWrapper<ComboBox, wxComboBox>
, public Object
{
public:
/**
* Constructor
*/
ComboBox(JSContext *cx, JSObject *obj);
/**
* Destructor
*/
virtual ~ComboBox();
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);
// Empty to avoid deleting. (It will be deleted by wxWindows).
static void Destruct(JSContext *cx, wxComboBox *p)
{
}
static JSBool copy(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval);
static JSBool cut(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval);
static JSBool paste(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval);
static JSBool replace(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval);
static JSBool remove(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval);
static JSBool redo(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval);
static JSBool undo(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval);
WXJS_DECLARE_PROPERTY_MAP()
WXJS_DECLARE_METHOD_MAP()
WXJS_DECLARE_CONSTANT_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
};
DECLARE_EVENT_TABLE()
void OnText(wxCommandEvent &event);
void OnComboBox(wxCommandEvent &event);
};
}; // namespace gui
}; // namespace wxjs
#endif //_WXJSComboBox_H

View File

@ -1,94 +0,0 @@
#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 598 2007-03-07 20:13:28Z fbraem $
*/
// control.cpp
#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 *obj, int id, jsval *vp)
{
if ( id == P_LABEL )
*vp = ToJS(cx, p->GetLabel());
return true;
}
bool Control::SetProperty(wxControl *p, JSContext *cx, JSObject *obj, int id, jsval *vp)
{
if ( id == P_LABEL )
{
wxString label;
FromJS(cx, *vp, label);
p->SetLabel(label);
}
return true;
}
void Control::Destruct(JSContext *cx, wxControl* p)
{
}
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 argc, jsval *argv, jsval *rval)
{
wxControl *p = GetPrivate(cx, obj);
if ( p == NULL )
return JS_FALSE;
return JS_TRUE;
}

View File

@ -1,75 +0,0 @@
/*
* 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 598 2007-03-07 20:13:28Z fbraem $
*/
#ifndef _WXJSControl_H
#define _WXJSControl_H
/////////////////////////////////////////////////////////////////////////////
// Name: control.h
// Purpose: Control ports wxControl to JavaScript
// Author: Franky Braem
// Modified by:
// Created: 31-01-2003
// Copyright: (c) 2001-2003 Franky Braem
// Licence: LGPL
/////////////////////////////////////////////////////////////////////////////
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);
/**
* Callback for when a wxControl object is destroyed
*/
static void Destruct(JSContext *cx, wxControl *p);
WXJS_DECLARE_PROPERTY_MAP()
WXJS_DECLARE_METHOD_MAP()
static JSBool command(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval);
/**
* Property Ids.
*/
enum
{
P_LABEL
};
};
}; // namespace gui
}; // namespace wxjs
#endif //_WXJSControl_H

View File

@ -1,275 +0,0 @@
#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 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 "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 *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;
}
void ControlWithItems::Destruct(JSContext *cx, wxControlWithItems* p)
{
}
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 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 argc, jsval *argv, jsval *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 argc, jsval *argv, jsval *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 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 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

@ -1,66 +0,0 @@
/*
* 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 598 2007-03-07 20:13:28Z 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);
// Empty to avoid deleting. (It will be deleted by wxWindows).
static void Destruct(JSContext *cx, wxControlWithItems *p);
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()
static JSBool append(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval);
static JSBool clear(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval);
static JSBool delete_item(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval);
static JSBool findString(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval);
static JSBool insert(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval);
};
}; // namespace gui
}; // namespace wxjs
#endif //_WXJSControlWithItems_H

View File

@ -1,314 +0,0 @@
#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 598 2007-03-07 20:13:28Z fbraem $
*/
// dialog.cpp
#ifndef WX_PRECOMP
#include <wx/wx.h>
#endif
#include "../../common/main.h"
#include "../event/jsevent.h"
#include "../event/evthand.h"
#include "../event/jsevent.h"
#include "../event/close.h"
#include "dialog.h"
#include "window.h"
#include "../misc/point.h"
#include "../misc/size.h"
using namespace wxjs;
using namespace wxjs::gui;
Dialog::Dialog(JSContext *cx, JSObject *obj)
: wxDialog()
, Object(obj, cx)
{
PushEventHandler(new EventHandler(this));
}
Dialog::~Dialog()
{
PopEventHandler(true);
}
/***
* <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">
* 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)
/***
* <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 *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;
}
/***
* <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>
* <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 constructing)
{
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) )
break;
// Fall through
case 5:
size = Size::GetPrivate(cx, argv[4]);
if ( size == NULL )
break;
// Fall through
case 4:
pt = Point::GetPrivate(cx, argv[3]);
if ( pt == NULL )
break;
// Fall through
default:
wxString title;
FromJS(cx, argv[2], title);
int id;
if ( ! FromJS(cx, argv[1], id) )
break;
wxWindow *parent = Window::GetPrivate(cx, argv[0]);
if ( parent != NULL )
{
Object *wxjsParent = dynamic_cast<Object *>(parent);
JS_SetParent(cx, obj, wxjsParent->GetObject());
}
Dialog *p = new Dialog(cx, obj);
if ( parent == NULL )
style |= wxDIALOG_NO_PARENT;
p->Create(parent, id, title, *pt, *size, style);
return p;
}
return NULL;
}
void Dialog::Destruct(JSContext *cx, wxDialog *p)
{
// p->Destroy();
}
WXJS_BEGIN_METHOD_MAP(Dialog)
WXJS_METHOD("endModal", end_modal, 1)
WXJS_METHOD("showModal", show_modal, 0)
WXJS_END_METHOD_MAP()
/***
* <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 argc, jsval *argv, jsval *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 argc, jsval *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>
* </events>
*/
void Dialog::OnClose(wxCloseEvent &event)
{
bool destroy = true;
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 )
{
Destroy();
}
}
BEGIN_EVENT_TABLE(Dialog, wxDialog)
EVT_CLOSE(Dialog::OnClose)
END_EVENT_TABLE()

View File

@ -1,83 +0,0 @@
/*
* 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 598 2007-03-07 20:13:28Z fbraem $
*/
#ifndef _WXJSDialog_H
#define _WXJSDialog_H
/////////////////////////////////////////////////////////////////////////////
// Name: dialog.h
// Purpose: Dialog ports wxDialog to JavaScript.
// Author: Franky Braem
// Modified by:
// Created: 28.01.02
// Copyright: (c) 2001-2002 Franky Braem
// Licence: LGPL
/////////////////////////////////////////////////////////////////////////////
namespace wxjs
{
namespace gui
{
class Dialog : public wxDialog
, public ApiWrapper<Dialog, wxDialog>
, public Object
{
public:
/**
* Constructor
*/
Dialog(JSContext *cx, JSObject *obj);
/**
* Destructor
*/
virtual ~Dialog();
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);
static void Destruct(JSContext *cx, wxDialog *p);
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);
enum
{
P_RETURN_CODE
, P_TITLE
, P_MODAL
};
WXJS_DECLARE_PROPERTY_MAP()
WXJS_DECLARE_METHOD_MAP()
WXJS_DECLARE_CONSTANT_MAP()
DECLARE_EVENT_TABLE()
void OnClose(wxCloseEvent &event);
};
}; // namespace gui
}; // namespace wxjs
#endif //_WXJSDialog_H

View File

@ -1,170 +0,0 @@
#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 598 2007-03-07 20:13:28Z fbraem $
*/
// dirdlg.cpp
#ifndef WX_PRECOMP
#include <wx/wx.h>
#endif
#include "../../common/main.h"
#include "dirdlg.h"
#include "window.h"
#include "../misc/point.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 *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 *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 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 )
break;
// Fall through
case 4:
if ( ! FromJS(cx, argv[3], style) )
break;
// 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 )
{
Object *wxjsParent = dynamic_cast<Object *>(parent);
JS_SetParent(cx, obj, wxjsParent->GetObject());
}
return new wxDirDialog(parent, message, defaultPath, style, *pt);
}
return NULL;
}
void DirDialog::Destruct(JSContext *cx, wxDirDialog *p)
{
p->Destroy();
}

View File

@ -1,66 +0,0 @@
/*
* 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 598 2007-03-07 20:13:28Z fbraem $
*/
#ifndef _WXJSDirDialog_H
#define _WXJSDirDialog_H
/////////////////////////////////////////////////////////////////////////////
// Name: dirdlg.h
// Purpose: DirDialog ports wxDirDialog to JavaScript.
// Author: Franky Braem
// Modified by:
// Created: 30.07.02
// Copyright: (c) 2001-2002 Franky Braem
// Licence: LGPL
/////////////////////////////////////////////////////////////////////////////
#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

@ -1,284 +0,0 @@
#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 598 2007-03-07 20:13:28Z fbraem $
*/
// filedlg.cpp
#ifndef WX_PRECOMP
#include <wx/wx.h>
#endif
#include "../../common/main.h"
#include "filedlg.h"
#include "window.h"
#include "../misc/point.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 *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 *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 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 )
break;
// Fall through
case 6:
if ( ! FromJS(cx, argv[5], style) )
break;
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 )
{
Object *wxjsParent = dynamic_cast<Object *>(parent);
JS_SetParent(cx, obj, wxjsParent->GetObject());
}
return new wxFileDialog(parent, message, defaultDir, defaultFile,
wildcard, style, *pt);
}
return NULL;
}
void FileDialog::Destruct(JSContext *cx, wxFileDialog *p)
{
p->Destroy();
}

View File

@ -1,69 +0,0 @@
/*
* 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 598 2007-03-07 20:13:28Z fbraem $
*/
#ifndef _WXJSFileDialog_H
#define _WXJSFileDialog_H
/////////////////////////////////////////////////////////////////////////////
// Name: filedlg.h
// Purpose: FileDialog ports wxFileDialog to JavaScript.
// Author: Franky Braem
// Modified by:
// Created: 02.01.02
// Copyright: (c) 2001-2002 Franky Braem
// Licence: LGPL
/////////////////////////////////////////////////////////////////////////////
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

@ -1,156 +0,0 @@
#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 598 2007-03-07 20:13:28Z fbraem $
*/
// finddata.cpp
#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 *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 *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 *obj, uintN argc, jsval *argv, bool 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

@ -1,68 +0,0 @@
/*
* 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 598 2007-03-07 20:13:28Z fbraem $
*/
#ifndef _WXJSFindReplaceData_H
#define _WXJSFindReplaceData_H
/////////////////////////////////////////////////////////////////////////////
// Name: finddata.h
// Purpose: FindReplaceData ports wxFindReplaceData to JavaScript.
// Author: Franky Braem
// Modified by:
// Created: 31.07.02
// Copyright: (c) 2001-2002 Franky Braem
// Licence: LGPL
/////////////////////////////////////////////////////////////////////////////
#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_PROPERTY_MAP()
WXJS_DECLARE_CONSTANT_MAP()
/**
* Property Ids.
*/
enum
{
P_FINDSTRING
, P_REPLACESTRING
, P_FLAGS
};
};
}; // namespace gui
}; // namespace wxjs
#endif //_WXJSFindReplaceData_H

View File

@ -1,251 +0,0 @@
#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 598 2007-03-07 20:13:28Z 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"
using namespace wxjs;
using namespace wxjs::gui;
FindReplaceDialog::FindReplaceDialog(JSContext *cx, JSObject *obj)
: wxFindReplaceDialog()
, Object(obj, cx)
{
}
/***
* <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)
/***
* <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 *obj, int id, jsval *vp)
{
if (id == P_DATA )
*vp = FindReplaceData::CreateObject(cx, new wxFindReplaceData(*p->GetData()));
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 constructing)
{
if ( argc > 4 )
argc = 4;
if ( argc == 0 )
return new FindReplaceDialog(cx, obj);
if ( argc < 3 )
return NULL;
int style = 0;
if ( argc == 4
&& ! FromJS(cx, argv[3], style) )
return NULL;
wxString message;
FromJS(cx, argv[2], message);
wxFindReplaceData *data = FindReplaceData::GetPrivate(cx, argv[1]);
if ( data == NULL )
return NULL;
wxWindow *parent = Window::GetPrivate(cx, argv[0]);
if ( parent == NULL )
return NULL;
Object *wxjsParent = dynamic_cast<Object *>(parent);
JS_SetParent(cx, obj, wxjsParent->GetObject());
FindReplaceDialog *p = new FindReplaceDialog(cx, obj);
// Copy the data.
p->m_data.SetFlags(data->GetFlags());
p->m_data.SetFindString(data->GetFindString());
p->m_data.SetReplaceString(data->GetReplaceString());
p->Create(parent, &p->m_data, message, style);
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);
if ( p == NULL )
return JS_FALSE;
int style = 0;
if ( ! FromJS(cx, argv[3], style) )
return JS_FALSE;
wxString title;
FromJS(cx, argv[2], title);
wxFindReplaceData *data = FindReplaceData::GetPrivate(cx, argv[1]);
if ( data == NULL )
return JS_FALSE;
wxWindow *parent = Window::GetPrivate(cx, argv[0]);
if ( parent != NULL )
{
Object *wxjsParent = dynamic_cast<Object *>(parent);
JS_SetParent(cx, obj, wxjsParent->GetObject());
}
p->Create(parent, data, title, style);
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>
*/
void FindReplaceDialog::OnFind(wxFindDialogEvent& event)
{
PrivFindDialogEvent::Fire<FindDialogEvent>(this, event, "onFind");
}
void FindReplaceDialog::OnFindNext(wxFindDialogEvent& event)
{
PrivFindDialogEvent::Fire<FindDialogEvent>(this, event, "onFindNext");
}
void FindReplaceDialog::OnReplace(wxFindDialogEvent& event)
{
PrivFindDialogEvent::Fire<FindDialogEvent>(this, event, "onFindReplace");
}
void FindReplaceDialog::OnReplaceAll(wxFindDialogEvent& event)
{
PrivFindDialogEvent::Fire<FindDialogEvent>(this, event, "onFindReplaceAll");
}
void FindReplaceDialog::OnFindClose(wxFindDialogEvent& event)
{
PrivFindDialogEvent::Fire<FindDialogEvent>(this, event, "onFindClose");
Destroy();
}
BEGIN_EVENT_TABLE(FindReplaceDialog, wxFindReplaceDialog)
EVT_FIND(-1, FindReplaceDialog::OnFind)
EVT_FIND_NEXT(-1, FindReplaceDialog::OnFindNext)
EVT_FIND_REPLACE(-1, FindReplaceDialog::OnReplace)
EVT_FIND_REPLACE_ALL(-1, FindReplaceDialog::OnReplaceAll)
EVT_FIND_CLOSE(-1, FindReplaceDialog::OnFindClose)
END_EVENT_TABLE()

View File

@ -1,92 +0,0 @@
/*
* 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 598 2007-03-07 20:13:28Z fbraem $
*/
#ifndef _WXJSFindReplaceDialog_H
#define _WXJSFindReplaceDialog_H
/////////////////////////////////////////////////////////////////////////////
// Name: findrdlg.h
// Purpose: FindReplaceDialog ports wxFindReplaceDialog to JavaScript
// Author: Franky Braem
// Modified by:
// Created: 30.07.02
// Copyright: (c) 2001-2002 Franky Braem
// Licence: LGPL
/////////////////////////////////////////////////////////////////////////////
#include <wx/fdrepdlg.h>
namespace wxjs
{
namespace gui
{
class FindReplaceDialog : public wxFindReplaceDialog
, public ApiWrapper<FindReplaceDialog, wxFindReplaceDialog>
, public Object
{
public:
/**
* Constructor
*/
FindReplaceDialog(JSContext *cx, JSObject *obj);
virtual ~FindReplaceDialog()
{
}
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);
// Empty to avoid deleting. (It will be deleted by wxWindows).
static void Destruct(JSContext *cx, wxFindReplaceDialog *p)
{
}
static JSBool create(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval);
WXJS_DECLARE_METHOD_MAP()
WXJS_DECLARE_CONSTANT_MAP()
enum
{
P_DATA
};
// 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;
WXJS_DECLARE_PROPERTY_MAP()
DECLARE_EVENT_TABLE()
void OnFind(wxFindDialogEvent& event);
void OnFindNext(wxFindDialogEvent& event);
void OnReplace(wxFindDialogEvent& event);
void OnReplaceAll(wxFindDialogEvent& event);
void OnFindClose(wxFindDialogEvent& event);
};
}; // namespace gui
}; // namespace wxjs
#endif //_WXJSFindReplaceDialog_H

View File

@ -1,171 +0,0 @@
#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

@ -1,68 +0,0 @@
/*
* 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

@ -1,116 +0,0 @@
#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 598 2007-03-07 20:13:28Z fbraem $
*/
// fontdlg.cpp
#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"
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 *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 constructing)
{
if ( argc > 2 )
return NULL;
wxFontData *data = NULL;
if ( argc == 2 )
{
if ( (data = FontData::GetPrivate(cx, argv[1])) == NULL )
return NULL;
}
wxWindow *parent = Window::GetPrivate(cx, argv[0]);
if ( parent != NULL )
{
Object *wxjsParent = dynamic_cast<Object *>(parent);
JS_SetParent(cx, obj, wxjsParent->GetObject());
}
#if wxCHECK_VERSION(2,7,0)
wxFontDialog *p = new wxFontDialog(parent, *data);
#else
wxFontDialog *p = new wxFontDialog(parent, data);
#endif
return p;
}
void FontDialog::Destruct(JSContext *cx, wxFontDialog *p)
{
p->Destroy();
}

View File

@ -1,63 +0,0 @@
/*
* 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 598 2007-03-07 20:13:28Z fbraem $
*/
#ifndef _WXJSFontDialog_H
#define _WXJSFontDialog_H
/////////////////////////////////////////////////////////////////////////////
// Name: fontdlg.h
// Purpose: FontDialog ports wxFontDialog to JavaScript.
// Author: Franky Braem
// Modified by:
// Created: 06.08.02
// Copyright: (c) 2001-2002 Franky Braem
// Licence: LGPL
/////////////////////////////////////////////////////////////////////////////
#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

@ -1,733 +0,0 @@
#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 598 2007-03-07 20:13:28Z fbraem $
*/
// frame.cpp
#ifndef WX_PRECOMP
#include <wx/wx.h>
#endif
#include "../../common/main.h"
#include "../event/jsevent.h"
#include "../event/evthand.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 "menubar.h"
#include "menu.h"
#include "frame.h"
#include "window.h"
#include "statbar.h"
#include "toolbar.h"
using namespace wxjs;
using namespace wxjs::gui;
Frame::Frame(JSContext *cx, JSObject *obj)
: wxFrame()
, Object(obj, cx)
{
PushEventHandler(new EventHandler(this));
}
Frame::~Frame()
{
PopEventHandler(true);
}
/***
* <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)
/***
* <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 *obj, int id, jsval *vp)
{
switch(id)
{
case P_MENUBAR:
{
Object *menuBar = dynamic_cast<Object*>(p->GetMenuBar());
*vp = ( menuBar == NULL )
? JSVAL_VOID : OBJECT_TO_JSVAL(menuBar->GetObject());
break;
}
case P_STATUSBAR:
{
Object *statBar = dynamic_cast<Object *>(p->GetStatusBar());
*vp = ( statBar == NULL )
? JSVAL_VOID : OBJECT_TO_JSVAL(statBar->GetObject());
break;
}
case P_TOOLBAR:
{
Object *toolBar = dynamic_cast<Object *>(p->GetToolBar());
*vp = ( toolBar == NULL )
? JSVAL_VOID : OBJECT_TO_JSVAL(toolBar->GetObject());
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 *obj, int id, jsval *vp)
{
switch(id)
{
case P_MENUBAR:
{
wxMenuBar *menuBar = MenuBar::GetPrivate(cx, *vp);
if ( menuBar != NULL )
p->SetMenuBar(menuBar);
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;
}
/***
* <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>
* <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>
* <function>
* <arg name="Title" type="String">The caption 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 constructing)
{
if ( argc == 1 )
{
wxString title;
FromJS(cx, argv[0], title);
wxFrame *p = new Frame(cx, obj);
p->Create(NULL, -1, title);
return p;
}
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) )
break;
// Fall through
case 5:
size = Size::GetPrivate(cx, argv[4]);
if ( size == NULL )
break;
// Fall through
case 4:
pt = Point::GetPrivate(cx, argv[3]);
if ( pt == NULL )
break;
// Fall through
default:
wxString title;
FromJS(cx, argv[2], title);
int id;
if ( ! FromJS(cx, argv[1], id) )
break;
wxWindow *parent = NULL;
if ( JSVAL_IS_OBJECT(argv[0]) )
{
parent = Window::GetPrivate(cx, argv[0]);
if ( parent != NULL )
{
Object *wxjsParent = dynamic_cast<Object *>(parent);
JS_SetParent(cx, obj, wxjsParent->GetObject());
}
}
wxFrame *p = new Frame(cx, obj);
p->Create((wxWindow *) parent, id, title, *pt, *size, style);
return p;
}
return NULL;
}
WXJS_BEGIN_METHOD_MAP(Frame)
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="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 argc, jsval *argv, jsval *rval)
{
wxFrame *p = GetPrivate(cx, obj);
if ( p == NULL )
return JS_FALSE;
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;
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
}
StatusBar *bar = dynamic_cast<StatusBar*>(p->CreateStatusBar(fields, style, id));
*rval = ( p == NULL ) ? JSVAL_VOID : OBJECT_TO_JSVAL(bar->GetObject());
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;
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
}
ToolBar *bar = dynamic_cast<ToolBar*>(p->CreateToolBar(style, id));
*rval = ( p == NULL ) ? JSVAL_VOID : OBJECT_TO_JSVAL(bar->GetObject());
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 *rval)
{
wxFrame *p = GetPrivate(cx, obj);
if ( p == NULL )
return JS_FALSE;
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 argc, jsval *argv, jsval *rval)
{
wxFrame *p = GetPrivate(cx, obj);
if ( p == NULL )
return JS_FALSE;
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;
}
wxToolBar* Frame::OnCreateToolBar(long style,
wxWindowID id,
const wxString& name)
{
JSContext *cx = GetContext();
jsval argv[] =
{
OBJECT_TO_JSVAL(GetObject()),
ToJS(cx, id),
Point::CreateObject(cx, new wxPoint(wxDefaultPosition)),
Size::CreateObject(cx, new wxSize(wxDefaultSize)),
ToJS(cx, style)
};
JSObject *obj = JS_ConstructObjectWithArguments(cx,
ToolBar::GetClass(),
NULL,
GetObject(), 5, argv);
return ToolBar::GetPrivate(cx, obj, false);
}
wxStatusBar* Frame::OnCreateStatusBar(int number,
long style,
wxWindowID id,
const wxString& name)
{
JSContext *cx = GetContext();
jsval argv[] =
{
OBJECT_TO_JSVAL(GetObject()),
ToJS(cx, id),
ToJS(cx, style)
};
JSObject *obj = JS_ConstructObjectWithArguments(GetContext(),
StatusBar::GetClass(),
NULL,
GetObject(), 3, argv);
wxStatusBar *bar = StatusBar::GetPrivate(cx, obj, false);
bar->SetFieldsCount(number);
return bar;
}
void Frame::OnMenu(wxCommandEvent &event)
{
wxMenuItem *item = GetMenuBar()->FindItem(event.GetId());
if ( item == NULL )
return;
Menu *menu = (Menu *) item->GetMenu();
Object *menuObject = dynamic_cast<Object*>(menu);
if ( menuObject == NULL )
return;
JSContext *cx = menuObject->GetContext();
jsval actions;
if ( JS_GetProperty(cx, menuObject->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, GetObject(), action, 1, argv, &rval);
if ( result == JS_FALSE )
{
JS_ReportPendingException(cx);
}
}
}
else
{
event.Skip();
}
}
}
void Frame::OnTool(wxCommandEvent &event)
{
ToolBar *bar = dynamic_cast<ToolBar *>(GetToolBar());
if ( bar == NULL )
return;
JSObject *toolObject = bar->GetObject();
JSContext *cx = bar->GetContext();
jsval actions;
if ( JS_GetProperty(cx, toolObject, "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, GetObject(), action, 1, argv, &rval);
if ( result == JS_FALSE )
{
JS_ReportPendingException(cx);
}
}
}
}
}
/***
* <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>
*/
void Frame::OnClose(wxCloseEvent &event)
{
bool destroy = true;
if ( PrivCloseEvent::Fire<CloseEvent>(this, event, "onClose") )
{
destroy = ! event.GetVeto();
}
// When the close event is not handled by JavaScript,
// wxJS destroys the frame.
if ( destroy )
{
Destroy();
}
}
void Frame::OnIconize(wxIconizeEvent &event)
{
PrivIconizeEvent::Fire<IconizeEvent>(this, event, "onIconize");
}
void Frame::OnMaximize(wxMaximizeEvent &event)
{
PrivMaximizeEvent::Fire<MaximizeEvent>(this, event, "onMaximize");
}
BEGIN_EVENT_TABLE(Frame, wxFrame)
EVT_MENU_RANGE(-1, -1, Frame::OnMenu)
EVT_TOOL_RANGE(-1, -1, Frame::OnTool)
EVT_CLOSE(Frame::OnClose)
EVT_ICONIZE(Frame::OnIconize)
EVT_MAXIMIZE(Frame::OnMaximize)
END_EVENT_TABLE()

View File

@ -1,107 +0,0 @@
/*
* 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 598 2007-03-07 20:13:28Z fbraem $
*/
#ifndef _WXJSFRAME_H
#define _WXJSFRAME_H
/////////////////////////////////////////////////////////////////////////////
// Name: frame.h
// Purpose: Frame ports wxFrame to JavaScript.
// Author: Franky Braem
// Modified by:
// Created: 16.12.01
// Copyright: (c) 2001-2002 Franky Braem
// Licence: LGPL
/////////////////////////////////////////////////////////////////////////////
namespace wxjs
{
namespace gui
{
class Frame : public wxFrame
, public ApiWrapper<Frame, wxFrame>
, public Object
{
public:
/**
* Constructor
*/
Frame(JSContext *cx, JSObject *obj);
/**
* Destructor
*/
virtual ~Frame();
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);
// Empty to avoid deleting. (It will be deleted by wxWindows).
static void Destruct(JSContext* WXUNUSED(cx), wxFrame* WXUNUSED(p) )
{
}
static JSBool setStatusText(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval);
static JSBool setStatusWidths(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval);
static JSBool createStatusBar(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval);
static JSBool processCommand(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval);
static JSBool createToolBar(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval);
void OnIconize(wxIconizeEvent &event);
void OnMaximize(wxMaximizeEvent &event);
WXJS_DECLARE_PROPERTY_MAP()
WXJS_DECLARE_METHOD_MAP()
WXJS_DECLARE_CONSTANT_MAP()
enum
{
P_MENUBAR
, P_STATUSBAR_FIELDS
, P_STATUS_WIDTHS
, P_TOOLBAR
, P_STATUSBAR
, P_STATUSBAR_PANE
};
DECLARE_EVENT_TABLE()
void OnClose(wxCloseEvent &event);
void OnMenu(wxCommandEvent &event);
void OnTool(wxCommandEvent &event);
// Overrided because wxJS needs a StatusBar
virtual wxStatusBar* OnCreateStatusBar(int number,
long style,
wxWindowID id,
const wxString& name);
virtual wxToolBar* OnCreateToolBar(long style,
wxWindowID id,
const wxString& name);
};
}; // namespace gui
}; // namespace wxjs
#endif // _WXJSFRAME_H

View File

@ -1,243 +0,0 @@
#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 598 2007-03-07 20:13:28Z fbraem $
*/
// gauge.cpp
#ifndef WX_PRECOMP
#include <wx/wx.h>
#endif
#include "../../common/main.h"
#include "../event/evthand.h"
#include "../misc/point.h"
#include "../misc/size.h"
#include "../misc/validate.h"
#include "gauge.h"
#include "window.h"
using namespace wxjs;
using namespace wxjs::gui;
Gauge::Gauge(JSContext *cx, JSObject *obj)
: Object(obj, cx)
{
PushEventHandler(new EventHandler(this));
}
Gauge::~Gauge()
{
PopEventHandler(true);
}
/***
* <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 *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 *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;
}
/***
* <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>
* <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 constructing)
{
if ( argc > 7 )
argc = 7;
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 )
break;
case 6:
if ( ! FromJS(cx, argv[5], style) )
break;
// Fall through
case 5:
size = Size::GetPrivate(cx, argv[4]);
if ( size == NULL )
break;
// Fall through
case 4:
pt = Point::GetPrivate(cx, argv[3]);
if ( pt == NULL )
break;
// Fall through
default:
int range;
if ( ! FromJS(cx, argv[2], range) )
break;
int id;
if ( ! FromJS(cx, argv[1], id) )
break;
wxWindow *parent = Window::GetPrivate(cx, argv[0]);
if ( parent == NULL )
break;
Object *wxjsParent = dynamic_cast<Object *>(parent);
JS_SetParent(cx, obj, wxjsParent->GetObject());
wxGauge *p = new Gauge(cx, obj);
p->Create(parent, id, range, *pt, *size, style, *val);
return p;
}
return NULL;
}

View File

@ -1,82 +0,0 @@
/*
* 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 598 2007-03-07 20:13:28Z fbraem $
*/
#ifndef _WXJSGauge_H
#define _WXJSGauge_H
/////////////////////////////////////////////////////////////////////////////
// Name: gauge.h
// Purpose: Gauge ports wxGauge to JavaScript.
// Author: Franky Braem
// Modified by:
// Created: 08.08.02
// Copyright: (c) 2001-2002 Franky Braem
// Licence: LGPL
/////////////////////////////////////////////////////////////////////////////
namespace wxjs
{
namespace gui
{
class Gauge : public wxGauge
, public ApiWrapper<Gauge, wxGauge>
, public Object
{
public:
/**
* Constructor
*/
Gauge(JSContext *cx, JSObject *obj);
/**
* Destructor
*/
virtual ~Gauge();
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 wxGauge* Construct(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, bool constructing);
// Empty to avoid deleting. (It will be deleted by wxWindows).
static void Destruct(JSContext *cx, wxGauge *p)
{
}
WXJS_DECLARE_PROPERTY_MAP()
WXJS_DECLARE_CONSTANT_MAP()
/**
* Property Ids.
*/
enum
{
P_BEZEL_FACE
, P_RANGE
, P_SHADOW_WIDTH
, P_VALUE
};
};
}; // namespace gui
}; // namespace wxjs
#endif //_WXJSGauge_H

View File

@ -1,92 +0,0 @@
#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 598 2007-03-07 20:13:28Z fbraem $
*/
#ifndef WX_PRECOMP
#include <wx/wx.h>
#endif
#include "../../common/main.h"
#include "../event/evthand.h"
#include "../event/jsevent.h"
#include "../event/command.h"
#include "../misc/size.h"
#include "../misc/point.h"
#include "helpbtn.h"
#include "../misc/bitmap.h"
#include "window.h"
using namespace wxjs;
using namespace wxjs::gui;
/***
* <file>control/helpbtn</file>
* <module>gui</module>
* <class name="wxContextHelpButton" prototype="@wxButton">
* 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)
ContextHelpButton::ContextHelpButton(wxWindow *parent, JSContext *cx, JSObject *obj)
: wxContextHelpButton(parent)
, Object(obj, cx)
{
PushEventHandler(new EventHandler(this));
}
ContextHelpButton::~ContextHelpButton()
{
PopEventHandler(true);
}
/***
* <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 constructing)
{
wxWindow *parent = Window::GetPrivate(cx, argv[0]);
if ( parent == NULL )
return NULL;
Object *wxjsParent = dynamic_cast<Object *>(parent);
JS_SetParent(cx, obj, wxjsParent->GetObject());
ContextHelpButton *p = new ContextHelpButton(parent, cx, obj);
return p;
}

View File

@ -1,68 +0,0 @@
/*
* 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 598 2007-03-07 20:13:28Z fbraem $
*/
#ifndef _WXJSContextHelpButton_H
#define _WXJSContextHelpButton_H
/////////////////////////////////////////////////////////////////////////////
// Name: helpbtn.h
// Purpose: ContextHelpButton ports wxContextHelpButton to JavaScript.
// Author: Franky Braem
// Modified by:
// Created: 27.09.02
// Copyright: (c) 2001-2002 Franky Braem
// Licence: LGPL
/////////////////////////////////////////////////////////////////////////////
#include <wx/cshelp.h>
namespace wxjs
{
namespace gui
{
class ContextHelpButton : public wxContextHelpButton
, public ApiWrapper<ContextHelpButton, wxContextHelpButton>
, public Object
{
public:
/**
* Constructor
*/
ContextHelpButton(wxWindow *parent, JSContext *cx, JSObject *obj);
/**
* Destructor
*/
virtual ~ContextHelpButton();
static wxContextHelpButton* Construct(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, bool constructing);
// Empty to avoid deleting. (It will be deleted by wxWindows).
static void Destruct(JSContext *cx, wxContextHelpButton *p)
{
}
};
}; // namespace gui
}; // namespace wxjs
#endif //_WXJSContextHelpButton_H

View File

@ -1,658 +0,0 @@
#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 598 2007-03-07 20:13:28Z 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/evthand.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"
using namespace wxjs;
using namespace wxjs::gui;
WXJS_INIT_CLASS(HtmlWindow, "wxHtmlWindow", 1)
HtmlWindow::HtmlWindow(JSContext *cx, JSObject *obj)
: wxHtmlWindow()
, Object(obj, cx)
{
}
HtmlWindow::~HtmlWindow()
{
}
void HtmlWindow::InitClass(JSContext* WXUNUSED(cx), JSObject* WXUNUSED(obj), JSObject* WXUNUSED(proto))
{
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))
{
EventConnector<wxHtmlWindow>::ConnectEvent(p, prop);
return true;
}
/***
* <ctor>
* <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.
* </desc>
* </ctor>
*/
wxHtmlWindow* HtmlWindow::Construct(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, bool WXUNUSED(constructing))
{
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) )
break;
// Walk through
case 4:
size = Size::GetPrivate(cx, argv[3]);
if ( size == NULL )
break;
// Walk through
case 3:
pt = Point::GetPrivate(cx, argv[2]);
if ( pt == NULL )
break;
// Walk through
case 2:
if ( ! FromJS(cx, argv[1], id) )
break;
// Walk through
default:
wxWindow *parent = Window::GetPrivate(cx, argv[0]);
if ( parent == NULL )
return NULL;
Object *wxjsParent = dynamic_cast<Object *>(parent);
JS_SetParent(cx, obj, wxjsParent->GetObject());
HtmlWindow *p = new HtmlWindow(cx, obj);
p->Create(parent, id, *pt, *size, style);
return p;
}
return NULL;
}
WXJS_INIT_EVT_CONNECTOR_MAP(wxHtmlWindow)
WXJS_BEGIN_EVT_CONNECTOR_MAP(HtmlWindow)
WXJS_EVT_CONNECTOR(wxT("onLinkClicked"), ConnectLinkClicked)
WXJS_END_EVT_CONNECTOR_MAP()
void HtmlWindow::ConnectLinkClicked(wxHtmlWindow *p)
{
p->Connect(wxEVT_COMMAND_HTML_LINK_CLICKED, wxHtmlLinkEventHandler(HtmlWindow::OnLinkClicked));
}
/***
* <events>
* <event name="onLinkClicked">
* This event is triggered when a hyperlinck is clicked. The function receives
* a @wxHtmlLinkEvent as argument.
* </event>
* </events>
*/
void HtmlWindow::OnLinkClicked(wxHtmlLinkEvent &event)
{
PrivHtmlLinkEvent::Fire<HtmlLinkEvent>(this, event, "onLinkClicked");
}
WXJS_BEGIN_METHOD_MAP(HtmlWindow)
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="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, "Argument %d must be a %s in %s", 1, "wxFrame", "setRelatedFrame");
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

View File

@ -1,109 +0,0 @@
/*
* 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 598 2007-03-07 20:13:28Z fbraem $
*/
#ifndef _WXJSHtmlWindow_H
#define _WXJSHtmlWindow_H
#include <wx/html/htmlwin.h>
#include "../../common/evtconn.h"
namespace wxjs
{
namespace gui
{
class HtmlWindow : public wxHtmlWindow
, public ApiWrapper<HtmlWindow, wxHtmlWindow>
, public EventConnector<wxHtmlWindow>
, public Object
{
public:
/**
* Constructor
*/
HtmlWindow(JSContext *cx, JSObject *obj);
/**
* Destructor
*/
virtual ~HtmlWindow();
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 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);
// Empty to avoid deleting. (It will be deleted by wxWidgets).
static void Destruct(JSContext* WXUNUSED(cx), wxHtmlWindow* WXUNUSED(p))
{
}
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()
static JSBool appendToPage(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval);
static JSBool historyBack(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval);
static JSBool historyForward(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval);
static JSBool historyClear(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval);
static JSBool loadFile(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval);
static JSBool loadPage(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval);
static JSBool setPage(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval);
static JSBool setRelatedFrame(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval);
static JSBool setRelatedStatusBar(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval);
static JSBool selectAll(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval);
static JSBool selectLine(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval);
static JSBool selectWord(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval);
static JSBool setBorders(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval);
static JSBool setFonts(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval);
WXJS_DECLARE_CONSTANT_MAP()
// Events
void OnLinkClicked(wxHtmlLinkEvent &event);
private:
static void ConnectLinkClicked(wxHtmlWindow *p);
static void InitConnectEventMap();
};
}; // namespace gui
}; //namespace wxjs
#endif //_WXJSHtmlWindow_H

View File

@ -1,176 +0,0 @@
#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

@ -1,52 +0,0 @@
/*
* 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

@ -1,315 +0,0 @@
#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 598 2007-03-07 20:13:28Z fbraem $
*/
// listbox.cpp
#ifndef WX_PRECOMP
#include <wx/wx.h>
#endif
#include "../../common/main.h"
#include "../../common/index.h"
#include "../event/evthand.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"
using namespace wxjs;
using namespace wxjs::gui;
ListBox::ListBox(JSContext *cx, JSObject *obj)
: wxListBox()
, Object(obj, cx)
{
PushEventHandler(new EventHandler(this));
}
ListBox::~ListBox()
{
PopEventHandler(true);
}
/***
* <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)
/***
* <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 *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;
}
/***
* <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>
* <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 constructing)
{
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 )
break;
Object *wxjsParent = dynamic_cast<Object *>(parent);
JS_SetParent(cx, obj, wxjsParent->GetObject());
wxListBox *p = new ListBox(cx, obj);
p->Create(parent, id, *pt, *size, items.GetCount(), items.GetStrings(), style, *val);
return p;
}
return NULL;
}
WXJS_BEGIN_METHOD_MAP(ListBox)
WXJS_METHOD("setFirstItem", set_first_item, 1)
WXJS_END_METHOD_MAP()
/***
* <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 argc, jsval *argv, jsval *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 *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>
*/
void ListBox::OnListBox(wxCommandEvent &event)
{
PrivCommandEvent::Fire<CommandEvent>(this, event, "onListBox");
}
void ListBox::OnDoubleClick(wxCommandEvent &event)
{
PrivCommandEvent::Fire<CommandEvent>(this, event, "onDoubleClicked");
}
BEGIN_EVENT_TABLE(ListBox, wxListBox)
EVT_TEXT(-1, ListBox::OnDoubleClick)
EVT_COMBOBOX(-1, ListBox::OnListBox)
END_EVENT_TABLE()

View File

@ -1,79 +0,0 @@
/*
* 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 598 2007-03-07 20:13:28Z fbraem $
*/
#ifndef _WXJSListBox_H
#define _WXJSListBox_H
/////////////////////////////////////////////////////////////////////////////
// Name: listbox.h
// Purpose: ListBox ports wxListBox to JavaScript.
// Author: Franky Braem
// Modified by:
// Created: 01.05.02
// Copyright: (c) 2001-2002 Franky Braem
// Licence: LGPL
/////////////////////////////////////////////////////////////////////////////
namespace wxjs
{
namespace gui
{
class ListBox : public wxListBox
, public ApiWrapper<ListBox, wxListBox>
, public Object
{
public:
ListBox(JSContext *cx, JSObject *obj);
virtual ~ListBox();
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);
// Empty to avoid deleting. (It will be deleted by wxWindows).
static void Destruct(JSContext *cx, wxListBox *p)
{
}
static JSBool insert_items(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval);
static JSBool set_first_item(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval);
WXJS_DECLARE_PROPERTY_MAP()
WXJS_DECLARE_METHOD_MAP()
WXJS_DECLARE_CONSTANT_MAP()
enum
{
P_SELECTIONS
};
void OnListBox(wxCommandEvent &event);
void OnDoubleClick(wxCommandEvent &event);
DECLARE_EVENT_TABLE()
};
}; // namespace gui
}; // namespace wxjs
#endif //_WXJSListBox_H

File diff suppressed because it is too large Load Diff

View File

@ -1,221 +0,0 @@
/*
* 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 598 2007-03-07 20:13:28Z fbraem $
*/
#ifndef _WXJSListCtrl_H
#define _WXJSListCtrl_H
/////////////////////////////////////////////////////////////////////////////
// Name: listctrl.h
// Purpose: ListCtrl ports wxListCtrl to JavaScript
// Author: Franky Braem
// Modified by:
// Created: 28.09.2002
// Copyright: (c) 2001-2002 Franky Braem
// Licence: LGPL
/////////////////////////////////////////////////////////////////////////////
#include <wx/listctrl.h>
namespace wxjs
{
namespace gui
{
class ListCtrl : public wxListCtrl
, public ApiWrapper<ListCtrl, wxListCtrl>
, public Object
{
public:
ListCtrl(JSContext *cx, JSObject *obj);
virtual ~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;
/**
* Callback for retrieving properties of wxListCtrl
*/
static bool GetProperty(wxListCtrl *p, JSContext *cx, JSObject *obj, int id, jsval *vp);
/**
* Callback for setting properties
*/
static bool SetProperty(wxListCtrl *p, JSContext *cx, JSObject *obj, int id, jsval *vp);
/**
* 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);
/**
* Callback for when a wxListCtrl object is destroyed
*/
static void Destruct(JSContext *cx, wxListCtrl *p);
WXJS_DECLARE_PROPERTY_MAP()
/**
* Property Ids.
*/
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()
static JSBool getColumn(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval);
static JSBool setColumn(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval);
static JSBool getColumnWidth(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval);
static JSBool setColumnWidth(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval);
static JSBool getItem(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval);
static JSBool setItem(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval);
static JSBool getItemState(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval);
static JSBool setItemState(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval);
static JSBool setItemImage(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval);
static JSBool getItemText(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval);
static JSBool setItemText(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval);
static JSBool getItemData(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval);
static JSBool setItemData(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval);
static JSBool getItemRect(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval);
static JSBool getItemPosition(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval);
static JSBool setItemPosition(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval);
static JSBool getItemSpacing(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval);
static JSBool setSingleStyle(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval);
static JSBool getNextItem(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval);
static JSBool getImageList(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval);
static JSBool setImageList(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval);
static JSBool refreshItem(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval);
static JSBool refreshItems(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval);
static JSBool arrange(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval);
static JSBool deleteItem(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval);
static JSBool deleteAllItems(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval);
static JSBool deleteColumn(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval);
static JSBool deleteAllColumns(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval);
static JSBool clearAll(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval);
static JSBool insertColumn(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval);
static JSBool insertItem(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval);
static JSBool editLabel(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval);
static JSBool endEditLabel(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval);
static JSBool ensureVisible(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval);
static JSBool findItem(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval);
static JSBool hitTest(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval);
static JSBool scrollList(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval);
static JSBool sortItems(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval);
WXJS_DECLARE_CONSTANT_MAP()
DECLARE_EVENT_TABLE()
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);
};
/**
* 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

@ -1,106 +0,0 @@
#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 598 2007-03-07 20:13:28Z 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 *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

@ -1,79 +0,0 @@
/*
* 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 598 2007-03-07 20:13:28Z 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

@ -1,165 +0,0 @@
#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

@ -1,55 +0,0 @@
/*
* 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

@ -1,315 +0,0 @@
#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 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 "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 *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 *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 *obj, uintN argc, jsval *argv, bool 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

@ -1,78 +0,0 @@
/*
* 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 598 2007-03-07 20:13:28Z fbraem $
*/
#ifndef _WXJSListItem_H
#define _WXJSListItem_H
/////////////////////////////////////////////////////////////////////////////
// Name: listitem.h
// Purpose: ListItem ports wxListItem
// ListItemAttr ports wxListItemAttr
// Author: Franky Braem
// Modified by:
// Created: 30.09.2002
// Copyright: (c) 2001-2002 Franky Braem
// Licence: LGPL
/////////////////////////////////////////////////////////////////////////////
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

@ -1,830 +0,0 @@
#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 598 2007-03-07 20:13:28Z 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/evthand.h"
#include "../event/command.h"
using namespace wxjs;
using namespace wxjs::gui;
Menu::Menu(JSContext *cx, JSObject *obj, const wxString& title, long style)
: wxMenu(title, style)
, Object(obj, cx)
{
}
Menu::Menu(JSContext *cx, JSObject *obj, long style)
: wxMenu(style)
, Object(obj, cx)
{
}
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 *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 *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 constructing)
{
if ( argc > 2 )
argc = 2;
Menu *p = NULL;
switch(argc)
{
case 2:
{
wxString title;
int style;
FromJS(cx, argv[0], title);
if ( FromJS(cx, argv[1], style) )
p = new Menu(cx, obj, title, style);
break;
}
case 1:
if ( JSVAL_IS_INT(argv[0]) )
{
int style = 0;
if ( FromJS(cx, argv[0], style) )
p = new Menu(cx, obj, style);
}
else
{
wxString title;
FromJS(cx, argv[0], title);
p = new Menu(cx, obj, title);
}
break;
default:
p = new Menu(cx, obj);
}
if ( p != NULL )
{
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

@ -1,103 +0,0 @@
/*
* 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 598 2007-03-07 20:13:28Z fbraem $
*/
#ifndef _WXJSMENU_H
#define _WXJSMENU_H
/////////////////////////////////////////////////////////////////////////////
// Name: menu.h
// Purpose: Menu ports wxMenu to JavaScript.
// Author: Franky Braem
// Modified by:
// Created: 16.12.01
// Copyright: (c) 2001-2002 Franky Braem
// Licence: LGPL
/////////////////////////////////////////////////////////////////////////////
namespace wxjs
{
namespace gui
{
class Menu : public wxMenu
, public ApiWrapper<Menu, wxMenu>
, public Object
{
public:
/**
* Constructors
*/
Menu(JSContext *cx, JSObject *obj, const wxString& title, long style = 0);
Menu(JSContext *cx, JSObject *obj, long style = 0);
virtual ~Menu();
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);
/**
* JSConstructor - Callback for when a wxMenu object is created
*/
static wxMenu* Construct(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, bool constructing);
static void Destruct(JSContext *cx, wxMenu *p);
////////////////////////
// JavaScript methods
////////////////////////
static JSBool append(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval);
static JSBool append_separator(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval);
static JSBool new_column(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval);
static JSBool check(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval);
static JSBool delete_item(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval);
static JSBool enable(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval);
static JSBool find_item(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval);
static JSBool getHelpString(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval);
static JSBool getItem(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval);
static JSBool getLabel(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval);
static JSBool destroy(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval);
static JSBool insert(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval);
static JSBool remove(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval);
static JSBool isChecked(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval);
static JSBool isEnabled(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval);
static JSBool setHelpString(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval);
static JSBool setLabel(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval);
WXJS_DECLARE_PROPERTY_MAP()
WXJS_DECLARE_METHOD_MAP()
WXJS_DECLARE_CONSTANT_MAP()
enum
{
P_MENU_ITEM_COUNT
, P_MENU_ITEMS
, P_TITLE
};
};
}; // namespace gui
}; // namespace wxjs
#endif //_WXJSMENU_H

View File

@ -1,796 +0,0 @@
#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 598 2007-03-07 20:13:28Z 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;
MenuBar::MenuBar(JSContext *cx, JSObject *obj)
: wxMenuBar()
, Object(obj, cx)
{
}
MenuBar::MenuBar(JSContext *cx, JSObject *obj, long style)
: wxMenuBar(style)
, Object(obj, cx)
{
}
MenuBar::~MenuBar()
{
// A menubar attached to a frame is destroyed by wxWindows.
// The private data is set to null, so that an access violation is prevented
// in the js object finalizer.
if ( GetFrame() != NULL )
{
JS_SetPrivate(GetContext(), GetObject(), NULL);
}
}
/***
* <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 *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++ )
{
Object *menuObject = dynamic_cast<Object*>(p->GetMenu(i));
if ( menuObject != NULL )
{
jsval element = OBJECT_TO_JSVAL(menuObject->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 constructing)
{
if ( argc == 0 )
return new MenuBar(cx, obj);
int style = 0;
if ( argc == 1
&& ! FromJS(cx, argv[0], style) )
return NULL;
return new MenuBar(cx, obj, style);
}
void MenuBar::Destruct(JSContext *cx, wxMenuBar *p)
{
if ( p != NULL )
{
delete p;
p = NULL;
}
}
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);
Object *menuObject = dynamic_cast<Object*>(menu);
*rval = ( menuObject == NULL ) ? JSVAL_NULL : OBJECT_TO_JSVAL(menuObject->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);
Object *menuObject = dynamic_cast<Object*>(menu);
*rval = ( menu == NULL ) ? JSVAL_VOID : OBJECT_TO_JSVAL(menuObject->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
{
Object *menuObject = dynamic_cast<Object*>(oldMenu);
*rval = ( menuObject == NULL ) ? JSVAL_VOID : OBJECT_TO_JSVAL(menuObject->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;
}

View File

@ -1,94 +0,0 @@
/*
* wxJavaScript - menubar.h
*
* Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project
*
* Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net
*
* This library is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or
* (at your option) any later version.
*
* This library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
* License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
* USA.
*
* $Id: menubar.h 598 2007-03-07 20:13:28Z fbraem $
*/
#ifndef _WXJSMENUBAR_H
#define _WXJSMENUBAR_H
/////////////////////////////////////////////////////////////////////////////
// Name: menubar.h
// Purpose: MenuBar ports wxMenuBar to JavaScript.
// Author: Franky Braem
// Modified by:
// Created: 19.12.01
// Copyright: (c) 2001-2002 Franky Braem
// Licence: LGPL
/////////////////////////////////////////////////////////////////////////////
namespace wxjs
{
namespace gui
{
class MenuBar : public wxMenuBar
, public ApiWrapper<MenuBar, wxMenuBar>
, public Object
{
public:
/**
* Constructor
*/
MenuBar(JSContext *cx, JSObject *obj);
MenuBar(JSContext *cx, JSObject *obj, long style);
virtual ~MenuBar();
static bool GetProperty(wxMenuBar *p, JSContext *cx, JSObject *obj, int id, jsval *vp);
static wxMenuBar* Construct(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, bool constructing);
static void Destruct(JSContext *cx, wxMenuBar *p);
static JSBool append(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval);
static JSBool get_menu(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval);
static JSBool check(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval);
static JSBool insert(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval);
static JSBool enable(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval);
static JSBool enableTop(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval);
static JSBool findMenu(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval);
static JSBool findMenuItem(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval);
static JSBool getHelpString(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval);
static JSBool getLabel(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval);
static JSBool getLabelTop(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval);
static JSBool isChecked(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval);
static JSBool isEnabled(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval);
static JSBool refresh(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval);
static JSBool remove(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval);
static JSBool replace(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval);
static JSBool setHelpString(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval);
static JSBool setLabel(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval);
static JSBool setLabelTop(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval);
WXJS_DECLARE_PROPERTY_MAP()
WXJS_DECLARE_METHOD_MAP()
WXJS_DECLARE_CONSTANT_MAP()
enum
{
P_MENUCOUNT
, P_MENUS
};
};
}; // namespace gui
}; // namespace wxjs
#endif // _WXJSMENUBAR_H

View File

@ -1,408 +0,0 @@
#include "precompiled.h"
/*
* wxJavaScript - menuitem.cpp
*
* Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project
*
* Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net
*
* This library is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or
* (at your option) any later version.
*
* This library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
* License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
* USA.
*
* $Id: menuitem.cpp 598 2007-03-07 20:13:28Z fbraem $
*/
// menuitem.cpp
#ifndef WX_PRECOMP
#include <wx/wx.h>
#endif
#include "../../common/main.h"
#include "menu.h"
#include "menuitem.h"
#include "../misc/accentry.h"
#include "../misc/font.h"
#include "../misc/bitmap.h"
#include "../misc/colour.h"
using namespace wxjs;
using namespace wxjs::gui;
/***
* <file>control/menuitem</file>
* <module>gui</module>
* <class name="wxMenuItem">
* A menu item represents an item in a popup menu.
* Note that the majority of this class is only implemented under Windows so far,
* but everything except fonts, colours and bitmaps can be achieved via wxMenu on all platforms.
* </class>
*/
WXJS_INIT_CLASS(MenuItem, "wxMenuItem", 1)
/***
* <properties>
* <property name="accel" type="@wxAcceleratorEntry">
* Get/Set the accelerator.
* </property>
* <property name="backgroundColour" type="@wxColour">
* Get/Set the background colour of the item (Windows only)
* </property>
* <property name="bitmap" type="@wxBitmap">
* Get/Set the checked bitmap. (Windows only)
* </property>
* <property name="check" type="Boolean">
* Check or uncheck the menu item.
* </property>
* <property name="checkable" type="Boolean">
* Returns true if the item is checkable.
* </property>
* <property name="enable" type="Boolean">
* Enables or disables the menu item.
* </property>
* <property name="font" type="@wxFont">
* Get/Set the font. (Windows only)
* </property>
* <property name="help" type="String">
* Get/Set the helpstring shown in the statusbar.
* </property>
* <property name="id" type="Integer">
* Get/Set the id of the menu item
* </property>
* <property name="label" type="String" readonly="Y">
* Gets the text associated with the menu item without any accelerator
* characters it might contain.
* </property>
* <property name="marginWidth" type="Integer">
* Get/Set the width of the menu item checkmark bitmap (Windows only).
* </property>
* <property name="menu" type="@wxMenu" readonly="Y">
* Gets the menu that owns this item.
* </property>
* <property name="separator" type="Boolean">
* Returns true if the item is a separator.
* </property>
* <property name="subMenu" type="@wxMenu" readonly="Y">
* Gets the submenu associated with the menu item
* </property>
* <property name="text" type="String">
* Get/Set the text associated with the menu item with any accelerator characters it may contain.
* </property>
* <property name="textColour" type="@wxColour">
* Get/Set the text colour. (Windows Only)
* </property>
* </properties>
*/
WXJS_BEGIN_PROPERTY_MAP(MenuItem)
WXJS_READONLY_PROPERTY(P_LABEL, "label")
WXJS_PROPERTY(P_ACCEL, "accel")
WXJS_PROPERTY(P_TEXT, "text")
WXJS_PROPERTY(P_CHECK, "check")
WXJS_READONLY_PROPERTY(P_CHECKABLE, "checkable")
WXJS_PROPERTY(P_ENABLE, "enable")
WXJS_PROPERTY(P_HELP, "help")
WXJS_PROPERTY(P_ID, "id")
WXJS_PROPERTY(P_FONT, "font")
WXJS_PROPERTY(P_TEXT_COLOUR, "textColour")
WXJS_PROPERTY(P_BITMAP, "bitmap")
WXJS_PROPERTY(P_MARGIN_WIDTH, "marginWidth")
WXJS_READONLY_PROPERTY(P_SUB_MENU, "subMenu")
WXJS_PROPERTY(P_BG_COLOUR, "backgroundColour")
WXJS_READONLY_PROPERTY(P_MENU, "menu")
WXJS_READONLY_PROPERTY(P_SEPARATOR, "separator")
WXJS_END_PROPERTY_MAP()
bool MenuItem::GetProperty(wxMenuItem *p, JSContext *cx, JSObject *obj, int id, jsval *vp)
{
switch (id)
{
case P_ACCEL:
*vp = AcceleratorEntry::CreateObject(cx, p->GetAccel());
break;
case P_BG_COLOUR:
#ifdef __WXMSW__
*vp = Colour::CreateObject(cx, new wxColour(p->GetBackgroundColour()));
#endif
break;
case P_LABEL:
*vp = ToJS(cx, p->GetLabel());
break;
case P_TEXT:
*vp = ToJS(cx, p->GetText());
break;
case P_CHECK:
*vp = ToJS(cx, p->IsChecked());
break;
case P_CHECKABLE:
*vp = ToJS(cx, p->IsCheckable());
break;
case P_ENABLE:
*vp = ToJS(cx, p->IsEnabled());
break;
case P_HELP:
*vp = ToJS(cx, p->GetHelp());
break;
case P_ID:
*vp = ToJS(cx, p->GetId());
break;
case P_MARGIN_WIDTH:
#ifdef __WXMSW__
*vp = ToJS(cx, p->GetMarginWidth());
#endif
break;
case P_SUB_MENU:
{
wxMenu *subMenu = p->GetSubMenu();
Object *objMenu = dynamic_cast<Object*>(subMenu);
*vp = (objMenu == NULL) ? JSVAL_NULL : OBJECT_TO_JSVAL(objMenu->GetObject());
break;
}
case P_MENU:
{
wxMenu *menu = p->GetMenu();
Object *objMenu = dynamic_cast<Object*>(menu);
*vp = (objMenu == NULL) ? JSVAL_NULL : OBJECT_TO_JSVAL(objMenu->GetObject());
break;
}
case P_FONT:
#ifdef __WXMSW__
*vp = Font::CreateObject(cx, new wxFont(p->GetFont()), obj);
#endif
break;
case P_BITMAP:
*vp = Bitmap::CreateObject(cx, new wxBitmap(p->GetBitmap()));
break;
case P_TEXT_COLOUR:
#ifdef __WXMSW__
*vp = Colour::CreateObject(cx, new wxColour(p->GetTextColour()));
#endif
break;
case P_SEPARATOR:
*vp = ToJS(cx, p->IsSeparator());
break;
}
return true;
}
bool MenuItem::SetProperty(wxMenuItem *p, JSContext *cx, JSObject *obj, int id, jsval *vp)
{
switch(id)
{
case P_ACCEL:
{
wxAcceleratorEntry *entry = AcceleratorEntry::GetPrivate(cx, *vp);
if ( entry != NULL )
p->SetAccel(entry);
break;
}
case P_BG_COLOUR:
{
#ifdef __WXMSW__
wxColour *colour = Colour::GetPrivate(cx, *vp);
if ( colour != NULL )
p->SetBackgroundColour(*colour);
#endif
break;
}
case P_TEXT:
{
wxString str;
FromJS(cx, *vp, str);
p->SetText(str);
break;
}
case P_CHECK:
{
bool value;
if ( FromJS(cx, *vp, value) )
p->Check(value);
break;
}
case P_ENABLE:
{
bool value;
if ( FromJS(cx, *vp, value) )
p->Enable(value);
break;
}
case P_HELP:
{
wxString str;
FromJS(cx, *vp, str);
p->SetHelp(str);
break;
}
case P_MARGIN_WIDTH:
{
#ifdef __WXMSW__
int value;
if ( FromJS(cx, *vp, value) )
p->SetMarginWidth(value);
#endif
break;
}
case P_FONT:
{
#ifdef __WXMSW__
wxFont *font = Font::GetPrivate(cx, *vp);
if ( font )
p->SetFont(*font);
#endif
break;
}
case P_BITMAP:
{
#ifdef __WXMSW__
wxBitmap *bmp = Bitmap::GetPrivate(cx, *vp);
if ( bmp )
p->SetBitmaps(*bmp, wxNullBitmap);
#endif
break;
}
case P_TEXT_COLOUR:
{
#ifdef __WXMSW__
wxColour *colour = Colour::GetPrivate(cx, *vp);
if ( colour != NULL )
p->SetTextColour(*colour);
#endif
break;
}
}
return true;
}
WXJS_BEGIN_METHOD_MAP(MenuItem)
WXJS_METHOD("setBitmaps", setBitmaps, 2)
WXJS_END_METHOD_MAP()
/***
* <ctor>
* <function>
* <arg name="Menu" type="@wxMenu">Menu that owns the item</arg>
* <arg name="Id" type="Integer" default="0">Identifier for this item</arg>
* <arg name="Text" type="String" default="">The text for the menu item</arg>
* <arg name="Help" type="String" default="">The help message shown in the statusbar</arg>
* <arg name="Checkable" type="Boolean" default="false">Indicates if the menu item can be checked or not.</arg>
* <arg name="SubMenu" type="@wxMenu" default="null">Indicates that the menu item is a submenu</arg>
* </function>
* <desc>
* Constructs a new wxMenuItem object
* </desc>
* </ctor>
*/
wxMenuItem* MenuItem::Construct(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, bool constructing)
{
if ( argc > 6 )
argc = 6;
int id = 0;
wxString text = wxEmptyString;
wxString help = wxEmptyString;
bool checkable = false;
wxMenu *subMenu = NULL;
switch(argc)
{
case 6:
if ( (subMenu = Menu::GetPrivate(cx, argv[5])) == NULL )
break;
// Fall through
case 5:
if ( ! FromJS(cx, argv[4], checkable) )
break;
// Fall through
case 4:
FromJS(cx, argv[3], help);
// Fall through
case 3:
FromJS(cx, argv[2], text);
// Fall through
case 2:
if ( ! FromJS(cx, argv[1], id) )
break;
// Fall through
default:
wxMenu *menu = Menu::GetPrivate(cx, argv[0]);
if ( menu != NULL )
{
wxItemKind itemkind = wxITEM_NORMAL;
if ( checkable )
itemkind = wxITEM_CHECK;
#if wxCHECK_VERSION(2,7,0)
return new wxMenuItem(menu, id, text, help, itemkind, subMenu);
#else
return new wxMenuItem(menu, id, text, help, checkable, subMenu);
#endif
}
}
return NULL;
}
void MenuItem::Destruct(JSContext *cx, wxMenuItem *p)
{
/* if ( p->GetMenu() == NULL )
{
delete p;
p = NULL;
}
*/
}
/***
* <method name="setBitmaps">
* <function>
* <arg name="BitmapChecked" type="@wxBitmap" />
* <arg name="BitmapUnchecked" type="@wxBitmap" default="null" />
* </function>
* <desc>
* Sets the checked/unchecked bitmaps for the menu item (Windows only).
* The first bitmap is also used as the single bitmap for uncheckable menu items.
* </desc>
* </method>
*/
JSBool MenuItem::setBitmaps(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
wxMenuItem *p = MenuItem::GetPrivate(cx, obj);
if ( p == NULL )
return JS_FALSE;
#ifdef __WXMSW__
wxBitmap *bmp1 = Bitmap::GetPrivate(cx, argv[0]);
if ( bmp1 != NULL )
{
const wxBitmap *bmp2 = &wxNullBitmap;
if ( argc > 1 )
{
bmp2 = Bitmap::GetPrivate(cx, argv[1]);
if ( bmp2 == NULL )
{
return JS_FALSE;
}
}
p->SetBitmaps(*bmp1, *bmp2);
return JS_TRUE;
}
#else
return JS_TRUE;
#endif
return JS_FALSE;
}

View File

@ -1,81 +0,0 @@
/*
* wxJavaScript - menuitem.h
*
* Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project
*
* Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net
*
* This library is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or
* (at your option) any later version.
*
* This library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
* License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
* USA.
*
* $Id: menuitem.h 598 2007-03-07 20:13:28Z fbraem $
*/
#ifndef _WXJSMENUITEM_H
#define _WXJSMENUITEM_H
/////////////////////////////////////////////////////////////////////////////
// Name: menuitem.h
// Purpose: MenuItem ports wxMenuItem to JavaScript.
// Author: Franky Braem
// Modified by:
// Created: 19.12.01
// Copyright: (c) 2001-2002 Franky Braem
// Licence: LGPL
/////////////////////////////////////////////////////////////////////////////
namespace wxjs
{
namespace gui
{
class MenuItem : public ApiWrapper<MenuItem, wxMenuItem>
{
public:
static bool GetProperty(wxMenuItem *p, JSContext *cx, JSObject *obj, int id, jsval *vp);
static bool SetProperty(wxMenuItem *p, JSContext *cx, JSObject *obj, int id, jsval *vp);
static wxMenuItem* Construct(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, bool constructing);
static void Destruct(JSContext *cx, wxMenuItem *p);
static JSBool is_checkable(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval);
static JSBool is_separator(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval);
static JSBool setBitmaps(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval);
WXJS_DECLARE_PROPERTY_MAP()
WXJS_DECLARE_METHOD_MAP()
enum
{
P_LABEL = WXJS_START_PROPERTY_ID
, P_TEXT
, P_CHECK
, P_CHECKABLE
, P_ENABLE
, P_HELP
, P_ID
, P_MARGIN_WIDTH
, P_SUB_MENU
, P_ACCEL
, P_BG_COLOUR
, P_MENU
, P_FONT
, P_BITMAP
, P_TEXT_COLOUR
, P_SEPARATOR
};
};
}; // namespace gui
}; // namespace wxjs
#endif //_WXJSMENUITEM_H

View File

@ -1,207 +0,0 @@
#include "precompiled.h"
/*
* wxJavaScript - panel.cpp
*
* Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project
*
* Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net
*
* This library is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or
* (at your option) any later version.
*
* This library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
* License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
* USA.
*
* $Id: panel.cpp 598 2007-03-07 20:13:28Z fbraem $
*/
// panel.cpp
#ifndef WX_PRECOMP
#include "wx/wx.h"
#endif
#include "../../common/main.h"
#include "../event/jsevent.h"
#include "../event/evthand.h"
#include "../misc/size.h"
#include "../misc/point.h"
#include "button.h"
#include "panel.h"
#include "window.h"
using namespace wxjs;
using namespace wxjs::gui;
Panel::Panel(JSContext *cx, JSObject *obj)
: wxPanel()
, Object(obj, cx)
{
PushEventHandler(new EventHandler(this));
}
Panel::~Panel()
{
PopEventHandler(true);
}
/***
* <file>control/panel</file>
* <module>gui</module>
* <class name="wxPanel" prototype="@wxWindow">
* A panel is a window on which controls are placed. It is usually placed within a frame.
* Its main purpose is to be similar in appearance and functionality to a dialog,
* but with the flexibility of having any window as a parent.
* See @wxDialog and @wxFrame
* </class>
*/
WXJS_INIT_CLASS(Panel, "wxPanel", 2)
/***
* <properties>
* <property name="defaultItem" type="@wxButton">
* Get/Set the default button.
* </property>
* </properties>
*/
WXJS_BEGIN_PROPERTY_MAP(Panel)
WXJS_PROPERTY(P_DEFAULT_ITEM, "defaultItem")
WXJS_END_PROPERTY_MAP()
bool Panel::GetProperty(wxPanel *p, JSContext *cx, JSObject *obj, int id, jsval *vp)
{
if ( id == P_DEFAULT_ITEM )
{
wxWindow *win = NULL;
#if wxCHECK_VERSION(2,7,0)
wxTopLevelWindow *tlw = wxDynamicCast(wxGetTopLevelParent(p), wxTopLevelWindow);
if ( tlw )
win = tlw->GetDefaultItem();
#else
win = p->GetDefaultItem();
#endif
Object *winObject = dynamic_cast<Object*>(win);
*vp = winObject == NULL ? JSVAL_VOID : OBJECT_TO_JSVAL(winObject->GetObject());
}
return true;
}
bool Panel::SetProperty(wxPanel *p, JSContext *cx, JSObject *obj, int id, jsval *vp)
{
if ( id == P_DEFAULT_ITEM )
{
wxWindow *win = Window::GetPrivate(cx, *vp);
if ( win != NULL )
{
#if wxCHECK_VERSION(2,7,0)
wxTopLevelWindow *tlw = wxDynamicCast(wxGetTopLevelParent(p), wxTopLevelWindow);
if ( tlw )
tlw->SetDefaultItem(win);
#else
p->SetDefaultItem(win);
#endif
}
}
return true;
}
/***
* <ctor>
* <function>
* <arg name="Parent" type="@wxWindow">
* The parent of wxPanel.
* </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 Panel control on the given parent.
* </arg>
* <arg name="Size" type="@wxSize" default="wxDefaultSize">
* The size of the Panel control.
* </arg>
* <arg name="Style" type="Integer" default="0">
* The wxPanel style.
* </arg>
* </function>
* <desc>
* Constructs a new wxPanel object.
* </desc>
* </ctor>
*/
wxPanel* Panel::Construct(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, bool constructing)
{
if ( argc > 5 )
argc = 5;
int style = 0;
const wxPoint *pt = &wxDefaultPosition;
const wxSize *size = &wxDefaultSize;
switch(argc)
{
case 5:
if ( ! FromJS(cx, argv[4], style) )
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 )
break;
Object *wxjsParent = dynamic_cast<Object *>(parent);
JS_SetParent(cx, obj, wxjsParent->GetObject());
wxPanel *p = new Panel(cx, obj);
p->Create(parent, id, *pt, *size, style);
return p;
}
return NULL;
}
/***
* <events>
* <event name="onSysColourChanged">
* To process a system colour changed event, use this property to set
* an event handler function. The function takes a @wxSysColourChangedEvent argument.
* </event>
* </events>
*/
void Panel::OnSysColourChanged(wxSysColourChangedEvent &event)
{
PrivSysColourChangedEvent::Fire<SysColourChangedEvent>(this, event, "onSysColourChanged");
}
BEGIN_EVENT_TABLE(Panel, wxPanel)
EVT_SYS_COLOUR_CHANGED(Panel::OnSysColourChanged)
END_EVENT_TABLE()

View File

@ -1,78 +0,0 @@
/*
* wxJavaScript - panel.h
*
* Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project
*
* Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net
*
* This library is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or
* (at your option) any later version.
*
* This library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
* License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
* USA.
*
* $Id: panel.h 598 2007-03-07 20:13:28Z fbraem $
*/
#ifndef _WXJSPanel_H
#define _WXJSPanel_H
/////////////////////////////////////////////////////////////////////////////
// Name: panel.h
// Purpose: Panel ports wxPanel to JavaScript
// Author: Franky Braem
// Modified by:
// Created:
// Copyright: (c) 2001-2002 Franky Braem
// Licence: LGPL
/////////////////////////////////////////////////////////////////////////////
namespace wxjs
{
namespace gui
{
class Panel : public wxPanel
, public ApiWrapper<Panel, wxPanel>
, public Object
{
public:
Panel(JSContext *cx, JSObject *obj);
/**
* Destructor
*/
virtual ~Panel();
static bool GetProperty(wxPanel *p, JSContext *cx, JSObject *obj, int id, jsval *vp);
static bool SetProperty(wxPanel *p, JSContext *cx, JSObject *obj, int id, jsval *vp);
static wxPanel* Construct(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, bool constructing);
// Empty to avoid deleting. (It will be deleted by wxWindows).
static void Destruct(JSContext *cx, wxPanel *p)
{
}
WXJS_DECLARE_PROPERTY_MAP()
/**
* Property Ids.
*/
enum
{
P_DEFAULT_ITEM
};
DECLARE_EVENT_TABLE()
void OnSysColourChanged(wxSysColourChangedEvent &event);
};
}; // namespace gui
}; // namespace wxjs
#endif //_WXJSPanel_H

View File

@ -1,142 +0,0 @@
#include "precompiled.h"
/*
* wxJavaScript - pwdlg.cpp
*
* Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project
*
* Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net
*
* This library is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or
* (at your option) any later version.
*
* This library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
* License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
* USA.
*
* $Id: pwdlg.cpp 598 2007-03-07 20:13:28Z fbraem $
*/
#ifndef WX_PRECOMP
#include <wx/wx.h>
#endif
#include <wx/textdlg.h>
#include "../../common/main.h"
#include "../misc/point.h"
#include "../event/jsevent.h"
#include "../event/evthand.h"
#include "pwdlg.h"
#include "window.h"
using namespace wxjs;
using namespace wxjs::gui;
PasswordEntryDialog::PasswordEntryDialog( JSContext *cx
, JSObject *obj
, wxWindow* parent
, const wxString& message
, const wxString& caption
, const wxString& defaultValue
, long style
, const wxPoint& pos)
: wxPasswordEntryDialog(parent, message, caption, defaultValue, style, pos)
, Object(obj, cx)
{
PushEventHandler(new EventHandler(this));
}
PasswordEntryDialog::~PasswordEntryDialog()
{
PopEventHandler(true);
}
/***
* <file>control/pwdlg</file>
* <module>gui</module>
* <class name="wxPasswordEntryDialog" prototype="@wxTextEntryDialog">
* This class represents a dialog that requests a password from the user.
* </class>
*/
WXJS_INIT_CLASS(PasswordEntryDialog, "wxPasswordEntryDialog", 2)
/***
* <ctor>
* <function>
* <arg name="Parent" type="@wxWindow">The parent of the dialog. null is Allowed.</arg>
* <arg name="Message" type="String">Message to show on the dialog.</arg>
* <arg name="Title" type="String">The title of the dialog.</arg>
* <arg name="DefaultValue" type="String">The default value of the text control.</arg>
* <arg name="Position" type="@wxPoint" default="wxDefaultPosition">The position of the dialog.</arg>
* <arg name="Style" type="Integer" default="wxId.OK + wxId.CANCEL">A dialog style, the buttons wxId.OK and wxId.CANCEL can be used.</arg>
* </function>
* <desc>
* Constructs a new wxPasswordEntryDialog object.
* </desc>
* </ctor>
*/
wxPasswordEntryDialog* PasswordEntryDialog::Construct(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, bool constructing)
{
if ( argc > 6 )
argc = 6;
int style = wxOK | wxCANCEL | wxCENTRE;
const wxPoint *pt = &wxDefaultPosition;
wxString defaultValue = wxEmptyString;
wxString caption = wxEmptyString;
switch(argc)
{
case 6:
pt = Point::GetPrivate(cx, argv[5]);
if ( pt == NULL )
break;
// Fall through
case 5:
if ( ! FromJS(cx, argv[4], style) )
break;
// Fall through
case 4:
if ( ! FromJS(cx, argv[3], defaultValue) )
break;
// Fall through
case 3:
if ( ! FromJS(cx, argv[2], caption) )
break;
// Fall through
default:
wxString message;
if ( ! FromJS(cx, argv[1], message) )
break;
wxWindow *parent = Window::GetPrivate(cx, argv[0]);
if ( parent != NULL )
{
Object *wxjsParent = dynamic_cast<Object *>(parent);
JS_SetParent(cx, obj, wxjsParent->GetObject());
}
PasswordEntryDialog *p = new PasswordEntryDialog(cx, obj, parent, message,
caption, defaultValue, style, *pt);
return p;
}
return NULL;
}
void PasswordEntryDialog::Destruct(JSContext *cx, wxPasswordEntryDialog *p)
{
}
BEGIN_EVENT_TABLE(PasswordEntryDialog, wxPasswordEntryDialog)
END_EVENT_TABLE()

View File

@ -1,69 +0,0 @@
/*
* wxJavaScript - pwdlg.h
*
* Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project
*
* Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net
*
* This library is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or
* (at your option) any later version.
*
* This library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
* License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
* USA.
*
* $Id: pwdlg.h 598 2007-03-07 20:13:28Z fbraem $
*/
#ifndef _WXJSPasswordEntryDialog_H
#define _WXJSPasswordEntryDialog_H
/////////////////////////////////////////////////////////////////////////////
// Name: pwdlg.h
// Purpose: PasswordEntryDialog ports wxPasswordEntryDialog to JavaScript.
// Author: Franky Braem
// Modified by:
// Created: 04.11.05
// Copyright: (c) 2001-2002 Franky Braem
// Licence: LGPL
/////////////////////////////////////////////////////////////////////////////
namespace wxjs
{
namespace gui
{
class PasswordEntryDialog : public wxPasswordEntryDialog
, public ApiWrapper<PasswordEntryDialog, wxPasswordEntryDialog>
, public Object
{
public:
/**
* Constructor
*/
PasswordEntryDialog(JSContext *cx,
JSObject *obj,
wxWindow* parent,
const wxString& message,
const wxString& caption, const wxString& defaultValue, long style,
const wxPoint& pos);
/**
* Destructor
*/
virtual ~PasswordEntryDialog();
static wxPasswordEntryDialog* Construct(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, bool constructing);
static void Destruct(JSContext *cx, wxPasswordEntryDialog *p);
DECLARE_EVENT_TABLE()
};
}; // namespace gui
}; // namespace wxjs
#endif //_WXJSPasswordEntryDialog_H

View File

@ -1,418 +0,0 @@
#include "precompiled.h"
/*
* wxJavaScript - radiobox.cpp
*
* Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project
*
* Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net
*
* This library is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or
* (at your option) any later version.
*
* This library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
* License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
* USA.
*
* $Id: radiobox.cpp 598 2007-03-07 20:13:28Z fbraem $
*/
// radiobox.cpp
#ifndef WX_PRECOMP
#include <wx/wx.h>
#endif
#include "../../common/main.h"
#include "../../common/index.h"
#include "../event/evthand.h"
#include "../event/jsevent.h"
#include "../event/command.h"
#include "../misc/size.h"
#include "../misc/point.h"
#include "../misc/validate.h"
#include "radiobox.h"
#include "radioboxit.h"
#include "window.h"
using namespace wxjs;
using namespace wxjs::gui;
RadioBox::RadioBox(JSContext *cx, JSObject *obj)
: wxRadioBox()
, Object(obj, cx)
{
PushEventHandler(new EventHandler(this));
}
RadioBox::~RadioBox()
{
PopEventHandler(true);
}
/***
* <file>control/radiobox</file>
* <module>gui</module>
* <class name="wxRadioBox" prototype="@wxControl">
* A radio box item is used to select one of number of mutually exclusive choices.
* It is displayed as a vertical column or horizontal row of labelled buttons.
* </class>
*/
WXJS_INIT_CLASS(RadioBox, "wxRadioBox", 3)
/***
* <properties>
* <property name="count" type="Integer" readonly="Y">
* Get the number of items
* </property>
* <property name="item" type="Array" readonly="Y">
* Get an array of with @wxRadioBoxItem items.
* </property>
* <property name="selection" type="Integer">
* Get/Set the selected button. (zero-indexed)
* </property>
* <property name="stringSelection" type="String">
* Get/Set the selected string.
* </property>
* </properties>
*/
WXJS_BEGIN_PROPERTY_MAP(RadioBox)
WXJS_PROPERTY(P_SELECTION, "selection")
WXJS_PROPERTY(P_STRING_SELECTION, "stringSelection")
WXJS_READONLY_PROPERTY(P_COUNT, "count")
WXJS_READONLY_PROPERTY(P_ITEM, "item")
WXJS_END_PROPERTY_MAP()
bool RadioBox::GetProperty(wxRadioBox *p, JSContext *cx, JSObject *obj, int id, jsval *vp)
{
switch (id)
{
case P_COUNT:
*vp = ToJS(cx, p->GetCount());
break;
case P_SELECTION:
*vp = ToJS(cx, p->GetSelection());
break;
case P_STRING_SELECTION:
*vp = ToJS(cx, p->GetStringSelection());
break;
case P_ITEM:
*vp = RadioBoxItem::CreateObject(cx, new Index(0));
break;
}
return true;
}
bool RadioBox::SetProperty(wxRadioBox *p, JSContext *cx, JSObject *obj, int id, jsval *vp)
{
switch (id)
{
case P_SELECTION:
{
int value;
if ( FromJS(cx, *vp, value) )
p->SetSelection(value);
break;
}
case P_STRING_SELECTION:
{
wxString value;
FromJS(cx, *vp, value);
p->SetStringSelection(value);
break;
}
}
return true;
}
/***
* <constants>
* <type name="Styles">
* <constant name="SPECIFY_ROWS">The major dimension parameter refers to the maximum number of rows.</constant>
* <constant name="SPECIFY_COLS">The major dimension parameter refers to the maximum number of columns.</constant>
* </type>
* </constants>
*/
WXJS_BEGIN_CONSTANT_MAP(RadioBox)
WXJS_CONSTANT(wxRA_, SPECIFY_ROWS)
WXJS_CONSTANT(wxRA_, SPECIFY_COLS)
WXJS_END_CONSTANT_MAP()
/***
* <ctor>
* <function>
* <arg name="Parent" type="@wxWindow">The parent of wxRadioBox.</arg>
* <arg name="Id" type="Integer">A window identifier. Use -1 when you don't need it.</arg>
* <arg name="Title" type="String">The title of the radiobox.</arg>
* <arg name="Position" type="@wxPoint" default="wxDefaultPosition">
* The position of the RadioBox control on the given parent.
* </arg>
* <arg name="Size" type="@wxSize" default="wxDefaultSize">
* The size of the RadioBox control.
* </arg>
* <arg name="Items" type="Array" default="null">
* An array of Strings to initialize the control.
* </arg>
* <arg name="MaximumDimension" type="Integer" default="0">
* Specifies the maximum number of rows (if style contains SPECIFY_ROWS) or columns
* (if style contains SPECIFY_COLS) for a two-dimensional radiobox.
* </arg>
* <arg name="Style" type="Integer" default="SPECIFY_COLS">
* The wxRadioBox style.
* </arg>
* <arg name="Validator" type="@wxValidator" default="null" />
* </function>
* <desc>
* Constructs a new wxRadioBox object.
* </desc>
* </ctor>
*/
wxRadioBox* RadioBox::Construct(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, bool constructing)
{
if ( argc > 9 )
argc = 9;
int style = 0;
int max = 0;
StringsPtr items;
const wxSize *size = &wxDefaultSize;
const wxPoint *pt = &wxDefaultPosition;
const wxValidator *val = &wxDefaultValidator;
switch(argc)
{
case 9:
val = Validator::GetPrivate(cx, argv[8]);
if ( val == NULL )
break;
case 8:
if ( ! FromJS(cx, argv[7], style) )
break;
// Fall through
case 7:
if ( ! FromJS(cx, argv[6], max) )
break;
// Fall through
case 6:
if ( ! FromJS(cx, argv[5], items) )
break;
// Fall through
case 5:
size = Size::GetPrivate(cx, argv[4]);
if ( size == NULL )
break;
// Fall through
case 4:
pt = Point::GetPrivate(cx, argv[3]);
if ( pt == NULL )
break;
// Fall through
default:
wxString title;
FromJS(cx, argv[2], title);
int id;
if ( ! FromJS(cx, argv[1], id) )
break;
wxWindow *parent = Window::GetPrivate(cx, argv[0]);
if ( parent == NULL )
break;
Object *wxjsParent = dynamic_cast<Object *>(parent);
JS_SetParent(cx, obj, wxjsParent->GetObject());
wxRadioBox *p = new RadioBox(cx, obj);
p->Create(parent, id, title, *pt, *size,
items.GetCount(), items.GetStrings(), max, style, *val);
return p;
}
return NULL;
}
WXJS_BEGIN_METHOD_MAP(RadioBox)
WXJS_METHOD("setString", setString, 2)
WXJS_METHOD("findString", setString, 2)
WXJS_METHOD("enable", enable, 2)
WXJS_METHOD("show", show, 2)
WXJS_END_METHOD_MAP()
/***
* <method name="setString">
* <function>
* <arg name="Index" type="Integer">
* The zero-based index of a button
* </arg>
* <arg name="Label" type="String">
* Sets the label of the button.
* </arg>
* </function>
* <desc />
* </method>
*/
JSBool RadioBox::setString(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
wxRadioBox *p = GetPrivate(cx, obj);
if ( p == NULL )
return JS_FALSE;
int idx;
wxString label;
if ( FromJS(cx, argv[0], idx) )
{
FromJS(cx, argv[1], label);
p->SetString(idx, label);
}
else
{
return JS_FALSE;
}
return JS_TRUE;
}
/***
* <method name="findString">
* <function returns="Integer">
* <arg name="Str" type="String" />
* </function>
* <desc>
* Finds a button matching the given string, returning the position if found,
* or -1 if not found.
* </desc>
* </method>
*/
JSBool RadioBox::findString(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
wxRadioBox *p = GetPrivate(cx, obj);
if ( p == NULL )
return JS_FALSE;
wxString label;
FromJS(cx, argv[0], label);
*rval = ToJS(cx, p->FindString(label));
return JS_TRUE;
}
/***
* <method name="enable">
* <function>
* <arg name="Switch" type="Boolean" />
* </function>
* <function>
* <arg name="Index" type="Integer">
* The zero-based index of a button
* </arg>
* <arg name="Switch" type="Boolean" />
* </function>
* <desc>
* Enables/Disables the button at the given index.
* See @wxRadioBoxItem @wxRadioBoxItem#enable.
* </desc>
* </method>
*/
JSBool RadioBox::enable(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
wxRadioBox *p = GetPrivate(cx, obj);
if ( p == NULL )
return JS_FALSE;
if ( argc == 1 ) // The prototype method enable
{
bool sw;
if ( FromJS(cx, argv[0], sw) )
{
p->Enable(sw);
return JS_TRUE;
}
}
else if ( argc == 2 )
{
int idx;
bool sw;
if ( FromJS(cx, argv[0], idx)
&& FromJS(cx, argv[1], sw) )
{
p->Enable(idx, sw);
return JS_TRUE;
}
}
return JS_FALSE;
}
/***
* <method name="show">
* <function>
* <arg name="Switch" type="Boolean" />
* </function>
* <function>
* <arg name="Index" type="Integer">
* The zero-based index of a button
* </arg>
* <arg name="Switch" type="Boolean" />
* </function>
* <desc>
* Shows/Hides the button at the given index.
* See @wxRadioBoxItem @wxRadioBoxItem#enable.
* </desc>
* </method>
*/
JSBool RadioBox::show(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
wxRadioBox *p = GetPrivate(cx, obj);
if ( p == NULL )
return JS_FALSE;
if ( argc == 1 ) // The prototype method enable
{
bool sw;
if ( FromJS(cx, argv[0], sw) )
{
p->Show(sw);
return JS_TRUE;
}
}
else if ( argc == 2 )
{
int idx;
bool sw;
if ( FromJS(cx, argv[0], idx)
&& FromJS(cx, argv[1], sw) )
{
p->Show(idx, sw);
return JS_TRUE;
}
}
return JS_FALSE;
}
/***
* <events>
* <event name="onRadioBox">
* Called when a radio button is clicked. The type of the argument that your handler receives
* is @wxCommandEvent.
* </event>
* </events>
*/
void RadioBox::OnRadioBox(wxCommandEvent &event)
{
PrivCommandEvent::Fire<CommandEvent>(this, event, "onRadioBox");
}
BEGIN_EVENT_TABLE(RadioBox, wxRadioBox)
EVT_RADIOBOX(-1, RadioBox::OnRadioBox)
END_EVENT_TABLE()

View File

@ -1,91 +0,0 @@
/*
* wxJavaScript - radiobox.h
*
* Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project
*
* Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net
*
* This library is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or
* (at your option) any later version.
*
* This library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
* License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
* USA.
*
* $Id: radiobox.h 598 2007-03-07 20:13:28Z fbraem $
*/
#ifndef _WXJSRadioBox_H
#define _WXJSRadioBox_H
/////////////////////////////////////////////////////////////////////////////
// Name: RadioBox.h
// Purpose: RadioBox ports wxRadioBox to JavaScript
// Author: Franky Braem
// Modified by:
// Created: 17.08.2002
// Copyright: (c) 2001-2002 Franky Braem
// Licence: LGPL
/////////////////////////////////////////////////////////////////////////////
namespace wxjs
{
namespace gui
{
class RadioBox : public wxRadioBox
, public ApiWrapper<RadioBox, wxRadioBox>
, public Object
{
public:
/**
* Constructor
*/
RadioBox(JSContext *cx, JSObject *obj);
/**
* Destructor
*/
virtual ~RadioBox();
static bool GetProperty(wxRadioBox *p, JSContext *cx, JSObject *obj, int id, jsval *vp);
static bool SetProperty(wxRadioBox *p, JSContext *cx, JSObject *obj, int id, jsval *vp);
static wxRadioBox* Construct(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, bool constructing);
// Empty to avoid deleting. (It will be deleted by wxWindows).
static void Destruct(JSContext *cx, wxRadioBox *p)
{
}
static JSBool setString(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval);
static JSBool findString(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval);
static JSBool enable(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval);
static JSBool show(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval);
WXJS_DECLARE_PROPERTY_MAP()
WXJS_DECLARE_CONSTANT_MAP()
WXJS_DECLARE_METHOD_MAP()
/**
* Property Ids.
*/
enum
{
P_SELECTION
, P_STRING_SELECTION
, P_ITEM
, P_COUNT
};
void OnRadioBox(wxCommandEvent &event);
DECLARE_EVENT_TABLE()
};
}; // namespace gui
}; // namespace wxjs
#endif //_WXJSRadioBox_H

View File

@ -1,137 +0,0 @@
#include "precompiled.h"
// radioboxit.cpp
#ifndef WX_PRECOMP
#include <wx/wx.h>
#endif
#include "../../common/main.h"
#include "../../common/index.h"
#include "radiobox.h"
#include "radioboxit.h"
using namespace wxjs;
using namespace wxjs::gui;
/***
* <file>control/radioboxit</file>
* <module>gui</module>
* <class name="wxRadioBoxItem">
* wxRadioBoxItem is a helper class for working with items of @wxRadioBox.
* There's no corresponding class in wxWidgets.
* See wxRadioBox @wxRadioBox#item property.
* </class>
*/
WXJS_INIT_CLASS(RadioBoxItem, "wxRadioBoxItem", 0)
/***
* <properties>
* <property name="enable" type="Boolean">
* Enables/Disables the button.
* </property>
* <property name="selected" type="Boolean">
* Returns true when the item is selected or sets the selection
* </property>
* <property name="show" type="Boolean">
* Hides or shows the item.
* </property>
* <property name="string" type="String">
* Get/Set the label of the button.
* </property>
* </properties>
*/
WXJS_BEGIN_PROPERTY_MAP(RadioBoxItem)
WXJS_PROPERTY(P_ENABLE, "enable")
WXJS_PROPERTY(P_STRING, "string")
WXJS_PROPERTY(P_SELECTED, "selected")
WXJS_PROPERTY(P_SHOW, "show")
WXJS_END_PROPERTY_MAP()
bool RadioBoxItem::GetProperty(Index *p, JSContext *cx, JSObject *obj, int id, jsval *vp)
{
JSObject *parent = JS_GetParent(cx, obj);
wxASSERT_MSG(parent != NULL, wxT("No parent found for RadioBoxItem"));
wxRadioBox *radiobox = RadioBox::GetPrivate(cx, parent);
if ( radiobox == NULL )
return false;
// When id is greater then 0, then we have an array index.
if ( id >= 0 )
{
if ( id < radiobox->GetCount() )
{
// Set the item index and don't forget to return ourselves.
p->SetIndex(id);
*vp = OBJECT_TO_JSVAL(obj);
}
}
else
{
// A negative index means a defined property.
int idx = p->GetIndex();
if ( idx < radiobox->GetCount() ) // To be sure
{
switch (id)
{
case P_STRING:
*vp = ToJS(cx, radiobox->wxControl::GetLabel());
break;
case P_SELECTED:
*vp = ToJS(cx, radiobox->GetSelection() == idx);
break;
}
}
}
return true;
}
bool RadioBoxItem::SetProperty(Index *p, JSContext *cx, JSObject *obj, int id, jsval *vp)
{
JSObject *parent = JS_GetParent(cx, obj);
wxASSERT_MSG(parent != NULL, wxT("No parent found for RadioBoxItem"));
wxRadioBox *radiobox = RadioBox::GetPrivate(cx, parent);
if ( radiobox == NULL )
return false;
int idx = p->GetIndex();
if ( idx < radiobox->GetCount() ) // To be sure
{
switch (id)
{
case P_STRING:
{
wxString str;
FromJS(cx, *vp, str);
radiobox->SetString(idx, str);
break;
}
case P_SELECTED:
{
bool value;
if ( FromJS(cx, *vp, value)
&& value )
radiobox->SetSelection(idx);
break;
}
case P_ENABLE:
{
bool value;
if ( FromJS(cx, *vp, value) )
radiobox->Enable(idx, value);
break;
}
case P_SHOW:
{
bool value;
if ( FromJS(cx, *vp, value) )
radiobox->Show(idx, value);
break;
}
}
}
return true;
}

View File

@ -1,51 +0,0 @@
/*
* wxJavaScript - radioboxit.h
*
* Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project
*
* Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net
*
* This library is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or
* (at your option) any later version.
*
* This library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
* License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
* USA.
*
* $Id: radioboxit.h 598 2007-03-07 20:13:28Z fbraem $
*/
#ifndef _wxjs_gui_radioboxit_h
#define _wxjs_gui_radioboxit_h
namespace wxjs
{
namespace gui
{
class RadioBoxItem : public ApiWrapper<RadioBoxItem, 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);
WXJS_DECLARE_PROPERTY_MAP()
enum
{
P_ENABLE = WXJS_START_PROPERTY_ID
, P_STRING
, P_SELECTED
, P_SHOW
};
};
}; // namespace gui
}; // namespace wxjs
#endif // _wxjs_gui_radioboxit_h

View File

@ -1,213 +0,0 @@
#include "precompiled.h"
/*
* wxJavaScript - radiobtn.cpp
*
* Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project
*
* Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net
*
* This library is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or
* (at your option) any later version.
*
* This library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
* License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
* USA.
*
* $Id: radiobtn.cpp 598 2007-03-07 20:13:28Z fbraem $
*/
// radiobtn.cpp
#ifndef WX_PRECOMP
#include <wx/wx.h>
#endif
#include "../../common/main.h"
#include "../event/evthand.h"
#include "../event/jsevent.h"
#include "../event/command.h"
#include "../misc/size.h"
#include "../misc/point.h"
#include "../misc/validate.h"
#include "radiobtn.h"
#include "window.h"
using namespace wxjs;
using namespace wxjs::gui;
RadioButton::RadioButton(JSContext *cx, JSObject *obj)
: wxRadioButton()
, Object(obj, cx)
{
PushEventHandler(new EventHandler(this));
}
RadioButton::~RadioButton()
{
PopEventHandler(true);
}
/***
* <file>control/radiobtn</file>
* <module>gui</module>
* <class name="wxRadioButton" prototype="@wxControl">
* A radio button item is a button which usually denotes one of several mutually exclusive
* options. It has a text label next to a (usually) round button.
* <br /><br />You can create a group of mutually-exclusive radio buttons by specifying
* wxRadioButton.GROUP for the first in the group. The group ends when another radio button
* group is created, or there are no more radio buttons.
* See also @wxRadioBox.
* </class>
*/
WXJS_INIT_CLASS(RadioButton, "wxRadioButton", 3)
/***
* <properties>
* <property name="value" type="Boolean">
* Select/Deselect the button
* </property>
* </properties>
*/
WXJS_BEGIN_PROPERTY_MAP(RadioButton)
WXJS_PROPERTY(P_VALUE, "value")
WXJS_END_PROPERTY_MAP()
bool RadioButton::GetProperty(wxRadioButton *p, JSContext *cx, JSObject *obj, int id, jsval *vp)
{
if (id == P_VALUE )
{
*vp = ToJS(cx, p->GetValue());
}
return true;
}
bool RadioButton::SetProperty(wxRadioButton *p, JSContext *cx, JSObject *obj, int id, jsval *vp)
{
if ( id == P_VALUE )
{
bool value;
if ( FromJS(cx, *vp, value) )
p->SetValue(value);
}
return true;
}
/***
* <constants>
* <type name="Styles">
* <constant name="GROUP">Marks the beginning of a new group of radio buttons.</constant>
* </type>
* </constants>
*/
WXJS_BEGIN_CONSTANT_MAP(RadioButton)
WXJS_CONSTANT(wxRB_, GROUP)
WXJS_END_CONSTANT_MAP()
/***
* <ctor>
* <function>
* <arg name="Parent" type="@wxWindow">
* The parent of wxRadioButton.
* </arg>
* <arg name="Id" type="Integer">
* An window identifier. Use -1 when you don't need it.
* </arg>
* <arg name="Label" type="String">
* The title of the RadioButton.
* </arg>
* <arg name="Position" type="@wxPoint" default="wxDefaultPosition">
* The position of the RadioButton control on the given parent.
* </arg>
* <arg name="Size" type="@wxSize" default="wxDefaultSize">
* The size of the RadioButton control.
* </arg>
* <arg name="Style" type="Integer" default="0">
* The wxRadioButton style.
* </arg>
* <arg name="Validator" type="@wxValidator" default="null" />
* </function>
* <desc>
* Constructs a new wxRadioButton object.
* </desc>
* </ctor>
*/
wxRadioButton* RadioButton::Construct(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, bool constructing)
{
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 )
break;
case 6:
if ( ! FromJS(cx, argv[5], style) )
break;
// Fall through
case 5:
size = Size::GetPrivate(cx, argv[4]);
if ( size == NULL )
break;
// Fall through
case 4:
pt = Point::GetPrivate(cx, argv[3]);
if ( pt == NULL )
break;
// Fall through
default:
wxString text;
FromJS(cx, argv[2], text);
int id;
if ( ! FromJS(cx, argv[1], id) )
break;
wxWindow *parent = Window::GetPrivate(cx, argv[0]);
if ( parent == NULL )
break;
Object *wxjsParent = dynamic_cast<Object *>(parent);
JS_SetParent(cx, obj, wxjsParent->GetObject());
RadioButton *p = new RadioButton(cx, obj);
p->Create(parent, id, text, *pt, *size, style, *val);
return p;
}
return NULL;
}
/***
* <events>
* <event name="onRadioButton">
* Called when a radio button is clicked. The type of the argument that your handler receives
* is @wxCommandEvent.
* </event>
* </events>
*/
void RadioButton::OnRadioButton(wxCommandEvent &event)
{
PrivCommandEvent::Fire<CommandEvent>(this, event, "onRadioButton");
}
BEGIN_EVENT_TABLE(RadioButton, wxRadioButton)
EVT_RADIOBUTTON(-1, RadioButton::OnRadioButton)
END_EVENT_TABLE()

View File

@ -1,83 +0,0 @@
/*
* wxJavaScript - radiobtn.h
*
* Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project
*
* Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net
*
* This library is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or
* (at your option) any later version.
*
* This library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
* License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
* USA.
*
* $Id: radiobtn.h 598 2007-03-07 20:13:28Z fbraem $
*/
#ifndef _WXJSRadioButton_H
#define _WXJSRadioButton_H
/////////////////////////////////////////////////////////////////////////////
// Name: radiobtn.h
// Purpose: RadioButton ports wxRadioButton to JavaScript
// Author: Franky Braem
// Modified by:
// Created: 19.08.2002
// Copyright: (c) 2001-2002 Franky Braem
// Licence: LGPL
/////////////////////////////////////////////////////////////////////////////
namespace wxjs
{
namespace gui
{
class RadioButton : public wxRadioButton
, public ApiWrapper<RadioButton, wxRadioButton>
, public Object
{
public:
/**
* Constructor
*/
RadioButton(JSContext *cx, JSObject *obj);
/**
* Destructor
*/
virtual ~RadioButton();
static bool GetProperty(wxRadioButton *p, JSContext *cx, JSObject *obj, int id, jsval *vp);
static bool SetProperty(wxRadioButton *p, JSContext *cx, JSObject *obj, int id, jsval *vp);
static wxRadioButton* Construct(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, bool constructing);
// Empty to avoid deleting. (It will be deleted by wxWindows).
static void Destruct(JSContext *cx, wxRadioButton *p)
{
}
WXJS_DECLARE_PROPERTY_MAP()
WXJS_DECLARE_CONSTANT_MAP()
/**
* Property Ids.
*/
enum
{
P_VALUE
};
void OnRadioButton(wxCommandEvent &event);
DECLARE_EVENT_TABLE()
};
}; // namespace gui
}; // namespace wxjs
#endif //_WXJSRadioButton_H

View File

@ -1,525 +0,0 @@
#include "precompiled.h"
/*
* wxJavaScript - scrollwnd.cpp
*
* Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project
*
* Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net
*
* This library is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or
* (at your option) any later version.
*
* This library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
* License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
* USA.
*
* $Id: scrollwnd.cpp 598 2007-03-07 20:13:28Z fbraem $
*/
#ifndef WX_PRECOMP
#include <wx/wx.h>
#endif
/***
* <file>control/scrolwin</file>
* <module>gui</module>
* <class name="wxScrolledWindow" prototype="@wxPanel">
* The wxScrolledWindow class manages scrolling for its client area, transforming
* the coordinates according to the scrollbar positions, and setting the scroll positions,
* thumb sizes and ranges according to the area in view.
* </class>
*/
#include "../../common/main.h"
#include "../misc/size.h"
#include "../misc/point.h"
#include "scrollwnd.h"
#include "window.h"
using namespace wxjs;
using namespace wxjs::gui;
WXJS_INIT_CLASS(ScrolledWindow, "wxScrolledWindow", 1)
ScrolledWindow::ScrolledWindow(JSContext *cx, JSObject *obj)
: wxScrolledWindow()
, Object(obj, cx)
{
}
ScrolledWindow::~ScrolledWindow()
{
}
/***
* <properties>
* <property name="retained" type="Boolean" readonly="Y">
* Motif only: true if the window has a backing bitmap
* </property>
* <property name="scrollPixelsPerUnit" type="Array" readonly="Y">
* Get the number of pixels per scroll unit (line), in each direction, as set
* by @wxScrolledWindow#setScrollbars. A value of zero indicates no scrolling in that direction.
* </property>
* <property name="viewStart" type="Array" readonly="Y">
* Get the position at which the visible portion of the window starts.
* </property>
* <property name="virtualSize" type="Array" readonly="Y">
* Gets the size in device units of the scrollable window area (as opposed to the client size,
* which is the area of the window currently visible)
* </property>
* </properties>
*/
WXJS_BEGIN_PROPERTY_MAP(ScrolledWindow)
WXJS_READONLY_PROPERTY(P_RETAINED, "retained")
WXJS_READONLY_PROPERTY(P_SCROLL_PIXELS_PER_UNIT, "scrollPixelsPerUnit")
WXJS_READONLY_PROPERTY(P_VIEW_START, "viewStart")
WXJS_READONLY_PROPERTY(P_VIRTUAL_SIZE, "virtualSize")
WXJS_END_PROPERTY_MAP()
bool ScrolledWindow::GetProperty(wxScrolledWindow *p, JSContext *cx, JSObject* WXUNUSED(obj), int id, jsval *vp)
{
switch (id)
{
case P_RETAINED:
*vp = ToJS(cx, p->IsRetained());
break;
case P_SCROLL_PIXELS_PER_UNIT:
{
int x = 0;
int y = 0;
p->GetScrollPixelsPerUnit(&x, &y);
JSObject *objArr = JS_NewArrayObject(cx, 2, NULL);
*vp = OBJECT_TO_JSVAL(objArr);
jsval element = ToJS(cx, x);
JS_SetElement(cx, objArr, 0, &element);
element = ToJS(cx, y);
JS_SetElement(cx, objArr, 1, &element);
}
case P_VIEW_START:
{
int x = 0;
int y = 0;
p->GetViewStart(&x, &y);
JSObject *objArr = JS_NewArrayObject(cx, 2, NULL);
*vp = OBJECT_TO_JSVAL(objArr);
jsval element = ToJS(cx, x);
JS_SetElement(cx, objArr, 0, &element);
element = ToJS(cx, y);
JS_SetElement(cx, objArr, 1, &element);
}
case P_VIRTUAL_SIZE:
{
int x = 0;
int y = 0;
p->GetVirtualSize(&x, &y);
JSObject *objArr = JS_NewArrayObject(cx, 2, NULL);
*vp = OBJECT_TO_JSVAL(objArr);
jsval element = ToJS(cx, x);
JS_SetElement(cx, objArr, 0, &element);
element = ToJS(cx, y);
JS_SetElement(cx, objArr, 1, &element);
}
}
return true;
}
/***
* <ctor>
* <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="wxWindow.HSCROLL + wxWindow.VSCROLL">The style of the control</arg>
* </function>
* <desc>
* Constructs a new wxScrolledWindow object.
* </desc>
* </ctor>
*/
wxScrolledWindow* ScrolledWindow::Construct(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, bool WXUNUSED(constructing))
{
const wxPoint *pt = &wxDefaultPosition;
const wxSize *size = &wxDefaultSize;
int style = wxHSCROLL + wxVSCROLL;
int id = -1;
if ( argc > 5 )
argc = 5;
switch(argc)
{
case 5:
if ( ! FromJS(cx, argv[4], style) )
break;
// Walk through
case 4:
size = Size::GetPrivate(cx, argv[3]);
if ( size == NULL )
break;
// Walk through
case 3:
pt = Point::GetPrivate(cx, argv[2]);
if ( pt == NULL )
break;
// Walk through
case 2:
if ( ! FromJS(cx, argv[1], id) )
break;
// Walk through
default:
wxWindow *parent = Window::GetPrivate(cx, argv[0]);
if ( parent == NULL )
return NULL;
Object *wxjsParent = dynamic_cast<Object *>(parent);
JS_SetParent(cx, obj, wxjsParent->GetObject());
ScrolledWindow *p = new ScrolledWindow(cx, obj);
p->Create(parent, id, *pt, *size, style);
return p;
}
return NULL;
}
WXJS_BEGIN_METHOD_MAP(ScrolledWindow)
WXJS_METHOD("calcScrolledPosition", calcScrolledPosition, 2)
WXJS_METHOD("calcUnscrolledPosition", calcUnscrolledPosition, 2)
WXJS_METHOD("enableScrolling", enableScrolling, 2)
WXJS_METHOD("scroll", scroll, 2)
WXJS_METHOD("setScrollbars", setScrollbars, 4)
WXJS_METHOD("setScrollRate", setScrollRate, 2)
WXJS_METHOD("setTargetWindow", setTargetWindow, 1)
WXJS_END_METHOD_MAP()
/***
* <method name="calcScrolledPosition">
* <function returns="Array">
* <arg name="x" type="Integer" />
* <arg name="y" type="Integer" />
* </function>
* <desc>
* Translates the logical coordinates to the device ones.
* </desc>
* </method>
*/
JSBool ScrolledWindow::calcScrolledPosition(JSContext *cx, JSObject *obj, uintN WXUNUSED(argc), jsval *argv, jsval *rval)
{
wxScrolledWindow *p = GetPrivate(cx, obj);
if ( p == NULL )
return JS_FALSE;
int x = 0;
int y = 0;
int xx = 0;
int yy = 0;
if ( FromJS(cx, argv[0], x)
&& FromJS(cx, argv[1], y) )
{
p->CalcScrolledPosition(x, y, &xx, &yy);
}
JSObject *objArr = JS_NewArrayObject(cx, 2, NULL);
*rval = OBJECT_TO_JSVAL(objArr);
jsval element = ToJS(cx, xx);
JS_SetElement(cx, objArr, 0, &element);
element = ToJS(cx, yy);
JS_SetElement(cx, objArr, 1, &element);
return JS_TRUE;
}
/***
* <method name="calcUnscrolledPosition">
* <function returns="Array">
* <arg name="x" type="Integer" />
* <arg name="y" type="Integer" />
* </function>
* <desc>
* Translates the device coordinates to the logical ones.
* </desc>
* </method>
*/
JSBool ScrolledWindow::calcUnscrolledPosition(JSContext *cx, JSObject *obj, uintN WXUNUSED(argc), jsval *argv, jsval *rval)
{
wxScrolledWindow *p = GetPrivate(cx, obj);
if ( p == NULL )
return JS_FALSE;
int x = 0;
int y = 0;
int xx = 0;
int yy = 0;
if ( FromJS(cx, argv[0], x)
&& FromJS(cx, argv[1], y) )
{
p->CalcUnscrolledPosition(x, y, &xx, &yy);
}
JSObject *objArr = JS_NewArrayObject(cx, 2, NULL);
*rval = OBJECT_TO_JSVAL(objArr);
jsval element = ToJS(cx, xx);
JS_SetElement(cx, objArr, 0, &element);
element = ToJS(cx, yy);
JS_SetElement(cx, objArr, 1, &element);
return JS_TRUE;
}
/***
* <method name="enableScrolling">
* <function>
* <arg name="xScrolling" type="Boolean" />
* <arg name="yScrolling" type="Boolean" />
* </function>
* <desc>
* Enable or disable physical scrolling in the given direction.
* Physical scrolling is the physical transfer of bits up or down the screen when a scroll event occurs.
* If the application scrolls by a variable amount (e.g. if there are different font sizes)
* then physical scrolling will not work, and you should switch it off. Note that you will have
* to reposition child windows yourself, if physical scrolling is disabled.
* <blockquote>
* Physical scrolling may not be available on all platforms. Where it is available, it is enabled by default.
* </blockquote>
* </desc>
* </method>
*/
JSBool ScrolledWindow::enableScrolling(JSContext *cx, JSObject *obj, uintN WXUNUSED(argc), jsval *argv, jsval* WXUNUSED(rval))
{
wxScrolledWindow *p = GetPrivate(cx, obj);
if ( p == NULL )
return JS_FALSE;
bool xScrolling = true;
bool yScrolling = true;
if ( FromJS(cx, argv[0], xScrolling)
&& FromJS(cx, argv[1], yScrolling) )
{
p->EnableScrolling(xScrolling, yScrolling);
}
return JS_TRUE;
}
/***
* <method name="getView">
* <function returns="Array" />
* <desc>
* Get the number of pixels per scroll unit (line), in each direction, as set
* by @wxScrolledWindow#setScrollbars. A value of zero indicates no scrolling in that direction.
* </desc>
* </method>
*/
JSBool ScrolledWindow::getScrollPixelsPerUnit(JSContext *cx, JSObject *obj, uintN WXUNUSED(argc), jsval* WXUNUSED(argv), jsval *rval)
{
wxScrolledWindow *p = GetPrivate(cx, obj);
if ( p == NULL )
return JS_FALSE;
int x = 0;
int y = 0;
p->GetScrollPixelsPerUnit(&x, &y);
JSObject *objArr = JS_NewArrayObject(cx, 2, NULL);
*rval = OBJECT_TO_JSVAL(objArr);
jsval element = ToJS(cx, x);
JS_SetElement(cx, objArr, 0, &element);
element = ToJS(cx, y);
JS_SetElement(cx, objArr, 1, &element);
return JS_TRUE;
}
/***
* <method name="scroll">
* <function>
* <arg name="x" type="Integer">The x position to scroll to</arg>
* <arg name="y" type="Integer">The y position to scroll to</arg>
* </function>
* <desc>
* Scrolls a window so the view start is at the given point.
* <blockquote>
* The positions are in scroll units, not pixels, so to convert to pixels you will have
* to multiply by the number of pixels per scroll increment. If either parameter is -1,
* that position will be ignored (no change in that direction).
* </blockquote>
* </desc>
* </method>
*/
JSBool ScrolledWindow::scroll(JSContext *cx, JSObject *obj, uintN WXUNUSED(argc), jsval *argv, jsval* WXUNUSED(rval))
{
wxScrolledWindow *p = GetPrivate(cx, obj);
if ( p == NULL )
return JS_FALSE;
int x = 0;
int y = 0;
if ( FromJS(cx, argv[0], x)
&& FromJS(cx, argv[1], y) )
{
p->Scroll(x, y);
}
return JS_TRUE;
}
/***
* <method name="setScrollbars">
* <function>
* <arg name="pixelsPerUnitX" type="Integer">
* Pixels per scroll unit in the horizontal direction.
* </arg>
* <arg name="pixelsPerUnitY" type="Integer">
* Pixels per scroll unit in the vertical direction.
* </arg>
* <arg name="noUnitsX" type="Integer">
* Number of units in the horizontal direction.
* </arg>
* <arg name="noUnitsY" type="Integer">
* Number of units in the vertical direction.
* </arg>
* <arg name="xPos" type="Integer" default="0">
* Position to initialize the scrollbars in the horizontal direction, in scroll units.
* </arg>
* <arg name="yPos" type="Integer" default="0">
* Position to initialize the scrollbars in the vertical direction, in scroll units.
* </arg>
* <arg name="noRefresh" type="Integer" default="false">
* Will not refresh window if true.
* </arg>
* </function>
* <desc>
* Sets up vertical and/or horizontal scrollbars.
* <blockquote>
* The first pair of parameters give the number of pixels per 'scroll step', i.e. amount moved when the up or down scroll arrows are pressed. The second pair gives the length of scrollbar in scroll steps, which sets the size of the virtual window.
* xPos and yPos optionally specify a position to scroll to immediately.
* For example, the following gives a window horizontal and vertical scrollbars with 20 pixels per scroll step, and a size of 50 steps (1000 pixels) in each direction.
* <code class="whjs">
* window.setScrollbars(20, 20, 50, 50);
* </code>
* wxScrolledWindow manages the page size itself, using the current client window size as the page size.
* </blockquote>
* </desc>
* </method>
*/
JSBool ScrolledWindow::setScrollbars(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval* WXUNUSED(rval))
{
wxScrolledWindow *p = GetPrivate(cx, obj);
if ( p == NULL )
return JS_FALSE;
int pixelsPerUnitX;
int pixelsPerUnitY;
int noUnitsX;
int noUnitsY;
int xPos = 0;
int yPos = 0;
bool noRefresh = false;
if ( argc > 7 )
argc = 7;
switch(argc)
{
case 7:
if ( ! FromJS(cx, argv[6], noRefresh) )
break;
// fall trough
case 6:
if ( ! FromJS(cx, argv[5], yPos) )
break;
// fall through
case 5:
if ( ! FromJS(cx, argv[4], xPos) )
break;
// fall through
default:
{
if ( FromJS(cx, argv[0], pixelsPerUnitX)
&& FromJS(cx, argv[1], pixelsPerUnitY)
&& FromJS(cx, argv[2], noUnitsX)
&& FromJS(cx, argv[3], noUnitsY) )
{
p->SetScrollbars(pixelsPerUnitX, pixelsPerUnitY, noUnitsX, noUnitsY, xPos, yPos, noRefresh);
}
}
}
return JS_TRUE;
}
/***
* <method name="setScrollRate">
* <function>
* <arg name="xStep" type="Integer" />
* <arg name="yStep" type="Integer" />
* </function>
* <desc>
* Set the horizontal and vertical scrolling increment only.
* See the pixelsPerUnit parameter in @wxScrolledWindow#setScrollbars.
* </desc>
* </method>
*/
JSBool ScrolledWindow::setScrollRate(JSContext *cx, JSObject *obj, uintN WXUNUSED(argc), jsval *argv, jsval* WXUNUSED(rval))
{
wxScrolledWindow *p = GetPrivate(cx, obj);
if ( p == NULL )
return JS_FALSE;
int x = 0;
int y = 0;
if ( FromJS(cx, argv[0], x)
&& FromJS(cx, argv[1], y) )
{
p->SetScrollRate(x, y);
}
return JS_TRUE;
}
/***
* <method name="setTargetWindow">
* <function>
* <arg name="Window" type="@wxWindow" />
* </function>
* <desc>
* Call this function to tell wxScrolledWindow to perform the actual scrolling on a different window (and not on itself).
* </desc>
* </method>
*/
JSBool ScrolledWindow::setTargetWindow(JSContext *cx, JSObject *obj, uintN WXUNUSED(argc), jsval *argv, jsval* WXUNUSED(rval))
{
wxScrolledWindow *p = GetPrivate(cx, obj);
if ( p == NULL )
return JS_FALSE;
wxWindow *win = Window::GetPrivate(cx, argv[0]);
if ( win )
{
p->SetTargetWindow(win);
}
return JS_TRUE;
}

View File

@ -1,83 +0,0 @@
/*
* wxJavaScript - scrollwnd.h
*
* Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project
*
* Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net
*
* This library is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or
* (at your option) any later version.
*
* This library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
* License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
* USA.
*
* $Id: scrollwnd.h 598 2007-03-07 20:13:28Z fbraem $
*/
#ifndef _WXJSScrolledWindow_H
#define _WXJSScrolledWindow_H
#include <wx/scrolwin.h>
namespace wxjs
{
namespace gui
{
class ScrolledWindow : public wxScrolledWindow
, public ApiWrapper<ScrolledWindow, wxScrolledWindow>
, public Object
{
public:
/**
* Constructor
*/
ScrolledWindow(JSContext *cx, JSObject *obj);
/**
* Destructor
*/
virtual ~ScrolledWindow();
static bool GetProperty(wxScrolledWindow *p, JSContext *cx, JSObject *obj, int id, jsval *vp);
static wxScrolledWindow* Construct(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, bool constructing);
// Empty to avoid deleting. (It will be deleted by wxWidgets).
static void Destruct(JSContext* WXUNUSED(cx), wxScrolledWindow* WXUNUSED(p))
{
}
WXJS_DECLARE_PROPERTY_MAP()
/**
* Property Ids.
*/
enum
{
P_SCROLL_PIXELS_PER_UNIT = WXJS_START_PROPERTY_ID
, P_VIEW_START
, P_VIRTUAL_SIZE
, P_RETAINED
};
WXJS_DECLARE_METHOD_MAP()
static JSBool calcScrolledPosition(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval);
static JSBool calcUnscrolledPosition(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval);
static JSBool enableScrolling(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval);
static JSBool getScrollPixelsPerUnit(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval);
static JSBool scroll(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval);
static JSBool setScrollbars(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval);
static JSBool setScrollRate(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval);
static JSBool setTargetWindow(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval);
};
}; // namespace gui
}; //namespace wxjs
#endif //_WXJSScrolledWindow_H

View File

@ -1,603 +0,0 @@
#include "precompiled.h"
/*
* wxJavaScript - slider.cpp
*
* Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project
*
* Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net
*
* This library is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or
* (at your option) any later version.
*
* This library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
* License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
* USA.
*
* $Id: slider.cpp 598 2007-03-07 20:13:28Z fbraem $
*/
// slider.cpp
#ifndef WX_PRECOMP
#include <wx/wx.h>
#endif
#include "../../common/main.h"
#include "../event/evthand.h"
#include "../event/jsevent.h"
#include "../event/command.h"
#include "../event/scroll.h"
#include "../misc/size.h"
#include "../misc/point.h"
#include "../misc/validate.h"
#include "slider.h"
#include "window.h"
using namespace wxjs;
using namespace wxjs::gui;
Slider::Slider(JSContext *cx, JSObject *obj)
: wxSlider()
, Object(obj, cx)
{
PushEventHandler(new EventHandler(this));
}
Slider::~Slider()
{
PopEventHandler(true);
}
/***
* <file>control/slider</file>
* <module>gui</module>
* <class name="wxSlider" prototype="@wxControl">
* A slider is a control with a handle which can be pulled back and forth to change the value.
* In Windows versions below Windows 95, a scrollbar is used to simulate the slider.
* In Windows 95, the track bar control is used.
* See also @wxScrollEvent.
* </class>
*/
WXJS_INIT_CLASS(Slider, "wxSlider", 5)
/***
* <properties>
* <property name="lineSize" type="Integer">
* Get/Set the line size
* </property>
* <property name="max" type="Integer">
* Get/Set the maximum value
* </property>
* <property name="min" type="Integer">
* Get/Set the minimum value
* </property>
* <property name="pageSize" type="Integer">
* Get/Set the pagesize
* </property>
* <property name="selEnd" type="Integer">
* Get/Set the end selection point
* </property>
* <property name="selStart" type="Integer">
* Get/Set the start selection point
* </property>
* <property name="value" type="Integer">
* Get/Set the current value
* </property>
* </properties>
*/
WXJS_BEGIN_PROPERTY_MAP(Slider)
WXJS_PROPERTY(P_LINESIZE, "lineSize")
WXJS_PROPERTY(P_MAX, "max")
WXJS_PROPERTY(P_MIN, "min")
WXJS_PROPERTY(P_PAGESIZE, "pageSize")
WXJS_PROPERTY(P_SEL_END, "selEnd")
WXJS_PROPERTY(P_SEL_START, "selStart")
WXJS_PROPERTY(P_THUMB_LENGTH, "thumbLength")
WXJS_PROPERTY(P_VALUE, "value")
WXJS_END_PROPERTY_MAP()
WXJS_BEGIN_METHOD_MAP(Slider)
WXJS_METHOD("clearSel", clearSel, 0)
WXJS_METHOD("setRange", setRange, 2)
WXJS_METHOD("setSelection", setSelection, 2)
WXJS_METHOD("setTickFreq", setTickFreq, 2)
WXJS_END_METHOD_MAP()
/***
* <constants>
* <type name="Styles">
* <constant name="HORIZONTAL">
* Displays the slider horizontally.
* </constant>
* <constant name="VERTICAL">
* Displays the slider vertically.
* </constant>
* <constant name="AUTOTICKS">
* Displays tick marks.
* </constant>
* <constant name="LABELS">
* Displays minimum, maximum and value labels. (NB: only displays the current value label under wxGTK)
* </constant>
* <constant name="LEFT">
* Displays ticks on the left, if a vertical slider.
* </constant>
* <constant name="RIGHT">
* Displays ticks on the right, if a vertical slider.
* </constant>
* <constant name="TOP">
* Displays ticks on the top, if a horizontal slider.
* </constant>
* <constant name="SELRANGE">
* Allows the user to select a range on the slider. Windows 95 only.
* </constant>
* </type>
* </constants>
*/
WXJS_BEGIN_CONSTANT_MAP(Slider)
WXJS_CONSTANT(wxSL_, HORIZONTAL)
WXJS_CONSTANT(wxSL_, VERTICAL)
WXJS_CONSTANT(wxSL_, TICKS)
WXJS_CONSTANT(wxSL_, AUTOTICKS)
WXJS_CONSTANT(wxSL_, LABELS)
WXJS_CONSTANT(wxSL_, LEFT)
WXJS_CONSTANT(wxSL_, TOP)
WXJS_CONSTANT(wxSL_, RIGHT)
WXJS_CONSTANT(wxSL_, BOTTOM)
WXJS_CONSTANT(wxSL_, BOTH)
WXJS_CONSTANT(wxSL_, SELRANGE)
WXJS_END_CONSTANT_MAP()
bool Slider::GetProperty(wxSlider *p, JSContext *cx, JSObject *obj, int id, jsval *vp)
{
switch (id)
{
case P_LINESIZE:
*vp = ToJS(cx, p->GetLineSize());
break;
case P_MAX:
*vp = ToJS(cx, p->GetMax());
break;
case P_MIN:
*vp = ToJS(cx, p->GetMin());
break;
case P_PAGESIZE:
*vp = ToJS(cx, p->GetPageSize());
break;
case P_SEL_END:
*vp = ToJS(cx, p->GetSelEnd());
break;
case P_SEL_START:
*vp = ToJS(cx, p->GetSelStart());
break;
case P_THUMB_LENGTH:
*vp = ToJS(cx ,p->GetThumbLength());
break;
case P_VALUE:
*vp = ToJS(cx, p->GetValue());
break;
}
return true;
}
bool Slider::SetProperty(wxSlider *p, JSContext *cx, JSObject *obj, int id, jsval *vp)
{
switch (id)
{
case P_LINESIZE:
{
int value;
if ( FromJS(cx, *vp, value) )
p->SetLineSize(value);
break;
}
case P_MAX:
{
int value;
if ( FromJS(cx, *vp, value) )
p->SetRange(p->GetMin(), value);
break;
}
case P_MIN:
{
int value;
if ( FromJS(cx, *vp, value) )
p->SetRange(value, p->GetMax());
break;
}
case P_PAGESIZE:
{
int value;
if ( FromJS(cx, *vp, value) )
p->SetPageSize(value);
break;
}
case P_SEL_END:
{
int value;
if ( FromJS(cx, *vp, value) )
p->SetSelection(p->GetSelStart(), value);
break;
}
case P_SEL_START:
{
int value;
if ( FromJS(cx, *vp, value) )
p->SetSelection(value, p->GetSelEnd());
break;
}
case P_THUMB_LENGTH:
{
int value;
if ( FromJS(cx, *vp, value) )
p->SetThumbLength(value);
break;
}
case P_TICK:
{
int value;
if ( FromJS(cx, *vp, value) )
p->SetTick(value);
break;
}
case P_VALUE:
{
int value;
if ( FromJS(cx, *vp, value) )
p->SetValue(value);
break;
}
}
return true;
}
/***
* <ctor>
* <function>
* <arg name="Parent" type="@wxWindow">
* The parent of wxSlider.
* </arg>
* <arg name="Id" type="Integer">
* An window identifier. Use -1 when you don't need it.
* </arg>
* <arg name="Value" type="Integer">
* Initial position of the slider
* </arg>
* <arg name="Min" type="Integer">
* Minimum slider position.
* </arg>
* <arg name="Max" type="Integer">
* Maximum slider position.
* </arg>
* <arg name="Position" type="@wxPoint" default="wxDefaultPosition">
* The position of the Slider control on the given parent.
* </arg>
* <arg name="Size" type="@wxSize" default="wxDefaultSize">
* The size of the Slider control.
* </arg>
* <arg name="Style" type="Integer" default="wxSlider.HORIZONTAL">
* The wxSlider style.
* </arg>
* <arg name="Validator" type="@wxValidator" default="null" />
* </function>
* <desc>
* Constructs a new wxSlider object.
* </desc>
* </ctor>
*/
wxSlider* Slider::Construct(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, bool constructing)
{
if ( argc > 9 )
argc = 9;
const wxPoint *pt = &wxDefaultPosition;
const wxSize *size = &wxDefaultSize;
int style = 0;
const wxValidator *val = &wxDefaultValidator;
switch(argc)
{
case 9:
val = Validator::GetPrivate(cx, argv[8]);
if ( val == NULL )
break;
case 8:
if ( ! FromJS(cx, argv[7], style) )
break;
// Fall through
case 7:
size = Size::GetPrivate(cx, argv[6]);
if ( size == NULL )
break;
// Fall through
case 6:
pt = Point::GetPrivate(cx, argv[5]);
if ( pt == NULL )
break;
// Fall through
default:
int max;
if ( ! FromJS(cx, argv[4], max) )
break;
int min;
if ( ! FromJS(cx, argv[3], min) )
break;
int value;
if ( ! FromJS(cx, argv[2], value) )
break;
int id;
if ( ! FromJS(cx, argv[1], id) )
break;
wxWindow *parent = Window::GetPrivate(cx, argv[0]);
if ( parent == NULL )
break;
Object *wxjsParent = dynamic_cast<Object *>(parent);
JS_SetParent(cx, obj, wxjsParent->GetObject());
wxSlider *p = new Slider(cx, obj);
p->Create(parent, id, value, min, max, *pt, *size, style, *val);
return p;
}
return NULL;
}
/***
* <method name="clearSel">
* <function />
* <desc>
* Clears the selection, for a slider with the SELRANGE style.
* </desc>
* </method>
*/
JSBool Slider::clearSel(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
wxSlider *p = GetPrivate(cx, obj);
if ( p == NULL )
return JS_FALSE;
p->ClearSel();
return JS_TRUE;
}
/***
* <method name="clearTicks">
* <function />
* <desc>
* Clears the ticks.
* </desc>
* </method>
*/
JSBool Slider::clearTicks(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
wxSlider *p = GetPrivate(cx, obj);
if ( p == NULL )
return JS_FALSE;
p->ClearTicks();
return JS_TRUE;
}
/***
* <method name="setRange">
* <function>
* <arg name="Min" type="Integer">
* The minimum value
* </arg>
* <arg name="Max" type="Integer">
* The maximum value
* </arg>
* </function>
* <desc>
* Sets the minimum and maximum slider values.
* </desc>
* </method>
*/
JSBool Slider::setRange(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
wxSlider *p = GetPrivate(cx, obj);
if ( p == NULL )
return JS_FALSE;
int mini;
int maxi;
if ( FromJS(cx, argv[0], mini)
&& FromJS(cx, argv[1], maxi) )
{
p->SetRange(mini, maxi);
}
else
{
return JS_FALSE;
}
return JS_TRUE;
}
/***
* <method name="setSelection">
* <function>
* <arg name="Start" type="Integer">
* The selection start position
* </arg>
* <arg name="End" type="Integer">
* The selection end position
* </arg>
* </function>
* <desc>
* Sets the selection
* </desc>
* </method>
*/
JSBool Slider::setSelection(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
wxSlider *p = GetPrivate(cx, obj);
if ( p == NULL )
return JS_FALSE;
int start;
int end;
if ( FromJS(cx, argv[0], start)
&& FromJS(cx, argv[1], end) )
{
p->SetSelection(start, end);
}
else
{
return JS_FALSE;
}
return JS_TRUE;
}
/***
* <method name="setTickFreq">
* <function>
* <arg name="Freq" type="Integer">
* Frequency
* </arg>
* <arg name="Pos" type="Integer">
* Position
* </arg>
* </function>
* <desc>
* Sets the tick mark frequency and position.
* </desc>
* </method>
*/
JSBool Slider::setTickFreq(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
wxSlider *p = GetPrivate(cx, obj);
if ( p == NULL )
return JS_FALSE;
int n;
int pos;
if ( FromJS(cx, argv[0], n)
&& FromJS(cx, argv[1], pos) )
{
p->SetTickFreq(n, pos);
}
else
{
return JS_FALSE;
}
return JS_TRUE;
}
/***
* <events>
* <event name="onScroll">
* Catch all scroll commands. The argument of the function is a @wxScrollEvent.
* </event>
* <event name="onScrollTop">
* Catch a command to put the scroll thumb at the maximum position.
* The argument of the function is a @wxScrollEvent.
* </event>
* <event name="onScrollBottom">
* Catch a command to put the scroll thumb at the maximum position.
* The argument of the function is a @wxScrollEvent.
* </event>
* <event name="onScrollLineUp">
* Catch a line up command.
* The argument of the function is a @wxScrollEvent.
* </event>
* <event name="onScrollLineDown">
* Catch a line down command.
* The argument of the function is a @wxScrollEvent.
* </event>
* <event name="onScrollPageUp">
* Catch a page up command.
* The argument of the function is a @wxScrollEvent.
* </event>
* <event name="onScrollPageDown">
* Catch a page down command.
* The argument of the function is a @wxScrollEvent.
* </event>
* <event name="onScrollThumbTrack">
* Catch a thumbtrack command (continuous movement of the scroll thumb).
* The argument of the function is a @wxScrollEvent.
* </event>
* <event name="onScrollThumbRelease">
* Catch a thumbtrack release command.
* The argument of the function is a @wxScrollEvent.
* </event>
* </events>
*/
void Slider::OnScroll(wxScrollEvent& event)
{
PrivScrollEvent::Fire<ScrollEvent>(this, event, "onScroll");
}
void Slider::OnScrollTop(wxScrollEvent& event)
{
PrivScrollEvent::Fire<ScrollEvent>(this, event, "onScrollTop");
}
void Slider::OnScrollBottom(wxScrollEvent& event)
{
PrivScrollEvent::Fire<ScrollEvent>(this, event, "onScrollBottom");
}
void Slider::OnScrollLineUp(wxScrollEvent& event)
{
PrivScrollEvent::Fire<ScrollEvent>(this, event, "onScrollLineUp");
}
void Slider::OnScrollLineDown(wxScrollEvent& event)
{
PrivScrollEvent::Fire<ScrollEvent>(this, event, "onScrollLineDown");
}
void Slider::OnScrollPageUp(wxScrollEvent& event)
{
PrivScrollEvent::Fire<ScrollEvent>(this, event, "onScrollPageUp");
}
void Slider::OnScrollPageDown(wxScrollEvent& event)
{
PrivScrollEvent::Fire<ScrollEvent>(this, event, "onScrollPageDown");
}
void Slider::OnScrollThumbTrack(wxScrollEvent& event)
{
PrivScrollEvent::Fire<ScrollEvent>(this, event, "onScrollThumbTrack");
}
void Slider::OnScrollThumbRelease(wxScrollEvent& event)
{
PrivScrollEvent::Fire<ScrollEvent>(this, event, "onScrollThumbRelease");
}
BEGIN_EVENT_TABLE(Slider, wxSlider)
EVT_SCROLL(Slider::OnScroll)
EVT_SCROLL_TOP(Slider::OnScrollTop)
EVT_SCROLL_BOTTOM(Slider::OnScrollBottom)
EVT_SCROLL_LINEUP(Slider::OnScrollLineUp)
EVT_SCROLL_LINEDOWN(Slider::OnScrollLineDown)
EVT_SCROLL_PAGEUP(Slider::OnScrollPageUp)
EVT_SCROLL_PAGEDOWN(Slider::OnScrollPageDown)
EVT_SCROLL_THUMBTRACK(Slider::OnScrollThumbTrack)
EVT_SCROLL_THUMBRELEASE(Slider::OnScrollThumbRelease)
END_EVENT_TABLE()

View File

@ -1,109 +0,0 @@
/*
* wxJavaScript - slider.h
*
* Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project
*
* Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net
*
* This library is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or
* (at your option) any later version.
*
* This library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
* License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
* USA.
*
* $Id: slider.h 598 2007-03-07 20:13:28Z fbraem $
*/
#ifndef _WXJSSlider_H
#define _WXJSSlider_H
/////////////////////////////////////////////////////////////////////////////
// Name: slider.h
// Purpose: Slider ports wxSlider to JavaScript
// Author: Franky Braem
// Modified by:
// Created: 19.08.2002
// Copyright: (c) 2001-2002 Franky Braem
// Licence: LGPL
/////////////////////////////////////////////////////////////////////////////
namespace wxjs
{
namespace gui
{
class Slider : public wxSlider
, public ApiWrapper<Slider, wxSlider>
, public Object
{
public:
/**
* Constructor
*/
Slider(JSContext *cx, JSObject *obj);
/**
* Destructor
*/
virtual ~Slider();
/**
* Callback for retrieving properties
*/
static bool GetProperty(wxSlider *p, JSContext *cx, JSObject *obj, int id, jsval *vp);
static bool SetProperty(wxSlider *p, JSContext *cx, JSObject *obj, int id, jsval *vp);
static wxSlider* Construct(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, bool constructing);
// Empty to avoid deleting. (It will be deleted by wxWindows).
static void Destruct(JSContext *cx, wxSlider *p)
{
}
static JSBool clearSel(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval);
static JSBool clearTicks(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval);
static JSBool setRange(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval);
static JSBool setSelection(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval);
static JSBool setTickFreq(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval);
WXJS_DECLARE_PROPERTY_MAP()
WXJS_DECLARE_CONSTANT_MAP()
WXJS_DECLARE_METHOD_MAP()
/**
* Property Ids.
*/
enum
{
P_LINESIZE
, P_MAX
, P_MIN
, P_PAGESIZE
, P_SEL_END
, P_SEL_START
, P_THUMB_LENGTH
, P_TICK
, P_VALUE
};
DECLARE_EVENT_TABLE()
void OnScroll(wxScrollEvent& event);
void OnScrollTop(wxScrollEvent& event);
void OnScrollBottom(wxScrollEvent& event);
void OnScrollLineUp(wxScrollEvent& event);
void OnScrollLineDown(wxScrollEvent& event);
void OnScrollPageUp(wxScrollEvent& event);
void OnScrollPageDown(wxScrollEvent& event);
void OnScrollThumbTrack(wxScrollEvent& event);
void OnScrollThumbRelease(wxScrollEvent& event);
};
}; // namespace gui
}; // namespace wxjs
#endif //_WXJSSlider_H

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