home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 14 Text / 14-Text.zip / RB3774.ZIP / RECORD.ZIP / RECORD.C < prev    next >
Text File  |  1992-04-05  |  31KB  |  992 lines

  1. /*************************************************************************/
  2. /*                                                                       */
  3. /* ITSC Redbook OS/2 v2.0 Sample Program                                 */
  4. /*                                                                       */
  5. /*                                                                       */
  6. /* RECORD.C  -  This is the C implementation of a WPS transient          */
  7. /*              Record class                                             */
  8. /*                                                                       */
  9. /*************************************************************************/
  10.  
  11. /*
  12.  * This file was generated by the SOM Compiler.
  13.  * FileName: record.c.
  14.  * Generated using:
  15.  *     SOM Precompiler spc: 1.21
  16.  *     SOM Emitter emitc: 1.23
  17.  */
  18.  
  19. #define INCL_DOS
  20. #define INCL_WIN
  21. #include <os2.h>
  22.  
  23. #include <stdio.h>
  24. #include <stdlib.h>
  25. #include <string.h>
  26. #include <ctype.h>
  27. #include <stddef.h>
  28. #include <process.h>
  29. #include <memory.h>
  30. #include <sys\types.h>
  31. #include <sys\stat.h>
  32. #include <bsememf.h>
  33.  
  34. #include "res.h"      /* resource definitions */
  35. #include "msgs.h"     /* Message and data passing definitions */
  36.  
  37. #define Record_Class_Source
  38. #include "record.ih"
  39.  
  40. #define DebugBox(title, text)  WinMessageBox(HWND_DESKTOP,HWND_DESKTOP, \
  41.                                (PSZ) text , (PSZ) title, 0, \
  42.                                MB_OK | MB_INFORMATION )
  43.  
  44.  
  45. /*************************************************************/
  46. /* Define the new record view OPEN_CONTENTS to OPEN_TREE are */
  47. /* reserved by the shell user views begin at OPEN_USER this  */
  48. /* is similar to the WM_USER concept for messages            */
  49. /*************************************************************/
  50. #define OPEN_RECORD (OPEN_USER+1)
  51.  
  52. /******************************************************************/
  53. /*                           Class Data                           */
  54. /******************************************************************/
  55.  
  56. /* Store the class pointer itself to save time getting hold of it */
  57. SOMAny  *ThisClass;
  58.  
  59. /* module handle - this can be used by all instances of this class */
  60. HMODULE  ThisClasshmodule;
  61.  
  62. /* default title when created without a title */
  63. PSZ ThisClassDefaultTitle = "Record";
  64.  
  65. /* default icon for record objects */
  66. HPOINTER    ThisClassDefaultIcon;
  67.  
  68. /* Handle to requester object window - all methods go via this */
  69. /* to send messages to the sever process                       */
  70. HWND hwndRequester;
  71.  
  72. /******************************************************************/
  73. /*                           Structures                           */
  74. /******************************************************************/
  75.  
  76. #define RECORD_BUFFER_SIZE 500
  77.  
  78. /* Structure needed for views of records */
  79. typedef struct _RECORDVIEW {
  80.   SOMAny   *Record;
  81.   USEITEM  UseItem;
  82.   VIEWITEM ViewItem;
  83. } RECORDVIEW;
  84. typedef RECORDVIEW *PRECORDVIEW;
  85.  
  86. /* Buffer to hold record text */
  87. typedef struct _RECORDVIEWDATA {
  88.   SOMAny   *Record;
  89.   CHAR     Data[RECORD_BUFFER_SIZE];
  90. } RECORDVIEWDATA;
  91. typedef RECORDVIEWDATA *PRECORDVIEWDATA;
  92.  
  93. /******************************************************************/
  94. /*                           Functions                            */
  95. /******************************************************************/
  96. MRESULT EXPENTRY MLEFrameWindowProc( HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2 );
  97. HWND CreateViewWindow( SOMAny *somSelf );
  98. void DeleteViewWindow( HWND hwnd );
  99.  
  100.  
  101. /****************************************************************************/
  102. /*                 Required for the object window requester                 */
  103. /****************************************************************************/
  104.  
  105. typedef struct {
  106.         HWND hwndServer;
  107.         PID  pidServer;
  108. } REQ_DATA, *PREQ_DATA;
  109.  
  110. MRESULT EXPENTRY IpcRequesterObjectWinProc( HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2 );
  111.  
  112. VOID  IpcRequesterObjectThread (VOID *p);
  113. VOID  IpcStartServerProg(PSZ Args);
  114. BOOL  IpcServerWinCheck(HWND hwnd);
  115. PVOID IpcGetMessageMem(ULONG ObjectSize);
  116.  
  117. #define STACKSIZE 9000
  118.  
  119. /****************************************************************************/
  120. /* Start of Methods section                                                 */
  121.  
  122.  
  123. /*
  124.  *
  125.  *  METHOD:   SetRecordInfo                               PUBLIC
  126.  *
  127.  *  PURPOSE:  Copy the szData string in to the
  128.  *            Record objects text buffer
  129.  *
  130.  */
  131.  
  132. #undef SOM_CurrentClass
  133. #define SOM_CurrentClass SOMInstance
  134. SOM_Scope BOOL   SOMLINK record_SetRecordInfo(Record *somSelf,
  135.                 PSZ szData)
  136. {
  137.     RecordData *somThis = RecordGetData(somSelf);
  138.     RecordMethodDebug("Record","record_SetRecordInfo");
  139.  
  140.     strcpy ( _pRecordData, szData);
  141.     return (BOOL) 0;
  142. }
  143.  
  144. /*
  145.  *
  146.  *  METHOD:   GetRecordInfo                               PUBLIC
  147.  *
  148.  *  PURPOSE:  Copy the  Record objects text buffer
  149.  *            in to the szData string
  150.  *
  151.  */
  152.  
  153. SOM_Scope BOOL   SOMLINK record_GetRecordInfo(Record *somSelf,
  154.                 PSZ szData)
  155. {
  156.     RecordData *somThis = RecordGetData(somSelf);
  157.     RecordMethodDebug("Record","record_GetRecordInfo");
  158.  
  159.     strcpy ( szData, _pRecordData);
  160.  
  161.     return (BOOL) 0;
  162. }
  163.  
  164. /*
  165.  *
  166.  *  METHOD:   clsQueryDatabase                            PUBLIC
  167.  *
  168.  *  PURPOSE:  Search the record database for all entries
  169.  *            that match the patern in the search string.
  170.  *            This results in the creation of new objects
  171.  *            in the Folder specified
  172.  *
  173.  */
  174.  
  175. #undef SOM_CurrentClass
  176. #define SOM_CurrentClass SOMMeta
  177. SOM_Scope BOOL   SOMLINK recordcls_clsQueryDatabase(M_Record *somSelf,
  178.                 PSZ szSearch,
  179.                 WPObject *Folder)
  180. {
  181.     PQUERY_DATA pQuery;
  182.  
  183.     /* M_RecordData *somThis = M_RecordGetData(somSelf); */
  184.     M_RecordMethodDebug("M_Record","recordcls_clsQueryDatabase");
  185.  
  186.     pQuery = (PQUERY_DATA) IpcGetMessageMem( sizeof(QUERY_DATA) );
  187.  
  188.     pQuery->folder = (ULONG)Folder;
  189.     strcpy( pQuery->szSearch, szSearch );
  190.  
  191.     /* Ask the server to perform the search */
  192.     WinPostMsg(hwndRequester,
  193.                WMP_SEND_MSG_TO_SERVER,
  194.                (MPARAM) WMP_SEARCH_DATABASE,
  195.                (MPARAM) pQuery );
  196.  
  197.     return (BOOL) 0;
  198. }
  199.  
  200. /*
  201.  *
  202.  *  METHOD:   clsRestartServer                            PUBLIC
  203.  *
  204.  *  PURPOSE:  Restarts the server program.
  205.  *
  206.  */
  207.  
  208. SOM_Scope BOOL   SOMLINK recordcls_clsRestartServer(M_Record *somSelf)
  209. {
  210.     /* M_RecordData *somThis = M_RecordGetData(somSelf); */
  211.     M_RecordMethodDebug("M_Record","recordcls_clsRestartServer");
  212.  
  213.     WinPostMsg(hwndRequester, WMP_START_SERVER_PROGRAM, (MPARAM)0, (MPARAM)0 );
  214.     return (BOOL) 0;
  215. }
  216.  
  217. /*
  218.  *
  219.  *  METHOD:   wpInitData                    OVERRIDE      PUBLIC
  220.  *
  221.  *  PURPOSE:  Initialise the object memory for
  222.  *            the record text buffer
  223.  *
  224.  */
  225.  
  226. #undef SOM_CurrentClass
  227. #define SOM_CurrentClass SOMInstance
  228. SOM_Scope void   SOMLINK record_wpInitData(Record *somSelf)
  229. {
  230.     SOMAny   *RecordClass;
  231.     RecordData *somThis = RecordGetData(somSelf);
  232.     RecordMethodDebug("Record","record_wpInitData");
  233.  
  234.     /* Allocate storage for record text buffer */
  235.     _pRecordData = (PSZ) _wpAllocMem(somSelf, RECORD_BUFFER_SIZE, NULL);
  236.  
  237.     /* Initialise the buffer */
  238.     strcpy( _pRecordData, "<Empty Record>");
  239.     parent_wpInitData(somSelf);
  240. }
  241.  
  242. /*
  243.  *
  244.  *  METHOD:   wpUnInitData                   OVERRIDE      PUBLIC
  245.  *
  246.  *  PURPOSE:  Free the object memory for
  247.  *            the record text buffer
  248.  *
  249.  */
  250.  
  251. SOM_Scope void   SOMLINK record_wpUnInitData(Record *somSelf)
  252. {
  253.     RecordData *somThis = RecordGetData(somSelf);
  254.     RecordMethodDebug("Record","record_wpUnInitData");
  255.  
  256.     /* Free storage for record buffer */
  257.     _wpFreeMem(somSelf, _pRecordData );
  258.  
  259.     parent_wpUnInitData(somSelf);
  260. }
  261.  
  262. /*
  263.  *
  264.  *  METHOD:   wpModifyPopupMenu             OVERRIDE      PUBLIC
  265.  *
  266.  *  PURPOSE:  Add any new options for the records
  267.  *            context menu
  268.  *
  269.  */
  270.  
  271. SOM_Scope BOOL   SOMLINK record_wpModifyPopupMenu(Record *somSelf,
  272.                 HWND hwndMenu,
  273.                 HWND hwndCnr,
  274.                 ULONG iPosition)
  275. {
  276.     RecordData *somThis = RecordGetData(somSelf);
  277.     RecordMethodDebug("Record","record_wpModifyPopupMenu");
  278.     /* Reserved for future use */
  279.     return (parent_wpModifyPopupMenu(somSelf,hwndMenu,hwndCnr,iPosition));
  280. }
  281.  
  282. /*
  283.  *
  284.  *  METHOD:   wpMenuItemSelected            OVERRIDE      PUBLIC
  285.  *
  286.  *  PURPOSE:  Processing for record objects menu
  287.  *
  288.  */
  289.  
  290. SOM_Scope ULONG  SOMLINK record_wpMenuItemSelected(Record *somSelf,
  291.                 HWND hwndFrame,
  292.                 ULONG MenuId)
  293. {
  294.     RecordData *somThis = RecordGetData(somSelf);
  295.     RecordMethodDebug("Record","record_wpMenuItemSelected");
  296.     /* Reserved for future use */
  297.     return parent_wpMenuItemSelected(somSelf,hwndFrame,MenuId);
  298. }
  299.  
  300. /*
  301.  *
  302.  *  METHOD:   wpOpen                        OVERRIDE      PUBLIC
  303.  *
  304.  *  PURPOSE:  Open a view of the object ( see also
  305.  *            wpclsQueryDefaultView )
  306.  *
  307.  */
  308.  
  309. SOM_Scope HWND   SOMLINK record_wpOpen(Record *somSelf,
  310.                 HWND hwndCnr,
  311.                 ULONG ulView,
  312.                 ULONG param)
  313. {
  314.     RecordData *somThis = RecordGetData(somSelf);
  315.     RecordMethodDebug("Record","record_wpOpen");
  316.  
  317.     /********************************************************************/
  318.     /* Note that double clicking on an icon sends the object a message  */
  319.     /* with OPEN_DEFAULT as the parameter. The Normal processing of     */
  320.     /* this is the find out what the default is with wpQueryDefaultView */
  321.     /* and then send a wpOpen message with whatever was returned.       */
  322.     /********************************************************************/
  323.  
  324.     if (ulView==OPEN_RECORD)
  325.     {
  326.        /***************************************************************/
  327.        /* Try and switch to an open view of the object. If this fails */
  328.        /* it means that the view has yet to be created                */
  329.        /***************************************************************/
  330.        if ( !_wpSwitchTo(somSelf,OPEN_RECORD) )
  331.        {
  332.           /*****************************************************************/
  333.           /* Here we wanted to get the sever process to show the view      */
  334.           /* for our object. However WPS needs to subclass the view frame  */
  335.           /* window in order manipulate the title bar mini icon, and       */
  336.           /* since subclassing does not work across processes it presents  */
  337.           /* a problem. If you did not care to have the Mini icon feature  */
  338.           /* for the view of your object then creating the frame in the    */
  339.           /* second process is ok.                                         */
  340.           /* Another approach would be to start a new program whose        */
  341.           /* sole purpose would be to represent the view to the object,    */
  342.           /* See the WinStartApp API.                                      */
  343.           /*****************************************************************/
  344.  
  345.           HWND  hwndView;
  346.           hwndView = CreateViewWindow( somSelf );
  347.  
  348.           if(! WinIsWindow( (HAB)0, hwndView) )
  349.           {
  350.              /****************************************/
  351.              /* If unsuccessful do parent processing */
  352.              /****************************************/
  353.              return (parent_wpOpen(somSelf,hwndCnr,ulView,param));
  354.           }
  355.           else
  356.           {
  357.              /***************************************************************/
  358.              /* Post a message to the view frame to display the record data */
  359.              /***************************************************************/
  360.              WinPostMsg( hwndView, WMP_INSERT_DATA_INTO_VIEW, (MPARAM) _pRecordData, (MPARAM)0 );
  361.              return( hwndView );
  362.           }
  363.        }
  364.        else
  365.        {
  366.           return (parent_wpOpen(somSelf,hwndCnr,ulView,param));
  367.        }
  368.     }
  369.     else
  370.     {
  371.        return (parent_wpOpen(somSelf,hwndCnr,ulView,param));
  372.     }
  373.  
  374. }
  375.  
  376. /*
  377.  *
  378.  *  METHOD:   wpSetup                       OVERRIDE      PUBLIC
  379.  *
  380.  *  PURPOSE:  Process the records Setup strings
  381.  *
  382.  */
  383.  
  384. SOM_Scope BOOL   SOMLINK record_wpSetup(Record *somSelf,
  385.                 PSZ pszSetupString)
  386. {
  387.     RecordData *somThis = RecordGetData(somSelf);
  388.     RecordMethodDebug("Record","record_wpSetup");
  389.     /* Reserved for future use */
  390.     return (parent_wpSetup(somSelf,pszSetupString));
  391. }
  392.  
  393. /*
  394.  *
  395.  *  METHOD:   wpclsFindObjects                            PUBLIC
  396.  *
  397.  *  PURPOSE:  Shell entry to finding record objects
  398.  *
  399.  */
  400.  
  401. #undef SOM_CurrentClass
  402. #define SOM_CurrentClass SOMMeta
  403. SOM_Scope BOOL   SOMLINK recordcls_wpclsFindObjectFirst(M_Record *somSelf,
  404.                 PCLASS pClassList,
  405.                 PHFIND phFind,
  406.                 PSZ pszTitle,
  407.                 WPFolder *Folder,
  408.                 BOOL fSubfolders,
  409.                 PVOID pExtendedCriteria,
  410.                 POBJECT pBuffer,
  411.                 PULONG pCount)
  412. {
  413.     /* M_RecordData *somThis = M_RecordGetData(somSelf); */
  414.     M_RecordMethodDebug("M_Record","recordcls_wpclsFindObjectFirst");
  415.  
  416.     return (parent_wpclsFindObjectFirst(somSelf,pClassList,phFind,pszTitle,Folder,fSubfolders,pExtendedCriteria,pBuffer,pCount));
  417. }
  418.  
  419. /*
  420.  *
  421.  *  METHOD:   wpclsInitData                 OVERRIDE      PUBLIC
  422.  *
  423.  *  PURPOSE:  Initialises the Class
  424.  *            This involves :
  425.  *               Initialising class variables
  426.  *               Loading class resources
  427.  *               Starting the IPC requester thread
  428.  *               Registering the Viewing window PM Class
  429.  *
  430.  */
  431.  
  432. #undef SOM_CurrentClass
  433. #define SOM_CurrentClass SOMMeta
  434. SOM_Scope void   SOMLINK recordcls_wpclsInitData(M_Record *somSelf)
  435. {
  436.     CHAR  ErrorBuffer[100];
  437.  
  438.     /* M_RecordData *somThis = M_RecordGetData(somSelf); */
  439.     M_RecordMethodDebug("M_Record","recordcls_wpclsInitData");
  440.  
  441.     DosLoadModule((PSZ) ErrorBuffer,
  442.                   sizeof(ErrorBuffer),
  443.                   "RECORD", &ThisClasshmodule);
  444.  
  445.     ThisClassDefaultIcon = WinLoadPointer( HWND_DESKTOP, ThisClasshmodule, ID_RECORDICON );
  446.  
  447.     /* Initialise the pointer to this class */
  448.     ThisClass = somSelf;
  449.  
  450.     /* Start the requester */
  451.     _beginthread( IpcRequesterObjectThread, NULL, STACKSIZE, NULL);
  452.  
  453.     /* Register the viewing window class */
  454.     if (!WinRegisterClass( (HAB)0, (PSZ)"MLEFrameWindow",
  455.                           (PFNWP)MLEFrameWindowProc,
  456.                           CS_SIZEREDRAW, sizeof( HWND ) ))
  457.     {
  458.        DebugBox("Fatal Error","Register View Frame Class Failed");
  459.     }
  460.  
  461.     parent_wpclsInitData(somSelf);
  462. }
  463.  
  464. /*
  465.  *
  466.  *  METHOD:   wpclsUnInitData               OVERRIDE      PUBLIC
  467.  *
  468.  *  PURPOSE:  Free Class resources
  469.  *
  470.  */
  471.  
  472. SOM_Scope void   SOMLINK recordcls_wpclsUnInitData(M_Record *somSelf)
  473. {
  474.     /* M_RecordData *somThis = M_RecordGetData(somSelf); */
  475.     M_RecordMethodDebug("M_Record","recordcls_wpclsUnInitData");
  476.  
  477.     /* Close down the Server */
  478.     WinPostMsg(hwndRequester, WMP_IPC_END, (MPARAM) 0, (MPARAM) 0 );
  479.  
  480.     DosFreeModule(ThisClasshmodule); /* Free the resources */
  481.  
  482.     parent_wpclsUnInitData(somSelf);
  483. }
  484.  
  485. /*
  486.  *
  487.  *  METHOD:   wpclsQueryTitle               OVERRIDE      PUBLIC
  488.  *
  489.  *  PURPOSE:  Return the string "Record" as the default
  490.  *            title for new record objects
  491.  *
  492.  */
  493.  
  494. SOM_Scope PSZ   SOMLINK recordcls_wpclsQueryTitle(M_Record *somSelf)
  495. {
  496.     /* M_RecordData *somThis = M_RecordGetData(somSelf); */
  497.     M_RecordMethodDebug("M_Record","recordcls_wpclsQueryTitle");
  498.  
  499.     return ( ThisClassDefaultTitle );
  500. }
  501.  
  502. /*
  503.  *
  504.  *  METHOD:   wpclsQueryIcon                OVERRIDE      PUBLIC
  505.  *
  506.  *  PURPOSE:  Returns the default record icon pointer.
  507.  *
  508.  */
  509.  
  510. SOM_Scope HPOINTER   SOMLINK recordcls_wpclsQueryIcon(M_Record *somSelf)
  511. {
  512.     /* M_RecordData *somThis = M_RecordGetData(somSelf); */
  513.     M_RecordMethodDebug("M_Record","recordcls_wpclsQueryIcon");
  514.  
  515.     if ( ThisClassDefaultIcon )
  516.     {
  517.        return( ThisClassDefaultIcon );
  518.     }
  519.     else
  520.     {
  521.        return( parent_wpclsQueryIcon(somSelf) );
  522.     }
  523. }
  524.  
  525. /*
  526.  *
  527.  *  METHOD:   wpclsQueryDefaultView         OVERRIDE      PUBLIC
  528.  *
  529.  *  PURPOSE:  Returns the default view for a
  530.  *            new instance of the record object.
  531.  *
  532.  */
  533.  
  534. SOM_Scope ULONG   SOMLINK recordcls_wpclsQueryDefaultView(M_Record *somSelf)
  535. {
  536.     /* M_RecordData *somThis = M_RecordGetData(somSelf); */
  537.     M_RecordMethodDebug("M_Record","recordcls_wpclsQueryDefaultView");
  538.  
  539.     return (OPEN_RECORD);
  540. }
  541.  
  542. /* End of Methods                                                         */
  543. /**************************************************************************/
  544.  
  545.  
  546. HWND CreateViewWindow( SOMAny *somSelf )
  547. {
  548.    HWND        hwndView;
  549.    ULONG       flViewCreate;
  550.    PRECORDVIEW pRecView;
  551.  
  552.    flViewCreate = FCF_TITLEBAR | FCF_SYSMENU | FCF_SIZEBORDER | FCF_MINMAX | FCF_SHELLPOSITION ;
  553.  
  554.    hwndView = WinCreateStdWindow( HWND_DESKTOP, 0,
  555.                                   &flViewCreate, "MLEFrameWindow",
  556.                                   "", 0, (HMODULE)0L, 0, NULL);
  557.  
  558.    WinSendMsg(hwndView, WM_SETICON, MPFROMP(ThisClassDefaultIcon), NULL);
  559.  
  560.    WinSetWindowPos( hwndView,  HWND_TOP, 0,0, 400, 180,
  561.                     SWP_ZORDER | SWP_SIZE | SWP_ACTIVATE | SWP_SHOW);
  562.  
  563.    /*******************************************************************/
  564.    /* Allocate memory for the objects viewitem and useitem structures */
  565.    /*                                                                 */
  566.    /* A viewitem should always be the next thing in memory after      */
  567.    /* a useitem (this is what WPS expects). So will allocate a        */
  568.    /* structure which guarantees this:                                */
  569.    /*                                                                 */
  570.    /*        RECORDVIEW                                               */
  571.    /*           SOMAny   *Record                                      */
  572.    /*           USEITEM  UseItem                                      */
  573.    /*           VIEWITEM ViewItem                                     */
  574.    /*                                                                 */
  575.    /* The useitems form a linked-list, one for each open view         */
  576.    /* of a particular object. The WPS scans this list in the          */
  577.    /* _wpSwitchTo method and then uses the information in the         */
  578.    /* adjacent viewitem to switch to the view.                        */
  579.    /*******************************************************************/
  580.  
  581.    pRecView = (PRECORDVIEW) _wpAllocMem(somSelf, sizeof(RECORDVIEW) , NULL);
  582.  
  583.    /********************************/
  584.    /* Fill out the item structures */
  585.    /********************************/
  586.    pRecView->Record          = somSelf;
  587.    pRecView->UseItem.type    = USAGE_OPENVIEW;
  588.    pRecView->ViewItem.view   = OPEN_RECORD;
  589.    pRecView->ViewItem.handle = hwndView;
  590.  
  591.    WinSetWindowULong(hwndView, QWL_USER, (ULONG) pRecView);
  592.  
  593.    /********************************************************/
  594.    /* Add the object to the use list, if this is the first */
  595.    /* time this is done then the Shell draws the in use    */
  596.    /* hash lines around the icon                           */
  597.    /********************************************************/
  598.    _wpAddToObjUseList(somSelf, &pRecView->UseItem);
  599.  
  600.    /********************************************************/
  601.    /* Registering the view with the shell will cause the   */
  602.    /* frame to be subclassed and the shell will take over  */
  603.    /* the system menu processing                           */
  604.    /********************************************************/
  605.    _wpRegisterView(somSelf, hwndView, "Person Details");
  606.  
  607.    return( hwndView );
  608. }
  609.  
  610. void DeleteViewWindow( HWND hwnd )
  611. {
  612.    HWND         hwndFrame;
  613.    PRECORDVIEW  pRecView;
  614.  
  615.    hwndFrame = WinQueryWindow(hwnd, QW_PARENT);
  616.  
  617.    /* Get the record view structure from the frames QWL_USER WW */
  618.    pRecView  = (PRECORDVIEW)WinQueryWindowULong(hwndFrame,QWL_USER);
  619.  
  620.    /**********************************************************/
  621.    /* Delete from use list. This will remove the in-use hash */
  622.    /* lines from around the icon                             */
  623.    /**********************************************************/
  624.    _wpDeleteFromObjUseList(pRecView->Record, &pRecView->UseItem);
  625.  
  626.    /* Free the view structure memory */
  627.    _wpFreeMem(pRecView->Record,(PBYTE)pRecView);
  628.  
  629. }
  630.  
  631. void IpcRequesterObjectThread (void *p)
  632. {
  633.   HMQ  hmq;
  634.   QMSG qmsg;
  635.   HAB  hab;
  636.  
  637.   hab = WinInitialize(0);
  638.  
  639.   hmq = WinCreateMsgQueue( hab, 0 );
  640.  
  641.   if ( !WinRegisterClass( hab, (PSZ)"IpcRequesterObjectWin",
  642.                           (PFNWP)IpcRequesterObjectWinProc,
  643.                           0L, sizeof(PREQ_DATA) )             )
  644.   {
  645.      DebugBox("IPC Fatal Error","Register Requester Class Failed");
  646.   }
  647.  
  648.   hwndRequester = WinCreateWindow(HWND_OBJECT,
  649.                                   "IpcRequesterObjectWin",
  650.                                   "", 0L, 0,0,0,0,
  651.                                   (HWND)0, HWND_TOP, 0L, NULL, NULL);
  652.  
  653.   while( WinGetMsg( hab, &qmsg, 0L, 0, 0 ) )
  654.      WinDispatchMsg( hab, &qmsg );
  655.  
  656.  
  657.   WinDestroyWindow(hwndRequester);
  658.   WinDestroyMsgQueue( hmq );
  659.   WinTerminate( hab );
  660. }
  661.  
  662.  
  663. MRESULT EXPENTRY IpcRequesterObjectWinProc( HWND hwnd,
  664.                                          ULONG msg,
  665.                                          MPARAM mp1,
  666.                                          MPARAM mp2 )
  667. {
  668.  
  669.   MRESULT mr;
  670.   REQ_DATA *pRequesterData;
  671.  
  672.   mr = (MRESULT)FALSE;
  673.  
  674.  
  675.   switch( msg )
  676.   {
  677.      case WM_CREATE:
  678.  
  679.          WinPostMsg(hwnd, WMP_INITIALISE_REQUESTER, (MPARAM)0, (MPARAM)0 );
  680.          mr = WinDefWindowProc( hwnd, msg, mp1, mp2 );
  681.          break;
  682.  
  683.      case WMP_INITIALISE_REQUESTER:
  684.  
  685.          pRequesterData = (REQ_DATA *)malloc( sizeof(REQ_DATA) );
  686.          pRequesterData->hwndServer = (HWND)0;
  687.          pRequesterData->pidServer  = 0;
  688.          WinSetWindowPtr(hwnd,0,pRequesterData);
  689.          WinPostMsg(hwnd, WMP_START_SERVER_PROGRAM, (MPARAM)0, (MPARAM)0 );
  690.          break;
  691.  
  692.     case WMP_START_SERVER_PROGRAM:
  693.          {
  694.             pRequesterData = (REQ_DATA *)WinQueryWindowPtr(hwnd,0);
  695.  
  696.             if( WinIsWindow( (HAB)0, pRequesterData->hwndServer) )
  697.             {
  698.                DosBeep(500,500);
  699.                DebugBox("Record Class Warning", "Server is already running. " \
  700.                         "Request to re-start has been discarded" );
  701.             }
  702.             else
  703.             {
  704.                CHAR  Args[80];
  705.                sprintf(Args,"%s@ %ul @",SERVER_PROGRAM, (ULONG)hwnd);
  706.                IpcStartServerProg(Args);
  707.             }
  708.          }
  709.          break;
  710.  
  711.  
  712.     case WMP_SERVER_READY:
  713.          {
  714.             PID pid;
  715.             TID tid;
  716.  
  717.             pRequesterData = (REQ_DATA *)WinQueryWindowPtr(hwnd,0);
  718.             pRequesterData->hwndServer = (HWND)mp1;
  719.             WinQueryWindowProcess((HWND)mp1,&pid,&tid);
  720.             pRequesterData->pidServer  = pid;
  721.          }
  722.          break;
  723.  
  724.     case WMP_SERVER_TERMINATED:
  725.          {
  726.             pRequesterData = (REQ_DATA *)WinQueryWindowPtr(hwnd,0);
  727.  
  728.             pRequesterData->hwndServer = (HWND)0;
  729.             pRequesterData->pidServer  = 0;
  730.  
  731.             DebugBox("Record Class Error", "Server Disconnected." \
  732.                      "Server must be restarted to perform record queries" );
  733.          }
  734.          break;
  735.  
  736.     case WMP_IPC_END:
  737.          {
  738.             pRequesterData = (REQ_DATA *)WinQueryWindowPtr(hwnd,0);
  739.  
  740.             WinPostMsg(pRequesterData->hwndServer, WM_CLOSE, (MPARAM)0, (MPARAM)0 );
  741.  
  742.             /* Exit this object window - end this thread */
  743.             WinPostMsg(hwnd, WM_CLOSE, (MPARAM)0, (MPARAM)0 );
  744.  
  745.          }
  746.          break;
  747.  
  748.     case WMP_RESULTS_FROM_SEARCH:
  749.          {
  750.             PRESULTS_DATA pResults;
  751.             PPERSON_DATA  pPerson;
  752.             APIRET rc;
  753.             USHORT i;
  754.             CHAR szTemp[500];
  755.             SOMAny *NewObj = NULL;
  756.  
  757.             pResults = (PRESULTS_DATA) mp1;
  758.             pPerson  = (PPERSON_DATA) ( (ULONG)mp1 + (ULONG)sizeof(RESULTS_DATA) );
  759.  
  760.             if(pResults->cRecords == 0)
  761.             {
  762.                /* This is temporary */
  763.                DebugBox("Query Results",(CHAR *)pPerson );
  764.             }
  765.             else
  766.             {
  767.                for(i=0; i<pResults->cRecords; i++)
  768.                {
  769.                   sprintf( szTemp,
  770.                            "\nName: %s\nAddress: %s\nTel: %s\n",
  771.                            pPerson->szName,
  772.                            pPerson->szAddress,
  773.                            pPerson->szTelepnone );
  774.  
  775.                   NewObj = _wpclsNew(ThisClass,
  776.                                      pPerson->szName,
  777.                                      "", (SOMAny *)pResults->folder,
  778.                                      TRUE);
  779.  
  780.                   _SetRecordInfo( NewObj, szTemp);
  781.                   pPerson++;
  782.                }
  783.             }
  784.  
  785.             rc = DosFreeMem( (PVOID)mp1 );
  786.             if (rc)
  787.             {
  788.                 DebugBox("Error","DosFreeMem Failed");
  789.             }
  790.          }
  791.          break;
  792.  
  793.  
  794.     case WMP_SEND_MSG_TO_SERVER:      /* mp1 = message                  */
  795.          {                            /* mp2 = pointer to shared memory */
  796.             ULONG ServerMsg;
  797.             PVOID pMsgData;
  798.             ULONG rc;
  799.  
  800.             ServerMsg = (ULONG) mp1;
  801.             pMsgData  = (PVOID) mp2;
  802.  
  803.             pRequesterData = (REQ_DATA *)WinQueryWindowPtr(hwnd,0);
  804.  
  805.             if( IpcServerWinCheck(pRequesterData->hwndServer) )
  806.             {
  807.                rc = DosGiveSharedMem( pMsgData,
  808.                                       pRequesterData->pidServer,
  809.                                       PAG_WRITE | PAG_READ);
  810.  
  811.                if (rc)
  812.                {
  813.                    DebugBox("Error","DosGiveSharedMem Failed");
  814.                }
  815.                else
  816.                {
  817.                   mr = WinSendMsg(pRequesterData->hwndServer, ServerMsg, (MPARAM)pMsgData, (MPARAM)0 );
  818.                   rc = DosFreeMem( pMsgData );
  819.                   if (rc)
  820.                   {
  821.                       DebugBox("Error","DosFreeMem Failed");
  822.                   }
  823.                   return(mr);
  824.                }
  825.             }
  826.             else
  827.             {
  828.                rc = DosFreeMem( pMsgData );
  829.                if (rc)
  830.                {
  831.                    DebugBox("Error","DosFreeMem Failed");
  832.                }
  833.             }
  834.          }
  835.          break;
  836.  
  837.     default:
  838.       mr = WinDefWindowProc( hwnd, msg, mp1, mp2 );
  839.   }
  840.   return mr;
  841. }
  842.  
  843.  
  844.  
  845. PVOID IpcGetMessageMem(ULONG ObjectSize)
  846. {
  847.     PVOID   pData;
  848.     ULONG   AttributeFlags;
  849.     APIRET  rc;
  850.  
  851.     AttributeFlags =  OBJ_GIVEABLE | PAG_WRITE | PAG_READ | PAG_COMMIT;
  852.  
  853.     rc = DosAllocSharedMem(&pData, NULL, ObjectSize,AttributeFlags);
  854.     if (rc)
  855.     {
  856.        /* This should never happen */
  857.  
  858.        DebugBox("IPC Fatal Error","DosAllocSharedMem failed");
  859.        return(NULL);
  860.     }
  861.     else
  862.     {
  863.        return(pData);
  864.     }
  865. }
  866.  
  867.  
  868. VOID IpcStartServerProg(PSZ Args )
  869. {
  870.    CHAR        LoadError[100];
  871.    RESULTCODES ReturnCodes;
  872.    ULONG       rc;
  873.    CHAR        *sptr;
  874.  
  875.    sptr = Args;
  876.    while(*sptr != '\0')
  877.    {
  878.       if(*sptr == '@')
  879.           *sptr = '\0';
  880.       sptr++;
  881.    }
  882.  
  883.    rc = DosExecPgm(LoadError, sizeof(LoadError),
  884.                    EXEC_BACKGROUND, Args,
  885.                    "", &ReturnCodes,
  886.                    SERVER_PROGRAM);
  887.  
  888.    if (rc)
  889.    {
  890.         DebugBox("IPC Fatal Error", "Sever Program could not be started");
  891.    }
  892. }
  893.  
  894. BOOL IpcServerWinCheck(HWND hwnd)
  895. {
  896.    if(! WinIsWindow( (HAB)0, hwnd) )
  897.    {
  898.       DosBeep(500,500);
  899.       DebugBox("IPC Fatal Error", "Cannot Access Server - Request discarded");
  900.       return(FALSE);
  901.    }
  902.    else
  903.       return(TRUE);
  904. }
  905.  
  906. /***************************************************************************/
  907. /*                          MLE in a Frame window                          */
  908. /***************************************************************************/
  909.  
  910. MRESULT EXPENTRY MLEFrameWindowProc( HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2 )
  911. {
  912.   MRESULT mr;
  913.  
  914.   mr = (MRESULT)FALSE;
  915.  
  916.   switch( msg )
  917.   {
  918.      case WM_CREATE:
  919.         {
  920.             HWND  hwndMLEWindow;
  921.  
  922.             /* Create MLE window */
  923.             hwndMLEWindow = WinCreateWindow(hwnd, WC_MLE,
  924.                                             "", MLS_VSCROLL | MLS_HSCROLL | MLS_BORDER,
  925.                                             0,0,0,0, hwnd, HWND_TOP, 0, NULL, NULL);
  926.  
  927.             /* Store the MLE hwnd in WW 0 */
  928.             WinSetWindowPtr(hwnd, 0, (PVOID) hwndMLEWindow);
  929.  
  930.             mr = WinDefWindowProc( hwnd, msg, mp1, mp2 );
  931.         }
  932.         break;
  933.  
  934.      case WMP_INSERT_DATA_INTO_VIEW:  /* mp1 = pointer to text buffer */
  935.         {
  936.             HWND    hwndMLEWindow;
  937.  
  938.             hwndMLEWindow = (HWND)WinQueryWindowPtr(hwnd, 0);
  939.             WinSendMsg(hwndMLEWindow, MLM_INSERT, (MPARAM)mp1, (MPARAM)0 );
  940.         }
  941.         break;
  942.  
  943.      case WM_SIZE:
  944.         {
  945.             RECTL   rc;
  946.             HWND    hwndMLEWindow;
  947.  
  948.             /* Get the MLE hwnd from WW 0 */
  949.             hwndMLEWindow = (HWND)WinQueryWindowPtr(hwnd, 0);
  950.  
  951.             WinQueryWindowRect(hwnd,&rc);
  952.  
  953.             WinSetWindowPos( hwndMLEWindow,  HWND_TOP,
  954.                              rc.xLeft,
  955.                              rc.yBottom,
  956.                              rc.xRight,
  957.                              rc.yTop,
  958.                              SWP_SIZE | SWP_MOVE | SWP_SHOW);
  959.  
  960.             mr = WinDefWindowProc( hwnd, msg, mp1, mp2 );
  961.         }
  962.         break;
  963.  
  964.     case WM_PAINT:
  965.         {
  966.            HPS    hps;
  967.            RECTL  rc;
  968.            hps = WinBeginPaint( hwnd, 0L, &rc );
  969.            WinFillRect(hps, &rc, CLR_WHITE);
  970.            WinEndPaint( hps );
  971.         }
  972.         break;
  973.  
  974.      case WM_CLOSE:
  975.         {
  976.            /************************************/
  977.            /* Tell WPS that this view has gone */
  978.            /************************************/
  979.            DeleteViewWindow( hwnd );
  980.  
  981.            WinPostMsg( hwnd, WM_QUIT, (MPARAM)0, (MPARAM)0 );
  982.            WinDestroyWindow( WinQueryWindow(hwnd, QW_PARENT) );
  983.         }
  984.         break;
  985.  
  986.     default:
  987.         mr = WinDefWindowProc( hwnd, msg, mp1, mp2 );
  988.         break;
  989.   }
  990.   return mr;
  991. }
  992.