6 * (C) Copyright 1998 Manuel Lemos.
7 * (C) Copyright 1995-1996 Jaba Development.
8 * (C) Copyright 1995-1996 Jan van den Baard.
11 * This is DragNDrop in it's most basic form. It is totally
12 * useless unless you create subclasses which actually make
13 * use of the dragged and dropped information.
15 * This example does show you a way to handle input events
16 * in a class which supports dragging.
18 * The program will open a window with two buttons, one draggable
19 * and one droppable. You can drag the draggable object on
20 * the dropable and when you release it the screen will beep.
23 * Revision 42.2 2004/06/17 07:38:47 chodorowski
24 * Added missing REGFUNC_END.
26 * Revision 42.1 2000/05/15 19:29:50 stegerg
27 * replacements for REG macro.
29 * Revision 42.0 2000/05/09 22:20:11 mlemos
30 * Bumped to revision 42.0 before handing BGUI to AROS team
32 * Revision 41.11 2000/05/09 20:34:00 mlemos
33 * Bumped to revision 41.11
35 * Revision 1.2 2000/05/09 19:59:15 mlemos
36 * Merged with the branch Manuel_Lemos_fixes.
38 * Revision 1.1.2.1 1998/02/28 17:45:45 mlemos
44 /* Execute me to compile with DICE V3.0
45 dcc Useless.c -proto -mi -ms -mRR -lbgui
54 #define INPUT(x) (( struct gpInput * )x )
57 * We need a simple subclass of the BGUI button class to
60 //SAVEDS ASM ULONG DispatchSB( REG(a0) Class *cl, REG(a2) Object *obj, REG(a1) Msg msg )
61 SAVEDS ASM
REGFUNC3(ULONG
, DispatchSB
,
62 REGPARAM(A0
, Class
*, cl
),
63 REGPARAM(A2
, Object
*, obj
),
64 REGPARAM(A1
, Msg
, msg
))
70 switch ( msg
->MethodID
) {
74 * Handle the input. To implement a draggable object we
75 * need to call the BASE_DRAGGING method as part of our
76 * input-processing code. This method will tell us what
77 * to do with the input event.
81 * Copy the input message. The BASE_DRAGGING method uses
82 * the same message structure.
85 copy
.MethodID
= BASE_DRAGGING
;
88 * Send this method to ourself. Eventually it will end
89 * up at the baseclass.
91 if (( dr
= DoMethodA( obj
, ( Msg
)©
)) != BDR_DRAGGING
) {
96 * The baseclass is about to start
97 * dragging the object. We de-select
100 if ( rp
= ObtainGIRPort( INPUT( msg
)->gpi_GInfo
)) {
101 SetAttrs( obj
, GA_Selected
, FALSE
, TAG_END
);
102 DoMethod( obj
, GM_RENDER
, INPUT( msg
)->gpi_GInfo
, rp
, GREDRAW_REDRAW
);
103 ReleaseGIRPort( rp
);
109 * The baseclass did not respond to the message
110 * so we will handle this event by calling the
111 * superclass (buttonclass).
113 rc
= DoSuperMethodA( cl
, obj
, msg
);
118 * Object dropped on the other object.
122 * Dropped on a non-droppable object or
123 * operation cancelled. We simply return
124 * GMR_NOREUSE in these cases.
135 * All the rest goes to the superclass...
137 rc
= DoSuperMethodA( cl
, obj
, msg
);
145 * Initialize the useless class.
147 Class
*InitUselessClass( void )
149 Class
*cl
= NULL
, *super
;
152 * Get a pointer to the ButtonClass which
155 if ( super
= BGUI_GetClassPtr( BGUI_BUTTON_GADGET
)) {
156 if ( cl
= MakeClass( NULL
, NULL
, super
, 0L, 0L ))
157 cl
->cl_Dispatcher
.h_Entry
= ( HOOKFUNC
)DispatchSB
;
165 VOID
StartDemo( void )
167 struct Window
*window
;
170 ULONG signal
= 0, rc
;
176 if ( class = InitUselessClass()) {
178 * Create the window object tree.
180 WO_Window
= WindowObject
,
181 WINDOW_Title
, "Useless ;)",
182 WINDOW_RMBTrap
, TRUE
,
183 WINDOW_AutoAspect
, TRUE
,
184 WINDOW_SizeGadget
, FALSE
,
186 VGroupObject
, NormalVOffset
, NormalHOffset
, NormalSpacing
,
188 InfoFixed( NULL
, ISEQ_C
"Useless demo. Just drag and drop the\nleft button on the right one", NULL
, 2 ), FixMinHeight
,
191 HGroupObject
, WideSpacing
,
194 * Create an object from the above
197 NewObject( class, NULL
, FuzzButtonFrame
,
198 Label( "Drag me!" ), BT_DragObject
, TRUE
, TAG_END
),
219 if ( window
= WindowOpen( WO_Window
)) {
223 GetAttr( WINDOW_SigMask
, WO_Window
, &signal
);
230 while (( rc
= HandleEvent( WO_Window
)) != WMHI_NOMORE
) {
232 case WMHI_CLOSEWINDOW
:
239 Tell( "Unable to open the window.\n" );
240 DisposeObject( WO_Window
);
242 Tell( "Unable to create the window object.\n" );
245 Tell( "Unable to initialize the class.\n" );