1. #include "config.h"
  2. #include <gtk/gtk.h>
  3. #include "gtklabelclickable.h"
  4.  
  5. static GdkWindow *
  6. gtk_label_create_window (GtkWidget *widget)
  7. {
  8.   GdkWindow *retval;
  9.   GdkWindowAttr attributes;
  10.   gint attributes_mask;
  11.  
  12.   g_assert (GTK_WIDGET_REALIZED (widget));
  13.  
  14.   attributes.x = widget->allocation.x;
  15.   attributes.y = widget->allocation.y;
  16.   attributes.width = widget->allocation.width;
  17.   attributes.height = widget->allocation.height;
  18.   attributes.window_type = GDK_WINDOW_CHILD;
  19.   attributes.wclass = GDK_INPUT_ONLY;
  20.   attributes.override_redirect = TRUE;
  21.   attributes.event_mask = gtk_widget_get_events (widget) |
  22.     GDK_BUTTON_PRESS_MASK        |
  23.     GDK_BUTTON_RELEASE_MASK      |
  24.     GDK_BUTTON_MOTION_MASK;
  25.   attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_NOREDIR;
  26.  
  27. /*
  28.   attributes.cursor = gdk_cursor_new_for_display (gtk_widget_get_display (widget),
  29.                                                       GDK_XTERM);
  30.   attributes_mask |= GDK_WA_CURSOR;
  31. */
  32.   retval = gdk_window_new (widget->window, &attributes, attributes_mask);
  33.   gdk_window_set_user_data (retval, widget);
  34.  
  35.   GTK_WIDGET_SET_FLAGS (widget, GTK_CAN_FOCUS);
  36.   gdk_window_show (retval);
  37.  
  38.   return retval;
  39. }
  40.  
  41. /* TODO, hook up map and unmap */
  42.  
  43. static void
  44. label_size_allocate (GtkWidget     *widget,
  45.                      GtkAllocation *allocation,
  46.                      gpointer       userdata)
  47. {
  48.     gdk_window_move_resize ( GDK_WINDOW(userdata),
  49.                              allocation->x,
  50.                              allocation->y,
  51.                              allocation->width,
  52.                              allocation->height);
  53. }
  54.  
  55. static void
  56. label_realize (GtkWidget *widget,
  57.                 gpointer   userdata)
  58. {
  59.     GdkWindow *window;
  60.  
  61.     window = gtk_label_create_window (widget);
  62.     g_signal_connect_after (widget, "size_allocate", G_CALLBACK(label_size_allocate), window);
  63. }
  64.  
  65. void MyGtkLabelClickable(GtkLabel *label)
  66. {
  67.     g_signal_connect_after (label, "realize", G_CALLBACK(label_realize), NULL);
  68. }