added concrete implementations of putc(), getc(), getchar() and gets()
[tangerine.git] / workbench / libs / reqtools / boopsigads.c
blob59cdd0dbb22258a4aa1b227b2f2132a386b72171
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;
134 if (gad->Flags & (GFLG_GADGIMAGE|GFLG_GADGHIMAGE))
135 if ((im = (struct Image *)gad->SelectRender))
136 if (im->Depth == CUSTOMIMAGEDEPTH)
137 if (*(ULONG *)&im->Width == BUTTON_MAGIC_LONGWORD)
138 if (im->ImageData == (UWORD *)im) return (im);
140 return (NULL);
143 /****************************************************************************************/
145 /**********
146 * STRGADS *
147 **********/
149 struct CombStringInfo
151 ULONG magic;
152 struct CombStringInfo *self;
153 struct StringInfo strinfo;
154 struct StringExtend strextend;
155 struct Hook edithook;
158 /****************************************************************************************/
160 #define IEQUALIFIER_SHIFT (IEQUALIFIER_LSHIFT|IEQUALIFIER_RSHIFT)
162 /****************************************************************************************/
164 #ifdef __AROS__
165 AROS_UFH3(ULONG, StrEditHookEntry,
166 AROS_UFHA(struct Hook *, hook, A0),
167 AROS_UFHA(struct SGWork *, sgw, A2),
168 AROS_UFHA(ULONG *, msg, A1))
170 AROS_USERFUNC_INIT
171 #else
172 ULONG ASM SAVEDS
173 StrEditHookEntry (
174 REGPARAM(a0, struct Hook *, hook),
175 REGPARAM(a2, struct SGWork *, sgw),
176 REGPARAM(a1, ULONG *, msg) )
178 #endif
179 struct StrGadUserData *userdata;
180 WORD qual, rawcode;
182 if( msg[ 0 ] == SGH_KEY )
184 rawcode = sgw->IEvent->ie_Code;
185 qual = sgw->IEvent->ie_Qualifier;
187 //kprintf("sgsg: editop = %d code = %x quali = %x\n", sgw->EditOp, rawcode, qual);
189 if( ( sgw->EditOp == EO_INSERTCHAR ) ||
190 ( sgw->EditOp == EO_REPLACECHAR ) ||
191 ( sgw->EditOp == EO_SPECIAL ) || /* CHECKME: AROS/AMIGAOS: ADDED THIS LINE */
192 ( sgw->EditOp == EO_NOOP ) || /* CHECKME: AROS/AMIGAOS: ADDED THIS LINE */
193 ( sgw->EditOp == EO_ENTER ) || /* CHECKME: AROS/AMIGAOS: ADDED THIS LINE */
194 ( sgw->EditOp == EO_BADFORMAT ) )
196 //kprintf("sgsg2\n");
197 if( ( qual & IEQUALIFIER_RCOMMAND ) || ( sgw->Code == 27 ) )
199 sgw->Actions &= ~( SGA_USE | SGA_BEEP | SGA_REDISPLAY );
200 sgw->IEvent->ie_Qualifier &= ~IEQUALIFIER_RCOMMAND;
202 if( !( qual & IEQUALIFIER_REPEAT ) )
204 sgw->Actions |= SGA_REUSE|SGA_END;
205 sgw->Code = KEYB_SHORTCUT;
210 if( ( userdata = ( struct StrGadUserData * ) sgw->Gadget->UserData ) )
212 if( userdata->flags & USERFLAG_MATCH_FILE )
214 if( sgw->Actions & SGA_USE )
216 if( Stricmp( sgw->WorkBuffer, sgw->PrevBuffer ) )
218 if( !userdata->fakeimsg.Micros )
220 userdata->fakeimsg.Micros = 1;
221 PutMsg( userdata->msgport, ( struct Message * ) &userdata->fakeimsg );
227 if( userdata->flags & USERFLAG_UP_DOWN_ARROW )
229 if( ( rawcode == RAWKEY_UP ) || ( rawcode == RAWKEY_DOWN ) )
231 sgw->Actions &= ~( SGA_USE | SGA_BEEP | SGA_REDISPLAY );
232 sgw->Actions |= SGA_REUSE | SGA_END;
233 sgw->Code = KEYB_SHORTCUT;
237 } /* if( ( userdata = ( struct StrGadUserData * ) sgw->Gadget->UserData ) ) */
239 return( TRUE );
241 } /* if( msg[ 0 ] == SGH_KEY ) */
243 return( FALSE );
244 #ifdef __AROS__
245 AROS_USERFUNC_EXIT
246 #endif
249 /****************************************************************************************/
251 struct Hook stredithook =
253 { NULL },
254 ( HOOKFUNC ) StrEditHookEntry, NULL, ( APTR ) 0xff525421
257 /****************************************************************************************/
259 #ifndef GTST_EditHook
260 #define GTST_EditHook (GT_TagBase+55)
261 #define GTIN_EditHook GTST_EditHook
262 #endif
264 /****************************************************************************************/
266 struct Gadget * REGARGS my_CreateIntegerGadget (
267 struct Gadget *gad,
268 struct NewGadget *newgad,
269 int maxchars,
270 LONG value,
271 ULONG just)
273 struct Gadget *intgad;
275 if ((intgad = myCreateGadget (INTEGER_KIND, gad, newgad,
276 GTIN_MaxChars, maxchars,
277 GTIN_Number, value, STRINGA_Justification, just,
278 GTST_EditHook, (IPTR) &stredithook,
279 TAG_END)))
280 intgad->UserData = NULL;
282 return (intgad);
285 /****************************************************************************************/
287 struct Gadget * REGARGS my_CreateStringGadget (
288 struct Gadget *gad,
289 struct NewGadget *newgad,
290 int maxchars,
291 char *string)
293 struct Gadget *strgad;
295 if ((strgad = myCreateGadget (STRING_KIND, gad, newgad, GTST_MaxChars, maxchars,
296 GTST_String, (IPTR) string, GTST_EditHook, (IPTR) &stredithook, TAG_END)))
297 strgad->UserData = NULL;
299 return (strgad);
302 /****************************************************************************************/
304 void REGARGS my_SetStringGadget (struct Window *win, struct Gadget *gad, char *str)
306 if (!gad) return;
308 myGT_SetGadgetAttrs (gad, win, NULL, GTST_String, (IPTR) str, TAG_END);
311 /****************************************************************************************/
313 void REGARGS my_SetIntegerGadget (struct Window *win, struct Gadget *gad, long val)
315 if (!gad) return;
317 myGT_SetGadgetAttrs (gad, win, NULL, GTIN_Number, val, TAG_END);
320 /****************************************************************************************/
322 void REGARGS my_FreeGadgets (struct Gadget *glist)
324 struct Gadget *gad;
325 struct Image *im;
327 #ifdef USE_FORBID
328 Forbid();
329 #else
330 /* FIXME: Any reason for locking here?
331 As far as I can tell all use of this function are reentrant and the
332 glist is never attached to Window when called.
333 If locking is needed for other reasons, semaphore would be better
334 than Forbid(). -Piru */
335 #endif
336 for (gad = glist; gad; gad = gad->NextGadget)
338 if ((im = IsButtonGad (gad))) DisposeObject (im);
340 FreeGadgets (glist);
341 #ifdef USE_FORBID
342 Permit();
343 #else
344 /* unlock */
345 #endif
348 /****************************************************************************************/
350 void REGARGS my_SelectGadget (struct Gadget *gad, struct Window *win)
352 gad->Flags ^= GFLG_SELECTED;
353 RefreshGList (gad, win, NULL, 1);
356 /****************************************************************************************/
358 void REGARGS my_DownGadget (struct Gadget *gad, UWORD code, struct KeyButtonInfo *info)
360 my_SelectGadget (gad, info->win);
361 ShortDelay();
362 info->lastgad = gad;
363 info->lastcode = code;
366 /****************************************************************************************/
368 #define SHIFT_KEY 0x60
370 /****************************************************************************************/
372 struct Gadget *REGARGS my_GetKeyGadget (UBYTE key, struct Gadget *glist)
374 struct Gadget *gad;
375 struct Image *im;
376 char underkey;
378 for (gad = glist; gad; gad = gad->NextGadget)
380 if ((im = IsButtonGad (gad)))
381 if ((underkey = im->PlaneOnOff))
382 if (key == (UBYTE)ToUpper (underkey)) return (gad);
384 return (NULL);
387 /****************************************************************************************/
389 ULONG REGARGS CheckGadgetKey (int code, int qual, char *key,
390 struct KeyButtonInfo *info)
392 struct InputEvent ev;
393 struct Gadget *gad;
394 int upkey = (code & IECODE_UP_PREFIX);
396 *key = 0;
397 if (!(code & ~IECODE_UP_PREFIX)) return (0);
399 /* Convert RAW to ASCII */
400 ev.ie_NextEvent = NULL;
401 ev.ie_Class = IECLASS_RAWKEY;
402 ev.ie_Code = code;
403 /* Ignore alt qualifier */
404 ev.ie_Qualifier = qual & ~(IEQUALIFIER_LALT|IEQUALIFIER_RALT);
405 RawKeyConvert (&ev, key, 1, NULL);
406 *key = ToUpper (*key);
408 if (!(qual & IEQUALIFIER_REPEAT))
410 if (upkey)
412 /* Gadget released ? */
413 if (code == (info->lastcode | IECODE_UP_PREFIX))
415 if (!(info->lastgad->Activation & GACT_TOGGLESELECT))
416 my_SelectGadget (info->lastgad, info->win);
417 info->lastcode = 0;
418 return ((ULONG)info->lastgad->GadgetID);
422 else
424 /* Shift pressed ? */
425 if ((code & ~1) == SHIFT_KEY)
427 if (info->lastcode)
429 my_SelectGadget (info->lastgad, info->win);
430 info->lastcode = 0;
433 else
435 /* No gadget down yet ? */
436 if (!info->lastcode)
438 /* Gadget down ? */
439 if ((gad = my_GetKeyGadget (*key, info->glist)))
441 if (!(gad->Flags & GFLG_DISABLED))
442 my_DownGadget (gad, code, info);
445 else /* return with keycode in 'key' */
446 return (0);
452 } /* if (upkey) else ... */
454 } /* if (!(qual & IEQUALIFIER_REPEAT)) */
456 *key = 0;
457 return (0);
460 /****************************************************************************************/
462 /*********
463 * IMAGES *
464 *********/
466 /* Read VisualInfo and TextAttr from newgadget structure */
467 /* Underscore char is always '_' */
469 struct Image * REGARGS my_CreateGadgetLabelImage (
470 struct Image *previm,
471 struct NewGadget *ng,
472 char *label,
473 WORD left, WORD top,
474 UWORD pen)
476 struct InitData idata;
478 if (!previm) return (NULL);
480 idata.idata_Gadget = NULL;
481 idata.idata_Label = label;
482 idata.idata_VisualInfo = ng->ng_VisualInfo;
483 idata.idata_TextAttr = ng->ng_TextAttr;
484 idata.idata_Underscore = '_';
486 return (previm->NextImage = NewObject (ButtonImgClass, NULL, IA_Data , (IPTR) &idata,
487 IA_FGPen, pen ,
488 IA_Left , left ,
489 IA_Top , top ,
490 TAG_END));
493 /****************************************************************************************/
495 void REGARGS my_FreeLabelImages (struct Image *images)
497 struct Image *im;
499 images = images->NextImage;
500 while (images)
502 im = images;
503 images = images->NextImage;
504 DisposeObject (im);
508 /****************************************************************************************/