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 ¥¦¥£¥ó¥É¥¦¥·¥¹¥Æ¥à´ØÏ¢¤Î¿¸À¸ìÂбþ
43 ¤³¤Î¥»¥¯¥·¥ç¥ó¤Ï¥¦¥£¥ó¥É¥¦¥·¥¹¥Æ¥à¾å¤Ç¤Î M-text ¤Îɽ¼¨¤ÈÆþÎϤò°·¤¦
44 m17n-win API ¤òÄêµÁ¤¹¤ë¡£
46 ¤³¤³¤Ç¤Î¤¹¤Ù¤Æ¤ÎÄêµÁ¤Ï¥¦¥£¥ó¥É¥¦¥·¥¹¥Æ¥à¤È¤ÏÆÈΩ¤Ç¤¢¤ë¡£¤·¤«¤·¼ÂÁõ
47 ¤Ï¸ÄÊ̤Υ¦¥£¥ó¥É¥¦¥·¥¹¥Æ¥à¤Ë°Í¸¤¹¤ë¾ì¹ç¤¬¤¢¤ë¡£m17n-X ¥é¥¤¥Ö¥é¥ê
48 ¤Ï X ¥¦¥£¥ó¥É¥¦ÍѤμÂÁõÎã¤Ç¤¢¤ë¡£ */
52 #if !defined (FOR_DOXYGEN) || defined (DOXYGEN_INTERNAL_MODULE)
53 /*** @addtogroup m17nInternal
63 #include "m17n-misc.h"
65 #include "internal-gui.h"
70 static int win_initialized;
73 free_frame (void *object)
75 MFrame *frame = (MFrame *) object;
77 M17N_OBJECT_UNREF (frame->face);
78 mwin__close_device ((MFrame *) object);
87 #endif /* !FOR_DOXYGEN || DOXYGEN_INTERNAL_MODULE */
95 int mdebug_mask = MDEBUG_INIT;
103 Mfont = msymbol ("font");
104 Mfont_width = msymbol ("font-width");
105 Mfont_ascent = msymbol ("font-ascent");
106 Mfont_descent = msymbol ("font-descent");
110 if (mfont__init () < 0)
112 MDEBUG_PRINT_TIME ("INIT", (stderr, " to initialize font module."));
113 if (mwin__init () < 0)
115 MDEBUG_PRINT_TIME ("INIT", (stderr, " to initialize win module."));
116 if (mfont__fontset_init () < 0)
118 MDEBUG_PRINT_TIME ("INIT", (stderr, " to initialize fontset module."));
119 if (mface__init () < 0)
121 MDEBUG_PRINT_TIME ("INIT", (stderr, " to initialize face module."));
122 if (mdraw__init () < 0)
124 MDEBUG_PRINT_TIME ("INIT", (stderr, " to initialize draw module."));
125 if (minput__win_init () < 0)
127 MDEBUG_PRINT_TIME ("INIT", (stderr, " to initialize input-win module."));
128 mframe_default = NULL;
133 MDEBUG_PRINT_TIME ("INIT", (stderr, " to initialize the m17n GUI module."));
141 int mdebug_mask = MDEBUG_FINI;
147 MDEBUG_PRINT_TIME ("INIT", (stderr, " to finalize input-gui module."));
149 MDEBUG_PRINT_TIME ("INIT", (stderr, " to finalize draw module."));
151 MDEBUG_PRINT_TIME ("INIT", (stderr, " to finalize face module."));
153 MDEBUG_PRINT_TIME ("INIT", (stderr, " to finalize fontset module."));
154 mfont__fontset_fini ();
155 MDEBUG_PRINT_TIME ("INIT", (stderr, " to finalize window module."));
157 MDEBUG_PRINT_TIME ("INIT", (stderr, " to finalize font module."));
159 mframe_default = NULL;
161 MDEBUG_PRINT_TIME ("INIT", (stderr, " to finalize the gui modules."));
168 /*** @addtogroup m17nFrame */
170 @brief A @e frame is an object corresponding to the physical device.
172 A @e frame is an object of the type #MFrame to hold various
173 information about each physical display/input device. Almost all
174 m17n GUI functions require a pointer to a frame as an
178 @brief ¥Õ¥ì¡¼¥à¤È¤ÏʪÍýŪ¥Ç¥Ð¥¤¥¹¤ËÂбþ¤¹¤ë¥ª¥Ö¥¸¥§¥¯¥È¤Ç¤¢¤ë
180 ¥Õ¥ì¡¼¥à¤È¤Ï #MFrame ·¿¤Î¥ª¥Ö¥¸¥§¥¯¥È¤Ç¤¢¤ê¡¢¸Ä¡¹¤ÎʪÍýŪ¤Êɽ¼¨¡¿
181 ÆþÎϥǥХ¤¥¹¤Î¾ðÊó¤ò³ÊǼ¤¹¤ë¤¿¤á¤ËÍѤ¤¤é¤ì¤ë¡£¤Û¤È¤ó¤É¤¹¤Ù¤Æ¤Î
182 m17n-win API ¤Ï¡¢°ú¿ô¤È¤·¤Æ¥Õ¥ì¡¼¥à¤Ø¤Î¥Ý¥¤¥ó¥¿¤òÍ׵᤹¤ë¡£ */
188 @name Variables: Keys of frame property (common).
194 MSymbol Mfont_ascent;
195 MSymbol Mfont_descent;
202 @brief Create a new frame.
204 The mframe () function creates a new frame with parameters listed
207 The recognized keys in $PLIST are window system dependent.
209 The following key is always recognized.
213 <li> #Mface, the value type must be <tt>(MFace *)</tt>.
215 The value is used as the default face of the frame.
219 In addition, in the m17n-X library, the following keys are
220 recognized. They are to specify the root window and the depth of
221 drawables that can be used with the frame.
225 <li> #Mdrawable, the value type must be <tt>Drawable</tt>
227 A parameter of key #Mdisplay must also be specified. The
228 created frame can be used for drawables whose root window and
229 depth are the same as those of the specified drawable on the
232 When this parameter is specified, the parameter of key #Mscreen
235 <li> #Mwidget, the value type must be <tt>Widget</tt>.
237 The created frame can be used for drawables whose root window and
238 depth are the same as those of the specified widget.
240 If a parameter of key #Mface is not specified, the default face
241 is created from the resources of the widget.
243 When this parameter is specified, the parameters of key #Mdisplay,
244 #Mscreen, #Mdrawable, #Mdepth are ignored.
246 <li> #Mdepth, the value type must be <tt>unsigned</tt>.
248 The created frame can be used for drawables of the specified
251 <li> #Mscreen, the value type must be <tt>(Screen *)</tt>.
253 The created frame can be used for drawables whose root window is
254 the same as the root window of the specified screen, and depth is
255 the same at the default depth of the screen.
257 When this parameter is specified, parameter of key #Mdisplay is
260 <li> #Mdisplay, the value type must be <tt>(Display *)</tt>.
262 The created frame can be used for drawables whose root window is
263 the same as the root window for the default screen of the display,
264 and depth is the same as the default depth of the screen.
266 <li> #Mcolormap, the value type must be <tt>(Colormap)</tt>.
268 The created frame uses the specified colormap.
273 If the operation was successful, mframe () returns a pointer to a
274 newly created frame. Otherwise, it returns @c NULL. */
277 @brief ¿·¤·¤¤¥Õ¥ì¡¼¥à¤òºî¤ë
279 ´Ø¿ô mframe () ¤Ï¿·¤·¤¤¥Õ¥ì¡¼¥à¤òºî¤ë¡£°ìÈ̤ˡ¢°ú¿ô $ARGC ¤È $ARGV
280 ¤Ï³Æ¥¢¥×¥ê¥±¡¼¥·¥ç¥ó¤Î <tt>main ()</tt> ´Ø¿ô¤ËÍ¿¤¨¤é¤ì¤ë¤â¤Î¤ÈƱ¤¸
281 ¤â¤Î¤Ç¤¢¤ë¡£¤Ä¤Þ¤ê¥³¥Þ¥ó¥É¥é¥¤¥ó°ú¿ô¤ò´Þ¤ó¤Ç¤¤¤ëɬÍפ¬¤¢¤ë¡£»ÈÍѤÇ
282 ¤¤ë°ú¿ô¤Ï¥¦¥£¥ó¥É¥¦¥·¥¹¥Æ¥à¤Ë°Í¸¤¹¤ë¡£
284 m17n-X ¥é¥¤¥Ö¥é¥ê¤Ë¤ª¤±¤ë¤³¤Î´Ø¿ô¤Ï¡¢<tt>XOpenDisplay (NULL)</tt>
285 ¤ò»È¤Ã¤Æ¥Ç¥Õ¥©¥ë¥È¤Î¥Ç¥£¥¹¥×¥ì¥¤¤ò³«¤¡¢¼¡¤¤¤Ç <tt>DefaultScreen
286 (DISPLAY)</tt> ¤ò»È¤Ã¤Æ¥Ç¥Õ¥©¥ë¥È¤Î¥¹¥¯¥ê¡¼¥ó¤òÆÀ¤¿¸å¡¢ºî¤é¤ì¤¿¥Õ¥ì¡¼¥à
287 ¤Ë¤³¤Îξ¼Ô¤ò´ØÏ¢ÉÕ¤±¤ë¡£
289 m17n-X ¥é¥¤¥Ö¥é¥ê¤Ï°Ê²¼¤Î°ú¿ô¤ò¼õ¤±ÉÕ¤±¤ë¡£
291 @li @c -fn @e font : ¥Õ¥ì¡¼¥à¤Î¥Ç¥Õ¥©¥ë¥È¤Î¥Õ¥©¥ó¥È¤ò @e font
293 @li @c -fg @e color : ¥Õ¥ì¡¼¥à¤Î¥Ç¥Õ¥©¥ë¥È¤ÎÁ°·Ê¿§¤ò @e color
295 @li @c -bg @e color : ¥Õ¥ì¡¼¥à¤Î¥Ç¥Õ¥©¥ë¥È¤ÎÇØ·Ê¿§¤ò @e color
297 @li @c -rv : Á°·Ê¿§¤ÈÇØ·Ê¿§¤ò¸ò´¹¤¹¤ë
300 À®¸ù¤¹¤ì¤Ð mframe() ¤Ï¿·¤·¤¤¥Õ¥ì¡¼¥à¤Ø¤Î¥Ý¥¤¥ó¥¿¤òÊÖ¤¹¡£¤½¤¦¤Ç¤Ê¤±
301 ¤ì¤Ð @c NULL ¤òÊÖ¤¹¡£ */
304 mframe (MPlist *plist)
309 M17N_OBJECT (frame, free_frame, MERROR_FRAME);
310 frame->device = mwin__open_device (frame, plist);
314 MERROR (MERROR_WIN, NULL);
317 frame->face = mface_from_font (frame->font);
318 frame->face->property[MFACE_FONTSET] = mfontset (NULL);
319 M17N_OBJECT_REF (mface__default->property[MFACE_FONTSET]);
321 for (; (key = mplist_key (plist)) != Mnil; plist = mplist_next (plist))
323 mface_merge (frame->face, (MFace *) mplist_value (plist));
325 frame->rface = mface__realize (frame, NULL, 0, Mnil, Mnil, 0);
326 if (! frame->rface->rfont)
327 MERROR (MERROR_WIN, NULL);
328 frame->space_width = frame->rface->space_width;
329 frame->ascent = frame->rface->ascent;
330 frame->descent = frame->rface->descent;
332 if (! mframe_default)
333 mframe_default = frame;
341 @brief Return property value of frame.
343 The mframe_get_prop () function returns a value of property $KEY
344 of frame $FRAME. The valid keys and the corresponding return
345 values are as follows.
349 key type of value meaning of value
350 --- ------------- ----------------
351 Mface MFace * The default face.
353 Mfont MFont * The default font.
355 Mfont_width int Width of the default font.
357 Mfont_ascent int Ascent of the default font.
359 Mfont_descent int Descent of the default font.
363 In the m17n-X library, the followings are also accepted.
367 key type of value meaning of value
368 --- ------------- ----------------
369 Mdisplay Display * Display associated with the frame.
371 Mscreen int Screen number of a screen associated
374 Mcolormap Colormap Colormap of the frame.
376 Mdepth unsigned Depth of the frame.
381 @brief ¥Õ¥ì¡¼¥à¤ÎMWDevice¤òÊÖ¤¹
383 ´Ø¿ô mframe_device () ¤Ï¥Õ¥ì¡¼¥à $FRAME ¤Ë³ÊǼ¤µ¤ì¤Æ¤¤¤ë @c
384 MWDevice ¹½Â¤ÂΤؤΥݥ¤¥¿¤òÊÖ¤¹¡£#MWDevice ¤Î·Á¼°¤Ï¥¦¥£¥ó¥É¥¦¥·
385 ¥¹¥Æ¥à¤Ë°Í¸¤¹¤ë¡£ */
388 mframe_get_prop (MFrame *frame, MSymbol key)
393 return &frame->rface->rfont->font;
394 if (key == Mfont_width)
395 return (void *) (frame->space_width);
396 if (key == Mfont_ascent)
397 return (void *) (frame->ascent);
398 if (key == Mfont_descent)
399 return (void *) (frame->descent);
400 return mwin__device_get_prop (frame->device, key);
406 @brief The default frame.
408 The external variable #mframe_default contains a pointer to the
409 default frame that is created by the first call of mframe (). */
414 ³°ÉôÊÑ¿ô #mframe_default ¤Ï¡¢¥Ç¥Õ¥©¥ë¥È¤Î¥Õ¥ì¡¼¥à¤Ø¤Î¥Ý¥¤¥ó¥¿¤ò
415 »ý¤Ä¡£¥Ç¥Õ¥©¥ë¥È¤Î¥Õ¥ì¡¼¥à¤Ï¡¢ºÇ½é¤Ë mframe () ¤¬¸Æ¤Ó½Ð¤µ¤ì¤¿¤È¤¤Ë
418 MFrame *mframe_default;