Ejemplo n.º 1
0
static void
seed_builder_connect_func (GtkBuilder *builder,
			   GObject *object,
			   const gchar *signal_name,
			   const gchar *handler_name,
			   GObject *connect_object,
			   GConnectFlags flags,
			   gpointer user_data)
{
  SeedContext ctx;
  SeedObject obj, func;
  builder_ud *priv = (builder_ud *)user_data;
  GClosure *closure;

  ctx = priv->ctx;
  obj = priv->obj;

  func = seed_object_get_property (ctx, obj, handler_name);
  if (!seed_value_is_object (ctx, func) || !seed_value_is_function (ctx, func))
    return;

  closure = seed_closure_new (ctx, func, priv->user_data,
                              "signal handler (GtkBuilder)");
  if (connect_object != NULL)
    g_object_watch_closure (connect_object, closure);

  g_signal_connect_closure (object, signal_name, closure, FALSE);
}
Ejemplo n.º 2
0
void
netstatus_connect_signal_while_alive (gpointer    object,
                                      const char *detailed_signal,
                                      GCallback   func,
                                      gpointer    func_data,
                                      gpointer    alive_object)
{
  GClosure *closure;
  GType     type;
  guint     signal_id = 0;
  GQuark    detail = 0;
  
  type = G_OBJECT_TYPE (object);

  if (!g_signal_parse_name (detailed_signal, type, &signal_id, &detail, FALSE))
    {
      g_warning (G_STRLOC ": unable to parse signal \"%s\" for type \"%s\"",
                 detailed_signal, g_type_name (type));
      return;
    }

  closure = g_cclosure_new (func, func_data, NULL);
  g_object_watch_closure (G_OBJECT (alive_object), closure);
  g_signal_connect_closure_by_id (object, signal_id, detail, closure, FALSE);
}
Ejemplo n.º 3
0
/*#
    @method connect_group
    @brief Installs an accelerator in this group.
    @param accel_key key of the accelerator
    @param accel_mods modifier combination of the accelerator
    @param accel_flags a flag mask to configure this accelerator
    @param callback a function or method to be executed upon accelerator activation

    The connect_group() method installs an accelerator in the accelerator group.
    When the accelerator group is being activated, the function (or method)
    specified by callback will be invoked if the accelerator key and modifier key
    match those specified by accel_key and accel_mods.

    The value of modifier is a combination of the GDK Modifier Constants.
    accel_flags is a combination of gtk.ACCEL_VISIBLE and gtk.ACCEL_LOCKED.

    The callback function is defined as:

    function callback(acceleratable, keyval, modifier)

    where acceleratable is the object that
    the accel_group is attached to (e.g. a gtk.Window), keyval is the accelerator
    key and modifier is the key modifier. callback returns True if the accelerator
    was handled by callback.
 */
FALCON_FUNC AccelGroup::connect_group( VMARG )
{
    Item* i_key = vm->param( 0 );
    Item* i_mods = vm->param( 1 );
    Item* i_flags = vm->param( 2 );
    Item* i_cb = vm->param( 3 );
#ifndef NO_PARAMETER_CHECK
    if ( !i_key || !i_key->isString()
        || !i_mods || !i_mods->isInteger()
        || !i_flags || !i_flags->isInteger()
        || !i_cb || !( i_cb->isCallable() || i_cb->isComposed() ) )
        throw_inv_params( "S,GdkModifierType,GtkAccelFlags,C" );
#endif
    MYSELF;
    GET_OBJ( self );
    String* chr = i_key->asString();
    guint keyval = chr->length() ? chr->getCharAt( 0 ) : 0;

    GarbageLock* lock = CoreGObject::lockItem( _obj, *i_cb );
    GClosure* cl = g_cclosure_new( G_CALLBACK( &AccelGroup::activate_cb ),
                                   (gpointer) lock,
                                   NULL );
    g_object_watch_closure( _obj, cl );

    gtk_accel_group_connect( GET_ACCELGROUP( vm->self() ),
                             keyval,
                             (GdkModifierType) i_mods->asInteger(),
                             (GtkAccelFlags) i_flags->asInteger(),
                             cl );
}
Ejemplo n.º 4
0
static void _gjs_builder_connect_func (GtkBuilder *builder,
                                       GObject *object,
                                       const gchar *signal_name,
                                       const gchar *handler_name,
                                       GObject *connect_object,
                                       GConnectFlags flags,
                                       gpointer user_data)
{
    builder_ud *priv = (builder_ud *)user_data;
    JSContext *ctx = priv->ctx;
    JSObject *obj = priv->obj;
    GClosure *closure;
    JSObject *callable;
    builder_cd *cd;
    closure_data *c;
    jsval func;

    if (!gjs_object_get_property (ctx, obj, handler_name, &func))
        return;

    if (!JSVAL_IS_OBJECT(func))
        return;

    callable = JSVAL_TO_OBJECT (func);
    if (!JS_ObjectIsFunction(ctx, callable))
        return;

    /* Protect from garbage collection. */
    cd = g_object_get_data (G_OBJECT (builder), GJS_BUILDER_CLOSURE_KEY);
    if (!cd) {
        cd = g_new0 (builder_cd, 1);
        cd->context = ctx;
        cd->closures = NULL;
        g_object_set_data_full (G_OBJECT (builder),
                                GJS_BUILDER_CLOSURE_KEY,
                                cd,
                                (GDestroyNotify) _builder_cd_free);
    }

    g_assert (cd->context == ctx);

    c = g_new0 (closure_data, 1);
    c->jsobj = callable;
    cd->closures = g_slist_prepend (cd->closures, c);
    JS_AddObjectRoot (ctx, &c->jsobj);

    closure = gjs_closure_new_for_signal (ctx,
                                          callable,
                                          "signal handler (GtkBuilder)",
                                          0);
    if (connect_object != NULL)
        g_object_watch_closure (connect_object, closure);

    c->object = g_object_ref (object);
    c->handler_id = g_signal_connect_closure (object, signal_name, closure, FALSE);
}
Ejemplo n.º 5
0
/* Handle the kAEOpenDocuments Apple events. This will register
 * an idle source callback for each filename in the event.
 */
static pascal OSErr
gui_unique_mac_open_documents (const AppleEvent *inAppleEvent,
                               AppleEvent       *outAppleEvent,
                               long              handlerRefcon)
{
  OSStatus    status;
  AEDescList  documents;
  gchar       path[MAXPATHLEN];

  status = AEGetParamDesc (inAppleEvent,
                           keyDirectObject, typeAEList,
                           &documents);
  if (status == noErr)
    {
      long count = 0;
      int  i;

      AECountItems (&documents, &count);

      for (i = 0; i < count; i++)
        {
          FSRef    ref;
          gchar    *callback_path;
          GSource  *source;
          GClosure *closure;

          status = AEGetNthPtr (&documents, i + 1, typeFSRef,
                                0, 0, &ref, sizeof (ref),
                                0);
          if (status != noErr)
            continue;

          FSRefMakePath (&ref, (UInt8 *) path, MAXPATHLEN);

          callback_path = g_strdup (path);

          closure = g_cclosure_new (G_CALLBACK (gui_unique_mac_idle_open),
                                    (gpointer) callback_path,
                                    (GClosureNotify) g_free);

          g_object_watch_closure (G_OBJECT (unique_gimp), closure);

          source = g_idle_source_new ();
          g_source_set_priority (source, G_PRIORITY_LOW);
          g_source_set_closure (source, closure);
          g_source_attach (source, NULL);
          g_source_unref (source);
        }
    }

    return status;
}
Ejemplo n.º 6
0
static void
matewncklet_connect_while_alive (gpointer object,
                             const char *signal,
                             GCallback func,
                             gpointer func_data, gpointer alive_object)
{
  GClosure *closure;

  closure = g_cclosure_new (func, func_data, NULL);
  g_object_watch_closure (G_OBJECT (alive_object), closure);
  g_signal_connect_closure_by_id (object,
                                  g_signal_lookup (signal,
                                                   G_OBJECT_TYPE (object)), 0,
                                  closure, FALSE);
}
Ejemplo n.º 7
0
void
gtk_signal_connect_while_alive (GtkObject    *object,
				const gchar  *name,
				GtkSignalFunc func,
				gpointer      func_data,
				GtkObject    *alive_object)
{
  GClosure *closure;

  g_return_if_fail (GTK_IS_OBJECT (object));

  closure = g_cclosure_new (func, func_data, NULL);
  g_object_watch_closure (G_OBJECT (alive_object), closure);
  g_signal_connect_closure_by_id (object,
				  g_signal_lookup (name, G_OBJECT_TYPE (object)), 0,
				  closure,
				  FALSE);
}
Ejemplo n.º 8
0
static LRESULT CALLBACK
gui_unique_win32_message_handler (HWND   hWnd,
                                  UINT   uMsg,
                                  WPARAM wParam,
                                  LPARAM lParam)
{
  switch (uMsg)
    {
    case WM_COPYDATA:
      if (unique_gimp)
        {
          COPYDATASTRUCT *copydata = (COPYDATASTRUCT *) lParam;
          GSource        *source;
          GClosure       *closure;
          IdleOpenData   *data;

          data = idle_open_data_new (copydata->lpData,
                                     copydata->cbData,
                                     copydata->dwData != 0);

          closure = g_cclosure_new (G_CALLBACK (gui_unique_win32_idle_open),
                                    data,
                                    (GClosureNotify) idle_open_data_free);

          g_object_watch_closure (unique_gimp, closure);

          source = g_idle_source_new ();
          g_source_set_priority (source, G_PRIORITY_LOW);
          g_source_set_closure (source, closure);
          g_source_attach (source, NULL);
          g_source_unref (source);
        }
      return TRUE;

    default:
      return DefWindowProcW (hWnd, uMsg, wParam, lParam);
    }
}
Ejemplo n.º 9
0
static void
track_monitor_hierarchy_changed (GtkWidget        *widget,
                                 GtkWidget        *previous_toplevel,
                                 TrackMonitorData *track_data)
{
  GtkWidget *toplevel;

  if (previous_toplevel)
    {
      g_signal_handlers_disconnect_by_func (previous_toplevel,
                                            track_monitor_configure_event,
                                            track_data);
    }

  toplevel = gtk_widget_get_toplevel (widget);

  if (GTK_IS_WINDOW (toplevel))
    {
      GClosure *closure;
      gint      monitor;

      closure = g_cclosure_new (G_CALLBACK (track_monitor_configure_event),
                                track_data, NULL);
      g_object_watch_closure (G_OBJECT (widget), closure);
      g_signal_connect_closure (toplevel, "configure-event", closure, FALSE);

      monitor = gimp_widget_get_monitor (toplevel);

      if (monitor != track_data->monitor)
        {
          track_data->monitor = monitor;

          track_data->callback (track_data->widget, track_data->user_data);
        }
    }
}
Ejemplo n.º 10
0
/*
 *  create a generic query box without any entry widget
 */
static QueryBox *
create_query_box (const gchar   *title,
                  GtkWidget     *parent,
                  GimpHelpFunc   help_func,
                  const gchar   *help_id,
                  GCallback      response_callback,
                  const gchar   *icon_name,
                  const gchar   *message,
                  const gchar   *ok_button,
                  const gchar   *cancel_button,
                  GObject       *object,
                  const gchar   *signal,
                  GCallback      callback,
                  gpointer       callback_data)
{
  QueryBox  *query_box;
  GtkWidget *hbox = NULL;
  GtkWidget *label;

  /*  make sure the object / signal passed are valid
   */
  g_return_val_if_fail (parent == NULL || GTK_IS_WIDGET (parent), NULL);
  g_return_val_if_fail (object == NULL || G_IS_OBJECT (object), NULL);
  g_return_val_if_fail (object == NULL || signal != NULL, NULL);

  query_box = g_slice_new0 (QueryBox);

  query_box->qbox = gimp_dialog_new (title, "gimp-query-box",
                                     parent, 0,
                                     help_func, help_id,

                                     cancel_button, GTK_RESPONSE_CANCEL,
                                     ok_button,     GTK_RESPONSE_OK,

                                     NULL);

  gtk_dialog_set_alternative_button_order (GTK_DIALOG (query_box->qbox),
                                           GTK_RESPONSE_OK,
                                           GTK_RESPONSE_CANCEL,
                                           -1);

  query_box->response_handler =
    g_signal_connect (query_box->qbox, "response",
                      G_CALLBACK (response_callback),
                      query_box);

  g_signal_connect (query_box->qbox, "destroy",
                    G_CALLBACK (gtk_widget_destroyed),
                    &query_box->qbox);

  /*  if we are associated with an object, connect to the provided signal
   */
  if (object)
    {
      GClosure *closure;

      closure = g_cclosure_new_swap (G_CALLBACK (query_box_cancel_callback),
                                     query_box, NULL);
      g_object_watch_closure (G_OBJECT (query_box->qbox), closure);

      g_signal_connect_closure (object, signal, closure, FALSE);
    }

  if (icon_name)
    {
      GtkWidget *content_area;
      GtkWidget *image;

      content_area = gtk_dialog_get_content_area (GTK_DIALOG (query_box->qbox));

      hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 12);
      gtk_container_set_border_width (GTK_CONTAINER (hbox), 12);
      gtk_box_pack_start (GTK_BOX (content_area), hbox, TRUE, TRUE, 0);
      gtk_widget_show (hbox);

      image = gtk_image_new_from_icon_name (icon_name, GTK_ICON_SIZE_DIALOG);
      gtk_misc_set_alignment (GTK_MISC (image), 0.5, 0.0);
      gtk_box_pack_start (GTK_BOX (hbox), image, FALSE, FALSE, 0);
      gtk_widget_show (image);
    }

  query_box->vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 12);

  g_object_set_data (G_OBJECT (query_box->qbox), "gimp-query-box-vbox",
                     query_box->vbox);

  if (hbox)
    {
      gtk_box_pack_start (GTK_BOX (hbox), query_box->vbox, FALSE, FALSE, 0);
    }
  else
    {
      GtkWidget *content_area;

      content_area = gtk_dialog_get_content_area (GTK_DIALOG (query_box->qbox));

      gtk_container_set_border_width (GTK_CONTAINER (query_box->vbox), 12);
      gtk_box_pack_start (GTK_BOX (content_area), query_box->vbox,
                          TRUE, TRUE, 0);
    }

  gtk_widget_show (query_box->vbox);

  if (message)
    {
      label = gtk_label_new (message);
      gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
      gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
      gtk_box_pack_start (GTK_BOX (query_box->vbox), label, FALSE, FALSE, 0);
      gtk_widget_show (label);
    }

  query_box->entry         = NULL;
  query_box->object        = object;
  query_box->callback      = callback;
  query_box->callback_data = callback_data;

  return query_box;
}
Ejemplo n.º 11
0
/**
 * gnome_popup_menu_attach:
 * @popup: A menu widget.
 * @widget: The widget to attach the popup menu to.
 * @user_data: Application specific data passed to the callback.
 *
 * Attaches the specified popup menu to the specified widget.  The
 * menu can then be activated by pressing mouse button 3 over the
 * widget.  When a menu item callback is invoked, the specified
 * user_data will be passed to it.
 *
 * This function requires the widget to have its own window
 * (i.e. GTK_WIDGET_NO_WINDOW (widget) == FALSE), This function will
 * try to set the GDK_BUTTON_PRESS_MASK flag on the widget's event
 * mask if it does not have it yet; if this is the case, then the
 * widget must not be realized for it to work.
 *
 * The popup menu can be attached to different widgets at the same
 * time.  A reference count is kept on the popup menu; when all the
 * widgets it is attached to are destroyed, the popup menu will be
 * destroyed as well.
 *
 * Under the current implementation, setting a popup menu for a NO_WINDOW
 * widget and then reparenting that widget will cause Bad Things to happen.
 */
void
gnome_popup_menu_attach (GtkWidget *popup, GtkWidget *widget,
			 gpointer user_data)
{
        GtkWidget *ev_widget;

	g_return_if_fail (popup != NULL);
	g_return_if_fail (GTK_IS_MENU (popup));
	g_return_if_fail (widget != NULL);
	g_return_if_fail (GTK_IS_WIDGET (widget));

	if(g_object_get_data (G_OBJECT (widget), "gnome_popup_menu"))
	  return;

	g_object_set_data (G_OBJECT (widget), "gnome_popup_menu", popup);

	/* This operation can fail if someone is trying to set a popup on e.g. an uncontained label, so we do it first. */
	for(ev_widget = widget; ev_widget && GTK_WIDGET_NO_WINDOW(ev_widget); ev_widget = ev_widget->parent)
	  {
	    g_object_set_data (G_OBJECT (ev_widget), "gnome_popup_menu_nowindow", GUINT_TO_POINTER(1));
	  }

	g_return_if_fail (ev_widget);

	/* Ref/sink the popup menu so that we take "ownership" of it */

	g_object_ref (G_OBJECT (popup));
	gtk_object_sink (GTK_OBJECT (popup));

	/* Store the user data pointer in the widget -- we will use it later when the menu has to be
	 * invoked.
	 */

	g_object_set_data (G_OBJECT (widget), "gnome_popup_menu_attach_user_data", user_data);
	g_object_set_data (G_OBJECT (widget), "gnome_popup_menu", user_data);

	/* Prepare the widget to accept button presses -- the proper assertions will be
	 * shouted by gtk_widget_set_events().
	 */

	gtk_widget_add_events (ev_widget, GDK_BUTTON_PRESS_MASK |
			       GDK_KEY_PRESS_MASK);

	g_signal_connect (widget, "button_press_event",
			  G_CALLBACK (popup_button_pressed), popup);

	g_signal_connect (G_OBJECT (widget), "popup_menu",
			  G_CALLBACK (popup_menu_pressed), popup);

	if (ev_widget != widget) {
		GClosure *closure;

		closure = g_cclosure_new (G_CALLBACK (relay_popup_button_pressed),
					  popup,
					  NULL);
		g_object_watch_closure (G_OBJECT (widget), closure);
		g_signal_connect_closure (ev_widget, "button_press_event",
					  closure, FALSE);
	}

	/* This callback will unref the popup menu when the widget it is attached to gets destroyed. */
	g_signal_connect (widget, "destroy",
			  G_CALLBACK (popup_attach_widget_destroyed),
			  popup);
}