Mercurial > pidgin
diff pidgin/gtkstatusbox.c @ 32672:3828a61c44da
A boring and large patch so I can merge heads.
author | Elliott Sales de Andrade <qulogic@pidgin.im> |
---|---|
date | Fri, 23 Dec 2011 08:21:58 +0000 |
parents | e2a1510da13d |
children |
line wrap: on
line diff
--- a/pidgin/gtkstatusbox.c Mon Aug 22 22:46:08 2011 +0000 +++ b/pidgin/gtkstatusbox.c Fri Dec 23 08:21:58 2011 +0000 @@ -70,6 +70,16 @@ /* Timeout for typing notifications in seconds */ #define TYPING_TIMEOUT 4 +#if !GTK_CHECK_VERSION(2,18,0) +#define gtk_widget_is_sensitive(x) GTK_WIDGET_IS_SENSITIVE(x) +#define gtk_widget_set_has_window(x, y) do { \ + if (y) \ + GTK_WIDGET_UNSET_FLAGS(x, GTK_WIDGET_NO_WINDOW); \ + else \ + GTK_WIDGET_SET_FLAGS(x, GTK_WIDGET_NO_WINDOW); \ +} while (0) +#endif + static void imhtml_changed_cb(GtkTextBuffer *buffer, void *data); static void imhtml_format_changed_cb(GtkIMHtml *imhtml, GtkIMHtmlButtons buttons, void *data); static void remove_typing_cb(PidginStatusBox *box); @@ -82,10 +92,9 @@ static void status_menu_refresh_iter(PidginStatusBox *status_box, gboolean status_changed); static void pidgin_status_box_regenerate(PidginStatusBox *status_box, gboolean status_changed); static void pidgin_status_box_changed(PidginStatusBox *box); -static void pidgin_status_box_get_preferred_height (GtkWidget *widget, - gint *minimum_height, gint *natural_height); +static void pidgin_status_box_size_request (GtkWidget *widget, GtkRequisition *requisition); static void pidgin_status_box_size_allocate (GtkWidget *widget, GtkAllocation *allocation); -static gboolean pidgin_status_box_draw (GtkWidget *widget, cairo_t *cr); +static gboolean pidgin_status_box_expose_event (GtkWidget *widget, GdkEventExpose *event); static void pidgin_status_box_redisplay_buddy_icon(PidginStatusBox *status_box); static void pidgin_status_box_forall (GtkContainer *container, gboolean include_internals, GtkCallback callback, gpointer callback_data); static void pidgin_status_box_popup(PidginStatusBox *box); @@ -283,7 +292,7 @@ if (!message || !*message) { - gtk_widget_hide(status_box->vbox); + gtk_widget_hide_all(status_box->vbox); status_box->imhtml_visible = FALSE; } else @@ -344,10 +353,9 @@ icon_box_dnd_cb(GtkWidget *widget, GdkDragContext *dc, gint x, gint y, GtkSelectionData *sd, guint info, guint t, PidginStatusBox *box) { - gchar *name = (gchar *) gtk_selection_data_get_data(sd); - - if ((gtk_selection_data_get_length(sd) >= 0) - && (gtk_selection_data_get_format(sd) == 8)) { + gchar *name = (gchar *)sd->data; + + if ((sd->length >= 0) && (sd->format == 8)) { /* Well, it looks like the drag event was cool. * Let's do something with it */ if (!g_ascii_strncasecmp(name, "file://", 7)) { @@ -414,14 +422,14 @@ if (src == NULL) return FALSE; - purple_util_fetch_url(src, TRUE, NULL, FALSE, statusbox_got_url, data); + purple_util_fetch_url(src, TRUE, NULL, FALSE, -1, statusbox_got_url, data); return TRUE; } static gboolean icon_box_enter_cb(GtkWidget *widget, GdkEventCrossing *event, PidginStatusBox *box) { - gdk_window_set_cursor(gtk_widget_get_window(widget), box->hand_cursor); + gdk_window_set_cursor(widget->window, box->hand_cursor); gtk_image_set_from_pixbuf(GTK_IMAGE(box->icon), box->buddy_icon_hover); return FALSE; } @@ -429,7 +437,7 @@ static gboolean icon_box_leave_cb(GtkWidget *widget, GdkEventCrossing *event, PidginStatusBox *box) { - gdk_window_set_cursor(gtk_widget_get_window(widget), box->arrow_cursor); + gdk_window_set_cursor(widget->window, box->arrow_cursor); gtk_image_set_from_pixbuf(GTK_IMAGE(box->icon), box->buddy_icon) ; return FALSE; } @@ -617,9 +625,9 @@ parent_class = g_type_class_peek_parent(klass); widget_class = (GtkWidgetClass*)klass; - widget_class->get_preferred_height = pidgin_status_box_get_preferred_height; + widget_class->size_request = pidgin_status_box_size_request; widget_class->size_allocate = pidgin_status_box_size_allocate; - widget_class->draw = pidgin_status_box_draw; + widget_class->expose_event = pidgin_status_box_expose_event; container_class->child_type = pidgin_status_box_child_type; container_class->forall = pidgin_status_box_forall; @@ -933,7 +941,7 @@ if (!purple_savedstatus_is_transient(saved_status) || !message || !*message) { status_box->imhtml_visible = FALSE; - gtk_widget_hide(status_box->vbox); + gtk_widget_hide_all(status_box->vbox); } else { @@ -1137,7 +1145,7 @@ static gboolean imhtml_remove_focus(GtkWidget *w, GdkEventKey *event, PidginStatusBox *status_box) { - if (event->keyval == GDK_KEY_Tab || event->keyval == GDK_KEY_KP_Tab || event->keyval == GDK_KEY_ISO_Left_Tab) + if (event->keyval == GDK_Tab || event->keyval == GDK_KP_Tab || event->keyval == GDK_ISO_Left_Tab) { /* If last inserted character is a tab, then remove the focus from here */ GtkWidget *top = gtk_widget_get_toplevel(w); @@ -1150,7 +1158,7 @@ return FALSE; /* Reset the status if Escape was pressed */ - if (event->keyval == GDK_KEY_Escape) + if (event->keyval == GDK_Escape) { purple_timeout_remove(status_box->typing); status_box->typing = 0; @@ -1301,15 +1309,13 @@ GdkRectangle monitor; GtkRequisition popup_req; GtkPolicyType hpolicy, vpolicy; - GtkAllocation allocation; - - gtk_widget_get_allocation(GTK_WIDGET(status_box), &allocation); - gdk_window_get_origin (gtk_widget_get_window(GTK_WIDGET(status_box)), x, y); - - *x += allocation.x; - *y += allocation.y; - - *width = allocation.width; + + gdk_window_get_origin (GTK_WIDGET(status_box)->window, x, y); + + *x += GTK_WIDGET(status_box)->allocation.x; + *y += GTK_WIDGET(status_box)->allocation.y; + + *width = GTK_WIDGET(status_box)->allocation.width; hpolicy = vpolicy = GTK_POLICY_NEVER; g_object_set(G_OBJECT(status_box->scrolled_window), @@ -1332,7 +1338,7 @@ screen = gtk_widget_get_screen (GTK_WIDGET (status_box)); monitor_num = gdk_screen_get_monitor_at_window (screen, - gtk_widget_get_window(GTK_WIDGET (status_box))); + GTK_WIDGET (status_box)->window); gdk_screen_get_monitor_geometry (screen, monitor_num, &monitor); if (*x < monitor.x) @@ -1340,13 +1346,13 @@ else if (*x + *width > monitor.x + monitor.width) *x = monitor.x + monitor.width - *width; - if (*y + allocation.height + *height <= monitor.y + monitor.height) - *y += allocation.height; + if (*y + GTK_WIDGET(status_box)->allocation.height + *height <= monitor.y + monitor.height) + *y += GTK_WIDGET(status_box)->allocation.height; else if (*y - *height >= monitor.y) *y -= *height; - else if (monitor.y + monitor.height - (*y + allocation.height) > *y - monitor.y) + else if (monitor.y + monitor.height - (*y + GTK_WIDGET(status_box)->allocation.height) > *y - monitor.y) { - *y += allocation.height; + *y += GTK_WIDGET(status_box)->allocation.height; *height = monitor.y + monitor.height - *y; } else @@ -1379,7 +1385,7 @@ if (!grab_keyboard || gdk_keyboard_grab (window, TRUE, activate_time) == 0) return TRUE; else { - gdk_display_pointer_ungrab (gdk_window_get_display (window), activate_time); + gdk_display_pointer_ungrab (gdk_drawable_get_display (window), activate_time); return FALSE; } } @@ -1398,7 +1404,7 @@ gtk_window_move (GTK_WINDOW (box->popup_window), x, y); gtk_widget_show(box->popup_window); gtk_widget_grab_focus (box->tree_view); - if (!popup_grab_on_window (gtk_widget_get_window(box->popup_window), + if (!popup_grab_on_window (box->popup_window->window, GDK_CURRENT_TIME, TRUE)) { gtk_widget_hide (box->popup_window); return; @@ -1429,10 +1435,10 @@ toggle_key_press_cb(GtkWidget *widget, GdkEventKey *event, PidginStatusBox *box) { switch (event->keyval) { - case GDK_KEY_Return: - case GDK_KEY_KP_Enter: - case GDK_KEY_KP_Space: - case GDK_KEY_space: + case GDK_Return: + case GDK_KP_Enter: + case GDK_KP_Space: + case GDK_space: if (!box->popup_in_progress) { pidgin_status_box_popup (box); box->popup_in_progress = TRUE; @@ -1664,7 +1670,7 @@ GdkEventKey *event, PidginStatusBox *box) { if (box->popup_in_progress) { - if (event->keyval == GDK_KEY_Escape) { + if (event->keyval == GDK_Escape) { pidgin_status_box_popdown(box); return TRUE; } else { @@ -1675,9 +1681,9 @@ if (gtk_tree_selection_get_selected(sel, NULL, &iter)) { gboolean ret = TRUE; path = gtk_tree_model_get_path(GTK_TREE_MODEL(box->dropdown_store), &iter); - if (event->keyval == GDK_KEY_Return) { + if (event->keyval == GDK_Return) { treeview_activate_current_selection(box, path); - } else if (event->keyval == GDK_KEY_Delete) { + } else if (event->keyval == GDK_Delete) { tree_view_delete_current_selection(box, path); } else ret = FALSE; @@ -1929,27 +1935,24 @@ } static void -pidgin_status_box_get_preferred_height(GtkWidget *widget, gint *minimum_height, - gint *natural_height) +pidgin_status_box_size_request(GtkWidget *widget, + GtkRequisition *requisition) { - gint box_min_height, box_nat_height; - gint border_width = gtk_container_get_border_width(GTK_CONTAINER (widget)); - - gtk_widget_get_preferred_height(PIDGIN_STATUS_BOX(widget)->toggle_button, - minimum_height, natural_height); - - *minimum_height = MAX(*minimum_height, 34) + border_width * 2; - *natural_height = MAX(*natural_height, 34) + border_width * 2; + GtkRequisition box_req; + gint border_width = GTK_CONTAINER (widget)->border_width; + + gtk_widget_size_request(PIDGIN_STATUS_BOX(widget)->toggle_button, requisition); + + /* Make this icon the same size as other buddy icons in the list; unless it already wants to be bigger */ + requisition->height = MAX(requisition->height, 34); + requisition->height += border_width * 2; /* If the gtkimhtml is visible, then add some additional padding */ - gtk_widget_get_preferred_height(PIDGIN_STATUS_BOX(widget)->vbox, - &box_min_height, &box_nat_height); - - if (box_min_height > 1) - *minimum_height += box_min_height + border_width * 2; - - if (box_nat_height > 1) - *natural_height += box_nat_height + border_width * 2; + gtk_widget_size_request(PIDGIN_STATUS_BOX(widget)->vbox, &box_req); + if (box_req.height > 1) + requisition->height += box_req.height + border_width * 2; + + requisition->width = 1; } /* From gnome-panel */ @@ -1997,9 +2000,9 @@ GtkAllocation *allocation) { PidginStatusBox *status_box = PIDGIN_STATUS_BOX(widget); - GtkRequisition req = {0,40}; + GtkRequisition req = {0,0}; GtkAllocation parent_alc, box_alc, icon_alc; - gint border_width = gtk_container_get_border_width(GTK_CONTAINER (widget)); + gint border_width = GTK_CONTAINER (widget)->border_width; gtk_widget_size_request(status_box->toggle_button, &req); /* Make this icon the same size as other buddy icons in the list; unless it already wants to be bigger */ @@ -2038,24 +2041,19 @@ gtk_widget_size_allocate(status_box->icon_box, &icon_alc); } gtk_widget_size_allocate(status_box->toggle_button, &parent_alc); - gtk_widget_set_allocation(GTK_WIDGET(status_box), allocation); - purple_debug_info("pidgin", "statusbox allocation: width = %d, height = %d\n", - allocation->width, allocation->height); + widget->allocation = *allocation; } static gboolean -pidgin_status_box_draw(GtkWidget *widget, cairo_t *cr) +pidgin_status_box_expose_event(GtkWidget *widget, + GdkEventExpose *event) { PidginStatusBox *status_box = PIDGIN_STATUS_BOX(widget); - gtk_widget_draw(status_box->vbox, cr); - gtk_widget_draw(status_box->toggle_button, cr); - + gtk_container_propagate_expose(GTK_CONTAINER(widget), status_box->vbox, event); + gtk_container_propagate_expose(GTK_CONTAINER(widget), status_box->toggle_button, event); if (status_box->icon_box && status_box->icon_opaque) { - GtkAllocation allocation; - - gtk_widget_get_allocation(status_box->icon_box, &allocation); - gtk_paint_box(gtk_widget_get_style(widget), cr, GTK_STATE_NORMAL, GTK_SHADOW_OUT, - status_box->icon_box, "button", allocation.x-1, allocation.y-1, + gtk_paint_box(widget->style, widget->window, GTK_STATE_NORMAL, GTK_SHADOW_OUT, NULL, + status_box->icon_box, "button", status_box->icon_box->allocation.x-1, status_box->icon_box->allocation.y-1, 34, 34); } return FALSE; @@ -2365,7 +2363,7 @@ message = pidgin_status_box_get_message(status_box); if (!message || !*message) { - gtk_widget_hide(status_box->vbox); + gtk_widget_hide_all(status_box->vbox); status_box->imhtml_visible = FALSE; if (message != NULL) { @@ -2637,7 +2635,7 @@ purple_timeout_remove(status_box->typing); status_box->typing = 0; - if (gtk_widget_get_sensitive(GTK_WIDGET(status_box))) + if (gtk_widget_is_sensitive(GTK_WIDGET(status_box))) { if (type == PIDGIN_STATUS_BOX_TYPE_POPULAR || type == PIDGIN_STATUS_BOX_TYPE_SAVED_POPULAR) { @@ -2699,7 +2697,7 @@ } g_list_free(accounts); - if (gtk_widget_get_sensitive(GTK_WIDGET(status_box))) + if (gtk_widget_is_sensitive(GTK_WIDGET(status_box))) { if (status_box->imhtml_visible) { @@ -2719,7 +2717,7 @@ } else { - gtk_widget_hide(status_box->vbox); + gtk_widget_hide_all(status_box->vbox); activate_currently_selected_status(status_box); /* This is where we actually set the status */ } } @@ -2755,7 +2753,7 @@ static void imhtml_changed_cb(GtkTextBuffer *buffer, void *data) { PidginStatusBox *status_box = (PidginStatusBox*)data; - if (gtk_widget_get_sensitive(GTK_WIDGET(status_box))) + if (gtk_widget_is_sensitive(GTK_WIDGET(status_box))) { if (status_box->typing != 0) { pidgin_status_box_pulse_typing(status_box);