diff options
author | Christopher James Lahey <clahey@helixcode.com> | 2000-07-09 20:38:16 +0800 |
---|---|---|
committer | Chris Lahey <clahey@src.gnome.org> | 2000-07-09 20:38:16 +0800 |
commit | 80206f6b32b1ff0aac3f5a54c66176a8c112b547 (patch) | |
tree | de4ca3aecab51c61f4dbc20835f7dcf288433a97 /widgets/text | |
parent | 26279f186a6c7ee5b500dbff8a2b7f227cf6f564 (diff) | |
download | gsoc2013-evolution-80206f6b32b1ff0aac3f5a54c66176a8c112b547.tar.gz gsoc2013-evolution-80206f6b32b1ff0aac3f5a54c66176a8c112b547.tar.zst gsoc2013-evolution-80206f6b32b1ff0aac3f5a54c66176a8c112b547.zip |
Removed some border padding and set the "draw_borders" argument of the
2000-07-09 Christopher James Lahey <clahey@helixcode.com>
* widgets/e-text/e-entry.c: Removed some border padding and set
the "draw_borders" argument of the contained GtkText.
* widgets/e-text/e-text.c, widget/e-text/e-text.h: Added a
"draw_borders" argument which, if set, makes the EText look more
like a GtkEntry.
svn path=/trunk/; revision=4011
Diffstat (limited to 'widgets/text')
-rw-r--r-- | widgets/text/e-entry.c | 11 | ||||
-rw-r--r-- | widgets/text/e-text.c | 135 | ||||
-rw-r--r-- | widgets/text/e-text.h | 2 |
3 files changed, 121 insertions, 27 deletions
diff --git a/widgets/text/e-entry.c b/widgets/text/e-entry.c index 588d5358d7..cbde382c93 100644 --- a/widgets/text/e-entry.c +++ b/widgets/text/e-entry.c @@ -27,7 +27,6 @@ #define MIN_ENTRY_WIDTH 150 #define INNER_BORDER 2 - #define PARENT_TYPE gtk_table_get_type () static GtkObjectClass *parent_class; @@ -75,8 +74,8 @@ canvas_size_allocate (GtkWidget *widget, GtkAllocation *alloc, e_entry->canvas, 0, 0, alloc->width, alloc->height); gtk_object_set (GTK_OBJECT (e_entry->item), - "clip_width", (double) alloc->width - 2 * INNER_BORDER, - "clip_height", (double) alloc->height - 2 * INNER_BORDER, + "clip_width", (double) alloc->width, + "clip_height", (double) alloc->height, NULL); } @@ -110,10 +109,8 @@ e_entry_init (GtkObject *object) "clip", TRUE, "fill_clip_rectangle", TRUE, "anchor", GTK_ANCHOR_NW, + "draw_borders", TRUE, NULL)); - e_canvas_item_move_absolute(GNOME_CANVAS_ITEM(e_entry->item), - INNER_BORDER, - INNER_BORDER); gtk_table_attach_defaults(gtk_table, GTK_WIDGET(e_entry->canvas), 0, 1, 0, 1); @@ -340,7 +337,7 @@ et_set_arg (GtkObject *o, GtkArg *arg, guint arg_id) break; } } - + static void e_entry_class_init (GtkObjectClass *object_class) { diff --git a/widgets/text/e-text.c b/widgets/text/e-text.c index e87cec59c8..6d7e08dad2 100644 --- a/widgets/text/e-text.c +++ b/widgets/text/e-text.c @@ -30,6 +30,8 @@ #include "e-text-event-processor-emacs-like.h" +#define BORDER_INDENT 4 + enum { E_TEXT_CHANGED, E_TEXT_ACTIVATE, @@ -80,7 +82,8 @@ enum { ARG_BREAK_CHARACTERS, ARG_MAX_LINES, ARG_WIDTH, - ARG_HEIGHT + ARG_HEIGHT, + ARG_DRAW_BORDERS, }; @@ -269,6 +272,8 @@ e_text_class_init (ETextClass *klass) GTK_TYPE_DOUBLE, GTK_ARG_READWRITE, ARG_WIDTH); gtk_object_add_arg_type ("EText::height", GTK_TYPE_DOUBLE, GTK_ARG_READABLE, ARG_HEIGHT); + gtk_object_add_arg_type ("EText::draw_borders", + GTK_TYPE_BOOL, GTK_ARG_READWRITE, ARG_DRAW_BORDERS); if (!clipboard_atom) clipboard_atom = gdk_atom_intern ("CLIPBOARD", FALSE); @@ -674,6 +679,7 @@ calc_line_widths (EText *text) struct line *lines; int i; int j; + gdouble clip_width; /* Make sure line has been split */ if (text->text && text->num_lines == 0) @@ -682,6 +688,14 @@ calc_line_widths (EText *text) lines = text->lines; text->max_width = 0; + clip_width = text->clip_width; + if (clip_width >= 0 && text->draw_borders) { + clip_width -= 6; + if (clip_width < 0) + clip_width = 0; + } + + if (!lines) return; @@ -698,12 +712,12 @@ calc_line_widths (EText *text) if (text->clip && text->use_ellipsis && ! text->editing && - lines->width > text->clip_width && - text->clip_width >= 0) { + lines->width > clip_width && + clip_width >= 0) { if (text->font) { lines->ellipsis_length = 0; for (j = 0; j < lines->length; j++ ) { - if (gdk_text_width (text->font, lines->text, j) + text->ellipsis_width <= text->clip_width) + if (gdk_text_width (text->font, lines->text, j) + text->ellipsis_width <= clip_width) lines->ellipsis_length = j; else break; @@ -747,6 +761,7 @@ split_into_lines (EText *text) char *laststart; char *lastend; char *linestart; + double clip_width; /* Free old array of lines */ e_text_free_lines(text); @@ -760,13 +775,20 @@ split_into_lines (EText *text) laststart = text->text; linestart = text->text; + clip_width = text->clip_width; + if (clip_width >= 0 && text->draw_borders) { + clip_width -= 6; + if (clip_width < 0) + clip_width = 0; + } + for (p = text->text; *p; p++) { if (text->line_wrap && (*p == ' ' || *p == '\n')) { if ( laststart != lastend && gdk_text_width(text->font, linestart, p - linestart) - > text->clip_width ) { + > clip_width ) { text->num_lines ++; linestart = laststart; laststart = p + 1; @@ -781,7 +803,7 @@ split_into_lines (EText *text) && gdk_text_width(text->font, linestart, p + 1 - linestart) - > text->clip_width ) { + > clip_width ) { text->num_lines ++; linestart = laststart; laststart = p + 1; @@ -804,7 +826,7 @@ split_into_lines (EText *text) && gdk_text_width(text->font, linestart, p - linestart) - > text->clip_width ) { + > clip_width ) { text->num_lines ++; } } @@ -831,7 +853,7 @@ split_into_lines (EText *text) if ( gdk_text_width(text->font, lines->text, p - lines->text) - > text->clip_width + > clip_width && laststart != lastend ) { lines->length = lastend - lines->text; lines++; @@ -852,7 +874,7 @@ split_into_lines (EText *text) && gdk_text_width(text->font, lines->text, p + 1 - lines->text) - > text->clip_width ) { + > clip_width ) { lines->length = lastend - lines->text; lines++; line_num++; @@ -885,7 +907,7 @@ split_into_lines (EText *text) if ( gdk_text_width(text->font, lines->text, p - lines->text) - > text->clip_width + > clip_width && laststart != lastend ) { lines->length = lastend - lines->text; lines++; @@ -1212,6 +1234,16 @@ e_text_set_arg (GtkObject *object, GtkArg *arg, guint arg_id) text->needs_calc_line_widths = 1; needs_reflow = 1; break; + + case ARG_DRAW_BORDERS: + if (text->draw_borders != GTK_VALUE_BOOL (*arg)) { + text->draw_borders = GTK_VALUE_BOOL (*arg); + text->needs_calc_height = 1; + text->needs_redraw = 1; + needs_reflow = 1; + needs_update = 1; + } + break; default: return; @@ -1348,6 +1380,10 @@ e_text_get_arg (GtkObject *object, GtkArg *arg, guint arg_id) GTK_VALUE_DOUBLE (*arg) = text->clip && text->clip_height != -1 ? text->clip_height : text->height / text->item.canvas->pixels_per_unit; break; + case ARG_DRAW_BORDERS: + GTK_VALUE_BOOL (*arg) = text->draw_borders; + break; + default: arg->type = GTK_TYPE_INVALID; break; @@ -1371,6 +1407,7 @@ e_text_reflow (GnomeCanvasItem *item, int flags) int x; int i; struct line *lines; + gdouble clip_width; calc_line_widths(text); text->needs_calc_line_widths = 0; text->needs_calc_height = 1; @@ -1396,8 +1433,15 @@ e_text_reflow (GnomeCanvasItem *item, int flags) text->xofs_edit = x; } - if (2 + x - text->clip_width > text->xofs_edit) { - text->xofs_edit = 2 + x - text->clip_width; + clip_width = text->clip_width; + if (clip_width >= 0 && text->draw_borders) { + clip_width -= 6; + if (clip_width < 0) + clip_width = 0; + } + + if (2 + x - clip_width > text->xofs_edit) { + text->xofs_edit = 2 + x - clip_width; } if ((text->font->ascent + text->font->descent) * i < text->yofs_edit) @@ -1593,12 +1637,15 @@ get_line_xpos (EText *text, struct line *line) break; default: + if (text->draw_borders) + x += BORDER_INDENT; /* For GTK_JUSTIFY_LEFT, we don't have to do anything. We do not support * GTK_JUSTIFY_FILL, yet. */ break; } + return x; } @@ -1637,6 +1684,37 @@ e_text_draw (GnomeCanvasItem *item, GdkDrawable *drawable, canvas = GNOME_CANVAS_ITEM(text)->canvas; fg_gc = GTK_WIDGET(canvas)->style->fg_gc[text->has_selection ? GTK_STATE_SELECTED : GTK_STATE_ACTIVE]; + + if (text->draw_borders) { + gdouble thisx = 0, thisy = 0; + gdouble thiswidth, thisheight; + GtkWidget *widget = GTK_WIDGET(item->canvas); + gtk_paint_flat_box (widget->style, drawable, + GTK_WIDGET_STATE(widget), GTK_SHADOW_NONE, + NULL, widget, "entry_bg", + 0, 0, -1, -1); + + gtk_object_get(GTK_OBJECT(text), + "width", &thiswidth, + "height", &thisheight, + NULL); + if (text->editing) { + thisx += 1; + thisy += 1; + thiswidth -= 2; + thisheight -= 2; + } + gtk_paint_shadow (widget->style, drawable, + GTK_STATE_NORMAL, GTK_SHADOW_IN, + NULL, widget, "entry", + thisx - x, thisy - y, thiswidth, thisheight); + + if (text->editing) { + gtk_paint_focus (widget->style, drawable, + NULL, widget, "entry", + - x, - y, thiswidth + 1, thisheight + 1); + } + } if (!text->text || !text->font) return; @@ -1659,6 +1737,9 @@ e_text_draw (GnomeCanvasItem *item, GdkDrawable *drawable, clip_rect = ▭ } ypos = text->cy + text->font->ascent; + if (text->draw_borders) + ypos += BORDER_INDENT; + if (text->editing) ypos -= text->yofs_edit; @@ -2345,7 +2426,12 @@ _do_tooltip (gpointer data) NULL); - e_canvas_item_move_absolute(tooltip_text, 1, 1); + + if (text->draw_borders) + e_canvas_item_move_absolute(tooltip_text, 1 + BORDER_INDENT, 1 + BORDER_INDENT); + else + e_canvas_item_move_absolute(tooltip_text, 1, 1); + calc_height(E_TEXT(tooltip_text)); calc_line_widths(E_TEXT(tooltip_text)); @@ -2422,15 +2508,16 @@ _do_tooltip (gpointer data) #endif gnome_canvas_item_set(rect, - "x2", (double) tooltip_width + 4, - "y2", (double) tooltip_height + 4, + "x2", (double) tooltip_width + 4 + (text->draw_borders ? BORDER_INDENT * 2 : 0), + "y2", (double) tooltip_height + 4 + (text->draw_borders ? BORDER_INDENT * 2 : 0), NULL); gtk_widget_set_usize (text->tooltip_window, - tooltip_width + 4, - tooltip_height + 4); + tooltip_width + 4 + (text->draw_borders ? BORDER_INDENT * 2 : 0), + tooltip_height + 4 + (text->draw_borders ? BORDER_INDENT * 2 : 0)); gnome_canvas_set_scroll_region (GNOME_CANVAS(canvas), 0.0, 0.0, - tooltip_width, (double)tooltip_height); + tooltip_width + (text->draw_borders ? BORDER_INDENT * 2 : 0), + (double)tooltip_height + (text->draw_borders ? BORDER_INDENT * 2 : 0)); gtk_widget_show (canvas); gtk_widget_realize (text->tooltip_window); gtk_signal_connect (GTK_OBJECT(text->tooltip_window), "event", @@ -2889,6 +2976,7 @@ e_text_command(ETextEventProcessor *tep, ETextEventProcessorCommand *command, gp int x; int i; struct line *lines = text->lines; + gdouble clip_width; if ( !lines ) return; @@ -2908,8 +2996,15 @@ e_text_command(ETextEventProcessor *tep, ETextEventProcessorCommand *command, gp text->xofs_edit = x; } - if (2 + x - text->clip_width > text->xofs_edit) { - text->xofs_edit = 2 + x - text->clip_width; + clip_width = text->clip_width; + if (clip_width >= 0 && text->draw_borders) { + clip_width -= 6; + if (clip_width < 0) + clip_width = 0; + } + + if (2 + x - clip_width > text->xofs_edit) { + text->xofs_edit = 2 + x - clip_width; } if ((text->font->ascent + text->font->descent) * i < text->yofs_edit) diff --git a/widgets/text/e-text.h b/widgets/text/e-text.h index a233501293..125804cf72 100644 --- a/widgets/text/e-text.h +++ b/widgets/text/e-text.h @@ -68,6 +68,7 @@ BEGIN_GNOME_DECLS * line_wrap boolean RW Line wrap when not editing. * break_characters string RW List of characters to optionally break on. * max_lines int RW Number of lines possible when doing line wrap. + * draw_borders boolean RW Whether to draw borders. */ #define E_TYPE_TEXT (e_text_get_type ()) @@ -175,6 +176,7 @@ struct _EText { guint pointer_in : 1; /* Is the pointer currently over us? */ guint default_cursor_shown : 1; /* Is the default cursor currently shown? */ + guint draw_borders : 1; /* Draw borders? */ guint line_wrap : 1; /* Do line wrap */ gchar *break_characters; /* Characters to optionally break after */ |