2001-08-19 02:23:59 -04:00
|
|
|
/* Metacity popup window thing showing windows you can tab to */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright (C) 2001 Havoc Pennington
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License as
|
|
|
|
* published by the Free Software Foundation; either version 2 of the
|
|
|
|
* License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful, but
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
|
|
|
|
* 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "util.h"
|
2001-08-30 00:01:38 -04:00
|
|
|
#include "core.h"
|
|
|
|
#include "tabpopup.h"
|
2001-08-19 02:23:59 -04:00
|
|
|
#include <gtk/gtk.h>
|
2002-02-06 22:07:56 -05:00
|
|
|
#include <math.h>
|
2001-08-19 02:23:59 -04:00
|
|
|
|
2001-08-22 23:24:51 -04:00
|
|
|
#define OUTSIDE_SELECT_RECT 2
|
|
|
|
#define INSIDE_SELECT_RECT 2
|
|
|
|
|
2001-08-19 02:23:59 -04:00
|
|
|
typedef struct _TabEntry TabEntry;
|
|
|
|
|
|
|
|
struct _TabEntry
|
|
|
|
{
|
|
|
|
Window xwindow;
|
|
|
|
char *title;
|
|
|
|
GdkPixbuf *icon;
|
|
|
|
GtkWidget *widget;
|
2001-08-29 00:53:48 -04:00
|
|
|
GdkRectangle rect;
|
2001-08-30 00:01:38 -04:00
|
|
|
GdkRectangle inner_rect;
|
2001-08-19 02:23:59 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
struct _MetaTabPopup
|
|
|
|
{
|
|
|
|
GtkWidget *window;
|
|
|
|
GtkWidget *label;
|
|
|
|
GList *current;
|
|
|
|
GList *entries;
|
2001-08-29 01:07:39 -04:00
|
|
|
TabEntry *current_selected_entry;
|
2001-08-29 00:53:48 -04:00
|
|
|
GtkWidget *outline_window;
|
2001-08-19 02:23:59 -04:00
|
|
|
};
|
|
|
|
|
2001-08-22 23:24:51 -04:00
|
|
|
static GtkWidget* selectable_image_new (GdkPixbuf *pixbuf);
|
|
|
|
static void select_image (GtkWidget *widget);
|
|
|
|
static void unselect_image (GtkWidget *widget);
|
|
|
|
|
2001-08-29 01:07:39 -04:00
|
|
|
static gboolean
|
|
|
|
outline_window_expose (GtkWidget *widget,
|
|
|
|
GdkEventExpose *event,
|
|
|
|
gpointer data)
|
|
|
|
{
|
|
|
|
MetaTabPopup *popup;
|
|
|
|
int w, h;
|
2001-08-30 00:01:38 -04:00
|
|
|
TabEntry *te;
|
2001-08-29 01:07:39 -04:00
|
|
|
|
|
|
|
popup = data;
|
|
|
|
|
|
|
|
if (popup->current_selected_entry == NULL)
|
|
|
|
return FALSE;
|
2001-08-30 00:01:38 -04:00
|
|
|
|
|
|
|
te = popup->current_selected_entry;
|
2001-08-29 01:07:39 -04:00
|
|
|
|
|
|
|
gdk_window_get_size (widget->window, &w, &h);
|
|
|
|
|
|
|
|
gdk_draw_rectangle (widget->window,
|
|
|
|
widget->style->white_gc,
|
2001-08-30 00:01:38 -04:00
|
|
|
FALSE,
|
|
|
|
0, 0,
|
|
|
|
te->rect.width - 1,
|
|
|
|
te->rect.height - 1);
|
2001-08-29 01:07:39 -04:00
|
|
|
|
2001-08-30 00:01:38 -04:00
|
|
|
gdk_draw_rectangle (widget->window,
|
|
|
|
widget->style->white_gc,
|
|
|
|
FALSE,
|
|
|
|
te->inner_rect.x - 1, te->inner_rect.y - 1,
|
|
|
|
te->inner_rect.width + 1,
|
|
|
|
te->inner_rect.height + 1);
|
|
|
|
|
2001-08-29 01:07:39 -04:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2001-08-19 02:23:59 -04:00
|
|
|
MetaTabPopup*
|
|
|
|
meta_ui_tab_popup_new (const MetaTabEntry *entries)
|
|
|
|
{
|
|
|
|
MetaTabPopup *popup;
|
|
|
|
int i, left, right, top, bottom;
|
|
|
|
GList *tab_entries;
|
|
|
|
int width;
|
|
|
|
int height;
|
|
|
|
GtkWidget *table;
|
2001-08-30 00:01:38 -04:00
|
|
|
GtkWidget *vbox;
|
|
|
|
GtkWidget *align;
|
2001-08-19 02:23:59 -04:00
|
|
|
GList *tmp;
|
2001-08-19 14:09:10 -04:00
|
|
|
GtkWidget *frame;
|
2001-08-28 23:37:03 -04:00
|
|
|
int max_label_width;
|
2001-08-19 02:23:59 -04:00
|
|
|
|
|
|
|
popup = g_new (MetaTabPopup, 1);
|
2001-08-29 00:53:48 -04:00
|
|
|
|
|
|
|
popup->outline_window = gtk_window_new (GTK_WINDOW_POPUP);
|
|
|
|
gtk_widget_set_app_paintable (popup->outline_window, TRUE);
|
|
|
|
gtk_widget_realize (popup->outline_window);
|
2001-08-30 00:01:38 -04:00
|
|
|
|
2001-08-29 01:07:39 -04:00
|
|
|
g_signal_connect (G_OBJECT (popup->outline_window), "expose_event",
|
|
|
|
G_CALLBACK (outline_window_expose), popup);
|
2001-08-29 00:53:48 -04:00
|
|
|
|
2001-08-19 02:23:59 -04:00
|
|
|
popup->window = gtk_window_new (GTK_WINDOW_POPUP);
|
2001-08-19 14:09:10 -04:00
|
|
|
gtk_window_set_position (GTK_WINDOW (popup->window),
|
|
|
|
GTK_WIN_POS_CENTER_ALWAYS);
|
|
|
|
/* enable resizing, to get never-shrink behavior */
|
|
|
|
gtk_window_set_resizable (GTK_WINDOW (popup->window),
|
|
|
|
TRUE);
|
2001-08-19 02:23:59 -04:00
|
|
|
popup->current = NULL;
|
|
|
|
popup->entries = NULL;
|
2001-08-29 01:07:39 -04:00
|
|
|
popup->current_selected_entry = NULL;
|
2001-08-19 14:09:10 -04:00
|
|
|
|
2001-08-19 02:23:59 -04:00
|
|
|
tab_entries = NULL;
|
|
|
|
i = 0;
|
|
|
|
while (entries[i].xwindow != None)
|
|
|
|
{
|
|
|
|
TabEntry *te;
|
|
|
|
|
|
|
|
te = g_new (TabEntry, 1);
|
|
|
|
te->xwindow = entries[i].xwindow;
|
|
|
|
te->title = g_strdup (entries[i].title);
|
|
|
|
te->icon = entries[i].icon;
|
|
|
|
g_object_ref (G_OBJECT (te->icon));
|
|
|
|
te->widget = NULL;
|
|
|
|
|
2001-08-29 00:53:48 -04:00
|
|
|
te->rect.x = entries[i].x;
|
|
|
|
te->rect.y = entries[i].y;
|
|
|
|
te->rect.width = entries[i].width;
|
|
|
|
te->rect.height = entries[i].height;
|
2001-08-30 00:01:38 -04:00
|
|
|
|
|
|
|
te->inner_rect.x = entries[i].inner_x;
|
|
|
|
te->inner_rect.y = entries[i].inner_y;
|
|
|
|
te->inner_rect.width = entries[i].inner_width;
|
|
|
|
te->inner_rect.height = entries[i].inner_height;
|
2001-08-29 00:53:48 -04:00
|
|
|
|
2001-08-19 02:23:59 -04:00
|
|
|
tab_entries = g_list_prepend (tab_entries, te);
|
|
|
|
|
|
|
|
++i;
|
|
|
|
}
|
|
|
|
|
|
|
|
popup->entries = g_list_reverse (tab_entries);
|
|
|
|
|
|
|
|
width = 5; /* FIXME */
|
|
|
|
height = i / width;
|
|
|
|
if (i % width)
|
|
|
|
height += 1;
|
|
|
|
|
2001-08-30 00:01:38 -04:00
|
|
|
table = gtk_table_new (height, width, FALSE);
|
|
|
|
vbox = gtk_vbox_new (FALSE, 0);
|
2001-08-19 14:09:10 -04:00
|
|
|
|
|
|
|
frame = gtk_frame_new (NULL);
|
|
|
|
gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_OUT);
|
|
|
|
gtk_container_set_border_width (GTK_CONTAINER (table), 1);
|
|
|
|
gtk_container_add (GTK_CONTAINER (popup->window),
|
|
|
|
frame);
|
|
|
|
gtk_container_add (GTK_CONTAINER (frame),
|
2001-08-30 00:01:38 -04:00
|
|
|
vbox);
|
2001-08-19 02:23:59 -04:00
|
|
|
|
2001-08-31 02:13:07 -04:00
|
|
|
align = gtk_alignment_new (0.5, 0.5, 0.0, 0.0);
|
2001-08-19 14:09:10 -04:00
|
|
|
|
2001-08-30 00:01:38 -04:00
|
|
|
gtk_box_pack_start (GTK_BOX (vbox), align, TRUE, TRUE, 0);
|
|
|
|
|
|
|
|
gtk_container_add (GTK_CONTAINER (align),
|
|
|
|
table);
|
2001-08-19 02:23:59 -04:00
|
|
|
|
2001-08-30 00:01:38 -04:00
|
|
|
popup->label = gtk_label_new ("");
|
|
|
|
gtk_misc_set_padding (GTK_MISC (popup->label), 3, 3);
|
|
|
|
|
|
|
|
gtk_box_pack_end (GTK_BOX (vbox), popup->label, FALSE, FALSE, 0);
|
2001-08-19 14:09:10 -04:00
|
|
|
|
2001-08-28 23:37:03 -04:00
|
|
|
max_label_width = 0;
|
2001-08-19 02:23:59 -04:00
|
|
|
top = 0;
|
|
|
|
bottom = 1;
|
|
|
|
tmp = popup->entries;
|
|
|
|
|
|
|
|
while (tmp && top < height)
|
2001-08-19 14:09:10 -04:00
|
|
|
{
|
|
|
|
left = 0;
|
|
|
|
right = 1;
|
|
|
|
|
2001-08-19 02:23:59 -04:00
|
|
|
while (tmp && left < width)
|
|
|
|
{
|
|
|
|
GtkWidget *image;
|
2001-08-28 23:37:03 -04:00
|
|
|
GtkRequisition req;
|
2001-08-19 14:09:10 -04:00
|
|
|
|
2001-08-19 02:23:59 -04:00
|
|
|
TabEntry *te;
|
|
|
|
|
|
|
|
te = tmp->data;
|
2001-08-19 14:09:10 -04:00
|
|
|
|
2001-08-22 23:24:51 -04:00
|
|
|
image = selectable_image_new (te->icon);
|
|
|
|
gtk_misc_set_padding (GTK_MISC (image),
|
|
|
|
INSIDE_SELECT_RECT + OUTSIDE_SELECT_RECT + 1,
|
|
|
|
INSIDE_SELECT_RECT + OUTSIDE_SELECT_RECT + 1);
|
|
|
|
gtk_misc_set_alignment (GTK_MISC (image), 0.5, 0.5);
|
2001-08-19 14:09:10 -04:00
|
|
|
|
2001-08-22 23:24:51 -04:00
|
|
|
te->widget = image;
|
2001-08-19 02:23:59 -04:00
|
|
|
|
|
|
|
gtk_table_attach (GTK_TABLE (table),
|
|
|
|
te->widget,
|
2001-08-22 23:24:51 -04:00
|
|
|
left, right, top, bottom,
|
2001-08-30 00:01:38 -04:00
|
|
|
0, 0,
|
2001-08-22 23:24:51 -04:00
|
|
|
0, 0);
|
2001-08-28 23:37:03 -04:00
|
|
|
|
|
|
|
/* Efficiency rules! */
|
|
|
|
gtk_label_set_text (GTK_LABEL (popup->label),
|
|
|
|
te->title);
|
|
|
|
gtk_widget_size_request (popup->label, &req);
|
|
|
|
max_label_width = MAX (max_label_width, req.width);
|
2001-08-19 02:23:59 -04:00
|
|
|
|
|
|
|
tmp = tmp->next;
|
|
|
|
|
|
|
|
++left;
|
2001-08-19 14:09:10 -04:00
|
|
|
++right;
|
2001-08-19 02:23:59 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
++top;
|
2001-08-19 14:09:10 -04:00
|
|
|
++bottom;
|
2001-08-19 02:23:59 -04:00
|
|
|
}
|
2001-08-28 23:37:03 -04:00
|
|
|
|
|
|
|
/* remove all the temporary text */
|
|
|
|
gtk_label_set_text (GTK_LABEL (popup->label), "");
|
|
|
|
|
2001-08-30 00:01:38 -04:00
|
|
|
max_label_width += 20; /* add random padding */
|
|
|
|
|
2001-08-28 23:37:03 -04:00
|
|
|
gtk_window_set_default_size (GTK_WINDOW (popup->window),
|
2001-08-30 00:01:38 -04:00
|
|
|
max_label_width,
|
2001-08-28 23:37:03 -04:00
|
|
|
-1);
|
|
|
|
|
2001-08-19 02:23:59 -04:00
|
|
|
return popup;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
free_entry (gpointer data, gpointer user_data)
|
|
|
|
{
|
|
|
|
TabEntry *te;
|
|
|
|
|
|
|
|
te = data;
|
|
|
|
|
|
|
|
g_free (te->title);
|
|
|
|
g_object_unref (G_OBJECT (te->icon));
|
|
|
|
|
|
|
|
g_free (te);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
meta_ui_tab_popup_free (MetaTabPopup *popup)
|
|
|
|
{
|
2001-08-29 00:53:48 -04:00
|
|
|
gtk_widget_destroy (popup->outline_window);
|
2001-08-19 02:23:59 -04:00
|
|
|
gtk_widget_destroy (popup->window);
|
|
|
|
|
|
|
|
g_list_foreach (popup->entries, free_entry, NULL);
|
|
|
|
|
|
|
|
g_list_free (popup->entries);
|
|
|
|
|
|
|
|
g_free (popup);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
meta_ui_tab_popup_set_showing (MetaTabPopup *popup,
|
|
|
|
gboolean showing)
|
|
|
|
{
|
|
|
|
if (showing)
|
|
|
|
gtk_widget_show_all (popup->window);
|
|
|
|
else
|
2001-08-30 00:01:38 -04:00
|
|
|
{
|
|
|
|
gtk_widget_hide (popup->window);
|
|
|
|
meta_core_increment_event_serial (gdk_display);
|
|
|
|
}
|
2001-08-19 02:23:59 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
display_entry (MetaTabPopup *popup,
|
|
|
|
TabEntry *te)
|
|
|
|
{
|
2001-08-29 00:53:48 -04:00
|
|
|
GdkRectangle rect;
|
2001-08-30 00:01:38 -04:00
|
|
|
GdkRegion *region;
|
|
|
|
GdkRegion *inner_region;
|
|
|
|
|
2001-08-29 00:53:48 -04:00
|
|
|
|
2001-08-29 01:07:39 -04:00
|
|
|
if (popup->current_selected_entry)
|
|
|
|
unselect_image (popup->current_selected_entry->widget);
|
2001-08-19 14:09:10 -04:00
|
|
|
|
2001-08-19 02:23:59 -04:00
|
|
|
gtk_label_set_text (GTK_LABEL (popup->label), te->title);
|
2001-08-22 23:24:51 -04:00
|
|
|
select_image (te->widget);
|
2001-08-29 01:07:39 -04:00
|
|
|
|
2001-08-29 00:53:48 -04:00
|
|
|
/* Do stuff behind gtk's back */
|
|
|
|
gdk_window_hide (popup->outline_window->window);
|
2001-08-30 00:01:38 -04:00
|
|
|
meta_core_increment_event_serial (gdk_display);
|
|
|
|
|
2001-08-29 00:53:48 -04:00
|
|
|
rect = te->rect;
|
|
|
|
rect.x = 0;
|
|
|
|
rect.y = 0;
|
2001-08-30 00:01:38 -04:00
|
|
|
|
|
|
|
gdk_window_move_resize (popup->outline_window->window,
|
|
|
|
te->rect.x, te->rect.y,
|
|
|
|
te->rect.width, te->rect.height);
|
2001-08-29 00:53:48 -04:00
|
|
|
|
2001-08-30 00:01:38 -04:00
|
|
|
gdk_window_set_background (popup->outline_window->window,
|
|
|
|
&popup->outline_window->style->black);
|
|
|
|
|
|
|
|
region = gdk_region_rectangle (&rect);
|
|
|
|
inner_region = gdk_region_rectangle (&te->inner_rect);
|
|
|
|
gdk_region_subtract (region, inner_region);
|
|
|
|
gdk_region_destroy (inner_region);
|
|
|
|
|
|
|
|
gdk_window_shape_combine_region (popup->outline_window->window,
|
|
|
|
region,
|
|
|
|
0, 0);
|
2001-08-29 00:53:48 -04:00
|
|
|
|
2001-08-30 00:01:38 -04:00
|
|
|
gdk_region_destroy (region);
|
|
|
|
|
|
|
|
/* This should piss off gtk a bit, but we don't want to raise
|
|
|
|
* above the tab popup
|
|
|
|
*/
|
|
|
|
gdk_window_show_unraised (popup->outline_window->window);
|
2001-08-29 00:53:48 -04:00
|
|
|
|
2001-08-29 01:07:39 -04:00
|
|
|
/* Must be before we handle an expose for the outline window */
|
|
|
|
popup->current_selected_entry = te;
|
2001-08-19 02:23:59 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
meta_ui_tab_popup_forward (MetaTabPopup *popup)
|
|
|
|
{
|
|
|
|
if (popup->current != NULL)
|
|
|
|
popup->current = popup->current->next;
|
|
|
|
|
|
|
|
if (popup->current == NULL)
|
|
|
|
popup->current = popup->entries;
|
|
|
|
|
|
|
|
if (popup->current != NULL)
|
|
|
|
{
|
|
|
|
TabEntry *te;
|
|
|
|
|
|
|
|
te = popup->current->data;
|
|
|
|
|
|
|
|
display_entry (popup, te);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
meta_ui_tab_popup_backward (MetaTabPopup *popup)
|
|
|
|
{
|
|
|
|
if (popup->current != NULL)
|
|
|
|
popup->current = popup->current->prev;
|
|
|
|
|
|
|
|
if (popup->current == NULL)
|
|
|
|
popup->current = g_list_last (popup->entries);
|
|
|
|
|
|
|
|
if (popup->current != NULL)
|
|
|
|
{
|
|
|
|
TabEntry *te;
|
|
|
|
|
|
|
|
te = popup->current->data;
|
|
|
|
|
|
|
|
display_entry (popup, te);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Window
|
|
|
|
meta_ui_tab_popup_get_selected (MetaTabPopup *popup)
|
|
|
|
{
|
|
|
|
if (popup->current)
|
|
|
|
{
|
|
|
|
TabEntry *te;
|
|
|
|
|
|
|
|
te = popup->current->data;
|
|
|
|
|
|
|
|
return te->xwindow;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return None;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
meta_ui_tab_popup_select (MetaTabPopup *popup,
|
|
|
|
Window xwindow)
|
|
|
|
{
|
|
|
|
GList *tmp;
|
|
|
|
|
|
|
|
tmp = popup->entries;
|
|
|
|
while (tmp != NULL)
|
|
|
|
{
|
|
|
|
TabEntry *te;
|
|
|
|
|
|
|
|
te = tmp->data;
|
|
|
|
|
|
|
|
if (te->xwindow == xwindow)
|
|
|
|
{
|
|
|
|
popup->current = tmp;
|
|
|
|
|
|
|
|
display_entry (popup, te);
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
tmp = tmp->next;
|
|
|
|
}
|
|
|
|
}
|
2001-08-22 23:24:51 -04:00
|
|
|
|
|
|
|
#define META_TYPE_SELECT_IMAGE (meta_select_image_get_type ())
|
|
|
|
#define META_SELECT_IMAGE(obj) (GTK_CHECK_CAST ((obj), META_TYPE_SELECT_IMAGE, MetaSelectImage))
|
|
|
|
|
|
|
|
typedef struct _MetaSelectImage MetaSelectImage;
|
|
|
|
typedef struct _MetaSelectImageClass MetaSelectImageClass;
|
|
|
|
|
|
|
|
struct _MetaSelectImage
|
|
|
|
{
|
|
|
|
GtkImage parent_instance;
|
|
|
|
guint selected : 1;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct _MetaSelectImageClass
|
|
|
|
{
|
|
|
|
GtkImageClass parent_class;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
static GType meta_select_image_get_type (void) G_GNUC_CONST;
|
|
|
|
|
|
|
|
static GtkWidget*
|
|
|
|
selectable_image_new (GdkPixbuf *pixbuf)
|
|
|
|
{
|
|
|
|
GtkWidget *w;
|
|
|
|
|
|
|
|
w = g_object_new (meta_select_image_get_type (), NULL);
|
|
|
|
gtk_image_set_from_pixbuf (GTK_IMAGE (w), pixbuf);
|
|
|
|
|
|
|
|
return w;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
select_image (GtkWidget *widget)
|
|
|
|
{
|
|
|
|
META_SELECT_IMAGE (widget)->selected = TRUE;
|
|
|
|
gtk_widget_queue_draw (widget);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
unselect_image (GtkWidget *widget)
|
|
|
|
{
|
|
|
|
META_SELECT_IMAGE (widget)->selected = FALSE;
|
|
|
|
gtk_widget_queue_draw (widget);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void meta_select_image_class_init (MetaSelectImageClass *klass);
|
|
|
|
static gboolean meta_select_image_expose_event (GtkWidget *widget,
|
|
|
|
GdkEventExpose *event);
|
|
|
|
|
|
|
|
static GtkImageClass *parent_class;
|
|
|
|
|
|
|
|
GType
|
|
|
|
meta_select_image_get_type (void)
|
|
|
|
{
|
|
|
|
static GtkType image_type = 0;
|
|
|
|
|
|
|
|
if (!image_type)
|
|
|
|
{
|
|
|
|
static const GTypeInfo image_info =
|
|
|
|
{
|
|
|
|
sizeof (MetaSelectImageClass),
|
|
|
|
NULL, /* base_init */
|
|
|
|
NULL, /* base_finalize */
|
|
|
|
(GClassInitFunc) meta_select_image_class_init,
|
|
|
|
NULL, /* class_finalize */
|
|
|
|
NULL, /* class_data */
|
|
|
|
sizeof (MetaSelectImage),
|
|
|
|
16, /* n_preallocs */
|
|
|
|
(GInstanceInitFunc) NULL,
|
|
|
|
};
|
|
|
|
|
|
|
|
image_type = g_type_register_static (GTK_TYPE_IMAGE, "MetaSelectImage", &image_info, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
return image_type;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
meta_select_image_class_init (MetaSelectImageClass *klass)
|
|
|
|
{
|
|
|
|
GtkWidgetClass *widget_class;
|
|
|
|
|
|
|
|
parent_class = gtk_type_class (gtk_image_get_type ());
|
|
|
|
|
|
|
|
widget_class = GTK_WIDGET_CLASS (klass);
|
|
|
|
|
|
|
|
widget_class->expose_event = meta_select_image_expose_event;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
meta_select_image_expose_event (GtkWidget *widget,
|
|
|
|
GdkEventExpose *event)
|
|
|
|
{
|
|
|
|
if (META_SELECT_IMAGE (widget)->selected)
|
|
|
|
{
|
|
|
|
int x, y, w, h;
|
|
|
|
GtkMisc *misc;
|
|
|
|
|
|
|
|
misc = GTK_MISC (widget);
|
|
|
|
|
|
|
|
x = (widget->allocation.x * (1.0 - misc->xalign) +
|
|
|
|
(widget->allocation.x + widget->allocation.width
|
|
|
|
- (widget->requisition.width - misc->xpad * 2)) *
|
|
|
|
misc->xalign) + 0.5;
|
|
|
|
y = (widget->allocation.y * (1.0 - misc->yalign) +
|
|
|
|
(widget->allocation.y + widget->allocation.height
|
|
|
|
- (widget->requisition.height - misc->ypad * 2)) *
|
|
|
|
misc->yalign) + 0.5;
|
|
|
|
|
2001-08-23 20:32:17 -04:00
|
|
|
x -= INSIDE_SELECT_RECT + 1;
|
|
|
|
y -= INSIDE_SELECT_RECT + 1;
|
2001-08-22 23:24:51 -04:00
|
|
|
|
|
|
|
w = widget->requisition.width - OUTSIDE_SELECT_RECT * 2 - 1;
|
|
|
|
h = widget->requisition.height - OUTSIDE_SELECT_RECT * 2 - 1;
|
|
|
|
|
|
|
|
gdk_draw_rectangle (widget->window,
|
|
|
|
widget->style->fg_gc[GTK_WIDGET_STATE (widget)],
|
|
|
|
FALSE,
|
|
|
|
x, y, w, h);
|
|
|
|
gdk_draw_rectangle (widget->window,
|
|
|
|
widget->style->fg_gc[GTK_WIDGET_STATE (widget)],
|
|
|
|
FALSE,
|
|
|
|
x - 1, y - 1, w + 2, h + 2);
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
gdk_draw_rectangle (widget->window,
|
|
|
|
widget->style->bg_gc[GTK_STATE_SELECTED],
|
|
|
|
TRUE,
|
|
|
|
x, y, w, h);
|
|
|
|
#endif
|
|
|
|
#if 0
|
|
|
|
gtk_paint_focus (widget->style, widget->window,
|
|
|
|
&event->area, widget, "meta-tab-image",
|
|
|
|
x, y, w, h);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
return GTK_WIDGET_CLASS (parent_class)->expose_event (widget, event);
|
|
|
|
}
|