home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / warptlk3.zip / TOOLKIT / SAMPLES / WPS / WSFILE / WSFILE.C < prev    next >
Text File  |  1995-08-24  |  52KB  |  1,604 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: WSFILE.C
  11. *
  12. *  OS/2 Work Place Shell Sample Program
  13. *
  14. *  Copyright (C) 1994, 1995 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. *  Entry Points:
  26. *
  27. *     Class Methods:
  28. *
  29. *        wsfM_clsQueryModuleHandle
  30. *        wsfM_clsQueryDefaultFileText
  31. *
  32. *     Overridden Class Methods:
  33. *
  34. *        wsfM_wpclsInitData
  35. *        wsfM_wpclsQueryDefaultHelp
  36. *        wsfM_wpclsQueryDefaultView
  37. *        wsfM_wpclsQueryDetailsInfo
  38. *        wsfM_wpclsQueryIconData
  39. *        wsfM_wpclsQueryInstanceFilter
  40. *        wsfM_wpclsQueryStyle
  41. *        wsfM_wpclsQueryTitle
  42. *        wsfM_wpclsUnInitData
  43. *
  44. *     Instance Methods:
  45. *
  46. *        wsf_AddLastWorkerPage
  47. *        wsf_soundAlarm
  48. *        wsf_queryLastWorker
  49. *        wsf_setLastWorker
  50. *
  51. *     Overridden Instance Methods:
  52. *
  53. *        wsf_wpAddSettingsPages
  54. *        wsf_wpFilterPopupMenu
  55. *        wsf_wpInitData
  56. *        wsf_wpMenuItemHelpSelected
  57. *        wsf_wpMenuItemSelected
  58. *        wsf_wpModifyPopupMenu
  59. *        wsf_wpOpen
  60. *        wsf_wpQueryDetailsData
  61. *        wsf_wpRestoreState
  62. *        wsf_wpSaveState
  63. *        wsf_wpUnInitData
  64. *        wsf_wpFormatDragItem
  65. *        wsf_wpSetup
  66. *        wsf_wpSetupOnce
  67. *
  68. *     Non-Method Functions:
  69. *
  70. *        WSFILEInit
  71. *        WSFILEWndProc
  72. *        LastWorkerDlgProc
  73. *
  74. ******************************************************************************/
  75.  
  76. #define WSFILE_Class_Source
  77. #define M_WSFILE_Class_Source
  78.  
  79. #include "wsfile.ih"
  80. /* CSC2IDL:  REMOVED after .csc -> .idl conversion:  #include "wsfile.ph" */
  81.  
  82. #include <string.h>
  83. #include <stdio.h>
  84. #include <memory.h>
  85. #include <stdlib.h>
  86.  
  87. /*
  88.  *   Non-Method function prototypes
  89.  */
  90.  
  91. HWND             WSFILEInit (WSFILE*);
  92. MRESULT EXPENTRY LastWorkerDlgProc( HWND hwnd, ULONG msg,
  93.                                    MPARAM mp1, MPARAM mp2 );
  94. MRESULT EXPENTRY WSFILEWndProc ( HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2 );
  95.  
  96.  
  97. /***************** GLOBAL/STATIC (NON-INSTANCE) DATA SECTION ******************
  98. *****                                                                     *****
  99. *****    This data shouldn't be changed by instance methods or it will    *****
  100. *****    affect all instances!  Any variables that are specific (unique   *****
  101. *****    values) for each instance of this object should be declared as   *****
  102. *****  instance data or dynamically allocated and stored as window data.  *****
  103. *****                                                                     *****
  104. *****      This global data should be declared as class instance data     *****
  105. *****    if it will change after initialization.  In this case, it will   *****
  106. *****                  be accessed through class methods.                 *****
  107. *****                                                                     *****
  108. ******************************************************************************/
  109.  
  110.  
  111.    CHAR       szWSFILEWindowClass[] =    "WSFILESAMPLE";
  112.    CHAR       szWSFILEInstanceFilter[] = "*.txt";
  113.    CHAR       szHelpLibrary[] =       "wsfile.hlp";
  114.    UCHAR      szWSFILEClassTitle[CCHMAXPATH] = "";
  115.    HMODULE    hmod = NULLHANDLE;
  116.  
  117.    /*
  118.     *   Statics required for FIELDINFO structures needed for DETAILS view are
  119.     *   handled in the three functions:
  120.     *
  121.     *   wsf_wpclsInitData, wsf_wpQueryDetailsData, wsf_wpQueryClassDetailsInfo
  122.     */
  123.  
  124.    #define NUM_WSFILE_FIELDS    1
  125.  
  126.    CLASSFIELDINFO fieldinfo[NUM_WSFILE_FIELDS];      /* structure in wsfile.h */
  127.  
  128.    PSZ apszWSFILEColTitles[] =
  129.    {
  130.       "Last Worker"           /* details column 1 */
  131.    };
  132.  
  133.  
  134. /*************************  INSTANCE METHODS SECTION  *************************
  135. *****                                                                     *****
  136. *****              Do not put any code in this section unless             *****
  137. *****                   it is an object INSTANCE method                   *****
  138. *****                                                                     *****
  139. ******************************************************************************/
  140. #undef SOM_CurrentClass
  141. #define SOM_CurrentClass SOMInstance
  142.  
  143.  
  144. /*
  145.  *
  146.  *  METHOD: queryLastWorker                                ( ) PRIVATE
  147.  *                                                         (X) PUBLIC
  148.  *  DESCRIPTION:
  149.  *
  150.  *    Query name of last person to work with wsfile
  151.  *
  152.  *  RETURN:
  153.  *
  154.  *    PSZ            name of last person to work on file
  155.  *
  156.  */
  157. SOM_Scope PSZ   SOMLINK wsf_queryLastWorker(WSFILE *somSelf)
  158. {
  159.     WSFILEData *somThis = WSFILEGetData(somSelf);
  160.     WSFILEMethodDebug("WSFILE","wsf_queryLastWorker");
  161.  
  162.     return _pszLastWorker;
  163. } /* end wsf_queryLastWorker */
  164.  
  165. /*
  166.  *
  167.  *  METHOD: setLastWorker                                  ( ) PRIVATE
  168.  *                                                         (X) PUBLIC
  169.  *  DESCRIPTION:
  170.  *
  171.  *    Set name of last person to work with wsfile
  172.  *
  173.  *  RETURN:
  174.  *
  175.  *    BOOL     Successful
  176.  *
  177.  */
  178. SOM_Scope BOOL   SOMLINK wsf_setLastWorker(WSFILE *somSelf,
  179.                 PSZ pszWorkerName)
  180. {
  181.     BOOL rc = FALSE;
  182.  
  183.     WSFILEData *somThis = WSFILEGetData(somSelf);
  184.     WSFILEMethodDebug("WSFILE","wsf_setLastWorker");
  185.  
  186.     if (pszWorkerName)
  187.     {
  188.       if (_pszLastWorker)
  189.       {
  190.          _wpFreeMem(somSelf, (PBYTE) _pszLastWorker);
  191.          _pszLastWorker = (PSZ) _wpAllocMem(somSelf, strlen(pszWorkerName)+1, NULL);
  192.          strcpy(_pszLastWorker, pszWorkerName);
  193.          _wpCnrRefreshDetails(somSelf);
  194.          rc = TRUE;
  195.       }
  196.     }
  197.     return(rc);
  198.  
  199. } /* end wsf_setLastWorker */
  200.  
  201. /*
  202.  *
  203.  *  METHOD: soundAlarm                                     ( ) PRIVATE
  204.  *                                                         (X) PUBLIC
  205.  *  DESCRIPTION:
  206.  *
  207.  *    Sound an alarm
  208.  *
  209.  *  RETURN:
  210.  *
  211.  *    TRUE           Successful
  212.  *    FALSE          Unsuccessful
  213.  *
  214.  */
  215. SOM_Scope BOOL   SOMLINK wsf_soundAlarm(WSFILE *somSelf)
  216. {
  217.     WSFILEData *somThis = WSFILEGetData(somSelf);
  218.     WSFILEMethodDebug("WSFILE","wsf_soundAlarm");
  219.  
  220.     DosBeep(100,50);
  221.     DosSleep(100);
  222.     DosBeep(100,50);
  223.     DosSleep(100);
  224.     DosBeep(100,50);
  225.     DosSleep(100);
  226.     DosBeep(100,50);
  227.     DosSleep(100);
  228.     DosBeep(100,50);
  229.     DosSleep(300);
  230.     DosBeep(100, 100);
  231.     DosSleep(100);
  232.     DosBeep(100, 100);
  233.  
  234.     return TRUE;
  235. } /* end wsf_soundAlarm */
  236.  
  237. /*
  238.  *
  239.  *  METHOD: AddLastWorkerPage                              ( ) PRIVATE
  240.  *                                                         (X) PUBLIC
  241.  *  DESCRIPTION:
  242.  *
  243.  *    This method adds the Last Worker page to the settings notebook.
  244.  *
  245.  *  RETURN:
  246.  *
  247.  *    0              Unsuccessful
  248.  *    ulPageId       Identifier for the inserted page
  249.  *
  250.  *  HOW TO OVERRIDE:
  251.  *
  252.  *    Method should always be overridden in order to replace or remove
  253.  *    the last worker page from an object which is a descendent of wsfile.
  254.  *    In most cases, an override of this method will not call the parent.
  255.  *
  256.  */
  257. SOM_Scope ULONG   SOMLINK wsf_AddLastWorkerPage(WSFILE *somSelf,
  258.                 HWND hwndNotebook)
  259. {
  260.     PAGEINFO pageinfo;
  261.  
  262.     WSFILEData *somThis = WSFILEGetData(somSelf);
  263.     WSFILEMethodDebug("WSFILE","wsf_AddLastWorkerPage");
  264.  
  265.     memset((PCH)&pageinfo,0,sizeof(PAGEINFO));
  266.     pageinfo.cb                 = sizeof(PAGEINFO);
  267.     pageinfo.hwndPage           = NULLHANDLE;
  268.     pageinfo.usPageStyleFlags   = BKA_MAJOR;
  269.     pageinfo.usPageInsertFlags  = BKA_FIRST;
  270.     pageinfo.pfnwp              = LastWorkerDlgProc;
  271.     pageinfo.resid              = hmod;
  272.     pageinfo.dlgid              = IDD_LASTWORKER;
  273.     pageinfo.pszName            = "LastWorker";
  274.     pageinfo.pCreateParams      = somSelf;
  275.     pageinfo.idDefaultHelpPanel = ID_HELP_LASTWORKER;
  276.     pageinfo.pszHelpLibraryName = szHelpLibrary;
  277.  
  278.     return _wpInsertSettingsPage( somSelf, hwndNotebook, &pageinfo );
  279.  
  280. }   /* end wsf_AddLastWorkerPage() */
  281.  
  282. /*
  283.  *
  284.  *  OVERRIDE: wpInitData                                   ( ) PRIVATE
  285.  *                                                         (X) PUBLIC
  286.  *  DESCRIPTION:
  287.  *
  288.  *    Initialize our state variables. Allocate any extra memory that
  289.  *    we might need.
  290.  *
  291.  */
  292. SOM_Scope void SOMLINK wsf_wpInitData(WSFILE *somSelf)
  293. {
  294.     WSFILEData *somThis = WSFILEGetData(somSelf);
  295.     WSFILEMethodDebug("WSFILE","wsf_wpInitData");
  296.  
  297.     parent_wpInitData(somSelf);
  298.  
  299.     _pszLastWorker = (PSZ) _wpAllocMem(somSelf, CCHMAXPATH+1, NULL);
  300.     if (_pszLastWorker)
  301.     {
  302.        strcpy(_pszLastWorker, DEFAULT_LASTWORKER);
  303.     }
  304.  
  305.  
  306. }   /* end wsf_wpInitData() */
  307.  
  308. /*
  309.  *
  310.  *  OVERRIDE: wpUnInitData                                 ( ) PRIVATE
  311.  *                                                         (X) PUBLIC
  312.  *  DESCRIPTION:
  313.  *
  314.  *    Clear up memory that was allocated on wpInitData.
  315.  *
  316.  */
  317. SOM_Scope void   SOMLINK wsf_wpUnInitData(WSFILE *somSelf)
  318. {
  319.     WSFILEData *somThis = WSFILEGetData(somSelf);
  320.     WSFILEMethodDebug("WSFILE","wsf_wpUnInitData");
  321.  
  322.     if (_pszLastWorker)
  323.     {
  324.       _wpFreeMem(somSelf, (PBYTE)_pszLastWorker);
  325.     }
  326.     parent_wpUnInitData(somSelf);
  327.  
  328. }   /* end wsf_wpUnInitData() */
  329.  
  330.  
  331. /*
  332.  *
  333.  *  METHOD: wpSaveState                                    ( ) PRIVATE
  334.  *                                                         (X) PUBLIC
  335.  *  DESCRIPTION:
  336.  *
  337.  *    Save our state variables (last worker).
  338.  *
  339.  */
  340. SOM_Scope BOOL SOMLINK wsf_wpSaveState(WSFILE *somSelf)
  341. {
  342.     WSFILEData *somThis = WSFILEGetData(somSelf);
  343.     WSFILEMethodDebug("WSFILE","wsf_wpSaveState");
  344.  
  345.     _wpSaveString( somSelf, szWSFILEClassTitle,
  346.                    IDKEY_LASTWORKER, _pszLastWorker);
  347.  
  348.     return (parent_wpSaveState(somSelf));
  349.  
  350. }   /* end wsf_wpSaveState() */
  351.  
  352. /*
  353.  *
  354.  *  METHOD: wpRestoreState                                 ( ) PRIVATE
  355.  *                                                         (X) PUBLIC
  356.  *  DESCRIPTION:
  357.  *
  358.  *    Retrieve our saved state variables (last worker).
  359.  *
  360.  */
  361. SOM_Scope BOOL SOMLINK wsf_wpRestoreState(WSFILE *somSelf, ULONG ulReserved)
  362. {
  363.     ULONG cbString;
  364.     WSFILEData *somThis = WSFILEGetData(somSelf);
  365.     WSFILEMethodDebug("WSFILE","wsf_wpRestoreState");
  366.  
  367.     _wpRestoreString( somSelf, szWSFILEClassTitle,
  368.                       IDKEY_LASTWORKER, _pszLastWorker, &cbString );
  369.  
  370.     return (parent_wpRestoreState(somSelf,ulReserved));
  371.  
  372. }   /* wsf_wpRestoreState() */
  373.  
  374. /*
  375.  *
  376.  *  METHOD: wpAddSettingsPages                             ( ) PRIVATE
  377.  *                                                         (X) PUBLIC
  378.  *  DESCRIPTION:
  379.  *
  380.  *    Add our own settings page to let the user modify the
  381.  *    last worker's name.
  382.  *
  383.  */
  384. SOM_Scope BOOL SOMLINK wsf_wpAddSettingsPages(WSFILE *somSelf, HWND hwndNotebook)
  385. {
  386.     WSFILEData *somThis = WSFILEGetData(somSelf);
  387.     WSFILEMethodDebug("WSFILE","wsf_wpAddSettingsPages");
  388.  
  389.     if (parent_wpAddSettingsPages(somSelf, hwndNotebook)
  390.              && _AddLastWorkerPage(somSelf, hwndNotebook))
  391.     {
  392.         return(TRUE);
  393.     }
  394.     else
  395.     {
  396.         DebugBox("wsf_wpAddSettingsPages", " Failed to add a settings page.");
  397.         return( FALSE );
  398.     }
  399.  
  400. }   /* wsf_wpAddSettingsPages() */
  401.  
  402. /*
  403.  *
  404.  *  METHOD: wpFilterPopupMenu                              ( ) PRIVATE
  405.  *                                                         (X) PUBLIC
  406.  *  DESCRIPTION:
  407.  *
  408.  *    Filter out any options from the context that don't apply,
  409.  *    (e.g. we take out "Create Shadow")
  410.  *
  411.  *  HOW TO OVERRIDE:
  412.  *
  413.  *    No restrictions.
  414.  *
  415.  */
  416. SOM_Scope ULONG SOMLINK wsf_wpFilterPopupMenu(WSFILE *somSelf,
  417.                 ULONG ulFlags,
  418.                 HWND hwndCnr,
  419.                 BOOL fMultiSelect)
  420. {
  421.     WSFILEData *somThis = WSFILEGetData(somSelf);
  422.     WSFILEMethodDebug("WSFILE","wsf_wpFilterPopupMenu");
  423.  
  424.     /*
  425.      *   This method allows you to filter which menus to include in the
  426.      *   popup menu.  Note: wpclsQueryStyle is overridden to disallow
  427.      *   linking (creating shadow) as well.
  428.      */
  429.     return( parent_wpFilterPopupMenu(somSelf,ulFlags,hwndCnr,
  430.                     fMultiSelect) & ~CTXT_LINK );
  431.  
  432. }   /* end wsf_wpFilterPopupMenu() */
  433.  
  434. /*
  435.  *
  436.  *  METHOD: wpModifyPopupMenu                              ( ) PRIVATE
  437.  *                                                         (X) PUBLIC
  438.  *  DESCRIPTION:
  439.  *
  440.  *    Add our extra option to the context menu
  441.  *
  442.  */
  443. SOM_Scope BOOL SOMLINK wsf_wpModifyPopupMenu(WSFILE *somSelf,
  444.                 HWND hwndMenu,
  445.                 HWND hwndCnr,
  446.                 ULONG iPosition)
  447. {
  448.     WSFILEData *somThis = WSFILEGetData(somSelf);
  449.     WSFILEMethodDebug("WSFILE","wsf_wpModifyPopupMenu");
  450.  
  451.     /*
  452.      *   Put in our special "open wsfile" submenu item under the "open" menu
  453.      */
  454.     _wpInsertPopupMenuItems( somSelf, hwndMenu, 0,
  455.                                hmod, ID_OPENMENU, WPMENUID_OPEN);
  456.     /*
  457.      *   insert a "beep horn" menu item at the end of the list.
  458.      */
  459.     _wpInsertPopupMenuItems( somSelf, hwndMenu, iPosition,
  460.                                hmod, ID_ALARMMENU, 0 );
  461.  
  462.     return (parent_wpModifyPopupMenu(somSelf,hwndMenu,hwndCnr,iPosition));
  463.  
  464. }   /* end wsf_wpModifyPopupMenu() */
  465.  
  466. /*
  467.  *
  468.  *  METHOD: wpMenuItemSelected                             ( ) PRIVATE
  469.  *                                                         (X) PUBLIC
  470.  *  DESCRIPTION:
  471.  *
  472.  *    Process the extra menu options that we added.
  473.  *
  474.  */
  475. SOM_Scope BOOL SOMLINK wsf_wpMenuItemSelected(WSFILE *somSelf,
  476.                 HWND hwndFrame,
  477.                 ULONG MenuId)
  478. {
  479.     WSFILEData *somThis = WSFILEGetData(somSelf);
  480.     WSFILEMethodDebug("WSFILE","wsf_wpMenuItemSelected");
  481.  
  482.     /* Which of our menu items was selected ?
  483.      */
  484.     switch( MenuId )
  485.     {
  486.        case IDM_OPENWSFILE:
  487.           /*
  488.            *   We could call wpOpen here, but, if the object is already opened,
  489.            *   the following API determines whether the object should be
  490.            *   resurfaced, or if multiple views are desired.
  491.            */
  492.           _wpViewObject(somSelf, NULLHANDLE, OPEN_WSFILE, 0);
  493.           break;
  494.  
  495.        case IDM_SOUNDALARM:
  496.           _soundAlarm(somSelf);
  497.           break;
  498.  
  499.        default:
  500.           return parent_wpMenuItemSelected(somSelf, hwndFrame, MenuId);
  501.           break;
  502.     }
  503.     return TRUE;                                          /* we processed it */
  504.  
  505. }   /* end wsf_wpMenuItemSelected() */
  506.  
  507. /*
  508.  *
  509.  *  METHOD: wpMenuItemHelpSelected                         ( ) PRIVATE
  510.  *                                                         (X) PUBLIC
  511.  *  DESCRIPTION:
  512.  *
  513.  *    Process help from the extra menu options that we added.
  514.  *
  515.  */
  516. SOM_Scope BOOL SOMLINK wsf_wpMenuItemHelpSelected(WSFILE *somSelf,
  517.                 ULONG MenuId)
  518. {
  519.     WSFILEData *somThis = WSFILEGetData(somSelf);
  520.     WSFILEMethodDebug("WSFILE","wsf_wpMenuItemHelpSelected");
  521.  
  522.     /* Which of our menu items was selected ?
  523.      */
  524.    switch( MenuId )
  525.    {
  526.       case IDM_SOUNDALARM:
  527.  
  528.          return(_wpDisplayHelp(somSelf,ID_HELP_SOUNDALARM,szHelpLibrary));
  529.          break;
  530.  
  531.       case IDM_OPENWSFILE:
  532.  
  533.          return(_wpDisplayHelp(somSelf,ID_HELP_OPENWSFILE,szHelpLibrary));
  534.          break;
  535.  
  536.       default:
  537.          break;
  538.    }
  539.  
  540.    return (parent_wpMenuItemHelpSelected(somSelf,MenuId));
  541.  
  542. }   /* end wsf_wpMenuItemHelpSelected() */
  543.  
  544. /*
  545.  *
  546.  *  METHOD: wpQueryDetailsData                             ( ) PRIVATE
  547.  *                                                         (X) PUBLIC
  548.  *  DESCRIPTION:
  549.  *
  550.  *    Returns the wsfile specific data for the details view of this object.
  551.  *    Sets the pointer (*ppDetailsData) to the beginning of the buffer
  552.  *    into which the data is written.
  553.  *
  554.  */
  555. SOM_Scope ULONG SOMLINK wsf_wpQueryDetailsData(WSFILE *somSelf,
  556.                 PVOID *ppDetailsData,
  557.                 PULONG pcp)
  558. {
  559.     PWSFILEDETAILS pWSFILEDetails;
  560.     PBYTE       pSize;
  561.     WSFILEData *somThis = WSFILEGetData(somSelf);
  562.     WSFILEMethodDebug("WSFILE","wsf_wpQueryDetailsData");
  563.  
  564.    parent_wpQueryDetailsData(somSelf,ppDetailsData, pcp);
  565.  
  566.    if (ppDetailsData)                                          /* query data */
  567.    {
  568.       pWSFILEDetails                  = (PWSFILEDETAILS) *ppDetailsData;
  569.       pWSFILEDetails->pszLastWorker   = _queryLastWorker(somSelf);
  570.  
  571.       /* point to buffer location after our details data */
  572.       *ppDetailsData = ((PBYTE) (*ppDetailsData)) + sizeof(*pWSFILEDetails);
  573.  
  574.    }   /* end if (ppDetailsData) */
  575.    else                                                /* query size of data */
  576.    {
  577.       *pcp += sizeof(*pWSFILEDetails);     /* caller is querying size of buffer */
  578.    }
  579.  
  580.    return(TRUE);
  581.  
  582. }   /* end wsf_wpQueryDetailsData() */
  583.  
  584. /*
  585.  *
  586.  *   METHOD: wpOpen                                         ( ) PRIVATE
  587.  *                                                          (X) PUBLIC
  588.  *   DESCRIPTION:
  589.  *
  590.  *     Opens the wsfile window.
  591.  *
  592.  */
  593. SOM_Scope HWND SOMLINK wsf_wpOpen(WSFILE *somSelf,
  594.                 HWND hwndCnr,
  595.                 ULONG ulView,
  596.                 ULONG param)
  597. {
  598.  WSFILEData *somThis = WSFILEGetData(somSelf);
  599.  WSFILEMethodDebug("WSFILE","wsf_wpOpen");
  600.  
  601.    switch (ulView)
  602.    {
  603.       case OPEN_WSFILE:
  604.  
  605.           /*
  606.            *   Create a basic Frame and Client window for this instance.
  607.            */
  608.          return WSFILEInit(somSelf);
  609.  
  610.       default:
  611.          return parent_wpOpen(somSelf,hwndCnr,ulView,param);
  612.  
  613.    }   /* end switch (ulView) */
  614.  
  615. }   /* end wsf_wpOpen() */
  616.  
  617.  
  618.  
  619. /*
  620.  *
  621.  *  METHOD: wpSetupOnce                                    ( ) PRIVATE
  622.  *                                                         (X) PUBLIC
  623.  *  DESCRIPTION:
  624.  *
  625.  *    Specify ONE TIME initialization.  This method is
  626.  *    invoked once on an object when it is initially created.
  627.  *
  628.  *    The one time initialization we're doing is to write
  629.  *    some default data to the file
  630.  */
  631. SOM_Scope BOOL   SOMLINK wsf_wpSetupOnce(WSFILE *somSelf,
  632.                 PSZ pszSetupString)
  633. {
  634.     WSFILEData *somThis = WSFILEGetData(somSelf);
  635.     ULONG  cbBytesWritten;         /* pointer to variable receiving byte count */
  636.     APIRET rc;
  637.     BOOL   fSuccess;
  638.     HFILE  hf;                          /* pointer to variable for file handle */
  639.     ULONG  ulAction;                   /* pointer to variable for action taken */
  640.     CHAR   szObjectFilename[CCHMAXPATH];       /* buffer for wpQueryRealName() */
  641.     ULONG  cb  = sizeof(szObjectFilename);
  642.     PSZ    pszDefaultText;
  643.  
  644.     WSFILEMethodDebug("WSFILE","wsf_wpSetupOnce");
  645.  
  646.    /*
  647.     *   When the object is created from scratch, put some default
  648.     *   text into the file on the hard disk
  649.     */
  650.  
  651.    fSuccess =
  652.    _wpQueryRealName(                 /* query full-pathname of object's file */
  653.       somSelf,                                     /* pointer to this object */
  654.       szObjectFilename,                                     /* return buffer */
  655.       &cb,                                                  /* sizeof buffer */
  656.       TRUE);                            /* request fully qualified pathname? */
  657.  
  658.    if (fSuccess)
  659.    {
  660.       rc =
  661.       DosOpen(szObjectFilename, &hf, &ulAction,
  662.          0,                             /* file size if created or truncated */
  663.          FILE_NORMAL,                                      /* file attribute */
  664.          FILE_OPEN             /* action taken if file exists/does not exist */
  665.             | FILE_CREATE,
  666.          OPEN_ACCESS_READWRITE                          /* open mode of file */
  667.             | OPEN_SHARE_DENYNONE,
  668.          NULL);              /* pointer to structure for extended attributes */
  669.  
  670.       if (rc)
  671.       {
  672.        CHAR ach[10];
  673.  
  674.          _ltoa(rc, ach, 10);
  675.          DebugBox("wsf_wpSetup:DosOpen failed rc =", ach);
  676.       }
  677.       else
  678.       {
  679.          pszDefaultText = _clsQueryDefaultFileText(_WSFILE);
  680.          DosWrite(hf, pszDefaultText, strlen(pszDefaultText), &cbBytesWritten);
  681.          DosClose(hf);
  682.       }
  683.    }   /* end if (fSuccess) */
  684.  
  685.    return parent_wpSetupOnce(somSelf,pszSetupString);
  686.  
  687. }   /* end wsf_wpSetupOnce() */
  688.  
  689.  
  690. /*
  691.  *
  692.  *  METHOD: wpSetup                                        ( ) PRIVATE
  693.  *                                                         (X) PUBLIC
  694.  *  DESCRIPTION:
  695.  *
  696.  *    Specify Setup strings to do special one time processing
  697.  *
  698.  *  New key\value to be parsed and processed by this override:
  699.  *
  700.  *             SOUND=(YES/NO)   YES will invoke _soundAlarm method
  701.  *                              NO  will do nothing
  702.  *
  703.  */
  704. SOM_Scope BOOL   SOMLINK wsf_wpSetup(WSFILE *somSelf,
  705.                 PSZ pszSetupString)
  706. {
  707.     WSFILEData *somThis = WSFILEGetData(somSelf);
  708.     BOOL   rcParentCall;
  709.     CHAR   szValue[CCHMAXPATH+1];
  710.     ULONG  cbBuffer;
  711.  
  712.     WSFILEMethodDebug("WSFILE","wsf_wpSetup");
  713.  
  714.    rcParentCall = parent_wpSetup(somSelf,pszSetupString);
  715.  
  716.    cbBuffer = CCHMAXPATH;
  717.    if ( _wpScanSetupString(somSelf,pszSetupString,"SOUND",
  718.                            szValue,&cbBuffer) )
  719.    {
  720.       if ((szValue[0] == 'Y') && (szValue[1] == 'E') && (szValue[2] == 'S'))
  721.       {
  722.          _soundAlarm(somSelf);
  723.       }
  724.    }
  725.  
  726.   return rcParentCall;
  727.  
  728. }   /* end wsf_wpSetup() */
  729.  
  730.  
  731. /*
  732.  * METHOD: wpFormatDragItem                              ( ) PRIVATE
  733.  *                                                       (X) PUBLIC
  734.  * DESCRIPTION:
  735.  *
  736.  *   Specify a unique RMF that will only be understood by instances
  737.  *   of class WSFOLDER.  (see _wpDragOver and _wpDrop overrides in
  738.  *   wsfolder.c).
  739.  */
  740. SOM_Scope BOOL   SOMLINK wsf_wpFormatDragItem(WSFILE *somSelf,
  741.                 PDRAGITEM pdrgItem)
  742. {
  743. /*  WSFILEData *somThis = WSFILEGetData(somSelf); */
  744.     WSFILEMethodDebug("WSFILE","wsf_wpFormatDragItem");
  745.  
  746.     parent_wpFormatDragItem(somSelf,pdrgItem);
  747.  
  748.     /* We do NOT want to really let the workplace shell render
  749.      * our object, so change the rendering mechanism and format
  750.      * to be uniquely ours.
  751.      */
  752.     DrgDeleteStrHandle(pdrgItem->hstrRMF);
  753.  
  754.     pdrgItem->hstrRMF = DrgAddStrHandle("<DRM_OUROWNSPECIAL,DRF_OBJECT>");
  755.  
  756.     return TRUE;
  757. }
  758.  
  759.  
  760. /**************************  CLASS METHODS SECTION  ***************************
  761. *****                                                                     *****
  762. *****              Do not put any code in this section unless             *****
  763. *****                     it is an object CLASS method                    *****
  764. *****                                                                     *****
  765. ******************************************************************************/
  766. #undef SOM_CurrentClass
  767. #define SOM_CurrentClass SOMMeta
  768.  
  769.  
  770. /*
  771.  *
  772.  *  METHOD: clsQueryModuleHandle                           ( ) PRIVATE
  773.  *                                                         (X) PUBLIC
  774.  *  DESCRIPTION:
  775.  *
  776.  *    This method returns the module handle of this class.  If this is the
  777.  *    first invocation, DosQueryModuleHandle is called to save the handle
  778.  *    for future invocations.
  779.  *
  780.  *  RETURN:
  781.  *
  782.  *    0              Unsuccessful
  783.  *    non-zero       module handle
  784.  *
  785.  */
  786. SOM_Scope HMODULE   SOMLINK wsfM_clsQueryModuleHandle(M_WSFILE *somSelf)
  787. {
  788.  APIRET rc;
  789.  
  790.     /* M_WSFILEData *somThis = M_WSFILEGetData(somSelf); */
  791.     M_WSFILEMethodDebug("M_WSFILE","wsfM_clsQueryModuleHandle");
  792.  
  793.    /*
  794.     *   Make sure we already have module handle
  795.     */
  796.  
  797.     if (hmod == NULLHANDLE)
  798.     {
  799.      zString zsPathName;
  800.        /*
  801.         *   Retrieve registered pathname of our module (DLL) and query the
  802.         *   module handle.
  803.         */
  804.        zsPathName =
  805.        _somLocateClassFile( SOMClassMgrObject, SOM_IdFromString("WSFILE"),
  806.                                               WSFILE_MajorVersion, WSFILE_MinorVersion);
  807.        rc =
  808.        DosQueryModuleHandle( zsPathName, &hmod);
  809.        if (rc)
  810.        {
  811.           DebugBox("wsfM_wpclsInitData", "Failed to load module");
  812.           return;
  813.        }
  814.  
  815.     }   /* end if (hmod == NULLHANDLE) */
  816.  
  817.     return (hmod);
  818.  
  819. }   /* end wsfM_clsQueryModuleHandle() */
  820.  
  821.  
  822.  
  823. /*
  824.  *
  825.  *  METHOD: clsQueryDefaultFileText                        ( ) PRIVATE
  826.  *                                                         (X) PUBLIC
  827.  *  DESCRIPTION:
  828.  *
  829.  *    This method returns some default text to stuff in an empty WSFILE.
  830.  *
  831.  *  RETURN:
  832.  *
  833.  *    PSZ
  834.  *
  835.  */
  836. SOM_Scope PSZ   SOMLINK wsfM_clsQueryDefaultFileText(M_WSFILE *somSelf)
  837. {
  838.     /* M_WSFILEData *somThis = M_WSFILEGetData(somSelf); */
  839.     M_WSFILEMethodDebug("M_WSFILE","wsfM_clsQueryDefaultFileText");
  840.  
  841.     return (PSZ) "This is an empty file of class WSFILE";
  842. } /* end wsfM_clsQueryDefaultFileText */
  843.  
  844. /*
  845.  *
  846.  *  METHOD: wpclsQueryStyle                                ( ) PRIVATE
  847.  *                                                         (X) PUBLIC
  848.  *  DESCRIPTION:
  849.  *
  850.  *     The wpclsQueryStyle method is called to allow the class object
  851.  *     to specify the default object class style for its instances.
  852.  *
  853.  *  REMARKS:
  854.  *
  855.  *     This method can be called at any time in order to determine the
  856.  *     default style for instances of this class.
  857.  *
  858.  *     This method should be overridden in order to modify the default
  859.  *     object style for instances of this class.
  860.  *
  861.  */
  862. SOM_Scope ULONG   SOMLINK wsfM_wpclsQueryStyle(M_WSFILE *somSelf)
  863. {
  864.     /* M_WSFILEData *somThis = M_WSFILEGetData(somSelf); */
  865.     M_WSFILEMethodDebug("M_WSFILE","wsfM_wpclsQueryStyle");
  866.  
  867.     /*
  868.      *   Modify style bits as described in programming reference.  This
  869.      *   particular style (link) is also disabled in wpFilterPopupMenu()
  870.      */
  871.     return (parent_wpclsQueryStyle(somSelf) | CLSSTYLE_NEVERLINK );
  872. }
  873.  
  874. /*
  875.  *
  876.  *  METHOD: wpclsInitData                                  ( ) PRIVATE
  877.  *                                                         (X) PUBLIC
  878.  *  DESCRIPTION:
  879.  *
  880.  *    Initalize the class data
  881.  *
  882.  */
  883. SOM_Scope void SOMLINK wsfM_wpclsInitData(M_WSFILE *somSelf)
  884. {
  885.  ULONG rc, i;
  886.  PCLASSFIELDINFO pCFI;
  887.  
  888.     /* M_WSFILEData *somThis  = M_WSFILEGetData(somSelf); */
  889.     M_WSFILEMethodDebug("M_WSFILE","wsfM_wpclsInitData");
  890.  
  891.     /*
  892.      *   Call the parent class method first
  893.      */
  894.     parent_wpclsInitData(somSelf);
  895.  
  896.     /*
  897.      *   Get class title
  898.      */
  899.     if (!WinLoadString(WinQueryAnchorBlock(HWND_DESKTOP), _clsQueryModuleHandle(somSelf), ID_TITLE,
  900.                          sizeof(szWSFILEClassTitle), szWSFILEClassTitle))
  901.                               /* Load string failed: use the parent's string */
  902.        strcpy(szWSFILEClassTitle, parent_wpclsQueryTitle(somSelf));
  903.  
  904.    /*
  905.     *   Initialize everything needed for the CLASSFIELDINFO structures
  906.     *   for the WSFILE object class
  907.     */
  908.  
  909.    for (i=0, pCFI=fieldinfo; i < NUM_WSFILE_FIELDS; i++, pCFI++)
  910.    {
  911.       memset((PCH) pCFI, 0, sizeof(CLASSFIELDINFO));               /* zero's */
  912.  
  913.       pCFI->cb        = sizeof(CLASSFIELDINFO);
  914.       pCFI->flData    = CFA_RIGHT | CFA_SEPARATOR | CFA_FIREADONLY;
  915.       pCFI->flTitle   = CFA_CENTER | CFA_SEPARATOR | CFA_HORZSEPARATOR |
  916.                         CFA_STRING | CFA_FITITLEREADONLY;
  917.       pCFI->pNextFieldInfo = pCFI + 1;       /* point to next CLASSFIELDINFO */
  918.       pCFI->pTitleData = (PVOID) apszWSFILEColTitles[i];
  919.       pCFI->flCompare  = COMPARE_SUPPORTED | SORTBY_SUPPORTED;
  920.  
  921.       switch (i)
  922.       {
  923.          case INDEX_LASTWORKER:
  924.  
  925.             pCFI->flData           |= CFA_STRING;
  926.             pCFI->offFieldData      = (ULONG)(FIELDOFFSET(WSFILEDETAILS,pszLastWorker));
  927.             pCFI->ulLenFieldData    = sizeof(PSZ);
  928.             pCFI->DefaultComparison = CMP_EQUAL;
  929.  
  930.             break;
  931.  
  932.       }   /* end switch(i) */
  933.  
  934.    }   /* end for (i=0, pCFI=fieldinfo; i < NUM_WSFILE_FIELDS; i++, pCFI++)  */
  935.  
  936.    fieldinfo[NUM_WSFILE_FIELDS-1].pNextFieldInfo = NULL;/* terminate linked list */
  937.  
  938. }   /* end wsfM_ wpclsInitData() */
  939.  
  940. /*
  941.  *
  942.  *  METHOD: wpclsUnInitData                                ( ) PRIVATE
  943.  *                                                         (X) PUBLIC
  944.  *  DESCRIPTION:
  945.  *
  946.  *    Free any class data
  947.  *
  948.  */
  949. SOM_Scope void SOMLINK wsfM_wpclsUnInitData(M_WSFILE *somSelf)
  950. {
  951.     M_WSFILEMethodDebug("M_WSFILE","wsfM_wpclsUnInitData");
  952.  
  953.     parent_wpclsUnInitData(somSelf);
  954.  
  955. }   /* end wsfM_wpclsUnInitData() */
  956.  
  957. /*
  958.  *
  959.  *  METHOD: wpclsQueryTitle                                ( ) PRIVATE
  960.  *                                                         (X) PUBLIC
  961.  *  DESCRIPTION:
  962.  *
  963.  *    Return the string "wsfile".
  964.  *
  965.  */
  966. SOM_Scope PSZ SOMLINK wsfM_wpclsQueryTitle(M_WSFILE *somSelf)
  967. {
  968.  /* M_WSFILEData *somThis = M_WSFILEGetData(somSelf); */
  969.     M_WSFILEMethodDebug("M_WSFILE","wsfM_wpclsQueryTitle");
  970.  
  971.     /*
  972.      *   Return the class title for a wsfile
  973.      */
  974.  
  975.     if (*szWSFILEClassTitle )
  976.        return( szWSFILEClassTitle );
  977.     else
  978.        return( parent_wpclsQueryTitle(somSelf));
  979.  
  980. }   /* end wsfM_wpclsQueryTitle() */
  981.  
  982. /*
  983.  *
  984.  *  METHOD: wpclsQueryIconDdata                            ( ) PRIVATE
  985.  *                                                         (X) PUBLIC
  986.  *  DESCRIPTION:
  987.  *
  988.  *    Return the class icon
  989.  *
  990.  */
  991. SOM_Scope ULONG SOMLINK wsfM_wpclsQueryIconData(M_WSFILE *somSelf,
  992.                   PICONINFO pIconInfo)
  993. {
  994.    APIRET rc;
  995.  
  996.    M_WSFILEMethodDebug("M_WSFILE","wsfM_wpclsQueryIconData");
  997.  
  998.    if (pIconInfo)
  999.    {
  1000.       /*
  1001.        *   fill in icon information
  1002.        */
  1003.       pIconInfo->fFormat = ICON_RESOURCE;
  1004.       pIconInfo->hmod= _clsQueryModuleHandle(somSelf);
  1005.       pIconInfo->resid= ID_ICON;
  1006.    }
  1007.  
  1008.    return (sizeof(ICONINFO));
  1009.  
  1010. }   /* end wsfM_wpclsQueryIconData() */
  1011.  
  1012. /*
  1013.  *
  1014.  *  METHOD: wpclsQueryDefaultHelp                          ( ) PRIVATE
  1015.  *                                                         (X) PUBLIC
  1016.  *  DESCRIPTION:
  1017.  *
  1018.  *    Process input from the extra menu option that we added.
  1019.  *
  1020.  */
  1021. SOM_Scope BOOL SOMLINK wsfM_wpclsQueryDefaultHelp(M_WSFILE *somSelf,
  1022.                 PULONG pHelpPanelId,
  1023.                 PSZ pszHelpLibrary)
  1024. {
  1025.  /* M_WSFILEData *somThis = M_WSFILEGetData(somSelf); */
  1026.     M_WSFILEMethodDebug("M_WSFILE","wsfM_wpclsQueryDefaultHelp");
  1027.  
  1028.     if (pHelpPanelId)                           /* set default help panel id */
  1029.        *pHelpPanelId   = ID_HELP_DEFAULT;
  1030.  
  1031.     if (pszHelpLibrary)                                /* copy help filename */
  1032.        strcpy(pszHelpLibrary, szHelpLibrary);
  1033.  
  1034.     return (TRUE);
  1035.  
  1036. }   /* end wsfM_wpclsQueryDefaultHelp() */
  1037.  
  1038. /*
  1039.  *
  1040.  *  METHOD: wpclsQueryDefaultView                          ( ) PRIVATE
  1041.  *                                                         (X) PUBLIC
  1042.  *  DESCRIPTION:
  1043.  *
  1044.  *    Returns the default view for a new instance of this object.
  1045.  *
  1046.  *  REMARKS:
  1047.  *
  1048.  *    Tell the system what our default open view is...
  1049.  *
  1050.  */
  1051. SOM_Scope ULONG SOMLINK wsfM_wpclsQueryDefaultView(M_WSFILE *somSelf)
  1052. {
  1053.  /* M_WSFILEData *somThis = M_WSFILEGetData(somSelf); */
  1054.     M_WSFILEMethodDebug("M_WSFILE","wsfM_wpclsQueryDefaultView");
  1055.  
  1056.     return OPEN_WSFILE;
  1057.  
  1058. }   /* end wsfM_wpclsQueryDefaultView() */
  1059.  
  1060. /*
  1061.  *
  1062.  *  METHOD: wpclsQueryDetailsInfo                          ( ) PRIVATE
  1063.  *                                                         (X) PUBLIC
  1064.  *  DESCRIPTION:
  1065.  *
  1066.  *    Appends the wsfile specific chain of FIELDINFO structures describing the
  1067.  *    details data of this object to *ppClassFieldInfo (if ppClassFieldInfo
  1068.  *    is NON-NULL).  In this case it also sets *ppClassFieldInfo to the
  1069.  *    head of the linked list.
  1070.  *
  1071.  *    Adds the number of bytes required by the details data for wsfile to *pSize
  1072.  *    (if pSize is NON-NULL).
  1073.  *
  1074.  *  REMARKS:
  1075.  *
  1076.  *    Add details data for this object.
  1077.  *
  1078.  */
  1079. SOM_Scope ULONG SOMLINK wsfM_wpclsQueryDetailsInfo(M_WSFILE *somSelf,
  1080.                 PCLASSFIELDINFO *ppClassFieldInfo,
  1081.                 PULONG pSize)
  1082. {
  1083.  ULONG           cParentColumns;
  1084.  PCLASSFIELDINFO pCFI;
  1085.  ULONG           i;
  1086.  
  1087.     /* M_WSFILEData *somThis = M_WSFILEGetData(somSelf); */
  1088.     M_WSFILEMethodDebug("M_WSFILE","wsfM_wpclsQueryDetailsInfo");
  1089.  
  1090.    /*
  1091.     *   Always call the parent method first to retrieve number of details
  1092.     *   columns and parent's data already defined in details buffer.
  1093.     */
  1094.  
  1095.    cParentColumns =
  1096.    parent_wpclsQueryDetailsInfo(somSelf, ppClassFieldInfo, pSize);
  1097.  
  1098.    /*
  1099.     *   If pSize is non-NULL, we must add the size of our deatils column
  1100.     *   data structure.
  1101.     */
  1102.  
  1103.    if (pSize)
  1104.       *pSize += sizeof(WSFILEDETAILS);                           /* adjust size */
  1105.  
  1106.    /*
  1107.     *   If the request was for the chained fieldinfo structures
  1108.     *   (ppClassFieldInfo is non-NULL), link them in
  1109.     *
  1110.     *   eventually the chain will look like
  1111.     *
  1112.     *   Grandad - Dad - Me - Kid - Grandkid
  1113.     *
  1114.     *   I will be getting the pointer to the beginning of the chain
  1115.     *
  1116.     *   If the beginning of the chain is 0, I will assign the address
  1117.     *   of my first CLASSFIELDINFO structure to *ppClassFieldInfo.
  1118.     *   Otherwise *pp points to the first column description in the
  1119.     *   chain.  We need to walk the chain and link our CLASSFIELDINFO
  1120.     *   structures at the end.
  1121.     */
  1122.  
  1123.    if (ppClassFieldInfo)
  1124.    {
  1125.       /*
  1126.        *   Find the last link in the chain;  Then link our CLASSFIELDINFO
  1127.        *   structures to the chain.
  1128.        */
  1129.  
  1130.       if (*ppClassFieldInfo)
  1131.       {
  1132.          pCFI = *ppClassFieldInfo;
  1133.          for (i=0;i<cParentColumns;i++)
  1134.             pCFI = (pCFI->pNextFieldInfo) ? pCFI->pNextFieldInfo : pCFI;
  1135.  
  1136.          pCFI->pNextFieldInfo = fieldinfo;
  1137.       }
  1138.       else
  1139.          *ppClassFieldInfo = fieldinfo;
  1140.    }
  1141.    return ((ULONG) (cParentColumns + NUM_WSFILE_FIELDS));
  1142.  
  1143. }   /* end wsfM_wpclsQueryDetailsInfo() */
  1144.  
  1145. /*
  1146.  *
  1147.  *  METHOD: wpclsQueryInstanceFilter                       ( ) PRIVATE
  1148.  *                                                         (X) PUBLIC
  1149.  *  DESCRIPTION:
  1150.  *
  1151.  *     The wpclsQueryInstanceFilter method is called to allow the class
  1152.  *     object to specify the file title filters for instances of its
  1153.  *     class.
  1154.  *
  1155.  *  REMARKS:
  1156.  *
  1157.  *     A pointer to a string containing file title filter(s).  This
  1158.  *     string can contain several file title filters separated by a
  1159.  *     comma.  Example: "*.TXT, *.DOC"
  1160.  *
  1161.  *  Note:  Overriding this method will cause any data file with the extension
  1162.  *         ".txt" to become a data object of the class "WSFILE."
  1163.  *
  1164.  */
  1165. SOM_Scope PSZ   SOMLINK wsfM_wpclsQueryInstanceFilter(M_WSFILE *somSelf)
  1166. {
  1167.     /* M_WSFILEData *somThis = M_WSFILEGetData(somSelf); */
  1168.     M_WSFILEMethodDebug("M_WSFILE","wsfM_wpclsQueryInstanceFilter");
  1169.  
  1170.     return (szWSFILEInstanceFilter);
  1171. }
  1172.  
  1173.  
  1174. /**************************  ORDINARY CODE SECTION  ***************************
  1175. *****                                                                     *****
  1176. *****                  Any non-method code should go here.                *****
  1177. *****                                                                     *****
  1178. ******************************************************************************/
  1179. #undef SOM_CurrentClass
  1180.  
  1181.  
  1182. /***************************************************************************
  1183. *                                                                          *
  1184. *       ROUTINE:    WSFILEInit ( )                                            *
  1185. *                                                                          *
  1186. *       DESCRIPTION:    WSFILE Initialization                                 *
  1187. *                                                                          *
  1188. *       RETURNS:    Handle of wsfile frame window, NULL if error              *
  1189. *                                                                          *
  1190. ***************************************************************************/
  1191. HWND WSFILEInit (WSFILE* somSelf)
  1192. {
  1193.    HAB  hab;                                       /* PM anchor block handle */
  1194.    HWND hwndFrame = NULLHANDLE;                       /* Frame window handle */
  1195.    HWND hwndClient = NULLHANDLE;
  1196.    PWINDOWDATA pWindowData;
  1197.    BOOL fSuccess;
  1198.    SWCNTRL    swcEntry;                                      /* Switch Entry */
  1199.    FRAMECDATA flFrameCtlData;                              /* Frame Ctl Data */
  1200.  
  1201.    hab = WinQueryAnchorBlock(HWND_DESKTOP);
  1202.    if (!WinRegisterClass( hab , szWSFILEWindowClass, (PFNWP)WSFILEWndProc ,
  1203.                             CS_SIZEREDRAW | CS_SYNCPAINT, sizeof(pWindowData)))
  1204.    {
  1205.       DebugBox("WSFILEInit", "Failure in WinRegisterClass");
  1206.       return NULLHANDLE ;
  1207.    }
  1208.  
  1209.    /*
  1210.     *   Allocate some instance specific data in Window words of Frame window.
  1211.     *   This will ensure our window procedure can use this object's methods
  1212.     *   (our window proc isn't passed a * somSelf pointer).
  1213.     */
  1214.    pWindowData = (PWINDOWDATA) _wpAllocMem(somSelf, sizeof(*pWindowData), NULL);
  1215.  
  1216.    if (!pWindowData)
  1217.    {
  1218.       DebugBox("WSFILEInit", "wpAllocMem failed to allocate pWindowData");
  1219.       return NULLHANDLE;
  1220.    }
  1221.  
  1222.    memset((PVOID) pWindowData, 0, sizeof(*pWindowData));
  1223.    pWindowData->cb = sizeof(*pWindowData);             /* first field = size */
  1224.    pWindowData->somSelf = somSelf;
  1225.  
  1226.    /* Create a frame window
  1227.     */
  1228.    flFrameCtlData.cb            = sizeof( flFrameCtlData );
  1229.    flFrameCtlData.flCreateFlags = FCF_SIZEBORDER | FCF_TITLEBAR | FCF_SYSMENU |
  1230.                                   FCF_MINMAX ;
  1231.    flFrameCtlData.hmodResources = hmod;
  1232.    flFrameCtlData.idResources   = ID_ICON;
  1233.  
  1234.    hwndFrame =                                        /* create frame window */
  1235.    WinCreateWindow(
  1236.       HWND_DESKTOP,               /* parent-window handle                    */
  1237.       WC_FRAME,                   /* pointer to registered class name        */
  1238.       _wpQueryTitle(somSelf),     /* pointer to window text                  */
  1239.       0,                          /* window style                            */
  1240.       0, 0, 0, 0,                 /* position of window                      */
  1241.       NULLHANDLE,                 /* owner-window handle                     */
  1242.       HWND_TOP,                   /* handle to sibling window                */
  1243.       (USHORT) ID_FRAME,          /* window identifier                       */
  1244.       (PVOID) &flFrameCtlData,    /* pointer to buffer                       */
  1245.       NULL);      ;               /* pointer to structure with pres. params. */
  1246.  
  1247.    if (!hwndFrame)
  1248.    {
  1249.       DebugBox("WSFILEInit", "Failure in WinCreateWindow");
  1250.       return NULLHANDLE;
  1251.    }
  1252.    hwndClient =         /* use WinCreateWindow so we can pass pres params */
  1253.    WinCreateWindow(
  1254.       hwndFrame,               /* parent-window handle                    */
  1255.       szWSFILEWindowClass,     /* pointer to registered class name        */
  1256.       NULL,                    /* pointer to window text                  */
  1257.       0,                       /* window style                            */
  1258.       0, 0, 0, 0,              /* position of window                      */
  1259.       hwndFrame,               /* owner-window handle                     */
  1260.       HWND_TOP,                /* handle to sibling window                */
  1261.       (USHORT)FID_CLIENT,      /* window identifier                       */
  1262.       pWindowData,             /* pointer to buffer                       */
  1263.       NULL);                   /* pointer to structure with pres. params. */
  1264.  
  1265.    if (!hwndClient)
  1266.    {
  1267.       WinDestroyWindow(hwndFrame);
  1268.       return NULLHANDLE;
  1269.    }
  1270.  
  1271.    WinSendMsg(hwndFrame,WM_SETICON,MPFROMP(_wpQueryIcon(somSelf)),NULL);
  1272.    WinSetWindowText(WinWindowFromID(hwndFrame,
  1273.                                     (USHORT)FID_TITLEBAR),
  1274.                                     _wpQueryTitle(somSelf));
  1275.  
  1276.    /*
  1277.     * Restore the Window Position
  1278.     */
  1279.    fSuccess = WinRestoreWindowPos( szWSFILEClassTitle,      /* class title */
  1280.                                    _wpQueryTitle(somSelf),  /* object title */
  1281.                                    hwndFrame);
  1282.  
  1283.    if (!fSuccess)
  1284.    {
  1285.     SWP        swp;
  1286.  
  1287.       /* Get the dimensions and the shell's suggested
  1288.        * location for the window
  1289.        */
  1290.       WinQueryTaskSizePos(hab,0,&swp);
  1291.  
  1292.       /* Set the frame window position
  1293.        */
  1294.       swp.fl = SWP_SIZE|SWP_MOVE|SWP_RESTORE|SWP_ZORDER;
  1295.       WinSetWindowPos(hwndFrame, HWND_TOP, swp.x, swp.y,
  1296.                                            swp.cx, swp.cy, swp.fl);
  1297.    }
  1298.  
  1299.    WinShowWindow(hwndFrame,TRUE);
  1300.    return hwndFrame;                                              /* success */
  1301.  
  1302. }   /* end WSFILEInit() */
  1303.  
  1304.  
  1305. /******************************************************************************
  1306. *
  1307. *   WSFILEWndProc()
  1308. *
  1309. *   DESCRIPTION: WSFILE Window Procedure
  1310. *
  1311. ******************************************************************************/
  1312. MRESULT EXPENTRY WSFILEWndProc( HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2 )
  1313. {
  1314.   PWINDOWDATA pWindowData;
  1315.   HWND     hwndFrame;
  1316.   BOOL     fSuccess;
  1317.  
  1318.    hwndFrame = WinQueryWindow(hwnd, QW_PARENT);
  1319.  
  1320.    switch( msg )
  1321.    {
  1322.       case WM_CREATE:
  1323.  
  1324.         pWindowData = (PWINDOWDATA) mp1;
  1325.  
  1326.         if (pWindowData == NULL)
  1327.         {
  1328.            DebugBox("WSFILEWndProc:WM_CREATE", "couldn't get window words");
  1329.            return FALSE;
  1330.         }
  1331.         /*
  1332.          *   Fill in the class view/usage details and window specific data
  1333.          *   for this instance.
  1334.          */
  1335.         pWindowData->UseItem.type    = USAGE_OPENVIEW;
  1336.         pWindowData->ViewItem.view   = OPEN_WSFILE;
  1337.         pWindowData->ViewItem.handle = hwndFrame;
  1338.  
  1339.         /*
  1340.          *   Set window pointer with object pointer and instance view info.
  1341.          *   Then add view to the in-use list so wpSwitchTo works.
  1342.          */
  1343.         WinSetWindowPtr(hwnd, QWL_USER, pWindowData);
  1344.         _wpAddToObjUseList(pWindowData->somSelf,&pWindowData->UseItem);
  1345.         _wpRegisterView(pWindowData->somSelf, hwndFrame,
  1346.                         _wpQueryTitle(pWindowData->somSelf));
  1347.         WinSetFocus( HWND_DESKTOP, hwndFrame);
  1348.         break;
  1349.  
  1350.       case WM_COMMAND:
  1351.  
  1352.         break;
  1353.  
  1354.       case WM_PAINT:
  1355.          pWindowData = (PWINDOWDATA) WinQueryWindowPtr(hwnd, QWL_USER);
  1356.  
  1357.          if (pWindowData == NULL)
  1358.          {
  1359.             DebugBox("WSFILEWndProc:WM_PAINT", "couldn't get window words");
  1360.             return FALSE;
  1361.          }
  1362.          else
  1363.          {
  1364.           HPS    hps;
  1365.           RECTL  rectl;
  1366.  
  1367.            hps = WinBeginPaint( hwnd, (HPS)NULLHANDLE, &rectl);
  1368.            WinFillRect( hps, &rectl, SYSCLR_WINDOW);
  1369.            WinDrawPointer(hps, 50, 50,
  1370.                           _wpQueryIcon(pWindowData->somSelf), DP_NORMAL);
  1371.            WinEndPaint( hps );
  1372.          }
  1373.          break;
  1374.  
  1375.       case WM_CLOSE:
  1376.          {
  1377.           HAB hab;
  1378.  
  1379.             hab = WinQueryAnchorBlock(HWND_DESKTOP);
  1380.  
  1381.             pWindowData = (PWINDOWDATA) WinQueryWindowPtr(hwnd, QWL_USER);
  1382.  
  1383.             if (pWindowData == NULL)
  1384.             {
  1385.                DebugBox("WSFILEWndProc:WM_CLOSE", "couldn't get window words");
  1386.                return FALSE;
  1387.             }
  1388.             /*
  1389.              * Restore the Window Position
  1390.              */
  1391.             fSuccess = WinStoreWindowPos(szWSFILEClassTitle,
  1392.                                          _wpQueryTitle(pWindowData->somSelf),
  1393.                                          hwndFrame);
  1394.             _wpDeleteFromObjUseList(pWindowData->somSelf,&pWindowData->UseItem);
  1395.             _wpFreeMem(pWindowData->somSelf,(PBYTE)pWindowData);
  1396.  
  1397.             WinPostMsg( hwnd, WM_QUIT, 0, 0 );
  1398.             WinDestroyWindow ( hwndFrame ) ;
  1399.          }
  1400.          break;
  1401.  
  1402.       default:
  1403.          return WinDefWindowProc( hwnd, msg, mp1, mp2 );
  1404.    }
  1405.    return FALSE;
  1406.  
  1407. }   /* end WSFILEWndProc() */
  1408.  
  1409. /******************************************************************************
  1410. *
  1411. *   LastWorkerDlgProc()
  1412. *
  1413. *   DESCRIPTION: Dialog Procedure for LastWorker settings page
  1414. *
  1415. ******************************************************************************/
  1416. MRESULT EXPENTRY LastWorkerDlgProc(HWND hwndDlg, ULONG msg,
  1417.                                   MPARAM mp1, MPARAM mp2)
  1418. {
  1419.  LASTWORKERDLGDATA * pLastWorkerDlgData;
  1420.  
  1421.    switch (msg)
  1422.    {
  1423.       case WM_INITDLG:          /* 0x003b */
  1424.       {
  1425.          PSZ       pszTemp;
  1426.  
  1427.          /*
  1428.           *   Store some instance specific data in Window words of this dialog.
  1429.           *   This will ensure our dialog procedure can access this objects
  1430.           *   data (our dialog proc isn't always passed a *somSelf pointer).
  1431.           */
  1432.          pLastWorkerDlgData =
  1433.             (PLASTWORKERDLGDATA) _wpAllocMem((WSFILE *)mp2, sizeof(*pLastWorkerDlgData), NULL);
  1434.          if (pLastWorkerDlgData)
  1435.          {
  1436.             memset((PVOID) pLastWorkerDlgData, 0, sizeof(*pLastWorkerDlgData));
  1437.             pLastWorkerDlgData->cb = sizeof(*pLastWorkerDlgData);
  1438.             pLastWorkerDlgData->somSelf = (WSFILE *) mp2;   /* pointer to this object */
  1439.             pszTemp = _queryLastWorker(pLastWorkerDlgData->somSelf);
  1440.             if (pszTemp)
  1441.             {
  1442.                pLastWorkerDlgData->PrevWorker =
  1443.                      (PSZ) _wpAllocMem(pLastWorkerDlgData->somSelf,
  1444.                                         CCHMAXPATH+1, NULL);
  1445.                if (pLastWorkerDlgData->PrevWorker)
  1446.                {
  1447.                   strcpy(pLastWorkerDlgData->PrevWorker, pszTemp);
  1448.                }
  1449.             }
  1450.  
  1451.             pLastWorkerDlgData->restorePrevWorker =
  1452.                         (PSZ) _wpAllocMem(pLastWorkerDlgData->somSelf,
  1453.                                            CCHMAXPATH+1, NULL);
  1454.             if (pLastWorkerDlgData->restorePrevWorker)
  1455.             {
  1456.                strcpy(pLastWorkerDlgData->restorePrevWorker,
  1457.                       pLastWorkerDlgData->PrevWorker);
  1458.             }
  1459.          }
  1460.          else
  1461.          {
  1462.             DebugBox("LastWorkerDlgProc:WM_INITDLG", "Couldn't allocate window words");
  1463.             break;
  1464.          }
  1465.  
  1466.          WinSetWindowPtr(hwndDlg, QWL_USER, pLastWorkerDlgData);
  1467.  
  1468.          /* set the text limit on the entry field
  1469.           */
  1470.          WinSendDlgItemMsg( hwndDlg, IDC_LASTWORKER, EM_SETTEXTLIMIT,
  1471.                             MPFROMSHORT( 0x1000-1 ), 0 );
  1472.  
  1473.          /* set the name into the entry field
  1474.           */
  1475.          WinSetWindowText( WinWindowFromID( hwndDlg, IDC_LASTWORKER ),
  1476.                            _queryLastWorker( (WSFILE *) mp2) );
  1477.  
  1478.          _wpCnrRefreshDetails( pLastWorkerDlgData->somSelf );
  1479.  
  1480.          return (MRESULT) FALSE;
  1481.       }   /* end case WM_INITDLG: */
  1482.  
  1483.       case WM_DESTROY:             /* 0x0002 */
  1484.       {
  1485.          WSFILE * pObject;
  1486.  
  1487.          pLastWorkerDlgData = WinQueryWindowPtr(hwndDlg, QWL_USER);
  1488.          if (pLastWorkerDlgData == NULL)
  1489.          {
  1490.             DebugBox("LastWorkerDlgProc:WM_DESTROY", "couldn't get window words");
  1491.             break;
  1492.          }
  1493.  
  1494.          if (pLastWorkerDlgData->PrevWorker)
  1495.          {
  1496.             _wpFreeMem(pLastWorkerDlgData->somSelf,
  1497.                        (PBYTE) pLastWorkerDlgData->PrevWorker);
  1498.          }
  1499.  
  1500.          if (pLastWorkerDlgData->restorePrevWorker)
  1501.          {
  1502.             _wpFreeMem(pLastWorkerDlgData->somSelf,
  1503.                        (PBYTE) pLastWorkerDlgData->restorePrevWorker);
  1504.          }
  1505.  
  1506.          pObject = pLastWorkerDlgData->somSelf;
  1507.          _wpFreeMem(pObject,(PBYTE)pLastWorkerDlgData);
  1508.          return (WinDefDlgProc(hwndDlg, msg, mp1, mp2) );
  1509.       }
  1510.  
  1511.       case WM_COMMAND:           /* 0x0020 */
  1512.  
  1513.          pLastWorkerDlgData = WinQueryWindowPtr(hwndDlg, QWL_USER);
  1514.          if (pLastWorkerDlgData == NULL)
  1515.          {
  1516.             DebugBox("LastWorkerDlgProc:WM_COMMAND", "couldn't get window words");
  1517.             break;
  1518.          }
  1519.  
  1520.          switch (SHORT1FROMMP(mp1))
  1521.          {
  1522.             case ID_UNDO:                   /* 0x0321 */
  1523.                if (pLastWorkerDlgData->restorePrevWorker)
  1524.                {
  1525.                   _setLastWorker(pLastWorkerDlgData->somSelf,
  1526.                                  pLastWorkerDlgData->restorePrevWorker);
  1527.  
  1528.                   if (pLastWorkerDlgData->PrevWorker)
  1529.                   {
  1530.                      strcpy(pLastWorkerDlgData->PrevWorker,
  1531.                             pLastWorkerDlgData->restorePrevWorker);
  1532.                   }
  1533.                   WinSetWindowText( WinWindowFromID( hwndDlg, IDC_LASTWORKER ),
  1534.                                     pLastWorkerDlgData->restorePrevWorker);
  1535.                }
  1536.                break;
  1537.  
  1538.             case ID_DEFAULT:             /* 0x0322 */
  1539.                /*
  1540.                 *   preserve previous values
  1541.                 */
  1542.                _setLastWorker(pLastWorkerDlgData->somSelf, DEFAULT_LASTWORKER);
  1543.  
  1544.                if (pLastWorkerDlgData->PrevWorker)
  1545.                {
  1546.                   strcpy(pLastWorkerDlgData->PrevWorker, DEFAULT_LASTWORKER);
  1547.                }
  1548.  
  1549.                WinSetWindowText( WinWindowFromID( hwndDlg, IDC_LASTWORKER ),
  1550.                                  pLastWorkerDlgData->PrevWorker);
  1551.  
  1552.                break;
  1553.  
  1554.             case ID_HELP:         /* 0x0323 */
  1555.  
  1556.                break;
  1557.  
  1558.          }   /* end switch (SHORT1FROMMP(mp1)) */
  1559.  
  1560.          return (MRESULT) TRUE;
  1561.  
  1562.       case WM_CONTROL:          /* 0x0030 */
  1563.       {
  1564.          pLastWorkerDlgData = WinQueryWindowPtr(hwndDlg, QWL_USER);
  1565.          if (pLastWorkerDlgData == NULL)
  1566.          {
  1567.             DebugBox("LastWorkerDlgProc:WM_CONTROL", "couldn't get window words");
  1568.             break;
  1569.          }
  1570.  
  1571.          switch (SHORT1FROMMP(mp1))
  1572.          {
  1573.          case IDC_LASTWORKER:
  1574.             if (SHORT2FROMMP(mp1) == EN_CHANGE)
  1575.             {
  1576.                CHAR newworker[CCHMAXPATH+1];
  1577.  
  1578.                WinQueryWindowText( WinWindowFromID( hwndDlg, IDC_LASTWORKER),
  1579.                                    CCHMAXPATH+1, newworker );
  1580.                _setLastWorker(pLastWorkerDlgData->somSelf, newworker);
  1581.                if (pLastWorkerDlgData->PrevWorker)
  1582.                {
  1583.                   strcpy(pLastWorkerDlgData->PrevWorker, newworker);
  1584.                }
  1585.             }
  1586.  
  1587.             return (MRESULT) TRUE;
  1588.          }
  1589.          break;
  1590.  
  1591.       }   /* end case WM_CONTROL: */
  1592.  
  1593.    }   /* end switch (msg) */
  1594.  
  1595.    return (WinDefDlgProc(hwndDlg, msg, mp1, mp2) );
  1596.  
  1597. }   /* end LastWorkerDlgProc() */
  1598.  
  1599.  
  1600. /********************************  END wsfile.c  ********************************/
  1601.  
  1602.  
  1603.  
  1604.