pidgin/gtkutils.c

branch
next.minor
changeset 22008
f9c24e25b08f
parent 21890
0a56eaa3ae9d
parent 22007
386062b58867
child 22013
1ff155dcd277
equal deleted inserted replaced
21972:e341941eded2 22008:f9c24e25b08f
130 gtk_widget_modify_font(imhtml, desc); 130 gtk_widget_modify_font(imhtml, desc);
131 pango_font_description_free(desc); 131 pango_font_description_free(desc);
132 } 132 }
133 } 133 }
134 134
135 GtkWidget * 135 static
136 pidgin_create_window(const char *title, guint border_width, const char *role, gboolean resizable) 136 void pidgin_window_init(GtkWindow *wnd, const char *title, guint border_width, const char *role, gboolean resizable)
137 { 137 {
138 GtkWindow *wnd = NULL;
139
140 wnd = GTK_WINDOW(gtk_window_new(GTK_WINDOW_TOPLEVEL));
141 if (title) 138 if (title)
142 gtk_window_set_title(wnd, title); 139 gtk_window_set_title(wnd, title);
143 #ifdef _WIN32 140 #ifdef _WIN32
144 else 141 else
145 gtk_window_set_title(wnd, PIDGIN_ALERT_TITLE); 142 gtk_window_set_title(wnd, PIDGIN_ALERT_TITLE);
146 #endif 143 #endif
147 gtk_container_set_border_width(GTK_CONTAINER(wnd), border_width); 144 gtk_container_set_border_width(GTK_CONTAINER(wnd), border_width);
148 if (role) 145 if (role)
149 gtk_window_set_role(wnd, role); 146 gtk_window_set_role(wnd, role);
150 gtk_window_set_resizable(wnd, resizable); 147 gtk_window_set_resizable(wnd, resizable);
148 }
149
150 GtkWidget *
151 pidgin_create_window(const char *title, guint border_width, const char *role, gboolean resizable)
152 {
153 GtkWindow *wnd = NULL;
154
155 wnd = GTK_WINDOW(gtk_window_new(GTK_WINDOW_TOPLEVEL));
156 pidgin_window_init(wnd, title, border_width, role, resizable);
151 157
152 return GTK_WIDGET(wnd); 158 return GTK_WIDGET(wnd);
159 }
160
161 GtkWidget *
162 pidgin_create_dialog(const char *title, guint border_width, const char *role, gboolean resizable)
163 {
164 GtkWindow *wnd = NULL;
165
166 wnd = GTK_WINDOW(gtk_dialog_new());
167 pidgin_window_init(wnd, title, border_width, role, resizable);
168 g_object_set(G_OBJECT(wnd), "has-separator", FALSE, NULL);
169
170 return GTK_WIDGET(wnd);
171 }
172
173 GtkWidget *
174 pidgin_dialog_get_vbox_with_properties(GtkDialog *dialog, gboolean homogeneous, gint spacing)
175 {
176 GtkBox *vbox = GTK_BOX(GTK_DIALOG(dialog)->vbox);
177 gtk_box_set_homogeneous(vbox, homogeneous);
178 gtk_box_set_spacing(vbox, spacing);
179 return GTK_WIDGET(vbox);
180 }
181
182 GtkWidget *pidgin_dialog_get_vbox(GtkDialog *dialog)
183 {
184 return GTK_DIALOG(dialog)->vbox;
185 }
186
187 GtkWidget *pidgin_dialog_get_action_area(GtkDialog *dialog)
188 {
189 return GTK_DIALOG(dialog)->action_area;
190 }
191
192 GtkWidget *pidgin_dialog_add_button(GtkDialog *dialog, const char *label,
193 GCallback callback, gpointer callbackdata)
194 {
195 GtkWidget *button = gtk_button_new_from_stock(label);
196 GtkWidget *bbox = pidgin_dialog_get_action_area(dialog);
197 gtk_box_pack_start(GTK_BOX(bbox), button, FALSE, FALSE, 0);
198 if (callback)
199 g_signal_connect(G_OBJECT(button), "clicked", callback, callbackdata);
200 gtk_widget_show(button);
201 return button;
153 } 202 }
154 203
155 GtkWidget * 204 GtkWidget *
156 pidgin_create_imhtml(gboolean editable, GtkWidget **imhtml_ret, GtkWidget **toolbar_ret, GtkWidget **sw_ret) 205 pidgin_create_imhtml(gboolean editable, GtkWidget **imhtml_ret, GtkWidget **toolbar_ret, GtkWidget **sw_ret)
157 { 206 {
3267 void pidgin_text_combo_box_entry_set_text(GtkWidget *widget, const char *text) 3316 void pidgin_text_combo_box_entry_set_text(GtkWidget *widget, const char *text)
3268 { 3317 {
3269 gtk_entry_set_text(GTK_ENTRY(GTK_BIN((widget))->child), (text)); 3318 gtk_entry_set_text(GTK_ENTRY(GTK_BIN((widget))->child), (text));
3270 } 3319 }
3271 3320
3321 gboolean pidgin_auto_parent_window(GtkWidget *widget)
3322 {
3323 #if 0
3324 /* This looks at the most recent window that received focus, and makes
3325 * that the parent window. */
3326 #ifndef _WIN32
3327 static GdkAtom _WindowTime = GDK_NONE;
3328 static GdkAtom _Cardinal = GDK_NONE;
3329 GList *windows = NULL;
3330 GtkWidget *parent = NULL;
3331 time_t window_time = 0;
3332
3333 windows = gtk_window_list_toplevels();
3334
3335 if (_WindowTime == GDK_NONE) {
3336 _WindowTime = gdk_x11_xatom_to_atom(gdk_x11_get_xatom_by_name("_NET_WM_USER_TIME"));
3337 }
3338 if (_Cardinal == GDK_NONE) {
3339 _Cardinal = gdk_atom_intern("CARDINAL", FALSE);
3340 }
3341
3342 while (windows) {
3343 GtkWidget *window = windows->data;
3344 guchar *data = NULL;
3345 int al = 0;
3346 time_t value;
3347
3348 windows = g_list_delete_link(windows, windows);
3349
3350 if (window == widget ||
3351 !GTK_WIDGET_VISIBLE(window))
3352 continue;
3353
3354 if (!gdk_property_get(window->window, _WindowTime, _Cardinal, 0, sizeof(time_t), FALSE,
3355 NULL, NULL, &al, &data))
3356 continue;
3357 value = *(time_t *)data;
3358 if (window_time < value) {
3359 window_time = value;
3360 parent = window;
3361 }
3362 g_free(data);
3363 }
3364 if (windows)
3365 g_list_free(windows);
3366 if (parent) {
3367 if (!gtk_get_current_event() && gtk_window_has_toplevel_focus(GTK_WINDOW(parent))) {
3368 /* The window is in focus, and the new window was not triggered by a keypress/click
3369 * event. So do not set it transient, to avoid focus stealing and all that.
3370 */
3371 return FALSE;
3372 }
3373 gtk_window_set_transient_for(GTK_WINDOW(widget), GTK_WINDOW(parent));
3374 return TRUE;
3375 }
3376 return FALSE;
3377 #endif
3378 #else
3379 /* This finds the currently active window and makes that the parent window. */
3380 GList *windows = NULL;
3381 GtkWidget *parent = NULL;
3382 GdkEvent *event = gtk_get_current_event();
3383 GdkWindow *menu = NULL;
3384
3385 if (event == NULL)
3386 /* The window was not triggered by a user action. */
3387 return FALSE;
3388
3389 /* We need to special case events from a popup menu. */
3390 if (event->type == GDK_BUTTON_RELEASE) {
3391 /* XXX: Neither of the following works:
3392 menu = event->button.window;
3393 menu = gdk_window_get_parent(event->button.window);
3394 menu = gdk_window_get_toplevel(event->button.window);
3395 */
3396 } else if (event->type == GDK_KEY_PRESS)
3397 menu = event->key.window;
3398
3399 windows = gtk_window_list_toplevels();
3400 while (windows) {
3401 GtkWidget *window = windows->data;
3402 windows = g_list_delete_link(windows, windows);
3403
3404 if (window == widget ||
3405 !GTK_WIDGET_VISIBLE(window)) {
3406 continue;
3407 }
3408
3409 if (gtk_window_has_toplevel_focus(GTK_WINDOW(window)) ||
3410 (menu && menu == window->window)) {
3411 parent = window;
3412 break;
3413 }
3414 }
3415 if (windows)
3416 g_list_free(windows);
3417 if (parent) {
3418 gtk_window_set_transient_for(GTK_WINDOW(widget), GTK_WINDOW(parent));
3419 return TRUE;
3420 }
3421 return FALSE;
3422 #endif
3423 }
3424

mercurial