home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 11 Util
/
11-Util.zip
/
BLACKHOL.ZIP
/
BLACKHOL.C
next >
Wrap
Text File
|
1993-01-08
|
9KB
|
212 lines
/*
* This file was generated by the SOM Compiler.
* FileName: BlackHol.c.
* Generated using:
* SOM Precompiler spc: 1.22
* SOM Emitter emitc: 1.24
*/
/*────────────────────────────────────────────────────────────────────┐
│ Greg's Black Hole - anything you put in will disappear forever... │
│ This version resolves folder structure │
│ and reset Read only attribute... Dangerous ! │
│ Gregory Czaja, 71052,720 November 1992 │
│ will allow removing desktop, if not the current one December 1992 │
│ better class checking for dropped objects January 1993 │
└────────────────────────────────────────────────────────────────────*/
#define BlackHole_Class_Source
#include "BlackHol.ih"
#include <wpObject.h>
#include <wpFolder.h>
#include <wpDesk.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <malloc.h>
void ResolveAndDelete(WPObject * pWPObject);
SOM_Scope MRESULT SOMLINK BlackHolX_wpDragOver(BlackHole *somSelf,
HWND hwndCnr,
PDRAGINFO pdrgInfo)
{
ULONG ulItemCnt=0;
ULONG ulItem=0;
USHORT usDropIndic=DOR_DROP;
BlackHoleData *somThis = BlackHoleGetData(somSelf);
BlackHoleMethodDebug("BlackHole","BlackHolX_wpDragOver");
/* Check that items are workplace shell objects */
ulItemCnt=DrgQueryDragitemCount(pdrgInfo);
for(ulItem=0;ulItem<ulItemCnt;ulItem++) {
DRAGITEM DItem;
DrgQueryDragitem(pdrgInfo,sizeof(DItem),&DItem,ulItem);
/* check that it is a WPS object RMF */
if(!DrgVerifyRMF(&DItem,"DRM_OBJECT","DRF_OBJECT")) {
/* if it's not - don't accept ! */
usDropIndic=DOR_NEVERDROP;
}/* end if */
}/* end for */
return (MRFROM2SHORT(usDropIndic,DO_UNKNOWN));
/*
return (parent_wpDragOver(somSelf,hwndCnr,pdrgInfo));
*/
}
SOM_Scope MRESULT SOMLINK BlackHolX_wpDrop(BlackHole *somSelf,
HWND hwndCnr,
PDRAGINFO pdrgInfo,
PDRAGITEM pdrgItem)
{
WPObject *pWPObjDropped;
PSZ message =malloc(256);
PSZ object;
PSZ pszClass;
BlackHoleData *somThis = BlackHoleGetData(somSelf);
BlackHoleMethodDebug("BlackHole","BlackHolX_wpDrop");
pWPObjDropped=OBJECT_FROM_PREC(pdrgItem->ulItemID);
object =_wpQueryTitle(pWPObjDropped);
pszClass =(PSZ)_somGetClassName(pWPObjDropped);
sprintf(message,
"You are about to delete: %s including the entire contents, if any.\
\nPush \"Yes\" to confirm, \"No\" to cancel !", object);
if (MBID_YES == WinMessageBox(HWND_DESKTOP,
HWND_DESKTOP,
message,
"Black Hole - destroy object",
0,
MB_YESNO | MB_DEFBUTTON2 | MB_WARNING | MB_SYSTEMMODAL )){
/* wants a VERY special delete ??? */
if (strcmp(pszClass, "WPDesktop") == 0) {
/* is this the current desktop ? */
if (_wpIsCurrentDesktop(pWPObjDropped)) {
WinMessageBox(HWND_DESKTOP,
HWND_DESKTOP,
"You must be joking... \
Do you realy want to delete your Desktop ?",
"DeskMan/2 - destroy object",
0,
MB_CANCEL | MB_WARNING | MB_SYSTEMMODAL );
} else {
if (MBID_YES == WinMessageBox(HWND_DESKTOP,
HWND_DESKTOP,
"Deleting an inactive Desktop may cause problems on some systems.\
Objects on the active Desktop may be damaged.\
\nDo you want to continue ?",
"DeskMan/2 - Destroy object",
0,
MB_YESNO | MB_DEFBUTTON2 | MB_WARNING | MB_SYSTEMMODAL )){
ResolveAndDelete(pWPObjDropped);
};
} /* endif */
} else {
ResolveAndDelete(pWPObjDropped);
} /* endif */
};
free(message);
return (parent_wpDrop(somSelf,hwndCnr,pdrgInfo,pdrgItem));
}
#undef SOM_CurrentClass
#define SOM_CurrentClass SOMMeta
SOM_Scope void SOMLINK BlackHolC_wpclsInitData(M_BlackHole *somSelf)
{
/* M_BlackHoleData *somThis = M_BlackHoleGetData(somSelf); */
M_BlackHoleMethodDebug("M_BlackHole","BlackHolC_wpclsInitData");
parent_wpclsInitData(somSelf);
}
SOM_Scope void SOMLINK BlackHolC_wpclsUnInitData(M_BlackHole *somSelf)
{
/* M_BlackHoleData *somThis = M_BlackHoleGetData(somSelf); */
M_BlackHoleMethodDebug("M_BlackHole","BlackHolC_wpclsUnInitData");
parent_wpclsUnInitData(somSelf);
}
/*───────────────────────── ORDINARY CODE SECTION ──────────────────────────┐
│**** ****│
│**** Any non-method code should go here. ****│
│**** ****│
└────────────────────────────────────────────────────────────────────────────*/
#undef SOM_CurrentClass
/*──────────────────────────────────────────────────────────────────────────┐
│ ResolveAndDelete │
│ Purpose: resolves composite objects and deletes atomic ones... │
└──────────────────────────────────────────────────────────────────────────*/
VOID ResolveAndDelete(WPObject * pWPObject)
{
ULONG ulFlags;
PSZ message =malloc(256);
PSZ pszObject =_wpQueryTitle(pWPObject);
PSZ pszClass =(PSZ)_somGetClassName(pWPObject);
SOMClass *Class=_somClassFromId(SOMClassMgrObject,
SOM_IdFromString(pszClass));
SOMClass *FolderClass=_somClassFromId(SOMClassMgrObject,
SOM_IdFromString("WPFolder"));
SOMClass *FileSystemClass=_somClassFromId(SOMClassMgrObject,
SOM_IdFromString("WPFileSystem"));
/* those are represented by real files... */
if (_somDescendedFrom(Class, FileSystemClass)){
/* get the object's file Attributes... */
ulFlags=_wpQueryAttr(pWPObject);
/* now reset the read only bit */
_wpSetAttr(pWPObject, ulFlags & ~FILE_READONLY);
} /* endif */
/* resolve composite objects if necessary */
if (_somDescendedFrom(Class, FolderClass)){
PSZ pszFilename=NULL;
ULONG pcb;
/* get the real name for populate */
if _wpQueryRealName(pWPObject,NULL,&pcb,TRUE){
pszFilename=malloc(pcb+2); /* get the buffer */
memset(pszFilename,'\0',pcb+1);
_wpQueryRealName(pWPObject,pszFilename,&pcb,TRUE);
} /* endif */
if (_wpPopulate(pWPObject, 0L, pszFilename, FALSE)) {
WPObject * pWPObjectTemp;
/* go through folder's content */
for(pWPObjectTemp=_wpQueryContent(pWPObject,pWPObjectTemp,QC_First);
pWPObjectTemp != NULL;
pWPObjectTemp=_wpQueryContent(pWPObject,pWPObjectTemp,QC_Next)) {
ResolveAndDelete(pWPObjectTemp);
}/* end for */
} /* endif */
if (pszFilename != NULL)
free(pszFilename);
} /* endif */
/* now reset the noDelete style */
_wpSetStyle(pWPObject, !OBJSTYLE_NODELETE);
/* and do the job... */
if ( _wpDelete(pWPObject, 0) != OK_DELETE ) {
sprintf(message, "Object: %s could not be deleted !", pszObject);
WinMessageBox(HWND_DESKTOP,
HWND_DESKTOP,
message,
"Black Hole - destroy object",
0,
MB_CANCEL | MB_WARNING | MB_SYSTEMMODAL );
};
free(message);
return;
}