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