home *** CD-ROM | disk | FTP | other *** search
/ The Developer Connection…ice Driver Kit for OS/2 3 / DEV3-D1.ISO / source / wpshidl / samples / wpsamps / myfolder.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-11-18  |  9.1 KB  |  271 lines

  1.  
  2. /*
  3.  *  This file was generated by the SOM Compiler.
  4.  *  Generated using:
  5.  *     SOM incremental update: 2.7
  6.  */
  7.  
  8. /******************************************************************************
  9. *
  10. *  Module Name: MYFOLDER.C
  11. *
  12. *  OS/2 Work Place Shell IDL File BETA Sample Program
  13. *
  14. *  Copyright (C) 1993 IBM Corporation
  15. *
  16. *      DISCLAIMER OF WARRANTIES.  The following [enclosed] code is
  17. *      sample code created by IBM Corporation. This sample code is not
  18. *      part of any standard or IBM product and is provided to you solely
  19. *      for  the purpose of assisting you in the development of your
  20. *      applications.  The code is provided "AS IS", without
  21. *      warranty of any kind.  IBM shall not be liable for any damages
  22. *      arising out of your use of the sample code, even if they have been
  23. *      advised of the possibility of such damages.                                                    *
  24. *
  25. ******************************************************************************/
  26.  
  27. #define INCL_DOS
  28. #define INCL_PM
  29. #include <os2.h>
  30.  
  31. #define MYFOLDER_Class_Source
  32. #include "myfolder.ih"
  33.  
  34. /* global used to set the handle for the FIRST opened view of an object
  35.  * of class MYFOLDER.  This is a quick and dirty way to do this, you would
  36.  * probably want to have an instance variable (i.e. per object) to represent
  37.  * this meaningfully, but this is effective for demonstration purposes.
  38.  */
  39. HWND hwndFirstView = NULLHANDLE;
  40.  
  41. /*
  42.  * SOM_Scope HWND   SOMLINK myfold_wpOpen(MYFOLDER *somSelf,
  43.  *                 HWND hwndCnr,
  44.  *                 ULONG ulView,
  45.  *                 ULONG param)
  46.  *
  47.  * this wpOpen override does several special things:
  48.  *
  49.  * 1 - if the global hwndFirstView is not set yet, it assumes the
  50.  *     folder hasn't been opened yet.  When this is the case, a
  51.  *     MYFOLDER object will populate itself, and then search through
  52.  *     its contents for WPFolder objects and delete them before
  53.  *     opening the view (calling parent_wpOpen).  This may be useful
  54.  *     if you want a particular class of folder to clean up some of
  55.  *     its contents on a new boot, etc.
  56.  *
  57.  * 2 - After one MYFOLDER object has been opened once, hwndFirstView
  58.  *     will be set to the hwnd for that first view, to be used later
  59.  *     on in CloseViews below
  60.  */
  61.  
  62. SOM_Scope HWND  SOMLINK myfold_wpOpen(MYFOLDER *somSelf, HWND hwndCnr,
  63.                                       ULONG ulView, ULONG param)
  64. {
  65.     HWND        hwndParent = NULLHANDLE;
  66.     /* MYFOLDERData *somThis = MYFOLDERGetData(somSelf); */
  67.     MYFOLDERMethodDebug("MYFOLDER","myfold_wpOpen");
  68.  
  69.     if (hwndFirstView == NULLHANDLE)
  70.     {
  71.  
  72.        /* This will enable multiple views for MYFOLDER objects.
  73.         * Again, this method could be better placed (e.g. in an
  74.         * override for myfold_wpInitData or a similar initialization
  75.         * method)
  76.         */
  77.        _wpSetConcurrentView(somSelf, (USHORT) CCVIEW_ON);
  78.  
  79.        /* we ONLY want to do this on the FIRST open of the folder.
  80.         * notice that hwndFirstView is a global that we set after
  81.         * the folder has been opened once.
  82.         */
  83.        if (_wpPopulate(somSelf, NULLHANDLE, NULL, FALSE))
  84.         {
  85.            WPObject *Obj;
  86.            WPObject *LastFoundObj = NULL;
  87.  
  88.            /* loop through the contents of the folder, checking each to
  89.             * see if it is an instance of a class we want to delete
  90.             */
  91.            for ( Obj = _wpQueryContent(somSelf,NULL,(ULONG)QC_First);
  92.                  Obj;
  93.                  Obj = _wpQueryContent(somSelf, Obj, (ULONG) QC_Next ))
  94.            {
  95.               /* delete the last object found on the previous iteration
  96.                * of the loop (we couldn't delete it then, because we
  97.                * needed it at the top of the loop for this iteration)
  98.                */
  99.               if (LastFoundObj)
  100.               {
  101.                  _wpDelete(LastFoundObj,0);
  102.                  LastFoundObj = NULL;
  103.               }
  104.  
  105.               /* for example, we want to make sure that all previously
  106.                * existing WPFolders are deleted
  107.                */
  108.               if (_somIsA(Obj, _WPFolder))
  109.               {
  110.                  LastFoundObj = Obj;
  111.               }
  112.  
  113.            }  /* end for */
  114.  
  115.  
  116.            /* if there is still one object left to delete, do it now
  117.             */
  118.            if (LastFoundObj)
  119.            {
  120.               _wpDelete(LastFoundObj,0);
  121.               LastFoundObj = NULL;
  122.            }
  123.        } /* end if populate */
  124.     } /* end if first open */
  125.  
  126.     /* now, show the opened folder */
  127.     hwndParent = parent_wpOpen(somSelf, hwndCnr, ulView, param);
  128.  
  129.     /* if this is the first open, set our global flag, so everybody knows
  130.      */
  131.     if (hwndFirstView == NULLHANDLE)
  132.     {
  133.         hwndFirstView = hwndParent;
  134.     }
  135.  
  136.     return hwndParent;
  137. }
  138.  
  139. /* I put a "close views" option on my context menu, so that I could
  140.  * easily invoke my _CloseViews method
  141.  */
  142.  
  143. /*
  144.  * SOM_Scope BOOL  SOMLINK myfold_wpModifyPopupMenu(MYFOLDER somSelf,
  145.  *                                                  HWND hwndMenu,
  146.  *                                                  HWND hwndCnr,
  147.  *                                                  ULONG iPosition)
  148.  *
  149.  * this overide adds a new item to the context menu for MYFOLDER objects,
  150.  * one that, when selected, will invoke the _CloseViews method
  151.  */
  152.  
  153. SOM_Scope BOOL  SOMLINK myfold_wpModifyPopupMenu(MYFOLDER *somSelf,
  154.                                                  HWND hwndMenu,
  155.                                                  HWND hwndCnr,
  156.                                                  ULONG iPosition)
  157. {
  158.     HMODULE    hmod = NULLHANDLE;
  159.     zString    zsPathName;
  160.  
  161.     /* MYFOLDERData *somThis = MYFOLDERGetData(somSelf); */
  162.     MYFOLDERMethodDebug("MYFOLDER","myfold_wpModifyPopupMenu");
  163.  
  164.     /* querying the module handle in this manner is very expensive, and
  165.      * placed here for convenience.  it more properly belongs in the
  166.      * class initialization code, where a global hmod could be set once.
  167.      */
  168.     zsPathName =
  169.      _somLocateClassFile( SOMClassMgrObject, SOM_IdFromString("MYFOLDER"),
  170.                           MYFOLDER_MajorVersion, MYFOLDER_MinorVersion);
  171.  
  172.     DosQueryModuleHandle(zsPathName, &hmod);
  173.     _wpInsertPopupMenuItems( somSelf, hwndMenu, 0, hmod, ID_CLOSEVIEWSMENU, 0);
  174.  
  175.     return (parent_wpModifyPopupMenu(somSelf,hwndMenu,hwndCnr,iPosition));
  176. }
  177.  
  178.  
  179. /*
  180.  * SOM_Scope BOOL   SOMLINK myfold_wpMenuItemSelected(MYFOLDER *somSelf,
  181.  *                 HWND hwndFrame,
  182.  *                 ULONG ulMenuId)
  183.  *
  184.  * this override will invode the _CloseViews method for my new context
  185.  * menu item.
  186.  */
  187. SOM_Scope BOOL  SOMLINK myfold_wpMenuItemSelected(MYFOLDER *somSelf,
  188.                                                   HWND hwndFrame,
  189.                                                   ULONG ulMenuId)
  190. {
  191.     /* MYFOLDERData *somThis = MYFOLDERGetData(somSelf); */
  192.     MYFOLDERMethodDebug("MYFOLDER","myfold_wpMenuItemSelected");
  193.  
  194.     if (ulMenuId == IDM_CLOSEVIEWS)
  195.     {
  196.        _CloseViews(somSelf);
  197.        return(TRUE);
  198.     }
  199.     else
  200.     {
  201.        return (parent_wpMenuItemSelected(somSelf,hwndFrame,ulMenuId));
  202.     }
  203. }
  204.  
  205. /*
  206.  * SOM_Scope void  SOMLINK myfold_CloseViews(MYFOLDER somSelf)
  207.  *
  208.  * this will close all open views of somSelf, except for a view with
  209.  * the same hwnd as that set in myfold_wpOpen above (if one of its views
  210.  * was the first one opened, hwndFirstView).
  211.  * I am also assuming that you only are interested in closing open
  212.  * folder views (i.e. OPEN_CONTENTS, OPEN_SETTINGS, OPEN_TREE..., and
  213.  * not OPEN_RUNNING views).
  214.  */
  215. SOM_Scope void  SOMLINK myfold_CloseViews(MYFOLDER *somSelf)
  216. {
  217.     PUSEITEM  pUseItem, pUseItemNext;
  218.     PVIEWITEM pViewItem;
  219.     HWND      hwndView;
  220.     typedef struct _HANDLENODE
  221.     {
  222.        LHANDLE handle;
  223.        struct _HANDLENODE * pNextHandle;
  224.     } HANDLENODE;
  225.     HANDLENODE *pHandles = NULL;
  226.     HANDLENODE *pTemp = NULL;
  227.  
  228.     /* MYFOLDERData *somThis = MYFOLDERGetData(somSelf); */
  229.     MYFOLDERMethodDebug("MYFOLDER","myfold_CloseViews");
  230.  
  231.     /* go through use list looking for OPENVIEW use items, as you
  232.      * find one, add view item's handle to a list
  233.      */
  234.     for ( pUseItem = _wpFindUseItem(somSelf , USAGE_OPENVIEW, NULL);
  235.           pUseItem;
  236.           pUseItem = _wpFindUseItem(somSelf , USAGE_OPENVIEW, pUseItem) )
  237.     {
  238.        if (pTemp = (HANDLENODE*)_wpAllocMem(somSelf,sizeof(HANDLENODE),NULL))
  239.        {
  240.           pViewItem = (PVIEWITEM)(pUseItem + 1);
  241.           pTemp->handle = pViewItem->handle;
  242.           pTemp->pNextHandle = pHandles;
  243.           pHandles = pTemp;
  244.        }
  245.     }
  246.  
  247.     /* go through list of handles we just found and close any
  248.      * views other than the first one
  249.      */
  250.     pTemp = pHandles;
  251.     while (pTemp)
  252.     {
  253.        if (hwndFirstView != (HWND)pTemp->handle )
  254.        {
  255.           WinSendMsg( (HWND)pTemp->handle, WM_CLOSE, 0, 0);
  256.        }
  257.        pTemp = pTemp->pNextHandle;
  258.     }
  259.  
  260.     /* free our list */
  261.     while (pHandles)
  262.     {
  263.        pTemp = pHandles;
  264.        pHandles = pTemp->pNextHandle;
  265.        _wpFreeMem(somSelf,(PBYTE)pTemp);
  266.     }
  267.  
  268. }
  269.  
  270.  
  271.