Commit 2d7528fb authored by Jiri (George) Lebl's avatar Jiri (George) Lebl Committed by George Lebl

redid the icon stuff, now icons are windowless widgets which don't even

Wed Aug 26 02:14:11 1998  George Lebl  <jirka@5z.com>

        * button-widget.[ch],panel-widget.[ch]: redid the icon stuff, now
          icons are windowless widgets which don't even draw themselves,
          the panel is aware of them and draws them itself, this will in
          the very near future have support for tiles.

        * launcher.c: using the new button-widget as the widget instead of
          gnome-pixmap

        * panel-types.h: new file for global types

        * panel.c: support rightclick menus for no_window applets

        * applet.[ch]: export the show_applet_menu function
parent 8fcde3ee
Wed Aug 26 02:14:11 1998 George Lebl <jirka@5z.com>
* button-widget.[ch],panel-widget.[ch]: redid the icon stuff, now
icons are windowless widgets which don't even draw themselves,
the panel is aware of them and draws them itself, this will in
the very near future have support for tiles.
* launcher.c: using the new button-widget as the widget instead of
gnome-pixmap
* panel-types.h: new file for global types
* panel.c: support rightclick menus for no_window applets
* applet.[ch]: export the show_applet_menu function
1998-08-20 Martin Baulig <martin@home-of-linux.org>
* orbit-applet-lib.c (gnome_panel_applet_register): Don't
......
Wed Aug 26 02:14:11 1998 George Lebl <jirka@5z.com>
* button-widget.[ch],panel-widget.[ch]: redid the icon stuff, now
icons are windowless widgets which don't even draw themselves,
the panel is aware of them and draws them itself, this will in
the very near future have support for tiles.
* launcher.c: using the new button-widget as the widget instead of
gnome-pixmap
* panel-types.h: new file for global types
* panel.c: support rightclick menus for no_window applets
* applet.[ch]: export the show_applet_menu function
1998-08-20 Martin Baulig <martin@home-of-linux.org>
* orbit-applet-lib.c (gnome_panel_applet_register): Don't
......
......@@ -121,6 +121,8 @@ panel_SOURCES = \
drawer-widget.h \
corner-widget.c \
corner-widget.h \
button-widget.c \
button-widget.h \
exec-queue.c \
exec-queue.h \
mulapp.c \
......
......@@ -10,7 +10,7 @@
extern "C" {
#endif /* __cplusplus */
#ifndef APPLET_H
#ifndef PANEL_INCLUDE_H
/*from applet.h*/
typedef enum {
ORIENT_UP,
......
......@@ -385,6 +385,10 @@ applet_menu_position (GtkMenu *menu, int *x, int *y, gpointer data)
w = gtk_object_get_data(GTK_OBJECT(panel), PANEL_PARENT);
gdk_window_get_origin (info->widget->window, &wx, &wy);
if(GTK_WIDGET_NO_WINDOW(info->widget)) {
wx += info->widget->allocation.x;
wy += info->widget->allocation.y;
}
if(IS_DRAWER_WIDGET(w)) {
if(panel->orient==PANEL_VERTICAL) {
......@@ -453,7 +457,7 @@ applet_menu_position (GtkMenu *menu, int *x, int *y, gpointer data)
}
static void
void
show_applet_menu(int applet_id, GdkEventButton *event)
{
AppletInfo *info = get_applet_info(applet_id);
......@@ -517,7 +521,7 @@ register_toy(GtkWidget *applet,
g_return_val_if_fail(applet != NULL, FALSE);
g_return_val_if_fail(panel != NULL, FALSE);
if(GTK_WIDGET_NO_WINDOW(applet) || GTK_IS_SOCKET(applet)) {
if(/*GTK_WIDGET_NO_WINDOW(applet) || */GTK_IS_SOCKET(applet)) {
/* We wrap the applet in a GtkEventBox so that we can capture
events over it */
eventbox = gtk_event_box_new();
......@@ -527,10 +531,11 @@ register_toy(GtkWidget *applet,
GDK_POINTER_MOTION_HINT_MASK));
gtk_container_add(GTK_CONTAINER(eventbox), applet);
} else {
gtk_widget_set_events(applet, (gtk_widget_get_events(applet) |
APPLET_EVENT_MASK) &
~( GDK_POINTER_MOTION_MASK |
GDK_POINTER_MOTION_HINT_MASK));
if(!GTK_WIDGET_NO_WINDOW(applet))
gtk_widget_set_events(applet, (gtk_widget_get_events(applet) |
APPLET_EVENT_MASK) &
~( GDK_POINTER_MOTION_MASK |
GDK_POINTER_MOTION_HINT_MASK));
eventbox = applet;
}
......@@ -588,10 +593,11 @@ register_toy(GtkWidget *applet,
panel = PANEL_WIDGET(list->data);
}
gtk_signal_connect(GTK_OBJECT(eventbox),
"button_press_event",
GTK_SIGNAL_FUNC(applet_button_press),
GINT_TO_POINTER(applet_count-1));
if(!GTK_WIDGET_NO_WINDOW(applet))
gtk_signal_connect(GTK_OBJECT(eventbox),
"button_press_event",
GTK_SIGNAL_FUNC(applet_button_press),
GINT_TO_POINTER(applet_count-1));
gtk_signal_connect(GTK_OBJECT(eventbox),
"destroy",
......
......@@ -26,13 +26,6 @@ typedef enum {
APPLET_EMPTY
} AppletType;
typedef enum {
ORIENT_UP,
ORIENT_DOWN,
ORIENT_LEFT,
ORIENT_RIGHT
} PanelOrientType;
typedef struct _AppletUserMenu AppletUserMenu;
typedef struct _AppletInfo AppletInfo;
......@@ -73,6 +66,7 @@ void applet_remove_callback(int applet_id,
char *callback_name);
void applet_menu_position (GtkMenu *menu, int *x, int *y,
gpointer data);
void show_applet_menu(int applet_id, GdkEventButton *event);
#define get_applet_info(applet_id) \
((applet_id>=0 && applet_id<applet_count) ? \
......
#include <config.h>
#include <string.h>
#include <gtk/gtk.h>
#include <gnome.h>
#include "button-widget.h"
#include "panel-widget.h"
/*FIXME: make this global, and use it everywhere*/
#define SMALL_ICON_SIZE 20
#define BIG_ICON_SIZE 48
static void button_widget_class_init (ButtonWidgetClass *klass);
static void button_widget_init (ButtonWidget *button);
static int button_widget_expose (GtkWidget *widget,
GdkEventExpose *event);
static void button_widget_size_request (GtkWidget *widget,
GtkRequisition *requisition);
static void button_widget_size_allocate (GtkWidget *widget,
GtkAllocation *allocation);
static void button_widget_pressed (ButtonWidget *button);
static void button_widget_unpressed (ButtonWidget *button);
typedef void (*VoidSignal) (GtkObject * object,
gpointer data);
/*list of all the button widgets*/
static GList *buttons=NULL;
/*the tiles go here*/
static GdkPixmap *tiles_up[MAX_TILES]={NULL,NULL,NULL,NULL};
static GdkBitmap *tiles_up_mask[MAX_TILES]={NULL,NULL,NULL,NULL};
static GdkPixmap *tiles_down[MAX_TILES]={NULL,NULL,NULL,NULL};
static GdkBitmap *tiles_down_mask[MAX_TILES]={NULL,NULL,NULL,NULL};
/*are tiles enabled*/
static int tiles_enabled = FALSE;
static GtkWidgetClass *parent_class;
guint
button_widget_get_type ()
{
static guint button_widget_type = 0;
if (!button_widget_type) {
GtkTypeInfo button_widget_info = {
"ButtonWidget",
sizeof (ButtonWidget),
sizeof (ButtonWidgetClass),
(GtkClassInitFunc) button_widget_class_init,
(GtkObjectInitFunc) button_widget_init,
(GtkArgSetFunc) NULL,
(GtkArgGetFunc) NULL,
};
button_widget_type = gtk_type_unique (GTK_TYPE_WIDGET,
&button_widget_info);
}
return button_widget_type;
}
enum {
CLICKED_SIGNAL,
PRESSED_SIGNAL,
UNPRESSED_SIGNAL,
LAST_SIGNAL
};
static int button_widget_signals[LAST_SIGNAL] = {0};
static void
marshal_signal_void (GtkObject * object,
GtkSignalFunc func,
gpointer func_data,
GtkArg * args)
{
VoidSignal rfunc;
rfunc = (VoidSignal) func;
(*rfunc) (object, func_data);
}
static void
button_widget_class_init (ButtonWidgetClass *class)
{
GtkObjectClass *object_class = (GtkObjectClass*) class;
GtkWidgetClass *widget_class = (GtkWidgetClass*) class;
parent_class = gtk_type_class (GTK_TYPE_WIDGET);
button_widget_signals[CLICKED_SIGNAL] =
gtk_signal_new("clicked",
GTK_RUN_LAST,
object_class->type,
GTK_SIGNAL_OFFSET(ButtonWidgetClass,
clicked),
marshal_signal_void,
GTK_TYPE_NONE,
0);
button_widget_signals[PRESSED_SIGNAL] =
gtk_signal_new("pressed",
GTK_RUN_FIRST,
object_class->type,
GTK_SIGNAL_OFFSET(ButtonWidgetClass,
pressed),
marshal_signal_void,
GTK_TYPE_NONE,
0);
button_widget_signals[UNPRESSED_SIGNAL] =
gtk_signal_new("unpressed",
GTK_RUN_LAST,
object_class->type,
GTK_SIGNAL_OFFSET(ButtonWidgetClass,
unpressed),
marshal_signal_void,
GTK_TYPE_NONE,
0);
gtk_object_class_add_signals(object_class,button_widget_signals,
LAST_SIGNAL);
class->clicked = NULL;
class->pressed = button_widget_pressed;
class->unpressed = button_widget_unpressed;
widget_class->size_allocate = button_widget_size_allocate;
widget_class->size_request = button_widget_size_request;
}
static int
button_widget_destroy(GtkWidget *w, gpointer data)
{
ButtonWidget *button = BUTTON_WIDGET(w);
if(button->pixmap)
gdk_pixmap_unref(button->pixmap);
button->pixmap = NULL;
if(button->mask)
gdk_bitmap_unref(button->mask);
button->mask = NULL;
buttons = g_list_remove(buttons,button);
return FALSE;
}
static void
draw_arrow(GdkPoint *points, PanelOrientType orient)
{
switch(orient) {
case ORIENT_UP:
points[0].x = BIG_ICON_SIZE-12;
points[0].y = 10;
points[1].x = BIG_ICON_SIZE-4;
points[1].y = 10;
points[2].x = BIG_ICON_SIZE-8;
points[2].y = 3;
break;
case ORIENT_DOWN:
points[0].x = 4;
points[0].y = BIG_ICON_SIZE - 10;
points[1].x = 12;
points[1].y = BIG_ICON_SIZE - 10;
points[2].x = 8;
points[2].y = BIG_ICON_SIZE - 3;
break;
case ORIENT_LEFT:
points[0].x = 10;
points[0].y = 4;
points[1].x = 10;
points[1].y = 12;
points[2].x = 3;
points[2].y = 8;
break;
case ORIENT_RIGHT:
points[0].x = BIG_ICON_SIZE - 10;
points[0].y = BIG_ICON_SIZE - 12;
points[1].x = BIG_ICON_SIZE - 10;
points[1].y = BIG_ICON_SIZE - 4;
points[2].x = BIG_ICON_SIZE - 3;
points[2].y = BIG_ICON_SIZE - 8;
break;
}
}
void
button_widget_draw(ButtonWidget *button, GdkPixmap *pixmap)
{
GtkWidget *widget = GTK_WIDGET(button);
GdkPixmap *tile;
GdkBitmap *tile_mask;
GdkGCValues values;
GdkPoint points[3];
GdkGC *gc;
if(!GTK_WIDGET_REALIZED(button))
return;
gc = gdk_gc_new(pixmap);
if(button->arrow)
draw_arrow(points,button->orient);
if(tiles_enabled) {
if(button->pressed) {
tile = tiles_down[button->tile];
tile_mask = tiles_down_mask[button->tile];
} else {
tile = tiles_up[button->tile];
tile_mask = tiles_up_mask[button->tile];
}
}
if(tiles_enabled) {
if (tile_mask) {
gdk_gc_set_clip_mask (gc, tile_mask);
gdk_gc_set_clip_origin (gc, widget->allocation.x,
widget->allocation.y);
}
gdk_draw_pixmap(pixmap, gc, tile, 0,0,
widget->allocation.x, widget->allocation.y,
BIG_ICON_SIZE, BIG_ICON_SIZE);
if (tile_mask) {
gdk_gc_set_clip_mask (gc, NULL);
gdk_gc_set_clip_origin (gc, 0, 0);
}
}
if (button->mask) {
gdk_gc_set_clip_mask (gc, button->mask);
gdk_gc_set_clip_origin (gc, widget->allocation.x,
widget->allocation.y);
}
gdk_draw_pixmap (pixmap, gc, button->pixmap, 0, 0,
widget->allocation.x, widget->allocation.y,
BIG_ICON_SIZE, BIG_ICON_SIZE);
/*stripe a pressed button if we have no tiles, to provide some sort of
feedback*/
if(!tiles_enabled && button->pressed) {
int i;
gdk_gc_set_foreground(gc,&widget->style->black);
for(i=0;i<BIG_ICON_SIZE;i+=2)
gdk_draw_line(pixmap,gc,
widget->allocation.x,widget->allocation.y+i,
widget->allocation.x+BIG_ICON_SIZE,widget->allocation.y+i);
}
if (button->mask) {
gdk_gc_set_clip_mask (gc, NULL);
gdk_gc_set_clip_origin (gc, 0, 0);
}
if(button->arrow) {
gdk_gc_set_foreground(gc,&widget->style->white);
gdk_draw_polygon(pixmap,gc,TRUE,points,3);
gdk_gc_set_foreground(gc,&widget->style->black);
gdk_draw_polygon(pixmap,gc,FALSE,points,3);
}
gdk_gc_destroy(gc);
}
static void
button_widget_size_request(GtkWidget *widget, GtkRequisition *requisition)
{
requisition->width = requisition->height = BIG_ICON_SIZE;
}
static void
button_widget_size_allocate(GtkWidget *widget, GtkAllocation *allocation)
{
widget->allocation = *allocation;
}
static void
button_widget_init (ButtonWidget *button)
{
GTK_WIDGET_SET_FLAGS (button, GTK_NO_WINDOW);
buttons = g_list_prepend(buttons,button);
button->pixmap = NULL;
button->mask = NULL;
button->tile = 0;
button->arrow = 0;
button->orient = ORIENT_UP;
button->pressed = FALSE;
gtk_signal_connect(GTK_OBJECT(button),"destroy",
GTK_SIGNAL_FUNC(button_widget_destroy),
NULL);
}
void
button_widget_clicked(ButtonWidget *button)
{
gtk_signal_emit(GTK_OBJECT(button),
button_widget_signals[CLICKED_SIGNAL]);
}
static void
button_widget_pressed(ButtonWidget *button)
{
button->pressed = TRUE;
panel_widget_draw_icon(PANEL_WIDGET(GTK_WIDGET(button)->parent),
button);
}
static void
button_widget_unpressed(ButtonWidget *button)
{
button->pressed = FALSE;
panel_widget_draw_icon(PANEL_WIDGET(GTK_WIDGET(button)->parent),
button);
}
void
button_widget_down(ButtonWidget *button)
{
gtk_signal_emit(GTK_OBJECT(button),
button_widget_signals[PRESSED_SIGNAL]);
}
void
button_widget_up(ButtonWidget *button)
{
gtk_signal_emit(GTK_OBJECT(button),
button_widget_signals[UNPRESSED_SIGNAL]);
}
GtkWidget*
button_widget_new(GdkPixmap *pixmap,
GdkBitmap *mask,
int tile,
int arrow,
PanelOrientType orient)
{
ButtonWidget *button;
button = BUTTON_WIDGET (gtk_type_new (button_widget_get_type ()));
button->pixmap = pixmap;
button->mask = mask;
button->tile = tile;
button->arrow = arrow;
button->orient = orient;
return GTK_WIDGET(button);
}
static void
loadup_file(GdkPixmap **pixmap, GdkBitmap **mask, char *file)
{
GdkImlibImage *im;
im = gdk_imlib_load_image (file);
if(!im) {
*pixmap = NULL;
*mask = NULL;
return;
}
gdk_imlib_render (im, BIG_ICON_SIZE, BIG_ICON_SIZE);
*pixmap = gdk_imlib_copy_image (im);
*mask = gdk_imlib_copy_mask (im);
gdk_imlib_destroy_image (im);
}
GtkWidget*
button_widget_new_from_file(char *pixmap,
int tile,
int arrow,
PanelOrientType orient)
{
GdkPixmap *_pixmap;
GdkBitmap *mask;
loadup_file(&_pixmap,&mask,pixmap);
if(!_pixmap)
return NULL;
return button_widget_new(_pixmap,mask,tile,arrow,orient);
}
void
button_widget_set_pixmap(ButtonWidget *button, GdkPixmap *pixmap, GdkBitmap *mask)
{
if(button->pixmap)
gdk_pixmap_unref(button->pixmap);
button->pixmap = NULL;
if(button->mask)
gdk_bitmap_unref(button->mask);
button->mask = NULL;
button->pixmap = pixmap;
button->mask = mask;
panel_widget_draw_icon(PANEL_WIDGET(GTK_WIDGET(button)->parent),
button);
}
int
button_widget_set_pixmap_from_file(ButtonWidget *button, char *pixmap)
{
GdkPixmap *_pixmap;
GdkBitmap *mask;
loadup_file(&_pixmap,&mask,pixmap);
if(!_pixmap)
return FALSE;
button_widget_set_pixmap(button,_pixmap,mask);
return TRUE;
}
void
button_widget_set_params(ButtonWidget *button,
int tile,
int arrow,
PanelOrientType orient)
{
button->tile = tile;
button->arrow = arrow;
button->orient = orient;
panel_widget_draw_icon(PANEL_WIDGET(GTK_WIDGET(button)->parent),
button);
}
void
button_widget_load_tile(int tile, char *tile_up, char *tile_down)
{
GList *list;
if(tiles_up[tile])
gdk_pixmap_unref(tiles_up[tile]);
tiles_up[tile] = NULL;
if(tiles_up_mask[tile])
gdk_bitmap_unref(tiles_up_mask[tile]);
tiles_up_mask[tile] = NULL;
if(tiles_down[tile])
gdk_pixmap_unref(tiles_down[tile]);
tiles_down[tile] = NULL;
if(tiles_down_mask[tile])
gdk_bitmap_unref(tiles_down_mask[tile]);
tiles_down_mask[tile] = NULL;
loadup_file(&tiles_up[tile],&tiles_up_mask[tile],tile_up);
loadup_file(&tiles_down[tile],&tiles_down_mask[tile],tile_down);
for(list = buttons;list!=NULL;list=g_list_next(list)) {
ButtonWidget *button = list->data;
if(button->tile == tile)
panel_widget_draw_icon(PANEL_WIDGET(GTK_WIDGET(button)->parent),
button);
}
}
void
button_widget_tile_enable(int enabled)
{
if(tiles_enabled != enabled) {
GList *list;
tiles_enabled = enabled;
for(list = buttons;list!=NULL;list=g_list_next(list))
panel_widget_draw_icon(PANEL_WIDGET(GTK_WIDGET(list->data)->parent),
list->data);
}
}
#ifndef __BUTTON_WIDGET_H__
#define __BUTTON_WIDGET_H__
#include <gtk/gtk.h>
#include <gnome.h>
#include "panel-types.h"
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
#define MAX_TILES 4
#define BUTTON_WIDGET(obj) GTK_CHECK_CAST (obj, button_widget_get_type (), ButtonWidget)
#define BUTTON_WIDGET_CLASS(klass) GTK_CHECK_CLASS_CAST (klass, button_widget_get_type (), ButtonWidgetClass)
#define IS_BUTTON_WIDGET(obj) GTK_CHECK_TYPE (obj, button_widget_get_type ())
typedef struct _ButtonWidget ButtonWidget;
typedef struct _ButtonWidgetClass ButtonWidgetClass;
struct _ButtonWidget
{
GtkWidget _pixmap;
GdkPixmap *pixmap; /*this is the one we start from*/
GdkBitmap *mask;
int pressed; /*true if the button is pressed*/
int tile; /*the tile number, only used if tiles are on*/
int arrow; /*0 no arrow, 1 simple arrow, more to do*/
PanelOrientType orient;
};
struct _ButtonWidgetClass
{
GtkWidgetClass parent_class;
void (* clicked) (ButtonWidget *button);
void (* pressed) (ButtonWidget *button);
void (* unpressed) (ButtonWidget *button);
};
guint button_widget_get_type (void);
GtkWidget* button_widget_new (GdkPixmap *pixmap,
GdkBitmap *mask,
int tile,
int arrow,
PanelOrientType orient);
GtkWidget* button_widget_new_from_file (char *pixmap,
int tile,
int arrow,
PanelOrientType orient);
void button_widget_draw (ButtonWidget *button,
GdkPixmap *pixmap);
void button_widget_set_pixmap (ButtonWidget *button,
GdkPixmap *pixmap,
GdkBitmap *mask);
int button_widget_set_pixmap_from_file(ButtonWidget *button,
char *pixmap);
void button_widget_set_params (ButtonWidget *button,
int tile,
int arrow,
PanelOrientType orient);
void button_widget_clicked (ButtonWidget *button);
void button_widget_down (ButtonWidget *button);
void button_widget_up (ButtonWidget *button);
void button_widget_load_tile (int tile,
char *tile_up,
char *tile_down);
void button_widget_tile_enamble (int enabled);
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif /* __BUTTON_WIDGET_H__ */
......@@ -29,36 +29,12 @@ extern PanelWidget *current_panel;
static int
launch (GtkWidget *widget, GdkEvent *event, void *data)
static void
launch (GtkWidget *widget, void *data)
{
static int in_button = FALSE;
GnomeDesktopEntry *item = data;
GdkEventButton *bevent = (GdkEventButton *)event;
/*this is a release after a press inside a button*/
if(event->type == GDK_BUTTON_RELEASE && in_button) {
in_button = FALSE;
gtk_grab_remove(widget);
/*if it's inside it's a click*/
if(bevent->x >= 0 &&
bevent->x < widget->allocation.width &&
bevent->y >= 0 &&
bevent->y < widget->allocation.height)
gnome_desktop_entry_launch (item);
return TRUE;
/*if it's inside and press, set in_button*/
} else if(event->type == GDK_BUTTON_PRESS &&
bevent->button == 1 &&
bevent->x >= 0 &&
bevent->x < widget->allocation.width &&
bevent->y >= 0 &&
bevent->y < widget->allocation.height) {
gtk_grab_add(widget);
in_button = TRUE;
return TRUE;