home *** CD-ROM | disk | FTP | other *** search
/ High Voltage Shareware / high1.zip / high1 / DIR24 / WPPRG15.ZIP / WPPRGEXT.C < prev    next >
Text File  |  1993-12-17  |  17KB  |  567 lines

  1.  
  2. /*
  3.  * This file was generated by the SOM Compiler.
  4.  * FileName: wpprgext.c.
  5.  * Generated using:
  6.  *     SOM Precompiler spc: 1.22
  7.  *     SOM Emitter emitc: 1.24
  8.  */
  9.  
  10. /*
  11.  * 
  12.  * 
  13.  *   Module Name : WPPRGEXT
  14.  * 
  15.  *   Description : OS/2 Workplace Shell WPProgram Object Extension.
  16.  *                 This extension adds the option to close the folder
  17.  *                 to which the launching program belongs.
  18.  * 
  19.  *   Programmer  : Yong D. Lee
  20.  *   Date        : Nov 21, 1993
  21.  * 
  22.  *   Disclaimer of warranties:
  23.  *       The code is provided "AS IS", without warranty of any kind.  I shall
  24.  *       not be liable for any damages arising out of your use of this code.
  25.  * 
  26.  */
  27.  
  28. #define WPPrgExt_Class_Source
  29. #define M_WPPrgExt_Class_Source
  30.  
  31. #include "wpprgext.ih"
  32. #include "wpprgext.ph"
  33.  
  34. #include <string.h>
  35. #include <stdio.h>
  36. #include <memory.h>
  37. #include <stdlib.h>
  38.  
  39. /*************************************************************************/
  40. /*                                                                       */
  41. /*                     Non-method function prototype                     */
  42. /*                                                                       */
  43. /*************************************************************************/
  44.  
  45. MRESULT EXPENTRY FolderDlgProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2);
  46.  
  47. /*************************************************************************/
  48. /*                                                                       */
  49. /*               Global/Static (Non-Instance) Data Section               */
  50. /*                                                                       */
  51. /*************************************************************************/
  52.  
  53. UCHAR szWPPrgExtClassTitle[CCHMAXPATH] = "";
  54. HMODULE hmod = NULLHANDLE;
  55.  
  56. /*************************************************************************/
  57. /*                                                                       */
  58. /*                         Method Implementation                         */
  59. /*                                                                       */
  60. /*************************************************************************/
  61.  
  62. /*
  63.  * 
  64.  *  METHOD: QueryFolderClose                               ( ) PRIVATE
  65.  *                                                         (X) PUBLIC
  66.  *  DESCRIPTION:
  67.  * 
  68.  *    Query state of folder close flag
  69.  * 
  70.  *  RETURN:
  71.  * 
  72.  *    ULONG - folder closing option
  73.  * 
  74.  */
  75.  
  76. SOM_Scope ULONG   SOMLINK wpprgext_QueryFolderClose(WPPrgExt *somSelf)
  77. {
  78.     WPPrgExtData *somThis = WPPrgExtGetData(somSelf);
  79.     WPPrgExtMethodDebug("WPPrgExt","wpprgext_QueryFolderClose");
  80.  
  81.     return (ULONG) _folderClose;
  82. }
  83.  
  84. /*
  85.  *
  86.  *  METHOD: SetFolderClose                                 ( ) PRIVATE
  87.  *                                                         (X) PUBLIC
  88.  *  DESCRIPTION:
  89.  *
  90.  *    Set state of folder close flag
  91.  *
  92.  */
  93.  
  94. SOM_Scope VOID   SOMLINK wpprgext_SetFolderClose(WPPrgExt *somSelf, ULONG flag)
  95. {
  96.     WPPrgExtData *somThis = WPPrgExtGetData(somSelf);
  97.     WPPrgExtMethodDebug("WPPrgExt","wpprgext_SetFolderClose");
  98.  
  99.     _folderClose = flag;
  100. }
  101.  
  102. /*
  103.  * 
  104.  *  METHOD: AddFolderPage                                  ( ) PRIVATE
  105.  *                                                         (X) PUBLIC
  106.  *  DESCRIPTION:
  107.  * 
  108.  *    Add the folder page to the settings notebook
  109.  * 
  110.  *  RETURN:
  111.  * 
  112.  *    0              Unsuccessful
  113.  *    ulPageId       Identifier for the inserted page
  114.  * 
  115.  * 
  116.  *    Methods from the WPObject class
  117.  * 
  118.  */
  119.  
  120. SOM_Scope ULONG   SOMLINK wpprgext_AddFolderPage(WPPrgExt *somSelf, HWND hwndNotebook)
  121. {
  122.     PAGEINFO pageinfo;
  123.  
  124.     WPPrgExtData *somThis = WPPrgExtGetData(somSelf);
  125.     WPPrgExtMethodDebug("WPPrgExt","wpprgext_AddFolderPage");
  126.  
  127.     memset((PCH)&pageinfo, 0, sizeof(PAGEINFO));
  128.     pageinfo.cb = sizeof(PAGEINFO);
  129.     pageinfo.hwndPage = NULLHANDLE;
  130.     pageinfo.usPageStyleFlags = BKA_MAJOR;
  131.     pageinfo.usPageInsertFlags = BKA_LAST;
  132.     pageinfo.pfnwp = FolderDlgProc;
  133.     pageinfo.resid = hmod;
  134.     pageinfo.dlgid = IDD_FOLDER;
  135.     pageinfo.pszName = "Folder";
  136.     pageinfo.pCreateParams = somSelf;
  137.  
  138.     return _wpInsertSettingsPage(somSelf, hwndNotebook, &pageinfo);
  139. }
  140.  
  141. /*************************************************************************/
  142. /*                                                                       */
  143. /*                     Override Method Implementation                    */
  144. /*                                                                       */
  145. /*************************************************************************/
  146.  
  147. /*
  148.  * 
  149.  *  OVERRIDE: wpInitData
  150.  * 
  151.  *  DESCRIPTION:
  152.  * 
  153.  *    Initialize the state variables and allocate any extra memory
  154.  *    that might be needed
  155.  * 
  156.  */
  157.  
  158. SOM_Scope void   SOMLINK wpprgext_wpInitData(WPPrgExt *somSelf)
  159. {
  160.     WPPrgExtData *somThis = WPPrgExtGetData(somSelf);
  161.     WPPrgExtMethodDebug("WPPrgExt","wpprgext_wpInitData");
  162.  
  163.     memset((PVOID)somThis, 0, sizeof(WPPrgExtData));
  164.     _folderClose = DONOTCLOSE;
  165.  
  166.     parent_wpInitData(somSelf);
  167. }
  168.  
  169. /*
  170.  * 
  171.  *  OVERRIDE: wpUnInitData
  172.  * 
  173.  *  DESCRIPTION:
  174.  * 
  175.  *    Clear up memory that was allocated on wpInitData
  176.  * 
  177.  */
  178.  
  179. SOM_Scope void   SOMLINK wpprgext_wpUnInitData(WPPrgExt *somSelf)
  180. {
  181.     WPPrgExtData *somThis = WPPrgExtGetData(somSelf);
  182.     WPPrgExtMethodDebug("WPPrgExt","wpprgext_wpUnInitData");
  183.  
  184.     parent_wpUnInitData(somSelf);
  185. }
  186.  
  187. /*
  188.  * 
  189.  *  OVERRIDE: wpSaveState
  190.  * 
  191.  *  DESCRIPTION:
  192.  * 
  193.  *    Save state variable (folder close flag)
  194.  * 
  195.  */
  196.  
  197. SOM_Scope BOOL   SOMLINK wpprgext_wpSaveState(WPPrgExt *somSelf)
  198. {
  199.     WPPrgExtData *somThis = WPPrgExtGetData(somSelf);
  200.     WPPrgExtMethodDebug("WPPrgExt","wpprgext_wpSaveState");
  201.  
  202.     _wpSaveLong(somSelf, szWPPrgExtClassTitle, IDKEY_FOLDER, _folderClose);
  203.  
  204.     return (parent_wpSaveState(somSelf));
  205. }
  206.  
  207. /*
  208.  * 
  209.  *  OVERRIDE: wpRestoreState
  210.  * 
  211.  *  DESCRIPTION:
  212.  * 
  213.  *    Restore saved state variable
  214.  * 
  215.  */
  216.  
  217. SOM_Scope BOOL   SOMLINK wpprgext_wpRestoreState(WPPrgExt *somSelf, ULONG ulReserved)
  218. {
  219.     WPPrgExtData *somThis = WPPrgExtGetData(somSelf);
  220.     WPPrgExtMethodDebug("WPPrgExt","wpprgext_wpRestoreState");
  221.  
  222.     _wpRestoreLong(somSelf, szWPPrgExtClassTitle, IDKEY_FOLDER, &_folderClose);
  223.  
  224.     return (parent_wpRestoreState(somSelf,ulReserved));
  225. }
  226.  
  227. /*
  228.  * 
  229.  *  OVERRIDE: wpAddSettingsPages
  230.  * 
  231.  *  DESCRIPTION:
  232.  * 
  233.  *    Add folder settings page to let the user alter the flag
  234.  * 
  235.  */
  236.  
  237. SOM_Scope BOOL   SOMLINK wpprgext_wpAddSettingsPages(WPPrgExt *somSelf, HWND hwndNotebook)
  238. {
  239.     WPPrgExtData *somThis = WPPrgExtGetData(somSelf);
  240.     WPPrgExtMethodDebug("WPPrgExt","wpprgext_wpAddSettingsPages");
  241.  
  242.     if (parent_wpAddSettingsPages(somSelf, hwndNotebook) && _AddFolderPage(somSelf, hwndNotebook)) {
  243.         return (TRUE);
  244.     } else {
  245.         return (FALSE);
  246.     }
  247.   
  248. }
  249.  
  250. /*
  251.  * 
  252.  *   METHOD: wpOpen                                        
  253.  *                                                         
  254.  *   DESCRIPTION:
  255.  * 
  256.  *     Opens the program object window. Close folder upon openning 
  257.  *     according to folderClose flag
  258.  * 
  259.  */
  260.  
  261. SOM_Scope HWND   SOMLINK wpprgext_wpOpen(WPPrgExt *somSelf, HWND hwndCnr, ULONG ulView, ULONG param)
  262. {
  263.     LONG leftShift;
  264.     LONG rightShift;
  265.     BOOL close;
  266.     HWND hwndTop;
  267.  
  268.     WPPrgExtData *somThis = WPPrgExtGetData(somSelf);
  269.     WPPrgExtMethodDebug("WPPrgExt","wpprgext_wpOpen");
  270.  
  271.     if (!_wpSwitchTo(somSelf, ulView)) {
  272.  
  273.         /*
  274.          * Get the state of shift keys so that we can close the parent
  275.          * folder if shift key is pressed
  276.          */
  277.         leftShift = WinGetPhysKeyState(HWND_DESKTOP, 0x002a);
  278.         rightShift = WinGetPhysKeyState(HWND_DESKTOP, 0x0036);
  279.  
  280.         if ((leftShift & 0x8000) || (rightShift & 0x8000))
  281.             close = TRUE;
  282.         else {
  283.  
  284.             /*
  285.              * Check for the flags in the Folder page in settings notebook
  286.              */
  287.             switch (ulView) {
  288.  
  289.                 case OPEN_SETTINGS:
  290.  
  291.                     if (_folderClose & CLOSENOTEBOOK)
  292.                         close = TRUE;
  293.                     else
  294.                         close = FALSE;
  295.  
  296.                     break;
  297.  
  298.                 case OPEN_RUNNING:
  299.  
  300.                     if (_folderClose & CLOSEPROGRAM)
  301.                         close = TRUE;
  302.                     else
  303.                         close = FALSE;
  304.  
  305.                     break;
  306.  
  307.                 default:
  308.                     close = FALSE;
  309.  
  310.             }
  311.         }
  312.  
  313.         if (close) {
  314.  
  315.             /*
  316.              * The active window before opwning the new folder must be the parent folder.
  317.              * If it's not the desktop window (if there are no window below the parent
  318.              * folder in z-order), close the parent window
  319.              */
  320.             if (((hwndTop = WinQueryActiveWindow(HWND_DESKTOP)) != NULLHANDLE) && (WinQueryWindow(hwndTop, QW_NEXT) != NULLHANDLE))
  321.                 WinSendMsg(hwndTop, WM_CLOSE, (MPARAM)0, (MPARAM)0);
  322.  
  323.         }
  324.     }
  325.  
  326.     /*
  327.      * Call the original wpOpen
  328.      */
  329.     return (parent_wpOpen(somSelf, hwndCnr, ulView, param));
  330. }
  331. /*
  332.  * 
  333.  *  OVERRIDE: wpSetup
  334.  * 
  335.  *  DESCRIPTION:
  336.  * 
  337.  *    Specift setup strings and do some initialization
  338.  * 
  339.  */
  340.  
  341. SOM_Scope BOOL   SOMLINK wpprgext_wpSetup(WPPrgExt *somSelf, PSZ pszSetupString)
  342. {
  343.     WPPrgExtData *somThis = WPPrgExtGetData(somSelf);
  344.     WPPrgExtMethodDebug("WPPrgExt","wpprgext_wpSetup");
  345.  
  346.     return (parent_wpSetup(somSelf,pszSetupString));
  347. }
  348.  
  349. #undef SOM_CurrentClass
  350. #define SOM_CurrentClass SOMMeta
  351.  
  352. /*************************************************************************/
  353. /*                                                                       */
  354. /*                      Class Method Implementation                      */
  355. /*                                                                       */
  356. /*************************************************************************/
  357.  
  358. /*
  359.  *
  360.  *  METHOD: clsQueryModuleHandle                         ( ) PRIVATE
  361.  *                                                       (X) PUBLIC
  362.  *  DESCRIPTION:
  363.  *
  364.  *    This method returns the module handle of this class.
  365.  *
  366.  *  RETURN:
  367.  *
  368.  *    0          Unsuccessful
  369.  *    non-zero   Module handle
  370.  *
  371.  */
  372.  
  373. SOM_Scope HMODULE   SOMLINK wpprgextM_clsQueryModuleHandle(M_WPPrgExt *somSelf)
  374. {
  375.     zString zsPathName;
  376.     APIRET rc;
  377.  
  378.     /* M_WPPrgExtData *somThis = M_WPPrgExtGetData(somSelf); */
  379.     M_WPPrgExtMethodDebug("M_WPPrgExt","wpprgextM_clsQueryModuleHandle");
  380.  
  381.     if (hmod == NULLHANDLE) {
  382.  
  383.        /*
  384.         *   Retrieve registered pathname of our module (DLL) and query the
  385.         *   module handle.
  386.         */
  387.        zsPathName = _somLocateClassFile(SOMClassMgrObject,
  388.                                         SOM_IdFromString("WPPrgExt"),
  389.                                         WPPrgExt_MajorVersion,
  390.                                         WPPrgExt_MinorVersion);
  391.        rc = DosQueryModuleHandle(zsPathName, &hmod);
  392.     }
  393.  
  394.     return (hmod);
  395. }
  396.  
  397. /*************************************************************************/
  398. /*                                                                       */
  399. /*                  Override Class Method Implementation                 */
  400. /*                                                                       */
  401. /*************************************************************************/
  402.  
  403. /*
  404.  * 
  405.  *  METHOD: wpclsInitData
  406.  * 
  407.  *  DESCRIPTION:
  408.  * 
  409.  *    Initialize the class data
  410.  * 
  411.  */
  412.  
  413. SOM_Scope void   SOMLINK wpprgextM_wpclsInitData(M_WPPrgExt *somSelf)
  414. {
  415.  
  416.     /* M_WPPrgExtData *somThis = M_WPPrgExtGetData(somSelf); */
  417.     M_WPPrgExtMethodDebug("M_WPPrgExt","wpprgextM_wpclsInitData");
  418.  
  419.     parent_wpclsInitData(somSelf);
  420.  
  421.     /* 
  422.      * Get class title
  423.      */
  424.  
  425.     if (!WinLoadString(WinQueryAnchorBlock(HWND_DESKTOP), 
  426.                        _clsQueryModuleHandle(somSelf),  
  427.                        ID_TITLE,        
  428.                        sizeof(szWPPrgExtClassTitle),
  429.                        szWPPrgExtClassTitle))
  430.         strcpy(szWPPrgExtClassTitle, parent_wpclsQueryTitle(somSelf));
  431. }
  432.  
  433. /*
  434.  * 
  435.  *  METHOD: wpclsUnInitData
  436.  * 
  437.  *  DESCRIPTION:
  438.  * 
  439.  *    Free any class data
  440.  * 
  441.  */
  442.  
  443. SOM_Scope void   SOMLINK wpprgextM_wpclsUnInitData(M_WPPrgExt *somSelf)
  444. {
  445.     /* M_WPPrgExtData *somThis = M_WPPrgExtGetData(somSelf); */
  446.     M_WPPrgExtMethodDebug("M_WPPrgExt","wpprgextM_wpclsUnInitData");
  447.  
  448.     parent_wpclsUnInitData(somSelf);
  449. }
  450.  
  451. /*
  452.  *
  453.  *  METHOD: wpclsQueryTitle                                
  454.  *                                                         
  455.  *  DESCRIPTION:
  456.  *
  457.  *    Return the string "Extended Program".
  458.  *
  459.  */
  460.  
  461. SOM_Scope PSZ   SOMLINK wpprgextM_wpclsQueryTitle(M_WPPrgExt *somSelf)
  462. {
  463.     /* M_WPPrgExtData *somThis = M_WPPrgExtGetData(somSelf); */
  464.     M_WPPrgExtMethodDebug("M_WPPrgExt","wpprgextM_wpclsQueryTitle");
  465.  
  466.     /* 
  467.      * Return the class title for a WPPrgExt
  468.      */
  469.     if (*szWPPrgExtClassTitle)
  470.         return (szWPPrgExtClassTitle);
  471.     else 
  472.         return (parent_wpclsQueryTitle(somSelf));
  473.  
  474. }
  475.  
  476. /*************************************************************************/
  477. /*                                                                       */
  478. /*                   Non-method function implementation                  */
  479. /*                                                                       */
  480. /*************************************************************************/
  481.  
  482. MRESULT EXPENTRY FolderDlgProc(HWND hwndDlg, ULONG msg, MPARAM mp1, MPARAM mp2)
  483. {
  484.    PFOLDER pFolder;
  485.    MRESULT rc;
  486.  
  487.    switch(msg) {
  488.       case WM_INITDLG:
  489.          pFolder = (PFOLDER)_wpAllocMem((WPPrgExt *)mp2, sizeof(FOLDER), NULL);
  490.  
  491.          if (pFolder) {
  492.             memset((PVOID)pFolder, 0, sizeof(FOLDER));
  493.             pFolder->cb = sizeof(FOLDER);
  494.             pFolder->somSelf = (WPPrgExt *)mp2;
  495.             pFolder->closeFolder = _QueryFolderClose(pFolder->somSelf);
  496.          }
  497.          else 
  498.             break;
  499.  
  500.          WinSetWindowPtr(hwndDlg, QWL_USER, pFolder);
  501.  
  502.          if (pFolder->closeFolder & CLOSENOTEBOOK)
  503.             WinSendMsg(WinWindowFromID(hwndDlg, IDCHECK_CLOSENOTEBOOK), BM_SETCHECK, MPFROMSHORT(1), (MPARAM)0);
  504.          else
  505.             WinSendMsg(WinWindowFromID(hwndDlg, IDCHECK_CLOSENOTEBOOK), BM_SETCHECK, MPFROMSHORT(0), (MPARAM)0);
  506.  
  507.          if (pFolder->closeFolder & CLOSEPROGRAM)
  508.             WinSendMsg(WinWindowFromID(hwndDlg, IDCHECK_CLOSEPROGRAM), BM_SETCHECK, MPFROMSHORT(1), (MPARAM)0);
  509.          else
  510.             WinSendMsg(WinWindowFromID(hwndDlg, IDCHECK_CLOSEPROGRAM), BM_SETCHECK, MPFROMSHORT(0), (MPARAM)0);
  511.  
  512.          return (MRESULT)TRUE;
  513.  
  514.       case WM_CLOSE:
  515.          pFolder = WinQueryWindowPtr(hwndDlg, QWL_USER);
  516.  
  517.          if (pFolder == NULL) 
  518.              break;
  519.  
  520.          _wpFreeMem(pFolder->somSelf, (PBYTE)pFolder);
  521.          return (WinDefDlgProc(hwndDlg, msg, mp1, mp2));
  522.  
  523.       case WM_CONTROL:
  524.          pFolder = WinQueryWindowPtr(hwndDlg, QWL_USER);
  525.  
  526.          if (pFolder == NULL) 
  527.             break;
  528.  
  529.          switch (SHORT1FROMMP(mp1)) {
  530.  
  531.             case IDCHECK_CLOSENOTEBOOK:
  532.  
  533.                if (SHORT2FROMMP(mp1) == BN_CLICKED) {
  534.                   rc = WinSendMsg(WinWindowFromID(hwndDlg, IDCHECK_CLOSENOTEBOOK), BM_QUERYCHECK, (MPARAM)0, (MPARAM)0);
  535.  
  536.                   if ((USHORT)rc == 1)
  537.                      pFolder->closeFolder |= CLOSENOTEBOOK;
  538.                   else if ((USHORT)rc == 0)
  539.                      pFolder->closeFolder &= ~CLOSENOTEBOOK;
  540.  
  541.                   _SetFolderClose(pFolder->somSelf, pFolder->closeFolder);
  542.                }
  543.  
  544.                break;
  545.             case IDCHECK_CLOSEPROGRAM:
  546.  
  547.                if (SHORT2FROMMP(mp1) == BN_CLICKED) {
  548.                   rc = WinSendMsg(WinWindowFromID(hwndDlg, IDCHECK_CLOSEPROGRAM), BM_QUERYCHECK, (MPARAM)0, (MPARAM)0);
  549.  
  550.                   if ((USHORT)rc == 1)
  551.                      pFolder->closeFolder |= CLOSEPROGRAM;
  552.                   else if ((USHORT)rc == 0)
  553.                      pFolder->closeFolder &= ~CLOSEPROGRAM;
  554.  
  555.                   _SetFolderClose(pFolder->somSelf, pFolder->closeFolder);
  556.                }
  557.  
  558.                break;
  559.  
  560.          }
  561.       
  562.          return (MRESULT)TRUE;
  563.    }
  564.  
  565.    return (WinDefDlgProc(hwndDlg, msg, mp1, mp2));
  566.