X-Git-Url: https://code.delx.au/gnu-emacs/blobdiff_plain/93da8ac5d79e742e1b1391f449c0456b9eb1f534..f3aaca3552ba961d13cd1ee935c1c6b075f2398a:/src/gtkutil.c diff --git a/src/gtkutil.c b/src/gtkutil.c index 5fc2bebdc6..14b76ce67a 100644 --- a/src/gtkutil.c +++ b/src/gtkutil.c @@ -1,6 +1,6 @@ /* Functions for creating and updating GTK widgets. -Copyright (C) 2003-2015 Free Software Foundation, Inc. +Copyright (C) 2003-2016 Free Software Foundation, Inc. This file is part of GNU Emacs. @@ -26,20 +26,18 @@ along with GNU Emacs. If not, see . */ #include #include "lisp.h" +#include "dispextern.h" +#include "frame.h" +#include "systime.h" #include "xterm.h" #include "blockinput.h" -#include "syssignal.h" #include "window.h" -#include "buffer.h" #include "gtkutil.h" #include "termhooks.h" #include "keyboard.h" -#include "charset.h" #include "coding.h" -#include "font.h" #include -#include "xsettings.h" #ifdef HAVE_XFT #include @@ -519,9 +517,12 @@ get_utf8_string (const char *str) if (cp) g_free (cp); len = strlen (str); - if ((min (PTRDIFF_MAX, SIZE_MAX) - len - 1) / 4 < nr_bad) + ptrdiff_t alloc; + if (INT_MULTIPLY_WRAPV (nr_bad, 4, &alloc) + || INT_ADD_WRAPV (len + 1, alloc, &alloc) + || SIZE_MAX < alloc) memory_full (SIZE_MAX); - up = utf8_str = xmalloc (len + nr_bad * 4 + 1); + up = utf8_str = xmalloc (alloc); p = (unsigned char *)str; while (! (cp = g_locale_to_utf8 ((char *)p, -1, &bytes_read, @@ -583,9 +584,7 @@ xg_check_special_colors (struct frame *f, (unsigned) (col.red * 65535), (unsigned) (col.green * 65535), (unsigned) (col.blue * 65535)); - success_p = (XParseColor (FRAME_X_DISPLAY (f), FRAME_X_COLORMAP (f), - buf, color) - != 0); + success_p = x_parse_color (f, buf, color) != 0; #else GtkStyle *gsty = gtk_widget_get_style (FRAME_GTK_WIDGET (f)); GdkColor *grgb = get_bg @@ -920,8 +919,6 @@ xg_frame_resized (struct frame *f, int pixelwidth, int pixelheight) change_frame_size (f, width, height, 0, 1, 0, 1); SET_FRAME_GARBAGED (f); cancel_mouse_face (f); - - do_pending_window_change (0); } } @@ -955,6 +952,8 @@ xg_frame_set_char_size (struct frame *f, int width, int height) totalwidth /= scale; } + x_wm_set_size_hint (f, 0, 0); + /* Resize the top level widget so rows and columns remain constant. When the frame is fullheight and we only want to change the width @@ -968,41 +967,34 @@ xg_frame_set_char_size (struct frame *f, int width, int height) { frame_size_history_add (f, Qxg_frame_set_char_size_1, width, height, - list2 (make_number (gheight), - make_number (totalheight))); + list2 (make_number (gheight), make_number (totalheight))); gtk_window_resize (GTK_WINDOW (FRAME_GTK_OUTER_WIDGET (f)), - gwidth, - totalheight); + gwidth, totalheight); } else if (EQ (fullscreen, Qfullheight) && height == FRAME_TEXT_HEIGHT (f)) { frame_size_history_add (f, Qxg_frame_set_char_size_2, width, height, - list2 (make_number (gwidth), - make_number (totalwidth))); + list2 (make_number (gwidth), make_number (totalwidth))); gtk_window_resize (GTK_WINDOW (FRAME_GTK_OUTER_WIDGET (f)), - totalwidth, - gheight); + totalwidth, gheight); } else { frame_size_history_add (f, Qxg_frame_set_char_size_3, width, height, - list2 (make_number (totalwidth), - make_number (totalheight))); + list2 (make_number (totalwidth), make_number (totalheight))); gtk_window_resize (GTK_WINDOW (FRAME_GTK_OUTER_WIDGET (f)), - totalwidth, - totalheight); + totalwidth, totalheight); fullscreen = Qnil; } SET_FRAME_GARBAGED (f); cancel_mouse_face (f); - x_wm_set_size_hint (f, 0, 0); /* We can not call change_frame_size for a mapped frame, we can not set pixel width/height either. The window manager may override our resize request, XMonad does this all the time. @@ -1403,7 +1395,8 @@ x_wm_set_size_hint (struct frame *f, long int flags, bool user_position) hint_flags |= GDK_HINT_BASE_SIZE; /* Use one row/col here so base_height/width does not become zero. - Gtk+ and/or Unity on Ubuntu 12.04 can't handle it. */ + Gtk+ and/or Unity on Ubuntu 12.04 can't handle it. + Obviously this makes the row/col value displayed off by 1. */ base_width = FRAME_TEXT_COLS_TO_PIXEL_WIDTH (f, 1) + FRAME_TOOLBAR_WIDTH (f); base_height = FRAME_TEXT_LINES_TO_PIXEL_HEIGHT (f, 1) + FRAME_MENUBAR_HEIGHT (f) + FRAME_TOOLBAR_HEIGHT (f); @@ -1928,9 +1921,7 @@ xg_get_file_with_chooser (struct frame *f, if (default_filename) { Lisp_Object file; - struct gcpro gcpro1; char *utf8_filename; - GCPRO1 (file); file = build_string (default_filename); @@ -1955,8 +1946,6 @@ xg_get_file_with_chooser (struct frame *f, gtk_file_chooser_set_current_name (GTK_FILE_CHOOSER (filewin), cp); } } - - UNGCPRO; } *func = xg_get_file_name_from_chooser; @@ -4095,43 +4084,46 @@ xg_page_setup_dialog (void) Lisp_Object xg_get_page_setup (void) { - Lisp_Object result, orientation_symbol; - GtkPageOrientation orientation; + Lisp_Object orientation_symbol; if (page_setup == NULL) page_setup = gtk_page_setup_new (); - result = list4 (Fcons (Qleft_margin, - make_float (gtk_page_setup_get_left_margin (page_setup, - GTK_UNIT_POINTS))), - Fcons (Qright_margin, - make_float (gtk_page_setup_get_right_margin (page_setup, - GTK_UNIT_POINTS))), - Fcons (Qtop_margin, - make_float (gtk_page_setup_get_top_margin (page_setup, - GTK_UNIT_POINTS))), - Fcons (Qbottom_margin, - make_float (gtk_page_setup_get_bottom_margin (page_setup, - GTK_UNIT_POINTS)))); - result = Fcons (Fcons (Qheight, - make_float (gtk_page_setup_get_page_height (page_setup, - GTK_UNIT_POINTS))), - result); - result = Fcons (Fcons (Qwidth, - make_float (gtk_page_setup_get_page_width (page_setup, - GTK_UNIT_POINTS))), - result); - orientation = gtk_page_setup_get_orientation (page_setup); - if (orientation == GTK_PAGE_ORIENTATION_PORTRAIT) - orientation_symbol = Qportrait; - else if (orientation == GTK_PAGE_ORIENTATION_LANDSCAPE) - orientation_symbol = Qlandscape; - else if (orientation == GTK_PAGE_ORIENTATION_REVERSE_PORTRAIT) - orientation_symbol = Qreverse_portrait; - else if (orientation == GTK_PAGE_ORIENTATION_REVERSE_LANDSCAPE) - orientation_symbol = Qreverse_landscape; - result = Fcons (Fcons (Qorientation, orientation_symbol), result); - - return result; + + switch (gtk_page_setup_get_orientation (page_setup)) + { + case GTK_PAGE_ORIENTATION_PORTRAIT: + orientation_symbol = Qportrait; + break; + case GTK_PAGE_ORIENTATION_LANDSCAPE: + orientation_symbol = Qlandscape; + break; + case GTK_PAGE_ORIENTATION_REVERSE_PORTRAIT: + orientation_symbol = Qreverse_portrait; + break; + case GTK_PAGE_ORIENTATION_REVERSE_LANDSCAPE: + orientation_symbol = Qreverse_landscape; + break; + default: + eassume (false); + } + + return listn (CONSTYPE_HEAP, 7, + Fcons (Qorientation, orientation_symbol), +#define MAKE_FLOAT_PAGE_SETUP(f) make_float (f (page_setup, GTK_UNIT_POINTS)) + Fcons (Qwidth, + MAKE_FLOAT_PAGE_SETUP (gtk_page_setup_get_page_width)), + Fcons (Qheight, + MAKE_FLOAT_PAGE_SETUP (gtk_page_setup_get_page_height)), + Fcons (Qleft_margin, + MAKE_FLOAT_PAGE_SETUP (gtk_page_setup_get_left_margin)), + Fcons (Qright_margin, + MAKE_FLOAT_PAGE_SETUP (gtk_page_setup_get_right_margin)), + Fcons (Qtop_margin, + MAKE_FLOAT_PAGE_SETUP (gtk_page_setup_get_top_margin)), + Fcons (Qbottom_margin, + MAKE_FLOAT_PAGE_SETUP (gtk_page_setup_get_bottom_margin)) +#undef MAKE_FLOAT_PAGE_SETUP + ); } static void @@ -4459,8 +4451,6 @@ find_rtl_image (struct frame *f, Lisp_Object image, Lisp_Object rtl) { int i; Lisp_Object file, rtl_name; - struct gcpro gcpro1, gcpro2; - GCPRO2 (file, rtl_name); rtl_name = Ffile_name_nondirectory (rtl); @@ -5008,9 +4998,23 @@ update_frame_tool_bar (struct frame *f) gtk_widget_show_all (x->toolbar_widget); if (xg_update_tool_bar_sizes (f)) { + int inhibit + = ((f->after_make_frame + && !f->tool_bar_resized + && (EQ (frame_inhibit_implied_resize, Qt) + || (CONSP (frame_inhibit_implied_resize) + && !NILP (Fmemq (Qtool_bar_lines, + frame_inhibit_implied_resize)))) + /* This will probably fail to DTRT in the + fullheight/-width cases. */ + && NILP (get_frame_param (f, Qfullscreen))) + ? 0 + : 2); + frame_size_history_add (f, Qupdate_frame_tool_bar, 0, 0, Qnil); - adjust_frame_size (f, -1, -1, 2, 0, Qtool_bar_lines); + adjust_frame_size (f, -1, -1, inhibit, 0, Qtool_bar_lines); } + f->tool_bar_resized = f->tool_bar_redisplayed; } unblock_input ();