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
REGFUNC3(IPTR
, DispatchSB
,
61 REGPARAM(A0
, Class
*, cl
),
62 REGPARAM(A2
, Object
*, obj
),
63 REGPARAM(A1
, Msg
, msg
))
69 switch ( msg
->MethodID
) {
73 * Handle the input. To implement a draggable object we
74 * need to call the BASE_DRAGGING method as part of our
75 * input-processing code. This method will tell us what
76 * to do with the input event.
80 * Copy the input message. The BASE_DRAGGING method uses
81 * the same message structure.
84 copy
.MethodID
= BASE_DRAGGING
;
87 * Send this method to ourself. Eventually it will end
88 * up at the baseclass.
90 if (( dr
= DoMethodA( obj
, ( Msg
)©
)) != BDR_DRAGGING
) {
95 * The baseclass is about to start
96 * dragging the object. We de-select
99 if (( rp
= ObtainGIRPort( INPUT( msg
)->gpi_GInfo
))) {
100 SetAttrs( obj
, GA_Selected
, FALSE
, TAG_END
);
101 DoMethod( obj
, GM_RENDER
, INPUT( msg
)->gpi_GInfo
, rp
, GREDRAW_REDRAW
);
102 ReleaseGIRPort( rp
);
108 * The baseclass did not respond to the message
109 * so we will handle this event by calling the
110 * superclass (buttonclass).
112 rc
= DoSuperMethodA( cl
, obj
, msg
);
117 * Object dropped on the other object.
121 * Dropped on a non-droppable object or
122 * operation cancelled. We simply return
123 * GMR_NOREUSE in these cases.
134 * All the rest goes to the superclass...
136 rc
= DoSuperMethodA( cl
, obj
, msg
);
144 * Initialize the useless class.
146 Class
*InitUselessClass( void )
148 Class
*cl
= NULL
, *super
;
151 * Get a pointer to the ButtonClass which
154 if (( super
= BGUI_GetClassPtr( BGUI_BUTTON_GADGET
))) {
155 if (( cl
= MakeClass( NULL
, NULL
, super
, 0L, 0L )))
156 cl
->cl_Dispatcher
.h_Entry
= ( HOOKFUNC
)DispatchSB
;
164 VOID
StartDemo( void )
166 struct Window
*window
;
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" );