c50d936f45ebadc8032d5a1598b353aaa94ee74d
[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   /** The default face of the frame.  */
45   MFace *face;
46
47   /** The default realized face of the frame.  */
48   MRealizedFace *rface;
49
50   /** The default width of one-char space.  It is a width of SPACE
51       character of the default face.  */
52   int space_width;
53
54   /** The default ascent and descent of a line.  It is ascent and
55       descent of ASCII font of the default face.  */
56   int ascent, descent;
57
58   /** The following three members are set by mwin__open_device ().  */
59
60   /** List of realized fonts.  */
61   MPlist *realized_font_list;
62
63   /** List of realized faces.  */
64   MPlist *realized_face_list;
65
66   /** List of realized fontsets.  */
67   MPlist *realized_fontset_list;
68 };
69
70 enum glyph_type
71   {
72     GLYPH_CHAR,
73     GLYPH_SPACE,
74     GLYPH_PAD,
75     GLYPH_BOX,
76     GLYPH_ANCHOR,
77     GLYPH_TYPE_MAX
78   };
79
80 struct MGlyph
81 {
82   int pos, to;
83   int c;
84   unsigned code;
85   MSymbol category;
86   MRealizedFace *rface;
87   short width, ascent, descent, lbearing, rbearing;
88   short xoff, yoff;
89   unsigned enabled : 1;
90   unsigned left_padding : 1;
91   unsigned right_padding : 1;
92   unsigned otf_encoded : 1;
93   unsigned bidi_level : 6;
94   enum glyph_type type : 3;
95   int combining_code;
96 };
97
98 typedef struct MGlyph MGlyph;
99
100 struct MGlyphString
101 {
102   M17NObject head;
103
104   int size, inc, used;
105   MGlyph *glyphs;
106   MText *mt;
107   int from, to;
108   short width, height, ascent, descent;
109   short physical_ascent, physical_descent, lbearing, rbearing;
110   short text_ascent, text_descent, line_ascent, line_descent;
111   int indent, width_limit;
112
113   /* Members to keep temporary data while layouting.  */
114   short sub_width, sub_lbearing, sub_rbearing;
115
116   MDrawControl control;
117
118   MDrawRegion region;
119
120   struct MGlyphString *next, *top;
121 };
122
123 #define MGLYPH(idx)     \
124   (gstring->glyphs + ((idx) >= 0 ? (idx) : (gstring->used + (idx))))
125
126 #define GLYPH_INDEX(g)  \
127   ((g) - gstring->glyphs)
128
129 #define INIT_GLYPH(g)   \
130   (memset (&(g), 0, sizeof (g)))
131
132 #define APPEND_GLYPH(gstring, g)        \
133   MLIST_APPEND1 ((gstring), glyphs, (g), MERROR_DRAW)
134
135 #define INSERT_GLYPH(gstring, at, g)                            \
136   do {                                                          \
137     MLIST_INSERT1 ((gstring), glyphs, (at), 1, MERROR_DRAW);    \
138     (gstring)->glyphs[at] = g;                                  \
139   } while (0)
140
141 #define DELETE_GLYPH(gstring, at)               \
142   do {                                          \
143     MLIST_DELETE1 (gstring, glyphs, at, 1);     \
144   } while (0)
145
146 #define REPLACE_GLYPHS(gstring, from, to, len)                            \
147   do {                                                                    \
148     int newlen = (gstring)->used - (from);                                \
149     int diff = newlen - (len);                                            \
150                                                                           \
151     if (diff < 0)                                                         \
152       MLIST_DELETE1 (gstring, glyphs, (to) + newlen, -diff);              \
153     else if (diff > 0)                                                    \
154       MLIST_INSERT1 ((gstring), glyphs, (to) + (len), diff, MERROR_DRAW); \
155     memmove ((gstring)->glyphs + to, (gstring)->glyphs + (from + diff),   \
156              (sizeof (MGlyph)) * newlen);                                 \
157     (gstring)->used -= newlen;                                            \
158   } while (0)
159
160 #define MAKE_COMBINING_CODE(base_y, base_x, add_y, add_x, off_y, off_x) \
161   (((off_y) << 16)                                                      \
162    | ((off_x) << 8)                                                     \
163    | ((base_x) << 6)                                                    \
164    | ((base_y) << 4)                                                    \
165    | ((add_x) << 2)                                                     \
166    | (add_y))
167
168 #define COMBINING_CODE_OFF_Y(code) (((code) >> 16) & 0xFF)
169 #define COMBINING_CODE_OFF_X(code) (((code) >> 8) & 0xFF)
170 #define COMBINING_CODE_BASE_X(code) (((code) >> 6) & 0x3)
171 #define COMBINING_CODE_BASE_Y(code) (((code) >> 4) & 0x3)
172 #define COMBINING_CODE_ADD_X(code) (((code) >> 2) & 0x3)
173 #define COMBINING_CODE_ADD_Y(code) ((code) & 0x3)
174
175 #define MAKE_COMBINING_CODE_BY_CLASS(class) (0x1000000 | class)
176
177 #define COMBINING_BY_CLASS_P(code) ((code) & 0x1000000)
178
179 #define COMBINING_CODE_CLASS(code) ((code) & 0xFFFFFF)
180
181 typedef struct MGlyphString MGlyphString;
182
183 typedef struct MFontDriver MFontDriver;
184
185 extern int mfont__init ();
186 extern void mfont__fini ();
187
188 extern int mface__init ();
189 extern void mface__fini ();
190
191 extern int mdraw__init ();
192 extern void mdraw__fini ();
193
194 extern int mfont__fontset_init ();
195 extern void mfont__fontset_fini ();
196
197 extern int minput__win_init ();
198 extern void minput__win_fini ();
199
200 extern int mwin__init ();
201 extern void mwin__fini ();
202
203 extern MWDevice *mwin__open_device (MFrame *frame, MPlist *plist);
204
205 extern void mwin__close_device (MFrame *frame);
206
207 extern void *mwin__device_get_prop (MWDevice *device, MSymbol key);
208
209 extern int mwin__parse_font_name (char *name, MFont *font);
210
211 extern char *mwin__build_font_name (MFont *font);
212
213 extern void mwin__realize_face (MRealizedFace *rface);
214
215 extern void mwin__free_realized_face (MRealizedFace *rface);
216
217 extern void mwin__fill_space (MFrame *frame, MDrawWindow win,
218                               MRealizedFace *rface, int reverse,
219                               int x, int y, int width, int height,
220                               MDrawRegion region);
221
222 extern void mwin__draw_hline (MFrame *frame, MDrawWindow win,
223                               MGlyphString *gstring,
224                               MRealizedFace *rface, int reverse,
225                               int x, int y, int width, MDrawRegion region);
226
227 extern void mwin__draw_box (MFrame *frame, MDrawWindow win,
228                             MGlyphString *gstring,
229                             MGlyph *g, int x, int y, int width,
230                             MDrawRegion region);
231
232 extern void mwin__draw_bitmap (MFrame *frame, MDrawWindow win,
233                                MRealizedFace *rface, int reverse,
234                                int x, int y,
235                                int width, int height, int row_bytes,
236                                unsigned char *bmp,
237                                MDrawRegion region);
238
239 extern MDrawRegion mwin__region_from_rect (MDrawMetric *rect);
240
241 extern void mwin__union_rect_with_region (MDrawRegion region,
242                                           MDrawMetric *rect);
243
244 extern void mwin__intersect_region (MDrawRegion region1, MDrawRegion region2);
245
246 extern void mwin__region_add_rect (MDrawRegion region, MDrawMetric *rect);
247
248 extern void mwin__region_to_rect (MDrawRegion region, MDrawMetric *rect);
249
250 extern void mwin__free_region (MDrawRegion region);
251
252 extern void mwin__verify_region (MFrame *frame, MDrawRegion region);
253
254 extern void mwin__dump_region (MDrawRegion region);
255
256 extern MDrawWindow mwin__create_window (MFrame *frame, MDrawWindow parent);
257
258 extern void mwin__destroy_window (MFrame *frame, MDrawWindow win);
259
260 #if 0
261 extern MDrawWindow mwin__event_window (void *event);
262
263 extern void mwin__print_event (void *event, char *win_name);
264 #endif
265
266 extern void mwin__map_window (MFrame *frame, MDrawWindow win);
267
268 extern void mwin__unmap_window (MFrame *frame, MDrawWindow win);
269
270 extern void mwin__window_geometry (MFrame *frame, MDrawWindow win,
271                                    MDrawWindow parent, MDrawMetric *geometry);
272
273 extern void mwin__adjust_window (MFrame *frame, MDrawWindow win,
274                                  MDrawMetric *current, MDrawMetric *new);
275
276 extern MSymbol mwin__parse_event (MFrame *frame, void *arg, int *modifiers);
277
278 #endif /* _M_INTERNAL_GUI_H */