File: color.c

package info (click to toggle)
xspread 3.1.1c-9
  • links: PTS
  • area: main
  • in suites: potato
  • size: 1,836 kB
  • ctags: 1,426
  • sloc: ansic: 19,342; yacc: 499; lisp: 231; makefile: 198; sh: 28; sed: 4
file content (198 lines) | stat: -rw-r--r-- 5,379 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
/*
 * Copyright (C) 1992  Board of Regents of the University of Wisconsin
 * on behalf of the Department of Electrical Engineering and Computer
 * Science, University of Wisconsin-Milwaukee, Milwaukee, WI 53201.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * a copy of which is included here in file "GNU_GENERAL"
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 *
 * The programs in this directory were developed by software engineering
 * teams as part of the course "Introduction to Software Engineering"
 * under the supervision of Professor G. Davida.
 * This is a modification of a program written or modified by
 * others.  The original copyrights, as per GNU General Public License,
 * may still be applicable.  The UWM copyright is applicable only
 * the those parts generated at UWM.
 *
 * Please send all changes, enhancements, and other comments about this
 * software to
 *              soft-eng@cs.uwm.edu
 *
 * No Warranty, expressed or implied, comes with this software.
 * This software is intended to be used by not-for-profit
 * organizations or by individuals for personal HOME use.
 * This software, or any of its parts, may not be used by for-profit
 * organization, regardless of application or intended product or
 * customer, without the permission of the Board of Regents of the
 * University  of Wisconsin.
 *
 * Contact:     soft-eng@cs.uwm.edu
 *                      or
 *
 *              Software Engineering Coordinator
 *              Computer Science
 *              Department of EECS
 *              University of Wisconsin - Milwaukee
 *              Milwaukee, WI  53201
 *              414-229-4677
 *
 *              HISTORY,CLAIMS and CONTRIBUTIONS
 */

/*--------------author RAMA DEVI PUVVADA ------------------------------------*/
#include <config.h>

#ifdef HAVE_X11_X_H	/* this code for now is X specific */

#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include "scXstuff.h"

#include "sc.h"

#define CLIM 3
#define RLIM 4

int copyc = 0;
char **copyv = 0;
unsigned long bg, fg;
Colormap cmap;
XColor exactBG, BG, exactFG, FG;
char foreg[30];
char backg[30];

static void	set_back PROTO((void));
static void	set_fore PROTO((void));

void
Color_Menu()
{
static char *mainmenu[] = {
                          "Foreground",
                          "Background"
                          };

static char *help[] = {
                       "Set the Foreground color",
                       "Set the Background color"
                      };
/* auto. */  unsigned int  choice=0;

    do{ /* do until ESC is selected */
      choice = menu(2, mainmenu, help);
      switch(choice) {
                case 1: set_fore();
                        break;
                case 2: set_back();
                        break;
                     }
       } while (choice != 0);  

XUnmapWindow(dpy, mainwin);
XCloseDisplay(dpy);

sc_Xinit(copyc, copyv);
update(TRUE);
}

/*--------*/

static void
set_fore()
{
char tempforeg[30];
XColor exacttempforeg, TempForeg;

sprintf(tempforeg, "Foreground: ");
get_str(tempforeg, 30);

cmap = DefaultColormap (dpy, DefaultScreen (dpy));
if (tempforeg && (XAllocNamedColor (dpy, cmap, tempforeg, &exacttempforeg, &TempForeg)) != 0)
   {
   strcpy(foreg, tempforeg);
   }

if (foreg && (XAllocNamedColor (dpy, cmap, foreg, &exactFG, &FG) != 0))
    {
    fg = FG.pixel;
    }
   else
    {
    fg = BlackPixel(dpy, DefaultScreen(dpy)); /* foreground */
    }
if (backg && (XAllocNamedColor (dpy, cmap, backg, &exactBG, &BG) != 0))
    {
    bg = BG.pixel;
    }
   else
    {
    bg = WhitePixel(dpy, DefaultScreen(dpy)); /* background */
    }

  XSetForeground(dpy, maingc, fg);
  XSetBackground(dpy, maingc, bg);
  XSetForeground(dpy, maingcreversed, bg);
  XSetBackground(dpy, maingcreversed, fg);

FullUpdate++;
modflg++;

}
/*--------*/

static void
set_back()
{
char tempbackg[30];
XColor exacttempbackg, TempBackg;

sprintf(tempbackg, "Background: ");
get_str(tempbackg, 30);

cmap = DefaultColormap (dpy, DefaultScreen (dpy));
if (tempbackg && (XAllocNamedColor (dpy, cmap, tempbackg, &exacttempbackg, &TempBackg)) != 0)
   {
   strcpy(backg, tempbackg);
   }

if (foreg && (XAllocNamedColor (dpy, cmap, foreg, &exactFG, &FG) != 0))
    {
    fg = FG.pixel;
    }
   else
    {
    fg = BlackPixel(dpy, DefaultScreen(dpy)); /* foreground */
    }
if (backg && (XAllocNamedColor (dpy, cmap, backg, &exactBG, &BG) != 0))
    {
    bg = BG.pixel;
    }
   else
    {
    bg = WhitePixel(dpy, DefaultScreen(dpy)); /* background */
    }

  XSetForeground(dpy, maingc, fg);
  XSetBackground(dpy, maingc, bg);
  XSetForeground(dpy, maingcreversed, bg);
  XSetBackground(dpy, maingcreversed, fg);

FullUpdate++;
modflg++;
}

/*------*/

#endif /* HAVE_X11_X_H	this code for now is X specific */