/* OpenCOBOL GTK+ 2.0 wrapper experiments */ /* First up, a calendar widget */ /* Tectonics: gcc -c `pkg-config --cflags --libs gtk+-2.0` ocgtk.c */ #include #include /* user data for the calendar info, a little bit of it anyway */ typedef struct _calendar_data { guint year; guint month; guint day; } gtkcalendar_data; /*-- This function allows the program to exit properly when the window is closed --*/ gint destroyapp (GtkWidget *widget, gpointer gdata) { gtk_main_quit(); return (FALSE); } /* get the data and close the window on double click */ void calendar_day_selected_double_click(GtkCalendar *calendar, gtkcalendar_data *data) { gtk_calendar_get_date(calendar, &data->year, &data->month, &data->day); g_print("Y: %d M: %d D: %d\n", data->year, data->month + 1, data->day); gtk_main_quit(); } /* get the data on click */ void calendar_day_selected(GtkCalendar *calendar, gtkcalendar_data *data) { gtk_calendar_get_date(calendar, &data->year, &data->month, &data->day); g_print("Y: %d M: %d D: %d\n", data->year, data->month + 1, data->day); } /* Main GTK module for OpenCOBOL call */ int gtkcalendar() { /*-- Declare the GTK Widgets used in the program --*/ GtkWidget *window; GtkWidget *calendar; /* user data */ gtkcalendar_data calendar_data; /*-- Initialize GTK --*/ // gtk_init (&argc, &argv); gtk_init(0, NULL); /*-- Create the new widget --*/ calendar = gtk_calendar_new(); /*-- Create the new window --*/ window = gtk_window_new(GTK_WINDOW_TOPLEVEL); /* set the title */ gtk_window_set_title(GTK_WINDOW(window), "OpenCOBOL GTK Calendar"); /* get initial calendar values, although close will refetch current */ gtk_calendar_get_date(GTK_CALENDAR(calendar), &calendar_data.year, &calendar_data.month, &calendar_data.day); /*-- Connect the window to the destroyapp function --*/ gtk_signal_connect(GTK_OBJECT(window), "delete_event", GTK_SIGNAL_FUNC(destroyapp), NULL); /*-- Add the calendar to the window --*/ gtk_container_add(GTK_CONTAINER(window), calendar); /* connect the double click and click callbacks */ gtk_signal_connect(GTK_OBJECT(calendar), "day_selected_double_click", GTK_SIGNAL_FUNC(calendar_day_selected_double_click), &calendar_data); gtk_signal_connect(GTK_OBJECT(calendar), "day_selected", GTK_SIGNAL_FUNC(calendar_day_selected), &calendar_data); /*-- Display the widgets --*/ gtk_widget_show(calendar); gtk_widget_show(window); /*-- Start the GTK event loop --*/ gtk_main(); /*-- Return the yyyymmdd as an int --*/ return (int)calendar_data.year * 10000 + (calendar_data.month + 1) * 100 + calendar_data.day; }