6e58efed1326a53ab8e9a899e68e9a023fff18a9
[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   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 (lib) 
129                                + strlen (DLOPEN_SHLIB_EXT) + 1);
130   sprintf (interface->library, "%s%s", lib, DLOPEN_SHLIB_EXT);
131   if (! device_library_list)
132     device_library_list = mplist ();
133   mplist_add (device_library_list, name, interface);
134   return 0;
135 }
136
137 \f
138 #ifdef HAVE_FREETYPE
139 /** Null device support.  */
140
141 static struct {
142   MPlist *realized_fontset_list;
143   MPlist *realized_font_list;
144   MPlist *realized_face_list;
145 } null_device;
146
147 static void
148 null_device_close (MFrame *frame)
149 {
150 }
151
152 static void *
153 null_device_get_prop (MFrame *frame, MSymbol key)
154 {
155   return NULL;
156 }
157
158 static void
159 null_device_realize_face (MRealizedFace *rface)
160 {
161   rface->info = NULL;
162 }
163
164 static void
165 null_device_free_realized_face (MRealizedFace *rface)
166 {
167 }
168
169 static MDeviceDriver null_driver =
170   {
171     null_device_close,
172     null_device_get_prop,
173     null_device_realize_face,
174     null_device_free_realized_face
175   };
176
177 static int
178 null_device_init ()
179 {
180   null_device.realized_fontset_list = mplist ();
181   null_device.realized_font_list = mplist ();
182   null_device.realized_face_list = mplist ();  
183   return 0;
184 }
185
186 static int
187 null_device_fini ()
188 {
189   MPlist *plist;
190
191   MPLIST_DO (plist, null_device.realized_fontset_list)
192     mfont__free_realized_fontset ((MRealizedFontset *) MPLIST_VAL (plist));
193   M17N_OBJECT_UNREF (null_device.realized_fontset_list);
194
195   MPLIST_DO (plist, null_device.realized_face_list)
196     mface__free_realized ((MRealizedFace *) MPLIST_VAL (plist));
197   M17N_OBJECT_UNREF (null_device.realized_face_list);
198
199   if (MPLIST_VAL (null_device.realized_font_list))
200     mfont__free_realized (MPLIST_VAL (null_device.realized_font_list));
201   M17N_OBJECT_UNREF (null_device.realized_font_list);
202   return 0;
203 }
204
205 static int
206 null_device_open (MFrame *frame, MPlist *param)
207 {
208   MFace *face;
209
210   frame->device = NULL;
211   frame->device_type = 0;
212   frame->driver = &null_driver;
213   frame->font_driver_list = mplist ();
214   mplist_add (frame->font_driver_list, Mfreetype, &mfont__ft_driver);
215   frame->realized_font_list = null_device.realized_font_list;
216   frame->realized_face_list = null_device.realized_face_list;
217   frame->realized_fontset_list = null_device.realized_fontset_list;
218   face = mface_copy (mface__default);
219   mplist_push (param, Mface, face);
220   M17N_OBJECT_UNREF (face);
221   return 0;
222 }
223
224 static MDeviceLibraryInterface null_interface =
225   { NULL, NULL, null_device_init, null_device_open, null_device_fini };
226
227 #endif
228 \f
229 /* Internal API */
230
231 \f
232 /* External API */
233
234 void
235 m17n_init_win (void)
236 {
237   int mdebug_mask = MDEBUG_INIT;
238
239   merror_code = MERROR_NONE;
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       free (interface);
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 /***ja
351     @brief @e ¥Õ¥ì¡¼¥à ¤È¤Ï¥°¥é¥Õ¥£¥Ã¥¯¥Ç¥Ð¥¤¥¹¤ËÂбþ¤¹¤ë¥ª¥Ö¥¸¥§¥¯¥È¤Ç¤¢¤ë.
352
353     @e ¥Õ¥ì¡¼¥à ¤È¤Ï #MFrame 
354     ·¿¤Î¥ª¥Ö¥¸¥§¥¯¥È¤Ç¤¢¤ê¡¢¸Ä¡¹¤Îɽ¼¨¡¿ÆþÎϥǥХ¤¥¹¤Î¾ðÊó¤ò³ÊǼ¤¹¤ë¤¿¤á¤ËÍѤ¤¤é¤ì¤ë¡£
355     ¤Û¤È¤ó¤É¤¹¤Ù¤Æ¤Î m17n GUI´Ø¿ô¤Ï¡¢°ú¿ô¤È¤·¤Æ¥Õ¥ì¡¼¥à¤Ø¤Î¥Ý¥¤¥ó¥¿¤òÍ׵᤹¤ë¡£  */
356
357 /*** @{ */
358 /*=*/
359
360 /***en
361     @name Variables: Keys of frame parameter
362
363     These are the symbols to use in a parameter to create a frame.  See
364     the function mframe () for details.
365
366     #Mdevice, #Mdisplay, #Mscreen, #Mdrawable, #Mdepth, and #Mcolormap
367     are also keys of a frame property.  */
368
369 /***ja
370     @name ÊÑ¿ô¡§ ¥Õ¥ì¡¼¥à¥Ñ¥é¥á¡¼¥¿ÍÑ¥­¡¼
371
372     ¥Õ¥ì¡¼¥à¤òÀ¸À®¤¹¤ëºÝ¤Î¥Ñ¥é¥á¡¼¥¿¤ËÍѤ¤¤ë¥·¥ó¥Ü¥ë¡£¾Ü¤·¤¯¤Ï´Ø¿ô
373     mframe () ¤ÎÀâÌÀ»²¾È¡£
374
375     #Mdevice¡¢ #Mdisplay¡¢ #Mscreen¡¢ #Mdrawable¡¢ #Mdepth¡¢#Mcolormap
376     ¤Ï¥Õ¥ì¡¼¥à¥×¥í¥Ñ¥Æ¥£¤Î¥­¡¼¤Ç¤â¤¢¤ë¡£  */
377
378 /*=*/
379
380 MSymbol Mdevice, Mdisplay, Mscreen, Mdrawable, Mdepth, Mcolormap, Mwidget; 
381
382 MSymbol Mgd;
383
384 /*=*/
385
386 /***en
387     @name Variables: Keys of frame property
388
389     These are the symbols to use as an argument to the function
390     mframe_get_prop ().  */
391 /***ja
392     @name ÊÑ¿ô¡§ ¥Õ¥ì¡¼¥à¥×¥í¥Ñ¥Æ¥£¤Î¥­¡¼
393
394     ´Ø¿ô mframe_get_prop () ¤Î°ú¿ô¤ËÍѤ¤¤é¤ì¤ë¥·¥ó¥Ü¥ë¡£  */ 
395 /*** @{ */ 
396 /*=*/
397 MSymbol Mfont;
398 MSymbol Mfont_width;
399 MSymbol Mfont_ascent;
400 MSymbol Mfont_descent;
401
402 /*=*/
403
404 /*** @} */ 
405 /*=*/
406
407 /***en
408     @brief Create a new frame.
409
410     The mframe () function creates a new frame with parameters listed
411     in $PLIST which may be @c NULL.
412
413     The recognized keys in $PLIST are window system dependent.
414
415     The following key is always recognized.
416
417     <ul>
418
419     <li> #Mdevice, the value must be one of #Mx, #Mgd, and #Mnil.
420
421     If the value is #Mx, the frame is for X Window System.  The
422     argument #MDrawWindow specified together with the frame must be of
423     type @c Window.  The frame is both readable and writable, thus all
424     GUI functions can be used.
425
426     If the value is #Mgd, the frame is for an image object of GD
427     library.  The argument #MDrawWindow specified together with the
428     frame must be of type @c gdImagePtr.  The frame is writable
429     only, thus functions minput_XXX can't be used for the frame.
430
431     If the value is #Mnil, the frame is for a null device.  The frame
432     is not writable nor readable, thus functions mdraw_XXX that
433     require the argument #MDrawWindow and functions minput_XXX can't
434     be used for the frame.
435
436     <li> #Mface, the value must be a pointer to #MFace.
437
438     The value is used as the default face of the frame.
439
440     </ul>
441
442     In addition, if the value of the key #Mdevice is #Mx, the
443     following keys are recognized.  They are to specify the root
444     window and the depth of drawables that can be used with the frame.
445
446     <ul>
447
448     <li> #Mdrawable, the value type must be <tt>Drawable</tt>.
449
450     A parameter of key #Mdisplay must also be specified.  The
451     created frame can be used for drawables whose root window and
452     depth are the same as those of the specified drawable on the
453     specified display.
454
455     When this parameter is specified, the parameter of key #Mscreen
456     is ignored.
457
458     <li> #Mwidget, the value type must be <tt>Widget</tt>.
459
460     The created frame can be used for drawables whose root window and
461     depth are the same as those of the specified widget.
462
463     If a parameter of key #Mface is not specified, the default face
464     is created from the resources of the widget.
465
466     When this parameter is specified, the parameters of key #Mdisplay,
467     #Mscreen, #Mdrawable, #Mdepth are ignored.
468
469     <li> #Mdepth, the value type must be <tt>unsigned</tt>.
470
471     The created frame can be used for drawables of the specified
472     depth.
473
474     <li> #Mscreen, the value type must be <tt>(Screen *)</tt>.
475
476     The created frame can be used for drawables whose root window is
477     the same as the root window of the specified screen, and depth is
478     the same at the default depth of the screen.
479
480     When this parameter is specified, parameter of key #Mdisplay is
481     ignored.
482
483     <li> #Mdisplay, the value type must be <tt>(Display *)</tt>.
484
485     The created frame can be used for drawables whose root window is
486     the same as the root window for the default screen of the display,
487     and depth is the same as the default depth of the screen.
488
489     <li> #Mcolormap, the value type must be <tt>(Colormap)</tt>.
490
491     The created frame uses the specified colormap.
492
493     <li> #Mfont, the value must be #Mx, #Mfreetype, or #Mxft.
494
495     The created frame uses the specified font backend.  The value #Mx
496     instructs to use X core fonts, #Mfreetype to use local fonts
497     supported by FreeType fonts, and #Mxft to use local fonts via Xft
498     library.  You can specify this parameter more than once with
499     different values if you want to use multiple font backends.  This
500     is ignored if the specified font backend is not supported on the
501     device.
502     
503     When this parameter is not specified, all font backend supported
504     on the device are used.
505
506     </ul>
507
508     @return
509     If the operation was successful, mframe () returns a pointer to a
510     newly created frame.  Otherwise, it returns @c NULL.  */
511
512 /***ja
513     @brief ¿·¤·¤¤¥Õ¥ì¡¼¥à¤òºî¤ë.
514
515     ´Ø¿ô mframe () ¤Ï $PLIST Ãæ¤Î¥Ñ¥é¥á¡¼¥¿¤ò»ý¤Ä¿·¤·¤¤¥Õ¥ì¡¼¥à¤òºî¤ë¡£
516     $PLIST ¤Ï @c NULL ¤Ç¤âÎɤ¤¡£
517
518     $PLIST ¤Ë¸½¤ï¤ì¤ë¥­¡¼¤Î¤¦¤Á¤É¤ì¤¬Ç§¼±¤µ¤ì¤ë¤«¤Ï¥¦¥£¥ó¥É¥¦¥·¥¹¥Æ¥à¤Ë°Í¸¤¹¤ë¡£
519
520     °Ê²¼¤Î¥­¡¼¤Ï¾ï¤Ëǧ¼±¤µ¤ì¤ë¡£
521
522     <ul>
523
524     <li> #Mdevice. ÃͤϠ#Mx, #Mgd, #Mnil ¤Î¤¤¤º¤ì¤«¤Ç¤Ê¤¯¤Æ¤Ï¤Ê¤é¤Ê¤¤¡£
525
526     Ãͤ¬ #Mx ¤Ê¤é¤Ð¡¢¿·¤·¤¤¥Õ¥ì¡¼¥à¤Ï X ¥¦¥£¥ó¥É¥¦¥·¥¹¥Æ¥àÍѤǤ¢¤ë¡£
527     ¤³¤Î¥Õ¥ì¡¼¥à¤È¶¦¤Ë»ØÄꤵ¤ì¤¿°ú¿ô #MDrawWindow ¤Ï¡¢ @c Window
528     ·¿¤Ç¤Ê¤¯¤Æ¤Ï¤Ê¤é¤Ê¤¤¡£¥Õ¥ì¡¼¥à¤ÏÆɤ߽ñ¤­¤È¤â¤Ë²Äǽ¤Ç¤¢¤ê¡¢¤¹¤Ù¤Æ¤ÎGUI 
529     ´Ø¿ô¤¬»ÈÍѤǤ­¤ë¡£
530
531     Ãͤ¬ #Mgd ¤Ê¤é¤Ð¡¢¿·¤·¤¤¥Õ¥ì¡¼¥à¤Ï GD 
532     ¥é¥¤¥Ö¥é¥ê¤Î¥¤¥á¡¼¥¸¥ª¥Ö¥¸¥§¥¯¥ÈÍѤǤ¢¤ë¡£¤³¤Î¥Õ¥ì¡¼¥à¤È¶¦¤Ë»ØÄꤵ¤ì¤¿°ú¿ô
533     #MDrawWindow ¤Ï¡¢ @c gdImagePtr ·¿¤Ç¤Ê¤¯¤Æ¤Ï¤Ê¤é¤Ê¤¤¡£¥Õ¥ì¡¼¥à¤Ï½ñ¤­½Ð¤·ÀìÍѤǤ¢¤ê¡¢
534     minput_ ¤Ç»Ï¤Þ¤ë̾Á°¤Î´Ø¿ô¤Ï»ÈÍѤǤ­¤Ê¤¤¡£
535
536     Ãͤ¬ #Mnil ¤Ê¤é¤Ð¡¢¿·¤·¤¤¥Õ¥ì¡¼¥à¤Ï, null 
537     ¥Ç¥Ð¥¤¥¹ÍѤǤ¢¤ë¡£¤³¤Î¥Õ¥ì¡¼¥à¤ÏÆɤ߽ñ¤­¤Ç¤­¤Ê¤¤¤Î¤Ç¡¢°ú¿ô #MDrawWindow 
538     ¤òɬÍפȤ¹¤ëmdraw_ ¤Ç»Ï¤Þ¤ë̾Á°¤Î´Ø¿ô¤ä¡¢minput_ ¤Ç»Ï¤Þ¤ë̾Á°¤Î´Ø¿ô¤Ï»ÈÍѤǤ­¤Ê¤¤¡£
539
540     <li> #Mface. ÃͤϠ#MFace ¤Ø¤Î¥Ý¥¤¥ó¥¿¤Ç¤Ê¤¯¤Æ¤Ï¤Ê¤é¤Ê¤¤¡£
541
542     ¤³¤ÎÃͤϥե졼¥à¤Î¥Ç¥Õ¥©¥ë¥È¤Î¥Õ¥§¡¼¥¹¤È¤·¤ÆÍѤ¤¤é¤ì¤ë¡£
543
544     </ul>
545
546     ¤³¤ì¤é¤Î¥­¡¼¤Ë²Ã¤¨¡¢#Mdevice ¤Î¥­¡¼¤¬ #Mx 
547     ¤Ç¤¢¤ë¾ì¹ç¤Ë¸Â¤ê°Ê²¼¤Î¥­¡¼¤âǧ¼±¤µ¤ì¤ë¡£°Ê²¼¤Î¥­¡¼¤Ï¥ë¡¼¥È¥¦¥£¥ó¥É¥¦¤È¡¢¥Õ¥ì¡¼¥à¤ÇÍøÍѤǤ­¤ë 
548     drawable ¤Î¿¼¤µ¤ò»ØÄꤹ¤ë¡£
549
550     <ul>
551
552     <li> #Mdrawable. ÃͤϠ<tt>Drawable</tt> ·¿¤Ç¤Ê¤¯¤Æ¤Ï¤Ê¤é¤Ê¤¤¡£
553
554     ¥­¡¼ #Mdisplay ¤ò»ý¤Ä¥Ñ¥é¥á¡¼¥¿¤â»ØÄꤵ¤ì¤Æ¤¤¤ëɬÍפ¬¤¢¤ë¡£
555     À¸À®¤µ¤ì¤¿¥Õ¥ì¡¼¥à¤Ï¡¢»ØÄꤵ¤ì¤¿¥Ç¥£¥¹¥×¥ì¥¤¾å¤Î»ØÄꤵ¤ì¤¿ drawable 
556     ¤ÈƱ¤¸¥ë¡¼¥È¥¦¥£¥ó¥É¥¦¤È¿¼¤µ¤ò»ý¤Ä drawable ¤ËÍѤ¤¤é¤ì¤ë¡£
557
558     ¤³¤Î¥Ñ¥é¥á¡¼¥¿¤¬¤¢¤ë¾ì¹ç¤Ë¤Ï¡¢#Mscreen ¤ò¥­¡¼¤È¤¹¤ë¥Ñ¥é¥á¡¼¥¿¤Ï̵»ë¤µ¤ì¤ë¡£
559
560     <li> #Mwidget. ÃͤϠ<tt>Widget</tt> ·¿¤Ç¤Ê¤¯¤Æ¤Ï¤Ê¤é¤Ê¤¤¡£
561
562     À¸À®¤µ¤ì¤¿¥Õ¥ì¡¼¥à¤Ï¡¢»ØÄꤷ¤¿¥¦¥£¥¸¥§¥Ã¥È¤ÈƱ¤¸¥ë¡¼¥È¥¦¥£¥ó¥É¥¦¤È¿¼¤µ¤ò»ý¤Ä
563     drawable ¤ËÍѤ¤¤é¤ì¤ë¡£
564
565     ¥­¡¼ #Mface ¤ò»ý¤Ä¥Ñ¥é¥á¡¼¥¿¤¬¤Ê¤±¤ì¤Ð¡¢¥Ç¥Õ¥©¥ë¥È¤Î¥Õ¥§¡¼¥¹¤Ï¤³¤Î
566     ¥¦¥£¥¸¥§¥Ã¥È¤Î¥ê¥½¡¼¥¹¤«¤éºî¤é¤ì¤ë¡£
567
568     ¤³¤Î¥Ñ¥é¥á¡¼¥¿¤¬¤¢¤ë¾ì¹ç¤Ë¤Ï¡¢#Mdisplay, #Mscreen, #Mdrawable,
569     #Mdepth ¤ò¥­¡¼¤È¤¹¤ë¥Ñ¥é¥á¡¼¥¿¤Ï̵»ë¤µ¤ì¤ë¡£
570
571     <li> #Mdepth. ÃͤϠ<tt>unsigned</tt>  ·¿¤Ç¤Ê¤¯¤Æ¤Ï¤Ê¤é¤Ê¤¤¡£
572
573     À¸À®¤µ¤ì¤¿¥Õ¥ì¡¼¥à¤Ï¡¢»ØÄꤷ¤¿¿¼¤µ¤Î drawable ¤ËÍѤ¤¤é¤ì¤ë¡£
574
575     <li> #Mscreen. ÃͤϠ<tt>(Screen *)</tt> ·¿¤Ç¤Ê¤¯¤Æ¤Ï¤Ê¤é¤Ê¤¤¡£
576
577     À¸À®¤·¤¿¥Õ¥ì¡¼¥à¤Ï¡¢»ØÄꤷ¤¿¥¹¥¯¥ê¡¼¥ó¤ÈƱ¤¸¥ë¡¼¥È¥¦¥£¥ó¥É¥¦¤ò»ý¤Á¡¢¥¹¥¯¥ê¡¼¥ó¤Î¥Ç¥Õ¥©¥ë¥È¤Î¿¼¤µ¤ÈƱ¤¸¿¼¤µ¤ò»ý¤Ä drawable ¤ËÍѤ¤¤é¤ì¤ë¡£
578
579     ¤³¤Î¥Ñ¥é¥á¡¼¥¿¤¬¤¢¤ë¾ì¹ç¤Ë¤Ï¡¢#Mdisplay ¤ò¥­¡¼¤È¤¹¤ë¥Ñ¥é¥á¡¼¥¿¤Ï̵»ë¤µ¤ì¤ë¡£
580
581     <li> #Mdisplay. ÃͤϠ<tt>(Display *)</tt> ·¿¤Ç¤Ê¤¯¤Æ¤Ï¤Ê¤é¤Ê¤¤¡£
582
583     À¸À®¤µ¤ì¤¿¥Õ¥ì¡¼¥à¤Ï¡¢»ØÄꤷ¤¿¥Ç¥£¥¹¥×¥ì¥¤¤Î¥Ç¥Õ¥©¥ë¥È¥¹¥¯¥ê¡¼¥ó¤ÈƱ¤¸¥ë¡¼¥È¥¦¥£¥ó¥É¥¦¤ÈƱ¤¸¿¼¤µ¤ò»ý¤Ädrawables ¤ËÍѤ¤¤é¤ì¤ë¡£
584
585     <li> #Mcolormap. ÃͤϠ<tt>(Colormap)</tt> ·¿¤Ç¤Ê¤¯¤Æ¤Ï¤Ê¤é¤Ê¤¤¡£
586
587     À¸À®¤µ¤ì¤¿¥Õ¥ì¡¼¥à¤Ï¡¢»ØÄꤷ¤¿¥«¥é¡¼¥Þ¥Ã¥×¤ò»ÈÍѤ¹¤ë¡£
588
589     <li> #Mfont. Ãͤϡ¢#Mx, #Mfreetype, #Mxft ¤Î¤¤¤º¤ì¤«¡£
590
591     À¸À®¤µ¤ì¤¿¥Õ¥ì¡¼¥à¤Ï»ØÄꤷ¤¿¥Õ¥©¥ó¥È¥Ð¥Ã¥¯¥¨¥ó¥É¤ò»ÈÍѤ¹¤ë¡£Ãͤ¬ 
592     #Mx ¤Ç¤¢¤ì¤Ð X ¤Î¥³¥¢¥Õ¥©¥ó¥È¡¢#Mfreetype ¤Ç¤¢¤ì¤Ð FreeType 
593     ¤Ç¥µ¥Ý¡¼¥È¤µ¤ì¤Æ¤¤¤ë¥í¡¼¥«¥ë¥Õ¥©¥ó¥È¡¢#Mxft ¤Ç¤¢¤ì¤Ð Xft 
594     ¥é¥¤¥Ö¥é¥ê·Ðͳ¤ÇÍѤ¤¤ë¥í¡¼¥«¥ë¥Õ¥©¥ó¥È¤ò»ÈÍѤ¹¤ë¡£
595     Ê£¿ô¤Î¥Õ¥©¥ó¥È¥Ð¥Ã¥¯¥¨¥ó¥É¤ò»ÈÍѤ·¤¿¤¤¾ì¹ç¤Ë¤Ï¡¢¤³¤Î¥Ñ¥é¥á¡¼¥¿¤òÊ£¿ô²ó¡¢°Û¤Ê¤ëÃͤǻØÄꤹ¤ë¤³¤È¤¬¤Ç¤­¤ë¡£
596     »ØÄꤷ¤¿¥Ð¥Ã¥¯¥¨¥ó¥É¤¬¥µ¥Ý¡¼¥È¤µ¤ì¤Æ¤¤¤Ê¤¤¥Ç¥Ð¥¤¥¹¤Ç¤Ï¡¢¤³¤Î¥Ñ¥é¥á¡¼¥¿¤Ï̵»ë¤µ¤ì¤ë¡£
597
598     ¤³¤Î¥Ñ¥é¥á¡¼¥¿¤¬Ìµ¤¤¾ì¹ç¤Ë¤Ï¡¢¥Ç¥Ð¥¤¥¹¤Ç¥µ¥Ý¡¼¥È¤µ¤ì¤Æ¤¤¤ë¤¹¤Ù¤Æ¤Î¥Õ¥©¥ó¥È¥Ð¥Ã¥¯¥¨¥ó¥É¤òÍøÍѤ¹¤ë¡£
599
600     </ul>
601
602     @return
603     À®¸ù¤¹¤ì¤Ð mframe() ¤Ï¿·¤·¤¤¥Õ¥ì¡¼¥à¤Ø¤Î¥Ý¥¤¥ó¥¿¤òÊÖ¤¹¡£¤½¤¦¤Ç¤Ê¤±¤ì¤Ð
604     @c NULL ¤òÊÖ¤¹¡£  */
605
606 MFrame *
607 mframe (MPlist *plist)
608 {
609   MFrame *frame;
610   int plist_created = 0;
611   MPlist *pl;
612   MSymbol device;
613   MDeviceLibraryInterface *interface;
614
615   if (plist)
616     {
617       pl = mplist_find_by_key (plist, Mdevice);
618       if (pl)
619         device = MPLIST_VAL (pl);
620       else
621         device = Mx;
622     }
623   else
624     {
625       plist = mplist ();
626       plist_created = 1;
627       device = Mx;
628     }
629
630   if (device == Mnil)
631     {
632 #ifdef HAVE_FREETYPE
633       interface = &null_interface;
634       if (! interface->handle)
635         {
636           (*interface->init) ();
637           interface->handle = (void *) 1;
638         }
639 #else  /* not HAVE_FREETYPE */
640       MERROR (MERROR_WIN, NULL);
641 #endif  /* not HAVE_FREETYPE */
642     }
643   else
644     {
645       interface = mplist_get (device_library_list, device);
646       if (! interface)
647         MERROR (MERROR_WIN, NULL);
648       if (! interface->handle)
649         {
650           if (! (interface->handle = dlopen (interface->library, RTLD_NOW))
651               || ! (interface->init
652                     = (int (*) ()) dlsym (interface->handle, "device_init"))
653               || ! (interface->open
654                     = (int (*) (MFrame *, MPlist *)) dlsym (interface->handle,
655                                                             "device_open"))
656               || ! (interface->fini
657                     = (int (*) ()) dlsym (interface->handle, "device_fini"))
658               || (*interface->init) () < 0)
659             {
660               fprintf (stderr, "%s\n", (char *) dlerror ());
661               if (interface->handle)
662                 dlclose (interface->handle);
663               MERROR (MERROR_WIN, NULL);
664             }
665         }
666     }
667
668   M17N_OBJECT (frame, free_frame, MERROR_FRAME);
669   if ((*interface->open) (frame, plist) < 0)
670     {
671       free (frame);
672       MERROR (MERROR_WIN, NULL);
673     }
674
675   if (! mframe_default)
676     mframe_default = frame;
677
678   frame->face = mface ();
679   MPLIST_DO (pl, plist)
680     if (MPLIST_KEY (pl) == Mface)
681       mface_merge (frame->face, (MFace *) MPLIST_VAL (pl));
682   mface__update_frame_face (frame);
683   frame->font = frame->rface->rfont ? frame->rface->rfont->font : NULL;
684
685   if (plist_created)
686     M17N_OBJECT_UNREF (plist);
687   return frame;
688 }
689
690 /*=*/
691
692 /***en
693     @brief Return property value of frame.
694
695     The mframe_get_prop () function returns a value of property $KEY
696     of frame $FRAME.  The valid keys and the corresponding return
697     values are as follows.
698
699 @verbatim
700
701         key             type of value   meaning of value
702         ---             -------------   ----------------
703         Mface           MFace *         The default face.
704
705         Mfont           MFont *         The default font.
706
707         Mfont_width     int             Width of the default font.
708
709         Mfont_ascent    int             Ascent of the default font.
710
711         Mfont_descent   int             Descent of the default font.
712
713 @endverbatim
714
715     In the m17n-X library, the followings are also accepted.
716
717 @verbatim
718
719         key             type of value   meaning of value
720         ---             -------------   ----------------
721         Mdisplay        Display *       Display associated with the frame.
722
723         Mscreen         int             Screen number of a screen associated
724                                         with the frame.
725
726         Mcolormap       Colormap        Colormap of the frame.
727
728         Mdepth          unsigned        Depth of the frame.
729 @endverbatim
730 */
731
732 /***ja
733     @brief ¥Õ¥ì¡¼¥à¤Î¥×¥í¥Ñ¥Æ¥£¤ÎÃͤòÊÖ¤¹.
734
735     ´Ø¿ô mframe_get_prop () ¤Ï¥Õ¥ì¡¼¥à $FRAME ¤Î¥­¡¼ $KEY 
736     ¤ò»ý¤Ä¥×¥í¥Ñ¥Æ¥£¤ÎÃͤòÊÖ¤¹¡£Í­¸ú¤Ê¥­¡¼¤È¤½¤ÎÃͤϰʲ¼¤ÎÄ̤ꡣ
737
738 @verbatim
739
740         ¥­¡¼            Ãͤη¿          ÃͤΰÕÌ£
741         ---             -------------   ----------------
742         Mface           MFace *         ¥Ç¥Õ¥©¥ë¥È¤Î¥Õ¥§¡¼¥¹
743
744         Mfont           MFont *         ¥Ç¥Õ¥©¥ë¥È¤Î¥Õ¥©¥ó¥È
745
746         Mfont_width     int             ¥Ç¥Õ¥©¥ë¥È¤Î¥Õ¥©¥ó¥È¤ÎÉý
747
748         Mfont_ascent    int             ¥Ç¥Õ¥©¥ë¥È¤Î¥Õ¥©¥ó¥È¤Î ascent
749
750         Mfont_descent   int             ¥Ç¥Õ¥©¥ë¥È¤Î¥Õ¥©¥ó¥È¤Î descent
751
752 @endverbatim
753
754      m17n-X ¥é¥¤¥Ö¥é¥ê¤Ç¤Ï¡¢°Ê²¼¤Î¥­¡¼¤â»ÈÍѤǤ­¤ë¡£
755
756 @verbatim
757
758         ¥­¡¼            Ãͤη¿          ÃͤΰÕÌ£
759         ---             -------------   ----------------
760         Mdisplay        Display *       ¥Õ¥ì¡¼¥à¤È´ØÏ¢ÉÕ¤±¤é¤ì¤¿¥Ç¥£¥¹¥×¥ì¥¤
761
762         Mscreen         int             ¥Õ¥ì¡¼¥à¤È´ØÏ¢ÉÕ¤±¤é¤ì¤¿¥¹¥¯¥ê¡¼¥ó
763                                         ¤Î¥¹¥¯¥ê¡¼¥ó¥Ê¥ó¥Ð
764
765         Mcolormap       Colormap        ¥Õ¥ì¡¼¥à¤Î¥«¥é¡¼¥Þ¥Ã¥×
766
767         Mdepth          unsigned        ¥Õ¥ì¡¼¥à¤Î¿¼¤µ
768 @endverbatim
769
770 */
771
772 void *
773 mframe_get_prop (MFrame *frame, MSymbol key)
774 {
775   if (key == Mface)
776     return frame->face;
777   if (key == Mfont)
778     return (frame->rface->rfont ? frame->rface->rfont->font : NULL);
779   if (key == Mfont_width)
780     return (void *) (frame->space_width);
781   if (key == Mfont_ascent)
782     return (void *) (frame->ascent);
783   if (key == Mfont_descent)
784     return (void *) (frame->descent);
785   return (*frame->driver->get_prop) (frame, key);
786 }
787
788 /*=*/
789
790 /***en
791     @brief The default frame.
792
793     The external variable #mframe_default contains a pointer to the
794     default frame that is created by the first call of mframe ().  */
795
796 /***ja
797     @brief ¥Ç¥Õ¥©¥ë¥È¤Î¥Õ¥ì¡¼¥à.
798
799     ³°ÉôÊÑ¿ô #mframe_default ¤Ï¡¢¥Ç¥Õ¥©¥ë¥È¤Î¥Õ¥ì¡¼¥à¤Ø¤Î¥Ý¥¤¥ó¥¿¤ò»ý¤Ä¡£
800     ¥Ç¥Õ¥©¥ë¥È¤Î¥Õ¥ì¡¼¥à¤Ï¡¢ºÇ½é¤Ë mframe () ¤¬¸Æ¤Ó½Ð¤µ¤ì¤¿¤È¤­¤Ëºî¤é¤ì¤ë¡£  */
801
802 MFrame *mframe_default;
803
804 /*** @} */
805
806 /*
807   Local Variables:
808   coding: euc-japan
809   End:
810 */