home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / WSTBSK.ZIP / WASTEBSK.C < prev    next >
Text File  |  1993-03-04  |  20KB  |  480 lines

  1. /* Program name:   WasteBsk.C  Title: Implementing a Wastebasket in     */
  2. /* the Workplace Shell.                                                 */
  3. /* OS/2 Developer Magazine, Issue:  Winter '93, page 102                */
  4. /* Author:  Dave Hock                                                   */
  5. /*          UCANDU Software, Inc.                                       */
  6. /*          P.O Box 336                                                 */
  7. /*          Cary, NC 27512                                              */
  8. /* Description:  Source code for implementing a wastebasket on the      */
  9. /*               OS/2 2.0 Workplace Shell desktop.                      */
  10. /* Program Requirements:  OS/2 2.0, OS/2 Toolkit, IBM CSet/2, SOM       */
  11. /*                        Compiler.                                     */
  12.  
  13. /*
  14.  * This file was generated by the SOM Compiler.
  15.  * FileName: wastebsk.c.
  16.  * Generated using:
  17.  *     SOM Precompiler spc: 1.22
  18.  *     SOM Emitter emitc: 1.24
  19.  *
  20.  */
  21. #define INCL_WIN
  22. #define INCL_DOS
  23. #define INCL_GPIBITMAPS
  24. #define INCL_WPCLASS
  25. #define INCL_WPFOLDER
  26.  
  27. /******************************************************************************/
  28. /* System-defined header files                                                */
  29. /******************************************************************************/
  30. #include <os2.h>
  31.  
  32. #include <pmwp.h>  /* eventually will be #define INCL_WINWORKPLACE */
  33.  
  34. #include <stdio.h>
  35. #include <string.h>
  36.  
  37. /******************************************************************************/
  38. /* Function prototype for dialog proc                                         */
  39. /******************************************************************************/
  40. MRESULT EXPENTRY AutoEmptyDlgProc(HWND hwndDlg,
  41.                                  ULONG msg,
  42.                                  MPARAM mp1,
  43.                                  MPARAM mp2);
  44.  
  45. /******************************************************************************/
  46. /* Dialog definitions header file                                             */
  47. /******************************************************************************/
  48. #include "dialog.h"
  49. /******************************************************************************/
  50. /* Global data                                                                */
  51. /******************************************************************************/
  52. HMODULE  hmodThisClass;                          /* Module handle             */
  53. HPOINTER hIcon;                                         /* Handle for icon    */
  54.  
  55. PSZ      DefaultClassTitle = "Waste Basket";  /* Default folder title      */
  56.  
  57. #define WPWasteBskt_Class_Source
  58. #include "wastebsk.ih"
  59.  
  60. /*
  61.  *
  62.  *   METHOD:   QueryAutoEmptyFlag                                   PRIVATE
  63.  *   PURPOSE:
  64.  *   INVOKED:  From AutoEmptyDlgProc
  65.  */
  66.  
  67. SOM_Scope BOOL   SOMLINK wpwastebskt_QueryAutoEmptyFlag(WPWasteBskt *somSelf)
  68. {
  69.     WPWasteBsktData *somThis = WPWasteBsktGetData(somSelf);
  70.     WPWasteBsktMethodDebug("WPWasteBskt","wpwastebskt_QueryAutoEmptyFlag");
  71.  
  72.     return _bAutoEmpty;
  73. }
  74.  
  75. /*
  76.  *
  77.  *   METHOD:   SetAutoEmptyFlag                                     PRIVATE
  78.  *   PURPOSE:
  79.  *   INVOKED:  From AutoEmptyDlgProc
  80.  */
  81.  
  82. SOM_Scope BOOL   SOMLINK wpwastebskt_SetAutoEmptyFlag(WPWasteBskt *somSelf,
  83.                 BOOL bAutoEmpty)
  84. {
  85.     WPWasteBsktData *somThis = WPWasteBsktGetData(somSelf);
  86.     WPWasteBsktMethodDebug("WPWasteBskt","wpwastebskt_SetAutoEmptyInfo");
  87.  
  88.     _bAutoEmpty = bAutoEmpty;
  89.     return (BOOL) 0;
  90. }
  91.  
  92. /*
  93.  *
  94.  *   METHOD:   wpInitData                                  PUBLIC
  95.  *   PURPOSE:  Initializes instance data
  96.  *   INVOKED:  By Workplace Shell, upon instantiation of the object instance.
  97.  */
  98.  
  99. SOM_Scope void   SOMLINK wpwastebskt_wpInitData(WPWasteBskt *somSelf)
  100. {
  101.     WPWasteBsktMethodDebug("WPWasteBskt","wpwastebskt_wpInitData");
  102.  
  103.     parent_wpInitData(somSelf);
  104.     _SetAutoEmptyFlag(somSelf, FALSE);
  105. }
  106.  
  107. /*
  108.  *
  109.  *   METHOD:   wpModifyPopupMenu                           PUBLIC
  110.  *   PURPOSE:  Adds an additional "Empty now" item to the object's context menu.
  111.  *   INVOKED:  By Workplace Shell, upon instantiation of the object instance.
  112.  */
  113.  
  114. SOM_Scope BOOL   SOMLINK wpwastebskt_wpModifyPopupMenu(WPWasteBskt *somSelf,
  115.                 HWND hwndMenu,
  116.                 HWND hwndCnr,
  117.                 ULONG iPosition)
  118. {
  119.     WPWasteBsktMethodDebug("WPWasteBskt","wpwastebskt_wpModifyPopupMenu");
  120.  
  121.     /* add the empty now item if the waste basket is not empty */
  122.     if (_wpQueryContent(somSelf,0,QC_First)) {
  123.        _wpInsertPopupMenuItems(somSelf,             /* Insert menu item          */
  124.                                hwndMenu,            /* Menu handle               */
  125.                                iPosition,           /* Default position          */
  126.                                hmodThisClass,       /* Module handle             */
  127.                                ID_CXTMENU_WASTE,     /* Menu item identifier      */
  128.                                0);                  /* No submenu identifier     */
  129.     } /* endif */
  130.  
  131.     return (parent_wpModifyPopupMenu(somSelf,hwndMenu,hwndCnr,iPosition));
  132. }
  133.  
  134. /*
  135.  *
  136.  *   METHOD:   wpMenuItemSelected                          PUBLIC
  137.  *   PURPOSE:  Processes the user's selections from the context menu.  The
  138.  *             overridden method processes only the added "Empty now" item, before
  139.  *             invoking the parent's default processing to handle other items.
  140.  *   INVOKED:  By Workplace Shell, upon selection of a menu item by the user.
  141.  */
  142.  
  143. SOM_Scope BOOL   SOMLINK wpwastebskt_wpMenuItemSelected(WPWasteBskt *somSelf,
  144.                 HWND hwndFrame,
  145.                 ULONG ulMenuId)
  146. {
  147.     WPWasteBsktMethodDebug("WPWasteBskt","wpwastebskt_wpMenuItemSelected");
  148.     switch( ulMenuId )                           /* Switch on item identifier */
  149.     {
  150.        case IDM_EMPTY:
  151.           _wpDeleteContents(somSelf, TRUE);
  152.           break;
  153.  
  154.        default:                                  /* All other items           */
  155.            return (parent_wpMenuItemSelected(somSelf,hwndFrame,ulMenuId));
  156.           break;
  157.     }
  158. return TRUE;
  159. }
  160.  
  161. /*
  162.  *
  163.  *   METHOD:   wpSetup                                     PUBLIC
  164.  *   PURPOSE:  Sets folder properties based upon a setup string passed by the
  165.  *             object's creator as part of the WinCreateObject() call.  The
  166.  *             overridden method simply processes the AUTOEMPTY keyword to set
  167.  *             the folder's autoempty status and period, before
  168.  *             invoking the parent's default processing to handle all other
  169.  *             keywords.
  170.  *   INVOKED:  By the Workplace Shell, upon instantiation of the object
  171.  *             instance.
  172.  */
  173.  
  174. SOM_Scope BOOL   SOMLINK wpwastebskt_wpSetup(WPWasteBskt *somSelf,
  175.                 PSZ pszSetupString)
  176. {
  177.     BOOL          rc;
  178.     CHAR          szValue[256];
  179.     ULONG         cbValue;
  180.  
  181.     WPWasteBsktMethodDebug("WPWasteBskt","wpwastebskt_wpSetup");
  182.  
  183.     rc = parent_wpSetup(somSelf,pszSetupString);
  184.     cbValue = 256;
  185.     if (_wpScanSetupString(somSelf,pszSetupString,(PSZ)"AUTOEMPTY",szValue,&cbValue))
  186.     {
  187.       if (!strcmp(szValue,"TRUE")) {
  188.          _SetAutoEmptyFlag(somSelf, TRUE);
  189.       } else {
  190.          _SetAutoEmptyFlag(somSelf, FALSE);
  191.       } /* endif */
  192.     }
  193.     return rc;
  194. }
  195.  
  196. /*
  197.  *
  198.  *   METHOD:   wpSaveState                                 PUBLIC
  199.  *   PURPOSE:  Saves the object instance's persistent state data.  The
  200.  *             overridden method simply saves the autoempty info , then invokes
  201.  *             the parent's default processing to handle any other instance
  202.  *             data defined by ancestor classes.
  203.  *   INVOKED:  By the Workplace Shell, when the object becomes dormant.
  204.  */
  205.  
  206. SOM_Scope BOOL   SOMLINK wpwastebskt_wpSaveState(WPWasteBskt *somSelf)
  207. {
  208.     BOOL rc;
  209.     BOOL bAutoEmpty;
  210.     WPWasteBsktMethodDebug("WPWasteBskt","wpwastebskt_wpSaveState");
  211.  
  212.     rc = parent_wpSaveState(somSelf);
  213.     bAutoEmpty = _QueryAutoEmptyFlag(somSelf);
  214.     _wpSaveData(somSelf,_somGetClassName(somSelf),IDKEY_AUTOEMPTY,
  215.                   (PBYTE)&bAutoEmpty,sizeof(BOOL));
  216.  
  217.     return rc;
  218. }
  219.  
  220. /*
  221.  *
  222.  *   METHOD:   wpRestoreState                              PUBLIC
  223.  *   PURPOSE:  Restores the object instance's persistent state data.  The
  224.  *             overridden method simply restores the autoempty data, then
  225.  *             invokes the parent's default processing to handle any other
  226.  *             instance data defined by ancestor classes.
  227.  *   INVOKED:  By the Workplace Shell, when the object becomes awake.
  228.  */
  229.  
  230. SOM_Scope BOOL   SOMLINK wpwastebskt_wpRestoreState(WPWasteBskt *somSelf,
  231.                 ULONG ulReserved)
  232. {
  233.     BOOL rc;
  234.     BOOL bAutoEmpty;
  235.     ULONG cbValue;
  236.     WPWasteBsktMethodDebug("WPWasteBskt","wpwastebskt_wpRestoreState");
  237.  
  238.     rc = parent_wpRestoreState(somSelf,ulReserved);
  239.     cbValue = sizeof(BOOL);
  240.     if ( _wpRestoreData(somSelf,_somGetClassName(somSelf),IDKEY_AUTOEMPTY,(PBYTE)&bAutoEmpty,&cbValue) ) {
  241.        _SetAutoEmptyFlag(somSelf,bAutoEmpty);
  242.        if (bAutoEmpty) {
  243.           _wpDeleteContents(somSelf, TRUE);
  244.        } /* endif */
  245.     } /* endif */
  246.     return rc;
  247. }
  248.  
  249. /*
  250.  *
  251.  *   METHOD:   wpQueryStyle                                 PUBLIC
  252.  *   PURPOSE: Allows us to force a style such as OBJSYTLE_NOCOPY or NODELETE
  253.  *   INVOKED:  By the Workplace Shell, when object(s) are dragged over the wastebasket
  254.  */
  255.  
  256. SOM_Scope ULONG   SOMLINK wpwastebskt_wpQueryStyle(WPWasteBskt *somSelf)
  257. {
  258.     WPWasteBsktMethodDebug("WPWasteBskt","wpwastebskt_wpQueryStyle");
  259.  
  260.     return (parent_wpQueryStyle(somSelf) | OBJSTYLE_NOCOPY);
  261. }
  262.  
  263. /*
  264.  *
  265.  *   METHOD:   wpDragOver                                 PUBLIC
  266.  *   PURPOSE: To detect if the user is trying to drag permanent/undeletable objects to
  267.  *              the wastebasket.  If they are, we will put up the no-drop sign.
  268.  *   INVOKED:  By the Workplace Shell, when object(s) are dragged over the wastebasket
  269.  */
  270.  
  271. SOM_Scope MRESULT   SOMLINK wpwastebskt_wpDragOver(WPWasteBskt *somSelf,
  272.                 HWND hwndCnr,
  273.                 PDRAGINFO pdrgInfo)
  274. {
  275.     MRESULT mResult;
  276.     USHORT usItem;
  277.     SOMAny * Object;
  278.     PDRAGITEM pDragItem;
  279.  
  280.     WPWasteBsktMethodDebug("WPWasteBskt","wpwastebskt_wpDragOver");
  281.     mResult          = parent_wpDragOver(somSelf,   /*Get parent call to   */
  282.                                          hwndCnr,   /*figure out if it is  */
  283.                                          pdrgInfo); /*droppable.           */
  284.                                                     /*                     */
  285.     if (SHORT1FROMMR(mResult)==DOR_NEVERDROP)       /*Parent says NEVERDROP*/
  286.        return(mResult);                             /*then return, otherwse*/
  287.                                                     /*Check if all usitems */
  288.                                                     /*are acceptable to the*/
  289.                                                     /*trash criteria       */
  290.     for (usItem=0; usItem < pdrgInfo->cditem; usItem++) {
  291.        if ( !(pDragItem = DrgQueryDragitemPtr(pdrgInfo,usItem)) )
  292.           return(MPFROM2SHORT(DOR_NEVERDROP,DO_DEFAULT));
  293.                                                     /*                     */
  294.        if ( !(pDragItem -> ulItemID) )              /*No SOM Object ID     */
  295.           return(MPFROM2SHORT(DOR_NEVERDROP,DO_DEFAULT));
  296.                                                     /*Get Object ID        */
  297.        if (!(Object=OBJECT_FROM_PREC(pDragItem->ulItemID)) )
  298.           return(MPFROM2SHORT(DOR_NEVERDROP,DO_DEFAULT));
  299.                                                     /*                     */
  300.        if (_wpQueryStyle(Object)&OBJSTYLE_NODELETE) /*Check if deletable   */
  301.           return(MPFROM2SHORT(DOR_NEVERDROP,DO_DEFAULT));
  302.                                                     /*                     */
  303.        if (pdrgInfo -> usOperation == DO_COPY ||    /*Check no Link or Copy*/
  304.            pdrgInfo -> usOperation == DO_LINK)      /*If so then return no */
  305.           return(MPFROM2SHORT(DOR_NEVERDROP,DO_DEFAULT));
  306.       }                                             /*Loop throughall items*/
  307.     return (MPFROM2SHORT(DOR_DROP,DO_MOVE));
  308.  
  309. }
  310.  
  311. /*
  312.  *
  313.  *   METHOD:   wpAddFolderIncludePage                                 PUBLIC
  314.  *   PURPOSE:  Allows us to remove the include page so the user can't hide any of the
  315.  *              items in the waste basket.  This is important for we want the user to
  316.  *              always see the items so that something important is not accidentally
  317.  *              emptied.
  318.  *   INVOKED:  By the Workplace Shell, when the include page is added to the settings view.
  319.  */
  320.  
  321. SOM_Scope ULONG   SOMLINK wpwastebskt_wpAddFolderIncludePage(WPWasteBskt *somSelf,
  322.                 HWND hwndNotebook)
  323. {
  324.     WPWasteBsktData *somThis = WPWasteBsktGetData(somSelf);
  325.     WPWasteBsktMethodDebug("WPWasteBskt","wpwastebskt_wpAddFolderIncludePage");
  326.     return TRUE;
  327. }
  328.  
  329. /*
  330.  *
  331.  *   METHOD:   wpAddSettingsPages                              PUBLIC
  332.  *   PURPOSE:  Allows us to add the AutoEmpty page to the settings view.
  333.  *   INVOKED:  By the Workplace Shell, when the settings view is openned.
  334.  */
  335.  
  336. SOM_Scope BOOL   SOMLINK wpwastebskt_wpAddSettingsPages(WPWasteBskt *somSelf,
  337.                 HWND hwndNotebook)
  338. {
  339.     PAGEINFO pageinfo;
  340.     WPWasteBsktData *somThis = WPWasteBsktGetData(somSelf);
  341.     WPWasteBsktMethodDebug("WPWasteBskt","wpwastebskt_wpAddSettingsPages");
  342.  
  343.     if (!parent_wpAddSettingsPages(somSelf,hwndNotebook))
  344.         return (FALSE);
  345.  
  346.     pageinfo.cb = sizeof(PAGEINFO);
  347.     pageinfo.hwndPage = 0;
  348.     pageinfo.pfnwp = AutoEmptyDlgProc;
  349.     pageinfo.resid = hmodThisClass;
  350.     pageinfo.pCreateParams = (PVOID)somSelf;
  351.     pageinfo.dlgid = ID_DLG_AUTOEMPTY;
  352.     pageinfo.usPageStyleFlags = BKA_MAJOR;
  353.     pageinfo.usPageInsertFlags = BKA_FIRST;
  354.     pageinfo.usReserved = 0;
  355.     pageinfo.pszName="~Auto Empty";
  356.     pageinfo.idDefaultHelpPanel = 0;
  357.     pageinfo.usReserved2 = 0;
  358.     pageinfo.pszHelpLibraryName = 0;
  359.     pageinfo.pHelpSubtable = 0;
  360.     pageinfo.hmodHelpSubtable = 0;
  361.     pageinfo.ulPageInsertId = 0;
  362.  
  363.     return _wpInsertSettingsPage(somSelf, hwndNotebook, &pageinfo);
  364. }
  365.  
  366. #undef SOM_CurrentClass
  367. #define SOM_CurrentClass SOMMeta
  368. /*
  369.  *   METHOD:   wpclsQueryTitle                             PUBLIC
  370.  *   PURPOSE:  This class method returns the default folder title for any
  371.  *             instance of the password protected folder class.  This title
  372.  *             is used if a title is not supplied in the WinCreateObject()
  373.  *             call.
  374.  *   INVOKED:  By the Workplace Shell, upon instantiation of the object
  375.  *             instance.
  376.  */
  377.  
  378. SOM_Scope PSZ   SOMLINK wpwastebsktcls_wpclsQueryTitle(M_WPWasteBskt *somSelf)
  379. {
  380.     /* M_WPWasteBsktData *somThis = M_WPWasteBsktGetData(somSelf); */
  381.     M_WPWasteBsktMethodDebug("M_WPWasteBskt","wpwastebsktcls_wpclsQueryTitle");
  382.     return(DefaultClassTitle);                   /* Return default title      */
  383. }
  384.  
  385. /*
  386.  *   METHOD:   wpclsInitData                               PUBLIC
  387.  *   PURPOSE:  This class method allows the initialization of any class data
  388.  *             items.  The overridden method simply obtains a module handle
  389.  *             to be used when accessing Presentation Manager resources, then
  390.  *             invokes the parent's default processing.
  391.  */
  392.  
  393. SOM_Scope void   SOMLINK wpwastebsktcls_wpclsInitData(M_WPWasteBskt *somSelf)
  394. {
  395.     CHAR ErrorBuffer[100];
  396.     M_WPWasteBsktMethodDebug("M_WPWasteBskt","wpwastebsktcls_wpclsInitData");
  397.     DosLoadModule((PSZ) ErrorBuffer,             /* Obtain DLL module handle  */
  398.                   sizeof(ErrorBuffer),
  399.                   "WASTEBSK",                    /* Module name               */
  400.                   &hmodThisClass);                       /* Module handle             */
  401.  
  402.     hIcon=WinLoadPointer(HWND_DESKTOP,     /* Load icons                */
  403.                                hmodThisClass,
  404.                                ID_WASTEICO);
  405.     parent_wpclsInitData(somSelf);
  406. }
  407.  
  408. /*
  409.  *   METHOD:   wpclsQueryIcon                                 PUBLIC
  410.  *   PURPOSE:  This class method returns the handle to the default icon for
  411.  *             the class. Allows setting of the icon to a wastebasket.
  412.  */
  413.  
  414. SOM_Scope HPOINTER   SOMLINK wpwastebsktcls_wpclsQueryIcon(M_WPWasteBskt *somSelf)
  415. {
  416.     M_WPWasteBsktMethodDebug("M_WPWasteBskt","wpwastebsktcls_wpclsQueryIcon");
  417.     return (hIcon);
  418. }
  419.  
  420. /*
  421.  *
  422.  *   METHOD:   wpclsUnInitData                             PUBLIC
  423.  *
  424.  *   PURPOSE:  This class method allows the release of any class data items
  425.  *             or resources.  The overridden method releases the module handle
  426.  *             obtained by wpclsInitData, then invokes the parent's default
  427.  *             processing.
  428.  *   INVOKED:  By the Workplace Shell, upon unloading the class DLL.
  429.  */
  430.  
  431. SOM_Scope void   SOMLINK wpwastebsktcls_wpclsUnInitData(M_WPWasteBskt *somSelf)
  432. {
  433.     /* M_WPWasteBsktData *somThis = M_WPWasteBsktGetData(somSelf); */
  434.     M_WPWasteBsktMethodDebug("M_WPWasteBskt","wpwastebsktcls_wpclsUnInitData");
  435.     WinDestroyPointer(hIcon);
  436.     DosFreeModule(hmodThisClass);                        /* Free module handle        */
  437.     parent_wpclsUnInitData(somSelf);
  438. }
  439. /******************************************************************************/
  440. /*                                                                            */
  441. /* PROCEDURE NAME:  AutoEmptyDlgProc                                          */
  442. /*                                                                            */
  443. /* description:  Dialog procedure for auto-empty page dialog                  */
  444. /*                                                                            */
  445. /******************************************************************************/
  446. MRESULT EXPENTRY AutoEmptyDlgProc(HWND hwndDlg, ULONG msg, MPARAM mp1,
  447.                                  MPARAM mp2)
  448. {
  449.    SOMAny * Wastebasket;
  450.    BOOL bAutoEmpty;
  451.    switch (msg)                                  /* Determine message class   */
  452.    {
  453.       case WM_INITDLG:                           /* Dialog being initialized  */
  454.          WinSetWindowULong(hwndDlg,              /* Store SOM pointer in      */
  455.                           QWL_USER,              /* window word QWL_USER      */
  456.                           (ULONG)LONGFROMMP(mp2));
  457.          Wastebasket = (WPWasteBskt *) LONGFROMMP(mp2);
  458.          if (_QueryAutoEmptyFlag(Wastebasket)) {
  459.             WinCheckButton(hwndDlg, ID_CB_AUTO, 1);
  460.          } /* endif */
  461.          break;
  462.       case WM_CONTROL:
  463.          Wastebasket = (WPWasteBskt *)WinQueryWindowULong(hwndDlg, QWL_USER);
  464.          switch (SHORT1FROMMP(mp1)) {
  465.          case ID_CB_AUTO:
  466.             if (SHORT2FROMMP(mp1) == BN_CLICKED) {
  467.                if (WinQueryButtonCheckstate(hwndDlg,ID_CB_AUTO)) {
  468.                   _SetAutoEmptyFlag(Wastebasket,FALSE);
  469.                } else {
  470.                   _SetAutoEmptyFlag(Wastebasket,TRUE);
  471.                } /* endif */
  472.                _wpSaveDeferred(Wastebasket);
  473.             } /* endif */
  474.             break;
  475.          } /* endswitch */
  476.          break;
  477.    }
  478.    return(WinDefDlgProc(hwndDlg, msg, mp1, mp2));
  479. }
  480.