Replaced System by SYS because on "native" the volume name of the system partition...
[AROS-Contrib.git] / bgui / examples / Useless.c
blobd3829338e1e454a820f0232c0cb289bc63757b0c
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 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))
66 struct RastPort *rp;
67 struct gpInput copy;
68 ULONG rc = 0L, dr;
70 switch ( msg->MethodID ) {
72 case GM_HANDLEINPUT:
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.
84 copy = *INPUT( msg );
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 )&copy )) != BDR_DRAGGING ) {
92 switch ( dr ) {
94 case BDR_DRAGPREPARE:
96 * The baseclass is about to start
97 * dragging the object. We de-select
98 * the object.
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 );
105 break;
107 case BDR_NONE:
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 );
114 break;
116 case BDR_DROP:
118 * Object dropped on the other object.
120 case BDR_CANCEL:
122 * Dropped on a non-droppable object or
123 * operation cancelled. We simply return
124 * GMR_NOREUSE in these cases.
126 rc = GMR_NOREUSE;
127 break;
129 } else
130 rc = GMR_MEACTIVE;
131 break;
133 default:
135 * All the rest goes to the superclass...
137 rc = DoSuperMethodA( cl, obj, msg );
138 break;
140 return( rc );
142 REGFUNC_END
145 * Initialize the useless class.
147 Class *InitUselessClass( void )
149 Class *cl = NULL, *super;
152 * Get a pointer to the ButtonClass which
153 * is our superclass.
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;
159 return( cl );
163 * Here we go.
165 VOID StartDemo( void )
167 struct Window *window;
168 Class *class;
169 Object *WO_Window;
170 ULONG signal = 0, 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" );