diff options
Diffstat (limited to 'widgets')
-rw-r--r-- | widgets/misc/ChangeLog | 34 | ||||
-rw-r--r-- | widgets/misc/e-calendar-item.c | 96 | ||||
-rw-r--r-- | widgets/misc/e-calendar-item.h | 3 | ||||
-rw-r--r-- | widgets/misc/e-calendar.c | 228 | ||||
-rw-r--r-- | widgets/misc/e-calendar.h | 12 | ||||
-rw-r--r-- | widgets/misc/e-dateedit.c | 106 | ||||
-rw-r--r-- | widgets/misc/test-calendar.c | 3 | ||||
-rw-r--r-- | widgets/misc/test-dateedit.c | 55 |
8 files changed, 290 insertions, 247 deletions
diff --git a/widgets/misc/ChangeLog b/widgets/misc/ChangeLog index 73fda202d4..1261de9ef8 100644 --- a/widgets/misc/ChangeLog +++ b/widgets/misc/ChangeLog @@ -1,3 +1,37 @@ +2000-09-23 Damon Chaplin <damon@helixcode.com> + + * e-calendar.c: use pixmaps instead of GtkArrows to look better. + Also set the canvas window's background when realized so that we can + set the button reliefs to none. + +2000-09-22 Damon Chaplin <damon@helixcode.com> + + * test-dateedit.c: updated a bit, adding a few EDateEdits with + different options. + + * e-calendar-item.c (e_calendar_item_set_selection): aborted any + current selection operation and initialize all of the selection fields. + (e_calendar_item_unmap): new function to abort any current selection + operation. Otherwise GnomeCanvas gets in a muddle about grabs. + + * e-dateedit.c: marked some strftime()/strptime() format strings for + translation and used "%m/%d/%Y" instead of "%x" so we get the complete + year number. Also changed e_date_edit_get_time() so it returns -2 if + it can't parse the date or time, and -1 if it is explicitly set to + None. + (e_date_edit_parse_date): new function to parse the date string and + add on the current century if a year of 0-99 is entered. + +2000-09-21 Damon Chaplin <damon@helixcode.com> + + * e-dateedit.c (on_date_button_clicked): only check return of strptime + for NULL. It should now select the correct day set in the popup. + + * e-calendar.c: + * e-calendar-item.c: + * test-calendar.c: removed support for buttons within the ECalendar. + It is cleaner to add them outside it, as EDateEdit does. + 2000-09-18 Dan Winship <danw@helixcode.com> * e-dateedit.c (_XOPEN_SOURCE): set this to 4 to specify how much diff --git a/widgets/misc/e-calendar-item.c b/widgets/misc/e-calendar-item.c index c1eb10a467..78604716f2 100644 --- a/widgets/misc/e-calendar-item.c +++ b/widgets/misc/e-calendar-item.c @@ -65,9 +65,6 @@ #define E_CALENDAR_ITEM_XPAD_BEFORE_CELLS 1 #define E_CALENDAR_ITEM_XPAD_AFTER_CELLS 4 -/* The space on each end of the horizontal line. */ -#define E_CALENDAR_ITEM_LINE_PAD 4 - /* The number of rows & columns of days in each month. */ #define E_CALENDAR_ROWS_PER_MONTH 6 #define E_CALENDAR_COLS_PER_MONTH 7 @@ -92,6 +89,7 @@ static void e_calendar_item_set_arg (GtkObject *o, guint arg_id); static void e_calendar_item_realize (GnomeCanvasItem *item); static void e_calendar_item_unrealize (GnomeCanvasItem *item); +static void e_calendar_item_unmap (GnomeCanvasItem *item); static void e_calendar_item_update (GnomeCanvasItem *item, double *affine, ArtSVP *clip_path, @@ -228,7 +226,6 @@ enum { ARG_Y1, ARG_X2, ARG_Y2, - ARG_BUTTONS_SPACE, ARG_FONT, ARG_WEEK_NUMBER_FONT, ARG_ROW_HEIGHT, @@ -290,9 +287,6 @@ e_calendar_item_class_init (ECalendarItemClass *class) gtk_object_add_arg_type ("ECalendarItem::y2", GTK_TYPE_DOUBLE, GTK_ARG_READWRITE, ARG_Y2); - gtk_object_add_arg_type ("ECalendarItem::buttons_space", - GTK_TYPE_DOUBLE, GTK_ARG_READWRITE, - ARG_BUTTONS_SPACE); gtk_object_add_arg_type ("ECalendarItem::font", GTK_TYPE_GDK_FONT, GTK_ARG_READWRITE, ARG_FONT); @@ -362,6 +356,7 @@ e_calendar_item_class_init (ECalendarItemClass *class) /* GnomeCanvasItem method overrides */ item_class->realize = e_calendar_item_realize; item_class->unrealize = e_calendar_item_unrealize; + item_class->unmap = e_calendar_item_unmap; item_class->update = e_calendar_item_update; item_class->draw = e_calendar_item_draw; item_class->point = e_calendar_item_point; @@ -407,8 +402,6 @@ e_calendar_item_init (ECalendarItem *calitem) calitem->x2 = 0.0; calitem->y2 = 0.0; - calitem->buttons_space = 0.0; - calitem->selection_set = FALSE; calitem->selection_changed = FALSE; @@ -476,9 +469,6 @@ e_calendar_item_get_arg (GtkObject *o, GtkArg *arg, guint arg_id) case ARG_Y2: GTK_VALUE_DOUBLE (*arg) = calitem->y2; break; - case ARG_BUTTONS_SPACE: - GTK_VALUE_DOUBLE (*arg) = calitem->buttons_space; - break; case ARG_FONT: GTK_VALUE_BOXED (*arg) = calitem->font; break; @@ -580,13 +570,6 @@ e_calendar_item_set_arg (GtkObject *o, GtkArg *arg, guint arg_id) need_update = TRUE; } break; - case ARG_BUTTONS_SPACE: - dvalue = GTK_VALUE_DOUBLE (*arg); - if (calitem->buttons_space != dvalue) { - calitem->buttons_space = dvalue; - need_update = TRUE; - } - break; case ARG_FONT: font = GTK_VALUE_BOXED (*arg); if (calitem->font != font) { @@ -688,6 +671,9 @@ e_calendar_item_realize (GnomeCanvasItem *item) gboolean success[E_CALENDAR_ITEM_COLOR_LAST]; gint nfailed; + if (GNOME_CANVAS_ITEM_CLASS (parent_class)->realize) + (* GNOME_CANVAS_ITEM_CLASS (parent_class)->realize) (item); + calitem = E_CALENDAR_ITEM (item); colormap = gtk_widget_get_colormap (GTK_WIDGET (item->canvas)); @@ -729,6 +715,26 @@ e_calendar_item_unrealize (GnomeCanvasItem *item) for (i = 0; i < E_CALENDAR_ITEM_COLOR_LAST; i++) gdk_colors_free (colormap, &calitem->colors[i].pixel, 1, 0); + + if (GNOME_CANVAS_ITEM_CLASS (parent_class)->unrealize) + (* GNOME_CANVAS_ITEM_CLASS (parent_class)->unrealize) (item); +} + + +static void +e_calendar_item_unmap (GnomeCanvasItem *item) +{ + ECalendarItem *calitem; + + calitem = E_CALENDAR_ITEM (item); + + if (calitem->selecting) { + gnome_canvas_item_ungrab (item, GDK_CURRENT_TIME); + calitem->selecting = FALSE; + } + + if (GNOME_CANVAS_ITEM_CLASS (parent_class)->unmap) + (* GNOME_CANVAS_ITEM_CLASS (parent_class)->unmap) (item); } @@ -767,7 +773,7 @@ e_calendar_item_update (GnomeCanvasItem *item, /* Calculate how many rows & cols we can fit in. */ width = item->x2 - item->x1; - height = item->y2 - item->y1 - calitem->buttons_space; + height = item->y2 - item->y1; width -= xthickness * 2; height -= ythickness * 2; @@ -865,7 +871,6 @@ e_calendar_item_draw (GnomeCanvasItem *canvas_item, GdkGC *base_gc, *bg_gc; gint char_height, row, col, row_y, bar_height, col_x; gint xthickness, ythickness; - gint line_y, line_x1, line_x2; #if 0 g_print ("In e_calendar_item_draw %i,%i %ix%i\n", @@ -937,18 +942,6 @@ e_calendar_item_draw (GnomeCanvasItem *canvas_item, row_y += calitem->month_height; } - - /* Draw the horizontal line, if the Today or None buttons is shown. */ - if (calitem->buttons_space) { - line_y = calitem->y2 + 1 - ythickness - calitem->buttons_space - - y; - line_x1 = calitem->x1 + xthickness - + E_CALENDAR_ITEM_LINE_PAD - x; - line_x2 = calitem->x2 + 1 - xthickness - - E_CALENDAR_ITEM_LINE_PAD - x; - gdk_draw_line (drawable, bg_gc, - line_x1, line_y, line_x2, line_y); - } } @@ -998,8 +991,7 @@ e_calendar_item_draw_month (ECalendarItem *calitem, month_w = item->x2 - item->x1 - xthickness * 2; month_w = MIN (month_w, calitem->month_width); month_y = item->y1 + ythickness + row * calitem->month_height - y; - month_h = item->y2 - item->y1 - calitem->buttons_space - - ythickness * 2; + month_h = item->y2 - item->y1 - ythickness * 2; month_h = MIN (month_h, calitem->month_height); /* Just return if the month is outside the given area. */ @@ -1043,7 +1035,8 @@ e_calendar_item_draw_month (ECalendarItem *calitem, clip_rect.height = text_y + char_height - clip_rect.y; gdk_gc_set_clip_rectangle (fg_gc, &clip_rect); - strftime (buffer, 64, "%B %Y", &tmp_tm); + /* This is a strftime() format. %B = Month name, %Y = Year. */ + strftime (buffer, 64, _("%B %Y"), &tmp_tm); /* Ideally we place the text centered in the month, but we won't go to the left of the minimum x position. */ @@ -1666,6 +1659,12 @@ e_calendar_item_button_press (ECalendarItem *calitem, round_up_end = TRUE; } + /* Don't round up or down if we can't select a week or more. */ + if (calitem->max_days_selected < 7) { + round_down_start = FALSE; + round_up_end = FALSE; + } + if (round_up_end) e_calendar_item_round_up_selection (calitem, &calitem->selection_end_month_offset, &calitem->selection_end_day); @@ -1682,12 +1681,12 @@ static gboolean e_calendar_item_button_release (ECalendarItem *calitem, GdkEvent *event) { - gnome_canvas_item_ungrab (GNOME_CANVAS_ITEM (calitem), - event->button.time); - if (!calitem->selecting) return FALSE; + gnome_canvas_item_ungrab (GNOME_CANVAS_ITEM (calitem), + event->button.time); + calitem->selecting = FALSE; /* If the user selects the grayed dates before the first month or @@ -1774,6 +1773,12 @@ e_calendar_item_motion (ECalendarItem *calitem, && !calitem->selection_dragging_end) round_up_end = TRUE; + /* Don't round up or down if we can't select a week or more. */ + if (calitem->max_days_selected < 7) { + round_down_start = FALSE; + round_up_end = FALSE; + } + if (round_up_end) e_calendar_item_round_up_selection (calitem, &end_month, &end_day); @@ -2488,6 +2493,13 @@ e_calendar_item_set_selection (ECalendarItem *calitem, g_return_if_fail (E_IS_CALENDAR_ITEM (calitem)); + /* If the user is in the middle of a selection, we must abort it. */ + if (calitem->selecting) { + gnome_canvas_item_ungrab (GNOME_CANVAS_ITEM (calitem), + GDK_CURRENT_TIME); + calitem->selecting = FALSE; + } + /* If start_date is NULL, we clear the selection without changing the month shown. */ if (start_date == NULL) { @@ -2542,6 +2554,9 @@ e_calendar_item_set_selection (ECalendarItem *calitem, calitem->selection_end_month_offset = new_end_month_offset; calitem->selection_end_day = new_end_day; + calitem->selection_real_start_month_offset = new_start_month_offset; + calitem->selection_real_start_day = new_start_day; + calitem->selection_from_full_week = FALSE; } if (need_update) @@ -2652,7 +2667,8 @@ e_calendar_item_show_popup_menu (ECalendarItem *calitem, tmp_tm.tm_mday = 1; tmp_tm.tm_isdst = -1; mktime (&tmp_tm); - strftime (buffer, 64, "%B %Y", &tmp_tm); + /* This is a strftime() format. %B = Month name, %Y = Year. */ + strftime (buffer, 64, _("%B %Y"), &tmp_tm); menuitem = gtk_menu_item_new_with_label (buffer); gtk_widget_show (menuitem); diff --git a/widgets/misc/e-calendar-item.h b/widgets/misc/e-calendar-item.h index 3820b84131..5708daa6ce 100644 --- a/widgets/misc/e-calendar-item.h +++ b/widgets/misc/e-calendar-item.h @@ -135,9 +135,6 @@ struct _ECalendarItem move back/forward one month. Used for the week view. */ gboolean round_selection_when_moving; - /* The space to leave at the bottom for the Today & None buttons. */ - gdouble buttons_space; - /* * Internal stuff. */ diff --git a/widgets/misc/e-calendar.c b/widgets/misc/e-calendar.c index 51881d3fc9..01882a41da 100644 --- a/widgets/misc/e-calendar.c +++ b/widgets/misc/e-calendar.c @@ -58,6 +58,35 @@ #define E_CALENDAR_AUTO_MOVE_TIMEOUT 150 #define E_CALENDAR_AUTO_MOVE_TIMEOUT_DELAY 2 +static char * left_arrow_xpm[] = { + "7 7 3 1", + " c None", + ". c #949594", + "+ c #000000", + " .+", + " .+++", + " .+++++", + "+++++++", + " .+++++", + " .+++", + " .+" +}; + +static char * right_arrow_xpm[] = { + "7 7 3 1", + " c None", + ". c #949594", + "+ c #000000", + "+. ", + "+++. ", + "+++++. ", + "+++++++", + "+++++. ", + "+++. ", + "+. " +}; + + static void e_calendar_class_init (ECalendarClass *class); static void e_calendar_init (ECalendar *cal); static void e_calendar_destroy (GtkObject *object); @@ -134,7 +163,10 @@ e_calendar_init (ECalendar *cal) { GnomeCanvasGroup *canvas_group; GdkFont *small_font; - GtkWidget *button, *arrow; + GtkWidget *button, *pixmap; + GdkColormap *colormap; + GdkPixmap *gdk_pixmap; + GdkBitmap *gdk_mask; /* Create the small font. */ small_font = gdk_font_load (E_CALENDAR_SMALL_FONT); @@ -154,27 +186,9 @@ e_calendar_init (ECalendar *cal) gdk_font_unref (small_font); - /* Create the 'Today' and 'None' buttons but don't show them. */ - cal->today_button = gtk_button_new_with_label (_("Today")); - cal->today_button_item = gnome_canvas_item_new (canvas_group, - gnome_canvas_widget_get_type (), - "widget", cal->today_button, - NULL); - gnome_canvas_item_hide (cal->today_button_item); - - - cal->none_button = gtk_button_new_with_label (_("None")); - cal->none_button_item = gnome_canvas_item_new (canvas_group, - gnome_canvas_widget_get_type (), - "widget", cal->none_button, - NULL); - gnome_canvas_item_hide (cal->none_button_item); - - /* Create the arrow buttons to move to the previous/next month. */ button = gtk_button_new (); - /* FIXME: The buttons doesn't display properly if we do this. */ - /*gtk_button_set_relief (GTK_BUTTON (button), GTK_RELIEF_NONE);*/ + gtk_button_set_relief (GTK_BUTTON (button), GTK_RELIEF_NONE); gtk_widget_show (button); gtk_signal_connect_object (GTK_OBJECT (button), "pressed", GTK_SIGNAL_FUNC (e_calendar_on_prev_pressed), @@ -182,16 +196,24 @@ e_calendar_init (ECalendar *cal) gtk_signal_connect_object (GTK_OBJECT (button), "released", GTK_SIGNAL_FUNC (e_calendar_on_prev_released), GTK_OBJECT (cal)); - arrow = gtk_arrow_new (GTK_ARROW_LEFT, GTK_SHADOW_OUT); - gtk_widget_show (arrow); - gtk_container_add (GTK_CONTAINER (button), arrow); + + colormap = gtk_widget_get_colormap (GTK_WIDGET (cal)); + gdk_pixmap = gdk_pixmap_colormap_create_from_xpm_d (NULL, colormap, + &gdk_mask, NULL, + left_arrow_xpm); + pixmap = gtk_pixmap_new (gdk_pixmap, gdk_mask); + gtk_widget_show (pixmap); + gdk_pixmap_unref (gdk_pixmap); + gdk_bitmap_unref (gdk_mask); + gtk_container_add (GTK_CONTAINER (button), pixmap); + cal->prev_item = gnome_canvas_item_new (canvas_group, gnome_canvas_widget_get_type (), "widget", button, NULL); button = gtk_button_new (); - /*gtk_button_set_relief (GTK_BUTTON (button), GTK_RELIEF_NONE);*/ + gtk_button_set_relief (GTK_BUTTON (button), GTK_RELIEF_NONE); gtk_widget_show (button); gtk_signal_connect_object (GTK_OBJECT (button), "pressed", GTK_SIGNAL_FUNC (e_calendar_on_next_pressed), @@ -199,9 +221,16 @@ e_calendar_init (ECalendar *cal) gtk_signal_connect_object (GTK_OBJECT (button), "released", GTK_SIGNAL_FUNC (e_calendar_on_next_released), GTK_OBJECT (cal)); - arrow = gtk_arrow_new (GTK_ARROW_RIGHT, GTK_SHADOW_OUT); - gtk_widget_show (arrow); - gtk_container_add (GTK_CONTAINER (button), arrow); + + gdk_pixmap = gdk_pixmap_colormap_create_from_xpm_d (NULL, colormap, + &gdk_mask, NULL, + right_arrow_xpm); + pixmap = gtk_pixmap_new (gdk_pixmap, gdk_mask); + gtk_widget_show (pixmap); + gdk_pixmap_unref (gdk_pixmap); + gdk_bitmap_unref (gdk_mask); + gtk_container_add (GTK_CONTAINER (button), pixmap); + cal->next_item = gnome_canvas_item_new (canvas_group, gnome_canvas_widget_get_type (), "widget", button, @@ -254,6 +283,11 @@ static void e_calendar_realize (GtkWidget *widget) { (*GTK_WIDGET_CLASS (parent_class)->realize) (widget); + + /* Set the background of the canvas window to the normal color, + or the arrow buttons are not displayed properly. */ + gdk_window_set_background (GTK_LAYOUT (widget)->bin_window, + &widget->style->bg[GTK_STATE_NORMAL]); } @@ -261,10 +295,15 @@ static void e_calendar_style_set (GtkWidget *widget, GtkStyle *previous_style) { - if (GTK_WIDGET_CLASS (parent_class)->style_set) (*GTK_WIDGET_CLASS (parent_class)->style_set) (widget, previous_style); + + /* Set the background of the canvas window to the normal color, + or the arrow buttons are not displayed properly. */ + if (GTK_WIDGET_REALIZED (widget->parent)) + gdk_window_set_background (GTK_LAYOUT (widget)->bin_window, + &widget->style->bg[GTK_STATE_NORMAL]); } @@ -275,12 +314,6 @@ e_calendar_size_request (GtkWidget *widget, ECalendar *cal; GtkStyle *style; gint col_width, row_height, width, height; - gboolean today_button_shown, none_button_shown; - gint buttons_shown = 0, button_height, button_width, buttons_width; - GtkRequisition today_button_requisition = { 0 }; - GtkRequisition none_button_requisition = { 0 }; - gint today_button_width = 0, today_button_height = 0; - gint none_button_width = 0, none_button_height = 0; cal = E_CALENDAR (widget); style = GTK_WIDGET (cal)->style; @@ -293,40 +326,6 @@ e_calendar_size_request (GtkWidget *widget, height = row_height * cal->min_rows; width = col_width * cal->min_cols; - /* Add on space for line & button if shown. */ - today_button_shown = GTK_WIDGET_VISIBLE (cal->today_button); - none_button_shown = GTK_WIDGET_VISIBLE (cal->none_button); - - if (today_button_shown || none_button_shown) { - /* Note that we use the buttons' requisition fields directly - since we want the sizes without any usize modification. */ - if (today_button_shown) { - gtk_widget_size_request (cal->today_button, - &today_button_requisition); - today_button_width = cal->today_button->requisition.width; - today_button_height = cal->today_button->requisition.height; - buttons_shown++; - } - if (none_button_shown) { - gtk_widget_size_request (cal->none_button, - &none_button_requisition); - none_button_width = cal->none_button->requisition.width; - none_button_height = cal->none_button->requisition.height; - buttons_shown++; - } - - button_height = MAX (today_button_height, none_button_height); - height += E_CALENDAR_YPAD_ABOVE_LOWER_BUTTONS + button_height - + E_CALENDAR_YPAD_BELOW_LOWER_BUTTONS; - - button_width = MAX (today_button_width, none_button_width); - button_width += E_CALENDAR_IXPAD_BUTTONS; - buttons_width = buttons_shown * button_width - + (buttons_shown - 1) * E_CALENDAR_XPAD_BUTTONS; - - width = MAX (width, buttons_width); - } - requisition->width = width + style->klass->xthickness * 2; requisition->height = height + style->klass->ythickness * 2; } @@ -339,16 +338,7 @@ e_calendar_size_allocate (GtkWidget *widget, ECalendar *cal; GdkFont *font; gdouble old_x2, old_y2, new_x2, new_y2; - gdouble buttons_x1, buttons_y1; - gdouble button_width, button_height; - gdouble buttons_width = 0, buttons_height = 0; gdouble xthickness, ythickness, arrow_button_size; - gboolean today_button_shown, none_button_shown; - gint buttons_shown = 0; - GtkRequisition today_button_requisition = { 0 }; - GtkRequisition none_button_requisition = { 0 }; - gint today_button_width = 0, today_button_height = 0; - gint none_button_width = 0, none_button_height = 0; cal = E_CALENDAR (widget); font = widget->style->font; @@ -366,67 +356,12 @@ e_calendar_size_allocate (GtkWidget *widget, gnome_canvas_set_scroll_region (GNOME_CANVAS (cal), 0, 0, new_x2, new_y2); - /* Set the positions of the Today & None buttons if shown. */ - today_button_shown = GTK_WIDGET_VISIBLE (cal->today_button); - none_button_shown = GTK_WIDGET_VISIBLE (cal->none_button); - - if (today_button_shown || none_button_shown) { - if (today_button_shown) { - gtk_widget_size_request (cal->today_button, - &today_button_requisition); - today_button_width = cal->today_button->requisition.width; - today_button_height = cal->today_button->requisition.height; - buttons_shown++; - } - if (none_button_shown) { - gtk_widget_size_request (cal->none_button, - &none_button_requisition); - none_button_width = cal->none_button->requisition.width; - none_button_height = cal->none_button->requisition.height; - buttons_shown++; - } - - button_height = MAX (today_button_height, none_button_height); - buttons_height = E_CALENDAR_YPAD_ABOVE_LOWER_BUTTONS - + button_height + E_CALENDAR_YPAD_BELOW_LOWER_BUTTONS; - - button_width = MAX (today_button_width, none_button_width); - button_width += E_CALENDAR_IXPAD_BUTTONS; - buttons_width = buttons_shown * button_width - + (buttons_shown - 1) * E_CALENDAR_XPAD_BUTTONS; - - buttons_x1 = (new_x2 + 1 - buttons_width) / 2; - buttons_x1 = MAX (0, buttons_x1); - - buttons_y1 = new_y2 + 1 - E_CALENDAR_YPAD_BELOW_LOWER_BUTTONS - - button_height - ythickness; - buttons_y1 = MAX (0, buttons_y1); - - gnome_canvas_item_set (cal->today_button_item, - "x", buttons_x1, - "y", buttons_y1, - "width", (gdouble) button_width, - "height", (gdouble) button_height, - NULL); - - if (today_button_shown) - buttons_x1 += button_width + E_CALENDAR_XPAD_BUTTONS; - - gnome_canvas_item_set (cal->none_button_item, - "x", buttons_x1, - "y", buttons_y1, - "width", (gdouble) button_width, - "height", (gdouble) button_height, - NULL); - } - /* Take off space for line & buttons if shown. */ gnome_canvas_item_set (GNOME_CANVAS_ITEM (cal->calitem), "x1", 0.0, "y1", 0.0, "x2", new_x2, "y2", new_y2, - "buttons_space", buttons_height, NULL); @@ -552,8 +487,7 @@ e_calendar_get_border_size (ECalendar *cal, if (style) { *top = style->klass->ythickness; - *bottom = style->klass->ythickness - + cal->calitem->buttons_space; + *bottom = style->klass->ythickness; *left = style->klass->xthickness; *right = style->klass->xthickness; } else { @@ -649,32 +583,6 @@ e_calendar_stop_auto_move (ECalendar *cal) } -/* Set which, if any, of the buttons to show beneath the month displays. - You must connect to the button's clicked signal and perform the - required action yourself. */ -void -e_calendar_set_buttons (ECalendar *cal, - gboolean show_today_button, - gboolean show_none_button) -{ - if (show_today_button) { - gtk_widget_show (cal->today_button); - gnome_canvas_item_show (cal->today_button_item); - } else { - gtk_widget_hide (cal->today_button); - gnome_canvas_item_hide (cal->today_button_item); - } - - if (show_none_button) { - gtk_widget_show (cal->none_button); - gnome_canvas_item_show (cal->none_button_item); - } else { - gtk_widget_hide (cal->none_button); - gnome_canvas_item_hide (cal->none_button_item); - } -} - - static gint e_calendar_drag_motion (GtkWidget *widget, GdkDragContext *context, diff --git a/widgets/misc/e-calendar.h b/widgets/misc/e-calendar.h index 5411a6c979..417b90d630 100644 --- a/widgets/misc/e-calendar.h +++ b/widgets/misc/e-calendar.h @@ -54,12 +54,6 @@ struct _ECalendar ECalendarItem *calitem; - GtkWidget *today_button; - GtkWidget *none_button; - - GnomeCanvasItem *today_button_item; - GnomeCanvasItem *none_button_item; - GnomeCanvasItem *prev_item; GnomeCanvasItem *next_item; @@ -100,12 +94,6 @@ void e_calendar_get_border_size (ECalendar *cal, gint *left, gint *right); -/* Set which, if any, of the buttons to show beneath the month displays. - You must connect to the button's clicked signal and perform the - required action yourself. */ -void e_calendar_set_buttons (ECalendar *cal, - gboolean show_today_button, - gboolean show_none_button); #ifdef __cplusplus } diff --git a/widgets/misc/e-dateedit.c b/widgets/misc/e-dateedit.c index 6078066d9f..6e61e11e93 100644 --- a/widgets/misc/e-dateedit.c +++ b/widgets/misc/e-dateedit.c @@ -117,6 +117,9 @@ static void rebuild_time_popup (EDateEdit *dedit); static void enable_time_combo (EDateEdit *dedit); static void disable_time_combo (EDateEdit *dedit); static gboolean date_is_none (char *date_text); +static gboolean e_date_edit_parse_date (EDateEdit *dedit, + char *date_text, + struct tm *date_tm); static GtkHBoxClass *parent_class; @@ -338,7 +341,6 @@ e_date_edit_destroy (GtkObject *object) { EDateEdit *dedit; - g_return_if_fail (object != NULL); g_return_if_fail (E_IS_DATE_EDIT (object)); dedit = E_DATE_EDIT (object); @@ -358,7 +360,6 @@ static void e_date_edit_forall (GtkContainer *container, gboolean include_internals, GtkCallback callback, gpointer callback_data) { - g_return_if_fail (container != NULL); g_return_if_fail (E_IS_DATE_EDIT (container)); g_return_if_fail (callback != NULL); @@ -383,7 +384,7 @@ on_date_button_clicked (GtkWidget *widget, EDateEdit *dedit) EDateEditPrivate *priv; ECalendar *calendar; struct tm mtm; - gchar *date_text, *status; + gchar *date_text; GDate selected_day; gboolean clear_selection = FALSE; @@ -391,13 +392,9 @@ on_date_button_clicked (GtkWidget *widget, EDateEdit *dedit) calendar = E_CALENDAR (priv->calendar); date_text = gtk_entry_get_text (GTK_ENTRY (dedit->_priv->date_entry)); - if (date_is_none (date_text)) { + if (date_is_none (date_text) + || !e_date_edit_parse_date (dedit, date_text, &mtm)) clear_selection = TRUE; - } else { - status = strptime (date_text, "%x", &mtm); - if (!status || !status[0]) - clear_selection = TRUE; - } if (clear_selection) { e_calendar_item_set_selection (calendar->calitem, NULL, NULL); @@ -473,7 +470,9 @@ on_date_popup_date_selected (ECalendarItem *calitem, EDateEdit *dedit) g_date_to_struct_tm (&start_date, &tmp_tm); - strftime (buffer, sizeof (buffer), "%x", &tmp_tm); + /* This is a strftime() format for a short date. %m = month, %d = day + of month, %Y = year (all digits). */ + strftime (buffer, sizeof (buffer), _("%m/%d/%Y"), &tmp_tm); gtk_entry_set_text (GTK_ENTRY (dedit->_priv->date_entry), buffer); enable_time_combo (dedit); @@ -503,7 +502,9 @@ on_date_popup_today_button_clicked (GtkWidget *button, t = time (NULL); tmp_tm = localtime (&t); - strftime (buffer, sizeof (buffer), "%x", tmp_tm); + /* This is a strftime() format for a short date. %m = month, %d = day + of month, %Y = year (all digits). */ + strftime (buffer, sizeof (buffer), _("%m/%d/%Y"), tmp_tm); gtk_entry_set_text (GTK_ENTRY (dedit->_priv->date_entry), buffer); enable_time_combo (dedit); @@ -606,7 +607,8 @@ hide_date_popup (EDateEdit *dedit) * e_date_edit_get_time: * @dedit: The EDateEdit widget * - * Returns the time entered in the EDateEdit widget + * Returns the time entered in the EDateEdit widget, or -1 if the date is not + * set or -2 if the date can't be parsed. */ time_t e_date_edit_get_time (EDateEdit *dedit) @@ -615,7 +617,6 @@ e_date_edit_get_time (EDateEdit *dedit) struct tm date_tm = { 0 }, time_tm = { 0 }; char *date_text, *time_text, *format; - g_return_val_if_fail (dedit != NULL, -1); g_return_val_if_fail (E_IS_DATE_EDIT (dedit), -1); priv = dedit->_priv; @@ -624,7 +625,8 @@ e_date_edit_get_time (EDateEdit *dedit) if (date_is_none (date_text)) return -1; - strptime (date_text, "%x", &date_tm); + if (!e_date_edit_parse_date (dedit, date_text, &date_tm)) + return -2; if (dedit->_priv->show_time) { time_text = gtk_entry_get_text (GTK_ENTRY (GTK_COMBO (priv->time_combo)->entry)); @@ -634,7 +636,8 @@ e_date_edit_get_time (EDateEdit *dedit) else format = "%I:%M %p"; - strptime (time_text, format, &time_tm); + if (!strptime (time_text, format, &time_tm)) + return -2; date_tm.tm_hour = time_tm.tm_hour; date_tm.tm_min = time_tm.tm_min; @@ -646,6 +649,35 @@ e_date_edit_get_time (EDateEdit *dedit) } +static gboolean +e_date_edit_parse_date (EDateEdit *dedit, + gchar *date_text, + struct tm *date_tm) +{ + struct tm *tmp_tm; + time_t t; + + /* This is a stpftime() format for a short date. %m = month, + %d = day of month, %Y = year (all digits). */ + if (!strptime (date_text, _("%m/%d/%Y"), date_tm)) + return FALSE; + + /* If the user entered a 2-digit year we use the current century. */ + if (date_tm->tm_year < 0) { + t = time (NULL); + tmp_tm = localtime (&t); + + /* This should convert it into a value from 0 to 99. */ + date_tm->tm_year += 1900; + + /* Now add on the century. */ + date_tm->tm_year += tmp_tm->tm_year - (tmp_tm->tm_year % 100); + } + + return TRUE; +} + + /** * e_date_edit_set_time: * @dedit: the EDateEdit widget @@ -680,7 +712,10 @@ e_date_edit_set_time (EDateEdit *dedit, time_t the_time) mytm = localtime (&the_time); /* Set the date */ - strftime (buffer, sizeof (buffer), "%x", mytm); + + /* This is a strftime() format for a short date. %m = month, %d = day + of month, %Y = year (all digits). */ + strftime (buffer, sizeof (buffer), _("%m/%d/%Y"), mytm); gtk_entry_set_text (GTK_ENTRY (priv->date_entry), buffer); /* Set the time */ @@ -695,7 +730,13 @@ e_date_edit_set_time (EDateEdit *dedit, time_t the_time) } -/* Whether we show the time field. */ +/** + * e_date_edit_get_show_time: + * @dedit: an #EDateEdit widget + * @Returns: Whether the time field is shown. + * + * Description: Returns TRUE if the time field is currently shown. + */ gboolean e_date_edit_get_show_time (EDateEdit *dedit) { @@ -705,6 +746,14 @@ e_date_edit_get_show_time (EDateEdit *dedit) } +/** + * e_date_edit_set_show_time: + * @dedit: an #EDateEdit widget + * @show_time: TRUE if the time field should be shown. + * + * Description: Specifies whether the time field should be shown. The time + * field would be hidden if only a date needed to be entered. + */ void e_date_edit_set_show_time (EDateEdit *dedit, gboolean show_time) @@ -731,7 +780,14 @@ e_date_edit_set_show_time (EDateEdit *dedit, } -/* The week start day, used in the date popup. 0 (Sun) to 6 (Sat). */ +/** + * e_date_edit_get_week_start_day: + * @dedit: an #EDateEdit widget + * @Returns: the week start day, from 0 (Sunday) to 6 (Saturday). + * + * Description: Returns the week start day currently used in the calendar + * popup. + */ gint e_date_edit_get_week_start_day (EDateEdit *dedit) { @@ -747,6 +803,13 @@ e_date_edit_get_week_start_day (EDateEdit *dedit) } +/** + * e_date_edit_set_week_start_day: + * @dedit: an #EDateEdit widget + * @week_start_day: the week start day, from 0 (Sunday) to 6 (Saturday). + * + * Description: Sets the week start day to use in the calendar popup. + */ void e_date_edit_set_week_start_day (EDateEdit *dedit, gint week_start_day) @@ -872,6 +935,8 @@ e_date_edit_set_time_popup_range (EDateEdit *dedit, } +/* Clears the time popup and rebuilds it using the lower_hour, upper_hour + and use_24_hour_format settings. */ static void rebuild_time_popup (EDateEdit *dedit) { @@ -924,6 +989,7 @@ rebuild_time_popup (EDateEdit *dedit) } +/* Makes the time field & popup sensitive so the user can set the time. */ static void enable_time_combo (EDateEdit *dedit) { @@ -931,6 +997,8 @@ enable_time_combo (EDateEdit *dedit) } +/* Makes the time field & popup insensitive and clears it. This is used when + the date has been set to "None". */ static void disable_time_combo (EDateEdit *dedit) { @@ -939,6 +1007,8 @@ disable_time_combo (EDateEdit *dedit) } +/* Returns TRUE if the string is empty or is "None" in the current locale. + It ignores whitespace. */ static gboolean date_is_none (char *date_text) { diff --git a/widgets/misc/test-calendar.c b/widgets/misc/test-calendar.c index 28656e216e..eb443c24c8 100644 --- a/widgets/misc/test-calendar.c +++ b/widgets/misc/test-calendar.c @@ -89,9 +89,6 @@ main (int argc, char **argv) GTK_SIGNAL_FUNC (delete_event_cb), NULL); cal = e_calendar_new (); -#if 1 - e_calendar_set_buttons (E_CALENDAR (cal), TRUE, TRUE); -#endif e_calendar_set_minimum_size (E_CALENDAR (cal), 1, 1); calitem = E_CALENDAR (cal)->calitem; gtk_widget_show (cal); diff --git a/widgets/misc/test-dateedit.c b/widgets/misc/test-dateedit.c index 12fb93ac88..e40b152039 100644 --- a/widgets/misc/test-dateedit.c +++ b/widgets/misc/test-dateedit.c @@ -45,42 +45,75 @@ main (int argc, char **argv) { GtkWidget *app; EDateEdit *dedit; - GtkWidget *vbox, *button; + GtkWidget *table, *button; gnome_init ("test-dateedit", "0.0", argc, argv); app = gnome_app_new ("Test", "Test"); - gtk_window_set_default_size (GTK_WINDOW (app), 400, 200); + gtk_window_set_default_size (GTK_WINDOW (app), 300, 200); gtk_window_set_policy (GTK_WINDOW (app), FALSE, TRUE, TRUE); gtk_container_set_border_width (GTK_CONTAINER (app), 8); gtk_signal_connect (GTK_OBJECT (app), "delete_event", GTK_SIGNAL_FUNC (delete_event_cb), NULL); + table = gtk_table_new (3, 2, FALSE); + gtk_table_set_row_spacings (GTK_TABLE (table), 4); + gtk_table_set_col_spacings (GTK_TABLE (table), 4); + gtk_widget_show (table); + gnome_app_set_contents (GNOME_APP (app), table); + + /* EDateEdit 1. */ dedit = E_DATE_EDIT (e_date_edit_new ()); + gtk_table_attach (GTK_TABLE (table), (GtkWidget*) dedit, + 0, 1, 0, 1, GTK_FILL, GTK_EXPAND, 0, 0); gtk_widget_show ((GtkWidget*) (dedit)); + button = gtk_button_new_with_label ("Print Date"); + gtk_table_attach (GTK_TABLE (table), button, + 1, 2, 0, 1, 0, 0, 0, 0); + gtk_widget_show (button); + gtk_signal_connect (GTK_OBJECT (button), "clicked", + GTK_SIGNAL_FUNC (on_get_date_clicked), dedit); + + /* EDateEdit 2. */ + dedit = E_DATE_EDIT (e_date_edit_new ()); + gtk_table_attach (GTK_TABLE (table), (GtkWidget*) dedit, + 0, 1, 1, 2, GTK_FILL, GTK_EXPAND, 0, 0); + gtk_widget_show ((GtkWidget*) (dedit)); e_date_edit_set_week_start_day (dedit, 1); e_date_edit_set_show_week_numbers (dedit, TRUE); e_date_edit_set_use_24_hour_format (dedit, FALSE); e_date_edit_set_time_popup_range (dedit, 8, 18); -#if 0 e_date_edit_set_show_time (dedit, FALSE); -#endif - vbox = gtk_vbox_new (FALSE, 0); - gtk_box_pack_start (GTK_BOX (vbox), (GtkWidget*) dedit, - FALSE, TRUE, 0); - gtk_widget_show (vbox); + button = gtk_button_new_with_label ("Print Date"); + gtk_table_attach (GTK_TABLE (table), button, + 1, 2, 1, 2, 0, 0, 0, 0); + gtk_widget_show (button); + gtk_signal_connect (GTK_OBJECT (button), "clicked", + GTK_SIGNAL_FUNC (on_get_date_clicked), dedit); - button = gtk_button_new_with_label ("Get Date"); - gtk_box_pack_end (GTK_BOX (vbox), button, FALSE, TRUE, 0); + /* EDateEdit 3. */ + dedit = E_DATE_EDIT (e_date_edit_new ()); + gtk_table_attach (GTK_TABLE (table), (GtkWidget*) dedit, + 0, 1, 2, 3, GTK_FILL, GTK_EXPAND, 0, 0); + gtk_widget_show ((GtkWidget*) (dedit)); + e_date_edit_set_week_start_day (dedit, 1); + e_date_edit_set_show_week_numbers (dedit, TRUE); + e_date_edit_set_use_24_hour_format (dedit, FALSE); + e_date_edit_set_time_popup_range (dedit, 8, 18); + e_date_edit_set_allow_no_date_set (dedit, TRUE); + + button = gtk_button_new_with_label ("Print Date"); + gtk_table_attach (GTK_TABLE (table), button, + 1, 2, 2, 3, 0, 0, 0, 0); gtk_widget_show (button); gtk_signal_connect (GTK_OBJECT (button), "clicked", GTK_SIGNAL_FUNC (on_get_date_clicked), dedit); - gnome_app_set_contents (GNOME_APP (app), vbox); + gtk_widget_show (app); gtk_main (); |