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
6 This file is part of the m17n library.
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.
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.
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
25 @brief GUI support for a window system.
27 This section defines the m17n GUI API concerning M-text drawing
28 and inputting under a window system.
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.
35 Actually the GUI API is mainly for toolkit libraries or to
36 implement XOM, not for direct use from application programs.
41 @brief ¥¦¥£¥ó¥É¥¦¥·¥¹¥Æ¥à¾å¤Î GUI ¥µ¥Ý¡¼¥È.
43 ¤³¤Î¥»¥¯¥·¥ç¥ó¤Ï¥¦¥£¥ó¥É¥¦¥·¥¹¥Æ¥à¤Î¤â¤È¤Ç¤Î M-text ¤Îɽ¼¨¤ÈÆþÎϤË
44 ¤«¤«¤ï¤ë m17n GUI API ¤òÄêµÁ¤¹¤ë¡£
46 ¤³¤³¤Ç¤Î¤¹¤Ù¤Æ¤ÎÄêµÁ¤Ï¥¦¥£¥ó¥É¥¦¥·¥¹¥Æ¥à¤È¤ÏÆÈΩ¤Ç¤¢¤ë¡£¤·¤«¤·¡¢¼Â
47 ºÝ¤Î¥é¥¤¥Ö¥é¥ê¥Õ¥¡¥¤¥ë¤Ï¸ÄÊ̤Υ¦¥£¥ó¥É¥¦¥·¥¹¥Æ¥à¤Ë°Í¸¤¹¤ë¾ì¹ç¤¬¤¢
48 ¤ë¡£¤¿¤È¤¨¤Ð¥é¥¤¥Ö¥é¥ê¥Õ¥¡¥¤¥ë m17n-X.so ¤Ï¡¢m17n GUI API ¤Î X ¥¦¥£
49 ¥ó¥É¥¦ÍѤμÂÁõÎã¤Ç¤¢¤ë¡£
51 ¸½¼Â¤Ë¤Ï¡¢GUI API ¤Ï¼ç¤Ë¥Ä¡¼¥ë¥¥Ã¥È¥é¥¤¥Ö¥é¥ê¸þ¤±¤Ç¤¢¤ë¤«¡¢¤Þ¤¿¤Ï
52 XOM ¤ò¼ÂÁõ¤¹¤ë¤¿¤á¤ËÍѤ¤¤é¤ì¤Æ¤ª¤ê¡¢¥¢¥×¥ê¥±¡¼¥·¥ç¥ó¥×¥í¥°¥é¥à¤«¤é
53 ¤ÎľÀܤÎÍøÍѤòǰƬ¤Ë¤ª¤¤¤¿¤â¤Î¤Ç¤Ï¤Ê¤¤¡£
58 #if !defined (FOR_DOXYGEN) || defined (DOXYGEN_INTERNAL_MODULE)
59 /*** @addtogroup m17nInternal
69 #include "m17n-misc.h"
71 #include "internal-gui.h"
76 static int win_initialized;
79 free_frame (void *object)
81 MFrame *frame = (MFrame *) object;
83 M17N_OBJECT_UNREF (frame->face);
84 mwin__close_device ((MFrame *) object);
93 #endif /* !FOR_DOXYGEN || DOXYGEN_INTERNAL_MODULE */
101 int mdebug_mask = MDEBUG_INIT;
106 if (merror_code != MERROR_NONE)
109 Mfont = msymbol ("font");
110 Mfont_width = msymbol ("font-width");
111 Mfont_ascent = msymbol ("font-ascent");
112 Mfont_descent = msymbol ("font-descent");
116 if (mfont__init () < 0)
118 MDEBUG_PRINT_TIME ("INIT", (stderr, " to initialize font module."));
119 if (mwin__init () < 0)
121 MDEBUG_PRINT_TIME ("INIT", (stderr, " to initialize win module."));
122 if (mfont__fontset_init () < 0)
124 MDEBUG_PRINT_TIME ("INIT", (stderr, " to initialize fontset module."));
125 if (mface__init () < 0)
127 MDEBUG_PRINT_TIME ("INIT", (stderr, " to initialize face module."));
128 if (mdraw__init () < 0)
130 MDEBUG_PRINT_TIME ("INIT", (stderr, " to initialize draw module."));
131 if (minput__win_init () < 0)
133 MDEBUG_PRINT_TIME ("INIT", (stderr, " to initialize input-win module."));
134 mframe_default = NULL;
139 MDEBUG_PRINT_TIME ("INIT", (stderr, " to initialize the m17n GUI module."));
147 int mdebug_mask = MDEBUG_FINI;
153 MDEBUG_PRINT_TIME ("FINI", (stderr, " to finalize input-gui module."));
155 MDEBUG_PRINT_TIME ("FINI", (stderr, " to finalize draw module."));
157 MDEBUG_PRINT_TIME ("FINI", (stderr, " to finalize face module."));
159 MDEBUG_PRINT_TIME ("FINI", (stderr, " to finalize fontset module."));
160 mfont__fontset_fini ();
161 MDEBUG_PRINT_TIME ("FINI", (stderr, " to finalize window module."));
163 MDEBUG_PRINT_TIME ("FINI", (stderr, " to finalize font module."));
165 mframe_default = NULL;
167 MDEBUG_PRINT_TIME ("FINI", (stderr, " to finalize the gui modules."));
174 /*** @addtogroup m17nFrame */
176 @brief A @e frame is an object corresponding to the physical device.
178 A @e frame is an object of the type #MFrame to hold various
179 information about each physical display/input device. Almost all
180 m17n GUI functions require a pointer to a frame as an
184 @brief @e ¥Õ¥ì¡¼¥à¤È¤ÏʪÍýŪ¥Ç¥Ð¥¤¥¹¤ËÂбþ¤¹¤ë¥ª¥Ö¥¸¥§¥¯¥È¤Ç¤¢¤ë.
186 @e ¥Õ¥ì¡¼¥à¤È¤Ï #MFrame ·¿¤Î¥ª¥Ö¥¸¥§¥¯¥È¤Ç¤¢¤ê¡¢¸Ä¡¹¤ÎʪÍýŪ¤Êɽ¼¨¡¿
187 ÆþÎϥǥХ¤¥¹¤Î¾ðÊó¤ò³ÊǼ¤¹¤ë¤¿¤á¤ËÍѤ¤¤é¤ì¤ë¡£¤Û¤È¤ó¤É¤¹¤Ù¤Æ¤Î
188 m17n GUI API ¤Ï¡¢°ú¿ô¤È¤·¤Æ¥Õ¥ì¡¼¥à¤Ø¤Î¥Ý¥¤¥ó¥¿¤òÍ׵᤹¤ë¡£ */
194 @name Variables: Keys of frame property (common).
196 @name ÊÑ¿ô¡§ ¥Õ¥ì¡¼¥à¥×¥í¥Ñ¥Æ¥£¤Î¥¡¼ (¶¦ÄÌ).
202 MSymbol Mfont_ascent;
203 MSymbol Mfont_descent;
210 @brief Create a new frame.
212 The mframe () function creates a new frame with parameters listed
215 The recognized keys in $PLIST are window system dependent.
217 The following key is always recognized.
221 <li> #Mface, the value type must be <tt>(MFace *)</tt>.
223 The value is used as the default face of the frame.
227 In addition, in the m17n-X library, the following keys are
228 recognized. They are to specify the root window and the depth of
229 drawables that can be used with the frame.
233 <li> #Mdrawable, the value type must be <tt>Drawable</tt>
235 A parameter of key #Mdisplay must also be specified. The
236 created frame can be used for drawables whose root window and
237 depth are the same as those of the specified drawable on the
240 When this parameter is specified, the parameter of key #Mscreen
243 <li> #Mwidget, the value type must be <tt>Widget</tt>.
245 The created frame can be used for drawables whose root window and
246 depth are the same as those of the specified widget.
248 If a parameter of key #Mface is not specified, the default face
249 is created from the resources of the widget.
251 When this parameter is specified, the parameters of key #Mdisplay,
252 #Mscreen, #Mdrawable, #Mdepth are ignored.
254 <li> #Mdepth, the value type must be <tt>unsigned</tt>.
256 The created frame can be used for drawables of the specified
259 <li> #Mscreen, the value type must be <tt>(Screen *)</tt>.
261 The created frame can be used for drawables whose root window is
262 the same as the root window of the specified screen, and depth is
263 the same at the default depth of the screen.
265 When this parameter is specified, parameter of key #Mdisplay is
268 <li> #Mdisplay, the value type must be <tt>(Display *)</tt>.
270 The created frame can be used for drawables whose root window is
271 the same as the root window for the default screen of the display,
272 and depth is the same as the default depth of the screen.
274 <li> #Mcolormap, the value type must be <tt>(Colormap)</tt>.
276 The created frame uses the specified colormap.
281 If the operation was successful, mframe () returns a pointer to a
282 newly created frame. Otherwise, it returns @c NULL. */
285 @brief ¿·¤·¤¤¥Õ¥ì¡¼¥à¤òºî¤ë.
287 ´Ø¿ô mframe () ¤Ï $PLIST Ãæ¤Î¥Ñ¥é¥á¡¼¥¿¤ò»ý¤Ä¿·¤·¤¤¥Õ¥ì¡¼¥à¤òºî¤ë¡£
289 $PLIST ¤Ë¸½¤ï¤ì¤ë¥¡¼¤Î¤¦¤Á¤É¤ì¤¬Ç§¼±¤µ¤ì¤ë¤«¤Ï¥¦¥£¥ó¥É¥¦¥·¥¹¥Æ¥à
290 ¤Ë°Í¸¤¹¤ë¡£¤·¤«¤·°Ê²¼¤Î¥¡¼¤Ï¾ï¤Ëǧ¼±¤µ¤ì¤ë¡£
294 <li> #Mface. ÃÍ¤Ï <tt>(MFace *)</tt> ·¿¤Ç¤Ê¤¯¤Æ¤Ï¤Ê¤é¤Ê¤¤¡£
296 ¤³¤ÎÃͤϥե졼¥à¤Î¥Ç¥Õ¥©¥ë¥È¤Î¥Õ¥§¡¼¥¹¤È¤·¤ÆÍѤ¤¤é¤ì¤ë¡£
300 ¤³¤ì¤Ë²Ã¤¨¤Æ¡¢m17n-X ¥é¥¤¥Ö¥é¥ê¤Ç¤Ï°Ê²¼¤Î¥¡¼¤âǧ¼±¤¹¤ë¡£¤³¤ì¤é¤Ï
301 ¥ë¡¼¥È¥¦¥£¥ó¥É¥¦¤È¡¢¥Õ¥ì¡¼¥à¤ÇÍøÍѤǤ¤ë drawable ¤Î¿¼¤µ¤ò»ØÄꤹ¤ë¡£
305 <li> #Mdrawable. ÃÍ¤Ï <tt>Drawable</tt> ·¿¤Ç¤Ê¤¯¤Æ¤Ï¤Ê¤é¤Ê¤¤¡£
307 ¥¡¼ #Mdisplay ¤ò»ý¤Ä¥Ñ¥é¥á¡¼¥¿¤â»ØÄꤵ¤ì¤Æ¤¤¤ëɬÍפ¬¤¢¤ë¡£À¸À®¤µ
308 ¤ì¤¿¥Õ¥ì¡¼¥à¤Ï¡¢»ØÄꤵ¤ì¤¿¥Ç¥£¥¹¥×¥ì¥¤¾å¤Î»ØÄꤵ¤ì¤¿ drawable ¤ÈƱ
309 ¤¸¥ë¡¼¥È¥¦¥£¥ó¥É¥¦¤È¿¼¤µ¤ò»ý¤Ä drawable ¤ËÍѤ¤¤é¤ì¤ë¡£
311 ¤³¤Î¥Ñ¥é¥á¡¼¥¿¤¬¤¢¤ë¾ì¹ç¤Ë¤Ï¡¢#Mscreen ¤ò¥¡¼¤È¤¹¤ë¥Ñ¥é¥á¡¼¥¿¤Ï̵
314 <li> #Mwidget. ÃÍ¤Ï <tt>Widget</tt> ·¿¤Ç¤Ê¤¯¤Æ¤Ï¤Ê¤é¤Ê¤¤¡£
316 À¸À®¤µ¤ì¤¿¥Õ¥ì¡¼¥à¤Ï¡¢»ØÄꤷ¤¿¥¦¥£¥¸¥§¥Ã¥È¤ÈƱ¤¸¥ë¡¼¥È¥¦¥£¥ó¥É¥¦¤È
317 ¿¼¤µ¤ò»ý¤Ä drawable ¤ËÍѤ¤¤é¤ì¤ë¡£
319 ¥¡¼ #Mface ¤ò»ý¤Ä¥Ñ¥é¥á¡¼¥¿¤¬¤Ê¤±¤ì¤Ð¡¢¥Ç¥Õ¥©¥ë¥È¤Î¥Õ¥§¡¼¥¹¤Ï¤³¤Î
320 ¥¦¥£¥¸¥§¥Ã¥È¤Î¥ê¥½¡¼¥¹¤«¤éºî¤é¤ì¤ë¡£
322 ¤³¤Î¥Ñ¥é¥á¡¼¥¿¤¬¤¢¤ë¾ì¹ç¤Ë¤Ï¡¢#Mdisplay, #Mscreen, #Mdrawable,
323 #Mdepth ¤ò¥¡¼¤È¤¹¤ë¥Ñ¥é¥á¡¼¥¿¤Ï̵»ë¤µ¤ì¤ë¡£
325 <li> #Mdepth. ÃÍ¤Ï <tt>unsigned</tt> ·¿¤Ç¤Ê¤¯¤Æ¤Ï¤Ê¤é¤Ê¤¤¡£
327 À¸À®¤µ¤ì¤¿¥Õ¥ì¡¼¥à¤Ï¡¢»ØÄꤷ¤¿¿¼¤µ¤Î drawable ¤ËÍѤ¤¤é¤ì¤ë¡£
329 <li> #Mscreen. ÃÍ¤Ï <tt>(Screen *)</tt> ·¿¤Ç¤Ê¤¯¤Æ¤Ï¤Ê¤é¤Ê¤¤¡£
331 À¸À®¤·¤¿¥Õ¥ì¡¼¥à¤Ï¡¢»ØÄꤷ¤¿¥¹¥¯¥ê¡¼¥ó¤ÈƱ¤¸¥ë¡¼¥È¥¦¥£¥ó¥É¥¦¤ò»ý¤Á¡¢
332 ¥¹¥¯¥ê¡¼¥ó¤Î¥Ç¥Õ¥©¥ë¥È¤Î¿¼¤µ¤ÈƱ¤¸¿¼¤µ¤ò»ý¤Ä drawable ¤ËÍѤ¤¤é¤ì¤ë¡£
334 ¤³¤Î¥Ñ¥é¥á¡¼¥¿¤¬¤¢¤ë¾ì¹ç¤Ë¤Ï¡¢#Mdisplay ¤ò¥¡¼¤È¤¹¤ë¥Ñ¥é¥á¡¼¥¿¤Ï̵
337 <li> #Mdisplay. ÃÍ¤Ï <tt>(Display *)</tt> ·¿¤Ç¤Ê¤¯¤Æ¤Ï¤Ê¤é¤Ê¤¤¡£
339 À¸À®¤µ¤ì¤¿¥Õ¥ì¡¼¥à¤Ï¡¢»ØÄꤷ¤¿¥Ç¥£¥¹¥×¥ì¥¤¤Î¥Ç¥Õ¥©¥ë¥È¥¹¥¯¥ê¡¼¥ó¤È
340 Ʊ¤¸¥ë¡¼¥È¥¦¥£¥ó¥É¥¦¤ÈƱ¤¸¿¼¤µ¤ò»ý¤Ädrawables ¤ËÍѤ¤¤é¤ì¤ë¡£
342 <li> #Mcolormap. ÃÍ¤Ï <tt>(Colormap)</tt> ·¿¤Ç¤Ê¤¯¤Æ¤Ï¤Ê¤é¤Ê¤¤¡£
344 À¸À®¤µ¤ì¤¿¥Õ¥ì¡¼¥à¤Ï¡¢»ØÄꤷ¤¿¥«¥é¡¼¥Þ¥Ã¥×¤ò»ÈÍѤ¹¤ë¡£
349 À®¸ù¤¹¤ì¤Ð mframe() ¤Ï¿·¤·¤¤¥Õ¥ì¡¼¥à¤Ø¤Î¥Ý¥¤¥ó¥¿¤òÊÖ¤¹¡£¤½¤¦¤Ç¤Ê¤±
350 ¤ì¤Ð @c NULL ¤òÊÖ¤¹¡£ */
353 mframe (MPlist *plist)
358 M17N_OBJECT (frame, free_frame, MERROR_FRAME);
359 frame->device = mwin__open_device (frame, plist);
363 MERROR (MERROR_WIN, NULL);
366 frame->face = mface_from_font (frame->font);
367 frame->face->property[MFACE_FONTSET] = mfontset (NULL);
368 M17N_OBJECT_REF (mface__default->property[MFACE_FONTSET]);
370 for (; (key = mplist_key (plist)) != Mnil; plist = mplist_next (plist))
372 mface_merge (frame->face, (MFace *) mplist_value (plist));
374 frame->rface = mface__realize (frame, NULL, 0, Mnil, Mnil, 0);
375 if (! frame->rface->rfont)
376 MERROR (MERROR_WIN, NULL);
377 frame->space_width = frame->rface->space_width;
378 frame->ascent = frame->rface->ascent;
379 frame->descent = frame->rface->descent;
381 if (! mframe_default)
382 mframe_default = frame;
390 @brief Return property value of frame.
392 The mframe_get_prop () function returns a value of property $KEY
393 of frame $FRAME. The valid keys and the corresponding return
394 values are as follows.
398 key type of value meaning of value
399 --- ------------- ----------------
400 Mface MFace * The default face.
402 Mfont MFont * The default font.
404 Mfont_width int Width of the default font.
406 Mfont_ascent int Ascent of the default font.
408 Mfont_descent int Descent of the default font.
412 In the m17n-X library, the followings are also accepted.
416 key type of value meaning of value
417 --- ------------- ----------------
418 Mdisplay Display * Display associated with the frame.
420 Mscreen int Screen number of a screen associated
423 Mcolormap Colormap Colormap of the frame.
425 Mdepth unsigned Depth of the frame.
430 @brief ¥Õ¥ì¡¼¥à¤Î¥×¥í¥Ñ¥Æ¥£¤ÎÃͤòÊÖ¤¹.
432 ´Ø¿ô mframe_get_prop () ¤Ï¥Õ¥ì¡¼¥à $FRAME ¤Î¥¡¼ $KEY ¤ò»ý¤Ä¥×¥í¥Ñ
433 ¥Æ¥£¤ÎÃͤòÊÖ¤¹¡£Í¸ú¤Ê¥¡¼¤È¤½¤ÎÃͤϰʲ¼¤ÎÄ̤ꡣ
438 --- ------------- ----------------
439 Mface MFace * ¥Ç¥Õ¥©¥ë¥È¤Î¥Õ¥§¡¼¥¹
441 Mfont MFont * ¥Ç¥Õ¥©¥ë¥È¤Î¥Õ¥©¥ó¥È
443 Mfont_width int ¥Ç¥Õ¥©¥ë¥È¤Î¥Õ¥©¥ó¥È¤ÎÉý
445 Mfont_ascent int ¥Ç¥Õ¥©¥ë¥È¤Î¥Õ¥©¥ó¥È¤Î ascent
447 Mfont_descent int ¥Ç¥Õ¥©¥ë¥È¤Î¥Õ¥©¥ó¥È¤Î descent
451 m17n-X ¥é¥¤¥Ö¥é¥ê¤Ç¤Ï¡¢°Ê²¼¤Î¥¡¼¤â»ÈÍѤǤ¤ë¡£
456 --- ------------- ----------------
457 Mdisplay Display * ¥Õ¥ì¡¼¥à¤È´ØÏ¢ÉÕ¤±¤é¤ì¤¿¥Ç¥£¥¹¥×¥ì¥¤
459 Mscreen int ¥Õ¥ì¡¼¥à¤È´ØÏ¢ÉÕ¤±¤é¤ì¤¿¥¹¥¯¥ê¡¼¥ó
462 Mcolormap Colormap ¥Õ¥ì¡¼¥à¤Î¥«¥é¡¼¥Þ¥Ã¥×
464 Mdepth unsigned ¥Õ¥ì¡¼¥à¤Î¿¼¤µ
470 mframe_get_prop (MFrame *frame, MSymbol key)
475 return &frame->rface->rfont->font;
476 if (key == Mfont_width)
477 return (void *) (frame->space_width);
478 if (key == Mfont_ascent)
479 return (void *) (frame->ascent);
480 if (key == Mfont_descent)
481 return (void *) (frame->descent);
482 return mwin__device_get_prop (frame->device, key);
488 @brief The default frame.
490 The external variable #mframe_default contains a pointer to the
491 default frame that is created by the first call of mframe (). */
494 @brief ¥Ç¥Õ¥©¥ë¥È¤Î¥Õ¥ì¡¼¥à.
496 ³°ÉôÊÑ¿ô #mframe_default ¤Ï¡¢¥Ç¥Õ¥©¥ë¥È¤Î¥Õ¥ì¡¼¥à¤Ø¤Î¥Ý¥¤¥ó¥¿¤ò»ý
497 ¤Ä¡£¥Ç¥Õ¥©¥ë¥È¤Î¥Õ¥ì¡¼¥à¤Ï¡¢ºÇ½é¤Ë mframe () ¤¬¸Æ¤Ó½Ð¤µ¤ì¤¿¤È¤¤Ë
500 MFrame *mframe_default;