forked from AuroraMiddleware/gtk
gtk/gtktoolbar.c: use accessor functions to access GtkWidget
This commit is contained in:
parent
7e753a9a86
commit
7fd15c82bf
175
gtk/gtktoolbar.c
175
gtk/gtktoolbar.c
@ -755,22 +755,25 @@ gtk_toolbar_unmap (GtkWidget *widget)
|
||||
static void
|
||||
gtk_toolbar_realize (GtkWidget *widget)
|
||||
{
|
||||
GtkAllocation allocation;
|
||||
GtkToolbar *toolbar = GTK_TOOLBAR (widget);
|
||||
GtkToolbarPriv *priv = toolbar->priv;
|
||||
GdkWindow *window;
|
||||
GdkWindowAttr attributes;
|
||||
gint attributes_mask;
|
||||
guint border_width;
|
||||
|
||||
gtk_widget_set_realized (widget, TRUE);
|
||||
|
||||
gtk_widget_get_allocation (widget, &allocation);
|
||||
border_width = gtk_container_get_border_width (GTK_CONTAINER (widget));
|
||||
|
||||
attributes.wclass = GDK_INPUT_ONLY;
|
||||
attributes.window_type = GDK_WINDOW_CHILD;
|
||||
attributes.x = widget->allocation.x + border_width;
|
||||
attributes.y = widget->allocation.y + border_width;
|
||||
attributes.width = widget->allocation.width - border_width * 2;
|
||||
attributes.height = widget->allocation.height - border_width * 2;
|
||||
attributes.x = allocation.x + border_width;
|
||||
attributes.y = allocation.y + border_width;
|
||||
attributes.width = allocation.width - border_width * 2;
|
||||
attributes.height = allocation.height - border_width * 2;
|
||||
attributes.event_mask = gtk_widget_get_events (widget);
|
||||
attributes.event_mask |= (GDK_BUTTON_PRESS_MASK |
|
||||
GDK_BUTTON_RELEASE_MASK |
|
||||
@ -779,9 +782,11 @@ gtk_toolbar_realize (GtkWidget *widget)
|
||||
|
||||
attributes_mask = GDK_WA_X | GDK_WA_Y;
|
||||
|
||||
widget->window = gtk_widget_get_parent_window (widget);
|
||||
g_object_ref (widget->window);
|
||||
widget->style = gtk_style_attach (widget->style, widget->window);
|
||||
window = gtk_widget_get_parent_window (widget);
|
||||
gtk_widget_set_window (widget, window);
|
||||
g_object_ref (window);
|
||||
|
||||
gtk_widget_style_attach (widget);
|
||||
|
||||
priv->event_window = gdk_window_new (gtk_widget_get_parent_window (widget),
|
||||
&attributes, attributes_mask);
|
||||
@ -808,9 +813,9 @@ static gint
|
||||
gtk_toolbar_expose (GtkWidget *widget,
|
||||
GdkEventExpose *event)
|
||||
{
|
||||
GtkAllocation allocation;
|
||||
GtkToolbar *toolbar = GTK_TOOLBAR (widget);
|
||||
GtkToolbarPriv *priv = toolbar->priv;
|
||||
|
||||
GList *list;
|
||||
guint border_width;
|
||||
|
||||
@ -818,15 +823,16 @@ gtk_toolbar_expose (GtkWidget *widget,
|
||||
|
||||
if (gtk_widget_is_drawable (widget))
|
||||
{
|
||||
gtk_paint_box (widget->style,
|
||||
widget->window,
|
||||
gtk_widget_get_allocation (widget, &allocation);
|
||||
gtk_paint_box (gtk_widget_get_style (widget),
|
||||
gtk_widget_get_window (widget),
|
||||
gtk_widget_get_state (widget),
|
||||
get_shadow_type (toolbar),
|
||||
&event->area, widget, "toolbar",
|
||||
border_width + widget->allocation.x,
|
||||
border_width + widget->allocation.y,
|
||||
widget->allocation.width - 2 * border_width,
|
||||
widget->allocation.height - 2 * border_width);
|
||||
border_width + allocation.x,
|
||||
border_width + allocation.y,
|
||||
allocation.width - 2 * border_width,
|
||||
allocation.height - 2 * border_width);
|
||||
}
|
||||
|
||||
for (list = priv->content; list != NULL; list = list->next)
|
||||
@ -960,8 +966,11 @@ gtk_toolbar_size_request (GtkWidget *widget,
|
||||
|
||||
if (get_shadow_type (toolbar) != GTK_SHADOW_NONE)
|
||||
{
|
||||
requisition->width += 2 * widget->style->xthickness;
|
||||
requisition->height += 2 * widget->style->ythickness;
|
||||
GtkStyle *style;
|
||||
|
||||
style = gtk_widget_get_style (widget);
|
||||
requisition->width += 2 * style->xthickness;
|
||||
requisition->height += 2 * style->ythickness;
|
||||
}
|
||||
|
||||
priv->button_maxw = max_homogeneous_child_width;
|
||||
@ -1163,8 +1172,10 @@ rect_within (GtkAllocation *a1,
|
||||
static void
|
||||
gtk_toolbar_begin_sliding (GtkToolbar *toolbar)
|
||||
{
|
||||
GtkAllocation allocation;
|
||||
GtkWidget *widget = GTK_WIDGET (toolbar);
|
||||
GtkToolbarPriv *priv = toolbar->priv;
|
||||
GtkStyle *style;
|
||||
GList *list;
|
||||
gint cur_x;
|
||||
gint cur_y;
|
||||
@ -1184,25 +1195,28 @@ gtk_toolbar_begin_sliding (GtkToolbar *toolbar)
|
||||
|
||||
if (!priv->idle_id)
|
||||
priv->idle_id = gdk_threads_add_idle (slide_idle_handler, toolbar);
|
||||
|
||||
|
||||
gtk_widget_get_allocation (widget, &allocation);
|
||||
style = gtk_widget_get_style (widget);
|
||||
|
||||
rtl = (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL);
|
||||
vertical = (priv->orientation == GTK_ORIENTATION_VERTICAL);
|
||||
border_width = get_internal_padding (toolbar) + gtk_container_get_border_width (GTK_CONTAINER (toolbar));
|
||||
|
||||
if (rtl)
|
||||
{
|
||||
cur_x = widget->allocation.width - border_width - widget->style->xthickness;
|
||||
cur_y = widget->allocation.height - border_width - widget->style->ythickness;
|
||||
cur_x = allocation.width - border_width - style->xthickness;
|
||||
cur_y = allocation.height - border_width - style->ythickness;
|
||||
}
|
||||
else
|
||||
{
|
||||
cur_x = border_width + widget->style->xthickness;
|
||||
cur_y = border_width + widget->style->ythickness;
|
||||
cur_x = border_width + style->xthickness;
|
||||
cur_y = border_width + style->ythickness;
|
||||
}
|
||||
|
||||
cur_x += widget->allocation.x;
|
||||
cur_y += widget->allocation.y;
|
||||
|
||||
|
||||
cur_x += allocation.x;
|
||||
cur_y += allocation.y;
|
||||
|
||||
for (list = priv->content; list != NULL; list = list->next)
|
||||
{
|
||||
ToolbarContent *content = list->data;
|
||||
@ -1214,7 +1228,7 @@ gtk_toolbar_begin_sliding (GtkToolbar *toolbar)
|
||||
toolbar_content_get_allocation (content, &item_allocation);
|
||||
|
||||
if ((state == NORMAL &&
|
||||
rect_within (&item_allocation, &(widget->allocation))) ||
|
||||
rect_within (&item_allocation, &allocation)) ||
|
||||
state == OVERFLOWN)
|
||||
{
|
||||
new_start_allocation = item_allocation;
|
||||
@ -1226,15 +1240,15 @@ gtk_toolbar_begin_sliding (GtkToolbar *toolbar)
|
||||
|
||||
if (vertical)
|
||||
{
|
||||
new_start_allocation.width = widget->allocation.width -
|
||||
2 * border_width - 2 * widget->style->xthickness;
|
||||
new_start_allocation.width = allocation.width -
|
||||
2 * border_width - 2 * style->xthickness;
|
||||
new_start_allocation.height = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
new_start_allocation.width = 0;
|
||||
new_start_allocation.height = widget->allocation.height -
|
||||
2 * border_width - 2 * widget->style->ythickness;
|
||||
new_start_allocation.height = allocation.height -
|
||||
2 * border_width - 2 * style->ythickness;
|
||||
}
|
||||
}
|
||||
|
||||
@ -1295,7 +1309,8 @@ static void
|
||||
remove_item (GtkWidget *menu_item,
|
||||
gpointer data)
|
||||
{
|
||||
gtk_container_remove (GTK_CONTAINER (menu_item->parent), menu_item);
|
||||
gtk_container_remove (GTK_CONTAINER (gtk_widget_get_parent (menu_item)),
|
||||
menu_item);
|
||||
}
|
||||
|
||||
static void
|
||||
@ -1386,11 +1401,13 @@ static void
|
||||
gtk_toolbar_size_allocate (GtkWidget *widget,
|
||||
GtkAllocation *allocation)
|
||||
{
|
||||
GtkAllocation widget_allocation;
|
||||
GtkToolbar *toolbar = GTK_TOOLBAR (widget);
|
||||
GtkToolbarPriv *priv = toolbar->priv;
|
||||
GtkAllocation *allocations;
|
||||
ItemState *new_states;
|
||||
GtkAllocation arrow_allocation;
|
||||
GtkStyle *style;
|
||||
gint arrow_size;
|
||||
gint size, pos, short_size;
|
||||
GList *list;
|
||||
@ -1407,20 +1424,23 @@ gtk_toolbar_size_allocate (GtkWidget *widget,
|
||||
gdouble elapsed;
|
||||
GtkAllocation item_area;
|
||||
GtkShadowType shadow_type;
|
||||
|
||||
|
||||
style = gtk_widget_get_style (widget);
|
||||
|
||||
gtk_widget_get_allocation (widget, &widget_allocation);
|
||||
size_changed = FALSE;
|
||||
if (widget->allocation.x != allocation->x ||
|
||||
widget->allocation.y != allocation->y ||
|
||||
widget->allocation.width != allocation->width ||
|
||||
widget->allocation.height != allocation->height)
|
||||
if (widget_allocation.x != allocation->x ||
|
||||
widget_allocation.y != allocation->y ||
|
||||
widget_allocation.width != allocation->width ||
|
||||
widget_allocation.height != allocation->height)
|
||||
{
|
||||
size_changed = TRUE;
|
||||
}
|
||||
|
||||
if (size_changed)
|
||||
gtk_toolbar_stop_sliding (toolbar);
|
||||
|
||||
widget->allocation = *allocation;
|
||||
|
||||
gtk_widget_set_allocation (widget, allocation);
|
||||
|
||||
border_width = gtk_container_get_border_width (GTK_CONTAINER (toolbar));
|
||||
|
||||
@ -1448,8 +1468,8 @@ gtk_toolbar_size_allocate (GtkWidget *widget,
|
||||
|
||||
if (shadow_type != GTK_SHADOW_NONE)
|
||||
{
|
||||
available_size -= 2 * widget->style->xthickness;
|
||||
short_size -= 2 * widget->style->ythickness;
|
||||
available_size -= 2 * style->xthickness;
|
||||
short_size -= 2 * style->ythickness;
|
||||
}
|
||||
}
|
||||
else
|
||||
@ -1460,8 +1480,8 @@ gtk_toolbar_size_allocate (GtkWidget *widget,
|
||||
|
||||
if (shadow_type != GTK_SHADOW_NONE)
|
||||
{
|
||||
available_size -= 2 * widget->style->ythickness;
|
||||
short_size -= 2 * widget->style->xthickness;
|
||||
available_size -= 2 * style->ythickness;
|
||||
short_size -= 2 * style->xthickness;
|
||||
}
|
||||
}
|
||||
|
||||
@ -1637,8 +1657,8 @@ gtk_toolbar_size_allocate (GtkWidget *widget,
|
||||
|
||||
if (shadow_type != GTK_SHADOW_NONE)
|
||||
{
|
||||
allocations[i].x += widget->style->xthickness;
|
||||
allocations[i].y += widget->style->ythickness;
|
||||
allocations[i].x += style->xthickness;
|
||||
allocations[i].y += style->ythickness;
|
||||
}
|
||||
}
|
||||
|
||||
@ -1649,8 +1669,8 @@ gtk_toolbar_size_allocate (GtkWidget *widget,
|
||||
|
||||
if (shadow_type != GTK_SHADOW_NONE)
|
||||
{
|
||||
arrow_allocation.x += widget->style->xthickness;
|
||||
arrow_allocation.y += widget->style->ythickness;
|
||||
arrow_allocation.x += style->xthickness;
|
||||
arrow_allocation.y += style->ythickness;
|
||||
}
|
||||
}
|
||||
|
||||
@ -1658,8 +1678,8 @@ gtk_toolbar_size_allocate (GtkWidget *widget,
|
||||
item_area.y += allocation->y;
|
||||
if (shadow_type != GTK_SHADOW_NONE)
|
||||
{
|
||||
item_area.x += widget->style->xthickness;
|
||||
item_area.y += widget->style->ythickness;
|
||||
item_area.x += style->xthickness;
|
||||
item_area.y += style->ythickness;
|
||||
}
|
||||
|
||||
/* did anything change? */
|
||||
@ -1789,8 +1809,10 @@ gtk_toolbar_style_set (GtkWidget *widget,
|
||||
priv->max_homogeneous_pixels = -1;
|
||||
|
||||
if (gtk_widget_get_realized (widget))
|
||||
gtk_style_set_background (widget->style, widget->window, widget->state);
|
||||
|
||||
gtk_style_set_background (gtk_widget_get_style (widget),
|
||||
gtk_widget_get_window (widget),
|
||||
gtk_widget_get_state (widget));
|
||||
|
||||
if (prev_style)
|
||||
gtk_toolbar_update_button_relief (GTK_TOOLBAR (widget));
|
||||
}
|
||||
@ -2558,6 +2580,7 @@ menu_position_func (GtkMenu *menu,
|
||||
gboolean *push_in,
|
||||
gpointer user_data)
|
||||
{
|
||||
GtkAllocation allocation;
|
||||
GtkToolbar *toolbar = GTK_TOOLBAR (user_data);
|
||||
GtkToolbarPriv *priv = toolbar->priv;
|
||||
GtkRequisition req;
|
||||
@ -2570,38 +2593,41 @@ menu_position_func (GtkMenu *menu,
|
||||
gtk_widget_size_request (GTK_WIDGET (menu), &menu_req);
|
||||
|
||||
screen = gtk_widget_get_screen (GTK_WIDGET (menu));
|
||||
monitor_num = gdk_screen_get_monitor_at_window (screen, priv->arrow_button->window);
|
||||
monitor_num = gdk_screen_get_monitor_at_window (screen,
|
||||
gtk_widget_get_window (priv->arrow_button));
|
||||
if (monitor_num < 0)
|
||||
monitor_num = 0;
|
||||
gdk_screen_get_monitor_geometry (screen, monitor_num, &monitor);
|
||||
|
||||
gtk_widget_get_allocation (priv->arrow_button, &allocation);
|
||||
|
||||
gdk_window_get_origin (GTK_BUTTON (priv->arrow_button)->event_window, x, y);
|
||||
if (priv->orientation == GTK_ORIENTATION_HORIZONTAL)
|
||||
{
|
||||
if (gtk_widget_get_direction (GTK_WIDGET (toolbar)) == GTK_TEXT_DIR_LTR)
|
||||
*x += priv->arrow_button->allocation.width - req.width;
|
||||
*x += allocation.width - req.width;
|
||||
else
|
||||
*x += req.width - menu_req.width;
|
||||
|
||||
if ((*y + priv->arrow_button->allocation.height + menu_req.height) <= monitor.y + monitor.height)
|
||||
*y += priv->arrow_button->allocation.height;
|
||||
if ((*y + allocation.height + menu_req.height) <= monitor.y + monitor.height)
|
||||
*y += allocation.height;
|
||||
else if ((*y - menu_req.height) >= monitor.y)
|
||||
*y -= menu_req.height;
|
||||
else if (monitor.y + monitor.height - (*y + priv->arrow_button->allocation.height) > *y)
|
||||
*y += priv->arrow_button->allocation.height;
|
||||
else if (monitor.y + monitor.height - (*y + allocation.height) > *y)
|
||||
*y += allocation.height;
|
||||
else
|
||||
*y -= menu_req.height;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (gtk_widget_get_direction (GTK_WIDGET (toolbar)) == GTK_TEXT_DIR_LTR)
|
||||
*x += priv->arrow_button->allocation.width;
|
||||
*x += allocation.width;
|
||||
else
|
||||
*x -= menu_req.width;
|
||||
|
||||
if (*y + menu_req.height > monitor.y + monitor.height &&
|
||||
*y + priv->arrow_button->allocation.height - monitor.y > monitor.y + monitor.height - *y)
|
||||
*y += priv->arrow_button->allocation.height - menu_req.height;
|
||||
*y + allocation.height - monitor.y > monitor.y + monitor.height - *y)
|
||||
*y += allocation.height - menu_req.height;
|
||||
}
|
||||
|
||||
*push_in = FALSE;
|
||||
@ -2772,7 +2798,7 @@ gtk_toolbar_get_item_index (GtkToolbar *toolbar,
|
||||
|
||||
g_return_val_if_fail (GTK_IS_TOOLBAR (toolbar), -1);
|
||||
g_return_val_if_fail (GTK_IS_TOOL_ITEM (item), -1);
|
||||
g_return_val_if_fail (GTK_WIDGET (item)->parent == GTK_WIDGET (toolbar), -1);
|
||||
g_return_val_if_fail (gtk_widget_get_parent (GTK_WIDGET (item)) == GTK_WIDGET (toolbar), -1);
|
||||
|
||||
priv = toolbar->priv;
|
||||
|
||||
@ -3244,7 +3270,7 @@ calculate_max_homogeneous_pixels (GtkWidget *widget)
|
||||
|
||||
context = gtk_widget_get_pango_context (widget);
|
||||
metrics = pango_context_get_metrics (context,
|
||||
widget->style->font_desc,
|
||||
gtk_widget_get_style (widget)->font_desc,
|
||||
pango_context_get_language (context));
|
||||
char_width = pango_font_metrics_get_approximate_char_width (metrics);
|
||||
pango_font_metrics_unref (metrics);
|
||||
@ -3595,6 +3621,9 @@ _gtk_toolbar_paint_space_line (GtkWidget *widget,
|
||||
{
|
||||
GtkToolbarPriv *priv = toolbar->priv;
|
||||
GtkOrientation orientation;
|
||||
GtkStateType state;
|
||||
GtkStyle *style;
|
||||
GdkWindow *window;
|
||||
const double start_fraction = (SPACE_LINE_START / SPACE_LINE_DIVISION);
|
||||
const double end_fraction = (SPACE_LINE_END / SPACE_LINE_DIVISION);
|
||||
|
||||
@ -3602,6 +3631,10 @@ _gtk_toolbar_paint_space_line (GtkWidget *widget,
|
||||
|
||||
orientation = toolbar? priv->orientation : GTK_ORIENTATION_HORIZONTAL;
|
||||
|
||||
style = gtk_widget_get_style (widget);
|
||||
window = gtk_widget_get_window (widget);
|
||||
state = gtk_widget_get_state (widget);
|
||||
|
||||
if (orientation == GTK_ORIENTATION_HORIZONTAL)
|
||||
{
|
||||
gboolean wide_separators;
|
||||
@ -3613,20 +3646,20 @@ _gtk_toolbar_paint_space_line (GtkWidget *widget,
|
||||
NULL);
|
||||
|
||||
if (wide_separators)
|
||||
gtk_paint_box (widget->style, widget->window,
|
||||
gtk_widget_get_state (widget), GTK_SHADOW_ETCHED_OUT,
|
||||
gtk_paint_box (style, window,
|
||||
state, GTK_SHADOW_ETCHED_OUT,
|
||||
area, widget, "vseparator",
|
||||
allocation->x + (allocation->width - separator_width) / 2,
|
||||
allocation->y + allocation->height * start_fraction,
|
||||
separator_width,
|
||||
allocation->height * (end_fraction - start_fraction));
|
||||
else
|
||||
gtk_paint_vline (widget->style, widget->window,
|
||||
gtk_widget_get_state (widget), area, widget,
|
||||
gtk_paint_vline (style, window,
|
||||
state, area, widget,
|
||||
"toolbar",
|
||||
allocation->y + allocation->height * start_fraction,
|
||||
allocation->y + allocation->height * end_fraction,
|
||||
allocation->x + (allocation->width - widget->style->xthickness) / 2);
|
||||
allocation->x + (allocation->width - style->xthickness) / 2);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -3639,20 +3672,20 @@ _gtk_toolbar_paint_space_line (GtkWidget *widget,
|
||||
NULL);
|
||||
|
||||
if (wide_separators)
|
||||
gtk_paint_box (widget->style, widget->window,
|
||||
gtk_widget_get_state (widget), GTK_SHADOW_ETCHED_OUT,
|
||||
gtk_paint_box (style, window,
|
||||
state, GTK_SHADOW_ETCHED_OUT,
|
||||
area, widget, "hseparator",
|
||||
allocation->x + allocation->width * start_fraction,
|
||||
allocation->y + (allocation->height - separator_height) / 2,
|
||||
allocation->width * (end_fraction - start_fraction),
|
||||
separator_height);
|
||||
else
|
||||
gtk_paint_hline (widget->style, widget->window,
|
||||
gtk_widget_get_state (widget), area, widget,
|
||||
gtk_paint_hline (style, window,
|
||||
state, area, widget,
|
||||
"toolbar",
|
||||
allocation->x + allocation->width * start_fraction,
|
||||
allocation->x + allocation->width * end_fraction,
|
||||
allocation->y + (allocation->height - widget->style->ythickness) / 2);
|
||||
allocation->y + (allocation->height - style->ythickness) / 2);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user