From: handa Date: Mon, 2 Mar 2009 01:47:45 +0000 (+0000) Subject: (CAST_FROM_XTPOINTER): New macro. X-Git-Tag: REL-0-9-9~9 X-Git-Url: http://git.chise.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=aa33d3b77ed4d83581bd42ad1d318e05aa4f0cac;p=m17n%2Flibotf.git (CAST_FROM_XTPOINTER): New macro. (XtAddCallbackWithCast): New macro. (GlyphProc): Use CAST_FROM_XTPOINTER. (CharmapProc, UVSProc, RenderProc): Likewise. (create_widgets): Delete superfluous ";". Use XtAddCallbackWithCast. --- diff --git a/example/otfview.c b/example/otfview.c index b89de38..739fd47 100644 --- a/example/otfview.c +++ b/example/otfview.c @@ -47,6 +47,19 @@ write to the Free Software Foundation, Inc., 59 Temple Place, Suite #include +#define CAST_FROM_XTPOINTER(TYPE, DATA, VAR) \ + do { \ + long TYPE temp = (long TYPE) (DATA); \ + (VAR) = temp; \ + } while (0) + +#define XtAddCallbackWithCast(TYPE, W, PROC, VAR) \ + do { \ + long TYPE temp = (long TYPE) (VAR); \ + XtAddCallback (W, XtNcallback, PROC, (XtPointer) temp); \ + } while (0) + + #define DEFAULT_PIXEL_SIZE 30 int pixel_size; @@ -708,18 +721,21 @@ void GlyphProc (Widget w, XtPointer client_data, XtPointer call_data) { int old_glyph_index = glyph_index; + int data; + + CAST_FROM_XTPOINTER (int, client_data, data); - if ((int) client_data == -3 && glyph_index > 0) + if (data == -3 && glyph_index > 0) glyph_index = 0; - else if ((int) client_data == -2 && glyph_index > 0) + else if (data == -2 && glyph_index > 0) glyph_index = (glyph_index - 1) & 0x1FF000; - else if ((int) client_data == -1 && glyph_index > 0) + else if (data == -1 && glyph_index > 0) glyph_index -= 0x80; - else if ((int) client_data == 1 && glyph_index < 0x10FF80) + else if (data == 1 && glyph_index < 0x10FF80) glyph_index += 0x80; - else if ((int) client_data == 2 && glyph_index < 0x10F000) + else if (data == 2 && glyph_index < 0x10F000) glyph_index = (glyph_index + 0x1000) & 0x1FF000; - else if ((int) client_data == 3 && glyph_index < 0x10F000) + else if (data == 3 && glyph_index < 0x10F000) glyph_index = 0x10FF80; if (glyph_index != old_glyph_index) update_glyph_area (); @@ -728,9 +744,13 @@ GlyphProc (Widget w, XtPointer client_data, XtPointer call_data) void CharmapProc (Widget w, XtPointer client_data, XtPointer call_data) { - if (charmap_index == (int) client_data) + int data; + + CAST_FROM_XTPOINTER (int, client_data, data); + + if (charmap_index == data) return; - charmap_index = (int) client_data; + charmap_index = data; if (charmap_index >= 0) FT_Set_Charmap (face, face->charmaps[charmap_index]); update_glyph_area (); @@ -739,11 +759,14 @@ CharmapProc (Widget w, XtPointer client_data, XtPointer call_data) void UVSProc (Widget w, XtPointer client_data, XtPointer call_data) { - unsigned idx = (unsigned) client_data; - int selector = uvs[idx].c; + unsigned idx; + int selector; OTF_VariationSelectorRecord *record; int i; + CAST_FROM_XTPOINTER (unsigned, client_data, idx); + selector = uvs[idx].c; + if (glyph_rec.n_glyphs >= 64) return; for (i = 0; i < sub14->nRecords; i++) @@ -766,11 +789,15 @@ UVSProc (Widget w, XtPointer client_data, XtPointer call_data) void RenderProc (Widget w, XtPointer client_data, XtPointer call_data) { - if ((int) client_data < 0) + int data; + + CAST_FROM_XTPOINTER (int, client_data, data); + + if (data < 0) { if (glyph_rec.n_glyphs > 0) { - if ((int) client_data == -2) + if (data == -2) glyph_rec.n_glyphs--; else glyph_rec.n_glyphs = 0; @@ -779,16 +806,16 @@ RenderProc (Widget w, XtPointer client_data, XtPointer call_data) } else if (glyph_rec.n_glyphs < 64) { - int index = glyph_index + (int) client_data; + int index = glyph_index + data; if (charmap_index >= 0) index = FT_Get_Char_Index (face, (FT_ULong) index); if (bitmap[index].pixmap) { - glyph_rec.codes[glyph_rec.n_glyphs] = glyph_index + (int) client_data; + glyph_rec.codes[glyph_rec.n_glyphs] = glyph_index + data; glyph_rec.glyphs[glyph_rec.n_glyphs++] = index; if (otf) - update_uvs_area (glyph_index + (int) client_data); + update_uvs_area (glyph_index + data); update_render_area (); } } @@ -1245,7 +1272,7 @@ create_widgets () XtSetArg (arg2[0], XtNborderWidth, 1); for (i = 0; i < sub14->nRecords; i++) { - OTF_VariationSelectorRecord *record = sub14->Records + i;; + OTF_VariationSelectorRecord *record = sub14->Records + i; unsigned selector = record->varSelector; unsigned idx; char lbl[4]; @@ -1260,7 +1287,7 @@ create_widgets () XtSetArg (arg2[2], XtNsensitive, False); uvs[idx].w = XtCreateManagedWidget ("lbl", commandWidgetClass, uvs_area, arg2, 3); - XtAddCallback (uvs[idx].w, XtNcallback, UVSProc, (XtPointer) idx); + XtAddCallbackWithCast (unsigned, uvs[idx].w, UVSProc, idx); } XtSetArg (arg[5], XtNfromVert, uvs_area); } @@ -1291,7 +1318,7 @@ create_widgets () charmap[i + 1] = XtCreateManagedWidget (charmap_rec[i + 1].name, toggleWidgetClass, command_area, arg, 1); - XtAddCallback (charmap[i + 1], XtNcallback, CharmapProc, (XtPointer) i); + XtAddCallbackWithCast (int, charmap[i + 1], CharmapProc, i); } XtSetArg (arg[0], XtNlabel, " |< (f)"); @@ -1365,7 +1392,7 @@ create_widgets () XtSetArg (arg[n], XtNbitmap, none_pixmap), n++; glyph[k] = XtCreateManagedWidget ("glyph", commandWidgetClass, glyph_area, arg, n); - XtAddCallback (glyph[k], XtNcallback, RenderProc, (XtPointer) k); + XtAddCallbackWithCast (int, glyph[k], RenderProc, k); } w = head; }