Changeset 053f751 for window.c


Ignore:
Timestamp:
Jun 1, 2010, 12:25:28 AM (11 years ago)
Author:
David Benjamin <davidben@mit.edu>
Branches:
master, release-1.7, release-1.8, release-1.9
Children:
e00355d
Parents:
4751077a
git-author:
David Benjamin <davidben@mit.edu> (06/01/10 00:24:15)
git-committer:
David Benjamin <davidben@mit.edu> (06/01/10 00:25:28)
Message:
For prototyping, use a GObject-backed owl_window

It gives us many signals and refcounting conveniences. This first
iteration doesn't use any of these features but gets it barely working
quickly.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • window.c

    r3da1f4f r053f751  
    44
    55struct _owl_window { /*noproto*/
     6  GObject object;
    67  /* hierarchy information */
    78  owl_window *parent;
     
    3233};
    3334
     35static void owl_window_dispose(GObject *gobject);
     36static void owl_window_finalize(GObject *gobject);
     37
    3438static owl_window *_owl_window_new(owl_window *parent, int nlines, int ncols, int begin_y, int begin_x);
    3539
     
    4145static void _owl_window_realize(owl_window *w);
    4246static void _owl_window_unrealize(owl_window *w);
     47
     48G_DEFINE_TYPE (OwlWindow, owl_window, G_TYPE_OBJECT)
     49
     50static void owl_window_class_init (OwlWindowClass *klass)
     51{
     52  GObjectClass *object_class = G_OBJECT_CLASS (klass);
     53
     54  object_class->dispose = owl_window_dispose;
     55  object_class->finalize = owl_window_finalize;
     56}
     57
     58static void owl_window_dispose (GObject *object)
     59{
     60  owl_window *w = OWL_WINDOW (object);
     61
     62  /* Unmap the window */
     63  owl_window_hide (w);
     64
     65  /* Unlink and unref all children */
     66  while (w->child) {
     67    owl_window *child = w->child;
     68    owl_window_unlink (child);
     69  }
     70
     71  /* Clear all cbs */
     72  owl_window_set_redraw_cb (w, 0, 0, 0);
     73  owl_window_set_size_cb (w, 0, 0, 0);
     74  owl_window_set_destroy_cb (w, 0, 0, 0);
     75
     76  /* Remove from hierarchy */
     77  owl_window_unlink (w);
     78
     79  G_OBJECT_CLASS (owl_window_parent_class)->dispose (object);
     80}
     81
     82static void owl_window_finalize (GObject *object)
     83{
     84  owl_window *w = OWL_WINDOW(object);
     85
     86  if (w->pan) {
     87    del_panel(w->pan);
     88    w->pan = NULL;
     89  }
     90
     91  G_OBJECT_CLASS (owl_window_parent_class)->finalize (object);
     92}
     93
     94static void owl_window_init (owl_window *w)
     95{
     96}
    4397
    4498/** singletons **/
     
    90144  owl_window *w;
    91145
    92   w = owl_malloc(sizeof(owl_window));
    93   memset(w, 0, sizeof(*w));
     146  w = g_object_new (OWL_TYPE_WINDOW, NULL);
     147  if (w == NULL) g_error("Failed to create owl_window instance");
    94148
    95149  w->nlines = nlines;
     
    105159
    106160  return w;
    107 }
    108 
    109 void owl_window_delete(owl_window *w)
    110 {
    111   /* destroy all children */
    112   owl_window_children_foreach_onearg(w, owl_window_delete);
    113 
    114   /* notify everyone of your imminent demise */
    115   if (w->destroy_cb)
    116     w->destroy_cb(w, w->destroy_cbdata);
    117 
    118   /* clear all cbs */
    119   owl_window_set_redraw_cb(w, 0, 0, 0);
    120   owl_window_set_size_cb(w, 0, 0, 0);
    121   owl_window_set_destroy_cb(w, 0, 0, 0);
    122 
    123   /* destroy curses structures */
    124   owl_window_unmap(w);
    125   if (w->pan) {
    126     del_panel(w->pan);
    127   }
    128 
    129   /* remove from hierarchy */
    130   _owl_window_unlink(w);
    131   owl_free(w);
    132161}
    133162
     
    193222      w->parent->child = w->next;
    194223    w->parent = NULL;
     224    g_object_unref (w);
    195225  }
    196226}
     
    206236    w->next = parent->child;
    207237    parent->child = w;
     238    g_object_ref (w);
    208239  }
    209240}
     
    222253void owl_window_children_foreach_onearg(owl_window *parent, void (*func)(owl_window*))
    223254{
    224   owl_window *w;
    225   for (w = parent->child;
    226        w != NULL;
    227        w = w->next) {
    228     func(w);
    229   }
     255  owl_window_children_foreach(parent, (GFunc)func, NULL);
    230256}
    231257
Note: See TracChangeset for help on using the changeset viewer.