2007-12-30 17:41:49 +01:00
|
|
|
/***************************************************************************
|
|
|
|
|
2011-12-31 03:39:20 +01:00
|
|
|
gbx_object.c
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2011-12-31 03:39:20 +01:00
|
|
|
(c) 2000-2012 Benoît Minisini <gambas@users.sourceforge.net>
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2011-12-31 03:39:20 +01:00
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation; either version 2, or (at your option)
|
|
|
|
any later version.
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2011-12-31 03:39:20 +01:00
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2011-12-31 03:39:20 +01:00
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
|
|
|
MA 02110-1301, USA.
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
***************************************************************************/
|
|
|
|
|
|
|
|
#define __OBJECT_C
|
|
|
|
|
|
|
|
#include "gb_common.h"
|
|
|
|
#include "gb_alloc.h"
|
|
|
|
#include "gb_list.h"
|
|
|
|
#include "gbx_class.h"
|
|
|
|
#include "gbx_event.h"
|
|
|
|
#include "gbx_exec.h"
|
|
|
|
#include "gbx_compare.h"
|
2010-12-21 15:05:42 +01:00
|
|
|
#include "gbx_c_observer.h"
|
2010-05-27 00:01:28 +02:00
|
|
|
#include "gbx_c_array.h"
|
2010-05-25 13:19:00 +02:00
|
|
|
#include "gbx_struct.h"
|
2007-12-30 17:41:49 +01:00
|
|
|
#include "gbx_object.h"
|
|
|
|
|
2009-06-16 02:17:25 +02:00
|
|
|
#if DEBUG_REF
|
|
|
|
const char *OBJECT_ref_where = 0;
|
|
|
|
#endif
|
|
|
|
|
2010-12-24 13:20:11 +01:00
|
|
|
void **OBJECT_set_pointer = NULL;
|
|
|
|
|
2007-12-30 17:41:49 +01:00
|
|
|
static OBJECT *EventObject = NULL;
|
|
|
|
|
2010-06-18 02:14:53 +02:00
|
|
|
void *OBJECT_new(CLASS *class, const char *name, OBJECT *parent)
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
2010-06-09 01:08:04 +02:00
|
|
|
OBJECT *object;
|
|
|
|
|
2010-12-21 15:05:42 +01:00
|
|
|
ALLOC_ZERO(&object, class->size, "OBJECT_new");
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2010-12-21 15:05:42 +01:00
|
|
|
object->class = class;
|
2009-06-16 02:17:25 +02:00
|
|
|
#if DEBUG_REF
|
|
|
|
object->ref = 0;
|
2010-06-09 01:08:04 +02:00
|
|
|
OBJECT_REF(object, "OBJECT_new");
|
2009-06-16 02:17:25 +02:00
|
|
|
#else
|
2010-12-21 15:05:42 +01:00
|
|
|
object->ref = 1;
|
2009-06-16 02:17:25 +02:00
|
|
|
#endif
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2010-12-21 15:05:42 +01:00
|
|
|
class->count++;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2010-12-21 15:05:42 +01:00
|
|
|
OBJECT_attach(object, parent, name);
|
2010-06-09 01:08:04 +02:00
|
|
|
|
2010-06-18 02:14:53 +02:00
|
|
|
return object;
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
2010-06-09 01:08:04 +02:00
|
|
|
|
2007-12-30 17:41:49 +01:00
|
|
|
#if 0
|
|
|
|
static void dump_attach(char *title)
|
|
|
|
{
|
|
|
|
void *ob;
|
|
|
|
|
|
|
|
fprintf(stderr, ">>>> %s: ", title);
|
|
|
|
for (ob = EventObject; ob; ob = OBJECT_event(ob)->next)
|
|
|
|
fprintf(stderr, "%p -> ", ob);
|
|
|
|
fprintf(stderr, "(nil)\n");
|
|
|
|
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2010-12-21 15:05:42 +01:00
|
|
|
static void call_attach_special_method(CLASS *class, void *ob, void *parent, const char *name)
|
|
|
|
{
|
|
|
|
STACK_check(2);
|
|
|
|
|
|
|
|
SP->_object.class = OBJECT_class(parent);
|
|
|
|
SP->_object.object = parent;
|
|
|
|
PUSH();
|
|
|
|
|
|
|
|
if (name)
|
|
|
|
{
|
|
|
|
SP->type = T_CSTRING;
|
|
|
|
SP->_string.addr = (char *)name;
|
|
|
|
SP->_string.start = 0;
|
|
|
|
SP->_string.len = strlen(name);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
SP->type = T_NULL;
|
|
|
|
}
|
|
|
|
SP++;
|
|
|
|
|
|
|
|
EXEC_special(SPEC_ATTACH, class, ob, 2, TRUE);
|
|
|
|
}
|
|
|
|
|
2008-01-17 22:39:26 +01:00
|
|
|
void OBJECT_detach(OBJECT *ob)
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
2010-12-21 15:05:42 +01:00
|
|
|
CLASS *class = OBJECT_class(ob);
|
|
|
|
OBJECT *parent;
|
|
|
|
OBJECT_EVENT *ev;
|
|
|
|
bool lock;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2010-05-27 00:01:28 +02:00
|
|
|
if (!class->is_observer && class->n_event == 0)
|
|
|
|
return;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2010-05-27 00:01:28 +02:00
|
|
|
ev = (OBJECT_EVENT *)((char *)ob + class->off_event);
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2010-05-27 00:01:28 +02:00
|
|
|
//if (!ev->parent)
|
|
|
|
// return;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2010-12-21 15:05:42 +01:00
|
|
|
// Do not free the observers there
|
|
|
|
|
2010-05-27 00:01:28 +02:00
|
|
|
if (ev->prev)
|
|
|
|
OBJECT_event(ev->prev)->next = ev->next;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2010-05-27 00:01:28 +02:00
|
|
|
if (ev->next)
|
|
|
|
OBJECT_event(ev->next)->prev = ev->prev;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2010-05-27 00:01:28 +02:00
|
|
|
if (ob == EventObject)
|
|
|
|
EventObject = ev->next;
|
|
|
|
|
|
|
|
ev->prev = NULL;
|
|
|
|
ev->next = NULL;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
//dump_attach("OBJECT_detach");
|
|
|
|
|
2010-05-27 00:01:28 +02:00
|
|
|
/* Avoids an infinite recursion, if freeing the parent implies freeing the object */
|
|
|
|
parent = OBJECT_parent(ob);
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2010-12-21 15:05:42 +01:00
|
|
|
if (parent)
|
|
|
|
{
|
2009-07-12 23:49:13 +02:00
|
|
|
if (class->special[SPEC_ATTACH] != NO_SYMBOL)
|
2010-12-21 15:05:42 +01:00
|
|
|
call_attach_special_method(class, ob, parent, NULL);
|
|
|
|
|
2009-07-12 23:49:13 +02:00
|
|
|
lock = OBJECT_is_locked(ob);
|
2010-12-21 15:05:42 +01:00
|
|
|
ev->parent = NULL;
|
|
|
|
OBJECT_lock(ob, lock);
|
|
|
|
#if DEBUG_EVENT || DEBUG_REF
|
|
|
|
fprintf(stderr, "OBJECT_detach : Detach (%s %p) from (%s %p)\n",
|
|
|
|
ob->class->name, ob, parent->class->name, parent);
|
|
|
|
#endif
|
|
|
|
OBJECT_UNREF(parent, "OBJECT_detach");
|
|
|
|
}
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
2008-02-14 12:59:36 +01:00
|
|
|
static void remove_observers(OBJECT *ob)
|
|
|
|
{
|
|
|
|
CLASS *class = OBJECT_class(ob);
|
2010-12-21 15:05:42 +01:00
|
|
|
OBJECT_EVENT *ev;
|
|
|
|
COBSERVER *obs, *next;
|
2008-02-14 12:59:36 +01:00
|
|
|
|
2010-05-27 00:01:28 +02:00
|
|
|
//fprintf(stderr, "Remove observers: %s %p\n", class->name, ob);
|
|
|
|
|
|
|
|
if (!class->is_observer && class->n_event == 0)
|
|
|
|
return;
|
|
|
|
|
2010-12-21 15:05:42 +01:00
|
|
|
ev = (OBJECT_EVENT *)((char *)ob + class->off_event);
|
|
|
|
obs = ev->observer;
|
|
|
|
ev->observer = NULL;
|
|
|
|
|
|
|
|
while (obs)
|
|
|
|
{
|
|
|
|
next = obs->list.next;
|
|
|
|
#if DEBUG_EVENT
|
|
|
|
fprintf(stderr, "Remove observer %p %d: %p: %p %p\n", obs, (int)obs->ob.ref, ob, obs->object, obs->proxy);
|
|
|
|
#endif
|
|
|
|
OBJECT_UNREF(obs, "remove_observers");
|
|
|
|
obs = next;
|
2008-02-14 12:59:36 +01:00
|
|
|
}
|
2010-12-21 15:05:42 +01:00
|
|
|
|
|
|
|
//ev->observer = NULL;
|
2008-02-14 12:59:36 +01:00
|
|
|
}
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2008-01-17 22:39:26 +01:00
|
|
|
void OBJECT_attach(OBJECT *ob, OBJECT *parent, const char *name)
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
2010-12-21 15:05:42 +01:00
|
|
|
CLASS *class = OBJECT_class(ob);
|
|
|
|
OBJECT_EVENT *ev;
|
|
|
|
bool lock;
|
|
|
|
|
2010-05-27 00:01:28 +02:00
|
|
|
if (!name)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (!class->is_observer && class->n_event == 0)
|
2007-12-30 17:41:49 +01:00
|
|
|
return;
|
|
|
|
|
|
|
|
lock = OBJECT_is_locked(ob);
|
|
|
|
|
2010-05-27 00:01:28 +02:00
|
|
|
OBJECT_detach(ob);
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2010-05-27 00:01:28 +02:00
|
|
|
ev = (OBJECT_EVENT *)((char *)ob + class->off_event);
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2010-05-27 00:01:28 +02:00
|
|
|
ev->parent = parent;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
OBJECT_lock(ob, lock);
|
|
|
|
|
2010-05-27 00:01:28 +02:00
|
|
|
#if DEBUG_EVENT || DEBUG_REF
|
|
|
|
fprintf(stderr, "OBJECT_attach : Attach (%s %p) to (%s %p) as %s\n",
|
|
|
|
ob->class->name, ob, parent->class->name, parent, name);
|
|
|
|
#endif
|
|
|
|
OBJECT_REF(parent, "OBJECT_attach");
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2010-05-27 00:01:28 +02:00
|
|
|
EVENT_search(class, ev->event, name, parent);
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2010-05-27 00:01:28 +02:00
|
|
|
ev->next = EventObject;
|
|
|
|
ev->prev = NULL;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2010-05-27 00:01:28 +02:00
|
|
|
if (EventObject)
|
|
|
|
OBJECT_event(EventObject)->prev = ob;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2010-05-27 00:01:28 +02:00
|
|
|
EventObject = ob;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2009-07-12 23:49:13 +02:00
|
|
|
if (class->special[SPEC_ATTACH] != NO_SYMBOL)
|
2010-12-21 15:05:42 +01:00
|
|
|
call_attach_special_method(class, ob, parent, name);
|
2009-07-12 23:49:13 +02:00
|
|
|
|
2007-12-30 17:41:49 +01:00
|
|
|
//dump_attach("OBJECT_attach");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-01-17 22:39:26 +01:00
|
|
|
void OBJECT_free(CLASS *class, OBJECT *ob)
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
2010-12-21 15:05:42 +01:00
|
|
|
OBJECT_detach(ob);
|
|
|
|
remove_observers(ob);
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2010-12-21 15:05:42 +01:00
|
|
|
class->count--;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2010-12-21 15:05:42 +01:00
|
|
|
#if DEBUG_REF
|
|
|
|
ob->class = FREE_MARK;
|
|
|
|
#endif
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2010-12-21 15:05:42 +01:00
|
|
|
FREE(&ob, "OBJECT_free");
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-01-17 22:39:26 +01:00
|
|
|
bool OBJECT_comp_value(VALUE *ob1, VALUE *ob2)
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
2010-12-21 15:05:42 +01:00
|
|
|
if (ob1->type == T_NULL && ob2->type == T_NULL)
|
|
|
|
return FALSE;
|
|
|
|
else if (ob1->type == T_NULL)
|
|
|
|
return ob2->_object.object != NULL;
|
|
|
|
else if (ob2->type == T_NULL)
|
|
|
|
return ob1->_object.object != NULL;
|
|
|
|
else
|
|
|
|
return COMPARE_object(&ob1->_object.object, &ob2->_object.object);
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
2010-07-08 00:06:05 +02:00
|
|
|
void OBJECT_release_static(CLASS *class, CLASS_VAR *var, int nelt, char *data)
|
2010-05-27 00:01:28 +02:00
|
|
|
{
|
2010-06-09 01:08:04 +02:00
|
|
|
static void *jump[17] = {
|
|
|
|
&&__NEXT, &&__NEXT, &&__NEXT, &&__NEXT, &&__NEXT, &&__NEXT, &&__NEXT, &&__NEXT, &&__NEXT,
|
|
|
|
&&__STRING, &&__NEXT, &&__NEXT, &&__VARIANT, &&__ARRAY, &&__STRUCT, &&__NEXT, &&__OBJECT
|
|
|
|
};
|
|
|
|
|
|
|
|
CTYPE type;
|
|
|
|
|
|
|
|
while (nelt--)
|
|
|
|
{
|
2010-05-27 00:01:28 +02:00
|
|
|
#if TRACE_MEMORY
|
2010-06-09 01:08:04 +02:00
|
|
|
if (var->type.id == T_STRING || var->type.id == T_OBJECT)
|
|
|
|
fprintf(stderr, "release_static: %s [%d] trying %p\n", class->name, i, (*(void **)&data[var->pos]));
|
2010-05-27 00:01:28 +02:00
|
|
|
#endif
|
|
|
|
|
2010-06-09 01:08:04 +02:00
|
|
|
type = var->type;
|
|
|
|
goto *jump[type.id];
|
|
|
|
|
|
|
|
__STRING:
|
|
|
|
STRING_unref((char **)&data[var->pos]);
|
|
|
|
goto __NEXT;
|
|
|
|
|
|
|
|
__OBJECT:
|
|
|
|
OBJECT_UNREF(*((void **)&data[var->pos]), "release");
|
|
|
|
goto __NEXT;
|
|
|
|
|
|
|
|
__VARIANT:
|
|
|
|
VARIANT_free((VARIANT *)&data[var->pos]);
|
|
|
|
goto __NEXT;
|
|
|
|
|
|
|
|
__ARRAY:
|
2010-07-08 00:06:05 +02:00
|
|
|
CARRAY_release_static(class, class->load->array[type.value], &data[var->pos]);
|
2010-06-09 01:08:04 +02:00
|
|
|
goto __NEXT;
|
|
|
|
|
|
|
|
__STRUCT:
|
2010-05-27 00:01:28 +02:00
|
|
|
{
|
2010-06-09 01:08:04 +02:00
|
|
|
CLASS *sclass = class->load->class_ref[type.value];
|
2010-07-08 00:06:05 +02:00
|
|
|
OBJECT_release_static(sclass, sclass->load->dyn, sclass->load->n_dyn, &data[var->pos]);
|
2010-05-27 00:01:28 +02:00
|
|
|
}
|
|
|
|
|
2010-06-09 01:08:04 +02:00
|
|
|
__NEXT:
|
|
|
|
var++;
|
|
|
|
}
|
2010-05-27 00:01:28 +02:00
|
|
|
}
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
static void release(CLASS *class, OBJECT *ob)
|
|
|
|
{
|
2010-12-21 15:05:42 +01:00
|
|
|
CLASS_VAR *var;
|
|
|
|
int nelt;
|
|
|
|
char *data;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2010-12-21 15:05:42 +01:00
|
|
|
if (class->parent != NULL && ob)
|
|
|
|
release(class->parent, ob);
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2010-12-21 15:05:42 +01:00
|
|
|
if (CLASS_is_native(class))
|
|
|
|
return;
|
2010-05-25 13:19:00 +02:00
|
|
|
|
2010-12-21 15:05:42 +01:00
|
|
|
if (ob == NULL)
|
|
|
|
{
|
|
|
|
var = class->load->stat;
|
|
|
|
nelt = class->load->n_stat;
|
|
|
|
data = class->stat;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-11-26 21:30:58 +01:00
|
|
|
if (CLASS_is_struct(class))
|
2010-05-27 00:01:28 +02:00
|
|
|
{
|
2010-11-26 21:30:58 +01:00
|
|
|
if (((CSTRUCT *)ob)->ref)
|
|
|
|
{
|
|
|
|
CSTRUCT_release((CSTRUCT *)ob);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
data = (char *)ob + sizeof(CSTRUCT);
|
2010-05-27 00:01:28 +02:00
|
|
|
}
|
2010-11-26 21:30:58 +01:00
|
|
|
else
|
|
|
|
data = (char *)ob;
|
2010-05-25 13:19:00 +02:00
|
|
|
|
2010-12-21 15:05:42 +01:00
|
|
|
var = class->load->dyn;
|
|
|
|
nelt = class->load->n_dyn;
|
|
|
|
}
|
|
|
|
|
|
|
|
OBJECT_release_static(class, var, nelt, data);
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-01-17 22:39:26 +01:00
|
|
|
void OBJECT_release(CLASS *class, OBJECT *ob)
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
|
|
|
#if TRACE_MEMORY
|
2010-12-21 15:05:42 +01:00
|
|
|
printf("> OBJECT_release %s %p\n", class->name, ob);
|
2007-12-30 17:41:49 +01:00
|
|
|
#endif
|
|
|
|
|
2010-12-21 15:05:42 +01:00
|
|
|
release(class, ob);
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2010-12-21 15:05:42 +01:00
|
|
|
if (ob)
|
|
|
|
OBJECT_free(class, ob);
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
#if TRACE_MEMORY
|
2010-12-21 15:05:42 +01:00
|
|
|
printf("< OBJECT_release %s %p\n", class->name, ob);
|
2007-12-30 17:41:49 +01:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-01-17 22:39:26 +01:00
|
|
|
void OBJECT_exit(void)
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
|
|
|
#if DEBUG_LOAD
|
|
|
|
fprintf(stderr, "------------ OBJECT_exit - BEGIN---------\n");
|
|
|
|
#endif
|
2010-12-21 15:05:42 +01:00
|
|
|
while (EventObject)
|
|
|
|
OBJECT_detach(EventObject);
|
2007-12-30 17:41:49 +01:00
|
|
|
#if DEBUG_LOAD
|
|
|
|
fprintf(stderr, "------------ OBJECT_exit - END ----------\n");
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2010-06-18 02:14:53 +02:00
|
|
|
static void *_object;
|
2010-12-21 15:05:42 +01:00
|
|
|
static char *_object_name;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2010-06-18 02:14:53 +02:00
|
|
|
static void error_OBJECT_create(void)
|
|
|
|
{
|
|
|
|
OBJECT_UNREF_KEEP(_object, "OBJECT_create");
|
2010-12-21 15:05:42 +01:00
|
|
|
EVENT_leave_name(_object_name);
|
2010-06-18 02:14:53 +02:00
|
|
|
}
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2010-06-18 02:14:53 +02:00
|
|
|
void *OBJECT_create(CLASS *class, const char *name, void *parent, int nparam)
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
2010-12-21 15:05:42 +01:00
|
|
|
void *ob;
|
2010-08-03 13:00:42 +02:00
|
|
|
void *save;
|
2010-12-21 15:05:42 +01:00
|
|
|
char *save_name;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
[CONFIGURATION]
* NEW: Qt 4.5.0 is now required to compile the gb.qt4 components.
[INTERPRETER]
* NEW: You can now define a non-creatable but auto-creatable class. It
means that you cannot instanciate the class, but you can use it
statically.
[GB.GTK]
* NEW: Screens is a new pseudo-array of all screens.
* NEW: Screen is a new class that represents the geometry of a screen. The
X, Y, Width and Height properties return the full geometry. The
AvailableX, AvailableY, AvailableWidth and AvailableHeight properties
return the geometry available to the windows. The screen class can be
used statically to get the geometry of the default screen.
BEWARE: The available geometry is not yet implemented on gb.gtk!
* NEW: Window.Screen is a new property that returns the screen where most
of the window is located.
* NEW: Desktop.{X,Y,Width,Height} are four new properties that return the
available geometry of the default screen. It is an equivalent of
Screen.{AvailableX,AvailableY,AvailableWidth,AvailableHeight}.
[GB.QT4]
* NEW: Screens is a new pseudo-array of all screens.
* NEW: Screen is a new class that represents the geometry of a screen. The
X, Y, Width and Height properties return the full geometry. The
AvailableX, AvailableY, AvailableWidth and AvailableHeight properties
return the geometry available to the windows. The screen class can be
used statically to get the geometry of the default screen.
* NEW: Window.Screen is a new property that returns the screen where most
of the window is located.
* NEW: Desktop.{X,Y,Width,Height} are four new properties that return the
available geometry of the default screen. It is an equivalent of
Screen.{AvailableX,AvailableY,AvailableWidth,AvailableHeight}.
git-svn-id: svn://localhost/gambas/trunk@3413 867c0c6c-44f3-4631-809d-bfa615b0a4ec
2010-12-30 02:52:40 +01:00
|
|
|
// The "no create" flag only concerns users of NEW
|
|
|
|
//if (class->no_create)
|
2012-10-19 23:00:35 +02:00
|
|
|
// THROW(E_CSTATIC, CLASS_get_name(class));
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2010-08-03 13:00:42 +02:00
|
|
|
save = _object;
|
2010-12-21 15:05:42 +01:00
|
|
|
save_name = _object_name;
|
|
|
|
|
|
|
|
ON_ERROR(error_OBJECT_create)
|
|
|
|
{
|
|
|
|
_object_name = EVENT_enter_name(name);
|
|
|
|
_object = ob = OBJECT_new(class, name, parent);
|
2010-12-24 13:20:11 +01:00
|
|
|
if (OBJECT_set_pointer)
|
|
|
|
{
|
|
|
|
*OBJECT_set_pointer = ob;
|
2011-04-18 15:57:46 +02:00
|
|
|
OBJECT_ref(ob);
|
2010-12-24 13:20:11 +01:00
|
|
|
OBJECT_set_pointer = NULL;
|
|
|
|
}
|
2010-12-21 15:05:42 +01:00
|
|
|
|
2007-12-30 17:41:49 +01:00
|
|
|
OBJECT_lock(ob, TRUE);
|
2010-12-21 15:05:42 +01:00
|
|
|
EXEC_special_inheritance(SPEC_NEW, class, ob, nparam, TRUE);
|
2007-12-30 17:41:49 +01:00
|
|
|
OBJECT_lock(ob, FALSE);
|
2010-12-21 15:05:42 +01:00
|
|
|
|
|
|
|
error_OBJECT_create();
|
|
|
|
}
|
|
|
|
END_ERROR
|
|
|
|
|
|
|
|
_object = save;
|
|
|
|
_object_name = save_name;
|
|
|
|
|
|
|
|
return ob;
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-08-19 15:01:57 +02:00
|
|
|
/* FIXME: The _new methods are called differently from EXEC_special_inheritance */
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2010-06-18 02:14:53 +02:00
|
|
|
void *OBJECT_create_native(CLASS *class, VALUE *param)
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
2010-12-21 15:05:42 +01:00
|
|
|
CLASS_DESC *desc;
|
|
|
|
short index;
|
2010-06-18 02:14:53 +02:00
|
|
|
void *object;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2010-12-21 15:05:42 +01:00
|
|
|
object = OBJECT_new(class, NULL, NULL);
|
|
|
|
|
|
|
|
for(;;)
|
|
|
|
{
|
|
|
|
index = class->special[SPEC_NEW];
|
|
|
|
if (index != NO_SYMBOL)
|
|
|
|
{
|
|
|
|
desc = CLASS_get_desc(class, index);
|
|
|
|
EXEC_call_native(desc->method.exec, object, desc->method.type, param);
|
|
|
|
}
|
|
|
|
class = class->parent;
|
|
|
|
if (!class)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
OBJECT_UNREF_KEEP(object, "OBJECT_create");
|
2010-06-18 02:14:53 +02:00
|
|
|
return object;
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
2008-01-17 22:39:26 +01:00
|
|
|
void OBJECT_lock(OBJECT *object, bool block)
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
2010-12-21 15:05:42 +01:00
|
|
|
CLASS *class;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2010-12-21 15:05:42 +01:00
|
|
|
if (!object)
|
|
|
|
return;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2010-12-21 15:05:42 +01:00
|
|
|
class = object->class;
|
2009-02-17 02:51:25 +01:00
|
|
|
|
|
|
|
if (class->is_observer)
|
|
|
|
{
|
|
|
|
COBSERVER_lock((COBSERVER *)object, block);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-12-21 15:05:42 +01:00
|
|
|
if (class->n_event == 0)
|
|
|
|
return;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
// fprintf(stderr, "OBJECT_lock: (%s %p) %s\n", class->name, object, block ? "lock" : "unlock");
|
|
|
|
|
2010-12-21 15:05:42 +01:00
|
|
|
if (block)
|
|
|
|
OBJECT_event(object)->parent = (OBJECT *)((intptr_t)OBJECT_event(object)->parent | 1);
|
|
|
|
else
|
|
|
|
OBJECT_event(object)->parent = (OBJECT *)((intptr_t)OBJECT_event(object)->parent & ~1);
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-01-17 22:39:26 +01:00
|
|
|
bool OBJECT_is_locked(OBJECT *object)
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
2010-12-21 15:05:42 +01:00
|
|
|
CLASS *class;
|
2009-02-17 02:51:25 +01:00
|
|
|
|
2010-12-21 15:05:42 +01:00
|
|
|
if (!object)
|
|
|
|
return FALSE;
|
2009-02-17 02:51:25 +01:00
|
|
|
|
2010-12-21 15:05:42 +01:00
|
|
|
class = object->class;
|
2009-02-17 02:51:25 +01:00
|
|
|
|
|
|
|
if (class->is_observer)
|
|
|
|
return COBSERVER_is_locked((COBSERVER *)object);
|
|
|
|
|
2010-12-21 15:05:42 +01:00
|
|
|
if (class->n_event == 0)
|
|
|
|
return FALSE;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2008-01-17 22:39:26 +01:00
|
|
|
return (((intptr_t)OBJECT_event(object)->parent & 1) != 0);
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-01-17 22:39:26 +01:00
|
|
|
OBJECT *OBJECT_parent(void *object)
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
2010-05-27 00:01:28 +02:00
|
|
|
CLASS *class = OBJECT_class(object);
|
|
|
|
|
|
|
|
if (!class->is_observer && class->n_event == 0)
|
|
|
|
return NULL;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2010-12-21 15:05:42 +01:00
|
|
|
return ((OBJECT *)((intptr_t)OBJECT_event(object)->parent & ~1));
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-01-17 22:39:26 +01:00
|
|
|
OBJECT *OBJECT_active_parent(void *object)
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
|
|
|
OBJECT *parent = OBJECT_parent(object);
|
|
|
|
|
|
|
|
if (!parent || OBJECT_is_locked((OBJECT *)object) || OBJECT_is_locked(parent))
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
return parent;
|
|
|
|
}
|