PROGRAM(calendar);
// IMG: GTK.Calendar();
INHERIT(widget);

SIGNAL("month_changed", "");
SIGNAL("day_selected", "");
SIGNAL("day_selected_double_click", "");
SIGNAL("prev_month", "");
SIGNAL("next_month", "");
SIGNAL("prev_year", "");
SIGNAL("next_year", "");

COMPLEX_FUNCTION(create);
int COMPLEX_FUNCTION(select_month, int, int);
NAME_ARGS(month, year);

COMPLEX_FUNCTION(select_day, int);
NAME_ARGS(day_of_month);

COMPLEX_FUNCTION(mark_day, int);
NAME_ARGS(day_of_month);

COMPLEX_FUNCTION(unmark_day, int);
NAME_ARGS(day_of_month);

SIMPLE_FUNCTION(clear_marks);

CONSTANT(GTK_CALENDAR_SHOW_HEADING);
CONSTANT(GTK_CALENDAR_SHOW_DAY_NAMES);
CONSTANT(GTK_CALENDAR_NO_MONTH_CHANGE);
CONSTANT(GTK_CALENDAR_SHOW_WEEK_NUMBERS);
CONSTANT(GTK_CALENDAR_WEEK_START_MONDAY);
COMPLEX_FUNCTION(display_options, int);
NAME_ARGS(options);
// Bitwise or of one or more of CONST(GTK_CALENDAR).

FUNCTION(get_date, "function(void:mapping)");
{
  guint y, m, d;
  gtk_calendar_get_date( GTK_CALENDAR( THIS->obj ), &y, &m, &d );
  push_text("year");
  push_int( y );
  push_text("month");
  push_int( m );
  push_text("day");
  push_int( d );
}

SIMPLE_FUNCTION(freeze);
SIMPLE_FUNCTION(thaw);

CLASSMEMBER(focus_row, int);
CLASSMEMBER(focus_col, int);

CLASSMEMBER(highlight_row, int);
CLASSMEMBER(highlight_col, int);

CLASSMEMBER(month, int);
CLASSMEMBER(year, int);
CLASSMEMBER(selected_day, int);
CLASSMEMBER(num_marked_dates, int);

FUNCTION(get_marked_dates, "function(void:array(int))");
// Returns an array (with 31 elements) with 1es and 0es.
{
  int i;
  for(i=0; i<31; i++)
    push_int( GTK_CALENDAR( THIS->obj )->marked_date[i] );
  f_aggregate( 31 );
}

FUNCTION(get_day_month, "function(void:array(array(int)))");
{
  int i,j;
  for(i=0; i<6; i++)
  {
    for(j=0; j<7; i++)
      push_int( GTK_CALENDAR( THIS->obj )->day_month[i][j] );
    f_aggregate( 7 );
  }
  f_aggregate( 6 );
}

FUNCTION(get_day, "function(void:array(array(int)))");
{
  int i,j;
  for(i=0; i<6; i++)
  {
    for(j=0; j<7; i++)
      push_int( GTK_CALENDAR( THIS->obj )->day[i][j] );
    f_aggregate( 7 );
  }
  f_aggregate( 6 );
}

FUNCTION(set_marked_date_color, "function(int,object:object)");
ARGS(int,GDK.Color);
NAME_ARGS(index,color);
{
  int n;
  struct object *o;
  get_all_args( "set_marked_date_color", args, "%d%o", &n, &o );
  if(!get_gdkobject(o, Color))
    error("Argument 2 is not a GDK.Color object\n");
  n--;
  if(n > 30 || n<0)
    error("Argument 1 is not between 1 and 31, inclusive\n");
  GTK_CALENDAR( THIS->obj )->marked_date_color[n] = *get_gdkobject(o, Color);
  RETURN_THIS();
}

