[Nautilus-list] some eel patching
- From: Havoc Pennington <hp redhat com>
- To: nautilus-list eazel com
- Subject: [Nautilus-list] some eel patching
- Date: 31 Oct 2001 23:35:23 -0500
Hi,
I went to town on eel-gtk-extensions.c, and got a couple other things
too.
Havoc
Index: ChangeLog
===================================================================
RCS file: /cvs/gnome/eel/ChangeLog,v
retrieving revision 1.184
diff -u -p -u -r1.184 ChangeLog
--- ChangeLog 2001/10/30 00:24:48 1.184
+++ ChangeLog 2001/11/01 04:36:08
@@ -1,3 +1,50 @@
+2001-10-31 Havoc Pennington <hp pobox com>
+
+ * eel/eel-gtk-extensions.c (eel_gtk_window_present): that one was
+ easy
+ (eel_gtk_widget_set_font_by_name): port to GTK 2
+ (eel_gtk_label_make_bold): port to GTK 2
+ (eel_gtk_label_make_larger): port and note in docs that it's
+ broken
+ (eel_gtk_label_make_smaller): port and note in docs that it's
+ broken
+ (eel_gtk_widget_set_background_color): do this properly
+ (eel_gtk_widget_set_foreground_color): ditto
+ (eel_get_current_event_time): simplify using GTK 2 features
+ (eel_drag_set_icon_pixbuf): simplify using GTK 2 features
+ (eel_gtk_widget_standard_draw): delete, there is no draw method
+ anymore
+ (eel_gtk_pixmap_new_empty): make this less lame
+ (eel_nullify_when_destroyed): work on GObject, use
+ g_object_add_weak_pointer()
+ (eel_nullify_cancel): corresponding change
+ (eel_gtk_widget_set_font): simplify using GTK 2 features
+ (eel_gtk_style_set_font): delete, this was totally broken; I don't
+ know what it's for but we have to do it a different way
+ (eel_gtk_menu_insert_separator): use GtkSeparatorMenuItem!
+ woo-hoo! also, remove setting it insensitive, this will be fixed
+ before 2.0 so it isn't required
+ (EEL_STANDARD_BUTTON_PADDING): remove, should fix in GTK if we are
+ going to fix it
+ (eel_gtk_button_auto_click): make it do nothing, GTK does this for
+ you now
+ (eel_gtk_button_set_standard_padding): make a no-op, should fix in
+ GTK
+ (activate_button_on_double_click): use gtk_widget_activate()
+ instead of eel_gtk_button_auto_click()
+ (eel_gtk_window_set_initial_geometry): use gtk_window_move()
+ instead of gtk_widget_set_uposition()
+ (eel_gtk_window_set_up_close_accelerator): make it whine if you
+ use it on GtkDialog, since that breaks the standard GtkDialog
+ close accelerators
+ (eel_popup_menu_position_func): remove obsolete FIXME about
+ GdkPoint using gint16
+
+ * eel/eel-gdk-extensions.c (eel_gdk_window_set_invisible_cursor):
+ port to GTK 2 (not sure why it used Xlib before)
+
+ * eel/eel-dnd.c (eel_drag_drop_action_ask): port to GTK 2
+
2001-10-29 Darin Adler <darin bentspoon com>
* eel-2.0.pc.in: Add some Requires.
Index: eel/eel-dnd.c
===================================================================
RCS file: /cvs/gnome/eel/eel/eel-dnd.c,v
retrieving revision 1.9
diff -u -p -u -r1.9 eel-dnd.c
--- eel/eel-dnd.c 2001/10/01 22:23:12 1.9
+++ eel/eel-dnd.c 2001/11/01 04:36:08
@@ -33,6 +33,8 @@
#include <eel/eel-string.h>
#include <eel/eel-vfs-extensions.h>
#include <gtk/gtkmain.h>
+#include <gtk/gtkmenu.h>
+#include <gtk/gtkseparatormenuitem.h>
#include <libgnome/gnome-i18n.h>
#include <libgnomeui/gnome-uidefs.h>
#include <libgnomevfs/gnome-vfs-find-directory.h>
@@ -487,59 +489,98 @@ eel_drag_modifier_based_action (int defa
return default_action;
}
-#ifdef GNOME2_CONVERSION_COMPLETE
+typedef struct
+{
+ GMainLoop *loop;
+ GdkDragAction chosen;
+} DropActionMenuData;
-/* The menu of DnD actions */
-static GnomeUIInfo menu_items[] = {
- GNOMEUIINFO_ITEM_NONE (N_("_Move here"), NULL, NULL),
- GNOMEUIINFO_ITEM_NONE (N_("_Copy here"), NULL, NULL),
- GNOMEUIINFO_ITEM_NONE (N_("_Link here"), NULL, NULL),
- GNOMEUIINFO_SEPARATOR,
- GNOMEUIINFO_ITEM_NONE (N_("Cancel"), NULL, NULL),
- GNOMEUIINFO_END
-};
+static void
+drop_action_activated_callback (GtkWidget *menu_item,
+ gpointer data)
+{
+ DropActionMenuData *damd;
+
+ damd = data;
+
+ damd->chosen = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (menu_item),
+ "action"));
+
+ if (g_main_loop_is_running (damd->loop))
+ g_main_loop_quit (damd->loop);
+}
-#endif
+static void
+append_drop_action_menu_item (GtkWidget *menu,
+ const char *text,
+ GdkDragAction action,
+ gboolean sensitive,
+ DropActionMenuData *damd)
+{
+ GtkWidget *menu_item;
+
+ menu_item = gtk_menu_item_new_with_mnemonic (text);
+ gtk_widget_set_sensitive (menu_item, sensitive);
+ gtk_menu_shell_append (GTK_MENU_SHELL (menu), menu_item);
+
+ g_object_set_data (G_OBJECT (menu_item),
+ "action",
+ GINT_TO_POINTER (action));
+
+ g_signal_connect (G_OBJECT (menu_item), "activate",
+ G_CALLBACK (drop_action_activated_callback),
+ damd);
+}
/* Pops up a menu of actions to perform on dropped files */
GdkDragAction
eel_drag_drop_action_ask (GdkDragAction actions)
{
-#ifndef GNOME2_CONVERSION_COMPLETE
- return 0;
-#else
GtkWidget *menu;
- int action;
-
+ GtkWidget *menu_item;
+ DropActionMenuData damd;
+
/* Create the menu and set the sensitivity of the items based on the
* allowed actions.
*/
- textdomain
- menu = gnome_popup_menu_new (menu_items);
- textdomain
-
- gtk_widget_set_sensitive (menu_items[0].widget, (actions & GDK_ACTION_MOVE) != 0);
- gtk_widget_set_sensitive (menu_items[1].widget, (actions & GDK_ACTION_COPY) != 0);
- gtk_widget_set_sensitive (menu_items[2].widget, (actions & GDK_ACTION_LINK) != 0);
-
- switch (gnome_popup_menu_do_popup_modal (menu, NULL, NULL, NULL, NULL)) {
- case 0:
- action = GDK_ACTION_MOVE;
- break;
- case 1:
- action = GDK_ACTION_COPY;
- break;
- case 2:
- action = GDK_ACTION_LINK;
- break;
- default:
- action = 0;
- }
+ menu = gtk_menu_new ();
- gtk_widget_destroy (menu);
+ append_drop_action_menu_item (menu, _("_Move here"),
+ GDK_ACTION_MOVE,
+ (actions & GDK_ACTION_MOVE) != 0,
+ &damd);
+
+ append_drop_action_menu_item (menu, _("_Copy here"),
+ GDK_ACTION_COPY,
+ (actions & GDK_ACTION_COPY) != 0,
+ &damd);
+
+ append_drop_action_menu_item (menu, _("_Link here"),
+ GDK_ACTION_LINK,
+ (actions & GDK_ACTION_LINK) != 0,
+ &damd);
+
+ menu_item = gtk_separator_menu_item_new ();
+ gtk_menu_shell_append (GTK_MENU_SHELL (menu), menu_item);
- return action;
-#endif
+ menu_item = gtk_menu_item_new_with_mnemonic (_("Cancel"));
+ gtk_menu_shell_append (GTK_MENU_SHELL (menu), menu_item);
+
+ damd.chosen = 0;
+ damd.loop = g_main_loop_new (NULL, FALSE);
+
+ gtk_widget_show_all (menu);
+
+ GDK_THREADS_LEAVE ();
+ g_main_loop_run (damd.loop);
+ GDK_THREADS_ENTER ();
+
+ g_main_loop_unref (damd.loop);
+
+ /* FIXME we may need to sink the menu, not destroy */
+ gtk_widget_destroy (menu);
+
+ return damd.chosen;
}
gboolean
Index: eel/eel-gdk-extensions.c
===================================================================
RCS file: /cvs/gnome/eel/eel/eel-gdk-extensions.c,v
retrieving revision 1.7
diff -u -p -u -r1.7 eel-gdk-extensions.c
--- eel/eel-gdk-extensions.c 2001/10/23 06:33:53 1.7
+++ eel/eel-gdk-extensions.c 2001/11/01 04:36:08
@@ -757,41 +757,28 @@ eel_gdk_window_set_wm_hints_input (GdkWi
void
eel_gdk_window_set_invisible_cursor (GdkWindow *window)
{
-#ifdef GNOME2_CONVERSION_COMPLETE
- XColor foreColor, backColor;
- GdkWindowPrivate *window_private;
- Pixmap sourcePixmap, maskPixmap;
- Cursor xcursor;
+ GdkBitmap *empty_bitmap;
+ GdkCursor *cursor;
+ GdkColor useless;
+ char invisible_cursor_bits[] = { 0x0 };
+
+ useless.red = useless.green = useless.blue = 0;
+ useless.pixel = 0;
+
+ empty_bitmap = gdk_bitmap_create_from_data (window,
+ invisible_cursor_bits,
+ 1, 1);
+
+ cursor = gdk_cursor_new_from_pixmap (empty_bitmap,
+ empty_bitmap,
+ &useless,
+ &useless, 0, 0);
- char invisible_cursor_bits[] = {0x0};
- char invisible_cursor_mask_bits[] = {0x0};
+ gdk_window_set_cursor (window, cursor);
- foreColor.pixel = 0L;
- foreColor.red = foreColor.green = foreColor.blue = 0;
- foreColor.flags = DoRed | DoGreen | DoBlue;
+ gdk_cursor_unref (cursor);
- backColor.pixel = 255L;
- backColor.red = backColor.green = backColor.blue = 65535;
- backColor.flags = DoRed | DoGreen | DoBlue;
-
- window_private = (GdkWindowPrivate *) window;
-
- sourcePixmap = XCreateBitmapFromData (window_private->xdisplay, window_private->xwindow,
- invisible_cursor_bits, 1, 1);
- g_assert (sourcePixmap != 0);
-
- maskPixmap = XCreateBitmapFromData (window_private->xdisplay, window_private->xwindow,
- invisible_cursor_mask_bits, 1, 1);
- g_assert (maskPixmap != 0);
-
- xcursor = XCreatePixmapCursor (window_private->xdisplay, sourcePixmap, maskPixmap,
- &foreColor, &backColor, 0, 0);
-
- XFreePixmap (window_private->xdisplay, sourcePixmap);
- XFreePixmap (window_private->xdisplay, maskPixmap);
-
- XDefineCursor (window_private->xdisplay, window_private->xwindow, xcursor);
-#endif
+ g_object_unref (G_OBJECT (empty_bitmap));
}
EelGdkGeometryFlags
Index: eel/eel-gtk-extensions.c
===================================================================
RCS file: /cvs/gnome/eel/eel/eel-gtk-extensions.c,v
retrieving revision 1.21
diff -u -p -u -r1.21 eel-gtk-extensions.c
--- eel/eel-gtk-extensions.c 2001/10/28 20:17:51 1.21
+++ eel/eel-gtk-extensions.c 2001/11/01 04:36:08
@@ -44,16 +44,12 @@
#include <gtk/gtkmain.h>
#include <gtk/gtkrc.h>
#include <gtk/gtkselection.h>
+#include <gtk/gtkseparatormenuitem.h>
#include <gtk/gtksignal.h>
#include "eel-marshal.h"
#include "eel-marshal.c"
-/* This number should be large enough to be visually noticeable,
- * but small enough to not allow the user to perform other actions.
- */
-#define BUTTON_AUTO_HIGHLIGHT_MILLISECONDS 100
-
/* This number is fairly arbitrary. Long enough to show a pretty long
* menu title, but not so long to make a menu grotesquely wide.
*/
@@ -65,73 +61,23 @@
#define MINIMUM_ON_SCREEN_WIDTH 100
#define MINIMUM_ON_SCREEN_HEIGHT 100
-/* GTK buttons cram the text too close to the edge of the buttons by default.
- * This is the standard padding used to make them look non-crammed.
- */
-#define EEL_STANDARD_BUTTON_PADDING 1
-
/* How far down the window tree will we search when looking for top-level
* windows? Some window managers doubly-reparent the client, so account
* for that, and add some slop.
*/
#define MAXIMUM_WM_REPARENTING_DEPTH 4
-static gboolean
-finish_button_activation (gpointer data)
-{
- GtkButton *button;
-
- button = GTK_BUTTON (data);
-
- if (!GTK_OBJECT_DESTROYED (button) && !button->in_button) {
- gtk_button_clicked (button);
- }
-
- /* Check again--button can be destroyed during call to gtk_button_clicked */
- if (!GTK_OBJECT_DESTROYED (button)) {
- gtk_button_released (button);
- }
-
- /* This was ref'd in eel_gtk_button_auto_click */
- gtk_object_unref (GTK_OBJECT (button));
-
- return FALSE;
-}
-
/**
* eel_gtk_button_auto_click:
- *
- * Programatically activate a button as if the user had clicked on it,
- * including briefly drawing the button's pushed-in state.
+ *
+ * Don't use this function anymore, GTK does it automatically.
+ *
* @button: Any GtkButton.
**/
void
eel_gtk_button_auto_click (GtkButton *button)
{
- g_return_if_fail (GTK_IS_BUTTON (button));
-
- if (!GTK_WIDGET_IS_SENSITIVE (GTK_WIDGET (button))) {
- return;
- }
-
- button->in_button = TRUE;
- gtk_button_pressed (button);
- button->in_button = FALSE;
-
- /* FIXME bugzilla.eazel.com 2562:
- * Nothing is preventing other events from occuring between
- * now and when this timeout function fires, which means in
- * theory the user could click on a different row or otherwise
- * get in between the double-click and the button activation.
- * In practice the timeout is short enough that this probably
- * isn't a problem.
- */
-
- /* This is unref'ed in finish_button_activation */
- gtk_object_ref (GTK_OBJECT (button));
-
- g_timeout_add (BUTTON_AUTO_HIGHLIGHT_MILLISECONDS,
- finish_button_activation, button);
+ /* No-op, because GTK does this automatically now */
}
/**
@@ -155,6 +101,8 @@ eel_gtk_button_set_padding (GtkButton *b
/**
* eel_gtk_button_set_standard_padding
+ *
+ * This function no longer does anything
*
* Adds the standard amount of padding around the contained widget in the button
* (typically the label). Use this rather than eel_gtk_button_set_padding
@@ -166,7 +114,7 @@ eel_gtk_button_set_standard_padding (Gtk
{
g_return_if_fail (GTK_IS_BUTTON (button));
- eel_gtk_button_set_padding (button, EEL_STANDARD_BUTTON_PADDING);
+ /* No-op, should use GTK standard padding */
}
@@ -239,7 +187,7 @@ activate_button_on_double_click (GtkWidg
*/
if (event->type == GDK_2BUTTON_PRESS
&& GTK_WIDGET_SENSITIVE (GTK_WIDGET (user_data))) {
- eel_gtk_button_auto_click (GTK_BUTTON (user_data));
+ gtk_widget_activate(GTK_WIDGET (user_data));
}
return FALSE;
@@ -325,41 +273,7 @@ eel_gtk_signal_connect_free_data (GtkObj
void
eel_gtk_window_present (GtkWindow *window)
{
- GdkWindow *gdk_window;
-#ifdef GNOME2_CONVERSION_COMPLETE
- int current_area_x, current_area_y;
-#endif
-
- g_return_if_fail (GTK_IS_WINDOW (window));
-
- /* Ensure that the window is on the current desktop and area */
- if (GTK_WIDGET_REALIZED (GTK_WIDGET (window))) {
-#ifdef GNOME2_CONVERSION_COMPLETE
- if (!eel_gtk_window_is_on_current_workspace_and_area (window)) {
- eel_gnome_win_hints_get_current_area (¤t_area_x,
- ¤t_area_y);
- eel_gnome_win_hints_set_area (GTK_WIDGET (window),
- current_area_x,
- current_area_y);
- /* Evilness: due to how sawfish updates window
- * properties, must set the workspace after
- * the area. I must fix this..
- */
- gnome_win_hints_set_workspace (GTK_WIDGET (window),
- gnome_win_hints_get_current_workspace ());
- }
-#endif
- }
-
- /* If we have no gdk window, then it's OK to just show, since
- * the window is new and presumably will show up in front.
- */
- gdk_window = GTK_WIDGET (window)->window;
- if (gdk_window != NULL) {
- eel_gdk_window_bring_to_front (gdk_window);
- }
-
- gtk_widget_show (GTK_WIDGET (window));
+ gtk_window_present (window);
}
static void
@@ -435,6 +349,9 @@ eel_gtk_window_event_is_close_accelerato
* Sets up the standard keyboard equivalent to close the window.
* Call this for windows that don't set up a keyboard equivalent to
* close the window some other way, e.g. via a menu item accelerator.
+ *
+ * NOTE: do not use for GtkDialog, it already sets up the right
+ * stuff here.
*
* @window: The GtkWindow that should be hidden when the standard
* keyboard equivalent is typed.
@@ -444,6 +361,11 @@ eel_gtk_window_set_up_close_accelerator
{
g_return_if_fail (GTK_IS_WINDOW (window));
+ if (GTK_IS_DIALOG (window)) {
+ g_warning ("eel_gtk_window_set_up_close_accelerator: Should not mess with close accelerator on GtkDialogs");
+ return;
+ }
+
gtk_signal_connect (GTK_OBJECT (window),
"key_press_event",
GTK_SIGNAL_FUNC (handle_standard_close_accelerator),
@@ -547,7 +469,7 @@ eel_gtk_window_set_initial_geometry (Gtk
}
sanity_check_window_position (&real_left, &real_top);
- gtk_widget_set_uposition (GTK_WIDGET (window), real_left, real_top);
+ gtk_window_move (window, real_left, real_top);
}
if ((geometry_flags & EEL_GDK_WIDTH_VALUE) && (geometry_flags & EEL_GDK_HEIGHT_VALUE)) {
@@ -574,9 +496,9 @@ eel_gtk_window_set_initial_geometry (Gtk
*/
void
eel_gtk_window_set_initial_geometry_from_string (GtkWindow *window,
- const char *geometry_string,
- guint minimum_width,
- guint minimum_height)
+ const char *geometry_string,
+ guint minimum_width,
+ guint minimum_height)
{
int left, top;
guint width, height;
@@ -665,9 +587,6 @@ eel_popup_menu_position_func (GtkMenu *
g_assert (offset != NULL);
- /* FIXME bugzilla.eazel.com 2561: The cast from gint16 might
- * cause problems. Unfortunately, GdkPoint uses gint16.
- */
gtk_widget_size_request (GTK_WIDGET (menu), &requisition);
*x = CLAMP (*x + (int) offset->x, 0, MAX (0, gdk_screen_width () - requisition.width));
@@ -749,8 +668,7 @@ eel_gtk_menu_insert_separator (GtkMenu *
{
GtkWidget *menu_item;
- menu_item = gtk_menu_item_new ();
- gtk_widget_set_sensitive (menu_item, FALSE);
+ menu_item = gtk_separator_menu_item_new ();
gtk_widget_show (menu_item);
gtk_menu_shell_insert (GTK_MENU_SHELL (menu), menu_item, index);
@@ -789,6 +707,12 @@ eel_point_in_allocation (const GtkAlloca
&& y < allocation->y + allocation->height;
}
+/* FIXME this function is dangerous, because widget->window coords (or
+ * other window-belonging-to-widget coords) do not need to be in the
+ * same coordinate system as widget->allocation.
+ * If you use this function, be aware of that. Someone should probably
+ * audit all uses, too.
+ */
gboolean
eel_point_in_widget (GtkWidget *widget,
int x, int y)
@@ -851,23 +775,6 @@ eel_gtk_object_list_copy (GList *list)
}
/**
- * eel_gtk_style_set_font
- *
- * Sets the font in a style object, managing the ref. counts.
- * @style: The style to change.
- * @font: The new font.
- **/
-void
-eel_gtk_style_set_font (GtkStyle *style, PangoFontDescription *font)
-{
- g_return_if_fail (style != NULL);
- g_return_if_fail (font != NULL);
-
- pango_font_description_free (style->font_desc);
- style->font_desc = pango_font_description_copy (font);
-}
-
-/**
* eel_gtk_widget_set_font
*
* Sets the font for a widget's style, managing the style objects.
@@ -877,17 +784,7 @@ eel_gtk_style_set_font (GtkStyle *style,
void
eel_gtk_widget_set_font (GtkWidget *widget, PangoFontDescription *font)
{
- GtkStyle *new_style;
-
- g_return_if_fail (GTK_IS_WIDGET (widget));
- g_return_if_fail (font != NULL);
-
- new_style = gtk_style_copy (gtk_widget_get_style (widget));
-
- eel_gtk_style_set_font (new_style, font);
-
- gtk_widget_set_style (widget, new_style);
- gtk_style_unref (new_style);
+ gtk_widget_modify_font (widget, font);
}
/**
@@ -918,18 +815,21 @@ eel_gtk_widget_set_shown (GtkWidget *wid
void
eel_gtk_widget_set_font_by_name (GtkWidget *widget, const char *font_name)
{
-#ifdef GNOME2_CONVERSION_COMPLETE
- GdkFont *font;
-#endif
-
+ PangoFontDescription *font_desc;
+
g_return_if_fail (GTK_IS_WIDGET (widget));
g_return_if_fail (font_name != NULL);
-
-#ifdef GNOME2_CONVERSION_COMPLETE
- font = gdk_fontset_load (font_name);
- eel_gtk_widget_set_font (widget, font);
- gdk_font_unref (font);
-#endif
+
+ font_desc = pango_font_description_from_string (font_name);
+
+ if (font_desc == NULL) {
+ g_warning ("Bad font name '%s'", font_name);
+ return;
+ }
+
+ gtk_widget_modify_font (widget, font_desc);
+
+ pango_font_description_free (font_desc);
}
/* This stuff is stolen from Gtk. */
@@ -1094,14 +994,6 @@ eel_gtk_signal_connect_while_realized (G
info->signal_handler = gtk_signal_connect (info->object, name, callback, callback_data);
}
-static void
-null_the_reference (GtkObject *object, gpointer callback_data)
-{
- g_assert (* (GtkObject **) callback_data == object);
-
- * (gpointer *) callback_data = NULL;
-}
-
/**
* eel_nullify_when_destroyed.
*
@@ -1112,18 +1004,18 @@ null_the_reference (GtkObject *object, g
void
eel_nullify_when_destroyed (gpointer data)
{
- GtkObject **object_reference;
+ GObject **object_reference;
- object_reference = (GtkObject **)data;
+ object_reference = (GObject **)data;
if (*object_reference == NULL) {
/* the reference is NULL, nothing to do. */
return;
}
- g_assert (GTK_IS_OBJECT (*object_reference));
+ g_assert (G_IS_OBJECT (*object_reference));
- gtk_signal_connect (*object_reference, "destroy",
- GTK_SIGNAL_FUNC (null_the_reference), object_reference);
+ g_object_add_weak_pointer (*object_reference,
+ (void*) object_reference);
}
/**
@@ -1138,9 +1030,9 @@ eel_nullify_when_destroyed (gpointer dat
void
eel_nullify_cancel (gpointer data)
{
- GtkObject **object_reference;
+ GObject **object_reference;
- object_reference = (GtkObject **)data;
+ object_reference = (GObject **)data;
if (*object_reference == NULL) {
/* the object was already destroyed and the reference nulled out,
* nothing to do.
@@ -1148,11 +1040,10 @@ eel_nullify_cancel (gpointer data)
return;
}
- g_assert (GTK_IS_OBJECT (*object_reference));
+ g_assert (G_IS_OBJECT (*object_reference));
- gtk_signal_disconnect_by_func (*object_reference,
- GTK_SIGNAL_FUNC (null_the_reference),
- object_reference);
+ g_object_remove_weak_pointer (*object_reference,
+ (void*) object_reference);
*object_reference = NULL;
}
@@ -1226,20 +1117,15 @@ eel_gtk_container_foreach_deep (GtkConta
gtk_container_foreach (container, container_foreach_deep_callback, &deep_data);
}
-/* We have to supply a dummy pixmap to avoid the return_if_fail in gtk_pixmap_new. */
+/* Don't use this function, use GtkImage */
GtkPixmap *
eel_gtk_pixmap_new_empty (void)
{
GtkPixmap *pixmap;
- /* Make a GtkPixmap with a dummy GdkPixmap. The
- * gdk_pixmap_new call will fail if passed 0 for height or
- * width, or if passed a bad depth.
- */
- pixmap = GTK_PIXMAP (gtk_pixmap_new (gdk_pixmap_new (NULL, 1, 1, gdk_visual_get_best_depth ()), NULL));
+ pixmap = g_object_new (GTK_TYPE_PIXMAP, NULL);
- /* Clear out the dummy pixmap. */
- gtk_pixmap_set (pixmap, NULL, NULL);
+ gtk_pixmap_set_build_insensitive (pixmap, TRUE);
return pixmap;
}
@@ -1281,132 +1167,170 @@ eel_gtk_adjustment_clamp_value (GtkAdjus
void
eel_gtk_label_make_bold (GtkLabel *label)
{
- GtkStyle *style;
-#ifdef GNOME2_CONVERSION_COMPLETE
- GdkFont *bold_font;
-#endif
+ PangoFontDescription *font_desc;
+
+ font_desc = pango_font_description_new ();
+
+ pango_font_description_set_weight (font_desc,
+ PANGO_WEIGHT_BOLD);
+
+ /* this will only affect the weight of the font, the rest is
+ * from the theme or user prefs, since the font desc only has
+ * the weight flag turned on
+ */
+ gtk_widget_modify_font (GTK_WIDGET (label), font_desc);
+
+ pango_font_description_free (font_desc);
+}
+
+static PangoFontDescription*
+eel_pango_font_description_scale (const PangoFontDescription *base_desc,
+ int steps)
+{
+ double factor;
+ PangoFontDescription *scaled_desc;
+
+ g_return_val_if_fail (base_desc != NULL, NULL);
+
+ switch (steps) {
+ case -3:
+ factor = PANGO_SCALE_XX_SMALL;
+ break;
+ case -2:
+ factor = PANGO_SCALE_X_SMALL;
+ break;
+ case -1:
+ factor = PANGO_SCALE_SMALL;
+ break;
+ case 0:
+ factor = PANGO_SCALE_MEDIUM;
+ break;
+ case 1:
+ factor = PANGO_SCALE_LARGE;
+ break;
+ case 2:
+ factor = PANGO_SCALE_X_LARGE;
+ break;
+ case 3:
+ factor = PANGO_SCALE_XX_LARGE;
+ break;
+ default:
+ /* someone is being silly, but handle it anyway */
+ if (steps < 0)
+ factor = PANGO_SCALE_XX_SMALL;
+ else
+ factor = PANGO_SCALE_XX_LARGE;
+ break;
+ };
+
+ scaled_desc = pango_font_description_copy (base_desc);
+ pango_font_description_set_size (scaled_desc,
+ factor * pango_font_description_get_size (base_desc));
+
+ return scaled_desc;
+}
+
+/**
+ * eel_gtk_label_scale:
+ * @label:
+ * @num_steps:
+ *
+ * Function is broken, see eel_gtk_label_make_larger() for explanation
+ *
+ **/
+static void
+eel_gtk_label_scale (GtkLabel *label,
+ int num_steps)
+{
+ GtkStyle *style;
+ PangoFontDescription *scaled_font;
+
g_return_if_fail (GTK_IS_LABEL (label));
+ g_warning ("Calling eel_gtk_label_make_larger() or make_smaller() breaks accessibility, use gtk_label_set_markup() instead");
+
gtk_widget_ensure_style (GTK_WIDGET (label));
style = gtk_widget_get_style (GTK_WIDGET (label));
-#ifdef GNOME2_CONVERSION_COMPLETE
- bold_font = eel_gdk_font_get_bold (style->font);
- if (bold_font == NULL) {
- return;
- }
- eel_gtk_widget_set_font (GTK_WIDGET (label), bold_font);
- gdk_font_unref (bold_font);
-#endif
+ scaled_font = eel_pango_font_description_scale (style->font_desc,
+ num_steps);
+
+ /* Unset all fields but size so we don't override them */
+ pango_font_description_unset_fields (scaled_font,
+ ~PANGO_FONT_MASK_SIZE);
+
+ gtk_widget_modify_font (GTK_WIDGET (label), scaled_font);
+
+ pango_font_description_free (scaled_font);
}
/**
* eel_gtk_label_make_larger.
*
* Switches the font of label to a larger version of the font.
+ *
+ * WARNING: This function is broken, it requires a GTK extension to
+ * work properly. The larger font size will "stick" when the theme
+ * changes, instead of remaining relative to the theme's font size.
+ * Instead of using this function, code should use markup labels, e.g.:
+ * gtk_label_set_markup (label, "<small>foo</small><xx-large>bar</xx-large>")
+ * Breaking theme font is bad for accessibility in addition to aesthetics.
+ *
+ *
* @label: The label.
**/
void
eel_gtk_label_make_larger (GtkLabel *label,
- guint num_steps)
+ guint num_steps)
{
- GtkStyle *style;
-#ifdef GNOME2_CONVERSION_COMPLETE
- GdkFont *larger_font;
-#endif
-
- g_return_if_fail (GTK_IS_LABEL (label));
-
- gtk_widget_ensure_style (GTK_WIDGET (label));
- style = gtk_widget_get_style (GTK_WIDGET (label));
-
-#ifdef GNOME2_CONVERSION_COMPLETE
- larger_font = eel_gdk_font_get_larger (style->font, num_steps);
- if (larger_font == NULL) {
- return;
- }
- eel_gtk_widget_set_font (GTK_WIDGET (label), larger_font);
- gdk_font_unref (larger_font);
-#endif
+ eel_gtk_label_scale (label, num_steps);
}
/**
* eel_gtk_label_make_smaller.
*
* Switches the font of label to a smaller version of the font.
+ *
+ * WARNING: broken function, see eel_gtk_label_mark_larger() for why.
+ *
* @label: The label.
**/
void
eel_gtk_label_make_smaller (GtkLabel *label,
- guint num_steps)
+ guint num_steps)
{
- GtkStyle *style;
-#ifdef GNOME2_CONVERSION_COMPLETE
- GdkFont *smaller_font;
-#endif
-
- g_return_if_fail (GTK_IS_LABEL (label));
-
- gtk_widget_ensure_style (GTK_WIDGET (label));
- style = gtk_widget_get_style (GTK_WIDGET (label));
-
-#ifdef GNOME2_CONVERSION_COMPLETE
- smaller_font = eel_gdk_font_get_smaller (style->font, num_steps);
- if (smaller_font == NULL) {
- return;
- }
- eel_gtk_widget_set_font (GTK_WIDGET (label), smaller_font);
- gdk_font_unref (smaller_font);
-#endif
+ eel_gtk_label_scale (label, - (int) num_steps);
}
void
eel_gtk_widget_set_background_color (GtkWidget *widget,
- const char *color_spec)
+ const char *color_spec)
{
- GtkStyle *style;
- GdkColor color;
+ GdkColor color;
g_return_if_fail (GTK_IS_WIDGET (widget));
- style = gtk_widget_get_style (widget);
-
- /* Make a copy of the style. */
- style = gtk_style_copy (style);
-
eel_gdk_color_parse_with_white_default (color_spec, &color);
- style->bg[GTK_STATE_NORMAL] = color;
- style->base[GTK_STATE_NORMAL] = color;
- style->bg[GTK_STATE_ACTIVE] = color;
- style->base[GTK_STATE_ACTIVE] = color;
-
- /* Put the style in the widget. */
- gtk_widget_set_style (widget, style);
- gtk_style_unref (style);
+
+ gtk_widget_modify_bg (widget, GTK_STATE_NORMAL, &color);
+ gtk_widget_modify_base (widget, GTK_STATE_NORMAL, &color);
+ gtk_widget_modify_bg (widget, GTK_STATE_ACTIVE, &color);
+ gtk_widget_modify_base (widget, GTK_STATE_ACTIVE, &color);
}
void
eel_gtk_widget_set_foreground_color (GtkWidget *widget,
const char *color_spec)
{
- GtkStyle *style;
GdkColor color;
g_return_if_fail (GTK_IS_WIDGET (widget));
- style = gtk_widget_get_style (widget);
-
- /* Make a copy of the style. */
- style = gtk_style_copy (style);
-
eel_gdk_color_parse_with_white_default (color_spec, &color);
- style->fg[GTK_STATE_NORMAL] = color;
- style->fg[GTK_STATE_ACTIVE] = color;
- /* Put the style in the widget. */
- gtk_widget_set_style (widget, style);
- gtk_style_unref (style);
+ gtk_widget_modify_fg (widget, GTK_STATE_NORMAL, &color);
+ gtk_widget_modify_fg (widget, GTK_STATE_ACTIVE, &color);
}
GtkWidget *
@@ -1834,95 +1758,19 @@ eel_gtk_get_system_font (void)
return font;
}
-static guint
-event_get_time (GdkEvent *event)
-{
- if (event != NULL) {
- switch (event->type) {
- case GDK_MOTION_NOTIFY:
- return event->motion.time;
- case GDK_BUTTON_PRESS:
- case GDK_2BUTTON_PRESS:
- case GDK_3BUTTON_PRESS:
- case GDK_BUTTON_RELEASE:
- return event->button.time;
- case GDK_KEY_PRESS:
- case GDK_KEY_RELEASE:
- return event->key.time;
- case GDK_ENTER_NOTIFY:
- case GDK_LEAVE_NOTIFY:
- return event->crossing.time;
- case GDK_PROPERTY_NOTIFY:
- return event->property.time;
- case GDK_SELECTION_CLEAR:
- case GDK_SELECTION_REQUEST:
- case GDK_SELECTION_NOTIFY:
- return event->selection.time;
- case GDK_PROXIMITY_IN:
- case GDK_PROXIMITY_OUT:
- return event->proximity.time;
- case GDK_DRAG_ENTER:
- case GDK_DRAG_LEAVE:
- case GDK_DRAG_MOTION:
- case GDK_DRAG_STATUS:
- case GDK_DROP_START:
- case GDK_DROP_FINISHED:
- return event->dnd.time;
- case GDK_CLIENT_EVENT:
- case GDK_CONFIGURE:
- case GDK_DELETE:
- case GDK_DESTROY:
- case GDK_EXPOSE:
- case GDK_FOCUS_CHANGE:
- case GDK_MAP:
- case GDK_NOTHING:
- case GDK_NO_EXPOSE:
- case GDK_SCROLL:
- case GDK_SETTING:
- case GDK_UNMAP:
- case GDK_VISIBILITY_NOTIFY:
- case GDK_WINDOW_STATE:
- /* return current time */
- break;
- }
- }
-
- return GDK_CURRENT_TIME;
-}
-
guint
eel_get_current_event_time (void)
{
- GdkEvent *event;
- guint time;
-
- event = gtk_get_current_event ();
- time = event_get_time (event);
- if (event != NULL) {
- gdk_event_free (event);
- }
- return time;
+ return gtk_get_current_event_time ();
}
void
eel_drag_set_icon_pixbuf (GdkDragContext *context,
- GdkPixbuf *pixbuf,
- int hot_x,
- int hot_y)
-{
- GdkPixmap *pixmap;
- GdkBitmap *mask;
-
- gdk_pixbuf_render_pixmap_and_mask
- (pixbuf, &pixmap, &mask,
- EEL_STANDARD_ALPHA_THRESHHOLD);
- gtk_drag_set_icon_pixmap
- (context, gdk_rgb_get_cmap (), pixmap, mask, hot_x, hot_y);
- /* FIXME: Verify that this does not leak the pixmap and mask.
- * We've always done it this way, but maybe we've always
- * leaked. Just doing the unref here definitely causes a
- * problem, so it's not that simple.
- */
+ GdkPixbuf *pixbuf,
+ int hot_x,
+ int hot_y)
+{
+ gtk_drag_set_icon_pixbuf (context, pixbuf, hot_x, hot_y);
}
/**
@@ -1974,36 +1822,6 @@ eel_gtk_widget_standard_realize (GtkWidg
widget->style = gtk_style_attach (widget->style, widget->window);
gtk_style_set_background (widget->style, widget->window, GTK_STATE_NORMAL);
-}
-
-/**
- * eel_gtk_widget_standard_draw:
- *
- * @widget: A GtkWidget
- * @area: Area from draw method.
- *
- * A standard implementation of GtkWidget::draw which simply
- * calls the expose_event method to do the work.
- *
- */
-void
-eel_gtk_widget_standard_draw (GtkWidget *widget,
- GdkRectangle *area)
-{
- GdkEventExpose event;
-
- g_return_if_fail (GTK_IS_WIDGET (widget));
- g_return_if_fail (area != NULL);
-
- event.type = GDK_EXPOSE;
- event.send_event = TRUE;
- event.window = widget->window;
- event.area = *area;
- event.count = 0;
-
- gdk_window_ref (event.window);
- gtk_widget_event (widget, (GdkEvent*) &event);
- gdk_window_unref (event.window);
}
/**
Index: eel/eel-gtk-extensions.h
===================================================================
RCS file: /cvs/gnome/eel/eel/eel-gtk-extensions.h,v
retrieving revision 1.13
diff -u -p -u -r1.13 eel-gtk-extensions.h
--- eel/eel-gtk-extensions.h 2001/09/28 18:45:49 1.13
+++ eel/eel-gtk-extensions.h 2001/11/01 04:36:08
@@ -155,11 +155,6 @@ GtkMenuItem * eel_gtk_menu_insert_se
void eel_gtk_menu_set_item_visibility (GtkMenu *menu,
int index,
gboolean visible);
-/* GtkStyle */
-void eel_gtk_style_set_font (GtkStyle *style,
- PangoFontDescription *font);
-void eel_gtk_style_set_font_by_name (GtkStyle *style,
- const char *font_name);
/* GtkLabel */
void eel_gtk_label_make_bold (GtkLabel *label);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]