home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 11 Util / 11-Util.zip / BLCKH3.ZIP / BlackHol.c next >
Text File  |  1993-01-18  |  9KB  |  212 lines

  1.  
  2. /*
  3.  * This file was generated by the SOM Compiler.
  4.  * FileName: BlackHol.c.
  5.  * Generated using:
  6.  *     SOM Precompiler spc: 1.22
  7.  *     SOM Emitter emitc: 1.24
  8.  */
  9.  
  10. /*────────────────────────────────────────────────────────────────────┐
  11. │  Greg's Black Hole - anything you put in will disappear forever...  │
  12. │                      This version resolves folder structure         │
  13. │                      and reset Read only attribute... Dangerous !   │
  14. │                      Gregory Czaja, 71052,720        November 1992  │
  15. │  will allow removing desktop, if not the current one December 1992  │
  16. │  better class checking for dropped objects           January  1993  │
  17. └────────────────────────────────────────────────────────────────────*/
  18.  
  19.  
  20. #define BlackHole_Class_Source
  21. #include "BlackHol.ih"
  22. #include <wpObject.h>
  23. #include <wpFolder.h>
  24. #include <wpDesk.h>
  25.  
  26. #include <stdio.h>
  27. #include <stdlib.h>
  28. #include <string.h>
  29. #include <malloc.h>
  30.  
  31. void ResolveAndDelete(WPObject * pWPObject);
  32.  
  33. SOM_Scope MRESULT   SOMLINK BlackHolX_wpDragOver(BlackHole *somSelf,
  34.                 HWND hwndCnr,
  35.                 PDRAGINFO pdrgInfo)
  36. {
  37.     ULONG ulItemCnt=0;
  38.     ULONG ulItem=0;
  39.     USHORT usDropIndic=DOR_DROP;
  40.     BlackHoleData *somThis = BlackHoleGetData(somSelf);
  41.     BlackHoleMethodDebug("BlackHole","BlackHolX_wpDragOver");
  42.  
  43.           /* Check that items are workplace shell objects */
  44.  
  45.       ulItemCnt=DrgQueryDragitemCount(pdrgInfo);
  46.       for(ulItem=0;ulItem<ulItemCnt;ulItem++) {
  47.        DRAGITEM DItem;
  48.  
  49.         DrgQueryDragitem(pdrgInfo,sizeof(DItem),&DItem,ulItem);
  50.  
  51.                       /* check that it is a WPS object RMF */
  52.         if(!DrgVerifyRMF(&DItem,"DRM_OBJECT","DRF_OBJECT")) {
  53.                       /* if it's not - don't accept !      */
  54.           usDropIndic=DOR_NEVERDROP;
  55.         }/* end if */
  56.       }/* end for */
  57.  
  58.       return (MRFROM2SHORT(usDropIndic,DO_UNKNOWN));
  59.       /*
  60.       return (parent_wpDragOver(somSelf,hwndCnr,pdrgInfo));
  61.        */
  62. }
  63.  
  64. SOM_Scope MRESULT   SOMLINK BlackHolX_wpDrop(BlackHole *somSelf,
  65.                 HWND hwndCnr,
  66.                 PDRAGINFO pdrgInfo,
  67.                 PDRAGITEM pdrgItem)
  68. {
  69.     WPObject *pWPObjDropped;
  70.     PSZ   message =malloc(256);
  71.     PSZ   object;
  72.     PSZ   pszClass;
  73.  
  74.     BlackHoleData *somThis = BlackHoleGetData(somSelf);
  75.     BlackHoleMethodDebug("BlackHole","BlackHolX_wpDrop");
  76.  
  77.     pWPObjDropped=OBJECT_FROM_PREC(pdrgItem->ulItemID);
  78.     object       =_wpQueryTitle(pWPObjDropped);
  79.     pszClass     =(PSZ)_somGetClassName(pWPObjDropped);
  80.  
  81.     sprintf(message,
  82.        "You are about to delete: %s including the entire contents, if any.\
  83.        \nPush \"Yes\" to confirm, \"No\" to cancel!", object);
  84.     if (MBID_YES == WinMessageBox(HWND_DESKTOP,
  85.                                   HWND_DESKTOP,
  86.                                   message,
  87.                                  "Black Hole - destroy object",
  88.                                   0,
  89.                                   MB_YESNO | MB_DEFBUTTON2 | MB_WARNING | MB_SYSTEMMODAL )){
  90.                                   /* wants a VERY special delete ??? */
  91.        if (strcmp(pszClass, "WPDesktop") == 0) {
  92.                                   /* is this the current desktop ? */
  93.           if (_wpIsCurrentDesktop(pWPObjDropped)) {
  94.              WinMessageBox(HWND_DESKTOP,
  95.                            HWND_DESKTOP,
  96.                            "You must be joking... \
  97.                            Do you realy want to delete your Desktop ?",
  98.                            "DeskMan/2 - destroy object",
  99.                            0,
  100.                            MB_CANCEL | MB_WARNING | MB_SYSTEMMODAL );
  101.           } else {
  102.             if (MBID_YES == WinMessageBox(HWND_DESKTOP,
  103.                                           HWND_DESKTOP,
  104.                "Deleting an inactive Desktop may cause problems on some systems.\
  105.  Objects on the active Desktop may be damaged.\
  106. \nDo you want to continue ?",
  107.                                           "Black Hole - Destroy object",
  108.                                           0,
  109.                                           MB_YESNO | MB_DEFBUTTON2 | MB_WARNING | MB_SYSTEMMODAL )){
  110.                ResolveAndDelete(pWPObjDropped);
  111.             };
  112.           } /* endif */
  113.        } else {
  114.           ResolveAndDelete(pWPObjDropped);
  115.        } /* endif */
  116.     };
  117.     free(message);
  118.  
  119.     return (parent_wpDrop(somSelf,hwndCnr,pdrgInfo,pdrgItem));
  120. }
  121.  
  122. #undef SOM_CurrentClass
  123. #define SOM_CurrentClass SOMMeta
  124. SOM_Scope void   SOMLINK BlackHolC_wpclsInitData(M_BlackHole *somSelf)
  125. {
  126.     /* M_BlackHoleData *somThis = M_BlackHoleGetData(somSelf); */
  127.     M_BlackHoleMethodDebug("M_BlackHole","BlackHolC_wpclsInitData");
  128.  
  129.     parent_wpclsInitData(somSelf);
  130. }
  131.  
  132. SOM_Scope void   SOMLINK BlackHolC_wpclsUnInitData(M_BlackHole *somSelf)
  133. {
  134.     /* M_BlackHoleData *somThis = M_BlackHoleGetData(somSelf); */
  135.     M_BlackHoleMethodDebug("M_BlackHole","BlackHolC_wpclsUnInitData");
  136.  
  137.     parent_wpclsUnInitData(somSelf);
  138. }
  139.  
  140. /*─────────────────────────  ORDINARY CODE SECTION  ──────────────────────────┐
  141. │****                                                                     ****│
  142. │****                  Any non-method code should go here.                ****│
  143. │****                                                                     ****│
  144. └────────────────────────────────────────────────────────────────────────────*/
  145. #undef SOM_CurrentClass
  146.  
  147. /*──────────────────────────────────────────────────────────────────────────┐
  148. │ ResolveAndDelete                                                          │
  149. │ Purpose: resolves composite objects and deletes atomic ones...            │
  150. └──────────────────────────────────────────────────────────────────────────*/
  151. VOID ResolveAndDelete(WPObject * pWPObject)
  152.    ULONG ulFlags;
  153.  
  154.    PSZ       message =malloc(256);
  155.    PSZ       pszObject =_wpQueryTitle(pWPObject);
  156.    PSZ       pszClass  =(PSZ)_somGetClassName(pWPObject);
  157.    SOMClass *Class=_somClassFromId(SOMClassMgrObject,            
  158.                                    SOM_IdFromString(pszClass));
  159.    SOMClass *FolderClass=_somClassFromId(SOMClassMgrObject,
  160.                                          SOM_IdFromString("WPFolder"));
  161.    SOMClass *FileSystemClass=_somClassFromId(SOMClassMgrObject,            
  162.                                              SOM_IdFromString("WPFileSystem"));
  163.  
  164.                                     /* those are represented by real files... */
  165.    if (_somDescendedFrom(Class, FileSystemClass)){
  166.                                     /* get the object's file Attributes... */
  167.       ulFlags=_wpQueryAttr(pWPObject);
  168.                                     /* now reset the read only bit */
  169.       _wpSetAttr(pWPObject, ulFlags & ~FILE_READONLY);
  170.  
  171.    } /* endif */
  172.                                     /* resolve composite objects if necessary */
  173.    if (_somDescendedFrom(Class, FolderClass)){
  174.  
  175.        PSZ pszFilename=NULL;
  176.        ULONG  pcb;
  177.                                      /* get the real name for populate */
  178.        if _wpQueryRealName(pWPObject,NULL,&pcb,TRUE){
  179.           pszFilename=malloc(pcb+2);            /* get the buffer */
  180.           memset(pszFilename,'\0',pcb+1);
  181.           _wpQueryRealName(pWPObject,pszFilename,&pcb,TRUE);
  182.        } /* endif */
  183.        if (_wpPopulate(pWPObject, 0L, pszFilename, FALSE)) {
  184.           WPObject * pWPObjectTemp;
  185.                       /* go through folder's content   */
  186.           for(pWPObjectTemp=_wpQueryContent(pWPObject,pWPObjectTemp,QC_First);
  187.               pWPObjectTemp != NULL;
  188.               pWPObjectTemp=_wpQueryContent(pWPObject,pWPObjectTemp,QC_Next)) {
  189.  
  190.               ResolveAndDelete(pWPObjectTemp);
  191.           }/* end for */
  192.        } /* endif */
  193.        if (pszFilename != NULL) 
  194.           free(pszFilename);
  195.    } /* endif */
  196.                                        /* now reset the noDelete style */
  197.    _wpSetStyle(pWPObject, !OBJSTYLE_NODELETE);
  198.                                        /* and do the job...            */
  199.    if ( !_wpFree(pWPObject)) {
  200.       sprintf(message, "Object: %s could not be deleted !", pszObject);
  201.       WinMessageBox(HWND_DESKTOP,
  202.                     HWND_DESKTOP,
  203.                     message,
  204.                     "Black Hole - destroy object",
  205.                     0,
  206.                     MB_CANCEL | MB_WARNING | MB_SYSTEMMODAL );
  207.    };
  208.   free(message);
  209.   return;
  210. }
  211.