Updated PCI IDs to latest snapshot.
[tangerine.git] / workbench / libs / reqtools / boopsigads.c
blob5967cbf301bf6ab656409668be9f51f8f4e19b57
2 /* Boopsi Button */
4 /* The Image structure as used by this class:
6 * struct Image {
8 * SHORT LeftEdge; <---- Offset
9 * SHORT TopEdge;
11 * SHORT Width; <---- } 4 chars 'Oops' used for identification!
12 * SHORT Height; <---- }
14 * SHORT Depth; <---- maintained by boopsi (set to CUSTOMIMAGEDEPTH).
16 * USHORT *ImageData; <---- only used during init, then points to self!
18 * UBYTE PlanePick; <---- used for the foreground color
20 * UBYTE PlaneOnOff; <---- holds ToUpper (underlined char) (after creation!)
22 * struct Image *NextImage; <---- pointer to the next image. Handled by DrawImage().
23 * };
27 #include <exec/types.h>
28 #include <exec/io.h>
29 #include <exec/memory.h>
30 #include <exec/execbase.h>
31 #include <dos/dosextens.h>
32 #include <utility/tagitem.h>
33 #include <intuition/intuition.h>
34 #include <intuition/classes.h>
35 #include <intuition/classusr.h>
36 #include <intuition/gadgetclass.h>
37 #include <intuition/imageclass.h>
38 #include <intuition/sghooks.h>
39 #include <graphics/gfxbase.h>
40 #include <graphics/gfxmacros.h>
41 #include <libraries/gadtools.h>
42 #include <graphics/monitor.h>
43 //#include <devices/audio.h>
44 #include <proto/graphics.h>
45 #include <proto/gadtools.h>
46 #include <proto/exec.h>
47 #include <proto/layers.h>
48 #include <proto/utility.h>
49 #include <proto/console.h>
50 #include <proto/intuition.h>
51 #include <proto/dos.h>
52 #include <string.h>
54 #ifdef __AROS__
55 #include <aros/asmcall.h>
56 #endif
58 #include "filereq.h"
60 /****************************************************************************************/
62 extern struct Library *GadToolsBase;
63 extern struct GfxBase *GfxBase;
64 extern struct IntuitionBase *IntuitionBase;
65 extern struct Window *win;
66 extern struct Screen *scr;
67 extern struct ExecBase *SysBase;
68 extern struct Device *ConsoleDevice;
70 extern void ShortDelay (void);
71 extern APTR STDARGS DofmtArgs (char *, char *,...);
74 #ifndef __AROS__
75 extern ULONG ASM myBoopsiDispatch (
76 REGPARAM(a0, Class *,),
77 REGPARAM(a2, struct Image *,),
78 REGPARAM(a1, struct impDraw *,));
79 #endif
81 extern Class *ButtonImgClass;
83 /****************************************************************************************/
85 /**********
86 * BUTTONS *
87 **********/
89 struct Gadget * REGARGS my_CreateButtonGadget (
90 struct Gadget *gad,
91 ULONG underscorechar,
92 struct NewGadget *ng)
94 struct InitData idata;
95 struct Image *image;
96 char *label;
98 label = ng->ng_GadgetText;
99 ng->ng_GadgetText = NULL;
101 if ((gad = myCreateGadget (GENERIC_KIND, gad, ng, TAG_END)))
104 /* set gadget attributes */
105 gad->Flags |= GFLG_GADGIMAGE|GFLG_GADGHIMAGE;
106 gad->GadgetType |= GTYP_BOOLGADGET;
107 gad->Activation |= GACT_RELVERIFY;
109 /* set image data */
110 idata.idata_Gadget = gad;
111 idata.idata_VisualInfo = ng->ng_VisualInfo;
112 idata.idata_Label = label;
113 idata.idata_TextAttr = ng->ng_TextAttr;
114 idata.idata_Underscore = underscorechar;
116 /* create image */
118 image = NewObject (ButtonImgClass, NULL, IA_Data, (IPTR) &idata, TAG_END);
120 gad->GadgetRender = gad->SelectRender = image;
123 ng->ng_GadgetText = label;
125 return (gad);
128 /****************************************************************************************/
130 static struct Image *IsButtonGad (struct Gadget *gad)
132 struct Image *im;
133 union {
134 struct {
135 WORD Width;
136 WORD Height;
137 } size;
138 ULONG magic;
139 } __tmp;
141 if (gad->Flags & (GFLG_GADGIMAGE|GFLG_GADGHIMAGE))
142 if ((im = (struct Image *)gad->SelectRender))
143 if (im->Depth == CUSTOMIMAGEDEPTH)
145 __tmp.size.Width = im->Width;
146 __tmp.size.Height = im->Height;
147 if (__tmp.magic == BUTTON_MAGIC_LONGWORD)
148 if (im->ImageData == (UWORD *)im) return (im);
151 return (NULL);
154 /****************************************************************************************/
156 /**********
157 * STRGADS *
158 **********/
160 struct CombStringInfo
162 ULONG magic;
163 struct CombStringInfo *self;
164 struct StringInfo strinfo;
165 struct StringExtend strextend;
166 struct Hook edithook;
169 /****************************************************************************************/
171 #define IEQUALIFIER_SHIFT (IEQUALIFIER_LSHIFT|IEQUALIFIER_RSHIFT)
173 /****************************************************************************************/
175 #ifdef __AROS__
176 AROS_UFH3(ULONG, StrEditHookEntry,
177 AROS_UFHA(struct Hook *, hook, A0),
178 AROS_UFHA(struct SGWork *, sgw, A2),
179 AROS_UFHA(ULONG *, msg, A1))
181 AROS_USERFUNC_INIT
182 #else
183 ULONG ASM SAVEDS
184 StrEditHookEntry (
185 REGPARAM(a0, struct Hook *, hook),
186 REGPARAM(a2, struct SGWork *, sgw),
187 REGPARAM(a1, ULONG *, msg) )
189 #endif
190 struct StrGadUserData *userdata;
191 WORD qual, rawcode;
193 if( msg[ 0 ] == SGH_KEY )
195 rawcode = sgw->IEvent->ie_Code;
196 qual = sgw->IEvent->ie_Qualifier;
198 //kprintf("sgsg: editop = %d code = %x quali = %x\n", sgw->EditOp, rawcode, qual);
200 if( ( sgw->EditOp == EO_INSERTCHAR ) ||
201 ( sgw->EditOp == EO_REPLACECHAR ) ||
202 ( sgw->EditOp == EO_SPECIAL ) || /* CHECKME: AROS/AMIGAOS: ADDED THIS LINE */
203 ( sgw->EditOp == EO_NOOP ) || /* CHECKME: AROS/AMIGAOS: ADDED THIS LINE */
204 ( sgw->EditOp == EO_ENTER ) || /* CHECKME: AROS/AMIGAOS: ADDED THIS LINE */
205 ( sgw->EditOp == EO_BADFORMAT ) )
207 //kprintf("sgsg2\n");
208 if( ( qual & IEQUALIFIER_RCOMMAND ) || ( sgw->Code == 27 ) )
210 sgw->Actions &= ~( SGA_USE | SGA_BEEP | SGA_REDISPLAY );
211 sgw->IEvent->ie_Qualifier &= ~IEQUALIFIER_RCOMMAND;
213 if( !( qual & IEQUALIFIER_REPEAT ) )
215 sgw->Actions |= SGA_REUSE|SGA_END;
216 sgw->Code = KEYB_SHORTCUT;
221 if( ( userdata = ( struct StrGadUserData * ) sgw->Gadget->UserData ) )
223 if( userdata->flags & USERFLAG_MATCH_FILE )
225 if( sgw->Actions & SGA_USE )
227 if( Stricmp( sgw->WorkBuffer, sgw->PrevBuffer ) )
229 if( !userdata->fakeimsg.Micros )
231 userdata->fakeimsg.Micros = 1;
232 PutMsg( userdata->msgport, ( struct Message * ) &userdata->fakeimsg );
238 if( userdata->flags & USERFLAG_UP_DOWN_ARROW )
240 if( ( rawcode == RAWKEY_UP ) || ( rawcode == RAWKEY_DOWN ) )
242 sgw->Actions &= ~( SGA_USE | SGA_BEEP | SGA_REDISPLAY );
243 sgw->Actions |= SGA_REUSE | SGA_END;
244 sgw->Code = KEYB_SHORTCUT;
248 } /* if( ( userdata = ( struct StrGadUserData * ) sgw->Gadget->UserData ) ) */
250 return( TRUE );
252 } /* if( msg[ 0 ] == SGH_KEY ) */
254 return( FALSE );
255 #ifdef __AROS__
256 AROS_USERFUNC_EXIT
257 #endif
260 /****************************************************************************************/
262 struct Hook stredithook =
264 { NULL },
265 ( HOOKFUNC ) StrEditHookEntry, NULL, ( APTR ) 0xff525421
268 /****************************************************************************************/
270 #ifndef GTST_EditHook
271 #define GTST_EditHook (GT_TagBase+55)
272 #define GTIN_EditHook GTST_EditHook
273 #endif
275 /****************************************************************************************/
277 struct Gadget * REGARGS my_CreateIntegerGadget (
278 struct Gadget *gad,
279 struct NewGadget *newgad,
280 int maxchars,
281 LONG value,
282 ULONG just)
284 struct Gadget *intgad;
286 if ((intgad = myCreateGadget (INTEGER_KIND, gad, newgad,
287 GTIN_MaxChars, maxchars,
288 GTIN_Number, value, STRINGA_Justification, just,
289 GTST_EditHook, (IPTR) &stredithook,
290 TAG_END)))
291 intgad->UserData = NULL;
293 return (intgad);
296 /****************************************************************************************/
298 struct Gadget * REGARGS my_CreateStringGadget (
299 struct Gadget *gad,
300 struct NewGadget *newgad,
301 int maxchars,
302 char *string)
304 struct Gadget *strgad;
306 if ((strgad = myCreateGadget (STRING_KIND, gad, newgad, GTST_MaxChars, maxchars,
307 GTST_String, (IPTR) string, GTST_EditHook, (IPTR) &stredithook, TAG_END)))
308 strgad->UserData = NULL;
310 return (strgad);
313 /****************************************************************************************/
315 void REGARGS my_SetStringGadget (struct Window *win, struct Gadget *gad, char *str)
317 if (!gad) return;
319 myGT_SetGadgetAttrs (gad, win, NULL, GTST_String, (IPTR) str, TAG_END);
322 /****************************************************************************************/
324 void REGARGS my_SetIntegerGadget (struct Window *win, struct Gadget *gad, long val)
326 if (!gad) return;
328 myGT_SetGadgetAttrs (gad, win, NULL, GTIN_Number, val, TAG_END);
331 /****************************************************************************************/
333 void REGARGS my_FreeGadgets (struct Gadget *glist)
335 struct Gadget *gad;
336 struct Image *im;
338 #ifdef USE_FORBID
339 Forbid();
340 #else
341 /* FIXME: Any reason for locking here?
342 As far as I can tell all use of this function are reentrant and the
343 glist is never attached to Window when called.
344 If locking is needed for other reasons, semaphore would be better
345 than Forbid(). -Piru */
346 #endif
347 for (gad = glist; gad; gad = gad->NextGadget)
349 if ((im = IsButtonGad (gad))) DisposeObject (im);
351 FreeGadgets (glist);
352 #ifdef USE_FORBID
353 Permit();
354 #else
355 /* unlock */
356 #endif
359 /****************************************************************************************/
361 void REGARGS my_SelectGadget (struct Gadget *gad, struct Window *win)
363 gad->Flags ^= GFLG_SELECTED;
364 RefreshGList (gad, win, NULL, 1);
367 /****************************************************************************************/
369 void REGARGS my_DownGadget (struct Gadget *gad, UWORD code, struct KeyButtonInfo *info)
371 my_SelectGadget (gad, info->win);
372 ShortDelay();
373 info->lastgad = gad;
374 info->lastcode = code;
377 /****************************************************************************************/
379 #define SHIFT_KEY 0x60
381 /****************************************************************************************/
383 struct Gadget *REGARGS my_GetKeyGadget (UBYTE key, struct Gadget *glist)
385 struct Gadget *gad;
386 struct Image *im;
387 char underkey;
389 for (gad = glist; gad; gad = gad->NextGadget)
391 if ((im = IsButtonGad (gad)))
392 if ((underkey = im->PlaneOnOff))
393 if (key == (UBYTE)ToUpper (underkey)) return (gad);
395 return (NULL);
398 /****************************************************************************************/
400 ULONG REGARGS CheckGadgetKey (int code, int qual, char *key,
401 struct KeyButtonInfo *info)
403 struct InputEvent ev;
404 struct Gadget *gad;
405 int upkey = (code & IECODE_UP_PREFIX);
407 *key = 0;
408 if (!(code & ~IECODE_UP_PREFIX)) return (0);
410 /* Convert RAW to ASCII */
411 ev.ie_NextEvent = NULL;
412 ev.ie_Class = IECLASS_RAWKEY;
413 ev.ie_Code = code;
414 /* Ignore alt qualifier */
415 ev.ie_Qualifier = qual & ~(IEQUALIFIER_LALT|IEQUALIFIER_RALT);
416 RawKeyConvert (&ev, key, 1, NULL);
417 *key = ToUpper (*key);
419 if (!(qual & IEQUALIFIER_REPEAT))
421 if (upkey)
423 /* Gadget released ? */
424 if (code == (info->lastcode | IECODE_UP_PREFIX))
426 if (!(info->lastgad->Activation & GACT_TOGGLESELECT))
427 my_SelectGadget (info->lastgad, info->win);
428 info->lastcode = 0;
429 return ((ULONG)info->lastgad->GadgetID);
433 else
435 /* Shift pressed ? */
436 if ((code & ~1) == SHIFT_KEY)
438 if (info->lastcode)
440 my_SelectGadget (info->lastgad, info->win);
441 info->lastcode = 0;
444 else
446 /* No gadget down yet ? */
447 if (!info->lastcode)
449 /* Gadget down ? */
450 if ((gad = my_GetKeyGadget (*key, info->glist)))
452 if (!(gad->Flags & GFLG_DISABLED))
453 my_DownGadget (gad, code, info);
456 else /* return with keycode in 'key' */
457 return (0);
463 } /* if (upkey) else ... */
465 } /* if (!(qual & IEQUALIFIER_REPEAT)) */
467 *key = 0;
468 return (0);
471 /****************************************************************************************/
473 /*********
474 * IMAGES *
475 *********/
477 /* Read VisualInfo and TextAttr from newgadget structure */
478 /* Underscore char is always '_' */
480 struct Image * REGARGS my_CreateGadgetLabelImage (
481 struct Image *previm,
482 struct NewGadget *ng,
483 char *label,
484 WORD left, WORD top,
485 UWORD pen)
487 struct InitData idata;
489 if (!previm) return (NULL);
491 idata.idata_Gadget = NULL;
492 idata.idata_Label = label;
493 idata.idata_VisualInfo = ng->ng_VisualInfo;
494 idata.idata_TextAttr = ng->ng_TextAttr;
495 idata.idata_Underscore = '_';
497 return (previm->NextImage = NewObject (ButtonImgClass, NULL, IA_Data , (IPTR) &idata,
498 IA_FGPen, pen ,
499 IA_Left , left ,
500 IA_Top , top ,
501 TAG_END));
504 /****************************************************************************************/
506 void REGARGS my_FreeLabelImages (struct Image *images)
508 struct Image *im;
510 images = images->NextImage;
511 while (images)
513 im = images;
514 images = images->NextImage;
515 DisposeObject (im);
519 /****************************************************************************************/