home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 5 Edit / 05-Edit.zip / alphal.zip / ALPHAE.C < prev    next >
C/C++ Source or Header  |  1997-07-15  |  10KB  |  179 lines

  1. /*************** AlphaE.C - Exit procedure for Alpha  *********************/
  2. /*                                                                        */                
  3. /* PROGRAM NAME: ALPHA.EXE                                                */
  4. /* -------------                                                          */                
  5. /*  Presentation Manager  C Program                                       */
  6. /*                                                                        */                
  7. /* REVISION LEVEL: 3.1                                                    */
  8. /* ---------------                                                        */
  9. /*                                                                        */
  10. /* Lionel de Lambert - July 1994 - IBM - Hursley                          */
  11. /*                                                                        */
  12. /* WHAT THIS PROGRAM DOES:                                                */
  13. /* -----------------------                                                */     
  14. /*    Procedures -                                                        */
  15. /*                 Alpha_parse_exit                                       */
  16. /*                                                                        */
  17. /*    This procedure is called before Alpha writes the line of text.      */
  18. /*    It is called from the WM_PAINT section of the child window.         */
  19. /*    return code - 0 - Execute standard Alpha parsing etc.               */
  20. /*                  4 - Don't excute Alpha parsing - this routine has     */
  21. /*                      output the text.                                  */
  22. /*                                                                        */
  23. /* WHAT YOU NEED TO COMPILE THIS PROGRAM:                                 */
  24. /* --------------------------------------                                 */
  25. /*                                                                        */
  26. /*  REQUIRED FILES:                                                       */
  27. /*  ---------------                                                       */     
  28. /*                                                                        */     
  29. /*    ALPHAE.C      - Source code                                         */
  30. /*    ALPHAE.DEF    - Module definition file                              */
  31. /*    ALPHA.H       - Application header file                             */
  32. /*                                                                        */
  33. /*    OS2.H          - Presentation Manager include file                  */     
  34. /*    STRING.H       - String handling function declarations              */     
  35. /*                                                                        */     
  36. /*  REQUIRED LIBRARIES:                                                   */                                                  
  37. /*  -------------------                                                   */     
  38. /*                                                                        */     
  39. /*    OS2386.LIB     - Presentation Manager/OS2 library                   */
  40. /*                                                                        */
  41. /* Use C/SET2 compiler, e.g.                                              */
  42. /* icc /Ge- /Fealphae.dll alphae.c alphae.def                             */
  43. /*                                                                        */
  44. /*  REQUIRED PROGRAMS:                                                    */     
  45. /*  ------------------                                                    */     
  46. /*    IBM C Compiler - icc                                                */                                                                          
  47. /*    IBM Linker                                                          */
  48. /*                                                                        */     
  49. /**************************************************************************/
  50.      
  51. #define INCL_BASE
  52. #define INCL_WIN
  53. #define INCL_GPI
  54. #define INCL_WINWINDOWMGR     
  55.  
  56. #include <os2.h>                   /* PM header file                      */
  57. #include <stdio.h>                 /* standard io                         */
  58. #include <CTYPE.H>
  59. #include <MALLOC.H>
  60. #include <STDLIB.H>
  61. #include <string.h>
  62.  
  63. /* External - global varialbles                                           */
  64.  
  65. #include "ALPHA1.h"                 /* Structure definitions              */
  66.  
  67.  
  68. #pragma subtitle("Alpha_parse_exit")
  69. #pragma page(1)
  70.  
  71. APIRET Alpha_parse_exit( HAB hab, FATTRS fat, FONTMETRICS fm,
  72.                        CHILD *pChild, char *ptr,
  73.                       int l, char *ptr0,
  74.                       int l0, int Cmt_s, int Cmt_e,
  75.                       int Str_s, int Str_e, int recno,
  76.                       POINTL pAPTL[Max_record_size] )
  77. {
  78. /* hab       - PM anchor block handle                                     */
  79. /* fat       - Attributes of font                                         */
  80. /* fm        - Currently selected font metrics                            */
  81. /* pChild    - pointer to child structure                                 */
  82. /* ptr       - pointer to text string including offset                    */
  83. /* l         - length of record less offset                               */
  84. /* ptr0      - pointer to complete record                                 */
  85. /* l0        - length of complete record                                  */
  86. /* Cmt_s     - start position of comment in record or 0                   */
  87. /* Cmt_e     - end position of comment in record or 0 - continued         */
  88. /* Str_s     - Start position of string in record or 0                    */
  89. /* Str_e     - End position of string in record or 0                      */
  90. /* recno     - record number                                              */
  91. /* pAPTL     - pointer to array of character positions                    */
  92. /*                                                                        */
  93. /* return code - 0 - Execute standard Alpha parsing                       */
  94. /*               4 - Don't excute Alpha parsing - this routine has output */
  95. /*                   the text.                                            */
  96.  
  97.  
  98.  int e, i, m, p, q, s, w;
  99.  int cmt_start;
  100.  POINTL CurPos;                    /* Current end of line position        */
  101.  USHORT Left, Right = FALSE;       /* State of end of keywords            */
  102.  char Upp_rec[Max_record_size];    /* upper case copy of record           */
  103.  RECTL rc;
  104.  COLOR Text_clr = CLR_DARKBLUE;
  105.  COLOR Back_clr = CLR_WHITE;
  106.  COLOR Select_clr = CLR_RED;
  107.  COLOR Cmmt_Back_clr = CLR_GREEN;
  108.  COLOR Cmmt_clr = CLR_BLACK;
  109.  int Chr_height = 20;
  110.  HPS   Chps;                       /* Presentation Space handle           */
  111.  ERRORID  erridErrorCode;
  112.  
  113.  
  114.  
  115.  
  116.  Chps = WinGetPS(pChild -> hwnd);
  117.  
  118.  GpiCreateLogFont( Chps, NULL, 1L, &fat ); /* create font 1               */
  119.  GpiSetCharSet( Chps , 1L );      /* select font                          */
  120.  
  121.  Chr_height =   fm.lMaxBaselineExt; /* chr. height                        */
  122.  
  123.  WinQueryWindowRect( pChild -> hwnd, &rc ); /* reset window  rectangle    */
  124.  
  125.  
  126.  GpiSetBackMix( Chps, BM_OVERPAINT ); /*                                  */
  127.  GpiSetMix( Chps, FM_OVERPAINT );   /*                                    */
  128.  GpiSetColor( Chps, Text_clr );     /* colour of the text part            */
  129.  GpiSetBackColor( Chps, Back_clr ); /* colour of the text background      */
  130.  
  131.  
  132. /*                 |----select------|                                     */
  133. /*     -------------------------------------------------------            */
  134. /*     |  text               |           comment             |            */
  135. /*     -------------------------------------------------------            */
  136. /*     a           b         c      d                        e            */
  137. /*                                                                        */
  138.  
  139.  cmt_start = Cmt_s;
  140.  if (cmt_start >= 1)               /* =0 if no comment part               */
  141.   if (cmt_start>pChild -> Offset)  /*                                     */
  142.    {                               /* reset comment start from offset     */
  143.     cmt_start = cmt_start - pChild -> Offset;  /*                         */
  144.    }                               /*                                     */
  145.   else cmt_start = 1;              /* offset beyond comment start         */
  146.  
  147.  
  148.  if (cmt_start>0)
  149.     {
  150.       GpiCharStringAt( Chps, &pAPTL[0], cmt_start, ptr ); /* write text   */
  151.  
  152.                                    /* write out the comment part          */
  153.                                    /* colour of the comment background    */
  154.       GpiSetBackColor( Chps, Cmmt_Back_clr ); /*                          */
  155.       GpiSetColor( Chps, Cmmt_clr ); /* colour of the comment text part   */
  156.       GpiCharStringAt( Chps, &pAPTL[cmt_start-1],l-cmt_start+1,
  157.                               &ptr[cmt_start-1] );
  158.     }
  159.  else
  160.     {
  161.      GpiCharStringAt( Chps, &pAPTL[0], l, ptr ); /* write text            */
  162.     };
  163.                                    /* Need to fill rest of line           */
  164.  GpiQueryCurrentPosition( Chps, &CurPos );  /* get end of line            */
  165.  WinQueryWindowRect( pChild -> hwnd, &rc ); /* get window  rectangle      */
  166.  rc.xLeft = CurPos.x;
  167.  rc.yBottom = CurPos.y - fm.lMaxDescender;
  168.  rc.yTop = CurPos.y + Chr_height - fm.lMaxDescender;
  169.  WinFillRect( Chps, &rc, CLR_BACKGROUND ); /* fill rectangle              */
  170.  
  171.  GpiSetCharSet(Chps, 0L);          /* release the font before deleting    */
  172.  GpiDeleteSetId(Chps, 1L);         /* delete the logical font             */  
  173.  
  174.  WinReleasePS(Chps);
  175.  
  176.  return (4);                       /* Don't call Alpha parsing            */
  177. };                                 /* end of Alpha_parse_exit             */
  178.  
  179.