diff --git a/gtk/gtkalignment.c b/gtk/gtkalignment.c index d29e7d749e..7f075861bf 100644 --- a/gtk/gtkalignment.c +++ b/gtk/gtkalignment.c @@ -92,7 +92,7 @@ gtk_alignment_class_init (GtkAlignmentClass *class) static void gtk_alignment_init (GtkAlignment *alignment) { - GTK_WIDGET_SET_FLAGS (alignment, GTK_NO_WINDOW | GTK_BASIC); + GTK_WIDGET_SET_FLAGS (alignment, GTK_NO_WINDOW); alignment->xalign = 0.5; alignment->yalign = 0.5; diff --git a/gtk/gtkarg.c b/gtk/gtkarg.c index 468ab92af3..ff543e63ca 100644 --- a/gtk/gtkarg.c +++ b/gtk/gtkarg.c @@ -39,7 +39,7 @@ struct _GtkArgQueryData /* --- functions --- */ -void +GtkArgInfo* gtk_arg_type_new_static (GtkType base_class_type, const gchar *arg_name, guint class_n_args_offset, @@ -56,14 +56,14 @@ gtk_arg_type_new_static (GtkType base_class_type, guint *n_args_p; gchar *p; - g_return_if_fail (arg_name != NULL); - g_return_if_fail (GTK_FUNDAMENTAL_TYPE (base_class_type) == GTK_TYPE_OBJECT); - g_return_if_fail (class_n_args_offset != 0); - g_return_if_fail (arg_info_hash_table != NULL); - g_return_if_fail (arg_type > GTK_TYPE_NONE); - g_return_if_fail (arg_id > 0); - g_return_if_fail ((arg_flags & GTK_ARG_READWRITE) != 0); - /* g_return_if_fail ((arg_flags & GTK_ARG_CHILD_ARG) == 0); */ + g_return_val_if_fail (arg_name != NULL, NULL); + g_return_val_if_fail (GTK_FUNDAMENTAL_TYPE (base_class_type) == GTK_TYPE_OBJECT, NULL); + g_return_val_if_fail (class_n_args_offset != 0, NULL); + g_return_val_if_fail (arg_info_hash_table != NULL, NULL); + g_return_val_if_fail (arg_type > GTK_TYPE_NONE, NULL); + g_return_val_if_fail (arg_id > 0, NULL); + g_return_val_if_fail ((arg_flags & GTK_ARG_READWRITE) != 0, NULL); + /* g_return_val_if_fail ((arg_flags & GTK_ARG_CHILD_ARG) == 0, NULL); */ arg_flags &= GTK_ARG_MASK; @@ -71,7 +71,7 @@ gtk_arg_type_new_static (GtkType base_class_type, if (!arg_part || (arg_part[0] != ':') || (arg_part[1] != ':')) { g_warning ("gtk_arg_type_new(): invalid arg name: \"%s\"\n", arg_name); - return; + return NULL; } class_offset = (guint) (arg_part - arg_name); @@ -84,7 +84,7 @@ gtk_arg_type_new_static (GtkType base_class_type, g_warning ("gtk_arg_type_new(): argument class in \"%s\" is not in the `%s' ancestry", arg_name, gtk_type_name (base_class_type)); - return; + return NULL; } p = gtk_type_class (class_type); @@ -102,6 +102,8 @@ gtk_arg_type_new_static (GtkType base_class_type, info->seq_id = *n_args_p; g_hash_table_insert (arg_info_hash_table, info, info); + + return info; } gchar* diff --git a/gtk/gtkarg.h b/gtk/gtkarg.h index c382841f11..c92e8bd872 100644 --- a/gtk/gtkarg.h +++ b/gtk/gtkarg.h @@ -50,38 +50,38 @@ struct _GtkArgInfo /* Non-public methods */ -GtkArg* gtk_arg_new (GtkType arg_type); -GtkArg* gtk_arg_copy (GtkArg *src_arg, - GtkArg *dest_arg); -void gtk_arg_free (GtkArg *arg, - gboolean free_contents); -gchar* gtk_args_collect (GtkType object_type, - GHashTable *arg_info_hash_table, - GSList **arg_list_p, - GSList **info_list_p, - const gchar *first_arg_name, - va_list var_args); -void gtk_args_collect_cleanup (GSList *arg_list, - GSList *info_list); -gchar* gtk_arg_get_info (GtkType object_type, - GHashTable *arg_info_hash_table, - const gchar *arg_name, - GtkArgInfo **info_p); -void gtk_arg_type_new_static (GtkType base_class_type, - const gchar *arg_name, - guint class_n_args_offset, - GHashTable *arg_info_hash_table, - GtkType arg_type, - guint arg_flags, - guint arg_id); -GtkArg* gtk_args_query (GtkType class_type, - GHashTable *arg_info_hash_table, - guint32 **arg_flags, - guint *n_args_p); -gchar* gtk_arg_name_strip_type (const gchar *arg_name); -gint gtk_arg_info_equal (gconstpointer arg_info_1, - gconstpointer arg_info_2); -guint gtk_arg_info_hash (gconstpointer arg_info); +GtkArg* gtk_arg_new (GtkType arg_type); +GtkArg* gtk_arg_copy (GtkArg *src_arg, + GtkArg *dest_arg); +void gtk_arg_free (GtkArg *arg, + gboolean free_contents); +gchar* gtk_args_collect (GtkType object_type, + GHashTable *arg_info_hash_table, + GSList **arg_list_p, + GSList **info_list_p, + const gchar *first_arg_name, + va_list var_args); +void gtk_args_collect_cleanup (GSList *arg_list, + GSList *info_list); +gchar* gtk_arg_get_info (GtkType object_type, + GHashTable *arg_info_hash_table, + const gchar *arg_name, + GtkArgInfo **info_p); +GtkArgInfo* gtk_arg_type_new_static (GtkType base_class_type, + const gchar *arg_name, + guint class_n_args_offset, + GHashTable *arg_info_hash_table, + GtkType arg_type, + guint arg_flags, + guint arg_id); +GtkArg* gtk_args_query (GtkType class_type, + GHashTable *arg_info_hash_table, + guint32 **arg_flags, + guint *n_args_p); +gchar* gtk_arg_name_strip_type (const gchar *arg_name); +gint gtk_arg_info_equal (gconstpointer arg_info_1, + gconstpointer arg_info_2); +guint gtk_arg_info_hash (gconstpointer arg_info); diff --git a/gtk/gtkbox.c b/gtk/gtkbox.c index c092c0bb00..cfc06220f7 100644 --- a/gtk/gtkbox.c +++ b/gtk/gtkbox.c @@ -134,7 +134,7 @@ gtk_box_class_init (GtkBoxClass *class) static void gtk_box_init (GtkBox *box) { - GTK_WIDGET_SET_FLAGS (box, GTK_NO_WINDOW | GTK_BASIC); + GTK_WIDGET_SET_FLAGS (box, GTK_NO_WINDOW); box->children = NULL; box->spacing = 0; diff --git a/gtk/gtkbox.h b/gtk/gtkbox.h index 1a47081a2e..f89ceab467 100644 --- a/gtk/gtkbox.h +++ b/gtk/gtkbox.h @@ -29,11 +29,11 @@ extern "C" { #endif /* __cplusplus */ -#define GTK_TYPE_BOX (gtk_box_get_type ()) -#define GTK_BOX(obj) (GTK_CHECK_CAST ((obj), GTK_TYPE_BOX, GtkBox)) -#define GTK_BOX_CLASS(klass) (GTK_CHECK_CLASS_CAST ((klass), GTK_TYPE_BOX, GtkBoxClass)) -#define GTK_IS_BOX(obj) (GTK_CHECK_TYPE ((obj), GTK_TYPE_BOX)) -#define GTK_IS_BOX_CLASS(klass) (GTK_CHECK_CLASS_TYPE ((klass), GTK_TYPE_BOX)) +#define GTK_TYPE_BOX (gtk_box_get_type ()) +#define GTK_BOX(obj) (GTK_CHECK_CAST ((obj), GTK_TYPE_BOX, GtkBox)) +#define GTK_BOX_CLASS(klass) (GTK_CHECK_CLASS_CAST ((klass), GTK_TYPE_BOX, GtkBoxClass)) +#define GTK_IS_BOX(obj) (GTK_CHECK_TYPE ((obj), GTK_TYPE_BOX)) +#define GTK_IS_BOX_CLASS(klass) (GTK_CHECK_CLASS_TYPE ((klass), GTK_TYPE_BOX)) typedef struct _GtkBox GtkBox; diff --git a/gtk/gtkclist.c b/gtk/gtkclist.c index 79ed963d0e..cca25b8fc6 100644 --- a/gtk/gtkclist.c +++ b/gtk/gtkclist.c @@ -142,8 +142,10 @@ enum enum { ARG_0, - ARG_HADJUSTMENT, - ARG_VADJUSTMENT + ARG_N_COLUMNS, + ARG_SHADOW_TYPE, + ARG_SELECTION_MODE, + ARG_ROW_HEIGHT }; static void sync_selection (GtkCList * clist, @@ -159,6 +161,9 @@ static void gtk_clist_destroy (GtkObject *object); static void gtk_clist_finalize (GtkObject *object); /* GtkWidget Methods */ +static void gtk_clist_scroll_adjustments (GtkCList *clist, + GtkAdjustment *hadjustment, + GtkAdjustment *vadjustment); static void gtk_clist_realize (GtkWidget *widget); static void gtk_clist_unrealize (GtkWidget *widget); static void gtk_clist_map (GtkWidget *widget); @@ -414,14 +419,36 @@ gtk_clist_class_init (GtkCListClass *klass) parent_class = gtk_type_class (GTK_TYPE_CONTAINER); - gtk_object_add_arg_type ("GtkCList::hadjustment", - GTK_TYPE_ADJUSTMENT, + gtk_object_add_arg_type ("GtkCList::n_columns", + GTK_TYPE_UINT, + GTK_ARG_READWRITE | GTK_ARG_CONSTRUCT_ONLY, + ARG_N_COLUMNS); + gtk_object_add_arg_type ("GtkCList::shadow_type", + GTK_TYPE_SHADOW_TYPE, GTK_ARG_READWRITE, - ARG_HADJUSTMENT); - gtk_object_add_arg_type ("GtkCList::vadjustment", - GTK_TYPE_ADJUSTMENT, + ARG_SHADOW_TYPE); + gtk_object_add_arg_type ("GtkCList::selection_mode", + GTK_TYPE_SELECTION_MODE, GTK_ARG_READWRITE, - ARG_VADJUSTMENT); + ARG_SELECTION_MODE); + gtk_object_add_arg_type ("GtkCList::row_height", + GTK_TYPE_UINT, + GTK_ARG_READWRITE, + ARG_ROW_HEIGHT); + + object_class->set_arg = gtk_clist_set_arg; + object_class->get_arg = gtk_clist_get_arg; + object_class->destroy = gtk_clist_destroy; + object_class->finalize = gtk_clist_finalize; + + + widget_class->scroll_adjustments_signal = + gtk_signal_new ("scroll_adjustments", + GTK_RUN_LAST, + object_class->type, + GTK_SIGNAL_OFFSET (GtkCListClass, scroll_adjustments), + gtk_marshal_NONE__POINTER_POINTER, + GTK_TYPE_NONE, 2, GTK_TYPE_ADJUSTMENT, GTK_TYPE_ADJUSTMENT); clist_signals[SELECT_ROW] = gtk_signal_new ("select_row", @@ -533,15 +560,8 @@ gtk_clist_class_init (GtkCListClass *klass) GTK_SIGNAL_OFFSET (GtkCListClass, abort_column_resize), gtk_marshal_NONE__NONE, GTK_TYPE_NONE, 0); - - gtk_object_class_add_signals (object_class, clist_signals, LAST_SIGNAL); - object_class->set_arg = gtk_clist_set_arg; - object_class->get_arg = gtk_clist_get_arg; - object_class->destroy = gtk_clist_destroy; - object_class->finalize = gtk_clist_finalize; - widget_class->realize = gtk_clist_realize; widget_class->unrealize = gtk_clist_unrealize; widget_class->map = gtk_clist_map; @@ -566,6 +586,7 @@ gtk_clist_class_init (GtkCListClass *klass) container_class->focus = gtk_clist_focus; container_class->set_focus_child = gtk_clist_set_focus_child; + klass->scroll_adjustments = gtk_clist_scroll_adjustments; klass->select_row = real_select_row; klass->unselect_row = real_unselect_row; klass->undo_selection = real_undo_selection; @@ -797,19 +818,22 @@ gtk_clist_set_arg (GtkObject *object, guint arg_id) { GtkCList *clist; - GtkAdjustment *adjustment; clist = GTK_CLIST (object); switch (arg_id) { - case ARG_HADJUSTMENT: - adjustment = GTK_VALUE_POINTER (*arg); - gtk_clist_set_hadjustment (clist, adjustment); + case ARG_N_COLUMNS: /* construct-only arg, only set when !GTK_CONSTRUCTED */ + gtk_clist_construct (clist, MAX (1, GTK_VALUE_UINT (*arg)), NULL); break; - case ARG_VADJUSTMENT: - adjustment = GTK_VALUE_POINTER (*arg); - gtk_clist_set_vadjustment (clist, adjustment); + case ARG_SHADOW_TYPE: + gtk_clist_set_shadow_type (clist, GTK_VALUE_ENUM (*arg)); + break; + case ARG_SELECTION_MODE: + gtk_clist_set_selection_mode (clist, GTK_VALUE_ENUM (*arg)); + break; + case ARG_ROW_HEIGHT: + gtk_clist_set_row_height (clist, GTK_VALUE_UINT (*arg)); break; default: break; @@ -827,11 +851,17 @@ gtk_clist_get_arg (GtkObject *object, switch (arg_id) { - case ARG_HADJUSTMENT: - GTK_VALUE_POINTER (*arg) = clist->hadjustment; + case ARG_N_COLUMNS: + GTK_VALUE_UINT (*arg) = clist->columns; break; - case ARG_VADJUSTMENT: - GTK_VALUE_POINTER (*arg) = clist->vadjustment; + case ARG_SHADOW_TYPE: + GTK_VALUE_ENUM (*arg) = clist->shadow_type; + break; + case ARG_SELECTION_MODE: + GTK_VALUE_ENUM (*arg) = clist->selection_mode; + break; + case ARG_ROW_HEIGHT: + GTK_VALUE_UINT (*arg) = GTK_CLIST_ROW_HEIGHT_SET (clist) ? clist->row_height : 0; break; default: arg->type = GTK_TYPE_INVALID; @@ -909,13 +939,13 @@ gtk_clist_construct (GtkCList *clist, gint columns, gchar *titles[]) { - int i; - g_return_if_fail (clist != NULL); g_return_if_fail (GTK_IS_CLIST (clist)); - g_return_if_fail (GTK_CLIST_CONSTRUCTED (clist) == FALSE); + g_return_if_fail (columns > 0); + g_return_if_fail (GTK_OBJECT_CONSTRUCTED (clist) == FALSE); - GTK_CLIST_SET_FLAG (clist, CLIST_CONSTRUCTED); + /* mark the object as constructed */ + gtk_object_constructed (GTK_OBJECT (clist)); /* initalize memory chunks, if this has not been done by any * possibly derived widget @@ -945,6 +975,8 @@ gtk_clist_construct (GtkCList *clist, if (titles) { + guint i; + GTK_CLIST_SET_FLAG (clist, CLIST_SHOW_TITLES); for (i = 0; i < columns; i++) gtk_clist_set_column_title (clist, i, titles[i]); @@ -965,17 +997,16 @@ gtk_clist_construct (GtkCList *clist, * gtk_clist_set_shadow_type * gtk_clist_set_border *** deprecated function *** * gtk_clist_set_selection_mode - * gtk_clist_set_policy * gtk_clist_freeze * gtk_clist_thaw */ -GtkWidget * +GtkWidget* gtk_clist_new (gint columns) { return gtk_clist_new_with_titles (columns, NULL); } -GtkWidget * +GtkWidget* gtk_clist_new_with_titles (gint columns, gchar *titles[]) { @@ -983,6 +1014,7 @@ gtk_clist_new_with_titles (gint columns, widget = gtk_type_new (GTK_TYPE_CLIST); gtk_clist_construct (GTK_CLIST (widget), columns, titles); + return widget; } @@ -1086,6 +1118,17 @@ gtk_clist_get_vadjustment (GtkCList *clist) return clist->vadjustment; } +static void +gtk_clist_scroll_adjustments (GtkCList *clist, + GtkAdjustment *hadjustment, + GtkAdjustment *vadjustment) +{ + if (clist->hadjustment != hadjustment) + gtk_clist_set_hadjustment (clist, hadjustment); + if (clist->vadjustment != vadjustment) + gtk_clist_set_vadjustment (clist, vadjustment); +} + void gtk_clist_set_shadow_type (GtkCList *clist, GtkShadowType type) @@ -1104,6 +1147,8 @@ void gtk_clist_set_border (GtkCList *clist, GtkShadowType border) { + g_message ("gtk_clist_set_border() is deprecated"); + gtk_clist_set_shadow_type (clist, border); } @@ -1140,15 +1185,6 @@ gtk_clist_set_selection_mode (GtkCList *clist, } } -void -gtk_clist_set_policy (GtkCList *clist, - GtkPolicyType vscrollbar_policy, - GtkPolicyType hscrollbar_policy) -{ - g_return_if_fail (clist != NULL); - g_return_if_fail (GTK_IS_CLIST (clist)); -} - void gtk_clist_freeze (GtkCList *clist) { @@ -1335,7 +1371,9 @@ gtk_clist_set_column_title (GtkCList *clist, break; } + gtk_widget_push_composite_child (); label = gtk_label_new (clist->column[column].title); + gtk_widget_pop_composite_child (); gtk_container_add (GTK_CONTAINER (alignment), label); gtk_container_add (GTK_CONTAINER (clist->column[column].button), alignment); gtk_widget_show (label); @@ -1959,7 +1997,9 @@ column_button_create (GtkCList *clist, { GtkWidget *button; + gtk_widget_push_composite_child (); button = clist->column[column].button = gtk_button_new (); + gtk_widget_pop_composite_child (); if (GTK_WIDGET_REALIZED (clist) && clist->title_window) gtk_widget_set_parent_window (clist->column[column].button, @@ -1995,25 +2035,38 @@ column_button_clicked (GtkWidget *widget, void gtk_clist_set_row_height (GtkCList *clist, - gint height) + guint height) { + GtkWidget *widget; + g_return_if_fail (clist != NULL); g_return_if_fail (GTK_IS_CLIST (clist)); - if (height > 0) - clist->row_height = height; - else - return; + widget = GTK_WIDGET (clist); + + if (height > 0) + { + clist->row_height = height; + GTK_CLIST_SET_FLAG (clist, CLIST_ROW_HEIGHT_SET); + } + else + { + GTK_CLIST_UNSET_FLAG (clist, CLIST_ROW_HEIGHT_SET); + clist->row_height = 0; + } - GTK_CLIST_SET_FLAG (clist, CLIST_ROW_HEIGHT_SET); - if (GTK_WIDGET_REALIZED (clist)) { - GdkFont *font; - - font = GTK_WIDGET (clist)->style->font; - clist->row_center_offset = (((height + font->ascent - font->descent - 1) - / 2) + 1.5); + if (!GTK_CLIST_ROW_HEIGHT_SET (clist)) + { + clist->row_height = (widget->style->font->ascent + + widget->style->font->descent + 1); + clist->row_center_offset = widget->style->font->ascent + 1.5; + } + else + clist->row_center_offset = 1.5 + (clist->row_height + + widget->style->font->ascent - + widget->style->font->descent - 1) / 2; } if (!GTK_CLIST_FROZEN (clist)) @@ -4077,11 +4130,13 @@ gtk_clist_destroy (GtkObject *object) /* unref adjustments */ if (clist->hadjustment) { + gtk_signal_disconnect_by_data (GTK_OBJECT (clist->hadjustment), clist); gtk_object_unref (GTK_OBJECT (clist->hadjustment)); clist->hadjustment = NULL; } if (clist->vadjustment) { + gtk_signal_disconnect_by_data (GTK_OBJECT (clist->vadjustment), clist); gtk_object_unref (GTK_OBJECT (clist->vadjustment)); clist->vadjustment = NULL; } diff --git a/gtk/gtkclist.h b/gtk/gtkclist.h index c9948abd29..5ca8f5af2f 100644 --- a/gtk/gtkclist.h +++ b/gtk/gtkclist.h @@ -41,11 +41,10 @@ enum GTK_CLIST_DRAG_SELECTION = 1 << 2, GTK_CLIST_ROW_HEIGHT_SET = 1 << 3, GTK_CLIST_SHOW_TITLES = 1 << 4, - GTK_CLIST_CONSTRUCTED = 1 << 5, - GTK_CLIST_CHILD_HAS_FOCUS = 1 << 6, - GTK_CLIST_ADD_MODE = 1 << 7, - GTK_CLIST_AUTO_SORT = 1 << 8, - GTK_CLIST_AUTO_RESIZE_BLOCKED = 1 << 9 + GTK_CLIST_CHILD_HAS_FOCUS = 1 << 5, + GTK_CLIST_ADD_MODE = 1 << 6, + GTK_CLIST_AUTO_SORT = 1 << 7, + GTK_CLIST_AUTO_RESIZE_BLOCKED = 1 << 8 }; /* cell types */ @@ -72,7 +71,6 @@ typedef enum #define GTK_CLIST_IN_DRAG(clist) (GTK_CLIST_FLAGS (clist) & GTK_CLIST_IN_DRAG) #define GTK_CLIST_ROW_HEIGHT_SET(clist) (GTK_CLIST_FLAGS (clist) & GTK_CLIST_ROW_HEIGHT_SET) #define GTK_CLIST_SHOW_TITLES(clist) (GTK_CLIST_FLAGS (clist) & GTK_CLIST_SHOW_TITLES) -#define GTK_CLIST_CONSTRUCTED(clist) (GTK_CLIST_FLAGS (clist) & GTK_CLIST_CONSTRUCTED) #define GTK_CLIST_CHILD_HAS_FOCUS(clist) (GTK_CLIST_FLAGS (clist) & GTK_CLIST_CHILD_HAS_FOCUS) #define GTK_CLIST_DRAG_SELECTION(clist) (GTK_CLIST_FLAGS (clist) & GTK_CLIST_DRAG_SELECTION) #define GTK_CLIST_ADD_MODE(clist) (GTK_CLIST_FLAGS (clist) & GTK_CLIST_ADD_MODE) @@ -191,6 +189,9 @@ struct _GtkCListClass { GtkContainerClass parent_class; + void (*scroll_adjustments) (GtkCList *clist, + GtkAdjustment *hadjustment, + GtkAdjustment *vadjustment); void (*select_row) (GtkCList *clist, gint row, gint column, @@ -374,7 +375,7 @@ struct _GtkCell GtkType gtk_clist_get_type (void); -/* constructers useful for gtk-- wrappers */ +/* constructors useful for gtk-- wrappers */ void gtk_clist_construct (GtkCList *clist, gint columns, gchar *titles[]); @@ -482,11 +483,11 @@ void gtk_clist_set_column_max_width (GtkCList *clist, gint column, gint max_width); -/* change the height of the rows, the default is the hight - * of the current font +/* change the height of the rows, the default (height=0) is + * the hight of the current font. */ void gtk_clist_set_row_height (GtkCList *clist, - gint height); + guint height); /* scroll the viewing area of the list to the given column and row; * row_align and col_align are between 0-1 representing the location the @@ -705,10 +706,6 @@ void gtk_clist_set_auto_sort (GtkCList *clist, void gtk_clist_set_border (GtkCList *clist, GtkShadowType border); -/* Completely non-functional */ -void gtk_clist_set_policy (GtkCList *clist, - GtkPolicyType vscrollbar_policy, - GtkPolicyType hscrollbar_policy); #ifdef __cplusplus } #endif /* __cplusplus */ diff --git a/gtk/gtkcombo.c b/gtk/gtkcombo.c index 8da37ca154..6275c1f44b 100644 --- a/gtk/gtkcombo.c +++ b/gtk/gtkcombo.c @@ -302,14 +302,14 @@ gtk_combo_get_pos (GtkCombo * combo, gint * x, gint * y, gint * height, gint * w 2 * popwin->child->style->klass->xthickness - 2 * GTK_CONTAINER (popwin->child)->border_width - 2 * GTK_CONTAINER (combo->popup)->border_width - - 2 * GTK_CONTAINER (popup->viewport)->border_width - - 2 * popup->viewport->style->klass->xthickness); + 2 * GTK_CONTAINER (popup->child)->border_width - + 2 * popup->child->style->klass->xthickness); work_height = (2 * popwin->child->style->klass->ythickness + 2 * GTK_CONTAINER (popwin->child)->border_width + 2 * GTK_CONTAINER (combo->popup)->border_width + - 2 * GTK_CONTAINER (popup->viewport)->border_width + - 2 * popup->viewport->style->klass->xthickness); + 2 * GTK_CONTAINER (popup->child)->border_width + + 2 * popup->child->style->klass->xthickness); do { @@ -694,7 +694,7 @@ gtk_combo_init (GtkCombo * combo) gtk_widget_set_events (combo->list, GDK_ENTER_NOTIFY_MASK); gtk_list_set_selection_mode(GTK_LIST(combo->list), GTK_SELECTION_BROWSE); - gtk_container_add (GTK_CONTAINER (combo->popup), combo->list); + gtk_scrolled_window_add_with_viewport (GTK_SCROLLED_WINDOW (combo->popup), combo->list); gtk_container_set_focus_vadjustment (GTK_CONTAINER (combo->list), gtk_scrolled_window_get_vadjustment (GTK_SCROLLED_WINDOW (combo->popup))); gtk_container_set_focus_hadjustment (GTK_CONTAINER (combo->list), diff --git a/gtk/gtkcontainer.c b/gtk/gtkcontainer.c index e430da3b74..881471ca7d 100644 --- a/gtk/gtkcontainer.c +++ b/gtk/gtkcontainer.c @@ -248,6 +248,7 @@ gtk_container_add_with_args (GtkContainer *container, g_return_if_fail (widget != NULL); g_return_if_fail (GTK_IS_WIDGET (widget)); g_return_if_fail (widget->parent == NULL); + g_return_if_fail (GTK_OBJECT_CONSTRUCTED (container) == TRUE); gtk_widget_ref (GTK_WIDGET (container)); gtk_widget_ref (widget); @@ -306,6 +307,7 @@ gtk_container_addv (GtkContainer *container, g_return_if_fail (widget != NULL); g_return_if_fail (GTK_IS_WIDGET (widget)); g_return_if_fail (widget->parent == NULL); + g_return_if_fail (GTK_OBJECT_CONSTRUCTED (container) == TRUE); gtk_widget_ref (GTK_WIDGET (container)); gtk_widget_ref (widget); @@ -690,6 +692,7 @@ gtk_container_add (GtkContainer *container, g_return_if_fail (widget != NULL); g_return_if_fail (GTK_IS_WIDGET (widget)); g_return_if_fail (widget->parent == NULL); + g_return_if_fail (GTK_OBJECT_CONSTRUCTED (container) == TRUE); gtk_signal_emit (GTK_OBJECT (container), container_signals[ADD], widget); } @@ -707,24 +710,13 @@ gtk_container_remove (GtkContainer *container, gtk_signal_emit (GTK_OBJECT (container), container_signals[REMOVE], widget); } -void -gtk_container_disable_resize (GtkContainer *container) -{ - g_warning ("gtk_container_disable_resize does nothing!"); -} - -void -gtk_container_enable_resize (GtkContainer *container) -{ - g_warning ("gtk_container_enable_resize does nothing!"); -} - void gtk_container_block_resize (GtkContainer *container) { g_return_if_fail (container != NULL); g_return_if_fail (GTK_IS_CONTAINER (container)); + g_message ("gtk_container_block_resize() is deprecated"); } void @@ -733,6 +725,7 @@ gtk_container_unblock_resize (GtkContainer *container) g_return_if_fail (container != NULL); g_return_if_fail (GTK_IS_CONTAINER (container)); + g_message ("gtk_container_unblock_resize() is deprecated"); } void @@ -791,6 +784,8 @@ gtk_container_set_resize_mode (GtkContainer *container, gint gtk_container_need_resize (GtkContainer *container) { + g_message ("gtk_container_need_resize() is deprecated"); + gtk_container_check_resize (container); return FALSE; } diff --git a/gtk/gtkcontainer.h b/gtk/gtkcontainer.h index d14955c07b..285b4a4da4 100644 --- a/gtk/gtkcontainer.h +++ b/gtk/gtkcontainer.h @@ -215,10 +215,6 @@ void gtk_container_forall (GtkContainer *container, /* Deprecated methods */ -/* Completely non-functional */ -void gtk_container_disable_resize (GtkContainer *container); -void gtk_container_enable_resize (GtkContainer *container); - /* Use gtk_container_set_resize_mode() instead */ void gtk_container_block_resize (GtkContainer *container); void gtk_container_unblock_resize (GtkContainer *container); diff --git a/gtk/gtkctree.c b/gtk/gtkctree.c index 140c8a4f23..3e824de29d 100644 --- a/gtk/gtkctree.c +++ b/gtk/gtkctree.c @@ -46,9 +46,28 @@ #define GTK_CLIST_CLASS_FW(_widget_) GTK_CLIST_CLASS (GTK_OBJECT (_widget_)->klass) +enum { + ARG_0, + ARG_N_COLUMNS, + ARG_TREE_COLUMN, + ARG_INDENT, + ARG_SPACING, + ARG_SHOW_STUB, + ARG_REORDERABLE, + ARG_USE_DRAG_ICONS, + ARG_LINE_STYLE, + ARG_EXPANDER_STYLE +}; + static void gtk_ctree_class_init (GtkCTreeClass *klass); static void gtk_ctree_init (GtkCTree *ctree); +static void gtk_ctree_set_arg (GtkObject *object, + GtkArg *arg, + guint arg_id); +static void gtk_ctree_get_arg (GtkObject *object, + GtkArg *arg, + guint arg_id); static void gtk_ctree_realize (GtkWidget *widget); static void gtk_ctree_unrealize (GtkWidget *widget); static gint gtk_ctree_button_press (GtkWidget *widget, @@ -306,6 +325,45 @@ gtk_ctree_class_init (GtkCTreeClass *klass) parent_class = gtk_type_class (GTK_TYPE_CLIST); container_class = gtk_type_class (GTK_TYPE_CONTAINER); + gtk_object_add_arg_type ("GtkCTree::n_columns", + GTK_TYPE_UINT, + GTK_ARG_READWRITE | GTK_ARG_CONSTRUCT_ONLY, + ARG_N_COLUMNS); + gtk_object_add_arg_type ("GtkCTree::tree_column", + GTK_TYPE_UINT, + GTK_ARG_READWRITE | GTK_ARG_CONSTRUCT_ONLY, + ARG_TREE_COLUMN); + gtk_object_add_arg_type ("GtkCTree::indent", + GTK_TYPE_UINT, + GTK_ARG_READWRITE, + ARG_INDENT); + gtk_object_add_arg_type ("GtkCTree::spacing", + GTK_TYPE_UINT, + GTK_ARG_READWRITE, + ARG_SPACING); + gtk_object_add_arg_type ("GtkCTree::show_stub", + GTK_TYPE_BOOL, + GTK_ARG_READWRITE, + ARG_SHOW_STUB); + gtk_object_add_arg_type ("GtkCTree::reorderable", + GTK_TYPE_BOOL, + GTK_ARG_READWRITE, + ARG_REORDERABLE); + gtk_object_add_arg_type ("GtkCTree::use_drag_icons", + GTK_TYPE_BOOL, + GTK_ARG_READWRITE, + ARG_USE_DRAG_ICONS); + gtk_object_add_arg_type ("GtkCTree::line_style", + GTK_TYPE_C_TREE_LINE_STYLE, + GTK_ARG_READWRITE, + ARG_LINE_STYLE); + gtk_object_add_arg_type ("GtkCTree::expander_style", + GTK_TYPE_C_TREE_EXPANDER_STYLE, + GTK_ARG_READWRITE, + ARG_EXPANDER_STYLE); + object_class->set_arg = gtk_ctree_set_arg; + object_class->get_arg = gtk_ctree_get_arg; + ctree_signals[TREE_SELECT_ROW] = gtk_signal_new ("tree_select_row", GTK_RUN_FIRST, @@ -350,7 +408,6 @@ gtk_ctree_class_init (GtkCTreeClass *klass) change_focus_row_expansion), gtk_marshal_NONE__ENUM, GTK_TYPE_NONE, 1, GTK_TYPE_C_TREE_EXPANSION_TYPE); - gtk_object_class_add_signals (object_class, ctree_signals, LAST_SIGNAL); widget_class->realize = gtk_ctree_realize; @@ -430,6 +487,104 @@ gtk_ctree_class_init (GtkCTreeClass *klass) } +static void +gtk_ctree_set_arg (GtkObject *object, + GtkArg *arg, + guint arg_id) +{ + GtkCTree *ctree; + + ctree = GTK_CTREE (object); + + switch (arg_id) + { + case ARG_N_COLUMNS: /* construct-only arg, only set when !GTK_CONSTRUCTED */ + if (ctree->tree_column) + gtk_ctree_construct (ctree, + MAX (1, GTK_VALUE_UINT (*arg)), + ctree->tree_column, NULL); + else + GTK_CLIST (ctree)->columns = MAX (1, GTK_VALUE_UINT (*arg)); + break; + case ARG_TREE_COLUMN: /* construct-only arg, only set when !GTK_CONSTRUCTED */ + if (GTK_CLIST (ctree)->columns) + gtk_ctree_construct (ctree, + GTK_CLIST (ctree)->columns, + MAX (1, GTK_VALUE_UINT (*arg)), + NULL); + else + ctree->tree_column = MAX (1, GTK_VALUE_UINT (*arg)); + break; + case ARG_INDENT: + gtk_ctree_set_indent (ctree, GTK_VALUE_UINT (*arg)); + break; + case ARG_SPACING: + gtk_ctree_set_spacing (ctree, GTK_VALUE_UINT (*arg)); + break; + case ARG_SHOW_STUB: + gtk_ctree_set_show_stub (ctree, GTK_VALUE_BOOL (*arg)); + break; + case ARG_REORDERABLE: + gtk_ctree_set_reorderable (ctree, GTK_VALUE_BOOL (*arg)); + break; + case ARG_USE_DRAG_ICONS: + gtk_ctree_set_use_drag_icons (ctree, GTK_VALUE_BOOL (*arg)); + break; + case ARG_LINE_STYLE: + gtk_ctree_set_line_style (ctree, GTK_VALUE_ENUM (*arg)); + break; + case ARG_EXPANDER_STYLE: + gtk_ctree_set_expander_style (ctree, GTK_VALUE_ENUM (*arg)); + break; + default: + break; + } +} + +static void +gtk_ctree_get_arg (GtkObject *object, + GtkArg *arg, + guint arg_id) +{ + GtkCTree *ctree; + + ctree = GTK_CTREE (object); + + switch (arg_id) + { + case ARG_N_COLUMNS: + GTK_VALUE_UINT (*arg) = GTK_CLIST (ctree)->columns; + break; + case ARG_TREE_COLUMN: + GTK_VALUE_UINT (*arg) = ctree->tree_column; + break; + case ARG_INDENT: + GTK_VALUE_UINT (*arg) = ctree->tree_indent; + break; + case ARG_SPACING: + GTK_VALUE_UINT (*arg) = ctree->tree_spacing; + break; + case ARG_SHOW_STUB: + GTK_VALUE_BOOL (*arg) = ctree->show_stub; + break; + case ARG_REORDERABLE: + GTK_VALUE_BOOL (*arg) = ctree->reorderable; + break; + case ARG_USE_DRAG_ICONS: + GTK_VALUE_BOOL (*arg) = ctree->use_icons; + break; + case ARG_LINE_STYLE: + GTK_VALUE_ENUM (*arg) = ctree->line_style; + break; + case ARG_EXPANDER_STYLE: + GTK_VALUE_ENUM (*arg) = ctree->expander_style; + break; + default: + arg->type = GTK_TYPE_INVALID; + break; + } +} + static void gtk_ctree_init (GtkCTree *ctree) { @@ -3734,7 +3889,7 @@ gtk_ctree_construct (GtkCTree *ctree, g_return_if_fail (ctree != NULL); g_return_if_fail (GTK_IS_CTREE (ctree)); - g_return_if_fail (GTK_CLIST_CONSTRUCTED (ctree) == FALSE); + g_return_if_fail (GTK_OBJECT_CONSTRUCTED (ctree) == FALSE); clist = GTK_CLIST (ctree); @@ -3767,6 +3922,7 @@ gtk_ctree_new_with_titles (gint columns, widget = gtk_type_new (GTK_TYPE_CTREE); gtk_ctree_construct (GTK_CTREE (widget), columns, tree_column, titles); + return widget; } @@ -5482,8 +5638,16 @@ gtk_ctree_set_spacing (GtkCTree *ctree, } void -gtk_ctree_show_stub (GtkCTree *ctree, +gtk_ctree_show_stub (GtkCTree *ctree, gboolean show_stub) +{ + g_message ("gtk_ctree_show_stub() is deprecated"); + gtk_ctree_set_show_stub (ctree, show_stub); +} + +void +gtk_ctree_set_show_stub (GtkCTree *ctree, + gboolean show_stub) { g_return_if_fail (ctree != NULL); g_return_if_fail (GTK_IS_CTREE (ctree)); diff --git a/gtk/gtkctree.h b/gtk/gtkctree.h index 2d7dddaa5b..141316a14d 100644 --- a/gtk/gtkctree.h +++ b/gtk/gtkctree.h @@ -416,7 +416,7 @@ void gtk_ctree_set_indent (GtkCTree *ctree, gint indent); void gtk_ctree_set_spacing (GtkCTree *ctree, gint spacing); -void gtk_ctree_show_stub (GtkCTree *ctree, +void gtk_ctree_set_show_stub (GtkCTree *ctree, gboolean show_stub); void gtk_ctree_set_reorderable (GtkCTree *ctree, gboolean reorderable); @@ -437,6 +437,14 @@ void gtk_ctree_sort_node (GtkCTree *ctree, GtkCTreeNode *node); void gtk_ctree_sort_recursive (GtkCTree *ctree, GtkCTreeNode *node); + + +/* deprecated*/ +void gtk_ctree_show_stub (GtkCTree *ctree, + gboolean show_stub); + + + #ifdef __cplusplus } #endif /* __cplusplus */ diff --git a/gtk/gtkdrawingarea.c b/gtk/gtkdrawingarea.c index b6c525bb8f..3a67328764 100644 --- a/gtk/gtkdrawingarea.c +++ b/gtk/gtkdrawingarea.c @@ -66,8 +66,6 @@ gtk_drawing_area_class_init (GtkDrawingAreaClass *class) static void gtk_drawing_area_init (GtkDrawingArea *darea) { - GTK_WIDGET_SET_FLAGS (darea, GTK_BASIC); - darea->draw_data = NULL; } diff --git a/gtk/gtkeventbox.c b/gtk/gtkeventbox.c index d99f288ba6..8cb5000116 100644 --- a/gtk/gtkeventbox.c +++ b/gtk/gtkeventbox.c @@ -76,7 +76,6 @@ static void gtk_event_box_init (GtkEventBox *event_box) { GTK_WIDGET_UNSET_FLAGS (event_box, GTK_NO_WINDOW); - GTK_WIDGET_SET_FLAGS (event_box, GTK_BASIC); } GtkWidget* diff --git a/gtk/gtkfixed.c b/gtk/gtkfixed.c index 799d9159d2..e2b9869292 100644 --- a/gtk/gtkfixed.c +++ b/gtk/gtkfixed.c @@ -108,7 +108,6 @@ static void gtk_fixed_init (GtkFixed *fixed) { GTK_WIDGET_UNSET_FLAGS (fixed, GTK_NO_WINDOW); - GTK_WIDGET_SET_FLAGS (fixed, GTK_BASIC); fixed->children = NULL; } diff --git a/gtk/gtkframe.c b/gtk/gtkframe.c index 93414fa113..f817e31b44 100644 --- a/gtk/gtkframe.c +++ b/gtk/gtkframe.c @@ -109,8 +109,6 @@ gtk_frame_class_init (GtkFrameClass *class) static void gtk_frame_init (GtkFrame *frame) { - GTK_WIDGET_SET_FLAGS (frame, GTK_BASIC); - frame->label = NULL; frame->shadow_type = GTK_SHADOW_ETCHED_IN; frame->label_width = 0; diff --git a/gtk/gtkhandlebox.c b/gtk/gtkhandlebox.c index 52df83c60e..efc4ad6ca9 100644 --- a/gtk/gtkhandlebox.c +++ b/gtk/gtkhandlebox.c @@ -173,7 +173,6 @@ static void gtk_handle_box_init (GtkHandleBox *handle_box) { GTK_WIDGET_UNSET_FLAGS (handle_box, GTK_NO_WINDOW); - GTK_WIDGET_SET_FLAGS (handle_box, GTK_BASIC); /* FIXME: are we really a basic widget? */ handle_box->bin_window = NULL; handle_box->float_window = NULL; diff --git a/gtk/gtkhbox.h b/gtk/gtkhbox.h index 88b61d9ada..5a326133d7 100644 --- a/gtk/gtkhbox.h +++ b/gtk/gtkhbox.h @@ -29,11 +29,11 @@ extern "C" { #endif /* __cplusplus */ -#define GTK_TYPE_HBOX (gtk_hbox_get_type ()) -#define GTK_HBOX(obj) (GTK_CHECK_CAST ((obj), GTK_TYPE_HBOX, GtkHBox)) -#define GTK_HBOX_CLASS(klass) (GTK_CHECK_CLASS_CAST ((klass), GTK_TYPE_HBOX, GtkHBoxClass)) -#define GTK_IS_HBOX(obj) (GTK_CHECK_TYPE ((obj), GTK_TYPE_HBOX)) -#define GTK_IS_HBOX_CLASS(klass) (GTK_CHECK_CLASS_TYPE ((klass), GTK_TYPE_HBOX)) +#define GTK_TYPE_HBOX (gtk_hbox_get_type ()) +#define GTK_HBOX(obj) (GTK_CHECK_CAST ((obj), GTK_TYPE_HBOX, GtkHBox)) +#define GTK_HBOX_CLASS(klass) (GTK_CHECK_CLASS_CAST ((klass), GTK_TYPE_HBOX, GtkHBoxClass)) +#define GTK_IS_HBOX(obj) (GTK_CHECK_TYPE ((obj), GTK_TYPE_HBOX)) +#define GTK_IS_HBOX_CLASS(klass) (GTK_CHECK_CLASS_TYPE ((klass), GTK_TYPE_HBOX)) typedef struct _GtkHBox GtkHBox; diff --git a/gtk/gtkhscale.c b/gtk/gtkhscale.c index e4559fb12c..037d9b00f2 100644 --- a/gtk/gtkhscale.c +++ b/gtk/gtkhscale.c @@ -25,85 +25,144 @@ #define SCALE_CLASS(w) GTK_SCALE_CLASS (GTK_OBJECT (w)->klass) #define RANGE_CLASS(w) GTK_RANGE_CLASS (GTK_OBJECT (w)->klass) +enum { + ARG_0, + ARG_ADJUSTMENT, +}; static void gtk_hscale_class_init (GtkHScaleClass *klass); static void gtk_hscale_init (GtkHScale *hscale); +static void gtk_hscale_set_arg (GtkObject *object, + GtkArg *arg, + guint arg_id); +static void gtk_hscale_get_arg (GtkObject *object, + GtkArg *arg, + guint arg_id); static void gtk_hscale_realize (GtkWidget *widget); static void gtk_hscale_size_request (GtkWidget *widget, - GtkRequisition *requisition); + GtkRequisition *requisition); static void gtk_hscale_size_allocate (GtkWidget *widget, - GtkAllocation *allocation); + GtkAllocation *allocation); static void gtk_hscale_pos_trough (GtkHScale *hscale, - gint *x, - gint *y, - gint *w, - gint *h); + gint *x, + gint *y, + gint *w, + gint *h); static void gtk_hscale_pos_background (GtkHScale *hscale, - gint *x, - gint *y, - gint *w, - gint *h); + gint *x, + gint *y, + gint *w, + gint *h); static void gtk_hscale_draw_slider (GtkRange *range); static void gtk_hscale_draw_value (GtkScale *scale); static void gtk_hscale_draw (GtkWidget *widget, - GdkRectangle *area); + GdkRectangle *area); static gint gtk_hscale_trough_keys (GtkRange *range, - GdkEventKey *key, - GtkScrollType *scroll, - GtkTroughType *pos); + GdkEventKey *key, + GtkScrollType *scroll, + GtkTroughType *pos); static void gtk_hscale_clear_background (GtkRange *range); -guint +GtkType gtk_hscale_get_type (void) { - static guint hscale_type = 0; - + static GtkType hscale_type = 0; + if (!hscale_type) { GtkTypeInfo hscale_info = { - "GtkHScale", - sizeof (GtkHScale), - sizeof (GtkHScaleClass), - (GtkClassInitFunc) gtk_hscale_class_init, - (GtkObjectInitFunc) gtk_hscale_init, - /* reserved_1 */ NULL, + "GtkHScale", + sizeof (GtkHScale), + sizeof (GtkHScaleClass), + (GtkClassInitFunc) gtk_hscale_class_init, + (GtkObjectInitFunc) gtk_hscale_init, + /* reserved_1 */ NULL, /* reserved_2 */ NULL, (GtkClassInitFunc) NULL, }; - - hscale_type = gtk_type_unique (gtk_scale_get_type (), &hscale_info); + + hscale_type = gtk_type_unique (GTK_TYPE_SCALE, &hscale_info); } - + return hscale_type; } static void gtk_hscale_class_init (GtkHScaleClass *class) { + GtkObjectClass *object_class; GtkWidgetClass *widget_class; GtkRangeClass *range_class; GtkScaleClass *scale_class; - + + object_class = (GtkObjectClass*) class; widget_class = (GtkWidgetClass*) class; range_class = (GtkRangeClass*) class; scale_class = (GtkScaleClass*) class; - + + gtk_object_add_arg_type ("GtkHScale::adjustment", + GTK_TYPE_ADJUSTMENT, + GTK_ARG_READWRITE | GTK_ARG_CONSTRUCT, + ARG_ADJUSTMENT); + + object_class->set_arg = gtk_hscale_set_arg; + object_class->get_arg = gtk_hscale_get_arg; + widget_class->realize = gtk_hscale_realize; widget_class->size_request = gtk_hscale_size_request; widget_class->size_allocate = gtk_hscale_size_allocate; widget_class->draw = gtk_hscale_draw; - + range_class->slider_update = gtk_range_default_hslider_update; range_class->trough_click = gtk_range_default_htrough_click; range_class->motion = gtk_range_default_hmotion; range_class->draw_slider = gtk_hscale_draw_slider; range_class->trough_keys = gtk_hscale_trough_keys; range_class->clear_background = gtk_hscale_clear_background; - + scale_class->draw_value = gtk_hscale_draw_value; } +static void +gtk_hscale_set_arg (GtkObject *object, + GtkArg *arg, + guint arg_id) +{ + GtkHScale *hscale; + + hscale = GTK_HSCALE (object); + + switch (arg_id) + { + case ARG_ADJUSTMENT: + gtk_range_set_adjustment (GTK_RANGE (hscale), GTK_VALUE_POINTER (*arg)); + break; + default: + break; + } +} + +static void +gtk_hscale_get_arg (GtkObject *object, + GtkArg *arg, + guint arg_id) +{ + GtkHScale *hscale; + + hscale = GTK_HSCALE (object); + + switch (arg_id) + { + case ARG_ADJUSTMENT: + GTK_VALUE_POINTER (*arg) = GTK_RANGE (hscale); + break; + default: + arg->type = GTK_TYPE_INVALID; + break; + } +} + static void gtk_hscale_init (GtkHScale *hscale) { @@ -113,16 +172,13 @@ gtk_hscale_init (GtkHScale *hscale) GtkWidget* gtk_hscale_new (GtkAdjustment *adjustment) { - GtkHScale *hscale; + GtkWidget *hscale; + + hscale = gtk_widget_new (GTK_TYPE_HSCALE, + "adjustment", adjustment, + NULL); - hscale = gtk_type_new (gtk_hscale_get_type ()); - - if (!adjustment) - adjustment = (GtkAdjustment*) gtk_adjustment_new (0.0, 0.0, 0.0, 0.0, 0.0, 0.0); - - gtk_range_set_adjustment (GTK_RANGE (hscale), adjustment); - - return GTK_WIDGET (hscale); + return hscale; } @@ -133,17 +189,18 @@ gtk_hscale_realize (GtkWidget *widget) GdkWindowAttr attributes; gint attributes_mask; gint x, y, w, h; - + g_return_if_fail (widget != NULL); g_return_if_fail (GTK_IS_HSCALE (widget)); - + GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED); range = GTK_RANGE (widget); - + widget->window = gtk_widget_get_parent_window (widget); gdk_window_ref (widget->window); - + gtk_hscale_pos_trough (GTK_HSCALE (widget), &x, &y, &w, &h); + attributes.x = x + widget->allocation.x; attributes.y = y + widget->allocation.y; attributes.width = w; @@ -152,79 +209,79 @@ gtk_hscale_realize (GtkWidget *widget) attributes.window_type = GDK_WINDOW_CHILD; attributes.event_mask = gtk_widget_get_events (widget) | - (GDK_EXPOSURE_MASK | - GDK_BUTTON_PRESS_MASK | - GDK_BUTTON_RELEASE_MASK | - GDK_ENTER_NOTIFY_MASK | - GDK_LEAVE_NOTIFY_MASK); + (GDK_EXPOSURE_MASK | + GDK_BUTTON_PRESS_MASK | + GDK_BUTTON_RELEASE_MASK | + GDK_ENTER_NOTIFY_MASK | + GDK_LEAVE_NOTIFY_MASK); attributes.visual = gtk_widget_get_visual (widget); attributes.colormap = gtk_widget_get_colormap (widget); - + attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP; - + range->trough = gdk_window_new (widget->window, &attributes, attributes_mask); - + attributes.width = SCALE_CLASS (range)->slider_length; attributes.height = RANGE_CLASS (range)->slider_width; attributes.event_mask |= (GDK_BUTTON_MOTION_MASK | - GDK_POINTER_MOTION_HINT_MASK); - + GDK_POINTER_MOTION_HINT_MASK); + range->slider = gdk_window_new (range->trough, &attributes, attributes_mask); - + widget->style = gtk_style_attach (widget->style, widget->window); - + gdk_window_set_user_data (range->trough, widget); gdk_window_set_user_data (range->slider, widget); - + gtk_style_set_background (widget->style, range->trough, GTK_STATE_ACTIVE); gtk_style_set_background (widget->style, range->slider, GTK_STATE_NORMAL); - + gtk_range_slider_update (GTK_RANGE (widget)); - + gdk_window_show (range->slider); } static void gtk_hscale_draw (GtkWidget *widget, - GdkRectangle *area) + GdkRectangle *area) { GtkRange *range; GdkRectangle tmp_area; GdkRectangle child_area; gint x, y, width, height; - + g_return_if_fail (widget != NULL); g_return_if_fail (GTK_IS_RANGE (widget)); g_return_if_fail (area != NULL); - + if (GTK_WIDGET_VISIBLE (widget) && GTK_WIDGET_MAPPED (widget)) { range = GTK_RANGE (widget); - + gtk_hscale_pos_background (GTK_HSCALE (widget), &x, &y, &width, &height); - + tmp_area.x = x; tmp_area.y = y; tmp_area.width = width; tmp_area.height = height; - + if (gdk_rectangle_intersect (area, &tmp_area, &child_area)) - gtk_range_draw_background (range); - + gtk_range_draw_background (range); + gtk_hscale_pos_trough (GTK_HSCALE (widget), &x, &y, &width, &height); - + tmp_area.x = x; tmp_area.y = y; tmp_area.width = width; tmp_area.height = height; - + if (gdk_rectangle_intersect (area, &tmp_area, &child_area)) - { - gtk_range_draw_trough (range); - gtk_range_draw_slider (range); - gtk_range_draw_step_forw (range); - gtk_range_draw_step_back (range); - } + { + gtk_range_draw_trough (range); + gtk_range_draw_slider (range); + gtk_range_draw_step_forw (range); + gtk_range_draw_step_back (range); + } } } @@ -233,129 +290,129 @@ gtk_hscale_clear_background (GtkRange *range) { GtkWidget *widget; gint x, y, width, height; - + g_return_if_fail (range != NULL); - + widget = GTK_WIDGET (range); gtk_hscale_pos_background (GTK_HSCALE (range), &x, &y, &width, &height); - + gtk_widget_queue_clear_area (GTK_WIDGET (range), - x, y, width, height); + x, y, width, height); } static void gtk_hscale_size_request (GtkWidget *widget, - GtkRequisition *requisition) + GtkRequisition *requisition) { GtkScale *scale; gint value_width; - + g_return_if_fail (widget != NULL); g_return_if_fail (GTK_IS_HSCALE (widget)); g_return_if_fail (requisition != NULL); - + scale = GTK_SCALE (widget); - + requisition->width = (SCALE_CLASS (scale)->slider_length + - widget->style->klass->xthickness) * 2; + widget->style->klass->xthickness) * 2; requisition->height = (RANGE_CLASS (scale)->slider_width + - widget->style->klass->ythickness * 2); - + widget->style->klass->ythickness * 2); + if (scale->draw_value) { value_width = gtk_scale_value_width (scale); - + if ((scale->value_pos == GTK_POS_LEFT) || - (scale->value_pos == GTK_POS_RIGHT)) - { - requisition->width += value_width + SCALE_CLASS (scale)->value_spacing; - if (requisition->height < (widget->style->font->ascent + widget->style->font->descent)) - requisition->height = widget->style->font->ascent + widget->style->font->descent; - } + (scale->value_pos == GTK_POS_RIGHT)) + { + requisition->width += value_width + SCALE_CLASS (scale)->value_spacing; + if (requisition->height < (widget->style->font->ascent + widget->style->font->descent)) + requisition->height = widget->style->font->ascent + widget->style->font->descent; + } else if ((scale->value_pos == GTK_POS_TOP) || - (scale->value_pos == GTK_POS_BOTTOM)) - { - if (requisition->width < value_width) - requisition->width = value_width; - requisition->height += widget->style->font->ascent + widget->style->font->descent; - } + (scale->value_pos == GTK_POS_BOTTOM)) + { + if (requisition->width < value_width) + requisition->width = value_width; + requisition->height += widget->style->font->ascent + widget->style->font->descent; + } } } static void gtk_hscale_size_allocate (GtkWidget *widget, - GtkAllocation *allocation) + GtkAllocation *allocation) { GtkRange *range; GtkScale *scale; gint width, height; gint x, y; - + g_return_if_fail (widget != NULL); g_return_if_fail (GTK_IS_HSCALE (widget)); g_return_if_fail (allocation != NULL); - + widget->allocation = *allocation; if (GTK_WIDGET_REALIZED (widget)) { range = GTK_RANGE (widget); scale = GTK_SCALE (widget); - + gtk_hscale_pos_trough (GTK_HSCALE (widget), &x, &y, &width, &height); - + gdk_window_move_resize (range->trough, - x + widget->allocation.x, - y + widget->allocation.y, width, height); + x + widget->allocation.x, + y + widget->allocation.y, width, height); gtk_range_slider_update (GTK_RANGE (widget)); } } static void gtk_hscale_pos_trough (GtkHScale *hscale, - gint *x, - gint *y, - gint *w, - gint *h) + gint *x, + gint *y, + gint *w, + gint *h) { GtkWidget *widget; GtkScale *scale; - + g_return_if_fail (hscale != NULL); g_return_if_fail (GTK_IS_HSCALE (hscale)); g_return_if_fail ((x != NULL) && (y != NULL) && (w != NULL) && (h != NULL)); - + widget = GTK_WIDGET (hscale); scale = GTK_SCALE (hscale); - + *w = widget->allocation.width; *h = (RANGE_CLASS (scale)->slider_width + - widget->style->klass->ythickness * 2); - + widget->style->klass->ythickness * 2); + if (scale->draw_value) { *x = 0; *y = 0; - + switch (scale->value_pos) - { - case GTK_POS_LEFT: - *x += gtk_scale_value_width (scale) + SCALE_CLASS (scale)->value_spacing; - *y = (widget->allocation.height - *h) / 2; - *w -= *x; - break; - case GTK_POS_RIGHT: - *w -= gtk_scale_value_width (scale) + SCALE_CLASS (scale)->value_spacing; - *y = (widget->allocation.height - *h) / 2; - break; - case GTK_POS_TOP: - *y = (widget->style->font->ascent + widget->style->font->descent + - (widget->allocation.height - widget->requisition.height) / 2); - break; - case GTK_POS_BOTTOM: - *y = (widget->allocation.height - widget->requisition.height) / 2; - break; - } + { + case GTK_POS_LEFT: + *x += gtk_scale_value_width (scale) + SCALE_CLASS (scale)->value_spacing; + *y = (widget->allocation.height - *h) / 2; + *w -= *x; + break; + case GTK_POS_RIGHT: + *w -= gtk_scale_value_width (scale) + SCALE_CLASS (scale)->value_spacing; + *y = (widget->allocation.height - *h) / 2; + break; + case GTK_POS_TOP: + *y = (widget->style->font->ascent + widget->style->font->descent + + (widget->allocation.height - widget->requisition.height) / 2); + break; + case GTK_POS_BOTTOM: + *y = (widget->allocation.height - widget->requisition.height) / 2; + break; + } } else { @@ -368,30 +425,30 @@ gtk_hscale_pos_trough (GtkHScale *hscale, static void gtk_hscale_pos_background (GtkHScale *hscale, - gint *x, - gint *y, - gint *w, - gint *h) + gint *x, + gint *y, + gint *w, + gint *h) { GtkWidget *widget; GtkScale *scale; - + gint tx, ty, twidth, theight; - + g_return_if_fail (hscale != NULL); g_return_if_fail (GTK_IS_HSCALE (hscale)); g_return_if_fail ((x != NULL) && (y != NULL) && (w != NULL) && (h != NULL)); - + gtk_hscale_pos_trough (hscale, &tx, &ty, &twidth, &theight); widget = GTK_WIDGET (hscale); scale = GTK_SCALE (hscale); - + *x = widget->allocation.x; *y = widget->allocation.y; *w = widget->allocation.width; *h = widget->allocation.height; - + switch (scale->value_pos) { case GTK_POS_LEFT: @@ -415,10 +472,10 @@ static void gtk_hscale_draw_slider (GtkRange *range) { GtkStateType state_type; - + g_return_if_fail (range != NULL); g_return_if_fail (GTK_IS_HSCALE (range)); - + if (range->slider) { if ((range->in_child == RANGE_CLASS (range)->slider) || @@ -426,8 +483,8 @@ gtk_hscale_draw_slider (GtkRange *range) state_type = GTK_STATE_PRELIGHT; else state_type = GTK_STATE_NORMAL; - - gtk_paint_slider(GTK_WIDGET (range)->style, range->slider, state_type, + + gtk_paint_slider (GTK_WIDGET (range)->style, range->slider, state_type, GTK_SHADOW_OUT, NULL, GTK_WIDGET (range), "hscale", 0, 0, -1, -1, @@ -444,76 +501,76 @@ gtk_hscale_draw_value (GtkScale *scale) gint text_width; gint width, height; gint x, y; - + g_return_if_fail (scale != NULL); g_return_if_fail (GTK_IS_HSCALE (scale)); - + widget = GTK_WIDGET (scale); if (scale->draw_value) { sprintf (buffer, "%0.*f", GTK_RANGE (scale)->digits, GTK_RANGE (scale)->adjustment->value); text_width = gdk_string_measure (GTK_WIDGET (scale)->style->font, buffer); - + switch (scale->value_pos) - { - case GTK_POS_LEFT: - gdk_window_get_position (GTK_RANGE (scale)->trough, &x, &y); - gdk_window_get_size (GTK_RANGE (scale)->trough, &width, &height); - - x -= SCALE_CLASS (scale)->value_spacing + text_width; - y += ((height - - (GTK_WIDGET (scale)->style->font->ascent + - GTK_WIDGET (scale)->style->font->descent)) / 2 + - GTK_WIDGET (scale)->style->font->ascent); - break; - case GTK_POS_RIGHT: - gdk_window_get_position (GTK_RANGE (scale)->trough, &x, &y); - gdk_window_get_size (GTK_RANGE (scale)->trough, &width, &height); - - x += width + SCALE_CLASS (scale)->value_spacing; - y += ((height - - (GTK_WIDGET (scale)->style->font->ascent + - GTK_WIDGET (scale)->style->font->descent)) / 2 + - GTK_WIDGET (scale)->style->font->ascent); - break; - case GTK_POS_TOP: - gdk_window_get_position (GTK_RANGE (scale)->slider, &x, NULL); - gdk_window_get_position (GTK_RANGE (scale)->trough, NULL, &y); - gdk_window_get_size (GTK_RANGE (scale)->slider, &width, NULL); - gdk_window_get_size (GTK_RANGE (scale)->trough, NULL, &height); - - x += widget->allocation.x + (width - text_width) / 2; - y -= GTK_WIDGET (scale)->style->font->descent; - break; - case GTK_POS_BOTTOM: - gdk_window_get_position (GTK_RANGE (scale)->slider, &x, NULL); - gdk_window_get_position (GTK_RANGE (scale)->trough, NULL, &y); - gdk_window_get_size (GTK_RANGE (scale)->slider, &width, NULL); - gdk_window_get_size (GTK_RANGE (scale)->trough, NULL, &height); - - x += widget->allocation.x + (width - text_width) / 2; - y += height + GTK_WIDGET (scale)->style->font->ascent; - break; - } - + { + case GTK_POS_LEFT: + gdk_window_get_position (GTK_RANGE (scale)->trough, &x, &y); + gdk_window_get_size (GTK_RANGE (scale)->trough, &width, &height); + + x -= SCALE_CLASS (scale)->value_spacing + text_width; + y += ((height - + (GTK_WIDGET (scale)->style->font->ascent + + GTK_WIDGET (scale)->style->font->descent)) / 2 + + GTK_WIDGET (scale)->style->font->ascent); + break; + case GTK_POS_RIGHT: + gdk_window_get_position (GTK_RANGE (scale)->trough, &x, &y); + gdk_window_get_size (GTK_RANGE (scale)->trough, &width, &height); + + x += width + SCALE_CLASS (scale)->value_spacing; + y += ((height - + (GTK_WIDGET (scale)->style->font->ascent + + GTK_WIDGET (scale)->style->font->descent)) / 2 + + GTK_WIDGET (scale)->style->font->ascent); + break; + case GTK_POS_TOP: + gdk_window_get_position (GTK_RANGE (scale)->slider, &x, NULL); + gdk_window_get_position (GTK_RANGE (scale)->trough, NULL, &y); + gdk_window_get_size (GTK_RANGE (scale)->slider, &width, NULL); + gdk_window_get_size (GTK_RANGE (scale)->trough, NULL, &height); + + x += widget->allocation.x + (width - text_width) / 2; + y -= GTK_WIDGET (scale)->style->font->descent; + break; + case GTK_POS_BOTTOM: + gdk_window_get_position (GTK_RANGE (scale)->slider, &x, NULL); + gdk_window_get_position (GTK_RANGE (scale)->trough, NULL, &y); + gdk_window_get_size (GTK_RANGE (scale)->slider, &width, NULL); + gdk_window_get_size (GTK_RANGE (scale)->trough, NULL, &height); + + x += widget->allocation.x + (width - text_width) / 2; + y += height + GTK_WIDGET (scale)->style->font->ascent; + break; + } + state_type = GTK_STATE_NORMAL; if (!GTK_WIDGET_IS_SENSITIVE (scale)) - state_type = GTK_STATE_INSENSITIVE; - - gtk_paint_string (GTK_WIDGET (scale)->style, - GTK_WIDGET (scale)->window, - state_type, - NULL, GTK_WIDGET (scale), "hscale", - x, y, buffer); + state_type = GTK_STATE_INSENSITIVE; + + gtk_paint_string (GTK_WIDGET (scale)->style, + GTK_WIDGET (scale)->window, + state_type, + NULL, GTK_WIDGET (scale), "hscale", + x, y, buffer); } } static gint -gtk_hscale_trough_keys(GtkRange *range, - GdkEventKey *key, - GtkScrollType *scroll, - GtkTroughType *pos) +gtk_hscale_trough_keys (GtkRange *range, + GdkEventKey *key, + GtkScrollType *scroll, + GtkTroughType *pos) { gint return_val = FALSE; switch (key->keyval) @@ -521,16 +578,16 @@ gtk_hscale_trough_keys(GtkRange *range, case GDK_Left: return_val = TRUE; if (key->state & GDK_CONTROL_MASK) - *scroll = GTK_SCROLL_PAGE_BACKWARD; + *scroll = GTK_SCROLL_PAGE_BACKWARD; else - *scroll = GTK_SCROLL_STEP_BACKWARD; + *scroll = GTK_SCROLL_STEP_BACKWARD; break; case GDK_Right: return_val = TRUE; if (key->state & GDK_CONTROL_MASK) - *scroll = GTK_SCROLL_PAGE_FORWARD; + *scroll = GTK_SCROLL_PAGE_FORWARD; else - *scroll = GTK_SCROLL_STEP_FORWARD; + *scroll = GTK_SCROLL_STEP_FORWARD; break; case GDK_Home: return_val = TRUE; diff --git a/gtk/gtkhscale.h b/gtk/gtkhscale.h index 6ae5fba925..d4474558ef 100644 --- a/gtk/gtkhscale.h +++ b/gtk/gtkhscale.h @@ -29,9 +29,12 @@ extern "C" { #endif /* __cplusplus */ -#define GTK_HSCALE(obj) GTK_CHECK_CAST (obj, gtk_hscale_get_type (), GtkHScale) -#define GTK_HSCALE_CLASS(klass) GTK_CHECK_CLASS_CAST (klass, gtk_hscale_get_type (), GtkHScaleClass) -#define GTK_IS_HSCALE(obj) GTK_CHECK_TYPE (obj, gtk_hscale_get_type ()) +#define GTK_TYPE_HSCALE (gtk_hscale_get_type ()) +#define GTK_HSCALE(obj) (GTK_CHECK_CAST ((obj), GTK_TYPE_HSCALE, GtkHScale)) +#define GTK_HSCALE_CLASS(klass) (GTK_CHECK_CLASS_CAST ((klass), GTK_TYPE_HSCALE, GtkHScaleClass)) +#define GTK_IS_HSCALE(obj) (GTK_CHECK_TYPE ((obj), GTK_TYPE_HSCALE)) +#define GTK_IS_HSCALE_CLASS(klass) (GTK_CHECK_CLASS_TYPE ((klass), GTK_TYPE_HSCALE)) + typedef struct _GtkHScale GtkHScale; @@ -48,7 +51,7 @@ struct _GtkHScaleClass }; -guint gtk_hscale_get_type (void); +GtkType gtk_hscale_get_type (void); GtkWidget* gtk_hscale_new (GtkAdjustment *adjustment); diff --git a/gtk/gtkhscrollbar.c b/gtk/gtkhscrollbar.c index 7b38db6486..71dac16648 100644 --- a/gtk/gtkhscrollbar.c +++ b/gtk/gtkhscrollbar.c @@ -25,59 +25,79 @@ #define RANGE_CLASS(w) GTK_RANGE_CLASS (GTK_OBJECT (w)->klass) +enum { + ARG_0, + ARG_ADJUSTMENT, +}; static void gtk_hscrollbar_class_init (GtkHScrollbarClass *klass); static void gtk_hscrollbar_init (GtkHScrollbar *hscrollbar); +static void gtk_hscrollbar_set_arg (GtkObject *object, + GtkArg *arg, + guint arg_id); +static void gtk_hscrollbar_get_arg (GtkObject *object, + GtkArg *arg, + guint arg_id); static void gtk_hscrollbar_realize (GtkWidget *widget); static void gtk_hscrollbar_size_allocate (GtkWidget *widget, - GtkAllocation *allocation); + GtkAllocation *allocation); static void gtk_hscrollbar_draw_step_forw (GtkRange *range); static void gtk_hscrollbar_draw_step_back (GtkRange *range); static void gtk_hscrollbar_slider_update (GtkRange *range); static void gtk_hscrollbar_calc_slider_size (GtkHScrollbar *hscrollbar); static gint gtk_hscrollbar_trough_keys (GtkRange *range, - GdkEventKey *key, - GtkScrollType *scroll, - GtkTroughType *pos); + GdkEventKey *key, + GtkScrollType *scroll, + GtkTroughType *pos); -guint +GtkType gtk_hscrollbar_get_type (void) { - static guint hscrollbar_type = 0; - + static GtkType hscrollbar_type = 0; + if (!hscrollbar_type) { GtkTypeInfo hscrollbar_info = { - "GtkHScrollbar", - sizeof (GtkHScrollbar), - sizeof (GtkHScrollbarClass), - (GtkClassInitFunc) gtk_hscrollbar_class_init, - (GtkObjectInitFunc) gtk_hscrollbar_init, - /* reserved_1 */ NULL, + "GtkHScrollbar", + sizeof (GtkHScrollbar), + sizeof (GtkHScrollbarClass), + (GtkClassInitFunc) gtk_hscrollbar_class_init, + (GtkObjectInitFunc) gtk_hscrollbar_init, + /* reserved_1 */ NULL, /* reserved_2 */ NULL, (GtkClassInitFunc) NULL, }; - - hscrollbar_type = gtk_type_unique (gtk_scrollbar_get_type (), &hscrollbar_info); + + hscrollbar_type = gtk_type_unique (GTK_TYPE_SCROLLBAR, &hscrollbar_info); } - + return hscrollbar_type; } static void gtk_hscrollbar_class_init (GtkHScrollbarClass *class) { + GtkObjectClass *object_class; GtkWidgetClass *widget_class; GtkRangeClass *range_class; - + + object_class = (GtkObjectClass*) class; widget_class = (GtkWidgetClass*) class; range_class = (GtkRangeClass*) class; - + + gtk_object_add_arg_type ("GtkHScrollbar::adjustment", + GTK_TYPE_ADJUSTMENT, + GTK_ARG_READWRITE | GTK_ARG_CONSTRUCT, + ARG_ADJUSTMENT); + + object_class->set_arg = gtk_hscrollbar_set_arg; + object_class->get_arg = gtk_hscrollbar_get_arg; + widget_class->realize = gtk_hscrollbar_realize; widget_class->size_allocate = gtk_hscrollbar_size_allocate; - + range_class->draw_step_forw = gtk_hscrollbar_draw_step_forw; range_class->draw_step_back = gtk_hscrollbar_draw_step_back; range_class->slider_update = gtk_hscrollbar_slider_update; @@ -86,36 +106,72 @@ gtk_hscrollbar_class_init (GtkHScrollbarClass *class) range_class->motion = gtk_range_default_hmotion; } +static void +gtk_hscrollbar_set_arg (GtkObject *object, + GtkArg *arg, + guint arg_id) +{ + GtkHScrollbar *hscrollbar; + + hscrollbar = GTK_HSCROLLBAR (object); + + switch (arg_id) + { + case ARG_ADJUSTMENT: + gtk_range_set_adjustment (GTK_RANGE (hscrollbar), GTK_VALUE_POINTER (*arg)); + break; + default: + break; + } +} + +static void +gtk_hscrollbar_get_arg (GtkObject *object, + GtkArg *arg, + guint arg_id) +{ + GtkHScrollbar *hscrollbar; + + hscrollbar = GTK_HSCROLLBAR (object); + + switch (arg_id) + { + case ARG_ADJUSTMENT: + GTK_VALUE_POINTER (*arg) = GTK_RANGE (hscrollbar); + break; + default: + arg->type = GTK_TYPE_INVALID; + break; + } +} + static void gtk_hscrollbar_init (GtkHScrollbar *hscrollbar) { GtkWidget *widget; GtkRequisition *requisition; - + widget = GTK_WIDGET (hscrollbar); requisition = &widget->requisition; - + requisition->width = (RANGE_CLASS (widget)->min_slider_size + - RANGE_CLASS (widget)->stepper_size + - RANGE_CLASS (widget)->stepper_slider_spacing + - widget->style->klass->xthickness) * 2; + RANGE_CLASS (widget)->stepper_size + + RANGE_CLASS (widget)->stepper_slider_spacing + + widget->style->klass->xthickness) * 2; requisition->height = (RANGE_CLASS (widget)->slider_width + - widget->style->klass->ythickness * 2); + widget->style->klass->ythickness * 2); } GtkWidget* gtk_hscrollbar_new (GtkAdjustment *adjustment) { - GtkHScrollbar *hscrollbar; + GtkWidget *hscrollbar; + + hscrollbar = gtk_widget_new (GTK_TYPE_HSCROLLBAR, + "adjustment", adjustment, + NULL); - hscrollbar = gtk_type_new (gtk_hscrollbar_get_type ()); - - if (!adjustment) - adjustment = (GtkAdjustment*) gtk_adjustment_new (0.0, 0.0, 0.0, 0.0, 0.0, 0.0); - - gtk_range_set_adjustment (GTK_RANGE (hscrollbar), adjustment); - - return GTK_WIDGET (hscrollbar); + return hscrollbar; } @@ -125,13 +181,13 @@ gtk_hscrollbar_realize (GtkWidget *widget) GtkRange *range; GdkWindowAttr attributes; gint attributes_mask; - + g_return_if_fail (widget != NULL); g_return_if_fail (GTK_IS_HSCROLLBAR (widget)); - + GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED); range = GTK_RANGE (widget); - + attributes.x = widget->allocation.x; attributes.y = widget->allocation.y + (widget->allocation.height - widget->requisition.height) / 2; attributes.width = widget->allocation.width; @@ -142,54 +198,54 @@ gtk_hscrollbar_realize (GtkWidget *widget) attributes.colormap = gtk_widget_get_colormap (widget); attributes.event_mask = gtk_widget_get_events (widget); attributes.event_mask |= (GDK_EXPOSURE_MASK | - GDK_BUTTON_PRESS_MASK | - GDK_BUTTON_RELEASE_MASK | - GDK_ENTER_NOTIFY_MASK | - GDK_LEAVE_NOTIFY_MASK); - + GDK_BUTTON_PRESS_MASK | + GDK_BUTTON_RELEASE_MASK | + GDK_ENTER_NOTIFY_MASK | + GDK_LEAVE_NOTIFY_MASK); + attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP; widget->window = gdk_window_new (gtk_widget_get_parent_window (widget), &attributes, attributes_mask); - + range->trough = widget->window; gdk_window_ref (range->trough); - + attributes.x = widget->style->klass->xthickness; attributes.y = widget->style->klass->ythickness; attributes.width = RANGE_CLASS (widget)->stepper_size; attributes.height = RANGE_CLASS (widget)->stepper_size; - + range->step_back = gdk_window_new (range->trough, &attributes, attributes_mask); - + attributes.x = (widget->allocation.width - - widget->style->klass->xthickness - - RANGE_CLASS (widget)->stepper_size); - + widget->style->klass->xthickness - + RANGE_CLASS (widget)->stepper_size); + range->step_forw = gdk_window_new (range->trough, &attributes, attributes_mask); - + attributes.x = 0; attributes.y = widget->style->klass->ythickness; attributes.width = RANGE_CLASS (widget)->min_slider_size; attributes.height = RANGE_CLASS (widget)->slider_width; attributes.event_mask |= (GDK_BUTTON_MOTION_MASK | - GDK_POINTER_MOTION_HINT_MASK); - + GDK_POINTER_MOTION_HINT_MASK); + range->slider = gdk_window_new (range->trough, &attributes, attributes_mask); - + gtk_hscrollbar_calc_slider_size (GTK_HSCROLLBAR (widget)); gtk_range_slider_update (GTK_RANGE (widget)); - + widget->style = gtk_style_attach (widget->style, widget->window); - + gdk_window_set_user_data (range->trough, widget); gdk_window_set_user_data (range->slider, widget); gdk_window_set_user_data (range->step_forw, widget); gdk_window_set_user_data (range->step_back, widget); - + gtk_style_set_background (widget->style, range->trough, GTK_STATE_ACTIVE); gtk_style_set_background (widget->style, range->slider, GTK_STATE_NORMAL); gtk_style_set_background (widget->style, range->step_forw, GTK_STATE_ACTIVE); gtk_style_set_background (widget->style, range->step_back, GTK_STATE_ACTIVE); - + gdk_window_show (range->slider); gdk_window_show (range->step_forw); gdk_window_show (range->step_back); @@ -197,38 +253,38 @@ gtk_hscrollbar_realize (GtkWidget *widget) static void gtk_hscrollbar_size_allocate (GtkWidget *widget, - GtkAllocation *allocation) + GtkAllocation *allocation) { GtkRange *range; - + g_return_if_fail (widget != NULL); g_return_if_fail (GTK_IS_HSCROLLBAR (widget)); g_return_if_fail (allocation != NULL); - + widget->allocation = *allocation; if (GTK_WIDGET_REALIZED (widget)) { range = GTK_RANGE (widget); - + gdk_window_move_resize (range->trough, - allocation->x, - allocation->y + (allocation->height - widget->requisition.height) / 2, - allocation->width, widget->requisition.height); + allocation->x, + allocation->y + (allocation->height - widget->requisition.height) / 2, + allocation->width, widget->requisition.height); gdk_window_move_resize (range->step_back, - widget->style->klass->xthickness, - widget->style->klass->ythickness, - RANGE_CLASS (widget)->stepper_size, - widget->requisition.height - widget->style->klass->ythickness * 2); + widget->style->klass->xthickness, + widget->style->klass->ythickness, + RANGE_CLASS (widget)->stepper_size, + widget->requisition.height - widget->style->klass->ythickness * 2); gdk_window_move_resize (range->step_forw, - allocation->width - widget->style->klass->xthickness - - RANGE_CLASS (widget)->stepper_size, - widget->style->klass->ythickness, - RANGE_CLASS (widget)->stepper_size, - widget->requisition.height - widget->style->klass->ythickness * 2); + allocation->width - widget->style->klass->xthickness - + RANGE_CLASS (widget)->stepper_size, + widget->style->klass->ythickness, + RANGE_CLASS (widget)->stepper_size, + widget->requisition.height - widget->style->klass->ythickness * 2); gdk_window_resize (range->slider, - RANGE_CLASS (widget)->min_slider_size, - widget->requisition.height - widget->style->klass->ythickness * 2); - + RANGE_CLASS (widget)->min_slider_size, + widget->requisition.height - widget->style->klass->ythickness * 2); + gtk_range_slider_update (GTK_RANGE (widget)); } } @@ -238,32 +294,32 @@ gtk_hscrollbar_draw_step_forw (GtkRange *range) { GtkStateType state_type; GtkShadowType shadow_type; - + g_return_if_fail (range != NULL); g_return_if_fail (GTK_IS_HSCROLLBAR (range)); - + if (GTK_WIDGET_DRAWABLE (range)) { if (range->in_child == RANGE_CLASS (range)->step_forw) - { - if (range->click_child == RANGE_CLASS (range)->step_forw) - state_type = GTK_STATE_ACTIVE; - else - state_type = GTK_STATE_PRELIGHT; - } + { + if (range->click_child == RANGE_CLASS (range)->step_forw) + state_type = GTK_STATE_ACTIVE; + else + state_type = GTK_STATE_PRELIGHT; + } else - state_type = GTK_STATE_NORMAL; - + state_type = GTK_STATE_NORMAL; + if (range->click_child == RANGE_CLASS (range)->step_forw) - shadow_type = GTK_SHADOW_IN; + shadow_type = GTK_SHADOW_IN; else - shadow_type = GTK_SHADOW_OUT; - + shadow_type = GTK_SHADOW_OUT; + gtk_paint_arrow (GTK_WIDGET (range)->style, range->step_forw, - state_type, shadow_type, - NULL, GTK_WIDGET (range), "hscrollbar", - GTK_ARROW_RIGHT, - TRUE, 0, 0, -1, -1); + state_type, shadow_type, + NULL, GTK_WIDGET (range), "hscrollbar", + GTK_ARROW_RIGHT, + TRUE, 0, 0, -1, -1); } } @@ -272,32 +328,32 @@ gtk_hscrollbar_draw_step_back (GtkRange *range) { GtkStateType state_type; GtkShadowType shadow_type; - + g_return_if_fail (range != NULL); g_return_if_fail (GTK_IS_HSCROLLBAR (range)); - + if (GTK_WIDGET_DRAWABLE (range)) { if (range->in_child == RANGE_CLASS (range)->step_back) - { - if (range->click_child == RANGE_CLASS (range)->step_back) - state_type = GTK_STATE_ACTIVE; - else - state_type = GTK_STATE_PRELIGHT; - } + { + if (range->click_child == RANGE_CLASS (range)->step_back) + state_type = GTK_STATE_ACTIVE; + else + state_type = GTK_STATE_PRELIGHT; + } else - state_type = GTK_STATE_NORMAL; - + state_type = GTK_STATE_NORMAL; + if (range->click_child == RANGE_CLASS (range)->step_back) - shadow_type = GTK_SHADOW_IN; + shadow_type = GTK_SHADOW_IN; else - shadow_type = GTK_SHADOW_OUT; - - gtk_paint_arrow (GTK_WIDGET (range)->style, range->step_back, - state_type, shadow_type, - NULL, GTK_WIDGET (range), "hscrollbar", - GTK_ARROW_LEFT, - TRUE, 0, 0, -1, -1); + shadow_type = GTK_SHADOW_OUT; + + gtk_paint_arrow (GTK_WIDGET (range)->style, range->step_back, + state_type, shadow_type, + NULL, GTK_WIDGET (range), "hscrollbar", + GTK_ARROW_LEFT, + TRUE, 0, 0, -1, -1); } } @@ -306,7 +362,7 @@ gtk_hscrollbar_slider_update (GtkRange *range) { g_return_if_fail (range != NULL); g_return_if_fail (GTK_IS_HSCROLLBAR (range)); - + gtk_hscrollbar_calc_slider_size (GTK_HSCROLLBAR (range)); gtk_range_default_hslider_update (range); } @@ -322,50 +378,50 @@ gtk_hscrollbar_calc_slider_size (GtkHScrollbar *hscrollbar) gint slider_height; gint left, right; gint width; - + g_return_if_fail (hscrollbar != NULL); g_return_if_fail (GTK_IS_HSCROLLBAR (hscrollbar)); - + if (GTK_WIDGET_REALIZED (hscrollbar)) { range = GTK_RANGE (hscrollbar); - + gdk_window_get_size (range->step_back, &step_back_width, NULL); gdk_window_get_position (range->step_back, &step_back_x, NULL); gdk_window_get_position (range->step_forw, &step_forw_x, NULL); - + left = (step_back_x + - step_back_width + - RANGE_CLASS (hscrollbar)->stepper_slider_spacing); + step_back_width + + RANGE_CLASS (hscrollbar)->stepper_slider_spacing); right = step_forw_x - RANGE_CLASS (hscrollbar)->stepper_slider_spacing; width = right - left; - + if ((range->adjustment->page_size > 0) && - (range->adjustment->lower != range->adjustment->upper)) - { - if (range->adjustment->page_size > - (range->adjustment->upper - range->adjustment->lower)) - range->adjustment->page_size = range->adjustment->upper - range->adjustment->lower; - - width = (width * range->adjustment->page_size / - (range->adjustment->upper - range->adjustment->lower)); - - if (width < RANGE_CLASS (hscrollbar)->min_slider_size) - width = RANGE_CLASS (hscrollbar)->min_slider_size; - } - + (range->adjustment->lower != range->adjustment->upper)) + { + if (range->adjustment->page_size > + (range->adjustment->upper - range->adjustment->lower)) + range->adjustment->page_size = range->adjustment->upper - range->adjustment->lower; + + width = (width * range->adjustment->page_size / + (range->adjustment->upper - range->adjustment->lower)); + + if (width < RANGE_CLASS (hscrollbar)->min_slider_size) + width = RANGE_CLASS (hscrollbar)->min_slider_size; + } + gdk_window_get_size (range->slider, &slider_width, &slider_height); - + if (slider_width != width) - gdk_window_resize (range->slider, width, slider_height); + gdk_window_resize (range->slider, width, slider_height); } } static gint gtk_hscrollbar_trough_keys(GtkRange *range, - GdkEventKey *key, - GtkScrollType *scroll, - GtkTroughType *pos) + GdkEventKey *key, + GtkScrollType *scroll, + GtkTroughType *pos) { gint return_val = FALSE; switch (key->keyval) @@ -381,16 +437,16 @@ gtk_hscrollbar_trough_keys(GtkRange *range, case GDK_Home: return_val = TRUE; if (key->state & GDK_CONTROL_MASK) - *scroll = GTK_SCROLL_PAGE_BACKWARD; + *scroll = GTK_SCROLL_PAGE_BACKWARD; else - *pos = GTK_TROUGH_START; + *pos = GTK_TROUGH_START; break; case GDK_End: return_val = TRUE; if (key->state & GDK_CONTROL_MASK) - *scroll = GTK_SCROLL_PAGE_FORWARD; + *scroll = GTK_SCROLL_PAGE_FORWARD; else - *pos = GTK_TROUGH_END; + *pos = GTK_TROUGH_END; break; } return return_val; diff --git a/gtk/gtkhscrollbar.h b/gtk/gtkhscrollbar.h index 852f3eec13..c61efbfa61 100644 --- a/gtk/gtkhscrollbar.h +++ b/gtk/gtkhscrollbar.h @@ -29,9 +29,11 @@ extern "C" { #endif /* __cplusplus */ -#define GTK_HSCROLLBAR(obj) GTK_CHECK_CAST (obj, gtk_hscrollbar_get_type (), GtkHScrollbar) -#define GTK_HSCROLLBAR_CLASS(klass) GTK_CHECK_CLASS_CAST (klass, gtk_hscrollbar_get_type (), GtkHScrollbarClass) -#define GTK_IS_HSCROLLBAR(obj) GTK_CHECK_TYPE (obj, gtk_hscrollbar_get_type ()) +#define GTK_TYPE_HSCROLLBAR (gtk_hscrollbar_get_type ()) +#define GTK_HSCROLLBAR(obj) (GTK_CHECK_CAST ((obj), GTK_TYPE_HSCROLLBAR, GtkHScrollbar)) +#define GTK_HSCROLLBAR_CLASS(klass) (GTK_CHECK_CLASS_CAST ((klass), GTK_TYPE_HSCROLLBAR, GtkHScrollbarClass)) +#define GTK_IS_HSCROLLBAR(obj) (GTK_CHECK_TYPE ((obj), GTK_TYPE_HSCROLLBAR)) +#define GTK_IS_HSCROLLBAR_CLASS(klass) (GTK_CHECK_CLASS_TYPE ((klass), GTK_TYPE_HSCROLLBAR)) typedef struct _GtkHScrollbar GtkHScrollbar; @@ -48,7 +50,7 @@ struct _GtkHScrollbarClass }; -guint gtk_hscrollbar_get_type (void); +GtkType gtk_hscrollbar_get_type (void); GtkWidget* gtk_hscrollbar_new (GtkAdjustment *adjustment); diff --git a/gtk/gtkmisc.c b/gtk/gtkmisc.c index e2fdf50f13..6e235df23d 100644 --- a/gtk/gtkmisc.c +++ b/gtk/gtkmisc.c @@ -87,8 +87,6 @@ gtk_misc_class_init (GtkMiscClass *class) static void gtk_misc_init (GtkMisc *misc) { - GTK_WIDGET_SET_FLAGS (misc, GTK_BASIC); - misc->xalign = 0.5; misc->yalign = 0.5; misc->xpad = 0; diff --git a/gtk/gtknotebook.c b/gtk/gtknotebook.c index f165b24b40..ee637473c7 100644 --- a/gtk/gtknotebook.c +++ b/gtk/gtknotebook.c @@ -242,7 +242,7 @@ gtk_notebook_class_init (GtkNotebookClass *class) gtk_object_add_arg_type ("GtkNotebook::page", GTK_TYPE_INT, GTK_ARG_READWRITE, ARG_PAGE); gtk_object_add_arg_type ("GtkNotebook::tab_pos", GTK_TYPE_POSITION_TYPE, GTK_ARG_READWRITE, ARG_TAB_POS); - gtk_object_add_arg_type ("GtkNotebook::tab_border", GTK_TYPE_UINT, GTK_ARG_READWRITE, ARG_TAB_BORDER); + gtk_object_add_arg_type ("GtkNotebook::tab_border", GTK_TYPE_UINT, GTK_ARG_WRITABLE, ARG_TAB_BORDER); gtk_object_add_arg_type ("GtkNotebook::tab_hborder", GTK_TYPE_UINT, GTK_ARG_READWRITE, ARG_TAB_HBORDER); gtk_object_add_arg_type ("GtkNotebook::tab_vborder", GTK_TYPE_UINT, GTK_ARG_READWRITE, ARG_TAB_VBORDER); gtk_object_add_arg_type ("GtkNotebook::show_tabs", GTK_TYPE_BOOL, GTK_ARG_READWRITE, ARG_SHOW_TABS); @@ -315,7 +315,6 @@ gtk_notebook_init (GtkNotebook *notebook) notebook->panel = NULL; notebook->menu = NULL; - notebook->tab_border = 2; notebook->tab_hborder = 2; notebook->tab_vborder = 2; @@ -433,9 +432,6 @@ gtk_notebook_get_arg (GtkObject *object, case ARG_TAB_POS: GTK_VALUE_ENUM (*arg) = notebook->tab_pos; break; - case ARG_TAB_BORDER: - GTK_VALUE_UINT (*arg) = notebook->tab_border; - break; case ARG_TAB_HBORDER: GTK_VALUE_UINT (*arg) = notebook->tab_hborder; break; @@ -3730,7 +3726,6 @@ gtk_notebook_set_tab_border (GtkNotebook *notebook, g_return_if_fail (notebook != NULL); g_return_if_fail (GTK_IS_NOTEBOOK (notebook)); - notebook->tab_border = tab_border; notebook->tab_hborder = tab_border; notebook->tab_vborder = tab_border; diff --git a/gtk/gtknotebook.h b/gtk/gtknotebook.h index ad049b9d10..5531722d2b 100644 --- a/gtk/gtknotebook.h +++ b/gtk/gtknotebook.h @@ -56,9 +56,6 @@ struct _GtkNotebook guint32 timer; - guint16 tab_border; /* deprecated field, - * use tab_hborder, tab_vborder instead - */ guint16 tab_hborder; guint16 tab_vborder; diff --git a/gtk/gtkobject.c b/gtk/gtkobject.c index 177f170561..15dd706088 100644 --- a/gtk/gtkobject.c +++ b/gtk/gtkobject.c @@ -40,7 +40,8 @@ enum { void gtk_object_init_type (void); static void gtk_object_base_class_init (GtkObjectClass *klass); static void gtk_object_class_init (GtkObjectClass *klass); -static void gtk_object_init (GtkObject *object); +static void gtk_object_init (GtkObject *object, + GtkObjectClass *klass); static void gtk_object_set_arg (GtkObject *object, GtkArg *arg, guint arg_id); @@ -56,10 +57,9 @@ static guint object_signals[LAST_SIGNAL] = { 0 }; static GHashTable *object_arg_info_ht = NULL; -static const gchar *user_data_key = "user_data"; -static guint user_data_key_id = 0; -static const gchar *weakrefs_key = "gtk-weakrefs"; -static guint weakrefs_key_id = 0; +static GQuark quark_user_data = 0; +static GQuark quark_weakrefs = 0; +static GQuark quark_carg_history = 0; #ifdef G_ENABLE_DEBUG @@ -131,6 +131,7 @@ gtk_object_base_class_init (GtkObjectClass *class) class->signals = NULL; class->nsignals = 0; class->n_args = 0; + class->construct_args = NULL; /* reset instance specifc methods that don't get inherited */ class->get_arg = NULL; @@ -140,6 +141,8 @@ gtk_object_base_class_init (GtkObjectClass *class) static void gtk_object_class_init (GtkObjectClass *class) { + quark_carg_history = g_quark_from_static_string ("gtk-construct-arg-history"); + gtk_object_add_arg_type ("GtkObject::user_data", GTK_TYPE_POINTER, GTK_ARG_READWRITE, @@ -179,9 +182,20 @@ gtk_object_class_init (GtkObjectClass *class) } static void -gtk_object_init (GtkObject *object) +gtk_object_init (GtkObject *object, + GtkObjectClass *klass) { + gboolean needs_construction = FALSE; + GTK_OBJECT_FLAGS (object) = GTK_FLOATING; + do + { + needs_construction |= klass->construct_args != NULL; + klass = gtk_type_parent_class (klass->type); + } + while (klass && !needs_construction); + if (!needs_construction) + GTK_OBJECT_FLAGS (object) |= GTK_CONSTRUCTED; object->ref_count = 1; g_datalist_init (&object->object_data); @@ -208,6 +222,7 @@ gtk_object_destroy (GtkObject *object) { g_return_if_fail (object != NULL); g_return_if_fail (GTK_IS_OBJECT (object)); + g_return_if_fail (GTK_OBJECT_CONSTRUCTED (object)); if (!GTK_OBJECT_DESTROYED (object)) { @@ -352,6 +367,8 @@ gtk_object_class_add_user_signal (GtkObjectClass *class, g_return_val_if_fail (class != NULL, 0); + g_message ("gtk_object_class_add_user_signal() is deprecated"); + if (nparams > 0) { params = g_new (GtkType, nparams); @@ -521,14 +538,14 @@ gtk_object_weakref (GtkObject *object, g_return_if_fail (notify != NULL); g_return_if_fail (GTK_IS_OBJECT (object)); - if (!weakrefs_key_id) - weakrefs_key_id = g_quark_from_static_string (weakrefs_key); + if (!quark_weakrefs) + quark_weakrefs = g_quark_from_static_string ("gtk-weakrefs"); weak = g_new (GtkWeakRef, 1); - weak->next = gtk_object_get_data_by_id (object, weakrefs_key_id); + weak->next = gtk_object_get_data_by_id (object, quark_weakrefs); weak->notify = notify; weak->data = data; - gtk_object_set_data_by_id (object, weakrefs_key_id, weak); + gtk_object_set_data_by_id (object, quark_weakrefs, weak); } void @@ -541,17 +558,17 @@ gtk_object_weakunref (GtkObject *object, g_return_if_fail (object != NULL); g_return_if_fail (GTK_IS_OBJECT (object)); - if (!weakrefs_key_id) + if (!quark_weakrefs) return; - weaks = gtk_object_get_data_by_id (object, weakrefs_key_id); + weaks = gtk_object_get_data_by_id (object, quark_weakrefs); for (wp = &weaks; *wp; wp = &(*wp)->next) { w = *wp; if (w->notify == notify && w->data == data) { if (w == weaks) - gtk_object_set_data_by_id (object, weakrefs_key_id, w->next); + gtk_object_set_data_by_id (object, quark_weakrefs, w->next); else *wp = w->next; g_free (w); @@ -563,11 +580,11 @@ gtk_object_weakunref (GtkObject *object, static void gtk_object_notify_weaks (GtkObject *object) { - if (weakrefs_key_id) + if (quark_weakrefs) { GtkWeakRef *w1, *w2; - w1 = gtk_object_get_data_by_id (object, weakrefs_key_id); + w1 = gtk_object_get_data_by_id (object, quark_weakrefs); while (w1) { @@ -628,6 +645,9 @@ gtk_object_new (GtkType object_type, gtk_args_collect_cleanup (arg_list, info_list); } + if (!GTK_OBJECT_CONSTRUCTED (object)) + gtk_object_default_construct (object); + return object; } @@ -648,6 +668,9 @@ gtk_object_newv (GtkType object_type, for (max_args = args + n_args; args < max_args; args++) gtk_object_arg_set (object, args, NULL); + if (!GTK_OBJECT_CONSTRUCTED (object)) + gtk_object_default_construct (object); + return object; } @@ -727,9 +750,9 @@ gtk_object_set (GtkObject *object, } void -gtk_object_arg_set (GtkObject *object, - GtkArg *arg, - GtkArgInfo *info) +gtk_object_arg_set (GtkObject *object, + GtkArg *arg, + GtkArgInfo *info) { GtkObjectClass *oclass; @@ -752,8 +775,15 @@ gtk_object_arg_set (GtkObject *object, return; } } - - if (! (info->arg_flags & GTK_ARG_WRITABLE)) + + if (info->arg_flags & GTK_ARG_CONSTRUCT_ONLY && + GTK_OBJECT_CONSTRUCTED (object)) + { + g_warning ("gtk_object_arg_set(): cannot set argument \"%s\" for constructed object", + info->full_name); + return; + } + if (!(info->arg_flags & GTK_ARG_WRITABLE)) { g_warning ("gtk_object_arg_set(): argument \"%s\" is not writable", info->full_name); @@ -770,12 +800,23 @@ gtk_object_arg_set (GtkObject *object, oclass = gtk_type_class (info->class_type); g_assert (oclass->set_arg != NULL); oclass->set_arg (object, arg, info->arg_id); + if (!GTK_OBJECT_CONSTRUCTED (object) && + (info->arg_flags & GTK_ARG_CONSTRUCT_ONLY || + info->arg_flags & GTK_ARG_CONSTRUCT)) + { + GSList *slist; + + slist = gtk_object_get_data_by_id (object, quark_carg_history); + gtk_object_set_data_by_id (object, + quark_carg_history, + g_slist_prepend (slist, info)); + } } void -gtk_object_arg_get (GtkObject *object, - GtkArg *arg, - GtkArgInfo *info) +gtk_object_arg_get (GtkObject *object, + GtkArg *arg, + GtkArgInfo *info) { GtkObjectClass *oclass; @@ -814,12 +855,79 @@ gtk_object_arg_get (GtkObject *object, oclass->get_arg (object, arg, info->arg_id); } +void +gtk_object_default_construct (GtkObject *object) +{ + GSList *slist; + + g_return_if_fail (object != NULL); + g_return_if_fail (GTK_IS_OBJECT (object)); + + if (!GTK_OBJECT_CONSTRUCTED (object)) + { + for (slist = object->klass->construct_args; + slist && !GTK_OBJECT_CONSTRUCTED (object); + slist = slist->next) + { + GSList *history; + GtkArgInfo *info; + + info = slist->data; + history = gtk_object_get_data_by_id (object, quark_carg_history); + if (!g_slist_find (history, info)) + { + GtkArg arg; + + /* default application */ + arg.type = info->type; + arg.name = info->name; + switch (gtk_type_get_varargs_type (arg.type)) + { + case GTK_TYPE_FLOAT: + GTK_VALUE_FLOAT (arg) = 0.0; + break; + case GTK_TYPE_DOUBLE: + GTK_VALUE_DOUBLE (arg) = 0.0; + break; + case GTK_TYPE_BOXED: + case GTK_TYPE_STRING: + case GTK_TYPE_POINTER: + case GTK_TYPE_OBJECT: + GTK_VALUE_POINTER (arg) = NULL; + break; + default: + memset (&arg.d, 0, sizeof (arg.d)); + break; + } + gtk_object_arg_set (object, &arg, info); + } + } + + if (!GTK_OBJECT_CONSTRUCTED (object)) + gtk_object_constructed (object); + } +} + +void +gtk_object_constructed (GtkObject *object) +{ + g_return_if_fail (object != NULL); + g_return_if_fail (GTK_IS_OBJECT (object)); + g_return_if_fail (GTK_OBJECT_CONSTRUCTED (object) == FALSE); + + g_slist_free (gtk_object_get_data_by_id (object, quark_carg_history)); + gtk_object_set_data_by_id (object, quark_carg_history, NULL); + GTK_OBJECT_FLAGS (object) |= GTK_CONSTRUCTED; +} + void gtk_object_add_arg_type (const char *arg_name, GtkType arg_type, guint arg_flags, guint arg_id) { + GtkArgInfo *info; + g_return_if_fail (arg_name != NULL); g_return_if_fail (arg_type > GTK_TYPE_NONE); g_return_if_fail (arg_id > 0); @@ -828,18 +936,32 @@ gtk_object_add_arg_type (const char *arg_name, g_return_if_fail ((arg_flags & GTK_ARG_READWRITE) == GTK_ARG_READWRITE); else g_return_if_fail ((arg_flags & GTK_ARG_READWRITE) != 0); + if (arg_flags & GTK_ARG_CONSTRUCT_ONLY) + g_return_if_fail ((arg_flags & GTK_ARG_WRITABLE) == GTK_ARG_WRITABLE); if (!object_arg_info_ht) object_arg_info_ht = g_hash_table_new (gtk_arg_info_hash, gtk_arg_info_equal); - gtk_arg_type_new_static (GTK_TYPE_OBJECT, - arg_name, - GTK_STRUCT_OFFSET (GtkObjectClass, n_args), - object_arg_info_ht, - arg_type, - arg_flags, - arg_id); + info = gtk_arg_type_new_static (GTK_TYPE_OBJECT, + arg_name, + GTK_STRUCT_OFFSET (GtkObjectClass, n_args), + object_arg_info_ht, + arg_type, + arg_flags, + arg_id); + if (info && + (info->arg_flags & GTK_ARG_CONSTRUCT || + info->arg_flags & GTK_ARG_CONSTRUCT_ONLY)) + { + GtkObjectClass *class; + + class = gtk_type_class (info->class_type); + if (info->arg_flags & GTK_ARG_CONSTRUCT_ONLY) + class->construct_args = g_slist_prepend (class->construct_args, info); + else + class->construct_args = g_slist_append (class->construct_args, info); + } } gchar* @@ -1003,10 +1125,10 @@ gtk_object_set_user_data (GtkObject *object, g_return_if_fail (object != NULL); g_return_if_fail (GTK_IS_OBJECT (object)); - if (!user_data_key_id) - user_data_key_id = g_quark_from_static_string (user_data_key); + if (!quark_user_data) + quark_user_data = g_quark_from_static_string ("user_data"); - g_datalist_id_set_data (&object->object_data, user_data_key_id, data); + g_datalist_id_set_data (&object->object_data, quark_user_data, data); } gpointer @@ -1015,7 +1137,7 @@ gtk_object_get_user_data (GtkObject *object) g_return_val_if_fail (object != NULL, NULL); g_return_val_if_fail (GTK_IS_OBJECT (object), NULL); - return g_datalist_id_get_data (&object->object_data, user_data_key_id); + return g_datalist_id_get_data (&object->object_data, quark_user_data); } /******************************************* diff --git a/gtk/gtkobject.h b/gtk/gtkobject.h index 923a45a99b..7900f84c70 100644 --- a/gtk/gtkobject.h +++ b/gtk/gtkobject.h @@ -74,16 +74,16 @@ typedef enum GTK_DESTROYED = 1 << 0, GTK_FLOATING = 1 << 1, GTK_CONNECTED = 1 << 2, - GTK_RESERVED_2 = 1 << 3, - GTK_OBJECT_FLAG_LAST = GTK_RESERVED_2 + GTK_CONSTRUCTED = 1 << 3, } GtkObjectFlags; /* Macros for extracting the object_flags from GtkObject. */ #define GTK_OBJECT_FLAGS(obj) (GTK_OBJECT (obj)->flags) -#define GTK_OBJECT_DESTROYED(obj) (GTK_OBJECT_FLAGS (obj) & GTK_DESTROYED) -#define GTK_OBJECT_FLOATING(obj) (GTK_OBJECT_FLAGS (obj) & GTK_FLOATING) -#define GTK_OBJECT_CONNECTED(obj) (GTK_OBJECT_FLAGS (obj) & GTK_CONNECTED) +#define GTK_OBJECT_DESTROYED(obj) ((GTK_OBJECT_FLAGS (obj) & GTK_DESTROYED) != 0) +#define GTK_OBJECT_FLOATING(obj) ((GTK_OBJECT_FLAGS (obj) & GTK_FLOATING) != 0) +#define GTK_OBJECT_CONNECTED(obj) ((GTK_OBJECT_FLAGS (obj) & GTK_CONNECTED) != 0) +#define GTK_OBJECT_CONSTRUCTED(obj) ((GTK_OBJECT_FLAGS (obj) & GTK_CONSTRUCTED) != 0) /* Macros for setting and clearing bits in the object_flags field of GtkObject. */ @@ -94,15 +94,16 @@ typedef enum */ typedef enum { - GTK_ARG_READABLE = 1 << 0, - GTK_ARG_WRITABLE = 1 << 1, - GTK_ARG_CONSTRUCT = 1 << 2, - GTK_ARG_CHILD_ARG = 1 << 3, - GTK_ARG_MASK = 0x0f, + GTK_ARG_READABLE = 1 << 0, + GTK_ARG_WRITABLE = 1 << 1, + GTK_ARG_CONSTRUCT = 1 << 2, + GTK_ARG_CONSTRUCT_ONLY = 1 << 3, + GTK_ARG_CHILD_ARG = 1 << 4, + GTK_ARG_MASK = 0x1f, /* aliases */ - GTK_ARG_READWRITE = GTK_ARG_READABLE | GTK_ARG_WRITABLE + GTK_ARG_READWRITE = GTK_ARG_READABLE | GTK_ARG_WRITABLE } GtkArgFlags; typedef struct _GtkObjectClass GtkObjectClass; @@ -162,6 +163,7 @@ struct _GtkObjectClass /* The number of arguments per class. */ guint n_args; + GSList *construct_args; /* Non overridable class methods to set and get per class arguments */ void (*set_arg) (GtkObject *object, @@ -212,6 +214,8 @@ GtkObject* gtk_object_new (GtkType type, GtkObject* gtk_object_newv (GtkType object_type, guint n_args, GtkArg *args); +void gtk_object_default_construct (GtkObject *object); +void gtk_object_constructed (GtkObject *object); void gtk_object_sink (GtkObject *object); void gtk_object_ref (GtkObject *object); void gtk_object_unref (GtkObject *object); diff --git a/gtk/gtkoptionmenu.c b/gtk/gtkoptionmenu.c index c92aa879d1..3c6310e169 100644 --- a/gtk/gtkoptionmenu.c +++ b/gtk/gtkoptionmenu.c @@ -531,14 +531,12 @@ gtk_option_menu_update_contents (GtkOptionMenu *option_menu) child = GTK_BIN (option_menu->menu_item)->child; if (child) { - gtk_container_block_resize (GTK_CONTAINER (option_menu)); if (GTK_BIN (option_menu)->child) gtk_container_remove (GTK_CONTAINER (option_menu), GTK_BIN (option_menu)->child); if (GTK_WIDGET (option_menu)->state != child->state) gtk_widget_set_state (child, GTK_WIDGET (option_menu)->state); gtk_widget_reparent (child, GTK_WIDGET (option_menu)); - gtk_container_unblock_resize (GTK_CONTAINER (option_menu)); } gtk_widget_size_request (child, &child->requisition); @@ -559,14 +557,12 @@ gtk_option_menu_remove_contents (GtkOptionMenu *option_menu) if (GTK_BIN (option_menu)->child) { - gtk_container_block_resize (GTK_CONTAINER (option_menu)); if (GTK_WIDGET (option_menu->menu_item)->state != GTK_BIN (option_menu)->child->state) gtk_widget_set_state (GTK_BIN (option_menu)->child, GTK_WIDGET (option_menu->menu_item)->state); gtk_widget_reparent (GTK_BIN (option_menu)->child, option_menu->menu_item); gtk_widget_unref (option_menu->menu_item); option_menu->menu_item = NULL; - gtk_container_unblock_resize (GTK_CONTAINER (option_menu)); } } diff --git a/gtk/gtkpacker.c b/gtk/gtkpacker.c index 6d30b5ae38..8026646e39 100644 --- a/gtk/gtkpacker.c +++ b/gtk/gtkpacker.c @@ -491,7 +491,7 @@ gtk_packer_get_child_arg (GtkContainer *container, static void gtk_packer_init (GtkPacker *packer) { - GTK_WIDGET_SET_FLAGS (packer, GTK_NO_WINDOW | GTK_BASIC); + GTK_WIDGET_SET_FLAGS (packer, GTK_NO_WINDOW); packer->children = NULL; packer->spacing = 0; diff --git a/gtk/gtkpreview.c b/gtk/gtkpreview.c index 076310137a..c3ebfabf8b 100644 --- a/gtk/gtkpreview.c +++ b/gtk/gtkpreview.c @@ -107,8 +107,6 @@ gtk_preview_reset (void) static void gtk_preview_init (GtkPreview *preview) { - GTK_WIDGET_SET_FLAGS (preview, GTK_BASIC); - preview->buffer = NULL; preview->buffer_width = 0; preview->buffer_height = 0; diff --git a/gtk/gtkprogress.c b/gtk/gtkprogress.c index 75fa72d7aa..586d58b276 100644 --- a/gtk/gtkprogress.c +++ b/gtk/gtkprogress.c @@ -25,8 +25,24 @@ #define EPSILON 1e-5 +enum { + ARG_0, + ARG_ACTIVITY_MODE, + ARG_SHOW_TEXT, + ARG_TEXT_XALIGN, + ARG_TEXT_YALIGN +}; + + static void gtk_progress_class_init (GtkProgressClass *klass); static void gtk_progress_init (GtkProgress *progress); +static void gtk_progress_set_arg (GtkObject *object, + GtkArg *arg, + guint arg_id); +static void gtk_progress_get_arg (GtkObject *object, + GtkArg *arg, + guint arg_id); +static void gtk_progress_destroy (GtkObject *object); static void gtk_progress_finalize (GtkObject *object); static void gtk_progress_realize (GtkWidget *widget); static gint gtk_progress_expose (GtkWidget *widget, @@ -39,10 +55,10 @@ static void gtk_progress_create_pixmap (GtkProgress *progress); static GtkWidgetClass *parent_class = NULL; -guint +GtkType gtk_progress_get_type (void) { - static guint progress_type = 0; + static GtkType progress_type = 0; if (!progress_type) { @@ -58,7 +74,7 @@ gtk_progress_get_type (void) (GtkClassInitFunc) NULL }; - progress_type = gtk_type_unique (gtk_widget_get_type (), &progress_info); + progress_type = gtk_type_unique (GTK_TYPE_WIDGET, &progress_info); } return progress_type; @@ -72,9 +88,28 @@ gtk_progress_class_init (GtkProgressClass *class) object_class = (GtkObjectClass *) class; widget_class = (GtkWidgetClass *) class; + parent_class = gtk_type_class (GTK_TYPE_WIDGET); - parent_class = gtk_type_class (gtk_widget_get_type ()); + gtk_object_add_arg_type ("GtkProgress::activity_mode", + GTK_TYPE_BOOL, + GTK_ARG_READWRITE, + ARG_ACTIVITY_MODE); + gtk_object_add_arg_type ("GtkProgress::show_text", + GTK_TYPE_BOOL, + GTK_ARG_READWRITE, + ARG_SHOW_TEXT); + gtk_object_add_arg_type ("GtkProgress::text_xalign", + GTK_TYPE_FLOAT, + GTK_ARG_READWRITE, + ARG_TEXT_XALIGN); + gtk_object_add_arg_type ("GtkProgress::text_yalign", + GTK_TYPE_FLOAT, + GTK_ARG_READWRITE, + ARG_TEXT_YALIGN); + object_class->set_arg = gtk_progress_set_arg; + object_class->get_arg = gtk_progress_get_arg; + object_class->destroy = gtk_progress_destroy; object_class->finalize = gtk_progress_finalize; widget_class->realize = gtk_progress_realize; @@ -87,11 +122,67 @@ gtk_progress_class_init (GtkProgressClass *class) class->act_mode_enter = NULL; } +static void +gtk_progress_set_arg (GtkObject *object, + GtkArg *arg, + guint arg_id) +{ + GtkProgress *progress; + + progress = GTK_PROGRESS (object); + + switch (arg_id) + { + case ARG_ACTIVITY_MODE: + gtk_progress_set_activity_mode (progress, GTK_VALUE_BOOL (*arg)); + break; + case ARG_SHOW_TEXT: + gtk_progress_set_show_text (progress, GTK_VALUE_BOOL (*arg)); + break; + case ARG_TEXT_XALIGN: + gtk_progress_set_text_alignment (progress, GTK_VALUE_FLOAT (*arg), progress->y_align); + break; + case ARG_TEXT_YALIGN: + gtk_progress_set_text_alignment (progress, progress->x_align, GTK_VALUE_FLOAT (*arg)); + break; + default: + break; + } +} + +static void +gtk_progress_get_arg (GtkObject *object, + GtkArg *arg, + guint arg_id) +{ + GtkProgress *progress; + + progress = GTK_PROGRESS (object); + + switch (arg_id) + { + case ARG_ACTIVITY_MODE: + GTK_VALUE_BOOL (*arg) = (progress->activity_mode != 0); + break; + case ARG_SHOW_TEXT: + GTK_VALUE_BOOL (*arg) = (progress->show_text != 0); + break; + case ARG_TEXT_XALIGN: + GTK_VALUE_FLOAT (*arg) = progress->x_align; + break; + case ARG_TEXT_YALIGN: + GTK_VALUE_FLOAT (*arg) = progress->y_align; + break; + default: + arg->type = GTK_TYPE_INVALID; + break; + } +} + static void gtk_progress_init (GtkProgress *progress) { - GTK_WIDGET_SET_FLAGS (progress, GTK_BASIC); - + progress->adjustment = NULL; progress->offscreen_pixmap = NULL; progress->format = g_strdup ("%P %%"); progress->x_align = 0.5; @@ -136,6 +227,23 @@ gtk_progress_realize (GtkWidget *widget) gtk_progress_create_pixmap (progress); } +static void +gtk_progress_destroy (GtkObject *object) +{ + GtkProgress *progress; + + g_return_if_fail (object != NULL); + g_return_if_fail (GTK_IS_PROGRESS (object)); + + progress = GTK_PROGRESS (object); + + if (progress->adjustment) + gtk_signal_disconnect_by_data (GTK_OBJECT (progress->adjustment), + progress); + + GTK_OBJECT_CLASS (parent_class)->destroy (object); +} + static void gtk_progress_finalize (GtkObject *object) { @@ -146,7 +254,8 @@ gtk_progress_finalize (GtkObject *object) progress = GTK_PROGRESS (object); - gtk_object_unref (GTK_OBJECT (GTK_PROGRESS (object)->adjustment)); + if (progress->adjustment) + gtk_object_unref (GTK_OBJECT (GTK_PROGRESS (object)->adjustment)); if (progress->offscreen_pixmap) gdk_pixmap_unref (progress->offscreen_pixmap); @@ -340,6 +449,10 @@ gtk_progress_set_adjustment (GtkProgress *progress, { g_return_if_fail (progress != NULL); g_return_if_fail (GTK_IS_PROGRESS (progress)); + if (adjustment) + g_return_if_fail (GTK_IS_ADJUSTMENT (adjustment)); + else + adjustment = (GtkAdjustment*) gtk_object_new (GTK_TYPE_ADJUSTMENT, NULL); if (progress->adjustment != adjustment) { diff --git a/gtk/gtkprogress.h b/gtk/gtkprogress.h index 7deaeeaab4..2bb4f3d785 100644 --- a/gtk/gtkprogress.h +++ b/gtk/gtkprogress.h @@ -31,9 +31,11 @@ extern "C" { #endif /* __cplusplus */ -#define GTK_PROGRESS(obj) GTK_CHECK_CAST (obj, gtk_progress_get_type (), GtkProgress) -#define GTK_PROGRESS_CLASS(klass) GTK_CHECK_CLASS_CAST (klass, gtk_progress_get_type (), GtkProgressClass) -#define GTK_IS_PROGRESS(obj) GTK_CHECK_TYPE (obj, gtk_progress_get_type ()) +#define GTK_TYPE_PROGRESS (gtk_progress_get_type ()) +#define GTK_PROGRESS(obj) (GTK_CHECK_CAST ((obj), GTK_TYPE_PROGRESS, GtkProgress)) +#define GTK_PROGRESS_CLASS(klass) (GTK_CHECK_CLASS_CAST ((klass), GTK_TYPE_PROGRESS, GtkProgressClass)) +#define GTK_IS_PROGRESS(obj) (GTK_CHECK_TYPE ((obj), GTK_TYPE_PROGRESS)) +#define GTK_IS_PROGRESS_CLASS(klass) (GTK_CHECK_CLASS_TYPE ((klass), GTK_TYPE_PROGRESS)) typedef struct _GtkProgress GtkProgress; @@ -64,7 +66,7 @@ struct _GtkProgressClass }; -guint gtk_progress_get_type (void); +GtkType gtk_progress_get_type (void); void gtk_progress_set_show_text (GtkProgress *progress, gint show_text); void gtk_progress_set_text_alignment (GtkProgress *progress, @@ -85,8 +87,8 @@ void gtk_progress_set_value (GtkProgress *progress, gfloat gtk_progress_get_value (GtkProgress *progress); void gtk_progress_set_activity_mode (GtkProgress *progress, guint activity_mode); -gchar * gtk_progress_get_current_text (GtkProgress *progress); -gchar * gtk_progress_get_text_from_value (GtkProgress *progress, +gchar* gtk_progress_get_current_text (GtkProgress *progress); +gchar* gtk_progress_get_text_from_value (GtkProgress *progress, gfloat value); gfloat gtk_progress_get_current_percentage (GtkProgress *progress); gfloat gtk_progress_get_percentage_from_value (GtkProgress *progress, diff --git a/gtk/gtkprogressbar.c b/gtk/gtkprogressbar.c index 429f8a435d..50518adcf9 100644 --- a/gtk/gtkprogressbar.c +++ b/gtk/gtkprogressbar.c @@ -29,9 +29,24 @@ #define MAX_TEXT_LENGTH 80 #define TEXT_SPACING 2 +enum { + ARG_0, + ARG_ADJUSTMENT, + ARG_ORIENTATION, + ARG_BAR_STYLE, + ARG_ACTIVITY_STEP, + ARG_ACTIVITY_BLOCKS, + ARG_DISCRETE_BLOCKS +}; static void gtk_progress_bar_class_init (GtkProgressBarClass *klass); static void gtk_progress_bar_init (GtkProgressBar *pbar); +static void gtk_progress_bar_set_arg (GtkObject *object, + GtkArg *arg, + guint arg_id); +static void gtk_progress_bar_get_arg (GtkObject *object, + GtkArg *arg, + guint arg_id); static void gtk_progress_bar_size_request (GtkWidget *widget, GtkRequisition *requisition); static void gtk_progress_bar_real_update (GtkProgress *progress); @@ -39,10 +54,10 @@ static void gtk_progress_bar_paint (GtkProgress *progress); static void gtk_progress_bar_act_mode_enter (GtkProgress *progress); -guint +GtkType gtk_progress_bar_get_type (void) { - static guint progress_bar_type = 0; + static GtkType progress_bar_type = 0; if (!progress_bar_type) { @@ -58,8 +73,7 @@ gtk_progress_bar_get_type (void) (GtkClassInitFunc) NULL }; - progress_bar_type = gtk_type_unique (gtk_progress_get_type (), - &progress_bar_info); + progress_bar_type = gtk_type_unique (GTK_TYPE_PROGRESS, &progress_bar_info); } return progress_bar_type; @@ -68,11 +82,41 @@ gtk_progress_bar_get_type (void) static void gtk_progress_bar_class_init (GtkProgressBarClass *class) { + GtkObjectClass *object_class; GtkWidgetClass *widget_class; GtkProgressClass *progress_class; - + + object_class = (GtkObjectClass *) class; widget_class = (GtkWidgetClass *) class; progress_class = (GtkProgressClass *) class; + + gtk_object_add_arg_type ("GtkProgressBar::adjustment", + GTK_TYPE_ADJUSTMENT, + GTK_ARG_READWRITE | GTK_ARG_CONSTRUCT, + ARG_ADJUSTMENT); + gtk_object_add_arg_type ("GtkProgressBar::orientation", + GTK_TYPE_PROGRESS_BAR_ORIENTATION, + GTK_ARG_READWRITE, + ARG_ORIENTATION); + gtk_object_add_arg_type ("GtkProgressBar::bar_style", + GTK_TYPE_PROGRESS_BAR_STYLE, + GTK_ARG_READWRITE, + ARG_BAR_STYLE); + gtk_object_add_arg_type ("GtkProgressBar::activity_step", + GTK_TYPE_UINT, + GTK_ARG_READWRITE, + ARG_ACTIVITY_STEP); + gtk_object_add_arg_type ("GtkProgressBar::activity_blocks", + GTK_TYPE_UINT, + GTK_ARG_READWRITE, + ARG_ACTIVITY_BLOCKS); + gtk_object_add_arg_type ("GtkProgressBar::discrete_blocks", + GTK_TYPE_UINT, + GTK_ARG_READWRITE, + ARG_DISCRETE_BLOCKS); + + object_class->set_arg = gtk_progress_bar_set_arg; + object_class->get_arg = gtk_progress_bar_get_arg; widget_class->size_request = gtk_progress_bar_size_request; @@ -84,8 +128,6 @@ gtk_progress_bar_class_init (GtkProgressBarClass *class) static void gtk_progress_bar_init (GtkProgressBar *pbar) { - GTK_WIDGET_SET_FLAGS (pbar, GTK_BASIC); - pbar->bar_style = GTK_PROGRESS_CONTINUOUS; pbar->blocks = 10; pbar->in_block = -1; @@ -96,29 +138,98 @@ gtk_progress_bar_init (GtkProgressBar *pbar) pbar->activity_blocks = 5; } - -GtkWidget * -gtk_progress_bar_new (void) +static void +gtk_progress_bar_set_arg (GtkObject *object, + GtkArg *arg, + guint arg_id) { GtkProgressBar *pbar; - pbar = gtk_type_new (gtk_progress_bar_get_type ()); + pbar = GTK_PROGRESS_BAR (object); - gtk_progress_bar_construct (pbar, NULL); - - return GTK_WIDGET (pbar); + switch (arg_id) + { + case ARG_ADJUSTMENT: + gtk_progress_set_adjustment (GTK_PROGRESS (pbar), GTK_VALUE_POINTER (*arg)); + break; + case ARG_ORIENTATION: + gtk_progress_bar_set_orientation (pbar, GTK_VALUE_ENUM (*arg)); + break; + case ARG_BAR_STYLE: + gtk_progress_bar_set_bar_style (pbar, GTK_VALUE_ENUM (*arg)); + break; + case ARG_ACTIVITY_STEP: + gtk_progress_bar_set_activity_step (pbar, GTK_VALUE_UINT (*arg)); + break; + case ARG_ACTIVITY_BLOCKS: + gtk_progress_bar_set_activity_blocks (pbar, GTK_VALUE_UINT (*arg)); + break; + case ARG_DISCRETE_BLOCKS: + gtk_progress_bar_set_discrete_blocks (pbar, GTK_VALUE_UINT (*arg)); + break; + default: + break; + } } -GtkWidget * -gtk_progress_bar_new_with_adjustment (GtkAdjustment *adjustment) +static void +gtk_progress_bar_get_arg (GtkObject *object, + GtkArg *arg, + guint arg_id) { GtkProgressBar *pbar; - pbar = gtk_type_new (gtk_progress_bar_get_type ()); + pbar = GTK_PROGRESS_BAR (object); - gtk_progress_bar_construct (pbar, adjustment); + switch (arg_id) + { + case ARG_ADJUSTMENT: + GTK_VALUE_POINTER (*arg) = GTK_PROGRESS (pbar)->adjustment; + break; + case ARG_ORIENTATION: + GTK_VALUE_ENUM (*arg) = pbar->orientation; + break; + case ARG_BAR_STYLE: + GTK_VALUE_ENUM (*arg) = pbar->bar_style; + break; + case ARG_ACTIVITY_STEP: + GTK_VALUE_UINT (*arg) = pbar->activity_step; + break; + case ARG_ACTIVITY_BLOCKS: + GTK_VALUE_UINT (*arg) = pbar->activity_blocks; + break; + case ARG_DISCRETE_BLOCKS: + GTK_VALUE_UINT (*arg) = pbar->blocks; + break; + default: + arg->type = GTK_TYPE_INVALID; + break; + } +} - return GTK_WIDGET (pbar); +GtkWidget* +gtk_progress_bar_new (void) +{ + GtkWidget *pbar; + + pbar = gtk_widget_new (GTK_TYPE_PROGRESS_BAR, NULL); + + return pbar; +} + +GtkWidget* +gtk_progress_bar_new_with_adjustment (GtkAdjustment *adjustment) +{ + GtkWidget *pbar; + + g_return_val_if_fail (adjustment != NULL, NULL); + g_return_val_if_fail (GTK_IS_ADJUSTMENT (adjustment), NULL); + + pbar = gtk_widget_new (GTK_TYPE_PROGRESS_BAR, + "adjustment", adjustment, + NULL); + + return pbar; } void @@ -128,8 +239,7 @@ gtk_progress_bar_construct (GtkProgressBar *pbar, g_return_if_fail (pbar != NULL); g_return_if_fail (GTK_IS_PROGRESS_BAR (pbar)); - if (!adjustment) - adjustment = (GtkAdjustment *) gtk_adjustment_new (0, 0, 100, 0, 0, 0); + g_message ("gtk_progress_bar_construct() is deprecated"); gtk_progress_set_adjustment (GTK_PROGRESS (pbar), adjustment); } diff --git a/gtk/gtkprogressbar.h b/gtk/gtkprogressbar.h index a8f235fa0e..20debc3d7e 100644 --- a/gtk/gtkprogressbar.h +++ b/gtk/gtkprogressbar.h @@ -30,9 +30,11 @@ extern "C" { #endif /* __cplusplus */ -#define GTK_PROGRESS_BAR(obj) GTK_CHECK_CAST (obj, gtk_progress_bar_get_type (), GtkProgressBar) -#define GTK_PROGRESS_BAR_CLASS(klass) GTK_CHECK_CLASS_CAST (klass, gtk_progress_bar_get_type (), GtkProgressBarClass) -#define GTK_IS_PROGRESS_BAR(obj) GTK_CHECK_TYPE (obj, gtk_progress_bar_get_type ()) +#define GTK_TYPE_PROGRESS_BAR (gtk_progress_bar_get_type ()) +#define GTK_PROGRESS_BAR(obj) (GTK_CHECK_CAST ((obj), GTK_TYPE_PROGRESS_BAR, GtkProgressBar)) +#define GTK_PROGRESS_BAR_CLASS(klass) (GTK_CHECK_CLASS_CAST ((klass), GTK_TYPE_PROGRESS_BAR, GtkProgressBarClass)) +#define GTK_IS_PROGRESS_BAR(obj) (GTK_CHECK_TYPE ((obj), GTK_TYPE_PROGRESS_BAR)) +#define GTK_IS_PROGRESS_BAR_CLASS(klass) (GTK_CHECK_CLASS_TYPE ((klass), GTK_TYPE_PROGRESS_BAR)) typedef struct _GtkProgressBar GtkProgressBar; @@ -74,11 +76,9 @@ struct _GtkProgressBarClass }; -guint gtk_progress_bar_get_type (void); +GtkType gtk_progress_bar_get_type (void); GtkWidget* gtk_progress_bar_new (void); GtkWidget* gtk_progress_bar_new_with_adjustment (GtkAdjustment *adjustment); -void gtk_progress_bar_construct (GtkProgressBar *pbar, - GtkAdjustment *adjustment); void gtk_progress_bar_set_bar_style (GtkProgressBar *pbar, GtkProgressBarStyle style); void gtk_progress_bar_set_discrete_blocks (GtkProgressBar *pbar, @@ -92,6 +92,10 @@ void gtk_progress_bar_set_orientation (GtkProgressBar *pbar, void gtk_progress_bar_update (GtkProgressBar *pbar, gfloat percentage); +/* deprecated */ +void gtk_progress_bar_construct (GtkProgressBar *pbar, + GtkAdjustment *adjustment); + #ifdef __cplusplus } diff --git a/gtk/gtkrange.c b/gtk/gtkrange.c index b3affe3da8..675e76bfe5 100644 --- a/gtk/gtkrange.c +++ b/gtk/gtkrange.c @@ -28,9 +28,20 @@ #define RANGE_CLASS(w) GTK_RANGE_CLASS (GTK_OBJECT (w)->klass) +enum { + ARG_0, + ARG_UPDATE_POLICY +}; static void gtk_range_class_init (GtkRangeClass *klass); static void gtk_range_init (GtkRange *range); +static void gtk_range_set_arg (GtkObject *object, + GtkArg *arg, + guint arg_id); +static void gtk_range_get_arg (GtkObject *object, + GtkArg *arg, + guint arg_id); +static void gtk_range_destroy (GtkObject *object); static void gtk_range_finalize (GtkObject *object); static void gtk_range_draw (GtkWidget *widget, GdkRectangle *area); @@ -81,10 +92,10 @@ static void gtk_range_trough_vdims (GtkRange *range, static GtkWidgetClass *parent_class = NULL; -guint +GtkType gtk_range_get_type (void) { - static guint range_type = 0; + static GtkType range_type = 0; if (!range_type) { @@ -100,7 +111,7 @@ gtk_range_get_type (void) (GtkClassInitFunc) NULL, }; - range_type = gtk_type_unique (gtk_widget_get_type (), &range_info); + range_type = gtk_type_unique (GTK_TYPE_WIDGET, &range_info); } return range_type; @@ -115,8 +126,16 @@ gtk_range_class_init (GtkRangeClass *class) object_class = (GtkObjectClass*) class; widget_class = (GtkWidgetClass*) class; - parent_class = gtk_type_class (gtk_widget_get_type ()); + parent_class = gtk_type_class (GTK_TYPE_WIDGET); + gtk_object_add_arg_type ("GtkRange::update_policy", + GTK_TYPE_UPDATE_TYPE, + GTK_ARG_READWRITE, + ARG_UPDATE_POLICY); + + object_class->set_arg = gtk_range_set_arg; + object_class->get_arg = gtk_range_get_arg; + object_class->destroy = gtk_range_destroy; object_class->finalize = gtk_range_finalize; widget_class->draw = gtk_range_draw; @@ -153,6 +172,45 @@ gtk_range_class_init (GtkRangeClass *class) class->timer = gtk_real_range_timer; } +static void +gtk_range_set_arg (GtkObject *object, + GtkArg *arg, + guint arg_id) +{ + GtkRange *range; + + range = GTK_RANGE (object); + + switch (arg_id) + { + case ARG_UPDATE_POLICY: + gtk_range_set_update_policy (range, GTK_VALUE_ENUM (*arg)); + break; + default: + break; + } +} + +static void +gtk_range_get_arg (GtkObject *object, + GtkArg *arg, + guint arg_id) +{ + GtkRange *range; + + range = GTK_RANGE (object); + + switch (arg_id) + { + case ARG_UPDATE_POLICY: + GTK_VALUE_ENUM (*arg) = range->policy; + break; + default: + arg->type = GTK_TYPE_INVALID; + break; + } +} + static void gtk_range_init (GtkRange *range) { @@ -203,6 +261,11 @@ gtk_range_set_adjustment (GtkRange *range, { g_return_if_fail (range != NULL); g_return_if_fail (GTK_IS_RANGE (range)); + + if (!adjustment) + adjustment = (GtkAdjustment*) gtk_adjustment_new (0.0, 0.0, 0.0, 0.0, 0.0, 0.0); + else + g_return_if_fail (GTK_IS_ADJUSTMENT (adjustment)); if (range->adjustment != adjustment) { @@ -212,26 +275,24 @@ gtk_range_set_adjustment (GtkRange *range, (gpointer) range); gtk_object_unref (GTK_OBJECT (range->adjustment)); } + range->adjustment = adjustment; - if (adjustment) - { - gtk_object_ref (GTK_OBJECT (adjustment)); - gtk_object_sink (GTK_OBJECT (adjustment)); - - gtk_signal_connect (GTK_OBJECT (adjustment), "changed", - (GtkSignalFunc) gtk_range_adjustment_changed, - (gpointer) range); - gtk_signal_connect (GTK_OBJECT (adjustment), "value_changed", - (GtkSignalFunc) gtk_range_adjustment_value_changed, - (gpointer) range); - - range->old_value = adjustment->value; - range->old_lower = adjustment->lower; - range->old_upper = adjustment->upper; - range->old_page_size = adjustment->page_size; - - gtk_range_adjustment_changed (adjustment, (gpointer) range); - } + gtk_object_ref (GTK_OBJECT (adjustment)); + gtk_object_sink (GTK_OBJECT (adjustment)); + + gtk_signal_connect (GTK_OBJECT (adjustment), "changed", + (GtkSignalFunc) gtk_range_adjustment_changed, + (gpointer) range); + gtk_signal_connect (GTK_OBJECT (adjustment), "value_changed", + (GtkSignalFunc) gtk_range_adjustment_value_changed, + (gpointer) range); + + range->old_value = adjustment->value; + range->old_lower = adjustment->lower; + range->old_upper = adjustment->upper; + range->old_page_size = adjustment->page_size; + + gtk_range_adjustment_changed (adjustment, (gpointer) range); } } @@ -622,6 +683,23 @@ gtk_range_default_vmotion (GtkRange *range, } +static void +gtk_range_destroy (GtkObject *object) +{ + GtkRange *range; + + g_return_if_fail (object != NULL); + g_return_if_fail (GTK_IS_RANGE (object)); + + range = GTK_RANGE (object); + + if (range->adjustment) + gtk_signal_disconnect_by_data (GTK_OBJECT (range->adjustment), + (gpointer) range); + + (* GTK_OBJECT_CLASS (parent_class)->destroy) (object); +} + static void gtk_range_finalize (GtkObject *object) { diff --git a/gtk/gtkrange.h b/gtk/gtkrange.h index 48da24c659..1f9292c4d0 100644 --- a/gtk/gtkrange.h +++ b/gtk/gtkrange.h @@ -30,9 +30,11 @@ extern "C" { #endif /* __cplusplus */ -#define GTK_RANGE(obj) GTK_CHECK_CAST (obj, gtk_range_get_type (), GtkRange) -#define GTK_RANGE_CLASS(klass) GTK_CHECK_CLASS_CAST (klass, gtk_range_get_type (), GtkRangeClass) -#define GTK_IS_RANGE(obj) GTK_CHECK_TYPE (obj, gtk_range_get_type ()) +#define GTK_TYPE_RANGE (gtk_range_get_type ()) +#define GTK_RANGE(obj) (GTK_CHECK_CAST ((obj), GTK_TYPE_RANGE, GtkRange)) +#define GTK_RANGE_CLASS(klass) (GTK_CHECK_CLASS_CAST ((klass), GTK_TYPE_RANGE, GtkRangeClass)) +#define GTK_IS_RANGE(obj) (GTK_CHECK_TYPE ((obj), GTK_TYPE_RANGE)) +#define GTK_IS_RANGE_CLASS(klass) (GTK_CHECK_CLASS_TYPE ((klass), GTK_TYPE_RANGE)) typedef struct _GtkRange GtkRange; @@ -104,7 +106,7 @@ struct _GtkRangeClass }; -guint gtk_range_get_type (void); +GtkType gtk_range_get_type (void); GtkAdjustment* gtk_range_get_adjustment (GtkRange *range); void gtk_range_set_update_policy (GtkRange *range, GtkUpdateType policy); diff --git a/gtk/gtkscale.c b/gtk/gtkscale.c index 9992160a44..2bc4944a0e 100644 --- a/gtk/gtkscale.c +++ b/gtk/gtkscale.c @@ -35,10 +35,10 @@ static void gtk_scale_draw_background (GtkRange *range); static GtkRangeClass *parent_class = NULL; -guint +GtkType gtk_scale_get_type (void) { - static guint scale_type = 0; + static GtkType scale_type = 0; if (!scale_type) { @@ -54,7 +54,7 @@ gtk_scale_get_type (void) (GtkClassInitFunc) NULL, }; - scale_type = gtk_type_unique (gtk_range_get_type (), &scale_info); + scale_type = gtk_type_unique (GTK_TYPE_RANGE, &scale_info); } return scale_type; @@ -71,7 +71,7 @@ gtk_scale_class_init (GtkScaleClass *class) range_class = (GtkRangeClass*) class; widget_class = (GtkWidgetClass*) class; - parent_class = gtk_type_class (gtk_range_get_type ()); + parent_class = gtk_type_class (GTK_TYPE_RANGE); widget_class->map = gtk_scale_map; widget_class->unmap = gtk_scale_unmap; diff --git a/gtk/gtkscale.h b/gtk/gtkscale.h index b5e2e33f8b..5d7bba1bde 100644 --- a/gtk/gtkscale.h +++ b/gtk/gtkscale.h @@ -29,9 +29,11 @@ extern "C" { #endif /* __cplusplus */ -#define GTK_SCALE(obj) GTK_CHECK_CAST (obj, gtk_scale_get_type (), GtkScale) -#define GTK_SCALE_CLASS(klass) GTK_CHECK_CLASS_CAST (klass, gtk_scale_get_type (), GtkScaleClass) -#define GTK_IS_SCALE(obj) GTK_CHECK_TYPE (obj, gtk_scale_get_type ()) +#define GTK_TYPE_SCALE (gtk_scale_get_type ()) +#define GTK_SCALE(obj) (GTK_CHECK_CAST ((obj), GTK_TYPE_SCALE, GtkScale)) +#define GTK_SCALE_CLASS(klass) (GTK_CHECK_CLASS_CAST ((klass), GTK_TYPE_SCALE, GtkScaleClass)) +#define GTK_IS_SCALE(obj) (GTK_CHECK_TYPE ((obj), GTK_TYPE_SCALE)) +#define GTK_IS_SCALE_CLASS(klass) (GTK_CHECK_CLASS_TYPE ((klass), GTK_TYPE_SCALE)) typedef struct _GtkScale GtkScale; @@ -51,21 +53,21 @@ struct _GtkScaleClass gint slider_length; gint value_spacing; - + void (* draw_value) (GtkScale *scale); }; -guint gtk_scale_get_type (void); -void gtk_scale_set_digits (GtkScale *scale, - gint digits); -void gtk_scale_set_draw_value (GtkScale *scale, - gint draw_value); -void gtk_scale_set_value_pos (GtkScale *scale, - GtkPositionType pos); -gint gtk_scale_value_width (GtkScale *scale); +GtkType gtk_scale_get_type (void); +void gtk_scale_set_digits (GtkScale *scale, + gint digits); +void gtk_scale_set_draw_value (GtkScale *scale, + gint draw_value); +void gtk_scale_set_value_pos (GtkScale *scale, + GtkPositionType pos); +gint gtk_scale_value_width (GtkScale *scale); -void gtk_scale_draw_value (GtkScale *scale); +void gtk_scale_draw_value (GtkScale *scale); #ifdef __cplusplus diff --git a/gtk/gtkscrollbar.c b/gtk/gtkscrollbar.c index cd8438be94..97bc35db05 100644 --- a/gtk/gtkscrollbar.c +++ b/gtk/gtkscrollbar.c @@ -21,10 +21,10 @@ static void gtk_scrollbar_class_init (GtkScrollbarClass *klass); static void gtk_scrollbar_init (GtkScrollbar *scrollbar); -guint +GtkType gtk_scrollbar_get_type (void) { - static guint scrollbar_type = 0; + static GtkType scrollbar_type = 0; if (!scrollbar_type) { @@ -40,7 +40,7 @@ gtk_scrollbar_get_type (void) (GtkClassInitFunc) NULL, }; - scrollbar_type = gtk_type_unique (gtk_range_get_type (), &scrollbar_info); + scrollbar_type = gtk_type_unique (GTK_TYPE_RANGE, &scrollbar_info); } return scrollbar_type; diff --git a/gtk/gtkscrollbar.h b/gtk/gtkscrollbar.h index bf4887a7c0..dd4ae8d6ac 100644 --- a/gtk/gtkscrollbar.h +++ b/gtk/gtkscrollbar.h @@ -29,9 +29,11 @@ extern "C" { #endif /* __cplusplus */ -#define GTK_SCROLLBAR(obj) GTK_CHECK_CAST (obj, gtk_scrollbar_get_type (), GtkScrollbar) -#define GTK_SCROLLBAR_CLASS(klass) GTK_CHECK_CLASS_CAST (klass, gtk_scrollbar_get_type (), GtkScrollbarClass) -#define GTK_IS_SCROLLBAR(obj) GTK_CHECK_TYPE (obj, gtk_scrollbar_get_type ()) +#define GTK_TYPE_SCROLLBAR (gtk_scrollbar_get_type ()) +#define GTK_SCROLLBAR(obj) (GTK_CHECK_CAST ((obj), GTK_TYPE_SCROLLBAR, GtkScrollbar)) +#define GTK_SCROLLBAR_CLASS(klass) (GTK_CHECK_CLASS_CAST ((klass), GTK_TYPE_SCROLLBAR, GtkScrollbarClass)) +#define GTK_IS_SCROLLBAR(obj) (GTK_CHECK_TYPE ((obj), GTK_TYPE_SCROLLBAR)) +#define GTK_IS_SCROLLBAR_CLASS(klass) (GTK_CHECK_CLASS_TYPE ((klass), GTK_TYPE_SCROLLBAR)) typedef struct _GtkScrollbar GtkScrollbar; @@ -48,7 +50,7 @@ struct _GtkScrollbarClass }; -guint gtk_scrollbar_get_type (void); +GtkType gtk_scrollbar_get_type (void); #ifdef __cplusplus diff --git a/gtk/gtkscrolledwindow.c b/gtk/gtkscrolledwindow.c index ce2964dc9c..d68960b924 100644 --- a/gtk/gtkscrolledwindow.c +++ b/gtk/gtkscrolledwindow.c @@ -24,7 +24,8 @@ enum { ARG_0, - ARG_VIEWPORT, + ARG_HADJUSTMENT, + ARG_VADJUSTMENT, ARG_HSCROLLBAR_POLICY, ARG_VSCROLLBAR_POLICY, ARG_WINDOW_PLACEMENT @@ -57,7 +58,7 @@ static void gtk_scrolled_window_forall (GtkContainer *cont gboolean include_internals, GtkCallback callback, gpointer callback_data); -static void gtk_scrolled_window_viewport_allocate (GtkWidget *widget, +static void gtk_scrolled_window_relative_allocation(GtkWidget *widget, GtkAllocation *allocation); static void gtk_scrolled_window_adjustment_changed (GtkAdjustment *adjustment, gpointer data); @@ -103,10 +104,14 @@ gtk_scrolled_window_class_init (GtkScrolledWindowClass *class) container_class = (GtkContainerClass*) class; parent_class = gtk_type_class (GTK_TYPE_CONTAINER); - gtk_object_add_arg_type ("GtkScrolledWindow::viewport", - GTK_TYPE_VIEWPORT, + gtk_object_add_arg_type ("GtkScrolledWindow::hadjustment", + GTK_TYPE_ADJUSTMENT, GTK_ARG_READWRITE | GTK_ARG_CONSTRUCT, - ARG_VIEWPORT); + ARG_HADJUSTMENT); + gtk_object_add_arg_type ("GtkScrolledWindow::vadjustment", + GTK_TYPE_ADJUSTMENT, + GTK_ARG_READWRITE | GTK_ARG_CONSTRUCT, + ARG_VADJUSTMENT); gtk_object_add_arg_type ("GtkScrolledWindow::hscrollbar_policy", GTK_TYPE_POLICY_TYPE, GTK_ARG_READWRITE, @@ -149,11 +154,12 @@ gtk_scrolled_window_set_arg (GtkObject *object, switch (arg_id) { - GtkWidget *viewport; - - case ARG_VIEWPORT: - viewport = GTK_VALUE_POINTER (*arg); - gtk_container_add (GTK_CONTAINER (scrolled_window), viewport); + case ARG_HADJUSTMENT: + gtk_scrolled_window_set_hadjustment (scrolled_window, GTK_VALUE_POINTER (*arg)); + break; + case ARG_VADJUSTMENT: + gtk_scrolled_window_set_vadjustment (scrolled_window, GTK_VALUE_POINTER (*arg)); + break; case ARG_HSCROLLBAR_POLICY: gtk_scrolled_window_set_policy (scrolled_window, GTK_VALUE_ENUM (*arg), @@ -184,8 +190,11 @@ gtk_scrolled_window_get_arg (GtkObject *object, switch (arg_id) { - case ARG_VIEWPORT: - GTK_VALUE_POINTER (*arg) = scrolled_window->viewport; + case ARG_HADJUSTMENT: + GTK_VALUE_POINTER (*arg) = gtk_scrolled_window_get_hadjustment (scrolled_window); + break; + case ARG_VADJUSTMENT: + GTK_VALUE_POINTER (*arg) = gtk_scrolled_window_get_vadjustment (scrolled_window); break; case ARG_HSCROLLBAR_POLICY: GTK_VALUE_ENUM (*arg) = scrolled_window->hscrollbar_policy; @@ -209,12 +218,14 @@ gtk_scrolled_window_init (GtkScrolledWindow *scrolled_window) gtk_container_set_resize_mode (GTK_CONTAINER (scrolled_window), GTK_RESIZE_QUEUE); + scrolled_window->child = NULL; scrolled_window->hscrollbar = NULL; scrolled_window->vscrollbar = NULL; scrolled_window->hscrollbar_policy = GTK_POLICY_ALWAYS; scrolled_window->vscrollbar_policy = GTK_POLICY_ALWAYS; + scrolled_window->hscrollbar_visible = FALSE; + scrolled_window->vscrollbar_visible = FALSE; scrolled_window->window_placement = GTK_CORNER_TOP_LEFT; - scrolled_window->autogenerated_viewport = FALSE; } GtkWidget* @@ -223,9 +234,16 @@ gtk_scrolled_window_new (GtkAdjustment *hadjustment, { GtkWidget *scrolled_window; - scrolled_window = gtk_type_new (GTK_TYPE_SCROLLED_WINDOW); + if (hadjustment) + g_return_val_if_fail (GTK_IS_ADJUSTMENT (hadjustment), NULL); - gtk_scrolled_window_construct (GTK_SCROLLED_WINDOW (scrolled_window), hadjustment, vadjustment); + if (vadjustment) + g_return_val_if_fail (GTK_IS_ADJUSTMENT (vadjustment), NULL); + + scrolled_window = gtk_widget_new (GTK_TYPE_SCROLLED_WINDOW, + "hadjustment", hadjustment, + "vadjustment", vadjustment, + NULL); return scrolled_window; } @@ -234,35 +252,107 @@ void gtk_scrolled_window_construct (GtkScrolledWindow *scrolled_window, GtkAdjustment *hadjustment, GtkAdjustment *vadjustment) +{ + g_message ("gtk_scrolled_window_construct() is deprecated"); + gtk_scrolled_window_set_hadjustment (scrolled_window, hadjustment); + gtk_scrolled_window_set_vadjustment (scrolled_window, vadjustment); + gtk_object_default_construct (GTK_OBJECT (scrolled_window)); +} + +void +gtk_scrolled_window_set_hadjustment (GtkScrolledWindow *scrolled_window, + GtkAdjustment *hadjustment) { g_return_if_fail (scrolled_window != NULL); g_return_if_fail (GTK_IS_SCROLLED_WINDOW (scrolled_window)); - g_return_if_fail (scrolled_window->hscrollbar == NULL); - g_return_if_fail (scrolled_window->vscrollbar == NULL); + if (hadjustment) + g_return_if_fail (GTK_IS_ADJUSTMENT (hadjustment)); + else + hadjustment = (GtkAdjustment*) gtk_object_new (GTK_TYPE_ADJUSTMENT, NULL); - scrolled_window->hscrollbar = gtk_hscrollbar_new (hadjustment); - scrolled_window->vscrollbar = gtk_vscrollbar_new (vadjustment); + if (!scrolled_window->hscrollbar) + { + gtk_widget_push_composite_child (); + scrolled_window->hscrollbar = gtk_hscrollbar_new (hadjustment); + gtk_widget_pop_composite_child (); - hadjustment = - gtk_range_get_adjustment (GTK_RANGE (scrolled_window->hscrollbar)); - vadjustment = - gtk_range_get_adjustment (GTK_RANGE (scrolled_window->vscrollbar)); + gtk_widget_set_parent (scrolled_window->hscrollbar, GTK_WIDGET (scrolled_window)); + gtk_widget_ref (scrolled_window->hscrollbar); + gtk_widget_show (scrolled_window->hscrollbar); + } + else + { + GtkAdjustment *old_adjustment; + + old_adjustment = gtk_range_get_adjustment (GTK_RANGE (scrolled_window->hscrollbar)); + if (old_adjustment == hadjustment) + return; - gtk_signal_connect (GTK_OBJECT (hadjustment), "changed", - (GtkSignalFunc) gtk_scrolled_window_adjustment_changed, - (gpointer) scrolled_window); - gtk_signal_connect (GTK_OBJECT (vadjustment), "changed", - (GtkSignalFunc) gtk_scrolled_window_adjustment_changed, - (gpointer) scrolled_window); - - gtk_widget_set_parent (scrolled_window->hscrollbar, GTK_WIDGET (scrolled_window)); - gtk_widget_set_parent (scrolled_window->vscrollbar, GTK_WIDGET (scrolled_window)); - - gtk_widget_show (scrolled_window->hscrollbar); - gtk_widget_show (scrolled_window->vscrollbar); + gtk_signal_disconnect_by_func (GTK_OBJECT (old_adjustment), + GTK_SIGNAL_FUNC (gtk_scrolled_window_adjustment_changed), + scrolled_window); + gtk_range_set_adjustment (GTK_RANGE (scrolled_window->hscrollbar), + hadjustment); + } + hadjustment = gtk_range_get_adjustment (GTK_RANGE (scrolled_window->hscrollbar)); + gtk_signal_connect (GTK_OBJECT (hadjustment), + "changed", + GTK_SIGNAL_FUNC (gtk_scrolled_window_adjustment_changed), + scrolled_window); + gtk_scrolled_window_adjustment_changed (hadjustment, scrolled_window); - gtk_widget_ref (scrolled_window->hscrollbar); - gtk_widget_ref (scrolled_window->vscrollbar); + if (scrolled_window->child) + gtk_widget_scroll_adjustements (scrolled_window->child, + gtk_range_get_adjustment (GTK_RANGE (scrolled_window->hscrollbar)), + gtk_range_get_adjustment (GTK_RANGE (scrolled_window->vscrollbar))); +} + +void +gtk_scrolled_window_set_vadjustment (GtkScrolledWindow *scrolled_window, + GtkAdjustment *vadjustment) +{ + g_return_if_fail (scrolled_window != NULL); + g_return_if_fail (GTK_IS_SCROLLED_WINDOW (scrolled_window)); + if (vadjustment) + g_return_if_fail (GTK_IS_ADJUSTMENT (vadjustment)); + else + vadjustment = (GtkAdjustment*) gtk_object_new (GTK_TYPE_ADJUSTMENT, NULL); + + if (!scrolled_window->vscrollbar) + { + gtk_widget_push_composite_child (); + scrolled_window->vscrollbar = gtk_vscrollbar_new (vadjustment); + gtk_widget_pop_composite_child (); + + gtk_widget_set_parent (scrolled_window->vscrollbar, GTK_WIDGET (scrolled_window)); + gtk_widget_ref (scrolled_window->vscrollbar); + gtk_widget_show (scrolled_window->vscrollbar); + } + else + { + GtkAdjustment *old_adjustment; + + old_adjustment = gtk_range_get_adjustment (GTK_RANGE (scrolled_window->vscrollbar)); + if (old_adjustment == vadjustment) + return; + + gtk_signal_disconnect_by_func (GTK_OBJECT (old_adjustment), + GTK_SIGNAL_FUNC (gtk_scrolled_window_adjustment_changed), + scrolled_window); + gtk_range_set_adjustment (GTK_RANGE (scrolled_window->vscrollbar), + vadjustment); + } + vadjustment = gtk_range_get_adjustment (GTK_RANGE (scrolled_window->vscrollbar)); + gtk_signal_connect (GTK_OBJECT (vadjustment), + "changed", + GTK_SIGNAL_FUNC (gtk_scrolled_window_adjustment_changed), + scrolled_window); + gtk_scrolled_window_adjustment_changed (vadjustment, scrolled_window); + + if (scrolled_window->child) + gtk_widget_scroll_adjustements (scrolled_window->child, + gtk_range_get_adjustment (GTK_RANGE (scrolled_window->hscrollbar)), + gtk_range_get_adjustment (GTK_RANGE (scrolled_window->vscrollbar))); } GtkAdjustment* @@ -271,7 +361,9 @@ gtk_scrolled_window_get_hadjustment (GtkScrolledWindow *scrolled_window) g_return_val_if_fail (scrolled_window != NULL, NULL); g_return_val_if_fail (GTK_IS_SCROLLED_WINDOW (scrolled_window), NULL); - return gtk_range_get_adjustment (GTK_RANGE (scrolled_window->hscrollbar)); + return (scrolled_window->hscrollbar ? + gtk_range_get_adjustment (GTK_RANGE (scrolled_window->hscrollbar)) : + NULL); } GtkAdjustment* @@ -280,7 +372,9 @@ gtk_scrolled_window_get_vadjustment (GtkScrolledWindow *scrolled_window) g_return_val_if_fail (scrolled_window != NULL, NULL); g_return_val_if_fail (GTK_IS_SCROLLED_WINDOW (scrolled_window), NULL); - return gtk_range_get_adjustment (GTK_RANGE (scrolled_window->vscrollbar)); + return (scrolled_window->vscrollbar ? + gtk_range_get_adjustment (GTK_RANGE (scrolled_window->vscrollbar)) : + NULL); } void @@ -297,8 +391,7 @@ gtk_scrolled_window_set_policy (GtkScrolledWindow *scrolled_window, scrolled_window->hscrollbar_policy = hscrollbar_policy; scrolled_window->vscrollbar_policy = vscrollbar_policy; - if (GTK_WIDGET (scrolled_window)->parent) - gtk_widget_queue_resize (GTK_WIDGET (scrolled_window)); + gtk_widget_queue_resize (GTK_WIDGET (scrolled_window)); } } @@ -313,8 +406,7 @@ gtk_scrolled_window_set_placement (GtkScrolledWindow *scrolled_window, { scrolled_window->window_placement = window_placement; - if (GTK_WIDGET (scrolled_window)->parent) - gtk_widget_queue_resize (GTK_WIDGET (scrolled_window)); + gtk_widget_queue_resize (GTK_WIDGET (scrolled_window)); } } @@ -328,7 +420,8 @@ gtk_scrolled_window_destroy (GtkObject *object) scrolled_window = GTK_SCROLLED_WINDOW (object); - gtk_widget_destroy (scrolled_window->viewport); + gtk_widget_unparent (scrolled_window->hscrollbar); + gtk_widget_unparent (scrolled_window->vscrollbar); gtk_widget_destroy (scrolled_window->hscrollbar); gtk_widget_destroy (scrolled_window->vscrollbar); @@ -342,7 +435,7 @@ gtk_scrolled_window_finalize (GtkObject *object) GtkScrolledWindow *scrolled_window; scrolled_window = GTK_SCROLLED_WINDOW (object); - gtk_widget_unref (scrolled_window->viewport); + gtk_widget_unref (scrolled_window->hscrollbar); gtk_widget_unref (scrolled_window->vscrollbar); @@ -352,20 +445,20 @@ gtk_scrolled_window_finalize (GtkObject *object) static void gtk_scrolled_window_map (GtkWidget *widget) { - GtkScrolledWindow *scrolled_window; - g_return_if_fail (widget != NULL); g_return_if_fail (GTK_IS_SCROLLED_WINDOW (widget)); if (!GTK_WIDGET_MAPPED (widget)) { - GTK_WIDGET_SET_FLAGS (widget, GTK_MAPPED); - scrolled_window = GTK_SCROLLED_WINDOW (widget); + GtkScrolledWindow *scrolled_window; - if (scrolled_window->viewport && - GTK_WIDGET_VISIBLE (scrolled_window->viewport) && - !GTK_WIDGET_MAPPED (scrolled_window->viewport)) - gtk_widget_map (scrolled_window->viewport); + scrolled_window = GTK_SCROLLED_WINDOW (widget); + GTK_WIDGET_SET_FLAGS (widget, GTK_MAPPED); + + if (scrolled_window->child && + GTK_WIDGET_VISIBLE (scrolled_window->child) && + !GTK_WIDGET_MAPPED (scrolled_window->child)) + gtk_widget_map (scrolled_window->child); if (GTK_WIDGET_VISIBLE (scrolled_window->hscrollbar) && !GTK_WIDGET_MAPPED (scrolled_window->hscrollbar)) @@ -374,31 +467,36 @@ gtk_scrolled_window_map (GtkWidget *widget) if (GTK_WIDGET_VISIBLE (scrolled_window->vscrollbar) && !GTK_WIDGET_MAPPED (scrolled_window->vscrollbar)) gtk_widget_map (scrolled_window->vscrollbar); + + gtk_widget_queue_draw (widget); } } static void gtk_scrolled_window_unmap (GtkWidget *widget) { - GtkScrolledWindow *scrolled_window; - g_return_if_fail (widget != NULL); g_return_if_fail (GTK_IS_SCROLLED_WINDOW (widget)); if (GTK_WIDGET_MAPPED (widget)) { - GTK_WIDGET_UNSET_FLAGS (widget, GTK_MAPPED); - scrolled_window = GTK_SCROLLED_WINDOW (widget); + GtkScrolledWindow *scrolled_window; - if (scrolled_window->viewport && - GTK_WIDGET_MAPPED (scrolled_window->viewport)) - gtk_widget_unmap (scrolled_window->viewport); + scrolled_window = GTK_SCROLLED_WINDOW (widget); + GTK_WIDGET_UNSET_FLAGS (widget, GTK_MAPPED); + + if (scrolled_window->child && + GTK_WIDGET_VISIBLE (scrolled_window->child) && + GTK_WIDGET_MAPPED (scrolled_window->child)) + gtk_widget_unmap (scrolled_window->child); if (GTK_WIDGET_MAPPED (scrolled_window->hscrollbar)) gtk_widget_unmap (scrolled_window->hscrollbar); if (GTK_WIDGET_MAPPED (scrolled_window->vscrollbar)) gtk_widget_unmap (scrolled_window->vscrollbar); + + gtk_widget_queue_clear (widget); } } @@ -406,29 +504,54 @@ static void gtk_scrolled_window_draw (GtkWidget *widget, GdkRectangle *area) { - GtkScrolledWindow *scrolled_window; - GdkRectangle child_area; - g_return_if_fail (widget != NULL); g_return_if_fail (GTK_IS_SCROLLED_WINDOW (widget)); g_return_if_fail (area != NULL); - + if (GTK_WIDGET_DRAWABLE (widget)) { + GtkScrolledWindow *scrolled_window; + GdkRectangle child_area; + scrolled_window = GTK_SCROLLED_WINDOW (widget); + + if (scrolled_window->child && GTK_WIDGET_VISIBLE (scrolled_window->child) && + gtk_widget_intersect (scrolled_window->child, area, &child_area)) + gtk_widget_draw (scrolled_window->child, &child_area); - if (scrolled_window->viewport && - gtk_widget_intersect (scrolled_window->viewport, area, &child_area)) - gtk_widget_draw (scrolled_window->viewport, &child_area); - - if (gtk_widget_intersect (scrolled_window->hscrollbar, area, &child_area)) + if (GTK_WIDGET_VISIBLE (scrolled_window->hscrollbar) && + gtk_widget_intersect (scrolled_window->hscrollbar, area, &child_area)) gtk_widget_draw (scrolled_window->hscrollbar, &child_area); - if (gtk_widget_intersect (scrolled_window->vscrollbar, area, &child_area)) + if (GTK_WIDGET_VISIBLE (scrolled_window->vscrollbar) && + gtk_widget_intersect (scrolled_window->vscrollbar, area, &child_area)) gtk_widget_draw (scrolled_window->vscrollbar, &child_area); } } +static void +gtk_scrolled_window_forall (GtkContainer *container, + gboolean include_internals, + GtkCallback callback, + gpointer callback_data) +{ + GtkScrolledWindow *scrolled_window; + + g_return_if_fail (container != NULL); + g_return_if_fail (GTK_IS_SCROLLED_WINDOW (container)); + g_return_if_fail (callback != NULL); + + scrolled_window = GTK_SCROLLED_WINDOW (container); + + if (scrolled_window->child) + callback (scrolled_window->child, callback_data); + if (include_internals) + { + callback (scrolled_window->vscrollbar, callback_data); + callback (scrolled_window->hscrollbar, callback_data); + } +} + static void gtk_scrolled_window_size_request (GtkWidget *widget, GtkRequisition *requisition) @@ -446,13 +569,12 @@ gtk_scrolled_window_size_request (GtkWidget *widget, requisition->width = 0; requisition->height = 0; - if (scrolled_window->viewport && - GTK_WIDGET_VISIBLE (scrolled_window->viewport)) + if (scrolled_window->child && GTK_WIDGET_VISIBLE (scrolled_window->child)) { - gtk_widget_size_request (scrolled_window->viewport, &scrolled_window->viewport->requisition); + gtk_widget_size_request (scrolled_window->child, &scrolled_window->child->requisition); - requisition->width += scrolled_window->viewport->requisition.width; - requisition->height += scrolled_window->viewport->requisition.height; + requisition->width += scrolled_window->child->requisition.width; + requisition->height += scrolled_window->child->requisition.height; } extra_width = 0; @@ -483,238 +605,8 @@ gtk_scrolled_window_size_request (GtkWidget *widget, } static void -gtk_scrolled_window_size_allocate (GtkWidget *widget, - GtkAllocation *allocation) -{ - GtkScrolledWindow *scrolled_window; - GtkAllocation viewport_allocation; - GtkAllocation child_allocation; - guint previous_hvis; - guint previous_vvis; - gint count; - - g_return_if_fail (widget != NULL); - g_return_if_fail (GTK_IS_SCROLLED_WINDOW (widget)); - g_return_if_fail (allocation != NULL); - - scrolled_window = GTK_SCROLLED_WINDOW (widget); - widget->allocation = *allocation; - - if (scrolled_window->hscrollbar_policy == GTK_POLICY_ALWAYS) - scrolled_window->hscrollbar_visible = TRUE; - if (scrolled_window->vscrollbar_policy == GTK_POLICY_ALWAYS) - scrolled_window->vscrollbar_visible = TRUE; - - if (scrolled_window->viewport && - GTK_WIDGET_VISIBLE (scrolled_window->viewport)) - { - count = 0; - - do { - gtk_scrolled_window_viewport_allocate (widget, &viewport_allocation); - - child_allocation.x = viewport_allocation.x + allocation->x; - child_allocation.y = viewport_allocation.y + allocation->y; - child_allocation.width = viewport_allocation.width; - child_allocation.height = viewport_allocation.height; - - previous_hvis = scrolled_window->hscrollbar_visible; - previous_vvis = scrolled_window->vscrollbar_visible; - - gtk_widget_size_allocate (scrolled_window->viewport, &child_allocation); - /* If, after the first iteration, the hscrollbar and the - * vscrollbar flip visiblity, then we need both. - */ - if ((count++) && - (previous_hvis != scrolled_window->hscrollbar_visible) && - (previous_vvis != scrolled_window->vscrollbar_visible)) - { - scrolled_window->hscrollbar_visible = TRUE; - scrolled_window->vscrollbar_visible = TRUE; - break; - } - - count++; - } while ((previous_hvis != scrolled_window->hscrollbar_visible) || - (previous_vvis != scrolled_window->vscrollbar_visible)); - } - - if (scrolled_window->hscrollbar_visible) - { - if (!GTK_WIDGET_VISIBLE (scrolled_window->hscrollbar)) - gtk_widget_show (scrolled_window->hscrollbar); - - child_allocation.x = viewport_allocation.x; - if (scrolled_window->window_placement == GTK_CORNER_TOP_LEFT || - scrolled_window->window_placement == GTK_CORNER_TOP_RIGHT) - child_allocation.y = (viewport_allocation.y + - viewport_allocation.height + - SCROLLBAR_SPACING (scrolled_window)); - else - child_allocation.y = GTK_CONTAINER (scrolled_window)->border_width; - - child_allocation.width = viewport_allocation.width; - child_allocation.height = scrolled_window->hscrollbar->requisition.height; - child_allocation.x += allocation->x; - child_allocation.y += allocation->y; - - gtk_widget_size_allocate (scrolled_window->hscrollbar, &child_allocation); - } - else if (GTK_WIDGET_VISIBLE (scrolled_window->hscrollbar)) - gtk_widget_hide (scrolled_window->hscrollbar); - - if (scrolled_window->vscrollbar_visible) - { - if (!GTK_WIDGET_VISIBLE (scrolled_window->vscrollbar)) - gtk_widget_show (scrolled_window->vscrollbar); - - if (scrolled_window->window_placement == GTK_CORNER_TOP_LEFT || - scrolled_window->window_placement == GTK_CORNER_BOTTOM_LEFT) - child_allocation.x = (viewport_allocation.x + - viewport_allocation.width + - SCROLLBAR_SPACING (scrolled_window)); - else - child_allocation.x = GTK_CONTAINER (scrolled_window)->border_width; - - child_allocation.y = viewport_allocation.y; - child_allocation.width = scrolled_window->vscrollbar->requisition.width; - child_allocation.height = viewport_allocation.height; - child_allocation.x += allocation->x; - child_allocation.y += allocation->y; - - gtk_widget_size_allocate (scrolled_window->vscrollbar, &child_allocation); - } - else if (GTK_WIDGET_VISIBLE (scrolled_window->vscrollbar)) - gtk_widget_hide (scrolled_window->vscrollbar); -} - -static void -gtk_scrolled_window_add (GtkContainer *container, - GtkWidget *widget) -{ - GtkScrolledWindow *scrolled_window; - GtkArgInfo *info_hadj; - GtkArgInfo *info_vadj; - gchar *error; - - g_return_if_fail (container != NULL); - g_return_if_fail (GTK_IS_SCROLLED_WINDOW (container)); - g_return_if_fail (widget != NULL); - - scrolled_window = GTK_SCROLLED_WINDOW (container); - - if (scrolled_window->viewport) - gtk_container_remove (container, scrolled_window->viewport); - - error = gtk_object_arg_get_info (GTK_OBJECT_TYPE (widget), - "hadjustment", &info_hadj); - if (!error) - { - error = gtk_object_arg_get_info (GTK_OBJECT_TYPE (widget), - "vadjustment", &info_vadj); - - if (!error) - { - gtk_object_set (GTK_OBJECT (widget), - "hadjustment", - gtk_scrolled_window_get_hadjustment - (scrolled_window), - "vadjustment", - gtk_scrolled_window_get_vadjustment - (scrolled_window), - NULL); - scrolled_window->viewport = widget; - gtk_widget_set_parent (widget, GTK_WIDGET (scrolled_window)); - gtk_widget_ref (widget); - scrolled_window->autogenerated_viewport = FALSE; - } - } - - if (error) - { - g_free (error); - - scrolled_window->viewport = gtk_viewport_new - (gtk_scrolled_window_get_hadjustment (scrolled_window), - gtk_scrolled_window_get_vadjustment (scrolled_window)); - gtk_widget_set_parent (scrolled_window->viewport, - GTK_WIDGET (scrolled_window)); - gtk_widget_ref (scrolled_window->viewport); - gtk_widget_show (scrolled_window->viewport); - scrolled_window->autogenerated_viewport = FALSE; - - gtk_container_add (GTK_CONTAINER (scrolled_window->viewport), widget); - - widget = scrolled_window->viewport; - } - - if (GTK_WIDGET_VISIBLE (scrolled_window)) - { - if (GTK_WIDGET_REALIZED (scrolled_window) && - !GTK_WIDGET_REALIZED (widget)) - gtk_widget_realize (widget); - - if (GTK_WIDGET_MAPPED (scrolled_window) && - !GTK_WIDGET_MAPPED (widget)) - gtk_widget_map (widget); - } - - if (GTK_WIDGET_VISIBLE (widget) && GTK_WIDGET_VISIBLE (scrolled_window)) - gtk_widget_queue_resize (widget); -} - -static void -gtk_scrolled_window_remove (GtkContainer *container, - GtkWidget *widget) -{ - GtkScrolledWindow *scrolled_window; - - g_return_if_fail (container != NULL); - g_return_if_fail (GTK_IS_SCROLLED_WINDOW (container)); - g_return_if_fail (widget != NULL); - - scrolled_window = GTK_SCROLLED_WINDOW (container); - if (scrolled_window->viewport == widget || - scrolled_window->hscrollbar == widget || - scrolled_window->vscrollbar == widget) - { - /* this happens during destroy */ - - if (scrolled_window->viewport == widget) - scrolled_window->autogenerated_viewport = FALSE; - - gtk_widget_unparent (widget); - } - else if (scrolled_window->autogenerated_viewport) - gtk_container_remove (GTK_CONTAINER (scrolled_window->viewport), widget); -} - -static void -gtk_scrolled_window_forall (GtkContainer *container, - gboolean include_internals, - GtkCallback callback, - gpointer callback_data) -{ - GtkScrolledWindow *scrolled_window; - - g_return_if_fail (container != NULL); - g_return_if_fail (GTK_IS_SCROLLED_WINDOW (container)); - g_return_if_fail (callback != NULL); - - scrolled_window = GTK_SCROLLED_WINDOW (container); - - if (scrolled_window->viewport) - (* callback) (scrolled_window->viewport, callback_data); - if (include_internals) - { - (* callback) (scrolled_window->vscrollbar, callback_data); - (* callback) (scrolled_window->hscrollbar, callback_data); - } -} - -static void -gtk_scrolled_window_viewport_allocate (GtkWidget *widget, - GtkAllocation *allocation) +gtk_scrolled_window_relative_allocation (GtkWidget *widget, + GtkAllocation *allocation) { GtkScrolledWindow *scrolled_window; @@ -735,10 +627,9 @@ gtk_scrolled_window_viewport_allocate (GtkWidget *widget, allocation->x += (scrolled_window->vscrollbar->requisition.width + SCROLLBAR_SPACING (scrolled_window)); - allocation->width = - MAX (1, allocation->width - - (scrolled_window->vscrollbar->requisition.width + - SCROLLBAR_SPACING (scrolled_window))); + allocation->width = MAX (1, allocation->width - + (scrolled_window->vscrollbar->requisition.width + + SCROLLBAR_SPACING (scrolled_window))); } if (scrolled_window->hscrollbar_visible) { @@ -747,19 +638,131 @@ gtk_scrolled_window_viewport_allocate (GtkWidget *widget, allocation->y += (scrolled_window->hscrollbar->requisition.height + SCROLLBAR_SPACING (scrolled_window)); - allocation->height = - MAX (1, allocation->height - - (scrolled_window->hscrollbar->requisition.height + - SCROLLBAR_SPACING (scrolled_window))); + allocation->height = MAX (1, allocation->height - + (scrolled_window->hscrollbar->requisition.height + + SCROLLBAR_SPACING (scrolled_window))); } } +static void +gtk_scrolled_window_size_allocate (GtkWidget *widget, + GtkAllocation *allocation) +{ + GtkScrolledWindow *scrolled_window; + GtkAllocation relative_allocation; + GtkAllocation child_allocation; + + g_return_if_fail (widget != NULL); + g_return_if_fail (GTK_IS_SCROLLED_WINDOW (widget)); + g_return_if_fail (allocation != NULL); + + scrolled_window = GTK_SCROLLED_WINDOW (widget); + widget->allocation = *allocation; + + if (scrolled_window->hscrollbar_policy == GTK_POLICY_ALWAYS) + scrolled_window->hscrollbar_visible = TRUE; + if (scrolled_window->vscrollbar_policy == GTK_POLICY_ALWAYS) + scrolled_window->vscrollbar_visible = TRUE; + + if (scrolled_window->child && GTK_WIDGET_VISIBLE (scrolled_window->child)) + { + gboolean previous_hvis; + gboolean previous_vvis; + guint count = 0; + + do + { + gtk_scrolled_window_relative_allocation (widget, &relative_allocation); + + child_allocation.x = relative_allocation.x + allocation->x; + child_allocation.y = relative_allocation.y + allocation->y; + child_allocation.width = relative_allocation.width; + child_allocation.height = relative_allocation.height; + + previous_hvis = scrolled_window->hscrollbar_visible; + previous_vvis = scrolled_window->vscrollbar_visible; + + gtk_widget_size_allocate (scrolled_window->child, &child_allocation); + + /* If, after the first iteration, the hscrollbar and the + * vscrollbar flip visiblity, then we need both. + */ + if (count && + previous_hvis != scrolled_window->hscrollbar_visible && + previous_vvis != scrolled_window->vscrollbar_visible) + { + scrolled_window->hscrollbar_visible = TRUE; + scrolled_window->vscrollbar_visible = TRUE; + + /* a new resize is already queued at this point, + * so we will immediatedly get reinvoked + */ + return; + } + + count++; + } + while (previous_hvis != scrolled_window->hscrollbar_visible || + previous_vvis != scrolled_window->vscrollbar_visible); + } + else + gtk_scrolled_window_relative_allocation (widget, &relative_allocation); + + if (scrolled_window->hscrollbar_visible) + { + if (!GTK_WIDGET_VISIBLE (scrolled_window->hscrollbar)) + gtk_widget_show (scrolled_window->hscrollbar); + + child_allocation.x = relative_allocation.x; + if (scrolled_window->window_placement == GTK_CORNER_TOP_LEFT || + scrolled_window->window_placement == GTK_CORNER_TOP_RIGHT) + child_allocation.y = (relative_allocation.y + + relative_allocation.height + + SCROLLBAR_SPACING (scrolled_window)); + else + child_allocation.y = GTK_CONTAINER (scrolled_window)->border_width; + + child_allocation.width = relative_allocation.width; + child_allocation.height = scrolled_window->hscrollbar->requisition.height; + child_allocation.x += allocation->x; + child_allocation.y += allocation->y; + + gtk_widget_size_allocate (scrolled_window->hscrollbar, &child_allocation); + } + else if (GTK_WIDGET_VISIBLE (scrolled_window->hscrollbar)) + gtk_widget_hide (scrolled_window->hscrollbar); + + if (scrolled_window->vscrollbar_visible) + { + if (!GTK_WIDGET_VISIBLE (scrolled_window->vscrollbar)) + gtk_widget_show (scrolled_window->vscrollbar); + + if (scrolled_window->window_placement == GTK_CORNER_TOP_LEFT || + scrolled_window->window_placement == GTK_CORNER_BOTTOM_LEFT) + child_allocation.x = (relative_allocation.x + + relative_allocation.width + + SCROLLBAR_SPACING (scrolled_window)); + else + child_allocation.x = GTK_CONTAINER (scrolled_window)->border_width; + + child_allocation.y = relative_allocation.y; + child_allocation.width = scrolled_window->vscrollbar->requisition.width; + child_allocation.height = relative_allocation.height; + child_allocation.x += allocation->x; + child_allocation.y += allocation->y; + + gtk_widget_size_allocate (scrolled_window->vscrollbar, &child_allocation); + } + else if (GTK_WIDGET_VISIBLE (scrolled_window->vscrollbar)) + gtk_widget_hide (scrolled_window->vscrollbar); +} + + static void gtk_scrolled_window_adjustment_changed (GtkAdjustment *adjustment, gpointer data) { GtkScrolledWindow *scrolled_win; - gboolean visible; g_return_if_fail (adjustment != NULL); g_return_if_fail (data != NULL); @@ -770,9 +773,11 @@ gtk_scrolled_window_adjustment_changed (GtkAdjustment *adjustment, { if (scrolled_win->hscrollbar_policy == GTK_POLICY_AUTOMATIC) { + gboolean visible; + visible = scrolled_win->hscrollbar_visible; - scrolled_win->hscrollbar_visible = - ((adjustment->upper - adjustment->lower) > adjustment->page_size); + scrolled_win->hscrollbar_visible = (adjustment->upper - adjustment->lower > + adjustment->page_size); if (scrolled_win->hscrollbar_visible != visible) gtk_widget_queue_resize (GTK_WIDGET (scrolled_win)); } @@ -781,16 +786,92 @@ gtk_scrolled_window_adjustment_changed (GtkAdjustment *adjustment, { if (scrolled_win->vscrollbar_policy == GTK_POLICY_AUTOMATIC) { + gboolean visible; + visible = scrolled_win->vscrollbar_visible; - scrolled_win->vscrollbar_visible = - ((adjustment->upper - adjustment->lower) > adjustment->page_size); + scrolled_win->vscrollbar_visible = (adjustment->upper - adjustment->lower > + adjustment->page_size); if (scrolled_win->vscrollbar_visible != visible) gtk_widget_queue_resize (GTK_WIDGET (scrolled_win)); } } - else - { - g_warning ("could not determine which adjustment scrollbar received change signal for"); - return; - } +} + +static void +gtk_scrolled_window_add (GtkContainer *container, + GtkWidget *child) +{ + GtkScrolledWindow *scrolled_window; + + scrolled_window = GTK_SCROLLED_WINDOW (container); + g_return_if_fail (scrolled_window->child == NULL); + + gtk_widget_set_parent (child, GTK_WIDGET (container)); + scrolled_window->child = child; + + /* this is a temporary message */ + if (!gtk_widget_scroll_adjustements (child, + gtk_range_get_adjustment (GTK_RANGE (scrolled_window->hscrollbar)), + gtk_range_get_adjustment (GTK_RANGE (scrolled_window->vscrollbar)))) + g_message ("gtk_scrolled_window_add(): cannot add non scrollable widget " + "use gtk_scrolled_window_add_with_viewport() instead"); + + if (GTK_WIDGET_VISIBLE (scrolled_window)) + { + if (GTK_WIDGET_REALIZED (scrolled_window) && + !GTK_WIDGET_REALIZED (child)) + gtk_widget_realize (child); + + if (GTK_WIDGET_MAPPED (scrolled_window) && + !GTK_WIDGET_MAPPED (child)) + gtk_widget_map (child); + } + + if (GTK_WIDGET_VISIBLE (child) && GTK_WIDGET_VISIBLE (scrolled_window)) + gtk_widget_queue_resize (child); +} + +static void +gtk_scrolled_window_remove (GtkContainer *container, + GtkWidget *child) +{ + GtkScrolledWindow *scrolled_window; + gboolean widget_was_visible; + + g_return_if_fail (container != NULL); + g_return_if_fail (GTK_IS_SCROLLED_WINDOW (container)); + g_return_if_fail (child != NULL); + + scrolled_window = GTK_SCROLLED_WINDOW (container); + g_return_if_fail (scrolled_window->child == child); + + widget_was_visible = GTK_WIDGET_VISIBLE (child); + + gtk_widget_scroll_adjustements (child, NULL, NULL); + gtk_widget_unparent (child); + scrolled_window->child = NULL; + + if (widget_was_visible) + gtk_widget_queue_resize (GTK_WIDGET (container)); +} + +void +gtk_scrolled_window_add_with_viewport (GtkScrolledWindow *scrolled_window, + GtkWidget *child) +{ + GtkWidget *viewport; + + g_return_if_fail (scrolled_window != NULL); + g_return_if_fail (GTK_IS_SCROLLED_WINDOW (scrolled_window)); + g_return_if_fail (child != NULL); + g_return_if_fail (GTK_IS_WIDGET (child)); + g_return_if_fail (scrolled_window->child == NULL); + g_return_if_fail (child->parent == NULL); + + viewport = + gtk_viewport_new (gtk_scrolled_window_get_hadjustment (scrolled_window), + gtk_scrolled_window_get_vadjustment (scrolled_window)); + gtk_widget_show (viewport); + gtk_container_add (GTK_CONTAINER (viewport), child); + gtk_container_add (GTK_CONTAINER (scrolled_window), viewport); } diff --git a/gtk/gtkscrolledwindow.h b/gtk/gtkscrolledwindow.h index 20260f04a3..1b74d69d5f 100644 --- a/gtk/gtkscrolledwindow.h +++ b/gtk/gtkscrolledwindow.h @@ -45,7 +45,7 @@ struct _GtkScrolledWindow { GtkContainer container; - GtkWidget *viewport; + GtkWidget *child; GtkWidget *hscrollbar; GtkWidget *vscrollbar; @@ -54,30 +54,37 @@ struct _GtkScrolledWindow guint hscrollbar_visible : 1; guint vscrollbar_visible : 1; guint window_placement : 2; - guint autogenerated_viewport : 1; }; struct _GtkScrolledWindowClass { GtkContainerClass parent_class; - + gint scrollbar_spacing; }; -GtkType gtk_scrolled_window_get_type (void); -GtkWidget* gtk_scrolled_window_new (GtkAdjustment *hadjustment, - GtkAdjustment *vadjustment); -void gtk_scrolled_window_construct (GtkScrolledWindow *scrolled_window, - GtkAdjustment *hadjustment, - GtkAdjustment *vadjustment); -GtkAdjustment* gtk_scrolled_window_get_hadjustment (GtkScrolledWindow *scrolled_window); -GtkAdjustment* gtk_scrolled_window_get_vadjustment (GtkScrolledWindow *scrolled_window); -void gtk_scrolled_window_set_policy (GtkScrolledWindow *scrolled_window, - GtkPolicyType hscrollbar_policy, - GtkPolicyType vscrollbar_policy); -void gtk_scrolled_window_set_placement (GtkScrolledWindow *scrolled_window, - GtkCornerType window_placement); +GtkType gtk_scrolled_window_get_type (void); +GtkWidget* gtk_scrolled_window_new (GtkAdjustment *hadjustment, + GtkAdjustment *vadjustment); +void gtk_scrolled_window_set_hadjustment (GtkScrolledWindow *scrolled_window, + GtkAdjustment *hadjustment); +void gtk_scrolled_window_set_vadjustment (GtkScrolledWindow *scrolled_window, + GtkAdjustment *hadjustment); +GtkAdjustment* gtk_scrolled_window_get_hadjustment (GtkScrolledWindow *scrolled_window); +GtkAdjustment* gtk_scrolled_window_get_vadjustment (GtkScrolledWindow *scrolled_window); +void gtk_scrolled_window_set_policy (GtkScrolledWindow *scrolled_window, + GtkPolicyType hscrollbar_policy, + GtkPolicyType vscrollbar_policy); +void gtk_scrolled_window_set_placement (GtkScrolledWindow *scrolled_window, + GtkCornerType window_placement); +void gtk_scrolled_window_add_with_viewport (GtkScrolledWindow *scrolled_window, + GtkWidget *child); + +/* deprecated */ +void gtk_scrolled_window_construct (GtkScrolledWindow *scrolled_window, + GtkAdjustment *hadjustment, + GtkAdjustment *vadjustment); #ifdef __cplusplus } diff --git a/gtk/gtkseparator.c b/gtk/gtkseparator.c index e0a4a0e668..e3bd8fc793 100644 --- a/gtk/gtkseparator.c +++ b/gtk/gtkseparator.c @@ -56,5 +56,5 @@ gtk_separator_class_init (GtkSeparatorClass *class) static void gtk_separator_init (GtkSeparator *separator) { - GTK_WIDGET_SET_FLAGS (separator, GTK_NO_WINDOW | GTK_BASIC); + GTK_WIDGET_SET_FLAGS (separator, GTK_NO_WINDOW); } diff --git a/gtk/gtkspinbutton.c b/gtk/gtkspinbutton.c index 3cb6889f31..08e21678f7 100644 --- a/gtk/gtkspinbutton.c +++ b/gtk/gtkspinbutton.c @@ -1272,6 +1272,17 @@ gtk_spin_button_real_spin (GtkSpinButton *spin_button, ***********************************************************/ +void +gtk_spin_button_construct (GtkSpinButton *spin_button, + GtkAdjustment *adjustment, + gfloat climb_rate, + guint digits) +{ + g_message ("gtk_spin_button_construct() is deprecated"); + + gtk_spin_button_configure (spin_button, adjustment, climb_rate, digits); +} + void gtk_spin_button_configure (GtkSpinButton *spin_button, GtkAdjustment *adjustment, diff --git a/gtk/gtkspinbutton.h b/gtk/gtkspinbutton.h index 2e2e591378..c875574124 100644 --- a/gtk/gtkspinbutton.h +++ b/gtk/gtkspinbutton.h @@ -142,8 +142,15 @@ void gtk_spin_button_set_shadow_type (GtkSpinButton *spin_button, void gtk_spin_button_set_snap_to_ticks (GtkSpinButton *spin_button, gboolean snap_to_ticks); -/* deprecated, defined for backwards compatibility */ -#define gtk_spin_button_construct gtk_spin_button_configure +void gtk_spin_button_configure (GtkSpinButton *spin_button, + GtkAdjustment *adjustment, + gfloat climb_rate, + guint digits); +/* deprecated */ +void gtk_spin_button_construct (GtkSpinButton *spin_button, + GtkAdjustment *adjustment, + gfloat climb_rate, + guint digits); #ifdef __cplusplus diff --git a/gtk/gtktable.c b/gtk/gtktable.c index ad09b98bc2..313dad2243 100644 --- a/gtk/gtktable.c +++ b/gtk/gtktable.c @@ -375,7 +375,7 @@ gtk_table_get_child_arg (GtkContainer *container, static void gtk_table_init (GtkTable *table) { - GTK_WIDGET_SET_FLAGS (table, GTK_NO_WINDOW | GTK_BASIC); + GTK_WIDGET_SET_FLAGS (table, GTK_NO_WINDOW); table->children = NULL; table->rows = NULL; diff --git a/gtk/gtktext.c b/gtk/gtktext.c index b30ea25a9c..78b987e49d 100644 --- a/gtk/gtktext.c +++ b/gtk/gtktext.c @@ -87,6 +87,14 @@ #define LAST_INDEX(t, m) ((m).index == TEXT_LENGTH(t)) #define CACHE_DATA(c) (*(LineParams*)(c)->data) +enum { + ARG_0, + ARG_HADJUSTMENT, + ARG_VADJUSTMENT, + ARG_LINE_WRAP, + ARG_WORD_WRAP +}; + typedef struct _TextProperty TextProperty; typedef struct _TabStopMark TabStopMark; typedef struct _PrevTabCont PrevTabCont; @@ -180,6 +188,12 @@ struct _LineParams static void gtk_text_class_init (GtkTextClass *klass); +static void gtk_text_set_arg (GtkObject *object, + GtkArg *arg, + guint arg_id); +static void gtk_text_get_arg (GtkObject *object, + GtkArg *arg, + guint arg_id); static void gtk_text_init (GtkText *text); static void gtk_text_destroy (GtkObject *object); static void gtk_text_finalize (GtkObject *object); @@ -518,9 +532,27 @@ gtk_text_class_init (GtkTextClass *class) object_class = (GtkObjectClass*) class; widget_class = (GtkWidgetClass*) class; editable_class = (GtkEditableClass*) class; - parent_class = gtk_type_class (GTK_TYPE_EDITABLE); - + + gtk_object_add_arg_type ("GtkText::hadjustment", + GTK_TYPE_ADJUSTMENT, + GTK_ARG_READWRITE | GTK_ARG_CONSTRUCT, + ARG_HADJUSTMENT); + gtk_object_add_arg_type ("GtkText::vadjustment", + GTK_TYPE_ADJUSTMENT, + GTK_ARG_READWRITE | GTK_ARG_CONSTRUCT, + ARG_VADJUSTMENT); + gtk_object_add_arg_type ("GtkText::line_wrap", + GTK_TYPE_BOOL, + GTK_ARG_READWRITE, + ARG_LINE_WRAP); + gtk_object_add_arg_type ("GtkText::word_wrap", + GTK_TYPE_BOOL, + GTK_ARG_READWRITE, + ARG_WORD_WRAP); + + object_class->set_arg = gtk_text_set_arg; + object_class->get_arg = gtk_text_get_arg; object_class->destroy = gtk_text_destroy; object_class->finalize = gtk_text_finalize; @@ -539,6 +571,14 @@ gtk_text_class_init (GtkTextClass *class) widget_class->focus_in_event = gtk_text_focus_in; widget_class->focus_out_event = gtk_text_focus_out; + widget_class->scroll_adjustments_signal = + gtk_signal_new ("scroll_adjustments", + GTK_RUN_LAST, + object_class->type, + GTK_SIGNAL_OFFSET (GtkTextClass, scroll_adjustments), + gtk_marshal_NONE__POINTER_POINTER, + GTK_TYPE_NONE, 2, GTK_TYPE_ADJUSTMENT, GTK_TYPE_ADJUSTMENT); + editable_class->set_editable = gtk_text_real_set_editable; editable_class->insert_text = gtk_text_insert_text; editable_class->delete_text = gtk_text_delete_text; @@ -557,12 +597,82 @@ gtk_text_class_init (GtkTextClass *class) editable_class->get_chars = gtk_text_get_chars; editable_class->set_selection = gtk_text_set_selection; editable_class->set_position = gtk_text_set_position; + + class->scroll_adjustments = gtk_text_set_adjustments; +} + +static void +gtk_text_set_arg (GtkObject *object, + GtkArg *arg, + guint arg_id) +{ + GtkText *text; + + text = GTK_TEXT (object); + + switch (arg_id) + { + case ARG_HADJUSTMENT: + gtk_text_set_adjustments (text, + GTK_VALUE_POINTER (*arg), + text->vadj); + break; + case ARG_VADJUSTMENT: + gtk_text_set_adjustments (text, + text->hadj, + GTK_VALUE_POINTER (*arg)); + break; + case ARG_LINE_WRAP: + gtk_text_set_line_wrap (text, GTK_VALUE_BOOL (*arg)); + break; + case ARG_WORD_WRAP: + gtk_text_set_word_wrap (text, GTK_VALUE_BOOL (*arg)); + break; + default: + break; + } +} + +static void +gtk_text_get_arg (GtkObject *object, + GtkArg *arg, + guint arg_id) +{ + GtkText *text; + + text = GTK_TEXT (object); + + switch (arg_id) + { + case ARG_HADJUSTMENT: + GTK_VALUE_POINTER (*arg) = text->hadj; + break; + case ARG_VADJUSTMENT: + GTK_VALUE_POINTER (*arg) = text->vadj; + break; + case ARG_LINE_WRAP: + GTK_VALUE_BOOL (*arg) = text->line_wrap; + break; + case ARG_WORD_WRAP: + GTK_VALUE_BOOL (*arg) = text->word_wrap; + break; + default: + arg->type = GTK_TYPE_INVALID; + break; + } } static void gtk_text_init (GtkText *text) { GTK_WIDGET_SET_FLAGS (text, GTK_CAN_FOCUS); + + text->text_area = NULL; + text->hadj = NULL; + text->vadj = NULL; + text->gc = NULL; + text->line_wrap_bitmap = NULL; + text->line_arrow_bitmap = NULL; text->text = g_new (guchar, INITIAL_BUFFER_SIZE); text->text_len = INITIAL_BUFFER_SIZE; @@ -589,24 +699,31 @@ gtk_text_init (GtkText *text) text->button = 0; text->current_font = NULL; - + init_properties (text); - - GTK_EDITABLE(text)->editable = FALSE; + + GTK_EDITABLE (text)->editable = FALSE; + + gtk_editable_set_position (GTK_EDITABLE (text), 0); } GtkWidget* gtk_text_new (GtkAdjustment *hadj, GtkAdjustment *vadj) { - GtkText *text; - - text = gtk_type_new (GTK_TYPE_TEXT); - - gtk_text_set_adjustments (text, hadj, vadj); - gtk_editable_set_position (GTK_EDITABLE (text), 0); - - return GTK_WIDGET (text); + GtkWidget *text; + + if (hadj) + g_return_val_if_fail (GTK_IS_ADJUSTMENT (hadj), NULL); + if (vadj) + g_return_val_if_fail (GTK_IS_ADJUSTMENT (vadj), NULL); + + text = gtk_widget_new (GTK_TYPE_TEXT, + "hadjustment", hadj, + "vadjustment", vadj, + NULL); + + return text; } void @@ -711,6 +828,7 @@ gtk_text_set_adjustments (GtkText *text, gtk_signal_connect (GTK_OBJECT (text->hadj), "disconnect", (GtkSignalFunc) gtk_text_disconnect, text); + gtk_text_adjustment (hadj, text); } if (text->vadj != vadj) @@ -728,6 +846,7 @@ gtk_text_set_adjustments (GtkText *text, gtk_signal_connect (GTK_OBJECT (text->vadj), "disconnect", (GtkSignalFunc) gtk_text_disconnect, text); + gtk_text_adjustment (vadj, text); } } @@ -1018,17 +1137,11 @@ gtk_text_destroy (GtkObject *object) g_return_if_fail (object != NULL); g_return_if_fail (GTK_IS_TEXT (object)); - text = (GtkText *)object; - if (text->hadj) - { - gtk_object_unref (GTK_OBJECT (text->hadj)); - text->hadj = NULL; - } - if (text->vadj) - { - gtk_object_unref (GTK_OBJECT (text->vadj)); - text->vadj = NULL; - } + text = (GtkText*) object; + + gtk_signal_disconnect_by_data (GTK_OBJECT (text->hadj), text); + gtk_signal_disconnect_by_data (GTK_OBJECT (text->hadj), text); + if (text->timer) { gtk_timeout_remove (text->timer); @@ -1049,6 +1162,9 @@ gtk_text_finalize (GtkObject *object) text = (GtkText *)object; + gtk_object_unref (GTK_OBJECT (text->hadj)); + gtk_object_unref (GTK_OBJECT (text->vadj)); + /* Clean up the internal structures */ g_free (text->text); free_cache (text); @@ -2110,11 +2226,11 @@ gtk_text_disconnect (GtkAdjustment *adjustment, g_return_if_fail (GTK_IS_ADJUSTMENT (adjustment)); g_return_if_fail (text != NULL); g_return_if_fail (GTK_IS_TEXT (text)); - + if (adjustment == text->hadj) - text->hadj = NULL; + gtk_text_set_adjustments (text, NULL, text->vadj); if (adjustment == text->vadj) - text->vadj = NULL; + gtk_text_set_adjustments (text, text->hadj, NULL); } diff --git a/gtk/gtktext.h b/gtk/gtktext.h index 7018667c1e..8284682dd4 100644 --- a/gtk/gtktext.h +++ b/gtk/gtktext.h @@ -156,6 +156,10 @@ struct _GtkText struct _GtkTextClass { GtkEditableClass parent_class; + + void (*scroll_adjustments) (GtkText *text, + GtkAdjustment *hadjustment, + GtkAdjustment *vadjustment); }; diff --git a/gtk/gtktypeutils.c b/gtk/gtktypeutils.c index 27c20eb5e1..41a5ec1f0d 100644 --- a/gtk/gtktypeutils.c +++ b/gtk/gtktypeutils.c @@ -359,30 +359,33 @@ gtk_type_new (GtkType type) /* we need to call the base classes' object_init_func for derived * objects with the object's ->klass field still pointing to the * corresponding base class, otherwise overridden class functions - * could get called with partly-initialized objects. + * could get called with partly-initialized objects. the real object + * class is passed as second argment to the initializers. */ if (node->n_supers) { guint i; GtkType *supers; + GtkTypeNode *pnode; supers = node->supers; for (i = node->n_supers; i > 0; i--) { - GtkTypeNode *pnode; - LOOKUP_TYPE_NODE (pnode, supers[i]); if (pnode->type_info.object_init_func) { tobject->klass = pnode->klass; - pnode->type_info.object_init_func (tobject); + pnode->type_info.object_init_func (tobject, klass); } } LOOKUP_TYPE_NODE (node, type); } tobject->klass = klass; if (node->type_info.object_init_func) - node->type_info.object_init_func (tobject); + { + node->type_info.object_init_func (tobject, klass); + tobject->klass = klass; + } return tobject; } @@ -768,7 +771,7 @@ gtk_type_set_varargs_type (GtkType foreign_type, } GtkType -gtk_type_get_varargs_type (GtkType foreign_type) +gtk_type_get_varargs_type (GtkType foreign_type) { GtkType type; guint i; diff --git a/gtk/gtktypeutils.h b/gtk/gtktypeutils.h index 51dc06624c..ae2fe399b8 100644 --- a/gtk/gtktypeutils.h +++ b/gtk/gtktypeutils.h @@ -71,6 +71,7 @@ typedef enum #define GTK_TYPE_STRUCTURED_FIRST GTK_TYPE_SIGNAL #define GTK_TYPE_STRUCTURED_LAST GTK_TYPE_FOREIGN #define GTK_TYPE_FUNDAMENTAL_LAST GTK_TYPE_OBJECT +#define GTK_TYPE_FUNDAMENTAL_MAX (32) /* retrive a structure offset */ @@ -138,7 +139,8 @@ typedef struct _GtkEnumValue GtkFlagValue; #define GTK_SIGNAL_FUNC(f) ((GtkSignalFunc) f) typedef void (*GtkClassInitFunc) (gpointer klass); -typedef void (*GtkObjectInitFunc) (gpointer object); +typedef void (*GtkObjectInitFunc) (gpointer object, + gpointer klass); typedef void (*GtkSignalFunc) (); typedef gint (*GtkFunction) (gpointer data); typedef void (*GtkDestroyNotify) (gpointer data); diff --git a/gtk/gtkvbox.h b/gtk/gtkvbox.h index 1b3a4ddc32..ddebeadf92 100644 --- a/gtk/gtkvbox.h +++ b/gtk/gtkvbox.h @@ -29,11 +29,11 @@ extern "C" { #endif /* __cplusplus */ -#define GTK_TYPE_VBOX (gtk_vbox_get_type ()) -#define GTK_VBOX(obj) (GTK_CHECK_CAST ((obj), GTK_TYPE_VBOX, GtkVBox)) -#define GTK_VBOX_CLASS(klass) (GTK_CHECK_CLASS_CAST ((klass), GTK_TYPE_VBOX, GtkVBoxClass)) -#define GTK_IS_VBOX(obj) (GTK_CHECK_TYPE ((obj), GTK_TYPE_VBOX)) -#define GTK_IS_VBOX_CLASS(klass) (GTK_CHECK_CLASS_TYPE ((klass), GTK_TYPE_VBOX)) +#define GTK_TYPE_VBOX (gtk_vbox_get_type ()) +#define GTK_VBOX(obj) (GTK_CHECK_CAST ((obj), GTK_TYPE_VBOX, GtkVBox)) +#define GTK_VBOX_CLASS(klass) (GTK_CHECK_CLASS_CAST ((klass), GTK_TYPE_VBOX, GtkVBoxClass)) +#define GTK_IS_VBOX(obj) (GTK_CHECK_TYPE ((obj), GTK_TYPE_VBOX)) +#define GTK_IS_VBOX_CLASS(klass) (GTK_CHECK_CLASS_TYPE ((klass), GTK_TYPE_VBOX)) typedef struct _GtkVBox GtkVBox; diff --git a/gtk/gtkviewport.c b/gtk/gtkviewport.c index 0ef84889bc..b88858e868 100644 --- a/gtk/gtkviewport.c +++ b/gtk/gtkviewport.c @@ -27,9 +27,9 @@ enum { }; - static void gtk_viewport_class_init (GtkViewportClass *klass); static void gtk_viewport_init (GtkViewport *viewport); +static void gtk_viewport_destroy (GtkObject *object); static void gtk_viewport_finalize (GtkObject *object); static void gtk_viewport_set_arg (GtkObject *object, GtkArg *arg, @@ -37,6 +37,9 @@ static void gtk_viewport_set_arg (GtkObject *object, static void gtk_viewport_get_arg (GtkObject *object, GtkArg *arg, guint arg_id); +static void gtk_viewport_scroll_adjustments (GtkViewport *viewport, + GtkAdjustment *hadjustment, + GtkAdjustment *vadjustment); static void gtk_viewport_map (GtkWidget *widget); static void gtk_viewport_unmap (GtkWidget *widget); static void gtk_viewport_realize (GtkWidget *widget); @@ -114,6 +117,7 @@ gtk_viewport_class_init (GtkViewportClass *class) object_class->set_arg = gtk_viewport_set_arg; object_class->get_arg = gtk_viewport_get_arg; + object_class->destroy = gtk_viewport_destroy; object_class->finalize = gtk_viewport_finalize; widget_class->map = gtk_viewport_map; @@ -125,8 +129,18 @@ gtk_viewport_class_init (GtkViewportClass *class) widget_class->size_request = gtk_viewport_size_request; widget_class->size_allocate = gtk_viewport_size_allocate; widget_class->style_set = gtk_viewport_style_set; - + + widget_class->scroll_adjustments_signal = + gtk_signal_new ("scroll_adjustments", + GTK_RUN_LAST, + object_class->type, + GTK_SIGNAL_OFFSET (GtkViewportClass, scroll_adjustments), + gtk_marshal_NONE__POINTER_POINTER, + GTK_TYPE_NONE, 2, GTK_TYPE_ADJUSTMENT, GTK_TYPE_ADJUSTMENT); + container_class->add = gtk_viewport_add; + + class->scroll_adjustments = gtk_viewport_scroll_adjustments; } static void @@ -140,15 +154,11 @@ gtk_viewport_set_arg (GtkObject *object, switch (arg_id) { - GtkAdjustment *adjustment; - case ARG_HADJUSTMENT: - adjustment = GTK_VALUE_POINTER (*arg); - gtk_viewport_set_hadjustment (viewport, adjustment); + gtk_viewport_set_hadjustment (viewport, GTK_VALUE_POINTER (*arg)); break; case ARG_VADJUSTMENT: - adjustment = GTK_VALUE_POINTER (*arg); - gtk_viewport_set_vadjustment (viewport, adjustment); + gtk_viewport_set_vadjustment (viewport, GTK_VALUE_POINTER (*arg)); break; case ARG_SHADOW_TYPE: gtk_viewport_set_shadow_type (viewport, GTK_VALUE_ENUM (*arg)); @@ -188,7 +198,6 @@ static void gtk_viewport_init (GtkViewport *viewport) { GTK_WIDGET_UNSET_FLAGS (viewport, GTK_NO_WINDOW); - GTK_WIDGET_SET_FLAGS (viewport, GTK_BASIC); gtk_container_set_resize_mode (GTK_CONTAINER (viewport), GTK_RESIZE_QUEUE); @@ -203,14 +212,29 @@ GtkWidget* gtk_viewport_new (GtkAdjustment *hadjustment, GtkAdjustment *vadjustment) { - GtkViewport *viewport; + GtkWidget *viewport; - viewport = gtk_type_new (gtk_viewport_get_type ()); + viewport = gtk_widget_new (GTK_TYPE_VIEWPORT, + "hadjustment", hadjustment, + "vadjustment", vadjustment, + NULL); - gtk_viewport_set_hadjustment (viewport, hadjustment); - gtk_viewport_set_vadjustment (viewport, vadjustment); + return viewport; +} - return GTK_WIDGET (viewport); +static void +gtk_viewport_destroy (GtkObject *object) +{ + GtkViewport *viewport = GTK_VIEWPORT (object); + + if (viewport->hadjustment) + gtk_signal_disconnect_by_data (GTK_OBJECT (viewport->hadjustment), + viewport); + if (viewport->vadjustment) + gtk_signal_disconnect_by_data (GTK_OBJECT (viewport->vadjustment), + viewport); + + GTK_OBJECT_CLASS(parent_class)->destroy (object); } static void @@ -316,6 +340,17 @@ gtk_viewport_set_vadjustment (GtkViewport *viewport, } } +static void +gtk_viewport_scroll_adjustments (GtkViewport *viewport, + GtkAdjustment *hadjustment, + GtkAdjustment *vadjustment) +{ + if (viewport->hadjustment != hadjustment) + gtk_viewport_set_hadjustment (viewport, hadjustment); + if (viewport->vadjustment != vadjustment) + gtk_viewport_set_vadjustment (viewport, vadjustment); +} + void gtk_viewport_set_shadow_type (GtkViewport *viewport, GtkShadowType type) diff --git a/gtk/gtkviewport.h b/gtk/gtkviewport.h index a108f4731b..3bd87fae3a 100644 --- a/gtk/gtkviewport.h +++ b/gtk/gtkviewport.h @@ -54,6 +54,10 @@ struct _GtkViewport struct _GtkViewportClass { GtkBinClass parent_class; + + void (*scroll_adjustments) (GtkViewport *viewport, + GtkAdjustment *hadjustment, + GtkAdjustment *vadjustment); }; diff --git a/gtk/gtkvscale.c b/gtk/gtkvscale.c index 2bdc33c11f..42fc9fbe8e 100644 --- a/gtk/gtkvscale.c +++ b/gtk/gtkvscale.c @@ -25,85 +25,144 @@ #define SCALE_CLASS(w) GTK_SCALE_CLASS (GTK_OBJECT (w)->klass) #define RANGE_CLASS(w) GTK_RANGE_CLASS (GTK_OBJECT (w)->klass) +enum { + ARG_0, + ARG_ADJUSTMENT, +}; static void gtk_vscale_class_init (GtkVScaleClass *klass); static void gtk_vscale_init (GtkVScale *vscale); +static void gtk_vscale_set_arg (GtkObject *object, + GtkArg *arg, + guint arg_id); +static void gtk_vscale_get_arg (GtkObject *object, + GtkArg *arg, + guint arg_id); static void gtk_vscale_realize (GtkWidget *widget); static void gtk_vscale_size_request (GtkWidget *widget, - GtkRequisition *requisition); + GtkRequisition *requisition); static void gtk_vscale_size_allocate (GtkWidget *widget, - GtkAllocation *allocation); + GtkAllocation *allocation); static void gtk_vscale_pos_trough (GtkVScale *vscale, - gint *x, - gint *y, - gint *w, - gint *h); + gint *x, + gint *y, + gint *w, + gint *h); static void gtk_vscale_pos_background (GtkVScale *vscale, - gint *x, - gint *y, - gint *w, - gint *h); + gint *x, + gint *y, + gint *w, + gint *h); static void gtk_vscale_draw_slider (GtkRange *range); static void gtk_vscale_draw_value (GtkScale *scale); static void gtk_vscale_draw (GtkWidget *widget, - GdkRectangle *area); + GdkRectangle *area); static gint gtk_vscale_trough_keys (GtkRange *range, - GdkEventKey *key, - GtkScrollType *scroll, - GtkTroughType *pos); + GdkEventKey *key, + GtkScrollType *scroll, + GtkTroughType *pos); static void gtk_vscale_clear_background (GtkRange *range); -guint +GtkType gtk_vscale_get_type (void) { - static guint vscale_type = 0; - + static GtkType vscale_type = 0; + if (!vscale_type) { GtkTypeInfo vscale_info = { - "GtkVScale", - sizeof (GtkVScale), - sizeof (GtkVScaleClass), - (GtkClassInitFunc) gtk_vscale_class_init, - (GtkObjectInitFunc) gtk_vscale_init, - /* reserved_1 */ NULL, + "GtkVScale", + sizeof (GtkVScale), + sizeof (GtkVScaleClass), + (GtkClassInitFunc) gtk_vscale_class_init, + (GtkObjectInitFunc) gtk_vscale_init, + /* reserved_1 */ NULL, /* reserved_2 */ NULL, (GtkClassInitFunc) NULL, }; - - vscale_type = gtk_type_unique (gtk_scale_get_type (), &vscale_info); + + vscale_type = gtk_type_unique (GTK_TYPE_SCALE, &vscale_info); } - + return vscale_type; } static void gtk_vscale_class_init (GtkVScaleClass *class) { + GtkObjectClass *object_class; GtkWidgetClass *widget_class; GtkRangeClass *range_class; GtkScaleClass *scale_class; - + + object_class = (GtkObjectClass*) class; widget_class = (GtkWidgetClass*) class; range_class = (GtkRangeClass*) class; scale_class = (GtkScaleClass*) class; - + + gtk_object_add_arg_type ("GtkVScale::adjustment", + GTK_TYPE_ADJUSTMENT, + GTK_ARG_READWRITE | GTK_ARG_CONSTRUCT, + ARG_ADJUSTMENT); + + object_class->set_arg = gtk_vscale_set_arg; + object_class->get_arg = gtk_vscale_get_arg; + widget_class->realize = gtk_vscale_realize; widget_class->size_request = gtk_vscale_size_request; widget_class->size_allocate = gtk_vscale_size_allocate; widget_class->draw = gtk_vscale_draw; - + range_class->slider_update = gtk_range_default_vslider_update; range_class->trough_click = gtk_range_default_vtrough_click; range_class->motion = gtk_range_default_vmotion; range_class->draw_slider = gtk_vscale_draw_slider; range_class->trough_keys = gtk_vscale_trough_keys; range_class->clear_background = gtk_vscale_clear_background; - + scale_class->draw_value = gtk_vscale_draw_value; } +static void +gtk_vscale_set_arg (GtkObject *object, + GtkArg *arg, + guint arg_id) +{ + GtkVScale *vscale; + + vscale = GTK_VSCALE (object); + + switch (arg_id) + { + case ARG_ADJUSTMENT: + gtk_range_set_adjustment (GTK_RANGE (vscale), GTK_VALUE_POINTER (*arg)); + break; + default: + break; + } +} + +static void +gtk_vscale_get_arg (GtkObject *object, + GtkArg *arg, + guint arg_id) +{ + GtkVScale *vscale; + + vscale = GTK_VSCALE (object); + + switch (arg_id) + { + case ARG_ADJUSTMENT: + GTK_VALUE_POINTER (*arg) = GTK_RANGE (vscale); + break; + default: + arg->type = GTK_TYPE_INVALID; + break; + } +} + static void gtk_vscale_init (GtkVScale *vscale) { @@ -113,16 +172,13 @@ gtk_vscale_init (GtkVScale *vscale) GtkWidget* gtk_vscale_new (GtkAdjustment *adjustment) { - GtkVScale *vscale; - - vscale = gtk_type_new (gtk_vscale_get_type ()); - - if (!adjustment) - adjustment = (GtkAdjustment*) gtk_adjustment_new (0.0, 0.0, 0.0, 0.0, 0.0, 0.0); - - gtk_range_set_adjustment (GTK_RANGE (vscale), adjustment); - - return GTK_WIDGET (vscale); + GtkWidget *vscale; + + vscale = gtk_widget_new (GTK_TYPE_VSCALE, + "adjustment", adjustment, + NULL); + + return vscale; } @@ -133,98 +189,99 @@ gtk_vscale_realize (GtkWidget *widget) GdkWindowAttr attributes; gint attributes_mask; gint x, y, w, h; - + g_return_if_fail (widget != NULL); g_return_if_fail (GTK_IS_VSCALE (widget)); - + GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED); range = GTK_RANGE (widget); - + widget->window = gtk_widget_get_parent_window (widget); gdk_window_ref (widget->window); - + gtk_vscale_pos_trough (GTK_VSCALE (widget), &x, &y, &w, &h); - + attributes.x = x; attributes.y = y; attributes.width = w; attributes.height = h; attributes.wclass = GDK_INPUT_OUTPUT; + attributes.window_type = GDK_WINDOW_CHILD; + attributes.event_mask = gtk_widget_get_events (widget) | - (GDK_EXPOSURE_MASK | - GDK_BUTTON_PRESS_MASK | - GDK_BUTTON_RELEASE_MASK | - GDK_ENTER_NOTIFY_MASK | - GDK_LEAVE_NOTIFY_MASK); + (GDK_EXPOSURE_MASK | + GDK_BUTTON_PRESS_MASK | + GDK_BUTTON_RELEASE_MASK | + GDK_ENTER_NOTIFY_MASK | + GDK_LEAVE_NOTIFY_MASK); attributes.visual = gtk_widget_get_visual (widget); attributes.colormap = gtk_widget_get_colormap (widget); - + attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP; - + range->trough = gdk_window_new (widget->window, &attributes, attributes_mask); - + attributes.width = RANGE_CLASS (range)->slider_width; attributes.height = SCALE_CLASS (range)->slider_length; attributes.event_mask |= (GDK_BUTTON_MOTION_MASK | - GDK_POINTER_MOTION_HINT_MASK); - + GDK_POINTER_MOTION_HINT_MASK); + range->slider = gdk_window_new (range->trough, &attributes, attributes_mask); - + widget->style = gtk_style_attach (widget->style, widget->window); - + gdk_window_set_user_data (range->trough, widget); gdk_window_set_user_data (range->slider, widget); - + gtk_style_set_background (widget->style, range->trough, GTK_STATE_ACTIVE); gtk_style_set_background (widget->style, range->slider, GTK_STATE_NORMAL); - + gtk_range_slider_update (GTK_RANGE (widget)); - + gdk_window_show (range->slider); - gdk_window_show (range->trough); } static void gtk_vscale_draw (GtkWidget *widget, - GdkRectangle *area) + GdkRectangle *area) { GtkRange *range; GdkRectangle tmp_area; GdkRectangle child_area; gint x, y, width, height; - + g_return_if_fail (widget != NULL); g_return_if_fail (GTK_IS_RANGE (widget)); g_return_if_fail (area != NULL); - + if (GTK_WIDGET_VISIBLE (widget) && GTK_WIDGET_MAPPED (widget)) { range = GTK_RANGE (widget); - + gtk_vscale_pos_background (GTK_VSCALE (widget), &x, &y, &width, &height); - + tmp_area.x = x; tmp_area.y = y; tmp_area.width = width; tmp_area.height = height; - + if (gdk_rectangle_intersect (area, &tmp_area, &child_area)) - gtk_range_draw_background (range); - + gtk_range_draw_background (range); + gtk_vscale_pos_trough (GTK_VSCALE (widget), &x, &y, &width, &height); - + tmp_area.x = x; tmp_area.y = y; tmp_area.width = width; tmp_area.height = height; - + if (gdk_rectangle_intersect (area, &tmp_area, &child_area)) - { - gtk_range_draw_trough (range); - gtk_range_draw_slider (range); - gtk_range_draw_step_forw (range); - gtk_range_draw_step_back (range); - } + { + gtk_range_draw_trough (range); + gtk_range_draw_slider (range); + gtk_range_draw_step_forw (range); + gtk_range_draw_step_back (range); + } } } @@ -234,79 +291,79 @@ gtk_vscale_clear_background (GtkRange *range) GtkWidget *widget; GtkScale *scale; gint x, y, width, height; - + g_return_if_fail (range != NULL); g_return_if_fail (GTK_IS_SCALE (range)); - + widget = GTK_WIDGET (range); scale = GTK_SCALE (range); - + gtk_vscale_pos_background (GTK_VSCALE (widget), &x, &y, &width, &height); - + gtk_widget_queue_clear_area (GTK_WIDGET (range), - x, y, width, height); + x, y, width, height); } static void gtk_vscale_size_request (GtkWidget *widget, - GtkRequisition *requisition) + GtkRequisition *requisition) { GtkScale *scale; gint value_width; - + g_return_if_fail (widget != NULL); g_return_if_fail (GTK_IS_VSCALE (widget)); g_return_if_fail (requisition != NULL); - + scale = GTK_SCALE (widget); - + requisition->width = (RANGE_CLASS (scale)->slider_width + - widget->style->klass->ythickness * 2); + widget->style->klass->ythickness * 2); requisition->height = (SCALE_CLASS (scale)->slider_length + - widget->style->klass->xthickness) * 2; - + widget->style->klass->xthickness) * 2; + if (scale->draw_value) { value_width = gtk_scale_value_width (scale); - + if ((scale->value_pos == GTK_POS_LEFT) || - (scale->value_pos == GTK_POS_RIGHT)) - { - requisition->width += value_width + SCALE_CLASS (scale)->value_spacing; - if (requisition->height < (widget->style->font->ascent + widget->style->font->descent)) - requisition->height = widget->style->font->ascent + widget->style->font->descent; - } + (scale->value_pos == GTK_POS_RIGHT)) + { + requisition->width += value_width + SCALE_CLASS (scale)->value_spacing; + if (requisition->height < (widget->style->font->ascent + widget->style->font->descent)) + requisition->height = widget->style->font->ascent + widget->style->font->descent; + } else if ((scale->value_pos == GTK_POS_TOP) || - (scale->value_pos == GTK_POS_BOTTOM)) - { - if (requisition->width < value_width) - requisition->width = value_width; - requisition->height += widget->style->font->ascent + widget->style->font->descent; - } + (scale->value_pos == GTK_POS_BOTTOM)) + { + if (requisition->width < value_width) + requisition->width = value_width; + requisition->height += widget->style->font->ascent + widget->style->font->descent; + } } } static void gtk_vscale_size_allocate (GtkWidget *widget, - GtkAllocation *allocation) + GtkAllocation *allocation) { GtkRange *range; GtkScale *scale; gint width, height; gint x, y; - + g_return_if_fail (widget != NULL); g_return_if_fail (GTK_IS_VSCALE (widget)); g_return_if_fail (allocation != NULL); - + widget->allocation = *allocation; if (GTK_WIDGET_REALIZED (widget)) { range = GTK_RANGE (widget); scale = GTK_SCALE (widget); - + gtk_vscale_pos_trough (GTK_VSCALE (widget), &x, &y, &width, &height); - + gdk_window_move_resize (range->trough, x, y, width, height); gtk_range_slider_update (GTK_RANGE (widget)); } @@ -314,49 +371,49 @@ gtk_vscale_size_allocate (GtkWidget *widget, static void gtk_vscale_pos_trough (GtkVScale *vscale, - gint *x, - gint *y, - gint *w, - gint *h) + gint *x, + gint *y, + gint *w, + gint *h) { GtkWidget *widget; GtkScale *scale; - + g_return_if_fail (vscale != NULL); g_return_if_fail (GTK_IS_VSCALE (vscale)); g_return_if_fail ((x != NULL) && (y != NULL) && (w != NULL) && (h != NULL)); - + widget = GTK_WIDGET (vscale); scale = GTK_SCALE (vscale); - + *w = (RANGE_CLASS (scale)->slider_width + - widget->style->klass->xthickness * 2); + widget->style->klass->xthickness * 2); *h = widget->allocation.height; - + if (scale->draw_value) { *x = 0; *y = 0; - + switch (scale->value_pos) - { - case GTK_POS_LEFT: - *x = (gtk_scale_value_width (scale) + - (widget->allocation.width - widget->requisition.width) / 2); - break; - case GTK_POS_RIGHT: - *x = (widget->allocation.width - widget->requisition.width) / 2; - break; - case GTK_POS_TOP: - *x = (widget->allocation.width - *w) / 2; - *y = widget->style->font->ascent + widget->style->font->descent; - *h -= *y; - break; - case GTK_POS_BOTTOM: - *x = (widget->allocation.width - *w) / 2; - *h -= widget->style->font->ascent + widget->style->font->descent; - break; - } + { + case GTK_POS_LEFT: + *x = (gtk_scale_value_width (scale) + + (widget->allocation.width - widget->requisition.width) / 2); + break; + case GTK_POS_RIGHT: + *x = (widget->allocation.width - widget->requisition.width) / 2; + break; + case GTK_POS_TOP: + *x = (widget->allocation.width - *w) / 2; + *y = widget->style->font->ascent + widget->style->font->descent; + *h -= *y; + break; + case GTK_POS_BOTTOM: + *x = (widget->allocation.width - *w) / 2; + *h -= widget->style->font->ascent + widget->style->font->descent; + break; + } } else { @@ -365,37 +422,37 @@ gtk_vscale_pos_trough (GtkVScale *vscale, } *y += 1; *h -= 2; - + *x += widget->allocation.x; *y += widget->allocation.y; } static void gtk_vscale_pos_background (GtkVScale *vscale, - gint *x, - gint *y, - gint *w, - gint *h) + gint *x, + gint *y, + gint *w, + gint *h) { GtkWidget *widget; GtkScale *scale; - + gint tx, ty, twidth, theight; - + g_return_if_fail (vscale != NULL); g_return_if_fail (GTK_IS_VSCALE (vscale)); g_return_if_fail ((x != NULL) && (y != NULL) && (w != NULL) && (h != NULL)); - + gtk_vscale_pos_trough (vscale, &tx, &ty, &twidth, &theight); widget = GTK_WIDGET (vscale); scale = GTK_SCALE (vscale); - + *x = widget->allocation.x; *y = widget->allocation.y; *w = widget->allocation.width; *h = widget->allocation.height; - + switch (scale->value_pos) { case GTK_POS_LEFT: @@ -419,10 +476,10 @@ static void gtk_vscale_draw_slider (GtkRange *range) { GtkStateType state_type; - + g_return_if_fail (range != NULL); g_return_if_fail (GTK_IS_VSCALE (range)); - + if (range->slider) { if ((range->in_child == RANGE_CLASS (range)->slider) || @@ -430,8 +487,8 @@ gtk_vscale_draw_slider (GtkRange *range) state_type = GTK_STATE_PRELIGHT; else state_type = GTK_STATE_NORMAL; - - gtk_paint_slider(GTK_WIDGET (range)->style, range->slider, state_type, + + gtk_paint_slider (GTK_WIDGET (range)->style, range->slider, state_type, GTK_SHADOW_OUT, NULL, GTK_WIDGET (range), "vscale", 0, 0, -1, -1, @@ -448,78 +505,78 @@ gtk_vscale_draw_value (GtkScale *scale) gint text_width; gint width, height; gint x, y; - + g_return_if_fail (scale != NULL); g_return_if_fail (GTK_IS_VSCALE (scale)); - + widget = GTK_WIDGET (scale); if (scale->draw_value) { sprintf (buffer, "%0.*f", GTK_RANGE (scale)->digits, GTK_RANGE (scale)->adjustment->value); text_width = gdk_string_measure (GTK_WIDGET (scale)->style->font, buffer); - + switch (scale->value_pos) - { - case GTK_POS_LEFT: - gdk_window_get_position (GTK_RANGE (scale)->trough, &x, NULL); - gdk_window_get_position (GTK_RANGE (scale)->slider, NULL, &y); - gdk_window_get_size (GTK_RANGE (scale)->trough, &width, NULL); - gdk_window_get_size (GTK_RANGE (scale)->slider, NULL, &height); - - x -= SCALE_CLASS (scale)->value_spacing + text_width; - y += widget->allocation.y + ((height - - (GTK_WIDGET (scale)->style->font->ascent + - GTK_WIDGET (scale)->style->font->descent)) / 2 + - GTK_WIDGET (scale)->style->font->ascent); - break; - case GTK_POS_RIGHT: - gdk_window_get_position (GTK_RANGE (scale)->trough, &x, NULL); - gdk_window_get_position (GTK_RANGE (scale)->slider, NULL, &y); - gdk_window_get_size (GTK_RANGE (scale)->trough, &width, NULL); - gdk_window_get_size (GTK_RANGE (scale)->slider, NULL, &height); - - x += width + SCALE_CLASS (scale)->value_spacing; - y += widget->allocation.y + ((height - - (GTK_WIDGET (scale)->style->font->ascent + - GTK_WIDGET (scale)->style->font->descent)) / 2 + - GTK_WIDGET (scale)->style->font->ascent); - break; - case GTK_POS_TOP: - gdk_window_get_position (GTK_RANGE (scale)->trough, &x, &y); - gdk_window_get_size (GTK_RANGE (scale)->slider, &width, NULL); - gdk_window_get_size (GTK_RANGE (scale)->trough, NULL, &height); - - x += (width - text_width) / 2; - y -= GTK_WIDGET (scale)->style->font->descent; - break; - case GTK_POS_BOTTOM: - gdk_window_get_position (GTK_RANGE (scale)->trough, &x, &y); - gdk_window_get_size (GTK_RANGE (scale)->slider, &width, NULL); - gdk_window_get_size (GTK_RANGE (scale)->trough, NULL, &height); - - x += (width - text_width) / 2; - y += height + GTK_WIDGET (scale)->style->font->ascent; - break; - } - + { + case GTK_POS_LEFT: + gdk_window_get_position (GTK_RANGE (scale)->trough, &x, NULL); + gdk_window_get_position (GTK_RANGE (scale)->slider, NULL, &y); + gdk_window_get_size (GTK_RANGE (scale)->trough, &width, NULL); + gdk_window_get_size (GTK_RANGE (scale)->slider, NULL, &height); + + x -= SCALE_CLASS (scale)->value_spacing + text_width; + y += widget->allocation.y + ((height - + (GTK_WIDGET (scale)->style->font->ascent + + GTK_WIDGET (scale)->style->font->descent)) / 2 + + GTK_WIDGET (scale)->style->font->ascent); + break; + case GTK_POS_RIGHT: + gdk_window_get_position (GTK_RANGE (scale)->trough, &x, NULL); + gdk_window_get_position (GTK_RANGE (scale)->slider, NULL, &y); + gdk_window_get_size (GTK_RANGE (scale)->trough, &width, NULL); + gdk_window_get_size (GTK_RANGE (scale)->slider, NULL, &height); + + x += width + SCALE_CLASS (scale)->value_spacing; + y += widget->allocation.y + ((height - + (GTK_WIDGET (scale)->style->font->ascent + + GTK_WIDGET (scale)->style->font->descent)) / 2 + + GTK_WIDGET (scale)->style->font->ascent); + break; + case GTK_POS_TOP: + gdk_window_get_position (GTK_RANGE (scale)->trough, &x, &y); + gdk_window_get_size (GTK_RANGE (scale)->slider, &width, NULL); + gdk_window_get_size (GTK_RANGE (scale)->trough, NULL, &height); + + x += (width - text_width) / 2; + y -= GTK_WIDGET (scale)->style->font->descent; + break; + case GTK_POS_BOTTOM: + gdk_window_get_position (GTK_RANGE (scale)->trough, &x, &y); + gdk_window_get_size (GTK_RANGE (scale)->slider, &width, NULL); + gdk_window_get_size (GTK_RANGE (scale)->trough, NULL, &height); + + x += (width - text_width) / 2; + y += height + GTK_WIDGET (scale)->style->font->ascent; + break; + } + state_type = GTK_STATE_NORMAL; if (!GTK_WIDGET_IS_SENSITIVE (scale)) - state_type = GTK_STATE_INSENSITIVE; - + state_type = GTK_STATE_INSENSITIVE; + gtk_paint_string (GTK_WIDGET (scale)->style, - GTK_WIDGET (scale)->window, - state_type, - NULL, GTK_WIDGET (scale), "vscale", - x, y, buffer); + GTK_WIDGET (scale)->window, + state_type, + NULL, GTK_WIDGET (scale), "vscale", + x, y, buffer); } } static gint -gtk_vscale_trough_keys(GtkRange *range, - GdkEventKey *key, - GtkScrollType *scroll, - GtkTroughType *pos) +gtk_vscale_trough_keys (GtkRange *range, + GdkEventKey *key, + GtkScrollType *scroll, + GtkTroughType *pos) { gint return_val = FALSE; switch (key->keyval) diff --git a/gtk/gtkvscale.h b/gtk/gtkvscale.h index 15da99cb18..bfe577a5fc 100644 --- a/gtk/gtkvscale.h +++ b/gtk/gtkvscale.h @@ -29,9 +29,11 @@ extern "C" { #endif /* __cplusplus */ -#define GTK_VSCALE(obj) GTK_CHECK_CAST (obj, gtk_vscale_get_type (), GtkVScale) -#define GTK_VSCALE_CLASS(klass) GTK_CHECK_CLASS_CAST (klass, gtk_vscale_get_type (), GtkVScaleClass) -#define GTK_IS_VSCALE(obj) GTK_CHECK_TYPE (obj, gtk_vscale_get_type ()) +#define GTK_TYPE_VSCALE (gtk_vscale_get_type ()) +#define GTK_VSCALE(obj) (GTK_CHECK_CAST ((obj), GTK_TYPE_VSCALE, GtkVScale)) +#define GTK_VSCALE_CLASS(klass) (GTK_CHECK_CLASS_CAST ((klass), GTK_TYPE_VSCALE, GtkVScaleClass)) +#define GTK_IS_VSCALE(obj) (GTK_CHECK_TYPE ((obj), GTK_TYPE_VSCALE)) +#define GTK_IS_VSCALE_CLASS(klass) (GTK_CHECK_CLASS_TYPE ((klass), GTK_TYPE_VSCALE)) typedef struct _GtkVScale GtkVScale; @@ -48,7 +50,7 @@ struct _GtkVScaleClass }; -guint gtk_vscale_get_type (void); +GtkType gtk_vscale_get_type (void); GtkWidget* gtk_vscale_new (GtkAdjustment *adjustment); diff --git a/gtk/gtkvscrollbar.c b/gtk/gtkvscrollbar.c index 2e02acf227..3cb8d50051 100644 --- a/gtk/gtkvscrollbar.c +++ b/gtk/gtkvscrollbar.c @@ -25,58 +25,79 @@ #define RANGE_CLASS(w) GTK_RANGE_CLASS (GTK_OBJECT (w)->klass) +enum { + ARG_0, + ARG_ADJUSTMENT, +}; static void gtk_vscrollbar_class_init (GtkVScrollbarClass *klass); static void gtk_vscrollbar_init (GtkVScrollbar *vscrollbar); +static void gtk_vscrollbar_set_arg (GtkObject *object, + GtkArg *arg, + guint arg_id); +static void gtk_vscrollbar_get_arg (GtkObject *object, + GtkArg *arg, + guint arg_id); static void gtk_vscrollbar_realize (GtkWidget *widget); static void gtk_vscrollbar_size_allocate (GtkWidget *widget, - GtkAllocation *allocation); + GtkAllocation *allocation); static void gtk_vscrollbar_draw_step_forw (GtkRange *range); static void gtk_vscrollbar_draw_step_back (GtkRange *range); static void gtk_vscrollbar_slider_update (GtkRange *range); static void gtk_vscrollbar_calc_slider_size (GtkVScrollbar *vscrollbar); static gint gtk_vscrollbar_trough_keys (GtkRange *range, - GdkEventKey *key, - GtkScrollType *scroll, - GtkTroughType *pos); + GdkEventKey *key, + GtkScrollType *scroll, + GtkTroughType *pos); -guint + +GtkType gtk_vscrollbar_get_type (void) { - static guint vscrollbar_type = 0; - + static GtkType vscrollbar_type = 0; + if (!vscrollbar_type) { GtkTypeInfo vscrollbar_info = { - "GtkVScrollbar", - sizeof (GtkVScrollbar), - sizeof (GtkVScrollbarClass), - (GtkClassInitFunc) gtk_vscrollbar_class_init, - (GtkObjectInitFunc) gtk_vscrollbar_init, - /* reserved_1 */ NULL, + "GtkVScrollbar", + sizeof (GtkVScrollbar), + sizeof (GtkVScrollbarClass), + (GtkClassInitFunc) gtk_vscrollbar_class_init, + (GtkObjectInitFunc) gtk_vscrollbar_init, + /* reserved_1 */ NULL, /* reserved_2 */ NULL, (GtkClassInitFunc) NULL, }; - - vscrollbar_type = gtk_type_unique (gtk_scrollbar_get_type (), &vscrollbar_info); + + vscrollbar_type = gtk_type_unique (GTK_TYPE_SCROLLBAR, &vscrollbar_info); } - + return vscrollbar_type; } static void -gtk_vscrollbar_class_init (GtkVScrollbarClass *klass) +gtk_vscrollbar_class_init (GtkVScrollbarClass *class) { + GtkObjectClass *object_class; GtkWidgetClass *widget_class; GtkRangeClass *range_class; - - widget_class = (GtkWidgetClass*) klass; - range_class = (GtkRangeClass*) klass; - + + object_class = (GtkObjectClass*) class; + widget_class = (GtkWidgetClass*) class; + range_class = (GtkRangeClass*) class; + + gtk_object_add_arg_type ("GtkVScrollbar::adjustment", + GTK_TYPE_ADJUSTMENT, + GTK_ARG_READWRITE | GTK_ARG_CONSTRUCT, + ARG_ADJUSTMENT); + + object_class->set_arg = gtk_vscrollbar_set_arg; + object_class->get_arg = gtk_vscrollbar_get_arg; + widget_class->realize = gtk_vscrollbar_realize; widget_class->size_allocate = gtk_vscrollbar_size_allocate; - + range_class->draw_step_forw = gtk_vscrollbar_draw_step_forw; range_class->draw_step_back = gtk_vscrollbar_draw_step_back; range_class->slider_update = gtk_vscrollbar_slider_update; @@ -85,36 +106,72 @@ gtk_vscrollbar_class_init (GtkVScrollbarClass *klass) range_class->motion = gtk_range_default_vmotion; } +static void +gtk_vscrollbar_set_arg (GtkObject *object, + GtkArg *arg, + guint arg_id) +{ + GtkVScrollbar *vscrollbar; + + vscrollbar = GTK_VSCROLLBAR (object); + + switch (arg_id) + { + case ARG_ADJUSTMENT: + gtk_range_set_adjustment (GTK_RANGE (vscrollbar), GTK_VALUE_POINTER (*arg)); + break; + default: + break; + } +} + +static void +gtk_vscrollbar_get_arg (GtkObject *object, + GtkArg *arg, + guint arg_id) +{ + GtkVScrollbar *vscrollbar; + + vscrollbar = GTK_VSCROLLBAR (object); + + switch (arg_id) + { + case ARG_ADJUSTMENT: + GTK_VALUE_POINTER (*arg) = GTK_RANGE (vscrollbar); + break; + default: + arg->type = GTK_TYPE_INVALID; + break; + } +} + static void gtk_vscrollbar_init (GtkVScrollbar *vscrollbar) { GtkWidget *widget; GtkRequisition *requisition; - + widget = GTK_WIDGET (vscrollbar); requisition = &widget->requisition; - + requisition->width = (RANGE_CLASS (widget)->slider_width + - widget->style->klass->xthickness * 2); + widget->style->klass->xthickness * 2); requisition->height = (RANGE_CLASS (widget)->min_slider_size + - RANGE_CLASS (widget)->stepper_size + - RANGE_CLASS (widget)->stepper_slider_spacing + - widget->style->klass->ythickness) * 2; + RANGE_CLASS (widget)->stepper_size + + RANGE_CLASS (widget)->stepper_slider_spacing + + widget->style->klass->ythickness) * 2; } GtkWidget* gtk_vscrollbar_new (GtkAdjustment *adjustment) { - GtkVScrollbar *vscrollbar; - - vscrollbar = gtk_type_new (gtk_vscrollbar_get_type ()); - - if (!adjustment) - adjustment = (GtkAdjustment*) gtk_adjustment_new (0.0, 0.0, 0.0, 0.0, 0.0, 0.0); - - gtk_range_set_adjustment (GTK_RANGE (vscrollbar), adjustment); - - return GTK_WIDGET (vscrollbar); + GtkWidget *vscrollbar; + + vscrollbar = gtk_widget_new (GTK_TYPE_VSCROLLBAR, + "adjustment", adjustment, + NULL); + + return vscrollbar; } @@ -124,13 +181,13 @@ gtk_vscrollbar_realize (GtkWidget *widget) GtkRange *range; GdkWindowAttr attributes; gint attributes_mask; - + g_return_if_fail (widget != NULL); g_return_if_fail (GTK_IS_VSCROLLBAR (widget)); - + GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED); range = GTK_RANGE (widget); - + attributes.x = widget->allocation.x + (widget->allocation.width - widget->requisition.width) / 2; attributes.y = widget->allocation.y; attributes.width = widget->requisition.width; @@ -141,54 +198,54 @@ gtk_vscrollbar_realize (GtkWidget *widget) attributes.colormap = gtk_widget_get_colormap (widget); attributes.event_mask = gtk_widget_get_events (widget); attributes.event_mask |= (GDK_EXPOSURE_MASK | - GDK_BUTTON_PRESS_MASK | - GDK_BUTTON_RELEASE_MASK | - GDK_ENTER_NOTIFY_MASK | - GDK_LEAVE_NOTIFY_MASK); - + GDK_BUTTON_PRESS_MASK | + GDK_BUTTON_RELEASE_MASK | + GDK_ENTER_NOTIFY_MASK | + GDK_LEAVE_NOTIFY_MASK); + attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP; widget->window = gdk_window_new (gtk_widget_get_parent_window (widget), &attributes, attributes_mask); - + range->trough = widget->window; gdk_window_ref (range->trough); - + attributes.x = widget->style->klass->xthickness; attributes.y = widget->style->klass->ythickness; attributes.width = RANGE_CLASS (widget)->stepper_size; attributes.height = RANGE_CLASS (widget)->stepper_size; - + range->step_back = gdk_window_new (range->trough, &attributes, attributes_mask); - + attributes.y = (widget->allocation.height - - widget->style->klass->ythickness - - RANGE_CLASS (widget)->stepper_size); - + widget->style->klass->ythickness - + RANGE_CLASS (widget)->stepper_size); + range->step_forw = gdk_window_new (range->trough, &attributes, attributes_mask); - + attributes.x = widget->style->klass->ythickness; attributes.y = 0; attributes.width = RANGE_CLASS (widget)->slider_width; attributes.height = RANGE_CLASS (widget)->min_slider_size; attributes.event_mask |= (GDK_BUTTON_MOTION_MASK | - GDK_POINTER_MOTION_HINT_MASK); - + GDK_POINTER_MOTION_HINT_MASK); + range->slider = gdk_window_new (range->trough, &attributes, attributes_mask); - + gtk_vscrollbar_calc_slider_size (GTK_VSCROLLBAR (widget)); gtk_range_slider_update (GTK_RANGE (widget)); - + widget->style = gtk_style_attach (widget->style, widget->window); - + gdk_window_set_user_data (range->trough, widget); gdk_window_set_user_data (range->slider, widget); gdk_window_set_user_data (range->step_forw, widget); gdk_window_set_user_data (range->step_back, widget); - + gtk_style_set_background (widget->style, range->trough, GTK_STATE_ACTIVE); gtk_style_set_background (widget->style, range->slider, GTK_STATE_NORMAL); gtk_style_set_background (widget->style, range->step_forw, GTK_STATE_ACTIVE); gtk_style_set_background (widget->style, range->step_back, GTK_STATE_ACTIVE); - + gdk_window_show (range->slider); gdk_window_show (range->step_forw); gdk_window_show (range->step_back); @@ -196,38 +253,38 @@ gtk_vscrollbar_realize (GtkWidget *widget) static void gtk_vscrollbar_size_allocate (GtkWidget *widget, - GtkAllocation *allocation) + GtkAllocation *allocation) { GtkRange *range; - + g_return_if_fail (widget != NULL); g_return_if_fail (GTK_IS_VSCROLLBAR (widget)); g_return_if_fail (allocation != NULL); - + widget->allocation = *allocation; if (GTK_WIDGET_REALIZED (widget)) { range = GTK_RANGE (widget); - + gdk_window_move_resize (range->trough, - allocation->x + (allocation->width - widget->requisition.width) / 2, - allocation->y, - widget->requisition.width, allocation->height); + allocation->x + (allocation->width - widget->requisition.width) / 2, + allocation->y, + widget->requisition.width, allocation->height); gdk_window_move_resize (range->step_back, - widget->style->klass->xthickness, - widget->style->klass->ythickness, - widget->requisition.width - widget->style->klass->xthickness * 2, - RANGE_CLASS (widget)->stepper_size); + widget->style->klass->xthickness, + widget->style->klass->ythickness, + widget->requisition.width - widget->style->klass->xthickness * 2, + RANGE_CLASS (widget)->stepper_size); gdk_window_move_resize (range->step_forw, - widget->style->klass->xthickness, - allocation->height - widget->style->klass->ythickness - - RANGE_CLASS (widget)->stepper_size, - widget->requisition.width - widget->style->klass->xthickness * 2, - RANGE_CLASS (widget)->stepper_size); + widget->style->klass->xthickness, + allocation->height - widget->style->klass->ythickness - + RANGE_CLASS (widget)->stepper_size, + widget->requisition.width - widget->style->klass->xthickness * 2, + RANGE_CLASS (widget)->stepper_size); gdk_window_resize (range->slider, - widget->requisition.width - widget->style->klass->xthickness * 2, - RANGE_CLASS (range)->min_slider_size); - + widget->requisition.width - widget->style->klass->xthickness * 2, + RANGE_CLASS (range)->min_slider_size); + gtk_range_slider_update (GTK_RANGE (widget)); } } @@ -237,32 +294,32 @@ gtk_vscrollbar_draw_step_forw (GtkRange *range) { GtkStateType state_type; GtkShadowType shadow_type; - + g_return_if_fail (range != NULL); g_return_if_fail (GTK_IS_VSCROLLBAR (range)); - + if (GTK_WIDGET_DRAWABLE (range)) { if (range->in_child == RANGE_CLASS (range)->step_forw) - { - if (range->click_child == RANGE_CLASS (range)->step_forw) - state_type = GTK_STATE_ACTIVE; - else - state_type = GTK_STATE_PRELIGHT; - } + { + if (range->click_child == RANGE_CLASS (range)->step_forw) + state_type = GTK_STATE_ACTIVE; + else + state_type = GTK_STATE_PRELIGHT; + } else - state_type = GTK_STATE_NORMAL; - + state_type = GTK_STATE_NORMAL; + if (range->click_child == RANGE_CLASS (range)->step_forw) - shadow_type = GTK_SHADOW_IN; + shadow_type = GTK_SHADOW_IN; else - shadow_type = GTK_SHADOW_OUT; - + shadow_type = GTK_SHADOW_OUT; + gtk_paint_arrow (GTK_WIDGET (range)->style, range->step_forw, - state_type, shadow_type, - NULL, GTK_WIDGET (range), "scrollbar", - GTK_ARROW_DOWN, - TRUE, 0, 0, -1, -1); + state_type, shadow_type, + NULL, GTK_WIDGET (range), "vscrollbar", + GTK_ARROW_DOWN, + TRUE, 0, 0, -1, -1); } } @@ -271,32 +328,32 @@ gtk_vscrollbar_draw_step_back (GtkRange *range) { GtkStateType state_type; GtkShadowType shadow_type; - + g_return_if_fail (range != NULL); g_return_if_fail (GTK_IS_VSCROLLBAR (range)); - + if (GTK_WIDGET_DRAWABLE (range)) { if (range->in_child == RANGE_CLASS (range)->step_back) - { - if (range->click_child == RANGE_CLASS (range)->step_back) - state_type = GTK_STATE_ACTIVE; - else - state_type = GTK_STATE_PRELIGHT; - } + { + if (range->click_child == RANGE_CLASS (range)->step_back) + state_type = GTK_STATE_ACTIVE; + else + state_type = GTK_STATE_PRELIGHT; + } else - state_type = GTK_STATE_NORMAL; - + state_type = GTK_STATE_NORMAL; + if (range->click_child == RANGE_CLASS (range)->step_back) - shadow_type = GTK_SHADOW_IN; + shadow_type = GTK_SHADOW_IN; else - shadow_type = GTK_SHADOW_OUT; - + shadow_type = GTK_SHADOW_OUT; + gtk_paint_arrow (GTK_WIDGET (range)->style, range->step_back, - state_type, shadow_type, - NULL, GTK_WIDGET (range), "scrollbar", - GTK_ARROW_UP, - TRUE, 0, 0, -1, -1); + state_type, shadow_type, + NULL, GTK_WIDGET (range), "vscrollbar", + GTK_ARROW_UP, + TRUE, 0, 0, -1, -1); } } @@ -305,7 +362,7 @@ gtk_vscrollbar_slider_update (GtkRange *range) { g_return_if_fail (range != NULL); g_return_if_fail (GTK_IS_VSCROLLBAR (range)); - + gtk_vscrollbar_calc_slider_size (GTK_VSCROLLBAR (range)); gtk_range_default_vslider_update (range); } @@ -321,50 +378,50 @@ gtk_vscrollbar_calc_slider_size (GtkVScrollbar *vscrollbar) gint slider_height; gint top, bottom; gint height; - + g_return_if_fail (vscrollbar != NULL); g_return_if_fail (GTK_IS_VSCROLLBAR (vscrollbar)); - + if (GTK_WIDGET_REALIZED (vscrollbar)) { range = GTK_RANGE (vscrollbar); - + gdk_window_get_size (range->step_back, NULL, &step_back_height); gdk_window_get_position (range->step_back, NULL, &step_back_y); gdk_window_get_position (range->step_forw, NULL, &step_forw_y); - + top = (step_back_y + - step_back_height + - RANGE_CLASS (vscrollbar)->stepper_slider_spacing); + step_back_height + + RANGE_CLASS (vscrollbar)->stepper_slider_spacing); bottom = step_forw_y - RANGE_CLASS (vscrollbar)->stepper_slider_spacing; height = bottom - top; - + if ((range->adjustment->page_size > 0) && - (range->adjustment->lower != range->adjustment->upper)) - { - if (range->adjustment->page_size > - (range->adjustment->upper - range->adjustment->lower)) - range->adjustment->page_size = range->adjustment->upper - range->adjustment->lower; - - height = (height * range->adjustment->page_size / - (range->adjustment->upper - range->adjustment->lower)); - - if (height < RANGE_CLASS (vscrollbar)->min_slider_size) - height = RANGE_CLASS (vscrollbar)->min_slider_size; - } - + (range->adjustment->lower != range->adjustment->upper)) + { + if (range->adjustment->page_size > + (range->adjustment->upper - range->adjustment->lower)) + range->adjustment->page_size = range->adjustment->upper - range->adjustment->lower; + + height = (height * range->adjustment->page_size / + (range->adjustment->upper - range->adjustment->lower)); + + if (height < RANGE_CLASS (vscrollbar)->min_slider_size) + height = RANGE_CLASS (vscrollbar)->min_slider_size; + } + gdk_window_get_size (range->slider, &slider_width, &slider_height); - + if (slider_height != height) - gdk_window_resize (range->slider, slider_width, height); + gdk_window_resize (range->slider, slider_width, height); } } static gint gtk_vscrollbar_trough_keys(GtkRange *range, - GdkEventKey *key, - GtkScrollType *scroll, - GtkTroughType *pos) + GdkEventKey *key, + GtkScrollType *scroll, + GtkTroughType *pos) { gint return_val = FALSE; switch (key->keyval) @@ -380,16 +437,16 @@ gtk_vscrollbar_trough_keys(GtkRange *range, case GDK_Page_Up: return_val = TRUE; if (key->state & GDK_CONTROL_MASK) - *pos = GTK_TROUGH_START; + *pos = GTK_TROUGH_START; else - *scroll = GTK_SCROLL_PAGE_BACKWARD; + *scroll = GTK_SCROLL_PAGE_BACKWARD; break; case GDK_Page_Down: return_val = TRUE; if (key->state & GDK_CONTROL_MASK) - *pos = GTK_TROUGH_END; + *pos = GTK_TROUGH_END; else - *scroll = GTK_SCROLL_PAGE_FORWARD; + *scroll = GTK_SCROLL_PAGE_FORWARD; break; } return return_val; diff --git a/gtk/gtkvscrollbar.h b/gtk/gtkvscrollbar.h index 379c9017b6..d1b5207e06 100644 --- a/gtk/gtkvscrollbar.h +++ b/gtk/gtkvscrollbar.h @@ -24,9 +24,11 @@ #include -#define GTK_VSCROLLBAR(obj) GTK_CHECK_CAST (obj, gtk_vscrollbar_get_type (), GtkVScrollbar) -#define GTK_VSCROLLBAR_CLASS(klass) GTK_CHECK_CLASS_CAST (klass, gtk_vscrollbar_get_type (), GtkVScrollbarClass) -#define GTK_IS_VSCROLLBAR(obj) GTK_CHECK_TYPE (obj, gtk_vscrollbar_get_type ()) +#define GTK_TYPE_VSCROLLBAR (gtk_vscrollbar_get_type ()) +#define GTK_VSCROLLBAR(obj) (GTK_CHECK_CAST ((obj), GTK_TYPE_VSCROLLBAR, GtkVScrollbar)) +#define GTK_VSCROLLBAR_CLASS(klass) (GTK_CHECK_CLASS_CAST ((klass), GTK_TYPE_VSCROLLBAR, GtkVScrollbarClass)) +#define GTK_IS_VSCROLLBAR(obj) (GTK_CHECK_TYPE ((obj), GTK_TYPE_VSCROLLBAR)) +#define GTK_IS_VSCROLLBAR_CLASS(klass) (GTK_CHECK_CLASS_TYPE ((klass), GTK_TYPE_VSCROLLBAR)) typedef struct _GtkVScrollbar GtkVScrollbar; @@ -48,7 +50,7 @@ extern "C" { #endif /* __cplusplus */ -guint gtk_vscrollbar_get_type (void); +GtkType gtk_vscrollbar_get_type (void); GtkWidget* gtk_vscrollbar_new (GtkAdjustment *adjustment); diff --git a/gtk/gtkwidget.c b/gtk/gtkwidget.c index b8abd70b45..426e0ead0c 100644 --- a/gtk/gtkwidget.c +++ b/gtk/gtkwidget.c @@ -705,6 +705,7 @@ gtk_widget_class_init (GtkWidgetClass *klass) object_class->finalize = gtk_widget_finalize; klass->activate_signal = 0; + klass->scroll_adjustments_signal = 0; klass->show = gtk_widget_real_show; klass->show_all = gtk_widget_show; klass->hide = gtk_widget_real_hide; @@ -1054,6 +1055,9 @@ gtk_widget_new (GtkType widget_type, gtk_args_collect_cleanup (arg_list, info_list); } + if (!GTK_OBJECT_CONSTRUCTED (object)) + gtk_object_default_construct (object); + return GTK_WIDGET (object); } @@ -1070,7 +1074,7 @@ gtk_widget_newv (GtkType type, guint nargs, GtkArg *args) { - g_return_val_if_fail (gtk_type_is_a (type, gtk_widget_get_type ()), NULL); + g_return_val_if_fail (gtk_type_is_a (type, GTK_TYPE_WIDGET), NULL); return GTK_WIDGET (gtk_object_newv (type, nargs, args)); } @@ -1353,7 +1357,8 @@ gtk_widget_destroy (GtkWidget *widget) { g_return_if_fail (widget != NULL); g_return_if_fail (GTK_IS_WIDGET (widget)); - + g_return_if_fail (GTK_OBJECT_CONSTRUCTED (widget)); + gtk_object_destroy ((GtkObject*) widget); } @@ -2621,14 +2626,45 @@ gtk_widget_event (GtkWidget *widget, * results: *****************************************/ -void +gboolean gtk_widget_activate (GtkWidget *widget) { - g_return_if_fail (widget != NULL); - g_return_if_fail (GTK_IS_WIDGET (widget)); + g_return_val_if_fail (widget != NULL, FALSE); + g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE); if (WIDGET_CLASS (widget)->activate_signal) - gtk_signal_emit (GTK_OBJECT (widget), WIDGET_CLASS (widget)->activate_signal); + { + /* FIXME: we should eventually check the signals signature here */ + gtk_signal_emit (GTK_OBJECT (widget), WIDGET_CLASS (widget)->activate_signal); + + return TRUE; + } + else + return FALSE; +} + +gboolean +gtk_widget_scroll_adjustements (GtkWidget *widget, + GtkAdjustment *hadjustment, + GtkAdjustment *vadjustment) +{ + g_return_val_if_fail (widget != NULL, FALSE); + g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE); + if (hadjustment) + g_return_val_if_fail (GTK_IS_ADJUSTMENT (hadjustment), FALSE); + if (vadjustment) + g_return_val_if_fail (GTK_IS_ADJUSTMENT (vadjustment), FALSE); + + if (WIDGET_CLASS (widget)->scroll_adjustments_signal) + { + /* FIXME: we should eventually check the signals signature here */ + gtk_signal_emit (GTK_OBJECT (widget), + WIDGET_CLASS (widget)->scroll_adjustments_signal, + hadjustment, vadjustment); + return TRUE; + } + else + return FALSE; } /***************************************** @@ -2795,47 +2831,6 @@ gtk_widget_intersect (GtkWidget *widget, return return_val; } - -gint -gtk_widget_basic (GtkWidget *widget) -{ - GList *children; - GList *tmp_list; - gint return_val; - - g_return_val_if_fail (widget != NULL, FALSE); - g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE); - - if (!GTK_WIDGET_BASIC (widget)) - return FALSE; - else if (GTK_IS_CONTAINER (widget)) - { - children = gtk_container_children (GTK_CONTAINER (widget)); - if (children) - { - return_val = TRUE; - tmp_list = children; - - while (tmp_list) - { - if (!gtk_widget_basic (GTK_WIDGET (tmp_list->data))) - { - return_val = FALSE; - break; - } - - tmp_list = tmp_list->next; - } - - g_list_free (children); - return return_val; - } - } - - return TRUE; -} - - /***************************************** * gtk_widget_grab_focus: * @@ -3875,13 +3870,13 @@ gtk_widget_push_visual (GdkVisual *visual) } void -gtk_widget_push_composite (void) +gtk_widget_push_composite_child (void) { composite_child_stack++; } void -gtk_widget_pop_composite (void) +gtk_widget_pop_composite_child (void) { if (composite_child_stack) composite_child_stack--; diff --git a/gtk/gtkwidget.h b/gtk/gtkwidget.h index 24bbda0be4..fb5ed8839c 100644 --- a/gtk/gtkwidget.h +++ b/gtk/gtkwidget.h @@ -22,6 +22,7 @@ #include #include #include +#include #include @@ -48,8 +49,7 @@ typedef enum GTK_HAS_DEFAULT = 1 << 14, GTK_HAS_GRAB = 1 << 15, GTK_RC_STYLE = 1 << 16, - GTK_COMPOSITE_CHILD = 1 << 17, - GTK_BASIC = 1 << 18 + GTK_COMPOSITE_CHILD = 1 << 17 } GtkWidgetFlags; /* Macro for casting a pointer to a GtkWidget or GtkWidgetClass pointer. @@ -87,7 +87,6 @@ typedef enum #define GTK_WIDGET_HAS_GRAB(wid) ((GTK_WIDGET_FLAGS (wid) & GTK_HAS_GRAB) != 0) #define GTK_WIDGET_RC_STYLE(wid) ((GTK_WIDGET_FLAGS (wid) & GTK_RC_STYLE) != 0) #define GTK_WIDGET_COMPOSITE_CHILD(wid) ((GTK_WIDGET_FLAGS (wid) & GTK_COMPOSITE_CHILD) != 0) -#define GTK_WIDGET_BASIC(wid) ((GTK_WIDGET_FLAGS (wid) & GTK_BASIC) != 0) /* Macros for setting and clearing widget flags. */ @@ -225,11 +224,18 @@ struct _GtkWidgetClass */ GtkObjectClass parent_class; - /* The signal to emit when an object of this class is activated. - * This is used when activating the current focus widget and - * the default widget. + /* The signal to emit when a widget of this class is activated, + * gtk_widget_activate() handles the emission. + * Implementation of this signal is optional. */ guint activate_signal; + + /* This signal is emitted when a widget of this class is added + * to a scrolling aware parent, gtk_widget_set_scroll_adjustments() + * handles the emission. + * Implementation of this signal is optional. + */ + guint scroll_adjustments_signal; /* basics */ void (* show) (GtkWidget *widget); @@ -465,7 +471,11 @@ void gtk_widget_thaw_accelerators (GtkWidget *widget); gint gtk_widget_event (GtkWidget *widget, GdkEvent *event); -void gtk_widget_activate (GtkWidget *widget); +gboolean gtk_widget_activate (GtkWidget *widget); +gboolean gtk_widget_scroll_adjustements (GtkWidget *widget, + GtkAdjustment *hadjustment, + GtkAdjustment *vadjustment); + void gtk_widget_reparent (GtkWidget *widget, GtkWidget *new_parent); void gtk_widget_popup (GtkWidget *widget, @@ -474,7 +484,6 @@ void gtk_widget_popup (GtkWidget *widget, gint gtk_widget_intersect (GtkWidget *widget, GdkRectangle *area, GdkRectangle *intersection); -gint gtk_widget_basic (GtkWidget *widget); void gtk_widget_grab_focus (GtkWidget *widget); void gtk_widget_grab_default (GtkWidget *widget); @@ -543,14 +552,14 @@ void gtk_widget_reset_rc_styles (GtkWidget *widget); * This will override the values that got set by the * gtk_widget_set_default_* () functions. */ -void gtk_widget_push_style (GtkStyle *style); -void gtk_widget_push_colormap (GdkColormap *cmap); -void gtk_widget_push_visual (GdkVisual *visual); -void gtk_widget_push_composite_flag (void); -void gtk_widget_pop_composite_flag (void); -void gtk_widget_pop_style (void); -void gtk_widget_pop_colormap (void); -void gtk_widget_pop_visual (void); +void gtk_widget_push_style (GtkStyle *style); +void gtk_widget_push_colormap (GdkColormap *cmap); +void gtk_widget_push_visual (GdkVisual *visual); +void gtk_widget_push_composite_child (void); +void gtk_widget_pop_composite_child (void); +void gtk_widget_pop_style (void); +void gtk_widget_pop_colormap (void); +void gtk_widget_pop_visual (void); /* Set certain default values to be used at widget creation time. */ diff --git a/gtk/testgtk.c b/gtk/testgtk.c index 31c5522615..4b550881c1 100644 --- a/gtk/testgtk.c +++ b/gtk/testgtk.c @@ -1222,7 +1222,7 @@ create_tree_sample(guint selection_mode, (GtkSignalFunc)cb_tree_changed, (gpointer)NULL); gtk_object_set_user_data(GTK_OBJECT(root_tree), tree_buttons); - gtk_container_add(GTK_CONTAINER(scrolled_win), root_tree); + gtk_scrolled_window_add_with_viewport (GTK_SCROLLED_WINDOW (scrolled_win), root_tree); gtk_tree_set_selection_mode(GTK_TREE(root_tree), selection_mode); gtk_tree_set_view_lines(GTK_TREE(root_tree), draw_line); gtk_tree_set_view_mode(GTK_TREE(root_tree), !view_line); @@ -2520,7 +2520,7 @@ create_scrolled_windows (void) table = gtk_table_new (20, 20, FALSE); gtk_table_set_row_spacings (GTK_TABLE (table), 10); gtk_table_set_col_spacings (GTK_TABLE (table), 10); - gtk_container_add (GTK_CONTAINER (scrolled_window), table); + gtk_scrolled_window_add_with_viewport (GTK_SCROLLED_WINDOW (scrolled_window), table); gtk_container_set_focus_hadjustment (GTK_CONTAINER (table), gtk_scrolled_window_get_hadjustment (GTK_SCROLLED_WINDOW (scrolled_window))); gtk_container_set_focus_vadjustment (GTK_CONTAINER (table), @@ -3264,7 +3264,7 @@ create_list (void) list = gtk_list_new (); gtk_list_set_selection_mode (GTK_LIST (list), GTK_SELECTION_EXTENDED); - gtk_container_add (GTK_CONTAINER (scrolled_win), list); + gtk_scrolled_window_add_with_viewport (GTK_SCROLLED_WINDOW (scrolled_win), list); gtk_container_set_focus_vadjustment (GTK_CONTAINER (list), gtk_scrolled_window_get_vadjustment @@ -7245,7 +7245,7 @@ create_selection_test (void) gtk_widget_set_usize (scrolled_win, 100, 200); list = gtk_list_new (); - gtk_container_add (GTK_CONTAINER (scrolled_win), list); + gtk_scrolled_window_add_with_viewport (GTK_SCROLLED_WINDOW (scrolled_win), list); gtk_signal_connect (GTK_OBJECT(list), "selection_received", GTK_SIGNAL_FUNC (selection_test_received), NULL); @@ -8056,7 +8056,7 @@ create_main_window (void) box2 = gtk_vbox_new (FALSE, 0); gtk_container_border_width (GTK_CONTAINER (box2), 10); - gtk_container_add (GTK_CONTAINER (scrolled_window), box2); + gtk_scrolled_window_add_with_viewport (GTK_SCROLLED_WINDOW (scrolled_window), box2); gtk_container_set_focus_vadjustment (GTK_CONTAINER (box2), gtk_scrolled_window_get_vadjustment (GTK_SCROLLED_WINDOW (scrolled_window))); gtk_widget_show (box2); diff --git a/tests/testgtk.c b/tests/testgtk.c index 31c5522615..4b550881c1 100644 --- a/tests/testgtk.c +++ b/tests/testgtk.c @@ -1222,7 +1222,7 @@ create_tree_sample(guint selection_mode, (GtkSignalFunc)cb_tree_changed, (gpointer)NULL); gtk_object_set_user_data(GTK_OBJECT(root_tree), tree_buttons); - gtk_container_add(GTK_CONTAINER(scrolled_win), root_tree); + gtk_scrolled_window_add_with_viewport (GTK_SCROLLED_WINDOW (scrolled_win), root_tree); gtk_tree_set_selection_mode(GTK_TREE(root_tree), selection_mode); gtk_tree_set_view_lines(GTK_TREE(root_tree), draw_line); gtk_tree_set_view_mode(GTK_TREE(root_tree), !view_line); @@ -2520,7 +2520,7 @@ create_scrolled_windows (void) table = gtk_table_new (20, 20, FALSE); gtk_table_set_row_spacings (GTK_TABLE (table), 10); gtk_table_set_col_spacings (GTK_TABLE (table), 10); - gtk_container_add (GTK_CONTAINER (scrolled_window), table); + gtk_scrolled_window_add_with_viewport (GTK_SCROLLED_WINDOW (scrolled_window), table); gtk_container_set_focus_hadjustment (GTK_CONTAINER (table), gtk_scrolled_window_get_hadjustment (GTK_SCROLLED_WINDOW (scrolled_window))); gtk_container_set_focus_vadjustment (GTK_CONTAINER (table), @@ -3264,7 +3264,7 @@ create_list (void) list = gtk_list_new (); gtk_list_set_selection_mode (GTK_LIST (list), GTK_SELECTION_EXTENDED); - gtk_container_add (GTK_CONTAINER (scrolled_win), list); + gtk_scrolled_window_add_with_viewport (GTK_SCROLLED_WINDOW (scrolled_win), list); gtk_container_set_focus_vadjustment (GTK_CONTAINER (list), gtk_scrolled_window_get_vadjustment @@ -7245,7 +7245,7 @@ create_selection_test (void) gtk_widget_set_usize (scrolled_win, 100, 200); list = gtk_list_new (); - gtk_container_add (GTK_CONTAINER (scrolled_win), list); + gtk_scrolled_window_add_with_viewport (GTK_SCROLLED_WINDOW (scrolled_win), list); gtk_signal_connect (GTK_OBJECT(list), "selection_received", GTK_SIGNAL_FUNC (selection_test_received), NULL); @@ -8056,7 +8056,7 @@ create_main_window (void) box2 = gtk_vbox_new (FALSE, 0); gtk_container_border_width (GTK_CONTAINER (box2), 10); - gtk_container_add (GTK_CONTAINER (scrolled_window), box2); + gtk_scrolled_window_add_with_viewport (GTK_SCROLLED_WINDOW (scrolled_window), box2); gtk_container_set_focus_vadjustment (GTK_CONTAINER (box2), gtk_scrolled_window_get_vadjustment (GTK_SCROLLED_WINDOW (scrolled_window))); gtk_widget_show (box2);