*** empty log message ***
[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 enum MDeviceType
27   {
28     MDEVICE_SUPPORT_OUTPUT = 1,
29     MDEVICE_SUPPORT_INPUT = 2
30   };
31
32 typedef struct MRealizedFont MRealizedFont;
33 typedef struct MRealizedFace MRealizedFace;
34 typedef struct MRealizedFontset MRealizedFontset;
35 typedef struct MDeviceDriver MDeviceDriver;
36
37 /** Information about a frame.  */
38
39 struct MFrame
40 {
41   M17NObject control;
42
43   MSymbol foreground, background, videomode;
44
45   MFont *font;
46
47   /** The default face of the frame.  */
48   MFace *face;
49
50   /** The default realized face of the frame.  */
51   MRealizedFace *rface;
52
53   /** The default width of one-char space.  It is a width of SPACE
54       character of the default face.  */
55   int space_width;
56
57   /** The default ascent and descent of a line.  It is ascent and
58       descent of ASCII font of the default face.  */
59   int ascent, descent;
60
61   /** Initialized to 0 and incremented on each modification of a face
62       on which one of the realized faces is based.  */
63   unsigned tick;
64
65   /** Pointer to device dependent information associated with the
66       frame.  */
67   void *device;
68
69   /** The following members are set by "device_open" function of a
70       device dependent library.  */
71
72   /** Logical OR of enum MDeviceType.  */
73   int device_type;
74
75   /** Resolution (dots per inch) of the device.  */
76   int dpi;
77
78   /** Correction of functions to manipulate the device.  */
79   MDeviceDriver *driver;
80
81   /** List of font drivers.  */
82   MPlist *font_driver_list;
83
84   /** List of realized fonts.  */
85   MPlist *realized_font_list;
86
87   /** List of realized faces.  */
88   MPlist *realized_face_list;
89
90   /** List of realized fontsets.  */
91   MPlist *realized_fontset_list;
92 };
93
94 #define M_CHECK_WRITABLE(frame, err, ret)                       \
95   do {                                                          \
96     if (! ((frame)->device_type & MDEVICE_SUPPORT_OUTPUT))      \
97       MERROR ((err), (ret));                                    \
98   } while (0)
99
100 #define M_CHECK_READABLE(frame, err, ret)                       \
101   do {                                                          \
102     if (! ((frame)->device_type & MDEVICE_SUPPORT_INPUT))       \
103       MERROR ((err), (ret));                                    \
104   } while (0)
105
106 enum glyph_type
107   {
108     GLYPH_CHAR,
109     GLYPH_SPACE,
110     GLYPH_PAD,
111     GLYPH_BOX,
112     GLYPH_ANCHOR,
113     GLYPH_TYPE_MAX
114   };
115
116 enum glyph_category
117   {
118     GLYPH_CATEGORY_NORMAL,
119     GLYPH_CATEGORY_MODIFIER,
120     GLYPH_CATEGORY_FORMATTER
121   };
122
123 typedef struct
124 {
125   int pos, to;
126   int c;
127   unsigned code;
128   MRealizedFace *rface;
129   short width, ascent, descent, lbearing, rbearing;
130   short xoff, yoff;
131   unsigned enabled : 1;
132   unsigned left_padding : 1;
133   unsigned right_padding : 1;
134   unsigned otf_encoded : 1;
135   unsigned bidi_level : 6;
136   enum glyph_category category : 2;
137   enum glyph_type type : 3;
138   int combining_code;
139 } MGlyph;
140
141 struct MGlyphString
142 {
143   M17NObject head;
144
145   MFrame *frame;
146   int tick;
147
148   int size, inc, used;
149   MGlyph *glyphs;
150   int from, to;
151   short width, height, ascent, descent;
152   short physical_ascent, physical_descent, lbearing, rbearing;
153   short text_ascent, text_descent, line_ascent, line_descent;
154   int indent, width_limit;
155
156   /* Copied for <control>.anti_alias but never set if the frame's
157      depth is less than 8.  */
158   unsigned anti_alias : 1;
159
160   MDrawControl control;
161
162   struct MGlyphString *next, *top;
163 };
164
165 #define MGLYPH(idx)     \
166   (gstring->glyphs + ((idx) >= 0 ? (idx) : (gstring->used + (idx))))
167
168 #define GLYPH_INDEX(g)  \
169   ((g) - gstring->glyphs)
170
171 #define INIT_GLYPH(g)   \
172   (memset (&(g), 0, sizeof (g)))
173
174 #define APPEND_GLYPH(gstring, g)        \
175   MLIST_APPEND1 ((gstring), glyphs, (g), MERROR_DRAW)
176
177 #define INSERT_GLYPH(gstring, at, g)                            \
178   do {                                                          \
179     MLIST_INSERT1 ((gstring), glyphs, (at), 1, MERROR_DRAW);    \
180     (gstring)->glyphs[at] = g;                                  \
181   } while (0)
182
183 #define DELETE_GLYPH(gstring, at)               \
184   do {                                          \
185     MLIST_DELETE1 (gstring, glyphs, at, 1);     \
186   } while (0)
187
188 #define REPLACE_GLYPHS(gstring, from, to, len)                            \
189   do {                                                                    \
190     int newlen = (gstring)->used - (from);                                \
191     int diff = newlen - (len);                                            \
192                                                                           \
193     if (diff < 0)                                                         \
194       MLIST_DELETE1 (gstring, glyphs, (to) + newlen, -diff);              \
195     else if (diff > 0)                                                    \
196       MLIST_INSERT1 ((gstring), glyphs, (to) + (len), diff, MERROR_DRAW); \
197     memmove ((gstring)->glyphs + to, (gstring)->glyphs + (from + diff),   \
198              (sizeof (MGlyph)) * newlen);                                 \
199     (gstring)->used -= newlen;                                            \
200   } while (0)
201
202 #define MAKE_COMBINING_CODE(base_y, base_x, add_y, add_x, off_y, off_x) \
203   (((off_y) << 16)                                                      \
204    | ((off_x) << 8)                                                     \
205    | ((base_x) << 6)                                                    \
206    | ((base_y) << 4)                                                    \
207    | ((add_x) << 2)                                                     \
208    | (add_y))
209
210 #define COMBINING_CODE_OFF_Y(code) (((code) >> 16) & 0xFF)
211 #define COMBINING_CODE_OFF_X(code) (((code) >> 8) & 0xFF)
212 #define COMBINING_CODE_BASE_X(code) (((code) >> 6) & 0x3)
213 #define COMBINING_CODE_BASE_Y(code) (((code) >> 4) & 0x3)
214 #define COMBINING_CODE_ADD_X(code) (((code) >> 2) & 0x3)
215 #define COMBINING_CODE_ADD_Y(code) ((code) & 0x3)
216
217 #define MAKE_COMBINING_CODE_BY_CLASS(class) (0x1000000 | class)
218
219 #define COMBINING_BY_CLASS_P(code) ((code) & 0x1000000)
220
221 #define COMBINING_CODE_CLASS(code) ((code) & 0xFFFFFF)
222
223 #define MAKE_PRECOMPUTED_COMBINDING_CODE() (0x2000000)
224
225 #define COMBINING_PRECOMPUTED_P(code) ((code) & 0x2000000)
226
227 typedef struct MGlyphString MGlyphString;
228
229 typedef struct
230 {
231   short x, y;
232 } MDrawPoint;
233
234 struct MDeviceDriver
235 {
236   void (*close) (MFrame *frame);
237   void *(*get_prop) (MFrame *frame, MSymbol key);
238   void (*realize_face) (MRealizedFace *rface);
239   void (*free_realized_face) (MRealizedFace *rface);
240   void (*fill_space) (MFrame *frame, MDrawWindow win,
241                       MRealizedFace *rface, int reverse,
242                       int x, int y, int width, int height,
243                       MDrawRegion region);
244   void (*draw_empty_boxes) (MDrawWindow win, int x, int y,
245                             MGlyphString *gstring,
246                             MGlyph *from, MGlyph *to,
247                             int reverse, MDrawRegion region);
248   void (*draw_hline) (MFrame *frame, MDrawWindow win,
249                       MGlyphString *gstring,
250                       MRealizedFace *rface, int reverse,
251                       int x, int y, int width, MDrawRegion region);
252   void (*draw_box) (MFrame *frame, MDrawWindow win,
253                     MGlyphString *gstring,
254                     MGlyph *g, int x, int y, int width,
255                     MDrawRegion region);
256
257   void (*draw_points) (MFrame *frame, MDrawWindow win,
258                        MRealizedFace *rface,
259                        int intensity, MDrawPoint *points, int num,
260                        MDrawRegion region);
261   MDrawRegion (*region_from_rect) (MDrawMetric *rect);
262   void (*union_rect_with_region) (MDrawRegion region, MDrawMetric *rect);
263   void (*intersect_region) (MDrawRegion region1, MDrawRegion region2);
264   void (*region_add_rect) (MDrawRegion region, MDrawMetric *rect);
265   void (*region_to_rect) (MDrawRegion region, MDrawMetric *rect);
266   void (*free_region) (MDrawRegion region);
267   void (*dump_region) (MDrawRegion region);
268   MDrawWindow (*create_window) (MFrame *frame, MDrawWindow parent);
269   void (*destroy_window) (MFrame *frame, MDrawWindow win);
270   void (*map_window) (MFrame *frame, MDrawWindow win);
271   void (*unmap_window) (MFrame *frame, MDrawWindow win);
272   void (*window_geometry) (MFrame *frame, MDrawWindow win,
273                            MDrawWindow parent, MDrawMetric *geometry);
274   void (*adjust_window) (MFrame *frame, MDrawWindow win,
275                          MDrawMetric *current, MDrawMetric *new);
276   MSymbol (*parse_event) (MFrame *frame, void *arg, int *modifiers);
277 };
278
279 extern MSymbol Mlatin;
280
281 extern MSymbol Mgd;
282
283 extern int mfont__init ();
284 extern void mfont__fini ();
285
286 extern int mface__init ();
287 extern void mface__fini ();
288
289 extern int mdraw__init ();
290 extern void mdraw__fini ();
291
292 extern int mfont__fontset_init ();
293 extern void mfont__fontset_fini ();
294
295 extern int minput__win_init ();
296 extern void minput__win_fini ();
297
298 #endif /* _M_INTERNAL_GUI_H */