home *** CD-ROM | disk | FTP | other *** search
/ Magazyn Amiga 12 / MA_Cover_12.iso / libs / bgui / examples / source / useless.c < prev    next >
Encoding:
C/C++ Source or Header  |  1999-02-19  |  5.1 KB  |  227 lines

  1. /*
  2.  * @(#) $Header: /cvsroot/bgui/examples/Attic/Useless.c,v 1.1.2.1 1998/02/28 17:45:45 mlemos Exp $
  3.  *
  4.  * Useless.c
  5.  *
  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.
  10.  *
  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.
  14.  *
  15.  * This example does show you a way to handle input events
  16.  * in a class which supports dragging.
  17.  *
  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.
  21.  *
  22.  * $Log: Useless.c,v $
  23.  * Revision 1.1.2.1  1998/02/28 17:45:45  mlemos
  24.  * Ian sources
  25.  *
  26.  *
  27.  */
  28.  
  29. /* Execute me to compile with DICE V3.0
  30. dcc Useless.c -proto -mi -ms -mRR -lbgui
  31. quit
  32. */
  33.  
  34. #include "DemoCode.h"
  35.  
  36. /*
  37.  *    Simple type-cast.
  38.  */
  39. #define INPUT(x)        (( struct gpInput * )x )
  40.  
  41. /*
  42.  *    We need a simple subclass of the BGUI button class to
  43.  *    make it draggable.
  44.  */
  45. SAVEDS ASM ULONG DispatchSB( REG(a0) Class *cl, REG(a2) Object *obj, REG(a1) Msg msg )
  46. {
  47.     struct RastPort         *rp;
  48.     struct gpInput         copy;
  49.     ULONG             rc = 0L, dr;
  50.  
  51.     switch ( msg->MethodID ) {
  52.  
  53.         case    GM_HANDLEINPUT:
  54.             /*
  55.              *    Handle the input. To implement a draggable object we
  56.              *    need to call the BASE_DRAGGING method as part of our
  57.              *    input-processing code. This method will tell us what
  58.              *    to do with the input event.
  59.              */
  60.  
  61.             /*
  62.              *    Copy the input message. The BASE_DRAGGING method uses
  63.              *    the same message structure.
  64.              */
  65.             copy = *INPUT( msg );
  66.             copy.MethodID = BASE_DRAGGING;
  67.  
  68.             /*
  69.              *    Send this method to ourself. Eventually it will end
  70.              *    up at the baseclass.
  71.              */
  72.             if (( dr = DoMethodA( obj, ( Msg )© )) != BDR_DRAGGING ) {
  73.                 switch ( dr ) {
  74.  
  75.                     case    BDR_DRAGPREPARE:
  76.                         /*
  77.                          *    The baseclass is about to start
  78.                          *    dragging the object. We de-select
  79.                          *    the object.
  80.                          */
  81.                         if ( rp = ObtainGIRPort( INPUT( msg )->gpi_GInfo )) {
  82.                             SetAttrs( obj, GA_Selected, FALSE, TAG_END );
  83.                             DoMethod( obj, GM_RENDER, INPUT( msg )->gpi_GInfo, rp, GREDRAW_REDRAW );
  84.                             ReleaseGIRPort( rp );
  85.                         }
  86.                         break;
  87.  
  88.                     case    BDR_NONE:
  89.                         /*
  90.                          *    The baseclass did not respond to the message
  91.                          *    so we will handle this event by calling the
  92.                          *    superclass (buttonclass).
  93.                          */
  94.                         rc = DoSuperMethodA( cl, obj, msg );
  95.                         break;
  96.  
  97.                     case    BDR_DROP:
  98.                         /*
  99.                          *    Object dropped on the other object.
  100.                          */
  101.                     case    BDR_CANCEL:
  102.                         /*
  103.                          *    Dropped on a non-droppable object or
  104.                          *    operation cancelled. We simply return
  105.                          *    GMR_NOREUSE in these cases.
  106.                          */
  107.                         rc = GMR_NOREUSE;
  108.                         break;
  109.                 }
  110.             } else
  111.                 rc = GMR_MEACTIVE;
  112.             break;
  113.  
  114.         default:
  115.             /*
  116.              *    All the rest goes to the superclass...
  117.              */
  118.             rc = DoSuperMethodA( cl, obj, msg );
  119.             break;
  120.     }
  121.     return( rc );
  122. }
  123.  
  124. /*
  125.  *    Initialize the useless class.
  126.  */
  127. Class *InitUselessClass( void )
  128. {
  129.     Class            *cl = NULL, *super;
  130.  
  131.     /*
  132.      *    Get a pointer to the ButtonClass which
  133.      *    is our superclass.
  134.      */
  135.     if ( super = BGUI_GetClassPtr( BGUI_BUTTON_GADGET )) {
  136.         if ( cl = MakeClass( NULL, NULL, super, 0L, 0L ))
  137.             cl->cl_Dispatcher.h_Entry = ( HOOKFUNC )DispatchSB;
  138.     }
  139.     return( cl );
  140. }
  141.  
  142. /*
  143.  *    Here we go.
  144.  */
  145. VOID StartDemo( void )
  146. {
  147.     struct Window        *window;
  148.     Class            *class;
  149.     Object            *WO_Window;
  150.     ULONG             signal = 0, rc;
  151.     BOOL             running = TRUE;
  152.  
  153.     /*
  154.      *    Setup the class.
  155.      */
  156.     if ( class = InitUselessClass()) {
  157.         /*
  158.          *    Create the window object tree.
  159.          */
  160.         WO_Window = WindowObject,
  161.             WINDOW_Title,        "Useless ;)",
  162.             WINDOW_RMBTrap,         TRUE,
  163.             WINDOW_AutoAspect,    TRUE,
  164.             WINDOW_SizeGadget,    FALSE,
  165.             WINDOW_MasterGroup,
  166.                 VGroupObject, NormalVOffset, NormalHOffset, NormalSpacing,
  167.                     StartMember,
  168.                         InfoFixed( NULL, ISEQ_C "Useless demo. Just drag and drop the\nleft button on the right one", NULL, 2 ), FixMinHeight,
  169.                     EndMember,
  170.                     StartMember,
  171.                         HGroupObject, WideSpacing,
  172.                             StartMember,
  173.                                 /*
  174.                                  *    Create an object from the above
  175.                                  *    defined class.
  176.                                  */
  177.                                 NewObject( class, NULL, FuzzButtonFrame,
  178.                                     Label( "Drag me!" ), BT_DragObject, TRUE, TAG_END ),
  179.                             EndMember,
  180.                             StartMember,
  181.                                 ButtonObject,
  182.                                     FuzzButtonFrame,
  183.                                     Label( "Drop me!" ),
  184.                                     BT_DropObject, TRUE,
  185.                                 EndObject,
  186.                             EndMember,
  187.                         EndObject,
  188.                     EndMember,
  189.                 EndObject,
  190.         EndObject;
  191.  
  192.         /*
  193.          *    Object OK?
  194.          */
  195.         if ( WO_Window ) {
  196.             /*
  197.              *    Open it.
  198.              */
  199.             if ( window = WindowOpen( WO_Window )) {
  200.                 /*
  201.                  *    Get signal mask.
  202.                  */
  203.                 GetAttr( WINDOW_SigMask, WO_Window, &signal );
  204.                 do {
  205.                     Wait( signal );
  206.  
  207.                     /*
  208.                      *    Handle messages.
  209.                      */
  210.                     while (( rc = HandleEvent( WO_Window )) != WMHI_NOMORE ) {
  211.                         switch ( rc ) {
  212.                             case    WMHI_CLOSEWINDOW:
  213.                                 running = FALSE;
  214.                                 break;
  215.                         }
  216.                     }
  217.                 } while ( running );
  218.             } else
  219.                 Tell( "Unable to open the window.\n" );
  220.             DisposeObject( WO_Window );
  221.         } else
  222.             Tell( "Unable to create the window object.\n" );
  223.         FreeClass( class );
  224.     } else
  225.         Tell( "Unable to initialize the class.\n" );
  226. }
  227.