Re: GtkCalendar improved keyboard focus movement



On Die, 2001-10-02 at 15:09, Owen Taylor wrote:
> 
> It's really best to submit patches to bugzilla
bug 61655
> 
> Two comments about your patch:
> 
>  * The coding style needs to match that in GTK+. The GTK+
>    coding style is basically that documented in 
>    pango/docs/TEXT/coding-style, with the difference 
>    that gint/gchar/getc. are used rather than int/char.
fixed

> 
>  * I think this needs to obey the GTK_CALENDAR_NO_MONTH change
>    flag or you could seriously confuse some applications.
oops. also fixed

have a nice day
detlef
--- gtkcalendar.c	Wed Oct  3 00:08:11 2001
+++ gtkcalendar.c.alt	Wed Oct  3 00:03:30 2001
@@ -2604,6 +2604,11 @@
   gint old_focus_row;
   gint old_focus_col;
   gint row, col, day;
+  gint ndays_in_prev_month, rows;
+  gint day_of_prev;
+  gint ndays_in_this_month;
+
+
 
   g_return_val_if_fail (widget != NULL, FALSE);
   g_return_val_if_fail (GTK_IS_CALENDAR (widget), FALSE);
@@ -2635,9 +2640,39 @@
 	      calendar->focus_col = 6;
 	      calendar->focus_row--;
 	    }
+	  else{
+	    if (! (calendar->display_flags & GTK_CALENDAR_NO_MONTH_CHANGE))
+	      {
+		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;
+		calendar->focus_row = ndays_in_prev_month == 28 ? 3 : 4;
+    		gtk_calendar_set_month_prev (calendar);
+		break;
+	      }
+	    }
+  	  if (! (calendar->display_flags & GTK_CALENDAR_NO_MONTH_CHANGE)
+	      && 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);
+	  gtk_calendar_paint_day (widget, calendar->focus_row, calendar->focus_col);
 	}
       break;
     case GDK_KP_Right:
@@ -2645,7 +2680,7 @@
       return_val = TRUE;
       if (event->state & GDK_CONTROL_MASK)
 	{
-	gtk_calendar_set_month_next (calendar);
+	  gtk_calendar_set_month_next (calendar);
 	}
       else
 	{
@@ -2658,6 +2693,13 @@
 	      calendar->focus_col = 0;
 	      calendar->focus_row++;
 	    }
+	  if (! (calendar->display_flags & GTK_CALENDAR_NO_MONTH_CHANGE) &&
+	      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);
@@ -2672,13 +2714,36 @@
 	}
       else
 	{
-	  if (calendar->focus_row > 0)
+	  if (calendar->display_flags & GTK_CALENDAR_NO_MONTH_CHANGE)
+	    {
+	      if (calendar->focus_row > 0)
+		{
+		  calendar->focus_row--;
+		}
+	    }
+	  else
 	    {
 	      calendar->focus_row--;
+	      if (calendar->focus_row == -1 ||
+		  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];
+		  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);
+	  gtk_calendar_paint_day (widget, calendar->focus_row, calendar->focus_col);
 	}
       break;
     case GDK_KP_Down:
@@ -2690,13 +2755,29 @@
 	}
       else
 	{
-	  if (calendar->focus_row < 5)
-	    {
+	  if (calendar->display_flags & GTK_CALENDAR_NO_MONTH_CHANGE)
+	  {
+	    if (calendar->focus_row < 5)
 	      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);
+	  }
+	    else
+	      {
+		calendar->focus_row++;
+		if (calendar->focus_row == 6 ||
+		    calendar->day_month[calendar->focus_row][calendar->focus_col]
+		    != MONTH_CURRENT)
+		  {
+		    ndays_in_this_month =
+		    month_length[leap (calendar->year)][calendar->month + 1];
+		    day = calendar->day[old_focus_row][old_focus_col];
+		    calendar->focus_row = 6 - (ndays_in_this_month - day)
+					  <= old_focus_col ? 0 : 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);
 	}
       break;
     case GDK_KP_Space:


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]