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);
86 #endif /* !FOR_DOXYGEN || DOXYGEN_INTERNAL_MODULE */
94 int mdebug_mask = MDEBUG_INIT;
102 Mfont = msymbol ("font");
103 Mfont_width = msymbol ("font-width");
104 Mfont_ascent = msymbol ("font-ascent");
105 Mfont_descent = msymbol ("font-descent");
109 if (mfont__init () < 0)
111 MDEBUG_PRINT_TIME ("INIT", (stderr, " to initialize font module."));
112 if (mwin__init () < 0)
114 MDEBUG_PRINT_TIME ("INIT", (stderr, " to initialize win module."));
115 if (mfont__fontset_init () < 0)
117 MDEBUG_PRINT_TIME ("INIT", (stderr, " to initialize fontset module."));
118 if (mface__init () < 0)
120 MDEBUG_PRINT_TIME ("INIT", (stderr, " to initialize face module."));
121 if (mdraw__init () < 0)
123 MDEBUG_PRINT_TIME ("INIT", (stderr, " to initialize draw module."));
124 if (minput__win_init () < 0)
126 MDEBUG_PRINT_TIME ("INIT", (stderr, " to initialize input-win module."));
127 mframe_default = NULL;
132 MDEBUG_PRINT_TIME ("INIT", (stderr, " to initialize the m17n GUI module."));
140 int mdebug_mask = MDEBUG_FINI;
146 MDEBUG_PRINT_TIME ("INIT", (stderr, " to finalize input-gui module."));
148 MDEBUG_PRINT_TIME ("INIT", (stderr, " to finalize draw module."));
150 MDEBUG_PRINT_TIME ("INIT", (stderr, " to finalize face module."));
152 MDEBUG_PRINT_TIME ("INIT", (stderr, " to finalize fontset module."));
153 mfont__fontset_fini ();
154 MDEBUG_PRINT_TIME ("INIT", (stderr, " to finalize window module."));
156 MDEBUG_PRINT_TIME ("INIT", (stderr, " to finalize font module."));
158 mframe_default = NULL;
160 MDEBUG_PRINT_TIME ("INIT", (stderr, " to finalize the gui modules."));
167 /*** @addtogroup m17nFrame */
169 @brief A @e frame is an object corresponding to the physical device.
171 A @e frame is an object of the type #MFrame to hold various
172 information about each physical display/input device. Almost all
173 m17n GUI functions require a pointer to a frame as an
177 @brief ¥Õ¥ì¡¼¥à¤È¤ÏʪÍýŪ¥Ç¥Ð¥¤¥¹¤ËÂбþ¤¹¤ë¥ª¥Ö¥¸¥§¥¯¥È¤Ç¤¢¤ë
179 ¥Õ¥ì¡¼¥à¤È¤Ï #MFrame ·¿¤Î¥ª¥Ö¥¸¥§¥¯¥È¤Ç¤¢¤ê¡¢¸Ä¡¹¤ÎʪÍýŪ¤Êɽ¼¨¡¿
180 ÆþÎϥǥХ¤¥¹¤Î¾ðÊó¤ò³ÊǼ¤¹¤ë¤¿¤á¤ËÍѤ¤¤é¤ì¤ë¡£¤Û¤È¤ó¤É¤¹¤Ù¤Æ¤Î
181 m17n-win API ¤Ï¡¢°ú¿ô¤È¤·¤Æ¥Õ¥ì¡¼¥à¤Ø¤Î¥Ý¥¤¥ó¥¿¤òÍ׵᤹¤ë¡£ */
187 @name Variables: Keys of frame property (common).
193 MSymbol Mfont_ascent;
194 MSymbol Mfont_descent;
201 @brief Create a new frame.
203 The mframe () function creates a new frame with parameters listed
206 The recognized keys in $PLIST are window system dependent.
208 The following key is always recognized.
212 <li> #Mface, the value type must be <tt>(MFace *)</tt>.
214 The value is used as the default face of the frame.
218 In addition, in the m17n-X library, the following keys are
219 recognized. They are to specify the root window and the depth of
220 drawables that can be used with the frame.
224 <li> #Mdrawable, the value type must be <tt>Drawable</tt>
226 A parameter of key #Mdisplay must also be specified. The
227 created frame can be used for drawables whose root window and
228 depth are the same as those of the specified drawable on the
231 When this parameter is specified, the parameter of key #Mscreen
234 <li> #Mwidget, the value type must be <tt>Widget</tt>.
236 The created frame can be used for drawables whose root window and
237 depth are the same as those of the specified widget.
239 If a parameter of key #Mface is not specified, the default face
240 is created from the resources of the widget.
242 When this parameter is specified, the parameters of key #Mdisplay,
243 #Mscreen, #Mdrawable, #Mdepth are ignored.
245 <li> #Mdepth, the value type must be <tt>unsigned</tt>.
247 The created frame can be used for drawables of the specified
250 <li> #Mscreen, the value type must be <tt>(Screen *)</tt>.
252 The created frame can be used for drawables whose root window is
253 the same as the root window of the specified screen, and depth is
254 the same at the default depth of the screen.
256 When this parameter is specified, parameter of key #Mdisplay is
259 <li> #Mdisplay, the value type must be <tt>(Display *)</tt>.
261 The created frame can be used for drawables whose root window is
262 the same as the root window for the default screen of the display,
263 and depth is the same as the default depth of the screen.
265 <li> #Mcolormap, the value type must be <tt>(Colormap)</tt>.
267 The created frame uses the specified colormap.
272 If the operation was successful, mframe () returns a pointer to a
273 newly created frame. Otherwise, it returns @c NULL. */
276 @brief ¿·¤·¤¤¥Õ¥ì¡¼¥à¤òºî¤ë
278 ´Ø¿ô mframe () ¤Ï¿·¤·¤¤¥Õ¥ì¡¼¥à¤òºî¤ë¡£°ìÈ̤ˡ¢°ú¿ô $ARGC ¤È $ARGV
279 ¤Ï³Æ¥¢¥×¥ê¥±¡¼¥·¥ç¥ó¤Î <tt>main ()</tt> ´Ø¿ô¤ËÍ¿¤¨¤é¤ì¤ë¤â¤Î¤ÈƱ¤¸
280 ¤â¤Î¤Ç¤¢¤ë¡£¤Ä¤Þ¤ê¥³¥Þ¥ó¥É¥é¥¤¥ó°ú¿ô¤ò´Þ¤ó¤Ç¤¤¤ëɬÍפ¬¤¢¤ë¡£»ÈÍѤÇ
281 ¤¤ë°ú¿ô¤Ï¥¦¥£¥ó¥É¥¦¥·¥¹¥Æ¥à¤Ë°Í¸¤¹¤ë¡£
283 m17n-X ¥é¥¤¥Ö¥é¥ê¤Ë¤ª¤±¤ë¤³¤Î´Ø¿ô¤Ï¡¢<tt>XOpenDisplay (NULL)</tt>
284 ¤ò»È¤Ã¤Æ¥Ç¥Õ¥©¥ë¥È¤Î¥Ç¥£¥¹¥×¥ì¥¤¤ò³«¤¡¢¼¡¤¤¤Ç <tt>DefaultScreen
285 (DISPLAY)</tt> ¤ò»È¤Ã¤Æ¥Ç¥Õ¥©¥ë¥È¤Î¥¹¥¯¥ê¡¼¥ó¤òÆÀ¤¿¸å¡¢ºî¤é¤ì¤¿¥Õ¥ì¡¼¥à
286 ¤Ë¤³¤Îξ¼Ô¤ò´ØÏ¢ÉÕ¤±¤ë¡£
288 m17n-X ¥é¥¤¥Ö¥é¥ê¤Ï°Ê²¼¤Î°ú¿ô¤ò¼õ¤±ÉÕ¤±¤ë¡£
290 @li @c -fn @e font : ¥Õ¥ì¡¼¥à¤Î¥Ç¥Õ¥©¥ë¥È¤Î¥Õ¥©¥ó¥È¤ò @e font
292 @li @c -fg @e color : ¥Õ¥ì¡¼¥à¤Î¥Ç¥Õ¥©¥ë¥È¤ÎÁ°·Ê¿§¤ò @e color
294 @li @c -bg @e color : ¥Õ¥ì¡¼¥à¤Î¥Ç¥Õ¥©¥ë¥È¤ÎÇØ·Ê¿§¤ò @e color
296 @li @c -rv : Á°·Ê¿§¤ÈÇØ·Ê¿§¤ò¸ò´¹¤¹¤ë
299 À®¸ù¤¹¤ì¤Ð mframe() ¤Ï¿·¤·¤¤¥Õ¥ì¡¼¥à¤Ø¤Î¥Ý¥¤¥ó¥¿¤òÊÖ¤¹¡£¤½¤¦¤Ç¤Ê¤±
300 ¤ì¤Ð @c NULL ¤òÊÖ¤¹¡£ */
303 mframe (MPlist *plist)
308 M17N_OBJECT (frame, free_frame, MERROR_FRAME);
309 frame->device = mwin__open_device (frame, plist);
313 MERROR (MERROR_WIN, NULL);
316 frame->face = mface_copy (mface__default);
318 for (; (key = mplist_key (plist)) != Mnil; plist = mplist_next (plist))
320 mface_merge (frame->face, (MFace *) mplist_value (plist));
322 frame->rface = mface__realize (frame, NULL, 0, Mnil, Mnil, 0);
323 if (! frame->rface->rfont)
324 MERROR (MERROR_WIN, NULL);
325 frame->space_width = frame->rface->space_width;
326 frame->ascent = frame->rface->ascent;
327 frame->descent = frame->rface->descent;
329 if (! mframe_default)
330 mframe_default = frame;
338 @brief Return property value of frame.
340 The mframe_get_prop () function returns a value of property $KEY
341 of frame $FRAME. The valid keys and the corresponding return
342 values are as follows.
346 key type of value meaning of value
347 --- ------------- ----------------
348 Mface MFace * The default face.
350 Mfont MFont * The default font.
352 Mfont_width int Width of the default font.
354 Mfont_ascent int Ascent of the default font.
356 Mfont_descent int Descent of the default font.
360 In the m17n-X library, the followings are also accepted.
364 key type of value meaning of value
365 --- ------------- ----------------
366 Mdisplay Display * Display associated with the frame.
368 Mscreen int Screen number of a screen associated
371 Mcolormap Colormap Colormap of the frame.
373 Mdepth unsigned Depth of the frame.
378 @brief ¥Õ¥ì¡¼¥à¤ÎMWDevice¤òÊÖ¤¹
380 ´Ø¿ô mframe_device () ¤Ï¥Õ¥ì¡¼¥à $FRAME ¤Ë³ÊǼ¤µ¤ì¤Æ¤¤¤ë @c
381 MWDevice ¹½Â¤ÂΤؤΥݥ¤¥¿¤òÊÖ¤¹¡£#MWDevice ¤Î·Á¼°¤Ï¥¦¥£¥ó¥É¥¦¥·
382 ¥¹¥Æ¥à¤Ë°Í¸¤¹¤ë¡£ */
385 mframe_get_prop (MFrame *frame, MSymbol key)
390 return &frame->rface->rfont->font;
391 if (key == Mfont_width)
392 return (void *) (frame->space_width);
393 if (key == Mfont_ascent)
394 return (void *) (frame->ascent);
395 if (key == Mfont_descent)
396 return (void *) (frame->descent);
397 return mwin__device_get_prop (frame->device, key);
403 @brief The default frame.
405 The external variable #mframe_default contains a pointer to the
406 default frame that is created by the first call of mframe (). */
411 ³°ÉôÊÑ¿ô #mframe_default ¤Ï¡¢¥Ç¥Õ¥©¥ë¥È¤Î¥Õ¥ì¡¼¥à¤Ø¤Î¥Ý¥¤¥ó¥¿¤ò
412 »ý¤Ä¡£¥Ç¥Õ¥©¥ë¥È¤Î¥Õ¥ì¡¼¥à¤Ï¡¢ºÇ½é¤Ë mframe () ¤¬¸Æ¤Ó½Ð¤µ¤ì¤¿¤È¤¤Ë
415 MFrame *mframe_default;