]> Pileus Git - ~andy/gtk/blobdiff - gtk/gtkcalendar.c
Deprecate widget flag: GTK_WIDGET_HAS_FOCUS
[~andy/gtk] / gtk / gtkcalendar.c
index ff5003c6fbabc1a77b7c8a747b755c29ffacdb77..34011972eadce4852f64cf022e28ea5de0bd2837 100644 (file)
@@ -188,8 +188,8 @@ dates_difference(guint year1, guint mm1, guint dd1,
 /* Color usage */
 #define HEADER_FG_COLOR(widget)                 (& (widget)->style->fg[GTK_WIDGET_STATE (widget)])
 #define HEADER_BG_COLOR(widget)                 (& (widget)->style->bg[GTK_WIDGET_STATE (widget)])
-#define SELECTED_BG_COLOR(widget)       (& (widget)->style->base[GTK_WIDGET_HAS_FOCUS (widget) ? GTK_STATE_SELECTED : GTK_STATE_ACTIVE])
-#define SELECTED_FG_COLOR(widget)       (& (widget)->style->text[GTK_WIDGET_HAS_FOCUS (widget) ? GTK_STATE_SELECTED : GTK_STATE_ACTIVE])
+#define SELECTED_BG_COLOR(widget)       (& (widget)->style->base[gtk_widget_has_focus (widget) ? GTK_STATE_SELECTED : GTK_STATE_ACTIVE])
+#define SELECTED_FG_COLOR(widget)       (& (widget)->style->text[gtk_widget_has_focus (widget) ? GTK_STATE_SELECTED : GTK_STATE_ACTIVE])
 #define NORMAL_DAY_COLOR(widget)        (& (widget)->style->text[GTK_WIDGET_STATE (widget)])
 #define PREV_MONTH_COLOR(widget)        (& (widget)->style->mid[GTK_WIDGET_STATE (widget)])
 #define NEXT_MONTH_COLOR(widget)        (& (widget)->style->mid[GTK_WIDGET_STATE (widget)])
@@ -439,7 +439,7 @@ gtk_calendar_class_init (GtkCalendarClass *class)
                                    g_param_spec_int ("year",
                                                     P_("Year"),
                                                     P_("The selected year"),
-                                                    0, G_MAXINT >> 8, 0,
+                                                    0, G_MAXINT >> 9, 0,
                                                     GTK_PARAM_READWRITE));
 
   /**
@@ -751,9 +751,10 @@ gtk_calendar_init (GtkCalendar *calendar)
    * Do *not* translate it to anything else, if it
    * it isn't calendar:YM or calendar:MY it will not work.
    *
-   * Note that this flipping is in top of the text direction flipping,
-   * so if you have a default text direction of RTL and YM, then
-   * the year will appear on the right.
+   * Note that the ordering described here is logical order, which is
+   * further influenced by BIDI ordering. Thus, if you have a default
+   * text direction of RTL and specify "calendar:YM", then the year
+   * will appear to the right of the month.
    */
   year_before = _("calendar:MY");
   if (strcmp (year_before, "calendar:YM") == 0)
@@ -1432,7 +1433,7 @@ calendar_realize_arrows (GtkCalendar *calendar)
          priv->arrow_win[i] = gdk_window_new (priv->header_win,
                                               &attributes, 
                                               attributes_mask);
-         if (GTK_WIDGET_IS_SENSITIVE (widget))
+         if (gtk_widget_is_sensitive (widget))
            priv->arrow_state[i] = GTK_STATE_NORMAL;
          else 
            priv->arrow_state[i] = GTK_STATE_INSENSITIVE;
@@ -1542,7 +1543,10 @@ calendar_realize_week_numbers (GtkCalendar *calendar)
       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->xthickness + INNER_BORDER;
+      if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR) 
+       attributes.x = widget->style->xthickness + INNER_BORDER;
+      else 
+       attributes.x = widget->allocation.width - priv->week_width - (widget->style->xthickness + INNER_BORDER);
       attributes.y = (priv->header_h + priv->day_name_h 
                      + (widget->style->ythickness + INNER_BORDER));
       attributes.width = priv->week_width;
@@ -1598,11 +1602,18 @@ gtk_calendar_realize (GtkWidget *widget)
                            | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK
                            | GDK_POINTER_MOTION_MASK | GDK_LEAVE_NOTIFY_MASK);
   
-  attributes.x = priv->week_width + (widget->style->ythickness + INNER_BORDER);
+  if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR) 
+    attributes.x = priv->week_width + (widget->style->ythickness + INNER_BORDER);
+  else
+    attributes.x = widget->style->ythickness + INNER_BORDER;
+
   attributes.y = (priv->header_h + priv->day_name_h 
                  + (widget->style->ythickness + INNER_BORDER));
   attributes.width = (widget->allocation.width - attributes.x 
                      - (widget->style->xthickness + INNER_BORDER));
+  if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
+    attributes.width -= priv->week_width;
+
   attributes.height = priv->main_h;
   priv->main_win = gdk_window_new (widget->window,
                                   &attributes, attributes_mask);
@@ -1657,8 +1668,7 @@ gtk_calendar_unrealize (GtkWidget *widget)
       priv->day_name_win = NULL;      
     }
 
-  if (GTK_WIDGET_CLASS (gtk_calendar_parent_class)->unrealize)
-    GTK_WIDGET_CLASS (gtk_calendar_parent_class)->unrealize (widget);
+  GTK_WIDGET_CLASS (gtk_calendar_parent_class)->unrealize (widget);
 }
 
 static gchar*
@@ -1669,6 +1679,9 @@ gtk_calendar_get_detail (GtkCalendar *calendar,
   GtkCalendarPrivate *priv = GTK_CALENDAR_GET_PRIVATE (calendar);
   gint year, month;
 
+  if (priv->detail_func == NULL)
+    return NULL;
+
   year = calendar->year;
   month = calendar->month + calendar->day_month[row][column] - MONTH_CURRENT;
 
@@ -1787,14 +1800,11 @@ gtk_calendar_size_request (GtkWidget      *widget,
 
       priv->max_year_width = 0;
       /* Translators:  This is a text measurement template.
-       * Translate it to the widest year text. 
-       * 
-       * Don't include the prefix "year measurement template|" 
-       * in the translation.
+       * Translate it to the widest year text
        *
        * If you don't understand this, leave it as "2000"
        */
-      pango_layout_set_text (layout, Q_("year measurement template|2000"), -1);          
+      pango_layout_set_text (layout, C_("year measurement template", "2000"), -1);       
       pango_layout_get_pixel_extents (layout, NULL, &logical_rect);
       priv->max_year_width = MAX (priv->max_year_width,
                                  logical_rect.width + 8);
@@ -1825,7 +1835,7 @@ gtk_calendar_size_request (GtkWidget        *widget,
   for (i = 0; i < 9; i++)
     {
       gchar buffer[32];
-      g_snprintf (buffer, sizeof (buffer), Q_("calendar:day:digits|%d"), i * 11);
+      g_snprintf (buffer, sizeof (buffer), C_("calendar:day:digits", "%d"), i * 11);
       pango_layout_set_text (layout, buffer, -1);        
       pango_layout_get_pixel_extents (layout, NULL, &logical_rect);
       priv->min_day_width = MAX (priv->min_day_width,
@@ -1857,7 +1867,7 @@ gtk_calendar_size_request (GtkWidget        *widget,
     for (i = 0; i < 9; i++)
       {
        gchar buffer[32];
-       g_snprintf (buffer, sizeof (buffer), Q_("calendar:week:digits|%d"), i * 11);
+       g_snprintf (buffer, sizeof (buffer), C_("calendar:week:digits", "%d"), i * 11);
        pango_layout_set_text (layout, buffer, -1);       
        pango_layout_get_pixel_extents (layout, NULL, &logical_rect);
        priv->max_week_char_width = MAX (priv->max_week_char_width,
@@ -2131,14 +2141,13 @@ calendar_paint_header (GtkCalendar *calendar)
    * gtkcalendar widget.  See strftime() manual for the format.
    * Use only ASCII in the translation.
    *
-   * Also look for the msgid "year measurement template|2000".  
+   * Also look for the msgid "2000".
    * Translate that entry to a year with the widest output of this
-   * msgid. 
-   * 
-   * Don't include the prefix "calendar year format|" in the 
-   * translation. "%Y" is appropriate for most locales.
+   * msgid.
+   *
+   * "%Y" is appropriate for most locales.
    */
-  strftime (buffer, sizeof (buffer), Q_("calendar year format|%Y"), tm);
+  strftime (buffer, sizeof (buffer), C_("calendar year format", "%Y"), tm);
   str = g_locale_to_utf8 (buffer, -1, NULL, NULL, NULL);
   layout = gtk_widget_create_pango_layout (widget, str);
   g_free (str);
@@ -2341,14 +2350,13 @@ calendar_paint_week_numbers (GtkCalendar *calendar)
        * localized digits or the ones used in English (0123...).
        *
        * Translate to "%Id" if you want to use localized digits, or
-       * translate to "%d" otherwise.  Don't include the
-       * "calendar:week:digits|" part in the translation.
+       * translate to "%d" otherwise.
        *
        * Note that translating this doesn't guarantee that you get localized
-       * digits.  That needs support from your system and locale definition
+       * digits. That needs support from your system and locale definition
        * too.
        */
-      g_snprintf (buffer, sizeof (buffer), Q_("calendar:week:digits|%d"), week);
+      g_snprintf (buffer, sizeof (buffer), C_("calendar:week:digits", "%d"), week);
       pango_layout_set_text (layout, buffer, -1);
       pango_layout_get_pixel_extents (layout, NULL, &logical_rect);
 
@@ -2479,21 +2487,17 @@ calendar_paint_day (GtkCalendar *calendar,
    * localized digits or the ones used in English (0123...).
    *
    * Translate to "%Id" if you want to use localized digits, or
-   * translate to "%d" otherwise.  Don't include the "calendar:day:digits|"
-   * part in the translation.
+   * translate to "%d" otherwise.
    *
    * Note that translating this doesn't guarantee that you get localized
-   * digits.  That needs support from your system and locale definition
+   * digits. That needs support from your system and locale definition
    * too.
    */
-  g_snprintf (buffer, sizeof (buffer), Q_("calendar:day:digits|%d"), day);
+  g_snprintf (buffer, sizeof (buffer), C_("calendar:day:digits", "%d"), day);
 
   /* Get extra information to show, if any: */
 
-  if (priv->detail_func)
-    detail = gtk_calendar_get_detail (calendar, row, col);
-  else
-    detail = NULL;
+  detail = gtk_calendar_get_detail (calendar, row, col);
 
   layout = gtk_widget_create_pango_layout (widget, buffer);
   pango_layout_set_alignment (layout, PANGO_ALIGN_CENTER);
@@ -2569,13 +2573,13 @@ calendar_paint_day (GtkCalendar *calendar,
       pango_cairo_show_layout (cr, layout);
     }
 
-  if (GTK_WIDGET_HAS_FOCUS (calendar) 
+  if (gtk_widget_has_focus (widget)
       && calendar->focus_row == row && calendar->focus_col == col)
     {
       GtkStateType state;
 
       if (calendar->selected_day == day)
-       state = GTK_WIDGET_HAS_FOCUS (widget) ? GTK_STATE_SELECTED : GTK_STATE_ACTIVE;
+       state = gtk_widget_has_focus (widget) ? GTK_STATE_SELECTED : GTK_STATE_ACTIVE;
       else
        state = GTK_STATE_NORMAL;
       
@@ -2662,7 +2666,7 @@ gtk_calendar_expose (GtkWidget        *widget,
   GtkCalendarPrivate *priv = GTK_CALENDAR_GET_PRIVATE (widget);
   int i;
 
-  if (GTK_WIDGET_DRAWABLE (widget))
+  if (gtk_widget_is_drawable (widget))
     {
       if (event->window == priv->main_win)
        calendar_paint_main (calendar);
@@ -2819,7 +2823,7 @@ calendar_main_button_press (GtkCalendar      *calendar,
       else if (day_month == MONTH_NEXT)
        calendar_set_month_next (calendar);
       
-      if (!GTK_WIDGET_HAS_FOCUS (widget))
+      if (!gtk_widget_has_focus (widget))
        gtk_widget_grab_focus (widget);
          
       if (event->button == 1) 
@@ -2852,7 +2856,7 @@ gtk_calendar_button_press (GtkWidget        *widget,
   if (event->window == priv->main_win)
     calendar_main_button_press (calendar, event);
 
-  if (!GTK_WIDGET_HAS_FOCUS (widget))
+  if (!gtk_widget_has_focus (widget))
     gtk_widget_grab_focus (widget);
 
   for (arrow = ARROW_YEAR_LEFT; arrow <= ARROW_MONTH_RIGHT; arrow++)
@@ -3044,13 +3048,13 @@ gtk_calendar_scroll (GtkWidget      *widget,
 
   if (event->direction == GDK_SCROLL_UP) 
     {
-      if (!GTK_WIDGET_HAS_FOCUS (widget))
+      if (!gtk_widget_has_focus (widget))
        gtk_widget_grab_focus (widget);
       calendar_set_month_prev (calendar);
     }
   else if (event->direction == GDK_SCROLL_DOWN) 
     {
-      if (!GTK_WIDGET_HAS_FOCUS (widget))
+      if (!gtk_widget_has_focus (widget))
        gtk_widget_grab_focus (widget);
       calendar_set_month_next (calendar);
     }
@@ -3257,14 +3261,14 @@ gtk_calendar_state_changed (GtkWidget      *widget,
   GtkCalendarPrivate *priv = GTK_CALENDAR_GET_PRIVATE (widget);
   int i;
   
-  if (!GTK_WIDGET_IS_SENSITIVE (widget))
+  if (!gtk_widget_is_sensitive (widget))
     {
       priv->in_drag = 0;
       calendar_stop_spinning (calendar);    
     }
 
   for (i = 0; i < 4; i++)
-    if (GTK_WIDGET_IS_SENSITIVE (widget))
+    if (gtk_widget_is_sensitive (widget))
       priv->arrow_state[i] = GTK_STATE_NORMAL;
     else 
       priv->arrow_state[i] = GTK_STATE_INSENSITIVE;
@@ -3724,7 +3728,7 @@ gtk_calendar_select_day (GtkCalendar *calendar,
       
       selected_day = calendar->selected_day;
       calendar->selected_day = 0;
-      if (GTK_WIDGET_DRAWABLE (GTK_WIDGET (calendar)))
+      if (gtk_widget_is_drawable (GTK_WIDGET (calendar)))
        calendar_invalidate_day_num (calendar, selected_day);
     }
   
@@ -3733,7 +3737,7 @@ gtk_calendar_select_day (GtkCalendar *calendar,
   /* Select the new day */
   if (day != 0)
     {
-      if (GTK_WIDGET_DRAWABLE (GTK_WIDGET (calendar)))
+      if (gtk_widget_is_drawable (GTK_WIDGET (calendar)))
        calendar_invalidate_day_num (calendar, day);
     }
   
@@ -3819,9 +3823,9 @@ gtk_calendar_unmark_day (GtkCalendar *calendar,
 /**
  * gtk_calendar_get_date:
  * @calendar: a #GtkCalendar
- * @year: location to store the year number, or %NULL
- * @month: location to store the month number (between 0 and 11), or %NULL
- * @day: location to store the day number (between 1 and 31), or %NULL
+ * @year: (allow-none): location to store the year number, or %NULL
+ * @month: (allow-none): location to store the month number (between 0 and 11), or %NULL
+ * @day: (allow-none): location to store the day number (between 1 and 31), or %NULL
  * 
  * Obtains the selected date from a #GtkCalendar.
  **/