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