aboutsummaryrefslogtreecommitdiffstats
path: root/widgets/table/e-table-field-chooser-item.c
diff options
context:
space:
mode:
authorFederico Mena Quintero <federico@helixcode.com>2000-12-03 01:35:22 +0800
committerFederico Mena Quintero <federico@src.gnome.org>2000-12-03 01:35:22 +0800
commitf70c74f37110d1bcb23227c720965a058cabf61c (patch)
tree0cd81472b7a6e231f6160f6beece3d6c3a61bce5 /widgets/table/e-table-field-chooser-item.c
parent4cffa30b1b778f3fa2b7e597e7bae589fc271a4e (diff)
downloadgsoc2013-evolution-f70c74f37110d1bcb23227c720965a058cabf61c.tar.gz
gsoc2013-evolution-f70c74f37110d1bcb23227c720965a058cabf61c.tar.zst
gsoc2013-evolution-f70c74f37110d1bcb23227c720965a058cabf61c.zip
Federico gets into pixel-perfect neurosis. Xmag is my best friend.
2000-12-01 Federico Mena Quintero <federico@helixcode.com> Federico gets into pixel-perfect neurosis. Xmag is my best friend. * e-table-item.c (eti_draw): Set the focus_gc stipple origin to match the upper-left corner of the focus rectangle. This way focusing will look consistent even among rows/columns with odd pixel sizes. Also, make the focus rectangle span the whole cell; there was one blank pixel column to the left of the rectangle. * e-table-header-utils.c: New file with utilities for drawing header buttons. This is so that ETableHeaderItem and ETableFieldChooserItem can share the same code. (e_table_header_compute_height): New function to compute the height of a column button. (make_composite_pixmap): New function to composite a pixbuf against a solid background and make a pixmap out of the result. This does some ultra-fancy fading-out of the original pixbuf if the destination area is smaller than the source. (compute_elision_length): New function to compute the elision length in O(n log n) instead of O(n^2), for n = strlen (str). (e_table_header_draw_button): New function to draw a header button. (e_table_draw_elided_string): New function to draw a string elided to a maximum width. * e-table-defines.h (HEADER_PADDING): Made the default padding be 1; now a header button's height is content_height + 2 * (HEADER_PADDING + style->ythickness). This is the correct way to measure button heights. * e-table-field-chooser-item.c (etfci_find_button): Use e_table_header_compute_height(). (etfci_reflow): Likewise. (etfci_draw): Use e_table_header_draw_button(). (etfci_start_drag): Likewise. (etfci_draw): Likewise. (etfci_start_drag): Likewise. (etfci_button_height): Removed function. (draw_button): Removed function. * e-table-header-item.c (draw_button): Removed function. (e_table_header_item_get_height): Use e_table_header_compute_height(). (ethi_draw): e_table_header_draw_button(). (ethi_start_drag): Likewise. (make_shaped_window_from_xpm): Fixed misspelling in function name. (draw_button): Removed function. * Makefile.am: Added e-table-header-utils.[ch]. svn path=/trunk/; revision=6766
Diffstat (limited to 'widgets/table/e-table-field-chooser-item.c')
-rw-r--r--widgets/table/e-table-field-chooser-item.c153
1 files changed, 45 insertions, 108 deletions
diff --git a/widgets/table/e-table-field-chooser-item.c b/widgets/table/e-table-field-chooser-item.c
index 4bb0653fef..47a7b01195 100644
--- a/widgets/table/e-table-field-chooser-item.c
+++ b/widgets/table/e-table-field-chooser-item.c
@@ -22,6 +22,7 @@
#include "e-table-header.h"
#include "e-table-col-dnd.h"
#include "e-table-defines.h"
+#include "e-table-header-utils.h"
#include "e-table-field-chooser-item.h"
@@ -62,39 +63,22 @@ etfci_destroy (GtkObject *object){
(*GTK_OBJECT_CLASS (etfci_parent_class)->destroy) (object);
}
-static double
-etfci_button_height (ETableFieldChooserItem *etfci, gint col)
-{
- ETableCol *ecol = e_table_header_get_column (etfci->full_header, col);
- double height;
-
- if (etfci->font) {
- height = etfci->font->ascent + etfci->font->descent + HEADER_PADDING + 1;
- } else {
- /* FIXME: Default??? */
- height = 16;
- }
-
- if (ecol->is_pixbuf) {
- height = MAX (height, gdk_pixbuf_get_height (ecol->pixbuf) + HEADER_PADDING + 1);
- }
-
- if (height < MIN_ARROW_SIZE + 1 + HEADER_PADDING)
- height = MIN_ARROW_SIZE + 1 + HEADER_PADDING;
-
- return height;
-}
-
static gint
etfci_find_button (ETableFieldChooserItem *etfci, double loc)
{
int i;
int count;
double height = 0;
-
+ GtkStyle *style;
+
+ style = GTK_WIDGET (GNOME_CANVAS_ITEM (etfci)->canvas)->style;
+
count = e_table_header_count(etfci->full_header);
for (i = 0; i < count; i++) {
- height += etfci_button_height(etfci, i);
+ ETableCol *ecol;
+
+ ecol = e_table_header_get_column (etfci->full_header, i);
+ height += e_table_header_compute_height (ecol, style, etfci->font);
if (height > loc)
return i;
}
@@ -109,12 +93,18 @@ etfci_reflow (GnomeCanvasItem *item, gint flags)
int i;
int count;
double height = 0;
+ GtkStyle *style;
+
+ style = GTK_WIDGET (GNOME_CANVAS_ITEM (etfci)->canvas)->style;
old_height = etfci->height;
count = e_table_header_count(etfci->full_header);
for (i = 0; i < count; i++) {
- height += etfci_button_height(etfci, i);
+ ETableCol *ecol;
+
+ ecol = e_table_header_get_column (etfci->full_header, i);
+ height += e_table_header_compute_height (ecol, style, etfci->font);
}
etfci->height = height;
@@ -348,77 +338,6 @@ etfci_unrealize (GnomeCanvasItem *item)
}
static void
-draw_button (ETableFieldChooserItem *etfci, int col,
- GdkDrawable *drawable, GtkStyle *style,
- int x, int y, int width, int height)
-{
- int xtra;
- GdkRectangle area;
- ETableCol *ecol = e_table_header_get_column(etfci->full_header, col);
- double button_height = etfci_button_height(etfci, col);
- GdkRectangle clip;
-
- GtkWidget *widget = GTK_WIDGET(GNOME_CANVAS_ITEM(etfci)->canvas);
-
- gdk_window_clear_area (drawable, x, y, width, height);
-
- area.x = x;
- area.y = y;
- area.width = width;
- area.height = height;
-
- gtk_paint_box (style, drawable,
- GTK_STATE_NORMAL, GTK_SHADOW_OUT,
- &area, widget, "button",
- x, y, width, height);
-
- clip.x = x + HEADER_PADDING / 2;
- clip.y = y + HEADER_PADDING / 2;
- clip.width = width - HEADER_PADDING;
- clip.height = button_height - HEADER_PADDING;
-
- if (ecol->is_pixbuf){
- xtra = (clip.width - gdk_pixbuf_get_width (ecol->pixbuf))/2;
- if (xtra < 0)
- xtra = 0;
-
- xtra += HEADER_PADDING / 2;
-
- gdk_pixbuf_render_to_drawable_alpha (ecol->pixbuf,
- drawable,
- 0, 0,
- x + xtra, y + (clip.height - gdk_pixbuf_get_height (ecol->pixbuf)) / 2,
- gdk_pixbuf_get_width (ecol->pixbuf),
- gdk_pixbuf_get_height(ecol->pixbuf),
- GDK_PIXBUF_ALPHA_FULL, 128,
- GDK_RGB_DITHER_NORMAL,
- 0, 0);
- } else {
- int y_xtra;
- GdkGC *gc = style->text_gc[GTK_STATE_NORMAL];
-
- gdk_gc_set_clip_rectangle (gc, &clip);
-
- /* Center the thing */
- xtra = (clip.width - gdk_string_measure (etfci->font, ecol->text))/2;
-
- /* Skip over border */
- if (xtra < 0)
- xtra = 0;
-
- xtra += HEADER_PADDING / 2;
-
- y_xtra = (button_height + etfci->font->ascent - etfci->font->descent) / 2;
-
- gdk_draw_text (
- drawable, etfci->font,
- gc, x + xtra, y + y_xtra,
- ecol->text, strlen (ecol->text));
- gdk_gc_set_clip_rectangle (gc, NULL);
- }
-}
-
-static void
etfci_draw (GnomeCanvasItem *item, GdkDrawable *drawable, int x, int y, int width, int height)
{
ETableFieldChooserItem *etfci = E_TABLE_FIELD_CHOOSER_ITEM (item);
@@ -426,20 +345,33 @@ etfci_draw (GnomeCanvasItem *item, GdkDrawable *drawable, int x, int y, int widt
const int rows = e_table_header_count (etfci->full_header);
int y1, y2;
int row;
+ GtkStyle *style;
+ GtkStateType state;
+
+ style = GTK_WIDGET (canvas)->style;
+ state = GTK_WIDGET_STATE (canvas);
y1 = y2 = 0;
for (row = 0; row < rows; row++, y1 = y2){
- y2 += etfci_button_height(etfci, row);
+ ETableCol *ecol;
+
+ ecol = e_table_header_get_column (etfci->full_header, row);
+
+ y2 += e_table_header_compute_height (ecol, style, etfci->font);
if (y1 > (y + height))
break;
if (y2 < y)
continue;
-
- draw_button (etfci, row, drawable,
- GTK_WIDGET (canvas)->style,
- - x, y1 - y, etfci->width, y2 - y1);
+
+ e_table_header_draw_button (drawable, ecol,
+ style, etfci->font, state,
+ GTK_WIDGET (canvas), style->fg_gc[GTK_STATE_NORMAL],
+ -x, y1 - y,
+ width, height,
+ etfci->width, y2 - y1,
+ E_TABLE_COL_ARROW_NONE);
}
}
@@ -473,7 +405,7 @@ etfci_start_drag (ETableFieldChooserItem *etfci, GdkEvent *event, double x, doub
ETableCol *ecol;
GdkPixmap *pixmap;
int drag_col;
- double button_height;
+ int button_height;
GtkTargetEntry etfci_drag_types [] = {
{ TARGET_ETABLE_COL_TYPE, 0, TARGET_ETABLE_COL_HEADER },
@@ -493,12 +425,17 @@ etfci_start_drag (ETableFieldChooserItem *etfci, GdkEvent *event, double x, doub
context = gtk_drag_begin (widget, list, GDK_ACTION_MOVE, 1, event);
g_free(etfci_drag_types[0].target);
-
- button_height = etfci_button_height(etfci, drag_col);
+ button_height = e_table_header_compute_height (ecol, widget->style, etfci->font);
pixmap = gdk_pixmap_new (widget->window, etfci->width, button_height, -1);
- draw_button (etfci, drag_col, pixmap,
- widget->style,
- 0, 0, etfci->width, button_height);
+
+ e_table_header_draw_button (pixmap, e_table_header_get_column (etfci->full_header, drag_col),
+ widget->style, etfci->font, GTK_WIDGET_STATE (widget),
+ widget, widget->style->fg_gc[GTK_STATE_NORMAL],
+ 0, 0,
+ etfci->width, button_height,
+ etfci->width, button_height,
+ E_TABLE_COL_ARROW_NONE);
+
gtk_drag_set_icon_pixmap (context,
gdk_window_get_colormap (widget->window),
pixmap,