Hey, I had no clue which list to post this to. I made a quick and dirty alternative to GtkCalendar that due to screen area usage fits more nicely into a program I'm working on (I'm porting a console program to GTK). I decided to post the widget to this list just to see what kind of response it gets. I may be writing more widgets and would like to keep them consistent with the GTK style. I don't know if I should refrain from using gtk_* as functions and names. I wouldn't want to interfere with potential future widgets. One more thing, is there currently a listing of third party widgets or possibly a place to download third party widgets? If not, I am willing to compile a list and pointers to websites of third party widgets if people e-mail me the site of the widget and what license the widgets are under. I'm attaching this as 3 files because gmail for some reason is not letting me send over tar.gz files. sorry -- Irtza Sharif
/* GtkDate
* By Irtza Sharif
*
* LGPL stuff taken from code
* Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free
* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include "gtkdate.h"
#include <gtk/gtklabel.h>
#include <gtk/gtkvbox.h>
static GtkWidgetClass *parent_class = NULL;
static void
gtk_date_class_init (GtkDateClass *class)
{
parent_class = gtk_type_class (gtk_hbox_get_type ());
}
static void
gtk_date_init(GtkDate *date)
{
date->day = NULL;
date->month = NULL;
date->year = NULL;
}
void
gtk_date_month_changed_handler(GtkDate *date) {
gint month = gtk_combo_box_get_active(date->month);
gint max_day;
switch (month) {
case 3:
case 5:
case 8:
case 10:
max_day = 30;
break;
case 1:
max_day = 28;
break;
default:
max_day = 31;
}
gtk_spin_button_set_range(date->day, 1, max_day);
}
GType
gtk_date_get_type ()
{
static GType date_type = 0;
if (!date_type)
{
static GTypeInfo date_info =
{
sizeof (GtkDateClass),
NULL,
NULL,
(GClassInitFunc) gtk_date_class_init,
NULL,
NULL,
sizeof (GtkDate),
0,
(GInstanceInitFunc) gtk_date_init,
};
date_type = g_type_register_static (gtk_hbox_get_type (), "GtkDate", &date_info, 0);
//date_type = g_type_register_static(gtk_hbox_get_type(), "GtkDate", &date_info);
}
return date_type;
}
GtkWidget *gtk_date_new()
{
GtkDate *date;
GtkVBox *vbox;
GtkLabel *label;
GtkHBox *hbox;
date = gtk_type_new(gtk_date_get_type());
hbox = GTK_HBOX(date);
date->day = GTK_SPIN_BUTTON(gtk_spin_button_new_with_range(1, 31, 1));
date->year = GTK_SPIN_BUTTON(gtk_spin_button_new_with_range(1000, 9999, 1));
date->month = GTK_COMBO_BOX(gtk_combo_box_new_text());
gtk_combo_box_append_text(date->month, "January");
gtk_combo_box_append_text(date->month, "February");
gtk_combo_box_append_text(date->month, "March");
gtk_combo_box_append_text(date->month, "April");
gtk_combo_box_append_text(date->month, "May");
gtk_combo_box_append_text(date->month, "June");
gtk_combo_box_append_text(date->month, "July");
gtk_combo_box_append_text(date->month, "August");
gtk_combo_box_append_text(date->month, "September");
gtk_combo_box_append_text(date->month, "October");
gtk_combo_box_append_text(date->month, "November");
gtk_combo_box_append_text(date->month, "December");
gtk_combo_box_set_active(date->month, 0);
gtk_widget_show(GTK_WIDGET(date->year));
gtk_widget_show(GTK_WIDGET(date->month));
gtk_widget_show(GTK_WIDGET(date->day));
vbox = GTK_VBOX(gtk_vbox_new(FALSE, 0));
label = GTK_LABEL(gtk_label_new("Day"));
gtk_widget_show(GTK_WIDGET(label));
gtk_box_pack_start(GTK_BOX(vbox), GTK_WIDGET(label), TRUE, TRUE, 0);
gtk_box_pack_start(GTK_BOX(vbox), GTK_WIDGET(date->day), TRUE, TRUE, 0);
gtk_box_pack_start(GTK_BOX(hbox), GTK_WIDGET(vbox), TRUE, TRUE, 0);
gtk_widget_show(GTK_WIDGET(vbox));
vbox = GTK_VBOX(gtk_vbox_new(FALSE, 0));
label = GTK_LABEL(gtk_label_new("Month"));
gtk_widget_show(GTK_WIDGET(label));
gtk_box_pack_start(GTK_BOX(vbox), GTK_WIDGET(label), TRUE, TRUE, 0);
gtk_box_pack_start(GTK_BOX(vbox), GTK_WIDGET(date->month), TRUE, TRUE, 0);
gtk_box_pack_start(GTK_BOX(hbox), GTK_WIDGET(vbox), TRUE, TRUE, 0);
gtk_widget_show(GTK_WIDGET(vbox));
vbox = GTK_VBOX(gtk_vbox_new(FALSE, 0));
label = GTK_LABEL(gtk_label_new("Year"));
gtk_widget_show(GTK_WIDGET(label));
gtk_box_pack_start(GTK_BOX(vbox), GTK_WIDGET(label), TRUE, TRUE, 0);
gtk_box_pack_start(GTK_BOX(vbox), GTK_WIDGET(date->year), TRUE, TRUE, 0);
gtk_box_pack_start(GTK_BOX(hbox), GTK_WIDGET(vbox), TRUE, TRUE, 0);
gtk_widget_show(GTK_WIDGET(vbox));
gtk_widget_show(GTK_WIDGET(date->year));
gtk_widget_show(GTK_WIDGET(date->month));
gtk_widget_show(GTK_WIDGET(date->day));
g_signal_connect_swapped(GTK_OBJECT(date->month), "changed", G_CALLBACK(gtk_date_month_changed_handler), date);
return GTK_WIDGET(date);
}
void
gtk_date_set(GtkDate *date, gint y, gint m, gint d)
{
gtk_spin_button_set_value(date->year, (gdouble) y);
gtk_spin_button_set_value(date->day, (gdouble) d);
gtk_combo_box_set_active(date->month, m - 1);
}
void
gtk_date_get(GtkDate *date, gint *y, gint *m, gint *d)
{
*y = gtk_spin_button_get_value_as_int(date->year);
*d = gtk_spin_button_get_value_as_int(date->day);
*m = 1+ gtk_combo_box_get_active(date->month);
}
/* GtkDate
* By Irtza Sharif
*
* LGPL stuff taken from code
* Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free
* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifndef __GTK_DATE_H__
#define __GTK_DATE_H__
#include <gtk/gtkwidget.h>
#include <gtk/gtkhbox.h>
#include <gtk/gtkcombobox.h>
#include <gtk/gtkspinbutton.h>
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
#define GTK_DATE(obj) GTK_CHECK_CAST (obj, gtk_date_get_type (), GtkDate)
#define GTK_DATE_CLASS(klass) GTK_CHECK_CLASS_CAST (klass, gtk_date_get_type (), GtkDateClass)
#define GTK_IS_DATE(obj) GTK_CHECK_TYPE (obj, gtk_date_get_type ())
typedef struct _GtkDate GtkDate;
typedef struct _GtkDateClass GtkDateClass;
struct _GtkDate
{
GtkHBox hbox;
GtkSpinButton *day;
GtkComboBox *month;
GtkSpinButton *year;
};
struct _GtkDateClass
{
GtkHBoxClass parent_class;
};
GtkWidget *gtk_date_new();
void gtk_date_set(GtkDate *date, gint y, gint m, gint d);
void gtk_date_get(GtkDate *date, gint *y, gint *m, gint *d);
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif /* __GTK_DATE_H__ */
Attachment:
Makefile
Description: Binary data