home *** CD-ROM | disk | FTP | other *** search
/ Enigma Amiga Life 113 / EnigmaAmiga113CD.iso / software / sviluppo / fm2000 / fieldlist.h < prev    next >
Encoding:
C/C++ Source or Header  |  2000-02-04  |  7.6 KB  |  312 lines

  1. /*
  2.      Filemaster - Multitasking directory utility.
  3.      Copyright (C) 2000  Toni Wilen
  4.      
  5.      This program is free software; you can redistribute it and/or
  6.      modify it under the terms of the GNU General Public License
  7.      as published by the Free Software Foundation; either version 2
  8.      of the License, or (at your option) any later version.
  9.      
  10.      This program is distributed in the hope that it will be useful,
  11.      but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13.      GNU General Public License for more details.
  14.      
  15.      You should have received a copy of the GNU General Public License
  16.      along with this program; if not, write to the Free Software
  17.      Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  18. */
  19.  
  20. /*
  21.  *    FIELDLIST.H
  22.  *
  23.  *    (C) Copyright 1995-1996 Jaba Development.
  24.  *    (C) Copyright 1995-1996 Jan van den Baard.
  25.  *        All Rights Reserved.
  26.  *
  27.  *    This is a simple subclass of the Listview class which
  28.  *    will allow drops from another Listview object, positioned
  29.  *    drops and sortable drops.
  30.  *
  31.  *    It is included in the demonstration programs that make
  32.  *    use of it.
  33.  *
  34.  *    Tags:
  35.  *        FL_DropAccept -- A pointer to the listview object from
  36.  *                 which drops will be accepted. Ofcourse
  37.  *                 you are responsible to make sure that
  38.  *                 the entries of this object are of the
  39.  *                 same format as the entries of the
  40.  *                 target object.
  41.  *
  42.  *        FL_SortDrops -- When TRUE the class will sort the drops
  43.  *                automatically. When FALSE the drops may
  44.  *                be positioned by the user.
  45.  */
  46.  
  47. #include <proto/utility.h>
  48.  
  49. /*
  50.  *    Tags for this subclass.
  51.  */
  52. #define FL_AcceptDrop0        TAG_USER+0x2000         /* IS--- */
  53. #define FL_AcceptDrop1        TAG_USER+0x2001         /* IS--- */
  54. #define FL_AcceptDrop2        TAG_USER+0x2002         /* IS--- */
  55. #define FL_AcceptDrop3        TAG_USER+0x2003         /* IS--- */
  56. #define FL_AcceptDrop4        TAG_USER+0x2004         /* IS--- */
  57. #define FL_AcceptDrop5        TAG_USER+0x2005         /* IS--- */
  58. #define FL_SortDrops        TAG_USER+0x2006         /* IS--- */
  59. #define FL_RemoveOld        TAG_USER+0x2007
  60.  
  61. /*
  62.  *    Object instance data.
  63.  */
  64. typedef struct {
  65.     Object    *fld_Accept[6];        /* Accept drops from this object. */
  66.     BOOL     fld_SortDrops;         /* Auto-sort drops. */
  67.     BOOL     fld_RemoveOld;
  68. } FLD;
  69.  
  70. /*
  71.  *    Some easy type-casts.
  72.  */
  73. #define SET(x)        (( struct opSet * )x )
  74. #define QUERY(x)    (( struct bmDragPoint * )x )
  75. #define DROP(x)         (( struct bmDropped * )x )
  76.  
  77. /*
  78.  *    Set attributes.
  79.  */
  80.  
  81. STATIC void __saveds __asm SetFLAttr(register __a0 FLD *fld, register __a1 struct TagItem *attr )
  82. {
  83.     struct TagItem        *tag, *tstate = attr;
  84.  
  85.     /*
  86.      *    Scan attribute list.
  87.      */
  88.     while ( tag = NextTagItem( &tstate )) {
  89.         switch ( tag->ti_Tag ) {
  90.  
  91.             case    FL_AcceptDrop0:
  92.                 fld->fld_Accept[0] = ( Object * )tag->ti_Data;
  93.                 break;
  94.             case    FL_AcceptDrop1:
  95.                 fld->fld_Accept[1] = ( Object * )tag->ti_Data;
  96.                 break;
  97.             case    FL_AcceptDrop2:
  98.                 fld->fld_Accept[2] = ( Object * )tag->ti_Data;
  99.                 break;
  100.             case    FL_AcceptDrop3:
  101.                 fld->fld_Accept[3] = ( Object * )tag->ti_Data;
  102.                 break;
  103.             case    FL_AcceptDrop4:
  104.                 fld->fld_Accept[4] = ( Object * )tag->ti_Data;
  105.                 break;
  106.             case    FL_AcceptDrop5:
  107.                 fld->fld_Accept[5] = ( Object * )tag->ti_Data;
  108.                 break;
  109.  
  110.             case    FL_SortDrops:
  111.                 fld->fld_SortDrops = tag->ti_Data;
  112.                 break;
  113.  
  114.             case    FL_RemoveOld:
  115.                 fld->fld_RemoveOld = tag->ti_Data;
  116.                 break;
  117.         }
  118.     }
  119. }
  120.  
  121. /*
  122.  *    Class dispatcher. Remember! NOSTACKCHECK or __interrupt for
  123.  *    SAS users!
  124.  */
  125. STATIC ULONG __saveds __asm DispatchFL(register __a0 Class *cl,register __a2 Object *obj, register __a1 Msg msg )
  126. {
  127.     FLD               *fld,*fld2;
  128.     APTR            entry;
  129.     struct IBox           *ib;
  130.     ULONG            rc, spot;
  131. ULONG *acceptapu;
  132. WORD cnt1;
  133.  
  134.     /*
  135.      *    What do they want...
  136.      */
  137.     switch ( msg->MethodID ) {
  138.  
  139.         case    OM_NEW:
  140.             /*
  141.              *    Let the superclass make the object.
  142.              */
  143.             if ( rc = DoSuperMethodA( cl, obj, msg )) {
  144.                 /*
  145.                  *    Get instance data.
  146.                  */
  147.                 fld = ( FLD * )INST_DATA( cl, rc );
  148.  
  149.                 /*
  150.                  *    Set defaults.
  151.                  */
  152.                 fld->fld_Accept[0]    = NULL;
  153.                 fld->fld_Accept[1]    = NULL;
  154.                 fld->fld_Accept[2]    = NULL;
  155.                 fld->fld_Accept[3]    = NULL;
  156.                 fld->fld_Accept[4]    = NULL;
  157.                 fld->fld_Accept[5]    = NULL;
  158.                 fld->fld_SortDrops = FALSE;
  159.                 fld->fld_RemoveOld = FALSE;
  160.  
  161.                 /*
  162.                  *    Get attributes.
  163.                  */
  164.                 SetFLAttr( fld, SET( msg )->ops_AttrList );
  165.             }
  166.             break;
  167.  
  168.         case    OM_SET:
  169.             /*
  170.              *    First the superclass.
  171.              */
  172.             rc = DoSuperMethodA( cl, obj, msg );
  173.  
  174.             /*
  175.              *    Then we have a go.
  176.              */
  177.             fld = ( FLD * )INST_DATA( cl, obj );
  178.             SetFLAttr( fld, SET( msg )->ops_AttrList );
  179.             break;
  180.  
  181.         case    BASE_DRAGQUERY:
  182.             /*
  183.              *    We only allow drops from ourselves and from
  184.              *    the object specified with FL_AcceptDrop.
  185.              */
  186.  
  187.             /*
  188.              *    We let the superclass worry about it when
  189.              *    the requesting object request is us.
  190.              */
  191.             if ( QUERY( msg )->bmdp_Source == obj )
  192.                 return( DoSuperMethodA( cl, obj, msg ));
  193.  
  194.             /*
  195.              *    Get instance data.
  196.              */
  197.             fld = ( FLD * )INST_DATA( cl, obj );
  198.  
  199.             /*
  200.              *    Is it the object specified with FL_AcceptDrop?
  201.              */
  202.             acceptapu=QUERY(msg)->bmdp_Source;
  203.             for(cnt1=0;cnt1<6;cnt1++) {
  204.                 if(acceptapu&&acceptapu==fld->fld_Accept[cnt1]) break;
  205.             }
  206.             if ( cnt1<6) {
  207.                 /*
  208.                  *    Get the listview class list bounds.
  209.                  */
  210.                 GetAttr( LISTV_ViewBounds, obj, ( ULONG * )&ib );
  211.  
  212.                 /*
  213.                  *    Mouse inside view bounds? Since the superclass
  214.                  *    starts sending this message when the mouse goes
  215.                  *    inside the hitbox we only need to check if it
  216.                  *    is not located right of the view area.
  217.                  */
  218.                 if ( QUERY( msg )->bmdp_Mouse.X < ib->Width )
  219.                     return( BQR_ACCEPT );
  220.             }
  221.  
  222.             /*
  223.              *    Screw the rest...
  224.              */
  225.             rc = BQR_REJECT;
  226.  
  227.             break;
  228.  
  229.         case    BASE_DROPPED:
  230.             /*
  231.              *    If the drop comes from ourself we let the
  232.              *    superclass handle it.
  233.              */
  234.             if ( DROP( msg )->bmd_Source == obj )
  235.                 return( DoSuperMethodA( cl, obj, msg ));
  236.  
  237.             /*
  238.              *    Get instance data.
  239.              */
  240.             fld = ( FLD * )INST_DATA( cl, obj );
  241.  
  242.             /*
  243.              *    Find out where the drop was made.
  244.              */
  245.             GetAttr( LISTV_DropSpot, obj, &spot );
  246.  
  247.             /*
  248.              *    Simply pick up all selected entries
  249.              *    from the dragged object.
  250.              */
  251.             while ( entry = ( APTR )FirstSelected( DROP( msg )->bmd_Source )) {
  252.                 /*
  253.                  *    Set it on ourselves. We insert it when we are
  254.                  *    not sortable. We add them sorted when we are
  255.                  *    sortable.
  256.                  */
  257.                 if ( fld->fld_SortDrops == FALSE ) DoMethod( obj, LVM_INSERTSINGLE, NULL, spot, entry, LVASF_SELECT );
  258.                 else                   DoMethod( obj, LVM_ADDSINGLE, NULL, entry, LVAP_SORTED, LVASF_SELECT );
  259.  
  260.                 /*
  261.                  *    Remove it from the dropped object.
  262.                  */
  263.                 fld2=(FLD*)INST_DATA(cl,DROP(msg)->bmd_Source);
  264.                 if(fld2->fld_RemoveOld) DoMethod( DROP( msg )->bmd_Source, LVM_REMENTRY, NULL, entry );
  265.             }
  266.  
  267.             /*
  268.              *    Refresh the dragged object. We do not have to
  269.              *    refresh ourselves since the base class will
  270.              *    do this for us when we are deactivated.
  271.              */
  272.             BGUI_DoGadgetMethod( DROP( msg )->bmd_Source,
  273.                          DROP( msg )->bmd_SourceWin,
  274.                          DROP( msg )->bmd_SourceReq,
  275.                          LVM_REFRESH, NULL );
  276.             rc = 1;
  277.             break;
  278.  
  279.         default:
  280.             /*
  281.              *    Let's the superclass handle the rest.
  282.              */
  283.             rc = DoSuperMethodA( cl, obj, msg );
  284.             break;
  285.     }
  286.     return( rc );
  287. }
  288.  
  289. /*
  290.  *    Simple class initialization.
  291.  */
  292. Class *InitFLClass( void )
  293. {
  294.     Class            *super, *cl = NULL;
  295.  
  296.     /*
  297.      *    Obtain the ListviewClass pointer which
  298.      *    will be our superclass.
  299.      */
  300.     if ( super = BGUI_GetClassPtr( BGUI_LISTVIEW_GADGET )) {
  301.         /*
  302.          *    Create the class.
  303.          */
  304.         if ( cl = MakeClass( NULL, NULL, super, sizeof( FLD ), 0L ))
  305.             /*
  306.              *    Setup dispatcher.
  307.              */
  308.             cl->cl_Dispatcher.h_Entry = ( HOOKFUNC )DispatchFL;
  309.     }
  310.     return( cl );
  311. }
  312.