- Give PCI controllers lower unit numbers than legacy controllers.
[cake.git] / rom / intuition / gadgetclass.c
blob8bf393c686e0dadb084ffffb8ee6614ec67febc5
1 /*
2 Copyright 1995-2005, The AROS Development Team. All rights reserved.
3 Copyright 2001-2003, The MorphOS Development Team. All Rights Reserved.
4 $Id$
5 */
7 #include <exec/types.h>
9 #include <dos/dos.h>
10 #include <dos/dosextens.h>
12 #include <intuition/intuition.h>
13 #include <intuition/intuitionbase.h>
14 #include <intuition/classes.h>
15 #include <intuition/classusr.h>
16 #include <intuition/gadgetclass.h>
17 #include <intuition/cghooks.h>
18 #include <intuition/icclass.h>
20 #include <graphics/gfxbase.h>
21 #include <graphics/gfxmacros.h>
23 #include <utility/tagitem.h>
24 #include <utility/hooks.h>
26 #include <clib/macros.h>
28 #include <string.h>
30 #include <proto/exec.h>
31 #include <proto/intuition.h>
32 #include <proto/graphics.h>
33 #include <proto/utility.h>
35 #ifndef __MORPHOS__
37 struct ICData;
38 #include "intuition_intern.h"
39 #include <aros/asmcall.h>
40 #include <proto/alib.h>
41 #include "gadgets.h"
43 #endif /* !__MORPHOS__ */
45 #define DEBUG_GADGET(x) ;
47 /****************************************************************************/
49 #undef IntuitionBase
50 #define IntuitionBase ((struct IntuitionBase *)cl->cl_UserData)
52 /* set gadget attributes
54 static ULONG set_gadgetclass(Class *cl, struct ExtGadget *eg, struct opSet *msg)
56 const struct TagItem *tstate = msg->ops_AttrList;
57 struct TagItem *tag;
58 IPTR tidata;
59 ULONG retval = 0UL; /* set to non-zero to signal visual changes */
61 while ( (tag = NextTagItem(&tstate)) )
63 tidata = tag->ti_Data;
65 switch(tag->ti_Tag)
67 case GA_Left:
68 eg->LeftEdge = (WORD)tidata;
69 //eg->Flags &= ~GFLG_RELRIGHT;
70 retval = 1UL;
71 break;
73 case GA_Top:
74 eg->TopEdge = (WORD)tidata;
75 //eg->Flags &= ~GFLG_RELBOTTOM;
76 retval = 1UL;
77 break;
79 case GA_Width:
80 eg->Width = (WORD)tidata;
81 eg->Flags &= ~GFLG_RELWIDTH;
82 retval = 1UL;
83 break;
85 case GA_Height:
86 eg->Height = (WORD)tidata;
87 eg->Flags &= ~GFLG_RELHEIGHT;
88 retval = 1UL;
89 break;
91 case GA_RelRight:
92 eg->LeftEdge = (WORD)tidata;
93 eg->Flags |= GFLG_RELRIGHT;
94 retval = 1UL;
95 break;
97 case GA_RelBottom:
98 eg->TopEdge = (WORD)tidata;
99 eg->Flags |= GFLG_RELBOTTOM;
100 retval = 1UL;
101 break;
103 case GA_RelWidth:
104 eg->Width = (WORD)tidata;
105 eg->Flags |= GFLG_RELWIDTH;
106 retval = 1UL;
107 break;
109 case GA_RelHeight:
110 eg->Height = (WORD)tidata;
111 eg->Flags |= GFLG_RELHEIGHT;
112 retval = 1UL;
113 break;
115 case GA_RelSpecial:
116 if (tidata)
118 eg->Flags |= GFLG_RELSPECIAL;
120 else
122 eg->Flags &= ~GFLG_RELSPECIAL;
124 retval = 1UL;
125 break;
127 case GA_Bounds:
128 if (tidata)
130 eg->BoundsLeftEdge = ((struct IBox *)tidata)->Left;
131 eg->BoundsTopEdge = ((struct IBox *)tidata)->Top;
132 eg->BoundsWidth = ((struct IBox *)tidata)->Width;
133 eg->BoundsHeight = ((struct IBox *)tidata)->Height;
134 eg->MoreFlags |= GMORE_BOUNDS;
136 retval = 1UL;
137 break;
139 case GA_GadgetHelp:
140 if (tidata)
142 eg->MoreFlags |= GMORE_GADGETHELP;
144 else
146 eg->MoreFlags &= ~GMORE_GADGETHELP;
148 retval = 1UL;
149 break;
151 case GA_Next:
152 eg->NextGadget = (struct ExtGadget *)tidata;
153 break;
155 case GA_Previous:
156 if( (tidata != 0L) && (msg->MethodID == OM_NEW) )
158 eg->NextGadget = ((struct ExtGadget *)tidata)->NextGadget;
159 ((struct ExtGadget *)tidata)->NextGadget = eg;
161 break;
163 case GA_IntuiText:
164 eg->GadgetText = (struct IntuiText *)tidata;
165 if (tidata)
167 eg->Flags &= ~GFLG_LABELMASK;
168 eg->Flags |= GFLG_LABELITEXT;
170 retval = 1UL;
171 break;
173 case GA_Text:
174 eg->GadgetText = (struct IntuiText *)tidata;
175 if (tidata)
177 eg->Flags &= ~GFLG_LABELMASK;
178 eg->Flags |= GFLG_LABELSTRING;
180 retval = 1UL;
181 break;
183 case GA_LabelImage:
184 eg->GadgetText = (struct IntuiText *)tidata;
185 if (tidata)
187 eg->Flags &= ~GFLG_LABELMASK;
188 eg->Flags |= GFLG_LABELIMAGE;
190 retval = 1UL;
191 break;
193 case GA_Image:
194 eg->GadgetRender = (APTR)tidata;
195 if (tidata)
197 eg->Flags |= GFLG_GADGIMAGE;
199 retval = 1UL;
200 break;
202 case GA_Border:
203 eg->GadgetRender = (APTR)tidata;
204 if (tidata)
206 eg->Flags &= ~GFLG_GADGIMAGE;
208 retval = 1UL;
209 break;
211 case GA_SelectRender:
212 eg->SelectRender = (APTR)tidata;
214 eg->Flags |= (GFLG_GADGIMAGE & GFLG_GADGHIMAGE);
216 retval = 1UL;
217 break;
219 case GA_SpecialInfo:
220 eg->SpecialInfo = (APTR)tidata;
221 break;
223 case GA_GZZGadget:
224 if ( tidata != FALSE )
226 eg->GadgetType |= GTYP_GZZGADGET;
228 else
230 eg->GadgetType &= ~GTYP_GZZGADGET;
232 break;
234 case GA_SysGadget:
235 if ( tidata != FALSE )
237 eg->GadgetType |= GTYP_SYSGADGET;
239 else
241 eg->GadgetType &= ~GTYP_SYSGADGET;
243 break;
245 case GA_Selected:
246 if ( tidata != FALSE )
248 eg->Flags |= GFLG_SELECTED;
250 else
252 eg->Flags &= ~GFLG_SELECTED;
254 retval = 1UL;
255 break;
257 case GA_Disabled:
258 if ( tidata != FALSE )
260 eg->Flags |= GFLG_DISABLED;
262 else
264 eg->Flags &= ~GFLG_DISABLED;
266 retval = 1UL;
267 break;
269 case GA_EndGadget:
270 if ( tidata != FALSE )
272 eg->Activation |= GACT_ENDGADGET;
274 else
276 eg->Activation &= ~GACT_ENDGADGET;
278 break;
280 case GA_Immediate:
281 if ( tidata != FALSE )
283 eg->Activation |= GACT_IMMEDIATE;
285 else
287 eg->Activation &= ~GACT_IMMEDIATE;
289 break;
291 case GA_RelVerify:
292 if ( tidata != FALSE )
294 eg->Activation |= GACT_RELVERIFY;
296 else
298 eg->Activation &= ~GACT_RELVERIFY;
300 break;
302 case GA_FollowMouse:
303 if ( tidata != FALSE )
305 eg->Activation |= GACT_FOLLOWMOUSE;
307 else
309 eg->Activation &= ~GACT_FOLLOWMOUSE;
311 break;
313 case GA_RightBorder:
314 if ( tidata != FALSE )
316 eg->Activation |= GACT_RIGHTBORDER;
318 else
320 eg->Activation &= ~GACT_RIGHTBORDER;
322 break;
324 case GA_LeftBorder:
325 if ( tidata != FALSE )
327 eg->Activation |= GACT_LEFTBORDER;
329 else
331 eg->Activation &= ~GACT_LEFTBORDER;
333 break;
335 case GA_TopBorder:
336 if ( tidata != FALSE )
338 eg->Activation |= GACT_TOPBORDER;
340 else
342 eg->Activation &= ~GACT_TOPBORDER;
344 break;
346 case GA_BottomBorder:
347 if ( tidata != FALSE )
349 eg->Activation |= GACT_BOTTOMBORDER;
351 else
353 eg->Activation &= ~GACT_BOTTOMBORDER;
355 break;
357 case GA_ToggleSelect:
358 if (tidata)
360 eg->Activation |= GACT_TOGGLESELECT;
362 else
364 eg->Activation &= ~GACT_TOGGLESELECT;
366 break;
368 case GA_TabCycle:
369 if (tidata)
371 eg->Flags |= GFLG_TABCYCLE;
373 else
375 eg->Flags &= ~GFLG_TABCYCLE;
377 break;
379 case GA_Highlight:
380 eg->Flags &= ~GFLG_GADGHIGHBITS;
381 eg->Flags |= tidata & GFLG_GADGHIGHBITS;
382 break;
384 case GA_SysGType:
385 eg->GadgetType &= ~GTYP_SYSTYPEMASK;
386 eg->GadgetType |= tidata & GTYP_SYSTYPEMASK;
387 break;
389 case GA_ID:
390 /* GA_ID should NOT be set if this is a OM_UPDATE.
391 ** This is because gadgets should send their GA_ID
392 ** when doing a OM_NOTIFY, so that the receiver
393 ** might see who sent the message.
394 ** But we surely don't want to change the GA_ID
395 ** of the reciver to that of the sender.
397 if (msg->MethodID != OM_UPDATE)
399 eg->GadgetID = tidata;
401 break;
403 case GA_UserData:
404 eg->UserData = (APTR)tidata;
405 DEBUG_GADGET(dprintf("set_gadgetclass: UserData 0x%lx\n",tidata));
406 break;
408 case ICA_TARGET:
409 ((struct GadgetData *)eg)->IC.ic_Target = (Object *)tidata;
410 break;
412 case ICA_MAP:
413 ((struct GadgetData *)eg)->IC.ic_Mapping = (struct TagItem *)tidata;
414 break;
416 } /* switch tag */
418 } /* while NextTagItem */
420 #if 0
421 /* This seems to be wrong here. Instead buttongclass is where
422 something like this happens, so look there (stegerg) */
424 if ((msg->MethodID == OM_NEW) &&
425 (eg->Flags & GFLG_GADGIMAGE) &&
426 (eg->GadgetRender != NULL))
428 if (eg->Width == 0) eg->Width = ((struct Image *)eg->GadgetRender)->Width;
429 if (eg->Height == 0) eg->Height = ((struct Image *)eg->GadgetRender)->Height;
431 #endif
433 return retval;
437 IPTR GadgetClass__OM_NEW(Class *cl, Object *o, struct opSet *msg)
439 struct ExtGadget *eg = (struct ExtGadget *)DoSuperMethodA(cl, o, (Msg)msg);
441 if (eg)
443 /* set some defaults */
445 * The instance object is cleared memory!
446 * memset (eg, 0, sizeof(struct GadgetData));
448 eg->Flags = GFLG_EXTENDED;
449 eg->GadgetType = GTYP_CUSTOMGADGET;
450 eg->MoreFlags = GMORE_BOOPSIGADGET;
451 eg->MutualExclude = (LONG)&((Class *)o)->cl_Dispatcher;
453 /* Handle our special tags - overrides defaults */
454 set_gadgetclass(cl, eg, msg);
457 return (IPTR)eg;
460 IPTR GadgetClass__OM_SET(Class *cl, struct ExtGadget *eg, struct opSet *msg)
462 return DoSuperMethodA(cl, (Object *)eg, (Msg)msg) + set_gadgetclass(cl, eg, (struct opSet *)msg);
465 IPTR GadgetClass__OM_NOTIFY(Class *cl, struct GadgetData *gd, struct opUpdate *msg)
467 DEBUG_GADGET(dprintf("dispatch_gadgetclass: OM_NOTIFY\n"));
468 DoNotify(cl, (Object *)gd, &(gd->IC), msg);
469 DEBUG_GADGET(dprintf("dispatch_gadgetclass: OM_NOTIFY done\n"));
471 return (IPTR)0;
474 IPTR GadgetClass__OM_DISPOSE(Class *cl, struct GadgetData *gd, Msg msg)
476 FreeICData((struct ICData *)&gd->IC);
477 return DoSuperMethodA(cl, (Object *)gd, (Msg)msg);
480 /* get gadget attributes - gadgetclass really has no gettable
481 * attributes, but we will implement some useful ones anyway. ;0
483 IPTR GadgetClass__OM_GET(Class *cl, struct ExtGadget *eg, struct opGet *msg)
485 ULONG retval = 1UL;
487 switch (msg->opg_AttrID)
489 case GA_Left:
490 case GA_RelRight:
491 *msg->opg_Storage = (IPTR) eg->LeftEdge;
492 break;
494 case GA_Top:
495 case GA_RelBottom:
496 *msg->opg_Storage = (IPTR) eg->TopEdge;
497 break;
499 case GA_Width:
500 case GA_RelWidth:
501 *msg->opg_Storage = (IPTR) eg->Width;
502 break;
504 case GA_Height:
505 case GA_RelHeight:
506 *msg->opg_Storage = (IPTR) eg->Height;
507 break;
509 case GA_Selected:
510 *msg->opg_Storage = (IPTR)((eg->Flags & GFLG_SELECTED) != 0);
511 break;
513 case GA_Disabled:
514 *msg->opg_Storage = (IPTR)((eg->Flags & GFLG_DISABLED) != 0);
515 break;
517 case GA_ID:
518 *msg->opg_Storage = (IPTR)eg->GadgetID;
519 break;
521 case GA_UserData:
522 *msg->opg_Storage = (IPTR)eg->UserData;
523 break;
525 case GA_RelSpecial:
526 *msg->opg_Storage = (IPTR)(eg->Flags & GFLG_RELSPECIAL) ? TRUE : FALSE;
527 break;
529 case GA_GadgetHelp:
530 *msg->opg_Storage = (IPTR)(eg->MoreFlags & GMORE_GADGETHELP) ? TRUE : FALSE;
531 break;
533 case GA_Next:
534 *msg->opg_Storage = (IPTR)eg->NextGadget;
535 break;
537 case GA_IntuiText:
538 *msg->opg_Storage = (IPTR)((eg->Flags & GFLG_LABELITEXT) ? eg->GadgetText : 0);
539 break;
541 case GA_Text:
542 *msg->opg_Storage = (IPTR)((eg->Flags & GFLG_LABELSTRING) ? eg->GadgetText : 0);
543 break;
545 case GA_LabelImage:
546 *msg->opg_Storage = (IPTR)((eg->Flags & GFLG_LABELIMAGE) ? eg->GadgetText : 0);
547 break;
549 case GA_Image:
550 *msg->opg_Storage = (IPTR)((eg->Flags & GFLG_GADGIMAGE) ? eg->GadgetRender : 0);
551 break;
553 case GA_Border:
554 *msg->opg_Storage = (IPTR)((eg->Flags & GFLG_GADGIMAGE) ? 0 : eg->GadgetRender);
555 break;
557 case GA_SelectRender:
558 *msg->opg_Storage = (IPTR)((eg->Flags & GFLG_GADGHIMAGE) ? eg->SelectRender : 0);
559 break;
561 case GA_SpecialInfo:
562 *msg->opg_Storage = (IPTR)eg->SpecialInfo;
563 break;
565 case GA_GZZGadget:
566 *msg->opg_Storage = (IPTR)((eg->GadgetType & GTYP_GZZGADGET) ? TRUE : FALSE);
567 break;
569 case GA_SysGadget:
570 *msg->opg_Storage = (IPTR)((eg->GadgetType & GTYP_SYSGADGET) ? TRUE : FALSE);
571 break;
573 case GA_EndGadget:
574 *msg->opg_Storage = (IPTR)((eg->Activation & GACT_ENDGADGET) ? TRUE : FALSE);
575 break;
577 case GA_Immediate:
578 *msg->opg_Storage = (IPTR)((eg->Activation & GACT_IMMEDIATE) ? TRUE : FALSE);
579 break;
581 case GA_RelVerify:
582 *msg->opg_Storage = (IPTR)((eg->Activation & GACT_RELVERIFY) ? TRUE : FALSE);
583 break;
585 case GA_FollowMouse:
586 *msg->opg_Storage = (IPTR)((eg->Activation & GACT_FOLLOWMOUSE) ? TRUE : FALSE);
587 break;
589 case GA_RightBorder:
590 *msg->opg_Storage = (IPTR)((eg->Activation & GACT_RIGHTBORDER) ? TRUE : FALSE);
591 break;
593 case GA_LeftBorder:
594 *msg->opg_Storage = (IPTR)((eg->Activation & GACT_LEFTBORDER) ? TRUE : FALSE);
595 break;
597 case GA_TopBorder:
598 *msg->opg_Storage = (IPTR)((eg->Activation & GACT_TOPBORDER) ? TRUE : FALSE);
599 break;
601 case GA_BottomBorder:
602 *msg->opg_Storage = (IPTR)((eg->Activation & GACT_BOTTOMBORDER) ? TRUE : FALSE);
603 break;
605 case GA_ToggleSelect:
606 *msg->opg_Storage = (IPTR)((eg->Activation & GACT_TOGGLESELECT) ? TRUE : FALSE);
607 break;
609 case GA_TabCycle:
610 *msg->opg_Storage = (IPTR)((eg->Flags & GFLG_TABCYCLE) ? TRUE : FALSE);
611 break;
613 case GA_Highlight:
614 *msg->opg_Storage = (IPTR)((eg->Flags & GFLG_GADGHIGHBITS) ? TRUE : FALSE);
615 break;
617 case GA_SysGType:
618 *msg->opg_Storage = (IPTR)(eg->GadgetType & GTYP_SYSTYPEMASK);
619 break;
621 case ICA_TARGET:
622 *msg->opg_Storage = (IPTR)((struct GadgetData *)eg)->IC.ic_Target;
623 break;
625 case ICA_MAP:
626 *msg->opg_Storage = (IPTR)((struct GadgetData *)eg)->IC.ic_Mapping;
627 break;
629 case GA_Bounds:
630 if (msg->opg_Storage)
632 struct IBox *ibox = (struct IBox *)msg->opg_Storage;
634 ibox->Left = eg->BoundsLeftEdge;
635 ibox->Top = eg->BoundsTopEdge;
636 ibox->Width = eg->BoundsWidth;
637 ibox->Height = eg->BoundsHeight;
639 break;
642 default:
643 #if 0
644 /* DONT DO THIS!! For example BGUI propclass relies on this not happening!! */
646 *msg->opg_Storage = (IPTR)NULL;
648 #endif
649 retval = 0UL;
650 break;
652 } /* switch attrid) */
654 return(retval);
657 /* test if we should try to activate this gadget...
659 IPTR GadgetClass__GM_HITTEST(Class *cl, Object *o, struct gpHitTest *gpht)
661 return (IPTR)GMR_GADGETHIT;
664 /* Methods follows that only need to return a value because they should be handled by
665 * the subclasses
667 IPTR GadgetClass__One(Class *cl, Object *o, Msg msg)
669 return (IPTR)1;
672 IPTR GadgetClass__Zero(Class *cl, Object *o, Msg msg)
674 return (IPTR)0;
677 IPTR GadgetClass_NoReuse(Class *cl, Object *o, Msg msg)
679 return (IPTR)GMR_NOREUSE;
682 IPTR GadgetClass__GM_HELPTEST(Class *cl, Object *o, Msg msg)
684 DEBUG_GADGET(dprintf("dispatch_gadgetclass: GM_HELPTEST\n"));
685 return (IPTR)GMR_HELPHIT;
688 IPTR GadgetClass__ICM_SETLOOP(Class *cl, struct GadgetData *gd, Msg msg)
690 DEBUG_GADGET(dprintf("dispatch_gadgetclass: ICM_SETLOOP\n"));
691 gd->IC.ic_LoopCounter += 1UL;
693 return (IPTR)0;
696 IPTR GadgetClass__ICM_CLEARLOOP(Class *cl, struct GadgetData *gd, Msg msg)
698 DEBUG_GADGET(dprintf("dispatch_gadgetclass: ICM_CLEARLOOP\n"));
699 gd->IC.ic_LoopCounter -= 1UL;
701 return (IPTR)0;
704 IPTR GadgetClass__ICM_CHECKLOOP(Class *cl, struct GadgetData *gd, Msg msg)
706 DEBUG_GADGET(dprintf("dispatch_gadgetclass: ICM_CHECKLOOP\n"));
707 return (IPTR)gd->IC.ic_LoopCounter;