#include <goocanvas.h>
#include "gtkcalex.h"
+#include "gtkcalexviewday.h"
+#include "gtkcalexviewweek.h"
+#include "gtkcalexviewmonth.h"
enum
{
static void gtk_calex_size_allocate (GtkWidget *widget,
GtkAllocation *allocation);
-static void gtk_calex_draw_day (GtkCalEx *gtk_calex);
+static void gtk_calex_clean_canvas (GtkCalEx *gtk_calex);
#define GTK_CALEX_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), TYPE_GTK_CALEX, GtkCalExPrivate))
GtkCalExViewType view_type;
GDate *date;
+
+ GObject *view;
};
G_DEFINE_TYPE (GtkCalEx, gtk_calex, GTK_TYPE_BIN)
GTK_WIDGET_UNSET_FLAGS (gtk_calex, GTK_NO_WINDOW);
priv->scrolledw = gtk_scrolled_window_new (NULL, NULL);
+ gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (priv->scrolledw),
+ GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
gtk_container_add (GTK_CONTAINER (gtk_calex), priv->scrolledw);
priv->goo_canvas = goo_canvas_new ();
priv->goo_canvas_root = goo_canvas_get_root_item (GOO_CANVAS (priv->goo_canvas));
- priv->view_type = GTK_CALEX_VIEW_TYPE_DAY;
-
priv->date = g_date_new ();
g_get_current_time (&tval);
g_date_set_time_val (priv->date, &tval);
- gtk_calex_draw_day (gtk_calex);
+ priv->view = NULL;
+ priv->view_type = -1;
+ gtk_calex_set_view_type (gtk_calex, GTK_CALEX_VIEW_TYPE_DAY);
}
static void
GtkCalExPrivate *priv = GTK_CALEX_GET_PRIVATE (calex);
+ if (priv->view_type == type) return;
+
+ gtk_calex_clean_canvas (calex);
+
priv->view_type = type;
+
+ switch (priv->view_type)
+ {
+ case GTK_CALEX_VIEW_TYPE_DAY:
+ if (priv->view != NULL)
+ {
+ g_object_unref (priv->view);
+ priv->view = NULL;
+ }
+ GtkCalExViewDay *vd = gtk_calex_view_day_new (priv->goo_canvas_root, priv->date);
+ priv->view = G_OBJECT (vd);
+ break;
+
+ case GTK_CALEX_VIEW_TYPE_WORK_WEEK:
+ if (priv->view != NULL)
+ {
+ g_object_unref (priv->view);
+ priv->view = NULL;
+ }
+ GtkCalExViewDay *vww = gtk_calex_view_day_new (priv->goo_canvas_root, priv->date);
+ priv->view = G_OBJECT (vww);
+ break;
+
+ case GTK_CALEX_VIEW_TYPE_WEEK:
+ if (priv->view != NULL)
+ {
+ g_object_unref (priv->view);
+ priv->view = NULL;
+ }
+ GtkCalExViewDay *vw = gtk_calex_view_day_new (priv->goo_canvas_root, priv->date);
+ priv->view = G_OBJECT (vw);
+ break;
+
+ case GTK_CALEX_VIEW_TYPE_MONTH:
+ if (priv->view != NULL)
+ {
+ g_object_unref (priv->view);
+ priv->view = NULL;
+ }
+ GtkCalExViewDay *vm = gtk_calex_view_day_new (priv->goo_canvas_root, priv->date);
+ priv->view = G_OBJECT (vm);
+ break;
+
+ case GTK_CALEX_VIEW_TYPE_LIST:
+ if (priv->view != NULL)
+ {
+ g_object_unref (priv->view);
+ priv->view = NULL;
+ }
+ GtkCalExViewDay *vl = gtk_calex_view_day_new (priv->goo_canvas_root, priv->date);
+ priv->view = G_OBJECT (vl);
+ break;
+
+ default:
+ g_warning ("View type «%d» not available.", priv->view_type);
+ break;
+ }
}
GDate
static void
gtk_calex_size_request (GtkWidget *widget,
- GtkRequisition *requisition)
+ GtkRequisition *requisition)
{
GtkCalEx *gtkcalex;
GtkBin *bin;
GtkRequisition child_requisition;
+ guint border_width;
+
g_return_if_fail (IS_GTK_CALEX (widget));
g_return_if_fail (requisition != NULL);
requisition->height += child_requisition.height;
}
- requisition->width += GTK_CONTAINER (widget)->border_width * 2;
- requisition->height += GTK_CONTAINER (widget)->border_width * 2;
+ border_width = gtk_container_get_border_width (GTK_CONTAINER (widget));
+ requisition->width += border_width * 2;
+ requisition->height += border_width * 2;
}
static void
gtk_calex_size_allocate (GtkWidget *widget,
- GtkAllocation *allocation)
+ GtkAllocation *allocation)
{
GtkCalEx *gtkcalex;
GtkCalExPrivate *priv;
GtkAllocation relative_allocation;
GtkAllocation child_allocation;
+ guint border_width;
+
g_return_if_fail (IS_GTK_CALEX (widget));
g_return_if_fail (allocation != NULL);
priv = GTK_CALEX_GET_PRIVATE (gtkcalex);
- widget->allocation = *allocation;
+ gtk_widget_set_allocation (widget, allocation);
- relative_allocation.x = GTK_CONTAINER (widget)->border_width;
- relative_allocation.y = GTK_CONTAINER (widget)->border_width;
+ border_width = gtk_container_get_border_width (GTK_CONTAINER (widget));
+ relative_allocation.x = border_width;
+ relative_allocation.y = border_width;
relative_allocation.width = MAX (1, (gint)widget->allocation.width - relative_allocation.x * 2);
relative_allocation.height = MAX (1, (gint)widget->allocation.height - relative_allocation.y * 2);
}
static void
-gtk_calex_draw_day (GtkCalEx *gtk_calex)
+gtk_calex_clean_canvas (GtkCalEx *gtk_calex)
{
- guint hour;
+ guint children;
+ guint i;
g_return_if_fail (IS_GTK_CALEX (gtk_calex));
GtkCalExPrivate *priv = GTK_CALEX_GET_PRIVATE (gtk_calex);
- for (hour = 0; hour < 24; hour++)
+ children = goo_canvas_item_get_n_children (priv->goo_canvas_root);
+ for (i = 0; i < children; i++)
{
- goo_canvas_text_new (priv->goo_canvas_root, g_strdup_printf ("%d", hour),
- 0, hour * 40, 50,
- GTK_ANCHOR_NORTH_WEST,
- "font", "Sans 24",
- NULL);
- goo_canvas_text_new (priv->goo_canvas_root, "00",
- 25, hour * 40, 25,
- GTK_ANCHOR_NORTH_WEST,
- "font", "Sans 12",
- NULL);
- goo_canvas_polyline_new_line (priv->goo_canvas_root, 0, hour * 40, 50, hour * 40,
- "stroke-color", "black",
- NULL);
- goo_canvas_rect_new (priv->goo_canvas_root, 55, hour * 40, 400, 20,
- "line-width", 1.0,
- "stroke-color", "black",
- "fill-color", "yellow",
- NULL);
- goo_canvas_polyline_new_line (priv->goo_canvas_root, 25, hour * 40 + 20, 50, hour * 40 + 20,
- "stroke-color", "black",
- NULL);
- goo_canvas_rect_new (priv->goo_canvas_root, 55, hour * 40 + 20, 400, 20,
- "line-width", 1.0,
- "stroke-color", "black",
- "fill-color", "yellow",
- NULL);
+ goo_canvas_item_remove (goo_canvas_item_get_child (priv->goo_canvas_root, i));
}
}
GTK_CALEX_VIEW_TYPE_WORK_WEEK,
GTK_CALEX_VIEW_TYPE_WEEK,
GTK_CALEX_VIEW_TYPE_MONTH,
- GTK_CALEX_VIEW_LIST
+ GTK_CALEX_VIEW_TYPE_LIST
} GtkCalExViewType;
GtkCalExViewType gtk_calex_get_view_type (GtkCalEx *calex);
#include <config.h>
#endif
-#include <goocanvas.h>
-
#include "gtkcalexviewday.h"
enum
GValue *value,
GParamSpec *pspec);
+static void gtk_calex_view_day_draw (GtkCalExViewDay *gtk_calex_view_day);
+
#define GTK_CALEX_VIEW_DAY_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), TYPE_GTK_CALEX_VIEW_DAY, GtkCalExViewDayPrivate))
typedef struct _GtkCalExViewDayPrivate GtkCalExViewDayPrivate;
struct _GtkCalExViewDayPrivate
{
- gpointer foo;
+ GooCanvasItem *goo_canvas_root;
+ GDate *date;
};
G_DEFINE_TYPE (GtkCalExViewDay, gtk_calex_view_day, G_TYPE_OBJECT)
* Returns: the newly created #GtkCalExViewDay object.
*/
GtkCalExViewDay
-*gtk_calex_view_day_new ()
+*gtk_calex_view_day_new (GooCanvasItem *root, GDate *date)
{
GtkCalExViewDay *gtk_calex_view_day = GTK_CALEX_VIEW_DAY (g_object_new (gtk_calex_view_day_get_type (), NULL));
+ GtkCalExViewDayPrivate *priv = GTK_CALEX_VIEW_DAY_GET_PRIVATE (gtk_calex_view_day);
+
+ priv->goo_canvas_root = root;
+ priv->date = date;
+
+ gtk_calex_view_day_draw (gtk_calex_view_day);
+
return gtk_calex_view_day;
}
+
+static void
+gtk_calex_view_day_draw (GtkCalExViewDay *gtk_calex_view_day)
+{
+ guint hour;
+
+ g_return_if_fail (IS_GTK_CALEX_VIEW_DAY (gtk_calex_view_day));
+
+ GtkCalExViewDayPrivate *priv = GTK_CALEX_VIEW_DAY_GET_PRIVATE (gtk_calex_view_day);
+
+ for (hour = 0; hour < 24; hour++)
+ {
+ goo_canvas_text_new (priv->goo_canvas_root, g_strdup_printf ("%d", hour),
+ 0, hour * 40, 50,
+ GTK_ANCHOR_NORTH_WEST,
+ "font", "Sans 24",
+ NULL);
+ goo_canvas_text_new (priv->goo_canvas_root, "00",
+ 25, hour * 40, 25,
+ GTK_ANCHOR_NORTH_WEST,
+ "font", "Sans 12",
+ NULL);
+ goo_canvas_polyline_new_line (priv->goo_canvas_root, 0, hour * 40, 50, hour * 40,
+ "stroke-color", "black",
+ NULL);
+ goo_canvas_rect_new (priv->goo_canvas_root, 55, hour * 40, 400, 20,
+ "line-width", 1.0,
+ "stroke-color", "black",
+ "fill-color", "yellow",
+ NULL);
+ goo_canvas_polyline_new_line (priv->goo_canvas_root, 25, hour * 40 + 20, 50, hour * 40 + 20,
+ "stroke-color", "black",
+ NULL);
+ goo_canvas_rect_new (priv->goo_canvas_root, 55, hour * 40 + 20, 400, 20,
+ "line-width", 1.0,
+ "stroke-color", "black",
+ "fill-color", "yellow",
+ NULL);
+ }
+}
#include <glib.h>
#include <glib-object.h>
+#include <goocanvas.h>
+
G_BEGIN_DECLS
GType gtk_calex_view_day_get_type (void) G_GNUC_CONST;
-GtkCalExViewDay *gtk_calex_view_day_new (void);
+GtkCalExViewDay *gtk_calex_view_day_new (GooCanvasItem *root, GDate *date);
G_END_DECLS
#include <libgtkcalendarex.h>
+GtkWidget *calex;
+
+G_MODULE_EXPORT void
+on_tbtn_view_type_day_toggled (GtkToggleToolButton *toggle_tool_button,
+ gpointer user_data)
+{
+ gtk_calex_set_view_type (GTK_CALEX (calex), GTK_CALEX_VIEW_TYPE_DAY);
+}
+
+G_MODULE_EXPORT void
+on_tbtn_view_type_wweek_toggled (GtkToggleToolButton *toggle_tool_button,
+ gpointer user_data)
+{
+ gtk_calex_set_view_type (GTK_CALEX (calex), GTK_CALEX_VIEW_TYPE_WORK_WEEK);
+}
+
+G_MODULE_EXPORT void
+on_tbtn_view_type_week_toggled (GtkToggleToolButton *toggle_tool_button,
+ gpointer user_data)
+{
+ gtk_calex_set_view_type (GTK_CALEX (calex), GTK_CALEX_VIEW_TYPE_WEEK);
+}
+
+G_MODULE_EXPORT void
+on_tbtn_view_type_month_toggled (GtkToggleToolButton *toggle_tool_button,
+ gpointer user_data)
+{
+ gtk_calex_set_view_type (GTK_CALEX (calex), GTK_CALEX_VIEW_TYPE_MONTH);
+}
+
+G_MODULE_EXPORT void
+on_tbtn_view_type_list_toggled (GtkToggleToolButton *toggle_tool_button,
+ gpointer user_data)
+{
+ gtk_calex_set_view_type (GTK_CALEX (calex), GTK_CALEX_VIEW_TYPE_LIST);
+}
+
int
main (int argc, char **argv)
{
GtkBuilder *gtkbuilder;
GError *error;
GtkWidget *w;
- GtkWidget *calex;
+ GtkWidget *vbox;
gtk_init (&argc, &argv);
}
w = GTK_WIDGET (gtk_builder_get_object (gtkbuilder, "window1"));
+ vbox = GTK_WIDGET (gtk_builder_get_object (gtkbuilder, "vbox1"));
calex = gtk_calex_new ();
- gtk_container_add (GTK_CONTAINER (w), calex);
+ gtk_box_pack_start (GTK_BOX (vbox), calex, TRUE, TRUE, 0);
gtk_builder_connect_signals (gtkbuilder, NULL);
<property name="destroy_with_parent">True</property>
<signal name="delete_event" handler="gtk_main_quit"/>
<child>
- <placeholder/>
+ <object class="GtkVBox" id="vbox1">
+ <property name="visible">True</property>
+ <property name="orientation">vertical</property>
+ <child>
+ <object class="GtkToolbar" id="toolbar1">
+ <property name="visible">True</property>
+ <child>
+ <object class="GtkRadioToolButton" id="toolbutton1">
+ <property name="visible">True</property>
+ <property name="label" translatable="yes">Day</property>
+ <property name="use_underline">True</property>
+ <signal name="toggled" handler="on_tbtn_view_type_day_toggled"/>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="homogeneous">True</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkRadioToolButton" id="toolbutton2">
+ <property name="visible">True</property>
+ <property name="label" translatable="yes">Working week</property>
+ <property name="use_underline">True</property>
+ <property name="group">toolbutton1</property>
+ <signal name="toggled" handler="on_tbtn_view_type_wweek_toggled"/>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="homogeneous">True</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkRadioToolButton" id="toolbutton3">
+ <property name="visible">True</property>
+ <property name="label" translatable="yes">Week</property>
+ <property name="use_underline">True</property>
+ <property name="group">toolbutton1</property>
+ <signal name="toggled" handler="on_tbtn_view_type_week_toggled"/>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="homogeneous">True</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkRadioToolButton" id="toolbutton4">
+ <property name="visible">True</property>
+ <property name="label" translatable="yes">Month</property>
+ <property name="use_underline">True</property>
+ <property name="group">toolbutton1</property>
+ <signal name="toggled" handler="on_tbtn_view_type_month_toggled"/>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="homogeneous">True</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkRadioToolButton" id="toolbutton5">
+ <property name="visible">True</property>
+ <property name="label" translatable="yes">List</property>
+ <property name="use_underline">True</property>
+ <property name="active">True</property>
+ <property name="group">toolbutton1</property>
+ <signal name="toggled" handler="on_tbtn_view_type_list_toggled"/>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="homogeneous">True</property>
+ </packing>
+ </child>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="position">0</property>
+ </packing>
+ </child>
+ <child>
+ <placeholder/>
+ </child>
+ </object>
</child>
</object>
</interface>