1 /*
2  * Copyright (C) 1992  Board of Regents of the University of Wisconsin
3  * on behalf of the Department of Electrical Engineering and Computer
4  * Science, University of Wisconsin-Milwaukee, Milwaukee, WI 53201.
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * a copy of which is included here in file "GNU_GENERAL"
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20  *
21  * The programs in this directory were developed by software engineering
22  * teams as part of the course "Introduction to Software Engineering"
23  * under the supervision of Professor G. Davida.
24  * This is a modification of a program written or modified by
25  * others.  The original copyrights, as per GNU General Public License,
26  * may still be applicable.  The UWM copyright is applicable only
27  * the those parts generated at UWM.
28  *
29  * Please send all changes, enhancements, and other comments about this
30  * software to
31  *     		soft-eng@cs.uwm.edu
32  *
33  * No Warranty, expressed or implied, comes with this software.
34  * This software is intended to be used by not-for-profit
35  * organizations or by individuals for personal HOME use.
36  * This software, or any of its parts, may not be used by for-profit
37  * organization, regardless of application or intended product or
38  * customer, without the permission of the Board of Regents of the
39  * University  of Wisconsin.
40  *
41  * Contact:	soft-eng@cs.uwm.edu
42  *			or
43  *
44  *		Software Engineering Coordinator
45  *		Computer Science
46  *    		Department of EECS
47  *		University of Wisconsin - Milwaukee
48  *		Milwaukee, WI  53201
49  *		414-229-4677
50  *
51  *		HISTORY,CLAIMS and CONTRIBUTIONS
52  */
53 /*************************************************************************
54  *  This procedure displays a stacked bar graph for the values chosen    *
55  *  by the user.  It displays one bar for each row chosen and 'stacks'   *
56  *  one section for each column chosen.  It uses patterns located in     *
57  *  the file pattern.h                                                   *
58  *  Dan Gruber - December 1991                                           *
59  *    Modified 5/94 by Dan Coppersmith to improve user friendliness of   *
60  *    error messages.                                                    *
61  *************************************************************************
62  */
63 
64 #include <config.h>
65 
66 #ifdef HAVE_X11_X_H	/* this code for now is X specific */
67 
68 #include <curses.h>
69 #include <X11/Xlib.h>
70 #include <X11/Xutil.h>
71 #include "plot.h"
72 #include "pattern.h"
73 #include "graphic_gvar.h"
74 #include "sc.h"
75 #include "scXstuff.h"
76 #include <math.h>
77 #define TITLE "XSPREAD-Grapher (Stacked Bar Plot)"
78 #define PIX_SEP 5
79 
80 #ifndef irint
81 #define irint(x) floor((x)+0.5)
82 #endif
83 
84   XWMHints   SBwmh = {
85      (InputHint|StateHint),  /*flags*/
86      False,                  /*input*/
87      NormalState,            /*initial_state*/
88      0,                      /*icon pixmap*/
89      0,                      /*icon window*/
90      0, 0,                   /*icon location*/
91      0,                      /*icon mask*/
92      0,                      /*Window group*/
93   };
94 
95 void
plot_stacked_bar()96 plot_stacked_bar()
97    { int argc = 0;
98     char **argv = 0;
99 
100 
101       double  max_y, min_y, Y_Range;
102 
103       int i,j /* ,k */;            /* Iteration variables                  */
104       int grid_l_x;         /* The size of the grid separators      */
105       int grid_l_y;
106       int grid_h;
107       int height, width;    /* Height and width of a bar            */
108       char str[100];        /* The label to be drawn                */
109       int text_w;           /* The width of a label in pixels       */
110       int len;              /* The length of a label                */
111       int x,y;              /* X and Y coordinates for the bar      */
112       struct ent *p, *val;
113       int looping = 1;      /* Continue looping variable            */
114       int draw = 0;         /* Continue drawing variable            */
115       int first_bar = 1;    /* first bar flag                       */
116       int number_of_bars;   /* Total number of bars                 */
117       int bars = 0;         /* Current bar                          */
118       int labelsize;        /* Maximum size of label to be drawn    */
119       double Row_Total[20]; /* Row Total                            */
120       int Y_Position[20];   /* Position to draw next portion of bar */
121       Pixmap Pattern;       /* Type of pattern to be drawn          */
122 
123 
124 /*---- Colors  & fonts added by Rama Devi ---------*/
125 Colormap cmap;
126 XColor exactBlack, exactOrange;
127 XColor exactGreen, exactGoldenrod, exactOrchid;
128 XColor exactYellow, exactGreenYellow, exactAquamarine;
129 
130 XColor Black, Orange;
131 XColor Green, Goldenrod, Orchid, Yellow, GreenYellow, Aquamarine;
132 
133 extern XFontStruct *curfont;       /* Font descriptor struct for current font */
134 extern Font       curfontid;       /* resource id of current font */
135 extern int        curfontwidth,
136            curfontheight;   /* pixel dimensions of current font */
137 
138     /*
139      * Decide the scale for x and y axes
140      */
141 
142   for (i=graphic_range[0].r1; i<=graphic_range[0].r2; i++)
143   {
144      p=lookat(i,graphic_range[0].c);
145      if(!(p->label)) continue;
146      bars++;
147      Row_Total[bars] = 0;
148      Y_Position[bars] = 0;
149   }
150 
151   if (bars < 1)
152   {
153      fprintf(stderr,"\007");
154      if (graphic_range[0].r2 - graphic_range[0].r1 > 1)
155 	message("x values must be strings");
156      else
157      	message("Not enough valid X labels");
158      return;
159   }
160 
161   number_of_bars = bars;
162 
163     if (g_auto_man[1] == 'M') {
164        max_y = graphic_scale[1][1];
165        min_y = graphic_scale[1][0];
166     }
167     else {
168        for (j=1; j < GRAPHRANGES; j++){
169           if (*(graphic_range[j].col) == '\0') continue;
170           bars = 0;
171 
172 /*-----for (i=graphic_range[j].r1; i<=graphic_range[j].r2; i++)------*/
173 
174           for (i=graphic_range[0].r1; i<=graphic_range[0].r2; i++)
175 	  {
176              /*----- p=lookat(i,graphic_range[j].c); ---commented Rama Devi--*/
177             /* if(!(p->flags & is_valid)) continue; */
178 
179      p=lookat(i,graphic_range[0].c); /*---added by Rama Devi ---*/
180      if(!(p->label)) continue;       /*---added by Rama Devi ---*/
181 
182              bars++;
183 
184          /*--- The following lines added by Rama Devi ---------*/
185              if (( i >= graphic_range[j].r1) && (i <= graphic_range[j].r2))
186 
187              {
188 
189              val =lookat(i,graphic_range[j].c);
190 
191             if (val->flags & is_valid){
192 
193          /*------------------------------------------------------*/
194 
195              Row_Total[bars] = Row_Total[bars] + (val->v);
196              if (first_bar){
197                  min_y = val->v;
198                  first_bar = 0;
199                 } else
200                  min_y = Min(min_y, val->v);
201                                         }
202 
203              }
204           }
205        }
206        first_bar = 1;
207        for (i=1; i<=bars; i++){
208           if (first_bar){
209              max_y = Row_Total[i];
210              first_bar = 0;
211           } else {
212                max_y = Max(max_y, Row_Total[i]);
213             }
214        }
215        min_y -= 0.1*(fabs(min_y));
216        max_y += 0.1*(fabs(max_y));
217     }
218     max_y = ceil(max_y);
219     min_y = floor(min_y);
220 
221     /*
222      * Select colors for the border,  the window background,  and the
223      * foreground.
224      */
225 
226     /*---- Colors and fonts added by Rama Devi --*/
227     cmap = DefaultColormap(dpy, DefaultScreen(dpy));
228     if ((XAllocNamedColor(dpy, cmap, "Black", &exactBlack,
229              &Black) != 0) && (XAllocNamedColor (dpy, cmap,
230              "Orange", &exactOrange, &Orange) != 0))
231       {
232       bd = Orange.pixel;
233       bg = Black.pixel;
234       fg = Orange.pixel;
235       }
236     else
237       {
238       bd = WhitePixel(dpy, DefaultScreen(dpy));
239       bg = BlackPixel(dpy, DefaultScreen(dpy));
240       fg = WhitePixel(dpy, DefaultScreen(dpy));
241       }
242 
243   if (userfont == NULL)
244      curfont = XLoadQueryFont(dpy, SC_FONT);
245   else
246      curfont = XLoadQueryFont(dpy, userfont);
247   if (curfont == NULL)
248   {
249     fprintf(stderr, "%s: Display %s doesn't know font \"%s\" \n",
250           progname, DisplayString(dpy), userfont == NULL ? SC_FONT : userfont);
251     exit(1);
252   }
253   /* initialize the font-related globals */
254   /* usefont(curfont); */
255   curfontid = curfont->fid;
256   curfontheight = curfont->max_bounds.ascent + curfont->max_bounds.descent;
257   curfontwidth = curfont->max_bounds.width;
258 
259     /*
260      * Set the border width of the window,  and the gap between the text
261      * and the edge of the window, "pad".
262      */
263 
264     pad = BORDER;
265     bw = 1;
266 
267     /*
268      * Deal with providing the window with an initial position & size.
269      * Fill out the XSizeHints struct to inform the window manager. See
270      * Sections 9.1.6 & 10.3.
271      */
272 
273     xsh.width = XTextWidth(curfont, TITLE, 80 + pad * 2);
274     xsh.flags = (PPosition | PSize);
275     xsh.height = WIN_H;
276     xsh.width =  WIN_W;
277     xsh.x = (DisplayWidth(dpy, DefaultScreen(dpy)) - xsh.width) / 2;
278     xsh.y = (DisplayHeight(dpy, DefaultScreen(dpy)) - xsh.height) / 2;
279 
280     /*
281      * Create the Window with the information in the XSizeHints, the
282      * border width,  and the border & background pixels. See Section 3.3.
283      */
284 
285     win = XCreateSimpleWindow(dpy, DefaultRootWindow(dpy),
286 			      xsh.x, xsh.y, xsh.width, xsh.height,
287 			    /*---  bw, bd, bg); ---*/
288 			      bw, fg, bg);
289 
290     /*
291      * Set the standard properties for the window managers. See Section
292      * 9.1.
293      */
294 
295     XSetStandardProperties(dpy, win, TITLE, TITLE, None, argv,
296 			   argc, &xsh);
297     XSetWMHints(dpy, win, &SBwmh);
298 
299     /*
300      * Ensure that the window's colormap field points to the default
301      * colormap,  so that the window manager knows the correct colormap to
302      * use for the window.  See Section 3.2.9. Also,  set the window's Bit
303      * Gravity to Orchiduce Expose events.
304      */
305 
306     xswa.colormap = DefaultColormap(dpy, DefaultScreen(dpy));
307     xswa.bit_gravity = CenterGravity;
308     XChangeWindowAttributes(dpy, win, (CWColormap | CWBitGravity), &xswa);
309 
310 /*--- The following statement is added by Rama Devi ---*/
311     cmap = DefaultColormap(dpy, DefaultScreen(dpy));
312     if ((XAllocNamedColor (dpy, cmap, "Orange", &exactOrange, &Orange) != 0))
313        {
314        maingcreversed = XCreateGC(dpy, win, 0,0);
315        XSetFont(dpy, maingcreversed, curfontid);
316        XSetForeground (dpy, maingcreversed, Orange.pixel);
317        XSetBackground (dpy, maingcreversed, Black.pixel);
318        }
319     else
320        {
321        maingcreversed = XCreateGC(dpy, win, 0,0);
322        XSetFont(dpy, maingcreversed, curfontid);
323        XSetForeground (dpy, maingcreversed, fg);
324        XSetBackground (dpy, maingcreversed, bg);
325        }  /*---*/
326 
327 
328     /*
329      * Map the window to make it visible.  See Section 3.5.
330      */
331 
332      XMapWindow(dpy, win);
333 
334 
335      /*
336      * Find out how big the window is now,  so that we can center
337      * the text in it.
338      */
339 
340     if (XGetWindowAttributes(dpy, win, &xwa) == 0){
341        fprintf(stderr,"Stacked Bar Plot: Can't access attributes for graph window\n");
342        exit(1);
343     }
344 
345     XClearWindow(dpy, win);
346     XSelectInput(dpy,win, ButtonPressMask|KeyPressMask|ExposureMask);
347 
348 
349     while (looping) {
350 	    XEvent event;
351 
352 	    XNextEvent(dpy,&event);
353 
354 	    switch(event.type)
355 	    {
356 		case KeyPress:
357 		case ButtonPress: looping = 0;
358 				  break;
359 		case Expose: draw = 1;
360 	    }
361 
362 
363 	   if (!draw) continue;
364 
365            XDrawRectangle(dpy,win,maingcreversed,
366 			  RECT_X,RECT_Y,RECT_W,RECT_H);
367 
368           /*
369 	   *  Calculate the length of the grid lines.  grid_l_x and
370 	   *  grid_l_y are set to '0' if a line should not be drawn.
371            */
372 
373            if  (graphic_grid == 'H')
374            {
375              grid_l_x = RECT_W;
376              grid_l_y = 0;
377            }
378            else if (graphic_grid == 'V')
379            {
380              grid_l_x = 0;
381              grid_l_y = RECT_H;
382            }
383            else if (graphic_grid == 'B')
384            {
385              grid_l_x = RECT_W;
386              grid_l_y = RECT_H;
387            }
388            else
389            {
390              grid_l_x = 0;
391              grid_l_y = 0;
392            }
393 
394            Y_Range = max_y - min_y;
395 
396            /* The width of each bar */
397            width = (RECT_W - (PIX_SEP * (number_of_bars)))/number_of_bars;
398 
399            grid_h = RECT_H /10;
400 
401 
402 	 /* Draw the grid along with the labels on the Y-Axis */
403 
404 	   for (i=0; i<11; i++) {
405              if (i > 0 && i < 10)
406 	         XDrawLine(dpy,win,maingcreversed,
407 		       RECT_X-4, RECT_Y+i*grid_h,
408 		       RECT_X, RECT_Y+i*grid_h);
409 	     XDrawLine(dpy,win,maingcreversed,
410 		       RECT_X, RECT_Y+i*grid_h,
411 		       RECT_X+grid_l_x, RECT_Y+i*grid_h);
412 	     XDrawLine(dpy,win,maingcreversed,
413 		       RECT_X + RECT_W,RECT_Y+i*grid_h,
414 		       RECT_X+RECT_W - grid_l_x, RECT_Y+i*grid_h);
415 
416              sprintf(str,"%.1f",(max_y - Y_Range*i/10));
417              len = strlen(str);
418              text_w = XTextWidth(curfont,str,len+2);
419              XDrawImageString(dpy,win,maingcreversed,
420                        RECT_X - text_w,
421                        RECT_Y + i*grid_h + curfontheight/3,
422                        str,len);
423 
424 	   } /*end for loop*/
425 
426 	   for (i=1; i < number_of_bars; i++) {
427              x = RECT_X + (PIX_SEP * i) + (width * i);
428 	     XDrawLine(dpy,win,maingcreversed,
429 		       x, RECT_Y, x, RECT_Y+grid_l_y);
430 	     XDrawLine(dpy,win,maingcreversed,
431 		       x, RECT_Y+RECT_H, x, RECT_Y+RECT_H-grid_l_y);
432 	   } /*end for loop*/
433 
434           /*
435            *
436            * Draw titles at top of graph
437            *
438            */
439 
440 	   len = strlen(graphic_title[0]);
441 	   text_w = XTextWidth(curfont, graphic_title[0], len);
442 	   XDrawImageString(dpy,win,maingcreversed,
443 			    (WIN_W - text_w)/2, RECT_Y/3,
444 			    graphic_title[0], len);
445 
446 
447 	   len = strlen(graphic_title[1]);
448 	   text_w = XTextWidth(curfont, graphic_title[1],len);
449 	   XDrawImageString(dpy,win,maingcreversed,
450 			   (WIN_W - text_w)/2, RECT_Y*2/3,
451 			   graphic_title[1],len);
452 
453 	   len = strlen(graphic_title[2]);
454 	   text_w=XTextWidth(curfont,graphic_title[2],len);
455 	   XDrawImageString(dpy,win,maingcreversed,
456 			    (WIN_W-text_w)/2, RECT_H+RECT_Y*3/2,
457 			    graphic_title[2],len);
458 
459 	   len = strlen(graphic_title[3]);
460 	   text_w=XTextWidth(curfont,graphic_title[3],len);
461            if ((RECT_X-text_w) < 0)
462                x = curfontwidth;
463            else
464                x = RECT_X-text_w;
465 	   XDrawImageString(dpy,win,maingcreversed,
466 			    x, RECT_Y - curfontheight,
467 			    graphic_title[3],len);
468 
469   /* --------------------------------------------------------------------*/
470   /* This next section will read values of the x and y center points     */
471   /* and find the maximum and minimum values for each, then set the      */
472   /* width and height paramters, convert x and y so that the origin      */
473   /* is at the lower left corner of the window, and then finally         */
474   /* draw and fill the bars.                                             */
475   /* ------------------------------------------------------------------- */
476 
477 /*
478  *  Draw Labels on the X-Axis
479  */
480 
481            labelsize = irint(floor(width/(double)curfontwidth)-1);
482 	   y = RECT_Y + RECT_H + curfontheight;
483 	   bars = 0;
484 	   for (i=graphic_range[0].r1;i<=graphic_range[0].r2; i++)
485 	   {
486 	      p = lookat(i,graphic_range[0].c);
487 	      if (!(p->label)) continue;
488               strncpy(str, p->label, labelsize);
489               str[labelsize] = '\0';
490 	      x = RECT_X+(PIX_SEP*bars)+(width*bars)+(width/2);
491               x = x - (curfontwidth*strlen(str))/2;
492 	      bars++;
493 	      XDrawImageString(dpy,win,maingcreversed,
494 		   	       x,y,
495 			       str,strlen(str));
496 	   }
497 
498         bars = 0;
499         for (i=graphic_range[0].r1; i<=graphic_range[0].r2; i++)
500         {
501      p=lookat(i,graphic_range[0].c); /*---added by Rama Devi --------*/
502      if(!(p->label)) continue;       /*---added by Rama Devi --------*/
503            bars++;
504            Y_Position[bars] = 0;
505         }
506 
507 
508         for (i = 1; i < GRAPHRANGES; i++){
509             if (*(graphic_range[i].col) == '\0') continue;
510 
511             bars = 0;
512 
513        /*----------the following lines are commented by Rama Devi --------
514         --------  for(j=graphic_range[0].r1, k=graphic_range[i].r1;
515                (j<=graphic_range[0].r2) && (k<=graphic_range[i].r2); j++, k++){
516 
517               if (!((p=lookat(j,graphic_range[0].c))->label)) continue; ----*/
518 
519 
520        /*------The following lines added by Rama Devi ------------------*/
521        for (j = graphic_range[0].r1; j <= graphic_range[0].r2; j++)
522             {
523 
524      p=lookat(j,graphic_range[0].c);
525      if(!(p->label)) continue;
526 
527       /*----------------------------------------------------------------*/
528 	      x = RECT_X + ((PIX_SEP)*(bars)) + (width*bars);
529 	      bars++;
530 
531 
532           /*-------the following lines commented by Rama Devi --------------
533           -----if (!((val=lookat(j,graphic_range[i].c))->flags & is_valid)
534               || (val->v < min_y) || (val->v > max_y)) continue; ---------*/
535 
536           /*-------The following lines added by Rama Devi ---------------*/
537 
538            if ((j >= graphic_range[i].r1) && (j <= graphic_range[i].r2))
539 
540                {
541                val = lookat(j, graphic_range[i].c);
542 	        if (val->flags & is_valid) {
543 
544           /*-----------------------------------------------------------*/
545               /*
546 	       *  Calculate the height of the bar.  If it is the 'lowest'
547 	       *  piece of the bar, subtract off the value of the min_y
548 	       *  for an accurate height.
549                */
550 
551               if (i == 1)
552 	         height = irint((val->v - min_y) / Y_Range * RECT_H);
553               else
554 	         height = irint(val->v / Y_Range * RECT_H);
555 
556 	      y = RECT_Y + RECT_H - height - Y_Position[bars];
557 
558               Y_Position[bars] = Y_Position[bars] + height;
559 
560               /* clear the area before drawing the bar */
561               if (graphic_grid != 'C')
562                  XClearArea(dpy,win,x,y,width,height,False);
563 
564               /* choose a pattern to be used */
565               switch (i) {
566         case 1 : Pattern = XCreateBitmapFromData(dpy,win,dark_wide_weave_bits,
567                      dark_wide_weave_width, dark_wide_weave_height);
568 
569 
570     /*---- The following two statements added by Rama Devi ----*/
571     cmap = DefaultColormap(dpy, DefaultScreen(dpy));
572     if ((XAllocNamedColor (dpy, cmap, "Green", &exactGreen, &Green) != 0))
573        {
574        XSetForeground (dpy, maingcreversed, Green.pixel);
575        XSetBackground (dpy, maingcreversed, Black.pixel);
576        }
577     else
578        {
579        XSetForeground (dpy, maingcreversed, fg);
580        XSetBackground (dpy, maingcreversed, bg);
581        }
582                              break;
583 
584         case 2: Pattern = XCreateBitmapFromData(dpy,win,dark_root_weave_bits,
585                      dark_root_weave_width, dark_root_weave_height);
586 
587     /*---- The following two statements added by Rama Devi ----*/
588     cmap = DefaultColormap(dpy, DefaultScreen(dpy));
589     if ((XAllocNamedColor (dpy, cmap, "Orchid", &exactOrchid, &Orchid) != 0))
590        {
591        XSetForeground (dpy, maingcreversed, Orchid.pixel);
592        XSetBackground (dpy, maingcreversed, Black.pixel);
593        }
594     else
595        {
596        XSetForeground (dpy, maingcreversed, fg);
597        XSetBackground (dpy, maingcreversed, bg);
598        }
599                              break;
600 
601         case 3: Pattern = XCreateBitmapFromData(dpy,win,dark_cross_weave_bits,
602                      dark_cross_weave_width, dark_cross_weave_height);
603 
604     /*---- The following two statements added by Rama Devi ----*/
605     cmap = DefaultColormap(dpy, DefaultScreen(dpy));
606     if ((XAllocNamedColor (dpy, cmap, "GreenYellow", &exactGreenYellow, &GreenYellow) != 0))
607        {
608        XSetForeground (dpy, maingcreversed, GreenYellow.pixel);
609        XSetBackground (dpy, maingcreversed, Black.pixel);
610        }
611     else
612        {
613        XSetForeground (dpy, maingcreversed, fg);
614        XSetBackground (dpy, maingcreversed, bg);
615        }
616 
617                              break;
618 
619         case 4: Pattern = XCreateBitmapFromData(dpy,win,light_wide_weave_bits,
620                      light_wide_weave_width, light_wide_weave_height);
621 
622     /*---- The following two statements added by Rama Devi ----*/
623     cmap = DefaultColormap(dpy, DefaultScreen(dpy));
624     if ((XAllocNamedColor (dpy, cmap, "Goldenrod", &exactGoldenrod, &Goldenrod) != 0))
625        {
626        XSetForeground (dpy, maingcreversed, Goldenrod.pixel);
627        XSetBackground (dpy, maingcreversed, Black.pixel);
628        }
629     else
630        {
631        XSetForeground (dpy, maingcreversed, fg);
632        XSetBackground (dpy, maingcreversed, bg);
633        }
634                              break;
635 
636 
637         case 5 : Pattern = XCreateBitmapFromData(dpy,win,light_root_weave_bits,
638                      light_root_weave_width, light_root_weave_height);
639 
640     /*---- The following two statements added by Rama Devi ----*/
641     cmap = DefaultColormap(dpy, DefaultScreen(dpy));
642     if ((XAllocNamedColor (dpy, cmap, "Aquamarine", &exactAquamarine, &Aquamarine) != 0))
643        {
644        XSetForeground (dpy, maingcreversed, Aquamarine.pixel);
645        XSetBackground (dpy, maingcreversed, Black.pixel);
646        }
647     else
648        {
649        XSetForeground (dpy, maingcreversed, fg);
650        XSetBackground (dpy, maingcreversed, bg);
651        }
652                              break;
653 
654         case 6: Pattern = XCreateBitmapFromData(dpy,win,light_cross_weave_bits,
655                      light_cross_weave_width, light_cross_weave_height);
656 
657     /*---- The following two statements added by Rama Devi ----*/
658     cmap = DefaultColormap(dpy, DefaultScreen(dpy));
659     if ((XAllocNamedColor (dpy, cmap, "Yellow", &exactYellow, &Yellow)
660 != 0))
661        {
662        XSetForeground (dpy, maingcreversed, Yellow.pixel);
663        XSetBackground (dpy, maingcreversed, Black.pixel);
664        }
665     else
666        {
667        XSetForeground (dpy, maingcreversed, fg);
668        XSetBackground (dpy, maingcreversed, bg);
669        }
670                              break;
671 
672                                  }
673               /* Display a filled portion of the bar */
674               XSetStipple(dpy, maingcreversed, Pattern);
675               XSetFillStyle(dpy, maingcreversed, FillStippled);
676 	      XFillRectangle(dpy,win,maingcreversed,x,y,width,height);
677 
678 	      /* Draw a solid outline around the bar */
679               XSetFillStyle(dpy, maingcreversed, FillSolid);
680 	      XDrawRectangle(dpy,win,maingcreversed,x,y,width,height);
681                      }  /*---*/
682             } /*----*/
683         }
684      }
685 
686     /*---- The following two statements added by Rama Devi ----*/
687     cmap = DefaultColormap(dpy, DefaultScreen(dpy));
688     if ((XAllocNamedColor (dpy, cmap, "Orange", &exactOrange, &Orange) != 0))
689        {
690        XSetForeground (dpy, maingcreversed, Orange.pixel);
691        XSetBackground (dpy, maingcreversed, Black.pixel);
692        }
693     else
694        {
695        XSetForeground (dpy, maingcreversed, fg);
696        XSetBackground (dpy, maingcreversed, bg);
697        }
698 
699    }
700 
701 cmap = DefaultColormap (dpy, DefaultScreen (dpy));
702 if (backg && (XAllocNamedColor (dpy, cmap, backg, &exactOrange, &Orange) != 0))
703     {
704     bg = Orange.pixel;
705     }
706    else
707     {
708     bg = WhitePixel(dpy, DefaultScreen(dpy)); /* background */
709     }
710 if (foreg && (XAllocNamedColor (dpy, cmap, foreg, &exactBlack, &Black) != 0))
711     {
712     fg = Black.pixel;
713     }
714    else
715     {
716     fg = BlackPixel(dpy, DefaultScreen(dpy)); /* foreground */
717     }
718 
719       XSetForeground (dpy, maingc, fg);
720       XSetBackground (dpy, maingc, bg);
721       XSetForeground (dpy, maingcreversed, bg);
722       XSetBackground (dpy, maingcreversed, fg);
723 
724 XSetForeground(dpy, invertgc, fg);
725 
726    XUnmapWindow(dpy, win);
727    XDestroyWindow(dpy, win);
728 
729 }
730 #endif /* HAVE_X11_X_H	this code for now is X specific */
731