Sun, 22 Jul 2007 08:14:16 +0000
revert 'no visible tabs when only one conversation' as it proved unpopular. Made tabs only fill the entire width of the notebook when there's only one tab to avoid http://pidgin.im/~deryni/that_just_looks_dumb.png
| 10298 | 1 | /* |
| 2 | * @file gtkdnd-hints.c GTK+ Drag-and-Drop arrow hints | |
|
16254
eeb2bba4dc94
Rename the Doxygen group from gtkui to pidgin.
Richard Laager <rlaager@pidgin.im>
parents:
15946
diff
changeset
|
3 | * @ingroup pidgin |
| 10298 | 4 | * |
|
15931
716b5fac1895
Re-sed the copyright notices so they don't all talk about Purple.
Richard Laager <rlaager@pidgin.im>
parents:
15884
diff
changeset
|
5 | * pidgin |
| 10298 | 6 | * |
|
15931
716b5fac1895
Re-sed the copyright notices so they don't all talk about Purple.
Richard Laager <rlaager@pidgin.im>
parents:
15884
diff
changeset
|
7 | * Pidgin is the legal property of its developers, whose names are too numerous |
| 10298 | 8 | * to list here. Please refer to the COPYRIGHT file distributed with this |
| 9 | * source distribution. | |
| 10 | * | |
| 11 | * This program is free software; you can redistribute it and/or modify | |
| 12 | * it under the terms of the GNU General Public License as published by | |
| 13 | * the Free Software Foundation; either version 2, or(at your option) | |
| 14 | * any later version. | |
| 15 | * | |
| 16 | * This program is distributed in the hope that it will be useful, | |
| 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 19 | * GNU General Public License for more details. | |
| 20 | * | |
| 21 | * You should have received a copy of the GNU General Public License | |
| 22 | * along with this program; if not, write to the Free Software | |
| 23 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | |
| 24 | */ | |
| 25 | ||
| 26 | #include "gtkdnd-hints.h" | |
| 27 | ||
| 28 | #include <gtk/gtk.h> | |
| 29 | #include <gdk/gdk.h> | |
| 30 | #include <gdk-pixbuf/gdk-pixbuf.h> | |
| 31 | ||
| 32 | #ifdef _WIN32 | |
| 33 | #include "win32dep.h" | |
| 34 | #endif | |
| 35 | ||
| 36 | typedef struct | |
| 37 | { | |
| 38 | GtkWidget *widget; | |
| 39 | gchar *filename; | |
| 40 | gint ox; | |
| 41 | gint oy; | |
| 42 | ||
| 43 | } HintWindowInfo; | |
| 44 | ||
| 45 | /** | |
| 46 | * Info about each hint widget. See DndHintWindowId enum. | |
| 47 | */ | |
|
10871
c0282a4f2250
[gaim-migrate @ 12558]
Mark Doliner <markdoliner@pidgin.im>
parents:
10298
diff
changeset
|
48 | static HintWindowInfo hint_windows[] = { |
|
16274
7d61ad2c489a
Some icon improvements from hbons
Sean Egan <seanegan@pidgin.im>
parents:
16254
diff
changeset
|
49 | { NULL, "arrow-up.xpm", -13/2, 0 }, |
|
7d61ad2c489a
Some icon improvements from hbons
Sean Egan <seanegan@pidgin.im>
parents:
16254
diff
changeset
|
50 | { NULL, "arrow-down.xpm", -13/2, -16 }, |
|
7d61ad2c489a
Some icon improvements from hbons
Sean Egan <seanegan@pidgin.im>
parents:
16254
diff
changeset
|
51 | { NULL, "arrow-left.xpm", 0, -13/2 }, |
|
7d61ad2c489a
Some icon improvements from hbons
Sean Egan <seanegan@pidgin.im>
parents:
16254
diff
changeset
|
52 | { NULL, "arrow-right.xpm", -16, -13/2 }, |
| 10298 | 53 | { NULL, NULL, 0, 0 } |
| 54 | }; | |
| 55 | ||
| 56 | static GtkWidget * | |
| 57 | dnd_hints_init_window(const gchar *fname) | |
| 58 | { | |
| 59 | GdkPixbuf *pixbuf; | |
| 60 | GdkPixmap *pixmap; | |
| 61 | GdkBitmap *bitmap; | |
| 62 | GtkWidget *pix; | |
| 63 | GtkWidget *win; | |
| 64 | ||
| 65 | pixbuf = gdk_pixbuf_new_from_file(fname, NULL); | |
| 66 | g_return_val_if_fail(pixbuf, NULL); | |
| 67 | ||
| 68 | gdk_pixbuf_render_pixmap_and_mask(pixbuf, &pixmap, &bitmap, 128); | |
| 69 | g_object_unref(G_OBJECT(pixbuf)); | |
| 70 | ||
| 71 | gtk_widget_push_colormap(gdk_rgb_get_colormap()); | |
| 72 | win = gtk_window_new(GTK_WINDOW_POPUP); | |
| 73 | pix = gtk_image_new_from_pixmap(pixmap, bitmap); | |
| 74 | gtk_container_add(GTK_CONTAINER(win), pix); | |
| 75 | gtk_widget_shape_combine_mask(win, bitmap, 0, 0); | |
| 76 | gtk_widget_pop_colormap(); | |
| 77 | ||
| 78 | g_object_unref(G_OBJECT(pixmap)); | |
| 79 | g_object_unref(G_OBJECT(bitmap)); | |
| 80 | ||
| 81 | gtk_widget_show_all(pix); | |
| 82 | ||
| 83 | return win; | |
| 84 | } | |
| 85 | ||
| 86 | static void | |
| 87 | get_widget_coords(GtkWidget *w, gint *x1, gint *y1, gint *x2, gint *y2) | |
| 88 | { | |
| 89 | gint ox, oy, width, height; | |
| 90 | ||
| 91 | if (w->parent && w->parent->window == w->window) | |
| 92 | { | |
| 93 | get_widget_coords(w->parent, &ox, &oy, NULL, NULL); | |
| 94 | height = w->allocation.height; | |
| 95 | width = w->allocation.width; | |
| 96 | } | |
| 97 | else | |
| 98 | { | |
| 99 | gdk_window_get_origin(w->window, &ox, &oy); | |
| 100 | gdk_drawable_get_size(w->window, &width, &height); | |
| 101 | } | |
| 102 | ||
| 103 | if (x1) *x1 = ox; | |
| 104 | if (y1) *y1 = oy; | |
| 105 | if (x2) *x2 = ox + width; | |
| 106 | if (y2) *y2 = oy + height; | |
| 107 | } | |
| 108 | ||
| 109 | static void | |
| 110 | dnd_hints_init(void) | |
| 111 | { | |
| 112 | static gboolean done = FALSE; | |
| 113 | gint i; | |
| 114 | ||
| 115 | if (done) | |
| 116 | return; | |
| 117 | ||
| 118 | done = TRUE; | |
| 119 | ||
| 120 | for (i = 0; hint_windows[i].filename != NULL; i++) { | |
| 121 | gchar *fname; | |
| 122 | ||
|
15946
d40e8847e825
More s/gaim/pidgin/ and s/gaim/purple/ and make the RPM spec file work a bit
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
15931
diff
changeset
|
123 | fname = g_build_filename(DATADIR, "pixmaps", "pidgin", |
| 10298 | 124 | hint_windows[i].filename, NULL); |
| 125 | ||
| 126 | hint_windows[i].widget = dnd_hints_init_window(fname); | |
| 127 | ||
| 128 | g_free(fname); | |
| 129 | } | |
| 130 | } | |
| 131 | ||
| 132 | void | |
| 133 | dnd_hints_hide_all(void) | |
| 134 | { | |
| 135 | gint i; | |
| 136 | ||
| 137 | for (i = 0; hint_windows[i].filename != NULL; i++) | |
| 138 | dnd_hints_hide(i); | |
| 139 | } | |
| 140 | ||
| 141 | void | |
| 142 | dnd_hints_hide(DndHintWindowId i) | |
| 143 | { | |
| 144 | GtkWidget *w = hint_windows[i].widget; | |
| 145 | ||
| 146 | if (w && GTK_IS_WIDGET(w)) | |
| 147 | gtk_widget_hide(w); | |
| 148 | } | |
| 149 | ||
| 150 | void | |
| 151 | dnd_hints_show(DndHintWindowId id, gint x, gint y) | |
| 152 | { | |
| 153 | GtkWidget *w; | |
| 154 | ||
| 155 | dnd_hints_init(); | |
| 156 | ||
| 157 | w = hint_windows[id].widget; | |
| 158 | ||
| 159 | if (w && GTK_IS_WIDGET(w)) | |
| 160 | { | |
| 161 | gtk_window_move(GTK_WINDOW(w), hint_windows[id].ox + x, | |
| 162 | hint_windows[id].oy + y); | |
| 163 | gtk_widget_show(w); | |
| 164 | } | |
| 165 | } | |
| 166 | ||
| 167 | void | |
| 168 | dnd_hints_show_relative(DndHintWindowId id, GtkWidget *widget, | |
| 169 | DndHintPosition horiz, DndHintPosition vert) | |
| 170 | { | |
| 171 | gint x1, x2, y1, y2; | |
| 172 | gint x = 0, y = 0; | |
| 173 | ||
| 174 | get_widget_coords(widget, &x1, &y1, &x2, &y2); | |
|
17176
39ea409eb27d
Fix background color issues in the coversation tabs.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
16274
diff
changeset
|
175 | x1 += widget->allocation.x; x2 += widget->allocation.x; |
|
39ea409eb27d
Fix background color issues in the coversation tabs.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
16274
diff
changeset
|
176 | y1 += widget->allocation.y; y2 += widget->allocation.y; |
| 10298 | 177 | |
| 178 | switch (horiz) | |
| 179 | { | |
| 180 | case HINT_POSITION_RIGHT: x = x2; break; | |
| 181 | case HINT_POSITION_LEFT: x = x1; break; | |
| 182 | case HINT_POSITION_CENTER: x = (x1 + x2) / 2; break; | |
| 183 | default: | |
| 184 | /* should not happen */ | |
| 185 | g_warning("Invalid parameter to dnd_hints_show_relative"); | |
| 186 | break; | |
| 187 | } | |
| 188 | ||
| 189 | switch (vert) | |
| 190 | { | |
| 191 | case HINT_POSITION_TOP: y = y1; break; | |
| 192 | case HINT_POSITION_BOTTOM: y = y2; break; | |
| 193 | case HINT_POSITION_CENTER: y = (y1 + y2) / 2; break; | |
| 194 | default: | |
| 195 | /* should not happen */ | |
| 196 | g_warning("Invalid parameter to dnd_hints_show_relative"); | |
| 197 | break; | |
| 198 | } | |
| 199 | ||
| 200 | dnd_hints_show(id, x, y); | |
| 201 | } | |
| 202 |