home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / qsetup.zip / DM2TEST.C < prev    next >
C/C++ Source or Header  |  1994-04-05  |  20KB  |  439 lines

  1.  
  2. /*
  3.  * This file was generated by the SOM Compiler.
  4.  * FileName: DM2Test.c.
  5.  * Generated using:
  6.  *     SOM Precompiler spc: 1.22
  7.  *     SOM Emitter emitc: 1.24
  8.  */
  9.  
  10. /*
  11.  * 
  12.  * 
  13.  * 
  14.  *      DM2Test.CSC - DeskMan/2 setup test object.
  15.  * 
  16.  *   ┌─────────────────────────────────────────────────────────────────────┐
  17.  *   │  DM2Test object - setup string manipulation methods.                │
  18.  *   │                   Part of DeskMan/2.                                │
  19.  *   │                                                                     │
  20.  *   │  (C) Copyright 1993-1994 Development Technologies, Inc.             │
  21.  *   │      Portions Copyright 1993 Gregory Czaja                          │
  22.  *   │      All rights reserved                                            │
  23.  *   │      DeskMan, DeskMan/2, DM2Setup, VUEMan, VUEMan/2 and DM2Image    │
  24.  *   │      are trademarks of Development Technologies, Inc. (DevTech),    │
  25.  *   │      a Pennsylvania Corporation                                     │
  26.  *   │                                                                     │
  27.  *   │  version 1: initial release                          April 1994     │
  28.  *   └─────────────────────────────────────────────────────────────────────┘
  29.  */
  30.  
  31.  
  32. #define DM2Test_Class_Source
  33.  
  34. #pragma checkout(suspend)
  35. #include "DM2Test.ih"
  36. #pragma checkout(resume)
  37.       /* Dm2Test.ih will include the DM2Setup.H file required for the direct
  38.          Dm2Setup's method invocation. See DM2Setup.H file for the methods 
  39.          description.
  40.  
  41.          This (enclosed) code demonstrates how to use the Dm2Setup's public
  42.          methods for saving and retrieving of private object's instance data
  43.          utilizing setup strings.
  44.          Currently, those methods can be invoked using DeskMan/2 starting with
  45.          version 1.50. To test the DM/2 Test object, run the DM2TEST.CMD, which
  46.          registers the DM2Test object class and creates a DM/2 Test object on
  47.          the Desktop. Then, DeskMan/2's "Save" or "Query object settings on drop"
  48.          Special function can be used to test the code. When PMPrintf is active
  49.          on the system, additional information will be put in the PMPrintf LOG
  50.          window.
  51.  
  52.          How does it work: if an object (class) responds to the DeskMan2QuerySetup
  53.          method, DeskMan/2 (or any other object) may create a DM2Setup object.
  54.          This object implements a set of setup string manipulation methods which
  55.          allow the receiver to pass private setup strings back to the caller.
  56.          Those setup string can be saved for the purpose of restoring/recreating
  57.          the original object with all instance data preserved, on the same or
  58.          a different system. The setup strings have to be constructed in a way
  59.          making them "environment-independent", i.e. pointers, handles, etc.
  60.          should not be used. Any inter-object dependencies need to be resolved
  61.          based on unique identifiers, such as object ID's or object titles/
  62.          locations. References to absolute directory names are allowed but should
  63.          be documented to the user, so, he would be able to modify the generated
  64.          object data before restoring the object. Generally, a better approach
  65.          would be providing the object with enough intelligence to either acquire
  66.          this kind of information by itself or ask the user during the restoration
  67.          process or before the first use.
  68.  
  69.        */
  70.  
  71. #include <stdio.h>
  72. #include <stdlib.h>
  73. #include <string.h>
  74. #include <malloc.h>
  75.  
  76. #include "DM2Test2.h"
  77.  
  78. HMODULE MyQueryModuleHandle(VOID);
  79.  
  80. MRESULT EXPENTRY ProdInfoDlgProc( HWND hwnd, ULONG msg, MPARAM mp1,
  81.                                   MPARAM mp2);
  82.  
  83. HMODULE hmodDLL = NULLHANDLE;         /* class DLL handle */
  84.  
  85. /*──────────────────────────────────────────────────────────────────────────┐
  86. │ DeskMan2QuerySetup - query private setup string                  94/03/31 │
  87. │ DeskMan2QuerySetup - your class has to support it!               94/03/31 │
  88. └──────────────────────────────────────────────────────────────────────────*/
  89. SOM_Scope APIRET   SOMLINK DM2TestX_DeskMan2QuerySetup(DM2Test *somSelf,
  90.         WPObject *setupObject)
  91. {
  92.     DM2TestData *somThis = DM2TestGetData(somSelf);
  93.     DM2TestMethodDebug("DM2Test","DM2TestX_DeskMan2QuerySetup");
  94.  
  95.               /* Note: there are two ways to invoke the DM2Setup methods:  */
  96.               /*                                                           */
  97.               /*       1. direct invocation (using the method's name).     */
  98.               /*          In this case, the DEF file for your object       */
  99.               /*          invoking the methods needs to contain the        */
  100.               /*          following IMPORT statements:                     */
  101.               /*                                                           */
  102.               /*          IMPORTS                                          */
  103.               /*             DM2Setup.DM2SetupCClassData                   */
  104.               /*             Dm2Setup.DM2SetupClassData                    */
  105.               /*             DM2Setup.DM2SetupNewClass                     */
  106.               /*             DM2Setup.M_DM2SetupCClassData                 */
  107.               /*             DM2Setup.M_DM2SetupClassData                  */
  108.               /*             DM2Setup.M_DM2SetupNewClass                   */
  109.               /*                                                           */
  110.               /*          and the DM2Setup.DLL needs to be located in a    */
  111.               /*          directory on the LIBPATH!                        */
  112.               /*          Note also that the SOM compiler will REPLACE the */
  113.               /*          DEF file for your class when you change the CSC  */
  114.               /*          file and re-run the SOM compile!                 */
  115.               /*                                                           */
  116.               /*          NOTE: since DM2Test uses this method, it locks   */
  117.               /*          the DM2Setup.DLL. This (currently) prevents      */
  118.               /*          DeskMan from being re-installed if the Dm2Test   */
  119.               /*          object is present on the Desktop!                */
  120.               /*          You have to delete DM2Test to be able to install */
  121.               /*          DeskMan/2!                                       */
  122.               /*                                                           */
  123.               /*       2. invocation using the SOM dispatching mechanism.  */
  124.               /*          This one may be not as pretty and readable,      */
  125.               /*          and has not as good performancend but it may be  */
  126.               /*          easier to implement and is less error-prone.     */
  127.               /*          It does NOT require neither inclusion of the     */
  128.               /*          DM2Setup.H file nor IMPORTS statements nor       */
  129.               /*          DM2Setup.DLL presence on the LIBPATH.            */
  130.               /*                                                           */
  131.               /*          Both methods are presented below.                */
  132.  
  133.               /* This one sets the entire setup string to the   */
  134.               /* character string specified.                    */             
  135.               /* Note: SEMICOLON(s) need to be included!        */
  136.               /*       The current contents of the setup buffer */
  137.               /*       will be destroyed.                       */
  138.  
  139.               /* Note: direct invocation.                       */
  140.     _fromString(setupObject, "SETUP1=First setup value;");
  141.  
  142.               /* Adds a setup string keyword/value pair to the  */
  143.               /* current contents of the setup buffer           */
  144.               /* Note: SEMICOLON will be appended by DM2Setup   */
  145.               /*       for the pair added. The EQUAL SIGN will  */
  146.               /*       be inserted automatically, too.          */
  147.  
  148.               /* Note: direct invocation.                       */
  149.     _addSetup(setupObject, "SETUP2", "Second setup value");
  150.  
  151.               /* Note: invocation using the somDispatch method  */
  152.     _somDispatchL(setupObject,
  153.                   SOM_IdFromString("addSetup"),
  154.                   NULL,
  155.                   "SETUP3", "Third setup value");
  156.  
  157.               /* display the LENGTH of the current setup string */
  158.               /* Note: direct invocation.                       */
  159.     printf("The current setup string length is: %d.\n",
  160.                                                _queryLength(setupObject));
  161.  
  162.               /* display the current contents of the setup buffer*/
  163.               /* Note: invocation using the somDispatch method  */
  164.     printf("The current setup string is:\n%s.\n", 
  165.                                   _somDispatchA(setupObject,
  166.                                                 SOM_IdFromString("queryBuffer"),
  167.                                                 NULL));
  168.  
  169.  
  170.     return (APIRET) 0;
  171. }
  172.  
  173. /*──────────────────────────────────────────────────────────────────────────┐
  174. │ wpSetup - override                                               94/03/31 │
  175. └──────────────────────────────────────────────────────────────────────────*/
  176. SOM_Scope BOOL   SOMLINK DM2TestX_wpSetup(DM2Test *somSelf,
  177.         PSZ pszSetupString)
  178. {
  179.     DM2TestData *somThis = DM2TestGetData(somSelf);
  180.  
  181.     ULONG   ulLength = 0;                          /* setup value length */
  182.     CHAR    szValue[256];                          /* setup value        */
  183.  
  184.     DM2TestMethodDebug("DM2Test","DM2TestX_wpSetup");
  185.  
  186.                  /* in wpSetup, expect the setup string passed during the */
  187.                  /* object creation to contain your private setup strings */
  188.                  /* in addition to the other (default) WPS setups.        */
  189.                  /* Process your PRIVATE setup strings and pass the string*/
  190.                  /* to your parent. The private values do NOT need to be  */
  191.                  /* removed from the setup string passed!                 */
  192.  
  193.     printf("Setup string passed:\n%s.\n", pszSetupString);
  194.  
  195.                  /* Note: wpScanSetupString with szValue==NULL seems to   */
  196.                  /*       be broken in 2.11. Do NOT use to get the szValue*/
  197.                  /*       length!                                         */
  198.     if (_wpScanSetupString(somSelf, pszSetupString,
  199.                            "SETUP1", szValue, &ulLength))
  200.        printf("SETUP1 value is: %s.\n", szValue);
  201.  
  202.     if (_wpScanSetupString(somSelf, pszSetupString,
  203.                            "SETUP2", szValue, &ulLength))
  204.        printf("SETUP2 value is: %s.\n", szValue);
  205.                       
  206.     if (_wpScanSetupString(somSelf, pszSetupString,
  207.                            "SETUP3", szValue, &ulLength))
  208.        printf("SETUP3 value is: %s.\n", szValue);
  209.  
  210.     return (parent_wpSetup(somSelf,pszSetupString));
  211. }
  212.  
  213. /*──────────────────────────────────────────────────────────────────────────┐
  214. │ wpModifyPopupMenu - override                                     94/03/31 │
  215. └──────────────────────────────────────────────────────────────────────────*/
  216. SOM_Scope BOOL   SOMLINK DM2TestX_wpModifyPopupMenu(DM2Test *somSelf,
  217.         HWND hwndMenu,
  218.         HWND hwndCnr,
  219.         ULONG iPosition)
  220. {
  221.     DM2TestData *somThis = DM2TestGetData(somSelf);
  222.     DM2TestMethodDebug("DM2Test","DM2TestX_wpModifyPopupMenu");
  223.  
  224.                             /* insert the Product information menu item */
  225.     _wpInsertPopupMenuItems(somSelf, hwndMenu, 0,
  226.                             MyQueryModuleHandle(), 
  227.                             MI_HELP_MENU, WPMENUID_HELP);
  228.                            
  229.     return (parent_wpModifyPopupMenu(somSelf,hwndMenu,hwndCnr,iPosition));
  230. }
  231.  
  232. /*──────────────────────────────────────────────────────────────────────────┐
  233. │ wpMenuItemSelected - override                                    94/03/31 │
  234. └──────────────────────────────────────────────────────────────────────────*/
  235. SOM_Scope BOOL   SOMLINK DM2TestX_wpMenuItemSelected(DM2Test *somSelf,
  236.         HWND hwndFrame,
  237.         ULONG ulMenuId)
  238. {
  239.     DM2TestData *somThis = DM2TestGetData(somSelf);
  240.     DM2TestMethodDebug("DM2Test","DM2TestX_wpMenuItemSelected");
  241.  
  242.     switch (ulMenuId) {
  243.  
  244.        case MI_DMTEST_PRODINFO:         /* display product information */
  245.           {
  246.             DLGDATA dlgData;              /* data passed to the dialog */
  247.  
  248.             dlgData.cb=sizeof(DLGDATA);
  249.             dlgData.ulLogoTime=0;
  250.             
  251.             WinDlgBox( HWND_DESKTOP,    /* Place anywhere on desktop    */
  252.                        HWND_DESKTOP,    /* Owned by the desktop         */
  253.                        ProdInfoDlgProc,          /* Addr. of procedure  */
  254.                        MyQueryModuleHandle(),    /* Module handle       */
  255.                        ID_PRODINFO,     /* Dialog identifier in resource*/
  256.                        &dlgData);
  257.           };
  258.           return TRUE;
  259.     } 
  260.  
  261.     return (parent_wpMenuItemSelected(somSelf,hwndFrame,ulMenuId));
  262. }
  263.  
  264. /*──────────────────────────────────────────────────────────────────────────┐
  265. │ wpAddObjectWindowPage - override                                 94/03/31 │
  266. └──────────────────────────────────────────────────────────────────────────*/
  267. SOM_Scope ULONG   SOMLINK DM2TestX_wpAddObjectWindowPage(DM2Test *somSelf,
  268.         HWND hwndNotebook)
  269. {
  270.     DM2TestData *somThis = DM2TestGetData(somSelf);
  271.     DM2TestMethodDebug("DM2Test","DM2TestX_wpAddObjectWindowPage");
  272.  
  273.     /* don't insert the Window - Settings page - not used ! */
  274.     return (SETTINGS_PAGE_REMOVED);
  275. }
  276. /*──────────────────────────────────────────────────────────────────────────┐
  277. │ Class methods                                                    94/03/31 │
  278. └──────────────────────────────────────────────────────────────────────────*/
  279. #undef SOM_CurrentClass
  280. #define SOM_CurrentClass SOMMeta
  281.  
  282. /*──────────────────────────────────────────────────────────────────────────┐
  283. │ wpclsInitData - override                                         94/03/31 │
  284. └──────────────────────────────────────────────────────────────────────────*/
  285. SOM_Scope void   SOMLINK DM2TestC_wpclsInitData(M_DM2Test *somSelf)
  286. {
  287.     /* M_DM2TestData *somThis = M_DM2TestGetData(somSelf); */
  288.     M_DM2TestMethodDebug("M_DM2Test","DM2TestC_wpclsInitData");
  289.  
  290.     MyQueryModuleHandle();       /* initialize our class DLL handle */
  291.  
  292.     parent_wpclsInitData(somSelf);
  293. }
  294.  
  295. /*──────────────────────────────────────────────────────────────────────────┐
  296. │ wpclsUnInitData - override                                       94/03/31 │
  297. └──────────────────────────────────────────────────────────────────────────*/
  298. SOM_Scope void   SOMLINK DM2TestC_wpclsUnInitData(M_DM2Test *somSelf)
  299. {
  300.     /* M_DM2TestData *somThis = M_DM2TestGetData(somSelf); */
  301.     M_DM2TestMethodDebug("M_DM2Test","DM2TestC_wpclsUnInitData");
  302.  
  303.     parent_wpclsUnInitData(somSelf);
  304. }
  305.  
  306. /*──────────────────────────────────────────────────────────────────────────┐
  307. │ wpclsQueryIconData - override                                    94/03/31 │
  308. └──────────────────────────────────────────────────────────────────────────*/
  309. SOM_Scope ULONG   SOMLINK DM2TestC_wpclsQueryIconData(M_DM2Test *somSelf,
  310.         PICONINFO pIconInfo)
  311. {
  312.     /* M_DM2TestData *somThis = M_DM2TestGetData(somSelf); */
  313.     M_DM2TestMethodDebug("M_DM2Test","DM2TestC_wpclsQueryIconData");
  314.  
  315.     if (pIconInfo != NULL) {          /* return our default ICON data */
  316.        pIconInfo->fFormat = ICON_RESOURCE;
  317.        pIconInfo->hmod    = MyQueryModuleHandle();
  318.        pIconInfo->resid   = ID_DM2TEST_MAIN;
  319.     } /* endif */
  320.  
  321.     return (sizeof(ICONINFO));       /* and ALWAYS return the SIZE OF */
  322. }
  323.  
  324. /*──────────────────────────────────────────────────────────────────────────┐
  325. │ wpclsQueryTitle - override                                       94/03/31 │
  326. └──────────────────────────────────────────────────────────────────────────*/
  327. SOM_Scope PSZ   SOMLINK DM2TestC_wpclsQueryTitle(M_DM2Test *somSelf)
  328. {
  329.     /* M_DM2TestData *somThis = M_DM2TestGetData(somSelf); */
  330.     M_DM2TestMethodDebug("M_DM2Test","DM2TestC_wpclsQueryTitle");
  331.  
  332.     return ("DM/2 Test");      /* this is our default object title */
  333. }
  334.  
  335. /**************************  ORDINARY CODE SECTION  ***************************
  336. *****                                                                     *****
  337. *****                  Any non-method code should go here.                *****
  338. *****                                                                     *****
  339. ******************************************************************************/
  340. #undef SOM_CurrentClass
  341.  
  342. /*─────────────────────────────────────────────────────────────────────────┐
  343. │ What's it called: MyQueryModuleHandle                                    │
  344. │                                                                          │
  345. │ What does it do : returns the module handle for this DLL                 │
  346. └─────────────────────────────────────────────────────────────────────────*/
  347. HMODULE MyQueryModuleHandle(VOID)
  348. {
  349.    ULONG rc;
  350.    PSZ   pszPathName;
  351.  
  352.    if (hmodDLL == NULLHANDLE) {
  353.  
  354.       pszPathName = _somLocateClassFile(SOMClassMgrObject,
  355.                                         SOM_IdFromString(DM2TEST_CLASSNAME),
  356.                                         0,0);
  357.       rc = DosQueryModuleHandle(pszPathName, &hmodDLL);
  358.  
  359.       if (rc) 
  360.          return NULLHANDLE;
  361.  
  362.    }/* end if */
  363.  
  364.    return(hmodDLL);
  365.  
  366. }  /* end MyQueryModuleHandle */
  367.  
  368. /*──────────────────────────────────────────────────────────────────────┐
  369. │   Name : ProdInfoDlgProc                                              │
  370. │                                                                       │
  371. │   Description : Processes all messages sent to the Product            │
  372. │                 Information dialog box.                               │
  373. └──────────────────────────────────────────────────────────────────────*/
  374. MRESULT EXPENTRY ProdInfoDlgProc( HWND hwnd, ULONG msg, MPARAM mp1,
  375.                                   MPARAM mp2)
  376. {
  377.    switch(msg) {
  378.       case WM_INITDLG:
  379.          {
  380.             SWP      swp;
  381.             HAB      hab = WinQueryAnchorBlock(HWND_DESKTOP);
  382.  
  383.             WinQueryTaskSizePos(hab, 0, &swp);   
  384.             WinSetWindowPos(hwnd,
  385.                             HWND_TOP,
  386.                             swp.x, swp.y, 0, 0,
  387.                             SWP_MOVE);
  388.          };
  389.          break;
  390.  
  391.       case WM_COMMAND:
  392.          {
  393.          /*
  394.           * No matter what the command, close the dialog
  395.           */
  396.           WinDismissDlg(hwnd, TRUE);
  397.          };
  398.          break;
  399.  
  400.       case WM_PAINT:
  401.       {
  402.          SWP      swpTxt, swpDlg;
  403.          HPS      hps;
  404.          POINTL   ptl;
  405.          HBITMAP  hbm = NULLHANDLE;
  406.  
  407.          WinDefDlgProc(hwnd, WM_PAINT, mp1, mp2);  /* normal dialog painting */
  408.  
  409.          hps = WinGetPS(hwnd);                         /* now, add our stuff */
  410.                                                     /* load and draw Example */
  411.          hbm = GpiLoadBitmap(hps,
  412.                              MyQueryModuleHandle(),
  413.                              ID_DM2TEST_BITMAP, 0L, 0L);
  414.  
  415.                              /* position the logo bitmap */
  416.          WinQueryWindowPos(WinWindowFromID(hwnd, ID_PROD_DESKMAN), &swpTxt);
  417.          WinQueryWindowPos(hwnd, &swpDlg);
  418.          ptl.x = (LONG)((swpDlg.cx - 30) / 2);
  419.          ptl.y = (LONG)((((swpDlg.cy - swpTxt.y) - 53) / 2) + swpTxt.y);
  420.          WinDrawBitmap(hps,
  421.                        hbm,
  422.                        NULL,
  423.                        &ptl,
  424.                        0L,
  425.                        0L,
  426.                        DBM_IMAGEATTRS);
  427.          WinReleasePS(hps);
  428.  
  429.          return (MRESULT)0;
  430.       }
  431.  
  432.       default:
  433.          return(WinDefDlgProc(hwnd, msg, mp1, mp2));
  434.    }
  435.  
  436.    return (MRESULT)0;
  437. }
  438.  
  439.