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

  1. /*
  2.  * OS/2 Work Place Shell Sample Program - Common functions, 
  3.  *     DLL initialization, and global variable initialization.
  4.  *
  5.  * Copyright (C) 1993 IBM Corporation
  6.  *
  7.  *   DISCLAIMER OF WARRANTIES.  The following [enclosed] code is
  8.  *   sample code created by IBM Corporation.  This sample code is
  9.  *   not part of any standard or IBM product and is provided to you
  10.  *   solely for the purpose of assisting you in the development of
  11.  *   your applications.  The code is provided "AS IS".  ALL
  12.  *   WARRANTIES ARE EXPRESSLY DISCLAIMED, INCLUDING THE IMPLIED
  13.  *   WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  14.  *   PURPOSE.  IBM shall not be liable for any damages arising out
  15.  *   of your use of the sample code, even if IBM has been advised of
  16.  *   the possibility of such damages.
  17.  */
  18.  
  19. /*
  20.  * The pragma below tells the compiler that it should put
  21.  * string constants in a read-only segment, ie:
  22.  *
  23.  *   PSZ psz = "bay";
  24.  *   *psz = 'd';
  25.  *
  26.  * would cause a runtime exception (trap).  Of course, using this
  27.  * pragma is a matter of the programmer's preference, but the author
  28.  * believes doing so avoids potential coding mistakes that are 
  29.  * difficult to debug.
  30.  */
  31.  
  32. #pragma strings(readonly)
  33.  
  34. /*
  35.  * Include the toolkit headers that are needed by just about every
  36.  * module in this example.
  37.  */
  38.  
  39. #define INCL_WIN
  40. #define INCL_DOS
  41. #include <os2.h>
  42. #include <som.h>
  43. #include <stdlib.h>
  44. #include <stdio.h>
  45. #include <string.h>
  46. #include <memory.h>
  47. #include <setjmp.h>
  48. #include <ctype.h>
  49. #include <wpobject.h>
  50.  
  51. /*
  52.  * Typedef's.
  53.  */
  54.  
  55. typedef struct 
  56. {
  57.   struct _EXCEPTIONREGISTRATIONRECORD * volatile prev_structure;
  58.    _ERR * volatile ExceptionHandler;
  59.    jmp_buf env;
  60. } SHREXCEPTIONREGISTRATIONRECORD, *PSHREXCEPTIONREGISTRATIONRECORD;
  61.  
  62. /*
  63.  * Misc constants
  64.  */
  65.  
  66. #define NULLCHAR                        '\0'
  67. #define CCHMAXSTRING                    260
  68. #define CCHMINSTRING                    64
  69.  
  70. /*
  71.  * Dialog IDs (IDD_)
  72.  */
  73.  
  74. #define IDD_PERSONINFOPAGE              100
  75.  
  76. /*
  77.  * Pointer (icon) IDs (IDP_)
  78.  */
  79.                                         
  80. #define IDP_PERSON                      1
  81. #define IDP_ADDRESSBOOK                 2
  82.  
  83. /*
  84.  * Dialog control IDs.
  85.  */
  86.                                         
  87. #define ID_NAME                         1
  88. #define ID_ADDRESS                      2
  89. #define ID_CITY                         3
  90. #define ID_STATE                        4
  91. #define ID_ZIPCODE                      5
  92. #define ID_PHONE                        6
  93.  
  94. /*
  95.  * Pop-up menu IDs.  Note these must start with WPMENUID_USER
  96.  * to be assured they don't overlap those defined by the WPS.
  97.  */
  98.  
  99. #define ID_OPENADDRESSINDEXVIEW         (WPMENUID_USER+0)
  100. #define ID_CREATEPERSON                 (WPMENUID_USER+1)
  101.  
  102. /*
  103.  * Menu control IDs (IDM_)
  104.  */
  105.  
  106. #define IDM_OPENADDRESSBOOK             1
  107. #define IDM_ADDRESSBOOK                 2                  
  108.                                                            
  109. /*                                                         
  110.  * String table IDs (IDS_)                                 
  111.  */                                                        
  112.                                                            
  113. #define IDS_ADDRESSBOOKVIEWTITLE        1       // "Indexed View"
  114. #define IDS_PERSONINFOTAB               2       // "Info"
  115. #define IDS_PERSONTITLE                 3       // "Person"
  116. #define IDS_ADDRESSBOOKTITLE            4       // "Address Book"
  117.  
  118. #define IDS_INDEXTAB1                   5       // "A - C"
  119. #define IDS_INDEXTAB2                   6       // "D - F"
  120. #define IDS_INDEXTAB3                   7       // "G - I"
  121. #define IDS_INDEXTAB4                   8       // "J - L"
  122. #define IDS_INDEXTAB5                   9       // "M - O"
  123. #define IDS_INDEXTAB6                   10      // "P - R"
  124. #define IDS_INDEXTAB7                   11      // "S - U"
  125. #define IDS_INDEXTAB8                   12      // "V - Z"
  126. #define IDS_INDEXTAB9                   13      // "Misc"
  127.                                                            
  128. #define IDS_FIRSTINDEXTAB               IDS_INDEXTAB1
  129. #define IDS_LASTINDEXTAB                IDS_INDEXTAB9
  130. #define CINDEXTABS \
  131.     (IDS_LASTINDEXTAB-IDS_FIRSTINDEXTAB+1)
  132. #define IDS_INDEXTABMISC                IDS_LASTINDEXTAB
  133.  
  134. #define IDS_INDEXCHARSALL               15      // "ABC...XYZ"
  135. #define IDS_INDEXCHARS1                 16      // "ABC"
  136. #define IDS_INDEXCHARS2                 17      // "DEF"
  137. #define IDS_INDEXCHARS3                 18      // "GHI"
  138. #define IDS_INDEXCHARS4                 19      // "JKL"
  139. #define IDS_INDEXCHARS5                 20      // "MNO"
  140. #define IDS_INDEXCHARS6                 21      // "PQR"
  141. #define IDS_INDEXCHARS7                 22      // "STU"
  142. #define IDS_INDEXCHARS8                 23      // "VWXYZ"
  143.  
  144. #define IDS_FIRSTINDEXCHARS             IDS_INDEXCHARS1
  145. #define IDS_LASTINDEXCHARS              IDS_INDEXCHARS8
  146. #define CINDEXCHARS \
  147.     (IDS_LASTINDEXCHARS-IDS_FIRSTINDEXCHARS+1)
  148.  
  149. #define IDS_PERSONNEWTITLE              24      // "Last name..."
  150. #define IDS_ADDRESS                     25      // "Address"
  151. #define IDS_CITY                        26      // "City"
  152. #define IDS_STATE                       27      // "State"
  153. #define IDS_ZIPCODE                     28      // "Zip Code"
  154. #define IDS_PHONE                       29      // "Phone"
  155. #define IDS_DEFAULTPHONE                30      // "(919) 469-6000"
  156. #define IDS_DEFAULTADDRESS              31      // "11000 Regency..."
  157. #define IDS_DEFAULTCITY                 32      // "Cary"
  158. #define IDS_DEFAULTSTATE                34      // "NC"
  159. #define IDS_DEFAULTZIPCODE              35      // "27513"
  160.  
  161. /*
  162.  * Protocol IDs (used for determining if an object
  163.  * responds to a given set of methods -- see
  164.  * shrUnderstandsProtocol in ShrPerson for more details).
  165.  */
  166.  
  167. #define PROTOCOL_PERSON                 1
  168.  
  169. /*
  170.  * Function declarations
  171.  */
  172.  
  173. extern BOOL ShrSetObjectString
  174.     (SOMAny *somObject, PSZ pszNew, PSZ *ppszOld, ULONG ulChangeMsg);
  175. extern ULONG ShrQueryObjectString
  176.     (SOMAny *, PSZ pszReturn, PSZ *ppsz, PSZ pszDefault);
  177.  
  178. extern BOOL ShrOpeningView
  179.     (SOMAny *somSelf, HWND hwndFrame, ULONG ulView, PSZ pszViewTitle);
  180. extern BOOL ShrClosingView
  181.     (SOMAny *somSelf, HWND hwndFrame);
  182. extern MRESULT EXPENTRY ShrDefPageDlgProc
  183.     (HWND hwndDlg, ULONG msg, MPARAM mp1, MPARAM mp2);
  184. extern VOID ShrSetDlgEntryFieldText
  185.     (HWND hwndDlg, ULONG id, PSZ psz);
  186. extern VOID ShrSetDlgMLEText
  187.     (HWND hwndDlg, ULONG id, PSZ psz);
  188.  
  189. extern VOID ShrEmptyObjectCnr(HWND hwndCnr);
  190.  
  191. extern ULONG APIENTRY ShrExceptionHandler
  192.     (PEXCEPTIONREPORTRECORD pReportRecord, 
  193.     PEXCEPTIONREGISTRATIONRECORD pRegRecord,
  194.     PCONTEXTRECORD pContextRecord, PVOID pReserved);
  195.  
  196. /*
  197.  * Read-only global strings.
  198.  */
  199.  
  200. extern CHAR vszShrPersonClass[];
  201. extern CHAR vszShrAddressBookClass[];
  202. extern CHAR vszAddressNotebook[];
  203. extern CHAR vszNullString[];
  204. extern CHAR vszDesktopObjectId[];
  205. extern CHAR vszShrUnderstandsProtocol[];
  206. extern CHAR vszDRMObject[];
  207. extern CHAR vszDRFObject[];
  208. extern CHAR vszWcFrameCnrOwner[];
  209. extern CHAR vszwpModifyPopupMenu[];
  210. extern CHAR vszAppName[];
  211. extern CHAR vszIndexedViewWindowPosKeyName[];
  212.  
  213. /*
  214.  * Global MRI-related strings.
  215.  */
  216.  
  217. extern CHAR vszPersonTitle[CCHMINSTRING];
  218. extern CHAR vszAddressBookTitle[CCHMINSTRING];
  219. extern CHAR vszAddressBookViewTitle[CCHMINSTRING];
  220. extern CHAR vszPersonInfoTab[CCHMINSTRING];
  221. extern CHAR vaszIndexTabs[CINDEXTABS][CCHMINSTRING];
  222. extern CHAR vaszIndexChars[CINDEXCHARS][CCHMINSTRING];
  223. extern CHAR vszAllIndexChars[CCHMINSTRING];
  224. extern CHAR vszAddressBookCnrTitle[CCHMINSTRING];
  225. extern CHAR vszPersonNewTitle[CCHMINSTRING];
  226. extern CHAR vszAddress[CCHMINSTRING];
  227. extern CHAR vszCity[CCHMINSTRING];
  228. extern CHAR vszState[CCHMINSTRING];
  229. extern CHAR vszZipCode[CCHMINSTRING];
  230. extern CHAR vszPhone[CCHMINSTRING];
  231. extern CHAR vszDefaultAddress[CCHMINSTRING];
  232. extern CHAR vszDefaultCity[CCHMINSTRING];
  233. extern CHAR vszDefaultState[CCHMINSTRING];
  234. extern CHAR vszDefaultZipCode[CCHMINSTRING];
  235. extern CHAR vszDefaultPhone[CCHMINSTRING];
  236.  
  237. /*
  238.  * Global PM-related variables.
  239.  */
  240.  
  241. extern PFNWP vpfnDefaultFrameProc;
  242. extern PFNWP vpfnDefaultNotebookProc;
  243. extern PFNWP vpfnWPSCnrOwnerProc;
  244.  
  245. /*
  246.  * Global SOM-related variables.
  247.  */
  248.  
  249. extern somId vmidShrUnderstandsProtocol;
  250.  
  251. /*
  252.  * Notification message constants
  253.  * (see NOTIFY.CSC for details).
  254.  */
  255.  
  256. #define SHRN_PERSONNAMECHANGED          (WM_USER+0)
  257. #define SHRN_PERSONADDRESSCHANGED       (WM_USER+1)
  258. #define SHRN_PERSONCITYCHANGED          (WM_USER+2)
  259. #define SHRN_PERSONSTATECHANGED         (WM_USER+3)
  260. #define SHRN_PERSONZIPCODECHANGED       (WM_USER+4)
  261. #define SHRN_PERSONPHONECHANGED         (WM_USER+5)
  262.  
  263. #define SHRN_ADDRESSBOOKPERSONADDED     (WM_USER+6)
  264. #define SHRN_ADDRESSBOOKPERSONREMOVED   (WM_USER+7)
  265.  
  266. /*
  267.  * User defined PM messages.
  268.  */
  269.  
  270. #define SHR_SETOBJECT                   (WM_USER+100)
  271. #define SHR_QUERYOBJECT                 (WM_USER+101)
  272.  
  273. /*
  274.  * Macros.
  275.  */
  276.  
  277. #define ShrDefFrameProc(h,m,p1,p2) \
  278.     (*vpfnDefaultFrameProc)(h,m,p1,p2)
  279. #define ShrDefWPSCnrOwnerProc(h,m,p1,p2) \
  280.     (*vpfnWPSCnrOwnerProc)(h,m,p1,p2)
  281.  
  282. #define ShrRemoveMenuItem(hwndMenu,id) \
  283.     WinSendMsg(hwndMenu,MM_REMOVEITEM,MPFROM2SHORT(id,TRUE),NULL)
  284. #define ShrDeleteMenuItem(hwndMenu,id) \
  285.     WinSendMsg(hwndMenu,MM_DELETEITEM,MPFROM2SHORT(id,TRUE),NULL)
  286.  
  287. #define BOOLFROMP(p)  ((p) ? TRUE: FALSE)
  288.  
  289. /*
  290.  * These two simple macros are used to set a trap exception handler.
  291.  * ShrStartTryBlock should be used at the beginning of the function
  292.  * following the data declarations.  ShrEndTryBlock must precede
  293.  * the return statement.
  294.  *
  295.  * OS/2 and the WPS use exception handlers to catch invalid pointers
  296.  * that would otherwise cause a trap.  Exception handlers should be
  297.  * used whenever it is critical that a routine clean up resources:
  298.  *
  299.  * 1. Free allocated memory.
  300.  * 2. Destroy unneeded windows.
  301.  *
  302.  * and MOST IMPORTANTLY...
  303.  *
  304.  * 3. Release owned semaphores.
  305.  *
  306.  * It is very, very important that owned semaphores be released,
  307.  * otherwise others that request the semaphore could wait indefinitely.
  308.  *
  309.  * For example, if an object's semaphore is requested with
  310.  * wpRequestObjectMutexSem, an exception handler must be registered
  311.  * so wpReleaseObjectMutexSem will be called if the routine traps.
  312.  * Otherwise, the WPS will hang when it requests the semaphore.
  313.  *
  314.  * Note: In general, it is wise to use wpRequestObjectMutexSem and
  315.  * wpReleaseObjectMutexSem within your own defined methods which
  316.  * access instance data to assure the data is not modified by more
  317.  * than one thread (eg, the wpMenuItemSelected method is invoked
  318.  * from the main UI thread; wpSaveState is invoked from another
  319.  * lower priority thread).  
  320.  *
  321.  * WARNING: The exception handler chain is corrupted if ShrEndTryBlock
  322.  * is not called before exiting a routine.  Having two return
  323.  * statements per function, one for "no exception" and another for 
  324.  * handling "exception" is a good habit to have in order to
  325.  * avoid this difficult to debug problem, eg:
  326.  *
  327.  *   extern BOOL Trapper(PSZ psz)
  328.  *   {
  329.  *     ShrStartTryBlock;
  330.  *
  331.  *     ...exception handling set, go about in safety...
  332.  *
  333.  *     ShrEndTryBlock;
  334.  *     return TRUE;
  335.  *
  336.  *   OnException:
  337.  *
  338.  *     ...free any resources that were allocated, relinquish
  339.  *        semaphores that were successfully gotten, etc...
  340.  *
  341.  *     ShrEndTryBlock;
  342.  *     return FALSE;
  343.  *   }
  344.  *
  345.  * It is also wise to compile with the /Kb+ option specified
  346.  * to detect uninitialized variables and unprototyped functions.
  347.  */
  348.  
  349. #define ShrStartTryBlock \
  350.     SHREXCEPTIONREGISTRATIONRECORD shrExceptionRegRecord; \
  351.     shrExceptionRegRecord.prev_structure = NULL; \
  352.     shrExceptionRegRecord.ExceptionHandler = ShrExceptionHandler; \
  353.     DosSetExceptionHandler \
  354.         ((PEXCEPTIONREGISTRATIONRECORD) &shrExceptionRegRecord); \
  355.     if (setjmp(shrExceptionRegRecord.env)) \
  356.       goto OnException;
  357.  
  358. #define ShrEndTryBlock DosUnsetExceptionHandler  \
  359.     ((PEXCEPTIONREGISTRATIONRECORD) &shrExceptionRegRecord);
  360.  
  361.