2008-07-01 22:57:50 +00:00
|
|
|
|
/* GTK - The GIMP Toolkit
|
1998-09-27 18:32:00 +00:00
|
|
|
|
* Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
|
|
|
|
|
*
|
|
|
|
|
* GTK Calendar Widget
|
2004-11-12 17:52:08 +00:00
|
|
|
|
* Copyright (C) 1998 Cesar Miquel, Shawn T. Amundson and Mattias Groenlund
|
2011-01-24 02:50:39 +00:00
|
|
|
|
*
|
1998-09-27 18:32:00 +00:00
|
|
|
|
* This library is free software; you can redistribute it and/or
|
2000-07-26 11:33:08 +00:00
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
1998-09-27 18:32:00 +00:00
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2011-01-24 02:50:39 +00:00
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
2000-07-26 11:33:08 +00:00
|
|
|
|
* Lesser General Public License for more details.
|
1998-09-27 18:32:00 +00:00
|
|
|
|
*
|
2000-07-26 11:33:08 +00:00
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
2014-10-01 23:30:12 +00:00
|
|
|
|
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
1998-09-27 18:32:00 +00:00
|
|
|
|
*/
|
|
|
|
|
|
1999-02-24 07:37:18 +00:00
|
|
|
|
/*
|
2000-03-14 19:57:25 +00:00
|
|
|
|
* Modified by the GTK+ Team and others 1997-2000. See the AUTHORS
|
1999-02-24 07:37:18 +00:00
|
|
|
|
* file for a list of people on the GTK+ Team. See the ChangeLog
|
|
|
|
|
* files for a list of changes. These files are distributed with
|
2011-01-24 02:50:39 +00:00
|
|
|
|
* GTK+ at ftp://ftp.gtk.org/pub/gtk/.
|
1999-02-24 07:37:18 +00:00
|
|
|
|
*/
|
|
|
|
|
|
2010-07-06 20:06:34 +00:00
|
|
|
|
/**
|
|
|
|
|
* SECTION:gtkcalendar
|
|
|
|
|
* @Short_description: Displays a calendar and allows the user to select a date
|
|
|
|
|
* @Title: GtkCalendar
|
|
|
|
|
*
|
2011-01-04 16:36:42 +00:00
|
|
|
|
* #GtkCalendar is a widget that displays a Gregorian calendar, one month
|
|
|
|
|
* at a time. It can be created with gtk_calendar_new().
|
2010-07-06 20:06:34 +00:00
|
|
|
|
*
|
2020-02-10 19:14:18 +00:00
|
|
|
|
* The date that is currently displayed can be altered with
|
|
|
|
|
* gtk_calendar_select_day().
|
2010-07-06 20:06:34 +00:00
|
|
|
|
*
|
2011-01-04 16:36:42 +00:00
|
|
|
|
* To place a visual marker on a particular day, use gtk_calendar_mark_day()
|
|
|
|
|
* and to remove the marker, gtk_calendar_unmark_day(). Alternative, all
|
|
|
|
|
* marks can be cleared with gtk_calendar_clear_marks().
|
2010-07-06 20:06:34 +00:00
|
|
|
|
*
|
|
|
|
|
* The selected date can be retrieved from a #GtkCalendar using
|
|
|
|
|
* gtk_calendar_get_date().
|
2011-01-04 16:36:42 +00:00
|
|
|
|
*
|
2014-01-31 16:11:23 +00:00
|
|
|
|
* Users should be aware that, although the Gregorian calendar is the
|
|
|
|
|
* legal calendar in most countries, it was adopted progressively
|
|
|
|
|
* between 1582 and 1929. Display before these dates is likely to be
|
|
|
|
|
* historically incorrect.
|
2020-02-13 16:53:42 +00:00
|
|
|
|
*
|
|
|
|
|
* # CSS nodes
|
|
|
|
|
*
|
|
|
|
|
* |[<!-- language="plain" -->
|
|
|
|
|
* calendar.view
|
|
|
|
|
* ├── header
|
|
|
|
|
* │ ├── button
|
|
|
|
|
* │ ├── stack.month
|
|
|
|
|
* │ ├── button
|
|
|
|
|
* │ ├── button
|
|
|
|
|
* │ ├── label.year
|
|
|
|
|
* │ ╰── button
|
|
|
|
|
* ╰── grid
|
2020-02-13 17:40:20 +00:00
|
|
|
|
* ╰── label[.day-name][.week-number][.day-number][.other-month][.today]
|
2020-02-13 16:53:42 +00:00
|
|
|
|
* ]|
|
|
|
|
|
*
|
|
|
|
|
* GtkCalendar has a main node with name calendar. It contains a subnode called header
|
|
|
|
|
* containing the widgets for switching between years and months.
|
|
|
|
|
*
|
|
|
|
|
* The grid subnode contains all day labels, including week numbers on the left (marked
|
|
|
|
|
* with the .week-number css class) and day names on top (marked with the .day-name
|
|
|
|
|
* css class).
|
|
|
|
|
*
|
|
|
|
|
* Day labels that belong to the previous or next month get the .other-month style class.
|
2020-02-13 17:40:20 +00:00
|
|
|
|
* The label of the current day get the .today style class.
|
2020-02-13 16:53:42 +00:00
|
|
|
|
*
|
|
|
|
|
* Marked day labels get the :selected state assigned.
|
2010-07-06 20:06:34 +00:00
|
|
|
|
*/
|
|
|
|
|
|
2008-06-22 14:28:52 +00:00
|
|
|
|
#include "config.h"
|
This might seem like a large patch, but it isn't that bad, and nothing
should break on Unix/X11.
Win32 merge and general portability stuff:
* acconfig.h,configure.in: Check for <sys/time.h>.
* gdk/win32: New directory (actually, been there for a while).
* gtk/fnmatch.c: Include <glib.h> for G_DIR_SEPARATOR, WIN32 and
NATIVE_WIN32, and use these. Always case fold on Win32. No
backslashed escapes on native Win32.
* gtk/{gtk.def,makefile.msc}: New files.
* gtk/Makefile.am: Add above new files.
* gtk/{gtkaccelgroup,gtkbindings}.c: Include <string.h>
instead of <strings.h>.
* gtk/{gtkcalendar,gtkitemfactory,gtkpreview,gtkrc}.c: Include
config.h. Protect inclusion of <sys/param.h>, <sys/time.h>, and
<unistd.h> appropriately.
* gtk/gtkdnd.c: Merge in Win32 version (which doesn't do much).
Use ABS() (from <glib.h>) instead of abs().
* gtk/gtkfilesel.c: Moved Win32-specific includes after inclusion
of gtk (and thus glib) headers, so that WIN32 will be
defined. With MS C, include <direct.h> for mkdir prototype.
* gtk/gtkitemfactory.c (gtk_item_factory_callback_marshal): Add
some casts, needed by MS C.
* gtk/{gtklayout,gtkplug}.c: Merge in Win32 version (which isn't
implemented).
* gtk/gtkmain.c: Include gdk/gdkx.h for GDK_WINDOWING. Include
<X11/Xlocale.h> only on X11 platform, otherwise <locale.h>. Use
G_SEARCHPATH_SEPARATOR_S and g_module_build_path.
* gtk/gtkmain.h: Mark variables for export/import on Win32.
* gtk/gtkrange.c (gtk_range_motion_notify): Set mods also in case
the event is not a hint, or its window is not the slider. Needed
on Win32, at least.
* gtk/gtkrc.c: Include config.h and gdk/gdkx.h. Use <locale.h>
unless on X11. Skip \r chars, too. Use G_DIR_SEPARATOR and
G_SEARCHPATH_SEPARATOR(_S). Use g_path_is_absolute. On Win32, use
a subdirectory of the Windows directory as gtk system
configuration directory.
* gtk/gtkselection.c: No chunks on Win32.
* gtk/gtksocket.c: Not implemented on Win32.
* gtk/gtkthemes.c (gtk_theme_engine_get): Use g_module_build_path.
* gtk/makeenums.h: Include gdkprivate.h after gdk.h.
* gtk/testrgb.c: Use dynamically allocated buffer. Use GTimers.
1999-03-15 00:03:37 +00:00
|
|
|
|
|
|
|
|
|
#ifdef HAVE_SYS_TIME_H
|
1998-09-27 18:32:00 +00:00
|
|
|
|
#include <sys/time.h>
|
This might seem like a large patch, but it isn't that bad, and nothing
should break on Unix/X11.
Win32 merge and general portability stuff:
* acconfig.h,configure.in: Check for <sys/time.h>.
* gdk/win32: New directory (actually, been there for a while).
* gtk/fnmatch.c: Include <glib.h> for G_DIR_SEPARATOR, WIN32 and
NATIVE_WIN32, and use these. Always case fold on Win32. No
backslashed escapes on native Win32.
* gtk/{gtk.def,makefile.msc}: New files.
* gtk/Makefile.am: Add above new files.
* gtk/{gtkaccelgroup,gtkbindings}.c: Include <string.h>
instead of <strings.h>.
* gtk/{gtkcalendar,gtkitemfactory,gtkpreview,gtkrc}.c: Include
config.h. Protect inclusion of <sys/param.h>, <sys/time.h>, and
<unistd.h> appropriately.
* gtk/gtkdnd.c: Merge in Win32 version (which doesn't do much).
Use ABS() (from <glib.h>) instead of abs().
* gtk/gtkfilesel.c: Moved Win32-specific includes after inclusion
of gtk (and thus glib) headers, so that WIN32 will be
defined. With MS C, include <direct.h> for mkdir prototype.
* gtk/gtkitemfactory.c (gtk_item_factory_callback_marshal): Add
some casts, needed by MS C.
* gtk/{gtklayout,gtkplug}.c: Merge in Win32 version (which isn't
implemented).
* gtk/gtkmain.c: Include gdk/gdkx.h for GDK_WINDOWING. Include
<X11/Xlocale.h> only on X11 platform, otherwise <locale.h>. Use
G_SEARCHPATH_SEPARATOR_S and g_module_build_path.
* gtk/gtkmain.h: Mark variables for export/import on Win32.
* gtk/gtkrange.c (gtk_range_motion_notify): Set mods also in case
the event is not a hint, or its window is not the slider. Needed
on Win32, at least.
* gtk/gtkrc.c: Include config.h and gdk/gdkx.h. Use <locale.h>
unless on X11. Skip \r chars, too. Use G_DIR_SEPARATOR and
G_SEARCHPATH_SEPARATOR(_S). Use g_path_is_absolute. On Win32, use
a subdirectory of the Windows directory as gtk system
configuration directory.
* gtk/gtkselection.c: No chunks on Win32.
* gtk/gtksocket.c: Not implemented on Win32.
* gtk/gtkthemes.c (gtk_theme_engine_get): Use g_module_build_path.
* gtk/makeenums.h: Include gdkprivate.h after gdk.h.
* gtk/testrgb.c: Use dynamically allocated buffer. Use GTimers.
1999-03-15 00:03:37 +00:00
|
|
|
|
#endif
|
2005-01-14 13:43:54 +00:00
|
|
|
|
#ifdef HAVE__NL_TIME_FIRST_WEEKDAY
|
2005-01-13 19:37:54 +00:00
|
|
|
|
#include <langinfo.h>
|
|
|
|
|
#endif
|
1998-09-27 18:32:00 +00:00
|
|
|
|
#include <string.h>
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
#include <time.h>
|
2005-11-28 01:51:08 +00:00
|
|
|
|
|
|
|
|
|
#include <glib.h>
|
|
|
|
|
|
|
|
|
|
#ifdef G_OS_WIN32
|
|
|
|
|
#include <windows.h>
|
|
|
|
|
#endif
|
|
|
|
|
|
1998-09-27 18:32:00 +00:00
|
|
|
|
#include "gtkcalendar.h"
|
2020-02-29 02:47:17 +00:00
|
|
|
|
#include "gtkdroptarget.h"
|
2003-05-08 00:25:51 +00:00
|
|
|
|
#include "gtkintl.h"
|
2003-05-20 22:37:57 +00:00
|
|
|
|
#include "gtkmain.h"
|
|
|
|
|
#include "gtkmarshalers.h"
|
2007-12-28 09:36:06 +00:00
|
|
|
|
#include "gtktooltip.h"
|
2005-03-22 02:14:55 +00:00
|
|
|
|
#include "gtkprivate.h"
|
2016-12-23 11:07:22 +00:00
|
|
|
|
#include "gtkrendericonprivate.h"
|
|
|
|
|
#include "gtksnapshot.h"
|
|
|
|
|
#include "gtkstylecontextprivate.h"
|
2017-06-27 18:48:14 +00:00
|
|
|
|
#include "gtkwidgetprivate.h"
|
2019-05-29 17:10:46 +00:00
|
|
|
|
#include "gtkgestureclick.h"
|
2017-12-11 03:15:12 +00:00
|
|
|
|
#include "gtkgesturedrag.h"
|
2017-09-15 12:55:19 +00:00
|
|
|
|
#include "gtkeventcontrollerscroll.h"
|
2018-03-05 13:58:57 +00:00
|
|
|
|
#include "gtkeventcontrollerkey.h"
|
2020-02-20 01:51:03 +00:00
|
|
|
|
#include "gtkeventcontrollerfocus.h"
|
2019-12-31 07:20:49 +00:00
|
|
|
|
#include "gtkdragsource.h"
|
2020-01-06 21:12:18 +00:00
|
|
|
|
#include "gtknative.h"
|
|
|
|
|
#include "gtkicontheme.h"
|
|
|
|
|
#include "gtkdragicon.h"
|
2020-01-27 09:28:42 +00:00
|
|
|
|
#include "gtkbutton.h"
|
|
|
|
|
#include "gtkbox.h"
|
2020-02-04 13:03:17 +00:00
|
|
|
|
#include "gtkboxlayout.h"
|
|
|
|
|
#include "gtkorientable.h"
|
2020-01-27 09:28:42 +00:00
|
|
|
|
#include "gtklabel.h"
|
|
|
|
|
#include "gtkstack.h"
|
2020-02-04 13:03:17 +00:00
|
|
|
|
#include "gtkgrid.h"
|
1998-09-27 18:32:00 +00:00
|
|
|
|
|
2005-12-06 17:07:55 +00:00
|
|
|
|
static const guint month_length[2][13] =
|
1998-09-27 18:32:00 +00:00
|
|
|
|
{
|
1998-10-01 13:24:42 +00:00
|
|
|
|
{ 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 },
|
|
|
|
|
{ 0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }
|
1998-09-27 18:32:00 +00:00
|
|
|
|
};
|
|
|
|
|
|
2011-01-24 02:50:39 +00:00
|
|
|
|
static gboolean
|
2005-12-06 17:07:55 +00:00
|
|
|
|
leap (guint year)
|
1998-09-27 18:32:00 +00:00
|
|
|
|
{
|
2014-12-24 01:28:49 +00:00
|
|
|
|
return ((((year % 4) == 0) && ((year % 100) != 0)) || ((year % 400) == 0));
|
1998-09-27 18:32:00 +00:00
|
|
|
|
}
|
|
|
|
|
|
2011-01-24 02:50:39 +00:00
|
|
|
|
static guint
|
2005-12-06 17:07:55 +00:00
|
|
|
|
day_of_week (guint year, guint mm, guint dd)
|
1998-09-27 18:32:00 +00:00
|
|
|
|
{
|
2014-12-24 01:28:49 +00:00
|
|
|
|
GDateTime *dt;
|
|
|
|
|
guint days;
|
1998-09-27 18:32:00 +00:00
|
|
|
|
|
2014-12-24 01:28:49 +00:00
|
|
|
|
dt = g_date_time_new_local (year, mm, dd, 1, 1, 1);
|
2015-01-02 23:05:29 +00:00
|
|
|
|
if (dt == NULL)
|
|
|
|
|
return 0;
|
|
|
|
|
|
2014-12-24 01:28:49 +00:00
|
|
|
|
days = g_date_time_get_day_of_week (dt);
|
|
|
|
|
g_date_time_unref (dt);
|
1998-09-27 18:32:00 +00:00
|
|
|
|
|
2014-12-24 01:28:49 +00:00
|
|
|
|
return days;
|
1998-09-27 18:32:00 +00:00
|
|
|
|
}
|
|
|
|
|
|
2011-01-24 02:50:39 +00:00
|
|
|
|
static guint
|
2014-12-24 01:28:49 +00:00
|
|
|
|
week_of_year (guint year, guint mm, guint dd)
|
1998-09-27 18:32:00 +00:00
|
|
|
|
{
|
2014-12-24 01:28:49 +00:00
|
|
|
|
GDateTime *dt;
|
|
|
|
|
guint week;
|
1998-09-27 18:32:00 +00:00
|
|
|
|
|
2014-12-24 01:28:49 +00:00
|
|
|
|
dt = g_date_time_new_local (year, mm, dd, 1, 1, 1);
|
2015-01-02 23:05:29 +00:00
|
|
|
|
if (dt == NULL)
|
|
|
|
|
return 1;
|
|
|
|
|
|
2014-12-24 01:28:49 +00:00
|
|
|
|
week = g_date_time_get_week_of_year (dt);
|
|
|
|
|
g_date_time_unref (dt);
|
1998-09-27 18:32:00 +00:00
|
|
|
|
|
2014-12-24 01:28:49 +00:00
|
|
|
|
return week;
|
1998-09-27 18:32:00 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
enum {
|
|
|
|
|
MONTH_PREV,
|
|
|
|
|
MONTH_CURRENT,
|
|
|
|
|
MONTH_NEXT
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
enum {
|
|
|
|
|
DAY_SELECTED_SIGNAL,
|
|
|
|
|
PREV_MONTH_SIGNAL,
|
|
|
|
|
NEXT_MONTH_SIGNAL,
|
|
|
|
|
PREV_YEAR_SIGNAL,
|
|
|
|
|
NEXT_YEAR_SIGNAL,
|
|
|
|
|
LAST_SIGNAL
|
|
|
|
|
};
|
|
|
|
|
|
2003-05-08 00:25:51 +00:00
|
|
|
|
enum
|
|
|
|
|
{
|
|
|
|
|
PROP_0,
|
|
|
|
|
PROP_YEAR,
|
|
|
|
|
PROP_MONTH,
|
|
|
|
|
PROP_DAY,
|
|
|
|
|
PROP_SHOW_HEADING,
|
|
|
|
|
PROP_SHOW_DAY_NAMES,
|
|
|
|
|
PROP_SHOW_WEEK_NUMBERS,
|
|
|
|
|
};
|
|
|
|
|
|
2005-05-11 19:16:19 +00:00
|
|
|
|
static guint gtk_calendar_signals[LAST_SIGNAL] = { 0 };
|
1998-10-04 23:07:04 +00:00
|
|
|
|
|
2019-05-26 22:56:56 +00:00
|
|
|
|
typedef struct _GtkCalendarClass GtkCalendarClass;
|
|
|
|
|
typedef struct _GtkCalendarPrivate GtkCalendarPrivate;
|
|
|
|
|
|
|
|
|
|
struct _GtkCalendar
|
|
|
|
|
{
|
|
|
|
|
GtkWidget widget;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct _GtkCalendarClass
|
|
|
|
|
{
|
|
|
|
|
GtkWidgetClass parent_class;
|
|
|
|
|
|
|
|
|
|
void (* day_selected) (GtkCalendar *calendar);
|
|
|
|
|
void (* prev_month) (GtkCalendar *calendar);
|
|
|
|
|
void (* next_month) (GtkCalendar *calendar);
|
|
|
|
|
void (* prev_year) (GtkCalendar *calendar);
|
|
|
|
|
void (* next_year) (GtkCalendar *calendar);
|
|
|
|
|
};
|
|
|
|
|
|
2005-05-11 19:16:19 +00:00
|
|
|
|
struct _GtkCalendarPrivate
|
1998-10-04 23:07:04 +00:00
|
|
|
|
{
|
2020-02-04 11:19:08 +00:00
|
|
|
|
guint show_week_numbers: 1;
|
|
|
|
|
guint show_heading: 1;
|
|
|
|
|
guint show_day_names: 1;
|
2010-08-12 15:14:51 +00:00
|
|
|
|
|
2020-01-27 09:28:42 +00:00
|
|
|
|
GtkWidget *header_box;
|
|
|
|
|
GtkWidget *year_label;
|
|
|
|
|
GtkWidget *month_name_stack;
|
|
|
|
|
GtkWidget *arrow_widgets[4];
|
|
|
|
|
|
2020-02-04 13:03:17 +00:00
|
|
|
|
GtkWidget *grid;
|
|
|
|
|
GtkWidget *day_name_labels[7];
|
|
|
|
|
GtkWidget *week_number_labels[6];
|
|
|
|
|
GtkWidget *day_number_labels[6][7];
|
|
|
|
|
|
2020-02-05 08:22:21 +00:00
|
|
|
|
GDateTime *date;
|
2010-08-12 15:14:51 +00:00
|
|
|
|
|
|
|
|
|
gint day_month[6][7];
|
|
|
|
|
gint day[6][7];
|
|
|
|
|
|
|
|
|
|
gint num_marked_dates;
|
|
|
|
|
gint marked_date[31];
|
|
|
|
|
|
|
|
|
|
gint focus_row;
|
|
|
|
|
gint focus_col;
|
|
|
|
|
|
2003-08-08 22:17:34 +00:00
|
|
|
|
guint year_before : 1;
|
2003-08-08 23:01:17 +00:00
|
|
|
|
|
2003-08-08 22:44:14 +00:00
|
|
|
|
gint week_start;
|
1998-10-04 23:07:04 +00:00
|
|
|
|
};
|
|
|
|
|
|
2005-05-11 19:16:19 +00:00
|
|
|
|
static void gtk_calendar_set_property (GObject *object,
|
2011-01-24 02:50:39 +00:00
|
|
|
|
guint prop_id,
|
|
|
|
|
const GValue *value,
|
|
|
|
|
GParamSpec *pspec);
|
2005-05-11 19:16:19 +00:00
|
|
|
|
static void gtk_calendar_get_property (GObject *object,
|
2011-01-24 02:50:39 +00:00
|
|
|
|
guint prop_id,
|
|
|
|
|
GValue *value,
|
|
|
|
|
GParamSpec *pspec);
|
2005-05-11 19:16:19 +00:00
|
|
|
|
|
2019-05-29 17:10:46 +00:00
|
|
|
|
static void gtk_calendar_button_press (GtkGestureClick *gesture,
|
|
|
|
|
int n_press,
|
|
|
|
|
double x,
|
|
|
|
|
double y,
|
|
|
|
|
gpointer user_data);
|
2018-03-05 13:58:57 +00:00
|
|
|
|
static gboolean gtk_calendar_key_controller_key_pressed (GtkEventControllerKey *controller,
|
|
|
|
|
guint keyval,
|
|
|
|
|
guint keycode,
|
|
|
|
|
GdkModifierType state,
|
|
|
|
|
GtkWidget *widget);
|
2020-02-20 01:51:03 +00:00
|
|
|
|
static void gtk_calendar_focus_controller_focus (GtkEventController *controller,
|
2018-03-23 15:09:37 +00:00
|
|
|
|
GtkWidget *widget);
|
2011-06-27 01:44:42 +00:00
|
|
|
|
|
2005-05-11 19:16:19 +00:00
|
|
|
|
static void calendar_invalidate_day (GtkCalendar *widget,
|
2011-01-24 02:50:39 +00:00
|
|
|
|
gint row,
|
|
|
|
|
gint col);
|
2005-05-11 19:16:19 +00:00
|
|
|
|
static void calendar_invalidate_day_num (GtkCalendar *widget,
|
2011-01-24 02:50:39 +00:00
|
|
|
|
gint day);
|
2005-05-11 19:16:19 +00:00
|
|
|
|
|
2018-07-18 13:34:39 +00:00
|
|
|
|
static gboolean gtk_calendar_scroll_controller_scroll (GtkEventControllerScroll *scroll,
|
|
|
|
|
gdouble dx,
|
|
|
|
|
gdouble dy,
|
|
|
|
|
GtkWidget *widget);
|
2017-09-15 12:55:19 +00:00
|
|
|
|
|
2020-01-27 09:28:42 +00:00
|
|
|
|
static void calendar_set_month_prev (GtkCalendar *calendar);
|
|
|
|
|
static void calendar_set_month_next (GtkCalendar *calendar);
|
|
|
|
|
static void calendar_set_year_prev (GtkCalendar *calendar);
|
|
|
|
|
static void calendar_set_year_next (GtkCalendar *calendar);
|
|
|
|
|
|
|
|
|
|
|
1998-09-27 18:32:00 +00:00
|
|
|
|
static char *default_abbreviated_dayname[7];
|
|
|
|
|
static char *default_monthname[12];
|
|
|
|
|
|
2013-06-27 19:02:52 +00:00
|
|
|
|
G_DEFINE_TYPE_WITH_PRIVATE (GtkCalendar, gtk_calendar, GTK_TYPE_WIDGET)
|
1998-09-27 18:32:00 +00:00
|
|
|
|
|
2020-02-29 02:47:17 +00:00
|
|
|
|
static void
|
|
|
|
|
gtk_calendar_drag_notify_value (GtkDropTarget *target,
|
|
|
|
|
GParamSpec **pspec,
|
|
|
|
|
GtkCalendar *calendar)
|
|
|
|
|
{
|
|
|
|
|
GDate *date;
|
|
|
|
|
const GValue *value;
|
|
|
|
|
|
|
|
|
|
value = gtk_drop_target_get_value (target);
|
|
|
|
|
if (value == NULL)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
date = g_date_new ();
|
|
|
|
|
g_date_set_parse (date, g_value_get_string (value));
|
|
|
|
|
if (!g_date_valid (date))
|
|
|
|
|
gtk_drop_target_reject (target);
|
|
|
|
|
g_date_free (date);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
|
gtk_calendar_drag_drop (GtkDropTarget *dest,
|
|
|
|
|
const GValue *value,
|
|
|
|
|
double x,
|
|
|
|
|
double y,
|
|
|
|
|
GtkCalendar *calendar)
|
|
|
|
|
{
|
|
|
|
|
GDate *date;
|
|
|
|
|
GDateTime *datetime;
|
|
|
|
|
|
|
|
|
|
date = g_date_new ();
|
|
|
|
|
g_date_set_parse (date, g_value_get_string (value));
|
|
|
|
|
|
|
|
|
|
if (!g_date_valid (date))
|
|
|
|
|
{
|
|
|
|
|
g_warning ("Received invalid date data");
|
|
|
|
|
g_date_free (date);
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
datetime = g_date_time_new_local (g_date_get_year (date),
|
|
|
|
|
g_date_get_month (date),
|
|
|
|
|
g_date_get_day (date),
|
|
|
|
|
0, 0, 0);
|
|
|
|
|
g_date_free (date);
|
|
|
|
|
|
|
|
|
|
gtk_calendar_select_day (calendar, datetime);
|
|
|
|
|
g_date_time_unref (datetime);
|
|
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
2020-01-27 09:28:42 +00:00
|
|
|
|
static void
|
|
|
|
|
gtk_calendar_dispose (GObject *object)
|
|
|
|
|
{
|
|
|
|
|
GtkCalendarPrivate *priv = gtk_calendar_get_instance_private (GTK_CALENDAR (object));
|
|
|
|
|
|
2020-02-05 08:22:21 +00:00
|
|
|
|
g_clear_pointer (&priv->date, g_date_time_unref);
|
2020-01-27 09:28:42 +00:00
|
|
|
|
g_clear_pointer (&priv->header_box, gtk_widget_unparent);
|
2020-02-04 13:03:17 +00:00
|
|
|
|
g_clear_pointer (&priv->grid, gtk_widget_unparent);
|
2020-01-27 09:28:42 +00:00
|
|
|
|
|
|
|
|
|
G_OBJECT_CLASS (gtk_calendar_parent_class)->dispose (object);
|
|
|
|
|
}
|
|
|
|
|
|
1998-09-27 18:32:00 +00:00
|
|
|
|
static void
|
|
|
|
|
gtk_calendar_class_init (GtkCalendarClass *class)
|
|
|
|
|
{
|
2002-02-10 14:33:06 +00:00
|
|
|
|
GObjectClass *gobject_class;
|
1998-09-27 18:32:00 +00:00
|
|
|
|
GtkWidgetClass *widget_class;
|
2002-02-10 14:33:06 +00:00
|
|
|
|
|
|
|
|
|
gobject_class = (GObjectClass*) class;
|
1998-09-27 18:32:00 +00:00
|
|
|
|
widget_class = (GtkWidgetClass*) class;
|
2011-01-24 02:50:39 +00:00
|
|
|
|
|
2020-01-27 09:28:42 +00:00
|
|
|
|
gobject_class->dispose = gtk_calendar_dispose;
|
2003-05-08 00:25:51 +00:00
|
|
|
|
gobject_class->set_property = gtk_calendar_set_property;
|
|
|
|
|
gobject_class->get_property = gtk_calendar_get_property;
|
doh, this was broken beyond believe.
Tue Dec 12 23:46:44 2000 Tim Janik <timj@gtk.org>
* gtk/stock-icons/Makefile.am: doh, this was broken beyond believe.
* gtk/gtkbox.c: change property types from (u)long to (u)int for
::position and ::padding.
* gtk/gtkcontainer.c: make ::border_width an INT property.
* gtk/gtkpacker.c: make ::position an INT property.
* gtk/gtkscrolledwindow.c (gtk_scrolled_window_adjustment_changed):
guard against NULL h/v scrollbars, since this is used at construction
time.
* gtk/gtkclist.[hc]: nuked gtk_clist_construct(), implemented
internal gtk_clist_constructor().
* gtk/gtkctree.[hc]: nuked gtk_ctree_construct(), implemented
gtk_ctree_constructor().
* gtk/gtkprogressbar.c (gtk_progress_bar_class_init): property
::pulse_step should use ARG_PULSE_STEP, not ARG_FRACTION.
* docs/reference/Makefile.am: fun stuff, disabled docs generation
again, gtk-scan.c needs to introspec paramspecs, not GtkAgs.
* gtk/gtkwidget.[hc]:
removed gtk_widget_setv(), gtk_widget_getv(), gtk_widget_newv()
and gtk_widget_get().
(gtk_widget_new): use g_object_new_valist().
(gtk_widget_set): use g_object_set_valist().
* gtk/gtkobject.[hc]:
removed gtk_object_arg_get_info(), gtk_object_getv(),
gtk_object_query_args(), gtk_object_newv(),
gtk_object_class_add_signals(),
gtk_object_class_user_signal_new(),
gtk_object_class_user_signal_newv(),
gtk_object_arg_set(), gtk_object_arg_get(),
gtk_object_args_collect(),
gtk_object_default_construct(),
gtk_object_constructed(),
GTK_CONSTRUCTED and GTK_OBJECT_CONSTRUCTED().
removed nsignals, signals and n_args members from GtkObjectClass.
(gtk_object_new): use g_object_new_valist().
(gtk_object_set): use g_object_set_valist().
(gtk_object_get): use g_object_get_valist().
* gtk/gtkcompat.h: define gtk_object_default_construct().
* gtk/gtktypeutils.c (gtk_type_new): create constructed objects via
g_object_new().
* gtk/*.c: removed gtk_object_class_add_signals() from class_init()
fucntions, cleaned up method assignments (make sure your structures
are setup properly before calling out). removed all GTK_CONSTRUCTED
hacks ;)
2000-12-13 01:34:41 +00:00
|
|
|
|
|
2007-12-28 19:36:16 +00:00
|
|
|
|
/**
|
|
|
|
|
* GtkCalendar:year:
|
|
|
|
|
*
|
2011-01-24 02:50:39 +00:00
|
|
|
|
* The selected year.
|
2007-12-28 19:36:16 +00:00
|
|
|
|
* This property gets initially set to the current year.
|
2011-01-24 02:50:39 +00:00
|
|
|
|
*/
|
2003-05-08 00:25:51 +00:00
|
|
|
|
g_object_class_install_property (gobject_class,
|
|
|
|
|
PROP_YEAR,
|
|
|
|
|
g_param_spec_int ("year",
|
2011-01-24 02:50:39 +00:00
|
|
|
|
P_("Year"),
|
|
|
|
|
P_("The selected year"),
|
2020-02-10 19:59:40 +00:00
|
|
|
|
1, 9999, 1,
|
|
|
|
|
G_PARAM_READWRITE|G_PARAM_EXPLICIT_NOTIFY));
|
2007-12-28 19:36:16 +00:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* GtkCalendar:month:
|
|
|
|
|
*
|
2011-01-24 02:50:39 +00:00
|
|
|
|
* The selected month (as a number between 0 and 11).
|
2007-12-28 19:36:16 +00:00
|
|
|
|
* This property gets initially set to the current month.
|
|
|
|
|
*/
|
2003-05-08 00:25:51 +00:00
|
|
|
|
g_object_class_install_property (gobject_class,
|
|
|
|
|
PROP_MONTH,
|
|
|
|
|
g_param_spec_int ("month",
|
2011-01-24 02:50:39 +00:00
|
|
|
|
P_("Month"),
|
|
|
|
|
P_("The selected month (as a number between 0 and 11)"),
|
|
|
|
|
0, 11, 0,
|
2020-02-10 19:59:40 +00:00
|
|
|
|
G_PARAM_READWRITE|G_PARAM_EXPLICIT_NOTIFY));
|
2007-12-28 19:36:16 +00:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* GtkCalendar:day:
|
|
|
|
|
*
|
2011-01-24 02:50:39 +00:00
|
|
|
|
* The selected day (as a number between 1 and 31, or 0
|
2007-12-28 19:36:16 +00:00
|
|
|
|
* to unselect the currently selected day).
|
|
|
|
|
* This property gets initially set to the current day.
|
|
|
|
|
*/
|
2003-05-08 00:25:51 +00:00
|
|
|
|
g_object_class_install_property (gobject_class,
|
|
|
|
|
PROP_DAY,
|
|
|
|
|
g_param_spec_int ("day",
|
2011-01-24 02:50:39 +00:00
|
|
|
|
P_("Day"),
|
|
|
|
|
P_("The selected day (as a number between 1 and 31, or 0 to unselect the currently selected day)"),
|
|
|
|
|
0, 31, 0,
|
2020-02-10 19:59:40 +00:00
|
|
|
|
G_PARAM_READWRITE|G_PARAM_EXPLICIT_NOTIFY));
|
2003-06-14 22:27:14 +00:00
|
|
|
|
|
2020-02-04 13:03:17 +00:00
|
|
|
|
/**
|
|
|
|
|
* GtkCalendar:show-heading:
|
|
|
|
|
*
|
|
|
|
|
* Determines whether a heading is displayed.
|
|
|
|
|
*/
|
2003-05-08 00:25:51 +00:00
|
|
|
|
g_object_class_install_property (gobject_class,
|
|
|
|
|
PROP_SHOW_HEADING,
|
2005-03-09 06:15:13 +00:00
|
|
|
|
g_param_spec_boolean ("show-heading",
|
2011-01-24 02:50:39 +00:00
|
|
|
|
P_("Show Heading"),
|
|
|
|
|
P_("If TRUE, a heading is displayed"),
|
|
|
|
|
TRUE,
|
2014-06-07 18:07:07 +00:00
|
|
|
|
GTK_PARAM_READWRITE|G_PARAM_EXPLICIT_NOTIFY));
|
2003-06-14 22:27:14 +00:00
|
|
|
|
|
2020-02-04 13:03:17 +00:00
|
|
|
|
/**
|
|
|
|
|
* GtkCalendar:show-day-names:
|
|
|
|
|
*
|
|
|
|
|
* Determines whether day names are displayed.
|
|
|
|
|
*/
|
2003-05-08 00:25:51 +00:00
|
|
|
|
g_object_class_install_property (gobject_class,
|
|
|
|
|
PROP_SHOW_DAY_NAMES,
|
2005-03-09 06:15:13 +00:00
|
|
|
|
g_param_spec_boolean ("show-day-names",
|
2011-01-24 02:50:39 +00:00
|
|
|
|
P_("Show Day Names"),
|
|
|
|
|
P_("If TRUE, day names are displayed"),
|
|
|
|
|
TRUE,
|
2014-06-07 18:07:07 +00:00
|
|
|
|
GTK_PARAM_READWRITE|G_PARAM_EXPLICIT_NOTIFY));
|
2020-02-04 13:03:17 +00:00
|
|
|
|
/**
|
|
|
|
|
* GtkCalendar:show-week-numbers:
|
|
|
|
|
*
|
|
|
|
|
* Determines whether week numbers are displayed.
|
|
|
|
|
*/
|
2003-05-08 00:25:51 +00:00
|
|
|
|
g_object_class_install_property (gobject_class,
|
|
|
|
|
PROP_SHOW_WEEK_NUMBERS,
|
2005-03-09 06:15:13 +00:00
|
|
|
|
g_param_spec_boolean ("show-week-numbers",
|
2011-01-24 02:50:39 +00:00
|
|
|
|
P_("Show Week Numbers"),
|
|
|
|
|
P_("If TRUE, week numbers are displayed"),
|
|
|
|
|
FALSE,
|
2014-06-07 18:07:07 +00:00
|
|
|
|
GTK_PARAM_READWRITE|G_PARAM_EXPLICIT_NOTIFY));
|
2003-06-14 22:27:14 +00:00
|
|
|
|
|
2010-07-06 20:06:34 +00:00
|
|
|
|
/**
|
|
|
|
|
* GtkCalendar::day-selected:
|
|
|
|
|
* @calendar: the object which received the signal.
|
|
|
|
|
*
|
|
|
|
|
* Emitted when the user selects a day.
|
|
|
|
|
*/
|
1998-09-27 18:32:00 +00:00
|
|
|
|
gtk_calendar_signals[DAY_SELECTED_SIGNAL] =
|
2008-08-11 13:07:18 +00:00
|
|
|
|
g_signal_new (I_("day-selected"),
|
2011-01-24 02:50:39 +00:00
|
|
|
|
G_OBJECT_CLASS_TYPE (gobject_class),
|
|
|
|
|
G_SIGNAL_RUN_FIRST,
|
|
|
|
|
G_STRUCT_OFFSET (GtkCalendarClass, day_selected),
|
|
|
|
|
NULL, NULL,
|
2016-08-29 14:00:17 +00:00
|
|
|
|
NULL,
|
2011-01-24 02:50:39 +00:00
|
|
|
|
G_TYPE_NONE, 0);
|
2010-07-06 20:06:34 +00:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* GtkCalendar::prev-month:
|
|
|
|
|
* @calendar: the object which received the signal.
|
|
|
|
|
*
|
|
|
|
|
* Emitted when the user switched to the previous month.
|
|
|
|
|
*/
|
1998-09-27 18:32:00 +00:00
|
|
|
|
gtk_calendar_signals[PREV_MONTH_SIGNAL] =
|
2008-08-11 13:07:18 +00:00
|
|
|
|
g_signal_new (I_("prev-month"),
|
2011-01-24 02:50:39 +00:00
|
|
|
|
G_OBJECT_CLASS_TYPE (gobject_class),
|
|
|
|
|
G_SIGNAL_RUN_FIRST,
|
|
|
|
|
G_STRUCT_OFFSET (GtkCalendarClass, prev_month),
|
|
|
|
|
NULL, NULL,
|
2016-08-29 14:00:17 +00:00
|
|
|
|
NULL,
|
2011-01-24 02:50:39 +00:00
|
|
|
|
G_TYPE_NONE, 0);
|
2010-07-06 20:06:34 +00:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* GtkCalendar::next-month:
|
|
|
|
|
* @calendar: the object which received the signal.
|
|
|
|
|
*
|
|
|
|
|
* Emitted when the user switched to the next month.
|
|
|
|
|
*/
|
1998-09-27 18:32:00 +00:00
|
|
|
|
gtk_calendar_signals[NEXT_MONTH_SIGNAL] =
|
2008-08-11 13:07:18 +00:00
|
|
|
|
g_signal_new (I_("next-month"),
|
2011-01-24 02:50:39 +00:00
|
|
|
|
G_OBJECT_CLASS_TYPE (gobject_class),
|
|
|
|
|
G_SIGNAL_RUN_FIRST,
|
|
|
|
|
G_STRUCT_OFFSET (GtkCalendarClass, next_month),
|
|
|
|
|
NULL, NULL,
|
2016-08-29 14:00:17 +00:00
|
|
|
|
NULL,
|
2011-01-24 02:50:39 +00:00
|
|
|
|
G_TYPE_NONE, 0);
|
2010-07-06 20:06:34 +00:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* GtkCalendar::prev-year:
|
|
|
|
|
* @calendar: the object which received the signal.
|
|
|
|
|
*
|
|
|
|
|
* Emitted when user switched to the previous year.
|
|
|
|
|
*/
|
1998-09-27 18:32:00 +00:00
|
|
|
|
gtk_calendar_signals[PREV_YEAR_SIGNAL] =
|
2008-08-11 13:07:18 +00:00
|
|
|
|
g_signal_new (I_("prev-year"),
|
2011-01-24 02:50:39 +00:00
|
|
|
|
G_OBJECT_CLASS_TYPE (gobject_class),
|
|
|
|
|
G_SIGNAL_RUN_FIRST,
|
|
|
|
|
G_STRUCT_OFFSET (GtkCalendarClass, prev_year),
|
|
|
|
|
NULL, NULL,
|
2016-08-29 14:00:17 +00:00
|
|
|
|
NULL,
|
2011-01-24 02:50:39 +00:00
|
|
|
|
G_TYPE_NONE, 0);
|
2010-07-06 20:06:34 +00:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* GtkCalendar::next-year:
|
|
|
|
|
* @calendar: the object which received the signal.
|
|
|
|
|
*
|
|
|
|
|
* Emitted when user switched to the next year.
|
|
|
|
|
*/
|
1998-09-27 18:32:00 +00:00
|
|
|
|
gtk_calendar_signals[NEXT_YEAR_SIGNAL] =
|
2008-08-11 13:07:18 +00:00
|
|
|
|
g_signal_new (I_("next-year"),
|
2011-01-24 02:50:39 +00:00
|
|
|
|
G_OBJECT_CLASS_TYPE (gobject_class),
|
|
|
|
|
G_SIGNAL_RUN_FIRST,
|
|
|
|
|
G_STRUCT_OFFSET (GtkCalendarClass, next_year),
|
|
|
|
|
NULL, NULL,
|
2016-08-29 14:00:17 +00:00
|
|
|
|
NULL,
|
2011-01-24 02:50:39 +00:00
|
|
|
|
G_TYPE_NONE, 0);
|
2015-10-28 10:35:33 +00:00
|
|
|
|
|
|
|
|
|
gtk_widget_class_set_accessible_role (widget_class, ATK_ROLE_CALENDAR);
|
2020-02-04 13:03:17 +00:00
|
|
|
|
gtk_widget_class_set_layout_manager_type (widget_class, GTK_TYPE_BOX_LAYOUT);
|
2017-11-18 03:49:57 +00:00
|
|
|
|
gtk_widget_class_set_css_name (widget_class, I_("calendar"));
|
1998-09-27 18:32:00 +00:00
|
|
|
|
}
|
2020-01-27 09:28:42 +00:00
|
|
|
|
|
2020-03-02 03:03:03 +00:00
|
|
|
|
static GdkContentProvider *
|
|
|
|
|
gtk_calendar_drag_prepare (GtkDragSource *source,
|
|
|
|
|
double x,
|
|
|
|
|
double y,
|
|
|
|
|
GtkCalendar *self)
|
|
|
|
|
{
|
|
|
|
|
GtkCalendarPrivate *priv = gtk_calendar_get_instance_private (self);
|
|
|
|
|
GDate *date;
|
|
|
|
|
gchar str[128];
|
|
|
|
|
|
|
|
|
|
date = g_date_new_dmy (g_date_time_get_day_of_month (priv->date),
|
|
|
|
|
g_date_time_get_month (priv->date),
|
|
|
|
|
g_date_time_get_year (priv->date));
|
|
|
|
|
g_date_strftime (str, 127, "%x", date);
|
|
|
|
|
g_free (date);
|
|
|
|
|
|
|
|
|
|
return gdk_content_provider_new_typed (G_TYPE_STRING, str);
|
|
|
|
|
}
|
|
|
|
|
|
2018-02-17 22:03:49 +00:00
|
|
|
|
#pragma GCC diagnostic push
|
|
|
|
|
#pragma GCC diagnostic ignored "-Wformat-nonliteral"
|
|
|
|
|
|
1998-09-27 18:32:00 +00:00
|
|
|
|
static void
|
|
|
|
|
gtk_calendar_init (GtkCalendar *calendar)
|
|
|
|
|
{
|
2020-01-27 09:28:42 +00:00
|
|
|
|
GtkCalendarPrivate *priv = gtk_calendar_get_instance_private (calendar);
|
2005-05-11 19:16:19 +00:00
|
|
|
|
GtkWidget *widget = GTK_WIDGET (calendar);
|
2018-03-10 17:29:57 +00:00
|
|
|
|
GtkEventController *controller;
|
2018-03-09 05:14:59 +00:00
|
|
|
|
GtkGesture *gesture;
|
2020-03-02 03:03:03 +00:00
|
|
|
|
GtkDragSource *source;
|
2020-02-29 02:47:17 +00:00
|
|
|
|
GtkDropTarget *target;
|
1998-09-27 18:32:00 +00:00
|
|
|
|
gint i;
|
2005-11-28 01:51:08 +00:00
|
|
|
|
#ifdef G_OS_WIN32
|
|
|
|
|
wchar_t wbuffer[100];
|
|
|
|
|
#else
|
2018-02-17 22:03:49 +00:00
|
|
|
|
static const char *month_format = NULL;
|
2006-10-07 21:32:53 +00:00
|
|
|
|
char buffer[255];
|
1998-09-27 18:32:00 +00:00
|
|
|
|
time_t tmp_time;
|
2005-11-28 01:51:08 +00:00
|
|
|
|
#endif
|
2003-08-08 22:17:34 +00:00
|
|
|
|
gchar *year_before;
|
2005-10-04 13:42:27 +00:00
|
|
|
|
#ifdef HAVE__NL_TIME_FIRST_WEEKDAY
|
2007-06-08 18:39:29 +00:00
|
|
|
|
union { unsigned int word; char *string; } langinfo;
|
2005-09-30 17:53:19 +00:00
|
|
|
|
gint week_1stday = 0;
|
|
|
|
|
gint first_weekday = 1;
|
2005-09-09 17:26:14 +00:00
|
|
|
|
guint week_origin;
|
2005-10-04 13:42:27 +00:00
|
|
|
|
#else
|
|
|
|
|
gchar *week_start;
|
|
|
|
|
#endif
|
2020-02-04 11:29:54 +00:00
|
|
|
|
int min_year_width;
|
2020-02-04 13:03:17 +00:00
|
|
|
|
GDateTime *now;
|
2005-09-09 17:26:14 +00:00
|
|
|
|
|
2010-03-02 03:40:38 +00:00
|
|
|
|
gtk_widget_set_can_focus (widget, TRUE);
|
2011-01-24 02:50:39 +00:00
|
|
|
|
|
2020-02-06 16:32:26 +00:00
|
|
|
|
gtk_widget_add_css_class (GTK_WIDGET (calendar), GTK_STYLE_CLASS_VIEW);
|
2017-05-07 12:26:10 +00:00
|
|
|
|
|
2020-01-27 09:28:42 +00:00
|
|
|
|
priv->header_box = g_object_new (GTK_TYPE_BOX,
|
|
|
|
|
"css-name", "header",
|
|
|
|
|
NULL);
|
|
|
|
|
priv->year_label = gtk_label_new ("");
|
2020-02-06 16:32:26 +00:00
|
|
|
|
gtk_widget_add_css_class (priv->year_label, "year");
|
2020-01-27 09:28:42 +00:00
|
|
|
|
priv->month_name_stack = gtk_stack_new ();
|
2020-02-06 16:32:26 +00:00
|
|
|
|
gtk_widget_add_css_class (priv->month_name_stack, "month");
|
2020-01-27 09:28:42 +00:00
|
|
|
|
priv->arrow_widgets[0] = gtk_button_new_from_icon_name ("pan-start-symbolic");
|
|
|
|
|
g_signal_connect_swapped (priv->arrow_widgets[0], "clicked", G_CALLBACK (calendar_set_month_prev), calendar);
|
|
|
|
|
priv->arrow_widgets[1] = gtk_button_new_from_icon_name ("pan-end-symbolic");
|
|
|
|
|
g_signal_connect_swapped (priv->arrow_widgets[1], "clicked", G_CALLBACK (calendar_set_month_next), calendar);
|
|
|
|
|
gtk_widget_set_hexpand (priv->arrow_widgets[1], TRUE);
|
|
|
|
|
gtk_widget_set_halign (priv->arrow_widgets[1], GTK_ALIGN_START);
|
|
|
|
|
priv->arrow_widgets[2] = gtk_button_new_from_icon_name ("pan-start-symbolic");
|
|
|
|
|
g_signal_connect_swapped (priv->arrow_widgets[2], "clicked", G_CALLBACK (calendar_set_year_prev), calendar);
|
|
|
|
|
priv->arrow_widgets[3] = gtk_button_new_from_icon_name ("pan-end-symbolic");
|
|
|
|
|
g_signal_connect_swapped (priv->arrow_widgets[3], "clicked", G_CALLBACK (calendar_set_year_next), calendar);
|
|
|
|
|
|
|
|
|
|
gtk_container_add (GTK_CONTAINER (priv->header_box), priv->arrow_widgets[0]);
|
|
|
|
|
gtk_container_add (GTK_CONTAINER (priv->header_box), priv->month_name_stack);
|
|
|
|
|
gtk_container_add (GTK_CONTAINER (priv->header_box), priv->arrow_widgets[1]);
|
|
|
|
|
gtk_container_add (GTK_CONTAINER (priv->header_box), priv->arrow_widgets[2]);
|
|
|
|
|
gtk_container_add (GTK_CONTAINER (priv->header_box), priv->year_label);
|
|
|
|
|
gtk_container_add (GTK_CONTAINER (priv->header_box), priv->arrow_widgets[3]);
|
|
|
|
|
|
|
|
|
|
gtk_widget_set_parent (priv->header_box, GTK_WIDGET (calendar));
|
|
|
|
|
|
2019-05-29 17:10:46 +00:00
|
|
|
|
gesture = gtk_gesture_click_new ();
|
2018-03-09 05:14:59 +00:00
|
|
|
|
g_signal_connect (gesture, "pressed", G_CALLBACK (gtk_calendar_button_press), calendar);
|
|
|
|
|
gtk_widget_add_controller (GTK_WIDGET (calendar), GTK_EVENT_CONTROLLER (gesture));
|
2017-09-13 15:37:25 +00:00
|
|
|
|
|
2020-03-02 03:03:03 +00:00
|
|
|
|
source = gtk_drag_source_new ();
|
|
|
|
|
g_signal_connect (source, "prepare", G_CALLBACK (gtk_calendar_drag_prepare), calendar);
|
|
|
|
|
gtk_widget_add_controller (GTK_WIDGET (calendar), GTK_EVENT_CONTROLLER (source));
|
2017-12-11 03:15:12 +00:00
|
|
|
|
|
2018-03-10 17:29:57 +00:00
|
|
|
|
controller =
|
|
|
|
|
gtk_event_controller_scroll_new (GTK_EVENT_CONTROLLER_SCROLL_VERTICAL |
|
2017-09-15 12:55:19 +00:00
|
|
|
|
GTK_EVENT_CONTROLLER_SCROLL_DISCRETE);
|
2018-03-10 17:29:57 +00:00
|
|
|
|
g_signal_connect (controller, "scroll",
|
2017-09-15 12:55:19 +00:00
|
|
|
|
G_CALLBACK (gtk_calendar_scroll_controller_scroll),
|
|
|
|
|
calendar);
|
2018-03-10 17:29:57 +00:00
|
|
|
|
gtk_widget_add_controller (GTK_WIDGET (calendar), controller);
|
2017-09-15 12:55:19 +00:00
|
|
|
|
|
2018-04-20 17:58:06 +00:00
|
|
|
|
controller = gtk_event_controller_key_new ();
|
|
|
|
|
g_signal_connect (controller, "key-pressed",
|
2018-03-05 13:58:57 +00:00
|
|
|
|
G_CALLBACK (gtk_calendar_key_controller_key_pressed),
|
|
|
|
|
calendar);
|
2020-02-20 01:51:03 +00:00
|
|
|
|
gtk_widget_add_controller (GTK_WIDGET (calendar), controller);
|
|
|
|
|
controller = gtk_event_controller_focus_new ();
|
|
|
|
|
g_signal_connect (controller, "enter",
|
|
|
|
|
G_CALLBACK (gtk_calendar_focus_controller_focus),
|
|
|
|
|
calendar);
|
|
|
|
|
g_signal_connect (controller, "leave",
|
|
|
|
|
G_CALLBACK (gtk_calendar_focus_controller_focus),
|
2018-03-23 15:09:37 +00:00
|
|
|
|
calendar);
|
2018-04-20 17:58:06 +00:00
|
|
|
|
gtk_widget_add_controller (GTK_WIDGET (calendar), controller);
|
2018-03-05 13:58:57 +00:00
|
|
|
|
|
1998-09-27 18:32:00 +00:00
|
|
|
|
if (!default_abbreviated_dayname[0])
|
|
|
|
|
for (i=0; i<7; i++)
|
|
|
|
|
{
|
2005-11-28 01:51:08 +00:00
|
|
|
|
#ifndef G_OS_WIN32
|
2011-01-24 02:50:39 +00:00
|
|
|
|
tmp_time= (i+3)*86400;
|
2018-02-10 13:07:56 +00:00
|
|
|
|
strftime (buffer, sizeof (buffer), "%a", gmtime (&tmp_time));
|
2011-01-24 02:50:39 +00:00
|
|
|
|
default_abbreviated_dayname[i] = g_locale_to_utf8 (buffer, -1, NULL, NULL, NULL);
|
2005-11-28 01:51:08 +00:00
|
|
|
|
#else
|
2011-01-24 02:50:39 +00:00
|
|
|
|
if (!GetLocaleInfoW (GetThreadLocale (), LOCALE_SABBREVDAYNAME1 + (i+6)%7,
|
|
|
|
|
wbuffer, G_N_ELEMENTS (wbuffer)))
|
|
|
|
|
default_abbreviated_dayname[i] = g_strdup_printf ("(%d)", i);
|
|
|
|
|
else
|
|
|
|
|
default_abbreviated_dayname[i] = g_utf16_to_utf8 (wbuffer, -1, NULL, NULL, NULL);
|
2005-11-28 01:51:08 +00:00
|
|
|
|
#endif
|
1998-09-27 18:32:00 +00:00
|
|
|
|
}
|
2011-01-24 02:50:39 +00:00
|
|
|
|
|
1998-09-27 18:32:00 +00:00
|
|
|
|
if (!default_monthname[0])
|
|
|
|
|
for (i=0; i<12; i++)
|
|
|
|
|
{
|
2005-11-28 01:51:08 +00:00
|
|
|
|
#ifndef G_OS_WIN32
|
2011-01-24 02:50:39 +00:00
|
|
|
|
tmp_time=i*2764800;
|
2018-02-17 22:03:49 +00:00
|
|
|
|
if (G_UNLIKELY (month_format == NULL))
|
|
|
|
|
{
|
|
|
|
|
buffer[0] = '\0';
|
|
|
|
|
month_format = "%OB";
|
|
|
|
|
strftime (buffer, sizeof (buffer), month_format, gmtime (&tmp_time));
|
|
|
|
|
/* "%OB" is not supported in Linux with glibc < 2.27 */
|
|
|
|
|
if (!strcmp (buffer, "%OB") || !strcmp (buffer, "OB") || !strcmp (buffer, ""))
|
|
|
|
|
{
|
|
|
|
|
month_format = "%B";
|
|
|
|
|
strftime (buffer, sizeof (buffer), month_format, gmtime (&tmp_time));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
strftime (buffer, sizeof (buffer), month_format, gmtime (&tmp_time));
|
|
|
|
|
|
2011-01-24 02:50:39 +00:00
|
|
|
|
default_monthname[i] = g_locale_to_utf8 (buffer, -1, NULL, NULL, NULL);
|
2005-11-28 01:51:08 +00:00
|
|
|
|
#else
|
2011-01-24 02:50:39 +00:00
|
|
|
|
if (!GetLocaleInfoW (GetThreadLocale (), LOCALE_SMONTHNAME1 + i,
|
|
|
|
|
wbuffer, G_N_ELEMENTS (wbuffer)))
|
|
|
|
|
default_monthname[i] = g_strdup_printf ("(%d)", i);
|
|
|
|
|
else
|
|
|
|
|
default_monthname[i] = g_utf16_to_utf8 (wbuffer, -1, NULL, NULL, NULL);
|
2005-11-28 01:51:08 +00:00
|
|
|
|
#endif
|
1998-09-27 18:32:00 +00:00
|
|
|
|
}
|
2011-01-24 02:50:39 +00:00
|
|
|
|
|
2020-01-27 09:28:42 +00:00
|
|
|
|
for (i = 0; i < 12; i ++)
|
|
|
|
|
{
|
|
|
|
|
GtkWidget *month_label = gtk_label_new (default_monthname[i]);
|
|
|
|
|
|
|
|
|
|
gtk_stack_add_named (GTK_STACK (priv->month_name_stack), month_label, default_monthname[i]);
|
|
|
|
|
}
|
|
|
|
|
|
2020-02-04 13:03:17 +00:00
|
|
|
|
priv->grid = gtk_grid_new ();
|
|
|
|
|
gtk_grid_set_row_homogeneous (GTK_GRID (priv->grid), TRUE);
|
|
|
|
|
gtk_grid_set_column_homogeneous (GTK_GRID (priv->grid), TRUE);
|
|
|
|
|
/* Day name labels */
|
|
|
|
|
for (i = 0; i < 7; i ++)
|
|
|
|
|
{
|
|
|
|
|
GtkWidget *label = gtk_label_new (default_abbreviated_dayname[i]);
|
|
|
|
|
|
|
|
|
|
gtk_widget_set_hexpand (label, TRUE);
|
|
|
|
|
gtk_widget_set_vexpand (label, TRUE);
|
2020-02-06 16:32:26 +00:00
|
|
|
|
gtk_widget_add_css_class (label, "day-name");
|
2020-02-04 13:03:17 +00:00
|
|
|
|
gtk_grid_attach (GTK_GRID (priv->grid), label, 1 + i, 0, 1, 1);
|
|
|
|
|
|
|
|
|
|
priv->day_name_labels[i] = label;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Week number labels */
|
|
|
|
|
for (i = 0; i < 6; i ++)
|
|
|
|
|
{
|
|
|
|
|
GtkWidget *label = gtk_label_new ("");
|
|
|
|
|
|
|
|
|
|
gtk_widget_set_hexpand (label, TRUE);
|
|
|
|
|
gtk_widget_set_vexpand (label, TRUE);
|
2020-02-06 16:32:26 +00:00
|
|
|
|
gtk_widget_add_css_class (label, "week-number");
|
2020-02-04 13:03:17 +00:00
|
|
|
|
gtk_grid_attach (GTK_GRID (priv->grid), label, 0, 1 + i, 1, 1);
|
|
|
|
|
|
|
|
|
|
priv->week_number_labels[i] = label;
|
|
|
|
|
gtk_widget_hide (label);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
int x, y;
|
|
|
|
|
|
|
|
|
|
for (y = 0; y < 6; y ++)
|
|
|
|
|
for (x = 0; x < 7; x ++)
|
|
|
|
|
{
|
|
|
|
|
GtkWidget *label = gtk_label_new ("");
|
|
|
|
|
|
|
|
|
|
gtk_widget_set_hexpand (label, TRUE);
|
|
|
|
|
gtk_widget_set_vexpand (label, TRUE);
|
2020-02-06 16:32:26 +00:00
|
|
|
|
gtk_widget_add_css_class (label, "day-number");
|
2020-02-04 13:03:17 +00:00
|
|
|
|
gtk_grid_attach (GTK_GRID (priv->grid), label, 1 + x, 1 + y, 1, 1);
|
|
|
|
|
|
|
|
|
|
priv->day_number_labels[y][x] = label;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
gtk_widget_set_hexpand (priv->grid, TRUE);
|
|
|
|
|
gtk_widget_set_vexpand (priv->grid, TRUE);
|
|
|
|
|
gtk_widget_set_parent (priv->grid, GTK_WIDGET (calendar));
|
|
|
|
|
|
1998-09-27 18:32:00 +00:00
|
|
|
|
for (i=0;i<31;i++)
|
2010-08-12 15:14:51 +00:00
|
|
|
|
priv->marked_date[i] = FALSE;
|
|
|
|
|
priv->num_marked_dates = 0;
|
2011-01-24 02:50:39 +00:00
|
|
|
|
|
2020-02-04 11:19:08 +00:00
|
|
|
|
priv->show_heading = TRUE;
|
|
|
|
|
priv->show_day_names = TRUE;
|
2011-01-24 02:50:39 +00:00
|
|
|
|
|
2010-08-12 15:14:51 +00:00
|
|
|
|
priv->focus_row = -1;
|
|
|
|
|
priv->focus_col = -1;
|
1998-10-05 03:52:48 +00:00
|
|
|
|
|
2020-02-29 02:47:17 +00:00
|
|
|
|
target = gtk_drop_target_new (G_TYPE_STRING, GDK_ACTION_COPY);
|
|
|
|
|
gtk_drop_target_set_preload (target, TRUE);
|
|
|
|
|
g_signal_connect (target, "notify::value", G_CALLBACK (gtk_calendar_drag_notify_value), calendar);
|
|
|
|
|
g_signal_connect (target, "drop", G_CALLBACK (gtk_calendar_drag_drop), calendar);
|
|
|
|
|
gtk_widget_add_controller (widget, GTK_EVENT_CONTROLLER (target));
|
2020-02-04 13:03:17 +00:00
|
|
|
|
|
2005-05-11 19:16:19 +00:00
|
|
|
|
priv->year_before = 0;
|
2003-08-08 22:17:34 +00:00
|
|
|
|
|
|
|
|
|
/* Translate to calendar:YM if you want years to be displayed
|
|
|
|
|
* before months; otherwise translate to calendar:MY.
|
|
|
|
|
* Do *not* translate it to anything else, if it
|
|
|
|
|
* it isn't calendar:YM or calendar:MY it will not work.
|
|
|
|
|
*
|
2009-07-07 15:37:07 +00:00
|
|
|
|
* 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.
|
2003-08-08 22:17:34 +00:00
|
|
|
|
*/
|
|
|
|
|
year_before = _("calendar:MY");
|
|
|
|
|
if (strcmp (year_before, "calendar:YM") == 0)
|
2005-05-11 19:16:19 +00:00
|
|
|
|
priv->year_before = 1;
|
2003-08-08 22:17:34 +00:00
|
|
|
|
else if (strcmp (year_before, "calendar:MY") != 0)
|
2016-02-28 16:06:25 +00:00
|
|
|
|
g_warning ("Whoever translated calendar:MY did so wrongly.");
|
2003-08-08 22:44:14 +00:00
|
|
|
|
|
2006-10-07 21:32:53 +00:00
|
|
|
|
#ifdef G_OS_WIN32
|
2006-10-10 21:51:11 +00:00
|
|
|
|
priv->week_start = 0;
|
|
|
|
|
week_start = NULL;
|
2006-10-07 21:32:53 +00:00
|
|
|
|
|
2006-10-10 21:51:11 +00:00
|
|
|
|
if (GetLocaleInfoW (GetThreadLocale (), LOCALE_IFIRSTDAYOFWEEK,
|
2011-01-24 02:50:39 +00:00
|
|
|
|
wbuffer, G_N_ELEMENTS (wbuffer)))
|
2006-10-10 21:51:11 +00:00
|
|
|
|
week_start = g_utf16_to_utf8 (wbuffer, -1, NULL, NULL, NULL);
|
2011-01-24 02:50:39 +00:00
|
|
|
|
|
2006-10-10 21:51:11 +00:00
|
|
|
|
if (week_start != NULL)
|
2006-10-07 21:32:53 +00:00
|
|
|
|
{
|
2006-10-10 21:51:11 +00:00
|
|
|
|
priv->week_start = (week_start[0] - '0' + 1) % 7;
|
|
|
|
|
g_free(week_start);
|
|
|
|
|
}
|
|
|
|
|
#else
|
2005-01-14 13:43:54 +00:00
|
|
|
|
#ifdef HAVE__NL_TIME_FIRST_WEEKDAY
|
2007-06-08 18:39:29 +00:00
|
|
|
|
langinfo.string = nl_langinfo (_NL_TIME_FIRST_WEEKDAY);
|
|
|
|
|
first_weekday = langinfo.string[0];
|
|
|
|
|
langinfo.string = nl_langinfo (_NL_TIME_WEEK_1STDAY);
|
|
|
|
|
week_origin = langinfo.word;
|
2005-09-30 17:53:19 +00:00
|
|
|
|
if (week_origin == 19971130) /* Sunday */
|
|
|
|
|
week_1stday = 0;
|
|
|
|
|
else if (week_origin == 19971201) /* Monday */
|
|
|
|
|
week_1stday = 1;
|
2005-09-09 17:26:14 +00:00
|
|
|
|
else
|
2016-02-28 16:06:25 +00:00
|
|
|
|
g_warning ("Unknown value of _NL_TIME_WEEK_1STDAY.");
|
2005-09-09 17:26:14 +00:00
|
|
|
|
|
2005-09-30 17:53:19 +00:00
|
|
|
|
priv->week_start = (week_1stday + first_weekday - 1) % 7;
|
2005-01-13 19:37:54 +00:00
|
|
|
|
#else
|
2004-01-02 01:52:04 +00:00
|
|
|
|
/* Translate to calendar:week_start:0 if you want Sunday to be the
|
|
|
|
|
* first day of the week to calendar:week_start:1 if you want Monday
|
|
|
|
|
* to be the first day of the week, and so on.
|
2011-01-24 02:50:39 +00:00
|
|
|
|
*/
|
2004-01-02 01:52:04 +00:00
|
|
|
|
week_start = _("calendar:week_start:0");
|
|
|
|
|
|
|
|
|
|
if (strncmp (week_start, "calendar:week_start:", 20) == 0)
|
2005-05-11 19:16:19 +00:00
|
|
|
|
priv->week_start = *(week_start + 20) - '0';
|
2011-01-24 02:50:39 +00:00
|
|
|
|
else
|
2005-05-11 19:16:19 +00:00
|
|
|
|
priv->week_start = -1;
|
2011-01-24 02:50:39 +00:00
|
|
|
|
|
2005-05-11 19:16:19 +00:00
|
|
|
|
if (priv->week_start < 0 || priv->week_start > 6)
|
2004-01-02 01:52:04 +00:00
|
|
|
|
{
|
2016-02-28 16:06:25 +00:00
|
|
|
|
g_warning ("Whoever translated calendar:week_start:0 did so wrongly.");
|
2005-05-11 19:16:19 +00:00
|
|
|
|
priv->week_start = 0;
|
2004-01-02 01:52:04 +00:00
|
|
|
|
}
|
2005-01-13 19:37:54 +00:00
|
|
|
|
#endif
|
2006-10-07 21:32:53 +00:00
|
|
|
|
#endif
|
2005-10-04 03:28:36 +00:00
|
|
|
|
|
2020-02-05 08:22:21 +00:00
|
|
|
|
gtk_orientable_set_orientation (GTK_ORIENTABLE (gtk_widget_get_layout_manager (GTK_WIDGET (calendar))),
|
|
|
|
|
GTK_ORIENTATION_VERTICAL);
|
|
|
|
|
|
|
|
|
|
/* Select current day */
|
|
|
|
|
priv->date = g_date_time_new_from_unix_local (0);
|
2020-02-04 13:03:17 +00:00
|
|
|
|
now = g_date_time_new_now_local ();
|
2020-02-05 08:22:21 +00:00
|
|
|
|
gtk_calendar_select_day (calendar, now);
|
|
|
|
|
g_date_time_unref (now);
|
2020-02-04 13:03:17 +00:00
|
|
|
|
|
|
|
|
|
/* We just initialized the year label, now add some space to it so
|
|
|
|
|
* changing the year does not increase the calendar width */
|
|
|
|
|
gtk_widget_measure (priv->year_label, GTK_ORIENTATION_HORIZONTAL, -1,
|
|
|
|
|
&min_year_width, NULL, NULL, NULL);
|
|
|
|
|
gtk_widget_set_size_request (priv->year_label, min_year_width + 10, -1);
|
1998-09-27 18:32:00 +00:00
|
|
|
|
}
|
|
|
|
|
|
2018-02-17 22:03:49 +00:00
|
|
|
|
#pragma GCC diagnostic pop
|
|
|
|
|
|
2007-12-28 09:26:38 +00:00
|
|
|
|
static void
|
|
|
|
|
calendar_queue_refresh (GtkCalendar *calendar)
|
|
|
|
|
{
|
2020-02-04 09:01:58 +00:00
|
|
|
|
gtk_widget_queue_resize (GTK_WIDGET (calendar));
|
2007-12-28 09:26:38 +00:00
|
|
|
|
}
|
|
|
|
|
|
1998-09-27 18:32:00 +00:00
|
|
|
|
static void
|
2020-02-05 08:22:21 +00:00
|
|
|
|
calendar_set_month_prev (GtkCalendar *calendar)
|
1998-09-27 18:32:00 +00:00
|
|
|
|
{
|
2019-05-26 23:20:26 +00:00
|
|
|
|
GtkCalendarPrivate *priv = gtk_calendar_get_instance_private (calendar);
|
2020-02-05 08:22:21 +00:00
|
|
|
|
GDateTime *new_date;
|
2008-02-07 15:50:39 +00:00
|
|
|
|
|
2020-02-05 08:22:21 +00:00
|
|
|
|
new_date = g_date_time_add_months (priv->date, -1);
|
2010-08-12 15:14:51 +00:00
|
|
|
|
|
2020-02-05 08:22:21 +00:00
|
|
|
|
gtk_calendar_select_day (calendar, new_date);
|
|
|
|
|
g_date_time_unref (new_date);
|
2020-02-15 10:19:25 +00:00
|
|
|
|
|
|
|
|
|
g_signal_emit (calendar, gtk_calendar_signals[PREV_MONTH_SIGNAL], 0);
|
2020-02-05 08:22:21 +00:00
|
|
|
|
}
|
2010-08-12 15:14:51 +00:00
|
|
|
|
|
2020-02-05 08:22:21 +00:00
|
|
|
|
static void
|
|
|
|
|
calendar_set_month_next (GtkCalendar *calendar)
|
|
|
|
|
{
|
|
|
|
|
GtkCalendarPrivate *priv = gtk_calendar_get_instance_private (calendar);
|
|
|
|
|
GDateTime *new_date;
|
2010-08-12 15:14:51 +00:00
|
|
|
|
|
2020-02-05 08:22:21 +00:00
|
|
|
|
new_date = g_date_time_add_months (priv->date, 1);
|
2001-12-03 15:24:25 +00:00
|
|
|
|
|
2020-02-05 08:22:21 +00:00
|
|
|
|
gtk_calendar_select_day (calendar, new_date);
|
|
|
|
|
g_date_time_unref (new_date);
|
2020-02-15 10:19:25 +00:00
|
|
|
|
|
|
|
|
|
g_signal_emit (calendar, gtk_calendar_signals[NEXT_MONTH_SIGNAL], 0);
|
1998-09-27 18:32:00 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2005-05-11 19:16:19 +00:00
|
|
|
|
calendar_set_year_prev (GtkCalendar *calendar)
|
1998-09-27 18:32:00 +00:00
|
|
|
|
{
|
2019-05-26 23:20:26 +00:00
|
|
|
|
GtkCalendarPrivate *priv = gtk_calendar_get_instance_private (calendar);
|
2020-02-05 08:22:21 +00:00
|
|
|
|
GDateTime *new_date;
|
2010-08-12 15:14:51 +00:00
|
|
|
|
|
2020-02-05 08:22:21 +00:00
|
|
|
|
new_date = g_date_time_add_years (priv->date, -1);
|
2010-08-12 15:14:51 +00:00
|
|
|
|
|
2020-02-05 08:22:21 +00:00
|
|
|
|
gtk_calendar_select_day (calendar, new_date);
|
|
|
|
|
g_date_time_unref (new_date);
|
2020-02-15 10:19:25 +00:00
|
|
|
|
|
|
|
|
|
g_signal_emit (calendar, gtk_calendar_signals[PREV_YEAR_SIGNAL], 0);
|
1998-09-27 18:32:00 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2005-05-11 19:16:19 +00:00
|
|
|
|
calendar_set_year_next (GtkCalendar *calendar)
|
1998-09-27 18:32:00 +00:00
|
|
|
|
{
|
2019-05-26 23:20:26 +00:00
|
|
|
|
GtkCalendarPrivate *priv = gtk_calendar_get_instance_private (calendar);
|
2020-02-05 08:22:21 +00:00
|
|
|
|
GDateTime *new_date;
|
2010-08-12 15:14:51 +00:00
|
|
|
|
|
2020-02-05 08:22:21 +00:00
|
|
|
|
new_date = g_date_time_add_years (priv->date, 1);
|
2010-08-12 15:14:51 +00:00
|
|
|
|
|
2020-02-05 08:22:21 +00:00
|
|
|
|
gtk_calendar_select_day (calendar, new_date);
|
|
|
|
|
g_date_time_unref (new_date);
|
2020-02-15 10:19:25 +00:00
|
|
|
|
|
|
|
|
|
g_signal_emit (calendar, gtk_calendar_signals[NEXT_YEAR_SIGNAL], 0);
|
1998-09-27 18:32:00 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2005-05-11 19:16:19 +00:00
|
|
|
|
calendar_compute_days (GtkCalendar *calendar)
|
1998-09-27 18:32:00 +00:00
|
|
|
|
{
|
2019-05-26 23:20:26 +00:00
|
|
|
|
GtkCalendarPrivate *priv = gtk_calendar_get_instance_private (calendar);
|
2020-02-05 08:22:21 +00:00
|
|
|
|
const int month = g_date_time_get_month (priv->date);
|
|
|
|
|
const int year = g_date_time_get_year (priv->date);
|
|
|
|
|
int ndays_in_month;
|
|
|
|
|
int ndays_in_prev_month;
|
|
|
|
|
int first_day;
|
|
|
|
|
int row;
|
|
|
|
|
int col;
|
|
|
|
|
int day;
|
2010-08-12 15:14:51 +00:00
|
|
|
|
|
2005-05-11 19:16:19 +00:00
|
|
|
|
ndays_in_month = month_length[leap (year)][month];
|
2010-08-12 15:14:51 +00:00
|
|
|
|
|
2005-05-11 19:16:19 +00:00
|
|
|
|
first_day = day_of_week (year, month, 1);
|
|
|
|
|
first_day = (first_day + 7 - priv->week_start) % 7;
|
2014-12-24 02:49:21 +00:00
|
|
|
|
if (first_day == 0)
|
|
|
|
|
first_day = 7;
|
2010-08-12 15:14:51 +00:00
|
|
|
|
|
2005-05-11 19:16:19 +00:00
|
|
|
|
/* Compute days of previous month */
|
|
|
|
|
if (month > 1)
|
2014-12-24 01:28:49 +00:00
|
|
|
|
ndays_in_prev_month = month_length[leap (year)][month - 1];
|
2005-05-11 19:16:19 +00:00
|
|
|
|
else
|
2014-12-24 01:28:49 +00:00
|
|
|
|
ndays_in_prev_month = month_length[leap (year - 1)][12];
|
2014-12-24 02:49:21 +00:00
|
|
|
|
day = ndays_in_prev_month - first_day+ 1;
|
2011-01-24 02:50:39 +00:00
|
|
|
|
|
2014-12-24 02:49:21 +00:00
|
|
|
|
for (col = 0; col < first_day; col++)
|
1998-09-27 18:32:00 +00:00
|
|
|
|
{
|
2014-12-24 02:49:21 +00:00
|
|
|
|
priv->day[0][col] = day;
|
|
|
|
|
priv->day_month[0][col] = MONTH_PREV;
|
|
|
|
|
day++;
|
2005-05-11 19:16:19 +00:00
|
|
|
|
}
|
2011-01-24 02:50:39 +00:00
|
|
|
|
|
2005-05-11 19:16:19 +00:00
|
|
|
|
/* Compute days of current month */
|
2014-12-24 02:49:21 +00:00
|
|
|
|
row = first_day / 7;
|
|
|
|
|
col = first_day % 7;
|
2005-05-11 19:16:19 +00:00
|
|
|
|
for (day = 1; day <= ndays_in_month; day++)
|
|
|
|
|
{
|
2010-08-12 15:14:51 +00:00
|
|
|
|
priv->day[row][col] = day;
|
|
|
|
|
priv->day_month[row][col] = MONTH_CURRENT;
|
|
|
|
|
|
2005-05-11 19:16:19 +00:00
|
|
|
|
col++;
|
|
|
|
|
if (col == 7)
|
2011-01-24 02:50:39 +00:00
|
|
|
|
{
|
|
|
|
|
row++;
|
|
|
|
|
col = 0;
|
|
|
|
|
}
|
2002-03-21 00:50:15 +00:00
|
|
|
|
}
|
2011-01-24 02:50:39 +00:00
|
|
|
|
|
2005-05-11 19:16:19 +00:00
|
|
|
|
/* Compute days of next month */
|
|
|
|
|
day = 1;
|
|
|
|
|
for (; row <= 5; row++)
|
2002-03-21 00:50:15 +00:00
|
|
|
|
{
|
2005-05-11 19:16:19 +00:00
|
|
|
|
for (; col <= 6; col++)
|
2011-01-24 02:50:39 +00:00
|
|
|
|
{
|
|
|
|
|
priv->day[row][col] = day;
|
|
|
|
|
priv->day_month[row][col] = MONTH_NEXT;
|
|
|
|
|
day++;
|
|
|
|
|
}
|
2005-05-11 19:16:19 +00:00
|
|
|
|
col = 0;
|
1998-09-27 18:32:00 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2005-05-11 19:16:19 +00:00
|
|
|
|
calendar_select_and_focus_day (GtkCalendar *calendar,
|
2020-02-04 13:38:19 +00:00
|
|
|
|
int day)
|
1998-09-27 18:32:00 +00:00
|
|
|
|
{
|
2019-05-26 23:20:26 +00:00
|
|
|
|
GtkCalendarPrivate *priv = gtk_calendar_get_instance_private (calendar);
|
2020-02-04 13:38:19 +00:00
|
|
|
|
GDateTime *new_date;
|
2005-05-11 19:16:19 +00:00
|
|
|
|
gint row;
|
|
|
|
|
gint col;
|
2011-01-24 02:50:39 +00:00
|
|
|
|
|
2005-05-11 19:16:19 +00:00
|
|
|
|
for (row = 0; row < 6; row ++)
|
|
|
|
|
for (col = 0; col < 7; col++)
|
|
|
|
|
{
|
2020-02-04 13:03:17 +00:00
|
|
|
|
if (priv->day_month[row][col] == MONTH_CURRENT &&
|
|
|
|
|
priv->day[row][col] == day)
|
2011-01-24 02:50:39 +00:00
|
|
|
|
{
|
|
|
|
|
priv->focus_row = row;
|
|
|
|
|
priv->focus_col = col;
|
2020-02-04 13:38:19 +00:00
|
|
|
|
break;
|
2011-01-24 02:50:39 +00:00
|
|
|
|
}
|
2005-05-11 19:16:19 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-02-05 08:22:21 +00:00
|
|
|
|
new_date = g_date_time_new_local (g_date_time_get_year (priv->date),
|
|
|
|
|
g_date_time_get_month (priv->date),
|
|
|
|
|
day,
|
2020-02-04 13:38:19 +00:00
|
|
|
|
0, 0, 0);
|
|
|
|
|
|
|
|
|
|
gtk_calendar_select_day (calendar, new_date);
|
|
|
|
|
g_date_time_unref (new_date);
|
2005-05-11 19:16:19 +00:00
|
|
|
|
}
|
1998-10-04 23:07:04 +00:00
|
|
|
|
|
2011-01-24 02:50:39 +00:00
|
|
|
|
static void
|
2005-05-11 19:16:19 +00:00
|
|
|
|
gtk_calendar_set_property (GObject *object,
|
2011-01-24 02:50:39 +00:00
|
|
|
|
guint prop_id,
|
|
|
|
|
const GValue *value,
|
|
|
|
|
GParamSpec *pspec)
|
2005-05-11 19:16:19 +00:00
|
|
|
|
{
|
2010-08-12 15:14:51 +00:00
|
|
|
|
GtkCalendar *calendar = GTK_CALENDAR (object);
|
2020-02-10 19:14:18 +00:00
|
|
|
|
GtkCalendarPrivate *priv = gtk_calendar_get_instance_private (calendar);
|
|
|
|
|
GDateTime *date;
|
2005-05-11 19:16:19 +00:00
|
|
|
|
|
2011-01-24 02:50:39 +00:00
|
|
|
|
switch (prop_id)
|
2005-05-11 19:16:19 +00:00
|
|
|
|
{
|
2020-02-10 19:14:18 +00:00
|
|
|
|
case PROP_YEAR:
|
|
|
|
|
date = g_date_time_new_local (g_value_get_int (value),
|
|
|
|
|
g_date_time_get_month (priv->date),
|
|
|
|
|
g_date_time_get_day_of_month (priv->date),
|
|
|
|
|
0, 0, 0);
|
2020-02-10 19:59:40 +00:00
|
|
|
|
if (date)
|
|
|
|
|
{
|
|
|
|
|
gtk_calendar_select_day (calendar, date);
|
|
|
|
|
g_date_time_unref (date);
|
|
|
|
|
}
|
2020-02-10 19:14:18 +00:00
|
|
|
|
break;
|
|
|
|
|
case PROP_MONTH:
|
|
|
|
|
date = g_date_time_new_local (g_date_time_get_year (priv->date),
|
2020-02-10 19:59:40 +00:00
|
|
|
|
g_value_get_int (value) + 1,
|
2020-02-10 19:14:18 +00:00
|
|
|
|
g_date_time_get_day_of_month (priv->date),
|
|
|
|
|
0, 0, 0);
|
2020-02-10 19:59:40 +00:00
|
|
|
|
if (date)
|
|
|
|
|
{
|
|
|
|
|
gtk_calendar_select_day (calendar, date);
|
|
|
|
|
g_date_time_unref (date);
|
|
|
|
|
}
|
2020-02-10 19:14:18 +00:00
|
|
|
|
break;
|
|
|
|
|
case PROP_DAY:
|
|
|
|
|
date = g_date_time_new_local (g_date_time_get_year (priv->date),
|
|
|
|
|
g_date_time_get_month (priv->date),
|
2020-02-10 19:59:40 +00:00
|
|
|
|
g_value_get_int (value) + 1,
|
2020-02-10 19:14:18 +00:00
|
|
|
|
0, 0, 0);
|
2020-02-10 19:59:40 +00:00
|
|
|
|
if (date)
|
|
|
|
|
{
|
|
|
|
|
gtk_calendar_select_day (calendar, date);
|
|
|
|
|
g_date_time_unref (date);
|
|
|
|
|
}
|
2020-02-10 19:14:18 +00:00
|
|
|
|
break;
|
2005-05-11 19:16:19 +00:00
|
|
|
|
case PROP_SHOW_HEADING:
|
2020-02-04 11:19:08 +00:00
|
|
|
|
gtk_calendar_set_show_heading (calendar, g_value_get_boolean (value));
|
2005-05-11 19:16:19 +00:00
|
|
|
|
break;
|
|
|
|
|
case PROP_SHOW_DAY_NAMES:
|
2020-02-04 11:19:08 +00:00
|
|
|
|
gtk_calendar_set_show_day_names (calendar, g_value_get_boolean (value));
|
2005-05-11 19:16:19 +00:00
|
|
|
|
break;
|
|
|
|
|
case PROP_SHOW_WEEK_NUMBERS:
|
2020-02-04 11:19:08 +00:00
|
|
|
|
gtk_calendar_set_show_week_numbers (calendar, g_value_get_boolean (value));
|
2005-05-11 19:16:19 +00:00
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-01-24 02:50:39 +00:00
|
|
|
|
static void
|
2005-05-11 19:16:19 +00:00
|
|
|
|
gtk_calendar_get_property (GObject *object,
|
2011-01-24 02:50:39 +00:00
|
|
|
|
guint prop_id,
|
|
|
|
|
GValue *value,
|
|
|
|
|
GParamSpec *pspec)
|
2005-05-11 19:16:19 +00:00
|
|
|
|
{
|
2007-12-27 20:41:08 +00:00
|
|
|
|
GtkCalendar *calendar = GTK_CALENDAR (object);
|
2019-05-26 23:20:26 +00:00
|
|
|
|
GtkCalendarPrivate *priv = gtk_calendar_get_instance_private (calendar);
|
2005-05-11 19:16:19 +00:00
|
|
|
|
|
2011-01-24 02:50:39 +00:00
|
|
|
|
switch (prop_id)
|
2005-05-11 19:16:19 +00:00
|
|
|
|
{
|
|
|
|
|
case PROP_YEAR:
|
2020-02-05 08:22:21 +00:00
|
|
|
|
g_value_set_int (value, g_date_time_get_year (priv->date));
|
2005-05-11 19:16:19 +00:00
|
|
|
|
break;
|
|
|
|
|
case PROP_MONTH:
|
2020-02-10 19:59:40 +00:00
|
|
|
|
g_value_set_int (value, g_date_time_get_month (priv->date) - 1);
|
2005-05-11 19:16:19 +00:00
|
|
|
|
break;
|
|
|
|
|
case PROP_DAY:
|
2020-02-10 19:59:40 +00:00
|
|
|
|
g_value_set_int (value, g_date_time_get_day_of_month (priv->date) - 1);
|
2005-05-11 19:16:19 +00:00
|
|
|
|
break;
|
|
|
|
|
case PROP_SHOW_HEADING:
|
2020-02-04 11:19:08 +00:00
|
|
|
|
g_value_set_boolean (value, gtk_calendar_get_show_heading (calendar));
|
2005-05-11 19:16:19 +00:00
|
|
|
|
break;
|
|
|
|
|
case PROP_SHOW_DAY_NAMES:
|
2020-02-04 11:19:08 +00:00
|
|
|
|
g_value_set_boolean (value, gtk_calendar_get_show_day_names (calendar));
|
2005-05-11 19:16:19 +00:00
|
|
|
|
break;
|
|
|
|
|
case PROP_SHOW_WEEK_NUMBERS:
|
2020-02-04 11:19:08 +00:00
|
|
|
|
g_value_set_boolean (value, gtk_calendar_get_show_week_numbers (calendar));
|
2005-05-11 19:16:19 +00:00
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
1998-09-27 18:32:00 +00:00
|
|
|
|
static void
|
2005-05-11 19:16:19 +00:00
|
|
|
|
calendar_invalidate_day_num (GtkCalendar *calendar,
|
2011-01-24 02:50:39 +00:00
|
|
|
|
gint day)
|
1998-09-27 18:32:00 +00:00
|
|
|
|
{
|
2017-06-27 18:48:14 +00:00
|
|
|
|
gtk_widget_queue_draw (GTK_WIDGET (calendar));
|
1998-09-27 18:32:00 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2005-05-11 19:16:19 +00:00
|
|
|
|
calendar_invalidate_day (GtkCalendar *calendar,
|
2011-01-24 02:50:39 +00:00
|
|
|
|
gint row,
|
|
|
|
|
gint col)
|
1998-09-27 18:32:00 +00:00
|
|
|
|
{
|
2017-06-27 18:48:14 +00:00
|
|
|
|
gtk_widget_queue_draw (GTK_WIDGET (calendar));
|
2005-05-11 19:16:19 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2020-02-04 13:03:17 +00:00
|
|
|
|
gtk_calendar_button_press (GtkGestureClick *gesture,
|
|
|
|
|
int n_press,
|
|
|
|
|
double x,
|
|
|
|
|
double y,
|
|
|
|
|
gpointer user_data)
|
1998-09-27 18:32:00 +00:00
|
|
|
|
{
|
2020-02-04 13:03:17 +00:00
|
|
|
|
GtkCalendar *calendar = user_data;
|
2005-05-11 19:16:19 +00:00
|
|
|
|
GtkWidget *widget = GTK_WIDGET (calendar);
|
2019-05-26 23:20:26 +00:00
|
|
|
|
GtkCalendarPrivate *priv = gtk_calendar_get_instance_private (calendar);
|
2020-02-04 13:03:17 +00:00
|
|
|
|
GtkWidget *label;
|
2020-02-04 13:38:19 +00:00
|
|
|
|
int row = -1, col = -1;
|
2020-02-04 13:03:17 +00:00
|
|
|
|
int ix, iy;
|
|
|
|
|
int day_month;
|
|
|
|
|
int day;
|
|
|
|
|
|
|
|
|
|
label = gtk_widget_pick (widget, x, y, GTK_PICK_DEFAULT);
|
|
|
|
|
for (iy = 0; iy < 6; iy ++)
|
2020-02-04 13:38:19 +00:00
|
|
|
|
for (ix = 0; ix < 7; ix ++)
|
2020-02-04 13:03:17 +00:00
|
|
|
|
{
|
|
|
|
|
if (label == priv->day_number_labels[iy][ix])
|
|
|
|
|
{
|
|
|
|
|
row = iy;
|
|
|
|
|
col = ix;
|
|
|
|
|
}
|
|
|
|
|
}
|
1998-09-27 18:32:00 +00:00
|
|
|
|
|
2005-05-11 19:16:19 +00:00
|
|
|
|
/* If row or column isn't found, just return. */
|
|
|
|
|
if (row == -1 || col == -1)
|
|
|
|
|
return;
|
2010-10-24 05:22:13 +00:00
|
|
|
|
|
2010-08-12 15:14:51 +00:00
|
|
|
|
day_month = priv->day_month[row][col];
|
2020-02-07 03:32:08 +00:00
|
|
|
|
day = priv->day[row][col];
|
2005-05-11 19:16:19 +00:00
|
|
|
|
|
2020-02-07 03:32:08 +00:00
|
|
|
|
if (day_month == MONTH_PREV)
|
|
|
|
|
calendar_set_month_prev (calendar);
|
|
|
|
|
else if (day_month == MONTH_NEXT)
|
|
|
|
|
calendar_set_month_next (calendar);
|
2010-10-24 05:22:13 +00:00
|
|
|
|
|
2020-02-07 03:32:08 +00:00
|
|
|
|
if (!gtk_widget_has_focus (widget))
|
|
|
|
|
gtk_widget_grab_focus (widget);
|
2010-10-24 05:22:13 +00:00
|
|
|
|
|
2020-02-07 03:32:08 +00:00
|
|
|
|
calendar_select_and_focus_day (calendar, day);
|
1998-09-27 18:32:00 +00:00
|
|
|
|
}
|
|
|
|
|
|
2018-07-18 13:34:39 +00:00
|
|
|
|
static gboolean
|
2017-09-15 12:55:19 +00:00
|
|
|
|
gtk_calendar_scroll_controller_scroll (GtkEventControllerScroll *scroll,
|
|
|
|
|
gdouble dx,
|
|
|
|
|
gdouble dy,
|
|
|
|
|
GtkWidget *widget)
|
2003-08-08 22:03:25 +00:00
|
|
|
|
{
|
|
|
|
|
GtkCalendar *calendar = GTK_CALENDAR (widget);
|
2017-08-25 14:43:42 +00:00
|
|
|
|
|
2017-09-15 12:55:19 +00:00
|
|
|
|
if (!gtk_widget_has_focus (widget))
|
|
|
|
|
gtk_widget_grab_focus (widget);
|
2003-08-08 22:03:25 +00:00
|
|
|
|
|
2017-09-15 12:55:19 +00:00
|
|
|
|
if (dy < 0)
|
|
|
|
|
calendar_set_month_prev (calendar);
|
|
|
|
|
else if (dy > 0)
|
|
|
|
|
calendar_set_month_next (calendar);
|
2018-07-18 13:34:39 +00:00
|
|
|
|
|
|
|
|
|
return GDK_EVENT_STOP;
|
2003-08-08 22:03:25 +00:00
|
|
|
|
}
|
|
|
|
|
|
2005-05-11 19:16:19 +00:00
|
|
|
|
|
|
|
|
|
/****************************************
|
|
|
|
|
* Key handling *
|
|
|
|
|
****************************************/
|
|
|
|
|
|
2011-01-24 02:50:39 +00:00
|
|
|
|
static void
|
|
|
|
|
move_focus (GtkCalendar *calendar,
|
|
|
|
|
gint direction)
|
2003-08-08 22:17:34 +00:00
|
|
|
|
{
|
2019-05-26 23:20:26 +00:00
|
|
|
|
GtkCalendarPrivate *priv = gtk_calendar_get_instance_private (calendar);
|
2003-08-08 22:17:34 +00:00
|
|
|
|
GtkTextDirection text_dir = gtk_widget_get_direction (GTK_WIDGET (calendar));
|
2011-01-24 02:50:39 +00:00
|
|
|
|
|
2003-08-08 22:17:34 +00:00
|
|
|
|
if ((text_dir == GTK_TEXT_DIR_LTR && direction == -1) ||
|
2011-01-24 02:50:39 +00:00
|
|
|
|
(text_dir == GTK_TEXT_DIR_RTL && direction == 1))
|
2003-08-08 22:17:34 +00:00
|
|
|
|
{
|
2010-08-12 15:14:51 +00:00
|
|
|
|
if (priv->focus_col > 0)
|
2011-01-24 02:50:39 +00:00
|
|
|
|
priv->focus_col--;
|
2010-08-12 15:14:51 +00:00
|
|
|
|
else if (priv->focus_row > 0)
|
2011-01-24 02:50:39 +00:00
|
|
|
|
{
|
|
|
|
|
priv->focus_col = 6;
|
|
|
|
|
priv->focus_row--;
|
|
|
|
|
}
|
2007-01-19 03:52:03 +00:00
|
|
|
|
|
2010-08-12 15:14:51 +00:00
|
|
|
|
if (priv->focus_col < 0)
|
|
|
|
|
priv->focus_col = 6;
|
|
|
|
|
if (priv->focus_row < 0)
|
|
|
|
|
priv->focus_row = 5;
|
2003-08-08 22:17:34 +00:00
|
|
|
|
}
|
2011-01-24 02:50:39 +00:00
|
|
|
|
else
|
2003-08-08 22:17:34 +00:00
|
|
|
|
{
|
2010-08-12 15:14:51 +00:00
|
|
|
|
if (priv->focus_col < 6)
|
2011-01-24 02:50:39 +00:00
|
|
|
|
priv->focus_col++;
|
2010-08-12 15:14:51 +00:00
|
|
|
|
else if (priv->focus_row < 5)
|
2011-01-24 02:50:39 +00:00
|
|
|
|
{
|
|
|
|
|
priv->focus_col = 0;
|
|
|
|
|
priv->focus_row++;
|
|
|
|
|
}
|
2007-01-19 03:52:03 +00:00
|
|
|
|
|
2010-08-12 15:14:51 +00:00
|
|
|
|
if (priv->focus_col < 0)
|
|
|
|
|
priv->focus_col = 0;
|
|
|
|
|
if (priv->focus_row < 0)
|
|
|
|
|
priv->focus_row = 0;
|
2003-08-08 22:17:34 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2001-03-16 20:12:40 +00:00
|
|
|
|
static gboolean
|
2018-03-05 13:58:57 +00:00
|
|
|
|
gtk_calendar_key_controller_key_pressed (GtkEventControllerKey *controller,
|
|
|
|
|
guint keyval,
|
|
|
|
|
guint keycode,
|
|
|
|
|
GdkModifierType state,
|
|
|
|
|
GtkWidget *widget)
|
1998-09-27 18:32:00 +00:00
|
|
|
|
{
|
2010-08-12 15:14:51 +00:00
|
|
|
|
GtkCalendar *calendar = GTK_CALENDAR (widget);
|
2019-05-26 23:20:26 +00:00
|
|
|
|
GtkCalendarPrivate *priv = gtk_calendar_get_instance_private (calendar);
|
1998-09-27 18:32:00 +00:00
|
|
|
|
gint return_val;
|
1998-10-05 03:52:48 +00:00
|
|
|
|
gint old_focus_row;
|
|
|
|
|
gint old_focus_col;
|
|
|
|
|
gint row, col, day;
|
2010-08-12 15:14:51 +00:00
|
|
|
|
|
1998-09-27 18:32:00 +00:00
|
|
|
|
return_val = FALSE;
|
2010-08-12 15:14:51 +00:00
|
|
|
|
|
|
|
|
|
old_focus_row = priv->focus_row;
|
|
|
|
|
old_focus_col = priv->focus_col;
|
1998-10-05 03:52:48 +00:00
|
|
|
|
|
2017-08-25 14:43:42 +00:00
|
|
|
|
switch (keyval)
|
1998-09-27 18:32:00 +00:00
|
|
|
|
{
|
2010-09-08 17:35:51 +00:00
|
|
|
|
case GDK_KEY_KP_Left:
|
|
|
|
|
case GDK_KEY_Left:
|
1998-09-27 18:32:00 +00:00
|
|
|
|
return_val = TRUE;
|
2017-08-25 14:43:42 +00:00
|
|
|
|
if (state & GDK_CONTROL_MASK)
|
2011-01-24 02:50:39 +00:00
|
|
|
|
calendar_set_month_prev (calendar);
|
1998-09-27 18:32:00 +00:00
|
|
|
|
else
|
2011-01-24 02:50:39 +00:00
|
|
|
|
{
|
|
|
|
|
move_focus (calendar, -1);
|
|
|
|
|
calendar_invalidate_day (calendar, old_focus_row, old_focus_col);
|
|
|
|
|
calendar_invalidate_day (calendar, priv->focus_row,
|
|
|
|
|
priv->focus_col);
|
|
|
|
|
}
|
1998-09-27 18:32:00 +00:00
|
|
|
|
break;
|
2010-09-08 17:35:51 +00:00
|
|
|
|
case GDK_KEY_KP_Right:
|
|
|
|
|
case GDK_KEY_Right:
|
1998-09-27 18:32:00 +00:00
|
|
|
|
return_val = TRUE;
|
2017-08-25 14:43:42 +00:00
|
|
|
|
if (state & GDK_CONTROL_MASK)
|
2011-01-24 02:50:39 +00:00
|
|
|
|
calendar_set_month_next (calendar);
|
1998-09-27 18:32:00 +00:00
|
|
|
|
else
|
2011-01-24 02:50:39 +00:00
|
|
|
|
{
|
|
|
|
|
move_focus (calendar, 1);
|
|
|
|
|
calendar_invalidate_day (calendar, old_focus_row, old_focus_col);
|
|
|
|
|
calendar_invalidate_day (calendar, priv->focus_row,
|
|
|
|
|
priv->focus_col);
|
|
|
|
|
}
|
1998-09-27 18:32:00 +00:00
|
|
|
|
break;
|
2010-09-08 17:35:51 +00:00
|
|
|
|
case GDK_KEY_KP_Up:
|
|
|
|
|
case GDK_KEY_Up:
|
1998-09-27 18:32:00 +00:00
|
|
|
|
return_val = TRUE;
|
2017-08-25 14:43:42 +00:00
|
|
|
|
if (state & GDK_CONTROL_MASK)
|
2011-01-24 02:50:39 +00:00
|
|
|
|
calendar_set_year_prev (calendar);
|
1998-09-27 18:32:00 +00:00
|
|
|
|
else
|
2011-01-24 02:50:39 +00:00
|
|
|
|
{
|
|
|
|
|
if (priv->focus_row > 0)
|
|
|
|
|
priv->focus_row--;
|
2010-08-12 15:14:51 +00:00
|
|
|
|
if (priv->focus_row < 0)
|
|
|
|
|
priv->focus_row = 5;
|
|
|
|
|
if (priv->focus_col < 0)
|
|
|
|
|
priv->focus_col = 6;
|
2011-01-24 02:50:39 +00:00
|
|
|
|
calendar_invalidate_day (calendar, old_focus_row, old_focus_col);
|
|
|
|
|
calendar_invalidate_day (calendar, priv->focus_row,
|
|
|
|
|
priv->focus_col);
|
|
|
|
|
}
|
1998-09-27 18:32:00 +00:00
|
|
|
|
break;
|
2010-09-08 17:35:51 +00:00
|
|
|
|
case GDK_KEY_KP_Down:
|
|
|
|
|
case GDK_KEY_Down:
|
1998-09-27 18:32:00 +00:00
|
|
|
|
return_val = TRUE;
|
2017-08-25 14:43:42 +00:00
|
|
|
|
if (state & GDK_CONTROL_MASK)
|
2011-01-24 02:50:39 +00:00
|
|
|
|
calendar_set_year_next (calendar);
|
1998-09-27 18:32:00 +00:00
|
|
|
|
else
|
2011-01-24 02:50:39 +00:00
|
|
|
|
{
|
|
|
|
|
if (priv->focus_row < 5)
|
|
|
|
|
priv->focus_row++;
|
2010-08-12 15:14:51 +00:00
|
|
|
|
if (priv->focus_col < 0)
|
|
|
|
|
priv->focus_col = 0;
|
2011-01-24 02:50:39 +00:00
|
|
|
|
calendar_invalidate_day (calendar, old_focus_row, old_focus_col);
|
|
|
|
|
calendar_invalidate_day (calendar, priv->focus_row,
|
|
|
|
|
priv->focus_col);
|
|
|
|
|
}
|
1998-09-27 18:32:00 +00:00
|
|
|
|
break;
|
2010-09-08 17:35:51 +00:00
|
|
|
|
case GDK_KEY_KP_Space:
|
|
|
|
|
case GDK_KEY_space:
|
2010-08-12 15:14:51 +00:00
|
|
|
|
row = priv->focus_row;
|
|
|
|
|
col = priv->focus_col;
|
2011-01-24 02:50:39 +00:00
|
|
|
|
|
1998-10-05 03:52:48 +00:00
|
|
|
|
if (row > -1 && col > -1)
|
2011-01-24 02:50:39 +00:00
|
|
|
|
{
|
|
|
|
|
return_val = TRUE;
|
1998-10-05 03:52:48 +00:00
|
|
|
|
|
2010-08-12 15:14:51 +00:00
|
|
|
|
day = priv->day[row][col];
|
2011-01-24 02:50:39 +00:00
|
|
|
|
if (priv->day_month[row][col] == MONTH_PREV)
|
|
|
|
|
calendar_set_month_prev (calendar);
|
|
|
|
|
else if (priv->day_month[row][col] == MONTH_NEXT)
|
|
|
|
|
calendar_set_month_next (calendar);
|
|
|
|
|
|
|
|
|
|
calendar_select_and_focus_day (calendar, day);
|
|
|
|
|
}
|
2020-03-06 07:32:21 +00:00
|
|
|
|
break;
|
2017-10-06 19:19:42 +00:00
|
|
|
|
default:
|
|
|
|
|
break;
|
2011-01-24 02:50:39 +00:00
|
|
|
|
}
|
|
|
|
|
|
1998-09-27 18:32:00 +00:00
|
|
|
|
return return_val;
|
|
|
|
|
}
|
2003-05-08 00:25:51 +00:00
|
|
|
|
|
2018-03-23 15:09:37 +00:00
|
|
|
|
static void
|
2020-02-20 01:51:03 +00:00
|
|
|
|
gtk_calendar_focus_controller_focus (GtkEventController *controller,
|
|
|
|
|
GtkWidget *widget)
|
2018-03-23 15:09:37 +00:00
|
|
|
|
{
|
|
|
|
|
GtkCalendar *calendar = GTK_CALENDAR (widget);
|
|
|
|
|
|
|
|
|
|
calendar_queue_refresh (calendar);
|
2003-05-08 00:25:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
2005-05-11 19:16:19 +00:00
|
|
|
|
|
|
|
|
|
/****************************************
|
|
|
|
|
* Public API *
|
|
|
|
|
****************************************/
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* gtk_calendar_new:
|
2011-01-24 02:50:39 +00:00
|
|
|
|
*
|
|
|
|
|
* Creates a new calendar, with the current date being selected.
|
|
|
|
|
*
|
2014-02-19 23:49:43 +00:00
|
|
|
|
* Returns: a newly #GtkCalendar widget
|
2005-05-11 19:16:19 +00:00
|
|
|
|
**/
|
|
|
|
|
GtkWidget*
|
|
|
|
|
gtk_calendar_new (void)
|
|
|
|
|
{
|
|
|
|
|
return g_object_new (GTK_TYPE_CALENDAR, NULL);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2020-02-05 08:22:21 +00:00
|
|
|
|
* gtk_calendar_select_day:
|
2020-02-11 17:25:44 +00:00
|
|
|
|
* @self: a #GtkCalendar.
|
2020-02-05 08:22:21 +00:00
|
|
|
|
* @date: (transfer none): a #GDateTime representing the day to select
|
2010-06-15 04:00:40 +00:00
|
|
|
|
*
|
2020-02-05 08:22:21 +00:00
|
|
|
|
* Will switch to @date's year and month and select its day.
|
2005-05-11 19:16:19 +00:00
|
|
|
|
**/
|
2010-06-15 04:00:40 +00:00
|
|
|
|
void
|
2020-02-05 08:22:21 +00:00
|
|
|
|
gtk_calendar_select_day (GtkCalendar *self,
|
|
|
|
|
GDateTime *date)
|
2003-08-08 23:01:17 +00:00
|
|
|
|
{
|
2020-02-04 13:38:19 +00:00
|
|
|
|
GtkCalendarPrivate *priv = gtk_calendar_get_instance_private (self);
|
2020-02-13 17:40:20 +00:00
|
|
|
|
GDateTime *today;
|
2020-02-05 08:22:21 +00:00
|
|
|
|
int new_day, new_month, new_year;
|
|
|
|
|
gboolean day_changed, month_changed, year_changed;
|
|
|
|
|
char buffer[255];
|
|
|
|
|
char *str;
|
|
|
|
|
time_t tmp_time;
|
|
|
|
|
struct tm *tm;
|
|
|
|
|
int i;
|
|
|
|
|
int x, y;
|
2020-02-13 17:40:20 +00:00
|
|
|
|
int today_day;
|
2020-02-04 13:38:19 +00:00
|
|
|
|
|
|
|
|
|
g_return_if_fail (GTK_IS_CALENDAR (self));
|
|
|
|
|
g_return_if_fail (date != NULL);
|
2010-08-12 15:14:51 +00:00
|
|
|
|
|
2020-02-05 08:22:21 +00:00
|
|
|
|
day_changed = g_date_time_get_day_of_month (priv->date) != g_date_time_get_day_of_month (date);
|
|
|
|
|
month_changed = g_date_time_get_month (priv->date) != g_date_time_get_month (date);
|
|
|
|
|
year_changed = g_date_time_get_year (priv->date) != g_date_time_get_year (date);
|
2010-06-15 04:00:40 +00:00
|
|
|
|
|
2020-02-05 08:22:21 +00:00
|
|
|
|
if (!day_changed && !month_changed && !year_changed)
|
|
|
|
|
return;
|
2014-06-07 18:07:07 +00:00
|
|
|
|
|
2020-02-05 08:22:21 +00:00
|
|
|
|
new_year = g_date_time_get_year (date);
|
|
|
|
|
new_month = g_date_time_get_month (date);
|
|
|
|
|
new_day = g_date_time_get_day_of_month (date);
|
2010-06-15 04:00:40 +00:00
|
|
|
|
|
2020-02-05 08:22:21 +00:00
|
|
|
|
g_date_time_unref (priv->date);
|
|
|
|
|
priv->date = g_date_time_ref (date);
|
2003-08-08 23:01:17 +00:00
|
|
|
|
|
2020-02-05 08:22:21 +00:00
|
|
|
|
tmp_time = 1; /* Jan 1 1970, 00:00:01 UTC */
|
|
|
|
|
tm = gmtime (&tmp_time);
|
|
|
|
|
tm->tm_year = new_year - 1900;
|
2003-08-08 23:01:17 +00:00
|
|
|
|
|
2020-02-05 08:22:21 +00:00
|
|
|
|
/* Translators: This dictates how the year is displayed in
|
|
|
|
|
* gtkcalendar widget. See strftime() manual for the format.
|
|
|
|
|
* Use only ASCII in the translation.
|
|
|
|
|
*
|
|
|
|
|
* "%Y" is appropriate for most locales.
|
|
|
|
|
*/
|
|
|
|
|
strftime (buffer, sizeof (buffer), C_("calendar year format", "%Y"), tm);
|
|
|
|
|
str = g_locale_to_utf8 (buffer, -1, NULL, NULL, NULL);
|
|
|
|
|
gtk_label_set_label (GTK_LABEL (priv->year_label), str);
|
|
|
|
|
g_free (str);
|
2010-08-12 15:14:51 +00:00
|
|
|
|
|
2020-02-05 08:22:21 +00:00
|
|
|
|
/* Update month */
|
|
|
|
|
|
|
|
|
|
calendar_compute_days (self);
|
|
|
|
|
gtk_stack_set_visible_child_name (GTK_STACK (priv->month_name_stack),
|
|
|
|
|
default_monthname[new_month - 1]);
|
|
|
|
|
|
2020-02-13 17:40:20 +00:00
|
|
|
|
today = g_date_time_new_now_local ();
|
|
|
|
|
|
|
|
|
|
if (g_date_time_get_year (priv->date) == g_date_time_get_year (today) &&
|
|
|
|
|
g_date_time_get_month (priv->date) == g_date_time_get_month (today))
|
|
|
|
|
today_day = g_date_time_get_day_of_month (today);
|
|
|
|
|
else
|
|
|
|
|
today_day = -1;
|
|
|
|
|
|
|
|
|
|
g_date_time_unref (today);
|
|
|
|
|
|
2020-02-05 08:22:21 +00:00
|
|
|
|
/* Update day labels */
|
|
|
|
|
for (y = 0; y < 6; y ++)
|
|
|
|
|
for (x = 0; x < 7; x ++)
|
|
|
|
|
{
|
|
|
|
|
const int day = priv->day[y][x];
|
|
|
|
|
GtkWidget *label = priv->day_number_labels[y][x];
|
|
|
|
|
/* Translators: this defines whether the day numbers should use
|
|
|
|
|
* localized digits or the ones used in English (0123...).
|
|
|
|
|
*
|
|
|
|
|
* Translate to "%Id" if you want to use localized digits, or
|
|
|
|
|
* 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
|
|
|
|
|
* too.
|
|
|
|
|
*/
|
|
|
|
|
g_snprintf (buffer, sizeof (buffer), C_("calendar:day:digits", "%d"), day);
|
2020-02-04 13:38:19 +00:00
|
|
|
|
|
2020-02-05 08:22:21 +00:00
|
|
|
|
gtk_label_set_label (GTK_LABEL (label), buffer);
|
2010-08-12 15:14:51 +00:00
|
|
|
|
|
2020-02-05 08:22:21 +00:00
|
|
|
|
if (priv->day_month[y][x] == MONTH_PREV ||
|
|
|
|
|
priv->day_month[y][x] == MONTH_NEXT)
|
2020-02-06 16:32:26 +00:00
|
|
|
|
gtk_widget_add_css_class (label, "other-month");
|
2020-02-05 08:22:21 +00:00
|
|
|
|
else
|
2020-02-06 16:32:26 +00:00
|
|
|
|
gtk_widget_remove_css_class (label, "other-month");
|
2020-02-05 08:22:21 +00:00
|
|
|
|
|
|
|
|
|
if (priv->marked_date[day-1])
|
|
|
|
|
gtk_widget_set_state_flags (label, GTK_STATE_FLAG_CHECKED, FALSE);
|
|
|
|
|
else
|
|
|
|
|
gtk_widget_unset_state_flags (label, GTK_STATE_FLAG_CHECKED);
|
|
|
|
|
|
|
|
|
|
if (new_day == day &&
|
|
|
|
|
priv->day_month[y][x] == MONTH_CURRENT)
|
|
|
|
|
gtk_widget_set_state_flags (label, GTK_STATE_FLAG_SELECTED, FALSE);
|
|
|
|
|
else
|
|
|
|
|
gtk_widget_unset_state_flags (label, GTK_STATE_FLAG_SELECTED);
|
2020-02-13 17:40:20 +00:00
|
|
|
|
|
|
|
|
|
if (day == today_day)
|
|
|
|
|
gtk_widget_add_css_class (label, "today");
|
|
|
|
|
else
|
|
|
|
|
gtk_widget_remove_css_class (label, "today");
|
2020-02-05 08:22:21 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Update week number labels.
|
|
|
|
|
* We simply get the week number of priv->date and add the others.
|
|
|
|
|
* simple. */
|
|
|
|
|
for (i = 0; i < 6; i ++)
|
2003-08-08 23:01:17 +00:00
|
|
|
|
{
|
2020-02-05 08:22:21 +00:00
|
|
|
|
int year = new_year;
|
|
|
|
|
int month, week;
|
2011-01-24 02:50:39 +00:00
|
|
|
|
|
2020-02-05 08:22:21 +00:00
|
|
|
|
month = new_month + priv->day_month[i][6] - MONTH_CURRENT;
|
2020-02-04 13:38:19 +00:00
|
|
|
|
|
2020-02-05 08:22:21 +00:00
|
|
|
|
if (month < 1)
|
|
|
|
|
{
|
|
|
|
|
month += 12;
|
|
|
|
|
year -= 1;
|
|
|
|
|
}
|
|
|
|
|
else if (month > 12)
|
|
|
|
|
{
|
|
|
|
|
month -= 12;
|
|
|
|
|
year += 1;
|
|
|
|
|
}
|
2011-01-24 02:50:39 +00:00
|
|
|
|
|
2020-02-05 08:22:21 +00:00
|
|
|
|
week = week_of_year (year, month, priv->day[i][6]);
|
|
|
|
|
|
|
|
|
|
/* Translators: this defines whether the week numbers should use
|
|
|
|
|
* localized digits or the ones used in English (0123...).
|
|
|
|
|
*
|
|
|
|
|
* Translate to "%Id" if you want to use localized digits, or
|
|
|
|
|
* 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
|
|
|
|
|
* too. */
|
|
|
|
|
g_snprintf (buffer, sizeof (buffer), C_("calendar:week:digits", "%d"), week);
|
|
|
|
|
|
|
|
|
|
gtk_label_set_label (GTK_LABEL (priv->week_number_labels[i]), buffer);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (day_changed)
|
|
|
|
|
{
|
|
|
|
|
g_object_notify (G_OBJECT (self), "day");
|
2020-02-04 13:38:19 +00:00
|
|
|
|
g_signal_emit (self, gtk_calendar_signals[DAY_SELECTED_SIGNAL], 0);
|
2005-05-11 19:16:19 +00:00
|
|
|
|
}
|
2020-02-05 08:22:21 +00:00
|
|
|
|
|
|
|
|
|
if (month_changed)
|
|
|
|
|
g_object_notify (G_OBJECT (self), "month");
|
|
|
|
|
|
|
|
|
|
if (year_changed)
|
|
|
|
|
g_object_notify (G_OBJECT (self), "year");
|
|
|
|
|
|
2003-08-08 23:01:17 +00:00
|
|
|
|
}
|
|
|
|
|
|
2005-05-11 19:16:19 +00:00
|
|
|
|
/**
|
|
|
|
|
* gtk_calendar_clear_marks:
|
|
|
|
|
* @calendar: a #GtkCalendar
|
2011-01-24 02:50:39 +00:00
|
|
|
|
*
|
2005-05-11 19:16:19 +00:00
|
|
|
|
* Remove all visual markers.
|
|
|
|
|
**/
|
|
|
|
|
void
|
|
|
|
|
gtk_calendar_clear_marks (GtkCalendar *calendar)
|
2003-08-08 23:01:17 +00:00
|
|
|
|
{
|
2019-05-26 23:20:26 +00:00
|
|
|
|
GtkCalendarPrivate *priv = gtk_calendar_get_instance_private (calendar);
|
2005-05-11 19:16:19 +00:00
|
|
|
|
guint day;
|
2010-08-12 15:14:51 +00:00
|
|
|
|
|
2005-05-11 19:16:19 +00:00
|
|
|
|
g_return_if_fail (GTK_IS_CALENDAR (calendar));
|
2010-08-12 15:14:51 +00:00
|
|
|
|
|
2005-05-11 19:16:19 +00:00
|
|
|
|
for (day = 0; day < 31; day++)
|
2003-08-08 23:01:17 +00:00
|
|
|
|
{
|
2010-08-12 15:14:51 +00:00
|
|
|
|
priv->marked_date[day] = FALSE;
|
2003-08-08 23:01:17 +00:00
|
|
|
|
}
|
|
|
|
|
|
2010-08-12 15:14:51 +00:00
|
|
|
|
priv->num_marked_dates = 0;
|
2007-12-28 09:26:38 +00:00
|
|
|
|
calendar_queue_refresh (calendar);
|
2003-08-08 23:01:17 +00:00
|
|
|
|
}
|
|
|
|
|
|
2005-05-11 19:16:19 +00:00
|
|
|
|
/**
|
|
|
|
|
* gtk_calendar_mark_day:
|
2010-06-15 04:00:40 +00:00
|
|
|
|
* @calendar: a #GtkCalendar
|
2005-05-11 19:16:19 +00:00
|
|
|
|
* @day: the day number to mark between 1 and 31.
|
2010-06-15 04:00:40 +00:00
|
|
|
|
*
|
2005-05-11 19:16:19 +00:00
|
|
|
|
* Places a visual marker on a particular day.
|
2010-06-15 04:00:40 +00:00
|
|
|
|
*/
|
|
|
|
|
void
|
2005-05-11 19:16:19 +00:00
|
|
|
|
gtk_calendar_mark_day (GtkCalendar *calendar,
|
2011-01-24 02:50:39 +00:00
|
|
|
|
guint day)
|
2003-08-08 23:01:17 +00:00
|
|
|
|
{
|
2019-05-26 23:20:26 +00:00
|
|
|
|
GtkCalendarPrivate *priv = gtk_calendar_get_instance_private (calendar);
|
2010-08-12 15:14:51 +00:00
|
|
|
|
|
2010-06-15 04:00:40 +00:00
|
|
|
|
g_return_if_fail (GTK_IS_CALENDAR (calendar));
|
|
|
|
|
|
2010-08-12 15:14:51 +00:00
|
|
|
|
if (day >= 1 && day <= 31 && !priv->marked_date[day-1])
|
2003-08-08 23:01:17 +00:00
|
|
|
|
{
|
2010-08-12 15:14:51 +00:00
|
|
|
|
priv->marked_date[day - 1] = TRUE;
|
|
|
|
|
priv->num_marked_dates++;
|
2005-05-11 19:16:19 +00:00
|
|
|
|
calendar_invalidate_day_num (calendar, day);
|
2003-08-08 23:01:17 +00:00
|
|
|
|
}
|
2005-05-11 19:16:19 +00:00
|
|
|
|
}
|
2003-08-08 23:01:17 +00:00
|
|
|
|
|
2010-08-29 17:14:24 +00:00
|
|
|
|
/**
|
|
|
|
|
* gtk_calendar_get_day_is_marked:
|
|
|
|
|
* @calendar: a #GtkCalendar
|
|
|
|
|
* @day: the day number between 1 and 31.
|
|
|
|
|
*
|
|
|
|
|
* Returns if the @day of the @calendar is already marked.
|
|
|
|
|
*
|
|
|
|
|
* Returns: whether the day is marked.
|
|
|
|
|
*/
|
|
|
|
|
gboolean
|
|
|
|
|
gtk_calendar_get_day_is_marked (GtkCalendar *calendar,
|
|
|
|
|
guint day)
|
|
|
|
|
{
|
2019-05-26 23:20:26 +00:00
|
|
|
|
GtkCalendarPrivate *priv = gtk_calendar_get_instance_private (calendar);
|
2010-08-29 17:14:24 +00:00
|
|
|
|
|
|
|
|
|
g_return_val_if_fail (GTK_IS_CALENDAR (calendar), FALSE);
|
|
|
|
|
|
|
|
|
|
if (day >= 1 && day <= 31)
|
|
|
|
|
return priv->marked_date[day - 1];
|
|
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
2005-05-11 19:16:19 +00:00
|
|
|
|
/**
|
|
|
|
|
* gtk_calendar_unmark_day:
|
|
|
|
|
* @calendar: a #GtkCalendar.
|
|
|
|
|
* @day: the day number to unmark between 1 and 31.
|
2010-06-15 04:00:40 +00:00
|
|
|
|
*
|
2005-05-11 19:16:19 +00:00
|
|
|
|
* Removes the visual marker from a particular day.
|
2010-06-15 04:00:40 +00:00
|
|
|
|
*/
|
|
|
|
|
void
|
2005-05-11 19:16:19 +00:00
|
|
|
|
gtk_calendar_unmark_day (GtkCalendar *calendar,
|
2011-01-24 02:50:39 +00:00
|
|
|
|
guint day)
|
2005-05-11 19:16:19 +00:00
|
|
|
|
{
|
2019-05-26 23:20:26 +00:00
|
|
|
|
GtkCalendarPrivate *priv = gtk_calendar_get_instance_private (calendar);
|
2010-08-12 15:14:51 +00:00
|
|
|
|
|
2010-06-15 04:00:40 +00:00
|
|
|
|
g_return_if_fail (GTK_IS_CALENDAR (calendar));
|
|
|
|
|
|
2010-08-12 15:14:51 +00:00
|
|
|
|
if (day >= 1 && day <= 31 && priv->marked_date[day-1])
|
2003-08-08 23:01:17 +00:00
|
|
|
|
{
|
2010-08-12 15:14:51 +00:00
|
|
|
|
priv->marked_date[day - 1] = FALSE;
|
|
|
|
|
priv->num_marked_dates--;
|
2005-05-11 19:16:19 +00:00
|
|
|
|
calendar_invalidate_day_num (calendar, day);
|
2003-08-08 23:01:17 +00:00
|
|
|
|
}
|
2005-05-11 19:16:19 +00:00
|
|
|
|
}
|
2003-08-08 23:01:17 +00:00
|
|
|
|
|
2005-05-11 19:16:19 +00:00
|
|
|
|
/**
|
|
|
|
|
* gtk_calendar_get_date:
|
2020-02-11 17:25:44 +00:00
|
|
|
|
* @self: a #GtkCalendar
|
2011-01-04 16:44:09 +00:00
|
|
|
|
*
|
2020-02-04 14:20:39 +00:00
|
|
|
|
* Returns: (transfer full): A #GDateTime representing the shown
|
|
|
|
|
* year, month and the selected day, in the local time zone.
|
2011-01-04 16:44:09 +00:00
|
|
|
|
*/
|
2020-02-04 14:20:39 +00:00
|
|
|
|
GDateTime *
|
|
|
|
|
gtk_calendar_get_date (GtkCalendar *self)
|
2005-05-11 19:16:19 +00:00
|
|
|
|
{
|
2020-02-04 14:20:39 +00:00
|
|
|
|
GtkCalendarPrivate *priv = gtk_calendar_get_instance_private (self);
|
2010-08-12 15:14:51 +00:00
|
|
|
|
|
2020-02-04 14:20:39 +00:00
|
|
|
|
g_return_val_if_fail (GTK_IS_CALENDAR (self), NULL);
|
2010-08-12 15:14:51 +00:00
|
|
|
|
|
2020-02-05 08:22:21 +00:00
|
|
|
|
return g_date_time_ref (priv->date);
|
2005-05-11 19:16:19 +00:00
|
|
|
|
}
|
2020-02-04 11:19:08 +00:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* gtk_calendar_set_show_week_numbers
|
|
|
|
|
* @self: a #GtkCalendar
|
|
|
|
|
* @value: Whether to show week numbers on the left of the days
|
|
|
|
|
*
|
|
|
|
|
* Sets whether week numbers are shown in the calendar.
|
|
|
|
|
*/
|
|
|
|
|
void
|
|
|
|
|
gtk_calendar_set_show_week_numbers (GtkCalendar *self,
|
|
|
|
|
gboolean value)
|
|
|
|
|
{
|
|
|
|
|
GtkCalendarPrivate *priv = gtk_calendar_get_instance_private (self);
|
|
|
|
|
|
|
|
|
|
g_return_if_fail (GTK_IS_CALENDAR (self));
|
|
|
|
|
|
|
|
|
|
if (value != priv->show_week_numbers)
|
|
|
|
|
{
|
2020-02-04 13:03:17 +00:00
|
|
|
|
int i;
|
|
|
|
|
|
2020-02-04 11:19:08 +00:00
|
|
|
|
priv->show_week_numbers = value;
|
|
|
|
|
|
2020-02-04 13:03:17 +00:00
|
|
|
|
for (i = 0; i < 6; i ++)
|
|
|
|
|
gtk_widget_set_visible (priv->week_number_labels[i], value);
|
2020-02-04 11:19:08 +00:00
|
|
|
|
|
|
|
|
|
g_object_notify (G_OBJECT (self), "show-week-numbers");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* gtk_calendar_get_show_week_numbers:
|
|
|
|
|
* @self: a #GtkCalendar
|
|
|
|
|
*
|
|
|
|
|
* Returns: Whether @self is showing week numbers right now,
|
|
|
|
|
* i.e. the value of the #GtkCalendar:show-week-numbers property.
|
|
|
|
|
*/
|
|
|
|
|
gboolean
|
|
|
|
|
gtk_calendar_get_show_week_numbers (GtkCalendar *self)
|
|
|
|
|
{
|
|
|
|
|
GtkCalendarPrivate *priv = gtk_calendar_get_instance_private (self);
|
|
|
|
|
|
|
|
|
|
g_return_val_if_fail (GTK_IS_CALENDAR (self), FALSE);
|
|
|
|
|
|
|
|
|
|
return priv->show_week_numbers;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* gtk_calendar_set_show_heading:
|
|
|
|
|
* @self: a #GtkCalendar
|
|
|
|
|
* @value: Whether to show the heading in the calendar,
|
|
|
|
|
* containing the current year and month as well as
|
|
|
|
|
* buttons for changing both.
|
|
|
|
|
*/
|
|
|
|
|
void
|
|
|
|
|
gtk_calendar_set_show_heading (GtkCalendar *self,
|
|
|
|
|
gboolean value)
|
|
|
|
|
{
|
|
|
|
|
GtkCalendarPrivate *priv = gtk_calendar_get_instance_private (self);
|
|
|
|
|
|
|
|
|
|
g_return_if_fail (GTK_IS_CALENDAR (self));
|
|
|
|
|
|
|
|
|
|
if (value != priv->show_heading)
|
|
|
|
|
{
|
|
|
|
|
priv->show_heading = value;
|
|
|
|
|
|
|
|
|
|
gtk_widget_set_visible (priv->header_box, value);
|
|
|
|
|
|
|
|
|
|
g_object_notify (G_OBJECT (self), "show-heading");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* gtk_calendar_get_show_heading:
|
|
|
|
|
* @self: a #GtkCalendar
|
|
|
|
|
*
|
|
|
|
|
* Returns: Whether @self is currently showing the heading,
|
|
|
|
|
* i.e. the value of the #GtkCalendar:show-heading property.
|
|
|
|
|
*/
|
|
|
|
|
gboolean
|
|
|
|
|
gtk_calendar_get_show_heading (GtkCalendar *self)
|
|
|
|
|
{
|
|
|
|
|
GtkCalendarPrivate *priv = gtk_calendar_get_instance_private (self);
|
|
|
|
|
|
|
|
|
|
g_return_val_if_fail (GTK_IS_CALENDAR (self), FALSE);
|
|
|
|
|
|
|
|
|
|
return priv->show_heading;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* gtk_calendar_set_show_day_names:
|
|
|
|
|
* @self: a #GtkCalendar
|
|
|
|
|
* @value: Whether to show week day names above the
|
|
|
|
|
* day numbers
|
|
|
|
|
*/
|
|
|
|
|
void
|
|
|
|
|
gtk_calendar_set_show_day_names (GtkCalendar *self,
|
|
|
|
|
gboolean value)
|
|
|
|
|
{
|
|
|
|
|
GtkCalendarPrivate *priv = gtk_calendar_get_instance_private (self);
|
|
|
|
|
|
|
|
|
|
g_return_if_fail (GTK_IS_CALENDAR (self));
|
|
|
|
|
|
|
|
|
|
if (value != priv->show_day_names)
|
|
|
|
|
{
|
2020-02-04 13:03:17 +00:00
|
|
|
|
int i;
|
|
|
|
|
|
2020-02-04 11:19:08 +00:00
|
|
|
|
priv->show_day_names = value;
|
|
|
|
|
|
2020-02-04 13:03:17 +00:00
|
|
|
|
for (i = 0; i < 7; i ++)
|
|
|
|
|
gtk_widget_set_visible (priv->day_name_labels[i], value);
|
2020-02-04 11:19:08 +00:00
|
|
|
|
|
|
|
|
|
g_object_notify (G_OBJECT (self), "show-day-names");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* gtk_calendar_get_day_names:
|
|
|
|
|
* @self: a #GtkCalendar
|
|
|
|
|
*
|
|
|
|
|
* Returns: Whether @self is currently showing the names
|
|
|
|
|
* of the week days above the day numbers, i.e. the value
|
|
|
|
|
* of the #GtkCalendar:show-day-names property.
|
|
|
|
|
*/
|
|
|
|
|
gboolean
|
|
|
|
|
gtk_calendar_get_show_day_names (GtkCalendar *self)
|
|
|
|
|
{
|
|
|
|
|
GtkCalendarPrivate *priv = gtk_calendar_get_instance_private (self);
|
|
|
|
|
|
|
|
|
|
g_return_val_if_fail (GTK_IS_CALENDAR (self), FALSE);
|
|
|
|
|
|
|
|
|
|
return priv->show_day_names;
|
|
|
|
|
}
|