Changeset 053f751


Ignore:
Timestamp:
Jun 1, 2010, 12:25:28 AM (14 years ago)
Author:
David Benjamin <davidben@mit.edu>
Branches:
master, release-1.10, 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.
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • owl.c

    r4e33cb2 r053f751  
    502502  setlocale(LC_ALL, "");
    503503
     504  g_type_init ();
     505
    504506  memset(&opts, 0, sizeof opts);
    505507  opts.load_initial_subs = 1;
  • popwin.c

    r3da1f4f r053f751  
    6666{
    6767  owl_window_unlink(pw->border);
    68   owl_window_delete(pw->border);
     68  g_object_unref(pw->border);
     69  g_object_unref(pw->content);
    6970  pw->border = 0;
    7071  pw->content = 0;
  • 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
  • window.h

    r3da1f4f r053f751  
    33
    44#include <glib.h>
     5#include <glib-object.h>
    56
    6 typedef struct _owl_window owl_window;
     7G_BEGIN_DECLS
     8
     9#define OWL_TYPE_WINDOW                  (owl_window_get_type ())
     10#define OWL_WINDOW(obj)                  (G_TYPE_CHECK_INSTANCE_CAST ((obj), OWL_TYPE_WINDOW, OwlWindow))
     11#define OWL_IS_WINDOW(obj)               (G_TYPE_CHECK_INSTANCE_TYPE ((obj), OWL_TYPE_WINDOW))
     12#define OWL_WINDOW_CLASS(klass)          (G_TYPE_CHECK_CLASS_CAST ((klass), OWL_TYPE_WINDOW, OwlWindowClass))
     13#define OWL_IS_WINDOW_CLASS(klass)       (G_TYPE_CHECK_CLASS_TYPE ((klass), OWL_TYPE_WINDOW))
     14#define OWL_WINDOW_GET_CLASS(obj)        (G_TYPE_INSTANCE_GET_CLASS ((obj), OWL_TYPE_WINDOW, OwlWindowClass))
     15
     16typedef struct _owl_window OwlWindow;
     17typedef struct _OwlWindowClass OwlWindowClass;
     18typedef OwlWindow owl_window; /* meh */
     19
     20struct _OwlWindowClass
     21{
     22  GObjectClass parent_class;
     23};
     24
     25GType owl_window_get_type(void);
    726
    827owl_window *owl_window_get_screen(void);
    928
    1029owl_window *owl_window_new(owl_window *parent);
    11 void owl_window_delete(owl_window *w);
    1230void owl_window_unlink(owl_window *w);
    1331
     
    4361void owl_window_erase_cb(owl_window *w, WINDOW *win, void *user_data);
    4462
     63G_END_DECLS
     64
    4565#endif /* __BARNOWL_WINDOW_H__ */
Note: See TracChangeset for help on using the changeset viewer.