diff options
author | Miguel de Icaza <miguel@helixcode.com> | 2000-12-25 06:28:17 +0800 |
---|---|---|
committer | Miguel de Icaza <miguel@src.gnome.org> | 2000-12-25 06:28:17 +0800 |
commit | ac6661ee1265683ac81f5a5306540572d8cc491c (patch) | |
tree | dcc0c0b277a6913ecc5b184bbae01705b74db627 /widgets/text | |
parent | d52ef16370370f59077bf209ae7dad639829495c (diff) | |
download | gsoc2013-evolution-ac6661ee1265683ac81f5a5306540572d8cc491c.tar gsoc2013-evolution-ac6661ee1265683ac81f5a5306540572d8cc491c.tar.gz gsoc2013-evolution-ac6661ee1265683ac81f5a5306540572d8cc491c.tar.bz2 gsoc2013-evolution-ac6661ee1265683ac81f5a5306540572d8cc491c.tar.lz gsoc2013-evolution-ac6661ee1265683ac81f5a5306540572d8cc491c.tar.xz gsoc2013-evolution-ac6661ee1265683ac81f5a5306540572d8cc491c.tar.zst gsoc2013-evolution-ac6661ee1265683ac81f5a5306540572d8cc491c.zip |
Handle draw background. (e_text_draw): Support both border drawing and
2000-12-24 Miguel de Icaza <miguel@helixcode.com>
* gal/e-text/e-text.c (e_text_set_arg): Handle draw background.
(e_text_draw): Support both border drawing and background drawing.
* gal/e-text/e-entry.c (et_get_arg, et_set_arg): Reduce code size by casting
once.
(et_set_arg, et_get_arg): Add ARG_DRAW_BORDERS handling.
svn path=/trunk/; revision=7159
Diffstat (limited to 'widgets/text')
-rw-r--r-- | widgets/text/e-entry.c | 107 | ||||
-rw-r--r-- | widgets/text/e-text.c | 47 | ||||
-rw-r--r-- | widgets/text/e-text.h | 2 |
3 files changed, 106 insertions, 50 deletions
diff --git a/widgets/text/e-entry.c b/widgets/text/e-entry.c index fdc08f4e20..0ae2803744 100644 --- a/widgets/text/e-entry.c +++ b/widgets/text/e-entry.c @@ -63,6 +63,7 @@ enum { ARG_BREAK_CHARACTERS, ARG_MAX_LINES, ARG_ALLOW_NEWLINES, + ARG_DRAW_BORDERS }; static void @@ -80,16 +81,25 @@ canvas_size_allocate (GtkWidget *widget, GtkAllocation *alloc, static void canvas_size_request (GtkWidget *widget, GtkRequisition *requisition, - EEntry *e_entry) + EEntry *ee) { + int border; + gboolean draw_borders = 0; + g_return_if_fail (widget != NULL); g_return_if_fail (GNOME_IS_CANVAS (widget)); g_return_if_fail (requisition != NULL); - requisition->width = MIN_ENTRY_WIDTH + (widget->style->klass->xthickness + INNER_BORDER) * 2; + gtk_object_get (GTK_OBJECT (ee->item), "draw_borders", &draw_borders, NULL); + if (draw_borders) + border = INNER_BORDER; + else + border = 0; + + requisition->width = MIN_ENTRY_WIDTH + (widget->style->klass->xthickness + border) * 2; requisition->height = (widget->style->font->ascent + widget->style->font->descent + - (widget->style->klass->ythickness + INNER_BORDER) * 2); + (widget->style->klass->ythickness + border) * 2); } static gint @@ -147,96 +157,104 @@ static void et_get_arg (GtkObject *o, GtkArg *arg, guint arg_id) { EEntry *ee = E_ENTRY (o); - + GtkObject *item = GTK_OBJECT (ee->item); + switch (arg_id){ case ARG_MODEL: - gtk_object_get(GTK_OBJECT(ee->item), + gtk_object_get(item, "model", >K_VALUE_OBJECT (*arg), NULL); break; case ARG_EVENT_PROCESSOR: - gtk_object_get(GTK_OBJECT(ee->item), + gtk_object_get(item, "event_processor", >K_VALUE_OBJECT (*arg), NULL); break; case ARG_TEXT: - gtk_object_get(GTK_OBJECT(ee->item), + gtk_object_get(item, "text", >K_VALUE_STRING (*arg), NULL); break; case ARG_FONT_GDK: - gtk_object_get(GTK_OBJECT(ee->item), + gtk_object_get(item, "font_gdk", >K_VALUE_BOXED (*arg), NULL); break; case ARG_JUSTIFICATION: - gtk_object_get(GTK_OBJECT(ee->item), + gtk_object_get(item, "justification", >K_VALUE_ENUM (*arg), NULL); break; case ARG_FILL_COLOR_GDK: - gtk_object_get(GTK_OBJECT(ee->item), + gtk_object_get(item, "fill_color_gdk", >K_VALUE_BOXED (*arg), NULL); break; case ARG_FILL_COLOR_RGBA: - gtk_object_get(GTK_OBJECT(ee->item), + gtk_object_get(item, "fill_color_rgba", >K_VALUE_UINT (*arg), NULL); break; case ARG_FILL_STIPPLE: - gtk_object_get(GTK_OBJECT(ee->item), + gtk_object_get(item, "fill_stiple", >K_VALUE_BOXED (*arg), NULL); break; case ARG_EDITABLE: - gtk_object_get(GTK_OBJECT(ee->item), + gtk_object_get(item, "editable", >K_VALUE_BOOL (*arg), NULL); break; case ARG_USE_ELLIPSIS: - gtk_object_get(GTK_OBJECT(ee->item), + gtk_object_get(item, "use_ellipsis", >K_VALUE_BOOL (*arg), NULL); break; case ARG_ELLIPSIS: - gtk_object_get(GTK_OBJECT(ee->item), + gtk_object_get(item, "ellipsis", >K_VALUE_STRING (*arg), NULL); break; case ARG_LINE_WRAP: - gtk_object_get(GTK_OBJECT(ee->item), + gtk_object_get(item, "line_wrap", >K_VALUE_BOOL (*arg), NULL); break; case ARG_BREAK_CHARACTERS: - gtk_object_get(GTK_OBJECT(ee->item), + gtk_object_get(item, "break_characters", >K_VALUE_STRING (*arg), NULL); break; case ARG_MAX_LINES: - gtk_object_get(GTK_OBJECT(ee->item), + gtk_object_get(item, "max_lines", >K_VALUE_INT (*arg), NULL); break; case ARG_ALLOW_NEWLINES: - gtk_object_get(GTK_OBJECT(ee->item), + gtk_object_get(item, "allow_newlines", >K_VALUE_BOOL (*arg), NULL); break; + + case ARG_DRAW_BORDERS: + gtk_object_get (item, + "draw_borders", >K_VALUE_BOOL (*arg), + NULL); + break; + default: arg->type = GTK_TYPE_INVALID; break; @@ -247,115 +265,128 @@ static void et_set_arg (GtkObject *o, GtkArg *arg, guint arg_id) { EEntry *ee = E_ENTRY (o); + GtkObject *item = GTK_OBJECT (ee->item); switch (arg_id){ case ARG_MODEL: - gtk_object_set(GTK_OBJECT(ee->item), + gtk_object_set(item, "model", GTK_VALUE_OBJECT (*arg), NULL); break; case ARG_EVENT_PROCESSOR: - gtk_object_set(GTK_OBJECT(ee->item), + gtk_object_set(item, "event_processor", GTK_VALUE_OBJECT (*arg), NULL); break; case ARG_TEXT: - gtk_object_set(GTK_OBJECT(ee->item), + gtk_object_set(item, "text", GTK_VALUE_STRING (*arg), NULL); break; case ARG_FONT: - gtk_object_set(GTK_OBJECT(ee->item), + gtk_object_set(item, "font", GTK_VALUE_STRING (*arg), NULL); break; case ARG_FONTSET: - gtk_object_set(GTK_OBJECT(ee->item), + gtk_object_set(item, "fontset", GTK_VALUE_STRING (*arg), NULL); break; case ARG_FONT_GDK: - gtk_object_set(GTK_OBJECT(ee->item), + gtk_object_set(item, "font_gdk", GTK_VALUE_BOXED (*arg), NULL); break; case ARG_JUSTIFICATION: - gtk_object_set(GTK_OBJECT(ee->item), + gtk_object_set(item, "justification", GTK_VALUE_ENUM (*arg), NULL); break; case ARG_FILL_COLOR: - gtk_object_set(GTK_OBJECT(ee->item), + gtk_object_set(item, "fill_color", GTK_VALUE_STRING (*arg), NULL); break; case ARG_FILL_COLOR_GDK: - gtk_object_set(GTK_OBJECT(ee->item), + gtk_object_set(item, "fill_color_gdk", GTK_VALUE_BOXED (*arg), NULL); break; case ARG_FILL_COLOR_RGBA: - gtk_object_set(GTK_OBJECT(ee->item), + gtk_object_set(item, "fill_color_rgba", GTK_VALUE_UINT (*arg), NULL); break; case ARG_FILL_STIPPLE: - gtk_object_set(GTK_OBJECT(ee->item), + gtk_object_set(item, "fill_stiple", GTK_VALUE_BOXED (*arg), NULL); break; case ARG_EDITABLE: - gtk_object_set(GTK_OBJECT(ee->item), + gtk_object_set(item, "editable", GTK_VALUE_BOOL (*arg), NULL); break; case ARG_USE_ELLIPSIS: - gtk_object_set(GTK_OBJECT(ee->item), + gtk_object_set(item, "use_ellipsis", GTK_VALUE_BOOL (*arg), NULL); break; case ARG_ELLIPSIS: - gtk_object_set(GTK_OBJECT(ee->item), + gtk_object_set(item, "ellipsis", GTK_VALUE_STRING (*arg), NULL); break; case ARG_LINE_WRAP: - gtk_object_set(GTK_OBJECT(ee->item), + gtk_object_set(item, "line_wrap", GTK_VALUE_BOOL (*arg), NULL); break; case ARG_BREAK_CHARACTERS: - gtk_object_set(GTK_OBJECT(ee->item), + gtk_object_set(item, "break_characters", GTK_VALUE_STRING (*arg), NULL); break; case ARG_MAX_LINES: - gtk_object_set(GTK_OBJECT(ee->item), + gtk_object_set(item, "max_lines", GTK_VALUE_INT (*arg), NULL); break; case ARG_ALLOW_NEWLINES: - gtk_object_set(GTK_OBJECT(ee->item), + gtk_object_set(item, "allow_newlines", GTK_VALUE_BOOL (*arg), NULL); break; + + case ARG_DRAW_BORDERS: { + gboolean draw_border; + gboolean need_queue; + + gtk_object_get (item, "draw_borders", &draw_border, NULL); + + need_queue = (draw_border ^ GTK_VALUE_BOOL (*arg)); + gtk_object_set (item, "draw_borders", GTK_VALUE_BOOL (*arg), NULL); + if (need_queue) + gtk_widget_queue_resize (GTK_WIDGET (ee)); + } } } @@ -426,6 +457,8 @@ e_entry_class_init (GtkObjectClass *object_class) GTK_TYPE_INT, GTK_ARG_READWRITE, ARG_MAX_LINES); gtk_object_add_arg_type ("EEntry::allow_newlines", GTK_TYPE_BOOL, GTK_ARG_READWRITE, ARG_ALLOW_NEWLINES); + gtk_object_add_arg_type ("EEntry::draw_borders", + GTK_TYPE_BOOL, GTK_ARG_READWRITE, ARG_DRAW_BORDERS); } E_MAKE_TYPE(e_entry, "EEntry", EEntry, e_entry_class_init, e_entry_init, PARENT_TYPE); diff --git a/widgets/text/e-text.c b/widgets/text/e-text.c index 2f1234f9c8..79499c71b7 100644 --- a/widgets/text/e-text.c +++ b/widgets/text/e-text.c @@ -86,6 +86,7 @@ enum { ARG_HEIGHT, ARG_DRAW_BORDERS, ARG_ALLOW_NEWLINES, + ARG_DRAW_BACKGROUND }; @@ -283,6 +284,8 @@ e_text_class_init (ETextClass *klass) GTK_TYPE_BOOL, GTK_ARG_READWRITE, ARG_DRAW_BORDERS); gtk_object_add_arg_type ("EText::allow_newlines", GTK_TYPE_BOOL, GTK_ARG_READWRITE, ARG_ALLOW_NEWLINES); + gtk_object_add_arg_type ("EText::draw_background", + GTK_TYPE_BOOL, GTK_ARG_READWRITE, ARG_DRAW_BORDERS); if (!clipboard_atom) clipboard_atom = gdk_atom_intern ("CLIPBOARD", FALSE); @@ -375,6 +378,8 @@ e_text_init (EText *text) text->dbl_timeout = 0; text->tpl_timeout = 0; + text->draw_background = 1; + e_canvas_item_set_reflow_callback(GNOME_CANVAS_ITEM(text), e_text_reflow); } @@ -1282,6 +1287,13 @@ e_text_set_arg (GtkObject *object, GtkArg *arg, guint arg_id) } break; + case ARG_DRAW_BACKGROUND: + if (text->draw_borders != GTK_VALUE_BOOL (*arg)){ + text->draw_background = GTK_VALUE_BOOL (*arg); + text->needs_redraw = 1; + } + break; + case ARG_ALLOW_NEWLINES: _get_tep(text); gtk_object_set (GTK_OBJECT (text->tep), @@ -1428,6 +1440,10 @@ e_text_get_arg (GtkObject *object, GtkArg *arg, guint arg_id) GTK_VALUE_BOOL (*arg) = text->draw_borders; break; + case ARG_DRAW_BACKGROUND: + GTK_VALUE_BOOL (*arg) = text->draw_background; + break; + case ARG_ALLOW_NEWLINES: { gboolean allow_newlines; @@ -1749,7 +1765,7 @@ e_text_draw (GnomeCanvasItem *item, GdkDrawable *drawable, fg_gc = GTK_WIDGET(canvas)->style->fg_gc[text->has_selection ? GTK_STATE_SELECTED : GTK_STATE_ACTIVE]; - if (text->draw_borders) { + if (text->draw_borders || text->draw_background) { gdouble thisx = 0, thisy = 0; gdouble thiswidth, thisheight; GtkWidget *widget = GTK_WIDGET(item->canvas); @@ -1758,25 +1774,30 @@ e_text_draw (GnomeCanvasItem *item, GdkDrawable *drawable, "width", &thiswidth, "height", &thisheight, NULL); - gtk_paint_flat_box (widget->style, drawable, - GTK_WIDGET_STATE(widget), GTK_SHADOW_NONE, - NULL, widget, "entry_bg", - 0, 0, thiswidth, thisheight); + + if (text->draw_background) + gtk_paint_flat_box (widget->style, drawable, + GTK_WIDGET_STATE(widget), GTK_SHADOW_NONE, + NULL, widget, "entry_bg", + 0, 0, thiswidth, thisheight); 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->draw_borders){ + 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->editing) { + gtk_paint_focus (widget->style, drawable, + NULL, widget, "entry", + - x, - y, thiswidth + 1, thisheight + 1); + } } } diff --git a/widgets/text/e-text.h b/widgets/text/e-text.h index fca7578079..5a1e843b7d 100644 --- a/widgets/text/e-text.h +++ b/widgets/text/e-text.h @@ -70,6 +70,7 @@ BEGIN_GNOME_DECLS * 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. + * draw_background boolean RW Whether to draw the background. */ #define E_TYPE_TEXT (e_text_get_type ()) @@ -187,6 +188,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 draw_background : 1; /* Draw background? */ guint line_wrap : 1; /* Do line wrap */ gchar *break_characters; /* Characters to optionally break after */ |