1 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
2 **+
3 ** NAME
4 **      flx_show_dialog
5 **
6 ** PURPOSE
7 **     Popup dialogs to replace some of the xforms goodies
8 **
9 ** CALLING SEQUENCE
10 **     status = flx_show_dialog("type", "message_string");
11 **
12 **     status (int) is the return value.  All dialogs except question have
13 **          only an "Ok" button, and return the value 1.  A question dialog
14 **          has "Ok" and "Cancel" buttons, and returns 1 for "Ok", and 0
15 **          for "Cancel"
16 **
17 **     type can be one of the following strings:
18 **          error
19 **          info
20 **          question
21 **          message
22 **          warning
23 **
24 **     message_string is the text to display in the dialog box, and may
25 **          contain newline (\n) characters for multi-line messages
26 **
27 **     Dialog attributes can be set by calling any of the following functions
28 **          before the call to fl_show_dialog()
29 **
30 **          void flx_set_dialog_lcol (int theLabelColor);
31 **          void flx_set_dialog_font (int theLabelStyle, int theLabelSize);
32 **          void flx_set_dialog_color (int theInactiveColor, int theActiveColor);
33 **          void flx_set_dialog_bgcolor (int theBgColor);
34 **
35 ** MODIFICATION HISTORY
36 **     Written, Robert.Mallozzi@msfc.nasa.gov, February 1997
37 **
38 ** * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
39 **
40 ** flx: Extensions for the xforms library
41 **
42 ** This library is free software; you can redistribute it and/or
43 ** modify it under the terms of the GNU Library General Public
44 ** License as published by the Free Software Foundation; either
45 ** version 2 of the License, or (at your option) any later version.
46 **
47 ** This library is distributed in the hope that it will be useful,
48 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
49 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
50 ** Library General Public License for more details.
51 **
52 ** You should have received a copy of the GNU Library General Public
53 ** License along with this library; if not, write to the Free
54 ** Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
55 **
56 ** * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
57 
58 #include <stdlib.h>
59 #include <forms.h>
60 #include "flx.h"
61 #include "flx_show_dialog.h" /* Internal to this routine */
62 
63 #include "error.xpm"
64 #include "info.xpm"
65 #include "message.xpm"
66 #include "warning.xpm"
67 #include "question.xpm"
68 
69 static void usage();
70 
71 
72 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
flx_show_dialog(const char * type_str,const char * message_str)73 int flx_show_dialog (const char *type_str, const char *message_str)
74 {
75 
76     FL_FORM *main_form;
77     FL_OBJECT *obj, *obj_ok, *obj_cancel, *ret;
78 
79     int button_width  = 70;
80     int button_height = 25;
81     int min_x         = 180;
82     int min_y         = 120;
83     int pad           = 10;
84     int pm_width      = 50;
85     int pm_height     = 50;
86 
87     int label_width, label_height;
88     int button_label_width, button_label_height;
89     int status = 0;
90     int form_x, form_y, yoffset, ymax_height;
91     char **discriminator;
92 
93 
94     /* discriminator holds the array of char pointers obtained from the
95     ** #include of the pixmaps
96     */
97     discriminator = NULL;
98 
99     if (strcmp(type_str, "error") == 0)
100        discriminator = error_xpm;
101 
102     if (strcmp(type_str, "info") == 0)
103        discriminator = info_xpm;
104 
105     if (strcmp(type_str, "message") == 0)
106        discriminator = message_xpm;
107 
108     if (strcmp(type_str, "question") == 0)
109        discriminator = question_xpm;
110 
111     if (strcmp(type_str, "warning") == 0)
112        discriminator = warning_xpm;
113 
114     if ((strcmp(type_str, "error")    != 0) &&
115         (strcmp(type_str, "info")     != 0) &&
116         (strcmp(type_str, "message")  != 0) &&
117         (strcmp(type_str, "question") != 0) &&
118         (strcmp(type_str, "warning")  != 0)) {
119        usage();
120     }
121 
122 
123     /* Get the string sizes, then size the form */
124 
125     /* The Ok, Cancel buttons */
126     fl_get_string_dimension(FLX_DIALOG_LSTYLE, FLX_DIALOG_LSIZE,
127                   "Cancel", strlen("Cancel"),
128                   &button_label_width, &button_label_height);
129 
130     /* Resize buttons ? */
131     if (button_label_width >= button_width)
132        button_width = button_label_width + 6;
133     if (button_label_height >= button_height)
134        button_height = button_label_height + 6;
135 
136     /* The main label */
137     fl_get_string_dimension(FLX_DIALOG_LSTYLE, FLX_DIALOG_LSIZE,
138                   message_str, strlen(message_str),
139                   &label_width, &label_height);
140 
141     form_x = pm_width + pad + label_width + pad;
142     if (form_x < min_x)
143        form_x = min_x;
144 
145     if (label_height <= pm_height)
146        ymax_height = pm_height;
147     else
148        ymax_height = label_height;
149 
150     form_y = ymax_height + pad + 10 + pad + button_height + pad;
151     if (form_y < min_y)
152        form_y = min_y;
153 
154     yoffset = form_y - min_y;
155 
156 
157     main_form = fl_bgn_form(FL_NO_BOX, form_x, form_y);
158 
159         obj = fl_add_box(FL_UP_BOX,
160             0, 0, form_x, form_y, "");
161         fl_set_object_color(obj, FLX_DIALOG_BGCOLOR, 0);
162 
163         obj = fl_add_pixmap(FL_NORMAL_PIXMAP,
164             0, 0, pm_width, pm_height, "");
165         fl_set_pixmap_data(obj, discriminator);
166 
167         obj = fl_add_box(FL_NO_BOX,
168             pm_width + pad, 0,
169             label_width, ymax_height,
170             message_str);
171         fl_set_object_lcol(obj, FLX_DIALOG_LCOL);
172         fl_set_object_lstyle(obj, FLX_DIALOG_LSTYLE);
173         fl_set_object_lsize(obj, FLX_DIALOG_LSIZE);
174 
175         obj = fl_add_box(FL_NO_BOX,
176             0, ymax_height + pad, form_x, 10, "@DnLine");
177 
178         if (strcmp(type_str, "question") == 0) {
179 
180            obj_ok = flx_add_return_button(FL_NORMAL_BUTTON,
181                pad, ymax_height + pad + 10 + pad,
182                button_width, button_height, "Ok");
183            fl_set_object_color(obj_ok, FLX_DIALOG_ICOLOR, FLX_DIALOG_ACOLOR);
184            fl_set_object_lcol(obj_ok, FLX_DIALOG_LCOL);
185            fl_set_object_lstyle(obj_ok, FLX_DIALOG_LSTYLE);
186            fl_set_object_lsize(obj_ok, FLX_DIALOG_LSIZE);
187 
188            obj_cancel = fl_add_button(FL_NORMAL_BUTTON,
189                form_x - button_width - pad, ymax_height + pad + 10 + pad,
190                button_width, button_height, "Cancel");
191            fl_set_object_color(obj_cancel, FLX_DIALOG_ICOLOR, FLX_DIALOG_ACOLOR);
192            fl_set_object_lcol(obj_cancel, FLX_DIALOG_LCOL);
193            fl_set_object_lstyle(obj_cancel, FLX_DIALOG_LSTYLE);
194            fl_set_object_lsize(obj_cancel, FLX_DIALOG_LSIZE);
195 
196         }
197         else {
198 
199            obj_ok = flx_add_return_button(FL_NORMAL_BUTTON,
200                (form_x - button_width)/2, ymax_height + pad + 10 + pad,
201                button_width, button_height, "Ok");
202            fl_set_object_color(obj_ok, FLX_DIALOG_ICOLOR, FLX_DIALOG_ACOLOR);
203            fl_set_object_lcol(obj_ok, FLX_DIALOG_LCOL);
204            fl_set_object_lstyle(obj_ok, FLX_DIALOG_LSTYLE);
205            fl_set_object_lsize(obj_ok, FLX_DIALOG_LSIZE);
206 
207            obj_cancel = obj_ok;
208 
209         }
210 
211     fl_end_form();
212 
213     fl_show_form(main_form, FL_PLACE_MOUSE, FL_TRANSIENT, type_str);
214 
215     ret = fl_do_forms();
216 
217     if (ret == obj_cancel)
218        status = 0;
219 
220     if (ret == obj_ok)
221        status = 1;
222 
223     fl_hide_form(main_form);
224     return (status);
225 
226 
227 } /* END */
228 
229 
230 
231 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
usage(void)232 void usage(void)
233 {
234        printf("int flx_show_dialog (const char *type_str, const char *message_str)\n");
235        printf("    type_str = error\n");
236        printf("               info\n");
237        printf("               message\n");
238        printf("               question\n");
239        printf("               warning\n");
240        printf("    message_string = the message drawn in the dialog box\n");
241        exit (2);
242 
243 }
244 
245 
246 
247 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
flx_set_dialog_lcol(int theLabelColor)248 void flx_set_dialog_lcol (int theLabelColor)
249 {
250     FLX_DIALOG_LCOL = theLabelColor;
251 
252 }
253 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
flx_set_dialog_font(int theLabelStyle,int theLabelSize)254 void flx_set_dialog_font (int theLabelStyle, int theLabelSize)
255 {
256     FLX_DIALOG_LSTYLE = theLabelStyle;
257     FLX_DIALOG_LSIZE  = theLabelSize;
258 
259 }
260 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
flx_set_dialog_color(int theInactiveColor,int theActiveColor)261 void flx_set_dialog_color (int theInactiveColor, int theActiveColor)
262 {
263     FLX_DIALOG_ICOLOR = theInactiveColor;
264     FLX_DIALOG_ACOLOR = theActiveColor;
265 
266 }
267 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
flx_set_dialog_bgcolor(int theBgColor)268 void flx_set_dialog_bgcolor (int theBgColor)
269 {
270     FLX_DIALOG_BGCOLOR = theBgColor;
271 
272 }
273