home *** CD-ROM | disk | FTP | other *** search
- /* Program name: WasteBsk.C Title: Implementing a Wastebasket in */
- /* the Workplace Shell. */
- /* OS/2 Developer Magazine, Issue: Winter '93, page 102 */
- /* Author: Dave Hock */
- /* UCANDU Software, Inc. */
- /* P.O Box 336 */
- /* Cary, NC 27512 */
- /* Description: Source code for implementing a wastebasket on the */
- /* OS/2 2.0 Workplace Shell desktop. */
- /* Program Requirements: OS/2 2.0, OS/2 Toolkit, IBM CSet/2, SOM */
- /* Compiler. */
-
- /*
- * This file was generated by the SOM Compiler.
- * FileName: wastebsk.c.
- * Generated using:
- * SOM Precompiler spc: 1.22
- * SOM Emitter emitc: 1.24
- *
- */
- #define INCL_WIN
- #define INCL_DOS
- #define INCL_GPIBITMAPS
- #define INCL_WPCLASS
- #define INCL_WPFOLDER
-
- /******************************************************************************/
- /* System-defined header files */
- /******************************************************************************/
- #include <os2.h>
-
- #include <pmwp.h> /* eventually will be #define INCL_WINWORKPLACE */
-
- #include <stdio.h>
- #include <string.h>
-
- /******************************************************************************/
- /* Function prototype for dialog proc */
- /******************************************************************************/
- MRESULT EXPENTRY AutoEmptyDlgProc(HWND hwndDlg,
- ULONG msg,
- MPARAM mp1,
- MPARAM mp2);
-
- /******************************************************************************/
- /* Dialog definitions header file */
- /******************************************************************************/
- #include "dialog.h"
- /******************************************************************************/
- /* Global data */
- /******************************************************************************/
- HMODULE hmodThisClass; /* Module handle */
- HPOINTER hIcon; /* Handle for icon */
-
- PSZ DefaultClassTitle = "Waste Basket"; /* Default folder title */
-
- #define WPWasteBskt_Class_Source
- #include "wastebsk.ih"
-
- /*
- *
- * METHOD: QueryAutoEmptyFlag PRIVATE
- * PURPOSE:
- * INVOKED: From AutoEmptyDlgProc
- */
-
- SOM_Scope BOOL SOMLINK wpwastebskt_QueryAutoEmptyFlag(WPWasteBskt *somSelf)
- {
- WPWasteBsktData *somThis = WPWasteBsktGetData(somSelf);
- WPWasteBsktMethodDebug("WPWasteBskt","wpwastebskt_QueryAutoEmptyFlag");
-
- return _bAutoEmpty;
- }
-
- /*
- *
- * METHOD: SetAutoEmptyFlag PRIVATE
- * PURPOSE:
- * INVOKED: From AutoEmptyDlgProc
- */
-
- SOM_Scope BOOL SOMLINK wpwastebskt_SetAutoEmptyFlag(WPWasteBskt *somSelf,
- BOOL bAutoEmpty)
- {
- WPWasteBsktData *somThis = WPWasteBsktGetData(somSelf);
- WPWasteBsktMethodDebug("WPWasteBskt","wpwastebskt_SetAutoEmptyInfo");
-
- _bAutoEmpty = bAutoEmpty;
- return (BOOL) 0;
- }
-
- /*
- *
- * METHOD: wpInitData PUBLIC
- * PURPOSE: Initializes instance data
- * INVOKED: By Workplace Shell, upon instantiation of the object instance.
- */
-
- SOM_Scope void SOMLINK wpwastebskt_wpInitData(WPWasteBskt *somSelf)
- {
- WPWasteBsktMethodDebug("WPWasteBskt","wpwastebskt_wpInitData");
-
- parent_wpInitData(somSelf);
- _SetAutoEmptyFlag(somSelf, FALSE);
- }
-
- /*
- *
- * METHOD: wpModifyPopupMenu PUBLIC
- * PURPOSE: Adds an additional "Empty now" item to the object's context menu.
- * INVOKED: By Workplace Shell, upon instantiation of the object instance.
- */
-
- SOM_Scope BOOL SOMLINK wpwastebskt_wpModifyPopupMenu(WPWasteBskt *somSelf,
- HWND hwndMenu,
- HWND hwndCnr,
- ULONG iPosition)
- {
- WPWasteBsktMethodDebug("WPWasteBskt","wpwastebskt_wpModifyPopupMenu");
-
- /* add the empty now item if the waste basket is not empty */
- if (_wpQueryContent(somSelf,0,QC_First)) {
- _wpInsertPopupMenuItems(somSelf, /* Insert menu item */
- hwndMenu, /* Menu handle */
- iPosition, /* Default position */
- hmodThisClass, /* Module handle */
- ID_CXTMENU_WASTE, /* Menu item identifier */
- 0); /* No submenu identifier */
- } /* endif */
-
- return (parent_wpModifyPopupMenu(somSelf,hwndMenu,hwndCnr,iPosition));
- }
-
- /*
- *
- * METHOD: wpMenuItemSelected PUBLIC
- * PURPOSE: Processes the user's selections from the context menu. The
- * overridden method processes only the added "Empty now" item, before
- * invoking the parent's default processing to handle other items.
- * INVOKED: By Workplace Shell, upon selection of a menu item by the user.
- */
-
- SOM_Scope BOOL SOMLINK wpwastebskt_wpMenuItemSelected(WPWasteBskt *somSelf,
- HWND hwndFrame,
- ULONG ulMenuId)
- {
- WPWasteBsktMethodDebug("WPWasteBskt","wpwastebskt_wpMenuItemSelected");
- switch( ulMenuId ) /* Switch on item identifier */
- {
- case IDM_EMPTY:
- _wpDeleteContents(somSelf, TRUE);
- break;
-
- default: /* All other items */
- return (parent_wpMenuItemSelected(somSelf,hwndFrame,ulMenuId));
- break;
- }
- return TRUE;
- }
-
- /*
- *
- * METHOD: wpSetup PUBLIC
- * PURPOSE: Sets folder properties based upon a setup string passed by the
- * object's creator as part of the WinCreateObject() call. The
- * overridden method simply processes the AUTOEMPTY keyword to set
- * the folder's autoempty status and period, before
- * invoking the parent's default processing to handle all other
- * keywords.
- * INVOKED: By the Workplace Shell, upon instantiation of the object
- * instance.
- */
-
- SOM_Scope BOOL SOMLINK wpwastebskt_wpSetup(WPWasteBskt *somSelf,
- PSZ pszSetupString)
- {
- BOOL rc;
- CHAR szValue[256];
- ULONG cbValue;
-
- WPWasteBsktMethodDebug("WPWasteBskt","wpwastebskt_wpSetup");
-
- rc = parent_wpSetup(somSelf,pszSetupString);
- cbValue = 256;
- if (_wpScanSetupString(somSelf,pszSetupString,(PSZ)"AUTOEMPTY",szValue,&cbValue))
- {
- if (!strcmp(szValue,"TRUE")) {
- _SetAutoEmptyFlag(somSelf, TRUE);
- } else {
- _SetAutoEmptyFlag(somSelf, FALSE);
- } /* endif */
- }
- return rc;
- }
-
- /*
- *
- * METHOD: wpSaveState PUBLIC
- * PURPOSE: Saves the object instance's persistent state data. The
- * overridden method simply saves the autoempty info , then invokes
- * the parent's default processing to handle any other instance
- * data defined by ancestor classes.
- * INVOKED: By the Workplace Shell, when the object becomes dormant.
- */
-
- SOM_Scope BOOL SOMLINK wpwastebskt_wpSaveState(WPWasteBskt *somSelf)
- {
- BOOL rc;
- BOOL bAutoEmpty;
- WPWasteBsktMethodDebug("WPWasteBskt","wpwastebskt_wpSaveState");
-
- rc = parent_wpSaveState(somSelf);
- bAutoEmpty = _QueryAutoEmptyFlag(somSelf);
- _wpSaveData(somSelf,_somGetClassName(somSelf),IDKEY_AUTOEMPTY,
- (PBYTE)&bAutoEmpty,sizeof(BOOL));
-
- return rc;
- }
-
- /*
- *
- * METHOD: wpRestoreState PUBLIC
- * PURPOSE: Restores the object instance's persistent state data. The
- * overridden method simply restores the autoempty data, then
- * invokes the parent's default processing to handle any other
- * instance data defined by ancestor classes.
- * INVOKED: By the Workplace Shell, when the object becomes awake.
- */
-
- SOM_Scope BOOL SOMLINK wpwastebskt_wpRestoreState(WPWasteBskt *somSelf,
- ULONG ulReserved)
- {
- BOOL rc;
- BOOL bAutoEmpty;
- ULONG cbValue;
- WPWasteBsktMethodDebug("WPWasteBskt","wpwastebskt_wpRestoreState");
-
- rc = parent_wpRestoreState(somSelf,ulReserved);
- cbValue = sizeof(BOOL);
- if ( _wpRestoreData(somSelf,_somGetClassName(somSelf),IDKEY_AUTOEMPTY,(PBYTE)&bAutoEmpty,&cbValue) ) {
- _SetAutoEmptyFlag(somSelf,bAutoEmpty);
- if (bAutoEmpty) {
- _wpDeleteContents(somSelf, TRUE);
- } /* endif */
- } /* endif */
- return rc;
- }
-
- /*
- *
- * METHOD: wpQueryStyle PUBLIC
- * PURPOSE: Allows us to force a style such as OBJSYTLE_NOCOPY or NODELETE
- * INVOKED: By the Workplace Shell, when object(s) are dragged over the wastebasket
- */
-
- SOM_Scope ULONG SOMLINK wpwastebskt_wpQueryStyle(WPWasteBskt *somSelf)
- {
- WPWasteBsktMethodDebug("WPWasteBskt","wpwastebskt_wpQueryStyle");
-
- return (parent_wpQueryStyle(somSelf) | OBJSTYLE_NOCOPY);
- }
-
- /*
- *
- * METHOD: wpDragOver PUBLIC
- * PURPOSE: To detect if the user is trying to drag permanent/undeletable objects to
- * the wastebasket. If they are, we will put up the no-drop sign.
- * INVOKED: By the Workplace Shell, when object(s) are dragged over the wastebasket
- */
-
- SOM_Scope MRESULT SOMLINK wpwastebskt_wpDragOver(WPWasteBskt *somSelf,
- HWND hwndCnr,
- PDRAGINFO pdrgInfo)
- {
- MRESULT mResult;
- USHORT usItem;
- SOMAny * Object;
- PDRAGITEM pDragItem;
-
- WPWasteBsktMethodDebug("WPWasteBskt","wpwastebskt_wpDragOver");
- mResult = parent_wpDragOver(somSelf, /*Get parent call to */
- hwndCnr, /*figure out if it is */
- pdrgInfo); /*droppable. */
- /* */
- if (SHORT1FROMMR(mResult)==DOR_NEVERDROP) /*Parent says NEVERDROP*/
- return(mResult); /*then return, otherwse*/
- /*Check if all usitems */
- /*are acceptable to the*/
- /*trash criteria */
- for (usItem=0; usItem < pdrgInfo->cditem; usItem++) {
- if ( !(pDragItem = DrgQueryDragitemPtr(pdrgInfo,usItem)) )
- return(MPFROM2SHORT(DOR_NEVERDROP,DO_DEFAULT));
- /* */
- if ( !(pDragItem -> ulItemID) ) /*No SOM Object ID */
- return(MPFROM2SHORT(DOR_NEVERDROP,DO_DEFAULT));
- /*Get Object ID */
- if (!(Object=OBJECT_FROM_PREC(pDragItem->ulItemID)) )
- return(MPFROM2SHORT(DOR_NEVERDROP,DO_DEFAULT));
- /* */
- if (_wpQueryStyle(Object)&OBJSTYLE_NODELETE) /*Check if deletable */
- return(MPFROM2SHORT(DOR_NEVERDROP,DO_DEFAULT));
- /* */
- if (pdrgInfo -> usOperation == DO_COPY || /*Check no Link or Copy*/
- pdrgInfo -> usOperation == DO_LINK) /*If so then return no */
- return(MPFROM2SHORT(DOR_NEVERDROP,DO_DEFAULT));
- } /*Loop throughall items*/
- return (MPFROM2SHORT(DOR_DROP,DO_MOVE));
-
- }
-
- /*
- *
- * METHOD: wpAddFolderIncludePage PUBLIC
- * PURPOSE: Allows us to remove the include page so the user can't hide any of the
- * items in the waste basket. This is important for we want the user to
- * always see the items so that something important is not accidentally
- * emptied.
- * INVOKED: By the Workplace Shell, when the include page is added to the settings view.
- */
-
- SOM_Scope ULONG SOMLINK wpwastebskt_wpAddFolderIncludePage(WPWasteBskt *somSelf,
- HWND hwndNotebook)
- {
- WPWasteBsktData *somThis = WPWasteBsktGetData(somSelf);
- WPWasteBsktMethodDebug("WPWasteBskt","wpwastebskt_wpAddFolderIncludePage");
- return TRUE;
- }
-
- /*
- *
- * METHOD: wpAddSettingsPages PUBLIC
- * PURPOSE: Allows us to add the AutoEmpty page to the settings view.
- * INVOKED: By the Workplace Shell, when the settings view is openned.
- */
-
- SOM_Scope BOOL SOMLINK wpwastebskt_wpAddSettingsPages(WPWasteBskt *somSelf,
- HWND hwndNotebook)
- {
- PAGEINFO pageinfo;
- WPWasteBsktData *somThis = WPWasteBsktGetData(somSelf);
- WPWasteBsktMethodDebug("WPWasteBskt","wpwastebskt_wpAddSettingsPages");
-
- if (!parent_wpAddSettingsPages(somSelf,hwndNotebook))
- return (FALSE);
-
- pageinfo.cb = sizeof(PAGEINFO);
- pageinfo.hwndPage = 0;
- pageinfo.pfnwp = AutoEmptyDlgProc;
- pageinfo.resid = hmodThisClass;
- pageinfo.pCreateParams = (PVOID)somSelf;
- pageinfo.dlgid = ID_DLG_AUTOEMPTY;
- pageinfo.usPageStyleFlags = BKA_MAJOR;
- pageinfo.usPageInsertFlags = BKA_FIRST;
- pageinfo.usReserved = 0;
- pageinfo.pszName="~Auto Empty";
- pageinfo.idDefaultHelpPanel = 0;
- pageinfo.usReserved2 = 0;
- pageinfo.pszHelpLibraryName = 0;
- pageinfo.pHelpSubtable = 0;
- pageinfo.hmodHelpSubtable = 0;
- pageinfo.ulPageInsertId = 0;
-
- return _wpInsertSettingsPage(somSelf, hwndNotebook, &pageinfo);
- }
-
- #undef SOM_CurrentClass
- #define SOM_CurrentClass SOMMeta
- /*
- * METHOD: wpclsQueryTitle PUBLIC
- * PURPOSE: This class method returns the default folder title for any
- * instance of the password protected folder class. This title
- * is used if a title is not supplied in the WinCreateObject()
- * call.
- * INVOKED: By the Workplace Shell, upon instantiation of the object
- * instance.
- */
-
- SOM_Scope PSZ SOMLINK wpwastebsktcls_wpclsQueryTitle(M_WPWasteBskt *somSelf)
- {
- /* M_WPWasteBsktData *somThis = M_WPWasteBsktGetData(somSelf); */
- M_WPWasteBsktMethodDebug("M_WPWasteBskt","wpwastebsktcls_wpclsQueryTitle");
- return(DefaultClassTitle); /* Return default title */
- }
-
- /*
- * METHOD: wpclsInitData PUBLIC
- * PURPOSE: This class method allows the initialization of any class data
- * items. The overridden method simply obtains a module handle
- * to be used when accessing Presentation Manager resources, then
- * invokes the parent's default processing.
- */
-
- SOM_Scope void SOMLINK wpwastebsktcls_wpclsInitData(M_WPWasteBskt *somSelf)
- {
- CHAR ErrorBuffer[100];
- M_WPWasteBsktMethodDebug("M_WPWasteBskt","wpwastebsktcls_wpclsInitData");
- DosLoadModule((PSZ) ErrorBuffer, /* Obtain DLL module handle */
- sizeof(ErrorBuffer),
- "WASTEBSK", /* Module name */
- &hmodThisClass); /* Module handle */
-
- hIcon=WinLoadPointer(HWND_DESKTOP, /* Load icons */
- hmodThisClass,
- ID_WASTEICO);
- parent_wpclsInitData(somSelf);
- }
-
- /*
- * METHOD: wpclsQueryIcon PUBLIC
- * PURPOSE: This class method returns the handle to the default icon for
- * the class. Allows setting of the icon to a wastebasket.
- */
-
- SOM_Scope HPOINTER SOMLINK wpwastebsktcls_wpclsQueryIcon(M_WPWasteBskt *somSelf)
- {
- M_WPWasteBsktMethodDebug("M_WPWasteBskt","wpwastebsktcls_wpclsQueryIcon");
- return (hIcon);
- }
-
- /*
- *
- * METHOD: wpclsUnInitData PUBLIC
- *
- * PURPOSE: This class method allows the release of any class data items
- * or resources. The overridden method releases the module handle
- * obtained by wpclsInitData, then invokes the parent's default
- * processing.
- * INVOKED: By the Workplace Shell, upon unloading the class DLL.
- */
-
- SOM_Scope void SOMLINK wpwastebsktcls_wpclsUnInitData(M_WPWasteBskt *somSelf)
- {
- /* M_WPWasteBsktData *somThis = M_WPWasteBsktGetData(somSelf); */
- M_WPWasteBsktMethodDebug("M_WPWasteBskt","wpwastebsktcls_wpclsUnInitData");
- WinDestroyPointer(hIcon);
- DosFreeModule(hmodThisClass); /* Free module handle */
- parent_wpclsUnInitData(somSelf);
- }
- /******************************************************************************/
- /* */
- /* PROCEDURE NAME: AutoEmptyDlgProc */
- /* */
- /* description: Dialog procedure for auto-empty page dialog */
- /* */
- /******************************************************************************/
- MRESULT EXPENTRY AutoEmptyDlgProc(HWND hwndDlg, ULONG msg, MPARAM mp1,
- MPARAM mp2)
- {
- SOMAny * Wastebasket;
- BOOL bAutoEmpty;
- switch (msg) /* Determine message class */
- {
- case WM_INITDLG: /* Dialog being initialized */
- WinSetWindowULong(hwndDlg, /* Store SOM pointer in */
- QWL_USER, /* window word QWL_USER */
- (ULONG)LONGFROMMP(mp2));
- Wastebasket = (WPWasteBskt *) LONGFROMMP(mp2);
- if (_QueryAutoEmptyFlag(Wastebasket)) {
- WinCheckButton(hwndDlg, ID_CB_AUTO, 1);
- } /* endif */
- break;
- case WM_CONTROL:
- Wastebasket = (WPWasteBskt *)WinQueryWindowULong(hwndDlg, QWL_USER);
- switch (SHORT1FROMMP(mp1)) {
- case ID_CB_AUTO:
- if (SHORT2FROMMP(mp1) == BN_CLICKED) {
- if (WinQueryButtonCheckstate(hwndDlg,ID_CB_AUTO)) {
- _SetAutoEmptyFlag(Wastebasket,FALSE);
- } else {
- _SetAutoEmptyFlag(Wastebasket,TRUE);
- } /* endif */
- _wpSaveDeferred(Wastebasket);
- } /* endif */
- break;
- } /* endswitch */
- break;
- }
- return(WinDefDlgProc(hwndDlg, msg, mp1, mp2));
- }