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