aboutsummaryrefslogtreecommitdiffstats
path: root/calendar/year-view.c
diff options
context:
space:
mode:
authorFederico Mena Quintero <federico@nuclecu.unam.mx>1998-10-01 09:32:47 +0800
committerArturo Espinosa <unammx@src.gnome.org>1998-10-01 09:32:47 +0800
commit7dae771114a7121f78f368f07f5e3adc69651c17 (patch)
treed894c1f4f505e2638ff0b7998a085f4567c755b4 /calendar/year-view.c
parentd1769d5646e9fef3c6de607f9f884b02dd954844 (diff)
downloadgsoc2013-evolution-7dae771114a7121f78f368f07f5e3adc69651c17.tar.gz
gsoc2013-evolution-7dae771114a7121f78f368f07f5e3adc69651c17.tar.zst
gsoc2013-evolution-7dae771114a7121f78f368f07f5e3adc69651c17.zip
Colorify the month item and prepare it for prelighting here.
1998-09-30 Federico Mena Quintero <federico@nuclecu.unam.mx> * goto.c (create_days): Colorify the month item and prepare it for prelighting here. * main.c (color_props): Changed the default colors to something not dull. * year-view.c (compute_min_size): New function to compute the minimum size of the year view properly. (year_view_size_request): Added two new fields to the year view structure that contain the minimum size. Return this in the size_request method. (year_view_new): Call compute_min_size to save the minimum size for later use. (idle_handler): Make it resize the items correctly. * gnome-month-item.c (gnome_month_item_set_arg): Reshape when necessary. This is needed becaues we now actually calculate a minimum size for the month item based on the font sizes and paddings. (check_heading_sizes): New function to calculate a minimum size based on the headings' dimensions. (check_day_sizes): New function to calculate a minimum size based on the day number labels' dimensions. (check_sizes): New function that computes a minimum size for the month item. (reshape): Now calls check_sizes() to ensure a minimum size for the month item. svn path=/trunk/; revision=419
Diffstat (limited to 'calendar/year-view.c')
-rw-r--r--calendar/year-view.c147
1 files changed, 110 insertions, 37 deletions
diff --git a/calendar/year-view.c b/calendar/year-view.c
index 96b43c264b..93cd591292 100644
--- a/calendar/year-view.c
+++ b/calendar/year-view.c
@@ -18,7 +18,7 @@
#define HEAD_SPACING 4 /* Spacing between year heading and months */
-#define TITLE_SPACING 2 /* Spacing between title and calendar */
+#define TITLE_SPACING 1 /* Spacing between title and calendar */
#define SPACING 4 /* Spacing between months */
@@ -81,62 +81,71 @@ static gint
idle_handler (gpointer data)
{
YearView *yv;
+ GtkArg arg;
+ double head_height;
+ double title_height;
double width, height;
- double mwidth, mheight;
- double h_yofs, m_yofs;
+ double month_width;
+ double month_height;
+ double month_yofs;
+ double xofs, yofs;
double x, y;
- GtkArg arg;
- GdkFont *head_font, *title_font;
int i;
yv = data;
- /* Get the fonts to get their size later */
+ /* Get the heights of the heading and the titles */
- arg.name = "font_gdk";
+ arg.name = "text_height";
gtk_object_getv (GTK_OBJECT (yv->heading), 1, &arg);
- head_font = GTK_VALUE_BOXED (arg);
+ head_height = GTK_VALUE_DOUBLE (arg) + 2 * HEAD_SPACING;
- arg.name = "font_gdk";
+ arg.name = "text_height";
gtk_object_getv (GTK_OBJECT (yv->titles[0]), 1, &arg);
- title_font = GTK_VALUE_BOXED (arg);
+ title_height = GTK_VALUE_DOUBLE (arg);
- /* Adjust heading */
+ /* Space for the titles and months */
- gnome_canvas_item_set (yv->heading,
- "x", (double) yv->canvas.width / 2.0,
- "y", (double) HEAD_SPACING,
- NULL);
+ width = yv->canvas.width;
+ height = yv->canvas.height - head_height;
- /* Adjust months */
+ /* Offsets */
- h_yofs = 2 * HEAD_SPACING + head_font->ascent + head_font->descent;
- m_yofs = SPACING + title_font->ascent + title_font->descent;
+ xofs = (width + SPACING) / 3.0;
+ yofs = (height + SPACING) / 4.0;
- width = (yv->canvas.width + SPACING) / 3.0;
- height = (yv->canvas.height - h_yofs + SPACING) / 4.0;
+ /* Month item vertical offset */
- mwidth = (yv->canvas.width - 2 * SPACING) / 3.0;
- mheight = (yv->canvas.height - h_yofs - 3 * SPACING - 4 * m_yofs) / 4.0;
+ month_yofs = title_height + TITLE_SPACING;
- for (i = 0; i < 12; i++) {
- x = (i % 3) * width;
- y = (i / 3) * height + h_yofs;
+ /* Month item dimensions */
- /* Title */
+ month_width = (width - 2 * SPACING) / 3.0;
+ month_height = (yofs - SPACING) - month_yofs;
+
+ /* Adjust the year heading */
+
+ gnome_canvas_item_set (yv->heading,
+ "x", width / 2.0,
+ "y", (double) HEAD_SPACING,
+ NULL);
+
+ /* Adjust titles and months */
+
+ for (i = 0; i < 12; i++) {
+ x = (i % 3) * xofs;
+ y = head_height + (i / 3) * yofs;
gnome_canvas_item_set (yv->titles[i],
- "x", x + width / 2.0,
+ "x", x + month_width / 2.0,
"y", y,
NULL);
- /* Month item */
-
gnome_canvas_item_set (yv->mitems[i],
"x", x,
- "y", y + m_yofs,
- "width", mwidth,
- "height", mheight,
+ "y", y + month_yofs,
+ "width", month_width,
+ "height", month_height,
NULL);
}
@@ -433,6 +442,72 @@ setup_month_item (YearView *yv, int n)
month_item_prepare_prelight (GNOME_MONTH_ITEM (mitem), default_color_func, NULL);
}
+/* Computes the minimum size for the year view and stores it in its internal fields */
+static void
+compute_min_size (YearView *yv)
+{
+ GtkArg args[2];
+ double m_width;
+ double m_height;
+ double max_width;
+ double w;
+ int i;
+
+ /* Compute the minimum size of the year heading */
+
+ args[0].name = "text_width";
+ args[1].name = "text_height";
+ gtk_object_getv (GTK_OBJECT (yv->heading), 1, args);
+
+ m_width = GTK_VALUE_DOUBLE (args[0]);
+ m_height = 2 * HEAD_SPACING + GTK_VALUE_DOUBLE (args[1]);
+
+ /* Add height of month titles and their spacings */
+
+ args[0].name = "text_height";
+ gtk_object_getv (GTK_OBJECT (yv->titles[0]), 1, &args[0]);
+
+ m_height += 4 * (GTK_VALUE_DOUBLE (args[0]) + TITLE_SPACING);
+
+ /* Add width of month titles */
+
+ max_width = 0.0;
+
+ for (i = 0; i < 12; i++) {
+ args[0].name = "text_width";
+ gtk_object_getv (GTK_OBJECT (yv->titles[i]), 1, &args[0]);
+
+ w = GTK_VALUE_DOUBLE (args[0]);
+ if (max_width < w)
+ max_width = w;
+ }
+
+ max_width = 3 * max_width + 2 * SPACING;
+
+ if (m_width < max_width)
+ m_width = max_width;
+
+ /* Add width of month items */
+
+ args[0].name = "width";
+ args[1].name = "height";
+ gtk_object_getv (GTK_OBJECT (yv->mitems[0]), 2, args);
+
+ max_width = 3 * GTK_VALUE_DOUBLE (args[0]) + 2 * SPACING;
+
+ if (m_width < max_width)
+ m_width = max_width;
+
+ /* Add height of month items */
+
+ m_height += 4 * GTK_VALUE_DOUBLE (args[1]) + 3 * SPACING;
+
+ /* Finally, set the minimum width and height in the year view */
+
+ yv->min_width = (int) (m_width + 0.5);
+ yv->min_height = (int) (m_height + 0.5);
+}
+
static void
year_view_init (YearView *yv)
{
@@ -516,6 +591,7 @@ year_view_new (GnomeCalendar *calendar, time_t year)
year_view_colors_changed (yv);
year_view_set (yv, year);
+ compute_min_size (yv);
return GTK_WIDGET (yv);
}
@@ -530,11 +606,8 @@ year_view_size_request (GtkWidget *widget, GtkRequisition *requisition)
yv = YEAR_VIEW (widget);
- if (GTK_WIDGET_CLASS (parent_class)->size_request)
- (* GTK_WIDGET_CLASS (parent_class)->size_request) (widget, requisition);
-
- requisition->width = 200;
- requisition->height = 150;
+ requisition->width = yv->min_width;
+ requisition->height = yv->min_height;
}
static void