Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.
 
 
 
 
 
 

440 rindas
19 KiB

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