exported gtk_spin_button_spin since it is used in testgtk, and besides

Tue Mar 17 03:56:13 1998  Tim Janik  <timj@gimp.org>

        * gtk/gtkspinbutton.h: exported gtk_spin_button_spin since it is
                used in testgtk, and besides that.

                        * gtk/testgtk.c: created a new "test" cursors, which showes different
                                types of GdkCursors and is a very simple example at using the drawing
                                        area.

                                        Tue Mar 17 03:56:13 1998  Tim Janik  <timj@gimp.org>

                                                * gtk/gtkspinbutton.h: exported gtk_spin_button_spin since it is
                                                        used in testgtk, and besides that.

                                                                * gtk/testgtk.c: created a new "test" cursors, which showes different
                                                                        types of GdkCursors and is a very simple example at using the drawing
                                                                                area.
This commit is contained in:
Tim Janik 1998-03-17 03:16:11 +00:00 committed by Tim Janik
parent 444c9529db
commit 077b5109a4
12 changed files with 473 additions and 38 deletions

View File

@ -1,3 +1,12 @@
Tue Mar 17 03:56:13 1998 Tim Janik <timj@gimp.org>
* gtk/gtkspinbutton.h: exported gtk_spin_button_spin since it is
used in testgtk, and besides that.
* gtk/testgtk.c: created a new "test" cursors, which showes different
types of GdkCursors and is a very simple example at using the drawing
area.
Mon Mar 16 18:19:31 GMT 1998 Tony Gale <gale@gimp.org> Mon Mar 16 18:19:31 GMT 1998 Tony Gale <gale@gimp.org>
* docs/gtkfaq.sgml: * docs/gtkfaq.sgml:
- new question on modal windows - new question on modal windows

View File

@ -1,3 +1,12 @@
Tue Mar 17 03:56:13 1998 Tim Janik <timj@gimp.org>
* gtk/gtkspinbutton.h: exported gtk_spin_button_spin since it is
used in testgtk, and besides that.
* gtk/testgtk.c: created a new "test" cursors, which showes different
types of GdkCursors and is a very simple example at using the drawing
area.
Mon Mar 16 18:19:31 GMT 1998 Tony Gale <gale@gimp.org> Mon Mar 16 18:19:31 GMT 1998 Tony Gale <gale@gimp.org>
* docs/gtkfaq.sgml: * docs/gtkfaq.sgml:
- new question on modal windows - new question on modal windows

View File

@ -1,3 +1,12 @@
Tue Mar 17 03:56:13 1998 Tim Janik <timj@gimp.org>
* gtk/gtkspinbutton.h: exported gtk_spin_button_spin since it is
used in testgtk, and besides that.
* gtk/testgtk.c: created a new "test" cursors, which showes different
types of GdkCursors and is a very simple example at using the drawing
area.
Mon Mar 16 18:19:31 GMT 1998 Tony Gale <gale@gimp.org> Mon Mar 16 18:19:31 GMT 1998 Tony Gale <gale@gimp.org>
* docs/gtkfaq.sgml: * docs/gtkfaq.sgml:
- new question on modal windows - new question on modal windows

View File

@ -1,3 +1,12 @@
Tue Mar 17 03:56:13 1998 Tim Janik <timj@gimp.org>
* gtk/gtkspinbutton.h: exported gtk_spin_button_spin since it is
used in testgtk, and besides that.
* gtk/testgtk.c: created a new "test" cursors, which showes different
types of GdkCursors and is a very simple example at using the drawing
area.
Mon Mar 16 18:19:31 GMT 1998 Tony Gale <gale@gimp.org> Mon Mar 16 18:19:31 GMT 1998 Tony Gale <gale@gimp.org>
* docs/gtkfaq.sgml: * docs/gtkfaq.sgml:
- new question on modal windows - new question on modal windows

View File

@ -1,3 +1,12 @@
Tue Mar 17 03:56:13 1998 Tim Janik <timj@gimp.org>
* gtk/gtkspinbutton.h: exported gtk_spin_button_spin since it is
used in testgtk, and besides that.
* gtk/testgtk.c: created a new "test" cursors, which showes different
types of GdkCursors and is a very simple example at using the drawing
area.
Mon Mar 16 18:19:31 GMT 1998 Tony Gale <gale@gimp.org> Mon Mar 16 18:19:31 GMT 1998 Tony Gale <gale@gimp.org>
* docs/gtkfaq.sgml: * docs/gtkfaq.sgml:
- new question on modal windows - new question on modal windows

View File

@ -1,3 +1,12 @@
Tue Mar 17 03:56:13 1998 Tim Janik <timj@gimp.org>
* gtk/gtkspinbutton.h: exported gtk_spin_button_spin since it is
used in testgtk, and besides that.
* gtk/testgtk.c: created a new "test" cursors, which showes different
types of GdkCursors and is a very simple example at using the drawing
area.
Mon Mar 16 18:19:31 GMT 1998 Tony Gale <gale@gimp.org> Mon Mar 16 18:19:31 GMT 1998 Tony Gale <gale@gimp.org>
* docs/gtkfaq.sgml: * docs/gtkfaq.sgml:
- new question on modal windows - new question on modal windows

View File

@ -1,3 +1,12 @@
Tue Mar 17 03:56:13 1998 Tim Janik <timj@gimp.org>
* gtk/gtkspinbutton.h: exported gtk_spin_button_spin since it is
used in testgtk, and besides that.
* gtk/testgtk.c: created a new "test" cursors, which showes different
types of GdkCursors and is a very simple example at using the drawing
area.
Mon Mar 16 18:19:31 GMT 1998 Tony Gale <gale@gimp.org> Mon Mar 16 18:19:31 GMT 1998 Tony Gale <gale@gimp.org>
* docs/gtkfaq.sgml: * docs/gtkfaq.sgml:
- new question on modal windows - new question on modal windows

View File

@ -312,6 +312,7 @@ gtk_container_add (GtkContainer *container,
g_return_if_fail (GTK_IS_CONTAINER (container)); g_return_if_fail (GTK_IS_CONTAINER (container));
g_return_if_fail (widget != NULL); g_return_if_fail (widget != NULL);
g_return_if_fail (GTK_IS_WIDGET (widget)); g_return_if_fail (GTK_IS_WIDGET (widget));
g_return_if_fail (widget->parent == NULL);
gtk_signal_emit (GTK_OBJECT (container), container_signals[ADD], widget); gtk_signal_emit (GTK_OBJECT (container), container_signals[ADD], widget);
} }

View File

@ -70,9 +70,6 @@ static gint gtk_spin_button_focus_out (GtkWidget *widget,
static void gtk_spin_button_draw_arrow (GtkSpinButton *spin_button, static void gtk_spin_button_draw_arrow (GtkSpinButton *spin_button,
guint arrow); guint arrow);
static gint gtk_spin_button_timer (GtkSpinButton *spin_button); static gint gtk_spin_button_timer (GtkSpinButton *spin_button);
static void gtk_spin_button_spin (GtkSpinButton *spin_button,
guint direction,
gfloat step);
static void gtk_spin_button_value_changed (GtkWidget *widget, static void gtk_spin_button_value_changed (GtkWidget *widget,
GtkSpinButton *spin_button); GtkSpinButton *spin_button);
static gint gtk_spin_button_key_press (GtkWidget *widget, static gint gtk_spin_button_key_press (GtkWidget *widget,
@ -756,7 +753,7 @@ gtk_spin_button_timer (GtkSpinButton *spin_button)
return FALSE; return FALSE;
} }
static void void
gtk_spin_button_spin (GtkSpinButton *spin_button, gtk_spin_button_spin (GtkSpinButton *spin_button,
guint direction, guint direction,
gfloat step) gfloat step)

View File

@ -79,48 +79,42 @@ struct _GtkSpinButtonClass
GtkEntryClass parent_class; GtkEntryClass parent_class;
}; };
guint guint gtk_spin_button_get_type (void);
gtk_spin_button_get_type (void);
void void gtk_spin_button_construct (GtkSpinButton *spin_button,
gtk_spin_button_construct (GtkSpinButton *spin_button, GtkAdjustment *adjustment,
GtkAdjustment *adjustment, gfloat climb_rate,
gfloat climb_rate, gint digits);
gint digits);
GtkWidget * GtkWidget* gtk_spin_button_new (GtkAdjustment *adjustment,
gtk_spin_button_new (GtkAdjustment *adjustment, gfloat climb_rate,
gfloat climb_rate, gint digits);
gint digits);
void void gtk_spin_button_set_adjustment (GtkSpinButton *spin_button,
gtk_spin_button_set_adjustment (GtkSpinButton *spin_button, GtkAdjustment *adjustment);
GtkAdjustment *adjustment);
GtkAdjustment * GtkAdjustment* gtk_spin_button_get_adjustment (GtkSpinButton *spin_button);
gtk_spin_button_get_adjustment (GtkSpinButton *spin_button);
void void gtk_spin_button_set_digits (GtkSpinButton *spin_button,
gtk_spin_button_set_digits (GtkSpinButton *spin_button, gint digits);
gint digits);
gfloat gfloat gtk_spin_button_get_value_as_float (GtkSpinButton *spin_button);
gtk_spin_button_get_value_as_float (GtkSpinButton *spin_button);
gint gint gtk_spin_button_get_value_as_int (GtkSpinButton *spin_button);
gtk_spin_button_get_value_as_int (GtkSpinButton *spin_button);
void void gtk_spin_button_set_value (GtkSpinButton *spin_button,
gtk_spin_button_set_value (GtkSpinButton *spin_button, gfloat value);
gfloat value);
void void gtk_spin_button_set_update_policy (GtkSpinButton *spin_button,
gtk_spin_button_set_update_policy (GtkSpinButton *spin_button, GtkSpinButtonUpdatePolicy policy);
GtkSpinButtonUpdatePolicy policy);
void void gtk_spin_button_set_numeric (GtkSpinButton *spin_button,
gtk_spin_button_set_numeric (GtkSpinButton *spin_button, gint numeric);
gint numeric);
void gtk_spin_button_spin (GtkSpinButton *spin_button,
guint direction,
gfloat step);
#ifdef __cplusplus #ifdef __cplusplus
} }

View File

@ -2421,6 +2421,196 @@ create_spins ()
gtk_widget_destroy (window); gtk_widget_destroy (window);
} }
/*
* Cursors
*/
static gint
cursor_expose_event (GtkWidget *widget,
GdkEvent *event,
gpointer user_data)
{
GtkDrawingArea *darea;
GdkDrawable *drawable;
GdkGC *black_gc;
GdkGC *gray_gc;
GdkGC *white_gc;
guint max_width;
guint max_height;
g_return_val_if_fail (widget != NULL, TRUE);
g_return_val_if_fail (GTK_IS_DRAWING_AREA (widget), TRUE);
darea = GTK_DRAWING_AREA (widget);
drawable = widget->window;
white_gc = widget->style->white_gc;
gray_gc = widget->style->bg_gc[GTK_STATE_NORMAL];
black_gc = widget->style->black_gc;
max_width = widget->allocation.width;
max_height = widget->allocation.height;
gdk_draw_rectangle (drawable, white_gc,
TRUE,
0,
0,
max_width,
max_height / 2);
gdk_draw_rectangle (drawable, black_gc,
TRUE,
0,
max_height / 2,
max_width,
max_height / 2);
gdk_draw_rectangle (drawable, gray_gc,
TRUE,
max_width / 3,
max_height / 3,
max_width / 3,
max_height / 3);
return TRUE;
}
static void
set_cursor (GtkWidget *spinner,
GtkWidget *widget)
{
guint c;
GdkCursor *cursor;
c = CLAMP (gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON (spinner)), 0, 152);
c &= 0xfe;
cursor = gdk_cursor_new (c);
gdk_window_set_cursor (widget->window, cursor);
gdk_cursor_destroy (cursor);
}
static gint
cursor_event (GtkWidget *widget,
GdkEvent *event,
GtkSpinButton *spinner)
{
if ((event->type == GDK_BUTTON_PRESS) &&
((event->button.button == 1) ||
(event->button.button == 3)))
{
gtk_spin_button_spin (spinner,
event->button.button == 1 ? GTK_ARROW_UP : GTK_ARROW_DOWN,
spinner->adjustment->step_increment);
return TRUE;
}
return FALSE;
}
static void
create_cursors ()
{
static GtkWidget *window = NULL;
GtkWidget *frame;
GtkWidget *hbox;
GtkWidget *main_vbox;
GtkWidget *vbox;
GtkWidget *darea;
GtkWidget *spinner;
GtkWidget *button;
GtkWidget *label;
GtkWidget *any;
GtkAdjustment *adj;
if (!window)
{
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
gtk_signal_connect (GTK_OBJECT (window), "destroy",
GTK_SIGNAL_FUNC (gtk_widget_destroyed),
&window);
gtk_window_set_title (GTK_WINDOW (window), "Cursors");
main_vbox = gtk_vbox_new (FALSE, 5);
gtk_container_border_width (GTK_CONTAINER (main_vbox), 0);
gtk_container_add (GTK_CONTAINER (window), main_vbox);
vbox =
gtk_widget_new (gtk_vbox_get_type (),
"GtkBox::homogeneous", FALSE,
"GtkBox::spacing", 5,
"GtkContainer::border_width", 10,
"GtkWidget::parent", main_vbox,
"GtkWidget::visible", TRUE,
NULL);
hbox = gtk_hbox_new (FALSE, 0);
gtk_container_border_width (GTK_CONTAINER (hbox), 5);
gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, TRUE, 0);
label = gtk_label_new ("Cursor Value:");
gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, TRUE, 0);
adj = (GtkAdjustment *) gtk_adjustment_new (0,
0, 152,
2,
10, 0);
spinner = gtk_spin_button_new (adj, 0, 0);
gtk_box_pack_start (GTK_BOX (hbox), spinner, TRUE, TRUE, 0);
frame =
gtk_widget_new (gtk_frame_get_type (),
"GtkFrame::shadow", GTK_SHADOW_ETCHED_IN,
"GtkFrame::label_xalign", 0.5,
"GtkFrame::label", "Cursor Area",
"GtkContainer::border_width", 10,
"GtkWidget::parent", vbox,
"GtkWidget::visible", TRUE,
NULL);
darea = gtk_drawing_area_new ();
gtk_widget_set_usize (darea, 80, 80);
gtk_container_add (GTK_CONTAINER (frame), darea);
gtk_signal_connect (GTK_OBJECT (darea),
"expose_event",
GTK_SIGNAL_FUNC (cursor_expose_event),
NULL);
gtk_widget_set_events (darea, GDK_EXPOSURE_MASK | GDK_BUTTON_PRESS_MASK);
gtk_signal_connect (GTK_OBJECT (darea),
"button_press_event",
GTK_SIGNAL_FUNC (cursor_event),
spinner);
gtk_widget_show (darea);
gtk_signal_connect (GTK_OBJECT (spinner), "changed",
GTK_SIGNAL_FUNC (set_cursor),
darea);
any =
gtk_widget_new (gtk_hseparator_get_type (),
"GtkWidget::visible", TRUE,
NULL);
gtk_box_pack_start (GTK_BOX (main_vbox), any, FALSE, TRUE, 0);
hbox = gtk_hbox_new (FALSE, 0);
gtk_container_border_width (GTK_CONTAINER (hbox), 10);
gtk_box_pack_start (GTK_BOX (main_vbox), hbox, FALSE, TRUE, 0);
button = gtk_button_new_with_label ("Close");
gtk_signal_connect_object (GTK_OBJECT (button), "clicked",
GTK_SIGNAL_FUNC (gtk_widget_destroy),
GTK_OBJECT (window));
gtk_box_pack_start (GTK_BOX (hbox), button, TRUE, TRUE, 5);
}
if (!GTK_WIDGET_VISIBLE (window))
gtk_widget_show_all (window);
else
gtk_widget_destroy (window);
}
/* /*
* GtkList * GtkList
*/ */
@ -5309,7 +5499,7 @@ create_main_window ()
{ "tooltips", create_tooltips }, { "tooltips", create_tooltips },
{ "menus", create_menus }, { "menus", create_menus },
{ "scrolled windows", create_scrolled_windows }, { "scrolled windows", create_scrolled_windows },
{ "drawing areas", NULL }, { "cursors", create_cursors },
{ "entry", create_entry }, { "entry", create_entry },
{ "spinbutton", create_spins }, { "spinbutton", create_spins },
{ "list", create_list }, { "list", create_list },

View File

@ -2421,6 +2421,196 @@ create_spins ()
gtk_widget_destroy (window); gtk_widget_destroy (window);
} }
/*
* Cursors
*/
static gint
cursor_expose_event (GtkWidget *widget,
GdkEvent *event,
gpointer user_data)
{
GtkDrawingArea *darea;
GdkDrawable *drawable;
GdkGC *black_gc;
GdkGC *gray_gc;
GdkGC *white_gc;
guint max_width;
guint max_height;
g_return_val_if_fail (widget != NULL, TRUE);
g_return_val_if_fail (GTK_IS_DRAWING_AREA (widget), TRUE);
darea = GTK_DRAWING_AREA (widget);
drawable = widget->window;
white_gc = widget->style->white_gc;
gray_gc = widget->style->bg_gc[GTK_STATE_NORMAL];
black_gc = widget->style->black_gc;
max_width = widget->allocation.width;
max_height = widget->allocation.height;
gdk_draw_rectangle (drawable, white_gc,
TRUE,
0,
0,
max_width,
max_height / 2);
gdk_draw_rectangle (drawable, black_gc,
TRUE,
0,
max_height / 2,
max_width,
max_height / 2);
gdk_draw_rectangle (drawable, gray_gc,
TRUE,
max_width / 3,
max_height / 3,
max_width / 3,
max_height / 3);
return TRUE;
}
static void
set_cursor (GtkWidget *spinner,
GtkWidget *widget)
{
guint c;
GdkCursor *cursor;
c = CLAMP (gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON (spinner)), 0, 152);
c &= 0xfe;
cursor = gdk_cursor_new (c);
gdk_window_set_cursor (widget->window, cursor);
gdk_cursor_destroy (cursor);
}
static gint
cursor_event (GtkWidget *widget,
GdkEvent *event,
GtkSpinButton *spinner)
{
if ((event->type == GDK_BUTTON_PRESS) &&
((event->button.button == 1) ||
(event->button.button == 3)))
{
gtk_spin_button_spin (spinner,
event->button.button == 1 ? GTK_ARROW_UP : GTK_ARROW_DOWN,
spinner->adjustment->step_increment);
return TRUE;
}
return FALSE;
}
static void
create_cursors ()
{
static GtkWidget *window = NULL;
GtkWidget *frame;
GtkWidget *hbox;
GtkWidget *main_vbox;
GtkWidget *vbox;
GtkWidget *darea;
GtkWidget *spinner;
GtkWidget *button;
GtkWidget *label;
GtkWidget *any;
GtkAdjustment *adj;
if (!window)
{
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
gtk_signal_connect (GTK_OBJECT (window), "destroy",
GTK_SIGNAL_FUNC (gtk_widget_destroyed),
&window);
gtk_window_set_title (GTK_WINDOW (window), "Cursors");
main_vbox = gtk_vbox_new (FALSE, 5);
gtk_container_border_width (GTK_CONTAINER (main_vbox), 0);
gtk_container_add (GTK_CONTAINER (window), main_vbox);
vbox =
gtk_widget_new (gtk_vbox_get_type (),
"GtkBox::homogeneous", FALSE,
"GtkBox::spacing", 5,
"GtkContainer::border_width", 10,
"GtkWidget::parent", main_vbox,
"GtkWidget::visible", TRUE,
NULL);
hbox = gtk_hbox_new (FALSE, 0);
gtk_container_border_width (GTK_CONTAINER (hbox), 5);
gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, TRUE, 0);
label = gtk_label_new ("Cursor Value:");
gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, TRUE, 0);
adj = (GtkAdjustment *) gtk_adjustment_new (0,
0, 152,
2,
10, 0);
spinner = gtk_spin_button_new (adj, 0, 0);
gtk_box_pack_start (GTK_BOX (hbox), spinner, TRUE, TRUE, 0);
frame =
gtk_widget_new (gtk_frame_get_type (),
"GtkFrame::shadow", GTK_SHADOW_ETCHED_IN,
"GtkFrame::label_xalign", 0.5,
"GtkFrame::label", "Cursor Area",
"GtkContainer::border_width", 10,
"GtkWidget::parent", vbox,
"GtkWidget::visible", TRUE,
NULL);
darea = gtk_drawing_area_new ();
gtk_widget_set_usize (darea, 80, 80);
gtk_container_add (GTK_CONTAINER (frame), darea);
gtk_signal_connect (GTK_OBJECT (darea),
"expose_event",
GTK_SIGNAL_FUNC (cursor_expose_event),
NULL);
gtk_widget_set_events (darea, GDK_EXPOSURE_MASK | GDK_BUTTON_PRESS_MASK);
gtk_signal_connect (GTK_OBJECT (darea),
"button_press_event",
GTK_SIGNAL_FUNC (cursor_event),
spinner);
gtk_widget_show (darea);
gtk_signal_connect (GTK_OBJECT (spinner), "changed",
GTK_SIGNAL_FUNC (set_cursor),
darea);
any =
gtk_widget_new (gtk_hseparator_get_type (),
"GtkWidget::visible", TRUE,
NULL);
gtk_box_pack_start (GTK_BOX (main_vbox), any, FALSE, TRUE, 0);
hbox = gtk_hbox_new (FALSE, 0);
gtk_container_border_width (GTK_CONTAINER (hbox), 10);
gtk_box_pack_start (GTK_BOX (main_vbox), hbox, FALSE, TRUE, 0);
button = gtk_button_new_with_label ("Close");
gtk_signal_connect_object (GTK_OBJECT (button), "clicked",
GTK_SIGNAL_FUNC (gtk_widget_destroy),
GTK_OBJECT (window));
gtk_box_pack_start (GTK_BOX (hbox), button, TRUE, TRUE, 5);
}
if (!GTK_WIDGET_VISIBLE (window))
gtk_widget_show_all (window);
else
gtk_widget_destroy (window);
}
/* /*
* GtkList * GtkList
*/ */
@ -5309,7 +5499,7 @@ create_main_window ()
{ "tooltips", create_tooltips }, { "tooltips", create_tooltips },
{ "menus", create_menus }, { "menus", create_menus },
{ "scrolled windows", create_scrolled_windows }, { "scrolled windows", create_scrolled_windows },
{ "drawing areas", NULL }, { "cursors", create_cursors },
{ "entry", create_entry }, { "entry", create_entry },
{ "spinbutton", create_spins }, { "spinbutton", create_spins },
{ "list", create_list }, { "list", create_list },