sym2num: don't hardcode path to cpp
[oweals/cde.git] / cde / programs / dtudcfonted / cpyw.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 libraries 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 /* cpyw.c 1.9 - Fujitsu source for CDEnext    96/10/30 13:31:40      */
24 /* $XConsortium: cpyw.c /main/7 1996/11/08 01:53:38 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 #include <stdio.h>
35
36 #include <X11/Intrinsic.h>
37
38 #include "xoakufont.h"
39 #include "util.h"
40
41
42 extern Resource resource ;
43 extern Widget   cpyDialog;
44
45 /**
46  **  create and display the "User defined character ecitor :Copy" window
47  ** ==================================================================
48  **/
49
50 void    PopdownCpyPtn(void);
51 void    DoCpyProc(void);
52 void    CpyPtnCB(void);
53 void    CpyCB(Widget w, XtPointer cdata);
54
55 /* static */ TextField SrcTf;
56 /* static */ TextField DestTf;
57
58
59 /**
60  **  contents : initialize the "Copy" window
61  ** --------------------
62  **
63  **
64  **/
65
66 void
67 InitCpyPtn(void)
68 {
69         /* initialize font infomation */
70 }
71
72
73 /**
74  **  contents : create and pop up the "Copy" window
75  ** ----------------------------------
76  **
77  **/
78
79 void
80 CpyPtnCB(void)
81 {
82     extern void CpyPtnXLFD();
83     CpyPtnXLFD();
84 }
85
86
87 /**
88  **  contents : pop down the "Copy" window
89  ** ----------------------
90  **/
91
92 void
93 PopdownCpyPtn(void)
94 {
95     ForcePopdownDialog(cpyDialog);
96 }
97
98
99 /**  contents :
100  **  get the character strings of source code area from the input field
101  ** --------------------------------------
102  **/
103
104 String
105 CpySrcCodeTfValue(void)
106 {
107     return(GetTextFieldValue(&SrcTf));
108 }
109
110
111 /**  contents :
112  **  get the character strings of destination code area from input field
113  ** --------------------------------------
114  **/
115
116 String
117 CpyDestCodeTfValue(void)
118 {
119     return(GetTextFieldValue(&DestTf));
120 }
121
122
123 /**
124  **  contents : pop up the copy confirmation window
125  ** --------------------------------
126  **/
127
128 void
129 PopupCpyNotice( String message )
130 {
131     char bmsg[512] = "";
132
133     static NoticeButton buttons[] = {
134         NBTNARGS( DoCpyProc, NULL, NULL, True, False ),
135         NBTNARGS( NULL, NULL, NULL, True, False ),
136     };
137     static NButton BTN = NBUTTONS( buttons );
138
139     snprintf(bmsg, sizeof(bmsg), "%s%s", resource.mn_cpy_lost, message);
140     SetItemLabel(&BTN, 0, resource.l_ok);
141     SetItemLabel(&BTN, 1, resource.l_cancel);
142     PopupNotice( cpyPtnW, bmsg, D_WARNING, &BTN, False, resource.l_warning_title);
143 }
144
145
146 /**
147  **  contents : "Copy" button callback
148  ** ------------------------
149  **  execute the copy processing
150  **/
151
152 /*ARGSUSED*/
153 void
154 CpyCB(Widget w, XtPointer cdata)
155 {
156     extern Boolean BeforeCpyCheck();
157     if (BeforeCpyCheck(cdata)){
158         PopdownCpyPtn();
159         DoCpyProc();
160     }
161 }
162
163
164
165 /**
166  **  "Add/Delete" window
167  ** ===================================================================
168  **/
169
170 /**
171  **  contents : pop down the "Add/Delete" window
172  ** ------------------------------
173  **/
174
175 static void
176 PopdownMngPtn(void)
177 {
178     PopdownDialog(mngPtnW);
179 }
180
181 /**
182  **  contents : "Add" button callback
183  ** ------------------------
184  **/
185
186 static void
187 AddCB(void)
188 {
189     int s_code, e_code;
190     extern Boolean BeforeMngCheck();
191     extern void DoAddProc();
192
193     if (BeforeMngCheck(&s_code, &e_code)){
194         DoAddProc(s_code, e_code);
195         PopdownMngPtn();
196     }
197 }
198
199 /**
200  **  contents : "Delete" button callback
201  ** ------------------------
202  **/
203
204 static void
205 DelCB(void)
206 {
207     int s_code, e_code;
208     extern void DoDelProc();
209     extern Boolean BeforeMngCheck();
210
211     if (BeforeMngCheck(&s_code, &e_code)){
212         DoDelProc(s_code, e_code);
213     }
214 }
215
216 static ButtonItems add_btn[] = {
217     BTNARGS( (void(*)(struct _WidgetRec*,void*,void*)) AddCB, NULL, NULL, True, True ),
218     BTNARGS( (void(*)(struct _WidgetRec*,void*,void*)) DelCB, NULL, NULL, True, False ),
219     BTNARGS( (void(*)(struct _WidgetRec*,void*,void*)) PopdownMngPtn, NULL, NULL, True, False ),
220 };
221 static Button AddBTN = BUTTONS( add_btn );
222
223 static TextField MngCodeTf;
224
225 /**
226  **  contents : create and pop up the "Add/Delete" window
227  ** ------------------------------------
228  **/
229
230 void
231 MngPtnCB(void)
232 {
233     if (! mngPtnW){
234         Widget  rowcol;
235
236         SetItemLabel(&AddBTN, 0, resource.l_add);
237         SetItemLabel(&AddBTN, 1, resource.l_delete);
238         SetItemLabel(&AddBTN, 2, resource.l_cancel);
239         rowcol =
240         CreateDialogAndButtons( toplevel, resource.l_add_title,
241
242             NULL, &AddBTN, XtNumber(add_btn), &mngPtnW);
243
244         CreateTextField(rowcol, "wgkTxtF",
245             resource.l_manage_code, &MngCodeTf, 4);
246     }
247     PopupDialog(mngPtnW);
248 }
249
250
251
252
253 /**
254  **  contents : get the character strings of code for add or delete from the
255  **  input field
256  ** --------------------------------------------
257  **/
258
259 String
260 MngCodeTfValue(void)
261 {
262     return(GetTextFieldValue(&MngCodeTf));
263 }
264
265
266
267 /**
268  **  the delete confirmation window
269  ** ===================================================================
270  **/
271
272 static Widget   CreateDelNotice();
273 static void     drawDelPtn();
274 static void     drawDelCode();
275 static void     CBdnOblB_del();
276 static void     EHdnBulB_disp();
277 void    EHStaT_disp();                  /* add 1995.09.20 */
278
279 static  Widget  dnStaT_code[D_MAX], dnBulB_disp[D_MAX], dnPopW;
280
281 /**
282  **  contents : pop up the delete confirmation window
283  ** --------------------------
284  **/
285
286 void
287 PopupDelNotice( Widget owner )
288 {
289     int i;
290      Widget delNoticeW = NULL;
291
292     delNoticeW = CreateDelNotice(owner);
293     XtVaSetValues(XtParent(delNoticeW), XmNmappedWhenManaged, False, NULL);
294     XtManageChild(delNoticeW);
295
296     for ( i=0 ; i < dn.disp_num ; i++ ) {
297         /* moved from paneDelNotice body */
298         dl[i].disp_winID = XtWindow( dnBulB_disp[i] );
299
300         drawDelCode(i);
301         drawDelPtn(i);
302     }
303     XtVaSetValues(XtParent(delNoticeW), XmNmappedWhenManaged, True, NULL);
304
305     XBell(XtDisplayOfObject(delNoticeW), 0);
306 }
307
308
309 /**
310  **  contents : clear the image of deleted character
311  ** ----------------------------------------------
312  **/
313
314 static void
315 dstrypaneDelNotice(void)
316 {
317     int i;
318
319     for ( i=0; i<dn.disp_num; i++ ){
320         XFree((char *) dl[i].dispImage);
321     }
322 }
323
324
325 /**
326  **  contents : "OK" button callback
327  ** ----------------------------
328  **/
329
330 static void
331 DelOkCB(void)
332 {
333     CBdnOblB_del();
334     PopdownMngPtn();
335 }
336
337
338 /**
339  **  contents : callback of the delete list
340  ** ------------------------------------
341  **/
342
343 static void
344 delScProc( int value )
345 {
346     int         i;
347     extern int RelToAbsSq();
348
349     dn.sq_top = RelToAbsSq( dn.sq_start, value - dn.sq_start);
350     for ( i=0 ; i < dn.disp_num ; i++ ) {
351         drawDelCode(i);
352         drawDelPtn(i);
353     }
354 }
355
356
357 /**
358  **  contents : create the delete confirmation window
359  ** --------------------------
360  **/
361
362 static Widget
363 CreateDelNotice(Widget owner)
364 {
365     Widget form, listBase, itemform[D_MAX];
366     char buf[64];
367     int i, val, min, max;
368     int c ;
369     extern int AbsSqToRel();
370     extern void AddDestroyProc();
371
372     static NoticeButton buttons[] = {
373         NBTNARGS( (void(*)(struct _WidgetRec*,void*,void*)) DelOkCB, NULL, NULL, True, False ),
374         NBTNARGS( NULL, NULL, NULL, True, False ),
375     };
376     static NButton BTN = NBUTTONS( buttons );
377     c = AbsSqToRel( dn.sq_start, dn.sq_end) + 1;
378     if (c == 1) {
379         sprintf(buf, "%s(%d %s)", resource.mg_start_del_s,
380                                         c, resource.mg_start_del_cs );
381     } else {
382         sprintf(buf, "%s(%d %s)", resource.mg_start_del_m,
383                                         c, resource.mg_start_del_cm );
384     }
385     SetItemLabel(&BTN, 0, resource.l_ok);
386     SetItemLabel(&BTN, 1, resource.l_cancel);
387     form = CreateTemplateDialog( owner, buf, D_QUESTION, &BTN,
388                 resource.l_question_title, &dnPopW);
389     AddDestroyProc(dnPopW, dstrypaneDelNotice);
390
391     if ( dn.disp_num < (AbsSqToRel( dn.sq_start, dn.sq_end) + 1)) {
392
393         val = AbsSqToRel( dn.sq_start, dn.sq_top) + dn.sq_start;
394         min = dn.sq_start;
395         max = AbsSqToRel( dn.sq_start, dn.sq_end) + dn.sq_start +1;
396         listBase = CreateScrollBase( form, "listBase",
397                                 min, max, val, dn.disp_num, delScProc );
398     }
399     else{
400         listBase =
401         CreateRowColumn( form, "listBase", L_VERTICAL, 4,2,2 );
402     }
403
404     for(i=0; i<dn.disp_num; i++) {
405         /* create form for the codes and fonts to be deleted */
406         itemform[i] = CreateForm( listBase, "listBase" );
407
408         /* create widgets for the codes to be deleted in the list */
409         dnStaT_code[i] = CreateLabel( itemform[i], "label", "    " );
410         AddTopAttachForm( dnStaT_code[i], 0 );
411         AddLeftAttachForm( dnStaT_code[i], 0 );
412         AddBottomAttachForm( dnStaT_code[i], 0 );
413
414         /* create widgets for the image of the codes to be deleted in the list */
415         dnBulB_disp[i] = CreateDrawingArea( itemform[i], "image",
416                         edg.width, edg.height, EHdnBulB_disp, i);
417         AddLeftAttachWidget( dnBulB_disp[i], dnStaT_code[i], 0 );
418
419         /* */
420         dl[i].dispImage  = XCreateImage( xl.display,
421                 DefaultVisual( xl.display, DefaultScreen(xl.display) ),
422                 1, XYBitmap, 0, dl[i].ptn, dn.ptn_w, dn.ptn_h, 8, 0);
423         dl[i].dispImage->bitmap_bit_order = MSBFirst;
424         dl[i].dispImage->byte_order       = MSBFirst;
425
426     }
427     XtManageChildren( itemform, dn.disp_num );
428     return(dnPopW);
429 }
430
431
432 /**
433  **  contents : delete characters from editor
434  ** -----------------------------------------
435  **
436  **/
437
438 static void
439 CBdnOblB_del(void)
440 {
441     int         code;   /* code number for check */
442     int         ncode;  /* sequential number in the codeset system area */
443     int         sq_now; /* sequential number in the editor */
444     char        mode;   /* notify the modification of the edit list */
445     extern void chgEdCode();
446
447     XtSetSensitive( dnPopW, FALSE );
448     mode = OFF;
449     for( sq_now=dn.sq_end ; sq_now >= dn.sq_start ; sq_now-- ) {
450         ncode = ptnSqToNo(sq_now);
451         if ( codeCheck( noToCode(ncode)))
452             continue;
453         if (ptnSense( noToCode(ncode) ) == 1) {
454             ptnDel( noToCode(ncode) );
455             edlist.nptn--;
456             edg.flag = ON;
457             mode = ON;
458         }
459     }
460
461     /* update the current character */
462
463     sq_now++;
464     for ( ; sq_now < (edlist.sqstart + edlist.nptn); sq_now++) {
465         ncode = ptnSqToNo(sq_now);
466         if (( ncode >= 0) && ( codeCheck( noToCode( ncode)) == 0))
467             break;
468     }
469     if(sq_now > (edlist.sqstart + edlist.nptn -1)) {
470         sq_now--;
471         for ( ; sq_now >= edlist.sqstart; sq_now--) {
472             ncode = ptnSqToNo(sq_now);
473             if (( ncode >= 0) && ( codeCheck( noToCode( ncode)) == 0))
474                 break;
475         }
476     }
477
478     /* check the existence of the current character */
479     if( (sq_now != -1) && ((ncode = ptnSqToNo(sq_now)) != -1) ){
480         code = noToCode( ncode );
481     } else {
482         /* There is no characters on the editor, dtudcfonted does not
483         * display any character on the editing pane and forbid users
484         * to input.
485         * It can realize to put 0 to the first parameter of chgEdCode().
486         */
487         code = 0;
488     }
489     if(codeCheck( code )) {
490         code = 0;
491     }
492
493     /* */
494     if( ptnSense( edg.code ) == 1 ) {
495         ptnAdd( edg.code, edg.ptn );
496     }
497
498     /* renew the current character */
499     if (mode == ON) {
500         chgEdCode( code, mode );
501     }
502     XtSetSensitive( dnPopW,  TRUE );
503 }
504
505
506 /**
507  **  contents : display the image of the character to be deleted
508  ** ------------------------
509  **
510  **/
511
512 static void
513 drawDelPtn( int i /* window number */)
514 {
515     if ( RelToAbsSq( dn.sq_top, i) <= dn.sq_end) {
516         ptnGet( noToCode(ptnSqToNo(RelToAbsSq( dn.sq_top, i))),
517                                                                 dl[i].ptn );
518         XPutImage(xl.display, dl[i].disp_winID, xl.borderGC,
519                         dl[i].dispImage, 0,0,0,0, dn.ptn_w, dn.ptn_h );
520     } else {
521         return;
522     }
523 }
524
525
526 /**
527  **  contents : display the code of the character to be deleted
528  ** ----------------------
529  **
530  **/
531
532 static void
533 drawDelCode( int i /* window number */)
534 {
535     char        str[20];
536
537     if ( RelToAbsSq( dn.sq_top, i) <= dn.sq_end) {
538         sprintf(str, "%4x ", noToCode(ptnSqToNo(RelToAbsSq( dn.sq_top, i))));
539         SetLabelString(dnStaT_code[i], str);
540     } else {
541         return;
542     }
543 }
544
545
546 /**
547  **  contents : re-display the code of the character to be deleted
548  ** --------------------------------------------------------------
549  **/
550
551 /*ARGSUSED*/
552 static void
553 EHdnBulB_disp( Widget widget, int i /* widget that have some ivent */ )
554 {
555     drawDelPtn( i );
556 }
557
558
559
560 /**
561  **  notify error message
562  ** ===================================================================
563  **
564  **/
565
566 /**
567  **  contents : inner functions of DispMngErrorMessage()
568  ** ----------------------------------
569  **/
570
571 static void
572 DispErrorMessage( Widget owner, String title, String msg )
573 {
574     static NoticeButton buttons[] = {
575         NBTNARGS( NULL, NULL, NULL, True, False ),
576     };
577     static NButton BTN = NBUTTONS( buttons );
578
579     SetItemLabel(&BTN, 0, resource.l_ok);
580     PopupNotice( owner, msg, D_ERROR, &BTN, False, title );
581 }
582
583
584 /**
585  **  contents : display "Add" or "Delete" error
586  ** --------------------------------
587  **/
588
589 void
590 DispMngErrorMessage( String msg )
591 {
592     DispErrorMessage( mngPtnW, resource.l_error_title, msg );
593 }
594
595
596 /**
597  **  contents : display "Copy" error
598  ** --------------------------
599  **/
600
601 void
602 DispCpyErrorMessage( String msg )
603 {
604     DispErrorMessage( cpyPtnW, resource.l_error_title, msg );
605 }