dtcm: Resolve CID 87713
[oweals/cde.git] / cde / programs / dtudcfonted / ufont.c
1 /*
2  * CDE - Common Desktop Environment
3  *
4  * Copyright (c) 1993-2012, The Open Group. All rights reserved.
5  *
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)
10  * any later version.
11  *
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
16  * details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with these librararies and programs; if not, write
20  * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21  * Floor, Boston, MA 02110-1301 USA
22  */
23 /* ufont.c 1.45 - Fujitsu source for CDEnext    96/12/03 18:34:11      */
24 /* $XConsortium: ufont.c /main/14 1996/12/17 19:30:16 cde-fuj $ */
25 /*
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
30  */
31
32
33
34 #define substance_source
35
36 #include <stdio.h>
37 #include <math.h>
38
39 #include <X11/Intrinsic.h>
40
41 #include "xoakufont.h"
42 #include "util.h"
43
44 #ifndef NO_MESSAGE_CAT
45 #ifdef __ultrix
46 #define _CLIENT_CAT_NAME "dtudcfonted.cat"
47 #else  /* __ultrix */
48 #define _CLIENT_CAT_NAME "dtudcfonted"
49 #endif /* __ultrix */
50 #ifdef _NO_PROTO
51 extern char *_DtGetMessage();
52 #else  /* _NO_PROTO */
53 extern char *_DtGetMessage(
54                         char *filename,
55                         int set,
56                         int n,
57                         char *s );
58 #endif /* _NO_PROTO */
59 #define GETMESSAGE(set, number, string) GetMessage(set, number, string)
60 static char *
61 GetMessage(set, number, string)
62 int set, number;
63 char *string;
64 {
65     char *tmp, *ret;
66     tmp = _DtGetMessage(_CLIENT_CAT_NAME, set, number, string);
67     ret = malloc(strlen(tmp) + 1);
68     strcpy(ret, tmp);
69     return (ret);
70
71 #else /* NO_MESSAGE_CAT */
72 #define GETMESSAGE(set, number, string)\
73     string
74 #endif /* NO_MESSAGE_CAT */
75
76 /****************************************************************
77  *    Widgets                                                   *
78  ***************************************************************/
79 /* Widget       toplevel; */
80 static Widget   dnPopW;
81 Widget  wgeScro, editPopW;
82
83 static int      select_x, select_y, select_w, select_h;
84 static int      r1_x, r1_y, r2_x, r2_y, cut_w, cut_h;
85
86 extern  Widget          xlfdDialog, cpyDialog  ;
87
88 extern FalFontID font_id;
89
90 Pixmap          arrow_pix=0;
91
92 /*
93  * 
94  */
95 static XtAppContext app; /* application context */
96 static int edpane_size=0;
97 void CB_set_wait_msg();
98 void set_wait_msg();
99
100 static void OtherFontSelect();
101 void drawDelCode();
102 void drawDelPtn();
103 static void xeg_init();
104
105
106 static void dstrypaneEditPtn();
107 void chgEdCode();
108 void chgEdList();
109 static void chgEdPtn();
110 static void DrawRectEdPn();
111 static void DrawBorderEdPn();
112 static void DrawPointEdPn();
113 static void DrawDpPn();
114 static void DrawPointDpPn();
115 static void musPoint();
116 static void musLine();
117 static void musCircle();
118 static void musRect();
119 static void musRegionProc();
120 static void musPasteProc();
121 static void rubLine();
122 static void rubBand();
123 static void rubCircle();
124 static void resetEditMode();
125 static void copyPatterns();
126 extern String MngCodeTfValue();
127 extern String CpySrcCodeTfValue();
128 extern String CpyDestCodeTfValue();
129 char    *get_cmd_path() ;
130 extern  FalFontData     fullFontData;
131 extern  FalFontData     copyFontData;
132
133 extern void PopupSelectXLFD();
134 extern void UpdateMessage();
135 extern void DispMngErrorMessage();
136 extern void DispCpyErrorMessage();
137 static int setRealDelArea();
138
139 /****************************************************************
140  * parameters                                                   *
141  ***************************************************************/
142 static Arg      arg[30];
143 static int      n;
144
145 Resource resource;
146
147 /****************************************************************
148  * callback routines                                            *
149  ***************************************************************/
150
151 static void CancelCB();
152
153 static void
154 ExitCB()
155 {
156     exit(0);
157 }
158
159 int
160 efctPtnNum()
161 {
162     int no;
163     int sq;
164     int cnt;
165
166     for ( cnt = 0, sq = edlist.sqstart; 
167              sq < (edlist.sqstart + edlist.nptn); sq++) {
168         no = ptnSqToNo(sq);
169         if (( no >= 0) && (codeCheck( noToCode( no)) == 0))
170             cnt++;
171     }
172     return( cnt);
173 }
174
175 void
176 Error_message(widget, message)
177 Widget widget;
178 char *message;
179 {
180     static NoticeButton is_lock[] = {
181     NBTNARGS( ExitCB, NULL, 'E', True, False ),
182     NBTNARGS( CancelCB, NULL, 'C', True, True )
183     };
184     static NButton LockBTN = NBUTTONS( is_lock );
185
186     SetItemLabel(&LockBTN, 0, resource.l_exit);
187     SetItemLabel(&LockBTN, 1, resource.l_cancel);
188     PopupNotice( (widget), message,
189                 D_ERROR,
190                 &LockBTN,
191                 True,
192                 resource.l_question_title);
193 }
194
195 void
196 Error_message2(widget, message)
197 Widget widget;
198 char *message;
199 {
200     static NoticeButton is_lock[] = {
201     NBTNARGS( CancelCB, NULL, 'C', True, True )
202     };
203     static NButton LockBTN = NBUTTONS( is_lock );
204
205     if (widget == NULL)
206         widget = toplevel;
207
208     SetItemLabel(&LockBTN, 0, resource.l_ok);
209     PopupNotice( (widget), message,
210                 D_ERROR,
211                 &LockBTN,
212                 True,
213                 resource.l_question_title);
214 }
215
216 /*
217  * contents : read a character pattern from SNF file 
218  */
219 /*ARGSUSED*/
220 static void
221 CBmOblB_edit( widget, clientData, callData )
222 Widget          widget;
223 caddr_t         clientData;
224 caddr_t         callData;
225 {
226     int         ptn_n;
227     int         ptn_w;
228     int         ptn_h;
229     int         code;
230     int         i;
231     int         ret;
232     char        err[128];
233     extern int begin_code;
234
235     extern int ptnGetInfo();
236     extern void PopupEditPtn();
237
238     /* open font file and get informations of character to be edited  */
239
240     ret = readSNF( &(edg.fdata), &(edg.width), &(edg.height), err);
241
242     if( ret == -1 ) {
243         Error_message(widget, err);
244         return;
245     }
246     dn.ptn_w = (Dimension) edg.width;
247     dn.ptn_h = (Dimension) edg.height;
248
249
250     if( xlfdDialog != NULL )
251         PopdownDialog(xlfdDialog);
252
253     /* */
254     ptnGetInfo( &ptn_n, &ptn_w, &ptn_h );
255     for( i=0 ; i<ptn_n ; i++ ) {
256         code = noToCode( ptnSqToNo(i) );
257         if( begin_code > code){
258             edlist.sqstart = i+1;
259         } else {
260             edlist.nptn++;      
261         }
262     } 
263     if( efctPtnNum() > 0) {
264         for ( i=edlist.sqstart; i<(edlist.sqstart+edlist.nptn); i++){
265             if ( codeCheck( noToCode( ptnSqToNo(i))) == 0)
266                 break;
267         }
268         edg.ncode = ptnSqToNo( i );
269         edg.code = noToCode( edg.ncode );
270         ptnGet( edg.code, edg.ptn );
271     }
272     PopupEditPtn(toplevel);
273 }
274
275
276
277 void CBeOblB_aAdd();
278
279 static Boolean do_read = False;
280 static Boolean do_end = False;
281
282 static void CancelCB() { }
283
284 static void ContReadCB(w)
285 Widget w;
286 {
287     FalCloseFont(font_id);
288     editPtnW = NULL;
289     OtherFontSelect();
290     PopupSelectXLFD(toplevel);
291 }
292
293 static void SaveReadCB()
294 {
295     CBeOblB_aAdd();
296     do_read = True;
297     PopupSelectXLFD(toplevel);
298 }
299
300
301 static void ContEndCB()
302 {
303     FalCloseFont(font_id);
304     exit(0);
305 }
306
307 static void SaveEndCB()
308 {
309     CBeOblB_aAdd();
310     do_end = True;
311 }
312
313
314 /*
315  * contents : quit editting 
316  */
317
318
319 /*ARGSUSED*/
320 static int
321 QuitEditPtn( widget, clientData, callData )
322 Widget          widget; 
323 caddr_t         clientData;
324 caddr_t         callData;
325 {
326     resetEditMode( RES_MSG | RES_PROC | RES_SLCT | RES_RSV );
327
328     if( edg.code != 0 ){
329         ptnAdd( edg.code, edg.ptn );
330     }
331     if( edg.flag == ON ){
332         return(0);
333     }
334     return(1);
335 }
336
337
338
339 void
340 OpenCB(w, client_data, call_data)
341 Widget w;
342 XtPointer client_data;
343 XtPointer call_data;
344 {
345     static NoticeButton is_save_read_btn1[] = {
346     NBTNARGS( SaveReadCB, NULL, 'S', True, False ),
347     NBTNARGS( ContReadCB, NULL, 'O', True, False ),
348     NBTNARGS( CancelCB, NULL, 'C', True, True ),
349     };
350     static NoticeButton is_save_read_btn2[] = {
351     NBTNARGS( ContReadCB, NULL, 'O', True, False ),
352     NBTNARGS( CancelCB, NULL, 'C', True, True ),
353     };
354     static NButton SaveReadBTN1 = NBUTTONS( is_save_read_btn1 );
355     static NButton SaveReadBTN2 = NBUTTONS( is_save_read_btn2 );
356
357         if (QuitEditPtn((Widget)NULL, (caddr_t)NULL, (caddr_t)NULL)){
358             FalCloseFont(font_id);
359             editPtnW = NULL;
360             OtherFontSelect();
361             PopupSelectXLFD(toplevel);
362         }
363         else{
364             if (! fullFontData.prm) {
365                 SetItemLabel(&SaveReadBTN1, 0, resource.l_do_save_exit);
366                 SetItemLabel(&SaveReadBTN1, 1, resource.l_dont_save_exit);
367                 SetItemLabel(&SaveReadBTN1, 2, resource.l_cancel);
368                 PopupNotice( (w), resource.mn_saved_open ,
369                     D_QUESTION,
370                     &SaveReadBTN1,
371                     True,
372                     resource.l_question_title);
373             } else {
374                 SetItemLabel(&SaveReadBTN2, 0, resource.l_dont_save_exit);
375                 SetItemLabel(&SaveReadBTN2, 1, resource.l_cancel);
376                 PopupNotice( (w), resource.mn_saved_open ,
377                     D_QUESTION,
378                     &SaveReadBTN2,
379                     True,
380                     resource.l_question_title);
381             }
382         }
383 }
384
385
386 void
387 ReadCB(w, client_data, call_data)
388 Widget w;
389 XtPointer client_data;
390 XtPointer call_data;
391 {
392     if (fullFontData.xlfdname == NULL) {
393         return;
394     }
395     if (fullFontData.xlfdname == (char *) -1) {
396         Error_message(w, resource.mn_prop_font);
397         return;
398     }
399     CBmOblB_edit( w, client_data, call_data );
400 }
401
402 /****************************************************************
403  * callback routines and event handler                          *
404  ***************************************************************/
405
406 /*
407  * contents : write character patterns to SNF file      
408 */
409
410 static Boolean
411 WPwriteSNF( restart )
412 int     restart;
413 {
414     int         rc, err;
415     char        str[MG_MAXSIZE];
416
417     switch( rc = writeSNF( restart, &err ) ) {
418     case -1:
419         if (dnPopW)
420             XtSetSensitive( dnPopW,  TRUE );
421         switch( err ) {
422         case 001:
423             sprintf(str, "%s(permission denied)", resource.me_write_snf);
424             break;
425         case 002:
426             sprintf(str, "%s(disk full)", resource.me_write_snf);
427             break;
428         case 101:
429             sprintf(str, "%s(pipe error)", resource.me_write_snf);
430             break;
431         case 102:
432             sprintf(str, "%s(fork error)", resource.me_write_snf);
433             break;
434         case 103:
435             sprintf(str, "%s(execv error)", resource.me_write_snf);
436             break;
437         case 104:
438             sprintf(str, "%s(data error)", resource.me_write_snf);
439             break;
440         default:
441             sprintf(str, "%s", resource.me_write_snf);
442         }
443         SetString( wgeStaT, str );
444         return( TRUE );
445     case 0:
446         edg.flag = 0;
447         UpdateMessage( resource.mg_register );
448         sleep(1);
449         UpdateMessage("");
450
451         if (do_read){
452             do_read = False;
453             ContReadCB((Widget)NULL);
454         }
455         if (do_end){
456             do_read = False;
457             ContEndCB();
458         }
459         return(TRUE);
460     default:
461         if( rc == 1101 )
462             sprintf( str, "%s", resource.me_wait );
463         else 
464             sprintf( str, "%s(%3d%%)", resource.mg_write_snf , rc-1000 );
465
466         SetString( wgeStaT, str );
467         XtAppAddWorkProc( app, (XtWorkProc)WPwriteSNF, (XtPointer)ON );
468         if( rc == 1101 ){
469             XSync( xl.display,0 );
470         }
471         return( TRUE );
472     }
473 }
474
475
476
477 /*
478  * contents : write character patterns to SNF file
479  */
480
481 void
482 CBeOblB_aAdd()
483 {
484     char        str[MG_MAXSIZE];
485
486     resetEditMode( RES_MSG | RES_PROC | RES_SLCT | RES_RSV );
487     SetString( wgeStaT, resource.mg_write_snf );
488
489     if( edg.code != 0 )
490         ptnAdd( edg.code, edg.ptn );
491
492     if( edg.flag == ON ) {
493         sprintf( str, "%s", resource.mg_write_snf );
494         if (dnPopW)
495             XtSetSensitive( dnPopW,  FALSE );
496
497         XtAppAddWorkProc( app, (XtWorkProc)WPwriteSNF, (XtPointer)OFF );
498         return;
499     } 
500     else{
501         SetString( wgeStaT, "" );
502     }
503 }
504
505
506
507 /* 
508  * contents : destroy the editor window
509  */
510
511 static void
512 OtherFontSelect()
513 {
514     dstrypaneEditPtn();
515     xeg_init();
516 }
517
518
519
520 /*
521  * contents : close dtudcfonted
522  */
523
524 /*ARGSUSED*/
525 void
526 CBeOblB_aEnd( widget, clientData, callData )
527 Widget          widget; 
528 caddr_t         clientData;
529 caddr_t         callData;
530 {
531     static NoticeButton is_save_exit_btn[] = {
532     NBTNARGS( SaveEndCB, NULL, 'S', True, False ),
533     NBTNARGS( ContEndCB, NULL, 'E', True, False ),
534     NBTNARGS( CancelCB,  NULL, 'C', True, True ),
535     };
536     static NButton SaveEndBTN = NBUTTONS( is_save_exit_btn );
537
538     resetEditMode( RES_MSG | RES_PROC | RES_SLCT | RES_RSV );
539
540     if( edg.code != 0 )
541         ptnAdd( edg.code, edg.ptn );
542     if( edg.flag == ON ) {
543
544         SetItemLabel(&SaveEndBTN, 0, resource.l_do_save);
545         SetItemLabel(&SaveEndBTN, 1, resource.l_dont_save);
546         SetItemLabel(&SaveEndBTN, 2, resource.l_cancel);
547         PopupNotice( widget, resource.mn_saved_exit, D_QUESTION,
548                             &SaveEndBTN, True, resource.l_question_title);
549         return;
550     } else {
551         FalCloseFont(font_id);
552     }
553
554     exit(0);
555 }
556
557
558
559 /*ARGSUSED*/
560 void
561 CBeOblB_rCmd( widget, proc, callData )
562 Widget          widget; 
563 int             proc;   
564 caddr_t         callData;
565 {
566     extern void SelectUnset();
567     extern void UndoSet();
568     if (!select_x && !select_y && !select_w && !select_h)
569         return;
570     em.rsv_f = ON;
571     bitPtnCopy( em.rsv_ptn,  edg.ptn );
572     rubBand( r1_x,  r1_y,  r2_x,  r2_y );
573     switch( proc ) {
574     case PROC_CLS:
575         bitDrawCls (edg.ptn, select_x, select_y, select_w, select_h );
576         break;
577     case PROC_SET:
578         bitDrawSet (edg.ptn, select_x, select_y, select_w, select_h );
579         break;
580     case PROC_REV:
581         bitDrawRev (edg.ptn, select_x, select_y, select_w, select_h );
582         break;
583     case PROC_ROLL:
584         bitDrawRoll(edg.ptn, select_x, select_y, select_w, select_h);
585         break;
586     case PROC_SYMV:
587         bitDrawSymV(edg.ptn, select_x, select_y, select_w, select_h );
588         break;
589     case PROC_SYMH:
590         bitDrawSymH(edg.ptn, select_x, select_y, select_w, select_h );
591         break;
592     }
593     edg.flag = ON;
594     DrawRectEdPn( 0, 0,  edg.width - 1,  edg.height - 1 );
595     DrawDpPn();
596     select_x = select_y = select_w = select_h = 0;
597     SelectUnset();
598     UndoSet();
599 }
600
601 /*ARGSUSED*/
602 void
603 CBeOblB_rCmdp( widget, proc, callData )
604 Widget          widget; 
605 int             proc;   
606 caddr_t         callData;
607 {
608     extern Widget wgeBulB_edit;
609     extern void CopySet();
610     extern void UndoSet();
611     extern void SelectUnset();
612
613     switch( proc ) {
614     case PROC_CPY:
615         if (!select_x && !select_y && !select_w && !select_h)
616             return;
617         rubBand( r1_x,  r1_y,  r2_x,  r2_y );
618         bitDrawCpy(edg.ptn, select_x, select_y, select_w, select_h, False);
619         cut_w = select_w;
620         cut_h = select_h;
621         select_x = select_y = select_w = select_h = 0;
622         CopySet();
623         SelectUnset();
624         break;
625     case PROC_CUT:
626         if (!select_x && !select_y && !select_w && !select_h)
627             return;
628         em.rsv_f = ON;
629         rubBand( r1_x,  r1_y,  r2_x,  r2_y );
630         bitPtnCopy( em.rsv_ptn,  edg.ptn );
631         bitDrawCpy(edg.ptn, select_x, select_y, select_w, select_h, True);
632         cut_w = select_w;
633         cut_h = select_h;
634         edg.flag = ON;
635         DrawRectEdPn( 0, 0,  edg.width - 1,  edg.height - 1 );
636         DrawDpPn();
637         select_x = select_y = select_w = select_h = 0;
638         CopySet();
639         UndoSet();
640         SelectUnset();
641         break;
642     case PROC_PASTE:
643         XtAddEventHandler(wgeBulB_edit,
644                             ButtonReleaseMask|PointerMotionMask,
645                                     False, musPasteProc, NULL );
646     }
647 }
648
649
650
651
652 /*
653  * contents : cancel all editting 
654  */
655
656 /*ARGSUSED*/
657 void
658 CBeOblB_rCan( widget, clientData, callData )
659 Widget          widget;
660 caddr_t         clientData;
661 caddr_t         callData;
662 {
663     extern void UndoUnset();
664     
665     resetEditMode( RES_MSG | RES_PROC | RES_SLCT );
666
667     if( em.rsv_f == ON ) {
668         bitPtnCopy( edg.ptn, em.rsv_ptn );
669         em.rsv_f = OFF;
670
671         DrawRectEdPn( 0, 0, edg.width - 1, edg.height - 1 );
672         DrawDpPn();
673         UndoUnset();
674     }
675 }
676
677
678
679
680 /*
681  *
682  *   contents : get a sequential number of the editor 
683  */
684 int
685 RelToAbsSq( from, cnt)
686 int from;
687 int cnt;
688 {
689     int i;
690     int no;
691
692     if ( cnt >= 0) {
693         for ( i = -1; from < (edlist.sqstart + edlist.nptn) ; from++) {
694             no = ptnSqToNo(from);
695             if (( no >= 0) && ( noToCode( no) >= 0) ) {
696                 i++;
697                 if ( i >= cnt)
698                     return( from);
699             }
700         }
701     } else {
702         cnt *= -1;
703         for ( i = -1; from >= edlist.sqstart; from--) {
704             no = ptnSqToNo(from);
705             if (( no >= 0) && ( noToCode( no) >= 0) ) {
706                 i++;
707                 if ( i >= cnt)
708                     return(from);
709             }
710         }
711     }
712     return( -1);
713 }
714
715 /*
716  *   contents : get a relative number of the system area 
717  */
718 int
719 AbsSqToRel( from, to)
720 int from;
721 int to;
722 {
723     int sq;
724     int cnt;
725     int sign = 1;
726     int no;
727
728     if ( from > to) {
729         sq = from;
730         from = to;
731         to = sq;
732         sign = -1;
733     }
734
735     for ( cnt = -1, sq = from; sq <= to; sq++) {
736         no = ptnSqToNo(sq);
737         if (( no >= 0) && (codeCheck( noToCode( no)) == 0))
738             cnt++;
739     }
740
741     if ( cnt < 0)
742         cnt = 0;
743
744     cnt *= sign;
745     return( cnt);
746 }
747     
748
749
750
751 /*
752  * contents : be the character list selected 
753  */
754
755 /*ARGSUSED*/
756 void
757 EHeStaT_list( widget, select, e )
758 Widget          widget;
759 int             select;
760 XEvent          *e;                     /*    X Event   */
761 {
762     int         sq, no;
763     int         code;
764
765     resetEditMode( RES_MSG|RES_PROC|RES_SLCT|RES_RSV );
766
767     if( (e->xbutton.button != 1) || (e->type != ButtonRelease) ||
768         (e->xbutton.x < 0) || ((int)edlist.elem_w < e->xbutton.x) ||
769         (e->xbutton.y < 0) || ((int)edlist.elem_h < e->xbutton.y)
770        )
771         return;
772
773     if( edlist.slctloc == select )
774         return;
775
776     /* */
777     sq = RelToAbsSq( edlist.sqstart + edlist.statloc, select);
778
779     if( (no = ptnSqToNo(sq)) == -1 )
780         return;
781
782     code = noToCode( no );
783     if( codeCheck( code ) == -1 )
784         return;
785
786     if( ptnSense( code) == 0 )
787         return ;
788
789     chgEdList( edlist.statloc, select, OFF );
790     if( ptnSense(edg.code) == 1 )
791         ptnAdd(edg.code, edg.ptn );
792     chgEdPtn( code );
793 }
794
795
796
797
798 /*
799  * contents : update the character list 
800  */
801
802 /*ARGSUSED*/
803 void
804 CBeScro( widget, clientData, callData )
805 Widget                  widget;
806 caddr_t                 clientData;
807 caddr_t                 callData;
808 {
809     int         newl;
810     int         new_statloc;
811     int         new_slct;
812
813     n = 0;
814     XtSetArg( arg[n], XmNvalue,   (XtArgVal)&newl );    n++;
815     XtGetValues( wgeScro , arg, n );
816
817     if (( new_statloc = RelToAbsSq( edlist.sqstart, newl)) < 0) {
818         new_statloc = 0;
819     } else {
820         new_statloc -= edlist.sqstart;
821     }
822     /*
823      */
824     new_slct = edlist.slctloc 
825         - AbsSqToRel( edlist.sqstart + edlist.statloc, 
826                       edlist.sqstart + new_statloc);
827     chgEdList( new_statloc, new_slct, OFF);
828 }
829
830
831
832
833 /*
834  * contents : select the edit items by mouse 
835  */
836
837 /*ARGSUSED*/
838 void
839 EHeBulB_eMEv( widget, clientData, e )
840 Widget          widget;
841 caddr_t         clientData;
842 XEvent          *e;             /*    X Event                   */
843 {
844     int         px, py;
845     int         downbutton;
846
847     if (edpane.pix_w * edpane.pix_h == 0 ) {
848         return;
849     }
850
851     if( e->type == ButtonPress ){
852         em.drag_f = ON;
853     }
854     if( (edg.code == 0) || (em.drag_f == OFF) )
855         return;
856     if( e->type == ButtonRelease ){
857         em.drag_f = OFF;
858     }
859     
860     px = e->xbutton.x / edpane.pix_w;
861     py = e->xbutton.y / edpane.pix_h;
862
863     if (( e->type == ButtonPress) || (e->type == ButtonRelease)){
864         downbutton = e->xbutton.button;
865     }else if ( e->type == MotionNotify ){
866         if ( e->xmotion.state & Button1Mask ){
867             downbutton = 1; /* select button */
868         }else if ( e->xmotion.state & Button2Mask ){
869             downbutton = 2; /* adjust button */
870         } else {
871             downbutton = 0;
872         }       
873     }
874     
875     switch( downbutton ) {
876     case 1: 
877         switch( em.proc ) {
878         case PROC_POINT:
879             resetEditMode( RES_MSG | RES_PROC | RES_SLCT | RES_RSV );
880             musPoint( e->type, px, py );
881             break;
882         case PROC_LINE:
883             resetEditMode( RES_MSG | RES_PROC | RES_SLCT | RES_RSV );
884             musLine( e->type, px, py );
885             break;
886         case PROC_CIRCLE:
887             resetEditMode( RES_MSG | RES_PROC | RES_SLCT | RES_RSV );
888             musCircle( e->type, px, py );
889             break;
890         case PROC_RECT:
891             resetEditMode( RES_MSG | RES_PROC | RES_SLCT | RES_RSV );
892             musRect( em.proc, e->type, px, py );
893             break;
894         case PROC_ERASE:
895             resetEditMode( RES_MSG | RES_PROC | RES_SLCT | RES_RSV );
896             musPoint( e->type, px, py );
897             break;
898         case PROC_SELECT:
899             musRegionProc( em.proc, e->type, px, py );
900             break;
901         default:
902             break;
903         }
904         break;
905
906     case 2:
907         if( (0 <= px) && (px < edg.width) && (0 <= py) && (py < edg.height) ) {
908             resetEditMode( RES_MSG | RES_PROC | RES_SLCT | RES_RSV );
909
910             switch( e->type ) {
911             case MotionNotify:
912                 if( (em.adj_px == px) && (em.adj_py == py) )
913                     return;
914                 break;
915             case ButtonPress:
916                 em.adj_px = px;
917                 em.adj_py = py;
918                 if( bitRead(edg.ptn, px, py) == 0 ) {
919                     bitSet( edg.ptn, px, py );
920                     DrawPointEdPn( px,py, 1 );
921                     DrawPointDpPn( px,py, 1 );
922                 }
923                 else {
924                     bitReset( edg.ptn, px, py );
925                     DrawPointEdPn( px,py, 0 );
926                     DrawPointDpPn( px,py, 0 );
927                 }
928                 edg.flag = ON;
929                 break;
930             default:
931                 return;
932             }
933         }
934     default:
935         break;
936     }    
937 }
938
939
940
941
942 /*
943  * contents : restore the editting pane 
944  */
945
946 /*ARGSUSED*/
947 void
948 EHeBulB_eExp( widget, clientData, e )
949 Widget          widget;
950 caddr_t         clientData;
951 XEvent          *e;                     /*    X Event   */
952 {
953     int         x1, y1;
954     int         x2, y2;
955
956     if (edpane.pix_w * edpane.pix_h == 0 ) {
957         return;
958     }
959         
960     x1 = e->xexpose.x / edpane.pix_w;
961     y1 = e->xexpose.y / edpane.pix_h;
962     x2 = (e->xexpose.x + e->xexpose.width - 1) / edpane.pix_w;
963     y2 = (e->xexpose.y + e->xexpose.height - 1) / edpane.pix_h;
964
965     DrawRectEdPn( x1, y1, x2, y2 );
966     DrawBorderEdPn( x1, y1, x2, y2 );
967 }
968
969
970
971
972 /*
973  * contents : specifies the drawing operation (Pont/Line/Rectangle/Circle)
974  */
975
976 /*ARGSUSED*/
977 void
978 CBeRecB_obj( widget, obj, call)
979 Widget          widget;
980 int             obj;
981 XmToggleButtonCallbackStruct    *call;
982 {
983     extern void SelectUnset();
984
985     if (call->set == False)
986         return;
987
988     resetEditMode( RES_MSG | RES_RSV | RES_SLCT );
989
990     if (obj == PROC_ERASE)
991         edpane.color = OFF;
992     else
993         edpane.color = ON;
994     edpane.obj = obj;
995     em.proc = obj;
996     if (obj != PROC_SELECT) {
997         if (select_x || select_y || select_w || select_h) {
998             rubBand( r1_x,  r1_y,  r2_x,  r2_y );
999             select_x = select_y = select_w = select_h = 0;
1000             SelectUnset();
1001         }
1002     }
1003 }
1004
1005
1006
1007
1008 /*
1009  * contents : restore the displaying pane 
1010  */
1011
1012 /*ARGSUSED*/
1013 void
1014 EHeBulB_dExp( widget, clientData )
1015 Widget          widget; 
1016 caddr_t         clientData;
1017 {
1018     if (xl.display == NULL ){
1019         return;
1020     }
1021
1022     DrawDpPn();
1023 }
1024
1025 /*
1026  * contents : set the range to be add or deleted 
1027  */
1028
1029 static int
1030 codeAreaSet(s_code,e_code)
1031 int     *s_code;
1032 int     *e_code;
1033 {
1034     char        *str;
1035     char        delm;
1036
1037     str = MngCodeTfValue();
1038     delm = '\0';
1039     *s_code = 0;
1040     *e_code = 0;
1041     if (!str || !*str){
1042         return(-1);
1043     }
1044     sscanf( str, "%x %c %x", s_code, &delm, e_code );
1045     if (str) free( str );
1046     switch( delm ) {
1047     case '\0':
1048         *e_code = *s_code;
1049         break;
1050     case '-':
1051         break;
1052     default:
1053         return(-1);
1054     }
1055     if( codeCheck(*s_code) || codeCheck(*e_code) ||
1056         (*s_code > *e_code) ) {
1057         return(-1);
1058     }
1059     return(0);
1060 }
1061
1062
1063 /****************************************************************
1064  * callback routines (character management window)              *
1065  ***************************************************************/
1066
1067 Boolean
1068 BeforeMngCheck(s_code, e_code)
1069 int *s_code;
1070 int *e_code;
1071 {
1072     if(codeAreaSet(s_code, e_code) == -1) {
1073         DispMngErrorMessage( resource.me_illegal_code );
1074         return(False);
1075     }
1076     return(True);
1077 }
1078
1079 void
1080 DoAddProc(s_code, e_code)
1081 int s_code;
1082 int e_code;
1083 {
1084     int         code;
1085
1086     int         s_ncode;
1087     int         e_ncode;
1088     char        ptn[MAXPTNBYTE];
1089     char        mode;
1090     int         i;
1091
1092     resetEditMode( RES_MSG | RES_PROC | RES_SLCT | RES_RSV );
1093
1094     /* */
1095     s_ncode = codeToNo( s_code );
1096     e_ncode = codeToNo( e_code );
1097     mode = OFF;
1098     bitPtnClear( ptn );
1099     for( i=s_ncode ; i <= e_ncode ; i++ ) {
1100         code = noToCode(i);
1101         if ( codeCheck( code)) 
1102             continue;
1103         if (ptnSense(code) == 0) {
1104             if(ptnAdd(code, ptn) != 1) {
1105                 SetString( wgeStaT, resource.me_non_memory );
1106                 return;
1107             }
1108             edg.flag = ON;
1109             mode = ON;  
1110             edlist.nptn++;
1111         }
1112     }
1113
1114     /* */
1115     if( ptnSense( edg.code ) == 1 ) {
1116         ptnAdd( edg.code, edg.ptn );
1117     }
1118     /* */
1119     if(mode == ON) {
1120         chgEdCode( s_code, mode );
1121     }
1122
1123     resetEditMode( RES_MSG | RES_PROC | RES_SLCT | RES_RSV );
1124 }
1125
1126
1127
1128 void PopupDelNotice();
1129 Widget CreateDelNotice();
1130
1131
1132 void
1133 DoDelProc( s_code, e_code )
1134 int s_code;
1135 int e_code;
1136 {
1137     resetEditMode( RES_MSG | RES_PROC | RES_SLCT | RES_RSV );
1138
1139     if( ptnSense( edg.code) == 1 )
1140         ptnAdd( edg.code, edg.ptn );
1141
1142     dn.s_ncode = codeToNo( s_code );
1143     dn.e_ncode = codeToNo( e_code );
1144
1145     if (setRealDelArea(&dn.s_ncode, &dn.e_ncode, &dn.sq_start, &dn.sq_end) == -1) {
1146         DispMngErrorMessage( resource.me_nodelete_code );
1147         return;
1148     }
1149     dn.sq_top  = dn.sq_start;
1150     dn.disp_num = AbsSqToRel( dn.sq_start, dn.sq_end) + 1;
1151     dn.disp_num = (dn.disp_num <= D_MAX) ? dn.disp_num : D_MAX;
1152
1153     PopupDelNotice( mngPtnW );
1154
1155 }
1156
1157
1158
1159
1160 /*
1161  * contents : get the real range to be add or delete 
1162  */
1163
1164
1165 static int
1166 setRealDelArea(s_ncode, e_ncode, sq_start, sq_end )
1167 int     *s_ncode,  *e_ncode;
1168 int     *sq_start, *sq_end;
1169 {
1170     int         ncode;
1171     int         flg;
1172     int         sq;
1173     int         i;
1174
1175     /* first code */
1176     flg = 0;
1177     ncode = *e_ncode;
1178     for( i=*s_ncode ; i <= ncode ; i++ ) {
1179         if (((sq = ptnNoToSq(i)) != -1) && (codeCheck( noToCode(i)) == 0)) {
1180             flg = 1;
1181             break;
1182         }
1183     }
1184     if (flg == 1) {
1185         *s_ncode = ptnSqToNo( sq );
1186         *sq_start = sq;
1187     } else {
1188         return(-1);
1189     }
1190
1191     /* last code */
1192     flg = 0;
1193     ncode = *s_ncode;
1194     for( i=*e_ncode ; i >= ncode ; i-- ) {
1195         if ((( sq = ptnNoToSq(i)) != -1) && (codeCheck( noToCode(i) ) == 0)) {
1196             flg = 1;
1197             break;
1198         }
1199     }
1200     *e_ncode = ptnSqToNo( sq );
1201     *sq_end = sq;
1202     return(0);
1203 }
1204
1205
1206
1207
1208
1209
1210 /****************************************************************
1211  * callback routines (Copy)                                     *
1212  ****************************************************************/
1213
1214 static int
1215 CpySrcCodeCheck()
1216 {
1217     char        *str;
1218     char        delm;
1219
1220     str = CpySrcCodeTfValue();
1221     if (!str)
1222         return(-1);
1223     if (!*str) {
1224         free(str);
1225         return(-1);
1226     }
1227     delm = '\0';
1228     cpm.s1_code = 0;
1229     cpm.s2_code = 0;
1230     sscanf( str, "%x %c %x", &cpm.s1_code,&delm, &cpm.s2_code );
1231     free( str );
1232     switch( delm ) {
1233     case '\0':
1234         cpm.s2_code = cpm.s1_code;
1235         break;
1236     case '-':
1237         break;
1238     default:
1239         return(-1);
1240     }
1241     if (cpm.s1_code > cpm.s2_code)
1242         return(-1);
1243     return(0);
1244 }
1245
1246 static int
1247 CpyDestCodeCheck()
1248 {
1249     char        *str;
1250     
1251     str = CpyDestCodeTfValue();
1252     if (!str)
1253         return(-1);
1254     if (!*str){
1255         free(str);
1256         return(-1);
1257     }
1258     cpm.d1_code = 0;
1259     sscanf( str, "%x", &cpm.d1_code );
1260     free( str );
1261
1262     if( codeCheck(cpm.d1_code)  ) {
1263         return(-1);
1264     }
1265     return(0);
1266 }
1267
1268 Boolean
1269 BeforeCpyCheck( proc )
1270 int proc;
1271 {
1272     int         s_ncode, e_ncode;
1273     int         r1_code, r2_code;
1274     int         no;
1275     int         i;
1276     char        rstr[30];
1277     extern void PopupCpyNotice();
1278
1279     if (copyFontData.xlfdname == NULL) {
1280         DispCpyErrorMessage(resource.me_non_srcfile);
1281         return(False);
1282     }
1283
1284     if (CpySrcCodeCheck() == -1){
1285         DispCpyErrorMessage( resource.me_illegal_srccode );
1286         return(False);
1287     }
1288
1289     if (CpyDestCodeCheck() == -1){
1290         DispCpyErrorMessage( resource.me_illegal_destcode );
1291         return(False);
1292     }
1293
1294     s_ncode = codeToNo( cpm.d1_code );
1295     e_ncode = codeToNo( cpm.d1_code + cpm.s2_code - cpm.s1_code);
1296     r1_code = r2_code = 0;
1297     for( i=s_ncode ; i <= e_ncode ; i++ ) {
1298         no = ptnSqToNo(i);
1299         if (( no >= 0) && (codeCheck( noToCode( no)) == 0)) {
1300             if(r1_code == 0)
1301                 r1_code = noToCode(i);
1302             r2_code = noToCode(i);
1303         }
1304     }
1305
1306     cpm.proc = proc;
1307
1308     if( r1_code != 0 ) {
1309         if( r1_code == r2_code ) {
1310             sprintf( rstr, "%s %x¡¡", resource.l_code, r1_code );
1311         } else if ( codeCheck(r1_code) && codeCheck(r2_code)){
1312             sprintf( rstr, "        %x - %x", r1_code, r2_code );
1313         } else {
1314             sprintf( rstr, "%s %x - %x ", resource.l_code_range, r1_code, r2_code );
1315         }
1316         PopupCpyNotice(rstr);
1317         
1318         return(False);
1319     }
1320     return(True);
1321 }
1322
1323 void
1324 DoCpyProc()
1325 {
1326     extern void PopdownCpyPtn();
1327
1328     PopdownCpyPtn();
1329
1330     resetEditMode( RES_MSG | RES_PROC | RES_SLCT | RES_RSV );
1331
1332     copyPatterns( cpm.fdata, cpm.s1_code, cpm.s2_code, cpm.d1_code, cpm.proc );
1333 }
1334
1335 /****************************************************************
1336  * main routine                                                 *
1337  ****************************************************************/
1338 #define R(name, class, member,def)      { \
1339         name, \
1340         class, \
1341         XtRString, \
1342         sizeof(char *), \
1343         XtOffsetOf(Resource, member), \
1344         XtRString, \
1345         (XtPointer)def }
1346
1347 #define RBoolean(name, class, member,def) \
1348         { name, class, XtRBoolean, sizeof(XtRBoolean), \
1349         XtOffsetOf(Resource, member), XtRString, (XtPointer)def }
1350
1351 #define RDimension(name, class, member,def) \
1352         { name, class, XtRDimension, sizeof(XtRDimension), \
1353         XtOffsetOf(Resource, member), XtRString, (XtPointer)def }
1354
1355 #define Rint(name, class, member,def) \
1356         { name, class, XtRInt, sizeof(XtRInt), \
1357         XtOffsetOf(Resource, member), XtRString, (XtPointer)def }
1358
1359 #define RPixel(name, class, member,def) \
1360         { name, class, XtRPixel, sizeof(XtRPixel), \
1361         XtOffsetOf(Resource, member), XtRString, (XtPointer)def }
1362
1363 static XtResource app_resources[] = {
1364 RBoolean("Codepoint", "codepoint", codepoint, "False"),
1365
1366 R( "lptog", "Lptog", l_ptog, DFLTPATH ),
1367 R( "lptogCmd", "LptogCmd", l_ptog_cmd, DFLTCMD ),
1368
1369 /* CreateCaptionFrame() */
1370 RBoolean( "captResize",  "CaptResize",  capt_resize,  "True"  ) ,
1371 Rint( "captLftoff",  "CaptLftoff",  capt_lftoff,  "2"  ) ,
1372 Rint( "captTopoff",  "CaptTopoff",  capt_topoff,  "2"  ) ,
1373 Rint( "captRghoff", "CaptRghoff", capt_rghoff, "2" ) ,
1374
1375 RPixel( "paneBackground", "paneBackground", pane_background, "white" ),
1376 RPixel( "paneForeground", "PaneForeground", pane_foreground, "black" ),
1377 RPixel( "background", "Background", background, "white" ),
1378 RPixel( "foreground", "Foreground", foreground, "black" ),
1379
1380 /* CreateMenuButtons() */
1381 RDimension( "menuMargin", "MenuMargin", menu_margin, "0" ) ,
1382
1383 /* CreateDialogAndButtons() */
1384 RBoolean( "diaTmAutomng",  "DiaTmAutomng",  dia_tm_automng,  "False" ) ,
1385 RDimension( "diaTmWidth",  "DiaTmWidth",  dia_tm_width,  "4" ) ,
1386 RDimension( "diaTmHeight", "DiaTmHeight", dia_tm_height, "4" ) ,
1387 RBoolean( "diaTmResize",   "DiaTmResize",   dia_tm_resize,   "True" ) ,
1388 RBoolean( "diaTmMinimize", "DiaTmMinimize", dia_tm_minimize, "True" ) ,
1389
1390 RDimension( "diaRwWidth",   "DiaRwWidth",   dia_rw_width,   "6" ) ,
1391 RDimension( "diaRwHeight",  "DiaRwHeight",  dia_rw_height,  "6" ) ,
1392 RDimension( "diaRwSpacing", "DiaRwSpacing", dia_rw_spacing, "4" ) ,
1393
1394 /* CreateDrawingArea() */
1395 RDimension( "drawBorder", "DrawBorder", draw_border, "1" ) ,
1396 Rint( "drawTopoff", "DrawTopoff", draw_topoff, "2" ) ,
1397 Rint( "drawLftoff", "DrawLftoff", draw_lftoff, "2" ) ,
1398
1399 /* PopupNotice() */
1400 RBoolean( "popResize",   "PopResize",   pop_resize ,   "True" ) ,
1401 RBoolean( "popMinimize", "PopMinimize", pop_minimize , "True" ) ,
1402
1403 /* CreateTemplateDialog() */
1404 RBoolean( "tempResize",   "TempResize",   temp_resize,   "True" ) ,
1405 RBoolean( "tempMinimize", "TempMinimize", temp_minimize, "True" ) ,
1406
1407 RDimension( "tempWidth",  "TempWidth",  temp_width,  "1" ) ,
1408 RDimension( "tempHeight", "TempHeight", temp_height, "1" ) ,
1409
1410 /* CreateMenuBarAndFooterMessageForm() */
1411 Rint( "edBarTopoff", "EdBarTopoff", ed_bar_topoff, "1" ) ,
1412 Rint( "edBarLftoff", "EdBarLftoff", ed_bar_lftoff, "1" ) ,
1413 Rint( "edBarRghoff", "EdBarRghoff", ed_bar_rghoff, "1" ) ,
1414
1415 Rint( "edFrmBtmoff", "EdFrmBtmoff", ed_frm_btmoff, "3" ) ,
1416 Rint( "edFrmLftoff", "EdFrmLftoff", ed_frm_lftoff, "3" ) ,
1417 Rint( "edFrmRghoff", "EdFrmRghoff", ed_frm_rghoff, "3" ) ,
1418
1419 RDimension( "edMsgMargintop", "EdMsgMargintop", ed_msg_margintop, "3" ) ,
1420 RDimension( "edMsgMarginbtm", "EdMsgMarginbtm", ed_msg_marginbtm, "3" ) ,
1421
1422 RDimension( "edMesgMargintop", "EdMesgMargintop", ed_mesg_margintop, "3" ) ,
1423 RDimension( "edMesgMarginbtm", "EdMesgMarginbtm", ed_mesg_marginbtm, "3" ) ,
1424
1425 Rint( "edSepBtmoff", "EdSepBtmoff", ed_sep_btmoff, "3" ) ,
1426 Rint( "edSepLftoff", "EdSepLftoff", ed_sep_lftoff, "0" ) ,
1427 Rint( "edSepRghoff", "EdSepRghoff", ed_sep_rghoff, "0" ) ,
1428 RDimension( "edSepMargin", "EdSepMargin", ed_sep_margin, "0" ) ,
1429
1430 Rint( "edWgeTopoff", "EdWgeTopoff", ed_wge_topoff, "10" ) ,
1431 Rint( "edWgeLftoff", "EdWgeLftoff", ed_wge_lftoff, "10" ) ,
1432 Rint( "edWgeRghoff", "EdWgeRghoff", ed_wge_rghoff, "10" ) ,
1433 Rint( "edWgeBtmoff", "EdWgeBtmoff", ed_wge_btmoff, "10" ) ,
1434
1435 /* CreateFrame() */
1436 RBoolean( "frameResize", "FrameResize", frame_resize, "False" ) ,
1437
1438 /* CreateScrollBase() */
1439 RDimension( "scllFrWidth", "ScllFrWidth", scll_fr_width, "500" ) ,
1440
1441 RDimension( "scllFrThick", "ScllFrThick", scll_fr_thick, "2" ) ,
1442
1443 Rint( "scllBarLftoff", "ScllBarLftoff", scll_bar_lftoff, "4" ) ,
1444 };
1445 #undef R
1446 #undef RBoolean
1447 #undef RDimension
1448 #undef Rint
1449 #undef RPixel
1450
1451 int CodePoint = False;
1452
1453 /*ARGSUSED*/
1454 static void
1455 xerror(d, ev)
1456 Display *d;
1457 register XErrorEvent *ev;
1458 {
1459     fprintf (stderr, "dtudcfonted:  warning, error event receieved.\n");
1460     exit(-1);
1461 }
1462
1463 int
1464 main(argc, argv)
1465 int     argc;
1466 char    *argv[];
1467 {
1468     static char class_name[] = "Dtudcfonted";
1469     int i;
1470
1471     /* initialize GUI */
1472     toplevel = (Widget)GuiInitialize(&app, class_name, &argc, argv);
1473
1474     /* get application's resources */
1475     XtGetApplicationResources( toplevel, &resource,
1476                 app_resources, XtNumber(app_resources), NULL, 0);
1477
1478     if (resource.codepoint)
1479         CodePoint = True;
1480     /* initialize the code range */
1481     for( i=1  ;  i < argc  ; i++  ) {
1482         if( !strcmp(argv[i],"-pane_size") ) {
1483             i++;
1484             edpane_size = atoi( argv[i] );
1485         } else if( !strcmp(argv[i],"-codepoint") ) {
1486             CodePoint = True;
1487         }
1488     }
1489
1490     resource.mg_write_snf = GETMESSAGE(2, 2, "Registration processing inside.");
1491     resource.me_write_snf = GETMESSAGE(2, 4, "Failed in the registration of the character.");
1492     resource.me_illegal_code = GETMESSAGE(2, 6, "Illegal code.");
1493     resource.me_non_memory = GETMESSAGE(2, 8, "Because the memory allocation cannot be done, it is not possible to add.");
1494     resource.mg_non_code = GETMESSAGE(2, 10, "There is no character of the specified code.");
1495     resource.me_illegal_srccode = GETMESSAGE(2, 12, "The mistake is found in the specified copy origin code.");
1496     resource.me_illegal_destcode = GETMESSAGE(2, 14, "The mistake is found in the specified copy target code.");
1497     resource.me_nodelete_code = GETMESSAGE(2, 16, "There is no character in the specified area.");
1498     resource.me_wait = GETMESSAGE(2, 18, "Please wait for a while.");
1499     resource.me_non_srcfile = GETMESSAGE(2, 20, "No copy origin code file is specified.");
1500     resource.mn_no_font = GETMESSAGE(2, 22, "Informations of user defined character cannot collect.\nThere is no font specified.");
1501     resource.mn_plural_font = GETMESSAGE(2, 24, "Informations of user defined character cannot collect.\nThere are plural fonts specified.");
1502     resource.mn_not_udc = GETMESSAGE(2, 26, "The specified font do not have any UDCs areas.");
1503     resource.mn_no_mem = GETMESSAGE(2, 28, "There are no memories any more.");
1504     resource.mn_illegal_area = GETMESSAGE(2, 30, "The information of UDCs area is illegal.");
1505     resource.mn_no_read = GETMESSAGE(2, 32, "The font file cannot read.\nPattern area was broken.");
1506     resource.mn_prop_font = GETMESSAGE(2, 34, "Dtudcfonted cannot edit proportional character font.");
1507     resource.mn_saved_open = GETMESSAGE(2, 36, "There are unsaved edits.\nDo you want to save them before opening?");
1508     resource.mn_saved_exit = GETMESSAGE(2, 38, "There are unsaved edits.\nDo you want to save them before exiting?");
1509     resource.mn_cpy_lost = GETMESSAGE(2, 40, "When the copy processing is done, the glyph\nimage within the following ranges is changed.\nDo you want to do the copy processing?\n\n");
1510     resource.mn_no_perm = GETMESSAGE(2, 42, "No write permission for this font. You should change the file access mode before saving.\n");
1511
1512     resource.l_selectitem = GETMESSAGE(2, 100, "Select Items"); /* font open */
1513     resource.l_codeset = GETMESSAGE(2, 102, "         CodeSet:");
1514     resource.l_style = GETMESSAGE(2, 104, "           Style:");
1515     resource.l_width = GETMESSAGE(2, 106, "           Width:");
1516     resource.l_height = GETMESSAGE(2, 108, "          Height:");
1517     resource.exec_label = GETMESSAGE(2, 110, "Open");
1518     resource.quit_label = GETMESSAGE(2, 112, "Quit");
1519
1520     resource.l_font = GETMESSAGE(2, 114, "Font");               /* menu bar */
1521     resource.l_edit = GETMESSAGE(2, 116, "Edit");
1522     resource.l_manage = GETMESSAGE(2, 118, "Character");
1523     resource.l_info = GETMESSAGE(2, 120, "Information");
1524
1525     resource.l_open_w = GETMESSAGE(2, 122, "Open");             /* font menu */
1526     resource.l_save = GETMESSAGE(2, 124, "Save");
1527     resource.l_exit = GETMESSAGE(2, 126, "Exit");
1528
1529     resource.l_clear = GETMESSAGE(2, 128, "Clear");             /* edit menu */
1530     resource.l_set = GETMESSAGE(2, 130, "Set");
1531     resource.l_reverse = GETMESSAGE(2, 132, "Reverse");
1532     resource.l_cut = GETMESSAGE(2, 134, "Cut");
1533     resource.l_Copy = GETMESSAGE(2, 135, "Copy");
1534     resource.l_paste = GETMESSAGE(2, 136, "Paste");
1535     resource.l_roll = GETMESSAGE(2, 138, "Rotate");
1536     resource.l_updown_roll = GETMESSAGE(2, 140, "Vertical Roll");
1537     resource.l_leftright_roll = GETMESSAGE(2, 142, "Horizontal Roll");
1538     resource.l_undo = GETMESSAGE(2, 144, "Undo");
1539
1540     resource.l_manage_w = GETMESSAGE(2, 146, "Add/Delete...");  /* character menu */
1541     resource.l_copy_w = GETMESSAGE(2, 148, "Copy...");
1542
1543     resource.l_xlfd = GETMESSAGE(2, 150, "XLFD name...");               /* information menu */
1544     resource.l_codearea = GETMESSAGE(2, 152, "Code Area...");
1545
1546     resource.l_add = GETMESSAGE(2, 154, "Add");         /* add/delete dialog */
1547     resource.l_delete = GETMESSAGE(2, 156, "Delete");
1548     resource.l_cancel = GETMESSAGE(2, 158, "Cancel");
1549
1550     resource.l_manage_code = GETMESSAGE(2, 160, "Code(hex):"); /* copy dialog */
1551     resource.l_copy_src_code = GETMESSAGE(2, 162, " Copy origin code(hex):");
1552     resource.l_copy_dest_code = GETMESSAGE(2, 164, "Copy target code(hex):");
1553     resource.l_copy = GETMESSAGE(2, 166, "Copy");
1554     resource.l_overlay = GETMESSAGE(2, 168, "Overlay");
1555     resource.l_ok = GETMESSAGE(2, 170, "OK");
1556
1557     resource.l_do_save = GETMESSAGE(2, 172, "Save");    /* unsaved edits */
1558     resource.l_dont_save = GETMESSAGE(2, 174, "Do not Save");
1559     resource.l_do_save_exit = GETMESSAGE(2, 176, "Save and Exit");
1560     resource.l_dont_save_exit = GETMESSAGE(2, 178, "Do not Save and Exit");
1561
1562     resource.mg_start_del_s = GETMESSAGE(2, 180, "The following character will be deleted.");   /* delete notice dialog */
1563     resource.mg_start_del_cs = GETMESSAGE(2, 182, "character");
1564     resource.mg_start_del_m = GETMESSAGE(2, 184, "The following characters will be deleted.");
1565     resource.mg_start_del_cm = GETMESSAGE(2, 186, "characters");
1566     resource.mg_register = GETMESSAGE(2, 188, "Register completed");
1567     resource.l_code = GETMESSAGE(2, 190, " Code : ");
1568     resource.l_code_range = GETMESSAGE(2, 192, " Code range : ");
1569
1570     resource.message = GETMESSAGE(2, 194, "Message : ");
1571
1572     resource.code = GETMESSAGE(2, 196, "code...");      /* code dialog */
1573     resource.previous = GETMESSAGE(2, 198, "Page up");
1574     resource.next = GETMESSAGE(2, 200, "Page down");
1575     resource.apply = GETMESSAGE(2, 202, "Apply");
1576
1577     resource.l_question_title = GETMESSAGE(2, 204, "dtudcfonted - Question");
1578     resource.l_warning_title = GETMESSAGE(2, 206, "dtudcfonted - Warning");
1579     resource.l_error_title = GETMESSAGE(2, 208, "dtudcfonted -  Error");
1580     resource.l_copy_title = GETMESSAGE(2, 210, "dtudcfonted - Copy");
1581     resource.l_open_title = GETMESSAGE(2, 212, "dtudcfonted - Open");
1582     resource.l_add_title = GETMESSAGE(2, 214, "dtudcfonted - Add/Delete");
1583     resource.l_xlfd_title = GETMESSAGE(2, 216, "dtudcfonted - XLFD");
1584     resource.l_codearea_title = GETMESSAGE(2, 218, "dtudcfonted - CodeArea");
1585
1586     resource.file_name = GETMESSAGE(2, 230, "File name");
1587     resource.xlfd_name = GETMESSAGE(2, 232, "XLFD name");
1588     resource.codearea = GETMESSAGE(2, 234, "Code area");
1589
1590     resource.falerrmsg[0] = GETMESSAGE(2, 300, "Fatal error occurred.");
1591     resource.falerrmsg[1] = GETMESSAGE(2, 301, "Cannot open the font file.");
1592     resource.falerrmsg[2] = GETMESSAGE(2, 302, "Cannot read the font file.");
1593     resource.falerrmsg[3] = GETMESSAGE(2, 303, "There is no more memory.");
1594     resource.falerrmsg[4] = GETMESSAGE(2, 304, "Fatal error occurred.");
1595     resource.falerrmsg[5] = GETMESSAGE(2, 305, "The specified font file does not exist.");
1596     resource.falerrmsg[6] = GETMESSAGE(2, 306, "This font is not a pcf or snf font.");
1597     resource.falerrmsg[7] = GETMESSAGE(2, 307, "Cannot open fonts.list file.");
1598     resource.falerrmsg[8] = GETMESSAGE(2, 308, "The format of fonts.list file is illegal.");
1599     resource.falerrmsg[9] = GETMESSAGE(2, 309, "The descriptions of the fonts.list file are incorrect.");
1600     resource.falerrmsg[10] = GETMESSAGE(2, 310, "The format of fonts.list file is illegal.");
1601     resource.falerrmsg[11] = GETMESSAGE(2, 311, "Cannot open fonts.dir file.");
1602     resource.falerrmsg[12] = GETMESSAGE(2, 312, "Cannot read fonts.dir file.");
1603     resource.falerrmsg[13] = GETMESSAGE(2, 313, "Cannot read font properties.");
1604     resource.falerrmsg[14] = GETMESSAGE(2, 314, "Cannot get FONT property.");
1605     resource.falerrmsg[15] = GETMESSAGE(2, 315, "Cannot get FAMILY_NAME property.");
1606     resource.falerrmsg[16] = GETMESSAGE(2, 316, "This font file is already opened by other application.");
1607     resource.falerrmsg[17] = GETMESSAGE(2, 317, "Cannot lock font file.");
1608     resource.falerrmsg[18] = GETMESSAGE(2, 318, "Cannot unlock font file.");
1609     resource.falerrmsg[19] = GETMESSAGE(2, 319, "Cannot get lock information from the font file.");
1610     resource.falerrmsg[20] = GETMESSAGE(2, 320, "Cannot find the specified font file.");
1611     resource.falerrmsg[21] = GETMESSAGE(2, 321, "Cannot read NLS database.");
1612     resource.falerrmsg[22] = GETMESSAGE(2, 322, "Cannot get charset names from NLS database.");
1613     resource.falerrmsg[23] = GETMESSAGE(2, 323, "Charset name not defined in NLS database.");
1614     resource.falerrmsg[24] = GETMESSAGE(2, 324, "The specified font has not been opened.");
1615     resource.falerrmsg[25] = GETMESSAGE(2, 325, "Fatal error occurred.");
1616
1617     xlfdDialog   = NULL ;
1618     cpyDialog    = NULL ;
1619
1620     /* initialize the global values and allocate the memories */
1621     xeg_init();
1622
1623
1624     /* displays the selection window */
1625     PopupSelectXLFD(toplevel);
1626
1627     XSetErrorHandler((XErrorHandler)xerror);
1628     XSetIOErrorHandler((XIOErrorHandler)xerror);
1629
1630     /* main loop */
1631     XtAppMainLoop(app);
1632
1633     return(-1);
1634 }
1635
1636
1637 /*
1638  * contents : initialize the global values 
1639  */
1640
1641 static void
1642 xeg_init()
1643 {
1644     int i;
1645
1646     edg.code = edg.ncode = 0;
1647     bitPtnClear( edg.ptn );
1648     edg.flag = (char)0;
1649
1650     edlist.nlist = EDLIST_MAX;
1651     edlist.statloc = edlist.slctloc = 0;
1652     edlist.nptn = 0;
1653     edlist.sqstart = 0;
1654     edlist.list_h = edlist.elem_w = edlist.elem_h = (Dimension)0;
1655     edlist.back = resource.pane_background;
1656     edlist.border = resource.pane_foreground; 
1657
1658     if ( edpane_size ){
1659         edpane.width = edpane_size;
1660         edpane.height = edpane_size;
1661     } else {
1662         edpane.width  = EDPANE_SIZE;
1663         edpane.height = EDPANE_SIZE;
1664     }
1665     edpane.pix_w  = edpane.pix_h = 0;
1666     edpane.color  = 0;
1667     edpane.obj    = 0;
1668     edpane.back   = resource.pane_background;
1669     edpane.border = resource.pane_foreground;
1670
1671     xl.display    = NULL;
1672     xl.root_winID = xl.edit_winID = xl.disp_winID = xl.list_winID =
1673                         (Window)NULL;
1674     xl.borderGC   = xl.backGC = xl.rubGC = xl.dashGC = (GC)NULL;
1675     xl.dispImage  = NULL;
1676
1677     dn.elem_w = dn.elem_h = (Dimension)0;
1678     dn.ptn_w  = dn.ptn_h  = (Dimension)0;
1679     dn.list_h = (Dimension)0;
1680     dn.s_ncode = dn.e_ncode = 0;
1681     dn.sq_top = dn.sq_start = dn.sq_end = 0;
1682     dn.disp_num = 0;
1683
1684     for ( i=0 ; i<D_MAX ; i++ ) {
1685         dl[i].disp_winID = (Window)NULL;
1686         dl[i].dispImage = NULL;
1687         bitPtnClear( dl[i].ptn );
1688     }
1689     for ( i=0 ; i<EDLIST_MAX ; i++ ) {
1690         dl_glyph[i].disp_winID = (Window)NULL;
1691         dl_glyph[i].dispImage = NULL;
1692         bitPtnClear( dl_glyph[i].ptn );
1693         sq_disp[i] = 0 ;
1694     }
1695     em.drag_f = OFF;
1696     em.adj_px = em.adj_py = 0;
1697     em.proc = em.slct_f = 0;
1698     em.src1_px = em.src1_py = 0;
1699     em.src2_px = em.src2_py = 0;
1700     em.dest_px = em.dest_py = 0;
1701     em.rsv_f = (char)0;
1702     bitPtnClear( em.rsv_ptn );
1703
1704     cpm.s1_code = cpm.s2_code = cpm.d1_code = 0;
1705     cpm.proc = 0;
1706
1707     return;
1708 }
1709
1710
1711
1712 /****************************************************************
1713  * distroy the "User defined character editor" window           *
1714  ****************************************************************/
1715
1716 /*
1717  * contents : destroy the editting window 
1718  */
1719
1720 static void
1721 dstrypaneEditPtn()
1722 {
1723     int i ;
1724     
1725     ptnClose();
1726     
1727     XFree( (char *)xl.dispImage );
1728     XFreeGC( xl.display, xl.borderGC );
1729     XFreeGC( xl.display, xl.backGC );
1730     XFreeGC( xl.display, xl.rubGC );
1731     XFreeGC( xl.display, xl.dashGC );
1732
1733     for( i=0; i<EDLIST_MAX; i++ ){
1734         if( dl_glyph[i].dispImage ){
1735             XFree( (char *)dl_glyph[i].dispImage );
1736             dl_glyph[i].dispImage = NULL ;
1737         }
1738     }
1739
1740     XtPopdown( editPopW );
1741     XtDestroyWidget( editPopW );
1742
1743     return;
1744 }
1745
1746
1747 /****************************************************************
1748  * update character list                                        *
1749  ***************************************************************/
1750
1751 /*
1752  * contents :   add the specified code to the character list 
1753  */
1754
1755 void
1756 chgEdCode( code, mode )
1757 int     code;
1758 char    mode;
1759 {
1760     int ncode;
1761     int esq;
1762     int statloc; 
1763     int slctloc; 
1764     int slimax;
1765
1766     if( code == 0 ) {
1767         esq = -1;
1768     } else {
1769         ncode = codeToNo( code );
1770         esq = ptnNoToSq( ncode ) - edlist.sqstart;
1771     }
1772     if( esq < 0 ) {
1773         slctloc = -1;
1774         statloc = 0;
1775     } else if (efctPtnNum() <= edlist.nlist) {
1776         statloc = 0;
1777         slctloc = AbsSqToRel(edlist.sqstart, ptnNoToSq( ncode));
1778     } else {
1779         if ((esq >= edlist.statloc) 
1780             && (esq <= (RelToAbsSq( edlist.sqstart + edlist.statloc, 
1781                             edlist.nlist - 1) - edlist.sqstart))){
1782             statloc = edlist.statloc;
1783             slctloc = AbsSqToRel(edlist.sqstart+statloc,
1784                                         edlist.sqstart + esq);
1785         } else {
1786             statloc = esq;
1787             slctloc = 0;
1788         }
1789         while( RelToAbsSq(edlist.sqstart+statloc, edlist.nlist - 1) < 0)
1790             statloc = RelToAbsSq( edlist.sqstart + statloc, -1) 
1791                        - edlist.sqstart; 
1792         slctloc = AbsSqToRel( edlist.sqstart + statloc, edlist.sqstart + esq);
1793     }
1794
1795     n = 0;
1796     if (( slimax = efctPtnNum()) < edlist.nlist)
1797         slimax = edlist.nlist;
1798     XtSetArg( arg[n], XmNmaximum,   (XtArgVal)slimax ); n++;
1799     XtSetArg( arg[n], XmNvalue, (XtArgVal)AbsSqToRel( edlist.sqstart, edlist.sqstart + statloc) );      n++;
1800     XtSetValues( wgeScro , arg, n );
1801
1802     chgEdList( statloc, slctloc, mode );
1803     chgEdPtn( code );
1804 }
1805
1806
1807 /*
1808  * contents : rewrite the character list 
1809  */
1810
1811 void
1812 chgEdList( statloc, slctloc, mode  )
1813 int     statloc;
1814 int     slctloc;
1815 char    mode;
1816 {
1817     int         sq;
1818     int         i;
1819     char        str[6];
1820     int         no;
1821     int         code;
1822     extern void ListSetLabelStr();
1823     extern void ListSetGlyphImage();
1824     extern void ListUnselectItem();
1825     extern void ListSelectItem();
1826         
1827     if((mode == ON) || (edlist.statloc != statloc)){
1828         for (i=0, sq=edlist.sqstart+statloc; i < edlist.nlist; sq++){
1829             no = ptnSqToNo(sq);
1830             sq_disp[i] = sq ;
1831
1832             if ((no >= 0) && (code = noToCode(no)) >= 0 ){
1833                 sprintf(str, "%4x", code);
1834                 ListSetLabelStr(i, str);
1835                 ListSetGlyphImage(i) ;
1836                 if (i == 0)
1837                     edlist.statloc = sq - edlist.sqstart;
1838                 i++;
1839             } else if (sq > ( edlist.sqstart + edlist.nptn - 1)){
1840                 strcpy(str, "    ");
1841                 ListSetLabelStr(i, str);
1842                 ListSetGlyphImage(i) ;
1843                 i++;
1844             }
1845         }
1846     }
1847
1848     if( (mode == ON) || (edlist.slctloc != slctloc) ) {
1849         if((0 <= edlist.slctloc) && (edlist.slctloc < edlist.nlist)){
1850             ListUnselectItem(edlist.slctloc);
1851         }
1852         if((0 <= slctloc) && (slctloc < edlist.nlist)){
1853             ListSelectItem(slctloc);
1854         }
1855         edlist.slctloc = slctloc;
1856     }
1857 }
1858
1859
1860 /*
1861  * contents : rewrite the editting pane 
1862  */
1863
1864 static void
1865 chgEdPtn( code )
1866 int     code;
1867 {
1868     extern void SetCodeString();
1869
1870         if (xl.display == NULL ){
1871                 return;
1872         }
1873         
1874     if( code == 0 ) {
1875         XClearWindow( xl.display, xl.edit_winID );
1876         DrawBorderEdPn( 0, 0, edg.width - 1, edg.height - 1 );
1877         XClearWindow( xl.display, xl.disp_winID );
1878         XClearWindow( xl.display, xl.list_winID );
1879         bitPtnClear( edg.ptn );
1880         edg.code = 0;
1881         edg.ncode = 0;
1882         SetCodeString(0);
1883     }
1884
1885     if( ptnGet( code, edg.ptn) == 0 ) {
1886         edg.code = code;
1887         edg.ncode = codeToNo( code );
1888         DrawRectEdPn( 0, 0, edg.width - 1, edg.height - 1 );
1889
1890         SetCodeString(code);
1891         DrawDpPn();
1892     }
1893 }
1894
1895
1896
1897
1898
1899 /****************************************************************
1900  * draw patterns to the editting pane                           * 
1901  ***************************************************************/
1902
1903 /*
1904  * contents : draw a rectangle 
1905  *
1906  */
1907
1908 static void
1909 DrawRectEdPn( x1, y1, x2, y2 )
1910 int     x1;
1911 int     y1;
1912 int     x2;
1913 int     y2;
1914 {
1915     int i, j, wk;
1916     short    cx1, cy1, cx2, cy2;
1917     XRectangle    recOn[MAXPTNSIZE*MAXPTNSIZE];
1918     XRectangle    recOff[MAXPTNSIZE*MAXPTNSIZE];
1919     int nron, nroff;
1920
1921     if (xl.display == NULL ){
1922             return;
1923     }
1924             
1925     if( x2 < x1 ) {
1926         wk = x2;
1927         x2 = x1;
1928         x1 = wk;
1929     }
1930     if( y2 < y1 ) {
1931         wk = y2;
1932         y2 = y1;
1933         y1 = wk;
1934     }
1935
1936     nron = nroff = 0;
1937     for( j=y1   ;   j <= y2   ;  j++ ) {
1938         for( i=x1   ;   i <= x2   ;   i++ ) {
1939             cx1 = (short)(edpane.pix_w * i);
1940             cy1 = (short)(edpane.pix_h * j);
1941             cx2 = (short)(cx1 + edpane.pix_w - 1);
1942             cy2 = (short)(cy1 + edpane.pix_h - 1);
1943
1944             if( bitRead( edg.ptn, i, j ) != 0 ) {
1945                 recOn[nron].x = cx1;
1946                 recOn[nron].y = cy1;
1947                 recOn[nron].width  = (USHORT)(cx2 - cx1);
1948                 recOn[nron].height = (USHORT)(cy2 - cy1);
1949                 nron++;
1950             }
1951             else {
1952                 recOff[nroff].x = cx1;
1953                 recOff[nroff].y = cy1;
1954                 recOff[nroff].width  = (USHORT)(cx2 - cx1);
1955                 recOff[nroff].height = (USHORT)(cy2 - cy1);
1956                 nroff++;
1957             }
1958         }
1959     }
1960     if( nron )
1961         XFillRectangles( xl.display, xl.edit_winID, xl.borderGC, recOn, nron );
1962     if( nroff )
1963         XFillRectangles( xl.display, xl.edit_winID, xl.backGC,   recOff, nroff );
1964 }
1965
1966
1967 /*
1968  * contents : draw a lattice inside of the editting pane 
1969  */
1970
1971 static void
1972 DrawBorderEdPn( x1, y1, x2, y2 )
1973 int     x1;
1974 int     y1;
1975 int     x2;
1976 int     y2;
1977 {
1978     short       cx1, cy1;
1979     short       cx2, cy2;
1980     int         ndseg;
1981     int         wk, i;
1982     XSegment    dseg[MAXPTNSIZE*2];
1983
1984     if (xl.display == NULL ){
1985             return;
1986     }
1987     
1988     if( x2 < x1 ) {
1989         wk = x2;
1990         x2 = x1;
1991         x1 = wk;
1992     }
1993     if( y2 < y1 ) {
1994         wk = y2;
1995         y2 = y1;
1996         y1 = wk;
1997     }
1998
1999     ndseg = 0;
2000
2001     cx1 = (short)(edpane.pix_w * x1);
2002     cx2 = (short)(edpane.pix_w * x2 + edpane.pix_w - 1);
2003     for( i=y1  ;  i <= y2  ;  i++ ) {
2004         cy1 = (short)(edpane.pix_h * i + edpane.pix_h - 1);
2005         dseg[ndseg].x1 = cx1;
2006         dseg[ndseg].y1 = cy1;
2007         dseg[ndseg].x2 = cx2;
2008         dseg[ndseg].y2 = cy1;
2009         ndseg++;
2010     }
2011     cy1 = (short)(edpane.pix_h * y1);
2012     cy2 = (short)(edpane.pix_h * y2 + edpane.pix_h - 1);
2013     for( i=x1  ;  i <= x2  ;   i++ ) {
2014         cx1 = (short)(edpane.pix_w * i + edpane.pix_w - 1);
2015         dseg[ndseg].x1 = cx1;
2016         dseg[ndseg].y1 = cy1;
2017         dseg[ndseg].x2 = cx1;
2018         dseg[ndseg].y2 = cy2;
2019         ndseg++;
2020     }
2021
2022     if( ndseg ) {
2023         XDrawSegments( xl.display,  xl.edit_winID,  xl.dashGC,  dseg, ndseg);
2024     }
2025 }
2026
2027
2028 /*
2029  * contents : draw a dot 
2030  */
2031
2032 static void
2033 DrawPointEdPn( x, y, mode )
2034 int     x;
2035 int     y;
2036 int     mode;
2037 {
2038     int         x1, y1;
2039     int         x2, y2;
2040
2041     if (xl.display == NULL ){
2042             return;
2043     }
2044
2045     x1 = edpane.pix_w * x;
2046     y1 = edpane.pix_h * y;
2047     x2 = x1 + edpane.pix_w - 1;
2048     y2 = y1 + edpane.pix_h - 1;
2049
2050     if( mode != 0 ) {
2051         XFillRectangle( xl.display, xl.edit_winID, xl.borderGC,
2052                         x1, y1, x2-x1, y2-y1 );
2053     } else {
2054         XFillRectangle( xl.display, xl.edit_winID, xl.backGC,
2055                         x1, y1, x2-x1, y2-y1 );
2056     }
2057 }
2058
2059
2060
2061 /*
2062  * contents : draw a current character pattern to the display pane 
2063  */
2064
2065 static void
2066 DrawDpPn()
2067 {
2068         if (xl.display == NULL ){
2069                 return;
2070         }
2071
2072         XPutImage( xl.display,  xl.disp_winID,  xl.borderGC,  xl.dispImage,
2073               0, 0, 0, 0, edg.width, edg.height );
2074         if( xl.list_winID ) {
2075                 XPutImage( xl.display,  xl.list_winID,  xl.borderGC,
2076                         xl.dispImage, 0, 0, 0, 0, edg.width, edg.height );
2077         }
2078 }
2079
2080
2081
2082 /*
2083  * contents : draw a dot 
2084  */
2085
2086 static void
2087 DrawPointDpPn( x, y, mode )
2088 int     x;
2089 int     y;
2090 int     mode;
2091 {
2092
2093     if (xl.display == NULL ){
2094             return;
2095     }
2096     if( mode != 0 ){
2097         XDrawPoint( xl.display,  xl.disp_winID,  xl.borderGC, x,  y );
2098         if (xl.list_winID)
2099             XDrawPoint( xl.display,  xl.list_winID,  xl.borderGC, x,  y );
2100     } else {
2101         XDrawPoint( xl.display,  xl.disp_winID,  xl.backGC,   x,  y );
2102         if (xl.list_winID)
2103             XDrawPoint( xl.display,  xl.list_winID,  xl.backGC,   x,  y );
2104     }
2105 }
2106
2107
2108
2109 /****************************************************************
2110  * draw patterns by mouse                                       *
2111  ****************************************************************/
2112
2113
2114 /*
2115  * contents : draw a dot 
2116  */
2117
2118 static void
2119 musPoint( evtype, px, py )
2120 int     evtype; 
2121 int     px;
2122 int     py;
2123 {
2124     switch( evtype ) {
2125     case MotionNotify:
2126         if( (em.src1_px == px) && (em.src1_py == py) )
2127             return;
2128         break;
2129     case ButtonPress:
2130         em.src1_px = px;
2131         em.src1_py = py;
2132         break;
2133     default:
2134         return;
2135     }
2136
2137     if( edpane.color == ON )
2138         bitSet( edg.ptn, px, py );
2139     else
2140         bitReset( edg.ptn, px, py );
2141     edg.flag = ON;
2142     DrawPointEdPn( px, py, edpane.color );
2143     DrawPointDpPn( px, py, edpane.color );
2144 }
2145
2146
2147 /*
2148  * contents : draw a line 
2149  */
2150
2151 static void
2152 musLine( evtype, px, py )
2153 int     evtype;
2154 int     px;
2155 int     py;
2156 {
2157     int         r1_x, r1_y;
2158     int         r2_x, r2_y;
2159     int         rx,   ry;
2160     int         harf_pix_w;
2161     int         harf_pix_h;
2162
2163     harf_pix_w = edpane.pix_w / 2;
2164     harf_pix_h = edpane.pix_h / 2;
2165     r1_x = em.src1_px * edpane.pix_w + harf_pix_w;
2166     r1_y = em.src1_py * edpane.pix_h + harf_pix_h;
2167     r2_x = em.src2_px * edpane.pix_w + harf_pix_w;
2168     r2_y = em.src2_py * edpane.pix_h + harf_pix_h;
2169     rx = px * edpane.pix_w + harf_pix_w;
2170     ry = py * edpane.pix_h + harf_pix_h;
2171
2172     switch( evtype ) {
2173     case MotionNotify:
2174         if( (em.src2_px == px) && (em.src2_py == py) )
2175             return;
2176         rubLine( r1_x, r1_y, r2_x, r2_y );
2177         rubLine( r1_x, r1_y, rx, ry );
2178         em.src2_px = px;
2179         em.src2_py = py;
2180         return;
2181     case ButtonPress:
2182         em.src1_px = em.src2_px = px;
2183         em.src1_py = em.src2_py = py;
2184         return;
2185     default:
2186         if( (r1_x == r2_x) && (r1_y == r2_y) )
2187             return;
2188         rubLine( r1_x, r1_y, r2_x, r2_y );
2189
2190         if ((em.src2_px < 0) || (em.src2_py < 0) ||
2191             (edg.width <= em.src2_px) || (edg.height <= em.src2_py))
2192             return;
2193
2194         bitDrawLine( edg.ptn, em.src1_px, em.src1_py,
2195                               em.src2_px, em.src2_py, edpane.color );
2196         edg.flag = ON;
2197         DrawRectEdPn( em.src1_px, em.src1_py, em.src2_px, em.src2_py );
2198         DrawDpPn();
2199     }
2200 }
2201
2202
2203
2204 /*
2205  * contents : draw a circle 
2206  */
2207
2208 static void
2209 musCircle( evtype, px, py )
2210 int     evtype; 
2211 int     px;
2212 int     py;
2213 {
2214     int         r1_x, r1_y;
2215     int         r2_x, r2_y;
2216     int         rx,   ry;       
2217     int         harf_pix_w;
2218     int         harf_pix_h;
2219     extern int  bitDrawCircle();
2220
2221     harf_pix_w = edpane.pix_w / 2;
2222     harf_pix_h = edpane.pix_h / 2;
2223
2224     r1_x = em.src1_px * edpane.pix_w + harf_pix_w;
2225     r1_y = em.src1_py * edpane.pix_h + harf_pix_h;
2226     r2_x = em.src2_px * edpane.pix_w + harf_pix_w;
2227     r2_y = em.src2_py * edpane.pix_h + harf_pix_h;
2228     rx = px * edpane.pix_w + harf_pix_w;
2229     ry = py * edpane.pix_h + harf_pix_h;
2230
2231     switch( evtype ) {
2232     case MotionNotify:
2233         if( (em.src2_px == px) && (em.src2_py == py) ) {
2234             return;
2235         }
2236         rubCircle( r1_x, r1_y, r2_x, r2_y );
2237         rubCircle( r1_x, r1_y, rx, ry );
2238         em.src2_px = px;
2239         em.src2_py = py;
2240         return;
2241     case ButtonPress:
2242         em.src1_px = em.src2_px = px;
2243         em.src1_py = em.src2_py = py;
2244         return;
2245     default:
2246         if( (em.src1_px == px) && (em.src1_py == py) ) {
2247             return;
2248         }
2249         rubCircle( r1_x, r1_y, r2_x, r2_y );
2250
2251         if( (px < 0) || (py < 0) || (edg.width <= px) || (edg.height <= py) ) {
2252             return;
2253         }
2254         bitDrawCircle( edg.ptn, em.src1_px, em.src1_py, px, py, edpane.color);
2255
2256         edg.flag = ON;
2257         DrawRectEdPn( 0, 0, edg.width -1, edg.height -1 );
2258         DrawDpPn();
2259     }
2260 }
2261
2262
2263 /*
2264  * contents : draw a rectangle 
2265  */
2266
2267 static void
2268 musRect( proc, evtype, px, py )
2269 int     proc;
2270 int     evtype;
2271 int     px;
2272 int     py;
2273 {
2274     int         r1_x, r1_y;
2275     int         r2_x, r2_y;
2276     int         rx,   ry;
2277     int         lux, luy;
2278     int         width, height;
2279     int         dpx, dpy, dp;    
2280
2281     if( (proc == PROC_ROLL) && (evtype != ButtonPress) ) {
2282         dpx = px - em.src1_px;
2283         dpy = py - em.src1_py;
2284         dp = (abs(dpx) > abs(dpy) ) ? abs(dpx) : abs(dpy);
2285
2286         if( dpx != 0 ) 
2287             px = em.src1_px + dpx/abs(dpx) * dp;
2288         if( dpy != 0 ) 
2289             py = em.src1_py + dpy/abs(dpy) * dp;
2290     }
2291
2292     r1_x = em.src1_px * edpane.pix_w + edpane.pix_w / 2;
2293     r1_y = em.src1_py * edpane.pix_h + edpane.pix_h / 2;
2294     r2_x = em.src2_px * edpane.pix_w + edpane.pix_w / 2;
2295     r2_y = em.src2_py * edpane.pix_h + edpane.pix_h / 2;
2296     rx = px * edpane.pix_w + edpane.pix_w / 2;
2297     ry = py * edpane.pix_h + edpane.pix_h / 2;
2298
2299     switch( evtype ) {
2300     case MotionNotify:
2301         if( (em.src2_px == px) && (em.src2_py == py) )
2302             return;
2303         rubBand( r1_x, r1_y, r2_x, r2_y );
2304         rubBand( r1_x, r1_y, rx, ry );
2305         em.src2_px = px;
2306         em.src2_py = py;
2307         return;
2308     case ButtonPress:
2309         resetEditMode( RES_SLCT );
2310         em.src1_px = em.src2_px = px;
2311         em.src1_py = em.src2_py = py;
2312         return;
2313     default:
2314         resetEditMode( RES_MSG | RES_PROC );
2315         rubBand( r1_x,  r1_y,  r2_x,  r2_y );
2316         if( (r1_x == r2_x) || (r1_y == r2_y) )
2317             return;
2318         if( (em.src2_px < 0) || (em.src2_py < 0) ||
2319             (edg.width <= em.src2_px) || (edg.height <= em.src2_py)     )
2320             return;
2321
2322         lux = (em.src1_px < em.src2_px ) ?  em.src1_px   :   em.src2_px;
2323         luy = (em.src1_py < em.src2_py ) ?  em.src1_py   :   em.src2_py;
2324         width  = abs( em.src1_px - em.src2_px ) + 1;
2325         height = abs( em.src1_py - em.src2_py ) + 1;
2326
2327         bitDrawRect(edg.ptn, lux, luy, width, height, edpane.color);
2328
2329         edg.flag = ON;
2330         DrawRectEdPn( em.src1_px, em.src1_py, px, py );
2331         DrawDpPn();
2332     }
2333 }
2334
2335
2336 /*
2337  * contents : edit inside of the specified area (clear, reverse, rotate,etc.)
2338  */
2339
2340 static void
2341 musRegionProc( proc, evtype, px, py )
2342 int     proc;
2343 int     evtype;
2344 int     px;
2345 int     py;
2346 {
2347     int         rx,   ry;
2348     int         dpx, dpy, dp;    
2349     extern void SelectSet();
2350
2351     if( (proc == PROC_ROLL) && (evtype != ButtonPress) ) {
2352         dpx = px - em.src1_px;
2353         dpy = py - em.src1_py;
2354         dp = (abs(dpx) > abs(dpy) ) ? abs(dpx) : abs(dpy);
2355
2356         if( dpx != 0 ) 
2357             px = em.src1_px + dpx/abs(dpx) * dp;
2358         if( dpy != 0 ) 
2359             py = em.src1_py + dpy/abs(dpy) * dp;
2360     }
2361
2362     r1_x = em.src1_px * edpane.pix_w + edpane.pix_w / 2;
2363     r1_y = em.src1_py * edpane.pix_h + edpane.pix_h / 2;
2364     r2_x = em.src2_px * edpane.pix_w + edpane.pix_w / 2;
2365     r2_y = em.src2_py * edpane.pix_h + edpane.pix_h / 2;
2366     rx = px * edpane.pix_w + edpane.pix_w / 2;
2367     ry = py * edpane.pix_h + edpane.pix_h / 2;
2368
2369     switch( evtype ) {
2370     case MotionNotify:
2371         if( (em.src2_px == px) && (em.src2_py == py) )
2372             return;
2373         rubBand( r1_x, r1_y, r2_x, r2_y );
2374         rubBand( r1_x, r1_y, rx, ry );
2375         em.src2_px = px;
2376         em.src2_py = py;
2377         return;
2378     case ButtonPress:
2379         if (select_x || select_y || select_w || select_h) {
2380             rubBand( r1_x, r1_y, r2_x, r2_y );
2381         }
2382         resetEditMode( RES_SLCT );
2383         em.src1_px = em.src2_px = px;
2384         em.src1_py = em.src2_py = py;
2385         return;
2386     default:
2387         resetEditMode( RES_MSG | RES_PROC );
2388         select_x = select_y = select_w  = select_h = 0;
2389         if( (r1_x == r2_x) || (r1_y == r2_y) ) {
2390             rubBand( r1_x,  r1_y,  r2_x,  r2_y );
2391             return;
2392         }
2393         if( (em.src2_px < 0) || (em.src2_py < 0) ||
2394             (edg.width <= em.src2_px) || (edg.height <= em.src2_py)     ) {
2395             rubBand( r1_x,  r1_y,  r2_x,  r2_y );
2396             return;
2397         }
2398
2399         select_x = (em.src1_px < em.src2_px ) ?  em.src1_px   :   em.src2_px;
2400         select_y = (em.src1_py < em.src2_py ) ?  em.src1_py   :   em.src2_py;
2401         select_w  = abs( em.src1_px - em.src2_px ) + 1;
2402         select_h = abs( em.src1_py - em.src2_py ) + 1;
2403         SelectSet();
2404     }
2405 }
2406
2407
2408 /*ARGSUSED*/
2409 static void
2410 musPasteProc(w, client_data, event)
2411 Widget w;
2412 XtPointer client_data;
2413 XEvent *event;
2414 {
2415     static int ox=0, oy=0;
2416     int rc, tx, ty;
2417     extern void UndoSet();
2418     extern Widget wgeBulB_edit;
2419     extern int  bitDrawPaste();
2420
2421     switch(event->type) {
2422     case MotionNotify:
2423         tx = (event->xmotion.x / edpane.pix_w) * edpane.pix_w + edpane.pix_w / 2;
2424         ty = (event->xmotion.y / edpane.pix_h) * edpane.pix_h + edpane.pix_h / 2;
2425         if (tx == ox && ty == oy)
2426             return;
2427         if(ox) {
2428             rubBand(ox, oy, ox + cut_w * edpane.pix_w, oy + cut_h * edpane.pix_h);
2429         }
2430         ox = tx;
2431         oy = ty;
2432         rubBand(ox, oy, ox + cut_w * edpane.pix_w, oy + cut_h * edpane.pix_h);
2433         break;
2434     case ButtonRelease:
2435         XtRemoveEventHandler(wgeBulB_edit,
2436                                 ButtonReleaseMask|PointerMotionMask,
2437                                     False, (XtEventHandler)musPasteProc, NULL );
2438         rubBand(ox, oy, ox + cut_w * edpane.pix_w, oy + cut_h * edpane.pix_h);
2439         ox = 0;
2440         oy = 0;
2441         bitPtnCopy( em.rsv_ptn,  edg.ptn );
2442
2443         tx = event->xbutton.x / edpane.pix_w;
2444         ty = event->xbutton.y / edpane.pix_h;
2445         rc = bitDrawPaste(edg.ptn, tx, ty);
2446         if( rc == -1 )
2447              return;
2448         edg.flag = ON;
2449         em.rsv_f = ON;
2450         DrawRectEdPn( 0, 0,  edg.width - 1,  edg.height - 1 );
2451         DrawDpPn();
2452         UndoSet();
2453         break;
2454     defaults:
2455         break;
2456     }
2457 }
2458
2459
2460
2461 static void
2462 rubLine( x1, y1, x2, y2  )
2463 int     x1;
2464 int     y1;
2465 int     x2;
2466 int     y2;
2467 {
2468     if( x1==x2 && y1==y2 ) return;
2469
2470     XDrawLine( xl.display, xl.edit_winID, xl.rubGC,    x1,y1, x2,y2 );
2471 }
2472
2473
2474
2475 static void
2476 rubBand( x1, y1, x2, y2  )
2477 int     x1;
2478 int     y1;
2479 int     x2;
2480 int     y2;
2481 {
2482     if( x1==x2 && y1==y2 )
2483         return;
2484
2485     XDrawLine( xl.display, xl.edit_winID, xl.rubGC, x1, y1, x2, y1 );
2486     XDrawLine( xl.display, xl.edit_winID, xl.rubGC, x1, y1, x1, y2 );
2487     XDrawLine( xl.display, xl.edit_winID, xl.rubGC, x2, y1, x2, y2 );
2488     XDrawLine( xl.display, xl.edit_winID, xl.rubGC, x1, y2, x2, y2 );
2489 }
2490
2491
2492
2493 static void
2494 rubCircle( ox, oy, rx, ry )
2495 int     ox;
2496 int     oy;
2497 int     rx;
2498 int     ry;
2499 {
2500     unsigned int        r;
2501     int                 x, y;
2502
2503     if( ox==rx && oy==ry ) return;
2504
2505     x = rx - ox;
2506     y = ry - oy;
2507     r = (unsigned int)sqrt( (double)(x*x + y*y) );
2508     if ( r == 0 ) return;
2509
2510     x = ox - (int)r;
2511     y = oy - (int)r;
2512     XDrawArc( xl.display, xl.edit_winID, xl.rubGC,
2513              x, y, 2*r-1, 2*r-1,
2514              0, 360*64
2515              );
2516 }
2517
2518
2519
2520 static void
2521 resetEditMode( flag )
2522 UINT    flag;
2523 {
2524     int         r1_x, r1_y;
2525     int         r2_x, r2_y;
2526
2527     if( flag & RES_MSG )
2528         SetString( wgeStaT, "" );
2529
2530     if( flag & RES_PROC )
2531         em.proc = edpane.obj;
2532
2533     if( (flag & RES_SLCT) && (em.slct_f) ) {
2534         r1_x = em.src1_px * edpane.pix_w + edpane.pix_w / 2;
2535         r1_y = em.src1_py * edpane.pix_h + edpane.pix_h / 2;
2536         r2_x = em.src2_px * edpane.pix_w + edpane.pix_w / 2;
2537         r2_y = em.src2_py * edpane.pix_h + edpane.pix_h / 2;
2538         rubBand( r1_x, r1_y, r2_x, r2_y );
2539         em.slct_f = OFF;
2540     }
2541
2542     if( flag & RES_RSV )
2543         em.rsv_f = OFF;
2544 }
2545
2546
2547 /****************************************************************
2548  * copy character pattern                                       *
2549  ***************************************************************/
2550
2551 /*
2552  * contents : copy or overlay the new character pattern to the current pattern 
2553  */
2554
2555 /*ARGSUSED*/
2556 static void
2557 copyPatterns( fdata, s1_code, s2_code, d1_code, proc )
2558 FalFontData     *fdata; 
2559 int     s1_code;
2560 int     s2_code;
2561 int     d1_code;
2562 int     proc;   
2563 {
2564     int         ret;
2565     int         d1_ncode, d2_ncode;
2566     int         code_d;
2567     int         code_disp;
2568     char        err[128];
2569     int         i_s, i_d;
2570     int         i;
2571     char        grc_d;
2572     char        **ptn;
2573     char        ptn2[MAXPTNBYTE];
2574     int         num;
2575     extern int  last_code;
2576
2577     ret = copySNF(s1_code, s2_code, &ptn, &num, err);
2578     if( ret == -1 ) {
2579         Error_message2((Widget)NULL, err);
2580         return;
2581     }
2582
2583     if (last_code < (d1_code + num))
2584         last_code = d1_code + num;
2585
2586     if( ptnSense(edg.code) == 1 )
2587         ptnAdd( edg.code, edg.ptn );
2588
2589     d1_ncode = codeToNo( d1_code );
2590
2591     for (i_d=d1_ncode, i_s=0; i_s < num; i_d++) {
2592         if ( codeCheck( noToCode( i_d)))
2593             continue;
2594         bitPtnClear( ptn2 );
2595         code_d = noToCode( i_d );
2596         grc_d = ptnGet( code_d,  ptn2 );
2597
2598         if (grc_d == 0) {
2599             if( proc == CPY_OVERLAY ) {
2600                 for( i=0  ;  i < edg.height*((edg.width+7)/8)  ;  i++ ) {
2601                     ptn[i_s][i] |= ptn2[i];
2602                 }
2603             }
2604             ptnAdd( code_d, ptn[i_s] );
2605             edg.flag = ON;
2606         } else {
2607             if( ptnAdd( code_d, ptn[i_s] ) != 1 ) {
2608                 SetString( wgeStaT, resource.me_non_memory );
2609                 break;
2610             }
2611             edlist.nptn++;
2612             edg.flag = ON;
2613         }
2614         i_s ++;
2615     }
2616     d2_ncode = i_d - 1;
2617     
2618     code_disp = 0;
2619     for( i=d1_ncode   ; i <= d2_ncode; i++ ) {
2620         if ( codeCheck( noToCode(i) ) )
2621             continue;
2622         if( ptnSense( noToCode( i ) ) == 1 ) {
2623             code_disp = noToCode( i );
2624             break;
2625         } 
2626     }
2627     freeSNF(ptn, num);
2628     
2629     if( (code_disp == 0) && (efctPtnNum() > 0))
2630         code_disp = noToCode( ptnSqToNo(edlist.sqstart) );
2631
2632     chgEdCode( code_disp, ON );
2633
2634     resetEditMode( (UINT) (RES_MSG | RES_PROC | RES_SLCT | RES_RSV) );
2635 }