1 /* 2 * e-text.h - Text item for evolution. 3 * 4 * This program is free software; you can redistribute it and/or modify it 5 * under the terms of the GNU Lesser General Public License as published by 6 * published by the Free Software Foundation; either the 7 * 8 * This program is distributed in the hope that it will be useful, but 9 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 10 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 11 * for more details. 12 * 13 * You should have received a copy of the GNU Lesser General Public License 14 * along with this program; if not, see <http://www.gnu.org/licenses/>. 15 * 16 * 17 * Authors: 18 * Chris Lahey <clahey@ximian.com> 19 * Jon Trowbridge <trow@ximian.com> 20 * 21 * A majority of code taken from: 22 * 23 * Text item type for GnomeCanvas widget 24 * 25 * GnomeCanvas is basically a port of the Tk toolkit's most excellent 26 * canvas widget. Tk is copyrighted by the Regents of the University 27 * of California, Sun Microsystems, and other parties. 28 * 29 * Copyright (C) 1998 The Free Software Foundation 30 * 31 * Author: Federico Mena <federico@nuclecu.unam.mx> 32 * 33 * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) 34 * 35 */ 36 37 #if !defined (__E_UTIL_H_INSIDE__) && !defined (LIBEUTIL_COMPILATION) 38 #error "Only <e-util/e-util.h> should be included directly." 39 #endif 40 41 #ifndef E_TEXT_H 42 #define E_TEXT_H 43 44 #include <gtk/gtk.h> 45 46 #include <e-util/e-canvas.h> 47 #include <e-util/e-text-event-processor.h> 48 #include <e-util/e-text-model.h> 49 50 /* Text item for the canvas. Text items are positioned by an anchor point and an anchor direction. 51 * 52 * A clipping rectangle may be specified for the text. The rectangle is anchored at the text's anchor 53 * point, and is specified by clipping width and height parameters. If the clipping rectangle is 54 * enabled, it will clip the text. 55 * 56 * In addition, x and y offset values may be specified. These specify an offset from the anchor 57 * position. If used in conjunction with the clipping rectangle, these could be used to implement 58 * simple scrolling of the text within the clipping rectangle. 59 * 60 * The following object arguments are available: 61 * 62 * name type read/write description 63 * ------------------------------------------------------------------------------------------ 64 * text string RW The string of the text label 65 * bold boolean RW Bold? 66 * justification GtkJustification RW Justification for multiline text 67 * fill_color string W X color specification for text 68 * fill_color_gdk GdkColor* RW Pointer to an allocated GdkColor 69 * clip_width gdouble RW Width of clip rectangle 70 * clip_height gdouble RW Height of clip rectangle 71 * clip boolean RW Use clipping rectangle? 72 * fill_clip_rect boolean RW Whether the text item represents itself as being the size of the clipping rectangle. 73 * x_offset gdouble RW Horizontal offset distance from anchor position 74 * y_offset gdouble RW Vertical offset distance from anchor position 75 * text_width gdouble R Used to query the width of the rendered text 76 * text_height gdouble R Used to query the rendered height of the text 77 * width gdouble RW A synonym for clip_width 78 * height gdouble R A synonym for text_height 79 * 80 * These are currently ignored in the AA version: 81 * editable boolean RW Can this item be edited 82 * use_ellipsis boolean RW Whether to use ellipsises if text gets cut off. Meaningless if clip == false. 83 * ellipsis string RW The characters to use as ellipsis. NULL = "...". 84 * line_wrap boolean RW Line wrap when not editing. 85 * break_characters string RW List of characters to optionally break on. 86 * max_lines gint RW Number of lines possible when doing line wrap. 87 */ 88 89 /* Standard GObject macros */ 90 #define E_TYPE_TEXT \ 91 (e_text_get_type ()) 92 #define E_TEXT(obj) \ 93 (G_TYPE_CHECK_INSTANCE_CAST \ 94 ((obj), E_TYPE_TEXT, EText)) 95 #define E_TEXT_CLASS(cls) \ 96 (G_TYPE_CHECK_CLASS_CAST \ 97 ((cls), E_TYPE_TEXT, ETextClass)) 98 #define E_IS_TEXT(obj) \ 99 (G_TYPE_CHECK_INSTANCE_TYPE \ 100 ((obj), E_TYPE_TEXT)) 101 #define E_IS_TEXT_CLASS(cls) \ 102 (G_TYPE_CHECK_CLASS_TYPE \ 103 ((cls), E_TYPE_TEXT)) 104 #define E_TEXT_GET_CLASS(obj) \ 105 (G_TYPE_INSTANCE_GET_CLASS \ 106 ((obj), E_TYPE_TEXT, ETextClass)) 107 108 G_BEGIN_DECLS 109 110 typedef struct _EText EText; 111 typedef struct _ETextClass ETextClass; 112 113 struct _EText { 114 GnomeCanvasItem item; 115 116 ETextModel *model; 117 gint model_changed_signal_id; 118 gint model_repos_signal_id; 119 120 const gchar *text; /* Text to display --- from the ETextModel */ 121 gint preedit_len; /* preedit length to display */ 122 gint preedit_pos; /* preedit cursor position */ 123 PangoLayout *layout; 124 gint num_lines; /* Number of lines of text */ 125 126 gchar *revert; /* Text to revert to */ 127 128 GtkJustification justification; /* Justification for text */ 129 130 gdouble clip_width; /* Width of optional clip rectangle */ 131 gdouble clip_height; /* Height of optional clip rectangle */ 132 133 gdouble xofs, yofs; /* Text offset distance from anchor position */ 134 135 gint cx, cy; /* Top-left canvas coordinates for text */ 136 gint text_cx, text_cy; /* Top-left canvas coordinates for text */ 137 gint clip_cx, clip_cy; /* Top-left canvas coordinates for clip rectangle */ 138 gint clip_cwidth, clip_cheight; /* Size of clip rectangle in pixels */ 139 gint max_width; /* Maximum width of text lines */ 140 gint width; /* Rendered text width in pixels */ 141 gint height; /* Rendered text height in pixels */ 142 143 guint32 rgba; /* RGBA color for text */ 144 gboolean rgba_set; /* whether RGBA is set */ 145 146 gchar *ellipsis; /* The ellipsis characters. NULL = "...". */ 147 gdouble ellipsis_width; /* The width of the ellipsis. */ 148 149 gint xofs_edit; /* Offset because of editing */ 150 gint yofs_edit; /* Offset because of editing */ 151 152 /* This needs to be reworked a bit once we get line wrapping. */ 153 gint selection_start; /* Start of selection IN BYTES */ 154 gint selection_end; /* End of selection IN BYTES */ 155 gboolean select_by_word; /* Current selection is by word */ 156 157 /* This section is for drag scrolling and blinking cursor. */ 158 gint timeout_id; /* Current timeout id for scrolling */ 159 GTimer *timer; /* Timer for blinking cursor and scrolling */ 160 161 gint lastx, lasty; /* Last x and y motion events */ 162 gint last_state; /* Last state */ 163 gulong scroll_start; /* Starting time for scroll (microseconds) */ 164 165 gint show_cursor; /* Is cursor currently shown */ 166 gboolean button_down; /* Is mouse button 1 down */ 167 168 ETextEventProcessor *tep; /* Text Event Processor */ 169 gint tep_command_id; 170 171 gboolean has_selection; /* TRUE if we have the selection */ 172 173 guint clip : 1; /* Use clip rectangle? */ 174 guint fill_clip_rectangle : 1; /* Fill the clipping rectangle. */ 175 176 guint pointer_in : 1; /* Is the pointer currently over us? */ 177 guint default_cursor_shown : 1; /* Is the default cursor currently shown? */ 178 179 guint line_wrap : 1; /* Do line wrap */ 180 181 guint needs_redraw : 1; /* Needs redraw */ 182 guint needs_recalc_bounds : 1; /* Need recalc_bounds */ 183 guint needs_calc_height : 1; /* Need calc_height */ 184 guint needs_split_into_lines : 1; /* Needs split_into_lines */ 185 guint needs_reset_layout : 1; /* Needs split_into_lines */ 186 187 guint bold : 1; 188 guint strikeout : 1; 189 guint italic : 1; 190 191 guint tooltip_owner : 1; 192 guint allow_newlines : 1; 193 194 guint use_ellipsis : 1; /* Whether to use the ellipsis. */ 195 196 guint editable : 1; /* Item is editable */ 197 guint editing : 1; /* Item is currently being edited */ 198 199 gchar *break_characters; /* Characters to optionally break after */ 200 201 gint max_lines; /* Max number of lines (-1 = infinite) */ 202 203 GdkCursor *default_cursor; /* Default cursor (arrow) */ 204 GdkCursor *i_cursor; /* I beam cursor */ 205 206 gint tooltip_timeout; /* Timeout for the tooltip */ 207 gint tooltip_count; /* GDK_ENTER_NOTIFY count. */ 208 209 gint dbl_timeout; /* Double click timeout */ 210 gint tpl_timeout; /* Triple click timeout */ 211 212 gint last_type_request; /* Last selection type requested. */ 213 guint32 last_time_request; /* The time of the last selection request. */ 214 GdkAtom last_selection_request; /* The time of the last selection request. */ 215 GList *queued_requests; /* Queued selection requests. */ 216 217 GtkIMContext *im_context; 218 gboolean need_im_reset; 219 gboolean im_context_signals_registered; 220 221 gboolean handle_popup; 222 223 PangoFontDescription *font_desc; 224 }; 225 226 struct _ETextClass { 227 GnomeCanvasItemClass parent_class; 228 229 void (*changed) (EText *text); 230 void (*activate) (EText *text); 231 void (*keypress) (EText *text, 232 guint keyval, 233 guint state); 234 void (*populate_popup) (EText *text, 235 GdkEvent *button_event, 236 gint pos, 237 GtkMenu *menu); 238 void (*style_updated) (EText *text); 239 }; 240 241 GType e_text_get_type (void) G_GNUC_CONST; 242 void e_text_cancel_editing (EText *text); 243 void e_text_stop_editing (EText *text); 244 void e_text_delete_selection (EText *text); 245 void e_text_cut_clipboard (EText *text); 246 void e_text_copy_clipboard (EText *text); 247 void e_text_paste_clipboard (EText *text); 248 void e_text_select_all (EText *text); 249 250 G_END_DECLS 251 252 #endif /* E_TEXT_H */ 253 254