File: RgbSrc.c

package info (click to toggle)
xcolorsel 1.1a-21
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 712 kB
  • sloc: ansic: 5,732; makefile: 78; sh: 9
file content (233 lines) | stat: -rw-r--r-- 9,850 bytes parent folder | download | duplicates (9)
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
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
/*********************************************************************************/
/* This file is  part of Xcolorsel, a multipurpose viewer for X11 rgb.txt files. */
/*                     Copyright (C) 1993, 1994 Michael Weller                   */
/*                                                                               */
/* This program is free software; you can redistribute it and/or modify it under */
/* the terms of the GNU General Public License as published be the Free Software */
/* Foundation;  either version 2 of the License,  or (at your opinion) 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  MERCHANBILITY 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 along with */
/* this program; if not,  write to the  Free Software Foundation, Inc., 675 Mass */
/* Ave, Cambridge, MA 02139, USA.                                                */
/*                                                                               */
/* The author can be  reached by means of email  as eowmob@exp-math.uni-essen.de */
/* or  eowmob@pollux.exp-math.uni-essen.de   or   mat42b@vm.hrz.uni-essen.de  or */
/* mat42b@de0hrz1a.bitnet.  Or as:  Michael Weller,  Heiderhoefen 116b,  D 46049 */
/* Oberhausen, Germany.                                                          */
/*                                                                               */
/* Part of the files are derived  from the Template Widget of the Athena Widgets */
/* as published  by the  Massachusetts Institute of  Technology.  Actually these */
/* files do not contain any code  by the M.I.T  but only  variable declarations. */
/* Nevertheless these parts of these files are still distributed under the terms */
/* of the M.I.T copyright which are here repeated:                               */
/*                                                                               */
/* Copyright    Massachusetts Institute of Technology   1987, 1988               */
/*                                                                               */
/* Permission to use, copy,  modify, distribute,  and sell this software and its */
/* documentation for  any purpose is hereby  granted without fee,  provided that */
/* the  above  copyright  notice  appear  in  all  copies  and  that  both  that */
/* copyright   notice   and   this  permission   notice  appear  in   supporting */
/* documentation,  and that the  name of M.I.T.  not  be used  in advertising or */
/* publicity  pertaining  to distribution  of  the  software  without  specific, */
/* written  prior  permission.    M.I.T.  makes  no  representations  about  the */
/* suitability  of  this  software  for  any  purpose.   It is provided  "as is" */
/* without express or implied warranty.                                          */
/*                                                                               */
/* M.I.T. DISCLAIMS ALL  WARRANTIES WITH REGARD  TO THIS SOFTWARE, INCLUDING ALL */
/* IMPLIED WARRANTIES  OF MERCHANTABILITY AND FITNESS,  IN NO EVENT SHALL M.I.T. */
/* BE LIABLE FOR ANY SPECIAL,  INDIRECT OR CONSEQUENTIAL  DAMAGES OR ANY DAMAGES */
/* WHATSOEVER RESULTING FROM LOSS OF USE,  DATA OR PROFITS, WHETHER IN AN ACTION */
/* OF CONTRACT,  NEGLIGENCE  OR  OTHER  TORTIOUS  ACTION,  ARISING OUT OF  OR IN */
/* CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.                      */
/*********************************************************************************/

/******************************************************************************************
* This defines an RgbSrc Object. This is a subclass of an AsciiSrc. It is designed to     *
* to be used by an RgbText Object. The only difference to an AsciiSrc is a special scan   *
* function.                                                                               *
******************************************************************************************/

/* This was inspirated from: */


/* $XConsortium: Template.c,v 1.4 91/02/17 16:18:42 converse Exp $ */

/* Copyright	Massachusetts Institute of Technology	1987, 1988
 *
 * Permission to use, copy, modify, distribute, and sell this software and its
 * documentation for any purpose is hereby granted without fee, provided that
 * the above copyright notice appear in all copies and that both that
 * copyright notice and this permission notice appear in supporting
 * documentation, and that the name of M.I.T. not be used in advertising or
 * publicity pertaining to distribution of the software without specific,
 * written prior permission.  M.I.T. makes no representations about the
 * suitability of this software for any purpose.  It is provided "as is"
 * without express or implied warranty.
 *
 * M.I.T. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL M.I.T.
 * BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
 * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 *
 */

#include <X11/IntrinsicP.h>
#include <X11/StringDefs.h>
#include <X11/Xaw3d/XawInit.h>
#include "RgbSrcP.h"

/* workaround for Xaw 7.x */
#if (defined(XawVersion) && (XawVersion <= 7000002L))
typedef XawTextPosition (*_XawTextPositionFunc)();
#endif

/* No resources */

/* No actions */

/* Both are in RgbText! */

/* No actions no translations */

static void initialize(Widget request, Widget new, ArgList args, Cardinal *numargs);
static XawTextPosition myscan(Widget w, XawTextPosition position, XawTextScanType type,
		XawTextScanDirection dir, int count, Boolean include);

RgbSrcClassRec rgbSrcClassRec = {
  { /* object fields */
    /* ======        */ 
    /* superclass		*/	(WidgetClass) &asciiSrcClassRec,
    /* class_name		*/	"RgbSrc",
    /* widget_size		*/	sizeof(RgbSrcRec),
    /* class_initialize		*/	NULL,
    /* class_part_initialize	*/	NULL,
    /* class_inited		*/	FALSE,
    /* initialize		*/	initialize,
    /* initialize_hook		*/	NULL,
    /* realize			*/	NULL,
    /* actions			*/	NULL,
    /* num_actions		*/	0,
    /* resources		*/	NULL,
    /* num_resources		*/	0,
    /* xrm_class		*/	NULLQUARK,
    /* compress_motion		*/	0,
    /* compress_exposure	*/	0,
    /* compress_enterleave	*/	0,
    /* visible_interest		*/	0,
    /* destroy			*/	NULL,
    /* resize			*/	NULL,
    /* expose			*/	NULL,
    /* set_values		*/	NULL,
    /* set_values_hook		*/	NULL,
    /* set_values_almost	*/	NULL,
    /* get_values_hook		*/	NULL,
    /* accept_focus		*/	NULL,
    /* version			*/	XtVersion,
    /* callback_private		*/	NULL,
    /* tm_table			*/	NULL,
    /* query_geometry		*/	NULL,
    /* display_accelerator	*/	NULL,
    /* extension		*/	NULL
  },
  { /* text_src fields */
    /* Read			*/	XtInheritRead,
    /* Replace			*/	XtInheritReplace,
    /* Scan			*/	(_XawTextPositionFunc)myscan,
    /* Search			*/	XtInheritSearch,
    /* SetSelection		*/	XtInheritSetSelection,
    /* ConvertSelection		*/	XtInheritConvertSelection,
  },
  { /* ascii_src fields */
    /* empty			*/	0
  },
  { /* rgb_src fields */
    /* empty			*/	0
  }
};

WidgetClass rgbSrcObjectClass = (WidgetClass)&rgbSrcClassRec;

#define rgbparent(widget)	(*(RgbTextRec *)XtParent(widget))
#define myself(widget)		(*(RgbSrcRec *)(widget))

static void initialize(Widget request, Widget new, ArgList args, Cardinal *numargs)
{
XtCheckSubclass(XtParent(new),rgbTextWidgetClass,
"rgbSrc: Didn't I say that my parent has to be a subclass of RgbText?\n");
}

static XawTextPosition myscan(Widget w, XawTextPosition position, XawTextScanType type,
		XawTextScanDirection dir, int count, Boolean include)
{
char *ptr,*start,*end;
XawTextPosition offset;
if(type!=XawstWhiteSpace)
	return (*(((AsciiSrcClassRec *)(rgbSrcClassRec.object_class.superclass))->text_src_class.Scan))
		(w, position, type, dir, count, include); 
start=rgbparent(w).rgb_text.asciirep;
while(count--)
	{
	/* find position in line: */
	ptr=start+position;
	while(ptr>start)
		{
		if(*(ptr-1)=='\n')break;
		ptr--;
		}
	offset=position-(ptr-start);
	if(dir==XawsdLeft)
		{
		if(offset<rgbparent(w).rgb_text.startofrgb)
			position=0;
		else if(offset<=rgbparent(w).rgb_text.endofrgb)
			{
			position=rgbparent(w).rgb_text.startofrgb;
			if(include==True)
				position=0;
			}
		else if(offset<=rgbparent(w).rgb_text.endofrgb+3)
			{
			position=rgbparent(w).rgb_text.endofrgb;
			position=0;
			}
		else 	{
			position=rgbparent(w).rgb_text.endofrgb+3;
			if(include==True)
				position=rgbparent(w).rgb_text.endofrgb;
			}
		}
	else	{
		end=strchr(ptr,'\n');
		if(!end)end=strchr(ptr,0);
		if(offset>=rgbparent(w).rgb_text.endofrgb+3)
			{
			position=(end-ptr);
			if(include==True)
				position++;
			}
		else if(offset>=rgbparent(w).rgb_text.endofrgb)
			{
			position=rgbparent(w).rgb_text.endofrgb+3;
			position=0;
			}
		else if(offset>=rgbparent(w).rgb_text.startofrgb)
			{
			position=rgbparent(w).rgb_text.endofrgb;
			if(include==True)
				position=rgbparent(w).rgb_text.endofrgb+3;
			}
		else	position=0;
		}
	position=((ptr+position)-start);
	}
/*printf("%lu\n",(unsigned long)position);*/
return position;
}