home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-386-Vol-2of3.iso / b / blckh2.zip / BLACKHOL.C next >
Text File  |  1992-12-19  |  9KB  |  237 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. └────────────────────────────────────────────────────────────────────*/
  17.  
  18.  
  19. #define BlackHole_Class_Source
  20. #include "BlackHol.ih"
  21. #include <wpObject.h>
  22. #include <wpFolder.h>
  23. #include <wpDesk.h>
  24.  
  25. #include <stdio.h>
  26. #include <stdlib.h>
  27. #include <string.h>
  28. #include <malloc.h>
  29.  
  30. void MyFreeDraginfo(PDRAGINFO pdrgInfo);
  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.                     /* Free the draginfo if not same process */
  59.       MyFreeDraginfo(pdrgInfo);
  60.  
  61.       return (MRFROM2SHORT(usDropIndic,DO_UNKNOWN));
  62.       /*
  63.       return (parent_wpDragOver(somSelf,hwndCnr,pdrgInfo));
  64.        */
  65. }
  66.  
  67. SOM_Scope MRESULT   SOMLINK BlackHolX_wpDrop(BlackHole *somSelf,
  68.                 HWND hwndCnr,
  69.                 PDRAGINFO pdrgInfo,
  70.                 PDRAGITEM pdrgItem)
  71. {
  72.     WPObject *pWPObjDropped;
  73.     PSZ   message =malloc(256);
  74.     PSZ   object;
  75.     PSZ   pszClass;
  76.  
  77.     BlackHoleData *somThis = BlackHoleGetData(somSelf);
  78.     BlackHoleMethodDebug("BlackHole","BlackHolX_wpDrop");
  79.  
  80.     pWPObjDropped=OBJECT_FROM_PREC(pdrgItem->ulItemID);
  81.     object       =_wpQueryTitle(pWPObjDropped);
  82.     pszClass     =(PSZ)_somGetClassName(pWPObjDropped);
  83.  
  84.     strcpy(message, "You are about to delete: ");
  85.     strcat(message, object);
  86.     strcat(message, " including the entire content, if any.");
  87.     strcat(message, " Push \"Yes\" to confirm, \"No\" to cancel !");
  88.     if (MBID_YES == WinMessageBox(HWND_DESKTOP,
  89.                                   HWND_DESKTOP,
  90.                                   message,
  91.                                  "Black Hole - destroy object",
  92.                                   0,
  93.                                   MB_YESNO | MB_DEFBUTTON2 | MB_WARNING | MB_SYSTEMMODAL )){
  94.                                   /* wants a VERY special delete ??? */
  95.        if (strcmp(pszClass, "WPDesktop") == 0) {
  96.                                   /* is this the current desktop ? */
  97.           if (_wpIsCurrentDesktop(pWPObjDropped)) {
  98.              WinMessageBox(HWND_DESKTOP,
  99.                            HWND_DESKTOP,
  100.                            "You must be joking... \
  101.                            Do you realy want to delete your Desktop ?",
  102.                            "DeskMan/2 - destroy object",
  103.                            0,
  104.                            MB_CANCEL | MB_WARNING | MB_SYSTEMMODAL );
  105.           } else {
  106.             if (MBID_YES == WinMessageBox(HWND_DESKTOP,
  107.                                           HWND_DESKTOP,
  108.                                           "Deleting an inactive Desktop may cause\
  109.                                           problems on some systems.\
  110.                                           Objects on the active Desktop may be damaged.\
  111.                                           Do you want to continue ?",
  112.                                           "DeskMan/2 - Destroy object",
  113.                                           0,
  114.                                           MB_YESNO | MB_DEFBUTTON2 | MB_WARNING | MB_SYSTEMMODAL )){
  115.                ResolveAndDelete(pWPObjDropped);
  116.             };
  117.           } /* endif */
  118.        } else {
  119.           ResolveAndDelete(pWPObjDropped);
  120.        } /* endif */
  121.     };
  122.     free(message);
  123.  
  124.     return (parent_wpDrop(somSelf,hwndCnr,pdrgInfo,pdrgItem));
  125. }
  126.  
  127. #undef SOM_CurrentClass
  128. #define SOM_CurrentClass SOMMeta
  129. SOM_Scope void   SOMLINK BlackHolC_wpclsInitData(M_BlackHole *somSelf)
  130. {
  131.     /* M_BlackHoleData *somThis = M_BlackHoleGetData(somSelf); */
  132.     M_BlackHoleMethodDebug("M_BlackHole","BlackHolC_wpclsInitData");
  133.  
  134.     parent_wpclsInitData(somSelf);
  135. }
  136.  
  137. SOM_Scope void   SOMLINK BlackHolC_wpclsUnInitData(M_BlackHole *somSelf)
  138. {
  139.     /* M_BlackHoleData *somThis = M_BlackHoleGetData(somSelf); */
  140.     M_BlackHoleMethodDebug("M_BlackHole","BlackHolC_wpclsUnInitData");
  141.  
  142.     parent_wpclsUnInitData(somSelf);
  143. }
  144.  
  145. /*─────────────────────────  ORDINARY CODE SECTION  ──────────────────────────┐
  146. │****                                                                     ****│
  147. │****                  Any non-method code should go here.                ****│
  148. │****                                                                     ****│
  149. └────────────────────────────────────────────────────────────────────────────*/
  150. #undef SOM_CurrentClass
  151.  
  152. /*──────────────────────────────────────────────────────────────────────────┐
  153. │ ResolveAndDelete                                                          │
  154. │ Purpose: resolves composite objects and deletes atomic ones...            │
  155. └──────────────────────────────────────────────────────────────────────────*/
  156. VOID ResolveAndDelete(WPObject * pWPObject)
  157.    ULONG ulFlags;
  158.  
  159.    PSZ   message =malloc(256);
  160.    PSZ pszObject =_wpQueryTitle(pWPObject);
  161.    PSZ pszClass  =(PSZ)_somGetClassName(pWPObject);
  162.                                     /* those are represented by real files... */
  163.    if (strcmp(pszClass,"WPFileSystem")==0   |
  164.        strcmp(pszClass,"WPDataFile")==0     |
  165.        strcmp(pszClass,"WPFolder")==0       |
  166.        strcmp(pszClass,"WPProgramGroup")==0 |
  167.        strcmp(pszClass,"WPProgramFile")==0  |
  168.        strcmp(pszClass,"WPTemplateFolder")==0 ) {
  169.                                     /* get the object's file Attributes... */
  170.       ulFlags=_wpQueryAttr(pWPObject);
  171.                                     /* now reset the read only bit */
  172.       _wpSetAttr(pWPObject, ulFlags & ~FILE_READONLY);
  173.  
  174.    } /* endif */
  175.                                     /* resolve composite objects if necessary */
  176.    if (strcmp(pszClass,"WPFolder")==0         |
  177.        strcmp(pszClass,"WPTemplateFolder")==0 |
  178.        strcmp(pszClass,"WPProgramGroup")==0   ){
  179.  
  180.        PSZ pszFilename=NULL;
  181.        ULONG  pcb;
  182.                                      /* get the real name for populate */
  183.        if _wpQueryRealName(pWPObject,NULL,&pcb,TRUE){
  184.           pszFilename=malloc(pcb+2);            /* get the buffer */
  185.           memset(pszFilename,'\0',pcb+1);
  186.           _wpQueryRealName(pWPObject,pszFilename,&pcb,TRUE);
  187.        } /* endif */
  188.        if (_wpPopulate(pWPObject, 0L, pszFilename, FALSE)) {
  189.           WPObject * pWPObjectTemp;
  190.                       /* go through folder's content   */
  191.           for(pWPObjectTemp=_wpQueryContent(pWPObject,pWPObjectTemp,QC_First);
  192.               pWPObjectTemp != NULL;
  193.               pWPObjectTemp=_wpQueryContent(pWPObject,pWPObjectTemp,QC_Next)) {
  194.  
  195.               ResolveAndDelete(pWPObjectTemp);
  196.           }/* end for */
  197.        } /* endif */
  198.        if (pszFilename != NULL) 
  199.           free(pszFilename);
  200.    } /* endif */
  201.                                        /* now reset the noDelete style */
  202.    _wpSetStyle(pWPObject, !OBJSTYLE_NODELETE);
  203.    if ( _wpDelete(pWPObject, 0) != OK_DELETE ) {
  204.       strcpy(message, "Object: ");
  205.       strcat(message, pszObject);
  206.       strcat(message, " could not be deleted !");
  207.       WinMessageBox(HWND_DESKTOP,
  208.                     HWND_DESKTOP,
  209.                     message,
  210.                     "Black Hole - destroy object",
  211.                     0,
  212.                     MB_CANCEL | MB_WARNING | MB_SYSTEMMODAL );
  213.    };
  214.   free(message);
  215.   return;
  216. }
  217. /*──────────────────────────────────────────────────────────────────────────┐
  218. │ MyFreeDraginfo()        courtesy of Ph. Gregoire                          │
  219. │ Purpose: Frees the drag info if not same process                          │
  220. └──────────────────────────────────────────────────────────────────────────*/
  221. void MyFreeDraginfo(PDRAGINFO pdrgInfo)
  222. {PID pidSrc;
  223.  TID tidSrc;
  224.  PTIB ptib;
  225.  PPIB ppib;
  226.  
  227.   WinQueryWindowProcess(pdrgInfo->hwndSource,&pidSrc,&tidSrc);
  228.   DosGetInfoBlocks(&ptib,&ppib);
  229.  
  230.   if(ppib->pib_ulpid!=pidSrc) {
  231.     DrgFreeDraginfo(pdrgInfo);
  232.   }/* end if */
  233.  
  234. }/* end MyFreeDraginfo */
  235.  
  236.