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