home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: InfoMgt / InfoMgt.zip / shr93.zip / PERSONV.C < prev    next >
Text File  |  1993-04-12  |  6KB  |  227 lines

  1. /*
  2.  * OS/2 Work Place Shell Sample Program - ShrPerson view code
  3.  *
  4.  * Copyright (C) 1993 IBM Corporation
  5.  *
  6.  *   DISCLAIMER OF WARRANTIES.  The following [enclosed] code is
  7.  *   sample code created by IBM Corporation.  This sample code is
  8.  *   not part of any standard or IBM product and is provided to you
  9.  *   solely for the purpose of assisting you in the development of
  10.  *   your applications.  The code is provided "AS IS".  ALL
  11.  *   WARRANTIES ARE EXPRESSLY DISCLAIMED, INCLUDING THE IMPLIED
  12.  *   WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  13.  *   PURPOSE.  IBM shall not be liable for any damages arising out
  14.  *   of your use of the sample code, even if IBM has been advised of
  15.  *   the possibility of such damages.
  16.  *
  17.  * The person object has one view, the "Settings" view with
  18.  * an additional page, the "Info" page.
  19.  */
  20.  
  21. #define SOM_NoTest
  22.  
  23. #include "share.h"
  24. #include "person.h"
  25. #include "personv.h"
  26. #include "notify.h"
  27.  
  28. /*
  29.  * ShrPersonInfoSetObject initializes the person "Info" page.
  30.  */
  31.  
  32. extern MRESULT ShrPersonInfoSetObject
  33.     (HWND hwndDlg, SOMAny *somSelf)
  34. {
  35.   CHAR szText[512];
  36.  
  37.   WinSetWindowULong(hwndDlg, QWL_USER, (ULONG) somSelf);
  38.  
  39.   ShrSetDlgMLEText(hwndDlg, ID_NAME, _wpQueryTitle(somSelf));
  40.  
  41.   _shrQueryAddress(somSelf, sizeof(szText), szText);
  42.   ShrSetDlgEntryFieldText(hwndDlg, ID_ADDRESS, szText);
  43.  
  44.   _shrQueryCity(somSelf, sizeof(szText), szText);
  45.   ShrSetDlgEntryFieldText(hwndDlg, ID_CITY, szText);
  46.  
  47.   _shrQueryState(somSelf, sizeof(szText), szText);
  48.   ShrSetDlgEntryFieldText(hwndDlg, ID_STATE, szText);
  49.  
  50.   _shrQueryZipCode(somSelf, sizeof(szText), szText);
  51.   ShrSetDlgEntryFieldText(hwndDlg, ID_ZIPCODE, szText);
  52.  
  53.   _shrQueryPhone(somSelf, sizeof(szText), szText);
  54.   ShrSetDlgEntryFieldText(hwndDlg, ID_PHONE, szText);
  55.   
  56.   _shrAddInterestedWindow(_shrQueryNotifier(somSelf), hwndDlg);
  57.   
  58.   return (MRESULT) WinSetFocus(HWND_DESKTOP,
  59.       WinWindowFromID(hwndDlg, ID_NAME));
  60. }
  61.  
  62. /*
  63.  * ShrPersonInfoDlgEntryFieldKillFocus is called when one
  64.  * of the Info page's entry fields looses the focus.
  65.  * The model (person object) is updated to the new value.
  66.  */
  67.  
  68. extern VOID ShrPersonInfoDlgEntryFieldKillFocus
  69.     (SOMAny *somSelf, USHORT id, HWND hwndEntryField)
  70. {
  71.   CHAR szText[512];
  72.  
  73.   if (WinSendMsg(hwndEntryField, EM_QUERYCHANGED, 0, 0))
  74.   {
  75.     WinQueryWindowText(hwndEntryField, sizeof(szText), szText);
  76.  
  77.     /*
  78.      * Set the model string data.
  79.      */
  80.  
  81.     if (id == ID_ADDRESS)
  82.       _shrSetAddress(somSelf, szText);
  83.     else if (id == ID_CITY)
  84.       _shrSetCity(somSelf, szText);
  85.     else if (id == ID_STATE)
  86.       _shrSetState(somSelf, szText);
  87.     else if (id == ID_ZIPCODE)
  88.       _shrSetZipCode(somSelf, szText);
  89.     else if (id == ID_PHONE)
  90.       _shrSetPhone(somSelf, szText);
  91.   }
  92. }
  93.  
  94. /*
  95.  * ShrPersonInfoDlgMLEKillFocus is called when one
  96.  * of the Info page's multi-line entry fields looses the focus.
  97.  * The model (person object) is updated to the new value.
  98.  */
  99.  
  100. extern VOID ShrPersonInfoDlgMLEKillFocus
  101.     (SOMAny *somSelf, USHORT id, HWND hwndMLE)
  102. {
  103.   ULONG ulOffset, ulCopy;
  104.   CHAR szText[512];
  105.  
  106.   if (WinSendMsg(hwndMLE, MLM_QUERYCHANGED, 0, 0))
  107.   {
  108.     /*
  109.      * Set the export buffer address and length.
  110.      */
  111.  
  112.     WinSendMsg(hwndMLE, MLM_SETIMPORTEXPORT,
  113.         MPFROMP(szText), MPFROMLONG(sizeof(szText)));
  114.   
  115.     /*
  116.      * Export the MLE text, append a NULL character (since the
  117.      * MLE doesn't).
  118.      */
  119.  
  120.     ulOffset = 0;
  121.     ulCopy = sizeof(szText) - 1;
  122.     ulCopy = (ULONG) WinSendMsg(hwndMLE, MLM_EXPORT,
  123.         &ulOffset, &ulCopy);
  124.     szText[ulCopy] = NULLCHAR;
  125.  
  126.     /*
  127.      * Set the model string data.
  128.      */
  129.  
  130.     if (id == ID_NAME)
  131.       _wpSetTitle(somSelf, szText);
  132.   }
  133. }
  134.  
  135. /*
  136.  * ShrPersonInfoPageDlgProc is the dialog procedure
  137.  * for the Info dialog when it is displayed as a page
  138.  * in the notebook of the Settings view.
  139.  */
  140.  
  141. extern MRESULT EXPENTRY ShrPersonInfoPageDlgProc
  142.     (HWND hwndDlg, ULONG msg, MPARAM mp1, MPARAM mp2)
  143. {
  144.   MRESULT mr = NULL;
  145.   SOMAny *somSelf;
  146.  
  147.   switch (msg)
  148.   {
  149.     case WM_INITDLG:
  150.       mr = WinSendMsg(hwndDlg, SHR_SETOBJECT, mp2, NULL);
  151.       break;
  152.  
  153.     case SHR_QUERYOBJECT:
  154.       mr = (MRESULT) WinQueryWindowULong(hwndDlg, QWL_USER);
  155.       break;
  156.  
  157.     case SHR_SETOBJECT:
  158.       mr = ShrPersonInfoSetObject(hwndDlg, (SOMAny *) mp1);
  159.       break;
  160.  
  161.     case WM_CONTROL:
  162.       somSelf = (SOMAny *) WinSendMsg(hwndDlg, 
  163.           SHR_QUERYOBJECT, NULL, NULL);
  164.  
  165.       switch (SHORT1FROMMP(mp1))
  166.       {
  167.         case ID_NAME:
  168.           if (SHORT2FROMMP(mp1) == MLN_KILLFOCUS)
  169.             ShrPersonInfoDlgMLEKillFocus(somSelf,
  170.                 SHORT1FROMMP(mp1), 
  171.                 WinWindowFromID(hwndDlg, SHORT1FROMMP(mp1)));
  172.           break;
  173.  
  174.         case ID_ADDRESS:
  175.         case ID_CITY:
  176.         case ID_STATE:
  177.         case ID_ZIPCODE:
  178.         case ID_PHONE:
  179.           if (SHORT2FROMMP(mp1) == EN_KILLFOCUS)
  180.             ShrPersonInfoDlgEntryFieldKillFocus(somSelf,
  181.                 SHORT1FROMMP(mp1), HWNDFROMMP(mp2));
  182.           break;
  183.       }
  184.       break;
  185.  
  186.     case SHRN_PERSONNAMECHANGED:
  187.       ShrSetDlgMLEText(hwndDlg, ID_NAME, (PSZ) mp2);
  188.       break;
  189.  
  190.     case SHRN_PERSONADDRESSCHANGED:
  191.       ShrSetDlgEntryFieldText(hwndDlg, ID_ADDRESS, (PSZ) mp2);
  192.       break;
  193.  
  194.     case SHRN_PERSONCITYCHANGED:
  195.       ShrSetDlgEntryFieldText(hwndDlg, ID_CITY, (PSZ) mp2);
  196.       break;
  197.  
  198.     case SHRN_PERSONSTATECHANGED:
  199.       ShrSetDlgEntryFieldText(hwndDlg, ID_STATE, (PSZ) mp2);
  200.       break;
  201.  
  202.     case SHRN_PERSONZIPCODECHANGED:
  203.       ShrSetDlgEntryFieldText(hwndDlg, ID_ZIPCODE, (PSZ) mp2);
  204.       break;
  205.  
  206.     case SHRN_PERSONPHONECHANGED:
  207.       ShrSetDlgEntryFieldText(hwndDlg, ID_PHONE, (PSZ) mp2);
  208.       break;
  209.  
  210.     case WM_DESTROY:
  211.       somSelf = (SOMAny *) WinSendMsg(hwndDlg, 
  212.           SHR_QUERYOBJECT, NULL, NULL);
  213.  
  214.       if (somSelf)
  215.         _shrRemoveInterestedWindow(_shrQueryNotifier(somSelf), hwndDlg);
  216.  
  217.       mr = ShrDefPageDlgProc(hwndDlg, msg, mp1, mp2);
  218.       break;
  219.  
  220.     default:
  221.       mr = ShrDefPageDlgProc(hwndDlg, msg, mp1, mp2);
  222.       break;
  223.   }
  224.   
  225.   return mr;
  226. }
  227.