2006-01-30 Kjartan Maraas <kmaraas@gnome.org> * e-timezone-dialog/e-timezone-dialog.c: (get_zone_from_point): * menus/gal-view-menus.c: * misc/e-attachment-bar.c: (calculate_height_width), (update_remote_file), (e_attachment_bar_get_attachment), (class_init): * misc/e-attachment.c: (async_progress_update_cb), (download_to_local_path): * misc/e-calendar-item.c: (e_calendar_item_get_arg), (e_calendar_item_realize), (e_calendar_item_ensure_days_visible): * misc/e-calendar.c: (e_calendar_drag_motion), (e_calendar_drag_leave), (e_calendar_focus): * misc/e-canvas-background.c: (ecb_get_property): * misc/e-canvas.c: (e_canvas_class_init), (pick_current_item): * misc/e-cell-date-edit.c: (e_cell_date_edit_do_popup), (e_cell_date_edit_show_popup): * misc/e-cell-percent.c: * misc/e-charset-picker.c: (e_charset_picker_bonobo_ui_populate): * misc/e-config-page.c: (e_config_page_class_init): * misc/e-dateedit.c: (e_date_edit_set_date), (e_date_edit_set_date_and_time_of_day), (on_date_popup_date_selected): * misc/e-dropdown-button.c: (e_dropdown_button_class_init): * misc/e-expander.c: (get_expander_bounds), (e_expander_expose), (is_in_expander_panel): * misc/e-filter-bar.c: (option_changed), (build_items): * misc/e-image-chooser.c: (e_image_chooser_init), (image_drag_data_received_cb): * misc/e-map.c: (e_map_size_allocate), (e_map_button_press), (e_map_button_release), (e_map_motion), (e_map_zoom_to_location), (e_map_zoom_out), (update_render_point), (repaint_point), (zoom_in_smooth): * misc/e-multi-config-dialog.c: (impl_response): * misc/e-reflow.c: (e_reflow_realize), (e_reflow_event): * misc/e-search-bar.c: (clear_search), (search_now_verb_cb), (entry_activated_cb), (activate_button_clicked_cb), (clear_button_clicked_cb): * misc/e-selection-model.c: (e_selection_model_key_press): * misc/e-send-options.c: (delay_until_date_changed_cb), (e_sendoptions_get_need_general_options): * misc/e-unicode.c: (e_stripped_char): * table/e-cell-progress.c: (eprog_draw_border), (eprog_draw), (eprog_event): * table/e-cell-spin-button.c: (ecsb_event), (ecsb_focus), (ecsb_unfocus), (ecsb_dispose): * table/e-cell-text.c: (ect_draw), (ect_show_tooltip): * table/e-cell-toggle.c: (etog_draw), (etog_event): * table/e-cell-tree.c: (ect_max_width): * table/e-cell-vbox.c: * table/e-table-click-to-add.c: (etcta_event): * table/e-table-config.c: (create_global_store): * table/e-table-field-chooser-dialog.c: * table/e-table-field-chooser-item.c: (etfci_find_button), (etfci_reflow), (etfci_get_property), (etfci_realize): * table/e-table-field-chooser.c: (e_table_field_chooser_class_init): * table/e-table-group-container.c: (etgc_unrealize): * table/e-table-group.c: (e_table_group_new): * table/e-table-header-item.c: (e_table_header_item_get_height), (ethi_realize), (ethi_event): * table/e-table-header-utils.c: (e_table_draw_elided_string), (e_table_header_draw_button): * table/e-table-item.c: (eti_set_property), (eti_get_property), (eti_draw), (eti_event), (eti_cursor_change): * table/e-table-scrolled.c: (e_table_scrolled_class_init): * table/e-table-search.c: * table/e-table-sort-info.c: (e_table_sort_info_save_to_node): * table/e-table.c: (table_canvas_reflow_idle), (table_canvas_size_allocate), (canvas_vbox_event), (click_to_add_event), (do_drag_motion), (e_table_class_init): * table/e-tree-scrolled.c: (e_tree_scrolled_class_init): * table/e-tree.c: (tree_canvas_reflow_idle), (tree_canvas_size_allocate), (e_tree_drag_get_data), (do_drag_motion), (e_tree_class_init): * text/e-text.c: (e_text_set_property), (e_text_draw), (_do_tooltip), (primary_clear_cb), (_get_position), (e_text_command): Tons of cleanups of the following sort: - remove unused vars - remove extraneous semi-colons - add some comments where assignments were done without using the results later - remove break; statements after return foo; - add casts in some places to be more type correct - rename variables with name clashes - s/if/ifdef in some cases - mark some code static - remove some unused functions - use guint for 1-bit bitfields svn path=/trunk/; revision=31371
473 lines
12 KiB
C
473 lines
12 KiB
C
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
|
|
/*
|
|
* e-table-header-utils.h
|
|
* Copyright 2000, 2001, Ximian, Inc.
|
|
*
|
|
* Authors:
|
|
* Chris Lahey <clahey@ximian.com>
|
|
* Miguel de Icaza <miguel@ximian.com>
|
|
* Federico Mena-Quintero <federico@ximian.com>
|
|
*
|
|
* This library is free software; you can redistribute it and/or
|
|
* modify it under the terms of the GNU Library General Public
|
|
* License, version 2, as published by the Free Software Foundation.
|
|
*
|
|
* This library is distributed in the hope that it will be useful, but
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
* Library General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU Library General Public
|
|
* License along with this library; if not, write to the Free Software
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
|
|
* 02111-1307, USA.
|
|
*/
|
|
|
|
#include <config.h>
|
|
|
|
#include <string.h> /* strlen() */
|
|
#include <glib.h>
|
|
|
|
#include <gtk/gtk.h>
|
|
|
|
#include "misc/e-unicode.h"
|
|
|
|
#include "e-table-defines.h"
|
|
#include "e-table-header-utils.h"
|
|
|
|
static PangoLayout*
|
|
build_header_layout (GtkWidget *widget, const char *str)
|
|
{
|
|
PangoLayout *layout;
|
|
|
|
layout = gtk_widget_create_pango_layout (widget, str);
|
|
|
|
#ifdef FROB_FONT_DESC
|
|
{
|
|
PangoFontDescription *desc;
|
|
desc = pango_font_description_copy (gtk_widget_get_style (widget)->font_desc);
|
|
pango_font_description_set_size (desc,
|
|
pango_font_description_get_size (desc) * 1.2);
|
|
|
|
pango_font_description_set_weight (desc, PANGO_WEIGHT_BOLD);
|
|
pango_layout_set_font_description (layout, desc);
|
|
|
|
pango_font_description_free (desc);
|
|
}
|
|
#endif
|
|
|
|
return layout;
|
|
}
|
|
|
|
/**
|
|
* e_table_header_compute_height:
|
|
* @ecol: Table column description.
|
|
* @widget: The widget from which to build the PangoLayout.
|
|
*
|
|
* Computes the minimum height required for a table header button.
|
|
*
|
|
* Return value: The height of the button, in pixels.
|
|
**/
|
|
double
|
|
e_table_header_compute_height (ETableCol *ecol, GtkWidget *widget)
|
|
{
|
|
int ythick;
|
|
int height;
|
|
PangoLayout *layout;
|
|
|
|
g_return_val_if_fail (ecol != NULL, -1);
|
|
g_return_val_if_fail (E_IS_TABLE_COL (ecol), -1);
|
|
g_return_val_if_fail (GTK_IS_WIDGET (widget), -1);
|
|
|
|
ythick = gtk_widget_get_style (widget)->ythickness;
|
|
|
|
layout = build_header_layout (widget, ecol->text);
|
|
|
|
pango_layout_get_pixel_size (layout, NULL, &height);
|
|
|
|
if (ecol->is_pixbuf) {
|
|
g_assert (ecol->pixbuf != NULL);
|
|
height = MAX (height, gdk_pixbuf_get_height (ecol->pixbuf));
|
|
}
|
|
|
|
height = MAX (height, MIN_ARROW_SIZE);
|
|
|
|
height += 2 * (ythick + HEADER_PADDING);
|
|
|
|
g_object_unref (layout);
|
|
|
|
return height;
|
|
}
|
|
|
|
double
|
|
e_table_header_width_extras (GtkStyle *style)
|
|
{
|
|
g_return_val_if_fail (style != NULL, -1);
|
|
|
|
return 2 * (style->xthickness + HEADER_PADDING);
|
|
}
|
|
|
|
/* Creates a pixmap that is a composite of a background color and the upper-left
|
|
* corner rectangle of a pixbuf.
|
|
*/
|
|
static GdkPixmap *
|
|
make_composite_pixmap (GdkDrawable *drawable, GdkGC *gc,
|
|
GdkPixbuf *pixbuf, GdkColor *bg, int width, int height,
|
|
int dither_xofs, int dither_yofs)
|
|
{
|
|
int pwidth, pheight;
|
|
GdkPixmap *pixmap;
|
|
GdkPixbuf *tmp;
|
|
int color;
|
|
|
|
pwidth = gdk_pixbuf_get_width (pixbuf);
|
|
pheight = gdk_pixbuf_get_height (pixbuf);
|
|
g_assert (width <= pwidth && height <= pheight);
|
|
|
|
color = ((bg->red & 0xff00) << 8) | (bg->green & 0xff00) | ((bg->blue & 0xff00) >> 8);
|
|
|
|
if (width >= pwidth && height >= pheight) {
|
|
tmp = gdk_pixbuf_new (GDK_COLORSPACE_RGB, FALSE, 8, width, height);
|
|
if (!tmp)
|
|
return NULL;
|
|
|
|
gdk_pixbuf_composite_color (pixbuf, tmp,
|
|
0, 0,
|
|
width, height,
|
|
0, 0,
|
|
1.0, 1.0,
|
|
GDK_INTERP_NEAREST,
|
|
255,
|
|
0, 0,
|
|
16,
|
|
color, color);
|
|
} else {
|
|
int x, y, rowstride;
|
|
GdkPixbuf *fade;
|
|
guchar *pixels;
|
|
|
|
/* Do a nice fade of the pixbuf down and to the right */
|
|
|
|
fade = gdk_pixbuf_new (GDK_COLORSPACE_RGB, TRUE, 8, width, height);
|
|
if (!fade)
|
|
return NULL;
|
|
|
|
gdk_pixbuf_copy_area (pixbuf,
|
|
0, 0,
|
|
width, height,
|
|
fade,
|
|
0, 0);
|
|
|
|
rowstride = gdk_pixbuf_get_rowstride (fade);
|
|
pixels = gdk_pixbuf_get_pixels (fade);
|
|
|
|
for (y = 0; y < height; y++) {
|
|
guchar *p;
|
|
int yfactor;
|
|
|
|
p = pixels + y * rowstride;
|
|
|
|
if (height < pheight)
|
|
yfactor = height - y;
|
|
else
|
|
yfactor = height;
|
|
|
|
for (x = 0; x < width; x++) {
|
|
int xfactor;
|
|
|
|
if (width < pwidth)
|
|
xfactor = width - x;
|
|
else
|
|
xfactor = width;
|
|
|
|
p[3] = ((int) p[3] * xfactor * yfactor / (width * height));
|
|
p += 4;
|
|
}
|
|
}
|
|
|
|
tmp = gdk_pixbuf_new (GDK_COLORSPACE_RGB, FALSE, 8, width, height);
|
|
if (!tmp) {
|
|
gdk_pixbuf_unref (fade);
|
|
return NULL;
|
|
}
|
|
|
|
gdk_pixbuf_composite_color (fade, tmp,
|
|
0, 0,
|
|
width, height,
|
|
0, 0,
|
|
1.0, 1.0,
|
|
GDK_INTERP_NEAREST,
|
|
255,
|
|
0, 0,
|
|
16,
|
|
color, color);
|
|
|
|
gdk_pixbuf_unref (fade);
|
|
}
|
|
|
|
pixmap = gdk_pixmap_new (drawable, width, height, gdk_rgb_get_visual ()->depth);
|
|
gdk_draw_rgb_image_dithalign (pixmap, gc,
|
|
0, 0,
|
|
width, height,
|
|
GDK_RGB_DITHER_NORMAL,
|
|
gdk_pixbuf_get_pixels (tmp),
|
|
gdk_pixbuf_get_rowstride (tmp),
|
|
dither_xofs, dither_yofs);
|
|
gdk_pixbuf_unref (tmp);
|
|
|
|
return pixmap;
|
|
}
|
|
|
|
/* Default width of the elision arrow in pixels */
|
|
#define ARROW_WIDTH 4
|
|
|
|
/**
|
|
* e_table_draw_elided_string:
|
|
* @drawable: Destination drawable.
|
|
* @font: Font for the text.
|
|
* @gc: GC to use for drawing.
|
|
* @x: X insertion point for the string.
|
|
* @y: Y insertion point for the string's baseline.
|
|
* @layout: the PangoLayout to draw.
|
|
* @str: the string we're drawing, passed in so we can change the layout if it needs eliding.
|
|
* @max_width: Maximum width in which the string must fit.
|
|
* @center: Whether to center the string in the available area if it does fit.
|
|
*
|
|
* Draws a string, possibly trimming it so that it fits inside the specified
|
|
* maximum width. If it does not fit, an elision indicator is drawn after the
|
|
* last character that does fit.
|
|
**/
|
|
static void
|
|
e_table_draw_elided_string (GdkDrawable *drawable, GdkGC *gc, GtkWidget *widget,
|
|
int x, int y, PangoLayout *layout, char *str,
|
|
int max_width, gboolean center)
|
|
{
|
|
int width;
|
|
int height;
|
|
int index;
|
|
GSList *lines;
|
|
PangoLayoutLine *line;
|
|
|
|
g_return_if_fail (drawable != NULL);
|
|
g_return_if_fail (gc != NULL);
|
|
g_return_if_fail (layout != NULL);
|
|
g_return_if_fail (max_width >= 0);
|
|
|
|
pango_layout_get_pixel_size (layout, &width, &height);
|
|
|
|
gdk_gc_set_clip_rectangle (gc, NULL);
|
|
|
|
if (width <= max_width) {
|
|
int xpos;
|
|
|
|
if (center)
|
|
xpos = x + (max_width - width) / 2;
|
|
else
|
|
xpos = x;
|
|
|
|
gdk_draw_layout (drawable, gc,
|
|
xpos, y,
|
|
layout);
|
|
} else {
|
|
int arrow_width;
|
|
int i;
|
|
|
|
if (max_width < ARROW_WIDTH + 1)
|
|
arrow_width = max_width - 1;
|
|
else
|
|
arrow_width = ARROW_WIDTH;
|
|
|
|
|
|
lines = pango_layout_get_lines (layout);
|
|
line = lines->data;
|
|
|
|
if (!pango_layout_line_x_to_index (line,
|
|
(max_width - arrow_width) * PANGO_SCALE,
|
|
&index,
|
|
NULL)) {
|
|
g_warning ("pango_layout_line_x_to_index returned false");
|
|
return;
|
|
}
|
|
|
|
pango_layout_set_text (layout, str, index);
|
|
|
|
gdk_draw_layout (drawable, gc, x, y, layout);
|
|
|
|
for (i = 0; i < arrow_width; i++) {
|
|
gdk_draw_line (drawable, gc,
|
|
x + max_width - i,
|
|
y + height / 2 - i,
|
|
x + max_width - i,
|
|
y + height / 2 + i + 1);
|
|
}
|
|
}
|
|
}
|
|
|
|
static GtkWidget *g_label;
|
|
|
|
/**
|
|
* e_table_header_draw_button:
|
|
* @drawable: Destination drawable.
|
|
* @ecol: Table column for the header information.
|
|
* @style: Style to use for drawing the button.
|
|
* @state: State of the table widget.
|
|
* @widget: The table widget.
|
|
* @x: Leftmost coordinate of the button.
|
|
* @y: Topmost coordinate of the button.
|
|
* @width: Width of the region to draw.
|
|
* @height: Height of the region to draw.
|
|
* @button_width: Width for the complete button.
|
|
* @button_height: Height for the complete button.
|
|
* @arrow: Arrow type to use as a sort indicator.
|
|
*
|
|
* Draws a button suitable for a table header.
|
|
**/
|
|
void
|
|
e_table_header_draw_button (GdkDrawable *drawable, ETableCol *ecol,
|
|
GtkStyle *style, GtkStateType state,
|
|
GtkWidget *widget,
|
|
int x, int y, int width, int height,
|
|
int button_width, int button_height,
|
|
ETableColArrow arrow)
|
|
{
|
|
int xthick, ythick;
|
|
int inner_x, inner_y;
|
|
int inner_width, inner_height;
|
|
GdkGC *gc;
|
|
PangoLayout *layout;
|
|
|
|
g_return_if_fail (drawable != NULL);
|
|
g_return_if_fail (ecol != NULL);
|
|
g_return_if_fail (E_IS_TABLE_COL (ecol));
|
|
g_return_if_fail (style != NULL);
|
|
g_return_if_fail (widget != NULL);
|
|
g_return_if_fail (GTK_IS_WIDGET (widget));
|
|
g_return_if_fail (button_width > 0 && button_height > 0);
|
|
|
|
if (g_label == NULL) {
|
|
GtkWidget *button = gtk_button_new_with_label("Hi");
|
|
GtkWidget *window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
|
|
g_label = GTK_BIN(button)->child;
|
|
gtk_container_add (GTK_CONTAINER (window), button);
|
|
gtk_widget_ensure_style (window);
|
|
gtk_widget_ensure_style (button);
|
|
gtk_widget_ensure_style (g_label);
|
|
}
|
|
|
|
gc = g_label->style->fg_gc[state];
|
|
|
|
gdk_gc_set_clip_rectangle (gc, NULL);
|
|
|
|
xthick = style->xthickness;
|
|
ythick = style->ythickness;
|
|
|
|
/* Button bevel */
|
|
|
|
gtk_paint_box (style, drawable, state, GTK_SHADOW_OUT,
|
|
NULL, widget, "button",
|
|
x, y, button_width, button_height);
|
|
|
|
/* Inside area */
|
|
|
|
inner_width = button_width - 2 * (xthick + HEADER_PADDING);
|
|
inner_height = button_height - 2 * (ythick + HEADER_PADDING);
|
|
|
|
if (inner_width < 1 || inner_height < 1)
|
|
return; /* nothing fits */
|
|
|
|
inner_x = x + xthick + HEADER_PADDING;
|
|
inner_y = y + ythick + HEADER_PADDING;
|
|
|
|
/* Arrow */
|
|
|
|
switch (arrow) {
|
|
case E_TABLE_COL_ARROW_NONE:
|
|
break;
|
|
|
|
case E_TABLE_COL_ARROW_UP:
|
|
case E_TABLE_COL_ARROW_DOWN: {
|
|
int arrow_width, arrow_height;
|
|
|
|
arrow_width = MIN (MIN_ARROW_SIZE, inner_width);
|
|
arrow_height = MIN (MIN_ARROW_SIZE, inner_height);
|
|
|
|
gtk_paint_arrow (style, drawable, state,
|
|
GTK_SHADOW_NONE, NULL, widget, "header",
|
|
(arrow == E_TABLE_COL_ARROW_UP) ? GTK_ARROW_UP : GTK_ARROW_DOWN,
|
|
TRUE,
|
|
inner_x + inner_width - arrow_width,
|
|
inner_y + (inner_height - arrow_height) / 2,
|
|
arrow_width, arrow_height);
|
|
|
|
inner_width -= arrow_width + HEADER_PADDING;
|
|
break;
|
|
}
|
|
|
|
default:
|
|
g_assert_not_reached ();
|
|
return;
|
|
}
|
|
|
|
if (inner_width < 1)
|
|
return; /* nothing else fits */
|
|
|
|
layout = build_header_layout (widget, ecol->text);
|
|
|
|
/* Pixbuf or label */
|
|
if (ecol->is_pixbuf) {
|
|
int pwidth, pheight;
|
|
int clip_width, clip_height;
|
|
int xpos;
|
|
GdkPixmap *pixmap;
|
|
|
|
g_assert (ecol->pixbuf != NULL);
|
|
|
|
pwidth = gdk_pixbuf_get_width (ecol->pixbuf);
|
|
pheight = gdk_pixbuf_get_height (ecol->pixbuf);
|
|
|
|
clip_width = MIN (pwidth, inner_width);
|
|
clip_height = MIN (pheight, inner_height);
|
|
|
|
xpos = inner_x;
|
|
|
|
if (inner_width - pwidth > 11) {
|
|
int ypos;
|
|
|
|
pango_layout_get_pixel_size (layout, &width, NULL);
|
|
|
|
if (width < inner_width - (pwidth + 1)) {
|
|
xpos = inner_x + (inner_width - width - (pwidth + 1)) / 2;
|
|
}
|
|
|
|
ypos = inner_y;
|
|
|
|
e_table_draw_elided_string (drawable, gc, widget,
|
|
xpos + pwidth + 1, ypos,
|
|
layout, ecol->text, inner_width - (xpos - inner_x), FALSE);
|
|
}
|
|
|
|
pixmap = make_composite_pixmap (drawable, gc,
|
|
ecol->pixbuf, &style->bg[state],
|
|
clip_width, clip_height,
|
|
xpos,
|
|
inner_y + (inner_height - clip_height) / 2);
|
|
|
|
gdk_gc_set_clip_rectangle (gc, NULL);
|
|
|
|
if (pixmap) {
|
|
gdk_draw_pixmap (drawable, gc, pixmap,
|
|
0, 0,
|
|
xpos,
|
|
inner_y + (inner_height - clip_height) / 2,
|
|
clip_width, clip_height);
|
|
gdk_pixmap_unref (pixmap);
|
|
}
|
|
} else {
|
|
e_table_draw_elided_string (drawable, gc, widget,
|
|
inner_x, inner_y,
|
|
layout, ecol->text, inner_width, TRUE);
|
|
}
|
|
|
|
g_object_unref (layout);
|
|
}
|