#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <sys/stat.h>
#include <math.h>
#include <time.h>
+#include <unistd.h>
#include "gtk.h"
-#include "../gdk/gdk.h"
-#include "../gdk/gdkx.h"
-#include "../gdk/gdkkeysyms.h"
+#include "gdk/gdk.h"
+#include "gdk/gdkkeysyms.h"
+#include "gdkx.h"
#include "circles.xbm"
gtk_toolbar_set_style (GTK_TOOLBAR (data), GTK_TOOLBAR_BOTH);
}
+static void
+set_toolbar_both_horiz (GtkWidget *widget,
+ gpointer data)
+{
+ gtk_toolbar_set_style (GTK_TOOLBAR (data), GTK_TOOLBAR_BOTH_HORIZ);
+}
+
static void
set_toolbar_small_space (GtkWidget *widget,
gpointer data)
"Both", "Show toolbar icons and text", "Toolbar/Both",
new_pixmap ("test.xpm", window->window, &window->style->bg[GTK_STATE_NORMAL]),
(GtkSignalFunc) set_toolbar_both, toolbar);
-
+ gtk_toolbar_append_item (GTK_TOOLBAR (toolbar),
+ "Both (horizontal)",
+ "Show toolbar icons and text in a horizontal fashion",
+ "Toolbar/BothHoriz",
+ new_pixmap ("test.xpm", window->window, &window->style->bg[GTK_STATE_NORMAL]),
+ (GtkSignalFunc) set_toolbar_both_horiz, toolbar);
+
gtk_toolbar_append_space (GTK_TOOLBAR (toolbar));
entry = gtk_entry_new ();
gtk_window_set_policy (GTK_WINDOW (window),
TRUE,
TRUE,
- FALSE);
+ TRUE);
gtk_signal_connect (GTK_OBJECT (window), "destroy",
GTK_SIGNAL_FUNC(gtk_widget_destroyed),
{ "/_Preferences", NULL, 0, 0, "<Branch>" },
{ "/_Preferences/_Color", NULL, 0, 0, "<Branch>" },
{ "/_Preferences/Color/_Red", NULL, gtk_ifactory_cb, 0, "<RadioItem>" },
- { "/_Preferences/Color/_Green", NULL, gtk_ifactory_cb, 0, "<RadioItem>" },
- { "/_Preferences/Color/_Blue", NULL, gtk_ifactory_cb, 0, "<RadioItem>" },
+ { "/_Preferences/Color/_Green", NULL, gtk_ifactory_cb, 0, "/Preferences/Color/Red" },
+ { "/_Preferences/Color/_Blue", NULL, gtk_ifactory_cb, 0, "/Preferences/Color/Red" },
{ "/_Preferences/_Shape", NULL, 0, 0, "<Branch>" },
{ "/_Preferences/Shape/_Square", NULL, gtk_ifactory_cb, 0, "<RadioItem>" },
- { "/_Preferences/Shape/_Rectangle", NULL, gtk_ifactory_cb, 0, "<RadioItem>" },
- { "/_Preferences/Shape/_Oval", NULL, gtk_ifactory_cb, 0, "<RadioItem>" },
+ { "/_Preferences/Shape/_Rectangle", NULL, gtk_ifactory_cb, 0, "/Preferences/Shape/Square" },
+ { "/_Preferences/Shape/_Oval", NULL, gtk_ifactory_cb, 0, "/Preferences/Shape/Rectangle" },
{ "/_Help", NULL, 0, 0, "<LastBranch>" },
{ "/Help/_About", NULL, gtk_ifactory_cb, 0 },
accel_group = gtk_accel_group_new ();
item_factory = gtk_item_factory_new (GTK_TYPE_MENU_BAR, "<main>", accel_group);
- gtk_item_factory_create_items (item_factory, nmenu_items, menu_items, NULL);
+ gtk_object_set_data_full (GTK_OBJECT (window),
+ "<main>",
+ item_factory,
+ (GtkDestroyNotify) gtk_object_unref);
gtk_accel_group_attach (accel_group, GTK_OBJECT (window));
gtk_window_set_title (GTK_WINDOW (window), "Item Factory");
gtk_container_set_border_width (GTK_CONTAINER (window), 0);
-
+ gtk_item_factory_create_items (item_factory, nmenu_items, menu_items, NULL);
+
+ /* preselect /Preferences/Shape/Oval over the other radios
+ */
+ gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (gtk_item_factory_get_item (item_factory,
+ "/Preferences/Shape/Oval")),
+ TRUE);
+
box1 = gtk_vbox_new (FALSE, 0);
gtk_container_add (GTK_CONTAINER (window), box1);
gtk_label_set_text (label, buf);
}
+static gint
+spin_button_time_output_func (GtkSpinButton *spin_button)
+{
+ static gchar buf[6];
+ gfloat hours;
+ gfloat minutes;
+
+ hours = spin_button->adjustment->value / 60.0;
+ minutes = (fabs(floor (hours) - hours) < 1e-5) ? 0.0 : 30;
+ sprintf (buf, "%02.0f:%02.0f", floor (hours), minutes);
+ if (strcmp (buf, gtk_entry_get_text (GTK_ENTRY (spin_button))))
+ gtk_entry_set_text (GTK_ENTRY (spin_button), buf);
+ return TRUE;
+}
+
+static gint
+spin_button_month_input_func (GtkSpinButton *spin_button,
+ gfloat *new_val)
+{
+ gint i;
+ static gchar *month[12] = { "January", "February", "March", "April",
+ "May", "June", "July", "August",
+ "September", "October", "November", "December" };
+ gchar *tmp1, *tmp2;
+ gboolean found = FALSE;
+
+ for (i = 1; i <= 12; i++)
+ {
+ tmp1 = g_strdup (month[i-1]);
+ g_strup (tmp1);
+ tmp2 = g_strdup (gtk_entry_get_text (GTK_ENTRY (spin_button)));
+ g_strup (tmp2);
+ if (strstr (tmp1, tmp2) == tmp1)
+ found = TRUE;
+ g_free (tmp1);
+ g_free (tmp2);
+ if (found)
+ break;
+ }
+ if (!found)
+ {
+ *new_val = 0.0;
+ return INPUT_ERROR;
+ }
+ *new_val = (gfloat) i;
+ return TRUE;
+}
+
+static gint
+spin_button_month_output_func (GtkSpinButton *spin_button)
+{
+ gint i;
+ static gchar *month[12] = { "January", "February", "March", "April",
+ "May", "June", "July", "August", "September",
+ "October", "November", "December" };
+
+ for (i = 1; i <= 12; i++)
+ if (fabs (spin_button->adjustment->value - (double)i) < 1e-5)
+ {
+ if (strcmp (month[i-1], gtk_entry_get_text (GTK_ENTRY (spin_button))))
+ gtk_entry_set_text (GTK_ENTRY (spin_button), month[i-1]);
+ }
+ return TRUE;
+}
+
+static gint
+spin_button_hex_input_func (GtkSpinButton *spin_button,
+ gfloat *new_val)
+{
+ gchar *buf;
+ gchar *err;
+ gfloat res;
+
+ buf = gtk_entry_get_text (GTK_ENTRY (spin_button));
+ res = (gfloat)(strtol(buf, &err, 16));
+ *new_val = res;
+ if (*err)
+ return INPUT_ERROR;
+ else
+ return TRUE;
+}
+
+static gint
+spin_button_hex_output_func (GtkSpinButton *spin_button)
+{
+ static gchar buf[7];
+ gint val;
+
+ val = (gint) spin_button->adjustment->value;
+ if (fabs (val) < 1e-5)
+ sprintf (buf, "0x00");
+ else
+ sprintf (buf, "0x%.2X", val);
+ if (strcmp (buf, gtk_entry_get_text (GTK_ENTRY (spin_button))))
+ gtk_entry_set_text (GTK_ENTRY (spin_button), buf);
+ return TRUE;
+}
+
static void
create_spins (void)
{
gtk_container_set_border_width (GTK_CONTAINER (vbox), 5);
gtk_container_add (GTK_CONTAINER (frame), vbox);
- /* Day, month, year spinners */
+ /* Time, month, hex spinners */
hbox = gtk_hbox_new (FALSE, 0);
gtk_box_pack_start (GTK_BOX (vbox), hbox, TRUE, TRUE, 5);
vbox2 = gtk_vbox_new (FALSE, 0);
gtk_box_pack_start (GTK_BOX (hbox), vbox2, TRUE, TRUE, 5);
- label = gtk_label_new ("Day :");
+ label = gtk_label_new ("Time :");
gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
gtk_box_pack_start (GTK_BOX (vbox2), label, FALSE, TRUE, 0);
- adj = (GtkAdjustment *) gtk_adjustment_new (1.0, 1.0, 31.0, 1.0,
- 5.0, 0.0);
+ adj = (GtkAdjustment *) gtk_adjustment_new (0, 0, 1410, 30, 60, 0);
spinner = gtk_spin_button_new (adj, 0, 0);
+ gtk_editable_set_editable (GTK_EDITABLE (spinner), FALSE);
+ gtk_signal_connect (GTK_OBJECT (spinner),
+ "output",
+ GTK_SIGNAL_FUNC (spin_button_time_output_func),
+ NULL);
gtk_spin_button_set_wrap (GTK_SPIN_BUTTON (spinner), TRUE);
- gtk_spin_button_set_shadow_type (GTK_SPIN_BUTTON (spinner),
- GTK_SHADOW_OUT);
+ gtk_widget_set_usize (spinner, 55, -1);
gtk_box_pack_start (GTK_BOX (vbox2), spinner, FALSE, TRUE, 0);
vbox2 = gtk_vbox_new (FALSE, 0);
adj = (GtkAdjustment *) gtk_adjustment_new (1.0, 1.0, 12.0, 1.0,
5.0, 0.0);
spinner = gtk_spin_button_new (adj, 0, 0);
+ gtk_spin_button_set_update_policy (GTK_SPIN_BUTTON (spinner),
+ GTK_UPDATE_IF_VALID);
+ gtk_signal_connect (GTK_OBJECT (spinner),
+ "input",
+ GTK_SIGNAL_FUNC (spin_button_month_input_func),
+ NULL);
+ gtk_signal_connect (GTK_OBJECT (spinner),
+ "output",
+ GTK_SIGNAL_FUNC (spin_button_month_output_func),
+ NULL);
gtk_spin_button_set_wrap (GTK_SPIN_BUTTON (spinner), TRUE);
- gtk_spin_button_set_shadow_type (GTK_SPIN_BUTTON (spinner),
- GTK_SHADOW_ETCHED_IN);
+ gtk_widget_set_usize (spinner, 85, -1);
gtk_box_pack_start (GTK_BOX (vbox2), spinner, FALSE, TRUE, 0);
vbox2 = gtk_vbox_new (FALSE, 0);
gtk_box_pack_start (GTK_BOX (hbox), vbox2, TRUE, TRUE, 5);
- label = gtk_label_new ("Year :");
+ label = gtk_label_new ("Hex :");
gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
gtk_box_pack_start (GTK_BOX (vbox2), label, FALSE, TRUE, 0);
- adj = (GtkAdjustment *) gtk_adjustment_new (1998.0, 0.0, 2100.0,
- 1.0, 100.0, 0.0);
+ adj = (GtkAdjustment *) gtk_adjustment_new (0, 0, 255, 1, 16, 0);
spinner = gtk_spin_button_new (adj, 0, 0);
+ gtk_editable_set_editable (GTK_EDITABLE (spinner), TRUE);
+ gtk_signal_connect (GTK_OBJECT (spinner),
+ "input",
+ GTK_SIGNAL_FUNC (spin_button_hex_input_func),
+ NULL);
+ gtk_signal_connect (GTK_OBJECT (spinner),
+ "output",
+ GTK_SIGNAL_FUNC (spin_button_hex_output_func),
+ NULL);
gtk_spin_button_set_wrap (GTK_SPIN_BUTTON (spinner), TRUE);
- gtk_spin_button_set_shadow_type (GTK_SPIN_BUTTON (spinner),
- GTK_SHADOW_IN);
gtk_widget_set_usize (spinner, 55, 0);
gtk_box_pack_start (GTK_BOX (vbox2), spinner, FALSE, TRUE, 0);
adj = (GtkAdjustment *) gtk_adjustment_new (2, 1, 5, 1, 1, 0);
spinner2 = gtk_spin_button_new (adj, 0.0, 0);
- gtk_spin_button_set_wrap (GTK_SPIN_BUTTON (spinner2), TRUE);
gtk_signal_connect (GTK_OBJECT (adj), "value_changed",
GTK_SIGNAL_FUNC (change_digits),
(gpointer) spinner2);
gtk_widget_destroy (window);
}
+
/*
* Cursors
*/
GtkWidget *check;
GtkAdjustment *adj;
GtkWidget *spinner;
- GdkColor transparent;
+ GdkColor transparent = { 0 };
char *title[] = { "Tree" , "Info" };
char buf[80];
font_selection_ok (GtkWidget *w,
GtkFontSelectionDialog *fs)
{
- g_print ("%s\n", gtk_font_selection_dialog_get_font_name (fs));
+ gchar *s = gtk_font_selection_dialog_get_font_name (fs);
+
+ g_print ("%s\n", s);
+ g_free (s);
gtk_widget_destroy (GTK_WIDGET (fs));
}
* Shaped Windows
*/
-static GdkWindow *root_win = NULL;
-
typedef struct _cursoroffset {gint x,y;} CursorOffset;
static void
* Can't use event->x / event->y here
* because I need absolute coordinates.
*/
- gdk_window_get_pointer (root_win, &xp, &yp, &mask);
+ gdk_window_get_pointer (NULL, &xp, &yp, &mask);
gtk_widget_set_uposition (widget, xp - p->x, yp - p->y);
}
static GtkWidget *sheets = NULL;
static GtkWidget *rings = NULL;
- root_win = gdk_window_foreign_new (GDK_ROOT_WINDOW ());
-
if (!modeller)
{
modeller = shape_create_icon ("Modeller.xpm",
* Idle Test
*/
-static int idle = 0;
+static int idle_id = 0;
static gint
idle_test (GtkWidget *label)
start_idle_test (GtkWidget *widget,
GtkWidget *label)
{
- if (!idle)
+ if (!idle_id)
{
- idle = gtk_idle_add ((GtkFunction) idle_test, label);
+ idle_id = gtk_idle_add ((GtkFunction) idle_test, label);
}
}
stop_idle_test (GtkWidget *widget,
gpointer data)
{
- if (idle)
+ if (idle_id)
{
- gtk_idle_remove (idle);
- idle = 0;
+ gtk_idle_remove (idle_id);
+ idle_id = 0;
}
}
main (int argc, char *argv[])
{
GtkBindingSet *binding_set;
+ struct stat statbuf;
srand (time (NULL));
gtk_set_locale ();
+ /* Check to see if we are being run from the correct
+ * directory.
+ */
+ if (stat("./testgtkrc", &statbuf) < 0)
+ {
+ fprintf (stderr, "*** The testgtk program must be run from within the\n"
+ "*** gtk/ subdirectory of the GTK+ distribution.\n");
+ exit (1);
+ }
+
gtk_rc_add_default_file ("testgtkrc");
gtk_init (&argc, &argv);