2006-12-05 David Lodge <dave@cirt.net>
[dia.git] / lib / text.h
blobfcb69e942525736c86564431ac9bb35e0714f8a4
1 /* Dia -- an diagram creation/manipulation program
2 * Copyright (C) 1998 Alexander Larsson
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 #ifndef TEXT_H
19 #define TEXT_H
21 typedef enum {
22 TEXT_EDIT_START,
23 TEXT_EDIT_CHANGE,
24 TEXT_EDIT_END
25 } TextEditState;
27 #include <glib.h>
28 #include "diatypes.h"
29 #include "textattr.h"
30 #include "focus.h"
31 #include "properties.h"
33 #define USE_TEXTLINE_FOR_LINES
35 struct _Text {
36 /** The object that owns this text. */
37 DiaObject *parent_object;
38 /* don't change these values directly, use the text_set* functions */
40 /* Text data: */
41 int numlines;
42 TextLine **lines;
43 int *strlen; /* in characters */
45 /* Attributes: */
46 DiaFont *font;
47 real height;
48 Point position;
49 Color color;
50 Alignment alignment;
52 /* Cursor pos: */
53 int cursor_pos;
54 int cursor_row;
55 Focus focus;
57 /* Computed values: */
58 real ascent; /* **average** ascent */
59 real descent; /* **average** descent */
60 real max_width;
64 /* makes an internal copy of the string */
65 Text *new_text(const char *string, DiaFont *font, real height,
66 Point *pos, Color *color, Alignment align);
67 void text_destroy(Text *text);
68 Text *text_copy(Text *text);
69 gchar *text_get_line(Text *text, int line);
70 char *text_get_string_copy(Text *text);
71 void text_set_string(Text *text, const char *string);
72 void text_set_height(Text *text, real height);
73 void text_set_font(Text *text, DiaFont *font);
74 void text_set_position(Text *text, Point *pos);
75 void text_set_color(Text *text, Color *col);
76 void text_set_alignment(Text *text, Alignment align);
77 real text_distance_from(Text *text, Point *point);
78 void text_calc_boundingbox(Text *text, Rectangle *box);
79 void text_draw(Text *text, DiaRenderer *renderer);
80 void text_set_cursor(Text *text, Point *clicked_point,
81 DiaRenderer *interactive_renderer);
82 void text_set_cursor_at_end( Text* text );
83 void text_grab_focus(Text *text, DiaObject *object);
84 int text_is_empty(Text *text);
85 int text_delete_all(Text *text, ObjectChange **change);
86 void text_get_attributes(Text *text, TextAttributes *attr);
87 void text_set_attributes(Text *text, TextAttributes *attr);
89 real text_get_line_width(Text *text, int line_no);
90 int text_get_line_strlen(Text *text, int line_no);
91 real text_get_max_width(Text *text);
92 real text_get_ascent(Text *text);
93 real text_get_descent(Text *text);
95 void data_add_text(AttributeNode attr, Text *text);
96 Text *data_text(AttributeNode attr);
98 gboolean apply_textattr_properties(GPtrArray *props,
99 Text *text, const gchar *textname,
100 TextAttributes *attrs);
101 gboolean apply_textstr_properties(GPtrArray *props,
102 Text *text, const gchar *textname,
103 const gchar *str);
104 #endif /* TEXT_H */