*/
#include "config.h"
-#include <string.h>
+
#include "gtkpathbar.h"
+
+#include <string.h>
+
#include "gtktogglebutton.h"
#include "gtkalignment.h"
#include "gtkarrow.h"
static void gtk_path_bar_dispose (GObject *object);
static void gtk_path_bar_realize (GtkWidget *widget);
static void gtk_path_bar_unrealize (GtkWidget *widget);
-static void gtk_path_bar_size_request (GtkWidget *widget,
- GtkRequisition *requisition);
+static void gtk_path_bar_get_preferred_width (GtkWidget *widget,
+ gint *minimum,
+ gint *natural);
+static void gtk_path_bar_get_preferred_height (GtkWidget *widget,
+ gint *minimum,
+ gint *natural);
static void gtk_path_bar_map (GtkWidget *widget);
static void gtk_path_bar_unmap (GtkWidget *widget);
static void gtk_path_bar_size_allocate (GtkWidget *widget,
gtk_path_bar_class_init (GtkPathBarClass *path_bar_class)
{
GObjectClass *gobject_class;
- GtkObjectClass *object_class;
GtkWidgetClass *widget_class;
GtkContainerClass *container_class;
gobject_class = (GObjectClass *) path_bar_class;
- object_class = (GtkObjectClass *) path_bar_class;
widget_class = (GtkWidgetClass *) path_bar_class;
container_class = (GtkContainerClass *) path_bar_class;
gobject_class->finalize = gtk_path_bar_finalize;
gobject_class->dispose = gtk_path_bar_dispose;
- widget_class->size_request = gtk_path_bar_size_request;
+ widget_class->get_preferred_width = gtk_path_bar_get_preferred_width;
+ widget_class->get_preferred_height = gtk_path_bar_get_preferred_height;
widget_class->realize = gtk_path_bar_realize;
widget_class->unrealize = gtk_path_bar_unrealize;
widget_class->map = gtk_path_bar_map;
container_class->add = gtk_path_bar_add;
container_class->forall = gtk_path_bar_forall;
container_class->remove = gtk_path_bar_remove;
+ gtk_container_class_handle_border_width (container_class);
/* FIXME: */
/* container_class->child_type = gtk_path_bar_child_type;*/
path_bar_signals [PATH_CLICKED] =
g_signal_new (I_("path-clicked"),
- G_OBJECT_CLASS_TYPE (object_class),
+ G_OBJECT_CLASS_TYPE (gobject_class),
G_SIGNAL_RUN_FIRST,
G_STRUCT_OFFSET (GtkPathBarClass, path_clicked),
NULL, NULL,
* available space.
*/
static void
-gtk_path_bar_size_request (GtkWidget *widget,
- GtkRequisition *requisition)
+gtk_path_bar_get_preferred_width (GtkWidget *widget,
+ gint *minimum,
+ gint *natural)
{
ButtonData *button_data;
GtkPathBar *path_bar;
- GtkRequisition child_requisition;
GList *list;
- guint border_width;
+ gint child_height;
+ gint height;
+ gint child_min, child_nat;
path_bar = GTK_PATH_BAR (widget);
- requisition->width = 0;
- requisition->height = 0;
+ *minimum = *natural = 0;
+ height = 0;
for (list = path_bar->button_list; list; list = list->next)
{
button_data = BUTTON_DATA (list->data);
- gtk_widget_size_request (button_data->button, &child_requisition);
-
+ gtk_widget_get_preferred_width (button_data->button, &child_min, &child_nat);
+ gtk_widget_get_preferred_height (button_data->button, &child_height, NULL);
+ height = MAX (height, child_height);
+
if (button_data->type == NORMAL_BUTTON)
- /* Use 2*Height as button width because of ellipsized label. */
- requisition->width = MAX (child_requisition.height * 2, requisition->width);
- else
- requisition->width = MAX (child_requisition.width, requisition->width);
+ {
+ /* Use 2*Height as button width because of ellipsized label. */
+ child_min = MAX (child_min, child_height * 2);
+ child_nat = MAX (child_min, child_height * 2);
+ }
- requisition->height = MAX (child_requisition.height, requisition->height);
+ *minimum = MAX (*minimum, child_min);
+ *natural = MAX (*natural, child_nat);
}
/* Add space for slider, if we have more than one path */
/* Theoretically, the slider could be bigger than the other button. But we're
* not going to worry about that now.
*/
- path_bar->slider_width = MIN(requisition->height * 2 / 3 + 5, requisition->height);
+ path_bar->slider_width = MIN (height * 2 / 3 + 5, height);
if (path_bar->button_list && path_bar->button_list->next != NULL)
- requisition->width += (path_bar->spacing + path_bar->slider_width) * 2;
+ {
+ *minimum += (path_bar->spacing + path_bar->slider_width) * 2;
+ *natural += (path_bar->spacing + path_bar->slider_width) * 2;
+ }
+}
+
+static void
+gtk_path_bar_get_preferred_height (GtkWidget *widget,
+ gint *minimum,
+ gint *natural)
+{
+ ButtonData *button_data;
+ GtkPathBar *path_bar;
+ GList *list;
+ gint child_min, child_nat;
+
+ path_bar = GTK_PATH_BAR (widget);
- gtk_widget_size_request (path_bar->up_slider_button, &child_requisition);
- gtk_widget_size_request (path_bar->down_slider_button, &child_requisition);
+ *minimum = *natural = 0;
- border_width = gtk_container_get_border_width (GTK_CONTAINER (widget));
- requisition->width += border_width * 2;
- requisition->height += border_width * 2;
+ for (list = path_bar->button_list; list; list = list->next)
+ {
+ button_data = BUTTON_DATA (list->data);
+ gtk_widget_get_preferred_height (button_data->button, &child_min, &child_nat);
- widget->requisition = *requisition;
+ *minimum = MAX (*minimum, child_min);
+ *natural = MAX (*natural, child_nat);
+ }
}
static void
gtk_path_bar_realize (GtkWidget *widget)
{
GtkPathBar *path_bar;
+ GtkAllocation allocation;
+ GdkWindow *window;
GdkWindowAttr attributes;
gint attributes_mask;
gtk_widget_set_realized (widget, TRUE);
path_bar = GTK_PATH_BAR (widget);
- widget->window = gtk_widget_get_parent_window (widget);
- g_object_ref (widget->window);
+ window = gtk_widget_get_parent_window (widget);
+ gtk_widget_set_window (widget, window);
+ g_object_ref (window);
+
+ gtk_widget_get_allocation (widget, &allocation);
attributes.window_type = GDK_WINDOW_CHILD;
- attributes.x = widget->allocation.x;
- attributes.y = widget->allocation.y;
- attributes.width = widget->allocation.width;
- attributes.height = widget->allocation.height;
+ attributes.x = allocation.x;
+ attributes.y = allocation.y;
+ attributes.width = allocation.width;
+ attributes.height = allocation.height;
attributes.wclass = GDK_INPUT_ONLY;
attributes.event_mask = gtk_widget_get_events (widget);
attributes.event_mask |= GDK_SCROLL_MASK;
attributes_mask = GDK_WA_X | GDK_WA_Y;
path_bar->event_window = gdk_window_new (gtk_widget_get_parent_window (widget),
- &attributes, attributes_mask);
+ &attributes, attributes_mask);
gdk_window_set_user_data (path_bar->event_window, widget);
- widget->style = gtk_style_attach (widget->style, widget->window);
+ gtk_widget_style_attach (widget);
}
static void
GList *list, *first_button;
gint width;
gint allocation_width;
- guint border_width;
gboolean need_sliders = FALSE;
gint up_slider_offset = 0;
GtkRequisition child_requisition;
- widget->allocation = *allocation;
+ gtk_widget_set_allocation (widget, allocation);
if (gtk_widget_get_realized (widget))
gdk_window_move_resize (path_bar->event_window,
return;
direction = gtk_widget_get_direction (widget);
- border_width = gtk_container_get_border_width (GTK_CONTAINER (path_bar));
- allocation_width = allocation->width - 2 * border_width;
+ allocation_width = allocation->width;
/* First, we check to see if we need the scrollbars. */
if (path_bar->fake_root)
{
child = BUTTON_DATA (list->data)->button;
- gtk_widget_get_child_requisition (child, &child_requisition);
+ gtk_widget_get_preferred_size (child, &child_requisition, NULL);
width += child_requisition.width + path_bar->spacing;
if (list == path_bar->fake_root)
* button, then count backwards.
*/
/* Count down the path chain towards the end. */
- gtk_widget_get_child_requisition (BUTTON_DATA (first_button->data)->button, &child_requisition);
+ gtk_widget_get_preferred_size (BUTTON_DATA (first_button->data)->button,
+ &child_requisition, NULL);
width = child_requisition.width;
list = first_button->prev;
{
child = BUTTON_DATA (list->data)->button;
- gtk_widget_get_child_requisition (child, &child_requisition);
+ gtk_widget_get_preferred_size (child, &child_requisition, NULL);
if (width + child_requisition.width +
path_bar->spacing + slider_space > allocation_width)
{
child = BUTTON_DATA (first_button->next->data)->button;
- gtk_widget_get_child_requisition (child, &child_requisition);
+ gtk_widget_get_preferred_size (child, &child_requisition, NULL);
if (width + child_requisition.width + path_bar->spacing + slider_space > allocation_width)
{
}
/* Now, we allocate space to the buttons */
- child_allocation.y = allocation->y + border_width;
- child_allocation.height = MAX (1, (gint) allocation->height - border_width * 2);
+ child_allocation.y = allocation->y;
+ child_allocation.height = allocation->height;
if (direction == GTK_TEXT_DIR_RTL)
{
- child_allocation.x = allocation->x + allocation->width - border_width;
+ child_allocation.x = allocation->x + allocation->width;
if (need_sliders || path_bar->fake_root)
{
child_allocation.x -= (path_bar->spacing + path_bar->slider_width);
- up_slider_offset = allocation->width - border_width - path_bar->slider_width;
+ up_slider_offset = allocation->width - path_bar->slider_width;
}
}
else
{
- child_allocation.x = allocation->x + border_width;
+ child_allocation.x = allocation->x;
if (need_sliders || path_bar->fake_root)
{
- up_slider_offset = border_width;
+ up_slider_offset = 0;
child_allocation.x += (path_bar->spacing + path_bar->slider_width);
}
}
for (list = first_button; list; list = list->prev)
{
+ GtkAllocation widget_allocation;
ButtonData *button_data;
button_data = BUTTON_DATA (list->data);
child = button_data->button;
- gtk_widget_get_child_requisition (child, &child_requisition);
+ gtk_widget_get_preferred_size (child, &child_requisition, NULL);
child_allocation.width = MIN (child_requisition.width,
allocation_width - (path_bar->spacing + path_bar->slider_width) * 2);
/* Check to see if we've don't have any more space to allocate buttons */
if (need_sliders && direction == GTK_TEXT_DIR_RTL)
{
- if (child_allocation.x - path_bar->spacing - path_bar->slider_width < widget->allocation.x + border_width)
+ gtk_widget_get_allocation (widget, &widget_allocation);
+ if (child_allocation.x - path_bar->spacing - path_bar->slider_width < widget_allocation.x)
break;
}
else if (need_sliders && direction == GTK_TEXT_DIR_LTR)
{
+ gtk_widget_get_allocation (widget, &widget_allocation);
if (child_allocation.x + child_allocation.width + path_bar->spacing + path_bar->slider_width >
- widget->allocation.x + border_width + allocation_width)
+ widget_allocation.x + allocation_width)
break;
}
child_allocation.width = path_bar->slider_width;
if (direction == GTK_TEXT_DIR_RTL)
- child_allocation.x = border_width;
+ child_allocation.x = 0;
else
- child_allocation.x = allocation->width - border_width - path_bar->slider_width;
+ child_allocation.x = allocation->width - path_bar->slider_width;
child_allocation.x += allocation->x;
static void
gtk_path_bar_scroll_down (GtkPathBar *path_bar)
{
+ GtkAllocation allocation, button_allocation;
GList *list;
GList *down_button = NULL;
gint space_available;
}
}
- space_available = (GTK_WIDGET (path_bar)->allocation.width
- - 2 * gtk_container_get_border_width (GTK_CONTAINER (path_bar))
+ gtk_widget_get_allocation (GTK_WIDGET (path_bar), &allocation);
+ gtk_widget_get_allocation (BUTTON_DATA (down_button->data)->button, &button_allocation);
+
+ space_available = (allocation.width
- 2 * path_bar->spacing - 2 * path_bar->slider_width
- - BUTTON_DATA (down_button->data)->button->allocation.width);
+ - button_allocation.width);
path_bar->first_scrolled_button = down_button;
/* We have space_available free space that's not being used.
down_button = down_button->next;
if (!down_button)
break;
- space_available -= (BUTTON_DATA (down_button->data)->button->allocation.width
+ space_available -= (button_allocation.width
+ path_bar->spacing);
}
}
if (button_data->ignore_changes)
return;
- path_bar = GTK_PATH_BAR (button->parent);
+ path_bar = GTK_PATH_BAR (gtk_widget_get_parent (button));
button_list = g_list_find (path_bar->button_list, button_data);
g_assert (button_list != NULL);
* or not the contents are bold
*/
static void
-label_size_request_cb (GtkWidget *widget,
- GtkRequisition *requisition,
- ButtonData *button_data)
+set_label_size_request (GtkWidget *alignment,
+ ButtonData *button_data)
{
const gchar *dir_name = get_dir_name (button_data);
PangoLayout *layout = gtk_widget_create_pango_layout (button_data->label, dir_name);
- gint bold_width, bold_height;
+ gint width, height, bold_width, bold_height;
gchar *markup;
-
- pango_layout_get_pixel_size (layout, &requisition->width, &requisition->height);
+
+ pango_layout_get_pixel_size (layout, &width, &height);
markup = g_markup_printf_escaped ("<b>%s</b>", dir_name);
pango_layout_set_markup (layout, markup, -1);
g_free (markup);
pango_layout_get_pixel_size (layout, &bold_width, &bold_height);
- requisition->width = MAX (requisition->width, bold_width);
- requisition->height = MAX (requisition->height, bold_height);
-
+
+ gtk_widget_set_size_request (alignment,
+ MAX (width, bold_width),
+ MAX (height, bold_height));
g_object_unref (layout);
}
char *uris[2];
button_data = data;
- path_bar = GTK_PATH_BAR (widget->parent); /* the button's parent *is* the path bar */
+ path_bar = GTK_PATH_BAR (gtk_widget_get_parent (widget)); /* the button's parent *is* the path bar */
uris[0] = g_file_get_uri (button_data->file);
uris[1] = NULL;
button_data->label = gtk_label_new (NULL);
label_alignment = gtk_alignment_new (0.5, 0.5, 1.0, 1.0);
gtk_container_add (GTK_CONTAINER (label_alignment), button_data->label);
- child = gtk_hbox_new (FALSE, 2);
+ child = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, FALSE, 2);
gtk_box_pack_start (GTK_BOX (child), button_data->image, FALSE, FALSE, 0);
gtk_box_pack_start (GTK_BOX (child), label_alignment, FALSE, FALSE, 0);
break;
button_data->image = NULL;
}
- /* label_alignment is created because we can't override size-request
- * on label itself and still have the contents of the label centered
- * properly in the label's requisition
- */
- if (label_alignment)
- g_signal_connect (label_alignment, "size-request",
- G_CALLBACK (label_size_request_cb), button_data);
-
button_data->dir_name = g_strdup (dir_name);
button_data->file = g_object_ref (file);
button_data->file_is_hidden = file_is_hidden;
+ /* FIXME: Maybe we dont need this alignment at all and we can
+ * use GtkMisc aligments or even GtkWidget:halign/valign center.
+ *
+ * The following function ensures that the alignment will always
+ * request the same size whether the button's text is bold or not.
+ */
+ if (label_alignment)
+ set_label_size_request (label_alignment, button_data);
+
gtk_container_add (GTK_CONTAINER (button_data->button), child);
gtk_widget_show_all (button_data->button);