1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ 2 3 /* 4 * Author : 5 * Damon Chaplin <damon@ximian.com> 6 * 7 * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) 8 * 9 * Based on the GnomeDateEdit, part of the Gnome Library. 10 * Copyright (C) 1997, 1998, 1999, 2000 Free Software Foundation 11 * 12 * This program is free software; you can redistribute it and/or modify it 13 * under the terms of the GNU Lesser General Public License as published by 14 * published by the Free Software Foundation; either the 15 * 16 * This program is distributed in the hope that it will be useful, but 17 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 18 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 19 * for more details. 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * along with this program; if not, see <http://www.gnu.org/licenses/>. 23 */ 24 25 /* 26 * EDateEdit - a widget based on GnomeDateEdit to provide a date & optional 27 * time field with popups for entering a date. 28 * 29 * It emits a "changed" signal when the date and/or time has changed. 30 * You can check if the last date or time entered was invalid by 31 * calling e_date_edit_date_is_valid() and e_date_edit_time_is_valid(). 32 * 33 * Note that when the user types in a date or time, it will only emit the 34 * signals when the user presses the return key or switches the keyboard 35 * focus to another widget, or you call one of the _get_time/date functions. 36 */ 37 38 #if !defined (__E_UTIL_H_INSIDE__) && !defined (LIBEUTIL_COMPILATION) 39 #error "Only <e-util/e-util.h> should be included directly." 40 #endif 41 42 #ifndef E_DATE_EDIT_H 43 #define E_DATE_EDIT_H 44 45 #include <time.h> 46 #include <gtk/gtk.h> 47 48 /* Standard GObject macros */ 49 #define E_TYPE_DATE_EDIT \ 50 (e_date_edit_get_type ()) 51 #define E_DATE_EDIT(obj) \ 52 (G_TYPE_CHECK_INSTANCE_CAST \ 53 ((obj), E_TYPE_DATE_EDIT, EDateEdit)) 54 #define E_DATE_EDIT_CLASS(cls) \ 55 (G_TYPE_CHECK_CLASS_CAST \ 56 ((cls), E_TYPE_DATE_EDIT, EDateEditClass)) 57 #define E_IS_DATE_EDIT(obj) \ 58 (G_TYPE_CHECK_INSTANCE_TYPE \ 59 ((obj), E_TYPE_DATE_EDIT)) 60 #define E_IS_DATE_EDIT_CLASS(cls) \ 61 (G_TYPE_CHECK_CLASS_TYPE \ 62 ((cls), E_TYPE_DATE_EDIT)) 63 #define E_DATE_EDIT_GET_CLASS(obj) \ 64 (G_TYPE_INSTANCE_GET_CLASS \ 65 ((obj), E_TYPE_DATE_EDIT, EDateEditClass)) 66 67 G_BEGIN_DECLS 68 69 typedef struct _EDateEdit EDateEdit; 70 typedef struct _EDateEditClass EDateEditClass; 71 typedef struct _EDateEditPrivate EDateEditPrivate; 72 73 /* The type of the callback function optionally used to get the current time. 74 */ 75 typedef struct tm (*EDateEditGetTimeCallback) 76 (EDateEdit *dedit, 77 gpointer data); 78 79 struct _EDateEdit { 80 GtkBox hbox; 81 EDateEditPrivate *priv; 82 }; 83 84 struct _EDateEditClass { 85 GtkBoxClass parent_class; 86 87 /* Signals */ 88 void (*changed) (EDateEdit *dedit); 89 }; 90 91 GType e_date_edit_get_type (void) G_GNUC_CONST; 92 GtkWidget * e_date_edit_new (void); 93 94 /* Analogous to gtk_editable_set_editable. disable editing, while still 95 * allowing selection. */ 96 void e_date_edit_set_editable (EDateEdit *dedit, 97 gboolean editable); 98 99 /* Returns TRUE if the last date and time set were valid. The date and time 100 * are only set when the user hits Return or switches keyboard focus, or 101 * selects a date or time from the popup. */ 102 gboolean e_date_edit_date_is_valid (EDateEdit *dedit); 103 gboolean e_date_edit_time_is_valid (EDateEdit *dedit); 104 105 /* Returns the last valid date & time set, or -1 if the date & time was set to 106 * 'None' and this is permitted via e_date_edit_set_allow_no_date_set. */ 107 time_t e_date_edit_get_time (EDateEdit *dedit); 108 void e_date_edit_set_time (EDateEdit *dedit, 109 time_t the_time); 110 111 /* This returns the last valid date set, without the time. It returns TRUE 112 * if a date is set, or FALSE if the date is set to 'None' and this is 113 * permitted via e_date_edit_set_allow_no_date_set. (Month is 1 - 12). */ 114 gboolean e_date_edit_get_date (EDateEdit *dedit, 115 gint *year, 116 gint *month, 117 gint *day); 118 void e_date_edit_set_date (EDateEdit *dedit, 119 gint year, 120 gint month, 121 gint day); 122 123 /* This returns the last valid time set, without the date. It returns TRUE 124 * if a time is set, or FALSE if the time is set to 'None' and this is 125 * permitted via e_date_edit_set_allow_no_date_set. */ 126 gboolean e_date_edit_get_time_of_day (EDateEdit *dedit, 127 gint *hour, 128 gint *minute); 129 /* Set the time. Pass -1 as hour to set to empty. */ 130 void e_date_edit_set_time_of_day (EDateEdit *dedit, 131 gint hour, 132 gint minute); 133 134 void e_date_edit_set_date_and_time_of_day 135 (EDateEdit *dedit, 136 gint year, 137 gint month, 138 gint day, 139 gint hour, 140 gint minute); 141 142 /* Whether we show the date field. */ 143 gboolean e_date_edit_get_show_date (EDateEdit *dedit); 144 void e_date_edit_set_show_date (EDateEdit *dedit, 145 gboolean show_date); 146 147 /* Whether we show the time field. */ 148 gboolean e_date_edit_get_show_time (EDateEdit *dedit); 149 void e_date_edit_set_show_time (EDateEdit *dedit, 150 gboolean show_time); 151 152 /* The week start day, used in the date popup. */ 153 GDateWeekday e_date_edit_get_week_start_day (EDateEdit *dedit); 154 void e_date_edit_set_week_start_day (EDateEdit *dedit, 155 GDateWeekday week_start_day); 156 157 /* Whether we show week numbers in the date popup. */ 158 gboolean e_date_edit_get_show_week_numbers 159 (EDateEdit *dedit); 160 void e_date_edit_set_show_week_numbers 161 (EDateEdit *dedit, 162 gboolean show_week_numbers); 163 164 /* Whether we use 24 hour format in the time field & popup. */ 165 gboolean e_date_edit_get_use_24_hour_format 166 (EDateEdit *dedit); 167 void e_date_edit_set_use_24_hour_format 168 (EDateEdit *dedit, 169 gboolean use_24_hour_format); 170 171 /* Whether we allow the date to be set to 'None'. e_date_edit_get_time() will 172 * return (time_t) -1 in this case. */ 173 gboolean e_date_edit_get_allow_no_date_set 174 (EDateEdit *dedit); 175 void e_date_edit_set_allow_no_date_set 176 (EDateEdit *dedit, 177 gboolean allow_no_date_set); 178 179 /* The range of time to show in the time combo popup. */ 180 void e_date_edit_get_time_popup_range 181 (EDateEdit *dedit, 182 gint *lower_hour, 183 gint *upper_hour); 184 void e_date_edit_set_time_popup_range 185 (EDateEdit *dedit, 186 gint lower_hour, 187 gint upper_hour); 188 189 /* Whether the time field is made insensitive rather than hiding it. */ 190 gboolean e_date_edit_get_make_time_insensitive 191 (EDateEdit *dedit); 192 void e_date_edit_set_make_time_insensitive 193 (EDateEdit *dedit, 194 gboolean make_insensitive); 195 196 /* Whether two-digit years in date could be modified as in future; default is TRUE */ 197 gboolean e_date_edit_get_twodigit_year_can_future 198 (EDateEdit *dedit); 199 void e_date_edit_set_twodigit_year_can_future 200 (EDateEdit *dedit, 201 gboolean value); 202 203 /* Sets a callback to use to get the current time. This is useful if the 204 * application needs to use its own timezone data rather than rely on the 205 * Unix timezone. */ 206 void e_date_edit_set_get_time_callback 207 (EDateEdit *dedit, 208 EDateEditGetTimeCallback cb, 209 gpointer data, 210 GDestroyNotify destroy); 211 212 GtkWidget * e_date_edit_get_entry (EDateEdit *dedit); 213 214 gboolean e_date_edit_has_focus (EDateEdit *dedit); 215 216 G_END_DECLS 217 218 #endif /* E_DATE_EDIT_H */ 219