forgotten commit. disabled until egl is adapted.
[AROS-Contrib.git] / bgui / examples / Useless.c
blobf686e08dfb3ed0fa0d1cac944231e5fb9f5fe418
1 /*
2 * @(#) $Header$
4 * Useless.c
6 * (C) Copyright 1998 Manuel Lemos.
7 * (C) Copyright 1995-1996 Jaba Development.
8 * (C) Copyright 1995-1996 Jan van den Baard.
9 * All Rights Reserved.
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.
22 * $Log$
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
39 * Ian sources
44 /* Execute me to compile with DICE V3.0
45 dcc Useless.c -proto -mi -ms -mRR -lbgui
46 quit
49 #include "DemoCode.h"
52 * Simple type-cast.
54 #define INPUT(x) (( struct gpInput * )x )
57 * We need a simple subclass of the BGUI button class to
58 * make it draggable.
60 SAVEDS ASM REGFUNC3(IPTR, DispatchSB,
61 REGPARAM(A0, Class *, cl),
62 REGPARAM(A2, Object *, obj),
63 REGPARAM(A1, Msg, msg))
65 struct RastPort *rp;
66 struct gpInput copy;
67 IPTR rc = 0L, dr;
69 switch ( msg->MethodID ) {
71 case GM_HANDLEINPUT:
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.
83 copy = *INPUT( msg );
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 )&copy )) != BDR_DRAGGING ) {
91 switch ( dr ) {
93 case BDR_DRAGPREPARE:
95 * The baseclass is about to start
96 * dragging the object. We de-select
97 * the object.
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 );
104 break;
106 case BDR_NONE:
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 );
113 break;
115 case BDR_DROP:
117 * Object dropped on the other object.
119 case BDR_CANCEL:
121 * Dropped on a non-droppable object or
122 * operation cancelled. We simply return
123 * GMR_NOREUSE in these cases.
125 rc = GMR_NOREUSE;
126 break;
128 } else
129 rc = GMR_MEACTIVE;
130 break;
132 default:
134 * All the rest goes to the superclass...
136 rc = DoSuperMethodA( cl, obj, msg );
137 break;
139 return( rc );
141 REGFUNC_END
144 * Initialize the useless class.
146 Class *InitUselessClass( void )
148 Class *cl = NULL, *super;
151 * Get a pointer to the ButtonClass which
152 * is our superclass.
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;
158 return( cl );
162 * Here we go.
164 VOID StartDemo( void )
166 struct Window *window;
167 Class *class;
168 Object *WO_Window;
169 IPTR signal = 0;
170 ULONG rc;
171 BOOL running = TRUE;
174 * Setup the class.
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,
185 WINDOW_MasterGroup,
186 VGroupObject, NormalVOffset, NormalHOffset, NormalSpacing,
187 StartMember,
188 InfoFixed( NULL, ISEQ_C "Useless demo. Just drag and drop the\nleft button on the right one", NULL, 2 ), FixMinHeight,
189 EndMember,
190 StartMember,
191 HGroupObject, WideSpacing,
192 StartMember,
194 * Create an object from the above
195 * defined class.
197 NewObject( class, NULL, FuzzButtonFrame,
198 Label( "Drag me!" ), BT_DragObject, TRUE, TAG_END ),
199 EndMember,
200 StartMember,
201 ButtonObject,
202 FuzzButtonFrame,
203 Label( "Drop me!" ),
204 BT_DropObject, TRUE,
205 EndObject,
206 EndMember,
207 EndObject,
208 EndMember,
209 EndObject,
210 EndObject;
213 * Object OK?
215 if ( WO_Window ) {
217 * Open it.
219 if (( window = WindowOpen( WO_Window ))) {
221 * Get signal mask.
223 GetAttr( WINDOW_SigMask, WO_Window, &signal );
224 do {
225 Wait( signal );
228 * Handle messages.
230 while (( rc = HandleEvent( WO_Window )) != WMHI_NOMORE ) {
231 switch ( rc ) {
232 case WMHI_CLOSEWINDOW:
233 running = FALSE;
234 break;
237 } while ( running );
238 } else
239 Tell( "Unable to open the window.\n" );
240 DisposeObject( WO_Window );
241 } else
242 Tell( "Unable to create the window object.\n" );
243 FreeClass( class );
244 } else
245 Tell( "Unable to initialize the class.\n" );