Changeset 1d74663


Ignore:
Timestamp:
Sep 18, 2010, 5:07:39 PM (14 years ago)
Author:
David Benjamin <davidben@mit.edu>
Branches:
master, release-1.10, release-1.7, release-1.8, release-1.9
Children:
cb81570
Parents:
818f19c
git-author:
David Benjamin <davidben@mit.edu> (08/07/10 16:15:02)
git-committer:
David Benjamin <davidben@mit.edu> (09/18/10 17:07:39)
Message:
Add deactivate and delete hooks for owl_context

Also make pushing and popping slightly more flexible.
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • context.c

    r07b59ea r1d74663  
    5353  return(ctx->mode & OWL_CTX_INTERACTIVE)?1:0;
    5454}
     55
     56void owl_context_deactivate(owl_context *ctx)
     57{
     58  if (ctx->deactivate_cb)
     59    ctx->deactivate_cb(ctx);
     60}
     61
     62void owl_context_delete(owl_context *ctx)
     63{
     64  if (ctx->cursor)
     65    g_object_unref(ctx->cursor);
     66  owl_free(ctx->keymap);
     67  if (ctx->delete_cb)
     68    ctx->delete_cb(ctx);
     69  owl_free(ctx);
     70}
  • global.c

    r818f19c r1d74663  
    174174    mode |= OWL_CTX_INTERACTIVE;
    175175  c = owl_malloc(sizeof *c);
     176  memset(c, 0, sizeof(*c));
    176177  c->mode = mode;
    177178  c->data = data;
    178179  c->cursor = cursor ? g_object_ref(cursor) : NULL;
    179180  c->keymap = owl_strdup(keymap);
     181  owl_global_push_context_obj(g, c);
     182}
     183
     184void owl_global_push_context_obj(owl_global *g, owl_context *c)
     185{
    180186  g->context_stack = g_list_prepend(g->context_stack, c);
    181187  owl_global_activate_context(g, owl_global_get_context(g));
    182188}
    183189
     190/* Pops the current context from the context stack and returns it. Caller is
     191 * responsible for freeing. */
     192owl_context *owl_global_pop_context_no_delete(owl_global *g) {
     193  owl_context *c;
     194  if (!g->context_stack)
     195    return NULL;
     196  c = owl_global_get_context(g);
     197  owl_context_deactivate(c);
     198  g->context_stack = g_list_delete_link(g->context_stack,
     199                                        g->context_stack);
     200  owl_global_activate_context(g, owl_global_get_context(g));
     201  return c;
     202}
     203
     204/* Pops the current context from the context stack and deletes it. */
    184205void owl_global_pop_context(owl_global *g) {
    185206  owl_context *c;
    186   if (!g->context_stack)
    187     return;
    188   c = owl_global_get_context(g);
    189   g->context_stack = g_list_delete_link(g->context_stack,
    190                                         g->context_stack);
    191   if (c->cursor)
    192     g_object_unref(c->cursor);
    193   owl_free(c->keymap);
    194   owl_free(c);
    195   owl_global_activate_context(g, owl_global_get_context(g));
     207  c = owl_global_pop_context_no_delete(g);
     208  if (c)
     209    owl_context_delete(c);
    196210}
    197211
  • owl.h

    r60c1386 r1d74663  
    304304  char *keymap;
    305305  owl_window *cursor;
     306  void (*deactivate_cb)(struct _owl_context*);
     307  void (*delete_cb)(struct _owl_context*);
    306308} owl_context;
    307309
Note: See TracChangeset for help on using the changeset viewer.