/* medit.c -- simple multilingual editor. -*- coding: euc-jp; -*-
- Copyright (C) 2003, 2004, 2005
+ Copyright (C) 2003, 2004, 2005, 2006, 2007
National Institute of Advanced Industrial Science and Technology (AIST)
Registration Number H15PRO112
You should have received a copy of the GNU Lesser General Public
License along with the m17n library; if not, write to the Free
- Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
02111-1307, USA. */
/***en
This program is to demonstrate how to use the m17n GUI API.
Although m17n-edit directly uses the GUI API, the API is mainly
- for toolkit libraries or to implement XOM (X Outout Method), not
+ for toolkit libraries or to implement XOM (X Output Method), not
for direct use from application programs.
*/
/***ja
¤³¤Î¥×¥í¥°¥é¥à¤Ï m17n GUI API ¤Î»È¤¤Êý¤ò¼¨¤¹¤â¤Î¤Ç¤¢¤ë¡£m17n-edit
¤ÏľÀÜ GUI API ¤ò»È¤Ã¤Æ¤¤¤ë¤¬¡¢¤³¤Î API ¤Ï¼ç¤Ë¥Ä¡¼¥ë¥¥Ã¥È¥é¥¤¥Ö¥é
- ¥ê¤äXOM (X Outout Method) ¤Î¼ÂÁõÍѤǤ¢¤ê¡¢¥¢¥×¥ê¥±¡¼¥·¥ç¥ó¥×¥í¥°¥é
+ ¥ê¤äXOM (X Output Method) ¤Î¼ÂÁõÍѤǤ¢¤ê¡¢¥¢¥×¥ê¥±¡¼¥·¥ç¥ó¥×¥í¥°¥é
¥à¤«¤é¤ÎľÀܤÎÍøÍѤò°Õ¿Þ¤·¤Æ¤¤¤Ê¤¤¡£
*/
#include <X11/Xaw/SmeLine.h>
#include <X11/Xaw/MenuButton.h>
-#define VERSION "1.2.0"
-
/* Global variables. */
char *filename;
MFrame *frame;
MText *mt;
int nchars; /* == mtext_len (mt) */
+int mt_modified;
MDrawControl control, input_status_control;
MTextProperty *selection;
{
int from; /* BOL position of the line. */
int to; /* BOL position of the next line. */
- int y0, y1; /* Top and bottom Y position of the line. */
+ int y0, y1; /* Top and bottom Y position of the line. */
int ascent; /* Height of the top Y position. */
};
else
{
XtSetArg (arg[0], XtNborderWidth, 1);
- XtSetArg (arg[1], XtNlabel,
- msymbol_name (msymbol_get (sym, Mlanguage)));
+ XtSetArg (arg[1], XtNlabel, mlanguage_name (sym));
XtSetValues (CurLangWidget, arg, 2);
}
XtSetValues (CurLangWidget, arg, 2);
{
MText *produced = mtext ();
- minput_lookup (current_input_context, Mnil, NULL, produced);
+ minput_lookup (current_input_context, Mnil, NULL, produced);
if (mtext_len (produced) > 0)
{
insert_chars (produced);
/* If set to 1, do not update target_x_position. */
int keep_target_x_position = 0;
MText *produced;
+ int y0, old_y1, new_y1;
+
+ hide_cursor ();
+ mt_modified = 0;
+ y0 = cur.y0;
+ old_y1 = cur.y1;
if (current_input_context
&& minput_filter (current_input_context, Mnil, event))
- return;
+ {
+ if (mt_modified)
+ {
+ new_y1 = cur.y1;
+ update_region (y0, old_y1, new_y1);
+ }
+ return;
+ }
if (event->type == KeyRelease)
return;
- hide_cursor ();
-
produced = mtext ();
ret = minput_lookup (current_input_context, Mnil, event, produced);
if (mtext_len (produced) > 0)
{
int len = (int) mplist_value (ic->plist);
int pos;
- MText *surround = NULL;
+ MText *surround;
if (len < 0)
{
pos = nchars;
surround = mtext_duplicate (mt, cursor.from, pos);
}
- if (surround)
- {
- mplist_set (ic->plist, Mtext, surround);
- m17n_object_unref (surround);
- }
+ else
+ surround = mtext ();
+ mplist_set (ic->plist, Mtext, surround);
+ m17n_object_unref (surround);
}
else if (command == Minput_delete_surrounding_text)
{
if (cursor.from + len < 0)
len = - cursor.from;
mtext_del (mt, cursor.from + len, cursor.from);
- cursor.from += len;
+ nchars += len;
+ update_cursor (cursor.from + len, 1);
}
else if (len > 0)
{
if (cursor.from + len > nchars)
len = nchars - cursor.from;
mtext_del (mt, cursor.from, cursor.from + len);
+ nchars -= len;
+ update_cursor (cursor.from, 1);
}
+ if (len)
+ mt_modified = 1;
}
}
return 1;
if (im2->language == Mt)
return -1;
- lang1 = msymbol_get (im1->language, Mlanguage);
- lang2 = msymbol_get (im2->language, Mlanguage);
+ lang1 = mlanguage_name (im1->language);
+ lang2 = mlanguage_name (im2->language);
return strcmp (msymbol_name (lang1), msymbol_name (lang2));
}
qsort (input_method_table, num_input_methods, sizeof input_method_table[0],
compare_input_method);
- mplist_put (minput_driver->callback_list, Minput_status_start,
- (void *) input_status);
- mplist_put (minput_driver->callback_list, Minput_status_draw,
- (void *) input_status);
- mplist_put (minput_driver->callback_list, Minput_status_done,
- (void *) input_status);
- mplist_put (minput_driver->callback_list, Minput_get_surrounding_text,
- (void *) surrounding_text_handler);
- mplist_put (minput_driver->callback_list, Minput_delete_surrounding_text,
- (void *) surrounding_text_handler);
+ mplist_put_func (minput_driver->callback_list, Minput_status_start,
+ M17N_FUNC (input_status));
+ mplist_put_func (minput_driver->callback_list, Minput_status_draw,
+ M17N_FUNC (input_status));
+ mplist_put_func (minput_driver->callback_list, Minput_status_done,
+ M17N_FUNC (input_status));
+ mplist_put_func (minput_driver->callback_list, Minput_get_surrounding_text,
+ M17N_FUNC (surrounding_text_handler));
+ mplist_put_func (minput_driver->callback_list, Minput_delete_surrounding_text,
+ M17N_FUNC (surrounding_text_handler));
current_input_context = NULL;
current_input_method = -1;
XtSetArg (arg[3], XtNhighlightThickness, 1);
XtSetArg (arg[4], XtNleft, XawChainLeft);
XtSetArg (arg[5], XtNright, XawChainLeft);
- i = 6;
+ XtSetArg (arg[6], XtNinternational, True);
+ i = 7;
if (left)
XtSetArg (arg[i], XtNfromHoriz, left), i++;
button = XtCreateManagedWidget (button_name, menuButtonWidgetClass, parent,
{
Widget form, BodyWidget, w;
char *fontset_name = NULL;
+ char *font_name = NULL;
int fontsize = 0;
char *initial_input_method = NULL;
int col = 80, row = 32;
int with_xim = 0;
int i, j;
char *filter = NULL;
+ MFont *font = NULL;
setlocale (LC_ALL, "");
/* Create the top shell. */
help_exit (argv[0], 0);
else if (! strcmp (argv[i], "--version"))
{
- printf ("m17n-edit (m17n library) %s\n", VERSION);
- printf ("Copyright (C) 2003 AIST, JAPAN\n");
+ printf ("m17n-edit (m17n library) %s\n", M17NLIB_VERSION_NAME);
+ printf ("Copyright (C) 2003, 2004, 2005, 2006, 2007 AIST, JAPAN\n");
exit (0);
}
else if (! strcmp (argv[i], "--geometry"))
i++;
fontset_name = strdup (argv[i]);
}
+ else if (! strcmp (argv[i], "--font"))
+ {
+ i++;
+ font_name = strdup (argv[i]);
+ }
else if (! strcmp (argv[i], "--im"))
{
i++;
{
MPlist *plist = mplist ();
- MFace *face;
MFont *font;
mplist_put (plist, msymbol ("widget"), ShellWidget);
- if (fontset_name || fontsize > 0)
+ if (fontset_name || font_name || fontsize > 0)
{
- MFontset *fontset = mfontset (fontset_name);
-
- face = mface ();
- mface_put_prop (face, Mfontset, fontset);
- mface_put_prop (face, Msize, (void *) fontsize);
- m17n_object_unref (fontset);
+ MFace *face;
+
+ if (font_name)
+ {
+ font = mfont_parse_name (font_name, Mnil);
+ if (font)
+ face = mface_from_font (font);
+ else
+ face = mface ();
+ }
+ else
+ face = mface ();
+ if (fontset_name)
+ {
+ MFontset *fontset = mfontset (fontset_name);
+
+ mface_put_prop (face, Mfontset, fontset);
+ m17n_object_unref (fontset);
+ }
+ if (fontsize > 0)
+ mface_put_prop (face, Msize, (void *) fontsize);
mplist_add (plist, Mface, face);
m17n_object_unref (face);
}
if (im->language != Mnil && im->language != Mt)
{
- MSymbol sym = msymbol_get (im->language, Mlanguage);
+ MSymbol sym = mlanguage_name (im->language);
if (sym == Mnil)
name1 = msymbol_name (im->language);
else
MSymbol fullname;
if (sym != Mnil
- && ((fullname = msymbol_get (sym, Mlanguage)) != Mnil))
+ && ((fullname = mlanguage_name (sym)) != Mnil))
{
char *name = msymbol_name (fullname);
char c = name[0];
m17n_object_unref (face_default);
m17n_object_unref (default_face_list);
m17n_object_unref (selection);
+ if (font)
+ free (font);
XFreeGC (display, mono_gc);
XFreeGC (display, mono_gc_inv);
M17N_FINI ();
+ free (font_name);
free (fontset_name);
free (filename);
free (input_method_table);