2 * CDE - Common Desktop Environment
4 * Copyright (c) 1993-2012, The Open Group. All rights reserved.
6 * These libraries and programs are free software; you can
7 * redistribute them and/or modify them under the terms of the GNU
8 * Lesser General Public License as published by the Free Software
9 * Foundation; either version 2 of the License, or (at your option)
12 * These libraries and programs are distributed in the hope that
13 * they will be useful, but WITHOUT ANY WARRANTY; without even the
14 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU Lesser General Public License for more
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with these libraries and programs; if not, write
20 * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21 * Floor, Boston, MA 02110-1301 USA
23 /* code.c 1.37 - Fujitsu source for CDEnext 96/10/30 13:13:47 */
24 /* $XConsortium: code.c /main/6 1996/11/08 01:57:21 cde-fuj $ */
26 * (c) Copyright 1995 FUJITSU LIMITED
27 * This is source code modified by FUJITSU LIMITED under the Joint
28 * Development Agreement for the CDEnext PST.
29 * This is unpublished proprietary source code of FUJITSU LIMITED
33 #include <X11/keysym.h>
37 #include <Xm/RowColumn.h>
38 #include <Xm/SeparatoG.h>
43 #include <Xm/MwmUtil.h>
44 #include <X11/Intrinsic.h>
46 #include "xoakufont.h"
50 static Display *display=NULL;
52 static Boolean open_font;
53 static Widget toggle[NUM];
56 static Widget set_widget;
57 static Widget code_w=0;
58 static int font_w, font_h;
59 static unsigned long fg, bg;
60 static unsigned char *ptn, *clr;
62 static int len, code1;
63 static char *FontName=NULL;
66 extern FalFontID font_id;
68 extern Resource resource;
74 FalFontData font_data;
75 static FalFontDataList *copylist;
76 extern FalFontData fullFontData;
78 if(strcmp(FontName, fullFontData.xlfdname) == 0) {
82 mask = FAL_FONT_MASK_XLFDNAME | FAL_FONT_MASK_DEFINED |
83 FAL_FONT_MASK_UNDEFINED;
84 font_data.xlfdname = FontName;
86 mask |= FAL_FONT_MASK_GLYPH_INDEX;
89 fid = FalOpenSysFont(&font_data, mask, ©list);
102 DrawCode(Widget w, int low_code)
107 GC gc = XDefaultGC(display, 0);
109 hi_code = (code1 & 0xff) << 8;
110 image.width = font_w;
111 image.height = font_h;
113 image.format = XYBitmap;
114 image.byte_order = LSBFirst;
115 image.bitmap_unit = 8;
116 image.bitmap_bit_order = MSBFirst;
117 image.bitmap_pad = 8;
119 image.bytes_per_line = (font_w - 1) / 8 + 1;
120 XSetForeground(display, gc, fg);
121 XSetBackground(display, gc, bg);
124 f = (char *)FalReadFont(fid, hi_code | low_code, font_w, font_h);
125 if(f == NULL || f == (char *)FAL_ERROR) {
128 if( EXISTS_FLAG == 0 ) {
130 image.data = (char *)ptn;
132 image.data = (char *)clr;
134 XPutImage(display, XtWindow(toggle[low_code]), gc, &image, 0, 0, 6, 6, font_w, font_h);
136 if (ptnGet(hi_code | low_code, ptn) == 0) {
137 image.data = (char *)ptn;
139 image.data = (char *)clr;
141 XPutImage(display, XtWindow(toggle[low_code]), gc, &image, 0, 0, 6, 6, font_w, font_h);
146 SetPixmap(start_code)
148 int hi_code, low_code;
151 GC gc = XDefaultGC(display, 0);
153 hi_code = (start_code & 0xff) << 8;
154 image.width = font_w;
155 image.height = font_h;
157 image.format = XYBitmap;
158 image.byte_order = LSBFirst;
159 image.bitmap_unit = 8;
160 image.bitmap_bit_order = MSBFirst;
161 image.bitmap_pad = 8;
163 image.bytes_per_line = (font_w - 1) / 8 + 1;
164 XSetForeground(display, gc, fg);
165 XSetBackground(display, gc, bg);
168 for (low_code=0; low_code < NUM; low_code++) {
169 f = (char *)FalReadFont(fid, hi_code | low_code, font_w, font_h);
170 if(f == NULL || f == (char *)FAL_ERROR) {
173 if( EXISTS_FLAG == 0 ) {
175 image.data = (char *)ptn;
177 image.data = (char *)clr;
179 XPutImage(display, XtWindow(toggle[low_code]), gc, &image, 0, 0, 6, 6, font_w, font_h);
182 for (low_code=0; low_code < NUM; low_code++) {
183 if (ptnGet(hi_code | low_code, ptn) == 0) {
184 image.data = (char *)ptn;
186 image.data = (char *)clr;
188 XPutImage(display, XtWindow(toggle[low_code]), gc, &image, 0, 0, 6, 6, font_w, font_h);
194 Code1Call(Widget w, int start_code, XmListCallbackStruct *data)
196 code1 = start_code + data->item_position -1;
201 Code2Call(Widget w, int code2, XmPushButtonCallbackStruct *data)
204 sprintf(asc, "%2.2X%2.2X", code1, code2);
205 XtVaSetValues(text, XmNvalue, asc, NULL);
210 PrevPage(Widget w, Widget scroll)
214 if (XmListGetSelectedPos(scroll, &list, &num)) {
216 XmListSelectPos(scroll, list[0] - 1, True);
217 XmListSetPos(scroll, list[0] - 1);
223 NextPage(Widget w, Widget scroll)
227 XtVaGetValues(scroll, XmNitemCount, &item, NULL);
228 if (XmListGetSelectedPos(scroll, &list, &num)) {
230 XmListSelectPos(scroll, list[0] + 1, True);
231 XmListSetBottomPos(scroll, list[0] + 1);
239 XtUnmapWidget(XtParent(code_w));
246 XtVaGetValues(text, XmNvalue, &asc, NULL);
247 XtVaSetValues(set_widget, XmNvalue, asc, NULL);
253 CreateItem(XmString *item, int *item_count, int *start_code)
259 extern int begin_code, last_code;
262 if (FalQueryFont(fid, &finfo) == FAL_ERROR) {
267 font_w = finfo.width;
268 font_h = finfo.height;
269 start = (finfo.top & 0xff00) >> 8;
270 end = (finfo.bottom & 0xff00) >> 8;
274 start = (begin_code & 0xff00) >> 8;
275 end = (last_code & 0xff00) >> 8;
289 for (count=0;start <= end; start++, count++) {
290 sprintf(str, "%X", start);
291 item[count] = XmStringCreateLocalized(str);
297 CreateCodeWindow(Widget w)
299 Widget top, base1, base2, base3, base4;
300 Widget frame, scroll, label, sep, form;
301 Widget push1, push2, push3, push4;
306 int item_count, start_code, add_c;
310 XtSetArg(args[n], XmNmwmFunctions, MWM_FUNC_ALL | MWM_FUNC_CLOSE |
311 MWM_FUNC_RESIZE); n++;
312 XtSetArg(args[n], XmNmwmDecorations, MWM_DECOR_ALL); n++;
313 top = XmCreateFormDialog(w, "code", args, n);
315 base1 = XtVaCreateManagedWidget("base1", xmRowColumnWidgetClass, top,
316 XmNorientation, XmVERTICAL, NULL);
318 frame = XtVaCreateManagedWidget("frame", xmFrameWidgetClass, base1,
321 base2 = XtVaCreateManagedWidget("base2", xmRowColumnWidgetClass, frame,
322 XmNorientation, XmHORIZONTAL, NULL);
324 CreateItem(item, &item_count, &start_code);
327 XtSetArg(args[n], XmNitems, item); n++;
328 XtSetArg(args[n], XmNitemCount, item_count); n++;
329 XtSetArg(args[n], XmNscrollBarDisplayPolicy, XmSTATIC); n++;
330 scroll = XmCreateScrolledList(base2, "scroll", args, n);
331 XtManageChild(scroll);
332 XtAddCallback(scroll, XmNbrowseSelectionCallback,
333 (XtCallbackProc)Code1Call, (XtPointer) (intptr_t) start_code);
334 XtAddCallback(scroll, XmNdefaultActionCallback,
335 (XtCallbackProc)Code1Call, (XtPointer) (intptr_t) start_code);
336 XmListSelectPos(scroll, 1, False);
338 base3 = XtVaCreateManagedWidget("base3", xmRowColumnWidgetClass, base2,
339 XmNorientation, XmHORIZONTAL,
340 XmNpacking, XmPACK_COLUMN,
341 XmNradioAlwaysOne, True,
342 XmNradioBehavior , True,
346 XmNnumColumns, 9, NULL);
349 len = (font_w / 8 + 1) * font_h;
350 ptn = (unsigned char *) malloc(len);
351 clr = (unsigned char *) malloc(len);
353 XtVaGetValues(w, XmNforeground, &fg, XmNbackground, &bg, NULL);
354 no_pix = XCreatePixmapFromBitmapData(display, BaseW, (char *)clr,
355 font_w, font_h, fg, bg, DefaultDepth(display, screen));
357 XtVaCreateManagedWidget("", xmLabelWidgetClass, base3, NULL);
358 for (i=0; i < 16; i++) {
359 sprintf(add, "%2.1X", i);
360 XtVaCreateManagedWidget(add, xmLabelWidgetClass, base3, NULL);
366 for (i=0; i < NUM; i++) {
368 snprintf(add, sizeof(add), "%2.1X", add_c++);
369 XtVaCreateManagedWidget(add, xmLabelWidgetClass, base3, NULL);
371 toggle[i] = XtVaCreateWidget("toggle",
372 xmPushButtonWidgetClass, base3,
375 XmNlabelType, XmPIXMAP,
376 XmNlabelPixmap, no_pix, NULL);
377 XtAddCallback(toggle[i], XmNactivateCallback,
378 (XtCallbackProc)Code2Call, (XtPointer) (intptr_t) i);
379 XtAddCallback(toggle[i], XmNarmCallback,
380 (XtCallbackProc)DrawCode, (XtPointer) (intptr_t) i);
381 XtAddCallback(toggle[i], XmNdisarmCallback,
382 (XtCallbackProc)DrawCode, (XtPointer) (intptr_t) i);
383 XtAddEventHandler(toggle[i], ExposureMask, False,
384 (XtEventHandler)DrawCode, (XtPointer) (intptr_t) i);
386 XtManageChildren(toggle, NUM);
388 base4 = XtVaCreateManagedWidget("base4", xmFormWidgetClass, base1, NULL);
390 xcs = XmStringCreateLocalized(resource.l_code);
391 label = XtVaCreateManagedWidget("code", xmLabelWidgetClass, base4,
393 XmNleftAttachment, XmATTACH_POSITION,
394 XmNleftPosition, 30, NULL);
396 text = XtVaCreateManagedWidget("text", xmTextWidgetClass, base4,
398 XmNcursorPositionVisible, False,
400 XmNleftAttachment, XmATTACH_WIDGET,
401 XmNleftWidget, label, NULL);
403 sep = XtVaCreateManagedWidget("sep", xmSeparatorGadgetClass, base1,
404 XmNorientation, XmHORIZONTAL, NULL);
406 form = XtVaCreateManagedWidget("sep", xmFormWidgetClass, base1, NULL);
408 xcs = XmStringCreateLocalized(resource.previous);
409 push1 = XtVaCreateManagedWidget("PreviousPage", xmPushButtonWidgetClass, form,
410 XmNleftAttachment, XmATTACH_POSITION,
412 XmNleftPosition, 10, NULL);
413 XtAddCallback(push1, XmNactivateCallback,
414 (XtCallbackProc)PrevPage, (XtPointer)scroll);
417 xcs = XmStringCreateLocalized(resource.next);
418 push2 = XtVaCreateManagedWidget("NextPage", xmPushButtonWidgetClass, form,
419 XmNleftAttachment, XmATTACH_POSITION,
421 XmNleftPosition, 35, NULL);
422 XtAddCallback(push2, XmNactivateCallback,
423 (XtCallbackProc)NextPage, (XtPointer)scroll);
426 xcs = XmStringCreateLocalized(resource.apply);
427 push3 = XtVaCreateManagedWidget("Apply", xmPushButtonWidgetClass, form,
428 XmNleftAttachment, XmATTACH_POSITION,
430 XmNleftPosition, 60, NULL);
431 XtAddCallback(push3, XmNactivateCallback, (XtCallbackProc)Apply, NULL);
434 xcs = XmStringCreateLocalized(resource.l_cancel);
435 push4 = XtVaCreateManagedWidget("Cancel", xmPushButtonWidgetClass, form,
436 XmNleftAttachment, XmATTACH_POSITION,
438 XmNleftPosition, 80, NULL);
439 XtAddCallback(push4, XmNactivateCallback, (XtCallbackProc)Cancel, NULL);
446 CodeWindow(Widget widget, char *font_name, Boolean load_font)
448 static Boolean old_load_font;
449 extern int CodePoint;
453 BaseW = XtWindow(widget);
454 display = XtDisplay(widget);
455 screen = DefaultScreen(display);
456 if (FontName == NULL || strcmp(font_name, FontName) ||
457 load_font != old_load_font) {
458 old_load_font = load_font;
460 XtDestroyWidget(code_w);
470 FontName = (char *)malloc(strlen(font_name)+1);
471 strcpy(FontName, font_name);
482 code_w = CreateCodeWindow(widget);
483 XtManageChild(code_w);
485 XtMapWidget(XtParent(code_w));