1 /* GTK - The GIMP Toolkit 2 * gtktextlayout.h 3 * 4 * Copyright (c) 1992-1994 The Regents of the University of California. 5 * Copyright (c) 1994-1997 Sun Microsystems, Inc. 6 * Copyright (c) 2000 Red Hat, Inc. 7 * Tk->Gtk port by Havoc Pennington 8 * Pango support by Owen Taylor 9 * 10 * This file can be used under your choice of two licenses, the LGPL 11 * and the original Tk license. 12 * 13 * LGPL: 14 * 15 * This library is free software; you can redistribute it and/or 16 * modify it under the terms of the GNU Lesser General Public 17 * License as published by the Free Software Foundation; either 18 * version 2 of the License, or (at your option) any later version. 19 * 20 * This library is distributed in the hope that it will be useful, 21 * but WITHOUT ANY WARRANTY; without even the implied warranty of 22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 23 * Lesser General Public License for more details. 24 * 25 * You should have received a copy of the GNU Lesser General Public 26 * License along with this library. If not, see <http://www.gnu.org/licenses/>. 27 * 28 * Original Tk license: 29 * 30 * This software is copyrighted by the Regents of the University of 31 * California, Sun Microsystems, Inc., and other parties. The 32 * following terms apply to all files associated with the software 33 * unless explicitly disclaimed in individual files. 34 * 35 * The authors hereby grant permission to use, copy, modify, 36 * distribute, and license this software and its documentation for any 37 * purpose, provided that existing copyright notices are retained in 38 * all copies and that this notice is included verbatim in any 39 * distributions. No written agreement, license, or royalty fee is 40 * required for any of the authorized uses. Modifications to this 41 * software may be copyrighted by their authors and need not follow 42 * the licensing terms described here, provided that the new terms are 43 * clearly indicated on the first page of each file where they apply. 44 * 45 * IN NO EVENT SHALL THE AUTHORS OR DISTRIBUTORS BE LIABLE TO ANY 46 * PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL 47 * DAMAGES ARISING OUT OF THE USE OF THIS SOFTWARE, ITS DOCUMENTATION, 48 * OR ANY DERIVATIVES THEREOF, EVEN IF THE AUTHORS HAVE BEEN ADVISED 49 * OF THE POSSIBILITY OF SUCH DAMAGE. 50 * 51 * THE AUTHORS AND DISTRIBUTORS SPECIFICALLY DISCLAIM ANY WARRANTIES, 52 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 53 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND 54 * NON-INFRINGEMENT. THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, 55 * AND THE AUTHORS AND DISTRIBUTORS HAVE NO OBLIGATION TO PROVIDE 56 * MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. 57 * 58 * GOVERNMENT USE: If you are acquiring this software on behalf of the 59 * U.S. government, the Government shall have only "Restricted Rights" 60 * in the software and related documentation as defined in the Federal 61 * Acquisition Regulations (FARs) in Clause 52.227.19 (c) (2). If you 62 * are acquiring the software on behalf of the Department of Defense, 63 * the software shall be classified as "Commercial Computer Software" 64 * and the Government shall have only "Restricted Rights" as defined 65 * in Clause 252.227-7013 (c) (1) of DFARs. Notwithstanding the 66 * foregoing, the authors grant the U.S. Government and others acting 67 * in its behalf permission to use and distribute the software in 68 * accordance with the terms specified in this license. 69 * 70 */ 71 /* 72 * Modified by the GTK+ Team and others 1997-2000. See the AUTHORS 73 * file for a list of people on the GTK+ Team. See the ChangeLog 74 * files for a list of changes. These files are distributed with 75 * GTK+ at ftp://ftp.gtk.org/pub/gtk/. 76 */ 77 78 #ifndef __GTK_TEXT_LAYOUT_H__ 79 #define __GTK_TEXT_LAYOUT_H__ 80 81 /* This is a "semi-private" header; it is intended for 82 * use by the text widget, and the text canvas item, 83 * but that’s all. We may have to install it so the 84 * canvas item can use it, but users are not supposed 85 * to use it. 86 */ 87 #ifndef GTK_TEXT_USE_INTERNAL_UNSUPPORTED_API 88 #error "You are not supposed to be including this file; the equivalent public API is in gtktextview.h" 89 #endif 90 91 #include <gtk/gtk.h> 92 93 G_BEGIN_DECLS 94 95 /* forward declarations that have to be here to avoid including 96 * gtktextbtree.h 97 */ 98 typedef struct _GtkTextLine GtkTextLine; 99 typedef struct _GtkTextLineData GtkTextLineData; 100 101 #define GTK_TYPE_TEXT_LAYOUT (gtk_text_layout_get_type ()) 102 #define GTK_TEXT_LAYOUT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_TEXT_LAYOUT, GtkTextLayout)) 103 #define GTK_TEXT_LAYOUT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GTK_TYPE_TEXT_LAYOUT, GtkTextLayoutClass)) 104 #define GTK_IS_TEXT_LAYOUT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_TEXT_LAYOUT)) 105 #define GTK_IS_TEXT_LAYOUT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GTK_TYPE_TEXT_LAYOUT)) 106 #define GTK_TEXT_LAYOUT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_TEXT_LAYOUT, GtkTextLayoutClass)) 107 108 typedef struct _GtkTextLayout GtkTextLayout; 109 typedef struct _GtkTextLayoutClass GtkTextLayoutClass; 110 typedef struct _GtkTextLineDisplay GtkTextLineDisplay; 111 typedef struct _GtkTextAttrAppearance GtkTextAttrAppearance; 112 113 struct _GtkTextLayout 114 { 115 GObject parent_instance; 116 117 /* width of the display area on-screen, 118 * i.e. pixels we should wrap to fit inside. */ 119 gint screen_width; 120 121 /* width/height of the total logical area being layed out */ 122 gint width; 123 gint height; 124 125 /* Pixel offsets from the left and from the top to be used when we 126 * draw; these allow us to create left/top margins. We don't need 127 * anything special for bottom/right margins, because those don't 128 * affect drawing. 129 */ 130 /* gint left_edge; */ 131 /* gint top_edge; */ 132 133 GtkTextBuffer *buffer; 134 135 gint left_padding; 136 gint right_padding; 137 138 /* Default style used if no tags override it */ 139 GtkTextAttributes *default_style; 140 141 /* Pango contexts used for creating layouts */ 142 PangoContext *ltr_context; 143 PangoContext *rtl_context; 144 145 /* A cache of one style; this is used to ensure 146 * we don't constantly regenerate the style 147 * over long runs with the same style. */ 148 GtkTextAttributes *one_style_cache; 149 150 /* A cache of one line display. Getting the same line 151 * many times in a row is the most common case. 152 */ 153 GtkTextLineDisplay *one_display_cache; 154 155 /* Whether we are allowed to wrap right now */ 156 gint wrap_loop_count; 157 158 /* Whether to show the insertion cursor */ 159 guint cursor_visible : 1; 160 161 /* For what GtkTextDirection to draw cursor GTK_TEXT_DIR_NONE - 162 * means draw both cursors. 163 */ 164 guint cursor_direction : 2; 165 166 /* The keyboard direction is used to default the alignment when 167 there are no strong characters. 168 */ 169 guint keyboard_direction : 2; 170 171 /* The preedit string and attributes, if any */ 172 173 gchar *preedit_string; 174 PangoAttrList *preedit_attrs; 175 gint preedit_len; 176 gint preedit_cursor; 177 178 guint overwrite_mode : 1; 179 }; 180 181 struct _GtkTextLayoutClass 182 { 183 GObjectClass parent_class; 184 185 /* Some portion of the layout was invalidated 186 */ 187 void (*invalidated) (GtkTextLayout *layout); 188 189 /* A range of the layout changed appearance and possibly height 190 */ 191 void (*changed) (GtkTextLayout *layout, 192 gint y, 193 gint old_height, 194 gint new_height); 195 GtkTextLineData* (*wrap) (GtkTextLayout *layout, 196 GtkTextLine *line, 197 GtkTextLineData *line_data); /* may be NULL */ 198 void (*get_log_attrs) (GtkTextLayout *layout, 199 GtkTextLine *line, 200 PangoLogAttr **attrs, 201 gint *n_attrs); 202 void (*invalidate) (GtkTextLayout *layout, 203 const GtkTextIter *start, 204 const GtkTextIter *end); 205 void (*free_line_data) (GtkTextLayout *layout, 206 GtkTextLine *line, 207 GtkTextLineData *line_data); 208 209 void (*allocate_child) (GtkTextLayout *layout, 210 GtkWidget *child, 211 gint x, 212 gint y); 213 214 void (*invalidate_cursors) (GtkTextLayout *layout, 215 const GtkTextIter *start, 216 const GtkTextIter *end); 217 218 /* Padding for future expansion */ 219 void (*_gtk_reserved1) (void); 220 void (*_gtk_reserved2) (void); 221 void (*_gtk_reserved3) (void); 222 }; 223 224 struct _GtkTextAttrAppearance 225 { 226 PangoAttribute attr; 227 GtkTextAppearance appearance; 228 }; 229 230 struct _GtkTextLineDisplay 231 { 232 PangoLayout *layout; 233 GArray *cursors; /* indexes of cursors in the PangoLayout */ 234 235 GtkTextDirection direction; 236 237 gint width; /* Width of layout */ 238 gint total_width; /* width - margins, if no width set on layout, if width set on layout, -1 */ 239 gint height; 240 /* Amount layout is shifted from left edge - this is the left margin 241 * plus any other factors, such as alignment or indentation. 242 */ 243 gint x_offset; 244 gint left_margin; 245 gint right_margin; 246 gint top_margin; 247 gint bottom_margin; 248 gint insert_index; /* Byte index of insert cursor within para or -1 */ 249 250 GtkTextLine *line; 251 252 GdkColor *pg_bg_color; 253 254 GdkRectangle block_cursor; 255 guint cursors_invalid : 1; 256 guint has_block_cursor : 1; 257 guint cursor_at_line_end : 1; 258 guint size_only : 1; 259 260 GdkRGBA *pg_bg_rgba; 261 }; 262 263 #ifdef GTK_COMPILATION 264 extern G_GNUC_INTERNAL PangoAttrType gtk_text_attr_appearance_type; 265 #endif 266 267 GDK_AVAILABLE_IN_ALL 268 GType gtk_text_layout_get_type (void) G_GNUC_CONST; 269 270 GDK_AVAILABLE_IN_ALL 271 GtkTextLayout* gtk_text_layout_new (void); 272 GDK_AVAILABLE_IN_ALL 273 void gtk_text_layout_set_buffer (GtkTextLayout *layout, 274 GtkTextBuffer *buffer); 275 GDK_AVAILABLE_IN_ALL 276 GtkTextBuffer *gtk_text_layout_get_buffer (GtkTextLayout *layout); 277 GDK_AVAILABLE_IN_ALL 278 void gtk_text_layout_set_default_style (GtkTextLayout *layout, 279 GtkTextAttributes *values); 280 GDK_AVAILABLE_IN_ALL 281 void gtk_text_layout_set_contexts (GtkTextLayout *layout, 282 PangoContext *ltr_context, 283 PangoContext *rtl_context); 284 GDK_AVAILABLE_IN_ALL 285 void gtk_text_layout_set_cursor_direction (GtkTextLayout *layout, 286 GtkTextDirection direction); 287 GDK_AVAILABLE_IN_ALL 288 void gtk_text_layout_set_overwrite_mode (GtkTextLayout *layout, 289 gboolean overwrite); 290 GDK_AVAILABLE_IN_ALL 291 void gtk_text_layout_set_keyboard_direction (GtkTextLayout *layout, 292 GtkTextDirection keyboard_dir); 293 GDK_AVAILABLE_IN_ALL 294 void gtk_text_layout_default_style_changed (GtkTextLayout *layout); 295 296 GDK_AVAILABLE_IN_ALL 297 void gtk_text_layout_set_screen_width (GtkTextLayout *layout, 298 gint width); 299 GDK_AVAILABLE_IN_ALL 300 void gtk_text_layout_set_preedit_string (GtkTextLayout *layout, 301 const gchar *preedit_string, 302 PangoAttrList *preedit_attrs, 303 gint cursor_pos); 304 305 GDK_AVAILABLE_IN_ALL 306 void gtk_text_layout_set_cursor_visible (GtkTextLayout *layout, 307 gboolean cursor_visible); 308 GDK_AVAILABLE_IN_ALL 309 gboolean gtk_text_layout_get_cursor_visible (GtkTextLayout *layout); 310 311 /* Getting the size or the lines potentially results in a call to 312 * recompute, which is pretty massively expensive. Thus it should 313 * basically only be done in an idle handler. 314 * 315 * Long-term, we would really like to be able to do these without 316 * a full recompute so they may get cheaper over time. 317 */ 318 GDK_AVAILABLE_IN_ALL 319 void gtk_text_layout_get_size (GtkTextLayout *layout, 320 gint *width, 321 gint *height); 322 GDK_AVAILABLE_IN_ALL 323 GSList* gtk_text_layout_get_lines (GtkTextLayout *layout, 324 /* [top_y, bottom_y) */ 325 gint top_y, 326 gint bottom_y, 327 gint *first_line_y); 328 329 GDK_AVAILABLE_IN_ALL 330 void gtk_text_layout_wrap_loop_start (GtkTextLayout *layout); 331 GDK_AVAILABLE_IN_ALL 332 void gtk_text_layout_wrap_loop_end (GtkTextLayout *layout); 333 334 GDK_AVAILABLE_IN_ALL 335 GtkTextLineDisplay* gtk_text_layout_get_line_display (GtkTextLayout *layout, 336 GtkTextLine *line, 337 gboolean size_only); 338 GDK_AVAILABLE_IN_ALL 339 void gtk_text_layout_free_line_display (GtkTextLayout *layout, 340 GtkTextLineDisplay *display); 341 342 GDK_AVAILABLE_IN_ALL 343 void gtk_text_layout_get_line_at_y (GtkTextLayout *layout, 344 GtkTextIter *target_iter, 345 gint y, 346 gint *line_top); 347 GDK_AVAILABLE_IN_ALL 348 gboolean gtk_text_layout_get_iter_at_pixel (GtkTextLayout *layout, 349 GtkTextIter *iter, 350 gint x, 351 gint y); 352 GDK_AVAILABLE_IN_ALL 353 gboolean gtk_text_layout_get_iter_at_position (GtkTextLayout *layout, 354 GtkTextIter *iter, 355 gint *trailing, 356 gint x, 357 gint y); 358 GDK_AVAILABLE_IN_ALL 359 void gtk_text_layout_invalidate (GtkTextLayout *layout, 360 const GtkTextIter *start, 361 const GtkTextIter *end); 362 GDK_AVAILABLE_IN_ALL 363 void gtk_text_layout_invalidate_cursors(GtkTextLayout *layout, 364 const GtkTextIter *start, 365 const GtkTextIter *end); 366 GDK_AVAILABLE_IN_ALL 367 void gtk_text_layout_free_line_data (GtkTextLayout *layout, 368 GtkTextLine *line, 369 GtkTextLineData *line_data); 370 371 GDK_AVAILABLE_IN_ALL 372 gboolean gtk_text_layout_is_valid (GtkTextLayout *layout); 373 GDK_AVAILABLE_IN_ALL 374 void gtk_text_layout_validate_yrange (GtkTextLayout *layout, 375 GtkTextIter *anchor_line, 376 gint y0_, 377 gint y1_); 378 GDK_AVAILABLE_IN_ALL 379 void gtk_text_layout_validate (GtkTextLayout *layout, 380 gint max_pixels); 381 382 /* This function should return the passed-in line data, 383 * OR remove the existing line data from the line, and 384 * return a NEW line data after adding it to the line. 385 * That is, invariant after calling the callback is that 386 * there should be exactly one line data for this view 387 * stored on the btree line. 388 */ 389 GDK_AVAILABLE_IN_ALL 390 GtkTextLineData* gtk_text_layout_wrap (GtkTextLayout *layout, 391 GtkTextLine *line, 392 GtkTextLineData *line_data); /* may be NULL */ 393 GDK_AVAILABLE_IN_ALL 394 void gtk_text_layout_changed (GtkTextLayout *layout, 395 gint y, 396 gint old_height, 397 gint new_height); 398 GDK_AVAILABLE_IN_ALL 399 void gtk_text_layout_cursors_changed (GtkTextLayout *layout, 400 gint y, 401 gint old_height, 402 gint new_height); 403 GDK_AVAILABLE_IN_ALL 404 void gtk_text_layout_get_iter_location (GtkTextLayout *layout, 405 const GtkTextIter *iter, 406 GdkRectangle *rect); 407 GDK_AVAILABLE_IN_ALL 408 void gtk_text_layout_get_line_yrange (GtkTextLayout *layout, 409 const GtkTextIter *iter, 410 gint *y, 411 gint *height); 412 GDK_AVAILABLE_IN_ALL 413 void gtk_text_layout_get_cursor_locations (GtkTextLayout *layout, 414 GtkTextIter *iter, 415 GdkRectangle *strong_pos, 416 GdkRectangle *weak_pos); 417 gboolean _gtk_text_layout_get_block_cursor (GtkTextLayout *layout, 418 GdkRectangle *pos); 419 GDK_AVAILABLE_IN_ALL 420 gboolean gtk_text_layout_clamp_iter_to_vrange (GtkTextLayout *layout, 421 GtkTextIter *iter, 422 gint top, 423 gint bottom); 424 425 GDK_AVAILABLE_IN_ALL 426 gboolean gtk_text_layout_move_iter_to_line_end (GtkTextLayout *layout, 427 GtkTextIter *iter, 428 gint direction); 429 GDK_AVAILABLE_IN_ALL 430 gboolean gtk_text_layout_move_iter_to_previous_line (GtkTextLayout *layout, 431 GtkTextIter *iter); 432 GDK_AVAILABLE_IN_ALL 433 gboolean gtk_text_layout_move_iter_to_next_line (GtkTextLayout *layout, 434 GtkTextIter *iter); 435 GDK_AVAILABLE_IN_ALL 436 void gtk_text_layout_move_iter_to_x (GtkTextLayout *layout, 437 GtkTextIter *iter, 438 gint x); 439 GDK_AVAILABLE_IN_ALL 440 gboolean gtk_text_layout_move_iter_visually (GtkTextLayout *layout, 441 GtkTextIter *iter, 442 gint count); 443 444 GDK_AVAILABLE_IN_ALL 445 gboolean gtk_text_layout_iter_starts_line (GtkTextLayout *layout, 446 const GtkTextIter *iter); 447 448 GDK_AVAILABLE_IN_ALL 449 void gtk_text_layout_get_iter_at_line (GtkTextLayout *layout, 450 GtkTextIter *iter, 451 GtkTextLine *line, 452 gint byte_offset); 453 454 /* Don't use these. Use gtk_text_view_add_child_at_anchor(). 455 * These functions are defined in gtktextchild.c, but here 456 * since they are semi-public and require GtkTextLayout to 457 * be declared. 458 */ 459 GDK_AVAILABLE_IN_ALL 460 void gtk_text_child_anchor_register_child (GtkTextChildAnchor *anchor, 461 GtkWidget *child, 462 GtkTextLayout *layout); 463 GDK_AVAILABLE_IN_ALL 464 void gtk_text_child_anchor_unregister_child (GtkTextChildAnchor *anchor, 465 GtkWidget *child); 466 467 GDK_AVAILABLE_IN_ALL 468 void gtk_text_child_anchor_queue_resize (GtkTextChildAnchor *anchor, 469 GtkTextLayout *layout); 470 471 GDK_AVAILABLE_IN_ALL 472 void gtk_text_anchored_child_set_layout (GtkWidget *child, 473 GtkTextLayout *layout); 474 475 GDK_AVAILABLE_IN_ALL 476 void gtk_text_layout_spew (GtkTextLayout *layout); 477 478 G_END_DECLS 479 480 #endif /* __GTK_TEXT_LAYOUT_H__ */ 481