|
NCBI Home IEB Home C Toolkit docs C++ Toolkit source browser C Toolkit source browser (2) |
NCBI C Toolkit Cross ReferenceC/vibrant/palette.c |
source navigation diff markup identifier search freetext search file search |
1 /* palette.c
2 * ===========================================================================
3 *
4 * PUBLIC DOMAIN NOTICE
5 * National Center for Biotechnology Information (NCBI)
6 *
7 * This software/database is a "United States Government Work" under the
8 * terms of the United States Copyright Act. It was written as part of
9 * the author's official duties as a United States Government employee and
10 * thus cannot be copyrighted. This software/database is freely available
11 * to the public for use. The National Library of Medicine and the U.S.
12 * Government do not place any restriction on its use or reproduction.
13 * We would, however, appreciate having the NCBI and the author cited in
14 * any work or product based on this material
15 *
16 * Although all reasonable efforts have been taken to ensure the accuracy
17 * and reliability of the software and data, the NLM and the U.S.
18 * Government do not and cannot warrant the performance or results that
19 * may be obtained by using this software or data. The NLM and the U.S.
20 * Government disclaim all warranties, express or implied, including
21 * warranties of performance, merchantability or fitness for any particular
22 * purpose.
23 *
24 * ===========================================================================
25 *
26 * File Name: palette.c
27 *
28 * Author: Jonathan Kans
29 *
30 * Version Creation Date: 1/1/91
31 *
32 * $Revision: 6.1 $
33 *
34 * File Description: Active graphics objects
35 *
36 * Modifications:
37 * --------------------------------------------------------------------------
38 * Date Name Description of modification
39 * ------- ---------- -----------------------------------------------------
40 *
41 *
42 * $Log: palette.c,v $
43 * Revision 6.1 2003/11/07 16:02:30 rsmith
44 * Renamed static function NewPalette to Nlm_NewPalette to avoid a name conflict on Mac.
45 *
46 * Revision 6.0 1997/08/25 18:56:11 madden
47 * Revision changed to 6.0
48 *
49 * Revision 5.0 1996/05/28 13:45:08 ostell
50 * Set to revision 5.0
51 *
52 * Revision 4.0 1995/07/26 13:51:04 ostell
53 * force revision to 4.0
54 *
55 * Revision 2.3 1995/05/17 15:15:14 kans
56 * added Log line
57 *
58 *
59 * ==========================================================================
60 */
61
62 #include "panels.h"
63
64 typedef struct paletteData {
65 Int2 drawCount;
66 Handle drawHandles;
67 Int2 leftMargin;
68 Int2 rightMargin;
69 Int2 width;
70 PaletteProc action;
71 } PaletteData;
72
73 typedef struct drawRec {
74 PaintProc draw;
75 PaletteProc click;
76 RecT rect;
77 Int2 value;
78 } DrawRec, PNTR DrawPtr;
79
80 static void DrawPalette (PaneL p)
81
82 {
83 DrawPtr dptr;
84 PaintProc drw;
85 Handle hdld;
86 Int2 i;
87 Int2 numd;
88 Int2 off;
89 PaletteData pdata;
90 RecT r;
91 SlatE s;
92 RecT sr;
93
94 s = (SlatE) Parent (p);
95 GetPanelExtra (p, &pdata);
96 numd = pdata.drawCount;
97 hdld = pdata.drawHandles;
98 ObjectRect (s, &sr);
99 InsetRect (&sr, 4, 4);
100 GetOffset (p, NULL, &off);
101 if (hdld != NULL) {
102 dptr = (DrawPtr) HandLock (hdld);
103 i = 0;
104 while (i < numd) {
105 drw = dptr [i].draw;
106 if (drw != NULL) {
107 r = dptr [i].rect;
108 OffsetRect (&r, 0, -off);
109 if (RectInRect (&r, &sr) &&
110 (updateRgn == NULL || RectInRgn (&r, updateRgn))) {
111 drw ((PalettE) p, i + 1, &r);
112 }
113 }
114 i++;
115 }
116 HandUnlock (hdld);
117 }
118 }
119
120 extern void AppendPalette (PalettE p, RectPtr rct,
121 PaintProc draw, PaletteProc click,
122 Int2 value)
123
124 {
125 Int2 chunk;
126 DrawPtr dptr;
127 RecT dr;
128 Handle hdld;
129 Int2 numd;
130 Int2 off;
131 PaletteData pdata;
132 RecT r;
133 SlatE s;
134 RecT sr;
135 WindoW tempPort;
136
137 if (p != NULL && rct != NULL) {
138 tempPort = SavePort (p);
139 s = (SlatE) Parent (p);
140 GetPanelExtra ((PaneL) p, &pdata);
141 numd = pdata.drawCount;
142 hdld = pdata.drawHandles;
143 chunk = 128;
144 if (hdld != NULL) {
145 if (numd % chunk == 0) {
146 hdld = HandMore (hdld, sizeof (DrawRec) *
147 (numd / chunk + 1) * chunk);
148 }
149 } else {
150 hdld = HandNew (sizeof (DrawRec) * chunk);
151 }
152 numd++;
153 pdata.drawHandles = hdld;
154 pdata.drawCount = numd;
155 SetPanelExtra ((PaneL) p, &pdata);
156 dptr = (DrawPtr) HandLock (hdld);
157 dptr [numd - 1].draw = draw;
158 dptr [numd - 1].click = click;
159 dptr [numd - 1].rect = *rct;
160 dptr [numd - 1].value = value;
161 HandUnlock (hdld);
162 r = *rct;
163 RegisterRect ((PaneL) p, &r);
164 if (draw != NULL && Enabled (p) && AllParentsEnabled (p) &&
165 Visible (p) && AllParentsVisible (p)) {
166 ObjectRect (s, &sr);
167 InsetRect (&sr, 4, 4);
168 GetOffset (p, NULL, &off);
169 OffsetRect (&r, 0, -off);
170 SectRect (&r, &sr, &dr);
171 if (RectInRect (&dr, &sr)) {
172 Select (p);
173 InvalRect (&dr);
174 }
175 }
176 RestorePort (tempPort);
177 }
178 }
179
180 extern void SetPaletteValue (PalettE p, Int2 num, Int2 value)
181
182 {
183 DrawPtr dptr;
184 Handle hdld;
185 Int2 numd;
186 Int2 off;
187 PaletteData pdata;
188 RecT r;
189 SlatE s;
190 RecT sr;
191 WindoW tempPort;
192
193 if (p != NULL && num > 0) {
194 tempPort = SavePort (p);
195 num--;
196 s = (SlatE) Parent (p);
197 GetPanelExtra ((PaneL) p, &pdata);
198 ObjectRect (s, &sr);
199 InsetRect (&sr, 4, 4);
200 GetOffset (p, NULL, &off);
201 numd = pdata.drawCount;
202 hdld = pdata.drawHandles;
203 if (hdld != NULL && num < numd) {
204 dptr = (DrawPtr) HandLock (hdld);
205 if (dptr [num].value != value) {
206 dptr [num].value = value;
207 r = dptr [num].rect;
208 OffsetRect (&r, 0, -off);
209 if (dptr [num].draw != NULL && Enabled (p) && AllParentsEnabled (p) &&
210 Visible (p) && AllParentsVisible (p) &&
211 RectInRect (&r, &sr)) {
212 Select (p);
213 InvalRect (&r);
214 }
215 }
216 HandUnlock (hdld);
217 }
218 RestorePort (tempPort);
219 }
220 }
221
222 extern Int2 GetPaletteValue (PalettE p, Int2 num)
223
224 {
225 DrawPtr dptr;
226 Handle hdld;
227 Int2 numd;
228 PaletteData pdata;
229 Int2 rsult;
230
231 rsult = 0;
232 if (p != NULL && num > 0) {
233 num--;
234 GetPanelExtra ((PaneL) p, &pdata);
235 numd = pdata.drawCount;
236 hdld = pdata.drawHandles;
237 if (hdld != NULL && num < numd) {
238 dptr = (DrawPtr) HandLock (hdld);
239 rsult = dptr [num].value;
240 HandUnlock (hdld);
241 }
242 }
243 return rsult;
244 }
245
246 extern Int2 PaletteNumItems (PalettE p)
247
248 {
249 PaletteData pdata;
250 Int2 rsult;
251
252 rsult = 0;
253 if (p != NULL) {
254 GetPanelExtra ((PaneL) p, &pdata);
255 rsult = pdata.drawCount;
256 }
257 return rsult;
258 }
259
260 static void PaletteClick (PaneL p, PoinT pt)
261
262 {
263 PaletteProc actn;
264 DrawPtr dptr;
265 Boolean goOn;
266 Handle hdld;
267 Int2 i;
268 Int2 numd;
269 Int2 off;
270 PaletteData pdata;
271 RecT r;
272 SlatE s;
273 RecT sr;
274
275 if (p != NULL) {
276 actn = NULL;
277 s = (SlatE) Parent (p);
278 GetPanelExtra (p, &pdata);
279 ObjectRect (s, &sr);
280 InsetRect (&sr, 4, 4);
281 GetOffset (p, NULL, &off);
282 numd = pdata.drawCount;
283 hdld = pdata.drawHandles;
284 if (hdld != NULL) {
285 dptr = (DrawPtr) HandLock (hdld);
286 i = 0;
287 goOn = TRUE;
288 while (i < numd && goOn) {
289 actn = dptr [i].click;
290 r = dptr [i].rect;
291 OffsetRect (&r, 0, -off);
292 if (dptr [i].draw != NULL) {
293 if (RectInRect (&r, &sr) && PtInRect (pt, &r)) {
294 goOn = FALSE;
295 } else {
296 i++;
297 }
298 } else {
299 if (PtInRect (pt, &r) && PtInRect (pt, &sr)) {
300 goOn = FALSE;
301 } else {
302 i++;
303 }
304 }
305 }
306 HandUnlock (hdld);
307 if (i < numd) {
308 if (actn != NULL) {
309 actn ((PalettE) p, i + 1);
310 }
311 actn = pdata.action;
312 if (actn != NULL) {
313 actn ((PalettE) p, i + 1);
314 }
315 }
316 }
317 }
318 }
319
320 static void Nlm_NewPalette (PalettE p, Int2 minwid, PaletteProc actn)
321
322 {
323 PoinT npt;
324 PaletteData pdata;
325 RecT r;
326 SlatE s;
327
328 SelectFont (systemFont);
329 s = (SlatE) Parent (p);
330 ObjectRect (s, &r);
331 InsetRect (&r, 4, 4);
332 GetNextPosition (p, &npt);
333 pdata.drawCount = 0;
334 pdata.drawHandles = NULL;
335 pdata.leftMargin = npt.x;
336 pdata.rightMargin = npt.x + minwid;
337 pdata.width = pdata.rightMargin - pdata.leftMargin;
338 pdata.action = actn;
339 SetPanelExtra ((PaneL) p, &pdata);
340 LoadRect (&r, npt.x, npt.y, pdata.rightMargin, npt.y);
341 RegisterRect ((PaneL) p, &r);
342 Break (p);
343 }
344
345 static void ResetPalette (PaneL p)
346
347 {
348 PaletteData pdata;
349
350 GetPanelExtra (p, &pdata);
351 if (pdata.drawHandles != NULL) {
352 HandFree (pdata.drawHandles);
353 }
354 Nlm_NewPalette ((PalettE) p, pdata.width, pdata.action);
355 }
356
357 extern PalettE PalettePanel (SlatE s, Int2 pixwidth, PaletteProc actn)
358
359 {
360 PalettE p;
361 WindoW tempPort;
362
363 p = NULL;
364 if (s != NULL) {
365 tempPort = SavePort (s);
366 p = (PalettE) CustomPanel (s, DrawPalette, sizeof (PaletteData), ResetPalette);
367 if (p != NULL) {
368 SetPanelClick ((PaneL) p, PaletteClick, NULL, NULL, NULL);
369 Nlm_NewPalette (p, pixwidth, actn);
370 }
371 RestorePort (tempPort);
372 }
373 return p;
374 }
375 |
This page was automatically generated by the
LXR engine.
Visit the LXR main site for more information. |