home *** CD-ROM | disk | FTP | other *** search
/ Amiga ISO Collection / AmigaUtilCD2.iso / Misc / tollmanager3.lha / toolmanager3 / ToolManagerSrc.lha / ToolManager / Source / Prefs / cliplist.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-02-22  |  8.1 KB  |  308 lines

  1. /*
  2.  * cliplist.c  V3.0
  3.  *
  4.  * Class for TM objects clipboard window
  5.  *
  6.  * Copyright (C) 1990-97 Stefan Becker
  7.  *
  8.  * This source code is for educational purposes only. You may study it
  9.  * and copy ideas or algorithms from it for your own projects. It is
  10.  * not allowed to use any of the source codes (in full or in parts)
  11.  * in other programs. Especially it is not allowed to create variants
  12.  * of ToolManager or ToolManager-like programs from this source code.
  13.  *
  14.  */
  15.  
  16. #include "toolmanager.h"
  17.  
  18. /* ClipList class instance data */
  19. struct ClipListClassData {
  20.  struct Hook clcd_Construct;
  21. };
  22. #define TYPED_INST_DATA(cl, o) ((struct ClipListClassData *) INST_DATA((cl), (o)))
  23.  
  24. /* ClipList class construct function */
  25. #undef  DEBUGFUNCTION
  26. #define DEBUGFUNCTION ClipListClassConstruct
  27. __geta4 static ULONG ClipListClassConstruct(__a0 struct Hook *h,
  28.                                             __a1 Object *obj)
  29. {
  30.  /* Attach to object */
  31.  return((ULONG) DoMethod(obj, TMM_Attach, h->h_Data));
  32. }
  33.  
  34. /* ClipList class destruct function */
  35. #undef  DEBUGFUNCTION
  36. #define DEBUGFUNCTION ClipListClassDestruct
  37. __geta4 static void ClipListClassDestruct(__a1 struct AttachData *ad)
  38. {
  39.  /* Detach from object if not a notify event */
  40.  if (ad->ad_Object) DoMethod(ad->ad_Object, TMM_Detach, ad);
  41. }
  42.  
  43. /* ClipList class display function */
  44. #undef  DEBUGFUNCTION
  45. #define DEBUGFUNCTION ClipListClassDisplay
  46. __geta4 static void ClipListClassDisplay(__a1 struct AttachData *ad,
  47.                                          __a2 const char **array)
  48. {
  49.  /* Get object name */
  50.  GetAttr(TMA_Name, ad->ad_Object,  (ULONG *) array);
  51. }
  52.  
  53. /* Hooks */
  54. static const struct Hook DestructHook = {
  55.  {NULL, NULL}, (void *) ClipListClassDestruct, NULL, NULL
  56. };
  57. static const struct Hook DisplayHook = {
  58.  {NULL, NULL}, (void *) ClipListClassDisplay, NULL, NULL
  59. };
  60.  
  61. /* ClipList class method: OM_NEW */
  62. #define DEBUGFUNCTION ClipListClassNew
  63. static ULONG ClipListClassNew(Class *cl, Object *obj, struct opSet *ops)
  64. {
  65.  CLIPLIST_LOG((LOG1(Tags, "0x%08lx", ops->ops_AttrList),
  66.                PrintTagList(ops->ops_AttrList)))
  67.  
  68.  /* Create object */
  69.  if (obj = (Object *) DoSuperNew(cl, obj,
  70.                                  MUIA_List_DestructHook,  &DestructHook,
  71.                                  MUIA_List_DisplayHook,   &DisplayHook,
  72.                                  MUIA_List_ShowDropMarks, FALSE,
  73.                                  TAG_MORE,               ops->ops_AttrList)) {
  74.   struct ClipListClassData *clcd = TYPED_INST_DATA(cl, obj);
  75.  
  76.   /* Initialize construct hook */
  77.   clcd->clcd_Construct.h_Entry = (void *) ClipListClassConstruct;
  78.   clcd->clcd_Construct.h_Data  = obj;
  79.  
  80.   /* Set construct hook */
  81.   SetAttrs(obj, MUIA_List_ConstructHook, &clcd->clcd_Construct, TAG_DONE);
  82.  }
  83.  
  84.  CLIPLIST_LOG(LOG1(Result, "0x%08lx", obj))
  85.  
  86.  /* Return pointer to created object */
  87.  return((ULONG) obj);
  88. }
  89.  
  90. /* ClipList class method: OM_GET */
  91. #undef  DEBUGFUNCTION
  92. #define DEBUGFUNCTION ClipListClassGet
  93. static ULONG ClipListClassGet(Class *cl, Object *obj, struct opGet *opg)
  94. {
  95.  ULONG rc;
  96.  
  97.  CLIPLIST_LOG(LOG2(Attribute, "0x%08lx (%s)", opg->opg_AttrID,
  98.                    GetTagName(opg->opg_AttrID)))
  99.  
  100.  /* Which attribute is requested? */
  101.  switch(opg->opg_AttrID) {
  102.   case TMA_Active: {
  103.     struct AttachData *ad;
  104.  
  105.     /* Get active entry */
  106.     DoMethod(obj, MUIM_List_GetEntry, MUIV_List_GetEntry_Active,
  107.              (ULONG *) &ad);
  108.  
  109.     /* If active entry is valid return pointer to attached object */
  110.     *opg->opg_Storage = (ULONG) (ad ? ad->ad_Object : NULL);
  111.  
  112.     /* Return TRUE to indicate that the attribute is implemented */
  113.     rc = TRUE;
  114.    }
  115.    break;
  116.  
  117.   default:
  118.    rc = DoSuperMethodA(cl, obj, (Msg) opg);
  119.    break;
  120.  }
  121.  
  122.  CLIPLIST_LOG(LOG2(Result, "%ld value 0x%08lx", rc, *opg->opg_Storage))
  123.  
  124.  return(rc);
  125. }
  126.  
  127. /* ClipList class method: MUIM_DragQuery */
  128. #undef  DEBUGFUNCTION
  129. #define DEBUGFUNCTION ClipListClassDragQuery
  130. static ULONG ClipListClassDragQuery(Class *cl, Object *obj,
  131.                                     struct MUIP_DragQuery *mpdq)
  132. {
  133.  ULONG rc = MUIV_DragQuery_Refuse;
  134.  
  135. #if DEBUG_VERY_NOISY
  136.  /* This just generates too much debug output... */
  137.  CLIPLIST_LOG(LOG2(Arguments, "Object 0x%08lx Source 0x%08lx", obj,
  138.                    mpdq->obj))
  139. #endif
  140.  
  141.  /* Is source our list? */
  142.  if (mpdq->obj != obj) {
  143.   Object *active;
  144.   ULONG   type   = TMOBJTYPES;
  145.  
  146.   /* No, get active entry */
  147.   if (GetAttr(TMA_Active, mpdq->obj, (ULONG *) &active))
  148.  
  149.    /* Get type of object */
  150.    GetAttr(TMA_Type, active, &type);
  151.  
  152.   /* Check type, only Exec, Image and Sound objects are accepted */
  153.   if (type <= TMOBJTYPE_SOUND) rc = MUIV_DragQuery_Accept;
  154.  }
  155.  
  156.  return(rc);
  157. }
  158.  
  159. /* ClipList class method: MUIM_DragDrop */
  160. #undef  DEBUGFUNCTION
  161. #define DEBUGFUNCTION ClipListClassDragDrop
  162. static ULONG ClipListClassDragDrop(Class *cl, Object *obj,
  163.                                    struct MUIP_DragDrop *mpdd)
  164. {
  165.  Object *active;
  166.  
  167.  /* Get active entry */
  168.  GetAttr(TMA_Active, mpdd->obj, (ULONG *) &active);
  169.  
  170.  CLIPLIST_LOG(LOG1(Object, "0x%08lx", active))
  171.  
  172.  /* Insert object */
  173.  DoMethod(obj, MUIM_List_InsertSingle, active, MUIV_List_Insert_Bottom);
  174.  
  175.  /* Return 1 to indicate that the method is implemented */
  176.  return(1);
  177. }
  178.  
  179. /* ClipList class method: TMM_Notify */
  180. #undef  DEBUGFUNCTION
  181. #define DEBUGFUNCTION ClipListClassNotify
  182. static ULONG ClipListClassNotify(Class *cl, Object *obj,
  183.                                  struct TMP_Notify *tmpn)
  184. {
  185.  int                i  = -1;
  186.  struct AttachData *ad;
  187.  
  188.  CLIPLIST_LOG(LOG2(Arguments, "Attach 0x%08lx Object 0x%08lx",
  189.                    tmpn->tmpn_Data, tmpn->tmpn_Data->ad_Object))
  190.  
  191.  /* For each entry in list */
  192.  do {
  193.  
  194.   /* Get next entry */
  195.   DoMethod(obj, MUIM_List_GetEntry, ++i, &ad);
  196.  
  197.   CLIPLIST_LOG(LOG1(Next entry, "0x%08lx", ad))
  198.  
  199.   /* AttachData found? */
  200.   if (ad == tmpn->tmpn_Data) {
  201.    ULONG method;
  202.  
  203.    /* Object deleted? Yes, remove entry, otherwise redraw it */
  204.    method = (tmpn->tmpn_Data->ad_Object == NULL) ? MUIM_List_Remove :
  205.                                                    MUIM_List_Redraw;
  206.  
  207.    CLIPLIST_LOG(LOG1(Method, "0x%08lx", method))
  208.  
  209.    /* Call method */
  210.    DoMethod(obj, method, i);
  211.  
  212.    /* Leave loop */
  213.    break;
  214.   }
  215.  
  216.  } while (ad);
  217.  
  218.  /* Return 1 to indicate that the method is implemented */
  219.  return(1);
  220. }
  221.  
  222. /* ClipList class method: TMM_DoubleClicked */
  223. #undef  DEBUGFUNCTION
  224. #define DEBUGFUNCTION ClipListClassDoubleClicked
  225. static ULONG ClipListClassDoubleClicked(Class *cl, Object *obj)
  226. {
  227.  struct AttachData *ad;
  228.  
  229.  CLIPLIST_LOG(LOG0(Entry))
  230.  
  231.  /* Get active entry */
  232.  DoMethod(obj, MUIM_List_GetEntry, MUIV_List_GetEntry_Active, &ad);
  233.  
  234.  /* Call Edit method on the object */
  235.  DoMethod(ad->ad_Object, TMM_Edit, NULL);
  236.  
  237.  /* Return 1 to indicate that the method is implemented */
  238.  return(1);
  239. }
  240.  
  241. /* ClipList class method dispatcher */
  242. #undef  DEBUGFUNCTION
  243. #define DEBUGFUNCTION ClipListClassDispatcher
  244. __geta4 static ULONG ClipListClassDispatcher(__a0 Class *cl, __a2 Object *obj,
  245.                                              __a1 Msg msg)
  246. {
  247.  ULONG rc;
  248.  
  249.  CLIPLIST_LOG(LOG3(Arguments, "Class 0x%08lx Object 0x%08lx Msg 0x%08lx",
  250.                    cl, obj, msg))
  251.  
  252.  switch(msg->MethodID) {
  253.   /* BOOPSI methods */
  254.   case OM_NEW:
  255.    rc = ClipListClassNew(cl, obj, (struct opSet *) msg);
  256.    break;
  257.  
  258.   case OM_GET:
  259.    rc = ClipListClassGet(cl, obj, (struct opGet *) msg);
  260.    break;
  261.  
  262.   /* MUI methods */
  263.   case MUIM_DragQuery:
  264.    rc = ClipListClassDragQuery(cl, obj, (struct MUIP_DragQuery *) msg);
  265.    break;
  266.  
  267.   case MUIM_DragDrop:
  268.    rc = ClipListClassDragDrop(cl, obj, (struct MUIP_DragDrop *) msg);
  269.    break;
  270.  
  271.   /* TM methods */
  272.   case TMM_Notify:
  273.    rc = ClipListClassNotify(cl, obj, (struct TMP_Notify *) msg);
  274.    break;
  275.  
  276.   case TMM_DoubleClicked:
  277.    rc = ClipListClassDoubleClicked(cl, obj);
  278.    break;
  279.  
  280.   /* Unknown method -> delegate to SuperClass */
  281.   default:
  282.    rc = DoSuperMethodA(cl, obj, msg);
  283.    break;
  284.  }
  285.  
  286.  return(rc);
  287. }
  288.  
  289. /* Create ClipList class */
  290. #undef  DEBUGFUNCTION
  291. #define DEBUGFUNCTION CreateClipListClass
  292. struct MUI_CustomClass *CreateClipListClass(void)
  293. {
  294.  struct MUI_CustomClass *rc;
  295.  
  296.  /* Create class */
  297.  if (rc = MUI_CreateCustomClass(NULL, MUIC_List, NULL,
  298.                                 sizeof(struct ClipListClassData),
  299.                                 ClipListClassDispatcher)) {
  300.  
  301.   /* Localize strings */
  302.  }
  303.  
  304.  CLIPLIST_LOG(LOG1(Result, "0x%08lx", rc))
  305.  
  306.  return(rc);
  307. }
  308.