* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ * License along with this library. If not, see <http://www.gnu.org/licenses/>.
*
* Authors:
* Mathias Hasselmann
#include "config.h"
-#include "gtktoolpaletteprivate.h"
-
-#include <gtk/gtk.h>
#include <math.h>
#include <string.h>
+
+#include "gtktoolpaletteprivate.h"
+#include "gtktypebuiltins.h"
#include "gtkprivate.h"
#include "gtkintl.h"
GList *children;
- gboolean animation;
gint64 animation_start;
GSource *animation_timeout;
- GtkExpanderStyle expander_style;
gint expander_size;
gint header_spacing;
- PangoEllipsizeMode ellipsize;
gulong focus_set_id;
GtkWidget *toplevel;
GtkSettings *settings;
gulong settings_connection;
+ PangoEllipsizeMode ellipsize;
+
+ guint animation : 1;
guint collapsed : 1;
};
if (old_settings)
{
g_signal_handler_disconnect (old_settings, priv->settings_connection);
+ priv->settings_connection = 0;
g_object_unref (old_settings);
}
}
static gboolean
-gtk_tool_item_group_header_expose_event_cb (GtkWidget *widget,
- GdkEventExpose *event,
- gpointer data)
+gtk_tool_item_group_header_draw_cb (GtkWidget *widget,
+ cairo_t *cr,
+ gpointer data)
{
- GtkAllocation allocation;
GtkToolItemGroup *group = GTK_TOOL_ITEM_GROUP (data);
GtkToolItemGroupPrivate* priv = group->priv;
- GtkExpanderStyle expander_style;
GtkOrientation orientation;
- gint x, y;
+ gint x, y, width, height;
GtkTextDirection direction;
+ GtkStyleContext *context;
+ GtkStateFlags state = 0;
orientation = gtk_tool_shell_get_orientation (GTK_TOOL_SHELL (group));
- expander_style = priv->expander_style;
direction = gtk_widget_get_direction (widget);
+ width = gtk_widget_get_allocated_width (widget);
+ height = gtk_widget_get_allocated_height (widget);
+ context = gtk_widget_get_style_context (widget);
+ state = gtk_widget_get_state_flags (widget);
+
+ if (!priv->collapsed)
+ state |= GTK_STATE_FLAG_ACTIVE;
+
+ gtk_style_context_save (context);
+ gtk_style_context_set_state (context, state);
+ gtk_style_context_add_class (context, GTK_STYLE_CLASS_EXPANDER);
- gtk_widget_get_allocation (widget, &allocation);
if (GTK_ORIENTATION_VERTICAL == orientation)
{
+ gtk_style_context_add_class (context, GTK_STYLE_CLASS_VERTICAL);
+
if (GTK_TEXT_DIR_RTL == direction)
- x = allocation.x + allocation.width - priv->expander_size / 2;
+ x = width;
else
- x = allocation.x + priv->expander_size / 2;
+ x = 0;
- y = allocation.y + allocation.height / 2;
+ y = height / 2 - priv->expander_size / 2;
}
else
{
- x = allocation.x + allocation.width / 2;
- y = allocation.y + priv->expander_size / 2;
-
- /* Unfortunatly gtk_paint_expander() doesn't support rotated drawing
- * modes. Luckily the following shady arithmetics produce the desired
- * result. */
- expander_style = GTK_EXPANDER_EXPANDED - expander_style;
+ gtk_style_context_add_class (context, GTK_STYLE_CLASS_HORIZONTAL);
+ x = width / 2 - priv->expander_size / 2;
+ y = 0;
}
- gtk_paint_expander (gtk_widget_get_style (widget),
- gtk_widget_get_window (widget),
- gtk_widget_get_state (priv->header),
- &event->area, GTK_WIDGET (group),
- "tool-palette-header", x, y,
- expander_style);
+ gtk_render_expander (context, cr, x, y,
+ priv->expander_size,
+ priv->expander_size);
- return FALSE;
-}
+ gtk_style_context_restore (context);
-static void
-gtk_tool_item_group_header_size_request_cb (GtkWidget *widget,
- GtkRequisition *requisition,
- gpointer data)
-{
- GtkToolItemGroup *group = GTK_TOOL_ITEM_GROUP (data);
- requisition->height = MAX (requisition->height, group->priv->expander_size);
+ return FALSE;
}
static void
"header-spacing", &(priv->header_spacing),
"expander-size", &(priv->expander_size),
NULL);
+
+ gtk_widget_set_size_request (alignment, -1, priv->expander_size);
switch (gtk_tool_shell_get_orientation (GTK_TOOL_SHELL (group)))
{
priv->children = NULL;
priv->header_spacing = DEFAULT_HEADER_SPACING;
priv->expander_size = DEFAULT_EXPANDER_SIZE;
- priv->expander_style = GTK_EXPANDER_EXPANDED;
priv->label_widget = gtk_label_new (NULL);
- gtk_misc_set_alignment (GTK_MISC (priv->label_widget), 0.0, 0.5);
+ gtk_widget_set_halign (priv->label_widget, GTK_ALIGN_START);
+ gtk_widget_set_valign (priv->label_widget, GTK_ALIGN_CENTER);
alignment = gtk_alignment_new (0.5, 0.5, 1.0, 1.0);
gtk_container_add (GTK_CONTAINER (alignment), priv->label_widget);
gtk_widget_show_all (alignment);
gtk_tool_item_group_header_adjust_style (group);
- g_signal_connect_after (alignment, "expose-event",
- G_CALLBACK (gtk_tool_item_group_header_expose_event_cb),
- group);
- g_signal_connect_after (alignment, "size-request",
- G_CALLBACK (gtk_tool_item_group_header_size_request_cb),
+ g_signal_connect_after (alignment, "draw",
+ G_CALLBACK (gtk_tool_item_group_header_draw_cb),
group);
g_signal_connect (priv->header, "clicked",
priv->toplevel = NULL;
}
+ if (priv->settings_connection > 0)
+ {
+ g_signal_handler_disconnect (priv->settings, priv->settings_connection);
+ priv->settings_connection = 0;
+ }
+
+ g_clear_object (&priv->settings);
+
G_OBJECT_CLASS (gtk_tool_item_group_parent_class)->dispose (object);
}
if (priv->children && gtk_tool_item_group_get_label_widget (group))
{
- gtk_size_request_get_size (GTK_SIZE_REQUEST (priv->header),
- requisition, NULL);
+ gtk_widget_get_preferred_size (priv->header,
+ requisition, NULL);
gtk_widget_show (priv->header);
}
else
requisition->height += border_width * 2;
}
+static void
+gtk_tool_item_group_get_preferred_width (GtkWidget *widget,
+ gint *minimum,
+ gint *natural)
+{
+ GtkRequisition requisition;
+
+ gtk_tool_item_group_size_request (widget, &requisition);
+
+ *minimum = *natural = requisition.width;
+}
+
+static void
+gtk_tool_item_group_get_preferred_height (GtkWidget *widget,
+ gint *minimum,
+ gint *natural)
+{
+ GtkRequisition requisition;
+
+ gtk_tool_item_group_size_request (widget, &requisition);
+
+ *minimum = *natural = requisition.height;
+}
+
+
static gboolean
gtk_tool_item_group_is_item_visible (GtkToolItemGroup *group,
GtkToolItemGroupChild *child)
GtkAllocation item_area;
GtkOrientation orientation;
- GtkToolbarStyle style;
gint min_rows;
guint border_width;
border_width = gtk_container_get_border_width (GTK_CONTAINER (widget));
orientation = gtk_tool_shell_get_orientation (GTK_TOOL_SHELL (group));
- style = gtk_tool_shell_get_style (GTK_TOOL_SHELL (group));
/* figure out the size of homogeneous items */
gtk_tool_item_group_get_item_size (group, &item_size, TRUE, &min_rows);
item_area.width = 0;
item_area.height = 0;
- /* figure out the required columns (n_columns) and rows (n_rows) to place all items */
+ /* figure out the required columns (n_columns) and rows (n_rows)
+ * to place all items
+ */
if (!priv->collapsed || !priv->animation || priv->animation_timeout)
{
guint n_columns;
GtkRequisition req = {0, 0};
guint width;
- gtk_size_request_get_size (GTK_SIZE_REQUEST (child->item),
- &req, NULL);
+ gtk_widget_get_preferred_size (GTK_WIDGET (child->item),
+ &req, NULL);
width = udiv (req.width, item_size.width);
col += width;
row_min_width = g_new0 (guint, n_rows);
- /* calculate minimal and maximal required cols and minimal required rows */
+ /* calculate minimal and maximal required cols and minimal
+ * required rows
+ */
for (it = priv->children; it != NULL; it = it->next)
{
GtkToolItemGroupChild *child = it->data;
GtkRequisition req = {0, 0};
guint width;
- gtk_size_request_get_size (GTK_SIZE_REQUEST (child->item),
- &req, NULL);
+ gtk_widget_get_preferred_size (GTK_WIDGET (child->item),
+ &req, NULL);
width = udiv (req.width, item_size.width);
min_col = MAX (min_col, row_min_width[i]);
}
- /* simple linear search for minimal required columns for the given maximal number of rows (n_rows) */
+ /* simple linear search for minimal required columns
+ * for the given maximal number of rows (n_rows)
+ */
for (n_columns = min_col; n_columns < max_col; n_columns ++)
{
new_row = TRUE;
GtkRequisition req = {0, 0};
guint width;
- gtk_size_request_get_size (GTK_SIZE_REQUEST (child->item),
- &req, NULL);
+ gtk_widget_get_preferred_size (GTK_WIDGET (child->item),
+ &req, NULL);
width = udiv (req.width, item_size.width);
col += width;
{
GtkRequisition child_requisition;
- gtk_size_request_get_size (GTK_SIZE_REQUEST (priv->header),
- &child_requisition, NULL);
+ gtk_widget_get_preferred_size (priv->header,
+ &child_requisition, NULL);
if (GTK_ORIENTATION_VERTICAL == orientation)
inquery->height += child_requisition.height;
GtkAllocation item_area;
GtkOrientation orientation;
- GtkToolbarStyle style;
GList *it;
gint n_columns, n_rows = 1;
gint min_rows;
guint border_width;
+ GtkTextDirection direction;
border_width = gtk_container_get_border_width (GTK_CONTAINER (widget));
- GtkTextDirection direction = gtk_widget_get_direction (widget);
+ direction = gtk_widget_get_direction (widget);
orientation = gtk_tool_shell_get_orientation (GTK_TOOL_SHELL (group));
- style = gtk_tool_shell_get_style (GTK_TOOL_SHELL (group));
/* chain up */
GTK_WIDGET_CLASS (gtk_tool_item_group_parent_class)->size_allocate (widget, allocation);
/* place the header widget */
if (gtk_widget_get_visible (priv->header))
{
- gtk_size_request_get_size (GTK_SIZE_REQUEST (priv->header),
- &child_requisition, NULL);
+ gtk_widget_get_preferred_size (priv->header,
+ &child_requisition, NULL);
if (GTK_ORIENTATION_VERTICAL == orientation)
{
if (!child->homogeneous)
{
- gtk_size_request_get_size (GTK_SIZE_REQUEST (child->item),
- &child_requisition, NULL);
+ gtk_widget_get_preferred_size (GTK_WIDGET (child->item),
+ &child_requisition, NULL);
child_requisition.width = MIN (child_requisition.width, item_area.width);
}
/* Check that the focused widgets is fully visible within
* the group's parent widget and make it visible otherwise. */
- adjustment = gtk_tool_palette_get_vadjustment (GTK_TOOL_PALETTE (p));
+ adjustment = gtk_scrollable_get_vadjustment (GTK_SCROLLABLE (p));
if (adjustment)
{
if (gtk_widget_translate_coordinates
(widget, p, 0, 0, NULL, &y) && y < 0)
{
- y += adjustment->value;
+ y += gtk_adjustment_get_value (adjustment);
gtk_adjustment_clamp_page (adjustment, y, y + allocation.height);
}
else if (gtk_widget_translate_coordinates (widget, p, 0, allocation.height, NULL, &y) &&
y > p_allocation.height)
{
- y += adjustment->value;
+ y += gtk_adjustment_get_value (adjustment);
gtk_adjustment_clamp_page (adjustment, y - allocation.height, y);
}
}
- adjustment = gtk_tool_palette_get_hadjustment (GTK_TOOL_PALETTE (p));
+ adjustment = gtk_scrollable_get_hadjustment (GTK_SCROLLABLE (p));
if (adjustment)
{
if (gtk_widget_translate_coordinates
(widget, p, 0, 0, &x, NULL) && x < 0)
{
- x += adjustment->value;
+ x += gtk_adjustment_get_value (adjustment);
gtk_adjustment_clamp_page (adjustment, x, x + allocation.width);
}
else if (gtk_widget_translate_coordinates (widget, p, allocation.width, 0, &x, NULL) &&
x > p_allocation.width)
{
- x += adjustment->value;
+ x += gtk_adjustment_get_value (adjustment);
gtk_adjustment_clamp_page (adjustment, x - allocation.width, x);
}
GtkWidget *toplevel_window;
GdkWindow *window;
GdkWindowAttr attributes;
- GdkDisplay *display;
gint attributes_mask;
guint border_width;
+ GtkStyleContext *context;
gtk_widget_set_realized (widget, TRUE);
border_width = gtk_container_get_border_width (GTK_CONTAINER (widget));
+ context = gtk_widget_get_style_context (widget);
gtk_widget_get_allocation (widget, &allocation);
attributes.height = allocation.height - border_width * 2;
attributes.wclass = GDK_INPUT_OUTPUT;
attributes.visual = gtk_widget_get_visual (widget);
- attributes.colormap = gtk_widget_get_colormap (widget);
attributes.event_mask = gtk_widget_get_events (widget)
| GDK_VISIBILITY_NOTIFY_MASK | GDK_EXPOSURE_MASK
| GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK
| GDK_BUTTON_MOTION_MASK;
- attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
+ attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL;
window = gdk_window_new (gtk_widget_get_parent_window (widget),
&attributes, attributes_mask);
gtk_widget_set_window (widget, window);
- display = gdk_drawable_get_display (window);
-
- if (gdk_display_supports_composite (display))
- gdk_window_set_composited (window, TRUE);
-
- gdk_window_set_user_data (window, widget);
+ gtk_widget_register_window (widget, window);
- gtk_widget_style_attach (widget);
- gtk_style_set_background (gtk_widget_get_style (widget),
- window, GTK_STATE_NORMAL);
+ gtk_style_context_set_background (context, window);
gtk_container_forall (GTK_CONTAINER (widget),
(GtkCallback) gtk_widget_set_parent_window,
}
static void
-gtk_tool_item_group_style_set (GtkWidget *widget,
- GtkStyle *previous_style)
+gtk_tool_item_group_style_updated (GtkWidget *widget)
{
gtk_tool_item_group_header_adjust_style (GTK_TOOL_ITEM_GROUP (widget));
- GTK_WIDGET_CLASS (gtk_tool_item_group_parent_class)->style_set (widget, previous_style);
+ GTK_WIDGET_CLASS (gtk_tool_item_group_parent_class)->style_updated (widget);
}
static void
oclass->finalize = gtk_tool_item_group_finalize;
oclass->dispose = gtk_tool_item_group_dispose;
- wclass->size_request = gtk_tool_item_group_size_request;
- wclass->size_allocate = gtk_tool_item_group_size_allocate;
- wclass->realize = gtk_tool_item_group_realize;
- wclass->unrealize = gtk_tool_item_group_unrealize;
- wclass->style_set = gtk_tool_item_group_style_set;
- wclass->screen_changed = gtk_tool_item_group_screen_changed;
+ wclass->get_preferred_width = gtk_tool_item_group_get_preferred_width;
+ wclass->get_preferred_height = gtk_tool_item_group_get_preferred_height;
+ wclass->size_allocate = gtk_tool_item_group_size_allocate;
+ wclass->realize = gtk_tool_item_group_realize;
+ wclass->unrealize = gtk_tool_item_group_unrealize;
+ wclass->style_updated = gtk_tool_item_group_style_updated;
+ wclass->screen_changed = gtk_tool_item_group_screen_changed;
cclass->add = gtk_tool_item_group_add;
cclass->remove = gtk_tool_item_group_remove;
if (priv->label_widget)
{
- gtk_widget_set_state (priv->label_widget, GTK_STATE_NORMAL);
+ gtk_widget_set_state_flags (priv->label_widget, 0, TRUE);
gtk_container_remove (GTK_CONTAINER (alignment), priv->label_widget);
}
static gint64
gtk_tool_item_group_get_animation_timestamp (GtkToolItemGroup *group)
{
- GTimeVal now;
-
- g_source_get_current_time (group->priv->animation_timeout, &now);
- return (now.tv_sec * G_USEC_PER_SEC + now.tv_usec - group->priv->animation_start) / 1000;
+ return (g_source_get_time (group->priv->animation_timeout) -
+ group->priv->animation_start) / 1000;
}
static void
gint64 timestamp = gtk_tool_item_group_get_animation_timestamp (group);
gboolean retval;
- GDK_THREADS_ENTER ();
+ gdk_threads_enter ();
/* Enque this early to reduce number of expose events. */
gtk_widget_queue_resize_no_redraw (GTK_WIDGET (group));
- /* Figure out current style of the expander arrow. */
- if (priv->collapsed)
- {
- if (priv->expander_style == GTK_EXPANDER_EXPANDED)
- priv->expander_style = GTK_EXPANDER_SEMI_COLLAPSED;
- else
- priv->expander_style = GTK_EXPANDER_COLLAPSED;
- }
- else
- {
- if (priv->expander_style == GTK_EXPANDER_COLLAPSED)
- priv->expander_style = GTK_EXPANDER_SEMI_EXPANDED;
- else
- priv->expander_style = GTK_EXPANDER_EXPANDED;
- }
-
gtk_tool_item_group_force_expose (group);
/* Finish animation when done. */
retval = (priv->animation_timeout != NULL);
- GDK_THREADS_LEAVE ();
+ gdk_threads_leave ();
return retval;
}
{
if (priv->animation)
{
- GTimeVal now;
-
- g_get_current_time (&now);
-
if (priv->animation_timeout)
g_source_destroy (priv->animation_timeout);
- priv->animation_start = (now.tv_sec * G_USEC_PER_SEC + now.tv_usec);
+ priv->animation_start = g_get_monotonic_time ();
priv->animation_timeout = g_timeout_source_new (ANIMATION_TIMEOUT);
g_source_set_callback (priv->animation_timeout,
gtk_tool_item_group_animation_cb,
group, NULL);
-
g_source_attach (priv->animation_timeout, NULL);
}
- else
- {
- priv->expander_style = GTK_EXPANDER_COLLAPSED;
- gtk_tool_item_group_force_expose (group);
- }
+ else
+ gtk_tool_item_group_force_expose (group);
priv->collapsed = collapsed;
g_object_notify (G_OBJECT (group), "collapsed");
*
* Since: 2.20
*/
-G_CONST_RETURN gchar*
+const gchar*
gtk_tool_item_group_get_label (GtkToolItemGroup *group)
{
GtkToolItemGroupPrivate *priv;
gint y)
{
GtkAllocation allocation;
- GtkOrientation orientation;
GList *it;
g_return_val_if_fail (GTK_IS_TOOL_ITEM_GROUP (group), NULL);
gtk_widget_get_allocation (GTK_WIDGET (group), &allocation);
- orientation = gtk_tool_shell_get_orientation (GTK_TOOL_SHELL (group));
g_return_val_if_fail (x >= 0 && x < allocation.width, NULL);
g_return_val_if_fail (y >= 0 && y < allocation.height, NULL);
GList *it;
gint rows = 0;
gboolean new_row = TRUE;
- GtkOrientation orientation;
- GtkToolbarStyle style;
g_return_if_fail (GTK_IS_TOOL_ITEM_GROUP (group));
g_return_if_fail (NULL != item_size);
- orientation = gtk_tool_shell_get_orientation (GTK_TOOL_SHELL (group));
- style = gtk_tool_shell_get_style (GTK_TOOL_SHELL (group));
-
item_size->width = item_size->height = 0;
for (it = group->priv->children; it != NULL; it = it->next)
if (!child->homogeneous && child->expand)
new_row = TRUE;
- gtk_size_request_get_size (GTK_SIZE_REQUEST (child->item),
- &child_requisition, NULL);
+ gtk_widget_get_preferred_size (GTK_WIDGET (child->item),
+ &child_requisition, NULL);
if (!homogeneous_only || child->homogeneous)
item_size->width = MAX (item_size->width, child_requisition.width);
gtk_widget_get_allocation (widget, &allocation);
- gdk_cairo_set_source_pixmap (cr, gtk_widget_get_window (widget),
+ gdk_cairo_set_source_window (cr, gtk_widget_get_window (widget),
allocation.x,
allocation.y);
GtkRequisition requisition;
GtkToolItemGroupPrivate* priv = group->priv;
- gtk_size_request_get_size (GTK_SIZE_REQUEST (group),
- &requisition, NULL);
+ gtk_widget_get_preferred_size (GTK_WIDGET (group),
+ &requisition, NULL);
if (!priv->collapsed || priv->animation_timeout)
{