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

  1. /*
  2.  * @(#) $Header: /cvsroot/bgui/examples/Attic/FieldList.h,v 1.1.2.2 1999/02/19 05:03:52 mlemos Exp $
  3.  *
  4.  * FieldList.h
  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 a simple subclass of the Listview class which
  12.  * will allow drops from another Listview object, positioned
  13.  * drops and sortable drops.
  14.  *
  15.  * It is included in the demonstration programs that make
  16.  * use of it.
  17.  *
  18.  * Tags:
  19.  *  FL_DropAccept -- A pointer to the listview object from
  20.  *    which drops will be accepted. Ofcourse
  21.  *    you are responsible to make sure that
  22.  *    the entries of this object are of the
  23.  *    same format as the entries of the
  24.  *    target object.
  25.  *
  26.  *  FL_SortDrops -- When TRUE the class will sort the drops
  27.  *    automatically. When FALSE the drops may
  28.  *    be positioned by the user.
  29.  *
  30.  * $Log: FieldList.h,v $
  31.  * Revision 1.1.2.2  1999/02/19 05:03:52  mlemos
  32.  * Added support to build with Storm C.
  33.  *
  34.  * Revision 1.1.2.1  1998/02/28 17:45:52  mlemos
  35.  * Ian sources
  36.  *
  37.  *
  38.  */
  39.  
  40. #include <proto/utility.h>
  41.  
  42. /*
  43.  *    Tags for this subclass.
  44.  */
  45. #define FL_AcceptDrop        TAG_USER+0x2000         /* IS--- */
  46. #define FL_SortDrops        TAG_USER+0x2001         /* IS--- */
  47.  
  48. /*
  49.  *    Object instance data.
  50.  */
  51. typedef struct {
  52.     Object            *fld_Accept;        /* Accept drops from this object. */
  53.     BOOL             fld_SortDrops;         /* Auto-sort drops. */
  54. } FLD;
  55.  
  56. /*
  57.  *    Some easy type-casts.
  58.  */
  59. #define SET(x)        (( struct opSet * )x )
  60. #define QUERY(x)    (( struct bmDragPoint * )x )
  61. #define DROP(x)         (( struct bmDropped * )x )
  62.  
  63. /*
  64.  *    Set attributes.
  65.  */
  66. STATIC ASM VOID SetFLAttr( REG(a0) FLD *fld, REG(a1) struct TagItem *attr )
  67. {
  68.     struct TagItem        *tag, *tstate = attr;
  69.  
  70.     /*
  71.      *    Scan attribute list.
  72.      */
  73.     while ( tag = NextTagItem( &tstate )) {
  74.         switch ( tag->ti_Tag ) {
  75.  
  76.             case    FL_AcceptDrop:
  77.                 fld->fld_Accept = ( Object * )tag->ti_Data;
  78.                 break;
  79.  
  80.             case    FL_SortDrops:
  81.                 fld->fld_SortDrops = tag->ti_Data;
  82.                 break;
  83.         }
  84.     }
  85. }
  86.  
  87. /*
  88.  *    Class dispatcher. Remember! NOSTACKCHECK or __interrupt for
  89.  *    SAS users!
  90.  */
  91. #ifdef __STORM__
  92. STATIC ULONG SAVEDS ASM
  93. #else
  94. STATIC SAVEDS ASM ULONG
  95. #endif
  96. DispatchFL( REG(a0) Class *cl, REG(a2) Object *obj, REG(a1) Msg msg )
  97. {
  98.     FLD               *fld;
  99.     APTR            entry;
  100.     struct IBox           *ib;
  101.     ULONG            rc, spot;
  102.  
  103.     /*
  104.      *    What do they want...
  105.      */
  106.     switch ( msg->MethodID ) {
  107.  
  108.         case    OM_NEW:
  109.             /*
  110.              *    Let the superclass make the object.
  111.              */
  112.             if ( rc = DoSuperMethodA( cl, obj, msg )) {
  113.                 /*
  114.                  *    Get instance data.
  115.                  */
  116.                 fld = ( FLD * )INST_DATA( cl, rc );
  117.  
  118.                 /*
  119.                  *    Set defaults.
  120.                  */
  121.                 fld->fld_Accept    = NULL;
  122.                 fld->fld_SortDrops = FALSE;
  123.  
  124.                 /*
  125.                  *    Get attributes.
  126.                  */
  127.                 SetFLAttr( fld, SET( msg )->ops_AttrList );
  128.             }
  129.             break;
  130.  
  131.         case    OM_SET:
  132.             /*
  133.              *    First the superclass.
  134.              */
  135.             rc = DoSuperMethodA( cl, obj, msg );
  136.  
  137.             /*
  138.              *    Then we have a go.
  139.              */
  140.             fld = ( FLD * )INST_DATA( cl, obj );
  141.             SetFLAttr( fld, SET( msg )->ops_AttrList );
  142.             break;
  143.  
  144.         case    BASE_DRAGQUERY:
  145.             /*
  146.              *    We only allow drops from ourselves and from
  147.              *    the object specified with FL_AcceptDrop.
  148.              */
  149.  
  150.             /*
  151.              *    We let the superclass worry about it when
  152.              *    the requesting object request is us.
  153.              */
  154.             if ( QUERY( msg )->bmdp_Source == obj )
  155.                 return( DoSuperMethodA( cl, obj, msg ));
  156.  
  157.             /*
  158.              *    Get instance data.
  159.              */
  160.             fld = ( FLD * )INST_DATA( cl, obj );
  161.  
  162.             /*
  163.              *    Is it the object specified with FL_AcceptDrop?
  164.              */
  165.             if ( QUERY( msg )->bmdp_Source == fld->fld_Accept ) {
  166.                 /*
  167.                  *    Get the listview class list bounds.
  168.                  */
  169.                 GetAttr( LISTV_ViewBounds, obj, ( ULONG * )&ib );
  170.  
  171.                 /*
  172.                  *    Mouse inside view bounds? Since the superclass
  173.                  *    starts sending this message when the mouse goes
  174.                  *    inside the hitbox we only need to check if it
  175.                  *    is not located right of the view area.
  176.                  */
  177.                 if ( QUERY( msg )->bmdp_Mouse.X < ib->Width )
  178.                     return( BQR_ACCEPT );
  179.             }
  180.  
  181.             /*
  182.              *    Screw the rest...
  183.              */
  184.             rc = BQR_REJECT;
  185.  
  186.             break;
  187.  
  188.         case    BASE_DROPPED:
  189.             /*
  190.              *    If the drop comes from ourself we let the
  191.              *    superclass handle it.
  192.              */
  193.             if ( DROP( msg )->bmd_Source == obj )
  194.                 return( DoSuperMethodA( cl, obj, msg ));
  195.  
  196.             /*
  197.              *    Get instance data.
  198.              */
  199.             fld = ( FLD * )INST_DATA( cl, obj );
  200.  
  201.             /*
  202.              *    Find out where the drop was made.
  203.              */
  204.             GetAttr( LISTV_DropSpot, obj, &spot );
  205.  
  206.             /*
  207.              *    Simply pick up all selected entries
  208.              *    from the dragged object.
  209.              */
  210.             while ( entry = ( APTR )FirstSelected( DROP( msg )->bmd_Source )) {
  211.                 /*
  212.                  *    Set it on ourselves. We insert it when we are
  213.                  *    not sortable. We add them sorted when we are
  214.                  *    sortable.
  215.                  */
  216.                 if ( fld->fld_SortDrops == FALSE ) DoMethod( obj, LVM_INSERTSINGLE, NULL, spot, entry, LVASF_SELECT );
  217.                 else                   DoMethod( obj, LVM_ADDSINGLE, NULL, entry, LVAP_SORTED, LVASF_SELECT );
  218.  
  219.                 /*
  220.                  *    Remove it from the dropped object.
  221.                  */
  222.                 DoMethod( DROP( msg )->bmd_Source, LVM_REMENTRY, NULL, entry );
  223.             }
  224.  
  225.             /*
  226.              *    Refresh the dragged object. We do not have to
  227.              *    refresh ourselves since the base class will
  228.              *    do this for us when we are deactivated.
  229.              */
  230.             BGUI_DoGadgetMethod( DROP( msg )->bmd_Source,
  231.                          DROP( msg )->bmd_SourceWin,
  232.                          DROP( msg )->bmd_SourceReq,
  233.                          LVM_REFRESH, NULL );
  234.             rc = 1;
  235.             break;
  236.  
  237.         default:
  238.             /*
  239.              *    Let's the superclass handle the rest.
  240.              */
  241.             rc = DoSuperMethodA( cl, obj, msg );
  242.             break;
  243.     }
  244.     return( rc );
  245. }
  246.  
  247. /*
  248.  *    Simple class initialization.
  249.  */
  250. Class *InitFLClass( void )
  251. {
  252.     Class            *super, *cl = NULL;
  253.  
  254.     /*
  255.      *    Obtain the ListviewClass pointer which
  256.      *    will be our superclass.
  257.      */
  258.     if ( super = BGUI_GetClassPtr( BGUI_LISTVIEW_GADGET )) {
  259.         /*
  260.          *    Create the class.
  261.          */
  262.         if ( cl = MakeClass( NULL, NULL, super, sizeof( FLD ), 0L ))
  263.             /*
  264.              *    Setup dispatcher.
  265.              */
  266.             cl->cl_Dispatcher.h_Entry = ( HOOKFUNC )DispatchFL;
  267.     }
  268.     return( cl );
  269. }
  270.