build git 2.17.1
[AROS-Contrib.git] / bgui / examples / FieldList.h
blobb8b65d55c6dd5f1376aee4af8994d5f2659319bd
1 /*
2 * @(#) $Header$
4 * FieldList.h
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 a simple subclass of the Listview class which
12 * will allow drops from another Listview object, positioned
13 * drops and sortable drops.
15 * It is included in the demonstration programs that make
16 * use of it.
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.
26 * FL_SortDrops -- When TRUE the class will sort the drops
27 * automatically. When FALSE the drops may
28 * be positioned by the user.
30 * $Log$
31 * Revision 42.2 2004/06/17 07:38:47 chodorowski
32 * Added missing REGFUNC_END.
34 * Revision 42.1 2000/05/15 19:28:19 stegerg
35 * REG() macro replacementes
37 * Revision 42.0 2000/05/09 22:19:43 mlemos
38 * Bumped to revision 42.0 before handing BGUI to AROS team
40 * Revision 41.11 2000/05/09 20:33:33 mlemos
41 * Bumped to revision 41.11
43 * Revision 1.2 2000/05/09 19:58:52 mlemos
44 * Merged with the branch Manuel_Lemos_fixes.
46 * Revision 1.1.2.2 1999/02/19 05:03:52 mlemos
47 * Added support to build with Storm C.
49 * Revision 1.1.2.1 1998/02/28 17:45:52 mlemos
50 * Ian sources
55 #include <proto/utility.h>
58 * Tags for this subclass.
60 #define FL_AcceptDrop TAG_USER+0x2000 /* IS--- */
61 #define FL_SortDrops TAG_USER+0x2001 /* IS--- */
64 * Object instance data.
66 typedef struct {
67 Object *fld_Accept; /* Accept drops from this object. */
68 BOOL fld_SortDrops; /* Auto-sort drops. */
69 } FLD;
72 * Some easy type-casts.
74 #define SET(x) (( struct opSet * )x )
75 #define QUERY(x) (( struct bmDragPoint * )x )
76 #define DROP(x) (( struct bmDropped * )x )
79 * Set attributes.
81 STATIC ASM VOID SetFLAttr( REG(a0) FLD *fld, REG(a1) struct TagItem *attr )
83 struct TagItem *tag;
84 struct TagItem *tstate = attr;
87 * Scan attribute list.
89 while (( tag = NextTagItem( &tstate ))) {
90 switch ( tag->ti_Tag ) {
92 case FL_AcceptDrop:
93 fld->fld_Accept = ( Object * )tag->ti_Data;
94 break;
96 case FL_SortDrops:
97 fld->fld_SortDrops = tag->ti_Data;
98 break;
104 * Class dispatcher. Remember! NOSTACKCHECK or __interrupt for
105 * SAS users!
107 REGFUNC3(IPTR SAVEDS ASM,DispatchFL,
108 REGPARAM(A0, Class *, cl),
109 REGPARAM(A2, Object *, obj),
110 REGPARAM(A1, Msg, msg))
112 FLD *fld;
113 APTR entry;
114 struct IBox *ib;
115 IPTR rc, spot;
118 * What do they want...
120 switch ( msg->MethodID ) {
122 case OM_NEW:
124 * Let the superclass make the object.
126 if (( rc = DoSuperMethodA( cl, obj, msg ))) {
128 * Get instance data.
130 fld = ( FLD * )INST_DATA( cl, rc );
133 * Set defaults.
135 fld->fld_Accept = NULL;
136 fld->fld_SortDrops = FALSE;
139 * Get attributes.
141 SetFLAttr( fld, SET( msg )->ops_AttrList );
143 break;
145 case OM_SET:
147 * First the superclass.
149 rc = DoSuperMethodA( cl, obj, msg );
152 * Then we have a go.
154 fld = ( FLD * )INST_DATA( cl, obj );
155 SetFLAttr( fld, SET( msg )->ops_AttrList );
156 break;
158 case BASE_DRAGQUERY:
160 * We only allow drops from ourselves and from
161 * the object specified with FL_AcceptDrop.
165 * We let the superclass worry about it when
166 * the requesting object request is us.
168 if ( QUERY( msg )->bmdp_Source == obj )
169 return( DoSuperMethodA( cl, obj, msg ));
172 * Get instance data.
174 fld = ( FLD * )INST_DATA( cl, obj );
177 * Is it the object specified with FL_AcceptDrop?
179 if ( QUERY( msg )->bmdp_Source == fld->fld_Accept ) {
181 * Get the listview class list bounds.
183 GetAttr( LISTV_ViewBounds, obj, ( IPTR * )&ib );
186 * Mouse inside view bounds? Since the superclass
187 * starts sending this message when the mouse goes
188 * inside the hitbox we only need to check if it
189 * is not located right of the view area.
191 if ( QUERY( msg )->bmdp_Mouse.X < ib->Width )
192 return( BQR_ACCEPT );
196 * Screw the rest...
198 rc = BQR_REJECT;
200 break;
202 case BASE_DROPPED:
204 * If the drop comes from ourself we let the
205 * superclass handle it.
207 if ( DROP( msg )->bmd_Source == obj )
208 return( DoSuperMethodA( cl, obj, msg ));
211 * Get instance data.
213 fld = ( FLD * )INST_DATA( cl, obj );
216 * Find out where the drop was made.
218 GetAttr( LISTV_DropSpot, obj, &spot );
221 * Simply pick up all selected entries
222 * from the dragged object.
224 while (( entry = ( APTR )FirstSelected( DROP( msg )->bmd_Source ))) {
226 * Set it on ourselves. We insert it when we are
227 * not sortable. We add them sorted when we are
228 * sortable.
230 if ( fld->fld_SortDrops == FALSE ) DoMethod( obj, LVM_INSERTSINGLE, NULL, spot, entry, LVASF_SELECT );
231 else DoMethod( obj, LVM_ADDSINGLE, NULL, entry, LVAP_SORTED, LVASF_SELECT );
234 * Remove it from the dropped object.
236 DoMethod( DROP( msg )->bmd_Source, LVM_REMENTRY, NULL, entry );
240 * Refresh the dragged object. We do not have to
241 * refresh ourselves since the base class will
242 * do this for us when we are deactivated.
244 BGUI_DoGadgetMethod( DROP( msg )->bmd_Source,
245 DROP( msg )->bmd_SourceWin,
246 DROP( msg )->bmd_SourceReq,
247 LVM_REFRESH, NULL );
248 rc = 1;
249 break;
251 default:
253 * Let's the superclass handle the rest.
255 rc = DoSuperMethodA( cl, obj, msg );
256 break;
258 return( rc );
261 REGFUNC_END
264 * Simple class initialization.
266 Class *InitFLClass( void )
268 Class *super, *cl = NULL;
271 * Obtain the ListviewClass pointer which
272 * will be our superclass.
274 if (( super = BGUI_GetClassPtr( BGUI_LISTVIEW_GADGET ))) {
276 * Create the class.
278 if (( cl = MakeClass( NULL, NULL, super, sizeof( FLD ), 0L )))
280 * Setup dispatcher.
282 cl->cl_Dispatcher.h_Entry = ( HOOKFUNC )DispatchFL;
284 return( cl );