* 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 "gtktoolpaletteprivate.h"
#include "gtkmarshalers.h"
-
+#include "gtktypebuiltins.h"
#include "gtkprivate.h"
#include "gtkscrollable.h"
+#include "gtkorientableprivate.h"
#include "gtkintl.h"
#define DEFAULT_ICON_SIZE GTK_ICON_SIZE_SMALL_TOOLBAR
if ((guint) g_value_get_enum (value) != palette->priv->orientation)
{
palette->priv->orientation = g_value_get_enum (value);
+ _gtk_orientable_set_style_classes (GTK_ORIENTABLE (palette));
gtk_tool_palette_reconfigured (palette);
}
break;
gint remaining_space = 0;
gint expand_space = 0;
- gint page_start, page_size = 0;
+ gint total_size, page_size;
gint offset = 0;
guint i;
guint border_width;
GtkToolItemGroupInfo *group = g_ptr_array_index (palette->priv->groups, i);
gint size;
+ group_sizes[i] = 0;
+
if (!group->widget)
continue;
child_allocation.y += border_width;
child_allocation.y += offset;
- page_start = child_allocation.y;
+ total_size = child_allocation.y;
}
else
{
x += border_width;
x += offset;
- page_start = x;
+ total_size = x;
}
/* update the scrollbar to match the displayed adjustment */
if (adjustment)
{
- gdouble value;
+ gdouble lower, upper;
- adjustment->page_increment = page_size * 0.9;
- adjustment->step_increment = page_size * 0.1;
- adjustment->page_size = page_size;
+ total_size = MAX (0, total_size);
+ page_size = MIN (total_size, page_size);
if (GTK_ORIENTATION_VERTICAL == palette->priv->orientation ||
GTK_TEXT_DIR_LTR == direction)
{
- adjustment->lower = 0;
- adjustment->upper = MAX (0, page_start);
-
- value = MIN (offset, adjustment->upper - adjustment->page_size);
- gtk_adjustment_clamp_page (adjustment, value, offset + page_size);
+ lower = 0;
+ upper = total_size;
}
else
{
- adjustment->lower = page_size - MAX (0, page_start);
- adjustment->upper = page_size;
+ lower = page_size - total_size;
+ upper = page_size;
offset = -offset;
-
- value = MAX (offset, adjustment->lower);
- gtk_adjustment_clamp_page (adjustment, offset, value + page_size);
}
- gtk_adjustment_changed (adjustment);
+ gtk_adjustment_configure (adjustment,
+ offset,
+ lower,
+ upper,
+ page_size * 0.1,
+ page_size * 0.9,
+ page_size);
}
}
-static gboolean
-gtk_tool_palette_draw (GtkWidget *widget,
- cairo_t *cr)
-{
- GtkToolPalette *palette = GTK_TOOL_PALETTE (widget);
- GdkDisplay *display;
- GdkWindow *window;
- guint i;
-
- window = gtk_widget_get_window (widget);
-
- display = gdk_window_get_display (window);
-
- if (!gdk_display_supports_composite (display))
- return FALSE;
-
- cairo_push_group (cr);
-
- for (i = 0; i < palette->priv->groups->len; ++i)
- {
- GtkToolItemGroupInfo *info = g_ptr_array_index (palette->priv->groups, i);
- if (info->widget)
- _gtk_tool_item_group_paint (info->widget, cr);
- }
-
- cairo_pop_group_to_source (cr);
-
- cairo_paint (cr);
-
- return FALSE;
-}
-
static void
gtk_tool_palette_realize (GtkWidget *widget)
{
gtk_widget_set_window (widget, window);
gdk_window_set_user_data (window, widget);
- gtk_widget_style_attach (widget);
- gtk_style_set_background (gtk_widget_get_style (widget),
- window, GTK_STATE_NORMAL);
+ gtk_style_context_set_background (gtk_widget_get_style_context (widget),
+ window);
gtk_container_forall (GTK_CONTAINER (widget),
(GtkCallback) gtk_widget_set_parent_window,
gpointer callback_data)
{
GtkToolPalette *palette = GTK_TOOL_PALETTE (container);
- guint i;
-
+ guint i, len;
for (i = 0; i < palette->priv->groups->len; ++i)
{
GtkToolItemGroupInfo *info = g_ptr_array_index (palette->priv->groups, i);
+
+ len = palette->priv->groups->len;
+
if (info->widget)
callback (GTK_WIDGET (info->widget),
callback_data);
+
+ /* At destroy time, 'callback' results in removing a widget,
+ * here we just reset the current index to account for the removed widget. */
+ i -= (len - palette->priv->groups->len);
}
}
wclass->get_preferred_width = gtk_tool_palette_get_preferred_width;
wclass->get_preferred_height= gtk_tool_palette_get_preferred_height;
wclass->size_allocate = gtk_tool_palette_size_allocate;
- wclass->draw = gtk_tool_palette_draw;
wclass->realize = gtk_tool_palette_realize;
cclass->add = gtk_tool_palette_add;
* GtkToolPalette:icon-size:
*
* The size of the icons in a tool palette is normally determined by
- * the #GtkSettings:toolbar-icon-size setting. When this property is set,
+ * the #GtkSettings:gtk-toolbar-icon-size setting. When this property is set,
* it overrides the setting.
*
* This should only be used for special-purpose tool palettes, normal
const GtkSelectionData *selection)
{
GtkToolPaletteDragData *data;
+ GdkAtom target;
g_return_val_if_fail (GTK_IS_TOOL_PALETTE (palette), NULL);
g_return_val_if_fail (NULL != selection, NULL);
- g_return_val_if_fail (selection->format == 8, NULL);
- g_return_val_if_fail (selection->length == sizeof (GtkToolPaletteDragData), NULL);
- g_return_val_if_fail (selection->target == dnd_target_atom_item ||
- selection->target == dnd_target_atom_group,
+ g_return_val_if_fail (gtk_selection_data_get_format (selection) == 8, NULL);
+ g_return_val_if_fail (gtk_selection_data_get_length (selection) == sizeof (GtkToolPaletteDragData), NULL);
+ target = gtk_selection_data_get_target (selection);
+ g_return_val_if_fail (target == dnd_target_atom_item ||
+ target == dnd_target_atom_group,
NULL);
- data = (GtkToolPaletteDragData*) selection->data;
+ data = (GtkToolPaletteDragData*) gtk_selection_data_get_data (selection);
g_return_val_if_fail (data->palette == palette, NULL);
- if (dnd_target_atom_item == selection->target)
+ if (dnd_target_atom_item == target)
g_return_val_if_fail (GTK_IS_TOOL_ITEM (data->item), NULL);
- else if (dnd_target_atom_group == selection->target)
+ else if (dnd_target_atom_group == target)
g_return_val_if_fail (GTK_IS_TOOL_ITEM_GROUP (data->item), NULL);
return data->item;
/**
* gtk_tool_palette_set_drag_source:
* @palette: a #GtkToolPalette
- * @targets: the #GtkToolPaletteDragTarget<!-- -->s
+ * @targets: the #GtkToolPaletteDragTargets
* which the widget should support
*
* Sets the tool palette as a drag source.
* @widget: a #GtkWidget which should be a drag destination for @palette
* @flags: the flags that specify what actions GTK+ should take for drops
* on that widget
- * @targets: the #GtkToolPaletteDragTarget<!-- -->s which the widget
+ * @targets: the #GtkToolPaletteDragTargets which the widget
* should support
* @actions: the #GdkDragAction<!-- -->s which the widget should suppport
*
gpointer data)
{
GtkToolPaletteDragData drag_data = { GTK_TOOL_PALETTE (data), NULL };
+ GdkAtom target;
+
+ target = gtk_selection_data_get_target (selection);
- if (selection->target == dnd_target_atom_item)
+ if (target == dnd_target_atom_item)
drag_data.item = gtk_widget_get_ancestor (widget, GTK_TYPE_TOOL_ITEM);
if (drag_data.item)
- gtk_selection_data_set (selection, selection->target, 8,
+ gtk_selection_data_set (selection, target, 8,
(guchar*) &drag_data, sizeof (drag_data));
}
gpointer data)
{
GtkToolPaletteDragData drag_data = { GTK_TOOL_PALETTE (data), NULL };
+ GdkAtom target;
+
+ target = gtk_selection_data_get_target (selection);
- if (selection->target == dnd_target_atom_group)
+ if (target == dnd_target_atom_group)
drag_data.item = gtk_widget_get_ancestor (widget, GTK_TYPE_TOOL_ITEM_GROUP);
if (drag_data.item)
- gtk_selection_data_set (selection, selection->target, 8,
+ gtk_selection_data_set (selection, target, 8,
(guchar*) &drag_data, sizeof (drag_data));
}
*
* Since: 2.20
*/
-G_CONST_RETURN GtkTargetEntry*
+const GtkTargetEntry*
gtk_tool_palette_get_drag_target_item (void)
{
return &dnd_targets[0];
*
* Since: 2.20
*/
-G_CONST_RETURN GtkTargetEntry*
+const GtkTargetEntry*
gtk_tool_palette_get_drag_target_group (void)
{
return &dnd_targets[1];
G_CALLBACK (gtk_tool_palette_adjustment_value_changed),
palette);
priv->hadjustment = g_object_ref_sink (adjustment);
- /* FIXME: Adjustment should probably have it's values updated now */
+ /* FIXME: Adjustment should probably have its values updated now */
g_object_notify (G_OBJECT (palette), "hadjustment");
}
G_CALLBACK (gtk_tool_palette_adjustment_value_changed),
palette);
priv->vadjustment = g_object_ref_sink (adjustment);
- /* FIXME: Adjustment should probably have it's values updated now */
+ /* FIXME: Adjustment should probably have its values updated now */
g_object_notify (G_OBJECT (palette), "vadjustment");
}