/* Functions for creating and updating GTK widgets.
-Copyright (C) 2003-2011 Free Software Foundation, Inc.
+Copyright (C) 2003-2012 Free Software Foundation, Inc.
This file is part of GNU Emacs.
#include <config.h>
#ifdef USE_GTK
+#include <float.h>
#include <signal.h>
#include <stdio.h>
#include <setjmp.h>
Returns non-zero if display could be opened, zero if display could not
be opened, and less than zero if the GTK version doesn't support
- multipe displays. */
+ multiple displays. */
void
xg_display_open (char *display_name, Display **dpy)
GDK_COLORSPACE_RGB,
FALSE,
xim->bitmap_unit,
- (int) width,
- (int) height,
+ width,
+ height,
xim->bytes_per_line,
NULL,
NULL);
/* For the image defined in IMG, make and return a GtkImage. For displays with
8 planes or less we must make a GdkPixbuf and apply the mask manually.
- Otherwise the highlightning and dimming the tool bar code in GTK does
+ Otherwise the highlighting and dimming the tool bar code in GTK does
will look bad. For display with more than 8 planes we just use the
pixmap and mask directly. For monochrome displays, GTK doesn't seem
able to use external pixmaps, it looks bad whatever we do.
static void
xg_set_cursor (GtkWidget *w, GdkCursor *cursor)
{
- GdkWindow *window = gtk_widget_get_window(w);
+ GdkWindow *window = gtk_widget_get_window (w);
GList *children = gdk_window_peek_children (window);
gdk_window_set_cursor (window, cursor);
if (!utf8_str)
{
/* Probably some control characters in str. Escape them. */
- size_t nr_bad = 0;
+ ptrdiff_t len;
+ ptrdiff_t nr_bad = 0;
gsize bytes_read;
gsize bytes_written;
unsigned char *p = (unsigned char *)str;
}
if (cp) g_free (cp);
- up = utf8_str = xmalloc (strlen (str) + nr_bad * 4 + 1);
+ len = strlen (str);
+ if ((min (PTRDIFF_MAX, SIZE_MAX) - len - 1) / 4 < nr_bad)
+ memory_full (SIZE_MAX);
+ up = utf8_str = xmalloc (len + nr_bad * 4 + 1);
p = (unsigned char *)str;
while (! (cp = g_locale_to_utf8 ((char *)p, -1, &bytes_read,
GtkStyleContext *gsty
= gtk_widget_get_style_context (FRAME_GTK_OUTER_WIDGET (f));
GdkRGBA col;
- char buf[64];
+ char buf[sizeof "rgbi://" + 3 * (DBL_MAX_10_EXP + sizeof "-1.000000" - 1)];
int state = GTK_STATE_FLAG_SELECTED|GTK_STATE_FLAG_FOCUSED;
if (get_fg)
gtk_style_context_get_color (gsty, state, &col);
struct x_output *x = f->output_data.x;
if (x->ttip_widget == NULL)
{
+ GtkWidget *p;
+ GList *list, *iter;
+
g_object_set (G_OBJECT (widget), "has-tooltip", FALSE, NULL);
x->ttip_widget = tooltip;
g_object_ref (G_OBJECT (tooltip));
g_object_ref (G_OBJECT (x->ttip_lbl));
gtk_tooltip_set_custom (tooltip, x->ttip_lbl);
x->ttip_window = GTK_WINDOW (gtk_widget_get_toplevel (x->ttip_lbl));
+
+ /* Change stupid Gtk+ default line wrapping. */
+ p = gtk_widget_get_parent (x->ttip_lbl);
+ list = gtk_container_get_children (GTK_CONTAINER (p));
+ for (iter = list; iter; iter = g_list_next (iter))
+ {
+ GtkWidget *w = GTK_WIDGET (iter->data);
+ if (GTK_IS_LABEL (w))
+ gtk_label_set_line_wrap (GTK_LABEL (w), FALSE);
+ }
+ g_list_free (list);
+
/* ATK needs an empty title for some reason. */
gtk_window_set_title (x->ttip_window, "");
/* Realize so we can safely get screen later on. */
int
xg_prepare_tooltip (FRAME_PTR f,
- Lisp_Object string,
- int *width,
+ Lisp_Object string,
+ int *width,
int *height)
{
#ifndef USE_GTK_TOOLTIP
(gtk_widget_get_display (GTK_WIDGET (x->ttip_window))),
"gdk-display-current-tooltip", NULL);
- /* Put out dummy widget in so we can get callbacks for unrealize and
+ /* Put our dummy widget in so we can get callbacks for unrealize and
hierarchy-changed. */
gtk_tooltip_set_custom (x->ttip_widget, widget);
-
gtk_tooltip_set_text (x->ttip_widget, SSDATA (encoded_string));
gtk_widget_get_preferred_size (GTK_WIDGET (x->ttip_window), NULL, &req);
if (width) *width = req.width;
}
/* Hide tooltip if shown. Do nothing if not shown.
- Return non-zero if tip was hidden, non-ero if not (i.e. not using
+ Return non-zero if tip was hidden, non-zero if not (i.e. not using
system tooltips). */
int
int xneg = f->size_hint_flags & XNegative;
int top = f->top_pos;
int yneg = f->size_hint_flags & YNegative;
- char geom_str[32];
+ char geom_str[sizeof "=x--" + 4 * INT_STRLEN_BOUND (int)];
if (xneg)
left = -left;
}
}
-/* Resize the outer window of frame F after chainging the height.
+/* Resize the outer window of frame F after changing the height.
COLUMNS/ROWS is the size the edit area shall have after the resize. */
void
{
GdkEvent event;
event.any.window = gdkwin;
+ event.any.type = GDK_NOTHING;
gwdesc = gtk_get_event_widget (&event);
}
else
wtop = gtk_window_new (GTK_WINDOW_TOPLEVEL);
+ /* gtk_window_set_has_resize_grip is a Gtk+ 3.0 function but Ubuntu
+ has backported it to Gtk+ 2.0 and they add the resize grip for
+ Gtk+ 2.0 applications also. But it has a bug that makes Emacs loop
+ forever, so disable the grip. */
+#if GTK_MAJOR_VERSION < 3 && defined (HAVE_GTK_WINDOW_SET_HAS_RESIZE_GRIP)
+ gtk_window_set_has_resize_grip (GTK_WINDOW (wtop), FALSE);
+#endif
+
xg_set_screen (wtop, f);
wvbox = gtk_vbox_new (FALSE, 0);
/* Callback for dialogs that get WM_DELETE_WINDOW. We pop down
the dialog, but return TRUE so the event does not propagate further
in GTK. This prevents GTK from destroying the dialog widget automatically
- and we can always destrou the widget manually, regardles of how
+ and we can always destroy the widget manually, regardless of how
it was popped down (button press or WM_DELETE_WINDOW).
W is the dialog widget.
EVENT is the GdkEvent that represents WM_DELETE_WINDOW (not used).
PROMPT is a prompt to show to the user. May not be NULL.
DEFAULT_FILENAME is a default selection to be displayed. May be NULL.
If MUSTMATCH_P is non-zero, the returned file name must be an existing
- file. *FUNC is set to a function that can be used to retrieve the
- selected file name from the returned widget.
+ file. (Actually, this only has cosmetic effects, the user can
+ still enter a non-existing file.) *FUNC is set to a function that
+ can be used to retrieve the selected file name from the returned widget.
Returns the created widget. */
int filesel_done = 0;
xg_get_file_func func;
-#if defined (HAVE_GTK_AND_PTHREAD) && defined (__SIGRTMIN)
+#if defined (HAVE_PTHREAD) && defined (__SIGRTMIN)
/* I really don't know why this is needed, but without this the GLIBC add on
library linuxthreads hangs when the Gnome file chooser backend creates
threads. */
sigblock (sigmask (__SIGRTMIN));
-#endif /* HAVE_GTK_AND_PTHREAD */
+#endif /* HAVE_PTHREAD */
#ifdef HAVE_GTK_FILE_SELECTION_NEW
filesel_done = xg_dialog_run (f, w);
-#if defined (HAVE_GTK_AND_PTHREAD) && defined (__SIGRTMIN)
+#if defined (HAVE_PTHREAD) && defined (__SIGRTMIN)
sigunblock (sigmask (__SIGRTMIN));
#endif
char *fontname = NULL;
int done = 0;
-#if defined (HAVE_GTK_AND_PTHREAD) && defined (__SIGRTMIN)
+#if defined (HAVE_PTHREAD) && defined (__SIGRTMIN)
sigblock (sigmask (__SIGRTMIN));
-#endif /* HAVE_GTK_AND_PTHREAD */
+#endif /* HAVE_PTHREAD */
w = gtk_font_selection_dialog_new ("Pick a font");
if (!default_name)
done = xg_dialog_run (f, w);
-#if defined (HAVE_GTK_AND_PTHREAD) && defined (__SIGRTMIN)
+#if defined (HAVE_PTHREAD) && defined (__SIGRTMIN)
sigunblock (sigmask (__SIGRTMIN));
#endif
/* Create a menu item widget, and connect the callbacks.
- ITEM decribes the menu item.
+ ITEM describes the menu item.
F is the frame the created menu belongs to.
SELECT_CB is the callback to use when a menu item is selected.
HIGHLIGHT_CB is the callback to call when entering/leaving menu items.
HIGHLIGHT_CB is the callback to call when entering/leaving menu items.
POP_UP_P is non-zero if we shall create a popup menu.
MENU_BAR_P is non-zero if we shall create a menu bar.
- ADD_TEAROFF_P is non-zero if we shall add a teroff menu item. Ignored
+ ADD_TEAROFF_P is non-zero if we shall add a tearoff menu item. Ignored
if MENU_BAR_P is non-zero.
TOPMENU is the topmost GtkWidget that others shall be placed under.
It may be NULL, in that case we create the appropriate widget
}
}
- /* Remove widgets from first structual change. */
+ /* Remove widgets from first structural change. */
if (iter)
{
/* If we are adding new menu items below, we must remove from
gw = gdk_x11_window_lookup_for_display (gdpy, event->xbutton.window);
if (! gw) return 0;
gevent.any.window = gw;
+ gevent.any.type = GDK_NOTHING;
gwdesc = gtk_get_event_widget (&gevent);
if (! gwdesc) return 0;
if (! GTK_IS_MENU_BAR (gwdesc)
static struct
{
GtkWidget **widgets;
- int max_size;
- int used;
+ ptrdiff_t max_size;
+ ptrdiff_t used;
} id_to_widget;
/* Grow this much every time we need to allocate more */
/* Store the widget pointer W in id_to_widget and return the integer index. */
-static int
+static ptrdiff_t
xg_store_widget_in_map (GtkWidget *w)
{
- int i;
+ ptrdiff_t i;
if (id_to_widget.max_size == id_to_widget.used)
{
- int new_size = id_to_widget.max_size + ID_TO_WIDGET_INCR;
+ ptrdiff_t new_size;
+ if (TYPE_MAXIMUM (Window) - ID_TO_WIDGET_INCR < id_to_widget.max_size)
+ memory_full (SIZE_MAX);
- id_to_widget.widgets = xrealloc (id_to_widget.widgets,
- sizeof (GtkWidget *)*new_size);
+ new_size = id_to_widget.max_size + ID_TO_WIDGET_INCR;
+ id_to_widget.widgets = xnrealloc (id_to_widget.widgets,
+ new_size, sizeof (GtkWidget *));
for (i = id_to_widget.max_size; i < new_size; ++i)
id_to_widget.widgets[i] = 0;
Called when scroll bar is destroyed. */
static void
-xg_remove_widget_from_map (int idx)
+xg_remove_widget_from_map (ptrdiff_t idx)
{
if (idx < id_to_widget.max_size && id_to_widget.widgets[idx] != 0)
{
/* Get the widget pointer at IDX from id_to_widget. */
static GtkWidget *
-xg_get_widget_from_map (int idx)
+xg_get_widget_from_map (ptrdiff_t idx)
{
if (idx < id_to_widget.max_size && id_to_widget.widgets[idx] != 0)
return id_to_widget.widgets[idx];
/* Return the scrollbar id for X Window WID on display DPY.
Return -1 if WID not in id_to_widget. */
-int
+ptrdiff_t
xg_get_scroll_id_for_window (Display *dpy, Window wid)
{
- int idx;
+ ptrdiff_t idx;
GtkWidget *w;
w = xg_win_to_widget (dpy, wid);
static void
xg_gtk_scroll_destroy (GtkWidget *widget, gpointer data)
{
- int id = (intptr_t) data;
+ intptr_t id = (intptr_t) data;
xg_remove_widget_from_map (id);
}
/* Remove the scroll bar represented by SCROLLBAR_ID from the frame F. */
void
-xg_remove_scroll_bar (FRAME_PTR f, int scrollbar_id)
+xg_remove_scroll_bar (FRAME_PTR f, ptrdiff_t scrollbar_id)
{
GtkWidget *w = xg_get_widget_from_map (scrollbar_id);
if (w)
void
xg_update_scrollbar_pos (FRAME_PTR f,
- int scrollbar_id,
+ ptrdiff_t scrollbar_id,
int top,
int left,
int width,
gtk_adjustment_set_page_size (adj, size);
gtk_adjustment_set_step_increment (adj, new_step);
/* Assume a page increment is about 95% of the page size */
- gtk_adjustment_set_page_increment (adj,(int) (0.95*size));
+ gtk_adjustment_set_page_increment (adj, size - size / 20);
changed = 1;
}
}
GtkToolItem *ti = gtk_tool_item_new ();
GtkWidget *vb = horiz ? gtk_hbox_new (FALSE, 0) : gtk_vbox_new (FALSE, 0);
GtkWidget *wb = gtk_button_new ();
+ /* The eventbox is here so we can have tooltips on disabled items. */
GtkWidget *weventbox = gtk_event_box_new ();
if (wimage && !text_image)
gtk_container_add (GTK_CONTAINER (weventbox), wb);
gtk_container_add (GTK_CONTAINER (ti), weventbox);
- if (wimage)
+ if (wimage || label)
{
intptr_t ii = i;
gpointer gi = (gpointer) ii;
#endif
gtk_tool_item_set_homogeneous (ti, FALSE);
- /* Callback to save modifyer mask (Shift/Control, etc). GTK makes
+ /* Callback to save modifier mask (Shift/Control, etc). GTK makes
no distinction based on modifiers in the activate callback,
so we have to do it ourselves. */
g_signal_connect (wb, "button-release-event",
GtkWidget *wlbl = xg_get_tool_bar_widgets (vb, &wimage);
/* Check if the tool icon matches. */
- if (stock_name)
+ if (stock_name && wimage)
{
old = g_object_get_data (G_OBJECT (wimage),
XG_TOOL_BAR_STOCK_NAME);
if (!old || strcmp (old, stock_name))
return 1;
}
- else if (icon_name)
+ else if (icon_name && wimage)
{
old = g_object_get_data (G_OBJECT (wimage),
XG_TOOL_BAR_ICON_NAME);
if (!old || strcmp (old, icon_name))
return 1;
}
- else
+ else if (wimage)
{
gpointer gold_img = g_object_get_data (G_OBJECT (wimage),
XG_TOOL_BAR_IMAGE_DATA);
return 1;
/* Ensure label is correct. */
- if (label)
+ if (label && wlbl)
gtk_label_set_text (GTK_LABEL (wlbl), label);
return 0;
}
int enabled_p = !NILP (PROP (TOOL_BAR_ITEM_ENABLED_P));
int selected_p = !NILP (PROP (TOOL_BAR_ITEM_SELECTED_P));
int idx;
- int img_id;
+ ptrdiff_t img_id;
int icon_size = 0;
struct image *img = NULL;
Lisp_Object image;