1 /* eel-gtk-extensions.c - implementation of new functions that operate on
2  *                         gtk classes. Perhaps some of these should be
3  *                         rolled into gtk someday.
4  *
5  *  Copyright (C) 1999, 2000, 2001 Eazel, Inc.
6  *
7  *  The Gnome Library is free software; you can redistribute it and/or
8  *  modify it under the terms of the GNU Library General Public License as
9  *  published by the Free Software Foundation; either version 2 of the
10  *  License, or (at your option) any later version.
11  *
12  *  The Gnome Library is distributed in the hope that it will be useful,
13  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  *  Library General Public License for more details.
16  *
17  *  You should have received a copy of the GNU Library General Public
18  *  License along with the Gnome Library; see the file COPYING.LIB.  If not,
19  *  see <http://www.gnu.org/licenses/>.
20  *
21  *  Authors: John Sullivan <sullivan@eazel.com>
22  *           Ramiro Estrugo <ramiro@eazel.com>
23  *           Darin Adler <darin@eazel.com>
24  */
25 
26 #include <config.h>
27 #include "eel-gtk-extensions.h"
28 
29 #include "eel-glib-extensions.h"
30 #include "eel-string.h"
31 
32 #include <gdk/gdk.h>
33 #include <gtk/gtk.h>
34 #include <glib/gi18n-lib.h>
35 #include <math.h>
36 
37 /* This number is fairly arbitrary. Long enough to show a pretty long
38  * menu title, but not so long to make a menu grotesquely wide.
39  */
40 #define MAXIMUM_MENU_TITLE_LENGTH       48
41 
42 /* Used for window position & size sanity-checking. The sizes are big enough to prevent
43  * at least normal-sized gnome panels from obscuring the window at the screen edges.
44  */
45 #define MINIMUM_ON_SCREEN_WIDTH         100
46 #define MINIMUM_ON_SCREEN_HEIGHT        100
47 
48 
49 /**
50  * eel_gtk_window_get_geometry_string:
51  * @window: a #GtkWindow
52  *
53  * Obtains the geometry string for this window, suitable for
54  * set_geometry_string(); assumes the window has NorthWest gravity
55  *
56  * Return value: geometry string, must be freed
57  **/
58 char *
eel_gtk_window_get_geometry_string(GtkWindow * window)59 eel_gtk_window_get_geometry_string (GtkWindow *window)
60 {
61     char *str;
62     int w, h, x, y;
63 
64     g_return_val_if_fail (GTK_IS_WINDOW (window), NULL);
65     g_return_val_if_fail (gtk_window_get_gravity (window) ==
66                           GDK_GRAVITY_NORTH_WEST, NULL);
67 
68     gtk_window_get_position (window, &x, &y);
69     gtk_window_get_size (window, &w, &h);
70 
71     str = g_strdup_printf ("%dx%d+%d+%d", w, h, x, y);
72 
73     return str;
74 }
75 
76 GtkMenuItem *
eel_gtk_menu_append_separator(GtkMenu * menu)77 eel_gtk_menu_append_separator (GtkMenu *menu)
78 {
79     return eel_gtk_menu_insert_separator (menu, -1);
80 }
81 
82 GtkMenuItem *
eel_gtk_menu_insert_separator(GtkMenu * menu,int index)83 eel_gtk_menu_insert_separator (GtkMenu *menu,
84                                int      index)
85 {
86     GtkWidget *menu_item;
87 
88     menu_item = gtk_separator_menu_item_new ();
89     gtk_widget_show (menu_item);
90     gtk_menu_shell_insert (GTK_MENU_SHELL (menu), menu_item, index);
91 
92     return GTK_MENU_ITEM (menu_item);
93 }
94