diff options
author | Havoc Pennington <hp@redhat.com> | 2001-03-07 21:32:51 +0000 |
---|---|---|
committer | Havoc Pennington <hp@src.gnome.org> | 2001-03-07 21:32:51 +0000 |
commit | 29b902a4817e3a4caed166e698f1dda35c8b7ed9 (patch) | |
tree | aac23f9ef300d32726407c9c1a0eed2ff76dee17 | |
parent | 9d1e2a13231fd894a5b7a0ee5a95035af6f55745 (diff) | |
download | gtk+-29b902a4817e3a4caed166e698f1dda35c8b7ed9.tar.gz |
remove trailer (gtk_entry_set_property): remove trailer
2001-03-07 Havoc Pennington <hp@redhat.com>
* gtk/gtkentry.c (gtk_entry_get_property): remove trailer
(gtk_entry_set_property): remove trailer
* gtk/gtkentry.c (gtk_entry_set_width_chars):
(gtk_entry_get_width_chars): new functions, to set size request to
a given number of characters
* gtk/testgtk.c (create_dialog): beef up the dialog test slightly
* gtk/gtkdialog.c (gtk_dialog_set_has_separator): new function
(gtk_dialog_get_has_separator): new function
(run_delete_handler): fix to not emit "response" signal
because we already did in the delete event handler installed
at dialog creation time.
* gtk/gtkdialog.h: add a has_separator property,
add GTK_DIALOG_NO_SEPARATOR flag
-rw-r--r-- | ChangeLog | 20 | ||||
-rw-r--r-- | ChangeLog.pre-2-0 | 20 | ||||
-rw-r--r-- | ChangeLog.pre-2-10 | 20 | ||||
-rw-r--r-- | ChangeLog.pre-2-2 | 20 | ||||
-rw-r--r-- | ChangeLog.pre-2-4 | 20 | ||||
-rw-r--r-- | ChangeLog.pre-2-6 | 20 | ||||
-rw-r--r-- | ChangeLog.pre-2-8 | 20 | ||||
-rw-r--r-- | docs/reference/gtk/tmpl/gtkdialog.sgml | 6 | ||||
-rw-r--r-- | docs/reference/gtk/tmpl/gtkentry.sgml | 5 | ||||
-rw-r--r-- | gtk/gtkdialog.c | 133 | ||||
-rw-r--r-- | gtk/gtkdialog.h | 13 | ||||
-rw-r--r-- | gtk/gtkentry.c | 102 | ||||
-rw-r--r-- | gtk/gtkentry.h | 6 | ||||
-rw-r--r-- | gtk/gtkspinbutton.c | 13 | ||||
-rw-r--r-- | gtk/testgtk.c | 36 | ||||
-rw-r--r-- | tests/testgtk.c | 36 |
16 files changed, 451 insertions, 39 deletions
@@ -1,5 +1,25 @@ 2001-03-07 Havoc Pennington <hp@redhat.com> + * gtk/gtkentry.c (gtk_entry_get_property): remove trailer + (gtk_entry_set_property): remove trailer + + * gtk/gtkentry.c (gtk_entry_set_width_chars): + (gtk_entry_get_width_chars): new functions, to set size request to + a given number of characters + + * gtk/testgtk.c (create_dialog): beef up the dialog test slightly + + * gtk/gtkdialog.c (gtk_dialog_set_has_separator): new function + (gtk_dialog_get_has_separator): new function + (run_delete_handler): fix to not emit "response" signal + because we already did in the delete event handler installed + at dialog creation time. + + * gtk/gtkdialog.h: add a has_separator property, + add GTK_DIALOG_NO_SEPARATOR flag + +2001-03-07 Havoc Pennington <hp@redhat.com> + * gtk/gtkwindow.c (gtk_window_set_decorated): new function, turns off decorations for a window. diff --git a/ChangeLog.pre-2-0 b/ChangeLog.pre-2-0 index bed341a8f3..0c9654576b 100644 --- a/ChangeLog.pre-2-0 +++ b/ChangeLog.pre-2-0 @@ -1,5 +1,25 @@ 2001-03-07 Havoc Pennington <hp@redhat.com> + * gtk/gtkentry.c (gtk_entry_get_property): remove trailer + (gtk_entry_set_property): remove trailer + + * gtk/gtkentry.c (gtk_entry_set_width_chars): + (gtk_entry_get_width_chars): new functions, to set size request to + a given number of characters + + * gtk/testgtk.c (create_dialog): beef up the dialog test slightly + + * gtk/gtkdialog.c (gtk_dialog_set_has_separator): new function + (gtk_dialog_get_has_separator): new function + (run_delete_handler): fix to not emit "response" signal + because we already did in the delete event handler installed + at dialog creation time. + + * gtk/gtkdialog.h: add a has_separator property, + add GTK_DIALOG_NO_SEPARATOR flag + +2001-03-07 Havoc Pennington <hp@redhat.com> + * gtk/gtkwindow.c (gtk_window_set_decorated): new function, turns off decorations for a window. diff --git a/ChangeLog.pre-2-10 b/ChangeLog.pre-2-10 index bed341a8f3..0c9654576b 100644 --- a/ChangeLog.pre-2-10 +++ b/ChangeLog.pre-2-10 @@ -1,5 +1,25 @@ 2001-03-07 Havoc Pennington <hp@redhat.com> + * gtk/gtkentry.c (gtk_entry_get_property): remove trailer + (gtk_entry_set_property): remove trailer + + * gtk/gtkentry.c (gtk_entry_set_width_chars): + (gtk_entry_get_width_chars): new functions, to set size request to + a given number of characters + + * gtk/testgtk.c (create_dialog): beef up the dialog test slightly + + * gtk/gtkdialog.c (gtk_dialog_set_has_separator): new function + (gtk_dialog_get_has_separator): new function + (run_delete_handler): fix to not emit "response" signal + because we already did in the delete event handler installed + at dialog creation time. + + * gtk/gtkdialog.h: add a has_separator property, + add GTK_DIALOG_NO_SEPARATOR flag + +2001-03-07 Havoc Pennington <hp@redhat.com> + * gtk/gtkwindow.c (gtk_window_set_decorated): new function, turns off decorations for a window. diff --git a/ChangeLog.pre-2-2 b/ChangeLog.pre-2-2 index bed341a8f3..0c9654576b 100644 --- a/ChangeLog.pre-2-2 +++ b/ChangeLog.pre-2-2 @@ -1,5 +1,25 @@ 2001-03-07 Havoc Pennington <hp@redhat.com> + * gtk/gtkentry.c (gtk_entry_get_property): remove trailer + (gtk_entry_set_property): remove trailer + + * gtk/gtkentry.c (gtk_entry_set_width_chars): + (gtk_entry_get_width_chars): new functions, to set size request to + a given number of characters + + * gtk/testgtk.c (create_dialog): beef up the dialog test slightly + + * gtk/gtkdialog.c (gtk_dialog_set_has_separator): new function + (gtk_dialog_get_has_separator): new function + (run_delete_handler): fix to not emit "response" signal + because we already did in the delete event handler installed + at dialog creation time. + + * gtk/gtkdialog.h: add a has_separator property, + add GTK_DIALOG_NO_SEPARATOR flag + +2001-03-07 Havoc Pennington <hp@redhat.com> + * gtk/gtkwindow.c (gtk_window_set_decorated): new function, turns off decorations for a window. diff --git a/ChangeLog.pre-2-4 b/ChangeLog.pre-2-4 index bed341a8f3..0c9654576b 100644 --- a/ChangeLog.pre-2-4 +++ b/ChangeLog.pre-2-4 @@ -1,5 +1,25 @@ 2001-03-07 Havoc Pennington <hp@redhat.com> + * gtk/gtkentry.c (gtk_entry_get_property): remove trailer + (gtk_entry_set_property): remove trailer + + * gtk/gtkentry.c (gtk_entry_set_width_chars): + (gtk_entry_get_width_chars): new functions, to set size request to + a given number of characters + + * gtk/testgtk.c (create_dialog): beef up the dialog test slightly + + * gtk/gtkdialog.c (gtk_dialog_set_has_separator): new function + (gtk_dialog_get_has_separator): new function + (run_delete_handler): fix to not emit "response" signal + because we already did in the delete event handler installed + at dialog creation time. + + * gtk/gtkdialog.h: add a has_separator property, + add GTK_DIALOG_NO_SEPARATOR flag + +2001-03-07 Havoc Pennington <hp@redhat.com> + * gtk/gtkwindow.c (gtk_window_set_decorated): new function, turns off decorations for a window. diff --git a/ChangeLog.pre-2-6 b/ChangeLog.pre-2-6 index bed341a8f3..0c9654576b 100644 --- a/ChangeLog.pre-2-6 +++ b/ChangeLog.pre-2-6 @@ -1,5 +1,25 @@ 2001-03-07 Havoc Pennington <hp@redhat.com> + * gtk/gtkentry.c (gtk_entry_get_property): remove trailer + (gtk_entry_set_property): remove trailer + + * gtk/gtkentry.c (gtk_entry_set_width_chars): + (gtk_entry_get_width_chars): new functions, to set size request to + a given number of characters + + * gtk/testgtk.c (create_dialog): beef up the dialog test slightly + + * gtk/gtkdialog.c (gtk_dialog_set_has_separator): new function + (gtk_dialog_get_has_separator): new function + (run_delete_handler): fix to not emit "response" signal + because we already did in the delete event handler installed + at dialog creation time. + + * gtk/gtkdialog.h: add a has_separator property, + add GTK_DIALOG_NO_SEPARATOR flag + +2001-03-07 Havoc Pennington <hp@redhat.com> + * gtk/gtkwindow.c (gtk_window_set_decorated): new function, turns off decorations for a window. diff --git a/ChangeLog.pre-2-8 b/ChangeLog.pre-2-8 index bed341a8f3..0c9654576b 100644 --- a/ChangeLog.pre-2-8 +++ b/ChangeLog.pre-2-8 @@ -1,5 +1,25 @@ 2001-03-07 Havoc Pennington <hp@redhat.com> + * gtk/gtkentry.c (gtk_entry_get_property): remove trailer + (gtk_entry_set_property): remove trailer + + * gtk/gtkentry.c (gtk_entry_set_width_chars): + (gtk_entry_get_width_chars): new functions, to set size request to + a given number of characters + + * gtk/testgtk.c (create_dialog): beef up the dialog test slightly + + * gtk/gtkdialog.c (gtk_dialog_set_has_separator): new function + (gtk_dialog_get_has_separator): new function + (run_delete_handler): fix to not emit "response" signal + because we already did in the delete event handler installed + at dialog creation time. + + * gtk/gtkdialog.h: add a has_separator property, + add GTK_DIALOG_NO_SEPARATOR flag + +2001-03-07 Havoc Pennington <hp@redhat.com> + * gtk/gtkwindow.c (gtk_window_set_decorated): new function, turns off decorations for a window. diff --git a/docs/reference/gtk/tmpl/gtkdialog.sgml b/docs/reference/gtk/tmpl/gtkdialog.sgml index 65968c1bfa..f05199f418 100644 --- a/docs/reference/gtk/tmpl/gtkdialog.sgml +++ b/docs/reference/gtk/tmpl/gtkdialog.sgml @@ -144,6 +144,7 @@ gtk_window_set_title(). See the #GtkWindow section for more). @GTK_DIALOG_MODAL: @GTK_DIALOG_DESTROY_WITH_PARENT: +@GTK_DIALOG_NO_SEPARATOR: <!-- ##### ENUM GtkResponseType ##### --> <para> @@ -246,3 +247,8 @@ was clicked. @dialog: the object which received the signal. @arg1: the response ID +<!-- ##### ARG GtkDialog:has-separator ##### --> +<para> + +</para> + diff --git a/docs/reference/gtk/tmpl/gtkentry.sgml b/docs/reference/gtk/tmpl/gtkentry.sgml index f5d0720a0e..46aa77a6ec 100644 --- a/docs/reference/gtk/tmpl/gtkentry.sgml +++ b/docs/reference/gtk/tmpl/gtkentry.sgml @@ -300,3 +300,8 @@ are visible or not. See gtk_entry_set_visibility(). </para> +<!-- ##### ARG GtkEntry:width-chars ##### --> +<para> + +</para> + diff --git a/gtk/gtkdialog.c b/gtk/gtkdialog.c index ea47558750..edb2b3555a 100644 --- a/gtk/gtkdialog.c +++ b/gtk/gtkdialog.c @@ -32,6 +32,7 @@ #include "gtksignal.h" #include "gdkkeysyms.h" #include "gtkmain.h" +#include "gtkintl.h" static void gtk_dialog_class_init (GtkDialogClass *klass); static void gtk_dialog_init (GtkDialog *dialog); @@ -46,6 +47,19 @@ static gint gtk_dialog_delete_event_handler (GtkWidget *widget, GdkEventAny *event, gpointer user_data); +static void gtk_dialog_set_property (GObject *object, + guint prop_id, + const GValue *value, + GParamSpec *pspec); +static void gtk_dialog_get_property (GObject *object, + guint prop_id, + GValue *value, + GParamSpec *pspec); + +enum { + PROP_0, + PROP_HAS_SEPARATOR +}; enum { RESPONSE, @@ -83,16 +97,29 @@ gtk_dialog_get_type (void) static void gtk_dialog_class_init (GtkDialogClass *class) { + GObjectClass *gobject_class; GtkObjectClass *object_class; GtkWidgetClass *widget_class; - - object_class = (GtkObjectClass*) class; - widget_class = (GtkWidgetClass*) class; + + gobject_class = G_OBJECT_CLASS (class); + object_class = GTK_OBJECT_CLASS (class); + widget_class = GTK_WIDGET_CLASS (class); parent_class = g_type_class_peek_parent (class); + + gobject_class->set_property = gtk_dialog_set_property; + gobject_class->get_property = gtk_dialog_get_property; widget_class->key_press_event = gtk_dialog_key_press; + g_object_class_install_property (gobject_class, + PROP_HAS_SEPARATOR, + g_param_spec_boolean ("has_separator", + _("Has separator"), + _("The dialog has a separator bar above its buttons"), + TRUE, + G_PARAM_READWRITE)); + dialog_signals[RESPONSE] = gtk_signal_new ("response", GTK_RUN_LAST, @@ -106,8 +133,6 @@ gtk_dialog_class_init (GtkDialogClass *class) static void gtk_dialog_init (GtkDialog *dialog) { - GtkWidget *separator; - /* To avoid breaking old code that prevents destroy on delete event * by connecting a handler, we have to have the FIRST signal * connection on the dialog. @@ -136,14 +161,59 @@ gtk_dialog_init (GtkDialog *dialog) FALSE, TRUE, 0); gtk_widget_show (dialog->action_area); - separator = gtk_hseparator_new (); - gtk_box_pack_end (GTK_BOX (dialog->vbox), separator, FALSE, TRUE, 0); - gtk_widget_show (separator); + dialog->separator = gtk_hseparator_new (); + gtk_box_pack_end (GTK_BOX (dialog->vbox), dialog->separator, FALSE, TRUE, 0); + gtk_widget_show (dialog->separator); gtk_window_set_type_hint (GTK_WINDOW (dialog), GDK_WINDOW_TYPE_HINT_DIALOG); } + +static void +gtk_dialog_set_property (GObject *object, + guint prop_id, + const GValue *value, + GParamSpec *pspec) +{ + GtkDialog *dialog; + + dialog = GTK_DIALOG (object); + + switch (prop_id) + { + case PROP_HAS_SEPARATOR: + gtk_dialog_set_has_separator (dialog, g_value_get_boolean (value)); + break; + + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } +} + +static void +gtk_dialog_get_property (GObject *object, + guint prop_id, + GValue *value, + GParamSpec *pspec) +{ + GtkDialog *dialog; + + dialog = GTK_DIALOG (object); + + switch (prop_id) + { + case PROP_HAS_SEPARATOR: + g_value_set_boolean (value, dialog->separator != NULL); + break; + + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } +} + static gint gtk_dialog_delete_event_handler (GtkWidget *widget, GdkEventAny *event, @@ -172,7 +242,7 @@ gtk_dialog_key_press (GtkWidget *widget, if (key->keyval != GDK_Escape) return FALSE; - /* Synthesize delete_event on key press. */ + /* Synthesize delete_event to close dialog. */ g_object_ref (G_OBJECT (event.window)); gtk_main_do_event ((GdkEvent*)&event); @@ -209,6 +279,9 @@ gtk_dialog_new_empty (const gchar *title, if (flags & GTK_DIALOG_DESTROY_WITH_PARENT) gtk_window_set_destroy_with_parent (GTK_WINDOW (dialog), TRUE); + if (flags & GTK_DIALOG_NO_SEPARATOR) + gtk_dialog_set_has_separator (dialog, FALSE); + return GTK_WIDGET (dialog); } @@ -233,7 +306,7 @@ gtk_dialog_new_empty (const gchar *title, * enumeration. If the user clicks one of these dialog buttons, * #GtkDialog will emit the "response" signal with the corresponding * response ID. If a #GtkDialog receives the "delete_event" signal, it - * will emit "response" with a response ID of GTK_RESPONSE_NONE. + * will emit "response" with a response ID of GTK_RESPONSE_DELETE_EVENT. * However, destroying a dialog does not emit the "response" signal; * so be careful relying on "response" when using * the GTK_DIALOG_DESTROY_WITH_PARENT flag. Buttons are from left to right, @@ -544,6 +617,43 @@ gtk_dialog_set_default_response (GtkDialog *dialog, g_list_free (children); } +void +gtk_dialog_set_has_separator (GtkDialog *dialog, + gboolean setting) +{ + g_return_if_fail (GTK_IS_DIALOG (dialog)); + + /* this might fail if we get called before _init() somehow */ + g_assert (dialog->vbox != NULL); + + if (setting && dialog->separator == NULL) + { + dialog->separator = gtk_hseparator_new (); + gtk_box_pack_end (GTK_BOX (dialog->vbox), dialog->separator, FALSE, TRUE, 0); + + /* The app programmer could screw this up, but, their own fault. + * Moves the separator just above the action area. + */ + gtk_box_reorder_child (GTK_BOX (dialog->vbox), dialog->separator, 1); + gtk_widget_show (dialog->separator); + } + else if (!setting && dialog->separator != NULL) + { + gtk_widget_destroy (dialog->separator); + dialog->separator = NULL; + } + + g_object_notify (G_OBJECT (dialog), "has_separator"); +} + +gboolean +gtk_dialog_get_has_separator (GtkDialog *dialog) +{ + g_return_val_if_fail (GTK_IS_DIALOG (dialog), FALSE); + + return dialog->separator != NULL; +} + /** * gtk_dialog_response: * @dialog: a #GtkDialog @@ -610,9 +720,6 @@ run_delete_handler (GtkDialog *dialog, RunInfo *ri = data; shutdown_loop (ri); - - /* emit response signal */ - gtk_dialog_response (dialog, GTK_RESPONSE_NONE); return TRUE; /* Do not destroy */ } diff --git a/gtk/gtkdialog.h b/gtk/gtkdialog.h index fc0c178299..7bd8e975bf 100644 --- a/gtk/gtkdialog.h +++ b/gtk/gtkdialog.h @@ -39,9 +39,9 @@ extern "C" { /* Parameters for dialog construction */ typedef enum { - GTK_DIALOG_MODAL, /* call gtk_window_set_modal (win, TRUE) */ - GTK_DIALOG_DESTROY_WITH_PARENT /* call gtk_window_set_destroy_with_parent () */ - + GTK_DIALOG_MODAL, /* call gtk_window_set_modal (win, TRUE) */ + GTK_DIALOG_DESTROY_WITH_PARENT, /* call gtk_window_set_destroy_with_parent () */ + GTK_DIALOG_NO_SEPARATOR /* no separator bar above buttons */ } GtkDialogFlags; /* Convenience enum to use for response_id's. Positive values are @@ -99,6 +99,9 @@ struct _GtkDialog GtkWidget *vbox; GtkWidget *action_area; + + /*< private >*/ + GtkWidget *separator; }; struct _GtkDialogClass @@ -134,6 +137,10 @@ void gtk_dialog_set_response_sensitive (GtkDialog *dialog, void gtk_dialog_set_default_response (GtkDialog *dialog, gint response_id); +void gtk_dialog_set_has_separator (GtkDialog *dialog, + gboolean setting); +gboolean gtk_dialog_get_has_separator (GtkDialog *dialog); + /* Emit response signal */ void gtk_dialog_response (GtkDialog *dialog, gint response_id); diff --git a/gtk/gtkentry.c b/gtk/gtkentry.c index 78eb75c8c7..11cfb9bf49 100644 --- a/gtk/gtkentry.c +++ b/gtk/gtkentry.c @@ -75,7 +75,8 @@ enum { PROP_MAX_LENGTH, PROP_VISIBILITY, PROP_INVISIBLE_CHAR, - PROP_ACTIVATES_DEFAULT + PROP_ACTIVATES_DEFAULT, + PROP_WIDTH_CHARS }; static guint signals[LAST_SIGNAL] = { 0 }; @@ -101,13 +102,11 @@ static void gtk_entry_init (GtkEntry *entry); static void gtk_entry_set_property (GObject *object, guint prop_id, const GValue *value, - GParamSpec *pspec, - const gchar *trailer); + GParamSpec *pspec); static void gtk_entry_get_property (GObject *object, guint prop_id, GValue *value, - GParamSpec *pspec, - const gchar *trailer); + GParamSpec *pspec); static void gtk_entry_finalize (GObject *object); /* GtkWidget methods @@ -412,6 +411,16 @@ gtk_entry_class_init (GtkEntryClass *class) _("Whether to activate the default widget (such as the default button in a dialog) when Enter is pressed."), FALSE, G_PARAM_READABLE | G_PARAM_WRITABLE)); + g_object_class_install_property (gobject_class, + PROP_WIDTH_CHARS, + g_param_spec_int ("width_chars", + _("Width in chars"), + _("Number of characters to leave space for in the entry."), + -1, + G_MAXINT, + + -1, + G_PARAM_READABLE | G_PARAM_WRITABLE)); signals[INSERT_TEXT] = gtk_signal_new ("insert_text", @@ -648,11 +657,11 @@ gtk_entry_editable_init (GtkEditableClass *iface) iface->get_position = gtk_entry_get_position; } -static void gtk_entry_set_property (GObject *object, - guint prop_id, - const GValue *value, - GParamSpec *pspec, - const gchar *trailer) +static void +gtk_entry_set_property (GObject *object, + guint prop_id, + const GValue *value, + GParamSpec *pspec) { GtkEntry *entry = GTK_ENTRY (object); @@ -690,6 +699,10 @@ static void gtk_entry_set_property (GObject *object, case PROP_ACTIVATES_DEFAULT: gtk_entry_set_activates_default (entry, g_value_get_boolean (value)); break; + + case PROP_WIDTH_CHARS: + gtk_entry_set_width_chars (entry, g_value_get_int (value)); + break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); @@ -697,11 +710,11 @@ static void gtk_entry_set_property (GObject *object, } } -static void gtk_entry_get_property (GObject *object, - guint prop_id, - GValue *value, - GParamSpec *pspec, - const gchar *trailer) +static void +gtk_entry_get_property (GObject *object, + guint prop_id, + GValue *value, + GParamSpec *pspec) { GtkEntry *entry; @@ -727,6 +740,10 @@ static void gtk_entry_get_property (GObject *object, case PROP_ACTIVATES_DEFAULT: g_value_set_boolean (value, entry->activates_default); break; + case PROP_WIDTH_CHARS: + g_value_set_int (value, entry->width_chars); + break; + default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); break; @@ -746,7 +763,8 @@ gtk_entry_init (GtkEntry *entry) entry->visible = TRUE; entry->invisible_char = '*'; entry->dnd_position = -1; - + entry->width_chars = -1; + entry->has_frame = TRUE; gtk_drag_dest_set (GTK_WIDGET (entry), @@ -935,8 +953,16 @@ gtk_entry_size_request (GtkWidget *widget, xborder += 1; yborder += 1; } - - requisition->width = MIN_ENTRY_WIDTH + xborder * 2; + + if (entry->width_chars < 0) + requisition->width = MIN_ENTRY_WIDTH + xborder * 2; + else + { + requisition->width = + PANGO_PIXELS (metrics.approximate_char_width) * entry->width_chars + + xborder * 2; + } + requisition->height = ((metrics.ascent + metrics.descent) / PANGO_SCALE + yborder * 2); } @@ -2956,6 +2982,46 @@ gtk_entry_get_activates_default (GtkEntry *entry) } /** + * gtk_entry_set_width_chars: + * @entry: a #GtkEntry + * @n_chars: width in chars + * + * Changes the size request of the entry to be about the right size + * for @n_chars characters. Note that it changes the size + * <emphasize>request</emphasize>, the size can still be affected by + * how you pack the widget into containers. If @n_chars is -1, the + * size reverts to the default entry size. + * + **/ +void +gtk_entry_set_width_chars (GtkEntry *entry, + gint n_chars) +{ + g_return_if_fail (GTK_IS_ENTRY (entry)); + + if (entry->width_chars != n_chars) + { + entry->width_chars = n_chars; + g_object_notify (G_OBJECT (entry), "width_chars"); + gtk_widget_queue_resize (GTK_WIDGET (entry)); + } +} + +/** + * gtk_entry_get_width_chars: + * @entry: a #GtkEntry + * + * Gets the value set by gtk_entry_set_width_chars(). + * + * Return value: number of chars to request space for, or negative if unset + **/ +gint +gtk_entry_get_width_chars (GtkEntry *entry) +{ + return entry->width_chars; +} + +/** * gtk_entry_set_has_frame: * @entry: a #GtkEntry * @setting: new value diff --git a/gtk/gtkentry.h b/gtk/gtkentry.h index 45a5db38a2..5ba3df752f 100644 --- a/gtk/gtkentry.h +++ b/gtk/gtkentry.h @@ -99,6 +99,8 @@ struct _GtkEntry gint drag_start_y; gunichar invisible_char; + + gint width_chars; }; struct _GtkEntryClass @@ -152,6 +154,10 @@ void gtk_entry_set_activates_default (GtkEntry *entry, gboolean setting); gboolean gtk_entry_get_activates_default (GtkEntry *entry); +void gtk_entry_set_width_chars (GtkEntry *entry, + gint n_chars); +gint gtk_entry_get_width_chars (GtkEntry *entry); + /* Somewhat more convenient than the GtkEditable generic functions */ void gtk_entry_set_text (GtkEntry *entry, diff --git a/gtk/gtkspinbutton.c b/gtk/gtkspinbutton.c index 5e35c95741..c20642021c 100644 --- a/gtk/gtkspinbutton.c +++ b/gtk/gtkspinbutton.c @@ -482,14 +482,21 @@ static void gtk_spin_button_size_request (GtkWidget *widget, GtkRequisition *requisition) { + GtkEntry *entry; + g_return_if_fail (widget != NULL); g_return_if_fail (requisition != NULL); g_return_if_fail (GTK_IS_SPIN_BUTTON (widget)); - GTK_WIDGET_CLASS (parent_class)->size_request (widget, requisition); + entry = GTK_ENTRY (widget); - requisition->width = MIN_SPIN_BUTTON_WIDTH + ARROW_SIZE - + 2 * widget->style->xthickness; + GTK_WIDGET_CLASS (parent_class)->size_request (widget, requisition); + + if (entry->width_chars < 0) + requisition->width = MIN_SPIN_BUTTON_WIDTH + ARROW_SIZE + + 2 * widget->style->xthickness; + else + requisition->width += ARROW_SIZE + 2 * widget->style->xthickness; } static void diff --git a/gtk/testgtk.c b/gtk/testgtk.c index c4cada989a..646024a34d 100644 --- a/gtk/testgtk.c +++ b/gtk/testgtk.c @@ -6138,6 +6138,22 @@ label_toggle (GtkWidget *widget, gtk_widget_destroy (*label); } +#define RESPONSE_TOGGLE_SEPARATOR 1 + +static void +print_response (GtkWidget *dialog, + gint response_id, + gpointer data) +{ + g_print ("response signal received (%d)\n", response_id); + + if (response_id == RESPONSE_TOGGLE_SEPARATOR) + { + gtk_dialog_set_has_separator (GTK_DIALOG (dialog), + !gtk_dialog_get_has_separator (GTK_DIALOG (dialog))); + } +} + static void create_dialog (void) { @@ -6146,15 +6162,24 @@ create_dialog (void) if (!dialog_window) { + /* This is a terrible example; it's much simpler to create + * dialogs than this. Don't use testgtk for example code, + * use gtk-demo ;-) + */ + dialog_window = gtk_dialog_new (); + gtk_signal_connect (GTK_OBJECT (dialog_window), + "response", + GTK_SIGNAL_FUNC (print_response), + NULL); + gtk_signal_connect (GTK_OBJECT (dialog_window), "destroy", GTK_SIGNAL_FUNC(gtk_widget_destroyed), &dialog_window); gtk_window_set_title (GTK_WINDOW (dialog_window), "GtkDialog"); gtk_container_set_border_width (GTK_CONTAINER (dialog_window), 0); - gtk_widget_set_usize (dialog_window, 200, 110); button = gtk_button_new_with_label ("OK"); GTK_WIDGET_SET_FLAGS (button, GTK_CAN_DEFAULT); @@ -6173,6 +6198,15 @@ create_dialog (void) gtk_widget_show (button); label = NULL; + + button = gtk_button_new_with_label ("Separator"); + + GTK_WIDGET_SET_FLAGS (button, GTK_CAN_DEFAULT); + + gtk_dialog_add_action_widget (GTK_DIALOG (dialog_window), + button, + RESPONSE_TOGGLE_SEPARATOR); + gtk_widget_show (button); } if (!GTK_WIDGET_VISIBLE (dialog_window)) diff --git a/tests/testgtk.c b/tests/testgtk.c index c4cada989a..646024a34d 100644 --- a/tests/testgtk.c +++ b/tests/testgtk.c @@ -6138,6 +6138,22 @@ label_toggle (GtkWidget *widget, gtk_widget_destroy (*label); } +#define RESPONSE_TOGGLE_SEPARATOR 1 + +static void +print_response (GtkWidget *dialog, + gint response_id, + gpointer data) +{ + g_print ("response signal received (%d)\n", response_id); + + if (response_id == RESPONSE_TOGGLE_SEPARATOR) + { + gtk_dialog_set_has_separator (GTK_DIALOG (dialog), + !gtk_dialog_get_has_separator (GTK_DIALOG (dialog))); + } +} + static void create_dialog (void) { @@ -6146,15 +6162,24 @@ create_dialog (void) if (!dialog_window) { + /* This is a terrible example; it's much simpler to create + * dialogs than this. Don't use testgtk for example code, + * use gtk-demo ;-) + */ + dialog_window = gtk_dialog_new (); + gtk_signal_connect (GTK_OBJECT (dialog_window), + "response", + GTK_SIGNAL_FUNC (print_response), + NULL); + gtk_signal_connect (GTK_OBJECT (dialog_window), "destroy", GTK_SIGNAL_FUNC(gtk_widget_destroyed), &dialog_window); gtk_window_set_title (GTK_WINDOW (dialog_window), "GtkDialog"); gtk_container_set_border_width (GTK_CONTAINER (dialog_window), 0); - gtk_widget_set_usize (dialog_window, 200, 110); button = gtk_button_new_with_label ("OK"); GTK_WIDGET_SET_FLAGS (button, GTK_CAN_DEFAULT); @@ -6173,6 +6198,15 @@ create_dialog (void) gtk_widget_show (button); label = NULL; + + button = gtk_button_new_with_label ("Separator"); + + GTK_WIDGET_SET_FLAGS (button, GTK_CAN_DEFAULT); + + gtk_dialog_add_action_widget (GTK_DIALOG (dialog_window), + button, + RESPONSE_TOGGLE_SEPARATOR); + gtk_widget_show (button); } if (!GTK_WIDGET_VISIBLE (dialog_window)) |