Beispiel #1
0
void wxlogunbind(wxLog *obj) {
	BBObject * peer = wxlogfind(obj);
	if (peer != &bbNullObject) {
		logPeerMap.erase(obj);
		BBRELEASE(peer);
	}
}
void cpunbind(void *obj) {
	BBObject * peer = cpfind(obj);
	if (peer != &bbNullObject) {
		peerMap.erase(obj);
		BBRELEASE(peer);
	}
}
Beispiel #3
0
static void setMouseHwnd( HWND hwnd,int x,int y,BBObject *source ){
	if( hwnd==mouseHwnd ) return;

	if( hwnd && source ){
		BBRETAIN( source );
	}
	
	if( mouseHwnd ){
		POINT p;
		GetCursorPos( &p );
		ScreenToClient( mouseHwnd,&p );
		bbSystemEmitEvent( BBEVENT_MOUSELEAVE,mouseSource,0,0,p.x,p.y,&bbNullObject );
		if( mouseSource ){
			BBRELEASE( mouseSource );
		}
	}
	mouseHwnd=hwnd;
	updateMouseVisibility();
	if( mouseHwnd ){
		TRACKMOUSEEVENT tm={sizeof(tm),TME_LEAVE,hwnd,0};
		mouseSource=source;
		bbSystemEmitEvent( BBEVENT_MOUSEENTER,mouseSource,0,0,x,y,&bbNullObject );
		_TrackMouseEvent( &tm );
	}
}
Beispiel #4
0
void bmx_releaseindexedclientdata(wxListCtrl * list, long index) {
	void * data = wxUIntToPtr(list->GetItemData(index));
	if (data) {
		if ((BBObject*)data != &bbNullObject) {
			BBRELEASE((BBObject*)data);
			list->SetItemData(index, 0);
		}
	}
}
Beispiel #5
0
void bmx_wxlistitem_setcolumn(MaxListItem * item, int col) {
	item->Item().SetColumn(col);
	
	// check that we haven't set any data on a non-zero column...
	BBObject * data = (BBObject *)wxUIntToPtr(item->Item().GetData());
	if (data && (data != &bbNullObject)) {
			BBRELEASE(data);
			item->Item().SetData((void*)NULL);
	}
}
Beispiel #6
0
void bbTimerStop( int timer,BBObject *bbTimer ){
	int i;
	
	for( i=0;i<n_timers && timer!=timers[i];++i ) {}
	if( i==n_timers ) return;

	timers[i]=timers[--n_timers];
	timeKillEvent( timer );

	BBRELEASE( bbTimer );
}
Beispiel #7
0
void MaxCheckListBox::Delete(unsigned int n) {
	if (HasClientUntypedData()) {
		void * data = GetClientData(n);
		if (data) {
			BBRELEASE((BBObject*)data);
			SetClientData(n, 0);
		}
	}
	
	wxCheckListBox::Delete(n);
}
Beispiel #8
0
void MaxTreeItemData::SetData(BBObject * data) {
	if (maxHandle != &bbNullObject) {
		BBRELEASE(maxHandle);
	}
	
	maxHandle = data;
	
	if (data != &bbNullObject) {
		BBRETAIN(data);
	}	
}
Beispiel #9
0
void bmx_releaseallclientdata(wxListCtrl * list) {
	int count = list->GetItemCount();
	for (int i = 0; i < count; i++) {
		void * data = wxUIntToPtr(list->GetItemData(i));
		if (data) {
			if ((BBObject*)data != &bbNullObject) {
				BBRELEASE((BBObject*)data);
			}
		}
	}
}
Beispiel #10
0
static LRESULT CALLBACK getMessageHook( int code,WPARAM wp,LPARAM lp ){
	if( code>=0 && wp==PM_REMOVE ){
		MSG *msg=(MSG*)lp;
		if( msg->message==WM_BBRESERVED1 ){
			AsyncOp *p=(AsyncOp*)msg->lParam;
			p->syncOp( p->syncInfo,p->asyncRet );
			if( p->asyncOp ){
				BBRELEASE( p->syncInfo );
			}
			free( p );
		}
	}
	return CallNextHookEx( msghook,code,wp,lp );
}
Beispiel #11
0
void MaxCheckListBox::Clear() {
	// we need to free any items
	int count = GetCount();
	if (HasClientUntypedData()) {
		for (int i = 0; i < count; i++) {
			void * data = GetClientData(i);
			if (data) {
				BBRELEASE((BBObject*)data);
				SetClientData(i, 0);
			}
		}
	}
	wxCheckListBox::Clear();
}
Beispiel #12
0
MaxComboBox::~MaxComboBox() {
	wxunbind(this);
	
	// we need to free any items
	int count = GetCount();
	if (HasClientUntypedData()) {
		for (int i = 0; i < count; i++) {
			void * data = GetClientData(i);
			if (data) {
				BBRELEASE((BBObject*)data);
			}
		}
	}
}
Beispiel #13
0
int bmx_libwebsockets_callback(struct libwebsocket_context * context, struct libwebsocket * wsi, enum libwebsocket_callback_reasons reason, void * user, void * in, size_t len, struct libwebsocket_protocols * protocol) {
	BBString * name = bbStringFromCString(protocol->name);
	struct per_session_data_obj *maxObj = (struct per_session_data_obj *)user;
	
	if (reason == LWS_CALLBACK_FILTER_PROTOCOL_CONNECTION) {
		maxObj = 0;
	}

	// on a new connection, we should initialise the object
	if (maxObj && ((reason == LWS_CALLBACK_ESTABLISHED) || (!maxObj->handle))) {
		if (maxObj->handle && maxObj->handle != &bbNullObject) {
			BBRELEASE(maxObj->handle);
		}

		// call the object creation function
		maxObj->handle = CB_PREF(bah_libwebsockets_TLWSProtocol__objectCallback)(name);

		// prevent early GC
		if (maxObj->handle != &bbNullObject) {
			BBRETAIN(maxObj->handle);
		}
	}
	
	int result = CB_PREF(bah_libwebsockets_TLWSProtocol__callback)(name, context, wsi, reason, (maxObj) ? maxObj->handle : &bbNullObject, in, len);

	// release on close of connection
	if (reason == LWS_CALLBACK_CLOSED) {
		if (maxObj && maxObj->handle) {
			if (maxObj->handle != &bbNullObject) {
				BBRELEASE(maxObj->handle);
			}
		}
	}
	
	return result;
}
Beispiel #14
0
void bmx_wxlistitem_setdata(MaxListItem * item, BBObject * data) {
	if (item->Item().GetColumn() == 0) {
		// is there any data here already?
		BBObject * oldData = (BBObject *)wxUIntToPtr(item->Item().GetData());
		if (oldData && (oldData != &bbNullObject)) {
			BBRELEASE(oldData);
			item->Item().SetData((void*)NULL);
		}
	
		if (data != &bbNullObject) {
			BBRETAIN( data );
		}
		item->Item().SetData(wxPtrToUInt((void*)data));
	}
}
Beispiel #15
0
static void timerSyncOp( BBObject *user,int ret ){
	BBTimer *timer=(BBTimer*)ret;

	++timer->gets;	

	switch( timer->status ){
	case 1:
		brl_timer__TimerFired( timer->bbTimer );
		break;
	case 2:
		if( timer->puts==timer->gets ){
			BBRELEASE( timer->bbTimer );
			free( timer );
		}
		break;
	}
}
Beispiel #16
0
void TCOD_sys_delete_bitmap(void *bitmap) {
	BBRELEASE((BBObject*)bitmap);
}
Beispiel #17
0
MaxBxStream::~MaxBxStream() {
	BBRELEASE(maxStream);
}
Beispiel #18
0
	~MaxSoundStopEventReceiver()
	{
		BBRELEASE(maxHandle);
	}
Beispiel #19
0
MaxTreeItemData::~MaxTreeItemData() {
	if (maxHandle != &bbNullObject) {
		BBRELEASE(maxHandle);
	}
}
Beispiel #20
0
MaxTextDropTarget::~MaxTextDropTarget() {
	BBRELEASE(maxHandle);
}
Beispiel #21
0
/* table[key] = value OR table.key = value */
static int lugi_newindex_object(lua_State *state) {
    if (lua_type(state, 2) == LUA_TSTRING) {

        BBObject *obj = lua_tobmaxobject(state, 1);
        BBClass *clas = obj->clas;

        /* while class != NULL */
        do {
            /* get class VMT */
            lua_pushlightuserdata(state, clas);
            lua_gettable(state, LUA_REGISTRYINDEX);

            if ( lua_type(state, -1) == LUA_TTABLE ) /* there's a lookup table for the class.. */
            {
                lua_pushvalue(state, 2);
                lua_rawget(state, -2);

                if (lua_type(state, -1) == LUA_TUSERDATA) {		/* getting the value of a field */
                    fieldinfo_t *info = (fieldinfo_t*)lua_touserdata(state, -1);;
                    bmx_field *field = (bmx_field*)((char*)obj+info->offset);

                    clas = NULL;

                    switch (info->type) /* set the value of a field */
                    {
                    case BYTEFIELD:
                        if (lua_type(state, 3) == LUA_TBOOLEAN) {
                            field->byte_value = (unsigned char)lua_toboolean(state, 3);
                        }
                        else {
                            field->byte_value = (unsigned char)lua_tointeger(state, 3);
                        }
                        break;

                    case SHORTFIELD:
                        if (lua_type(state, 3) == LUA_TBOOLEAN) {
                            field->short_value = (unsigned short)lua_toboolean(state, 3);
                        }
                        else {
                            field->short_value = (unsigned short)lua_tointeger(state, 3);
                        }
                        break;

                    case INTFIELD:
                        if (lua_type(state, 3) == LUA_TBOOLEAN) {
                            field->int_value = lua_toboolean(state, 3);
                        }
                        else {
                            field->int_value = lua_tointeger(state, 3);
                        }
                        break;

                    case FLOATFIELD:
                        field->float_value = (float)lua_tonumber(state, 3);
                        break;

                    case DOUBLEFIELD:
                        field->double_value = lua_tonumber(state, 3);
                        break;

                    case LONGFIELD:
                        if (lua_type(state, 3) == LUA_TBOOLEAN) {
                            field->long_value = lua_toboolean(state, 3);
                        }
                        else {
                            field->long_value = lua_tointeger(state, 3);
                        }
                        break;

                    case STRINGFIELD: {
                        const char *strbuf = lua_tostring(state, 3);
                        BBString *last = field->string_value;
                        BBRETAIN((BBObject*)(field->string_value = bbStringFromCString(strbuf)));
                        BBRELEASE((BBObject*)last);
                    }
                    break;

                    case ARRAYFIELD: {
                        BBArray *last = field->arr_value;
                        BBRETAIN((BBObject*)(field->arr_value = lua_tobmaxarray(state, 3)));
                        BBRELEASE((BBObject*)last);
                    }
                    break;

                    case OBJECTFIELD: {
                        BBObject *last = field->obj_value;
                        BBRETAIN(field->obj_value = lua_tobmaxobject(state, 3));
                        BBRELEASE(last);
                    }
                    break;

                    default:
                        return luaL_error(state, ERRORSTR("@lugi_newindex_object: Unrecognized field type (%d)."), info->type);
                        break;
                    } /* set value based on type */
                    return 0;
                }
                else {
                    lua_pop(state, 1);
                }
            } /* VMT found */

            lua_pop(state, 1);

            clas = clas->super; /* iterate to a superclass if nothing is found in the class */

        } while (clas != NULL);
    } /* key is string */

#if BMX_TABLE_SUPPORT < 1
    const char *objtype="null";
    if (lua_isbmaxobject(state, 1))
        objtype = lua_tobmaxobject(state, 1)->clas->debug_scope->name;

    if ((LUA_TNUMBER|LUA_TSTRING)&lua_type(state,2))
        return luaL_error(state, ERRORSTR("@lugi_newindex_object: Index (%s) for object<%s> is not a valid field or method."), lua_tostring(state, 2), objtype);
    else
        return luaL_error(state, ERRORSTR("@lugi_newindex_object: Index for object<%s> is not a valid field or method."), objtype);
#else
    /* prior table behavior for BMax objects - disabled by default */
    lua_settop(state, 3);

    lua_getfenv(state, 1);
    lua_insert(state, 2);
    lua_settable(state, 2);

    return 0;
#endif
}
Beispiel #22
0
static int lugi_newindex_array(lua_State *state) {
    if (lua_isnumber(state, 2) == 1) {
        BBArray *arr = lua_tobmaxarray(state, 1);

        lua_Integer index = lua_tointeger(state, 2);
        if ( index < 0 || arr->scales[0] <= index ) {
            return luaL_error(state, ERRORSTR("@lugi_newindex_array: Attempt to index array failed: index (%d) out of bounds"), index);
        }

        switch (arr->type[0]) {
        case 'b':	/* byte */
            if ( lua_isnumber(state, 3) ) {
                ((BBBYTE*)BBARRAYDATA(arr, arr->dims))[index] = (BBBYTE)lua_tointeger(state, 3);
            }
            else {
                return luaL_error(state, ERRORSTR("@lugi_newindex_array: Cannot assign value with type %s to element of byte array"), lua_typename(state, lua_type(state, 3)));
            }
            break;

        case 's':	/* short */
            if ( lua_isnumber(state, 3) ) {
                ((BBSHORT*)BBARRAYDATA(arr, arr->dims))[index] = (BBSHORT)lua_tointeger(state, 3);
            }
            else {
                return luaL_error(state, ERRORSTR("@lugi_newindex_array: Cannot assign value with type %s to element of short array"), lua_typename(state, lua_type(state, 3)));
            }
            break;

        case 'i':	/* int */
            if ( lua_isnumber(state, 3) ) {
                ((BBINT*)BBARRAYDATA(arr, arr->dims))[index] = (BBINT)lua_tointeger(state, 3);
            }
            else {
                return luaL_error(state, ERRORSTR("@lugi_newindex_array: Cannot assign value with type %s to element of integer array"), lua_typename(state, lua_type(state, 3)));
            }
            break;

        case 'l':	/* long */
            if ( lua_isnumber(state, 3) ) {
                ((BBLONG*)BBARRAYDATA(arr, arr->dims))[index] = (BBLONG)lua_tointeger(state, 3);
            }
            else {
                return luaL_error(state, ERRORSTR("@lugi_newindex_array: Cannot assign value with type %s to element of long array"), lua_typename(state, lua_type(state, 3)));
            }
            break;

        case 'f':	/* float */
            if ( lua_isnumber(state, 3) ) {
                ((BBFLOAT*)BBARRAYDATA(arr, arr->dims))[index] = (BBFLOAT)lua_tonumber(state, 3);
            }
            else {
                return luaL_error(state, ERRORSTR("@lugi_newindex_array: Cannot assign value with type %s to element of short array"), lua_typename(state, lua_type(state, 3)));
            }
            break;

        case 'd':	/* double */
            if ( lua_isnumber(state, 3) ) {
                ((BBDOUBLE*)BBARRAYDATA(arr, arr->dims))[index] = (BBDOUBLE)lua_tonumber(state, 3);
            }
            else {
                return luaL_error(state, ERRORSTR("@lugi_newindex_array: Cannot assign value with type %s to element of short array"), lua_typename(state, lua_type(state, 3)));
            }
            break;

        case '$':	/* string */
        {
            BBString **data = ((BBString**)BBARRAYDATA(arr, arr->dims));
            if ( lua_isstring(state, 3) ) {
                BBString *newstring = bbStringFromCString(lua_tostring(state, 3));
                BBRETAIN((BBObject*)newstring);
                BBRELEASE((BBObject*)data[index]);
                data[index] = newstring;
            }
            else if ( lua_isnil(state, 3 ) ) {
                BBRELEASE((BBObject*)data[index]);
                data[index] = &bbEmptyString;
            }
            else {
                return luaL_error(state, ERRORSTR("@lugi_newindex_array: Cannot assign value with type %s to element of string array"), lua_typename(state, lua_type(state, 3)));
            }
        }
        break;

        case ':':	/* any type of object */
        {
            BBObject *value = lua_tobmaxobject(state, 3);
            BBClass *arrclas = NULL;

            {   /* search for the array element type's class */
                const char *arrtypename = arr->type+1;
                int numTypes = 0;
                int regidx = 0;
                BBClass **regtypes = bbObjectRegisteredTypes(&numTypes);

                for (; regidx < numTypes; ++regidx) {
                    if ( strcmp(regtypes[regidx]->debug_scope->name, arrtypename) == 0 ) {
                        arrclas = regtypes[regidx];
                        break;
                    }
                }
            }

            if ( arrclas == NULL ) {
                return luaL_error(state, ERRORSTR("@lugi_newindex_array: Undefined array type encountered: %s"), arr->type);
            }

            value = bbObjectDowncast(value, arrclas);

            BBObject **data = (BBObject**)BBARRAYDATA(arr, arr->dims);
            BBRETAIN(value);
            BBRELEASE(data[index]);
            data[index] = value;
        }
        break;

        case '[': {
            BBArray *value = lua_tobmaxarray(state, 3);
            if ( (BBObject*)value == &bbNullObject ) {
                value = &bbEmptyArray;
            }

            if ( value == &bbEmptyArray || strcmp(arr->type+2, value->type) == 0 ) {
                BBArray **data = (BBArray**)BBARRAYDATA(arr, arr->dims);
                BBRETAIN((BBObject*)value);
                BBRELEASE((BBObject*)data[index]);
                data[index] = value;
            }
            else {
                return luaL_error(state, ERRORSTR("@lugi_newindex_array: Cannot assign array value to an element of an array of a differing type"));
            }
        }
        break;

        default:
            return luaL_error(state, ERRORSTR("@lugi_newindex_array: Unsupported array element type: %s"), arr->type);
        }

        return 0;
    } /* key is a valid type of index for an array */

    return luaL_error(state, ERRORSTR("@lugi_newindex_array: Invalid type for an array index (%s), must be an integer or a string convertible to an integer"), lua_typename(state, lua_type(state, 2)));
}
Beispiel #23
0
/* Userdata collection routine - only used in unthreaded builds where refcount has to be decremented */
static int lugi_gc_object(lua_State *state) {
    BBObject **obj = (BBObject**)lua_touserdata(state,1);
    BBRELEASE(*obj);
    *obj = NULL;
    return 0;
}
Beispiel #24
0
MaxTipProvider::~MaxTipProvider() {
	BBRELEASE(maxHandle);
}
Beispiel #25
0
void lua_gcobject( lua_State *L )
{
	BBObject *obj=lua_unboxobject( L,1 );
	BBRELEASE( obj );
}
Beispiel #26
0
int lua_gcobject( lua_State *L ){
	BBObject *obj=lua_unboxobject( L,1 );
	BBRELEASE( obj );
	return 1;
}