X-Git-Url: http://git.code-monkey.de/?a=blobdiff_plain;f=src%2Fesmart_file_dialog%2Frb_esmart_file_dialog.c;h=ba62e24992fbb3b39d45e227b582b6f488e80325;hb=6f0fed37e64e6ec18bd73544528a652a229aee66;hp=ad61a521d7766e62115a1d1f2c349d41d079968d;hpb=afcdcdd3b9f7fa92ed327bb189cf6b09cc94c5bf;p=ruby-esmart.git diff --git a/src/esmart_file_dialog/rb_esmart_file_dialog.c b/src/esmart_file_dialog/rb_esmart_file_dialog.c index ad61a52..ba62e24 100644 --- a/src/esmart_file_dialog/rb_esmart_file_dialog.c +++ b/src/esmart_file_dialog/rb_esmart_file_dialog.c @@ -1,5 +1,5 @@ /* - * $Id: rb_esmart_file_dialog.c 336 2005-05-02 17:29:52Z tilman $ + * $Id: rb_esmart_file_dialog.c 391 2006-11-11 12:14:24Z tilman $ * * Copyright (C) 2005 Tilman Sauerbeck (tilman at code-monkey de) * @@ -32,6 +32,11 @@ typedef struct { VALUE edje; } RbFileDialog; +static void on_action (void *data, Evas_Object *edje, + Esmart_File_Dialog_Op op); + +static VALUE cEdje; + static void c_mark (RbFileDialog *e) { c_evas_object_mark (&e->real); @@ -49,28 +54,39 @@ static void c_free (RbFileDialog *e) free (e); } -static VALUE c_new (VALUE klass, VALUE evas, VALUE edj) +static VALUE c_alloc (VALUE klass) { - VALUE self, argv[1]; RbFileDialog *fd = NULL; + return Data_Make_Struct (klass, RbFileDialog, c_mark, c_free, fd); +} + +static VALUE c_init (VALUE self, VALUE evas, VALUE edj) +{ + if (!rb_block_given_p ()) { + rb_raise (rb_eStandardError, "no block given"); + return Qnil; + } + CHECK_CLASS (evas, cEvas); StringValue (edj); GET_OBJ (evas, RbEvas, e); + GET_OBJ (self, RbFileDialog, fd); - self = Data_Make_Struct (klass, RbFileDialog, c_mark, c_free, fd); fd->real.real = esmart_file_dialog_new (e->real, StringValuePtr (edj)); if (!fd->real.real) rb_raise (rb_eStandardError, "failed"); - argv[0] = evas; - rb_obj_call_init (self, 1, argv); + rb_call_super (1, &evas); - fd->callback = Qnil; + fd->callback = rb_block_proc (); fd->edje = Qnil; + esmart_file_dialog_callback_add (fd->real.real, on_action, + (void *) fd->callback); + return self; } @@ -105,38 +121,15 @@ static void on_action (void *data, Evas_Object *edje, rb_funcall ((VALUE) data, rb_intern ("call"), 1, ID2SYM (sym)); } -static VALUE c_on_action (VALUE self) -{ - GET_OBJ (self, RbFileDialog, fd); - - if (!rb_block_given_p ()) - return Qnil; - - fd->callback = rb_block_proc (); - - esmart_file_dialog_callback_add (fd->real.real, on_action, - (void *) fd->callback); - - return Qnil; -} - static VALUE c_edje_get (VALUE self) { Evas_Object *e; - VALUE mEdje, cEdje, s; - ID const_get; GET_OBJ (self, RbFileDialog, fd); if (!NIL_P (fd->edje)) return fd->edje; - const_get = rb_intern ("const_get"); - s = rb_str_new2 ("Edje"); - - mEdje = rb_funcall (rb_cModule, const_get, 1, s); - cEdje = rb_funcall (mEdje, const_get, 1, s); - e = esmart_file_dialog_edje_get (fd->real.real); fd->edje = rb_funcall (cEdje, rb_intern ("new_from_pointer"), 2, TO_EVAS (self, evas_object_evas_get (e)), @@ -177,14 +170,18 @@ static VALUE c_current_directory_get (VALUE self) void Init_esmart_file_dialog (void) { - VALUE c; + VALUE m, c; rb_require ("esmart"); + rb_require ("edje"); + + m = rb_const_get (rb_cModule, rb_intern ("Edje")); + cEdje = rb_const_get (m, rb_intern ("Edje")); c = rb_define_class_under (mEsmart, "FileDialog", cEvasObject); - rb_define_singleton_method (c, "new", c_new, 2); - rb_define_method (c, "on_action", c_on_action, 0); + rb_define_alloc_func (c, c_alloc); + rb_define_method (c, "initialize", c_init, 2); rb_define_method (c, "edje", c_edje_get, 0); rb_define_method (c, "selections", c_selections_get, 0); rb_define_method (c, "current_directory", c_current_directory_get, 0);