#include <X11/Xft/Xft.h>
#endif
+#ifdef HAVE_GTK3
+#include <gtk/gtkx.h>
+#endif
+
#define FRAME_TOTAL_PIXEL_HEIGHT(f) \
(FRAME_PIXEL_HEIGHT (f) + FRAME_MENUBAR_HEIGHT (f) + FRAME_TOOLBAR_HEIGHT (f))
#define remove_submenu(w) gtk_menu_item_remove_submenu ((w))
#endif
+#ifndef HAVE_GTK3
+#define gdk_window_get_screen(w) gdk_drawable_get_screen (w)
+#define gdk_window_get_geometry(w, a, b, c, d) \
+ gdk_window_get_geometry (w, a, b, c, d, 0)
+#define gdk_x11_window_lookup_for_display(d, w) \
+ gdk_xid_table_lookup_for_display (d, w)
+#define GDK_KEY_g GDK_g
+#endif
+
#define XG_BIN_CHILD(x) gtk_bin_get_child (GTK_BIN (x))
\f
static void
xg_set_screen (GtkWidget *w, FRAME_PTR f)
{
- if (FRAME_X_DISPLAY (f) != GDK_DISPLAY ())
+ if (FRAME_X_DISPLAY (f) != DEFAULT_GDK_DISPLAY ())
{
GdkDisplay *gdpy = gdk_x11_lookup_xdisplay (FRAME_X_DISPLAY (f));
GdkScreen *gscreen = gdk_display_get_default_screen (gdpy);
return gdk_cursor_new_for_display (gdpy, GDK_LEFT_PTR);
}
+static GdkPixbuf *
+xg_get_pixbuf_from_pixmap (FRAME_PTR f, Pixmap pix)
+{
+ int iunused;
+ GdkPixbuf *tmp_buf;
+ Window wunused;
+ unsigned int width, height, uunused;
+ XImage *xim;
+
+ XGetGeometry (FRAME_X_DISPLAY (f), pix, &wunused, &iunused, &iunused,
+ &width, &height, &uunused, &uunused);
+
+ xim = XGetImage (FRAME_X_DISPLAY (f), pix, 0, 0, width, height,
+ ~0, XYPixmap);
+ if (!xim) return 0;
+
+ tmp_buf = gdk_pixbuf_new_from_data (xim->data,
+ GDK_COLORSPACE_RGB,
+ FALSE,
+ xim->bitmap_unit,
+ (int) width,
+ (int) height,
+ xim->bytes_per_line,
+ NULL,
+ NULL);
+ XDestroyImage (xim);
+ return tmp_buf;
+}
+
/* Apply GMASK to GPIX and return a GdkPixbuf with an alpha channel. */
static GdkPixbuf *
-xg_get_pixbuf_from_pix_and_mask (GdkPixmap *gpix,
- GdkPixmap *gmask,
- GdkColormap *cmap)
+xg_get_pixbuf_from_pix_and_mask (FRAME_PTR f,
+ Pixmap pix,
+ Pixmap mask)
{
int width, height;
GdkPixbuf *icon_buf, *tmp_buf;
- gdk_drawable_get_size (gpix, &width, &height);
- tmp_buf = gdk_pixbuf_get_from_drawable (NULL, gpix, cmap,
- 0, 0, 0, 0, width, height);
+ tmp_buf = xg_get_pixbuf_from_pixmap (f, pix);
icon_buf = gdk_pixbuf_add_alpha (tmp_buf, FALSE, 0, 0, 0);
g_object_unref (G_OBJECT (tmp_buf));
- if (gmask)
+ width = gdk_pixbuf_get_width (icon_buf);
+ height = gdk_pixbuf_get_height (icon_buf);
+
+ if (mask)
{
- GdkPixbuf *mask_buf = gdk_pixbuf_get_from_drawable (NULL,
- gmask,
- NULL,
- 0, 0, 0, 0,
- width, height);
+ GdkPixbuf *mask_buf = xg_get_pixbuf_from_pixmap (f, mask);
guchar *pixels = gdk_pixbuf_get_pixels (icon_buf);
guchar *mask_pixels = gdk_pixbuf_get_pixels (mask_buf);
int rowstride = gdk_pixbuf_get_rowstride (icon_buf);
GtkWidget *widget,
GtkImage *old_widget)
{
- GdkPixmap *gpix;
- GdkPixmap *gmask;
- GdkDisplay *gdpy;
- GdkColormap *cmap;
GdkPixbuf *icon_buf;
/* If we have a file, let GTK do all the image handling.
on a monochrome display, and sometimes bad on all displays with
certain themes. */
- gdpy = gdk_x11_lookup_xdisplay (FRAME_X_DISPLAY (f));
- gpix = gdk_pixmap_foreign_new_for_display (gdpy, img->pixmap);
- gmask = img->mask ? gdk_pixmap_foreign_new_for_display (gdpy, img->mask) : 0;
-
/* This is a workaround to make icons look good on pseudo color
displays. Apparently GTK expects the images to have an alpha
channel. If they don't, insensitive and activated icons will
not associated with the img->pixmap. The img->pixmap may be removed
by clearing the image cache and then the tool bar redraw fails, since
Gtk+ assumes the pixmap is always there. */
- cmap = gtk_widget_get_colormap (widget);
- icon_buf = xg_get_pixbuf_from_pix_and_mask (gpix, gmask, cmap);
-
- if (! old_widget)
- old_widget = GTK_IMAGE (gtk_image_new_from_pixbuf (icon_buf));
- else
- gtk_image_set_from_pixbuf (old_widget, icon_buf);
+ icon_buf = xg_get_pixbuf_from_pix_and_mask (f, img->pixmap, img->mask);
- g_object_unref (G_OBJECT (icon_buf));
+ if (icon_buf)
+ {
+ if (! old_widget)
+ old_widget = GTK_IMAGE (gtk_image_new_from_pixbuf (icon_buf));
+ else
+ gtk_image_set_from_pixbuf (old_widget, icon_buf);
- g_object_unref (G_OBJECT (gpix));
- if (gmask) g_object_unref (G_OBJECT (gmask));
+ g_object_unref (G_OBJECT (icon_buf));
+ }
return GTK_WIDGET (old_widget);
}
XColor *color)
{
int success_p = 0;
- if (FRAME_GTK_WIDGET (f))
- {
- if (strcmp ("gtk_selection_bg_color", color_name) == 0)
- {
- GtkStyle *gsty = gtk_widget_get_style (FRAME_GTK_WIDGET (f));
- color->red = gsty->bg[GTK_STATE_SELECTED].red;
- color->green = gsty->bg[GTK_STATE_SELECTED].green;
- color->blue = gsty->bg[GTK_STATE_SELECTED].blue;
- color->pixel = gsty->bg[GTK_STATE_SELECTED].pixel;
- success_p = 1;
- }
- else if (strcmp ("gtk_selection_fg_color", color_name) == 0)
- {
- GtkStyle *gsty = gtk_widget_get_style (FRAME_GTK_WIDGET (f));
- color->red = gsty->fg[GTK_STATE_SELECTED].red;
- color->green = gsty->fg[GTK_STATE_SELECTED].green;
- color->blue = gsty->fg[GTK_STATE_SELECTED].blue;
- color->pixel = gsty->fg[GTK_STATE_SELECTED].pixel;
- success_p = 1;
- }
- }
+ int get_bg = strcmp ("gtk_selection_bg_color", color_name) == 0;
+ int get_fg = !get_bg && strcmp ("gtk_selection_fg_color", color_name) == 0;
+
+ if (! FRAME_GTK_WIDGET (f) || ! (get_bg || get_fg))
+ return success_p;
+
+ BLOCK_INPUT;
+ {
+#ifdef HAVE_GTK3
+ GtkStyleContext *gsty
+ = gtk_widget_get_style_context (FRAME_GTK_OUTER_WIDGET (f));
+ GdkRGBA col;
+ char buf[64];
+ int state = GTK_STATE_FLAG_SELECTED|GTK_STATE_FLAG_FOCUSED;
+ if (get_fg)
+ gtk_style_context_get_color (gsty, state, &col);
+ else
+ gtk_style_context_get_background_color (gsty, state, &col);
+
+ sprintf (buf, "rgbi:%lf/%lf/%lf", col.red, col.green, col.blue);
+ success_p = XParseColor (FRAME_X_DISPLAY (f), FRAME_X_COLORMAP (f),
+ buf, color);
+#else
+ GtkStyle *gsty = gtk_widget_get_style (FRAME_GTK_WIDGET (f));
+ GdkColor *grgb = get_bg
+ ? &gsty->bg[GTK_STATE_SELECTED]
+ : &gsty->fg[GTK_STATE_SELECTED];
+
+ color->red = grgb->red;
+ color->green = grgb->green;
+ color->blue = grgb->blue;
+ color->pixel = grgb->pixel;
+ success_p = 1;
+#endif
+ }
+ UNBLOCK_INPUT;
return success_p;
}
encoded_string = ENCODE_UTF_8 (string);
widget = GTK_WIDGET (x->ttip_lbl);
gwin = gtk_widget_get_window (GTK_WIDGET (x->ttip_window));
- screen = gdk_drawable_get_screen (gwin);
+ screen = gdk_window_get_screen (gwin);
settings = gtk_settings_get_for_screen (screen);
g_object_get (settings, "gtk-enable-tooltips", &tt_enabled, NULL);
if (tt_enabled)
gtk_tooltip_set_custom (x->ttip_widget, widget);
gtk_tooltip_set_text (x->ttip_widget, SDATA (encoded_string));
- gtk_widget_size_request (GTK_WIDGET (x->ttip_window), &req);
+ gtk_widget_get_preferred_size (GTK_WIDGET (x->ttip_window), NULL, &req);
if (width) *width = req.width;
if (height) *height = req.height;
if (g_object_get_data (G_OBJECT (win), "restore-tt"))
{
GdkWindow *gwin = gtk_widget_get_window (GTK_WIDGET (win));
- GdkScreen *screen = gdk_drawable_get_screen (gwin);
+ GdkScreen *screen = gdk_window_get_screen (gwin);
GtkSettings *settings = gtk_settings_get_for_screen (screen);
g_object_set (settings, "gtk-enable-tooltips", TRUE, NULL);
}
if (FRAME_GTK_WIDGET (f) && gtk_widget_get_mapped (FRAME_GTK_WIDGET (f)))
gdk_window_get_geometry (gtk_widget_get_window (FRAME_GTK_WIDGET (f)),
0, 0,
- &pixelwidth, &pixelheight, 0);
+ &pixelwidth, &pixelheight);
else return;
}
BLOCK_INPUT;
- gdkwin = gdk_xid_table_lookup_for_display (gdk_x11_lookup_xdisplay (dpy),
- wdesc);
+ gdkwin = gdk_x11_window_lookup_for_display (gdk_x11_lookup_xdisplay (dpy),
+ wdesc);
if (gdkwin)
{
GdkEvent event;
return gwdesc;
}
-/* Fill in the GdkColor C so that it represents PIXEL.
- W is the widget that color will be used for. Used to find colormap. */
+/* Set the background of widget W to PIXEL. */
static void
-xg_pix_to_gcolor (GtkWidget *w, long unsigned int pixel, GdkColor *c)
+xg_set_widget_bg (FRAME_PTR f, GtkWidget *w, long unsigned int pixel)
{
+#ifdef HAVE_GTK3
+ GdkRGBA bg;
+ XColor xbg;
+ xbg.pixel = pixel;
+ if (XQueryColor (FRAME_X_DISPLAY (f), FRAME_X_COLORMAP (f), &xbg))
+ {
+ bg.red = (double)xbg.red/65536.0;
+ bg.green = (double)xbg.green/65536.0;
+ bg.blue = (double)xbg.blue/65536.0;
+ bg.alpha = 1.0;
+ gtk_widget_override_background_color (w, GTK_STATE_FLAG_NORMAL, &bg);
+ }
+#else
+ GdkColor bg;
GdkColormap *map = gtk_widget_get_colormap (w);
- gdk_colormap_query_color (map, pixel, c);
+ gdk_colormap_query_color (map, pixel, &bg);
+ gtk_widget_modify_bg (FRAME_GTK_WIDGET (f), GTK_STATE_NORMAL, &bg);
+#endif
}
/* Callback called when the gtk theme changes.
kbd_buffer_store_event (&event);
}
+/* Called when a delete-event occurs on WIDGET. */
+
+static gboolean
+delete_cb (GtkWidget *widget,
+ GdkEvent *event,
+ gpointer user_data)
+{
+#ifdef HAVE_GTK3
+ /* The event doesn't arrive in the normal event loop. Send event
+ here. */
+ FRAME_PTR f = (FRAME_PTR) user_data;
+ struct input_event ie;
+
+ EVENT_INIT (ie);
+ ie.kind = DELETE_WINDOW_EVENT;
+ XSETFRAME (ie.frame_or_window, f);
+ kbd_buffer_store_event (&ie);
+#endif
+
+ return TRUE;
+}
+
/* Create and set up the GTK widgets for frame F.
Return 0 if creation failed, non-zero otherwise. */
GtkWidget *wtop;
GtkWidget *wvbox, *whbox;
GtkWidget *wfixed;
- GdkColor bg;
GtkRcStyle *style;
char *title = 0;
/* Add callback to do nothing on WM_DELETE_WINDOW. The default in
GTK is to destroy the widget. We want Emacs to do that instead. */
g_signal_connect (G_OBJECT (wtop), "delete-event",
- G_CALLBACK (gtk_true), 0);
+ G_CALLBACK (delete_cb), f);
/* Convert our geometry parameters into a geometry string
and specify it.
/* Since GTK clears its window by filling with the background color,
we must keep X and GTK background in sync. */
- xg_pix_to_gcolor (wfixed, FRAME_BACKGROUND_PIXEL (f), &bg);
- gtk_widget_modify_bg (wfixed, GTK_STATE_NORMAL, &bg);
+ xg_set_widget_bg (f, wfixed, FRAME_BACKGROUND_PIXEL (f));
+#ifndef HAVE_GTK3
/* Also, do not let any background pixmap to be set, this looks very
bad as Emacs overwrites the background pixmap with its own idea
of background color. */
/* Must use g_strdup because gtk_widget_modify_style does g_free. */
style->bg_pixmap_name[GTK_STATE_NORMAL] = g_strdup ("<none>");
gtk_widget_modify_style (wfixed, style);
+#else
+ gtk_widget_set_can_focus (wfixed, TRUE);
+#endif
#ifdef USE_GTK_TOOLTIP
/* Steal a tool tip window we can move ourselves. */
{
if (FRAME_GTK_WIDGET (f))
{
- GdkColor gdk_bg;
-
BLOCK_INPUT;
- xg_pix_to_gcolor (FRAME_GTK_WIDGET (f), bg, &gdk_bg);
- gtk_widget_modify_bg (FRAME_GTK_WIDGET (f), GTK_STATE_NORMAL, &gdk_bg);
+ xg_set_widget_bg (f, FRAME_GTK_WIDGET (f), FRAME_BACKGROUND_PIXEL (f));
UNBLOCK_INPUT;
}
}
void
xg_set_frame_icon (FRAME_PTR f, Pixmap icon_pixmap, Pixmap icon_mask)
{
- GdkDisplay *gdpy = gdk_x11_lookup_xdisplay (FRAME_X_DISPLAY (f));
- GdkPixmap *gpix = gdk_pixmap_foreign_new_for_display (gdpy, icon_pixmap);
- GdkPixmap *gmask = gdk_pixmap_foreign_new_for_display (gdpy, icon_mask);
- GdkPixbuf *gp = xg_get_pixbuf_from_pix_and_mask (gpix, gmask, NULL);
-
+ GdkPixbuf *gp = xg_get_pixbuf_from_pix_and_mask (f,
+ icon_pixmap,
+ icon_mask);
+ if (gp)
gtk_window_set_icon (GTK_WINDOW (FRAME_GTK_OUTER_WIDGET (f)), gp);
}
/* Try to make dialog look better. Must realize first so
the widget can calculate the size it needs. */
gtk_widget_realize (w);
- gtk_widget_size_request (w, &req);
+ gtk_widget_get_preferred_size (w, NULL, &req);
gtk_box_set_spacing (wvbox, req.height);
if (item->value && strlen (item->value) > 0)
button_spacing = 2*req.width/strlen (item->value);
{
GtkRequisition req;
FRAME_PTR f = (FRAME_PTR) user_data;
- gtk_widget_size_request (w, &req);
+ gtk_widget_get_preferred_size (w, NULL, &req);
if (FRAME_MENUBAR_HEIGHT (f) != req.height)
{
FRAME_MENUBAR_HEIGHT (f) = req.height;
g_signal_connect (x->menubar_widget, "map", G_CALLBACK (menubar_map_cb), f);
gtk_widget_show_all (x->menubar_widget);
- gtk_widget_size_request (x->menubar_widget, &req);
+ gtk_widget_get_preferred_size (x->menubar_widget, NULL, &req);
/* If menu bar doesn't know its height yet, cheat a little so the frame
doesn't jump so much when resized later in menubar_map_cb. */
return 0;
gdpy = gdk_x11_lookup_xdisplay (FRAME_X_DISPLAY (f));
- gw = gdk_xid_table_lookup_for_display (gdpy, event->xbutton.window);
+ gw = gdk_x11_window_lookup_for_display (gdpy, event->xbutton.window);
if (! gw) return 0;
gevent.any.window = gw;
gwdesc = gtk_get_event_widget (&gevent);
{
GtkWidget *wscroll;
GtkWidget *webox;
- GtkObject *vadj;
int scroll_id;
+#ifdef HAVE_GTK3
+ GtkAdjustment *vadj;
+#else
+ GtkObject *vadj;
+#endif
/* Page, step increment values are not so important here, they
will be corrected in x_set_toolkit_scroll_bar_thumb. */
wscroll = gtk_vscrollbar_new (GTK_ADJUSTMENT (vadj));
webox = gtk_event_box_new ();
gtk_widget_set_name (wscroll, scroll_bar_name);
+#ifndef HAVE_GTK3
gtk_range_set_update_policy (GTK_RANGE (wscroll), GTK_UPDATE_CONTINUOUS);
+#endif
g_object_set_data (G_OBJECT (wscroll), XG_FRAME_DATA, (gpointer)f);
scroll_id = xg_store_widget_in_map (wscroll);
{
GtkRequisition req, req2;
FRAME_X_OUTPUT (f)->toolbar_detached = 1;
- gtk_widget_size_request (GTK_WIDGET (wbox), &req);
- gtk_widget_size_request (w, &req2);
+ gtk_widget_get_preferred_size (GTK_WIDGET (wbox), NULL, &req);
+ gtk_widget_get_preferred_size (w, NULL, &req2);
req.width -= req2.width;
req.height -= req2.height;
if (FRAME_TOOLBAR_TOP_HEIGHT (f) != 0)
{
GtkRequisition req, req2;
FRAME_X_OUTPUT (f)->toolbar_detached = 0;
- gtk_widget_size_request (GTK_WIDGET (wbox), &req);
- gtk_widget_size_request (w, &req2);
+ gtk_widget_get_preferred_size (GTK_WIDGET (wbox), NULL, &req);
+ gtk_widget_get_preferred_size (w, NULL, &req2);
req.width += req2.width;
req.height += req2.height;
if (FRAME_TOOLBAR_TOP_HEIGHT (f) != 0)
Returns FALSE to tell GTK to keep processing this event. */
+#ifndef HAVE_GTK3
static gboolean
xg_tool_bar_item_expose_callback (GtkWidget *w,
GdkEventExpose *event,
gint width, height;
gdk_drawable_get_size (event->window, &width, &height);
-
event->area.x -= width > event->area.width ? width-event->area.width : 0;
event->area.y -= height > event->area.height ? height-event->area.height : 0;
return FALSE;
}
+#endif
#ifdef HAVE_GTK_ORIENTABLE_SET_ORIENTATION
#define toolbar_set_orientation(w, o) \
g_object_set_data (G_OBJECT (weventbox), XG_FRAME_DATA, (gpointer)f);
+#ifndef HAVE_GTK3
/* Catch expose events to overcome an annoying redraw bug, see
comment for xg_tool_bar_item_expose_callback. */
g_signal_connect (G_OBJECT (ti),
"expose-event",
G_CALLBACK (xg_tool_bar_item_expose_callback),
0);
-
+#endif
gtk_tool_item_set_homogeneous (ti, FALSE);
/* Callback to save modifyer mask (Shift/Control, etc). GTK makes
GtkRequisition req;
int nl = 0, nr = 0, nt = 0, nb = 0;
- gtk_widget_size_request (GTK_WIDGET (x->handlebox_widget), &req);
+ gtk_widget_get_preferred_size (GTK_WIDGET (x->handlebox_widget), NULL, &req);
if (x->toolbar_in_hbox)
{
int pos;
GtkToolItem *ti;
GtkTextDirection dir;
int pack_tool_bar = x->handlebox_widget == NULL;
-
Lisp_Object style;
int text_image, horiz;
/* Make dialogs close on C-g. Since file dialog inherits from
dialog, this works for them also. */
binding_set = gtk_binding_set_by_class (g_type_class_ref (GTK_TYPE_DIALOG));
- gtk_binding_entry_add_signal (binding_set, GDK_g, GDK_CONTROL_MASK,
+ gtk_binding_entry_add_signal (binding_set, GDK_KEY_g, GDK_CONTROL_MASK,
"close", 0);
/* Make menus close on C-g. */
binding_set = gtk_binding_set_by_class (g_type_class_ref
(GTK_TYPE_MENU_SHELL));
- gtk_binding_entry_add_signal (binding_set, GDK_g, GDK_CONTROL_MASK,
+ gtk_binding_entry_add_signal (binding_set, GDK_KEY_g, GDK_CONTROL_MASK,
"cancel", 0);
}