Changeset 405

Show
Ignore:
Timestamp:
09/20/07 18:07:56 (1 year ago)
Author:
bjourne
Message:

Add overrides that makes GdkPixbufDrawOpts and GdkPixbufDrawCache
boxed types. Also add a constructor for GdkPixbufDrawOpts, implemented
using a function in a (to me) really weird way.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • pygtkimageview/src/gtkimageview.defs

    r401 r405  
    4848  (gtype-id "GTK_TYPE_ANIM_VIEW") 
    4949) 
     50 
     51;; boxes 
     52 
     53;; This is the weird looparounds you have to use to give c-structs 
     54;; constructors. 
     55(define-function pixbuf_draw_opts_new 
     56  (c-name "gdk_pixbuf_draw_opts_new") 
     57  (is-constructor-of "GdkPixbufDrawOpts") 
     58  (return-type "GdkPixbufDrawOpts") 
     59  ) 
     60 
     61(define-boxed PixbufDrawOpts 
     62  (in-module "Gtk") 
     63  (c-name "GdkPixbufDrawOpts") 
     64  (gtype-id "GDK_TYPE_PIXBUF_DRAW_OPTS") 
     65  (fields 
     66   '("gdouble" "zoom") 
     67   '("GdkRectangle" "zoom_rect") 
     68   '("int" "widget_x") 
     69   '("int" "widget_y") 
     70   '("GdkInterpType" "interp") 
     71   '("GdkPixbuf*" "pixbuf") 
     72   '("int" "check_color1") 
     73   '("int" "check_color2") 
     74   ) 
     75  ) 
     76 
     77(define-boxed PixbufDrawCache 
     78  (in-module "Gtk") 
     79  (c-name "GdkPixbufDrawCache") 
     80  (gtype-id "GDK_TYPE_PIXBUF_DRAW_CACHE") 
     81  (fields 
     82   '("GdkPixbuf*" "last_pixbuf") 
     83   '("GdkPixbufDrawOpts" "old") 
     84   '("int" "check_size") 
     85   ) 
     86  ) 
    5087 
    5188;; Enumerations and flags ... 
  • pygtkimageview/src/gtkimageview.override

    r401 r405  
     1/* -*- Mode: C; c-basic-offset: 4 -*- */ 
    12%% 
    23headers 
     
    3637} 
    3738 
     39/* These overrides are here because pygtk insists on that boxed types 
     40   should be registered. */ 
     41#define GDK_TYPE_PIXBUF_DRAW_OPTS (gdk_pixbuf_draw_opts_get_type()) 
     42 
     43static GdkPixbufDrawOpts* 
     44gdk_pixbuf_draw_opts_copy (GdkPixbufDrawOpts *opts) 
     45{ 
     46    return g_memdup (opts, sizeof (GdkPixbufDrawOpts)); 
     47} 
     48 
     49GType 
     50gdk_pixbuf_draw_opts_get_type (void) 
     51{ 
     52    static GType our_type = 0; 
     53    if (our_type) 
     54        return our_type; 
     55    const char *name = g_intern_static_string ("GdkPixbufDrawOpts"); 
     56    our_type = 
     57        g_boxed_type_register_static (name, 
     58                                      (GBoxedCopyFunc) gdk_pixbuf_draw_opts_copy, 
     59                                      (GBoxedFreeFunc )g_free); 
     60    return our_type; 
     61} 
     62 
     63#define GDK_TYPE_PIXBUF_DRAW_CACHE (gdk_pixbuf_draw_cache_get_type()) 
     64 
     65static GdkPixbufDrawCache* 
     66gdk_pixbuf_draw_cache_copy (GdkPixbufDrawCache *cache) 
     67{ 
     68    return g_memdup (cache, sizeof (GdkPixbufDrawCache)); 
     69} 
     70 
     71GType 
     72gdk_pixbuf_draw_cache_get_type (void) 
     73{ 
     74    static GType our_type = 0; 
     75    if (our_type) 
     76        return our_type; 
     77    const char *name = g_intern_static_string ("GdkPixbufDrawCache"); 
     78    our_type = 
     79        g_boxed_type_register_static (name, 
     80                                      (GBoxedCopyFunc) gdk_pixbuf_draw_cache_copy, 
     81                                      (GBoxedFreeFunc) gdk_pixbuf_draw_cache_free); 
     82    return our_type; 
     83} 
     84 
     85/* We must also add more boilerplate to make instantiation work. */ 
    3886%% 
    3987module gtkimageview 
     
    77125    return pyg_boxed_new (GDK_TYPE_RECTANGLE, &rect, TRUE, TRUE); 
    78126} 
     127%% 
     128override gdk_pixbuf_draw_opts_new kwargs 
     129static int 
     130_wrap_gdk_pixbuf_draw_opts_new (PyGBoxed *self, 
     131                                PyObject *args, 
     132                                PyObject *kwargs) 
     133{ 
     134    static char *kwlist[] = { 
     135        "zoom", "zoom_rect", 
     136        "widget_x", "widget_y", 
     137        "interp", 
     138        "pixbuf", 
     139        "check_color1", "check_color2", 
     140        NULL 
     141    }; 
     142    GdkPixbufDrawOpts opts = { 
     143        0, {0, 0, 0, 0}, 
     144        0, 0, 
     145        GDK_INTERP_BILINEAR, 
     146        NULL, 
     147        0, 0 
     148    }; 
    79149 
     150    if (!PyArg_ParseTupleAndKeywords (args, kwargs, 
     151                                      "|fOiiOOii:GdkPixbufDrawOpts.__init__", 
     152                                      kwlist, 
     153                                      &opts.zoom, &opts.zoom_rect, 
     154                                      &opts.widget_x, &opts.widget_y, 
     155                                      &opts.interp, &opts.pixbuf, 
     156                                      &opts.check_color1, &opts.check_color2)) 
     157        return -1; 
     158 
     159    self->boxed = g_boxed_copy (GDK_TYPE_PIXBUF_DRAW_OPTS, &opts); 
     160    self->free_on_dealloc = TRUE; 
     161    self->gtype = GDK_TYPE_PIXBUF_DRAW_OPTS; 
     162 
     163    return 0; 
     164} 
     165 
     166