(m17n_init_win): Initialize Mcolormap.
[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->dpi = (int) mplist_get (param, Mresolution);
213   if (frame->dpi == 0)
214     frame->dpi = 100;
215   frame->driver = &null_driver;
216   frame->font_driver_list = mplist ();
217   mplist_add (frame->font_driver_list, Mfreetype, &mfont__ft_driver);
218   frame->realized_font_list = null_device.realized_font_list;
219   frame->realized_face_list = null_device.realized_face_list;
220   frame->realized_fontset_list = null_device.realized_fontset_list;
221   face = mface_copy (mface__default);
222   mplist_push (param, Mface, face);
223   M17N_OBJECT_UNREF (face);
224   return 0;
225 }
226
227 static MDeviceLibraryInterface null_interface =
228   { NULL, NULL, null_device_init, null_device_open, null_device_fini };
229
230 #endif
231 \f
232 /* Internal API */
233
234 \f
235 /* External API */
236
237 void
238 m17n_init_win (void)
239 {
240   int mdebug_mask = MDEBUG_INIT;
241
242   merror_code = MERROR_NONE;
243   if (m17n__gui_initialized++)
244     return;
245   m17n_init ();
246   if (merror_code != MERROR_NONE)
247     {
248       m17n__gui_initialized--;
249       return;
250     }
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   Mcolormap = msymbol ("colormap");
268
269   MDEBUG_PUSH_TIME ();
270   if (mfont__init () < 0)
271     goto err;
272   MDEBUG_PRINT_TIME ("INIT", (stderr, " to initialize font module."));
273   if (mfont__fontset_init () < 0)
274     goto err;
275   MDEBUG_PRINT_TIME ("INIT", (stderr, " to initialize fontset module."));
276   if (mface__init () < 0)
277     goto err;
278   MDEBUG_PRINT_TIME ("INIT", (stderr, " to initialize face module."));
279   if (mdraw__init () < 0)
280     goto err;
281   MDEBUG_PRINT_TIME ("INIT", (stderr, " to initialize draw module."));
282   if (minput__win_init () < 0)
283     goto err;
284   MDEBUG_PRINT_TIME ("INIT", (stderr, " to initialize input-win module."));
285   mframe_default = NULL;
286
287   register_device_library (Mx, "libm17n-X");
288   register_device_library (Mgd, "libm17n-gd");
289   return;
290
291  err:
292   MDEBUG_POP_TIME ();
293   MDEBUG_PRINT_TIME ("INIT", (stderr, " to initialize the m17n GUI module."));
294   MDEBUG_POP_TIME ();
295 }
296
297 void
298 m17n_fini_win (void)
299 {
300   int mdebug_mask = MDEBUG_FINI;
301   MPlist *plist;
302
303   if (m17n__gui_initialized == 0
304       || --m17n__gui_initialized > 0)
305     return;
306
307   MDEBUG_PUSH_TIME ();
308   MDEBUG_PUSH_TIME ();
309   MDEBUG_PRINT_TIME ("FINI", (stderr, " to finalize device modules."));
310   MPLIST_DO (plist, device_library_list)
311     {
312       MDeviceLibraryInterface *interface = MPLIST_VAL (plist);
313
314       if (interface->handle && interface->fini)
315         {
316           (*interface->fini) ();
317           dlclose (interface->handle);
318         }
319       free (interface->library);
320       free (interface);
321     }
322 #ifdef HAVE_FREETYPE
323   if (null_interface.handle)
324     (*null_interface.fini) ();
325 #endif  /* not HAVE_FREETYPE */
326   M17N_OBJECT_UNREF (device_library_list);
327   MDEBUG_PRINT_TIME ("FINI", (stderr, " to finalize input-gui module."));
328   minput__win_fini ();
329   MDEBUG_PRINT_TIME ("FINI", (stderr, " to finalize draw module."));
330   mdraw__fini ();
331   MDEBUG_PRINT_TIME ("FINI", (stderr, " to finalize face module."));
332   mface__fini ();
333   MDEBUG_PRINT_TIME ("FINI", (stderr, " to finalize fontset module."));
334   mfont__fontset_fini ();
335   MDEBUG_PRINT_TIME ("FINI", (stderr, " to finalize font module."));
336   mfont__fini ();
337   mframe_default = NULL;
338   MDEBUG_POP_TIME ();
339   MDEBUG_PRINT_TIME ("FINI", (stderr, " to finalize the gui modules."));
340   MDEBUG_POP_TIME ();
341   m17n_fini ();
342 }
343
344 /*** @} */ 
345 #endif /* !FOR_DOXYGEN || DOXYGEN_INTERNAL_MODULE */
346
347 /*** @addtogroup m17nFrame */
348 /***en
349     @brief A @e frame is an object corresponding to the graphic device.
350
351     A @e frame is an object of the type #MFrame to hold various
352     information about each display/input device.  Almost all m17n GUI
353     functions require a pointer to a frame as an argument.  */
354 /***ja
355     @brief @e ¥Õ¥ì¡¼¥à ¤È¤Ï¥°¥é¥Õ¥£¥Ã¥¯¥Ç¥Ð¥¤¥¹¤ËÂбþ¤¹¤ë¥ª¥Ö¥¸¥§¥¯¥È¤Ç¤¢¤ë.
356
357     @e ¥Õ¥ì¡¼¥à ¤È¤Ï #MFrame 
358     ·¿¤Î¥ª¥Ö¥¸¥§¥¯¥È¤Ç¤¢¤ê¡¢¸Ä¡¹¤Îɽ¼¨¡¿ÆþÎϥǥХ¤¥¹¤Î¾ðÊó¤ò³ÊǼ¤¹¤ë¤¿¤á¤ËÍѤ¤¤é¤ì¤ë¡£
359     ¤Û¤È¤ó¤É¤¹¤Ù¤Æ¤Î m17n GUI´Ø¿ô¤Ï¡¢°ú¿ô¤È¤·¤Æ¥Õ¥ì¡¼¥à¤Ø¤Î¥Ý¥¤¥ó¥¿¤òÍ׵᤹¤ë¡£  */
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 create 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     The created frame uses the specified font backend.  The value #Mx
500     instructs to use X core fonts, #Mfreetype to use local fonts
501     supported by FreeType fonts, and #Mxft to use local fonts via Xft
502     library.  You can specify this parameter more than once with
503     different values if you want to use multiple font backends.  This
504     is ignored if the specified font backend is not supported on the
505     device.
506     
507     When this parameter is not specified, all font backend supported
508     on the device are used.
509
510     </ul>
511
512     @return
513     If the operation was successful, mframe () returns a pointer to a
514     newly created frame.  Otherwise, it returns @c NULL.  */
515
516 /***ja
517     @brief ¿·¤·¤¤¥Õ¥ì¡¼¥à¤òºî¤ë.
518
519     ´Ø¿ô mframe () ¤Ï $PLIST Ãæ¤Î¥Ñ¥é¥á¡¼¥¿¤ò»ý¤Ä¿·¤·¤¤¥Õ¥ì¡¼¥à¤òºî¤ë¡£
520     $PLIST ¤Ï @c NULL ¤Ç¤âÎɤ¤¡£
521
522     $PLIST ¤Ë¸½¤ï¤ì¤ë¥­¡¼¤Î¤¦¤Á¤É¤ì¤¬Ç§¼±¤µ¤ì¤ë¤«¤Ï¥¦¥£¥ó¥É¥¦¥·¥¹¥Æ¥à¤Ë°Í¸¤¹¤ë¡£
523
524     °Ê²¼¤Î¥­¡¼¤Ï¾ï¤Ëǧ¼±¤µ¤ì¤ë¡£
525
526     <ul>
527
528     <li> #Mdevice. ÃͤϠ#Mx, #Mgd, #Mnil ¤Î¤¤¤º¤ì¤«¤Ç¤Ê¤¯¤Æ¤Ï¤Ê¤é¤Ê¤¤¡£
529
530     Ãͤ¬ #Mx ¤Ê¤é¤Ð¡¢¿·¤·¤¤¥Õ¥ì¡¼¥à¤Ï X ¥¦¥£¥ó¥É¥¦¥·¥¹¥Æ¥àÍѤǤ¢¤ë¡£
531     ¤³¤Î¥Õ¥ì¡¼¥à¤È¶¦¤Ë»ØÄꤵ¤ì¤¿°ú¿ô #MDrawWindow ¤Ï¡¢ @c Window
532     ·¿¤Ç¤Ê¤¯¤Æ¤Ï¤Ê¤é¤Ê¤¤¡£¥Õ¥ì¡¼¥à¤ÏÆɤ߽ñ¤­¤È¤â¤Ë²Äǽ¤Ç¤¢¤ê¡¢¤¹¤Ù¤Æ¤ÎGUI 
533     ´Ø¿ô¤¬»ÈÍѤǤ­¤ë¡£
534
535     Ãͤ¬ #Mgd ¤Ê¤é¤Ð¡¢¿·¤·¤¤¥Õ¥ì¡¼¥à¤Ï GD 
536     ¥é¥¤¥Ö¥é¥ê¤Î¥¤¥á¡¼¥¸¥ª¥Ö¥¸¥§¥¯¥ÈÍѤǤ¢¤ë¡£¤³¤Î¥Õ¥ì¡¼¥à¤È¶¦¤Ë»ØÄꤵ¤ì¤¿°ú¿ô
537     #MDrawWindow ¤Ï¡¢ @c gdImagePtr ·¿¤Ç¤Ê¤¯¤Æ¤Ï¤Ê¤é¤Ê¤¤¡£¥Õ¥ì¡¼¥à¤Ï½ñ¤­½Ð¤·ÀìÍѤǤ¢¤ê¡¢
538     minput_ ¤Ç»Ï¤Þ¤ë̾Á°¤Î´Ø¿ô¤Ï»ÈÍѤǤ­¤Ê¤¤¡£
539
540     Ãͤ¬ #Mnil ¤Ê¤é¤Ð¡¢¿·¤·¤¤¥Õ¥ì¡¼¥à¤Ï, null 
541     ¥Ç¥Ð¥¤¥¹ÍѤǤ¢¤ë¡£¤³¤Î¥Õ¥ì¡¼¥à¤ÏÆɤ߽ñ¤­¤Ç¤­¤Ê¤¤¤Î¤Ç¡¢°ú¿ô #MDrawWindow 
542     ¤òɬÍפȤ¹¤ëmdraw_ ¤Ç»Ï¤Þ¤ë̾Á°¤Î´Ø¿ô¤ä¡¢minput_ ¤Ç»Ï¤Þ¤ë̾Á°¤Î´Ø¿ô¤Ï»ÈÍѤǤ­¤Ê¤¤¡£
543
544     <li> #Mface. ÃͤϠ#MFace ¤Ø¤Î¥Ý¥¤¥ó¥¿¤Ç¤Ê¤¯¤Æ¤Ï¤Ê¤é¤Ê¤¤¡£
545
546     ¤³¤ÎÃͤϥե졼¥à¤Î¥Ç¥Õ¥©¥ë¥È¤Î¥Õ¥§¡¼¥¹¤È¤·¤ÆÍѤ¤¤é¤ì¤ë¡£
547
548     </ul>
549
550     ¤³¤ì¤é¤Î¥­¡¼¤Ë²Ã¤¨¡¢#Mdevice ¤Î¥­¡¼¤¬ #Mx 
551     ¤Ç¤¢¤ë¾ì¹ç¤Ë¸Â¤ê°Ê²¼¤Î¥­¡¼¤âǧ¼±¤µ¤ì¤ë¡£°Ê²¼¤Î¥­¡¼¤Ï¥ë¡¼¥È¥¦¥£¥ó¥É¥¦¤È¡¢¥Õ¥ì¡¼¥à¤ÇÍøÍѤǤ­¤ë 
552     drawable ¤Î¿¼¤µ¤ò»ØÄꤹ¤ë¡£
553
554     <ul>
555
556     <li> #Mdrawable. ÃͤϠ<tt>Drawable</tt> ·¿¤Ç¤Ê¤¯¤Æ¤Ï¤Ê¤é¤Ê¤¤¡£
557
558     ¥­¡¼ #Mdisplay ¤ò»ý¤Ä¥Ñ¥é¥á¡¼¥¿¤â»ØÄꤵ¤ì¤Æ¤¤¤ëɬÍפ¬¤¢¤ë¡£
559     À¸À®¤µ¤ì¤¿¥Õ¥ì¡¼¥à¤Ï¡¢»ØÄꤵ¤ì¤¿¥Ç¥£¥¹¥×¥ì¥¤¾å¤Î»ØÄꤵ¤ì¤¿ drawable 
560     ¤ÈƱ¤¸¥ë¡¼¥È¥¦¥£¥ó¥É¥¦¤È¿¼¤µ¤ò»ý¤Ä drawable ¤ËÍѤ¤¤é¤ì¤ë¡£
561
562     ¤³¤Î¥Ñ¥é¥á¡¼¥¿¤¬¤¢¤ë¾ì¹ç¤Ë¤Ï¡¢#Mscreen ¤ò¥­¡¼¤È¤¹¤ë¥Ñ¥é¥á¡¼¥¿¤Ï̵»ë¤µ¤ì¤ë¡£
563
564     <li> #Mwidget. ÃͤϠ<tt>Widget</tt> ·¿¤Ç¤Ê¤¯¤Æ¤Ï¤Ê¤é¤Ê¤¤¡£
565
566     À¸À®¤µ¤ì¤¿¥Õ¥ì¡¼¥à¤Ï¡¢»ØÄꤷ¤¿¥¦¥£¥¸¥§¥Ã¥È¤ÈƱ¤¸¥ë¡¼¥È¥¦¥£¥ó¥É¥¦¤È¿¼¤µ¤ò»ý¤Ä
567     drawable ¤ËÍѤ¤¤é¤ì¤ë¡£
568
569     ¥­¡¼ #Mface ¤ò»ý¤Ä¥Ñ¥é¥á¡¼¥¿¤¬¤Ê¤±¤ì¤Ð¡¢¥Ç¥Õ¥©¥ë¥È¤Î¥Õ¥§¡¼¥¹¤Ï¤³¤Î
570     ¥¦¥£¥¸¥§¥Ã¥È¤Î¥ê¥½¡¼¥¹¤«¤éºî¤é¤ì¤ë¡£
571
572     ¤³¤Î¥Ñ¥é¥á¡¼¥¿¤¬¤¢¤ë¾ì¹ç¤Ë¤Ï¡¢#Mdisplay, #Mscreen, #Mdrawable,
573     #Mdepth ¤ò¥­¡¼¤È¤¹¤ë¥Ñ¥é¥á¡¼¥¿¤Ï̵»ë¤µ¤ì¤ë¡£
574
575     <li> #Mdepth. ÃͤϠ<tt>unsigned</tt>  ·¿¤Ç¤Ê¤¯¤Æ¤Ï¤Ê¤é¤Ê¤¤¡£
576
577     À¸À®¤µ¤ì¤¿¥Õ¥ì¡¼¥à¤Ï¡¢»ØÄꤷ¤¿¿¼¤µ¤Î drawable ¤ËÍѤ¤¤é¤ì¤ë¡£
578
579     <li> #Mscreen. ÃͤϠ<tt>(Screen *)</tt> ·¿¤Ç¤Ê¤¯¤Æ¤Ï¤Ê¤é¤Ê¤¤¡£
580
581     À¸À®¤·¤¿¥Õ¥ì¡¼¥à¤Ï¡¢»ØÄꤷ¤¿¥¹¥¯¥ê¡¼¥ó¤ÈƱ¤¸¥ë¡¼¥È¥¦¥£¥ó¥É¥¦¤ò»ý¤Á¡¢¥¹¥¯¥ê¡¼¥ó¤Î¥Ç¥Õ¥©¥ë¥È¤Î¿¼¤µ¤ÈƱ¤¸¿¼¤µ¤ò»ý¤Ä drawable ¤ËÍѤ¤¤é¤ì¤ë¡£
582
583     ¤³¤Î¥Ñ¥é¥á¡¼¥¿¤¬¤¢¤ë¾ì¹ç¤Ë¤Ï¡¢#Mdisplay ¤ò¥­¡¼¤È¤¹¤ë¥Ñ¥é¥á¡¼¥¿¤Ï̵»ë¤µ¤ì¤ë¡£
584
585     <li> #Mdisplay. ÃͤϠ<tt>(Display *)</tt> ·¿¤Ç¤Ê¤¯¤Æ¤Ï¤Ê¤é¤Ê¤¤¡£
586
587     À¸À®¤µ¤ì¤¿¥Õ¥ì¡¼¥à¤Ï¡¢»ØÄꤷ¤¿¥Ç¥£¥¹¥×¥ì¥¤¤Î¥Ç¥Õ¥©¥ë¥È¥¹¥¯¥ê¡¼¥ó¤ÈƱ¤¸¥ë¡¼¥È¥¦¥£¥ó¥É¥¦¤ÈƱ¤¸¿¼¤µ¤ò»ý¤Ädrawables ¤ËÍѤ¤¤é¤ì¤ë¡£
588
589     <li> #Mcolormap. ÃͤϠ<tt>(Colormap)</tt> ·¿¤Ç¤Ê¤¯¤Æ¤Ï¤Ê¤é¤Ê¤¤¡£
590
591     À¸À®¤µ¤ì¤¿¥Õ¥ì¡¼¥à¤Ï¡¢»ØÄꤷ¤¿¥«¥é¡¼¥Þ¥Ã¥×¤ò»ÈÍѤ¹¤ë¡£
592
593     <li> #Mfont. Ãͤϡ¢#Mx, #Mfreetype, #Mxft ¤Î¤¤¤º¤ì¤«¡£
594
595     À¸À®¤µ¤ì¤¿¥Õ¥ì¡¼¥à¤Ï»ØÄꤷ¤¿¥Õ¥©¥ó¥È¥Ð¥Ã¥¯¥¨¥ó¥É¤ò»ÈÍѤ¹¤ë¡£Ãͤ¬ 
596     #Mx ¤Ç¤¢¤ì¤Ð X ¤Î¥³¥¢¥Õ¥©¥ó¥È¡¢#Mfreetype ¤Ç¤¢¤ì¤Ð FreeType 
597     ¤Ç¥µ¥Ý¡¼¥È¤µ¤ì¤Æ¤¤¤ë¥í¡¼¥«¥ë¥Õ¥©¥ó¥È¡¢#Mxft ¤Ç¤¢¤ì¤Ð Xft 
598     ¥é¥¤¥Ö¥é¥ê·Ðͳ¤ÇÍѤ¤¤ë¥í¡¼¥«¥ë¥Õ¥©¥ó¥È¤ò»ÈÍѤ¹¤ë¡£
599     Ê£¿ô¤Î¥Õ¥©¥ó¥È¥Ð¥Ã¥¯¥¨¥ó¥É¤ò»ÈÍѤ·¤¿¤¤¾ì¹ç¤Ë¤Ï¡¢¤³¤Î¥Ñ¥é¥á¡¼¥¿¤òÊ£¿ô²ó¡¢°Û¤Ê¤ëÃͤǻØÄꤹ¤ë¤³¤È¤¬¤Ç¤­¤ë¡£
600     »ØÄꤷ¤¿¥Ð¥Ã¥¯¥¨¥ó¥É¤¬¥µ¥Ý¡¼¥È¤µ¤ì¤Æ¤¤¤Ê¤¤¥Ç¥Ð¥¤¥¹¤Ç¤Ï¡¢¤³¤Î¥Ñ¥é¥á¡¼¥¿¤Ï̵»ë¤µ¤ì¤ë¡£
601
602     ¤³¤Î¥Ñ¥é¥á¡¼¥¿¤¬Ìµ¤¤¾ì¹ç¤Ë¤Ï¡¢¥Ç¥Ð¥¤¥¹¤Ç¥µ¥Ý¡¼¥È¤µ¤ì¤Æ¤¤¤ë¤¹¤Ù¤Æ¤Î¥Õ¥©¥ó¥È¥Ð¥Ã¥¯¥¨¥ó¥É¤òÍøÍѤ¹¤ë¡£
603
604     </ul>
605
606     @return
607     À®¸ù¤¹¤ì¤Ð mframe() ¤Ï¿·¤·¤¤¥Õ¥ì¡¼¥à¤Ø¤Î¥Ý¥¤¥ó¥¿¤òÊÖ¤¹¡£¤½¤¦¤Ç¤Ê¤±¤ì¤Ð
608     @c NULL ¤òÊÖ¤¹¡£  */
609
610 MFrame *
611 mframe (MPlist *plist)
612 {
613   MFrame *frame;
614   int plist_created = 0;
615   MPlist *pl;
616   MSymbol device;
617   MDeviceLibraryInterface *interface;
618
619   if (plist)
620     {
621       pl = mplist_find_by_key (plist, Mdevice);
622       if (pl)
623         device = MPLIST_VAL (pl);
624       else
625         device = Mx;
626     }
627   else
628     {
629       plist = mplist ();
630       plist_created = 1;
631       device = Mx;
632     }
633
634   if (device == Mnil)
635     {
636 #ifdef HAVE_FREETYPE
637       interface = &null_interface;
638       if (! interface->handle)
639         {
640           (*interface->init) ();
641           interface->handle = (void *) 1;
642         }
643 #else  /* not HAVE_FREETYPE */
644       MERROR (MERROR_WIN, NULL);
645 #endif  /* not HAVE_FREETYPE */
646     }
647   else
648     {
649       interface = mplist_get (device_library_list, device);
650       if (! interface)
651         MERROR (MERROR_WIN, NULL);
652       if (! interface->handle)
653         {
654           if (! (interface->handle = dlopen (interface->library, RTLD_NOW))
655               || ! (interface->init
656                     = (int (*) ()) dlsym (interface->handle, "device_init"))
657               || ! (interface->open
658                     = (int (*) (MFrame *, MPlist *)) dlsym (interface->handle,
659                                                             "device_open"))
660               || ! (interface->fini
661                     = (int (*) ()) 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   frame->font
688     = frame->rface->rfont ? (MFont *) frame->rface->rfont : NULL;
689   if (plist_created)
690     M17N_OBJECT_UNREF (plist);
691   return frame;
692 }
693
694 /*=*/
695
696 /***en
697     @brief Return property value of frame.
698
699     The mframe_get_prop () function returns a value of property $KEY
700     of frame $FRAME.  The valid keys and the corresponding return
701     values are as follows.
702
703 @verbatim
704
705         key             type of value   meaning of value
706         ---             -------------   ----------------
707         Mface           MFace *         The default face.
708
709         Mfont           MFont *         The default font.
710
711         Mfont_width     int             Width of the default font.
712
713         Mfont_ascent    int             Ascent of the default font.
714
715         Mfont_descent   int             Descent of the default font.
716
717 @endverbatim
718
719     In the m17n-X library, the followings are also accepted.
720
721 @verbatim
722
723         key             type of value   meaning of value
724         ---             -------------   ----------------
725         Mdisplay        Display *       Display associated with the frame.
726
727         Mscreen         int             Screen number of a screen associated
728                                         with the frame.
729
730         Mcolormap       Colormap        Colormap of the frame.
731
732         Mdepth          unsigned        Depth of the frame.
733 @endverbatim
734 */
735
736 /***ja
737     @brief ¥Õ¥ì¡¼¥à¤Î¥×¥í¥Ñ¥Æ¥£¤ÎÃͤòÊÖ¤¹.
738
739     ´Ø¿ô mframe_get_prop () ¤Ï¥Õ¥ì¡¼¥à $FRAME ¤Î¥­¡¼ $KEY 
740     ¤ò»ý¤Ä¥×¥í¥Ñ¥Æ¥£¤ÎÃͤòÊÖ¤¹¡£Í­¸ú¤Ê¥­¡¼¤È¤½¤ÎÃͤϰʲ¼¤ÎÄ̤ꡣ
741
742 @verbatim
743
744         ¥­¡¼            Ãͤη¿          ÃͤΰÕÌ£
745         ---             -------------   ----------------
746         Mface           MFace *         ¥Ç¥Õ¥©¥ë¥È¤Î¥Õ¥§¡¼¥¹
747
748         Mfont           MFont *         ¥Ç¥Õ¥©¥ë¥È¤Î¥Õ¥©¥ó¥È
749
750         Mfont_width     int             ¥Ç¥Õ¥©¥ë¥È¤Î¥Õ¥©¥ó¥È¤ÎÉý
751
752         Mfont_ascent    int             ¥Ç¥Õ¥©¥ë¥È¤Î¥Õ¥©¥ó¥È¤Î ascent
753
754         Mfont_descent   int             ¥Ç¥Õ¥©¥ë¥È¤Î¥Õ¥©¥ó¥È¤Î descent
755
756 @endverbatim
757
758      m17n-X ¥é¥¤¥Ö¥é¥ê¤Ç¤Ï¡¢°Ê²¼¤Î¥­¡¼¤â»ÈÍѤǤ­¤ë¡£
759
760 @verbatim
761
762         ¥­¡¼            Ãͤη¿          ÃͤΰÕÌ£
763         ---             -------------   ----------------
764         Mdisplay        Display *       ¥Õ¥ì¡¼¥à¤È´ØÏ¢ÉÕ¤±¤é¤ì¤¿¥Ç¥£¥¹¥×¥ì¥¤
765
766         Mscreen         int             ¥Õ¥ì¡¼¥à¤È´ØÏ¢ÉÕ¤±¤é¤ì¤¿¥¹¥¯¥ê¡¼¥ó
767                                         ¤Î¥¹¥¯¥ê¡¼¥ó¥Ê¥ó¥Ð
768
769         Mcolormap       Colormap        ¥Õ¥ì¡¼¥à¤Î¥«¥é¡¼¥Þ¥Ã¥×
770
771         Mdepth          unsigned        ¥Õ¥ì¡¼¥à¤Î¿¼¤µ
772 @endverbatim
773
774 */
775
776 void *
777 mframe_get_prop (MFrame *frame, MSymbol key)
778 {
779   if (key == Mface)
780     return frame->face;
781   if (key == Mfont)
782     return frame->font;
783   if (key == Mfont_width)
784     return (void *) (frame->average_width);
785   if (key == Mfont_ascent)
786     return (void *) (frame->ascent);
787   if (key == Mfont_descent)
788     return (void *) (frame->descent);
789   return (*frame->driver->get_prop) (frame, key);
790 }
791
792 /*=*/
793
794 /***en
795     @brief The default frame.
796
797     The external variable #mframe_default contains a pointer to the
798     default frame that is created by the first call of mframe ().  */
799
800 /***ja
801     @brief ¥Ç¥Õ¥©¥ë¥È¤Î¥Õ¥ì¡¼¥à.
802
803     ³°ÉôÊÑ¿ô #mframe_default ¤Ï¡¢¥Ç¥Õ¥©¥ë¥È¤Î¥Õ¥ì¡¼¥à¤Ø¤Î¥Ý¥¤¥ó¥¿¤ò»ý¤Ä¡£
804     ¥Ç¥Õ¥©¥ë¥È¤Î¥Õ¥ì¡¼¥à¤Ï¡¢ºÇ½é¤Ë mframe () ¤¬¸Æ¤Ó½Ð¤µ¤ì¤¿¤È¤­¤Ëºî¤é¤ì¤ë¡£  */
805
806 MFrame *mframe_default;
807
808 /*** @} */
809
810 /*
811   Local Variables:
812   coding: euc-japan
813   End:
814 */