4 /* The Image structure as used by this class:
8 * SHORT LeftEdge; <---- Offset
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().
27 #include <exec/types.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>
55 #include <aros/asmcall.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 *,...);
75 extern ULONG ASM
myBoopsiDispatch (
76 REGPARAM(a0
, Class
*,),
77 REGPARAM(a2
, struct Image
*,),
78 REGPARAM(a1
, struct impDraw
*,));
81 extern Class
*ButtonImgClass
;
83 /****************************************************************************************/
89 struct Gadget
* REGARGS
my_CreateButtonGadget (
94 struct InitData idata
;
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
;
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
;
118 image
= NewObject (ButtonImgClass
, NULL
, IA_Data
, (IPTR
) &idata
, TAG_END
);
120 gad
->GadgetRender
= gad
->SelectRender
= image
;
123 ng
->ng_GadgetText
= label
;
128 /****************************************************************************************/
130 static struct Image
*IsButtonGad (struct Gadget
*gad
)
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
);
143 /****************************************************************************************/
149 struct CombStringInfo
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 /****************************************************************************************/
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
))
174 REGPARAM(a0
, struct Hook
*, hook
),
175 REGPARAM(a2
, struct SGWork
*, sgw
),
176 REGPARAM(a1
, ULONG
*, msg
) )
179 struct StrGadUserData
*userdata
;
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 ) ) */
241 } /* if( msg[ 0 ] == SGH_KEY ) */
249 /****************************************************************************************/
251 struct Hook stredithook
=
254 ( HOOKFUNC
) StrEditHookEntry
, NULL
, ( APTR
) 0xff525421
257 /****************************************************************************************/
259 #ifndef GTST_EditHook
260 #define GTST_EditHook (GT_TagBase+55)
261 #define GTIN_EditHook GTST_EditHook
264 /****************************************************************************************/
266 struct Gadget
* REGARGS
my_CreateIntegerGadget (
268 struct NewGadget
*newgad
,
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
,
280 intgad
->UserData
= NULL
;
285 /****************************************************************************************/
287 struct Gadget
* REGARGS
my_CreateStringGadget (
289 struct NewGadget
*newgad
,
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
;
302 /****************************************************************************************/
304 void REGARGS
my_SetStringGadget (struct Window
*win
, struct Gadget
*gad
, char *str
)
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
)
317 myGT_SetGadgetAttrs (gad
, win
, NULL
, GTIN_Number
, val
, TAG_END
);
320 /****************************************************************************************/
322 void REGARGS
my_FreeGadgets (struct Gadget
*glist
)
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 */
336 for (gad
= glist
; gad
; gad
= gad
->NextGadget
)
338 if ((im
= IsButtonGad (gad
))) DisposeObject (im
);
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
);
363 info
->lastcode
= code
;
366 /****************************************************************************************/
368 #define SHIFT_KEY 0x60
370 /****************************************************************************************/
372 struct Gadget
*REGARGS
my_GetKeyGadget (UBYTE key
, struct Gadget
*glist
)
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
);
387 /****************************************************************************************/
389 ULONG REGARGS
CheckGadgetKey (int code
, int qual
, char *key
,
390 struct KeyButtonInfo
*info
)
392 struct InputEvent ev
;
394 int upkey
= (code
& IECODE_UP_PREFIX
);
397 if (!(code
& ~IECODE_UP_PREFIX
)) return (0);
399 /* Convert RAW to ASCII */
400 ev
.ie_NextEvent
= NULL
;
401 ev
.ie_Class
= IECLASS_RAWKEY
;
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
))
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
);
418 return ((ULONG
)info
->lastgad
->GadgetID
);
424 /* Shift pressed ? */
425 if ((code
& ~1) == SHIFT_KEY
)
429 my_SelectGadget (info
->lastgad
, info
->win
);
435 /* No gadget down yet ? */
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' */
452 } /* if (upkey) else ... */
454 } /* if (!(qual & IEQUALIFIER_REPEAT)) */
460 /****************************************************************************************/
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
,
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
,
493 /****************************************************************************************/
495 void REGARGS
my_FreeLabelImages (struct Image
*images
)
499 images
= images
->NextImage
;
503 images
= images
->NextImage
;
508 /****************************************************************************************/