Fix dttypes for BSD systems
[oweals/cde.git] / cde / programs / dtudcexch / udcexp.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 /* $XConsortium: udcexp.c /main/5 1996/10/14 14:45:34 barstow $ */
24 /*
25  *  (c) Copyright 1995 FUJITSU LIMITED
26  *  This is source code modified by FUJITSU LIMITED under the Joint
27  *  Development Agreement for the CDEnext PST.
28  *  This is unpublished proprietary source code of FUJITSU LIMITED
29  */
30
31 #include "excutil.h"
32 #include <Xm/MessageB.h>
33 #include <Xm/RowColumn.h>
34 #include <Xm/List.h>
35 #include <Xm/Form.h>
36 #include <Xm/Label.h>
37
38 void    setselectedcode();
39
40 extern char *maintitle;
41
42 void udcexp(Exc_data * ed)
43 {
44     ed->function = EXPORT;
45     strcpy(ed->bdfmode,"w");
46
47     PopupSelectXLFD(ed->toplevel);
48 }
49
50 void createbdf(Exc_data * ed)
51 {
52     int i = 0;
53     char *comment_list[] = {""};
54     int comment_num = 0;
55     char *msg;
56     int ans;
57
58     msg = GETMESSAGE(10, 2, "Failed to make the BDF file");
59
60     i =  ExpGpftoBDF(ed->fontfile, ed->bdffile,
61                      ed->code_num, ed->gpf_code_list,
62                      comment_num, comment_list, 0);
63     if (i != 0) {
64         AskUser(ed->toplevel, ed, msg, &ans, "error");
65     }
66     excterminate(ed);
67 }
68
69 void selcharokCB(Widget widget, ListData * ld, XtPointer call_data)
70 {
71     int         num;
72     Exc_data    *ed;
73     int         ans;
74     char        *msg;
75
76     msg = GETMESSAGE(10, 4, "No indexes are selected");
77
78     XtVaGetValues(ld->list, XmNselectedItemCount, &num, NULL);
79     if (num == 0) {
80 /*      AskUser(widget, ld->ed, msg, &ans, "error");*/
81         return;
82     } else {
83         setselectedcode(ld);
84         XtUnmanageChild(XtParent(widget));
85         ed = ld->ed;
86         freeld(ld);
87         getbdffn(ed);
88     }
89 }
90 void selcharcancelCB(Widget widget, ListData * ld, XtPointer call_data)
91 {
92     Exc_data    *ed;
93
94     ed = ld->ed;
95     freeld(ld);
96     excterminate(ed);
97 }
98
99 XmString * setxmslist(ListData * ld)
100 {
101     char        **cp;
102     XmString    *xmslist, *xmsp;
103     int         i;
104
105     if ((xmslist = (XmString *) calloc(ld->existcode_num, sizeof(XmString *)))
106         == NULL) {
107         excerror(ld->ed, EXCERRMALLOC, "setxmslist", "exit");
108     }
109     cp = ld->existcode_c;
110     xmsp = xmslist;
111     for (i = 0; i < ld->existcode_num; i++) {
112         *xmsp = XmStringCreateLocalized(*cp);
113         xmsp++;
114         cp++;
115     }
116     return (xmslist);
117 }
118
119 void freexmslist(ListData * ld, XmString * xmslist)
120 {
121     XmString    *xmsp;
122     int         i;
123
124     if (xmslist != NULL) {
125         xmsp = xmslist;
126         for (i = 0; i < ld->existcode_num; i++) {
127             XmStringFree(*xmsp);
128             xmsp++;
129         }
130         free(xmslist);
131     }
132 }
133
134 void selcharcd(Exc_data * ed)
135 {
136     Widget              mainw, selcd, ok, cancel;
137     Widget              slctLabel, form;
138     Arg                 args[20];
139     Cardinal            n;
140     char                *oklabel;
141     char                *cancellabel;
142     XmString            *xmslist;
143     extern ListData     *ld;
144     char                *p;
145
146     oklabel = GETMESSAGE(10, 6, "OK");
147     cancellabel = GETMESSAGE(10, 8, "Cancel");
148
149     n = 0;
150     XtSetArg(args[n], XmNautoUnmanage, False); n++;
151     XtSetArg(args[n], XmNtitle, maintitle); n++;
152     mainw = XmCreateTemplateDialog(ed->toplevel, "mainw", args, n);
153
154     n = 0;
155     form = XmCreateForm( mainw, "form", args, n);
156     XtManageChild(form);
157
158     p = GETMESSAGE(10, 10, "glyph indexes");
159     n = 0;
160     XtSetArg( args[n], XmNx,            20 ) ;  n++;
161     XtSetArg( args[n], XmNheight,       20 ) ;  n++ ;
162     XtSetArg( args[n], XmNtopAttachment, XmATTACH_FORM ) ; n++ ;
163     XtSetArg( args[n], XmNtopOffset,    10 ) ;  n++ ;
164     slctLabel = XmCreateLabel( form, p, args, n);
165     XtManageChild(slctLabel);
166
167     n = 0;
168     xmslist = setxmslist(ld);
169     XtSetArg( args[n], XmNleftAttachment,       XmATTACH_FORM ) ; n++ ;
170     XtSetArg( args[n], XmNleftOffset,   20 ) ;          n++ ;
171     XtSetArg( args[n], XmNtopAttachment,        XmATTACH_WIDGET ); n++ ;
172     XtSetArg( args[n], XmNtopOffset,    5 ) ;           n++ ;
173     XtSetArg( args[n], XmNwidth,        200 ) ;         n++ ;
174     XtSetArg (args[n], XmNtopWidget,    slctLabel );    n++;
175     XtSetArg(args[n], XmNitems, xmslist); n++;
176     XtSetArg(args[n], XmNitemCount, ld->existcode_num); n++;
177     XtSetArg(args[n], XmNvisibleItemCount, 10); n++;
178     XtSetArg(args[n], XmNlistSizePolicy, XmCONSTANT); n++;
179     XtSetArg(args[n], XmNscrollBarDisplayPolicy, XmAS_NEEDED); n++;
180     XtSetArg(args[n], XmNselectionPolicy, XmEXTENDED_SELECT); n++;    
181     selcd = XmCreateScrolledList(form, "Select codes", args, n);
182     freexmslist(ld, xmslist);
183     XtManageChild(selcd);
184
185     ld->list = selcd;
186
187     ok = excCreatePushButton(mainw, "ok", oklabel,
188                              (XtCallbackProc) selcharokCB, (XtPointer) ld);
189
190     cancel = excCreatePushButton(mainw, "cancel", cancellabel,
191                                  (XtCallbackProc) selcharcancelCB,
192                                  (XtPointer) ld);
193
194     XtManageChild(mainw);
195 }
196
197 void setselectedcode(ListData *ld)
198 {
199     int         *position_list;
200     int         position_count;
201     int         i;
202     int         *codep;
203
204     XmListGetSelectedPos(ld->list, &position_list, &position_count);
205
206     ld->ed->code_num = position_count;
207     ld->ed->gpf_code_list = (int *) calloc(position_count, sizeof(int));
208     codep = ld->ed->gpf_code_list;
209
210     for (i = 0; i < position_count; i++) {
211         *codep = *((ld->existcode)+(position_list[i]-1));
212         codep++;
213     }
214 }