1998-09-27 18:32:00 +00:00
|
|
|
|
/* GTK - The GIMP Toolkit
|
|
|
|
|
* Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
|
|
|
|
|
*
|
|
|
|
|
* GTK Calendar Widget
|
|
|
|
|
* Copyright (C) 1998 Cesar Miquel, Shawn T. Amundson and Mattias Gr<EFBFBD>nlund
|
|
|
|
|
*
|
|
|
|
|
* lib_date routines
|
|
|
|
|
* Copyright (c) 1995, 1996, 1997, 1998 by Steffen Beyer
|
|
|
|
|
*
|
|
|
|
|
* 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
|
1998-10-01 13:24:42 +00:00
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
1998-09-27 18:32:00 +00:00
|
|
|
|
* 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 <sys/time.h>
|
|
|
|
|
#include <string.h>
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
#include <time.h>
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
#include "gtkcalendar.h"
|
|
|
|
|
#include "gdk/gdkkeysyms.h"
|
|
|
|
|
|
|
|
|
|
/***************************************************************************/
|
|
|
|
|
/* The following date routines are taken from the lib_date package. Keep
|
|
|
|
|
* them seperate in case we want to update them if a newer lib_date comes
|
|
|
|
|
* out with fixes. */
|
|
|
|
|
|
1998-10-01 13:24:42 +00:00
|
|
|
|
typedef unsigned int N_int;
|
|
|
|
|
typedef unsigned long N_long;
|
|
|
|
|
typedef signed long Z_long;
|
1998-09-27 18:32:00 +00:00
|
|
|
|
typedef enum { false = FALSE , true = TRUE } boolean;
|
|
|
|
|
|
1998-10-01 13:24:42 +00:00
|
|
|
|
#define and && /* logical (boolean) operators: lower case */
|
|
|
|
|
#define or ||
|
1998-09-27 18:32:00 +00:00
|
|
|
|
|
1998-11-30 19:07:15 +00:00
|
|
|
|
static const N_int month_length[2][13] =
|
1998-09-27 18:32:00 +00:00
|
|
|
|
{
|
1998-10-01 13:24:42 +00:00
|
|
|
|
{ 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 },
|
|
|
|
|
{ 0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }
|
1998-09-27 18:32:00 +00:00
|
|
|
|
};
|
|
|
|
|
|
1998-11-30 19:07:15 +00:00
|
|
|
|
static const N_int days_in_months[2][14] =
|
1998-09-27 18:32:00 +00:00
|
|
|
|
{
|
1998-10-01 13:24:42 +00:00
|
|
|
|
{ 0, 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365 },
|
|
|
|
|
{ 0, 0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335, 366 }
|
1998-09-27 18:32:00 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static Z_long calc_days(N_int year, N_int mm, N_int dd);
|
|
|
|
|
static N_int day_of_week(N_int year, N_int mm, N_int dd);
|
|
|
|
|
static Z_long dates_difference(N_int year1, N_int mm1, N_int dd1,
|
1998-10-01 13:24:42 +00:00
|
|
|
|
N_int year2, N_int mm2, N_int dd2);
|
1998-09-27 18:32:00 +00:00
|
|
|
|
static N_int weeks_in_year(N_int year);
|
|
|
|
|
|
|
|
|
|
static boolean
|
|
|
|
|
leap(N_int year)
|
|
|
|
|
{
|
1998-10-01 13:24:42 +00:00
|
|
|
|
return((((year % 4) == 0) and ((year % 100) != 0)) or ((year % 400) == 0));
|
1998-09-27 18:32:00 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static N_int
|
|
|
|
|
day_of_week(N_int year, N_int mm, N_int dd)
|
|
|
|
|
{
|
1998-10-01 13:24:42 +00:00
|
|
|
|
Z_long days;
|
|
|
|
|
|
|
|
|
|
days = calc_days(year, mm, dd);
|
|
|
|
|
if (days > 0L)
|
1998-09-27 18:32:00 +00:00
|
|
|
|
{
|
1998-10-01 13:24:42 +00:00
|
|
|
|
days--;
|
|
|
|
|
days %= 7L;
|
|
|
|
|
days++;
|
1998-09-27 18:32:00 +00:00
|
|
|
|
}
|
1998-10-01 13:24:42 +00:00
|
|
|
|
return( (N_int) days );
|
1998-09-27 18:32:00 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static N_int weeks_in_year(N_int year)
|
|
|
|
|
{
|
1998-10-01 13:24:42 +00:00
|
|
|
|
return(52 + ((day_of_week(year,1,1)==4) or (day_of_week(year,12,31)==4)));
|
1998-09-27 18:32:00 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static boolean
|
|
|
|
|
check_date(N_int year, N_int mm, N_int dd)
|
|
|
|
|
{
|
1998-10-01 13:24:42 +00:00
|
|
|
|
if (year < 1) return(false);
|
|
|
|
|
if ((mm < 1) or (mm > 12)) return(false);
|
|
|
|
|
if ((dd < 1) or (dd > month_length[leap(year)][mm])) return(false);
|
|
|
|
|
return(true);
|
1998-09-27 18:32:00 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static N_int
|
|
|
|
|
week_number(N_int year, N_int mm, N_int dd)
|
|
|
|
|
{
|
1998-10-01 13:24:42 +00:00
|
|
|
|
N_int first;
|
|
|
|
|
|
|
|
|
|
first = day_of_week(year,1,1) - 1;
|
|
|
|
|
return( (N_int) ( (dates_difference(year,1,1, year,mm,dd) + first) / 7L ) +
|
|
|
|
|
(first < 4) );
|
1998-09-27 18:32:00 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static Z_long
|
|
|
|
|
year_to_days(N_int year)
|
|
|
|
|
{
|
1998-10-01 13:24:42 +00:00
|
|
|
|
return( year * 365L + (year / 4) - (year / 100) + (year / 400) );
|
1998-09-27 18:32:00 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static Z_long
|
|
|
|
|
calc_days(N_int year, N_int mm, N_int dd)
|
|
|
|
|
{
|
1998-10-01 13:24:42 +00:00
|
|
|
|
boolean lp;
|
|
|
|
|
|
|
|
|
|
if (year < 1) return(0L);
|
|
|
|
|
if ((mm < 1) or (mm > 12)) return(0L);
|
|
|
|
|
if ((dd < 1) or (dd > month_length[(lp = leap(year))][mm])) return(0L);
|
|
|
|
|
return( year_to_days(--year) + days_in_months[lp][mm] + dd );
|
1998-09-27 18:32:00 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static boolean
|
|
|
|
|
week_of_year(N_int *week, N_int *year, N_int mm, N_int dd)
|
|
|
|
|
{
|
1998-10-01 13:24:42 +00:00
|
|
|
|
if (check_date(*year,mm,dd))
|
|
|
|
|
{
|
|
|
|
|
*week = week_number(*year,mm,dd);
|
|
|
|
|
if (*week == 0)
|
|
|
|
|
*week = weeks_in_year(--(*year));
|
|
|
|
|
else if (*week > weeks_in_year(*year))
|
|
|
|
|
{
|
|
|
|
|
*week = 1;
|
|
|
|
|
(*year)++;
|
|
|
|
|
}
|
|
|
|
|
return(true);
|
|
|
|
|
}
|
|
|
|
|
return(false);
|
1998-09-27 18:32:00 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static Z_long
|
|
|
|
|
dates_difference(N_int year1, N_int mm1, N_int dd1,
|
1998-10-01 13:24:42 +00:00
|
|
|
|
N_int year2, N_int mm2, N_int dd2)
|
1998-09-27 18:32:00 +00:00
|
|
|
|
{
|
1998-10-01 13:24:42 +00:00
|
|
|
|
return( calc_days(year2, mm2, dd2) - calc_days(year1, mm1, dd1) );
|
1998-09-27 18:32:00 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** END OF lib_date routines ************************************************/
|
|
|
|
|
|
1998-10-01 13:24:42 +00:00
|
|
|
|
#define CALENDAR_MARGIN 0
|
|
|
|
|
#define CALENDAR_YSEP 4
|
|
|
|
|
#define CALENDAR_XSEP 4
|
|
|
|
|
#define INNER_BORDER 4
|
1998-09-27 18:32:00 +00:00
|
|
|
|
|
|
|
|
|
#define DAY_XPAD 2
|
|
|
|
|
#define DAY_YPAD 2
|
1998-10-01 13:24:42 +00:00
|
|
|
|
#define DAY_XSEP 0 /* not really good for small calendar */
|
1998-09-27 18:32:00 +00:00
|
|
|
|
#define DAY_YSEP 0 /* not really good for small calendar */
|
|
|
|
|
|
|
|
|
|
/* Color usage */
|
1998-10-01 13:24:42 +00:00
|
|
|
|
#define HEADER_FG_COLOR(widget) (& (widget)->style->fg[GTK_WIDGET_STATE (widget)])
|
|
|
|
|
#define HEADER_BG_COLOR(widget) (& (widget)->style->bg[GTK_WIDGET_STATE (widget)])
|
1998-10-05 03:52:48 +00:00
|
|
|
|
#define DAY_NAME_COLOR(widget) (& (widget)->style->bg[GTK_STATE_SELECTED])
|
1998-10-01 13:24:42 +00:00
|
|
|
|
#define NORMAL_DAY_COLOR(widget) (& (widget)->style->fg[GTK_WIDGET_STATE (widget)])
|
|
|
|
|
#define SELECTION_FOCUS_COLOR(widget) (& (widget)->style->fg[GTK_WIDGET_STATE (widget)])
|
1998-09-27 18:32:00 +00:00
|
|
|
|
#define SELECTION_NO_FOCUS_COLOR(widget) (& (widget)->style->mid[GTK_WIDGET_STATE (widget)])
|
1998-10-01 13:24:42 +00:00
|
|
|
|
#define PREV_MONTH_COLOR(widget) (& (widget)->style->mid[GTK_WIDGET_STATE (widget)])
|
|
|
|
|
#define NEXT_MONTH_COLOR(widget) (& (widget)->style->mid[GTK_WIDGET_STATE (widget)])
|
|
|
|
|
#define MARKED_COLOR(widget) (& (widget)->style->fg[GTK_WIDGET_STATE (widget)])
|
|
|
|
|
#define FOREGROUND_COLOR(widget) (& (widget)->style->fg[GTK_WIDGET_STATE (widget)])
|
|
|
|
|
#define BACKGROUND_COLOR(widget) (& (widget)->style->base[GTK_WIDGET_STATE (widget)])
|
|
|
|
|
#define HIGHLIGHT_BACK_COLOR(widget) (& (widget)->style->mid[GTK_WIDGET_STATE (widget)])
|
1998-09-27 18:32:00 +00:00
|
|
|
|
|
|
|
|
|
#define HEADER_FONT(widget) ((widget)->style->font)
|
|
|
|
|
#define LABEL_FONT(widget) ((widget)->style->font)
|
|
|
|
|
#define DAY_FONT(widget) ((widget)->style->font)
|
|
|
|
|
|
|
|
|
|
enum {
|
|
|
|
|
ARROW_YEAR_LEFT,
|
|
|
|
|
ARROW_YEAR_RIGHT,
|
|
|
|
|
ARROW_MONTH_LEFT,
|
|
|
|
|
ARROW_MONTH_RIGHT
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
enum {
|
|
|
|
|
MONTH_PREV,
|
|
|
|
|
MONTH_CURRENT,
|
|
|
|
|
MONTH_NEXT
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
enum {
|
|
|
|
|
MONTH_CHANGED_SIGNAL,
|
|
|
|
|
DAY_SELECTED_SIGNAL,
|
|
|
|
|
DAY_SELECTED_DOUBLE_CLICK_SIGNAL,
|
|
|
|
|
PREV_MONTH_SIGNAL,
|
|
|
|
|
NEXT_MONTH_SIGNAL,
|
|
|
|
|
PREV_YEAR_SIGNAL,
|
|
|
|
|
NEXT_YEAR_SIGNAL,
|
|
|
|
|
LAST_SIGNAL
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static gint gtk_calendar_signals[LAST_SIGNAL] = { 0 };
|
|
|
|
|
|
1998-10-04 23:07:04 +00:00
|
|
|
|
static GtkWidgetClass *parent_class = NULL;
|
|
|
|
|
|
|
|
|
|
typedef struct _GtkCalendarPrivateData GtkCalendarPrivateData;
|
|
|
|
|
struct _GtkCalendarPrivateData
|
|
|
|
|
{
|
|
|
|
|
GdkWindow *header_win;
|
|
|
|
|
GdkWindow *day_name_win;
|
|
|
|
|
GdkWindow *main_win;
|
|
|
|
|
GdkWindow *week_win;
|
|
|
|
|
GdkWindow *arrow_win[4];
|
|
|
|
|
|
1998-11-28 01:56:09 +00:00
|
|
|
|
guint header_h;
|
|
|
|
|
guint day_name_h;
|
|
|
|
|
guint main_h;
|
1998-10-04 23:07:04 +00:00
|
|
|
|
|
|
|
|
|
guint arrow_state[4];
|
|
|
|
|
guint arrow_width;
|
|
|
|
|
guint max_month_width;
|
|
|
|
|
guint max_year_width;
|
|
|
|
|
|
|
|
|
|
guint day_width;
|
|
|
|
|
guint week_width;
|
|
|
|
|
|
|
|
|
|
guint min_day_width;
|
|
|
|
|
guint max_day_char_width;
|
|
|
|
|
guint max_day_char_ascent;
|
|
|
|
|
guint max_day_char_descent;
|
|
|
|
|
guint max_label_char_ascent;
|
|
|
|
|
guint max_label_char_descent;
|
|
|
|
|
guint max_week_char_width;
|
|
|
|
|
|
1998-11-28 01:56:09 +00:00
|
|
|
|
guint freeze_count;
|
|
|
|
|
|
1998-10-04 23:07:04 +00:00
|
|
|
|
/* flags */
|
1998-11-28 01:56:09 +00:00
|
|
|
|
guint dirty_header : 1;
|
|
|
|
|
guint dirty_day_names : 1;
|
|
|
|
|
guint dirty_main : 1;
|
|
|
|
|
guint dirty_week : 1;
|
1998-10-04 23:07:04 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
#define GTK_CALENDAR_PRIVATE_DATA(widget) (((GtkCalendarPrivateData*)(GTK_CALENDAR (widget)->private_data)))
|
|
|
|
|
|
1998-09-27 18:32:00 +00:00
|
|
|
|
typedef void (*GtkCalendarSignalDate) (GtkObject *object, guint arg1, guint arg2, guint arg3, gpointer data);
|
|
|
|
|
|
1998-10-01 13:24:42 +00:00
|
|
|
|
static void gtk_calendar_class_init (GtkCalendarClass *class);
|
|
|
|
|
static void gtk_calendar_init (GtkCalendar *calendar);
|
|
|
|
|
static void gtk_calendar_realize (GtkWidget *widget);
|
|
|
|
|
static void gtk_calendar_unrealize (GtkWidget *widget);
|
|
|
|
|
static void gtk_calendar_draw_focus (GtkWidget *widget);
|
|
|
|
|
static void gtk_calendar_size_request (GtkWidget *widget,
|
|
|
|
|
GtkRequisition *requisition);
|
|
|
|
|
static void gtk_calendar_size_allocate (GtkWidget *widget,
|
|
|
|
|
GtkAllocation *allocation);
|
|
|
|
|
static gint gtk_calendar_expose (GtkWidget *widget,
|
|
|
|
|
GdkEventExpose *event);
|
|
|
|
|
static gint gtk_calendar_button_press (GtkWidget *widget,
|
|
|
|
|
GdkEventButton *event);
|
|
|
|
|
static void gtk_calendar_main_button (GtkWidget *widget,
|
|
|
|
|
GdkEventButton *event);
|
|
|
|
|
static gint gtk_calendar_motion_notify (GtkWidget *widget,
|
|
|
|
|
GdkEventMotion *event);
|
|
|
|
|
static gint gtk_calendar_enter_notify (GtkWidget *widget,
|
|
|
|
|
GdkEventCrossing *event);
|
|
|
|
|
static gint gtk_calendar_leave_notify (GtkWidget *widget,
|
|
|
|
|
GdkEventCrossing *event);
|
|
|
|
|
static gint gtk_calendar_key_press (GtkWidget *widget,
|
|
|
|
|
GdkEventKey *event);
|
|
|
|
|
static gint gtk_calendar_focus_in (GtkWidget *widget,
|
|
|
|
|
GdkEventFocus *event);
|
|
|
|
|
static gint gtk_calendar_focus_out (GtkWidget *widget,
|
|
|
|
|
GdkEventFocus *event);
|
|
|
|
|
static void gtk_calendar_state_changed (GtkWidget *widget,
|
1998-09-27 18:32:00 +00:00
|
|
|
|
GtkStateType previous_state);
|
1998-10-01 13:24:42 +00:00
|
|
|
|
static void gtk_calendar_style_set (GtkWidget *widget,
|
1998-09-27 18:32:00 +00:00
|
|
|
|
GtkStyle *previous_style);
|
1998-10-01 13:24:42 +00:00
|
|
|
|
static void gtk_calendar_paint_header (GtkWidget *widget);
|
|
|
|
|
static void gtk_calendar_paint_day_names (GtkWidget *widget);
|
|
|
|
|
static void gtk_calendar_paint_week_numbers (GtkWidget *widget);
|
|
|
|
|
static void gtk_calendar_paint_main (GtkWidget *widget);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void gtk_calendar_paint (GtkWidget *widget,
|
|
|
|
|
GdkRectangle *area);
|
|
|
|
|
static void gtk_calendar_paint_arrow (GtkWidget *widget,
|
|
|
|
|
guint arrow);
|
|
|
|
|
static void gtk_calendar_paint_day_num (GtkWidget *widget,
|
|
|
|
|
gint day);
|
|
|
|
|
static void gtk_calendar_paint_day (GtkWidget *widget,
|
|
|
|
|
gint row,
|
|
|
|
|
gint col);
|
|
|
|
|
static void gtk_calendar_draw (GtkWidget *widget,
|
|
|
|
|
GdkRectangle *area);
|
|
|
|
|
static void gtk_calendar_compute_days (GtkCalendar *calendar);
|
|
|
|
|
static gint left_x_for_column (GtkCalendar *calendar,
|
|
|
|
|
gint column);
|
|
|
|
|
static gint top_y_for_row (GtkCalendar *calendar,
|
|
|
|
|
gint row);
|
1998-09-27 18:32:00 +00:00
|
|
|
|
|
|
|
|
|
static char *default_abbreviated_dayname[7];
|
|
|
|
|
static char *default_monthname[12];
|
|
|
|
|
|
1998-10-01 13:24:42 +00:00
|
|
|
|
GtkType
|
|
|
|
|
gtk_calendar_get_type (void)
|
1998-09-27 18:32:00 +00:00
|
|
|
|
{
|
1998-10-01 13:24:42 +00:00
|
|
|
|
static GtkType calendar_type = 0;
|
|
|
|
|
|
1998-09-27 18:32:00 +00:00
|
|
|
|
if (!calendar_type)
|
|
|
|
|
{
|
1998-11-30 19:07:15 +00:00
|
|
|
|
static const GtkTypeInfo calendar_info =
|
1998-09-27 18:32:00 +00:00
|
|
|
|
{
|
|
|
|
|
"GtkCalendar",
|
|
|
|
|
sizeof (GtkCalendar),
|
|
|
|
|
sizeof (GtkCalendarClass),
|
|
|
|
|
(GtkClassInitFunc) gtk_calendar_class_init,
|
|
|
|
|
(GtkObjectInitFunc) gtk_calendar_init,
|
|
|
|
|
(GtkArgSetFunc) NULL,
|
|
|
|
|
(GtkArgGetFunc) NULL,
|
|
|
|
|
};
|
1998-10-01 13:24:42 +00:00
|
|
|
|
|
|
|
|
|
calendar_type = gtk_type_unique (GTK_TYPE_WIDGET, &calendar_info);
|
1998-09-27 18:32:00 +00:00
|
|
|
|
}
|
1998-10-01 13:24:42 +00:00
|
|
|
|
|
1998-09-27 18:32:00 +00:00
|
|
|
|
return calendar_type;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
gtk_calendar_class_init (GtkCalendarClass *class)
|
|
|
|
|
{
|
|
|
|
|
GtkObjectClass *object_class;
|
|
|
|
|
GtkWidgetClass *widget_class;
|
1998-10-01 13:24:42 +00:00
|
|
|
|
|
1998-09-27 18:32:00 +00:00
|
|
|
|
object_class = (GtkObjectClass*) class;
|
|
|
|
|
widget_class = (GtkWidgetClass*) class;
|
1998-10-01 13:24:42 +00:00
|
|
|
|
|
|
|
|
|
parent_class = gtk_type_class (GTK_TYPE_WIDGET);
|
|
|
|
|
|
1998-09-27 18:32:00 +00:00
|
|
|
|
widget_class->realize = gtk_calendar_realize;
|
|
|
|
|
widget_class->unrealize = gtk_calendar_unrealize;
|
|
|
|
|
widget_class->expose_event = gtk_calendar_expose;
|
|
|
|
|
widget_class->draw = gtk_calendar_draw;
|
|
|
|
|
widget_class->draw_focus = gtk_calendar_draw_focus;
|
|
|
|
|
widget_class->size_request = gtk_calendar_size_request;
|
|
|
|
|
widget_class->size_allocate = gtk_calendar_size_allocate;
|
|
|
|
|
widget_class->button_press_event = gtk_calendar_button_press;
|
|
|
|
|
widget_class->motion_notify_event = gtk_calendar_motion_notify;
|
|
|
|
|
widget_class->enter_notify_event = gtk_calendar_enter_notify;
|
|
|
|
|
widget_class->leave_notify_event = gtk_calendar_leave_notify;
|
|
|
|
|
widget_class->key_press_event = gtk_calendar_key_press;
|
|
|
|
|
widget_class->focus_in_event = gtk_calendar_focus_in;
|
|
|
|
|
widget_class->focus_out_event = gtk_calendar_focus_out;
|
|
|
|
|
widget_class->style_set = gtk_calendar_style_set;
|
|
|
|
|
widget_class->state_changed = gtk_calendar_state_changed;
|
1998-10-01 13:24:42 +00:00
|
|
|
|
|
1998-09-27 18:32:00 +00:00
|
|
|
|
gtk_calendar_signals[MONTH_CHANGED_SIGNAL] =
|
|
|
|
|
gtk_signal_new ("month_changed",
|
|
|
|
|
GTK_RUN_FIRST, object_class->type,
|
1998-10-01 13:24:42 +00:00
|
|
|
|
GTK_SIGNAL_OFFSET (GtkCalendarClass, month_changed),
|
1998-09-27 18:32:00 +00:00
|
|
|
|
gtk_signal_default_marshaller, GTK_TYPE_NONE, 0);
|
|
|
|
|
gtk_calendar_signals[DAY_SELECTED_SIGNAL] =
|
|
|
|
|
gtk_signal_new ("day_selected",
|
|
|
|
|
GTK_RUN_FIRST, object_class->type,
|
1998-10-01 13:24:42 +00:00
|
|
|
|
GTK_SIGNAL_OFFSET (GtkCalendarClass, day_selected),
|
1998-09-27 18:32:00 +00:00
|
|
|
|
gtk_signal_default_marshaller, GTK_TYPE_NONE, 0);
|
|
|
|
|
gtk_calendar_signals[DAY_SELECTED_DOUBLE_CLICK_SIGNAL] =
|
|
|
|
|
gtk_signal_new ("day_selected_double_click",
|
|
|
|
|
GTK_RUN_FIRST, object_class->type,
|
1998-10-01 13:24:42 +00:00
|
|
|
|
GTK_SIGNAL_OFFSET (GtkCalendarClass, day_selected_double_click),
|
1998-09-27 18:32:00 +00:00
|
|
|
|
gtk_signal_default_marshaller, GTK_TYPE_NONE, 0);
|
|
|
|
|
gtk_calendar_signals[PREV_MONTH_SIGNAL] =
|
|
|
|
|
gtk_signal_new ("prev_month",
|
|
|
|
|
GTK_RUN_FIRST, object_class->type,
|
1998-10-01 13:24:42 +00:00
|
|
|
|
GTK_SIGNAL_OFFSET (GtkCalendarClass, prev_month),
|
1998-09-27 18:32:00 +00:00
|
|
|
|
gtk_signal_default_marshaller, GTK_TYPE_NONE, 0);
|
|
|
|
|
gtk_calendar_signals[NEXT_MONTH_SIGNAL] =
|
|
|
|
|
gtk_signal_new ("next_month",
|
|
|
|
|
GTK_RUN_FIRST, object_class->type,
|
1998-10-01 13:24:42 +00:00
|
|
|
|
GTK_SIGNAL_OFFSET (GtkCalendarClass, next_month),
|
1998-09-27 18:32:00 +00:00
|
|
|
|
gtk_signal_default_marshaller, GTK_TYPE_NONE, 0);
|
|
|
|
|
gtk_calendar_signals[PREV_YEAR_SIGNAL] =
|
|
|
|
|
gtk_signal_new ("prev_year",
|
|
|
|
|
GTK_RUN_FIRST, object_class->type,
|
1998-10-01 13:24:42 +00:00
|
|
|
|
GTK_SIGNAL_OFFSET (GtkCalendarClass, prev_year),
|
1998-09-27 18:32:00 +00:00
|
|
|
|
gtk_signal_default_marshaller, GTK_TYPE_NONE, 0);
|
|
|
|
|
gtk_calendar_signals[NEXT_YEAR_SIGNAL] =
|
|
|
|
|
gtk_signal_new ("next_year",
|
|
|
|
|
GTK_RUN_FIRST, object_class->type,
|
1998-10-01 13:24:42 +00:00
|
|
|
|
GTK_SIGNAL_OFFSET (GtkCalendarClass, next_year),
|
1998-09-27 18:32:00 +00:00
|
|
|
|
gtk_signal_default_marshaller, GTK_TYPE_NONE, 0);
|
1998-10-01 13:24:42 +00:00
|
|
|
|
|
1998-09-27 18:32:00 +00:00
|
|
|
|
gtk_object_class_add_signals (object_class, gtk_calendar_signals, LAST_SIGNAL);
|
1998-10-01 13:24:42 +00:00
|
|
|
|
|
|
|
|
|
class->month_changed = NULL;
|
|
|
|
|
class->day_selected = NULL;
|
|
|
|
|
class->day_selected_double_click = NULL;
|
|
|
|
|
class->prev_month = NULL;
|
|
|
|
|
class->next_month = NULL;
|
|
|
|
|
class->prev_year = NULL;
|
|
|
|
|
class->next_year = NULL;
|
1998-09-27 18:32:00 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
gtk_calendar_init (GtkCalendar *calendar)
|
|
|
|
|
{
|
|
|
|
|
time_t secs;
|
|
|
|
|
struct tm *tm;
|
|
|
|
|
gint i;
|
|
|
|
|
char buffer[255];
|
|
|
|
|
time_t tmp_time;
|
|
|
|
|
GtkWidget *widget;
|
1998-10-04 23:07:04 +00:00
|
|
|
|
GtkCalendarPrivateData *private_data;
|
1998-10-01 13:24:42 +00:00
|
|
|
|
|
1998-09-27 18:32:00 +00:00
|
|
|
|
widget = GTK_WIDGET (calendar);
|
|
|
|
|
GTK_WIDGET_SET_FLAGS (widget, GTK_CAN_FOCUS);
|
1998-10-01 13:24:42 +00:00
|
|
|
|
|
1998-10-04 23:07:04 +00:00
|
|
|
|
calendar->private_data = (gpointer) malloc (sizeof (GtkCalendarPrivateData));
|
|
|
|
|
private_data = GTK_CALENDAR_PRIVATE_DATA (calendar);
|
|
|
|
|
|
1998-09-27 18:32:00 +00:00
|
|
|
|
if (!default_abbreviated_dayname[0])
|
|
|
|
|
for (i=0; i<7; i++)
|
|
|
|
|
{
|
|
|
|
|
tmp_time= (i+3)*86400;
|
|
|
|
|
strftime ( buffer, sizeof (buffer), "%a", gmtime (&tmp_time));
|
|
|
|
|
default_abbreviated_dayname[i] = g_strdup (buffer);
|
|
|
|
|
}
|
1998-10-01 13:24:42 +00:00
|
|
|
|
|
1998-09-27 18:32:00 +00:00
|
|
|
|
if (!default_monthname[0])
|
|
|
|
|
for (i=0; i<12; i++)
|
|
|
|
|
{
|
|
|
|
|
tmp_time=i*2764800;
|
|
|
|
|
strftime ( buffer, sizeof (buffer), "%B", gmtime (&tmp_time));
|
|
|
|
|
default_monthname[i] = g_strdup (buffer);
|
|
|
|
|
}
|
1998-10-01 13:24:42 +00:00
|
|
|
|
|
1998-09-27 18:32:00 +00:00
|
|
|
|
/* Set defaults */
|
|
|
|
|
secs = time (NULL);
|
|
|
|
|
tm = localtime (&secs);
|
|
|
|
|
calendar->month = tm->tm_mon;
|
|
|
|
|
calendar->year = 1900 + tm->tm_year;
|
1998-10-01 13:24:42 +00:00
|
|
|
|
|
1998-09-27 18:32:00 +00:00
|
|
|
|
for (i=0;i<31;i++)
|
|
|
|
|
calendar->marked_date[i] = FALSE;
|
|
|
|
|
calendar->selected_day = 1;
|
1998-10-01 13:24:42 +00:00
|
|
|
|
|
1998-10-04 23:07:04 +00:00
|
|
|
|
calendar->display_flags = ( GTK_CALENDAR_SHOW_HEADING |
|
|
|
|
|
GTK_CALENDAR_SHOW_DAY_NAMES );
|
1998-10-01 13:24:42 +00:00
|
|
|
|
|
1998-09-27 18:32:00 +00:00
|
|
|
|
calendar->highlight_row = -1;
|
|
|
|
|
calendar->highlight_col = -1;
|
1998-10-01 13:24:42 +00:00
|
|
|
|
|
1998-10-05 03:52:48 +00:00
|
|
|
|
calendar->focus_row = -1;
|
|
|
|
|
calendar->focus_col = -1;
|
|
|
|
|
calendar->xor_gc = NULL;
|
|
|
|
|
|
1998-10-04 23:07:04 +00:00
|
|
|
|
private_data->max_year_width = 0;
|
|
|
|
|
private_data->max_month_width = 0;
|
|
|
|
|
private_data->max_day_char_width = 0;
|
|
|
|
|
private_data->max_week_char_width = 0;
|
|
|
|
|
|
|
|
|
|
private_data->max_day_char_ascent = 0;
|
|
|
|
|
private_data->max_day_char_descent = 0;
|
|
|
|
|
private_data->max_label_char_ascent = 0;
|
|
|
|
|
private_data->max_label_char_descent = 0;
|
|
|
|
|
|
|
|
|
|
private_data->arrow_width = 10;
|
1998-11-28 01:56:09 +00:00
|
|
|
|
|
|
|
|
|
private_data->freeze_count = 0;
|
1998-10-01 13:24:42 +00:00
|
|
|
|
|
1998-10-04 23:07:04 +00:00
|
|
|
|
private_data->dirty_header = 0;
|
|
|
|
|
private_data->dirty_day_names = 0;
|
|
|
|
|
private_data->dirty_week = 0;
|
|
|
|
|
private_data->dirty_main = 0;
|
1998-09-27 18:32:00 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
GtkWidget*
|
1998-10-01 13:24:42 +00:00
|
|
|
|
gtk_calendar_new (void)
|
1998-09-27 18:32:00 +00:00
|
|
|
|
{
|
1998-10-01 13:24:42 +00:00
|
|
|
|
return GTK_WIDGET (gtk_type_new (GTK_TYPE_CALENDAR));
|
1998-09-27 18:32:00 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* column_from_x: returns the column 0-6 that the
|
|
|
|
|
* x pixel of the xwindow is in */
|
|
|
|
|
static gint
|
1998-10-01 13:24:42 +00:00
|
|
|
|
column_from_x (GtkCalendar *calendar,
|
|
|
|
|
gint event_x)
|
1998-09-27 18:32:00 +00:00
|
|
|
|
{
|
|
|
|
|
gint c, column;
|
|
|
|
|
gint x_left, x_right;
|
1998-10-01 13:24:42 +00:00
|
|
|
|
|
1998-09-27 18:32:00 +00:00
|
|
|
|
column = -1;
|
1998-10-01 13:24:42 +00:00
|
|
|
|
|
1998-09-27 18:32:00 +00:00
|
|
|
|
for (c = 0; c < 7; c++)
|
|
|
|
|
{
|
|
|
|
|
x_left = left_x_for_column (calendar, c);
|
1998-10-04 23:07:04 +00:00
|
|
|
|
x_right = x_left + GTK_CALENDAR_PRIVATE_DATA (calendar)->day_width;
|
1998-10-01 13:24:42 +00:00
|
|
|
|
|
1998-09-27 18:32:00 +00:00
|
|
|
|
if (event_x > x_left && event_x < x_right)
|
|
|
|
|
{
|
|
|
|
|
column = c;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
1998-10-01 13:24:42 +00:00
|
|
|
|
|
1998-09-27 18:32:00 +00:00
|
|
|
|
return column;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static gint
|
|
|
|
|
row_height (GtkCalendar *calendar)
|
|
|
|
|
{
|
1998-10-04 23:07:04 +00:00
|
|
|
|
return (GTK_CALENDAR_PRIVATE_DATA (calendar)->main_h - CALENDAR_MARGIN
|
1998-09-27 18:32:00 +00:00
|
|
|
|
- ((calendar->display_flags & GTK_CALENDAR_SHOW_DAY_NAMES)
|
|
|
|
|
? CALENDAR_YSEP : CALENDAR_MARGIN)) / 6;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* row_from_y: returns the row 0-5 that the
|
|
|
|
|
* y pixel of the xwindow is in */
|
|
|
|
|
static gint
|
1998-10-01 13:24:42 +00:00
|
|
|
|
row_from_y (GtkCalendar *calendar,
|
|
|
|
|
gint event_y)
|
1998-09-27 18:32:00 +00:00
|
|
|
|
{
|
|
|
|
|
gint r, row;
|
|
|
|
|
gint height;
|
|
|
|
|
gint y_top, y_bottom;
|
1998-10-01 13:24:42 +00:00
|
|
|
|
|
1998-09-27 18:32:00 +00:00
|
|
|
|
height = row_height (calendar);
|
|
|
|
|
row = -1;
|
1998-10-01 13:24:42 +00:00
|
|
|
|
|
1998-09-27 18:32:00 +00:00
|
|
|
|
for (r = 0; r < 6; r++)
|
|
|
|
|
{
|
|
|
|
|
y_top = top_y_for_row (calendar, r);
|
|
|
|
|
y_bottom = y_top + height;
|
1998-10-01 13:24:42 +00:00
|
|
|
|
|
1998-09-27 18:32:00 +00:00
|
|
|
|
if (event_y > y_top && event_y < y_bottom)
|
|
|
|
|
{
|
|
|
|
|
row = r;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
1998-10-01 13:24:42 +00:00
|
|
|
|
|
1998-09-27 18:32:00 +00:00
|
|
|
|
return row;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* left_x_for_column: returns the x coordinate
|
|
|
|
|
* for the left of the column */
|
|
|
|
|
static gint
|
1998-10-01 13:24:42 +00:00
|
|
|
|
left_x_for_column (GtkCalendar *calendar,
|
|
|
|
|
gint column)
|
1998-09-27 18:32:00 +00:00
|
|
|
|
{
|
|
|
|
|
gint width;
|
|
|
|
|
gint x_left;
|
1998-10-01 13:24:42 +00:00
|
|
|
|
|
1998-10-04 23:07:04 +00:00
|
|
|
|
width = GTK_CALENDAR_PRIVATE_DATA (calendar)->day_width;
|
1998-09-27 18:32:00 +00:00
|
|
|
|
if (calendar->display_flags & GTK_CALENDAR_SHOW_WEEK_NUMBERS)
|
|
|
|
|
x_left = DAY_XSEP + (width + DAY_XSEP) * column;
|
|
|
|
|
else
|
|
|
|
|
x_left = CALENDAR_MARGIN + (width + DAY_XSEP) * column;
|
1998-10-01 13:24:42 +00:00
|
|
|
|
|
1998-09-27 18:32:00 +00:00
|
|
|
|
return x_left;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* top_y_for_row: returns the y coordinate
|
|
|
|
|
* for the top of the row */
|
|
|
|
|
static gint
|
1998-10-01 13:24:42 +00:00
|
|
|
|
top_y_for_row (GtkCalendar *calendar,
|
|
|
|
|
gint row)
|
1998-09-27 18:32:00 +00:00
|
|
|
|
{
|
1998-10-01 13:24:42 +00:00
|
|
|
|
|
1998-10-04 23:07:04 +00:00
|
|
|
|
return (GTK_CALENDAR_PRIVATE_DATA (calendar)->main_h
|
|
|
|
|
- (CALENDAR_MARGIN + (6 - row)
|
|
|
|
|
* row_height (calendar)));
|
1998-09-27 18:32:00 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* This function should be done by the toolkit, but we don't like the
|
|
|
|
|
* GTK arrows because they don't look good on this widget */
|
|
|
|
|
static void
|
1998-10-01 13:24:42 +00:00
|
|
|
|
draw_arrow_right (GdkWindow *window,
|
|
|
|
|
GdkGC *gc,
|
|
|
|
|
gint x,
|
|
|
|
|
gint y,
|
|
|
|
|
gint size)
|
1998-09-27 18:32:00 +00:00
|
|
|
|
{
|
|
|
|
|
gint i;
|
1998-10-01 13:24:42 +00:00
|
|
|
|
|
1998-09-27 18:32:00 +00:00
|
|
|
|
for (i = 0; i <= size / 2; i++)
|
|
|
|
|
{
|
|
|
|
|
gdk_draw_line (window, gc,
|
|
|
|
|
x + i,
|
|
|
|
|
y + i,
|
|
|
|
|
x + i,
|
|
|
|
|
y + size - i);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* This function should be done by the toolkit, but we don't like the
|
|
|
|
|
* GTK arrows because they don't look good on this widget */
|
|
|
|
|
static void
|
1998-10-01 13:24:42 +00:00
|
|
|
|
draw_arrow_left (GdkWindow *window,
|
|
|
|
|
GdkGC *gc,
|
|
|
|
|
gint x,
|
|
|
|
|
gint y,
|
|
|
|
|
gint size)
|
1998-09-27 18:32:00 +00:00
|
|
|
|
{
|
|
|
|
|
gint i;
|
1998-10-01 13:24:42 +00:00
|
|
|
|
|
1998-09-27 18:32:00 +00:00
|
|
|
|
for (i = 0; i <= size / 2; i++)
|
|
|
|
|
{
|
|
|
|
|
gdk_draw_line (window, gc,
|
|
|
|
|
x + size/2 - i,
|
|
|
|
|
y + i,
|
|
|
|
|
x + size/2 - i,
|
|
|
|
|
y + size - i);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
gtk_calendar_set_month_prev (GtkCalendar *calendar)
|
|
|
|
|
{
|
|
|
|
|
gint month_len;
|
1998-10-01 13:24:42 +00:00
|
|
|
|
|
1998-09-27 18:32:00 +00:00
|
|
|
|
if (calendar->display_flags & GTK_CALENDAR_NO_MONTH_CHANGE)
|
|
|
|
|
return;
|
1998-10-01 13:24:42 +00:00
|
|
|
|
|
1998-09-27 18:32:00 +00:00
|
|
|
|
if (calendar->month == 0)
|
|
|
|
|
{
|
|
|
|
|
calendar->month = 11;
|
|
|
|
|
calendar->year--;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
calendar->month--;
|
1998-10-01 13:24:42 +00:00
|
|
|
|
|
1998-09-27 18:32:00 +00:00
|
|
|
|
month_len = month_length[leap (calendar->year)][calendar->month + 1];
|
1998-10-01 13:24:42 +00:00
|
|
|
|
|
1998-09-27 18:32:00 +00:00
|
|
|
|
gtk_calendar_freeze (calendar);
|
|
|
|
|
gtk_calendar_compute_days (calendar);
|
1998-10-01 13:24:42 +00:00
|
|
|
|
|
1998-09-27 18:32:00 +00:00
|
|
|
|
gtk_signal_emit (GTK_OBJECT (calendar),
|
|
|
|
|
gtk_calendar_signals[PREV_MONTH_SIGNAL]);
|
|
|
|
|
gtk_signal_emit (GTK_OBJECT (calendar),
|
|
|
|
|
gtk_calendar_signals[MONTH_CHANGED_SIGNAL]);
|
1998-10-01 13:24:42 +00:00
|
|
|
|
|
1998-09-27 18:32:00 +00:00
|
|
|
|
if (month_len < calendar->selected_day)
|
|
|
|
|
{
|
|
|
|
|
calendar->selected_day = 0;
|
|
|
|
|
gtk_calendar_select_day (calendar, month_len);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (calendar->selected_day < 0)
|
|
|
|
|
calendar->selected_day = calendar->selected_day + 1 + month_length[leap (calendar->year)][calendar->month + 1];
|
|
|
|
|
else
|
|
|
|
|
gtk_calendar_select_day (calendar, calendar->selected_day);
|
|
|
|
|
}
|
1998-10-01 13:24:42 +00:00
|
|
|
|
|
1998-09-27 18:32:00 +00:00
|
|
|
|
gtk_calendar_select_day (calendar, calendar->selected_day);
|
|
|
|
|
gtk_calendar_paint (GTK_WIDGET (calendar), NULL);
|
|
|
|
|
gtk_calendar_thaw (calendar);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
gtk_calendar_set_month_next (GtkCalendar *calendar)
|
|
|
|
|
{
|
|
|
|
|
gint month_len;
|
1998-10-01 13:24:42 +00:00
|
|
|
|
|
1998-09-27 18:32:00 +00:00
|
|
|
|
g_return_if_fail (calendar != NULL);
|
|
|
|
|
g_return_if_fail (GTK_IS_WIDGET (calendar));
|
1998-10-01 13:24:42 +00:00
|
|
|
|
|
1998-09-27 18:32:00 +00:00
|
|
|
|
if (calendar->display_flags & GTK_CALENDAR_NO_MONTH_CHANGE)
|
|
|
|
|
return;
|
1998-10-01 13:24:42 +00:00
|
|
|
|
|
|
|
|
|
|
1998-09-27 18:32:00 +00:00
|
|
|
|
if (calendar->month == 11)
|
|
|
|
|
{
|
|
|
|
|
calendar->month = 0;
|
|
|
|
|
calendar->year++;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
calendar->month++;
|
1998-10-01 13:24:42 +00:00
|
|
|
|
|
1998-09-27 18:32:00 +00:00
|
|
|
|
gtk_calendar_freeze (calendar);
|
|
|
|
|
gtk_calendar_compute_days (calendar);
|
|
|
|
|
gtk_signal_emit (GTK_OBJECT (calendar),
|
|
|
|
|
gtk_calendar_signals[NEXT_MONTH_SIGNAL]);
|
|
|
|
|
gtk_signal_emit (GTK_OBJECT (calendar),
|
|
|
|
|
gtk_calendar_signals[MONTH_CHANGED_SIGNAL]);
|
1998-10-01 13:24:42 +00:00
|
|
|
|
|
1998-09-27 18:32:00 +00:00
|
|
|
|
month_len = month_length[leap (calendar->year)][calendar->month + 1];
|
1998-10-01 13:24:42 +00:00
|
|
|
|
|
1998-09-27 18:32:00 +00:00
|
|
|
|
if (month_len < calendar->selected_day)
|
|
|
|
|
{
|
|
|
|
|
calendar->selected_day = 0;
|
|
|
|
|
gtk_calendar_select_day (calendar, month_len);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
gtk_calendar_select_day (calendar, calendar->selected_day);
|
1998-10-01 13:24:42 +00:00
|
|
|
|
|
1998-09-27 18:32:00 +00:00
|
|
|
|
gtk_calendar_paint (GTK_WIDGET(calendar), NULL);
|
|
|
|
|
gtk_calendar_thaw (calendar);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
gtk_calendar_set_year_prev (GtkCalendar *calendar)
|
|
|
|
|
{
|
|
|
|
|
gint month_len;
|
1998-10-01 13:24:42 +00:00
|
|
|
|
|
1998-09-27 18:32:00 +00:00
|
|
|
|
g_return_if_fail (calendar != NULL);
|
|
|
|
|
g_return_if_fail (GTK_IS_WIDGET (calendar));
|
1998-10-01 13:24:42 +00:00
|
|
|
|
|
1998-09-27 18:32:00 +00:00
|
|
|
|
calendar->year--;
|
|
|
|
|
gtk_calendar_freeze (calendar);
|
|
|
|
|
gtk_calendar_compute_days (calendar);
|
|
|
|
|
gtk_signal_emit (GTK_OBJECT (calendar),
|
|
|
|
|
gtk_calendar_signals[PREV_YEAR_SIGNAL]);
|
|
|
|
|
gtk_signal_emit (GTK_OBJECT (calendar),
|
|
|
|
|
gtk_calendar_signals[MONTH_CHANGED_SIGNAL]);
|
1998-10-01 13:24:42 +00:00
|
|
|
|
|
1998-09-27 18:32:00 +00:00
|
|
|
|
month_len = month_length[leap (calendar->year)][calendar->month + 1];
|
1998-10-01 13:24:42 +00:00
|
|
|
|
|
1998-09-27 18:32:00 +00:00
|
|
|
|
if (month_len < calendar->selected_day)
|
|
|
|
|
{
|
|
|
|
|
calendar->selected_day = 0;
|
|
|
|
|
gtk_calendar_select_day (calendar, month_len);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
gtk_calendar_select_day (calendar, calendar->selected_day);
|
1998-10-01 13:24:42 +00:00
|
|
|
|
|
1998-09-27 18:32:00 +00:00
|
|
|
|
gtk_calendar_paint (GTK_WIDGET (calendar), NULL);
|
|
|
|
|
gtk_calendar_thaw (calendar);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
gtk_calendar_set_year_next (GtkCalendar *calendar)
|
|
|
|
|
{
|
|
|
|
|
gint month_len;
|
|
|
|
|
GtkWidget *widget;
|
1998-10-01 13:24:42 +00:00
|
|
|
|
|
1998-09-27 18:32:00 +00:00
|
|
|
|
g_return_if_fail (calendar != NULL);
|
|
|
|
|
g_return_if_fail (GTK_IS_WIDGET (calendar));
|
1998-10-01 13:24:42 +00:00
|
|
|
|
|
1998-09-27 18:32:00 +00:00
|
|
|
|
widget = GTK_WIDGET (calendar);
|
1998-10-01 13:24:42 +00:00
|
|
|
|
|
1998-09-27 18:32:00 +00:00
|
|
|
|
gtk_calendar_freeze (calendar);
|
1998-10-01 13:24:42 +00:00
|
|
|
|
|
1998-09-27 18:32:00 +00:00
|
|
|
|
calendar->year++;
|
|
|
|
|
gtk_calendar_compute_days (calendar);
|
|
|
|
|
gtk_signal_emit (GTK_OBJECT (calendar),
|
|
|
|
|
gtk_calendar_signals[NEXT_YEAR_SIGNAL]);
|
|
|
|
|
gtk_signal_emit (GTK_OBJECT (calendar),
|
|
|
|
|
gtk_calendar_signals[MONTH_CHANGED_SIGNAL]);
|
1998-10-01 13:24:42 +00:00
|
|
|
|
|
1998-09-27 18:32:00 +00:00
|
|
|
|
month_len = month_length[leap (calendar->year)][calendar->month + 1];
|
1998-10-01 13:24:42 +00:00
|
|
|
|
|
1998-09-27 18:32:00 +00:00
|
|
|
|
if (month_len < calendar->selected_day)
|
|
|
|
|
{
|
|
|
|
|
calendar->selected_day = 0;
|
|
|
|
|
gtk_calendar_select_day (calendar, month_len);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
gtk_calendar_select_day (calendar, calendar->selected_day);
|
1998-10-01 13:24:42 +00:00
|
|
|
|
|
1998-09-27 18:32:00 +00:00
|
|
|
|
gtk_calendar_paint (GTK_WIDGET (calendar), NULL);
|
|
|
|
|
gtk_calendar_thaw (calendar);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
1998-10-01 13:24:42 +00:00
|
|
|
|
gtk_calendar_main_button (GtkWidget *widget,
|
1998-09-27 18:32:00 +00:00
|
|
|
|
GdkEventButton *event)
|
|
|
|
|
{
|
|
|
|
|
GtkCalendar *calendar;
|
|
|
|
|
gint x, y;
|
|
|
|
|
gint row, col;
|
|
|
|
|
gint day_month;
|
1998-10-05 03:52:48 +00:00
|
|
|
|
gint old_focus_row, old_focus_col;
|
1998-10-01 13:24:42 +00:00
|
|
|
|
|
1998-09-27 18:32:00 +00:00
|
|
|
|
calendar = GTK_CALENDAR (widget);
|
1998-10-01 13:24:42 +00:00
|
|
|
|
|
1998-09-27 18:32:00 +00:00
|
|
|
|
x = (gint) (event->x);
|
|
|
|
|
y = (gint) (event->y);
|
1998-10-01 13:24:42 +00:00
|
|
|
|
|
1998-09-27 18:32:00 +00:00
|
|
|
|
row = row_from_y (calendar, y);
|
|
|
|
|
col = column_from_x (calendar, x);
|
1998-10-01 13:24:42 +00:00
|
|
|
|
|
1998-09-27 18:32:00 +00:00
|
|
|
|
day_month = calendar->day_month[row][col];
|
1998-10-01 13:24:42 +00:00
|
|
|
|
|
1998-09-27 18:32:00 +00:00
|
|
|
|
if (day_month == MONTH_CURRENT)
|
|
|
|
|
{
|
|
|
|
|
if (event->type == GDK_2BUTTON_PRESS)
|
|
|
|
|
gtk_signal_emit (GTK_OBJECT (calendar),
|
|
|
|
|
gtk_calendar_signals[DAY_SELECTED_DOUBLE_CLICK_SIGNAL]);
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (!GTK_WIDGET_HAS_FOCUS (widget))
|
|
|
|
|
gtk_widget_grab_focus (widget);
|
1998-10-05 03:52:48 +00:00
|
|
|
|
old_focus_row = calendar->focus_row;
|
|
|
|
|
old_focus_col = calendar->focus_col;
|
|
|
|
|
calendar->focus_row = row;
|
|
|
|
|
calendar->focus_col = col;
|
|
|
|
|
gtk_calendar_paint_day (widget, old_focus_row, old_focus_col);
|
1998-09-27 18:32:00 +00:00
|
|
|
|
gtk_calendar_select_day (calendar, calendar->day[row][col]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if (day_month == MONTH_PREV)
|
|
|
|
|
gtk_calendar_set_month_prev (calendar);
|
|
|
|
|
else if (day_month == MONTH_NEXT)
|
|
|
|
|
gtk_calendar_set_month_next (calendar);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
gtk_calendar_realize_arrows (GtkWidget *widget)
|
|
|
|
|
{
|
|
|
|
|
GtkCalendar *calendar;
|
1998-10-04 23:07:04 +00:00
|
|
|
|
GtkCalendarPrivateData *private_data;
|
1998-09-27 18:32:00 +00:00
|
|
|
|
GdkWindowAttr attributes;
|
|
|
|
|
gint attributes_mask;
|
|
|
|
|
gint i;
|
1998-10-01 13:24:42 +00:00
|
|
|
|
|
1998-09-27 18:32:00 +00:00
|
|
|
|
g_return_if_fail (widget != NULL);
|
|
|
|
|
g_return_if_fail (GTK_IS_CALENDAR (widget));
|
1998-10-01 13:24:42 +00:00
|
|
|
|
|
1998-09-27 18:32:00 +00:00
|
|
|
|
calendar = GTK_CALENDAR (widget);
|
1998-10-04 23:07:04 +00:00
|
|
|
|
private_data = GTK_CALENDAR_PRIVATE_DATA (widget);
|
|
|
|
|
|
1998-09-27 18:32:00 +00:00
|
|
|
|
/* Arrow windows ------------------------------------- */
|
|
|
|
|
if (! (calendar->display_flags & GTK_CALENDAR_NO_MONTH_CHANGE)
|
|
|
|
|
&& (calendar->display_flags & GTK_CALENDAR_SHOW_HEADING))
|
|
|
|
|
{
|
|
|
|
|
attributes.wclass = GDK_INPUT_OUTPUT;
|
|
|
|
|
attributes.window_type = GDK_WINDOW_CHILD;
|
|
|
|
|
attributes.visual = gtk_widget_get_visual (widget);
|
|
|
|
|
attributes.colormap = gtk_widget_get_colormap (widget);
|
|
|
|
|
attributes.event_mask = (gtk_widget_get_events (widget) | GDK_EXPOSURE_MASK
|
|
|
|
|
| GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK
|
|
|
|
|
| GDK_ENTER_NOTIFY_MASK | GDK_LEAVE_NOTIFY_MASK);
|
|
|
|
|
attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
|
|
|
|
|
attributes.y = 3;
|
1998-10-04 23:07:04 +00:00
|
|
|
|
attributes.width = private_data->arrow_width;
|
|
|
|
|
attributes.height = private_data->header_h - 7;
|
1998-09-27 18:32:00 +00:00
|
|
|
|
for (i = 0; i < 4; i++)
|
|
|
|
|
{
|
|
|
|
|
switch (i)
|
|
|
|
|
{
|
|
|
|
|
case ARROW_MONTH_LEFT:
|
|
|
|
|
attributes.x = 3;
|
|
|
|
|
break;
|
|
|
|
|
case ARROW_MONTH_RIGHT:
|
1998-10-04 23:07:04 +00:00
|
|
|
|
attributes.x = (private_data->arrow_width
|
|
|
|
|
+ private_data->max_month_width);
|
1998-09-27 18:32:00 +00:00
|
|
|
|
break;
|
|
|
|
|
case ARROW_YEAR_LEFT:
|
1998-10-04 23:07:04 +00:00
|
|
|
|
attributes.x = (widget->allocation.width - 4
|
|
|
|
|
- (3 + 2*private_data->arrow_width
|
|
|
|
|
+ private_data->max_year_width));
|
1998-09-27 18:32:00 +00:00
|
|
|
|
break;
|
|
|
|
|
case ARROW_YEAR_RIGHT:
|
1998-10-04 23:07:04 +00:00
|
|
|
|
attributes.x = (widget->allocation.width - 4
|
|
|
|
|
- 3 - private_data->arrow_width);
|
1998-09-27 18:32:00 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
1998-10-04 23:07:04 +00:00
|
|
|
|
private_data->arrow_win[i] = gdk_window_new (private_data->header_win,
|
|
|
|
|
&attributes,
|
|
|
|
|
attributes_mask);
|
|
|
|
|
private_data->arrow_state[i] = GTK_STATE_NORMAL;
|
|
|
|
|
gdk_window_set_background (private_data->arrow_win[i],
|
1998-09-27 18:32:00 +00:00
|
|
|
|
HEADER_BG_COLOR (GTK_WIDGET (calendar)));
|
1998-10-04 23:07:04 +00:00
|
|
|
|
gdk_window_show (private_data->arrow_win[i]);
|
|
|
|
|
gdk_window_set_user_data (private_data->arrow_win[i], widget);
|
1998-09-27 18:32:00 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
1998-10-04 23:07:04 +00:00
|
|
|
|
{
|
|
|
|
|
for (i = 0; i < 4; i++)
|
|
|
|
|
private_data->arrow_win[i] = NULL;
|
|
|
|
|
}
|
1998-09-27 18:32:00 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
gtk_calendar_realize_header (GtkWidget *widget)
|
|
|
|
|
{
|
|
|
|
|
GtkCalendar *calendar;
|
1998-10-04 23:07:04 +00:00
|
|
|
|
GtkCalendarPrivateData *private_data;
|
1998-09-27 18:32:00 +00:00
|
|
|
|
GdkWindowAttr attributes;
|
|
|
|
|
gint attributes_mask;
|
1998-10-01 13:24:42 +00:00
|
|
|
|
|
1998-09-27 18:32:00 +00:00
|
|
|
|
g_return_if_fail (widget != NULL);
|
|
|
|
|
g_return_if_fail (GTK_IS_CALENDAR (widget));
|
1998-10-01 13:24:42 +00:00
|
|
|
|
|
1998-09-27 18:32:00 +00:00
|
|
|
|
calendar = GTK_CALENDAR (widget);
|
1998-10-04 23:07:04 +00:00
|
|
|
|
private_data = GTK_CALENDAR_PRIVATE_DATA (widget);
|
|
|
|
|
|
1998-09-27 18:32:00 +00:00
|
|
|
|
/* Header window ------------------------------------- */
|
|
|
|
|
if (calendar->display_flags & GTK_CALENDAR_SHOW_HEADING)
|
|
|
|
|
{
|
|
|
|
|
attributes.wclass = GDK_INPUT_OUTPUT;
|
|
|
|
|
attributes.window_type = GDK_WINDOW_CHILD;
|
|
|
|
|
attributes.visual = gtk_widget_get_visual (widget);
|
|
|
|
|
attributes.colormap = gtk_widget_get_colormap (widget);
|
|
|
|
|
attributes.event_mask = gtk_widget_get_events (widget) | GDK_EXPOSURE_MASK;
|
|
|
|
|
attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
|
1998-10-04 23:07:04 +00:00
|
|
|
|
attributes.x = 2;
|
|
|
|
|
attributes.y = 2;
|
|
|
|
|
attributes.width = widget->allocation.width - 4;
|
|
|
|
|
attributes.height = private_data->header_h;
|
|
|
|
|
private_data->header_win = gdk_window_new (widget->window,
|
1998-09-27 18:32:00 +00:00
|
|
|
|
&attributes, attributes_mask);
|
1998-10-01 13:24:42 +00:00
|
|
|
|
|
1998-10-04 23:07:04 +00:00
|
|
|
|
gdk_window_set_background (private_data->header_win,
|
1998-09-27 18:32:00 +00:00
|
|
|
|
HEADER_BG_COLOR (GTK_WIDGET (calendar)));
|
1998-10-04 23:07:04 +00:00
|
|
|
|
gdk_window_show (private_data->header_win);
|
|
|
|
|
gdk_window_set_user_data (private_data->header_win, widget);
|
1998-10-01 13:24:42 +00:00
|
|
|
|
|
1998-09-27 18:32:00 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
1998-10-04 23:07:04 +00:00
|
|
|
|
{
|
|
|
|
|
private_data->header_win = NULL;
|
|
|
|
|
}
|
1998-09-27 18:32:00 +00:00
|
|
|
|
gtk_calendar_realize_arrows (widget);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
gtk_calendar_realize_day_names (GtkWidget *widget)
|
|
|
|
|
{
|
|
|
|
|
GtkCalendar *calendar;
|
1998-10-04 23:07:04 +00:00
|
|
|
|
GtkCalendarPrivateData *private_data;
|
1998-09-27 18:32:00 +00:00
|
|
|
|
GdkWindowAttr attributes;
|
|
|
|
|
gint attributes_mask;
|
1998-10-01 13:24:42 +00:00
|
|
|
|
|
1998-09-27 18:32:00 +00:00
|
|
|
|
g_return_if_fail (widget != NULL);
|
|
|
|
|
g_return_if_fail (GTK_IS_CALENDAR (widget));
|
1998-10-01 13:24:42 +00:00
|
|
|
|
|
1998-09-27 18:32:00 +00:00
|
|
|
|
calendar = GTK_CALENDAR (widget);
|
1998-10-04 23:07:04 +00:00
|
|
|
|
private_data = GTK_CALENDAR_PRIVATE_DATA (widget);
|
|
|
|
|
|
1998-10-01 13:24:42 +00:00
|
|
|
|
/* Day names window --------------------------------- */
|
1998-09-27 18:32:00 +00:00
|
|
|
|
if ( calendar->display_flags & GTK_CALENDAR_SHOW_DAY_NAMES)
|
|
|
|
|
{
|
|
|
|
|
attributes.wclass = GDK_INPUT_OUTPUT;
|
|
|
|
|
attributes.window_type = GDK_WINDOW_CHILD;
|
|
|
|
|
attributes.visual = gtk_widget_get_visual (widget);
|
|
|
|
|
attributes.colormap = gtk_widget_get_colormap (widget);
|
|
|
|
|
attributes.event_mask = gtk_widget_get_events (widget) | GDK_EXPOSURE_MASK;
|
|
|
|
|
attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
|
|
|
|
|
attributes.x = (widget->style->klass->xthickness + INNER_BORDER);
|
1998-10-04 23:07:04 +00:00
|
|
|
|
attributes.y = private_data->header_h + (widget->style->klass->ythickness
|
|
|
|
|
+ INNER_BORDER);
|
|
|
|
|
attributes.width = (widget->allocation.width
|
|
|
|
|
- (widget->style->klass->xthickness + INNER_BORDER)
|
|
|
|
|
* 2);
|
|
|
|
|
attributes.height = private_data->day_name_h;
|
|
|
|
|
private_data->day_name_win = gdk_window_new (widget->window,
|
|
|
|
|
&attributes,
|
|
|
|
|
attributes_mask);
|
|
|
|
|
gdk_window_set_background (private_data->day_name_win,
|
|
|
|
|
BACKGROUND_COLOR ( GTK_WIDGET ( calendar)));
|
|
|
|
|
gdk_window_show (private_data->day_name_win);
|
|
|
|
|
gdk_window_set_user_data (private_data->day_name_win, widget);
|
1998-09-27 18:32:00 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
1998-10-04 23:07:04 +00:00
|
|
|
|
{
|
|
|
|
|
private_data->day_name_win = NULL;
|
|
|
|
|
}
|
1998-09-27 18:32:00 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
gtk_calendar_realize_week_numbers (GtkWidget *widget)
|
|
|
|
|
{
|
|
|
|
|
GtkCalendar *calendar;
|
1998-10-04 23:07:04 +00:00
|
|
|
|
GtkCalendarPrivateData *private_data;
|
1998-09-27 18:32:00 +00:00
|
|
|
|
GdkWindowAttr attributes;
|
|
|
|
|
gint attributes_mask;
|
1998-10-01 13:24:42 +00:00
|
|
|
|
|
1998-09-27 18:32:00 +00:00
|
|
|
|
g_return_if_fail (widget != NULL);
|
|
|
|
|
g_return_if_fail (GTK_IS_CALENDAR (widget));
|
1998-10-01 13:24:42 +00:00
|
|
|
|
|
1998-09-27 18:32:00 +00:00
|
|
|
|
calendar = GTK_CALENDAR (widget);
|
1998-10-04 23:07:04 +00:00
|
|
|
|
private_data = GTK_CALENDAR_PRIVATE_DATA (widget);
|
|
|
|
|
|
1998-09-27 18:32:00 +00:00
|
|
|
|
/* Week number window -------------------------------- */
|
|
|
|
|
if (calendar->display_flags & GTK_CALENDAR_SHOW_WEEK_NUMBERS)
|
|
|
|
|
{
|
|
|
|
|
attributes.wclass = GDK_INPUT_OUTPUT;
|
|
|
|
|
attributes.window_type = GDK_WINDOW_CHILD;
|
|
|
|
|
attributes.visual = gtk_widget_get_visual (widget);
|
|
|
|
|
attributes.colormap = gtk_widget_get_colormap (widget);
|
|
|
|
|
attributes.event_mask = gtk_widget_get_events (widget) | GDK_EXPOSURE_MASK;
|
1998-10-01 13:24:42 +00:00
|
|
|
|
|
1998-09-27 18:32:00 +00:00
|
|
|
|
attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
|
|
|
|
|
attributes.x = + (widget->style->klass->xthickness + INNER_BORDER);
|
1998-10-04 23:07:04 +00:00
|
|
|
|
attributes.y = (private_data->header_h + private_data->day_name_h
|
1998-09-27 18:32:00 +00:00
|
|
|
|
+ (widget->style->klass->ythickness + INNER_BORDER));
|
1998-10-04 23:07:04 +00:00
|
|
|
|
attributes.width = private_data->week_width;
|
|
|
|
|
attributes.height = private_data->main_h;
|
|
|
|
|
private_data->week_win = gdk_window_new (widget->window,
|
|
|
|
|
&attributes, attributes_mask);
|
|
|
|
|
gdk_window_set_background (private_data->week_win,
|
|
|
|
|
BACKGROUND_COLOR (GTK_WIDGET (calendar)));
|
|
|
|
|
gdk_window_show (private_data->week_win);
|
|
|
|
|
gdk_window_set_user_data (private_data->week_win, widget);
|
1998-09-27 18:32:00 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
1998-10-04 23:07:04 +00:00
|
|
|
|
{
|
|
|
|
|
private_data->week_win = NULL;
|
|
|
|
|
}
|
1998-09-27 18:32:00 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
gtk_calendar_realize (GtkWidget *widget)
|
|
|
|
|
{
|
|
|
|
|
GtkCalendar *calendar;
|
1998-10-04 23:07:04 +00:00
|
|
|
|
GtkCalendarPrivateData *private_data;
|
1998-09-27 18:32:00 +00:00
|
|
|
|
GdkWindowAttr attributes;
|
|
|
|
|
gint attributes_mask;
|
1998-10-05 03:52:48 +00:00
|
|
|
|
GdkGCValues values;
|
|
|
|
|
|
1998-09-27 18:32:00 +00:00
|
|
|
|
g_return_if_fail (widget != NULL);
|
|
|
|
|
g_return_if_fail (GTK_IS_CALENDAR (widget));
|
1998-10-01 13:24:42 +00:00
|
|
|
|
|
1998-09-27 18:32:00 +00:00
|
|
|
|
calendar = GTK_CALENDAR (widget);
|
1998-10-04 23:07:04 +00:00
|
|
|
|
private_data = GTK_CALENDAR_PRIVATE_DATA (widget);
|
1998-10-01 13:24:42 +00:00
|
|
|
|
|
1998-09-27 18:32:00 +00:00
|
|
|
|
GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED);
|
|
|
|
|
gtk_calendar_compute_days (calendar);
|
1998-10-01 13:24:42 +00:00
|
|
|
|
|
1998-09-27 18:32:00 +00:00
|
|
|
|
attributes.x = widget->allocation.x;
|
|
|
|
|
attributes.y = widget->allocation.y;
|
|
|
|
|
attributes.width = widget->allocation.width;
|
|
|
|
|
attributes.height = widget->allocation.height;
|
|
|
|
|
attributes.wclass = GDK_INPUT_OUTPUT;
|
|
|
|
|
attributes.window_type = GDK_WINDOW_CHILD;
|
|
|
|
|
attributes.event_mask = (gtk_widget_get_events (widget)
|
|
|
|
|
| GDK_EXPOSURE_MASK |GDK_KEY_PRESS_MASK);
|
|
|
|
|
attributes.visual = gtk_widget_get_visual (widget);
|
|
|
|
|
attributes.colormap = gtk_widget_get_colormap (widget);
|
1998-10-01 13:24:42 +00:00
|
|
|
|
|
1998-09-27 18:32:00 +00:00
|
|
|
|
attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
|
|
|
|
|
widget->window = gdk_window_new (widget->parent->window,
|
|
|
|
|
&attributes, attributes_mask);
|
1998-10-01 13:24:42 +00:00
|
|
|
|
|
1998-09-27 18:32:00 +00:00
|
|
|
|
widget->style = gtk_style_attach (widget->style, widget->window);
|
1998-10-01 13:24:42 +00:00
|
|
|
|
|
1998-09-27 18:32:00 +00:00
|
|
|
|
/* Header window ------------------------------------- */
|
|
|
|
|
gtk_calendar_realize_header (widget);
|
1998-10-01 13:24:42 +00:00
|
|
|
|
/* Day names window --------------------------------- */
|
1998-09-27 18:32:00 +00:00
|
|
|
|
gtk_calendar_realize_day_names (widget);
|
|
|
|
|
/* Week number window -------------------------------- */
|
|
|
|
|
gtk_calendar_realize_week_numbers (widget);
|
1998-10-01 13:24:42 +00:00
|
|
|
|
/* Main Window -------------------------------------- */
|
1998-09-27 18:32:00 +00:00
|
|
|
|
attributes.event_mask = (gtk_widget_get_events (widget) | GDK_EXPOSURE_MASK
|
|
|
|
|
| GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK
|
|
|
|
|
| GDK_POINTER_MOTION_MASK | GDK_LEAVE_NOTIFY_MASK);
|
1998-10-01 13:24:42 +00:00
|
|
|
|
|
1998-09-27 18:32:00 +00:00
|
|
|
|
if (calendar->display_flags & GTK_CALENDAR_SHOW_WEEK_NUMBERS)
|
1998-10-04 23:07:04 +00:00
|
|
|
|
attributes.x = private_data->week_width;
|
1998-09-27 18:32:00 +00:00
|
|
|
|
else
|
|
|
|
|
attributes.x = 0;
|
|
|
|
|
attributes.x += (widget->style->klass->xthickness + INNER_BORDER);
|
1998-10-04 23:07:04 +00:00
|
|
|
|
attributes.y = (private_data->header_h + private_data->day_name_h
|
|
|
|
|
+ (widget->style->klass->ythickness + INNER_BORDER));
|
|
|
|
|
attributes.width = (widget->allocation.width - attributes.x
|
|
|
|
|
- (widget->style->klass->xthickness + INNER_BORDER));
|
|
|
|
|
attributes.height = private_data->main_h;
|
|
|
|
|
private_data->main_win = gdk_window_new (widget->window,
|
|
|
|
|
&attributes, attributes_mask);
|
|
|
|
|
gdk_window_set_background (private_data->main_win,
|
|
|
|
|
BACKGROUND_COLOR ( GTK_WIDGET ( calendar)));
|
|
|
|
|
gdk_window_show (private_data->main_win);
|
|
|
|
|
gdk_window_set_user_data (private_data->main_win, widget);
|
1998-09-27 18:32:00 +00:00
|
|
|
|
gdk_window_set_background (widget->window, BACKGROUND_COLOR (widget));
|
|
|
|
|
gdk_window_show (widget->window);
|
|
|
|
|
gdk_window_set_user_data (widget->window, widget);
|
1998-10-01 13:24:42 +00:00
|
|
|
|
|
1998-09-27 18:32:00 +00:00
|
|
|
|
/* Set widgets gc */
|
|
|
|
|
calendar->gc = gdk_gc_new (widget->window);
|
1998-10-05 03:52:48 +00:00
|
|
|
|
|
|
|
|
|
values.foreground = widget->style->white;
|
|
|
|
|
values.function = GDK_XOR;
|
|
|
|
|
calendar->xor_gc = gdk_gc_new_with_values (widget->window,
|
|
|
|
|
&values,
|
|
|
|
|
GDK_GC_FOREGROUND |
|
|
|
|
|
GDK_GC_FUNCTION);
|
1998-09-27 18:32:00 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
gtk_calendar_unrealize (GtkWidget *widget)
|
|
|
|
|
{
|
|
|
|
|
GtkCalendar *calendar;
|
1998-10-04 23:07:04 +00:00
|
|
|
|
GtkCalendarPrivateData *private_data;
|
1998-09-27 18:32:00 +00:00
|
|
|
|
gint i;
|
1998-10-01 13:24:42 +00:00
|
|
|
|
|
1998-09-27 18:32:00 +00:00
|
|
|
|
g_return_if_fail (widget != NULL);
|
|
|
|
|
g_return_if_fail (GTK_IS_CALENDAR (widget));
|
1998-10-01 13:24:42 +00:00
|
|
|
|
|
1998-09-27 18:32:00 +00:00
|
|
|
|
calendar = GTK_CALENDAR (widget);
|
1998-10-04 23:07:04 +00:00
|
|
|
|
private_data = GTK_CALENDAR_PRIVATE_DATA (widget);
|
1998-10-01 13:24:42 +00:00
|
|
|
|
|
1998-10-04 23:07:04 +00:00
|
|
|
|
if (private_data->header_win)
|
1998-09-27 18:32:00 +00:00
|
|
|
|
{
|
1998-10-04 23:07:04 +00:00
|
|
|
|
for (i = 0; i < 4; i++)
|
|
|
|
|
{
|
|
|
|
|
if (private_data->arrow_win[i])
|
|
|
|
|
{
|
|
|
|
|
gdk_window_set_user_data (private_data->arrow_win[i], NULL);
|
|
|
|
|
gdk_window_destroy (private_data->arrow_win[i]);
|
|
|
|
|
private_data->arrow_win[i] = NULL;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
gdk_window_set_user_data (private_data->header_win, NULL);
|
|
|
|
|
gdk_window_destroy (private_data->header_win);
|
|
|
|
|
private_data->header_win = NULL;
|
1998-09-27 18:32:00 +00:00
|
|
|
|
}
|
1998-10-01 13:24:42 +00:00
|
|
|
|
|
1998-10-04 23:07:04 +00:00
|
|
|
|
if (private_data->week_win)
|
1998-09-27 18:32:00 +00:00
|
|
|
|
{
|
1998-10-04 23:07:04 +00:00
|
|
|
|
gdk_window_set_user_data (private_data->week_win, NULL);
|
|
|
|
|
gdk_window_destroy (private_data->week_win);
|
|
|
|
|
private_data->week_win = NULL;
|
1998-09-27 18:32:00 +00:00
|
|
|
|
}
|
1998-10-01 13:24:42 +00:00
|
|
|
|
|
1998-10-04 23:07:04 +00:00
|
|
|
|
if (private_data->main_win)
|
1998-09-27 18:32:00 +00:00
|
|
|
|
{
|
1998-10-04 23:07:04 +00:00
|
|
|
|
gdk_window_set_user_data (private_data->main_win, NULL);
|
|
|
|
|
gdk_window_destroy (private_data->main_win);
|
|
|
|
|
private_data->main_win = NULL;
|
1998-09-27 18:32:00 +00:00
|
|
|
|
}
|
1998-10-01 13:24:42 +00:00
|
|
|
|
|
1998-09-27 18:32:00 +00:00
|
|
|
|
if (GTK_WIDGET_CLASS (parent_class)->unrealize)
|
|
|
|
|
(* GTK_WIDGET_CLASS (parent_class)->unrealize) (widget);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
1998-10-01 13:24:42 +00:00
|
|
|
|
gtk_calendar_size_request (GtkWidget *widget,
|
1998-09-27 18:32:00 +00:00
|
|
|
|
GtkRequisition *requisition)
|
|
|
|
|
{
|
|
|
|
|
GtkCalendar *calendar;
|
1998-10-04 23:07:04 +00:00
|
|
|
|
GtkCalendarPrivateData *private_data;
|
|
|
|
|
|
1998-09-27 18:32:00 +00:00
|
|
|
|
gint height;
|
|
|
|
|
gint i;
|
|
|
|
|
gchar buffer[255];
|
|
|
|
|
gint calendar_margin = CALENDAR_MARGIN;
|
|
|
|
|
gint header_width, main_width;
|
|
|
|
|
gint lbearing;
|
|
|
|
|
gint rbearing;
|
|
|
|
|
gint ascent;
|
|
|
|
|
gint descent;
|
|
|
|
|
gint width;
|
1998-10-01 13:24:42 +00:00
|
|
|
|
|
1998-09-27 18:32:00 +00:00
|
|
|
|
calendar = GTK_CALENDAR (widget);
|
1998-10-04 23:07:04 +00:00
|
|
|
|
private_data = GTK_CALENDAR_PRIVATE_DATA (widget);
|
1998-10-01 13:24:42 +00:00
|
|
|
|
|
1998-09-27 18:32:00 +00:00
|
|
|
|
/*
|
1998-10-01 13:24:42 +00:00
|
|
|
|
* Calculate the requisition width for the widget.
|
1998-09-27 18:32:00 +00:00
|
|
|
|
*/
|
1998-10-01 13:24:42 +00:00
|
|
|
|
|
1998-09-27 18:32:00 +00:00
|
|
|
|
/* Header width */
|
1998-10-01 13:24:42 +00:00
|
|
|
|
|
1998-09-27 18:32:00 +00:00
|
|
|
|
if (calendar->display_flags & GTK_CALENDAR_SHOW_HEADING)
|
|
|
|
|
{
|
1998-10-04 23:07:04 +00:00
|
|
|
|
private_data->max_month_width = 0;
|
1998-09-27 18:32:00 +00:00
|
|
|
|
for (i = 0; i < 12; i++)
|
1998-10-04 23:07:04 +00:00
|
|
|
|
{
|
|
|
|
|
private_data->max_month_width = MAX (private_data->max_month_width,
|
|
|
|
|
gdk_string_measure (HEADER_FONT (widget),
|
|
|
|
|
default_monthname[i]) + 8);
|
|
|
|
|
}
|
|
|
|
|
private_data->max_year_width = 0;
|
1998-09-27 18:32:00 +00:00
|
|
|
|
for (i=0; i<10; i++)
|
|
|
|
|
{
|
|
|
|
|
sprintf (buffer, "%d%d%d%d", i,i,i,i);
|
1998-10-04 23:07:04 +00:00
|
|
|
|
private_data->max_year_width = MAX (private_data->max_year_width,
|
|
|
|
|
gdk_string_measure (HEADER_FONT (widget),
|
|
|
|
|
buffer) + 8);
|
1998-09-27 18:32:00 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
1998-10-04 23:07:04 +00:00
|
|
|
|
private_data->max_month_width = 0;
|
|
|
|
|
private_data->max_year_width = 0;
|
1998-09-27 18:32:00 +00:00
|
|
|
|
}
|
1998-10-01 13:24:42 +00:00
|
|
|
|
|
1998-09-27 18:32:00 +00:00
|
|
|
|
if (calendar->display_flags & GTK_CALENDAR_NO_MONTH_CHANGE)
|
1998-10-04 23:07:04 +00:00
|
|
|
|
header_width = (private_data->max_month_width
|
|
|
|
|
+ private_data->max_year_width
|
1998-09-27 18:32:00 +00:00
|
|
|
|
+ 3 * 3);
|
|
|
|
|
else
|
1998-10-04 23:07:04 +00:00
|
|
|
|
header_width = (private_data->max_month_width
|
|
|
|
|
+ private_data->max_year_width
|
|
|
|
|
+ 4 * private_data->arrow_width + 3 * 3);
|
|
|
|
|
|
1998-09-27 18:32:00 +00:00
|
|
|
|
/* Mainwindow labels width */
|
1998-10-01 13:24:42 +00:00
|
|
|
|
|
1998-10-04 23:07:04 +00:00
|
|
|
|
private_data->max_day_char_width = 0;
|
1998-09-27 18:32:00 +00:00
|
|
|
|
for (i = 0; i < 9; i++)
|
|
|
|
|
{
|
|
|
|
|
sprintf (buffer, "%d%d", i, i);
|
1998-10-04 23:07:04 +00:00
|
|
|
|
private_data->min_day_width = MAX (private_data->max_day_char_width,
|
1998-09-27 18:32:00 +00:00
|
|
|
|
gdk_string_measure (DAY_FONT (widget),
|
|
|
|
|
buffer));
|
|
|
|
|
}
|
|
|
|
|
/* We add one to max_day_char_width to be able to make the marked day "bold" */
|
1998-10-04 23:07:04 +00:00
|
|
|
|
private_data->max_day_char_width = private_data->min_day_width / 2 +1;
|
1998-10-01 13:24:42 +00:00
|
|
|
|
|
1998-09-27 18:32:00 +00:00
|
|
|
|
if (calendar->display_flags & GTK_CALENDAR_SHOW_DAY_NAMES)
|
|
|
|
|
for (i = 0; i < 7; i++)
|
|
|
|
|
{
|
|
|
|
|
gdk_text_extents (LABEL_FONT (widget),
|
|
|
|
|
default_abbreviated_dayname[i],
|
|
|
|
|
strlen(default_abbreviated_dayname[i]),
|
|
|
|
|
&lbearing,
|
|
|
|
|
&rbearing,
|
|
|
|
|
&width,
|
|
|
|
|
&ascent,
|
|
|
|
|
&descent);
|
1998-10-04 23:07:04 +00:00
|
|
|
|
private_data->min_day_width = MAX (private_data->min_day_width, width);
|
|
|
|
|
private_data->max_label_char_ascent = MAX (private_data->max_label_char_ascent,
|
1998-09-27 18:32:00 +00:00
|
|
|
|
ascent);
|
1998-10-04 23:07:04 +00:00
|
|
|
|
private_data->max_label_char_descent = MAX (private_data->max_label_char_descent,
|
|
|
|
|
descent);
|
1998-09-27 18:32:00 +00:00
|
|
|
|
}
|
1998-10-01 13:24:42 +00:00
|
|
|
|
|
1998-10-04 23:07:04 +00:00
|
|
|
|
private_data->max_week_char_width = 0;
|
1998-09-27 18:32:00 +00:00
|
|
|
|
if (calendar->display_flags & GTK_CALENDAR_SHOW_WEEK_NUMBERS)
|
|
|
|
|
for (i = 0; i < 9; i++)
|
|
|
|
|
{
|
|
|
|
|
sprintf (buffer, "%d%d", i, i);
|
1998-10-04 23:07:04 +00:00
|
|
|
|
private_data->max_week_char_width = MAX (private_data->max_week_char_width,
|
1998-09-27 18:32:00 +00:00
|
|
|
|
gdk_string_measure (LABEL_FONT (widget), buffer) / 2);
|
|
|
|
|
}
|
1998-10-01 13:24:42 +00:00
|
|
|
|
|
1998-10-04 23:07:04 +00:00
|
|
|
|
main_width = (7 * (private_data->min_day_width + DAY_XPAD * 2) + (DAY_XSEP * 6) + CALENDAR_MARGIN * 2
|
|
|
|
|
+ (private_data->max_week_char_width
|
|
|
|
|
? private_data->max_week_char_width * 2 + DAY_XPAD * 2 + CALENDAR_XSEP * 2
|
1998-09-27 18:32:00 +00:00
|
|
|
|
: 0));
|
1998-10-01 13:24:42 +00:00
|
|
|
|
|
|
|
|
|
|
1998-10-04 23:07:04 +00:00
|
|
|
|
requisition->width = MAX (header_width+4, main_width + (widget->style->klass->xthickness + INNER_BORDER) *2);
|
1998-10-01 13:24:42 +00:00
|
|
|
|
|
1998-09-27 18:32:00 +00:00
|
|
|
|
/*
|
|
|
|
|
* Calculate the requisition height for the widget.
|
|
|
|
|
*/
|
1998-10-01 13:24:42 +00:00
|
|
|
|
|
1998-09-27 18:32:00 +00:00
|
|
|
|
if (calendar->display_flags & GTK_CALENDAR_SHOW_HEADING)
|
1998-10-04 23:07:04 +00:00
|
|
|
|
{
|
|
|
|
|
private_data->header_h = (HEADER_FONT (widget)->ascent
|
|
|
|
|
+ HEADER_FONT (widget)->descent
|
|
|
|
|
+ CALENDAR_YSEP * 2);
|
|
|
|
|
}
|
1998-09-27 18:32:00 +00:00
|
|
|
|
else
|
1998-10-04 23:07:04 +00:00
|
|
|
|
{
|
|
|
|
|
private_data->header_h = 0;
|
|
|
|
|
}
|
1998-10-01 13:24:42 +00:00
|
|
|
|
|
1998-09-27 18:32:00 +00:00
|
|
|
|
if (calendar->display_flags & GTK_CALENDAR_SHOW_DAY_NAMES)
|
|
|
|
|
{
|
1998-10-04 23:07:04 +00:00
|
|
|
|
private_data->day_name_h = (private_data->max_label_char_ascent
|
|
|
|
|
+ private_data->max_label_char_descent
|
|
|
|
|
+ 2 * DAY_YPAD + calendar_margin);
|
1998-09-27 18:32:00 +00:00
|
|
|
|
calendar_margin = CALENDAR_YSEP;
|
|
|
|
|
}
|
|
|
|
|
else
|
1998-10-04 23:07:04 +00:00
|
|
|
|
{
|
|
|
|
|
private_data->day_name_h = 0;
|
|
|
|
|
}
|
|
|
|
|
|
1998-09-27 18:32:00 +00:00
|
|
|
|
gdk_text_extents (DAY_FONT (widget),
|
1998-10-01 13:24:42 +00:00
|
|
|
|
"0123456789",
|
|
|
|
|
10,
|
|
|
|
|
&lbearing,
|
|
|
|
|
&rbearing,
|
|
|
|
|
&width,
|
1998-10-04 23:07:04 +00:00
|
|
|
|
&private_data->max_day_char_ascent,
|
|
|
|
|
&private_data->max_day_char_descent);
|
1998-10-01 13:24:42 +00:00
|
|
|
|
|
1998-10-04 23:07:04 +00:00
|
|
|
|
private_data->main_h = (CALENDAR_MARGIN + calendar_margin
|
|
|
|
|
+ 6 * (private_data->max_day_char_ascent
|
|
|
|
|
+ private_data->max_day_char_descent
|
|
|
|
|
+ DAY_YPAD * 2)
|
|
|
|
|
+ DAY_YSEP * 5);
|
1998-10-01 13:24:42 +00:00
|
|
|
|
|
1998-09-27 18:32:00 +00:00
|
|
|
|
/*
|
|
|
|
|
* If we display weeknumbers we need some extra space
|
|
|
|
|
*/
|
1998-10-01 13:24:42 +00:00
|
|
|
|
|
1998-09-27 18:32:00 +00:00
|
|
|
|
if (calendar->display_flags & GTK_CALENDAR_SHOW_WEEK_NUMBERS)
|
1998-10-04 23:07:04 +00:00
|
|
|
|
{
|
|
|
|
|
private_data->main_h = MAX (private_data->main_h,
|
|
|
|
|
(CALENDAR_MARGIN + calendar_margin
|
|
|
|
|
+ 6 * (private_data->max_day_char_ascent
|
|
|
|
|
+ private_data->max_day_char_descent
|
|
|
|
|
+ DAY_YPAD * 2)
|
|
|
|
|
+ DAY_YSEP * 5));
|
|
|
|
|
}
|
1998-10-01 13:24:42 +00:00
|
|
|
|
|
1998-10-04 23:07:04 +00:00
|
|
|
|
height = (private_data->header_h + private_data->day_name_h
|
|
|
|
|
+ private_data->main_h);
|
1998-10-01 13:24:42 +00:00
|
|
|
|
|
1998-09-27 18:32:00 +00:00
|
|
|
|
requisition->height = height + (widget->style->klass->ythickness + INNER_BORDER) * 2;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
1998-10-01 13:24:42 +00:00
|
|
|
|
gtk_calendar_size_allocate (GtkWidget *widget,
|
1998-09-27 18:32:00 +00:00
|
|
|
|
GtkAllocation *allocation)
|
|
|
|
|
{
|
|
|
|
|
GtkCalendar *calendar;
|
1998-10-04 23:07:04 +00:00
|
|
|
|
GtkCalendarPrivateData *private_data;
|
1998-10-01 13:24:42 +00:00
|
|
|
|
|
1998-09-27 18:32:00 +00:00
|
|
|
|
g_return_if_fail (widget != NULL);
|
|
|
|
|
g_return_if_fail (GTK_IS_CALENDAR (widget));
|
|
|
|
|
g_return_if_fail (allocation != NULL);
|
1998-10-01 13:24:42 +00:00
|
|
|
|
|
1998-09-27 18:32:00 +00:00
|
|
|
|
widget->allocation = *allocation;
|
1998-10-01 13:24:42 +00:00
|
|
|
|
|
1998-09-27 18:32:00 +00:00
|
|
|
|
calendar = GTK_CALENDAR (widget);
|
1998-10-04 23:07:04 +00:00
|
|
|
|
private_data = GTK_CALENDAR_PRIVATE_DATA (widget);
|
1998-10-01 13:24:42 +00:00
|
|
|
|
|
1998-09-27 18:32:00 +00:00
|
|
|
|
if (calendar->display_flags & GTK_CALENDAR_SHOW_WEEK_NUMBERS)
|
|
|
|
|
{
|
1998-10-04 23:07:04 +00:00
|
|
|
|
private_data->day_width = (private_data->min_day_width
|
1998-09-27 18:32:00 +00:00
|
|
|
|
* ((allocation->width - (widget->style->klass->xthickness + INNER_BORDER) * 2
|
|
|
|
|
- (CALENDAR_MARGIN * 2) - (DAY_XSEP * 7) - CALENDAR_XSEP * 2))
|
1998-10-04 23:07:04 +00:00
|
|
|
|
/ (7 * private_data->min_day_width + private_data->max_week_char_width * 2));
|
|
|
|
|
private_data->week_width = ((allocation->width - (widget->style->klass->xthickness + INNER_BORDER) * 2
|
1998-09-27 18:32:00 +00:00
|
|
|
|
- (CALENDAR_MARGIN * 2) - (DAY_XSEP * 7) - CALENDAR_XSEP * 2 )
|
1998-10-04 23:07:04 +00:00
|
|
|
|
- private_data->day_width * 7 + CALENDAR_MARGIN + CALENDAR_XSEP);
|
1998-09-27 18:32:00 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
1998-10-04 23:07:04 +00:00
|
|
|
|
private_data->day_width = (allocation->width
|
1998-09-27 18:32:00 +00:00
|
|
|
|
- (widget->style->klass->xthickness + INNER_BORDER) * 2
|
|
|
|
|
- (CALENDAR_MARGIN * 2)
|
|
|
|
|
- (DAY_XSEP * 7))/7;
|
1998-10-04 23:07:04 +00:00
|
|
|
|
private_data->week_width = 0;
|
1998-09-27 18:32:00 +00:00
|
|
|
|
}
|
1998-10-01 13:24:42 +00:00
|
|
|
|
|
1998-09-27 18:32:00 +00:00
|
|
|
|
if (GTK_WIDGET_REALIZED (widget))
|
|
|
|
|
{
|
|
|
|
|
gdk_window_move_resize (widget->window,
|
|
|
|
|
allocation->x, allocation->y,
|
1998-10-01 13:24:42 +00:00
|
|
|
|
allocation->width, allocation->height);
|
1998-10-04 23:07:04 +00:00
|
|
|
|
if (private_data->header_win)
|
|
|
|
|
gdk_window_move_resize (private_data->header_win,
|
|
|
|
|
2, 2,
|
|
|
|
|
allocation->width-4, private_data->header_h);
|
|
|
|
|
if (private_data->arrow_win[ARROW_MONTH_LEFT])
|
|
|
|
|
gdk_window_move_resize (private_data->arrow_win[ARROW_MONTH_LEFT],
|
1998-09-27 18:32:00 +00:00
|
|
|
|
3, 3,
|
1998-10-04 23:07:04 +00:00
|
|
|
|
private_data->arrow_width,
|
|
|
|
|
private_data->header_h - 7);
|
|
|
|
|
if (private_data->arrow_win[ARROW_MONTH_RIGHT])
|
|
|
|
|
gdk_window_move_resize (private_data->arrow_win[ARROW_MONTH_RIGHT],
|
|
|
|
|
(private_data->arrow_width
|
|
|
|
|
+ private_data->max_month_width),
|
1998-09-27 18:32:00 +00:00
|
|
|
|
3,
|
1998-10-04 23:07:04 +00:00
|
|
|
|
private_data->arrow_width,
|
|
|
|
|
private_data->header_h - 7);
|
|
|
|
|
if (private_data->arrow_win[ARROW_YEAR_LEFT])
|
|
|
|
|
gdk_window_move_resize (private_data->arrow_win[ARROW_YEAR_LEFT],
|
|
|
|
|
(allocation->width - 4
|
|
|
|
|
- (3 + 2*private_data->arrow_width
|
|
|
|
|
+ private_data->max_year_width)),
|
|
|
|
|
3,
|
|
|
|
|
private_data->arrow_width,
|
|
|
|
|
private_data->header_h - 7);
|
|
|
|
|
if (private_data->arrow_win[ARROW_YEAR_RIGHT])
|
|
|
|
|
gdk_window_move_resize (private_data->arrow_win[ARROW_YEAR_RIGHT],
|
|
|
|
|
(allocation->width - 4
|
|
|
|
|
- 3 - private_data->arrow_width),
|
|
|
|
|
3,
|
|
|
|
|
private_data->arrow_width,
|
|
|
|
|
private_data->header_h - 7);
|
|
|
|
|
if (private_data->day_name_win)
|
|
|
|
|
gdk_window_move_resize (private_data->day_name_win,
|
|
|
|
|
widget->style->klass->xthickness + INNER_BORDER,
|
|
|
|
|
private_data->header_h + (widget->style->klass->ythickness + INNER_BORDER),
|
1998-09-27 18:32:00 +00:00
|
|
|
|
allocation->width - (widget->style->klass->xthickness + INNER_BORDER) * 2,
|
1998-10-04 23:07:04 +00:00
|
|
|
|
private_data->day_name_h);
|
|
|
|
|
if (private_data->week_win)
|
|
|
|
|
gdk_window_move_resize (private_data->week_win,
|
1998-09-27 18:32:00 +00:00
|
|
|
|
(widget->style->klass->xthickness + INNER_BORDER),
|
1998-10-04 23:07:04 +00:00
|
|
|
|
private_data->header_h + private_data->day_name_h
|
1998-09-27 18:32:00 +00:00
|
|
|
|
+ (widget->style->klass->ythickness + INNER_BORDER),
|
1998-10-04 23:07:04 +00:00
|
|
|
|
private_data->week_width,
|
|
|
|
|
private_data->main_h);
|
|
|
|
|
gdk_window_move_resize (private_data->main_win,
|
|
|
|
|
(private_data->week_width ? private_data->week_width + CALENDAR_XSEP :0)
|
1998-09-27 18:32:00 +00:00
|
|
|
|
+ (widget->style->klass->xthickness + INNER_BORDER),
|
1998-10-04 23:07:04 +00:00
|
|
|
|
private_data->header_h + private_data->day_name_h
|
1998-09-27 18:32:00 +00:00
|
|
|
|
+ (widget->style->klass->ythickness + INNER_BORDER),
|
|
|
|
|
allocation->width
|
1998-10-04 23:07:04 +00:00
|
|
|
|
- (private_data->week_width ? private_data->week_width + CALENDAR_XSEP :0)
|
1998-09-27 18:32:00 +00:00
|
|
|
|
- (widget->style->klass->xthickness + INNER_BORDER) * 2,
|
1998-10-04 23:07:04 +00:00
|
|
|
|
private_data->main_h);
|
1998-09-27 18:32:00 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
gtk_calendar_draw_focus (GtkWidget *widget)
|
|
|
|
|
{
|
1998-10-04 23:07:04 +00:00
|
|
|
|
GtkCalendar *calendar;
|
|
|
|
|
GtkCalendarPrivateData *private_data;
|
1998-09-27 18:32:00 +00:00
|
|
|
|
gint width, height;
|
|
|
|
|
gint x, y;
|
|
|
|
|
|
|
|
|
|
g_return_if_fail (widget != NULL);
|
|
|
|
|
g_return_if_fail (GTK_IS_CALENDAR (widget));
|
1998-10-04 23:07:04 +00:00
|
|
|
|
|
1998-09-27 18:32:00 +00:00
|
|
|
|
calendar = GTK_CALENDAR (widget);
|
1998-10-04 23:07:04 +00:00
|
|
|
|
private_data = GTK_CALENDAR_PRIVATE_DATA (widget);
|
1998-09-27 18:32:00 +00:00
|
|
|
|
|
|
|
|
|
if (GTK_WIDGET_DRAWABLE (widget))
|
|
|
|
|
{
|
|
|
|
|
x = 0;
|
|
|
|
|
y = 0;
|
|
|
|
|
gdk_window_get_size (widget->window, &width, &height);
|
|
|
|
|
gdk_window_clear (widget->window);
|
1998-10-01 13:24:42 +00:00
|
|
|
|
|
1998-10-04 23:07:04 +00:00
|
|
|
|
gdk_draw_rectangle (widget->window,
|
|
|
|
|
widget->style->base_gc[GTK_WIDGET_STATE (widget)],
|
|
|
|
|
FALSE, x + 2, y + 2, width - 5, height - 5);
|
1998-09-27 18:32:00 +00:00
|
|
|
|
|
|
|
|
|
gtk_draw_shadow (widget->style, widget->window,
|
|
|
|
|
GTK_STATE_NORMAL, GTK_SHADOW_IN,
|
|
|
|
|
x, y, width, height);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static gint
|
1998-10-01 13:24:42 +00:00
|
|
|
|
gtk_calendar_expose (GtkWidget *widget,
|
|
|
|
|
GdkEventExpose *event)
|
1998-09-27 18:32:00 +00:00
|
|
|
|
{
|
|
|
|
|
GtkCalendar *calendar;
|
1998-10-04 23:07:04 +00:00
|
|
|
|
GtkCalendarPrivateData *private_data;
|
|
|
|
|
|
1998-09-27 18:32:00 +00:00
|
|
|
|
g_return_val_if_fail (widget != NULL, FALSE);
|
|
|
|
|
g_return_val_if_fail (GTK_IS_CALENDAR (widget), FALSE);
|
|
|
|
|
g_return_val_if_fail (event != NULL, FALSE);
|
1998-10-01 13:24:42 +00:00
|
|
|
|
|
1998-09-27 18:32:00 +00:00
|
|
|
|
calendar = GTK_CALENDAR (widget);
|
1998-10-04 23:07:04 +00:00
|
|
|
|
private_data = GTK_CALENDAR_PRIVATE_DATA (widget);
|
1998-10-01 13:24:42 +00:00
|
|
|
|
|
1998-09-27 18:32:00 +00:00
|
|
|
|
if (GTK_WIDGET_DRAWABLE (widget))
|
|
|
|
|
{
|
1998-10-04 23:07:04 +00:00
|
|
|
|
if (event->window == private_data->main_win)
|
1998-09-27 18:32:00 +00:00
|
|
|
|
gtk_calendar_paint_main (widget);
|
1998-10-01 13:24:42 +00:00
|
|
|
|
|
1998-10-04 23:07:04 +00:00
|
|
|
|
if (event->window == private_data->header_win)
|
1998-09-27 18:32:00 +00:00
|
|
|
|
gtk_calendar_paint_header (widget);
|
1998-10-01 13:24:42 +00:00
|
|
|
|
|
1998-10-04 23:07:04 +00:00
|
|
|
|
if (event->window == private_data->day_name_win)
|
1998-09-27 18:32:00 +00:00
|
|
|
|
gtk_calendar_paint_day_names (widget);
|
1998-10-01 13:24:42 +00:00
|
|
|
|
|
1998-10-04 23:07:04 +00:00
|
|
|
|
if (event->window == private_data->week_win)
|
1998-09-27 18:32:00 +00:00
|
|
|
|
gtk_calendar_paint_week_numbers (widget);
|
|
|
|
|
if (event->window == widget->window)
|
|
|
|
|
gtk_widget_draw_focus (widget);
|
|
|
|
|
}
|
1998-10-01 13:24:42 +00:00
|
|
|
|
|
1998-09-27 18:32:00 +00:00
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
1998-10-01 13:24:42 +00:00
|
|
|
|
gtk_calendar_draw (GtkWidget *widget,
|
|
|
|
|
GdkRectangle *area)
|
1998-09-27 18:32:00 +00:00
|
|
|
|
{
|
|
|
|
|
g_return_if_fail (widget != NULL);
|
|
|
|
|
g_return_if_fail (GTK_IS_CALENDAR (widget));
|
|
|
|
|
g_return_if_fail (area != NULL);
|
1998-10-01 13:24:42 +00:00
|
|
|
|
|
1998-09-27 18:32:00 +00:00
|
|
|
|
if (GTK_WIDGET_DRAWABLE (widget))
|
|
|
|
|
gtk_calendar_paint (widget, area);
|
1998-10-01 13:24:42 +00:00
|
|
|
|
|
1998-09-27 18:32:00 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
1998-10-01 13:24:42 +00:00
|
|
|
|
gtk_calendar_paint (GtkWidget *widget,
|
|
|
|
|
GdkRectangle *area)
|
1998-09-27 18:32:00 +00:00
|
|
|
|
{
|
|
|
|
|
GtkCalendar *calendar;
|
1998-10-04 23:07:04 +00:00
|
|
|
|
GtkCalendarPrivateData *private_data;
|
|
|
|
|
|
1998-09-27 18:32:00 +00:00
|
|
|
|
g_return_if_fail (widget != NULL);
|
|
|
|
|
g_return_if_fail (widget->window != NULL);
|
|
|
|
|
g_return_if_fail (GTK_IS_CALENDAR (widget));
|
1998-10-01 13:24:42 +00:00
|
|
|
|
|
1998-09-27 18:32:00 +00:00
|
|
|
|
calendar = GTK_CALENDAR (widget);
|
1998-10-04 23:07:04 +00:00
|
|
|
|
private_data = GTK_CALENDAR_PRIVATE_DATA (widget);
|
1998-10-01 13:24:42 +00:00
|
|
|
|
|
1998-10-04 23:07:04 +00:00
|
|
|
|
if (private_data->main_win != NULL)
|
1998-09-27 18:32:00 +00:00
|
|
|
|
gtk_calendar_paint_main (widget);
|
1998-10-01 13:24:42 +00:00
|
|
|
|
|
1998-10-04 23:07:04 +00:00
|
|
|
|
if (private_data->header_win != NULL)
|
1998-09-27 18:32:00 +00:00
|
|
|
|
gtk_calendar_paint_header (widget);
|
1998-10-01 13:24:42 +00:00
|
|
|
|
|
1998-10-04 23:07:04 +00:00
|
|
|
|
if (private_data->day_name_win != NULL)
|
1998-09-27 18:32:00 +00:00
|
|
|
|
gtk_calendar_paint_day_names (widget);
|
1998-10-01 13:24:42 +00:00
|
|
|
|
|
1998-10-04 23:07:04 +00:00
|
|
|
|
if (private_data->week_win != NULL)
|
1998-09-27 18:32:00 +00:00
|
|
|
|
gtk_calendar_paint_week_numbers (widget);
|
1998-10-01 13:24:42 +00:00
|
|
|
|
|
1998-09-27 18:32:00 +00:00
|
|
|
|
gtk_widget_draw_focus (widget);
|
|
|
|
|
}
|
|
|
|
|
|
1998-10-01 13:24:42 +00:00
|
|
|
|
static void
|
1998-09-27 18:32:00 +00:00
|
|
|
|
gtk_calendar_paint_header (GtkWidget *widget)
|
|
|
|
|
{
|
|
|
|
|
GtkCalendar *calendar;
|
|
|
|
|
GdkGC *gc;
|
|
|
|
|
char buffer[255];
|
|
|
|
|
int y, y_arrow;
|
1998-10-04 23:07:04 +00:00
|
|
|
|
gint header_width, cal_height;
|
1998-09-27 18:32:00 +00:00
|
|
|
|
gint str_width;
|
|
|
|
|
gint max_month_width;
|
|
|
|
|
gint max_year_width;
|
1998-10-04 23:07:04 +00:00
|
|
|
|
GtkCalendarPrivateData *private_data;
|
|
|
|
|
|
1998-09-27 18:32:00 +00:00
|
|
|
|
calendar = GTK_CALENDAR (widget);
|
1998-10-04 23:07:04 +00:00
|
|
|
|
private_data = GTK_CALENDAR_PRIVATE_DATA (widget);
|
|
|
|
|
|
1998-11-28 01:56:09 +00:00
|
|
|
|
if (private_data->freeze_count)
|
1998-09-27 18:32:00 +00:00
|
|
|
|
{
|
1998-10-04 23:07:04 +00:00
|
|
|
|
private_data->dirty_header = 1;
|
1998-09-27 18:32:00 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
1998-10-04 23:07:04 +00:00
|
|
|
|
private_data->dirty_header = 0;
|
1998-09-27 18:32:00 +00:00
|
|
|
|
gc = calendar->gc;
|
1998-10-01 13:24:42 +00:00
|
|
|
|
|
1998-09-27 18:32:00 +00:00
|
|
|
|
/* Clear window */
|
1998-10-04 23:07:04 +00:00
|
|
|
|
gdk_window_clear (private_data->header_win);
|
1998-10-01 13:24:42 +00:00
|
|
|
|
|
1998-10-04 23:07:04 +00:00
|
|
|
|
header_width = widget->allocation.width - 4;
|
1998-09-27 18:32:00 +00:00
|
|
|
|
cal_height = widget->allocation.height;
|
1998-10-01 13:24:42 +00:00
|
|
|
|
|
1998-10-04 23:07:04 +00:00
|
|
|
|
max_month_width = private_data->max_month_width;
|
|
|
|
|
max_year_width = private_data->max_year_width;
|
1998-10-01 13:24:42 +00:00
|
|
|
|
|
1998-09-27 18:32:00 +00:00
|
|
|
|
gdk_gc_set_foreground (gc, BACKGROUND_COLOR (GTK_WIDGET (calendar)));
|
1998-10-04 23:07:04 +00:00
|
|
|
|
gtk_draw_shadow (widget->style, private_data->header_win,
|
1998-10-01 13:24:42 +00:00
|
|
|
|
GTK_STATE_NORMAL, GTK_SHADOW_OUT,
|
1998-10-04 23:07:04 +00:00
|
|
|
|
0, 0, header_width, private_data->header_h);
|
1998-09-27 18:32:00 +00:00
|
|
|
|
|
1998-10-01 13:24:42 +00:00
|
|
|
|
|
1998-09-27 18:32:00 +00:00
|
|
|
|
/* Draw title */
|
1998-10-04 23:07:04 +00:00
|
|
|
|
y = private_data->header_h - (private_data->header_h
|
|
|
|
|
- HEADER_FONT (widget)->ascent
|
|
|
|
|
+ HEADER_FONT (widget)->descent) / 2;
|
|
|
|
|
y_arrow = (private_data->header_h - 9) / 2;
|
1998-10-01 13:24:42 +00:00
|
|
|
|
|
1998-09-27 18:32:00 +00:00
|
|
|
|
/* Draw year and its arrows */
|
|
|
|
|
sprintf (buffer, "%d", calendar->year);
|
|
|
|
|
str_width = gdk_string_measure (HEADER_FONT (widget), buffer);
|
|
|
|
|
gdk_gc_set_foreground (gc, HEADER_FG_COLOR (GTK_WIDGET (calendar)));
|
|
|
|
|
if (calendar->display_flags & GTK_CALENDAR_NO_MONTH_CHANGE)
|
1998-10-04 23:07:04 +00:00
|
|
|
|
gdk_draw_string (private_data->header_win, HEADER_FONT (widget), gc,
|
|
|
|
|
header_width - (3 + max_year_width
|
|
|
|
|
- (max_year_width - str_width)/2),
|
1998-09-27 18:32:00 +00:00
|
|
|
|
y, buffer);
|
|
|
|
|
else
|
1998-10-04 23:07:04 +00:00
|
|
|
|
gdk_draw_string (private_data->header_win, HEADER_FONT (widget), gc,
|
|
|
|
|
header_width - (3 + private_data->arrow_width + max_year_width
|
|
|
|
|
- (max_year_width - str_width)/2),
|
1998-09-27 18:32:00 +00:00
|
|
|
|
y, buffer);
|
1998-10-01 13:24:42 +00:00
|
|
|
|
|
1998-09-27 18:32:00 +00:00
|
|
|
|
/* Draw month */
|
|
|
|
|
sprintf (buffer, "%s", default_monthname[calendar->month]);
|
|
|
|
|
str_width = gdk_string_measure (HEADER_FONT (widget), buffer);
|
|
|
|
|
if (calendar->display_flags & GTK_CALENDAR_NO_MONTH_CHANGE)
|
1998-10-04 23:07:04 +00:00
|
|
|
|
gdk_draw_string (private_data->header_win, HEADER_FONT (widget), gc,
|
1998-09-27 18:32:00 +00:00
|
|
|
|
3 + (max_month_width - str_width) / 2,
|
|
|
|
|
y, buffer);
|
|
|
|
|
else
|
1998-10-04 23:07:04 +00:00
|
|
|
|
gdk_draw_string (private_data->header_win, HEADER_FONT (widget), gc,
|
|
|
|
|
3 + private_data->arrow_width + (max_month_width - str_width)/2,
|
1998-09-27 18:32:00 +00:00
|
|
|
|
y, buffer);
|
1998-10-01 13:24:42 +00:00
|
|
|
|
|
1998-09-27 18:32:00 +00:00
|
|
|
|
y += CALENDAR_YSEP + HEADER_FONT (widget)->descent;
|
1998-10-01 13:24:42 +00:00
|
|
|
|
|
1998-09-27 18:32:00 +00:00
|
|
|
|
gdk_gc_set_foreground (gc, BACKGROUND_COLOR (GTK_WIDGET (calendar)));
|
1998-10-01 13:24:42 +00:00
|
|
|
|
|
1998-09-27 18:32:00 +00:00
|
|
|
|
gtk_calendar_paint_arrow (widget, ARROW_MONTH_LEFT);
|
|
|
|
|
gtk_calendar_paint_arrow (widget, ARROW_MONTH_RIGHT);
|
|
|
|
|
gtk_calendar_paint_arrow (widget, ARROW_YEAR_LEFT);
|
|
|
|
|
gtk_calendar_paint_arrow (widget, ARROW_YEAR_RIGHT);
|
1998-10-01 13:24:42 +00:00
|
|
|
|
|
1998-09-27 18:32:00 +00:00
|
|
|
|
}
|
|
|
|
|
|
1998-10-01 13:24:42 +00:00
|
|
|
|
static void
|
1998-09-27 18:32:00 +00:00
|
|
|
|
gtk_calendar_paint_day_names (GtkWidget *widget)
|
|
|
|
|
{
|
|
|
|
|
GtkCalendar *calendar;
|
|
|
|
|
GdkGC *gc;
|
|
|
|
|
char buffer[255];
|
|
|
|
|
int day,i;
|
|
|
|
|
int day_width, cal_width;
|
|
|
|
|
gint cal_height;
|
|
|
|
|
int day_wid_sep;
|
|
|
|
|
int str_width;
|
1998-10-04 23:07:04 +00:00
|
|
|
|
GtkCalendarPrivateData *private_data;
|
|
|
|
|
|
1998-09-27 18:32:00 +00:00
|
|
|
|
g_return_if_fail (widget != NULL);
|
|
|
|
|
g_return_if_fail (GTK_IS_CALENDAR (widget));
|
|
|
|
|
calendar = GTK_CALENDAR (widget);
|
1998-10-04 23:07:04 +00:00
|
|
|
|
private_data = GTK_CALENDAR_PRIVATE_DATA (widget);
|
1998-09-27 18:32:00 +00:00
|
|
|
|
gc = calendar->gc;
|
1998-10-01 13:24:42 +00:00
|
|
|
|
|
1998-09-27 18:32:00 +00:00
|
|
|
|
/*
|
|
|
|
|
* Handle freeze/thaw functionality
|
|
|
|
|
*/
|
1998-10-01 13:24:42 +00:00
|
|
|
|
|
1998-11-28 01:56:09 +00:00
|
|
|
|
if (private_data->freeze_count)
|
1998-09-27 18:32:00 +00:00
|
|
|
|
{
|
1998-10-04 23:07:04 +00:00
|
|
|
|
private_data->dirty_day_names = 1;
|
1998-09-27 18:32:00 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
1998-10-04 23:07:04 +00:00
|
|
|
|
private_data->dirty_day_names = 0;
|
1998-10-01 13:24:42 +00:00
|
|
|
|
|
1998-09-27 18:32:00 +00:00
|
|
|
|
/*
|
|
|
|
|
* Clear the window
|
|
|
|
|
*/
|
1998-10-01 13:24:42 +00:00
|
|
|
|
|
1998-10-04 23:07:04 +00:00
|
|
|
|
gdk_window_clear (private_data->day_name_win);
|
1998-10-01 13:24:42 +00:00
|
|
|
|
|
1998-10-04 23:07:04 +00:00
|
|
|
|
day_width = private_data->day_width;
|
1998-09-27 18:32:00 +00:00
|
|
|
|
cal_width = widget->allocation.width;
|
|
|
|
|
cal_height = widget->allocation.height;
|
|
|
|
|
day_wid_sep = day_width + DAY_XSEP;
|
1998-10-01 13:24:42 +00:00
|
|
|
|
|
1998-09-27 18:32:00 +00:00
|
|
|
|
/*
|
|
|
|
|
* Draw rectangles as inverted background for the labels.
|
|
|
|
|
*/
|
1998-10-01 13:24:42 +00:00
|
|
|
|
|
1998-10-05 03:52:48 +00:00
|
|
|
|
gdk_gc_set_foreground (gc, &widget->style->bg[GTK_STATE_SELECTED]);
|
1998-10-04 23:07:04 +00:00
|
|
|
|
gdk_draw_rectangle (private_data->day_name_win, gc, TRUE,
|
1998-09-27 18:32:00 +00:00
|
|
|
|
CALENDAR_MARGIN, CALENDAR_MARGIN,
|
|
|
|
|
cal_width-CALENDAR_MARGIN * 2,
|
1998-10-04 23:07:04 +00:00
|
|
|
|
private_data->day_name_h - CALENDAR_MARGIN);
|
1998-10-01 13:24:42 +00:00
|
|
|
|
|
1998-09-27 18:32:00 +00:00
|
|
|
|
if (calendar->display_flags & GTK_CALENDAR_SHOW_WEEK_NUMBERS)
|
1998-10-04 23:07:04 +00:00
|
|
|
|
gdk_draw_rectangle (private_data->day_name_win, gc, TRUE,
|
1998-09-27 18:32:00 +00:00
|
|
|
|
CALENDAR_MARGIN,
|
1998-10-04 23:07:04 +00:00
|
|
|
|
private_data->day_name_h - CALENDAR_YSEP,
|
|
|
|
|
private_data->week_width - CALENDAR_YSEP - CALENDAR_MARGIN,
|
1998-09-27 18:32:00 +00:00
|
|
|
|
CALENDAR_YSEP);
|
1998-10-01 13:24:42 +00:00
|
|
|
|
|
1998-09-27 18:32:00 +00:00
|
|
|
|
/*
|
|
|
|
|
* Write the labels
|
|
|
|
|
*/
|
1998-10-05 03:52:48 +00:00
|
|
|
|
gdk_gc_set_foreground (gc, &widget->style->fg[GTK_STATE_SELECTED]);
|
1998-09-27 18:32:00 +00:00
|
|
|
|
for (i = 0; i < 7; i++)
|
|
|
|
|
{
|
|
|
|
|
day=i;
|
|
|
|
|
if (calendar->display_flags & GTK_CALENDAR_WEEK_START_MONDAY)
|
|
|
|
|
day= (day+1)%7;
|
|
|
|
|
sprintf (buffer, "%s", default_abbreviated_dayname[day]);
|
|
|
|
|
str_width = gdk_string_measure (LABEL_FONT (widget), buffer);
|
1998-10-04 23:07:04 +00:00
|
|
|
|
gdk_draw_string (private_data->day_name_win, LABEL_FONT (widget),
|
1998-10-01 13:24:42 +00:00
|
|
|
|
gc,
|
1998-10-04 23:07:04 +00:00
|
|
|
|
((private_data->week_width ? CALENDAR_XSEP : CALENDAR_MARGIN)
|
1998-09-27 18:32:00 +00:00
|
|
|
|
+ day_wid_sep * i
|
1998-10-04 23:07:04 +00:00
|
|
|
|
+ private_data->week_width
|
1998-09-27 18:32:00 +00:00
|
|
|
|
+ (day_width - str_width)/2),
|
|
|
|
|
CALENDAR_MARGIN + DAY_YPAD
|
1998-10-04 23:07:04 +00:00
|
|
|
|
+ private_data->max_label_char_ascent, buffer);
|
1998-09-27 18:32:00 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
1998-10-01 13:24:42 +00:00
|
|
|
|
static void
|
1998-09-27 18:32:00 +00:00
|
|
|
|
gtk_calendar_paint_week_numbers (GtkWidget *widget)
|
|
|
|
|
{
|
|
|
|
|
GtkCalendar *calendar;
|
|
|
|
|
GdkGC *gc;
|
1998-12-31 21:01:18 +00:00
|
|
|
|
gint row, week = 0, year;
|
1998-09-27 18:32:00 +00:00
|
|
|
|
gint x_loc;
|
|
|
|
|
char buffer[3];
|
|
|
|
|
gint y_baseline, day_height;
|
1998-10-04 23:07:04 +00:00
|
|
|
|
GtkCalendarPrivateData *private_data;
|
1998-10-01 13:24:42 +00:00
|
|
|
|
|
1998-09-27 18:32:00 +00:00
|
|
|
|
g_return_if_fail (widget != NULL);
|
|
|
|
|
g_return_if_fail (widget->window != NULL);
|
|
|
|
|
g_return_if_fail (GTK_IS_CALENDAR (widget));
|
|
|
|
|
calendar = GTK_CALENDAR (widget);
|
1998-10-04 23:07:04 +00:00
|
|
|
|
private_data = GTK_CALENDAR_PRIVATE_DATA (widget);
|
1998-09-27 18:32:00 +00:00
|
|
|
|
gc = calendar->gc;
|
1998-10-01 13:24:42 +00:00
|
|
|
|
|
1998-09-27 18:32:00 +00:00
|
|
|
|
/*
|
|
|
|
|
* Handle freeze/thaw functionality
|
|
|
|
|
*/
|
1998-10-01 13:24:42 +00:00
|
|
|
|
|
1998-11-28 01:56:09 +00:00
|
|
|
|
if (private_data->freeze_count)
|
1998-09-27 18:32:00 +00:00
|
|
|
|
{
|
1998-10-04 23:07:04 +00:00
|
|
|
|
private_data->dirty_week = 1;
|
1998-09-27 18:32:00 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
1998-10-04 23:07:04 +00:00
|
|
|
|
private_data->dirty_week = 0;
|
1998-10-01 13:24:42 +00:00
|
|
|
|
|
1998-09-27 18:32:00 +00:00
|
|
|
|
/*
|
|
|
|
|
* Clear the window
|
|
|
|
|
*/
|
1998-10-01 13:24:42 +00:00
|
|
|
|
|
1998-10-04 23:07:04 +00:00
|
|
|
|
gdk_window_clear (private_data->week_win);
|
1998-10-01 13:24:42 +00:00
|
|
|
|
|
1998-09-27 18:32:00 +00:00
|
|
|
|
/*
|
|
|
|
|
* Draw a rectangle as inverted background for the labels.
|
|
|
|
|
*/
|
1998-10-01 13:24:42 +00:00
|
|
|
|
|
1998-10-05 03:52:48 +00:00
|
|
|
|
gdk_gc_set_foreground (gc, &widget->style->bg[GTK_STATE_SELECTED]);
|
1998-10-04 23:07:04 +00:00
|
|
|
|
if (private_data->day_name_win)
|
|
|
|
|
gdk_draw_rectangle (private_data->week_win, gc, TRUE,
|
1998-09-27 18:32:00 +00:00
|
|
|
|
CALENDAR_MARGIN,
|
|
|
|
|
0,
|
1998-10-04 23:07:04 +00:00
|
|
|
|
private_data->week_width - CALENDAR_MARGIN - CALENDAR_XSEP,
|
|
|
|
|
private_data->main_h - CALENDAR_MARGIN);
|
1998-09-27 18:32:00 +00:00
|
|
|
|
else
|
1998-10-04 23:07:04 +00:00
|
|
|
|
gdk_draw_rectangle (private_data->week_win, gc, TRUE,
|
1998-09-27 18:32:00 +00:00
|
|
|
|
CALENDAR_MARGIN,
|
|
|
|
|
CALENDAR_MARGIN,
|
1998-10-04 23:07:04 +00:00
|
|
|
|
private_data->week_width - CALENDAR_MARGIN - CALENDAR_XSEP,
|
|
|
|
|
private_data->main_h - 2 * CALENDAR_MARGIN);
|
1998-10-01 13:24:42 +00:00
|
|
|
|
|
1998-09-27 18:32:00 +00:00
|
|
|
|
/*
|
|
|
|
|
* Write the labels
|
|
|
|
|
*/
|
1998-10-01 13:24:42 +00:00
|
|
|
|
|
1998-10-05 03:52:48 +00:00
|
|
|
|
gdk_gc_set_foreground (gc, &widget->style->fg[GTK_STATE_SELECTED]);
|
1998-09-27 18:32:00 +00:00
|
|
|
|
day_height = row_height (calendar);
|
|
|
|
|
for (row = 0; row < 6; row++)
|
|
|
|
|
{
|
|
|
|
|
year = calendar->year;
|
|
|
|
|
if (calendar->day[row][6] < 15 && row > 3 && calendar->month == 11)
|
|
|
|
|
year++;
|
|
|
|
|
y_baseline = (top_y_for_row (calendar, row)
|
|
|
|
|
+ (day_height + LABEL_FONT (widget)->ascent
|
|
|
|
|
- LABEL_FONT (widget)->descent)/2);
|
|
|
|
|
g_return_if_fail (week_of_year (&week, &year,
|
|
|
|
|
((calendar->day[row][6] < 15 && row > 3 ? 1 : 0)
|
|
|
|
|
+ calendar->month) % 12 + 1, calendar->day[row][6]));
|
1998-10-04 23:07:04 +00:00
|
|
|
|
x_loc= (private_data->week_width - (private_data->week_width - CALENDAR_XSEP
|
1998-09-27 18:32:00 +00:00
|
|
|
|
- DAY_XPAD * 2 - CALENDAR_MARGIN ) / 2
|
1998-10-04 23:07:04 +00:00
|
|
|
|
- private_data->max_week_char_width
|
1998-09-27 18:32:00 +00:00
|
|
|
|
- CALENDAR_XSEP - DAY_XPAD);
|
1998-10-01 13:24:42 +00:00
|
|
|
|
|
1998-09-27 18:32:00 +00:00
|
|
|
|
if (week > 9)
|
|
|
|
|
{
|
|
|
|
|
sprintf (buffer, "%d", week/10);
|
1998-10-04 23:07:04 +00:00
|
|
|
|
gdk_draw_string (private_data->week_win, LABEL_FONT (widget), gc,
|
1998-09-27 18:32:00 +00:00
|
|
|
|
x_loc, y_baseline , buffer);
|
|
|
|
|
}
|
1998-10-01 13:24:42 +00:00
|
|
|
|
|
1998-09-27 18:32:00 +00:00
|
|
|
|
sprintf (buffer, "%d", week%10);
|
1998-10-04 23:07:04 +00:00
|
|
|
|
gdk_draw_string (private_data->week_win, LABEL_FONT (widget), gc,
|
|
|
|
|
x_loc + private_data->max_week_char_width, y_baseline , buffer);
|
1998-09-27 18:32:00 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
1998-10-01 13:24:42 +00:00
|
|
|
|
gtk_calendar_paint_day_num (GtkWidget *widget,
|
|
|
|
|
gint day)
|
1998-09-27 18:32:00 +00:00
|
|
|
|
{
|
|
|
|
|
GtkCalendar *calendar;
|
|
|
|
|
gint r, c, row, col;
|
1998-10-01 13:24:42 +00:00
|
|
|
|
|
1998-09-27 18:32:00 +00:00
|
|
|
|
g_return_if_fail (widget != NULL);
|
|
|
|
|
g_return_if_fail (GTK_IS_CALENDAR (widget));
|
1998-10-01 13:24:42 +00:00
|
|
|
|
|
1998-09-27 18:32:00 +00:00
|
|
|
|
calendar = GTK_CALENDAR (widget);
|
1998-10-01 13:24:42 +00:00
|
|
|
|
|
1998-09-27 18:32:00 +00:00
|
|
|
|
row = -1;
|
|
|
|
|
col = -1;
|
|
|
|
|
for (r = 0; r < 6; r++)
|
|
|
|
|
for (c = 0; c < 7; c++)
|
|
|
|
|
if (calendar->day_month[r][c] == MONTH_CURRENT &&
|
|
|
|
|
calendar->day[r][c] == day)
|
|
|
|
|
{
|
|
|
|
|
row = r;
|
|
|
|
|
col = c;
|
|
|
|
|
}
|
1998-10-01 13:24:42 +00:00
|
|
|
|
|
1998-09-27 18:32:00 +00:00
|
|
|
|
g_return_if_fail (row != -1);
|
|
|
|
|
g_return_if_fail (col != -1);
|
1998-10-01 13:24:42 +00:00
|
|
|
|
|
1998-09-27 18:32:00 +00:00
|
|
|
|
gtk_calendar_paint_day (widget, row, col);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
1998-10-01 13:24:42 +00:00
|
|
|
|
gtk_calendar_paint_day (GtkWidget *widget,
|
|
|
|
|
gint row,
|
|
|
|
|
gint col)
|
1998-09-27 18:32:00 +00:00
|
|
|
|
{
|
|
|
|
|
GtkCalendar *calendar;
|
|
|
|
|
GdkGC *gc;
|
|
|
|
|
gchar buffer[255];
|
|
|
|
|
gint day;
|
|
|
|
|
gint day_height;
|
|
|
|
|
gint x_left;
|
|
|
|
|
gint x_loc;
|
|
|
|
|
gint y_top;
|
|
|
|
|
gint y_baseline;
|
|
|
|
|
gint day_xspace;
|
1998-10-04 23:07:04 +00:00
|
|
|
|
GtkCalendarPrivateData *private_data;
|
1998-10-01 13:24:42 +00:00
|
|
|
|
|
1998-09-27 18:32:00 +00:00
|
|
|
|
g_return_if_fail (widget != NULL);
|
|
|
|
|
g_return_if_fail (GTK_IS_CALENDAR (widget));
|
|
|
|
|
g_return_if_fail (row < 6);
|
|
|
|
|
g_return_if_fail (col < 7);
|
|
|
|
|
calendar = GTK_CALENDAR (widget);
|
1998-10-04 23:07:04 +00:00
|
|
|
|
private_data = GTK_CALENDAR_PRIVATE_DATA (widget);
|
|
|
|
|
|
1998-09-27 18:32:00 +00:00
|
|
|
|
/*
|
|
|
|
|
* Handle freeze/thaw functionality
|
|
|
|
|
*/
|
1998-10-01 13:24:42 +00:00
|
|
|
|
|
1998-11-28 01:56:09 +00:00
|
|
|
|
if (private_data->freeze_count)
|
1998-09-27 18:32:00 +00:00
|
|
|
|
{
|
1998-10-04 23:07:04 +00:00
|
|
|
|
private_data->dirty_main = 1;
|
1998-09-27 18:32:00 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
1998-10-01 13:24:42 +00:00
|
|
|
|
|
1998-09-27 18:32:00 +00:00
|
|
|
|
day_height = row_height (calendar);
|
1998-10-01 13:24:42 +00:00
|
|
|
|
|
1998-10-04 23:07:04 +00:00
|
|
|
|
day_xspace = private_data->day_width - private_data->max_day_char_width*2;
|
1998-10-01 13:24:42 +00:00
|
|
|
|
|
1998-09-27 18:32:00 +00:00
|
|
|
|
day = calendar->day[row][col];
|
1998-10-01 13:24:42 +00:00
|
|
|
|
|
1998-09-27 18:32:00 +00:00
|
|
|
|
x_left = left_x_for_column (calendar, col);
|
1998-10-04 23:07:04 +00:00
|
|
|
|
x_loc = x_left + private_data->day_width / 2 + private_data->max_day_char_width;
|
1998-10-01 13:24:42 +00:00
|
|
|
|
|
1998-09-27 18:32:00 +00:00
|
|
|
|
y_top = top_y_for_row (calendar, row);
|
1998-10-04 23:07:04 +00:00
|
|
|
|
y_baseline = y_top + (day_height + private_data->max_day_char_ascent)/2;
|
1998-10-01 13:24:42 +00:00
|
|
|
|
|
1998-10-04 23:07:04 +00:00
|
|
|
|
gdk_window_clear_area (private_data->main_win, x_left, y_top,
|
|
|
|
|
private_data->day_width, day_height);
|
1998-10-01 13:24:42 +00:00
|
|
|
|
|
1998-09-27 18:32:00 +00:00
|
|
|
|
gc = calendar->gc;
|
1998-10-01 13:24:42 +00:00
|
|
|
|
|
1998-09-27 18:32:00 +00:00
|
|
|
|
if (calendar->day_month[row][col] == MONTH_PREV)
|
|
|
|
|
{
|
|
|
|
|
gdk_gc_set_foreground (gc, PREV_MONTH_COLOR (GTK_WIDGET (calendar)));
|
|
|
|
|
}
|
|
|
|
|
else if (calendar->day_month[row][col] == MONTH_NEXT)
|
|
|
|
|
{
|
|
|
|
|
gdk_gc_set_foreground (gc, NEXT_MONTH_COLOR (GTK_WIDGET (calendar)));
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
1998-10-05 03:52:48 +00:00
|
|
|
|
/*
|
1998-09-27 18:32:00 +00:00
|
|
|
|
if (calendar->highlight_row == row && calendar->highlight_col == col)
|
|
|
|
|
{
|
|
|
|
|
gdk_gc_set_foreground (gc, HIGHLIGHT_BACK_COLOR (GTK_WIDGET (calendar)));
|
1998-10-04 23:07:04 +00:00
|
|
|
|
gdk_draw_rectangle (private_data->main_win, gc, TRUE, x_left, y_top,
|
|
|
|
|
private_data->day_width, day_height);
|
1998-09-27 18:32:00 +00:00
|
|
|
|
}
|
1998-10-05 03:52:48 +00:00
|
|
|
|
*/
|
1998-09-27 18:32:00 +00:00
|
|
|
|
if (calendar->selected_day == day)
|
|
|
|
|
{
|
1998-10-05 03:52:48 +00:00
|
|
|
|
gdk_gc_set_foreground (gc, & (GTK_WIDGET (calendar)->style->bg[GTK_STATE_SELECTED]));
|
|
|
|
|
gdk_draw_rectangle (private_data->main_win, gc, TRUE, x_left, y_top,
|
|
|
|
|
private_data->day_width, day_height);
|
1998-09-27 18:32:00 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (calendar->marked_date[day-1])
|
1998-10-01 13:24:42 +00:00
|
|
|
|
gdk_gc_set_foreground (gc, MARKED_COLOR (GTK_WIDGET (calendar)));
|
1998-09-27 18:32:00 +00:00
|
|
|
|
else
|
|
|
|
|
gdk_gc_set_foreground (gc, NORMAL_DAY_COLOR (GTK_WIDGET (calendar)));
|
|
|
|
|
|
1998-10-05 03:52:48 +00:00
|
|
|
|
if (calendar->selected_day == day)
|
|
|
|
|
gdk_gc_set_foreground (gc, & (GTK_WIDGET (calendar)->style->fg[GTK_STATE_SELECTED]));
|
|
|
|
|
else
|
|
|
|
|
gdk_gc_set_foreground (gc, & (GTK_WIDGET (calendar)->style->fg[GTK_WIDGET_STATE (calendar)]));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
1998-09-27 18:32:00 +00:00
|
|
|
|
sprintf (buffer, "%d", day);
|
|
|
|
|
x_loc -= gdk_string_measure (DAY_FONT (widget), buffer);
|
|
|
|
|
sprintf (buffer, "%d", day);
|
1998-10-04 23:07:04 +00:00
|
|
|
|
gdk_draw_string (private_data->main_win,
|
1998-10-01 13:24:42 +00:00
|
|
|
|
DAY_FONT (widget), gc,
|
|
|
|
|
x_loc, y_baseline, buffer);
|
1998-11-20 05:51:45 +00:00
|
|
|
|
if (calendar->marked_date[day-1]
|
|
|
|
|
&& calendar->day_month[row][col] == MONTH_CURRENT)
|
1998-10-04 23:07:04 +00:00
|
|
|
|
gdk_draw_string (private_data->main_win,
|
1998-09-27 18:32:00 +00:00
|
|
|
|
DAY_FONT (widget), gc,
|
|
|
|
|
x_loc-1, y_baseline, buffer);
|
1998-10-05 03:52:48 +00:00
|
|
|
|
|
|
|
|
|
if (GTK_WIDGET_HAS_FOCUS (calendar)
|
|
|
|
|
&& calendar->focus_row == row && calendar->focus_col == col)
|
|
|
|
|
{
|
|
|
|
|
gdk_draw_rectangle (private_data->main_win, calendar->xor_gc,
|
|
|
|
|
FALSE, x_left, y_top,
|
|
|
|
|
private_data->day_width-1, day_height-1);
|
|
|
|
|
}
|
|
|
|
|
|
1998-09-27 18:32:00 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
1998-10-01 13:24:42 +00:00
|
|
|
|
static void
|
1998-09-27 18:32:00 +00:00
|
|
|
|
gtk_calendar_paint_main (GtkWidget *widget)
|
|
|
|
|
{
|
|
|
|
|
GtkCalendar *calendar;
|
1998-10-04 23:07:04 +00:00
|
|
|
|
GtkCalendarPrivateData *private_data;
|
1998-09-27 18:32:00 +00:00
|
|
|
|
gint row, col;
|
1998-10-01 13:24:42 +00:00
|
|
|
|
|
1998-09-27 18:32:00 +00:00
|
|
|
|
g_return_if_fail (widget != NULL);
|
|
|
|
|
g_return_if_fail (widget->window != NULL);
|
|
|
|
|
g_return_if_fail (GTK_IS_CALENDAR (widget));
|
1998-10-01 13:24:42 +00:00
|
|
|
|
|
1998-09-27 18:32:00 +00:00
|
|
|
|
calendar = GTK_CALENDAR (widget);
|
1998-10-04 23:07:04 +00:00
|
|
|
|
private_data = GTK_CALENDAR_PRIVATE_DATA (widget);
|
|
|
|
|
|
1998-11-28 01:56:09 +00:00
|
|
|
|
if (private_data->freeze_count)
|
1998-09-27 18:32:00 +00:00
|
|
|
|
{
|
1998-10-04 23:07:04 +00:00
|
|
|
|
private_data->dirty_main = 1;
|
1998-09-27 18:32:00 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
1998-10-04 23:07:04 +00:00
|
|
|
|
private_data->dirty_main = 0;
|
|
|
|
|
gdk_window_clear (private_data->main_win);
|
1998-10-01 13:24:42 +00:00
|
|
|
|
|
|
|
|
|
/* gtk_calendar_compute_days (calendar); */ /* REMOVE later */
|
|
|
|
|
|
1998-09-27 18:32:00 +00:00
|
|
|
|
for (col = 0; col < 7; col++)
|
|
|
|
|
for (row = 0; row < 6; row++)
|
|
|
|
|
gtk_calendar_paint_day (widget, row, col);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
gtk_calendar_compute_days (GtkCalendar *calendar)
|
|
|
|
|
{
|
|
|
|
|
gint month;
|
|
|
|
|
gint year;
|
|
|
|
|
gint ndays_in_month;
|
|
|
|
|
gint ndays_in_prev_month;
|
|
|
|
|
gint first_day;
|
|
|
|
|
gint row;
|
|
|
|
|
gint col;
|
|
|
|
|
gint day;
|
1998-10-01 13:24:42 +00:00
|
|
|
|
|
1998-09-27 18:32:00 +00:00
|
|
|
|
g_return_if_fail (calendar != NULL);
|
|
|
|
|
g_return_if_fail (GTK_IS_CALENDAR (calendar));
|
1998-10-01 13:24:42 +00:00
|
|
|
|
|
1998-09-27 18:32:00 +00:00
|
|
|
|
year = calendar->year;
|
|
|
|
|
month = calendar->month + 1;
|
1998-10-01 13:24:42 +00:00
|
|
|
|
|
1998-09-27 18:32:00 +00:00
|
|
|
|
ndays_in_month = month_length[leap (year)][month];
|
1998-10-01 13:24:42 +00:00
|
|
|
|
|
1998-09-27 18:32:00 +00:00
|
|
|
|
first_day = day_of_week (year, month, 1);
|
1998-10-01 13:24:42 +00:00
|
|
|
|
|
1998-09-27 18:32:00 +00:00
|
|
|
|
if (calendar->display_flags & GTK_CALENDAR_WEEK_START_MONDAY)
|
|
|
|
|
first_day--;
|
|
|
|
|
else
|
|
|
|
|
first_day %= 7;
|
1998-10-01 13:24:42 +00:00
|
|
|
|
|
|
|
|
|
|
1998-09-27 18:32:00 +00:00
|
|
|
|
/* Compute days of previous month */
|
|
|
|
|
if (month > 1)
|
|
|
|
|
ndays_in_prev_month = month_length[leap (year)][month-1];
|
|
|
|
|
else
|
|
|
|
|
ndays_in_prev_month = month_length[leap (year)][12];
|
|
|
|
|
day = ndays_in_prev_month - first_day + 1;
|
1998-10-01 13:24:42 +00:00
|
|
|
|
|
1998-09-27 18:32:00 +00:00
|
|
|
|
row = 0;
|
|
|
|
|
if (first_day > 0)
|
|
|
|
|
{
|
|
|
|
|
for (col = 0; col < first_day; col++)
|
|
|
|
|
{
|
|
|
|
|
calendar->day[row][col] = day;
|
|
|
|
|
calendar->day_month[row][col] = MONTH_PREV;
|
|
|
|
|
day++;
|
|
|
|
|
}
|
|
|
|
|
}
|
1998-10-01 13:24:42 +00:00
|
|
|
|
|
1998-09-27 18:32:00 +00:00
|
|
|
|
/* Compute days of current month */
|
|
|
|
|
col = first_day;
|
|
|
|
|
for (day = 1; day <= ndays_in_month; day++)
|
|
|
|
|
{
|
|
|
|
|
calendar->day[row][col] = day;
|
|
|
|
|
calendar->day_month[row][col] = MONTH_CURRENT;
|
1998-10-01 13:24:42 +00:00
|
|
|
|
|
1998-09-27 18:32:00 +00:00
|
|
|
|
col++;
|
|
|
|
|
if (col == 7)
|
|
|
|
|
{
|
|
|
|
|
row++;
|
|
|
|
|
col = 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
1998-10-01 13:24:42 +00:00
|
|
|
|
|
1998-09-27 18:32:00 +00:00
|
|
|
|
/* Compute days of next month */
|
|
|
|
|
day = 1;
|
|
|
|
|
for (; row <= 5; row++)
|
|
|
|
|
{
|
|
|
|
|
for (; col <= 6; col++)
|
|
|
|
|
{
|
|
|
|
|
calendar->day[row][col] = day;
|
|
|
|
|
calendar->day_month[row][col] = MONTH_NEXT;
|
|
|
|
|
day++;
|
|
|
|
|
}
|
|
|
|
|
col = 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* ----------------------------------------------------------------------
|
|
|
|
|
NAME: gtk_calendar_display_options
|
|
|
|
|
DESCRIPTION: Set display options (whether to display the
|
1998-10-01 13:24:42 +00:00
|
|
|
|
heading and the month headings)
|
|
|
|
|
|
|
|
|
|
flags is can be an XOR of:
|
|
|
|
|
GTK_CALENDAR_SHOW_HEADING
|
|
|
|
|
GTK_CALENDAR_SHOW_DAY_NAMES
|
|
|
|
|
GTK_CALENDAR_NO_MONTH_CHANGE
|
|
|
|
|
GTK_CALENDAR_SHOW_WEEK_NUMBERS
|
|
|
|
|
GTK_CALENDAR_WEEK_START_MONDAY
|
1998-09-27 18:32:00 +00:00
|
|
|
|
---------------------------------------------------------------------- */
|
|
|
|
|
|
1998-10-01 13:24:42 +00:00
|
|
|
|
void
|
|
|
|
|
gtk_calendar_display_options (GtkCalendar *calendar,
|
|
|
|
|
GtkCalendarDisplayOptions flags)
|
1998-09-27 18:32:00 +00:00
|
|
|
|
{
|
1998-10-04 23:07:04 +00:00
|
|
|
|
GtkCalendarPrivateData *private_data;
|
1998-09-27 18:32:00 +00:00
|
|
|
|
gint resize = 0;
|
|
|
|
|
GtkWidget *widget;
|
|
|
|
|
gint i;
|
1998-10-01 13:24:42 +00:00
|
|
|
|
|
|
|
|
|
g_return_if_fail (calendar != NULL);
|
1998-09-27 18:32:00 +00:00
|
|
|
|
g_return_if_fail (GTK_IS_CALENDAR (calendar));
|
1998-10-01 13:24:42 +00:00
|
|
|
|
|
1998-09-27 18:32:00 +00:00
|
|
|
|
widget = GTK_WIDGET (calendar);
|
1998-10-04 23:07:04 +00:00
|
|
|
|
private_data = GTK_CALENDAR_PRIVATE_DATA (calendar);
|
1998-10-01 13:24:42 +00:00
|
|
|
|
|
1998-09-27 18:32:00 +00:00
|
|
|
|
if (GTK_WIDGET_REALIZED (widget))
|
|
|
|
|
{
|
|
|
|
|
if ((flags ^ calendar->display_flags) & GTK_CALENDAR_NO_MONTH_CHANGE)
|
|
|
|
|
{
|
|
|
|
|
resize ++;
|
|
|
|
|
if (! (flags & GTK_CALENDAR_NO_MONTH_CHANGE)
|
1998-10-04 23:07:04 +00:00
|
|
|
|
&& (private_data->header_win))
|
1998-09-27 18:32:00 +00:00
|
|
|
|
{
|
|
|
|
|
calendar->display_flags &= ~GTK_CALENDAR_NO_MONTH_CHANGE;
|
|
|
|
|
gtk_calendar_realize_arrows (widget);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
1998-10-04 23:07:04 +00:00
|
|
|
|
for (i = 0; i < 4; i++)
|
|
|
|
|
{
|
|
|
|
|
if (private_data->arrow_win[i])
|
|
|
|
|
{
|
|
|
|
|
gdk_window_set_user_data (private_data->arrow_win[i],
|
|
|
|
|
NULL);
|
|
|
|
|
gdk_window_destroy (private_data->arrow_win[i]);
|
|
|
|
|
private_data->arrow_win[i] = NULL;
|
|
|
|
|
}
|
|
|
|
|
}
|
1998-09-27 18:32:00 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
1998-10-01 13:24:42 +00:00
|
|
|
|
|
1998-09-27 18:32:00 +00:00
|
|
|
|
if ((flags ^ calendar->display_flags) & GTK_CALENDAR_SHOW_HEADING)
|
|
|
|
|
{
|
|
|
|
|
resize++;
|
1998-10-01 13:24:42 +00:00
|
|
|
|
|
1998-09-27 18:32:00 +00:00
|
|
|
|
if (flags & GTK_CALENDAR_SHOW_HEADING)
|
|
|
|
|
{
|
|
|
|
|
calendar->display_flags |= GTK_CALENDAR_SHOW_HEADING;
|
|
|
|
|
gtk_calendar_realize_header (widget);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
1998-10-04 23:07:04 +00:00
|
|
|
|
for (i = 0; i < 4; i++)
|
|
|
|
|
{
|
|
|
|
|
if (private_data->arrow_win[i])
|
|
|
|
|
{
|
|
|
|
|
gdk_window_set_user_data (private_data->arrow_win[i],
|
|
|
|
|
NULL);
|
|
|
|
|
gdk_window_destroy (private_data->arrow_win[i]);
|
|
|
|
|
private_data->arrow_win[i] = NULL;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
gdk_window_set_user_data (private_data->header_win, NULL);
|
|
|
|
|
gdk_window_destroy (private_data->header_win);
|
|
|
|
|
private_data->header_win = NULL;
|
1998-09-27 18:32:00 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
1998-10-01 13:24:42 +00:00
|
|
|
|
|
|
|
|
|
|
1998-09-27 18:32:00 +00:00
|
|
|
|
if ((flags ^ calendar->display_flags) & GTK_CALENDAR_SHOW_DAY_NAMES)
|
|
|
|
|
{
|
|
|
|
|
resize++;
|
1998-10-01 13:24:42 +00:00
|
|
|
|
|
1998-09-27 18:32:00 +00:00
|
|
|
|
if (flags & GTK_CALENDAR_SHOW_DAY_NAMES)
|
|
|
|
|
{
|
|
|
|
|
calendar->display_flags |= GTK_CALENDAR_SHOW_DAY_NAMES;
|
|
|
|
|
gtk_calendar_realize_day_names (widget);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
1998-10-04 23:07:04 +00:00
|
|
|
|
gdk_window_set_user_data (private_data->day_name_win, NULL);
|
|
|
|
|
gdk_window_destroy (private_data->day_name_win);
|
|
|
|
|
private_data->day_name_win = NULL;
|
1998-09-27 18:32:00 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
1998-10-01 13:24:42 +00:00
|
|
|
|
|
1998-09-27 18:32:00 +00:00
|
|
|
|
if ((flags ^ calendar->display_flags) & GTK_CALENDAR_SHOW_WEEK_NUMBERS)
|
|
|
|
|
{
|
|
|
|
|
resize++;
|
1998-10-01 13:24:42 +00:00
|
|
|
|
|
1998-09-27 18:32:00 +00:00
|
|
|
|
if (flags & GTK_CALENDAR_SHOW_WEEK_NUMBERS)
|
|
|
|
|
{
|
|
|
|
|
calendar->display_flags |= GTK_CALENDAR_SHOW_WEEK_NUMBERS;
|
|
|
|
|
gtk_calendar_realize_week_numbers (widget);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
1998-10-04 23:07:04 +00:00
|
|
|
|
gdk_window_set_user_data (private_data->week_win, NULL);
|
|
|
|
|
gdk_window_destroy (private_data->week_win);
|
|
|
|
|
private_data->week_win = NULL;
|
1998-09-27 18:32:00 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
1998-10-01 13:24:42 +00:00
|
|
|
|
|
1998-09-27 18:32:00 +00:00
|
|
|
|
if ((flags ^ calendar->display_flags) & GTK_CALENDAR_WEEK_START_MONDAY)
|
|
|
|
|
{
|
|
|
|
|
if (calendar->display_flags & GTK_CALENDAR_WEEK_START_MONDAY)
|
|
|
|
|
calendar->display_flags &= ~GTK_CALENDAR_WEEK_START_MONDAY;
|
|
|
|
|
else
|
|
|
|
|
calendar->display_flags |= GTK_CALENDAR_WEEK_START_MONDAY;
|
1998-10-01 13:24:42 +00:00
|
|
|
|
|
1998-09-27 18:32:00 +00:00
|
|
|
|
gtk_calendar_compute_days (calendar);
|
|
|
|
|
gtk_calendar_paint_main (GTK_WIDGET (calendar));
|
1998-10-04 23:07:04 +00:00
|
|
|
|
if (private_data->day_name_win)
|
1998-09-27 18:32:00 +00:00
|
|
|
|
gtk_calendar_paint_day_names (GTK_WIDGET (calendar));
|
|
|
|
|
}
|
1998-10-01 13:24:42 +00:00
|
|
|
|
|
1998-09-27 18:32:00 +00:00
|
|
|
|
calendar->display_flags = flags;
|
|
|
|
|
if (resize)
|
|
|
|
|
gtk_widget_queue_resize (GTK_WIDGET (calendar));
|
1998-10-01 13:24:42 +00:00
|
|
|
|
|
1998-09-27 18:32:00 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
calendar->display_flags = flags;
|
1998-10-01 13:24:42 +00:00
|
|
|
|
|
1998-09-27 18:32:00 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
gint
|
1998-10-01 13:24:42 +00:00
|
|
|
|
gtk_calendar_select_month (GtkCalendar *calendar,
|
|
|
|
|
guint month,
|
|
|
|
|
guint year)
|
1998-09-27 18:32:00 +00:00
|
|
|
|
{
|
|
|
|
|
g_return_val_if_fail (calendar != NULL, FALSE);
|
|
|
|
|
g_return_val_if_fail (GTK_IS_CALENDAR (calendar), FALSE);
|
1998-10-01 13:24:42 +00:00
|
|
|
|
g_return_val_if_fail (month <= 11, FALSE);
|
|
|
|
|
|
1998-09-27 18:32:00 +00:00
|
|
|
|
calendar->month = month;
|
|
|
|
|
calendar->year = year;
|
1998-10-01 13:24:42 +00:00
|
|
|
|
|
1998-09-27 18:32:00 +00:00
|
|
|
|
gtk_calendar_compute_days (calendar);
|
1998-10-01 13:24:42 +00:00
|
|
|
|
|
1998-09-27 18:32:00 +00:00
|
|
|
|
if (GTK_WIDGET_DRAWABLE (GTK_WIDGET (calendar)))
|
|
|
|
|
gtk_calendar_paint (GTK_WIDGET (calendar), NULL);
|
1998-10-01 13:24:42 +00:00
|
|
|
|
|
1998-09-27 18:32:00 +00:00
|
|
|
|
gtk_signal_emit (GTK_OBJECT (calendar),
|
1998-10-01 13:24:42 +00:00
|
|
|
|
gtk_calendar_signals[MONTH_CHANGED_SIGNAL]);
|
1998-09-27 18:32:00 +00:00
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
1998-10-01 13:24:42 +00:00
|
|
|
|
gtk_calendar_select_day (GtkCalendar *calendar,
|
|
|
|
|
guint day)
|
1998-09-27 18:32:00 +00:00
|
|
|
|
{
|
|
|
|
|
g_return_if_fail (calendar != NULL);
|
1998-10-01 13:24:42 +00:00
|
|
|
|
g_return_if_fail (GTK_IS_CALENDAR (calendar));
|
|
|
|
|
g_return_if_fail (day <= 31);
|
|
|
|
|
|
|
|
|
|
/* gtk_calendar_compute_days (calendar); */
|
1998-09-27 18:32:00 +00:00
|
|
|
|
|
|
|
|
|
/* Deselect the old day */
|
|
|
|
|
if (calendar->selected_day > 0)
|
|
|
|
|
{
|
|
|
|
|
gint selected_day;
|
|
|
|
|
|
|
|
|
|
selected_day = calendar->selected_day;
|
|
|
|
|
calendar->selected_day = 0;
|
|
|
|
|
if (GTK_WIDGET_DRAWABLE (GTK_WIDGET (calendar)))
|
|
|
|
|
gtk_calendar_paint_day_num (GTK_WIDGET (calendar), selected_day);
|
|
|
|
|
}
|
1998-10-01 13:24:42 +00:00
|
|
|
|
|
1998-09-27 18:32:00 +00:00
|
|
|
|
calendar->selected_day = day;
|
1998-10-01 13:24:42 +00:00
|
|
|
|
|
1998-09-27 18:32:00 +00:00
|
|
|
|
/* Deselect the new day */
|
|
|
|
|
if (day != 0)
|
|
|
|
|
{
|
|
|
|
|
if (GTK_WIDGET_DRAWABLE (GTK_WIDGET (calendar)))
|
1998-10-01 13:24:42 +00:00
|
|
|
|
gtk_calendar_paint_day_num (GTK_WIDGET (calendar), day);
|
1998-09-27 18:32:00 +00:00
|
|
|
|
}
|
1998-10-01 13:24:42 +00:00
|
|
|
|
|
1998-09-27 18:32:00 +00:00
|
|
|
|
gtk_signal_emit (GTK_OBJECT (calendar),
|
1998-10-01 13:24:42 +00:00
|
|
|
|
gtk_calendar_signals[DAY_SELECTED_SIGNAL]);
|
1998-09-27 18:32:00 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
gtk_calendar_clear_marks (GtkCalendar *calendar)
|
|
|
|
|
{
|
1998-10-01 13:24:42 +00:00
|
|
|
|
guint day;
|
|
|
|
|
|
1998-09-27 18:32:00 +00:00
|
|
|
|
g_return_if_fail (calendar != NULL);
|
1998-10-01 13:24:42 +00:00
|
|
|
|
g_return_if_fail (GTK_IS_CALENDAR (calendar));
|
|
|
|
|
|
|
|
|
|
for (day = 0; day < 31; day++)
|
1998-09-27 18:32:00 +00:00
|
|
|
|
{
|
|
|
|
|
calendar->marked_date[day] = FALSE;
|
|
|
|
|
}
|
1998-10-01 13:24:42 +00:00
|
|
|
|
|
|
|
|
|
if (GTK_WIDGET_DRAWABLE (calendar))
|
1998-09-27 18:32:00 +00:00
|
|
|
|
{
|
|
|
|
|
gtk_calendar_paint_main (GTK_WIDGET (calendar));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
gint
|
1998-10-01 13:24:42 +00:00
|
|
|
|
gtk_calendar_mark_day (GtkCalendar *calendar,
|
|
|
|
|
guint day)
|
1998-09-27 18:32:00 +00:00
|
|
|
|
{
|
|
|
|
|
g_return_val_if_fail (calendar != NULL, FALSE);
|
1998-10-01 13:24:42 +00:00
|
|
|
|
g_return_val_if_fail (GTK_IS_CALENDAR (calendar), FALSE);
|
|
|
|
|
|
|
|
|
|
if (day >= 1 && day <= 31)
|
|
|
|
|
calendar->marked_date[day - 1] = TRUE;
|
|
|
|
|
|
1998-09-27 18:32:00 +00:00
|
|
|
|
if (GTK_WIDGET_DRAWABLE (GTK_WIDGET (calendar)))
|
|
|
|
|
{
|
|
|
|
|
gtk_calendar_paint_main (GTK_WIDGET (calendar));
|
|
|
|
|
}
|
1998-10-01 13:24:42 +00:00
|
|
|
|
|
1998-09-27 18:32:00 +00:00
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
gint
|
1998-10-01 13:24:42 +00:00
|
|
|
|
gtk_calendar_unmark_day (GtkCalendar *calendar,
|
|
|
|
|
guint day)
|
1998-09-27 18:32:00 +00:00
|
|
|
|
{
|
|
|
|
|
g_return_val_if_fail (calendar != NULL, FALSE);
|
1998-10-01 13:24:42 +00:00
|
|
|
|
g_return_val_if_fail (GTK_IS_CALENDAR (calendar), FALSE);
|
|
|
|
|
|
|
|
|
|
if (day >= 1 && day <= 31)
|
|
|
|
|
calendar->marked_date[day - 1] = FALSE;
|
|
|
|
|
|
1998-09-27 18:32:00 +00:00
|
|
|
|
if (GTK_WIDGET_DRAWABLE (GTK_WIDGET (calendar)))
|
|
|
|
|
{
|
|
|
|
|
gtk_calendar_paint_main (GTK_WIDGET (calendar));
|
|
|
|
|
}
|
1998-10-01 13:24:42 +00:00
|
|
|
|
|
1998-09-27 18:32:00 +00:00
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
1998-10-01 13:24:42 +00:00
|
|
|
|
gtk_calendar_get_date (GtkCalendar *calendar,
|
|
|
|
|
guint *year,
|
|
|
|
|
guint *month,
|
|
|
|
|
guint *day)
|
1998-09-27 18:32:00 +00:00
|
|
|
|
{
|
|
|
|
|
g_return_if_fail (calendar != NULL);
|
|
|
|
|
g_return_if_fail (GTK_IS_CALENDAR (calendar));
|
1998-10-01 13:24:42 +00:00
|
|
|
|
|
1998-09-27 18:32:00 +00:00
|
|
|
|
if (year)
|
|
|
|
|
*year = calendar->year;
|
1998-10-01 13:24:42 +00:00
|
|
|
|
|
1998-09-27 18:32:00 +00:00
|
|
|
|
if (month)
|
|
|
|
|
*month = calendar->month;
|
1998-10-01 13:24:42 +00:00
|
|
|
|
|
1998-09-27 18:32:00 +00:00
|
|
|
|
if (day)
|
|
|
|
|
*day = calendar->selected_day;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static gint
|
1998-10-01 13:24:42 +00:00
|
|
|
|
gtk_calendar_button_press (GtkWidget *widget,
|
1998-09-27 18:32:00 +00:00
|
|
|
|
GdkEventButton *event)
|
|
|
|
|
{
|
|
|
|
|
GtkCalendar *calendar;
|
1998-10-04 23:07:04 +00:00
|
|
|
|
GtkCalendarPrivateData *private_data;
|
1998-09-27 18:32:00 +00:00
|
|
|
|
gint x, y;
|
1998-10-01 13:24:42 +00:00
|
|
|
|
|
1998-09-27 18:32:00 +00:00
|
|
|
|
g_return_val_if_fail (widget != NULL, FALSE);
|
|
|
|
|
g_return_val_if_fail (GTK_IS_CALENDAR (widget), FALSE);
|
|
|
|
|
g_return_val_if_fail (event != NULL, FALSE);
|
1998-10-01 13:24:42 +00:00
|
|
|
|
|
1998-09-27 18:32:00 +00:00
|
|
|
|
calendar = GTK_CALENDAR (widget);
|
1998-10-04 23:07:04 +00:00
|
|
|
|
private_data = GTK_CALENDAR_PRIVATE_DATA (widget);
|
1998-10-01 13:24:42 +00:00
|
|
|
|
|
1998-09-27 18:32:00 +00:00
|
|
|
|
x = (gint) (event->x);
|
|
|
|
|
y = (gint) (event->y);
|
1998-10-01 13:24:42 +00:00
|
|
|
|
|
1998-10-04 23:07:04 +00:00
|
|
|
|
if (event->window == private_data->arrow_win[ARROW_MONTH_LEFT])
|
1998-09-27 18:32:00 +00:00
|
|
|
|
gtk_calendar_set_month_prev (calendar);
|
1998-10-01 13:24:42 +00:00
|
|
|
|
|
1998-10-04 23:07:04 +00:00
|
|
|
|
if (event->window == private_data->arrow_win[ARROW_MONTH_RIGHT])
|
1998-09-27 18:32:00 +00:00
|
|
|
|
gtk_calendar_set_month_next (calendar);
|
1998-10-01 13:24:42 +00:00
|
|
|
|
|
1998-10-04 23:07:04 +00:00
|
|
|
|
if (event->window == private_data->arrow_win[ARROW_YEAR_LEFT])
|
1998-09-27 18:32:00 +00:00
|
|
|
|
gtk_calendar_set_year_prev (calendar);
|
1998-10-01 13:24:42 +00:00
|
|
|
|
|
1998-10-04 23:07:04 +00:00
|
|
|
|
if (event->window == private_data->arrow_win[ARROW_YEAR_RIGHT])
|
1998-09-27 18:32:00 +00:00
|
|
|
|
gtk_calendar_set_year_next (calendar);
|
1998-10-01 13:24:42 +00:00
|
|
|
|
|
1998-10-04 23:07:04 +00:00
|
|
|
|
if (event->window == private_data->main_win)
|
1998-09-27 18:32:00 +00:00
|
|
|
|
gtk_calendar_main_button (widget, event);
|
1998-10-01 13:24:42 +00:00
|
|
|
|
|
1998-09-27 18:32:00 +00:00
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static gint
|
1998-10-01 13:24:42 +00:00
|
|
|
|
gtk_calendar_motion_notify (GtkWidget *widget,
|
1998-09-27 18:32:00 +00:00
|
|
|
|
GdkEventMotion *event)
|
|
|
|
|
{
|
|
|
|
|
GtkCalendar *calendar;
|
1998-10-04 23:07:04 +00:00
|
|
|
|
GtkCalendarPrivateData *private_data;
|
1998-09-27 18:32:00 +00:00
|
|
|
|
gint event_x, event_y;
|
|
|
|
|
gint row, col;
|
|
|
|
|
gint old_row, old_col;
|
1998-10-01 13:24:42 +00:00
|
|
|
|
|
1998-10-04 23:07:04 +00:00
|
|
|
|
calendar = GTK_CALENDAR (widget);
|
|
|
|
|
private_data = GTK_CALENDAR_PRIVATE_DATA (widget);
|
1998-09-27 18:32:00 +00:00
|
|
|
|
event_x = (gint) (event->x);
|
|
|
|
|
event_y = (gint) (event->y);
|
1998-10-01 13:24:42 +00:00
|
|
|
|
|
1998-10-04 23:07:04 +00:00
|
|
|
|
if (event->window == private_data->main_win)
|
1998-09-27 18:32:00 +00:00
|
|
|
|
{
|
1998-10-01 13:24:42 +00:00
|
|
|
|
|
1998-09-27 18:32:00 +00:00
|
|
|
|
row = row_from_y (calendar, event_y);
|
|
|
|
|
col = column_from_x (calendar, event_x);
|
1998-10-01 13:24:42 +00:00
|
|
|
|
|
1998-09-27 18:32:00 +00:00
|
|
|
|
if (row != calendar->highlight_row || calendar->highlight_col != col)
|
|
|
|
|
{
|
|
|
|
|
old_row = calendar->highlight_row;
|
|
|
|
|
old_col = calendar->highlight_col;
|
|
|
|
|
if (old_row > -1 && old_col > -1)
|
|
|
|
|
{
|
|
|
|
|
calendar->highlight_row = -1;
|
|
|
|
|
calendar->highlight_col = -1;
|
|
|
|
|
gtk_calendar_paint_day (widget, old_row, old_col);
|
|
|
|
|
}
|
1998-10-01 13:24:42 +00:00
|
|
|
|
|
1998-09-27 18:32:00 +00:00
|
|
|
|
calendar->highlight_row = row;
|
|
|
|
|
calendar->highlight_col = col;
|
1998-10-01 13:24:42 +00:00
|
|
|
|
|
1998-09-27 18:32:00 +00:00
|
|
|
|
if (row > -1 && col > -1)
|
|
|
|
|
gtk_calendar_paint_day (widget, row, col);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static gint
|
1998-10-01 13:24:42 +00:00
|
|
|
|
gtk_calendar_enter_notify (GtkWidget *widget,
|
|
|
|
|
GdkEventCrossing *event)
|
1998-09-27 18:32:00 +00:00
|
|
|
|
{
|
|
|
|
|
GtkCalendar *calendar;
|
1998-10-04 23:07:04 +00:00
|
|
|
|
GtkCalendarPrivateData *private_data;
|
1998-10-01 13:24:42 +00:00
|
|
|
|
|
1998-09-27 18:32:00 +00:00
|
|
|
|
g_return_val_if_fail (widget != NULL, FALSE);
|
|
|
|
|
g_return_val_if_fail (event != NULL, FALSE);
|
1998-10-01 13:24:42 +00:00
|
|
|
|
|
1998-09-27 18:32:00 +00:00
|
|
|
|
calendar = GTK_CALENDAR (widget);
|
1998-10-04 23:07:04 +00:00
|
|
|
|
private_data = GTK_CALENDAR_PRIVATE_DATA (widget);
|
1998-10-01 13:24:42 +00:00
|
|
|
|
|
1998-10-04 23:07:04 +00:00
|
|
|
|
if (event->window == private_data->arrow_win[ARROW_MONTH_LEFT])
|
1998-09-27 18:32:00 +00:00
|
|
|
|
{
|
1998-10-04 23:07:04 +00:00
|
|
|
|
private_data->arrow_state[ARROW_MONTH_LEFT] = GTK_STATE_PRELIGHT;
|
1998-09-27 18:32:00 +00:00
|
|
|
|
gtk_calendar_paint_arrow (widget, ARROW_MONTH_LEFT);
|
|
|
|
|
}
|
1998-10-01 13:24:42 +00:00
|
|
|
|
|
1998-10-04 23:07:04 +00:00
|
|
|
|
if (event->window == private_data->arrow_win[ARROW_MONTH_RIGHT])
|
1998-09-27 18:32:00 +00:00
|
|
|
|
{
|
1998-10-04 23:07:04 +00:00
|
|
|
|
private_data->arrow_state[ARROW_MONTH_RIGHT] = GTK_STATE_PRELIGHT;
|
1998-09-27 18:32:00 +00:00
|
|
|
|
gtk_calendar_paint_arrow (widget, ARROW_MONTH_RIGHT);
|
|
|
|
|
}
|
1998-10-01 13:24:42 +00:00
|
|
|
|
|
1998-10-04 23:07:04 +00:00
|
|
|
|
if (event->window == private_data->arrow_win[ARROW_YEAR_LEFT])
|
1998-09-27 18:32:00 +00:00
|
|
|
|
{
|
1998-10-04 23:07:04 +00:00
|
|
|
|
private_data->arrow_state[ARROW_YEAR_LEFT] = GTK_STATE_PRELIGHT;
|
1998-09-27 18:32:00 +00:00
|
|
|
|
gtk_calendar_paint_arrow (widget, ARROW_YEAR_LEFT);
|
|
|
|
|
}
|
1998-10-01 13:24:42 +00:00
|
|
|
|
|
1998-10-04 23:07:04 +00:00
|
|
|
|
if (event->window == private_data->arrow_win[ARROW_YEAR_RIGHT])
|
1998-09-27 18:32:00 +00:00
|
|
|
|
{
|
1998-10-04 23:07:04 +00:00
|
|
|
|
private_data->arrow_state[ARROW_YEAR_RIGHT] = GTK_STATE_PRELIGHT;
|
1998-09-27 18:32:00 +00:00
|
|
|
|
gtk_calendar_paint_arrow (widget, ARROW_YEAR_RIGHT);
|
|
|
|
|
}
|
1998-10-01 13:24:42 +00:00
|
|
|
|
|
1998-09-27 18:32:00 +00:00
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static gint
|
1998-10-01 13:24:42 +00:00
|
|
|
|
gtk_calendar_leave_notify (GtkWidget *widget,
|
|
|
|
|
GdkEventCrossing *event)
|
1998-09-27 18:32:00 +00:00
|
|
|
|
{
|
|
|
|
|
GtkCalendar *calendar;
|
1998-10-04 23:07:04 +00:00
|
|
|
|
GtkCalendarPrivateData *private_data;
|
1998-09-27 18:32:00 +00:00
|
|
|
|
gint row;
|
|
|
|
|
gint col;
|
1998-10-01 13:24:42 +00:00
|
|
|
|
|
1998-09-27 18:32:00 +00:00
|
|
|
|
g_return_val_if_fail (widget != NULL, FALSE);
|
|
|
|
|
g_return_val_if_fail (event != NULL, FALSE);
|
1998-10-01 13:24:42 +00:00
|
|
|
|
|
1998-09-27 18:32:00 +00:00
|
|
|
|
calendar = GTK_CALENDAR (widget);
|
1998-10-04 23:07:04 +00:00
|
|
|
|
private_data = GTK_CALENDAR_PRIVATE_DATA (widget);
|
1998-10-01 13:24:42 +00:00
|
|
|
|
|
1998-10-04 23:07:04 +00:00
|
|
|
|
if (event->window == private_data->main_win)
|
1998-09-27 18:32:00 +00:00
|
|
|
|
{
|
|
|
|
|
row = calendar->highlight_row;
|
|
|
|
|
col = calendar->highlight_col;
|
|
|
|
|
calendar->highlight_row = -1;
|
|
|
|
|
calendar->highlight_col = -1;
|
|
|
|
|
if (row > -1 && col > -1)
|
|
|
|
|
gtk_calendar_paint_day (widget, row, col);
|
|
|
|
|
}
|
1998-10-01 13:24:42 +00:00
|
|
|
|
|
1998-10-04 23:07:04 +00:00
|
|
|
|
if (event->window == private_data->arrow_win[ARROW_MONTH_LEFT])
|
1998-09-27 18:32:00 +00:00
|
|
|
|
{
|
1998-10-04 23:07:04 +00:00
|
|
|
|
private_data->arrow_state[ARROW_MONTH_LEFT] = GTK_STATE_NORMAL;
|
1998-09-27 18:32:00 +00:00
|
|
|
|
gtk_calendar_paint_arrow (widget, ARROW_MONTH_LEFT);
|
|
|
|
|
}
|
1998-10-01 13:24:42 +00:00
|
|
|
|
|
1998-10-04 23:07:04 +00:00
|
|
|
|
if (event->window == private_data->arrow_win[ARROW_MONTH_RIGHT])
|
1998-09-27 18:32:00 +00:00
|
|
|
|
{
|
1998-10-04 23:07:04 +00:00
|
|
|
|
private_data->arrow_state[ARROW_MONTH_RIGHT] = GTK_STATE_NORMAL;
|
1998-09-27 18:32:00 +00:00
|
|
|
|
gtk_calendar_paint_arrow (widget, ARROW_MONTH_RIGHT);
|
|
|
|
|
}
|
1998-10-01 13:24:42 +00:00
|
|
|
|
|
1998-10-04 23:07:04 +00:00
|
|
|
|
if (event->window == private_data->arrow_win[ARROW_YEAR_LEFT])
|
1998-09-27 18:32:00 +00:00
|
|
|
|
{
|
1998-10-04 23:07:04 +00:00
|
|
|
|
private_data->arrow_state[ARROW_YEAR_LEFT] = GTK_STATE_NORMAL;
|
1998-09-27 18:32:00 +00:00
|
|
|
|
gtk_calendar_paint_arrow (widget, ARROW_YEAR_LEFT);
|
|
|
|
|
}
|
1998-10-01 13:24:42 +00:00
|
|
|
|
|
1998-10-04 23:07:04 +00:00
|
|
|
|
if (event->window == private_data->arrow_win[ARROW_YEAR_RIGHT])
|
1998-09-27 18:32:00 +00:00
|
|
|
|
{
|
1998-10-04 23:07:04 +00:00
|
|
|
|
private_data->arrow_state[ARROW_YEAR_RIGHT] = GTK_STATE_NORMAL;
|
1998-09-27 18:32:00 +00:00
|
|
|
|
gtk_calendar_paint_arrow (widget, ARROW_YEAR_RIGHT);
|
|
|
|
|
}
|
1998-10-01 13:24:42 +00:00
|
|
|
|
|
1998-09-27 18:32:00 +00:00
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
1998-10-01 13:24:42 +00:00
|
|
|
|
gtk_calendar_paint_arrow (GtkWidget *widget,
|
|
|
|
|
guint arrow)
|
1998-09-27 18:32:00 +00:00
|
|
|
|
{
|
1998-10-04 23:07:04 +00:00
|
|
|
|
GtkCalendarPrivateData *private_data;
|
1998-09-27 18:32:00 +00:00
|
|
|
|
GdkWindow *window;
|
|
|
|
|
GdkGC *gc;
|
|
|
|
|
GtkCalendar *calendar;
|
|
|
|
|
gint state;
|
|
|
|
|
gint width, height;
|
1998-10-01 13:24:42 +00:00
|
|
|
|
|
1998-09-27 18:32:00 +00:00
|
|
|
|
g_return_if_fail (widget != NULL);
|
1998-10-01 13:24:42 +00:00
|
|
|
|
|
1998-09-27 18:32:00 +00:00
|
|
|
|
calendar = GTK_CALENDAR (widget);
|
1998-10-04 23:07:04 +00:00
|
|
|
|
private_data = GTK_CALENDAR_PRIVATE_DATA (widget);
|
|
|
|
|
|
1998-11-28 01:56:09 +00:00
|
|
|
|
if (private_data->freeze_count)
|
1998-09-27 18:32:00 +00:00
|
|
|
|
{
|
1998-10-04 23:07:04 +00:00
|
|
|
|
private_data->dirty_header = 1;
|
1998-09-27 18:32:00 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
1998-10-04 23:07:04 +00:00
|
|
|
|
window = private_data->arrow_win[arrow];
|
1998-09-27 18:32:00 +00:00
|
|
|
|
if (window)
|
|
|
|
|
{
|
1998-10-04 23:07:04 +00:00
|
|
|
|
state = private_data->arrow_state[arrow];
|
1998-09-27 18:32:00 +00:00
|
|
|
|
gc = calendar->gc;
|
1998-10-01 13:24:42 +00:00
|
|
|
|
|
1998-09-27 18:32:00 +00:00
|
|
|
|
gdk_window_clear (window);
|
|
|
|
|
gdk_window_set_background (window, &(widget)->style->bg[state]);
|
|
|
|
|
gdk_window_get_size (window, &width, &height);
|
|
|
|
|
gdk_window_clear_area (window,
|
|
|
|
|
0,0,
|
|
|
|
|
width,height);
|
1998-10-01 13:24:42 +00:00
|
|
|
|
|
1998-09-27 18:32:00 +00:00
|
|
|
|
gdk_gc_set_foreground (gc, & (widget)->style->fg[state]);
|
1998-10-01 13:24:42 +00:00
|
|
|
|
|
1998-09-27 18:32:00 +00:00
|
|
|
|
if (arrow == ARROW_MONTH_LEFT || arrow == ARROW_YEAR_LEFT)
|
|
|
|
|
draw_arrow_left (window, gc, width/2 - 3, height/2 - 4, 8);
|
|
|
|
|
else
|
|
|
|
|
draw_arrow_right (window, gc, width/2 - 2, height/2 - 4, 8);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
gtk_calendar_freeze (GtkCalendar *calendar)
|
|
|
|
|
{
|
1998-10-01 13:24:42 +00:00
|
|
|
|
g_return_if_fail (calendar != NULL);
|
1998-09-27 18:32:00 +00:00
|
|
|
|
g_return_if_fail (GTK_IS_CALENDAR (calendar));
|
1998-10-01 13:24:42 +00:00
|
|
|
|
|
1998-11-28 01:56:09 +00:00
|
|
|
|
GTK_CALENDAR_PRIVATE_DATA (calendar)->freeze_count++;
|
1998-09-27 18:32:00 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
gtk_calendar_thaw (GtkCalendar *calendar)
|
|
|
|
|
{
|
1998-10-04 23:07:04 +00:00
|
|
|
|
GtkCalendarPrivateData *private_data;
|
|
|
|
|
|
1998-10-01 13:24:42 +00:00
|
|
|
|
g_return_if_fail (calendar != NULL);
|
1998-09-27 18:32:00 +00:00
|
|
|
|
g_return_if_fail (GTK_IS_CALENDAR (calendar));
|
1998-10-01 13:24:42 +00:00
|
|
|
|
|
1998-10-04 23:07:04 +00:00
|
|
|
|
private_data = GTK_CALENDAR_PRIVATE_DATA (calendar);
|
1998-11-28 01:56:09 +00:00
|
|
|
|
|
|
|
|
|
if (private_data->freeze_count)
|
|
|
|
|
if (!(--private_data->freeze_count))
|
|
|
|
|
{
|
|
|
|
|
if (private_data->dirty_header)
|
|
|
|
|
if (GTK_WIDGET_DRAWABLE (calendar))
|
|
|
|
|
gtk_calendar_paint_header (GTK_WIDGET (calendar));
|
|
|
|
|
|
|
|
|
|
if (private_data->dirty_day_names)
|
|
|
|
|
if (GTK_WIDGET_DRAWABLE (calendar))
|
|
|
|
|
gtk_calendar_paint_day_names (GTK_WIDGET (calendar));
|
|
|
|
|
|
|
|
|
|
if (private_data->dirty_week)
|
|
|
|
|
if (GTK_WIDGET_DRAWABLE (calendar))
|
|
|
|
|
gtk_calendar_paint_week_numbers (GTK_WIDGET (calendar));
|
|
|
|
|
|
|
|
|
|
if (private_data->dirty_main)
|
|
|
|
|
if (GTK_WIDGET_DRAWABLE (calendar))
|
|
|
|
|
gtk_calendar_paint_main (GTK_WIDGET (calendar));
|
|
|
|
|
}
|
1998-09-27 18:32:00 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
1998-10-01 13:24:42 +00:00
|
|
|
|
gtk_calendar_set_background (GtkWidget *widget)
|
1998-09-27 18:32:00 +00:00
|
|
|
|
{
|
|
|
|
|
GtkCalendar *calendar;
|
1998-10-04 23:07:04 +00:00
|
|
|
|
GtkCalendarPrivateData *private_data;
|
1998-09-27 18:32:00 +00:00
|
|
|
|
gint i;
|
1998-10-01 13:24:42 +00:00
|
|
|
|
|
|
|
|
|
g_return_if_fail (widget != NULL);
|
1998-09-27 18:32:00 +00:00
|
|
|
|
g_return_if_fail (GTK_IS_CALENDAR (widget));
|
1998-10-01 13:24:42 +00:00
|
|
|
|
|
1998-10-04 23:07:04 +00:00
|
|
|
|
calendar = GTK_CALENDAR (widget);
|
|
|
|
|
private_data = GTK_CALENDAR_PRIVATE_DATA (widget);
|
|
|
|
|
|
1998-09-27 18:32:00 +00:00
|
|
|
|
if (GTK_WIDGET_REALIZED (widget))
|
|
|
|
|
{
|
1998-10-04 23:07:04 +00:00
|
|
|
|
for (i = 0; i < 4; i++)
|
|
|
|
|
{
|
|
|
|
|
if (private_data->arrow_win[i])
|
|
|
|
|
gdk_window_set_background (private_data->arrow_win[i],
|
|
|
|
|
HEADER_BG_COLOR (widget));
|
|
|
|
|
}
|
|
|
|
|
if (private_data->header_win)
|
|
|
|
|
gdk_window_set_background (private_data->header_win,
|
|
|
|
|
HEADER_BG_COLOR (widget));
|
|
|
|
|
if (private_data->day_name_win)
|
|
|
|
|
gdk_window_set_background (private_data->day_name_win,
|
|
|
|
|
BACKGROUND_COLOR (widget));
|
|
|
|
|
if (private_data->week_win)
|
|
|
|
|
gdk_window_set_background (private_data->week_win,
|
|
|
|
|
BACKGROUND_COLOR (widget));
|
|
|
|
|
if (private_data->main_win)
|
|
|
|
|
gdk_window_set_background (private_data->main_win,
|
|
|
|
|
BACKGROUND_COLOR (widget));
|
1998-09-27 18:32:00 +00:00
|
|
|
|
if (widget->window)
|
1998-10-04 23:07:04 +00:00
|
|
|
|
gdk_window_set_background (widget->window,
|
|
|
|
|
BACKGROUND_COLOR (widget));
|
1998-09-27 18:32:00 +00:00
|
|
|
|
}
|
|
|
|
|
if (GTK_WIDGET_DRAWABLE (widget))
|
|
|
|
|
gdk_window_clear (widget->window);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
gtk_calendar_style_set (GtkWidget *widget,
|
|
|
|
|
GtkStyle *previous_style)
|
|
|
|
|
{
|
|
|
|
|
g_return_if_fail (widget != NULL);
|
|
|
|
|
g_return_if_fail (GTK_IS_CALENDAR (widget));
|
1998-10-01 13:24:42 +00:00
|
|
|
|
|
1998-09-27 18:32:00 +00:00
|
|
|
|
if (previous_style && GTK_WIDGET_REALIZED (widget))
|
|
|
|
|
gtk_calendar_set_background(widget);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
1998-10-01 13:24:42 +00:00
|
|
|
|
gtk_calendar_state_changed (GtkWidget *widget,
|
|
|
|
|
GtkStateType previous_state)
|
1998-09-27 18:32:00 +00:00
|
|
|
|
{
|
|
|
|
|
g_return_if_fail (widget != NULL);
|
|
|
|
|
g_return_if_fail (GTK_IS_CALENDAR (widget));
|
1998-10-01 13:24:42 +00:00
|
|
|
|
|
|
|
|
|
gtk_calendar_set_background (widget);
|
1998-09-27 18:32:00 +00:00
|
|
|
|
}
|
|
|
|
|
|
1998-10-01 13:24:42 +00:00
|
|
|
|
static gint
|
|
|
|
|
gtk_calendar_focus_in (GtkWidget *widget,
|
|
|
|
|
GdkEventFocus *event)
|
1998-09-27 18:32:00 +00:00
|
|
|
|
{
|
|
|
|
|
GtkCalendar *calendar;
|
1998-10-01 13:24:42 +00:00
|
|
|
|
|
1998-09-27 18:32:00 +00:00
|
|
|
|
g_return_val_if_fail (widget != NULL, FALSE);
|
|
|
|
|
g_return_val_if_fail (GTK_IS_CALENDAR (widget), FALSE);
|
|
|
|
|
g_return_val_if_fail (event != NULL, FALSE);
|
1998-10-01 13:24:42 +00:00
|
|
|
|
|
1998-09-27 18:32:00 +00:00
|
|
|
|
calendar = GTK_CALENDAR (widget);
|
1998-10-01 13:24:42 +00:00
|
|
|
|
|
1998-09-27 18:32:00 +00:00
|
|
|
|
GTK_WIDGET_SET_FLAGS (widget, GTK_HAS_FOCUS);
|
|
|
|
|
gtk_widget_draw_focus (widget);
|
1998-10-05 03:52:48 +00:00
|
|
|
|
gtk_calendar_paint_day (widget, calendar->focus_row, calendar->focus_col);
|
1998-10-01 13:24:42 +00:00
|
|
|
|
|
1998-09-27 18:32:00 +00:00
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
1998-10-01 13:24:42 +00:00
|
|
|
|
static gint
|
|
|
|
|
gtk_calendar_focus_out (GtkWidget *widget,
|
|
|
|
|
GdkEventFocus *event)
|
1998-09-27 18:32:00 +00:00
|
|
|
|
{
|
|
|
|
|
GtkCalendar *calendar;
|
1998-10-01 13:24:42 +00:00
|
|
|
|
|
1998-09-27 18:32:00 +00:00
|
|
|
|
g_return_val_if_fail (widget != NULL, FALSE);
|
|
|
|
|
g_return_val_if_fail (GTK_IS_CALENDAR (widget), FALSE);
|
|
|
|
|
g_return_val_if_fail (event != NULL, FALSE);
|
1998-10-01 13:24:42 +00:00
|
|
|
|
|
1998-09-27 18:32:00 +00:00
|
|
|
|
calendar = GTK_CALENDAR (widget);
|
1998-10-01 13:24:42 +00:00
|
|
|
|
|
1998-09-27 18:32:00 +00:00
|
|
|
|
GTK_WIDGET_UNSET_FLAGS (widget, GTK_HAS_FOCUS);
|
|
|
|
|
gtk_widget_draw_focus (widget);
|
1998-10-05 03:52:48 +00:00
|
|
|
|
gtk_calendar_paint_day (widget, calendar->focus_row, calendar->focus_col);
|
1998-10-01 13:24:42 +00:00
|
|
|
|
|
1998-09-27 18:32:00 +00:00
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static gint
|
|
|
|
|
gtk_calendar_key_press (GtkWidget *widget,
|
1998-10-01 13:24:42 +00:00
|
|
|
|
GdkEventKey *event)
|
1998-09-27 18:32:00 +00:00
|
|
|
|
{
|
|
|
|
|
GtkCalendar *calendar;
|
|
|
|
|
gint return_val;
|
1998-10-05 03:52:48 +00:00
|
|
|
|
gint old_focus_row;
|
|
|
|
|
gint old_focus_col;
|
|
|
|
|
gint row, col, day;
|
|
|
|
|
|
1998-09-27 18:32:00 +00:00
|
|
|
|
g_return_val_if_fail (widget != NULL, FALSE);
|
|
|
|
|
g_return_val_if_fail (GTK_IS_CALENDAR (widget), FALSE);
|
|
|
|
|
g_return_val_if_fail (event != NULL, FALSE);
|
1998-10-01 13:24:42 +00:00
|
|
|
|
|
1998-09-27 18:32:00 +00:00
|
|
|
|
calendar = GTK_CALENDAR (widget);
|
|
|
|
|
return_val = FALSE;
|
1998-10-01 13:24:42 +00:00
|
|
|
|
|
1998-10-05 03:52:48 +00:00
|
|
|
|
old_focus_row = calendar->focus_row;
|
|
|
|
|
old_focus_col = calendar->focus_col;
|
|
|
|
|
|
1998-09-27 18:32:00 +00:00
|
|
|
|
switch (event->keyval)
|
|
|
|
|
{
|
|
|
|
|
case GDK_Left:
|
|
|
|
|
return_val = TRUE;
|
|
|
|
|
if (event->state & GDK_CONTROL_MASK)
|
1998-10-05 03:52:48 +00:00
|
|
|
|
{
|
|
|
|
|
gtk_calendar_set_month_prev (calendar);
|
|
|
|
|
}
|
1998-09-27 18:32:00 +00:00
|
|
|
|
else
|
|
|
|
|
{
|
1998-10-05 03:52:48 +00:00
|
|
|
|
if (calendar->focus_col > 0)
|
1998-09-27 18:32:00 +00:00
|
|
|
|
{
|
1998-10-05 03:52:48 +00:00
|
|
|
|
calendar->focus_col--;
|
1998-09-27 18:32:00 +00:00
|
|
|
|
}
|
1998-10-05 03:52:48 +00:00
|
|
|
|
else if (calendar->focus_row > 0)
|
|
|
|
|
{
|
|
|
|
|
calendar->focus_col = 6;
|
|
|
|
|
calendar->focus_row--;
|
|
|
|
|
}
|
|
|
|
|
gtk_calendar_paint_day (widget, old_focus_row, old_focus_col);
|
|
|
|
|
gtk_calendar_paint_day (widget, calendar->focus_row,
|
|
|
|
|
calendar->focus_col);
|
1998-09-27 18:32:00 +00:00
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case GDK_Right:
|
|
|
|
|
return_val = TRUE;
|
|
|
|
|
if (event->state & GDK_CONTROL_MASK)
|
1998-10-05 03:52:48 +00:00
|
|
|
|
{
|
1998-09-27 18:32:00 +00:00
|
|
|
|
gtk_calendar_set_month_next (calendar);
|
1998-10-05 03:52:48 +00:00
|
|
|
|
}
|
1998-09-27 18:32:00 +00:00
|
|
|
|
else
|
|
|
|
|
{
|
1998-10-05 03:52:48 +00:00
|
|
|
|
if (calendar->focus_col < 6)
|
1998-09-27 18:32:00 +00:00
|
|
|
|
{
|
1998-10-05 03:52:48 +00:00
|
|
|
|
calendar->focus_col++;
|
1998-09-27 18:32:00 +00:00
|
|
|
|
}
|
1998-10-05 03:52:48 +00:00
|
|
|
|
else if (calendar->focus_row < 5)
|
|
|
|
|
{
|
|
|
|
|
calendar->focus_col = 0;
|
|
|
|
|
calendar->focus_row++;
|
|
|
|
|
}
|
|
|
|
|
gtk_calendar_paint_day (widget, old_focus_row, old_focus_col);
|
|
|
|
|
gtk_calendar_paint_day (widget, calendar->focus_row,
|
|
|
|
|
calendar->focus_col);
|
1998-09-27 18:32:00 +00:00
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case GDK_Up:
|
|
|
|
|
return_val = TRUE;
|
|
|
|
|
if (event->state & GDK_CONTROL_MASK)
|
1998-10-05 03:52:48 +00:00
|
|
|
|
{
|
|
|
|
|
gtk_calendar_set_year_prev (calendar);
|
|
|
|
|
}
|
1998-09-27 18:32:00 +00:00
|
|
|
|
else
|
|
|
|
|
{
|
1998-10-05 03:52:48 +00:00
|
|
|
|
if (calendar->focus_row > 0)
|
1998-09-27 18:32:00 +00:00
|
|
|
|
{
|
1998-10-05 03:52:48 +00:00
|
|
|
|
calendar->focus_row--;
|
1998-09-27 18:32:00 +00:00
|
|
|
|
}
|
1998-10-05 03:52:48 +00:00
|
|
|
|
gtk_calendar_paint_day (widget, old_focus_row, old_focus_col);
|
|
|
|
|
gtk_calendar_paint_day (widget, calendar->focus_row,
|
|
|
|
|
calendar->focus_col);
|
1998-09-27 18:32:00 +00:00
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case GDK_Down:
|
|
|
|
|
return_val = TRUE;
|
|
|
|
|
if (event->state & GDK_CONTROL_MASK)
|
1998-10-05 03:52:48 +00:00
|
|
|
|
{
|
|
|
|
|
gtk_calendar_set_year_next (calendar);
|
|
|
|
|
}
|
1998-09-27 18:32:00 +00:00
|
|
|
|
else
|
|
|
|
|
{
|
1998-10-05 03:52:48 +00:00
|
|
|
|
if (calendar->focus_row < 5)
|
1998-09-27 18:32:00 +00:00
|
|
|
|
{
|
1998-10-05 03:52:48 +00:00
|
|
|
|
calendar->focus_row++;
|
1998-09-27 18:32:00 +00:00
|
|
|
|
}
|
1998-10-05 03:52:48 +00:00
|
|
|
|
gtk_calendar_paint_day (widget, old_focus_row, old_focus_col);
|
|
|
|
|
gtk_calendar_paint_day (widget, calendar->focus_row,
|
|
|
|
|
calendar->focus_col);
|
1998-09-27 18:32:00 +00:00
|
|
|
|
}
|
|
|
|
|
break;
|
1998-10-05 03:52:48 +00:00
|
|
|
|
case GDK_space:
|
|
|
|
|
row = calendar->focus_row;
|
|
|
|
|
col = calendar->focus_col;
|
|
|
|
|
day = calendar->day[row][col];
|
|
|
|
|
|
|
|
|
|
if (row > -1 && col > -1)
|
|
|
|
|
{
|
|
|
|
|
gtk_calendar_freeze (calendar);
|
|
|
|
|
|
|
|
|
|
if (calendar->day_month[row][col] == MONTH_PREV)
|
|
|
|
|
{
|
|
|
|
|
gtk_calendar_set_month_prev (calendar);
|
|
|
|
|
}
|
|
|
|
|
else if (calendar->day_month[row][col] == MONTH_NEXT)
|
|
|
|
|
{
|
|
|
|
|
gtk_calendar_set_month_next (calendar);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
gtk_calendar_select_day (calendar, day);
|
|
|
|
|
|
|
|
|
|
for (row = 0; row < 6; row ++)
|
|
|
|
|
for (col = 0; col < 7; col++)
|
|
|
|
|
{
|
|
|
|
|
if (calendar->day_month[row][col] == MONTH_CURRENT
|
|
|
|
|
&& calendar->day[row][col] == day)
|
|
|
|
|
{
|
|
|
|
|
calendar->focus_row = row;
|
|
|
|
|
calendar->focus_col = col;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
gtk_calendar_thaw (calendar);
|
|
|
|
|
}
|
1998-10-01 13:24:42 +00:00
|
|
|
|
}
|
|
|
|
|
|
1998-09-27 18:32:00 +00:00
|
|
|
|
return return_val;
|
|
|
|
|
}
|