(struct MFrame): New member tick.
[m17n/m17n-lib.git] / src / internal-gui.h
1 /* internal-gui.h -- common header file for the internal GUI API.
2    Copyright (C) 2003, 2004
3      National Institute of Advanced Industrial Science and Technology (AIST)
4      Registration Number H15PRO112
5
6    This file is part of the m17n library.
7
8    The m17n library is free software; you can redistribute it and/or
9    modify it under the terms of the GNU Lesser General Public License
10    as published by the Free Software Foundation; either version 2.1 of
11    the License, or (at your option) any later version.
12
13    The m17n library is distributed in the hope that it will be useful,
14    but WITHOUT ANY WARRANTY; without even the implied warranty of
15    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16    Lesser General Public License for more details.
17
18    You should have received a copy of the GNU Lesser General Public
19    License along with the m17n library; if not, write to the Free
20    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
21    02111-1307, USA.  */
22
23 #ifndef _M_INTERNAL_GUI_H
24 #define _M_INTERNAL_GUI_H
25
26 typedef struct MWDevice MWDevice;
27
28 extern MSymbol Mfont;
29
30 typedef struct MRealizedFont MRealizedFont;
31 typedef struct MRealizedFace MRealizedFace;
32 typedef struct MRealizedFontset MRealizedFontset;
33
34 /** Information about a frame.  */
35
36 struct MFrame
37 {
38   M17NObject control;
39
40   /** Pointer to a window-system dependent device object associated
41       with the frame.  */
42   MWDevice *device;
43
44   MSymbol foreground, background, videomode;
45
46   MFont *font;
47
48   /** The default face of the frame.  */
49   MFace *face;
50
51   /** The default realized face of the frame.  */
52   MRealizedFace *rface;
53
54   /** The default width of one-char space.  It is a width of SPACE
55       character of the default face.  */
56   int space_width;
57
58   /** The default ascent and descent of a line.  It is ascent and
59       descent of ASCII font of the default face.  */
60   int ascent, descent;
61
62   /** The following three members are set by mwin__open_device ().  */
63
64   /** List of realized fonts.  */
65   MPlist *realized_font_list;
66
67   /** List of realized faces.  */
68   MPlist *realized_face_list;
69
70   /** List of realized fontsets.  */
71   MPlist *realized_fontset_list;
72
73   /** Initialized to 0 and incremented on each modification of a face
74       on which one of the realized faces is based.  */
75   unsigned tick;
76 };
77
78 enum glyph_type
79   {
80     GLYPH_CHAR,
81     GLYPH_SPACE,
82     GLYPH_PAD,
83     GLYPH_BOX,
84     GLYPH_ANCHOR,
85     GLYPH_TYPE_MAX
86   };
87
88 typedef struct
89 {
90   int pos, to;
91   int c;
92   unsigned code;
93   MSymbol category;
94   MRealizedFace *rface;
95   short width, ascent, descent, lbearing, rbearing;
96   short xoff, yoff;
97   unsigned enabled : 1;
98   unsigned left_padding : 1;
99   unsigned right_padding : 1;
100   unsigned otf_encoded : 1;
101   unsigned bidi_level : 6;
102   enum glyph_type type : 3;
103   int combining_code;
104 } MGlyph;
105
106 struct MGlyphString
107 {
108   M17NObject head;
109
110   MFrame *frame;
111   int tick;
112
113   int size, inc, used;
114   MGlyph *glyphs;
115   MText *mt;
116   int from, to;
117   short width, height, ascent, descent;
118   short physical_ascent, physical_descent, lbearing, rbearing;
119   short text_ascent, text_descent, line_ascent, line_descent;
120   int indent, width_limit;
121
122   /* Members to keep temporary data while layouting.  */
123   short sub_width, sub_lbearing, sub_rbearing;
124
125   /* Copied for <control>.anti_alias but never set if the frame's
126      depth is less than 8.  */
127   unsigned anti_alias : 1;
128
129   MDrawControl control;
130
131   MDrawRegion region;
132
133   struct MGlyphString *next, *top;
134 };
135
136 #define MGLYPH(idx)     \
137   (gstring->glyphs + ((idx) >= 0 ? (idx) : (gstring->used + (idx))))
138
139 #define GLYPH_INDEX(g)  \
140   ((g) - gstring->glyphs)
141
142 #define INIT_GLYPH(g)   \
143   (memset (&(g), 0, sizeof (g)))
144
145 #define APPEND_GLYPH(gstring, g)        \
146   MLIST_APPEND1 ((gstring), glyphs, (g), MERROR_DRAW)
147
148 #define INSERT_GLYPH(gstring, at, g)                            \
149   do {                                                          \
150     MLIST_INSERT1 ((gstring), glyphs, (at), 1, MERROR_DRAW);    \
151     (gstring)->glyphs[at] = g;                                  \
152   } while (0)
153
154 #define DELETE_GLYPH(gstring, at)               \
155   do {                                          \
156     MLIST_DELETE1 (gstring, glyphs, at, 1);     \
157   } while (0)
158
159 #define REPLACE_GLYPHS(gstring, from, to, len)                            \
160   do {                                                                    \
161     int newlen = (gstring)->used - (from);                                \
162     int diff = newlen - (len);                                            \
163                                                                           \
164     if (diff < 0)                                                         \
165       MLIST_DELETE1 (gstring, glyphs, (to) + newlen, -diff);              \
166     else if (diff > 0)                                                    \
167       MLIST_INSERT1 ((gstring), glyphs, (to) + (len), diff, MERROR_DRAW); \
168     memmove ((gstring)->glyphs + to, (gstring)->glyphs + (from + diff),   \
169              (sizeof (MGlyph)) * newlen);                                 \
170     (gstring)->used -= newlen;                                            \
171   } while (0)
172
173 #define MAKE_COMBINING_CODE(base_y, base_x, add_y, add_x, off_y, off_x) \
174   (((off_y) << 16)                                                      \
175    | ((off_x) << 8)                                                     \
176    | ((base_x) << 6)                                                    \
177    | ((base_y) << 4)                                                    \
178    | ((add_x) << 2)                                                     \
179    | (add_y))
180
181 #define COMBINING_CODE_OFF_Y(code) (((code) >> 16) & 0xFF)
182 #define COMBINING_CODE_OFF_X(code) (((code) >> 8) & 0xFF)
183 #define COMBINING_CODE_BASE_X(code) (((code) >> 6) & 0x3)
184 #define COMBINING_CODE_BASE_Y(code) (((code) >> 4) & 0x3)
185 #define COMBINING_CODE_ADD_X(code) (((code) >> 2) & 0x3)
186 #define COMBINING_CODE_ADD_Y(code) ((code) & 0x3)
187
188 #define MAKE_COMBINING_CODE_BY_CLASS(class) (0x1000000 | class)
189
190 #define COMBINING_BY_CLASS_P(code) ((code) & 0x1000000)
191
192 #define COMBINING_CODE_CLASS(code) ((code) & 0xFFFFFF)
193
194 typedef struct MGlyphString MGlyphString;
195
196 typedef struct MFontDriver MFontDriver;
197
198 typedef struct
199 {
200   short x, y;
201 } MDrawPoint;
202
203 extern int mfont__init ();
204 extern void mfont__fini ();
205
206 extern int mface__init ();
207 extern void mface__fini ();
208
209 extern int mdraw__init ();
210 extern void mdraw__fini ();
211
212 extern int mfont__fontset_init ();
213 extern void mfont__fontset_fini ();
214
215 extern int minput__win_init ();
216 extern void minput__win_fini ();
217
218 extern int mwin__init ();
219 extern void mwin__fini ();
220
221 extern MWDevice *mwin__open_device (MFrame *frame, MPlist *plist);
222
223 extern void mwin__close_device (MFrame *frame);
224
225 extern void *mwin__device_get_prop (MWDevice *device, MSymbol key);
226
227 extern int mwin__parse_font_name (char *name, MFont *font);
228
229 extern char *mwin__build_font_name (MFont *font);
230
231 extern void mwin__realize_face (MRealizedFace *rface);
232
233 extern void mwin__free_realized_face (MRealizedFace *rface);
234
235 extern void mwin__fill_space (MFrame *frame, MDrawWindow win,
236                               MRealizedFace *rface, int reverse,
237                               int x, int y, int width, int height,
238                               MDrawRegion region);
239
240 extern void mwin__draw_rect (MFrame *frame, MDrawWindow win,
241                              MRealizedFace *face,
242                              int x, int y, int width, int height,
243                              MDrawRegion region);
244
245 extern void mwin__draw_empty_boxes (MDrawWindow win, int x, int y,
246                                     MGlyphString *gstring,
247                                     MGlyph *from, MGlyph *to,
248                                     int reverse, MDrawRegion region);
249
250 extern void mwin__draw_hline (MFrame *frame, MDrawWindow win,
251                               MGlyphString *gstring,
252                               MRealizedFace *rface, int reverse,
253                               int x, int y, int width, MDrawRegion region);
254
255 extern void mwin__draw_box (MFrame *frame, MDrawWindow win,
256                             MGlyphString *gstring,
257                             MGlyph *g, int x, int y, int width,
258                             MDrawRegion region);
259
260 extern void mwin__draw_points (MFrame *frame, MDrawWindow win,
261                                MRealizedFace *rface,
262                                int intensity, MDrawPoint *points, int num,
263                                MDrawRegion region);
264
265 extern MDrawRegion mwin__region_from_rect (MDrawMetric *rect);
266
267 extern void mwin__union_rect_with_region (MDrawRegion region,
268                                           MDrawMetric *rect);
269
270 extern void mwin__intersect_region (MDrawRegion region1, MDrawRegion region2);
271
272 extern void mwin__region_add_rect (MDrawRegion region, MDrawMetric *rect);
273
274 extern void mwin__region_to_rect (MDrawRegion region, MDrawMetric *rect);
275
276 extern void mwin__free_region (MDrawRegion region);
277
278 extern void mwin__verify_region (MFrame *frame, MDrawRegion region);
279
280 extern void mwin__dump_region (MDrawRegion region);
281
282 extern MDrawWindow mwin__create_window (MFrame *frame, MDrawWindow parent);
283
284 extern void mwin__destroy_window (MFrame *frame, MDrawWindow win);
285
286 #if 0
287 extern MDrawWindow mwin__event_window (void *event);
288
289 extern void mwin__print_event (void *event, char *win_name);
290 #endif
291
292 extern void mwin__map_window (MFrame *frame, MDrawWindow win);
293
294 extern void mwin__unmap_window (MFrame *frame, MDrawWindow win);
295
296 extern void mwin__window_geometry (MFrame *frame, MDrawWindow win,
297                                    MDrawWindow parent, MDrawMetric *geometry);
298
299 extern void mwin__adjust_window (MFrame *frame, MDrawWindow win,
300                                  MDrawMetric *current, MDrawMetric *new);
301
302 extern MSymbol mwin__parse_event (MFrame *frame, void *arg, int *modifiers);
303
304 #endif /* _M_INTERNAL_GUI_H */