home *** CD-ROM | disk | FTP | other *** search
/ Power GUI Programming with VisualAge C++ / powergui.iso / trialva / ibmcppw / samples / som / somi / c / irdump / irdump.c next >
Encoding:
C/C++ Source or Header  |  1996-02-10  |  32.7 KB  |  829 lines

  1. /*
  2.  *   COMPONENT_NAME: somx
  3.  *
  4.  *   ORIGINS: 27
  5.  *
  6.  *
  7.  *   10H9767, 10H9769  (C) COPYRIGHT International Business Machines Corp. 1992,1994
  8.  *   All Rights Reserved
  9.  *   Licensed Materials - Property of IBM
  10.  *   US Government Users Restricted Rights - Use, duplication or
  11.  *   disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  12.  */
  13. #ifndef lint
  14. static char *sccsid = "%Z% %I% %W% %G% %U% [%H% %T%]";
  15. #endif
  16.  
  17. /*
  18.  *
  19.  * DISCLAIMER OF WARRANTIES.
  20.  * The following [enclosed] code is sample code created by IBM
  21.  * Corporation. This sample code is not part of any standard or IBM
  22.  * product and is provided to you solely for the purpose of assisting
  23.  * you in the development of your applications.  The code is provided
  24.  * "AS IS". IBM MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT
  25.  * NOT LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  26.  * FOR A PARTICULAR PURPOSE, REGARDING THE FUNCTION OR PERFORMANCE OF
  27.  * THIS CODE.  IBM shall not be liable for any damages arising out of
  28.  * your use of the sample code, even if they have been advised of the
  29.  * possibility of such damages.
  30.  *
  31.  * DISTRIBUTION.
  32.  * This sample code can be freely distributed, copied, altered, and
  33.  * incorporated into other software, provided that it bears the above
  34.  * Copyright notice and DISCLAIMER intact.
  35.  */
  36.  
  37. /* Interface Repository Viewer Program Sample */
  38.  
  39. #include <windows.h>
  40. #include <string.h>
  41. #include <direct.h>
  42. #include <som.h>
  43. #include <stdlib.h>
  44. #include <repostry.h>
  45. #include <containr.h>
  46. #include <containd.h>
  47. #include <intfacdf.h>
  48. #include <moduledf.h>
  49. #include <typedef.h>
  50. #include <constdef.h>
  51. #include <irdump.h>
  52. #include "nlsutil.h"
  53. /* #include <bccstruc.h>
  54. */
  55. #define  MAXID        80
  56. #define  MAXTMP     2048
  57. #define  MAXOUT     8192
  58. #define  WM_BLDTEXT (WM_USER+0)
  59.  
  60. long WINAPI WndProc(HWND, UINT, UINT, LONG);
  61. LRESULT APIENTRY ListProc(HWND, UINT, UINT, LONG);
  62. LRESULT APIENTRY TextProc(HWND, UINT, UINT, LONG);
  63. static void irdumpHelp(HWND);
  64. static string getErrorType(irOpenErrorCodes ec);
  65. static int SOMLINK irOutChar(char c);
  66. static void expandComma(char *);
  67.  
  68. char szAppName[] = "IRdump";
  69. char szAppDesc[] = "SOM Interface Repository Viewer Sample";
  70. char szTxtName[] = "TextWin";
  71. char tmpbuf[MAXTMP] = "";
  72. char buf[MAXOUT] = "";
  73. Repository *repo = NULL;
  74. SOMObject *cSel = NULL;
  75. LPSTR parentid = NULL;
  76. SOMClass *containerClass = NULL;
  77. sequence(Contained) sc = {0, 0, NULL};
  78. Environment *ev = NULL;
  79. irOpenError *oep = NULL;
  80. string exname = NULL;
  81. HWND hwndCurr = NULL, hwndList = NULL, hwndText = NULL;
  82. WNDPROC lpfnOldList= NULL, lpfnOldText = NULL;
  83. HANDLE gHInstance = NULL;
  84.  
  85. /* Define standard video sizes */
  86. float hRes = 0, vRes = 0, hFact = 0, vFact = 0, htFact = 0, wtFact = 0;
  87. #define STDHRES    1024.0
  88. #define STDVRES    768.0
  89. #define STDHEIGHT  20.0
  90. #define STDWIDTH   9.0
  91.  
  92. /* Messages for NLS Support */
  93. static char *nlsmsgs[ENDNLSID-STARTNLSID+1];
  94. #define GetNlsMessage(id) nlsmsgs[id-STARTNLSID]
  95. #define SetNlsMessage(id, str) nlsmsgs[id-STARTNLSID] = (str);
  96.  
  97. /**********************************************************
  98. 18953: NLS support
  99. This procedure must be called first to initialize all the messages
  100. to be used by irdump. These messages are obtained from the resource file.
  101. ****************************************************************/
  102. static void InitNlsMsgs(){
  103. int i;
  104.     SetNlsMessage(IRFileErrorId, NlsMsgAlloc(IRFileErrorId));
  105.     SetNlsMessage(ModuleSelectId, NlsMsgAlloc(ModuleSelectId));
  106.     SetNlsMessage(InterfaceInheritId, NlsMsgAlloc(InterfaceInheritId));
  107.     SetNlsMessage(AttrOperationId, NlsMsgAlloc(AttrOperationId));
  108.     SetNlsMessage(OperationTypecodeId, NlsMsgAlloc(OperationTypecodeId));
  109.     SetNlsMessage(ParametersId, NlsMsgAlloc(ParametersId));
  110.     SetNlsMessage(ExceptionId, NlsMsgAlloc(ExceptionId    ));
  111.     SetNlsMessage(ParameterOperationId    , NlsMsgAlloc(ParameterOperationId));
  112.     SetNlsMessage(TypeDefinedId, NlsMsgAlloc(TypeDefinedId));
  113.     SetNlsMessage(ExceptionDefinedId, NlsMsgAlloc(ExceptionDefinedId));
  114.     SetNlsMessage(AttributeDefinedId, NlsMsgAlloc(AttributeDefinedId));
  115.     SetNlsMessage(ConstantDefinedId, NlsMsgAlloc(ConstantDefinedId));
  116.     SetNlsMessage(UnknownDescriptorId, NlsMsgAlloc(UnknownDescriptorId));
  117.     SetNlsMessage(SOMModifiersId, NlsMsgAlloc(SOMModifiersId));
  118.     SetNlsMessage(IRAccessId, NlsMsgAlloc(IRAccessId));
  119.     SetNlsMessage(StaticId, NlsMsgAlloc(StaticId));
  120.     SetNlsMessage(SelectedEntryId, NlsMsgAlloc(SelectedEntryId));
  121.     SetNlsMessage(RepositoryIdListId, NlsMsgAlloc(RepositoryIdListId));
  122.     SetNlsMessage(SelectedEntryDescriptionId, NlsMsgAlloc(SelectedEntryDescriptionId));
  123.     SetNlsMessage(NothingId, NlsMsgAlloc(NothingId));
  124.     SetNlsMessage(OperationsIntroducedId, NlsMsgAlloc(OperationsIntroducedId));
  125.     SetNlsMessage(NoParameterId, NlsMsgAlloc(NoParameterId));
  126.     SetNlsMessage(UnknownDescriptionId, NlsMsgAlloc(UnknownDescriptionId));
  127.     SetNlsMessage(CantFindSelectionId, NlsMsgAlloc(CantFindSelectionId));
  128.     SetNlsMessage(IRMessageId, NlsMsgAlloc(IRMessageId));
  129.     SetNlsMessage(AttrIntroducedId, NlsMsgAlloc(AttrIntroducedId));
  130.     SetNlsMessage(ModeId, NlsMsgAlloc(ModeId));
  131.  
  132. }
  133.  
  134. int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
  135.                     LPSTR lpszCmdLine, int nCmdShow)
  136. {
  137.     HWND hwnd;
  138.     MSG msg;
  139.     WNDCLASS wndclass;
  140.  
  141.     InitNlsMsgs();
  142. /*    SOM_MainProgram();
  143. */
  144.     gHInstance = hInstance;
  145.  
  146.     if (!hPrevInstance) {
  147.         wndclass.style = CS_HREDRAW | CS_VREDRAW;
  148.         wndclass.lpfnWndProc = WndProc;
  149.         wndclass.cbClsExtra = 0;
  150.         wndclass.cbWndExtra = 0;
  151.         wndclass.hInstance = hInstance;
  152.         wndclass.hIcon = LoadIcon(hInstance, szAppName);
  153.         wndclass.hCursor = LoadCursor(NULL, IDC_ARROW);
  154.         wndclass.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
  155.         wndclass.lpszMenuName  = szAppName;
  156.         wndclass.lpszClassName = szAppName;
  157.  
  158.         RegisterClass(&wndclass);
  159.  
  160.         wndclass.style = CS_HREDRAW | CS_VREDRAW;
  161.         wndclass.lpfnWndProc = TextProc;
  162.         wndclass.cbClsExtra = 0;
  163.         wndclass.cbWndExtra = 0;
  164.         wndclass.hInstance = hInstance;
  165.         wndclass.hIcon = NULL;
  166.         wndclass.hCursor = NULL;
  167.         wndclass.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
  168.         wndclass.lpszMenuName = NULL;
  169.         wndclass.lpszClassName = szTxtName;
  170.  
  171.         RegisterClass(&wndclass);
  172.     }
  173.  
  174.     /* Figure video sizing factors */
  175.     hRes  = GetSystemMetrics(SM_CXSCREEN);
  176.     vRes  = GetSystemMetrics(SM_CYSCREEN);
  177.     hFact = hRes / STDHRES;
  178.     vFact = vRes / STDVRES;
  179.  
  180.     hwnd = CreateWindow(szAppName, szAppDesc,
  181.                         WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN,
  182.                         20, 10, (int)(960 * hFact), (int)(690 * vFact),
  183.                         NULL, NULL, hInstance, 0);
  184.  
  185.  
  186.     ShowWindow(hwnd, nCmdShow);
  187.     UpdateWindow(hwnd);
  188.  
  189.     while (GetMessage(&msg, NULL, 0, 0)) {
  190.         TranslateMessage(&msg);
  191.         DispatchMessage(&msg);
  192.     }
  193.     return msg.wParam;
  194. }
  195.  
  196. long WINAPI WndProc(HWND hwnd, UINT message, UINT wParam,
  197.                                  LONG lParam)
  198. {
  199.     char szBuffer[MAXTMP + 1];
  200.     HDC hdc;
  201.     int i;
  202.     unsigned int ui;
  203.     TEXTMETRIC tm;
  204.     LRESULT rc;
  205.     HCURSOR hCursor;
  206.     HMENU hMenu;
  207.  
  208.     switch (message) {
  209.         case WM_CREATE:
  210.             hCursor = SetCursor(LoadCursor(NULL, IDC_WAIT));
  211.             ShowCursor(TRUE);
  212.             hMenu = GetMenu(hwnd);
  213.  
  214.             ev = somGetGlobalEnvironment();
  215.             somEnvironmentNew();
  216.             containerClass = ContainerNewClass(0, 0);
  217.             somSetOutChar((somTD_SOMOutCharRoutine *) irOutChar);
  218.  
  219.             /* Try to open up the IR and quit if we can't */
  220.             if (!(repo = RepositoryNew())) {
  221.                 exname = somExceptionId(ev);
  222.                 oep = (irOpenError *) somExceptionValue(ev);
  223.                 if ((ev->_major == USER_EXCEPTION) && exname && oep &&
  224.                     (strcmp(ex_irOpenError, exname) == 0)) {
  225.                     wsprintf(buf, GetNlsMessage(IRFileErrorId),
  226.                              (LPSTR) oep->fileName,
  227.                              (LPSTR) getErrorType(oep->errorCode));
  228.                     MessageBox(hwnd, buf, szAppDesc,
  229.                                MB_ICONEXCLAMATION | MB_OK);
  230.                     somExceptionFree(ev);
  231.                 }
  232.                 else
  233.                     MessageBox(hwnd, GetNlsMessage(IRAccessId), szAppDesc,
  234.                                MB_ICONEXCLAMATION | MB_OK);
  235.                 SendMessage(hwnd, WM_CLOSE, 0, 0L);
  236.                 return 0;
  237.             }
  238.                                         
  239.             hdc = GetDC(hwnd);
  240.             GetTextMetrics(hdc, &tm);
  241.             ReleaseDC(hwnd, hdc);
  242.  
  243.             htFact = STDHEIGHT / tm.tmHeight;
  244.             wtFact = STDWIDTH  / tm.tmAveCharWidth;
  245.  
  246.             CreateWindow("static", GetNlsMessage(SelectedEntryId),
  247.                          WS_CHILDWINDOW | WS_VISIBLE | SS_LEFT,
  248.                          (int)(tm.tmAveCharWidth * 7 * hFact * wtFact),
  249.                          (int)(tm.tmHeight * vFact * htFact),
  250.                          tm.tmAveCharWidth * 15,
  251.                          tm.tmHeight,
  252.                          hwnd, (HANDLE)2,
  253.                          (HINSTANCE)GetWindowLong(hwnd, GWL_HINSTANCE), 0);
  254.  
  255.             hwndCurr = CreateWindow("static", "::",
  256.                                     WS_CHILDWINDOW | WS_VISIBLE | SS_LEFT,
  257.                                     (int)(tm.tmAveCharWidth * 4 * hFact * wtFact),
  258.                                     (int)(tm.tmHeight * 3 * vFact * htFact),
  259.                                     (int)(tm.tmAveCharWidth * MAXID * hFact * wtFact),
  260.                                     tm.tmHeight,
  261.                                     hwnd, (HANDLE)2,
  262.                                     (HINSTANCE)GetWindowLong(hwnd, GWL_HINSTANCE), 0);
  263.  
  264.             CreateWindow("static", GetNlsMessage(RepositoryIdListId),
  265.                          WS_CHILDWINDOW | WS_VISIBLE | SS_LEFT,
  266.                          (int)(tm.tmAveCharWidth * 9 * hFact * wtFact),
  267.                          (int)(tm.tmHeight * 5 * vFact * htFact),
  268.                          tm.tmAveCharWidth * 19,
  269.                          tm.tmHeight,
  270.                          hwnd, (HANDLE)2,
  271.                          (HINSTANCE)GetWindowLong(hwnd, GWL_HINSTANCE), 0);
  272.  
  273.  
  274.             hwndList = CreateWindow("listbox", NULL,
  275.                                     WS_CHILDWINDOW | WS_VISIBLE | LBS_STANDARD,
  276.                                     (int)(tm.tmAveCharWidth * 4 * hFact * wtFact),
  277.                                     (int)(tm.tmHeight * 7 * vFact * htFact),
  278.                                     (int)(tm.tmAveCharWidth * 30 * hFact * wtFact +
  279.                                     GetSystemMetrics(SM_CXVSCROLL)),
  280.                                     (int)(tm.tmHeight * 22 * vFact * htFact),
  281.                                     hwnd, (HANDLE)1,
  282.                                     (HINSTANCE)GetWindowLong(hwnd, GWL_HINSTANCE), 0);
  283.  
  284.             CreateWindow("static", GetNlsMessage(SelectedEntryDescriptionId),
  285.                          WS_CHILDWINDOW | WS_VISIBLE | SS_LEFT,
  286.                          (int)(tm.tmAveCharWidth * 56 * hFact * wtFact),
  287.                          (int)(tm.tmHeight * 5 * vFact * htFact),
  288.                          tm.tmAveCharWidth * 26,
  289.                          tm.tmHeight,
  290.                          hwnd, (HANDLE)2,
  291.                          (HINSTANCE)GetWindowLong(hwnd, GWL_HINSTANCE), 0);
  292.  
  293.             hwndText = CreateWindow(szTxtName, NULL,
  294.                                     WS_CHILDWINDOW | WS_VISIBLE | WS_BORDER |
  295.                                     WS_HSCROLL | WS_VSCROLL | WS_TABSTOP,
  296.                                     (int)(tm.tmAveCharWidth * 40 * hFact * wtFact),
  297.                                     (int)(tm.tmHeight * 7 * vFact * htFact),
  298.                                     (int)(tm.tmAveCharWidth * 60 * hFact * wtFact +
  299.                                     GetSystemMetrics(SM_CXVSCROLL)),
  300.                                     (int)(tm.tmHeight * 22 * vFact * htFact),
  301.                                     hwnd, (HANDLE)1,
  302.                                     (HINSTANCE)GetWindowLong(hwnd, GWL_HINSTANCE), 0);
  303.  
  304.             lpfnOldList = (WNDPROC) SetWindowLong(hwndList, GWL_WNDPROC, (LONG)ListProc);
  305.             
  306.             /* Set the IR to be the current selection */
  307.             cSel = repo;
  308.  
  309.             /* Fill up list box with toplevel contents of IR */
  310.  
  311.             /* Get the contents of the Repository */
  312.             sc = Container_contents(cSel, ev, "all", FALSE);
  313.  
  314.             /* Clear current contents of our ListBox */
  315.             SendMessage(hwndList, LB_RESETCONTENT, 0, 0L);
  316.  
  317.             /* Don't display the ListBox while we are filling it */
  318.             SendMessage(hwndList, WM_SETREDRAW, FALSE, 0L);
  319.  
  320.             /*
  321.              * Fill the ListBox with the names of the entries in the current
  322.              * container
  323.              */
  324.             if (sc._length) {
  325.                 for (ui = 0; ui < sc._length; ui++) {
  326.                     SendMessage(hwndList, LB_ADDSTRING, 0,
  327.                                 (LONG) (LPSTR) __get_id(sc._buffer[ui], ev));
  328.                     _somFree(sc._buffer[ui]);
  329.                 }                      /* endfor */
  330.                 SOMFree(sc._buffer);
  331.                 sc._length = 0L;
  332.             }                          /* endif */
  333.  
  334.             /* OK, now we can display ListBox */
  335.             SendMessage(hwndList, WM_SETREDRAW, TRUE, 0L);
  336.  
  337.             ShowCursor(FALSE);
  338.             SetCursor(hCursor);
  339.             return 0;
  340.  
  341.         case WM_COMMAND:
  342.              switch (wParam)
  343.              {
  344.              case IDM_EXIT:
  345.                   SendMessage(hwnd, WM_CLOSE, 0, 0L);
  346.                   return 0;
  347.  
  348.              case IDM_HELP:
  349.                   irdumpHelp(hwnd);
  350.                   return 0L;
  351.              }
  352.  
  353.             if (LOWORD(wParam) == 1 && HIWORD(wParam) == LBN_DBLCLK) {
  354.                 if (LB_ERR == (i = (WORD) SendMessage(hwndList, LB_GETCURSEL, 0, 0L)))
  355.                     break;
  356.                 SendMessage(hwndList, LB_GETTEXT, i, (LONG) (char far *) szBuffer);
  357.  
  358.                 cSel = (strcmp(szBuffer, "::") == 0) ? repo
  359.                     : Repository_lookup_id(repo, ev, (string) szBuffer);
  360.  
  361.                 if (cSel) {
  362.                     SetWindowText(hwndCurr, szBuffer);
  363.                     if (_somIsA(cSel, containerClass)) {
  364.                         HCURSOR hCursor = SetCursor(LoadCursor(NULL, IDC_WAIT));
  365.                         ShowCursor(TRUE);
  366.                         /* Clear current contents of our ListBox */
  367.                         SendMessage(hwndList, LB_RESETCONTENT, 0, 0L);
  368.  
  369.                         /*
  370.                          * Add the object in which the selection in defined to
  371.                          * the List Box -- so the user can "pop back up" later
  372.                          */
  373.                         if (cSel != repo) {
  374.                             rc = SendMessage(hwndList, LB_ADDSTRING, 0,
  375.                                    (LONG) (LPSTR) __get_defined_in(cSel, ev));
  376.                         }              /* endfor */
  377.  
  378.                         /* Determine contents of current selection */
  379.                         sc = Container_contents(cSel, ev, "all", FALSE);
  380.  
  381.                         /*
  382.                          * Fill the ListBox with the names of the entries in
  383.                          * the current container
  384.                          */
  385.                         if (sc._length) {
  386.                             for (ui = 0; ui < sc._length; ui++) {
  387.                                 rc = SendMessage(hwndList, LB_ADDSTRING, 0,
  388.                                  (LONG) (LPSTR) __get_id(sc._buffer[ui], ev));
  389.                                 _somFree(sc._buffer[ui]);
  390.                             }          /* endfor */
  391.                             SOMFree(sc._buffer);
  392.                             sc._length = 0L;
  393.                         }              /* endif */
  394.                         ShowCursor(FALSE);
  395.                         SetCursor(hCursor);
  396.                     }
  397.                     else {             /* cSel is a contained object */
  398.                         parentid = __get_defined_in(cSel, ev);
  399.                         /* if parent not already in List Box, Add it */
  400.                         if (LB_ERR == SendMessage(hwndList,
  401.                                                   LB_FINDSTRINGEXACT,
  402.                                                   (WPARAM) - 1,
  403.                                               (LPARAM) ((LPCSTR) parentid))) {
  404.                             SendMessage(hwndList, LB_ADDSTRING, 0, (LONG) (LPSTR) parentid);
  405.                         }              /* endif */
  406.                     }                  /* endif */
  407.                 }
  408.                 else {                 /* cSel is NULL */
  409.                     MessageBox(hwnd, GetNlsMessage(CantFindSelectionId), szAppDesc,
  410.                                MB_ICONEXCLAMATION | MB_OK);
  411.                 }                      /* endif */
  412.  
  413.                 SendMessage(hwndText, WM_BLDTEXT, 0, 0L);
  414.             }                          /* end if */
  415.             return 0;
  416.  
  417.         case WM_DESTROY:
  418.             PostQuitMessage(0);
  419.             return 0;
  420.     }
  421.     return DefWindowProc(hwnd, message, wParam, lParam);
  422. }
  423.  
  424.  
  425. LRESULT APIENTRY ListProc(HWND hwnd, UINT message, UINT wParam,
  426.                                   LONG lParam)
  427. {
  428.     if (message == WM_KEYDOWN && wParam == VK_RETURN)
  429.          SendMessage(GetParent(hwnd), WM_COMMAND, (UINT)(MAKELONG(1, LBN_DBLCLK)), (LONG)hwnd);
  430.  
  431.     return CallWindowProc(lpfnOldList, hwnd, message, wParam, lParam);
  432. }
  433.  
  434.  
  435. LRESULT APIENTRY TextProc(HWND hwnd, UINT message, UINT wParam,
  436.                                  LONG lParam)
  437. {
  438.     HDC          hdc;
  439.     unsigned int ui, cnt;
  440.     PAINTSTRUCT  ps;
  441.     Description  cdesc;
  442.     HCURSOR      hCursor;
  443.     static BOOL  first = TRUE;
  444.     static RECT  rect = {0, 0, 0, 0};
  445.     static short vPos = 0, hPos = 0, numlines = 0, maxline = 0;
  446.     static TEXTMETRIC tm = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
  447.  
  448.  
  449.     switch (message) {
  450.         case WM_CREATE:
  451.             hCursor = SetCursor(LoadCursor(NULL, IDC_WAIT));
  452.             ShowCursor(TRUE);
  453.  
  454.             hdc = GetDC(hwnd);
  455.             SelectObject(hdc, GetStockObject(SYSTEM_FIXED_FONT));
  456.             GetTextMetrics(hdc, &tm);
  457.             ReleaseDC(hwnd, hdc);
  458.             first = TRUE;
  459.             return 0;
  460.  
  461.         case WM_SIZE:
  462.             rect.right = LOWORD(lParam);
  463.             rect.bottom = HIWORD(lParam);
  464.             return 0;
  465.  
  466.         case WM_VSCROLL:
  467.  
  468.             switch (wParam) {
  469.                 case SB_LINEUP:
  470.                     vPos -= 1;
  471.                     break;
  472.  
  473.                 case SB_LINEDOWN:
  474.                     vPos += 1;
  475.                     break;
  476.  
  477.                 case SB_PAGEUP:
  478.                     vPos -= rect.bottom / tm.tmHeight;
  479.                     break;
  480.  
  481.                 case SB_PAGEDOWN:
  482.                     vPos += rect.bottom / tm.tmHeight;
  483.                     break;
  484.  
  485.                 case SB_THUMBPOSITION:
  486.                     vPos = LOWORD(lParam);
  487.                     break;
  488.  
  489.             }
  490.             /* Must double the scroll range because of possibility of wrap */
  491.             vPos = max(0, min(vPos, numlines*2));
  492.  
  493.             if (vPos != GetScrollPos(hwnd, SB_VERT)) {
  494.                 SetScrollPos(hwnd, SB_VERT, vPos, TRUE);
  495.                 InvalidateRect(hwnd, NULL, TRUE);
  496.             }
  497.  
  498.             return 0;
  499.  
  500.         case WM_HSCROLL:
  501.  
  502.             switch (wParam) {
  503.                 case SB_LINEUP:
  504.                     hPos -= 1;
  505.                     break;
  506.  
  507.                 case SB_LINEDOWN:
  508.                     hPos += 1;
  509.                     break;
  510.  
  511.                 case SB_PAGEUP:
  512.                     hPos -= rect.right / tm.tmAveCharWidth;
  513.                     break;
  514.  
  515.                 case SB_PAGEDOWN:
  516.                     hPos += rect.right / tm.tmAveCharWidth;
  517.                     break;
  518.  
  519.                 case SB_THUMBPOSITION:
  520.                     hPos = LOWORD(lParam);
  521.                     break;
  522.  
  523.             }
  524.             hPos = max(0, min(hPos, maxline));
  525.  
  526.             if (hPos != GetScrollPos(hwnd, SB_HORZ)) {
  527.                 SetScrollPos(hwnd, SB_HORZ, hPos, TRUE);
  528.                 InvalidateRect(hwnd, NULL, TRUE);
  529.             }
  530.  
  531.             return 0;
  532.  
  533.         case WM_PAINT:
  534.             if (first) {
  535.                SendMessage(hwnd, WM_BLDTEXT, 0, 0L);
  536.                first = FALSE;
  537.             }
  538.  
  539.             rect.left = (1 * tm.tmAveCharWidth) - (hPos * tm.tmAveCharWidth);
  540.             rect.top  = (1 * tm.tmHeight) - (vPos * tm.tmHeight);
  541.  
  542.             hdc = BeginPaint(hwnd, &ps);
  543.             SelectObject(hdc, GetStockObject(SYSTEM_FIXED_FONT));
  544.             SetTextColor(hdc, GetSysColor(COLOR_WINDOWTEXT));
  545.             SetBkColor(hdc, GetSysColor(COLOR_WINDOW));
  546.  
  547.             /* Must double the scroll range because of possibility of wrap */
  548.             SetScrollRange(hwnd, SB_VERT, 0, numlines*2, FALSE);
  549.             SetScrollPos(hwnd, SB_VERT, vPos, TRUE);
  550.             SetScrollRange(hwnd, SB_HORZ, 0, maxline, FALSE);
  551.             SetScrollPos(hwnd, SB_HORZ, hPos, TRUE);
  552.  
  553.             DrawText(hdc, (LPSTR) buf, -1, &rect, DT_WORDBREAK |
  554.                      DT_EXPANDTABS | DT_NOCLIP | DT_NOPREFIX);
  555.  
  556.             EndPaint(hwnd, &ps);
  557.             return 0;
  558.  
  559.         case WM_BLDTEXT:
  560.             /*
  561.              * if there is a current object, get its description and "draw" it
  562.              */
  563.  
  564.             if (cSel == repo) {
  565.                 strcpy(buf, GetNlsMessage(IRMessageId));
  566.             }
  567.             else {
  568.                 sequence(somModifier) sm;
  569.                 cdesc = Contained_describe(cSel, ev);
  570.                 if (strcmp(cdesc.name, "ModuleDescription") == 0) {
  571.                     sequence(Contained) seq;
  572.                     ModuleDescription *md;
  573.                     seq = Container_contents(cSel, ev, "all", FALSE);
  574.                     md = (ModuleDescription *) cdesc.value._value;
  575.                     wsprintf(buf,
  576.                             GetNlsMessage(ModuleSelectId),
  577.                              (LPSTR) (md->name),
  578.                              seq._length,
  579.                              (LPSTR) (seq._length == 1 ? "" : "s"));
  580.                 }
  581.                 else if (strcmp(cdesc.name, "InterfaceDescription") == 0) {
  582.                     FullInterfaceDescription fifdesc;
  583.                     sequence(RepositoryId) srid;
  584.                     fifdesc = InterfaceDef_describe_interface(cSel, ev);
  585.                     wsprintf(buf, GetNlsMessage(InterfaceInheritId), (LPSTR) fifdesc.name);
  586.                     srid = __get_base_interfaces(cSel, ev);
  587.                     strcpy(tmpbuf, "");
  588.                     if (srid._length) {
  589.                         for (ui = 0; ui < srid._length; ui++) {
  590.                             strcat(tmpbuf, srid._buffer[ui]);
  591.                             if (ui + 1 < srid._length)
  592.                                 strcat(tmpbuf, ", ");
  593.                         }              /* endfor */
  594.                     }
  595.                     else {
  596.                         strcat(tmpbuf, GetNlsMessage(NothingId));
  597.                     }                  /* endif */
  598.                     strcat(tmpbuf, ".\n\n");
  599.                     strcat(buf, tmpbuf);
  600.                     wsprintf(tmpbuf, GetNlsMessage(AttrOperationId),
  601.                              (LPSTR) fifdesc.name,
  602.                              fifdesc.attributes._length,
  603.                          (LPSTR) (fifdesc.attributes._length == 1 ? "" : "s"),
  604.                              fifdesc.operation._length,
  605.                          (LPSTR) (fifdesc.operation._length == 1 ? "" : "s"));
  606.                     strcat(buf, tmpbuf);
  607.                     if (fifdesc.attributes._length) {
  608.                         strcat(buf, GetNlsMessage(AttrIntroducedId));
  609.                         for (ui = 0; ui < fifdesc.attributes._length; ui++) {
  610.                             strcat(buf, fifdesc.attributes._buffer[ui].name);
  611.                             if (ui + 1 < fifdesc.attributes._length)
  612.                                 strcat(buf, ", ");
  613.                         }              /* endfor */
  614.                         strcat(buf, "\n\n");
  615.                     }                  /* endif */
  616.                     if (fifdesc.operation._length) {
  617.                         strcat(buf, GetNlsMessage(OperationsIntroducedId));
  618.                         for (ui = 0; ui < fifdesc.operation._length; ui++) {
  619.                             strcat(buf, fifdesc.operation._buffer[ui].name);
  620.                             if (ui + 1 < fifdesc.operation._length)
  621.                                 strcat(buf, ", ");
  622.                         }              /* endfor */
  623.                         strcat(buf, "\n\n");
  624.                     }                  /* endif */
  625.                 }
  626.                 else if (strcmp(cdesc.name, "OperationDescription") == 0) {
  627.                     OperationDescription *opd = cdesc.value._value;
  628.                     sequence(ParameterDescription) params;
  629.                     sequence(ExceptionDescription) excepts;
  630.  
  631.                     wsprintf(buf, GetNlsMessage(OperationTypecodeId),
  632.                              (LPSTR) opd->name);
  633.                     TypeCode_print(opd->result, ev);
  634.                     strcat(buf, GetNlsMessage(ModeId));
  635.                     strcat(buf, (opd->mode == OperationDef_ONEWAY) ? "ONEWAY" : "NORMAL");
  636.                     params = opd->parameter;
  637.                     if (params._length) {
  638.                         wsprintf(tmpbuf, GetNlsMessage(ParametersId),
  639.                                  (LPSTR) (params._length == 1 ? "" : "s"));
  640.                         strcat(buf, tmpbuf);
  641.                         for (ui = 0; ui < params._length; ui++) {
  642.                             wsprintf(tmpbuf, "[%d] %s (%s):\n  ",
  643.                                      ui + 1,
  644.                                      (LPSTR) params._buffer[ui].name,
  645.                                      (LPSTR) (params._buffer[ui].mode == ParameterDef_IN) ?
  646.                                      "IN" : (params._buffer[ui].mode == ParameterDef_OUT) ?
  647.                                      "OUT" : "INOUT");
  648.                             strcat(buf, tmpbuf);
  649.                             TypeCode_print(params._buffer[ui].type, ev);
  650.                         }              /* endfor */
  651.                     }
  652.                     else {
  653.                         strcat(buf, GetNlsMessage(NoParameterId));
  654.                     }                  /* endif */
  655.                     excepts = opd->exceptions;
  656.                     if (excepts._length) {
  657.                         wsprintf(tmpbuf, GetNlsMessage(ExceptionId),
  658.                                  (LPSTR) (excepts._length == 1 ? "" : "s"));
  659.                         strcat(buf, tmpbuf);
  660.                         for (ui = 0; ui < excepts._length; ui++) {
  661.                             strcat(buf, excepts._buffer[ui].name);
  662.                             strcat(buf, ":\n  ");
  663.                             TypeCode_print(excepts._buffer[ui].type, ev);
  664.                         }              /* endfor */
  665.                     }                  /* endif */
  666.                 }
  667.                 else if (strcmp(cdesc.name, "ParameterDescription") == 0) {
  668.                     ParameterDescription *pd = cdesc.value._value;
  669.                     wsprintf(buf, GetNlsMessage(ParameterOperationId),
  670.                              (LPSTR) pd->name,
  671.                              (LPSTR) pd->defined_in,
  672.                              (LPSTR) (pd->mode == ParameterDef_IN) ?
  673.                              "IN" : (pd->mode == ParameterDef_OUT) ?
  674.                              "OUT" : "INOUT");
  675.                     TypeCode_print(pd->type, ev);
  676.                 }
  677.                 else if (strcmp(cdesc.name, "TypeDescription") == 0) {
  678.                     TypeDescription *td = cdesc.value._value;
  679.                     wsprintf(buf,GetNlsMessage(TypeDefinedId),
  680.                              (LPSTR) td->name,
  681.                              (LPSTR) td->defined_in);
  682.                     TypeCode_print(td->type, ev);
  683.                 }
  684.                 else if (strcmp(cdesc.name, "ExceptionDescription") == 0) {
  685.                     ExceptionDescription *xd = cdesc.value._value;
  686.                     wsprintf(buf,GetNlsMessage(ExceptionDefinedId),
  687.                              (LPSTR) xd->name,
  688.                              (LPSTR) xd->defined_in);
  689.                     TypeCode_print(xd->type, ev);
  690.                 }
  691.                 else if (strcmp(cdesc.name, "AttributeDescription") == 0) {
  692.                     AttributeDescription *ad = cdesc.value._value;
  693.                     wsprintf(buf,GetNlsMessage(AttributeDefinedId),
  694.                              (LPSTR) ad->name,
  695.                              (LPSTR) ad->defined_in,
  696.                              (LPSTR) (ad->mode == AttributeDef_READONLY) ?
  697.                              "READONLY" : "NORMAL");
  698.                     TypeCode_print(ad->type, ev);
  699.                 }
  700.                 else if (strcmp(cdesc.name, "ConstantDescription") == 0) {
  701.                     ConstantDescription *cd = cdesc.value._value;
  702.                     wsprintf(buf,GetNlsMessage(ConstantDefinedId),
  703.                              (LPSTR) cd->name,
  704.                              (LPSTR) cd->defined_in,
  705.                              (LPSTR) cd->value._value);
  706.                     TypeCode_print(cd->type, ev);
  707.                 }
  708.                 else {
  709.                     MessageBox(hwnd, GetNlsMessage(UnknownDescriptionId), szAppDesc,
  710.                                MB_ICONEXCLAMATION | MB_OK);
  711.                     SendMessage(hwnd, WM_CLOSE, 0, 0L);
  712.                 }                      /* endif */
  713.                 sm = __get_somModifiers(cSel, ev);
  714.                 if (sm._length) {
  715.                     strcat(buf, GetNlsMessage(SOMModifiersId));
  716.                     for (ui = 0; ui < sm._length; ui++) {
  717.                         if (sm._buffer[ui].name && sm._buffer[ui].value) {
  718.                             wsprintf(tmpbuf, "  %s = %s\n",
  719.                                    sm._buffer[ui].name, sm._buffer[ui].value);
  720.                             strcat(buf, tmpbuf);
  721.                         }
  722.                         else {
  723.                             strcat(buf, sm._buffer[ui].name ? sm._buffer[ui].name : "\"\"");
  724.                         }              /* endif */
  725.                     }                  /* endfor */
  726.                 }                      /* endif */
  727.             }                          /* endif */
  728.  
  729.             /* Make sure each ',' followed by ' ' */
  730.             expandComma(buf);
  731.  
  732.             /* Count the number of lines and figure the longest line */
  733.             numlines = maxline = cnt = 1;
  734.             for (ui = 0; buf[ui] != 0; ui++) {
  735.                 if (buf[ui] == '\n') {
  736.                     numlines++;
  737.                     maxline = max(cnt, maxline);
  738.                     cnt = 1;
  739.                 }
  740.                 else
  741.                     cnt++;
  742.             }
  743.  
  744.             vPos = hPos = 0;
  745.             InvalidateRect(hwnd, NULL, TRUE);
  746.             return 0;
  747.     }
  748.  
  749.     return DefWindowProc(hwnd, message, wParam, lParam);
  750. }
  751.  
  752.  
  753. static void irdumpHelp(HWND hwnd)
  754. {
  755.     int i;
  756.     static char *helpbuf = NULL;
  757.     char buf[80];
  758.  
  759.     if (helpbuf == NULL) {
  760.        helpbuf = SOMMalloc(1024);
  761.        *helpbuf = 0;
  762.        for (i = HELP01; i < HELP01+HELPCOUNT; i++) {
  763.            LoadString(gHInstance, i, buf, sizeof(buf));
  764.            strcat(helpbuf, buf);
  765.        }
  766.     }
  767.  
  768.     MessageBox(hwnd, helpbuf, szAppDesc, MB_ICONINFORMATION  | MB_OK);
  769. }
  770.  
  771.  
  772. static string getErrorType(irOpenErrorCodes ec)
  773. {
  774.     switch (ec) {
  775.             case Repository_NOACCESS:
  776.              return "NOACCESS";
  777.         case Repository_BADMAGICNUMBER:
  778.             return "BADMAGICNUMBER";
  779.         case Repository_MISSINGVERSIONINFO:
  780.             return "MISSINGVERSIONINFO";
  781.         case Repository_IOERROR:
  782.             return "IOERROR";
  783.         case Repository_VERSIONMISMATCH:
  784.             return "VERSIONMISMATCH";
  785.     }
  786.     return "UNKNOWN";
  787. }
  788.  
  789.  
  790. /* included so that we can dump typecodes using existing routines
  791.    that make use of somPrintf */
  792. static int SOMLINK irOutChar(char c)
  793. {
  794.     int n = strlen(buf);
  795.     if (n < MAXOUT) {
  796.         buf[n] = c;
  797.         buf[n + 1] = (char) 0;
  798.         return 1;
  799.     }
  800.     else
  801.         return 0;
  802. }
  803.  
  804.  
  805.  
  806. /* Added to maximize DrawText line wrapping */
  807. static void expandComma(char *pbuf)
  808. {
  809.     char tbuf[MAXOUT];
  810.     char *p1, *p2;
  811.  
  812.     p1 = pbuf;
  813.     p2 = tbuf;
  814.  
  815.     do {
  816.        *p2 = *p1;
  817.        if (*p1 == ',' && *(p1+1) != ' ') {
  818.           p2++;
  819.           *p2 = ' ';
  820.        }
  821.        p1++;
  822.        p2++;
  823.  
  824.     }
  825.     while (*(p1-1) != 0);
  826.  
  827.     strcpy(pbuf, tbuf);
  828. }
  829.