*** empty log message ***
[m17n/m17n-lib.git] / src / m17n-gui.c
1 /* m17n-gui.c -- body of the 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 /***en
24     @addtogroup m17nGUI
25     @brief GUI support for a window system.
26
27     This section defines the m17n GUI API concerning M-text drawing
28     and inputting under a window system.
29
30     All the definitions here are independent of window systems.  An
31     actual library file, however, can depend on a specific window
32     system.  For instance, the library file m17n-X.so is an example of
33     implementation of the m17n GUI API for the X Window System.
34
35     Actually the GUI API is mainly for toolkit libraries or to
36     implement XOM, not for direct use from application programs.
37 */
38
39 /***ja
40     @addtogroup m17nGUI
41     @brief ¥¦¥£¥ó¥É¥¦¥·¥¹¥Æ¥à¾å¤Î GUI ¥µ¥Ý¡¼¥È.
42
43     ¤³¤Î¥»¥¯¥·¥ç¥ó¤Ï¥¦¥£¥ó¥É¥¦¥·¥¹¥Æ¥à¤Î¤â¤È¤Ç¤Î M-text ¤Îɽ¼¨¤ÈÆþÎϤˤ«¤«¤ï¤ë
44     m17n GUI API ¤òÄêµÁ¤¹¤ë¡£
45
46     ¤³¤³¤Ç¤Î¤¹¤Ù¤Æ¤ÎÄêµÁ¤Ï¥¦¥£¥ó¥É¥¦¥·¥¹¥Æ¥à¤È¤ÏÆÈΩ¤Ç¤¢¤ë¡£
47     ¤·¤«¤·¡¢¼ÂºÝ¤Î¥é¥¤¥Ö¥é¥ê¥Õ¥¡¥¤¥ë¤Ï¸ÄÊ̤Υ¦¥£¥ó¥É¥¦¥·¥¹¥Æ¥à¤Ë°Í¸¤¹¤ë¾ì¹ç¤¬¤¢¤ë¡£
48     ¤¿¤È¤¨¤Ð¥é¥¤¥Ö¥é¥ê¥Õ¥¡¥¤¥ë m17n-X.so ¤Ï¡¢m17n GUI API ¤Î X 
49     ¥¦¥£¥ó¥É¥¦ÍѤμÂÁõÎã¤Ç¤¢¤ë¡£
50
51     ¸½¼Â¤Ë¤Ï¡¢GUI API ¤Ï¼ç¤Ë¥Ä¡¼¥ë¥­¥Ã¥È¥é¥¤¥Ö¥é¥ê¸þ¤±¤Ç¤¢¤ë¤«¡¢¤Þ¤¿¤Ï 
52     XOM ¤ò¼ÂÁõ¤¹¤ë¤¿¤á¤ËÍѤ¤¤é¤ì¤Æ¤ª¤ê¡¢¥¢¥×¥ê¥±¡¼¥·¥ç¥ó¥×¥í¥°¥é¥à¤«¤é¤ÎľÀܤÎÍøÍѤòǰƬ¤Ë¤ª¤¤¤¿¤â¤Î¤Ç¤Ï¤Ê¤¤¡£
53 */
54
55 /*=*/
56
57 #if !defined (FOR_DOXYGEN) || defined (DOXYGEN_INTERNAL_MODULE)
58 /*** @addtogroup m17nInternal
59      @{ */
60
61 #include "config.h"
62
63 #include <stdio.h>
64 #include <string.h>
65 #include <stdlib.h>
66
67 #include "config.h"
68 #ifdef HAVE_DLFCN_H
69 #include <dlfcn.h>
70 #endif
71
72 #include "m17n-gui.h"
73 #include "m17n-misc.h"
74 #include "internal.h"
75 #include "plist.h"
76 #include "internal-gui.h"
77 #include "font.h"
78 #include "fontset.h"
79 #include "face.h"
80
81 #ifndef DLOPEN_SHLIB_EXT
82 #define DLOPEN_SHLIB_EXT ".so"
83 #endif
84
85 /** Information about a dynamic library supporting a specific graphic
86     device.  */
87 typedef struct
88 {
89   /** Name of the dynamic library (e.g. "libm17n-X.so").  */
90   char *library;
91   /** Handle fo the dynamic library.  */
92   void *handle;
93   /** Function to call just after loading the library.  */
94   int (*init) ();
95   /** Function to call to open a frame on the graphic device.  */
96   int (*open) (MFrame *frame, MPlist *param);
97   /** Function to call just before unloading the library.  */
98   int (*fini) ();
99 } MDeviceLibraryInterface;
100
101
102 /** Plist of device symbol vs MDeviceLibraryInterface.  */
103
104 static MPlist *device_library_list;
105
106 /** Close MFrame and free it.  */
107
108 static void
109 free_frame (void *object)
110 {
111   MFrame *frame = (MFrame *) object;
112
113   (*frame->driver->close) (frame);
114   M17N_OBJECT_UNREF (frame->face);
115   free (frame->font);
116   M17N_OBJECT_UNREF (frame->font_driver_list);
117   free (object);
118 }
119
120
121 /** Register a dynamic library of name LIB by a key NAME.  */
122
123 static int
124 register_device_library (MSymbol name, char *lib)
125 {
126   MDeviceLibraryInterface *interface;
127
128   MSTRUCT_CALLOC (interface, MERROR_WIN);
129   interface->library = malloc (strlen (lib) 
130                                + strlen (DLOPEN_SHLIB_EXT) + 1);
131   sprintf (interface->library, "%s%s", lib, DLOPEN_SHLIB_EXT);
132   if (! device_library_list)
133     device_library_list = mplist ();
134   mplist_add (device_library_list, name, interface);
135   return 0;
136 }
137
138 \f
139 #ifdef HAVE_FREETYPE
140 /** Null device support.  */
141
142 static struct {
143   MPlist *realized_fontset_list;
144   MPlist *realized_font_list;
145   MPlist *realized_face_list;
146 } null_device;
147
148 static void
149 null_device_close (MFrame *frame)
150 {
151 }
152
153 static void *
154 null_device_get_prop (MFrame *frame, MSymbol key)
155 {
156   return NULL;
157 }
158
159 static void
160 null_device_realize_face (MRealizedFace *rface)
161 {
162   rface->info = NULL;
163 }
164
165 static void
166 null_device_free_realized_face (MRealizedFace *rface)
167 {
168 }
169
170 static MDeviceDriver null_driver =
171   {
172     null_device_close,
173     null_device_get_prop,
174     null_device_realize_face,
175     null_device_free_realized_face
176   };
177
178 static int
179 null_device_init ()
180 {
181   null_device.realized_fontset_list = mplist ();
182   null_device.realized_font_list = mplist ();
183   null_device.realized_face_list = mplist ();  
184   return 0;
185 }
186
187 static int
188 null_device_fini ()
189 {
190   MPlist *plist;
191
192   MPLIST_DO (plist, null_device.realized_fontset_list)
193     mfont__free_realized_fontset ((MRealizedFontset *) MPLIST_VAL (plist));
194   M17N_OBJECT_UNREF (null_device.realized_fontset_list);
195
196   MPLIST_DO (plist, null_device.realized_face_list)
197     mface__free_realized ((MRealizedFace *) MPLIST_VAL (plist));
198   M17N_OBJECT_UNREF (null_device.realized_face_list);
199
200   MPLIST_DO (plist, null_device.realized_font_list)
201     mfont__free_realized ((MRealizedFont *) MPLIST_VAL (plist));
202   M17N_OBJECT_UNREF (null_device.realized_font_list);
203   return 0;
204 }
205
206 static int
207 null_device_open (MFrame *frame, MPlist *param)
208 {
209   MFace *face;
210
211   frame->device = NULL;
212   frame->device_type = 0;
213   frame->driver = &null_driver;
214   frame->font_driver_list = mplist ();
215   mplist_add (frame->font_driver_list, Mfreetype, &mfont__ft_driver);
216   frame->realized_font_list = null_device.realized_font_list;
217   frame->realized_face_list = null_device.realized_face_list;
218   frame->realized_fontset_list = null_device.realized_fontset_list;
219   face = mface_copy (mface__default);
220   mplist_push (param, Mface, face);
221   M17N_OBJECT_UNREF (face);
222   return 0;
223 }
224
225 static MDeviceLibraryInterface null_interface =
226   { NULL, NULL, null_device_init, null_device_open, null_device_fini };
227
228 #endif
229 \f
230 /* Internal API */
231
232 \f
233 /* External API */
234
235 void
236 m17n_init_win (void)
237 {
238   int mdebug_mask = MDEBUG_INIT;
239
240   if (m17n__gui_initialized++)
241     return;
242   m17n_init ();
243   if (merror_code != MERROR_NONE)
244     {
245       m17n__gui_initialized--;
246       return;
247     }
248
249   MDEBUG_PUSH_TIME ();
250
251   Mgd = msymbol ("gd");
252
253   Mfont = msymbol ("font");
254   Mfont_width = msymbol ("font-width");
255   Mfont_ascent = msymbol ("font-ascent");
256   Mfont_descent = msymbol ("font-descent");
257   Mdevice = msymbol ("device");
258
259   Mdisplay = msymbol ("display");
260   Mscreen = msymbol ("screen");
261   Mdrawable = msymbol ("drawable");
262   Mdepth = msymbol ("depth");
263   Mwidget = msymbol ("widget");
264
265   MDEBUG_PUSH_TIME ();
266   if (mfont__init () < 0)
267     goto err;
268   MDEBUG_PRINT_TIME ("INIT", (stderr, " to initialize font module."));
269   if (mfont__fontset_init () < 0)
270     goto err;
271   MDEBUG_PRINT_TIME ("INIT", (stderr, " to initialize fontset module."));
272   if (mface__init () < 0)
273     goto err;
274   MDEBUG_PRINT_TIME ("INIT", (stderr, " to initialize face module."));
275   if (mdraw__init () < 0)
276     goto err;
277   MDEBUG_PRINT_TIME ("INIT", (stderr, " to initialize draw module."));
278   if (minput__win_init () < 0)
279     goto err;
280   MDEBUG_PRINT_TIME ("INIT", (stderr, " to initialize input-win module."));
281   mframe_default = NULL;
282
283   register_device_library (Mx, "libm17n-X");
284   register_device_library (Mgd, "libm17n-gd");
285   return;
286
287  err:
288   MDEBUG_POP_TIME ();
289   MDEBUG_PRINT_TIME ("INIT", (stderr, " to initialize the m17n GUI module."));
290   MDEBUG_POP_TIME ();
291 }
292
293 void
294 m17n_fini_win (void)
295 {
296   int mdebug_mask = MDEBUG_FINI;
297   MPlist *plist;
298
299   if (m17n__gui_initialized == 0
300       || --m17n__gui_initialized > 0)
301     return;
302
303   MDEBUG_PUSH_TIME ();
304   MDEBUG_PUSH_TIME ();
305   MDEBUG_PRINT_TIME ("FINI", (stderr, " to finalize device modules."));
306   MPLIST_DO (plist, device_library_list)
307     {
308       MDeviceLibraryInterface *interface = MPLIST_VAL (plist);
309
310       if (interface->handle && interface->fini)
311         {
312           (*interface->fini) ();
313           dlclose (interface->handle);
314         }
315       free (interface->library);
316     }
317 #ifdef HAVE_FREETYPE
318   if (null_interface.handle)
319     (*null_interface.fini) ();
320 #endif  /* not HAVE_FREETYPE */
321   M17N_OBJECT_UNREF (device_library_list);
322   MDEBUG_PRINT_TIME ("FINI", (stderr, " to finalize input-gui module."));
323   minput__win_fini ();
324   MDEBUG_PRINT_TIME ("FINI", (stderr, " to finalize draw module."));
325   mdraw__fini ();
326   MDEBUG_PRINT_TIME ("FINI", (stderr, " to finalize face module."));
327   mface__fini ();
328   MDEBUG_PRINT_TIME ("FINI", (stderr, " to finalize fontset module."));
329   mfont__fontset_fini ();
330   MDEBUG_PRINT_TIME ("FINI", (stderr, " to finalize font module."));
331   mfont__fini ();
332   mframe_default = NULL;
333   MDEBUG_POP_TIME ();
334   MDEBUG_PRINT_TIME ("FINI", (stderr, " to finalize the gui modules."));
335   MDEBUG_POP_TIME ();
336   m17n_fini ();
337 }
338
339 /*** @} */ 
340 #endif /* !FOR_DOXYGEN || DOXYGEN_INTERNAL_MODULE */
341
342 /*** @addtogroup m17nFrame */
343 /***en
344     @brief A @e frame is an object corresponding to the graphic device.
345
346     A @e frame is an object of the type #MFrame to hold various
347     information about each display/input device.  Almost all m17n GUI
348     functions require a pointer to a frame as an argument.  */
349 /***ja
350     @brief @e ¥Õ¥ì¡¼¥à ¤È¤Ï¥°¥é¥Õ¥£¥Ã¥¯¥Ç¥Ð¥¤¥¹¤ËÂбþ¤¹¤ë¥ª¥Ö¥¸¥§¥¯¥È¤Ç¤¢¤ë.
351
352     @e ¥Õ¥ì¡¼¥à ¤È¤Ï #MFrame 
353     ·¿¤Î¥ª¥Ö¥¸¥§¥¯¥È¤Ç¤¢¤ê¡¢¸Ä¡¹¤Îɽ¼¨¡¿ÆþÎϥǥХ¤¥¹¤Î¾ðÊó¤ò³ÊǼ¤¹¤ë¤¿¤á¤ËÍѤ¤¤é¤ì¤ë¡£
354     ¤Û¤È¤ó¤É¤¹¤Ù¤Æ¤Î m17n GUI´Ø¿ô¤Ï¡¢°ú¿ô¤È¤·¤Æ¥Õ¥ì¡¼¥à¤Ø¤Î¥Ý¥¤¥ó¥¿¤òÍ׵᤹¤ë¡£  */
355
356 /*** @{ */
357 /*=*/
358
359 /***en
360     @name Variables: Keys of frame parameter
361
362     These are the symbols to use in a parameter to create a frame.  See
363     the function mframe () for details.
364
365     #Mdevice, #Mdisplay, #Mscreen, #Mdrawable, #Mdepth, and #Mcolormap
366     are also keys of a frame property.  */
367
368 /***ja
369     @name ÊÑ¿ô¡§ ¥Õ¥ì¡¼¥à¥Ñ¥é¥á¡¼¥¿ÍÑ¥­¡¼
370
371     ¥Õ¥ì¡¼¥à¤òÀ¸À®¤¹¤ëºÝ¤Î¥Ñ¥é¥á¡¼¥¿¤ËÍѤ¤¤ë¥·¥ó¥Ü¥ë¡£¾Ü¤·¤¯¤Ï´Ø¿ô
372     mframe () ¤ÎÀâÌÀ»²¾È¡£
373
374     #Mdevice¡¢ #Mdisplay¡¢ #Mscreen¡¢ #Mdrawable¡¢ #Mdepth¡¢#Mcolormap
375     ¤Ï¥Õ¥ì¡¼¥à¥×¥í¥Ñ¥Æ¥£¤Î¥­¡¼¤Ç¤â¤¢¤ë¡£  */
376
377 /*=*/
378
379 MSymbol Mdevice, Mdisplay, Mscreen, Mdrawable, Mdepth, Mcolormap, Mwidget; 
380
381 MSymbol Mgd;
382
383 /*=*/
384
385 /***en
386     @name Variables: Keys of frame property
387
388     These are the symbols to use as an argument to the function
389     mframe_get_prop ().  */
390 /***ja
391     @name ÊÑ¿ô¡§ ¥Õ¥ì¡¼¥à¥×¥í¥Ñ¥Æ¥£¤Î¥­¡¼
392
393     ´Ø¿ô mframe_get_prop () ¤Î°ú¿ô¤ËÍѤ¤¤é¤ì¤ë¥·¥ó¥Ü¥ë¡£  */ 
394 /*** @{ */ 
395 /*=*/
396 MSymbol Mfont;
397 MSymbol Mfont_width;
398 MSymbol Mfont_ascent;
399 MSymbol Mfont_descent;
400
401 /*=*/
402
403 /*** @} */ 
404 /*=*/
405
406 /***en
407     @brief Create a new frame.
408
409     The mframe () function creates a new frame with parameters listed
410     in $PLIST which may be @c NULL.
411
412     The recognized keys in $PLIST are window system dependent.
413
414     The following key is always recognized.
415
416     <ul>
417
418     <li> #Mdevice, the value must be one of #Mx, #Mgd, and #Mnil.
419
420     If the value is #Mx, the frame is for X Window System.  The
421     argument #MDrawWindow specified together with the frame must be of
422     type @c Window.  The frame is both readable and writable, thus all
423     GUI functions can be used.
424
425     If the value is #Mgd, the frame is for an image object of GD
426     library.  The argument #MDrawWindow specified together with the
427     frame must be of type @c gdImagePtr.  The frame is writable
428     only, thus functions minput_XXX can't be used for the frame.
429
430     If the value is #Mnil, the frame is for a null device.  The frame
431     is not writable nor readable, thus functions mdraw_XXX that
432     require the argument #MDrawWindow and functions minput_XXX can't
433     be used for the frame.
434
435     <li> #Mface, the value must be a pointer to #MFace.
436
437     The value is used as the default face of the frame.
438
439     </ul>
440
441     In addition, if the value of the key #Mdevice is #Mx, the
442     following keys are recognized.  They are to specify the root
443     window and the depth of drawables that can be used with the frame.
444
445     <ul>
446
447     <li> #Mdrawable, the value type must be <tt>Drawable</tt>.
448
449     A parameter of key #Mdisplay must also be specified.  The
450     created frame can be used for drawables whose root window and
451     depth are the same as those of the specified drawable on the
452     specified display.
453
454     When this parameter is specified, the parameter of key #Mscreen
455     is ignored.
456
457     <li> #Mwidget, the value type must be <tt>Widget</tt>.
458
459     The created frame can be used for drawables whose root window and
460     depth are the same as those of the specified widget.
461
462     If a parameter of key #Mface is not specified, the default face
463     is created from the resources of the widget.
464
465     When this parameter is specified, the parameters of key #Mdisplay,
466     #Mscreen, #Mdrawable, #Mdepth are ignored.
467
468     <li> #Mdepth, the value type must be <tt>unsigned</tt>.
469
470     The created frame can be used for drawables of the specified
471     depth.
472
473     <li> #Mscreen, the value type must be <tt>(Screen *)</tt>.
474
475     The created frame can be used for drawables whose root window is
476     the same as the root window of the specified screen, and depth is
477     the same at the default depth of the screen.
478
479     When this parameter is specified, parameter of key #Mdisplay is
480     ignored.
481
482     <li> #Mdisplay, the value type must be <tt>(Display *)</tt>.
483
484     The created frame can be used for drawables whose root window is
485     the same as the root window for the default screen of the display,
486     and depth is the same as the default depth of the screen.
487
488     <li> #Mcolormap, the value type must be <tt>(Colormap)</tt>.
489
490     The created frame uses the specified colormap.
491
492     <li> #Mfont, the value must be #Mx, #Mfreetype, or #Mxft.
493
494     The created frame uses the specified font backend.  The value #Mx
495     instructs to use X core fonts, #Mfreetype to use local fonts
496     supported by FreeType fonts, and #Mxft to use local fonts via Xft
497     library.  You can specify this parameter more than once with
498     different values if you want to use multiple font backends.  This
499     is ignored if the specified font backend is not supported on the
500     device.
501     
502     When this parameter is not specified, all font backend supported
503     on the device are used.
504
505     </ul>
506
507     @return
508     If the operation was successful, mframe () returns a pointer to a
509     newly created frame.  Otherwise, it returns @c NULL.  */
510
511 /***ja
512     @brief ¿·¤·¤¤¥Õ¥ì¡¼¥à¤òºî¤ë.
513
514     ´Ø¿ô mframe () ¤Ï $PLIST Ãæ¤Î¥Ñ¥é¥á¡¼¥¿¤ò»ý¤Ä¿·¤·¤¤¥Õ¥ì¡¼¥à¤òºî¤ë¡£
515     $PLIST ¤Ï @c NULL ¤Ç¤âÎɤ¤¡£
516
517     $PLIST ¤Ë¸½¤ï¤ì¤ë¥­¡¼¤Î¤¦¤Á¤É¤ì¤¬Ç§¼±¤µ¤ì¤ë¤«¤Ï¥¦¥£¥ó¥É¥¦¥·¥¹¥Æ¥à¤Ë°Í¸¤¹¤ë¡£
518
519     °Ê²¼¤Î¥­¡¼¤Ï¾ï¤Ëǧ¼±¤µ¤ì¤ë¡£
520
521     <ul>
522
523     <li> #Mdevice. ÃͤϠ#Mx, #Mgd, #Mnil ¤Î¤¤¤º¤ì¤«¤Ç¤Ê¤¯¤Æ¤Ï¤Ê¤é¤Ê¤¤¡£
524
525     Ãͤ¬ #Mx ¤Ê¤é¤Ð¡¢¿·¤·¤¤¥Õ¥ì¡¼¥à¤Ï X ¥¦¥£¥ó¥É¥¦¥·¥¹¥Æ¥àÍѤǤ¢¤ë¡£
526     ¤³¤Î¥Õ¥ì¡¼¥à¤È¶¦¤Ë»ØÄꤵ¤ì¤¿°ú¿ô #MDrawWindow ¤Ï¡¢ @c Window
527     ·¿¤Ç¤Ê¤¯¤Æ¤Ï¤Ê¤é¤Ê¤¤¡£¥Õ¥ì¡¼¥à¤ÏÆɤ߽ñ¤­¤È¤â¤Ë²Äǽ¤Ç¤¢¤ê¡¢¤¹¤Ù¤Æ¤ÎGUI 
528     ´Ø¿ô¤¬»ÈÍѤǤ­¤ë¡£
529
530     Ãͤ¬ #Mgd ¤Ê¤é¤Ð¡¢¿·¤·¤¤¥Õ¥ì¡¼¥à¤Ï GD 
531     ¥é¥¤¥Ö¥é¥ê¤Î¥¤¥á¡¼¥¸¥ª¥Ö¥¸¥§¥¯¥ÈÍѤǤ¢¤ë¡£¤³¤Î¥Õ¥ì¡¼¥à¤È¶¦¤Ë»ØÄꤵ¤ì¤¿°ú¿ô
532     #MDrawWindow ¤Ï¡¢ @c gdImagePtr ·¿¤Ç¤Ê¤¯¤Æ¤Ï¤Ê¤é¤Ê¤¤¡£¥Õ¥ì¡¼¥à¤Ï½ñ¤­½Ð¤·ÀìÍѤǤ¢¤ê¡¢
533     minput_ ¤Ç»Ï¤Þ¤ë̾Á°¤Î´Ø¿ô¤Ï»ÈÍѤǤ­¤Ê¤¤¡£
534
535     Ãͤ¬ #Mnil ¤Ê¤é¤Ð¡¢¿·¤·¤¤¥Õ¥ì¡¼¥à¤Ï, null 
536     ¥Ç¥Ð¥¤¥¹ÍѤǤ¢¤ë¡£¤³¤Î¥Õ¥ì¡¼¥à¤ÏÆɤ߽ñ¤­¤Ç¤­¤Ê¤¤¤Î¤Ç¡¢°ú¿ô #MDrawWindow 
537     ¤òɬÍפȤ¹¤ëmdraw_ ¤Ç»Ï¤Þ¤ë̾Á°¤Î´Ø¿ô¤ä¡¢minput_ ¤Ç»Ï¤Þ¤ë̾Á°¤Î´Ø¿ô¤Ï»ÈÍѤǤ­¤Ê¤¤¡£
538
539     <li> #Mface. ÃͤϠ#MFace ¤Ø¤Î¥Ý¥¤¥ó¥¿¤Ç¤Ê¤¯¤Æ¤Ï¤Ê¤é¤Ê¤¤¡£
540
541     ¤³¤ÎÃͤϥե졼¥à¤Î¥Ç¥Õ¥©¥ë¥È¤Î¥Õ¥§¡¼¥¹¤È¤·¤ÆÍѤ¤¤é¤ì¤ë¡£
542
543     </ul>
544
545     ¤³¤ì¤é¤Î¥­¡¼¤Ë²Ã¤¨¡¢#Mdevice ¤Î¥­¡¼¤¬ #Mx 
546     ¤Ç¤¢¤ë¾ì¹ç¤Ë¸Â¤ê°Ê²¼¤Î¥­¡¼¤âǧ¼±¤µ¤ì¤ë¡£°Ê²¼¤Î¥­¡¼¤Ï¥ë¡¼¥È¥¦¥£¥ó¥É¥¦¤È¡¢¥Õ¥ì¡¼¥à¤ÇÍøÍѤǤ­¤ë 
547     drawable ¤Î¿¼¤µ¤ò»ØÄꤹ¤ë¡£
548
549     <ul>
550
551     <li> #Mdrawable. ÃͤϠ<tt>Drawable</tt> ·¿¤Ç¤Ê¤¯¤Æ¤Ï¤Ê¤é¤Ê¤¤¡£
552
553     ¥­¡¼ #Mdisplay ¤ò»ý¤Ä¥Ñ¥é¥á¡¼¥¿¤â»ØÄꤵ¤ì¤Æ¤¤¤ëɬÍפ¬¤¢¤ë¡£
554     À¸À®¤µ¤ì¤¿¥Õ¥ì¡¼¥à¤Ï¡¢»ØÄꤵ¤ì¤¿¥Ç¥£¥¹¥×¥ì¥¤¾å¤Î»ØÄꤵ¤ì¤¿ drawable 
555     ¤ÈƱ¤¸¥ë¡¼¥È¥¦¥£¥ó¥É¥¦¤È¿¼¤µ¤ò»ý¤Ä drawable ¤ËÍѤ¤¤é¤ì¤ë¡£
556
557     ¤³¤Î¥Ñ¥é¥á¡¼¥¿¤¬¤¢¤ë¾ì¹ç¤Ë¤Ï¡¢#Mscreen ¤ò¥­¡¼¤È¤¹¤ë¥Ñ¥é¥á¡¼¥¿¤Ï̵»ë¤µ¤ì¤ë¡£
558
559     <li> #Mwidget. ÃͤϠ<tt>Widget</tt> ·¿¤Ç¤Ê¤¯¤Æ¤Ï¤Ê¤é¤Ê¤¤¡£
560
561     À¸À®¤µ¤ì¤¿¥Õ¥ì¡¼¥à¤Ï¡¢»ØÄꤷ¤¿¥¦¥£¥¸¥§¥Ã¥È¤ÈƱ¤¸¥ë¡¼¥È¥¦¥£¥ó¥É¥¦¤È¿¼¤µ¤ò»ý¤Ä
562     drawable ¤ËÍѤ¤¤é¤ì¤ë¡£
563
564     ¥­¡¼ #Mface ¤ò»ý¤Ä¥Ñ¥é¥á¡¼¥¿¤¬¤Ê¤±¤ì¤Ð¡¢¥Ç¥Õ¥©¥ë¥È¤Î¥Õ¥§¡¼¥¹¤Ï¤³¤Î
565     ¥¦¥£¥¸¥§¥Ã¥È¤Î¥ê¥½¡¼¥¹¤«¤éºî¤é¤ì¤ë¡£
566
567     ¤³¤Î¥Ñ¥é¥á¡¼¥¿¤¬¤¢¤ë¾ì¹ç¤Ë¤Ï¡¢#Mdisplay, #Mscreen, #Mdrawable,
568     #Mdepth ¤ò¥­¡¼¤È¤¹¤ë¥Ñ¥é¥á¡¼¥¿¤Ï̵»ë¤µ¤ì¤ë¡£
569
570     <li> #Mdepth. ÃͤϠ<tt>unsigned</tt>  ·¿¤Ç¤Ê¤¯¤Æ¤Ï¤Ê¤é¤Ê¤¤¡£
571
572     À¸À®¤µ¤ì¤¿¥Õ¥ì¡¼¥à¤Ï¡¢»ØÄꤷ¤¿¿¼¤µ¤Î drawable ¤ËÍѤ¤¤é¤ì¤ë¡£
573
574     <li> #Mscreen. ÃͤϠ<tt>(Screen *)</tt> ·¿¤Ç¤Ê¤¯¤Æ¤Ï¤Ê¤é¤Ê¤¤¡£
575
576     À¸À®¤·¤¿¥Õ¥ì¡¼¥à¤Ï¡¢»ØÄꤷ¤¿¥¹¥¯¥ê¡¼¥ó¤ÈƱ¤¸¥ë¡¼¥È¥¦¥£¥ó¥É¥¦¤ò»ý¤Á¡¢¥¹¥¯¥ê¡¼¥ó¤Î¥Ç¥Õ¥©¥ë¥È¤Î¿¼¤µ¤ÈƱ¤¸¿¼¤µ¤ò»ý¤Ä drawable ¤ËÍѤ¤¤é¤ì¤ë¡£
577
578     ¤³¤Î¥Ñ¥é¥á¡¼¥¿¤¬¤¢¤ë¾ì¹ç¤Ë¤Ï¡¢#Mdisplay ¤ò¥­¡¼¤È¤¹¤ë¥Ñ¥é¥á¡¼¥¿¤Ï̵»ë¤µ¤ì¤ë¡£
579
580     <li> #Mdisplay. ÃͤϠ<tt>(Display *)</tt> ·¿¤Ç¤Ê¤¯¤Æ¤Ï¤Ê¤é¤Ê¤¤¡£
581
582     À¸À®¤µ¤ì¤¿¥Õ¥ì¡¼¥à¤Ï¡¢»ØÄꤷ¤¿¥Ç¥£¥¹¥×¥ì¥¤¤Î¥Ç¥Õ¥©¥ë¥È¥¹¥¯¥ê¡¼¥ó¤ÈƱ¤¸¥ë¡¼¥È¥¦¥£¥ó¥É¥¦¤ÈƱ¤¸¿¼¤µ¤ò»ý¤Ädrawables ¤ËÍѤ¤¤é¤ì¤ë¡£
583
584     <li> #Mcolormap. ÃͤϠ<tt>(Colormap)</tt> ·¿¤Ç¤Ê¤¯¤Æ¤Ï¤Ê¤é¤Ê¤¤¡£
585
586     À¸À®¤µ¤ì¤¿¥Õ¥ì¡¼¥à¤Ï¡¢»ØÄꤷ¤¿¥«¥é¡¼¥Þ¥Ã¥×¤ò»ÈÍѤ¹¤ë¡£
587
588     <li> #Mfont. Ãͤϡ¢#Mx, #Mfreetype, #Mxft ¤Î¤¤¤º¤ì¤«¡£
589
590     À¸À®¤µ¤ì¤¿¥Õ¥ì¡¼¥à¤Ï»ØÄꤷ¤¿¥Õ¥©¥ó¥È¥Ð¥Ã¥¯¥¨¥ó¥É¤ò»ÈÍѤ¹¤ë¡£Ãͤ¬ 
591     #Mx ¤Ç¤¢¤ì¤Ð X ¤Î¥³¥¢¥Õ¥©¥ó¥È¡¢#Mfreetype ¤Ç¤¢¤ì¤Ð FreeType 
592     ¤Ç¥µ¥Ý¡¼¥È¤µ¤ì¤Æ¤¤¤ë¥í¡¼¥«¥ë¥Õ¥©¥ó¥È¡¢#Mxft ¤Ç¤¢¤ì¤Ð Xft 
593     ¥é¥¤¥Ö¥é¥ê·Ðͳ¤ÇÍѤ¤¤ë¥í¡¼¥«¥ë¥Õ¥©¥ó¥È¤ò»ÈÍѤ¹¤ë¡£
594     Ê£¿ô¤Î¥Õ¥©¥ó¥È¥Ð¥Ã¥¯¥¨¥ó¥É¤ò»ÈÍѤ·¤¿¤¤¾ì¹ç¤Ë¤Ï¡¢¤³¤Î¥Ñ¥é¥á¡¼¥¿¤òÊ£¿ô²ó¡¢°Û¤Ê¤ëÃͤǻØÄꤹ¤ë¤³¤È¤¬¤Ç¤­¤ë¡£
595     »ØÄꤷ¤¿¥Ð¥Ã¥¯¥¨¥ó¥É¤¬¥µ¥Ý¡¼¥È¤µ¤ì¤Æ¤¤¤Ê¤¤¥Ç¥Ð¥¤¥¹¤Ç¤Ï¡¢¤³¤Î¥Ñ¥é¥á¡¼¥¿¤Ï̵»ë¤µ¤ì¤ë¡£
596
597     ¤³¤Î¥Ñ¥é¥á¡¼¥¿¤¬Ìµ¤¤¾ì¹ç¤Ë¤Ï¡¢¥Ç¥Ð¥¤¥¹¤Ç¥µ¥Ý¡¼¥È¤µ¤ì¤Æ¤¤¤ë¤¹¤Ù¤Æ¤Î¥Õ¥©¥ó¥È¥Ð¥Ã¥¯¥¨¥ó¥É¤òÍøÍѤ¹¤ë¡£
598
599     </ul>
600
601     @return
602     À®¸ù¤¹¤ì¤Ð mframe() ¤Ï¿·¤·¤¤¥Õ¥ì¡¼¥à¤Ø¤Î¥Ý¥¤¥ó¥¿¤òÊÖ¤¹¡£¤½¤¦¤Ç¤Ê¤±¤ì¤Ð
603     @c NULL ¤òÊÖ¤¹¡£  */
604
605 MFrame *
606 mframe (MPlist *plist)
607 {
608   MFrame *frame;
609   int plist_created = 0;
610   MPlist *pl;
611   MSymbol device;
612   MDeviceLibraryInterface *interface;
613
614   if (plist)
615     {
616       pl = mplist_find_by_key (plist, Mdevice);
617       if (pl)
618         device = MPLIST_VAL (pl);
619       else
620         device = Mx;
621     }
622   else
623     {
624       plist = mplist ();
625       plist_created = 1;
626       device = Mx;
627     }
628
629   if (device == Mnil)
630     {
631 #ifdef HAVE_FREETYPE
632       interface = &null_interface;
633       if (! interface->handle)
634         {
635           (*interface->init) ();
636           interface->handle = (void *) 1;
637         }
638 #else  /* not HAVE_FREETYPE */
639       MERROR (MERROR_WIN, NULL);
640 #endif  /* not HAVE_FREETYPE */
641     }
642   else
643     {
644       interface = mplist_get (device_library_list, device);
645       if (! interface)
646         MERROR (MERROR_WIN, NULL);
647       if (! interface->handle)
648         {
649           if (! (interface->handle = dlopen (interface->library, RTLD_NOW))
650               || ! (interface->init = dlsym (interface->handle, "device_init"))
651               || ! (interface->open = dlsym (interface->handle, "device_open"))
652               || ! (interface->fini = dlsym (interface->handle, "device_fini"))
653               || (*interface->init) () < 0)
654             {
655               fprintf (stderr, "%s\n", (char *) dlerror ());
656               if (interface->handle)
657                 dlclose (interface->handle);
658               MERROR (MERROR_WIN, NULL);
659             }
660         }
661     }
662
663   M17N_OBJECT (frame, free_frame, MERROR_FRAME);
664   if ((*interface->open) (frame, plist) < 0)
665     {
666       free (frame);
667       MERROR (MERROR_WIN, NULL);
668     }
669
670   if (! mframe_default)
671     mframe_default = frame;
672
673   frame->face = mface ();
674   MPLIST_DO (pl, plist)
675     if (MPLIST_KEY (pl) == Mface)
676       mface_merge (frame->face, (MFace *) MPLIST_VAL (pl));
677   mface__update_frame_face (frame);
678
679   if (plist_created)
680     M17N_OBJECT_UNREF (plist);
681   return frame;
682 }
683
684 /*=*/
685
686 /***en
687     @brief Return property value of frame.
688
689     The mframe_get_prop () function returns a value of property $KEY
690     of frame $FRAME.  The valid keys and the corresponding return
691     values are as follows.
692
693 @verbatim
694
695         key             type of value   meaning of value
696         ---             -------------   ----------------
697         Mface           MFace *         The default face.
698
699         Mfont           MFont *         The default font.
700
701         Mfont_width     int             Width of the default font.
702
703         Mfont_ascent    int             Ascent of the default font.
704
705         Mfont_descent   int             Descent of the default font.
706
707 @endverbatim
708
709     In the m17n-X library, the followings are also accepted.
710
711 @verbatim
712
713         key             type of value   meaning of value
714         ---             -------------   ----------------
715         Mdisplay        Display *       Display associated with the frame.
716
717         Mscreen         int             Screen number of a screen associated
718                                         with the frame.
719
720         Mcolormap       Colormap        Colormap of the frame.
721
722         Mdepth          unsigned        Depth of the frame.
723 @endverbatim
724 */
725
726 /***ja
727     @brief ¥Õ¥ì¡¼¥à¤Î¥×¥í¥Ñ¥Æ¥£¤ÎÃͤòÊÖ¤¹.
728
729     ´Ø¿ô mframe_get_prop () ¤Ï¥Õ¥ì¡¼¥à $FRAME ¤Î¥­¡¼ $KEY 
730     ¤ò»ý¤Ä¥×¥í¥Ñ¥Æ¥£¤ÎÃͤòÊÖ¤¹¡£Í­¸ú¤Ê¥­¡¼¤È¤½¤ÎÃͤϰʲ¼¤ÎÄ̤ꡣ
731
732 @verbatim
733
734         ¥­¡¼            Ãͤη¿          ÃͤΰÕÌ£
735         ---             -------------   ----------------
736         Mface           MFace *         ¥Ç¥Õ¥©¥ë¥È¤Î¥Õ¥§¡¼¥¹
737
738         Mfont           MFont *         ¥Ç¥Õ¥©¥ë¥È¤Î¥Õ¥©¥ó¥È
739
740         Mfont_width     int             ¥Ç¥Õ¥©¥ë¥È¤Î¥Õ¥©¥ó¥È¤ÎÉý
741
742         Mfont_ascent    int             ¥Ç¥Õ¥©¥ë¥È¤Î¥Õ¥©¥ó¥È¤Î ascent
743
744         Mfont_descent   int             ¥Ç¥Õ¥©¥ë¥È¤Î¥Õ¥©¥ó¥È¤Î descent
745
746 @endverbatim
747
748      m17n-X ¥é¥¤¥Ö¥é¥ê¤Ç¤Ï¡¢°Ê²¼¤Î¥­¡¼¤â»ÈÍѤǤ­¤ë¡£
749
750 @verbatim
751
752         ¥­¡¼            Ãͤη¿          ÃͤΰÕÌ£
753         ---             -------------   ----------------
754         Mdisplay        Display *       ¥Õ¥ì¡¼¥à¤È´ØÏ¢ÉÕ¤±¤é¤ì¤¿¥Ç¥£¥¹¥×¥ì¥¤
755
756         Mscreen         int             ¥Õ¥ì¡¼¥à¤È´ØÏ¢ÉÕ¤±¤é¤ì¤¿¥¹¥¯¥ê¡¼¥ó
757                                         ¤Î¥¹¥¯¥ê¡¼¥ó¥Ê¥ó¥Ð
758
759         Mcolormap       Colormap        ¥Õ¥ì¡¼¥à¤Î¥«¥é¡¼¥Þ¥Ã¥×
760
761         Mdepth          unsigned        ¥Õ¥ì¡¼¥à¤Î¿¼¤µ
762 @endverbatim
763
764 */
765
766 void *
767 mframe_get_prop (MFrame *frame, MSymbol key)
768 {
769   if (key == Mface)
770     return frame->face;
771   if (key == Mfont)
772     return &frame->rface->rfont->font;
773   if (key == Mfont_width)
774     return (void *) (frame->space_width);
775   if (key == Mfont_ascent)
776     return (void *) (frame->ascent);
777   if (key == Mfont_descent)
778     return (void *) (frame->descent);
779   return (*frame->driver->get_prop) (frame, key);
780 }
781
782 /*=*/
783
784 /***en
785     @brief The default frame.
786
787     The external variable #mframe_default contains a pointer to the
788     default frame that is created by the first call of mframe ().  */
789
790 /***ja
791     @brief ¥Ç¥Õ¥©¥ë¥È¤Î¥Õ¥ì¡¼¥à.
792
793     ³°ÉôÊÑ¿ô #mframe_default ¤Ï¡¢¥Ç¥Õ¥©¥ë¥È¤Î¥Õ¥ì¡¼¥à¤Ø¤Î¥Ý¥¤¥ó¥¿¤ò»ý¤Ä¡£
794     ¥Ç¥Õ¥©¥ë¥È¤Î¥Õ¥ì¡¼¥à¤Ï¡¢ºÇ½é¤Ë mframe () ¤¬¸Æ¤Ó½Ð¤µ¤ì¤¿¤È¤­¤Ëºî¤é¤ì¤ë¡£  */
795
796 MFrame *mframe_default;
797
798 /*** @} */
799
800 /*
801   Local Variables:
802   coding: euc-japan
803   End:
804 */