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