GtkCalendar improved keyboard focus movement
- From: Detlef Reichl <detlef reichl arcormail de>
- To: GTK-devel <gtk-devel-list gnome org>
- Subject: GtkCalendar improved keyboard focus movement
- Date: 21 Sep 2001 23:44:11 +0200
The attached patch changes the movement of the focus in GtkCalendar in
that way, that if the focus reaches the first or last day in month, it
will jump with the next key press to the last of the previous or the
first of the following month.
>From the top row it will jump to same day of the week in the previous
month on key press up. Key press down the same.
It is all handled in that way, that only days of type MONTH_CURRENT are
in use.
have a nice day
detlef
ChangeLog
2001-09-21 Detlef Reichl <detlef reichl arcormail de>
*gtk/gtkcalendar.c gtk_calendar_key_press
focus can now go to the next month, if it reaches the borders.
--- gtkcalendar.c Thu Jul 19 01:39:21 2001
+++ ../../gtk+/gtk/gtkcalendar.c Fri Sep 21 23:19:56 2001
@@ -2608,6 +2608,9 @@
gint old_focus_row;
gint old_focus_col;
gint row, col, day;
+ gint ndays_in_prev_month, rows;
+ gint ndays_in_this_month;
+ gint day_of_prev;
g_return_val_if_fail (widget != NULL, FALSE);
g_return_val_if_fail (GTK_IS_CALENDAR (widget), FALSE);
@@ -2639,6 +2642,36 @@
calendar->focus_col = 6;
calendar->focus_row--;
}
+ else{
+ if (calendar->month == 0)
+ ndays_in_prev_month =
+ month_length[leap (calendar->year - 1)][12];
+ else
+ ndays_in_prev_month =
+ month_length[leap (calendar->year)][calendar->month];
+
+ calendar->focus_col = 6;
+ ndays_in_prev_month == 28 ?
+ (calendar->focus_row = 3) : (calendar->focus_row = 4);
+ gtk_calendar_set_month_prev (calendar);
+ break;
+ }
+ if (calendar->day_month[calendar->focus_row][calendar->focus_col] !=
+ MONTH_CURRENT )
+ {
+ if (calendar->month == 0)
+ ndays_in_prev_month =
+ month_length[leap (calendar->year - 1)][12];
+ else
+ ndays_in_prev_month =
+ month_length[leap (calendar->year)][calendar->month];
+ rows = (ndays_in_prev_month + 6 - calendar->focus_col) / 7;
+ if ((ndays_in_prev_month + 6 - calendar->focus_col) %7 == 0)
+ rows--;
+ calendar->focus_row = rows;
+ gtk_calendar_set_month_prev (calendar);
+ break;
+ }
gtk_calendar_paint_day (widget, old_focus_row, old_focus_col);
gtk_calendar_paint_day (widget, calendar->focus_row,
calendar->focus_col);
@@ -2662,6 +2695,13 @@
calendar->focus_col = 0;
calendar->focus_row++;
}
+ if (calendar->day_month[calendar->focus_row][calendar->focus_col] !=
+ MONTH_CURRENT )
+ {
+ calendar->focus_row = 0;
+ gtk_calendar_set_month_next (calendar);
+ break;
+ }
gtk_calendar_paint_day (widget, old_focus_row, old_focus_col);
gtk_calendar_paint_day (widget, calendar->focus_row,
calendar->focus_col);
@@ -2676,10 +2716,25 @@
}
else
{
- if (calendar->focus_row > 0)
- {
- calendar->focus_row--;
- }
+ calendar->focus_row--;
+ if (calendar->day_month[calendar->focus_row][calendar->focus_col] !=
+ MONTH_CURRENT || calendar->focus_row == -1)
+ {
+ if (calendar->month == 0)
+ ndays_in_prev_month =
+ month_length[leap (calendar->year - 1)][12];
+ else
+ ndays_in_prev_month =
+ month_length[leap (calendar->year)][calendar->month];
+ day_of_prev = calendar->day[old_focus_row][old_focus_col] +
+ ndays_in_prev_month - 7;
+ rows = (day_of_prev + 6 - calendar->focus_col) / 7;
+ if ((day_of_prev + 6 - calendar->focus_col) %7 == 0)
+ rows--;
+ calendar->focus_row = rows;
+ gtk_calendar_set_month_prev (calendar);
+ break;
+ }
gtk_calendar_paint_day (widget, old_focus_row, old_focus_col);
gtk_calendar_paint_day (widget, calendar->focus_row,
calendar->focus_col);
@@ -2694,10 +2749,18 @@
}
else
{
- if (calendar->focus_row < 5)
- {
- calendar->focus_row++;
- }
+ calendar->focus_row++;
+ if (calendar->day_month[calendar->focus_row][calendar->focus_col] !=
+ MONTH_CURRENT || calendar->focus_row == 6)
+ {
+ ndays_in_this_month =
+ month_length[leap (calendar->year)][calendar->month + 1];
+ day = calendar->day[old_focus_row][old_focus_col];
+ 6 - (ndays_in_this_month - day) <= old_focus_col ?
+ (calendar->focus_row = 0) : (calendar->focus_row = 1);
+ gtk_calendar_set_month_next (calendar);
+ break;
+ }
gtk_calendar_paint_day (widget, old_focus_row, old_focus_col);
gtk_calendar_paint_day (widget, calendar->focus_row,
calendar->focus_col);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]