* BUG: Using stock pictures work correctly again, and does not crash the
  interpreter anymore.
* BUG: Fixes memory leaks with font and picture management.


git-svn-id: svn://localhost/gambas/trunk@1188 867c0c6c-44f3-4631-809d-bfa615b0a4ec
This commit is contained in:
Benoît Minisini 2008-03-17 15:04:36 +00:00
parent 9ccbaac697
commit ce5392adce
14 changed files with 21 additions and 96 deletions

View file

@ -425,7 +425,7 @@ static void cache_flush()
#define CREATE_IMAGE_FROM_MEMORY(_image, _addr, _len, _ok) \
_image = gPicture::fromMemory(_addr, _len);
#define DELETE_IMAGE(_image) delete _image
#define DELETE_IMAGE(_image)
#define CREATE_PICTURE_FROM_IMAGE(_cpicture, _image) \
_cpicture = CPICTURE_create(_image);
@ -440,85 +440,6 @@ static void cache_flush()
#include "gb.form.picture.h"
// BEGIN_METHOD(CPICTURE_get, GB_STRING path)
//
// char *addr;
// int len;
// CPICTURE *pic=NULL;
// gPicture *buf;
// GB_VALUE *value;
// char *key;
//
// key = g_strdup_printf("%s\n%.*s", GB.CurrentComponent(), (int)LENGTH(path), STRING(path));
//
// pic = cache_get(key);
// if (pic)
// {
// g_free(key);
// GB.ReturnObject(pic);
// return;
// }
//
// if (GB.LoadFile(STRING(path),LENGTH(path),&addr,&len))
// {
// buf=gPicture::fromNamedIcon(GB.ToZeroString(ARG(path)));
// if (buf)
// {
// pic = CPICTURE_create(buf);
// goto __OK;
// }
//
// if (LENGTH(path) >= STOCK_PREFIX_LEN && strncmp(STRING(path), STOCK_PREFIX, STOCK_PREFIX_LEN) == 0)
// {
// if (LENGTH(path) == STOCK_PREFIX_LEN) { GB.Error("Unable to load image");return; }
// if (init_stock()) { GB.Error("Unable to load image");return; }
//
// GB.Push(1, GB_T_STRING, &STRING(path)[STOCK_PREFIX_LEN], LENGTH(path) - STOCK_PREFIX_LEN);
// value = GB.Call(&_stock_get_func, 1, false);
// if (value->type >= GB_T_OBJECT)
// pic = (CPICTURE *)((GB_OBJECT *)value)->value;
// if (!pic) { GB.Error("Unable to load image");return; }
// GB.ReturnObject(pic);
// return;
//
// }
//
// //GB.Error("Unable to load image: &1", GB.ToZeroString(ARG(path)));
// //return;
// pic = NULL;
// }
// else
// {
// pic = CPICTURE_create(gPicture::fromMemory(addr, len));
// GB.ReleaseFile(&addr,len);
// }
//
// __OK:
//
// if (pic)
// cache_add(key, pic);
//
// g_free(key);
// GB.ReturnObject(pic);
//
// END_METHOD
/*BEGIN_METHOD(CPICTURE_put, GB_OBJECT picture; GB_STRING path)
CPICTURE *picture=(CPICTURE*)VARG(picture);
char *key;
if (picture)
{
key = g_strdup_printf("%s\n%.*s", GB.CurrentComponent(), (int)LENGTH(path), STRING(path));
cache_add(key, picture);
g_free(key);
}
END_METHOD
*/
/////////////
BEGIN_METHOD(CPICTURE_get, GB_STRING path)

View file

@ -316,8 +316,7 @@ END_METHOD
BEGIN_METHOD_VOID(CFORM_new)
if (!GB.Parent(_object))
GB.Attach(_object, _object, "Form");
GB.Attach(_object, _object, "Form");
END_METHOD

View file

@ -6,7 +6,7 @@ INCLUDES = @GTK_INC@ -I$(top_srcdir)/share
gblib_LTLIBRARIES = gb.gtk.ext.la
gb_gtk_ext_la_LIBADD = @GTK_LIB@
gb_gtk_ext_la_LDFLAGS = -module @LD_FLAGS@
gb_gtk_ext_la_LDFLAGS = -module @LD_FLAGS@ @GTK_LDFLAGS@
gb_gtk_ext_la_SOURCES = \
main.h main.cpp \

View file

@ -233,7 +233,7 @@ void gApplication::setToolTipsFont(gFont *ft)
GList *chd;
PangoFontDescription *desc;
gFont::assign(&app_tooltips_font, ft->copy());
gFont::set(&app_tooltips_font, ft->copy());
if (ft)
desc = pango_context_get_font_description(ft->ct);

View file

@ -615,7 +615,7 @@ gFont* gControl::font()
void gControl::setFont(gFont *ft)
{
gFont::assign(&fnt, ft->copy());
gFont::set(&fnt, ft->copy());
gtk_widget_modify_font(widget, fnt ? fnt->desc() : NULL);
resize();
}

View file

@ -129,7 +129,7 @@ gFont* gDesktop::font()
void gDesktop::setFont(gFont *ft)
{
gFont::assign(&_desktop_font, ft->copy());
gFont::set(&_desktop_font, ft->copy());
_desktop_scale = 0;
}

View file

@ -946,7 +946,7 @@ gFont* gDraw::font()
void gDraw::setFont(gFont *f)
{
gFont::assign(&ft, f->copy());
gFont::set(&ft, f->copy());
}

View file

@ -179,7 +179,6 @@ void gDrawingArea::resizeCache()
if (bw != w || bh != h)
{
//g_debug("resizeCache: (%d %d) -> (%d %d)", bw, bh, w, h);
buf = gdk_pixmap_new(win, w, h, -1);
gc2 = gdk_gc_new(buf);
gdk_gc_set_foreground(gc2, &widget->style->bg[GTK_STATE_NORMAL]);

View file

@ -11,6 +11,7 @@ public:
~gFont();
static void assign(gFont **dst, gFont *src = 0) { gShare::assign((gShare **)dst, src); }
static void set(gFont **dst, gFont *src = 0) { gShare::assign((gShare **)dst, src); src->unref(); }
static void init();
static void exit();

View file

@ -6,7 +6,7 @@
class gGambasTag: public gTag
{
public:
gGambasTag(void *p) : gTag(p) {}
gGambasTag(void *p) : gTag(p) { }
virtual ~gGambasTag() {}
virtual void ref(void *v) { GB.Ref(v); }
virtual void unref(void *v) { GB.Unref((void **)&v); }

View file

@ -388,7 +388,7 @@ gFont* gDialog::font()
void gDialog::setFont(gFont *ft)
{
gFont::assign(&DIALOG_font, ft->copy());
gFont::set(&DIALOG_font, ft->copy());
}
gColor gDialog::color()

View file

@ -39,7 +39,7 @@ class gShare
{
public:
gShare() { nref = 1; tag = NULL; }
virtual ~gShare() { if (tag) while (nref > 1) nref--, tag->unref(); }
virtual ~gShare() { if (tag) { while (nref > 1) nref--, tag->unref(); delete tag; } }
void ref() { nref++; if (tag) tag->ref(); }
void unref() { nref--; if (nref <= 0) delete this; else if (tag) tag->unref(); }

View file

@ -132,10 +132,18 @@ int gTextBox::position()
void gTextBox::setPosition(int pos)
{
int len;
if (!entry)
return;
len = length();
if (pos < 0)
pos=0;
pos = 0;
else if (pos >= len)
pos = -1;
gtk_editable_set_position(GTK_EDITABLE(entry), pos);
}
@ -160,7 +168,6 @@ void gTextBox::insert(char *txt, int len)
int pos = position();
gtk_editable_insert_text(GTK_EDITABLE(entry), txt, len, &pos);
}
int gTextBox::length()

View file

@ -216,8 +216,6 @@ extern "C"
int EXPORT GB_INIT(void)
{
//setGeneralMemoryHandler();
GB.Hook(GB_HOOK_QUIT, (void *)my_quit);
GB.Hook(GB_HOOK_MAIN, (void *)my_main);
GB.Hook(GB_HOOK_WAIT, (void *)my_wait);
@ -324,7 +322,7 @@ gboolean my_timer_function(GB_TIMER *timer)
if (timer->id)
{
MyTimerTag *tag = (MyTimerTag *)timer->tag;
GTimer *t = tag->timer;
GTimer *t = tag->timer;
int elapsed = (int)(g_timer_elapsed(t, NULL) * 1000) - tag->timeout;
int next = timer->delay - elapsed;
if (next < 10)