home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / sd386v50.zip / sd386src.zip / SETCOLOR.C < prev    next >
Text File  |  1995-08-16  |  46KB  |  788 lines

  1. /*****************************************************************************/
  2. /* File:                                             IBM INTERNAL USE ONLY   */
  3. /*   setcolor.c                                                              */
  4. /*                                                                           */
  5. /* Description:                                                              */
  6. /*   allow users to modify color settings interactively, and optionally      */
  7. /*   save the new settings to user profile, SD386.PRO.                       */
  8. /*                                                                           */
  9. /* History:                                                                  */
  10. /*                                                                           */
  11. /*   02/08/91 Creation of 32-bit SD386, from 16-bit version.                 */
  12. /*                                                                           */
  13. /*...Release 1.00                                                            */
  14. /*...                                                                        */
  15. /*... 02/08/91  100   made changes for 32-bit compilation.                   */
  16. /*...                                                                        */
  17. /*...Release 1.00 (Pre-release 107 11/13/91)                                 */
  18. /*...                                                                        */
  19. /*... 11/13/91  400   Srinivas  Vertical Register Display.                   */
  20. /*...                                                                        */
  21. /*...Release 1.00 (Pre-release 108 12/05/91)                                 */
  22. /*...                                                                        */
  23. /*... 02/12/92  521   Srinivas  Port to C-Set/2.                             */
  24. /*...                                                                        */
  25. /*...Release 1.01 (04/03/92)                                                 */
  26. /*...                                                                        */
  27. /*... 05/08/92  701   Srinivas  Cua Interface.                               */
  28. /*...                                                                        */
  29. /*...Release 1.05 (05/27/93)                                                 */
  30. /*...                                                                        */
  31. /*... 05/27/93  825   Joe       Reading SD386.PRO after a save causes trap.  */
  32. /*...                                                                        */
  33. /**Includes*******************************************************************/
  34.                                         /*                                   */
  35. #define INCL_16                         /* for 16-bit API                 101*/
  36. #define INCL_SUB                        /* kbd, vio, mouse routines       101*/
  37. #include "all.h"                        /* SD386 include files               */
  38. #define __MIG_LIB__                                                     /*521*/
  39. #include "io.h"                         /* for routines open, chsize, close  */
  40. #include "fcntl.h"                      /* for O_WRONLY, O_TEXT              */
  41. #include "diacolor.h"                   /* colors dialog data             701*/
  42.  
  43. /**Macros*********************************************************************/
  44.                                         /*                                   */
  45. #define BGColor(c) BGColors[(c)>>(4)]   /* c -> background color name        */
  46. #define FGColor(c) FGColors[(c)&(0x0F)] /* c -> foreground color name        */
  47.                                         /*                                   */
  48. /**Variables defined**********************************************************/
  49.  
  50. #define VATTLENGTH   23                 /* attribute field length            */
  51. #define BGLENGTH     11                 /* background color field length     */
  52. #define FGLENGTH     14                 /* foreground color field length     */
  53. #define DEMOLENGTH    7                 /* color demo field length           */
  54. #define MAXWINDOWSIZE HEADERSIZE+MAXVIDEOATR*(VATTLENGTH+\
  55.          BGLENGTH+FGLENGTH+DEMOLENGTH)+1 /* window text buffer size          */
  56. #define FIELDSLENGTH  BGLENGTH+FGLENGTH+DEMOLENGTH+2                    /*701*/
  57. #define MAXITEM       MAXVIDEOATR       /* max number of lines in window     */
  58. #define FILENOTFOUND  2                 /* file-not-found return code        */
  59.  
  60. char *vaTypes[MAXVIDEOATR+1] =          /* video attribute types             */
  61. {                                       /*                                   */
  62. "",                                     /* null       0                      */
  63. "ProgramLine",                          /* vaProgram  1                      */
  64. "LinesOkayForBrkPoint",                 /* vaBptOk    2                      */
  65. "LinesWithBrkPoint",                    /* vaBptOn    3                      */
  66. "ExecLineWithNoBrkPt",                  /* vaXline    4                      */
  67. "ExecLineWithBrkPt",                    /* vaXlineOn  5                      */
  68. "MenuBar",                              /* vaMenuBar  6                      */
  69. "MenuBarCursor",                        /* vaMenuCsr  7                      */
  70. "StorageExpression",                    /* vaStgExp   8                      */
  71. "StorageValues",                        /* vaStgVal   9                      */
  72. "RegisterWindow",                       /* vaRegWind 10                      */
  73. "MenuPrompts",                          /* vaPrompt  11                      */
  74. "ErrorMessages",                        /* vaError   12                      */
  75. "FileAndPosition",                      /* vaInfo    13                      */
  76. "HelpPanels",                           /* vaHelp    14                      */
  77. "StorageExprsnPrompts",                 /* vaStgPro  15                      */
  78. "ClearScreenOnExit",                    /* vaClear   16                      */
  79. "DataWindowStatusLine",                 /* vaStgStat 17                      */
  80. "AsmWindowSourceLines",                 /* vaMxdSrc  18                      */
  81. "MenuBarItemSelected",                  /* vaMenuSel 19                      */
  82. "SelectionWindow",                      /* vaCallStk 20                      */
  83. "SelectWinItemSelected"                 /* vaCallSel 21                      */
  84. };                                      /*                                   */
  85. char *BGColors[MAXBGCOLOR] =            /* background color names            */
  86. {                                       /*                                   */
  87. "BG_BLACK",                             /* 0x00  black                       */
  88. "BG_BLUE",                              /* 0x10  blue                        */
  89. "BG_GREEN",                             /* 0x20  green                       */
  90. "BG_CYAN",                              /* 0x30  cyan                        */
  91. "BG_RED",                               /* 0x40  red                         */
  92. "BG_MAGENTA",                           /* 0x50  magenta                     */
  93. "BG_BROWN",                             /* 0x60  brown                       */
  94. "BG_WHITE"                              /* 0x70  white                       */
  95. };                                      /*                                   */
  96. char *FGColors[MAXFGCOLOR] =            /* foreground color names            */
  97. {                                       /*                                   */
  98. "FG_BLACK",                             /* 0x00  black                       */
  99. "FG_BLUE",                              /* 0x01  blue                        */
  100. "FG_GREEN",                             /* 0x02  green                       */
  101. "FG_CYAN",                              /* 0x03  cyan                        */
  102. "FG_RED",                               /* 0x04  red                         */
  103. "FG_MAGENTA",                           /* 0x05  magenta                     */
  104. "FG_BROWN",                             /* 0x06  brown                       */
  105. "FG_WHITE",                             /* 0x07  white                       */
  106. "FG_GREY",                              /* 0x08  light black   = grey        */
  107. "FG_LT_BLUE",                           /* 0x09  light blue                  */
  108. "FG_LT_GREEN",                          /* 0x0A  light green                 */
  109. "FG_LT_CYAN",                           /* 0x0B  light cyan                  */
  110. "FG_LT_RED",                            /* 0x0C  light red                   */
  111. "FG_LT_MAGENTA",                        /* 0x0D  light magenta               */
  112. "FG_YELLOW",                            /* 0x0E  light brown   = yellow      */
  113. "FG_LT_WHITE"                           /* 0x0F  light white                 */
  114. };                                      /*                                   */
  115.                                         /*                                   */
  116. /**Externs********************************************************************/
  117.                                         /*                                   */
  118. extern uchar   ExceptionMap[MAXEXCEPTIONS];
  119. extern uchar   LocalExcepMap[MAXEXCEPTIONS];
  120. extern uchar   VideoAtr;                /* logical screen attribute          */
  121. extern uchar  *VideoMap;                /* logical->physical attribute map   */
  122. extern uchar   ScrollShade1[];          /* scroll bar attributes          701*/
  123. extern uchar   ScrollShade2[];          /* scroll bar attributes          701*/
  124. extern uchar   hilite[];                /* high light field attributes    701*/
  125. extern uchar   normal[];                /* normal field attributes        701*/
  126. extern uchar   ClearField[];            /* clear field attributes         701*/
  127. extern uchar   InScrollMode;            /* flag to tell we are in scrollmode */
  128.  
  129. extern CmdParms cmd;
  130. extern VIOCURSORINFO  NormalCursor;     /* make underscore flashing cursor   */
  131.  
  132. static uchar  DemoColor[] = { RepCnt(DEMOLENGTH+1), Attrib(0), 0 };
  133.                                         /* color for demo Sample field       */
  134. static uchar LocalVaMap[MAXVIDEOATR+1]; /* local copy of va map              */
  135. static uchar DefVaMap[MAXVIDEOATR+1];   /* constant copy of default va map   */
  136. static enum  { AttrField,               /* user currently at attribute field */
  137.                BGField,                 /* user currently at bgcolor field   */
  138.                FGField                  /* user currently at fgcolor field   */
  139.              } fld;                     /* user current field position       */
  140.  
  141. /**Begin Code*****************************************************************/
  142.  
  143. /*****************************************************************************/
  144. /* SaveColors()                                                              */
  145. /*                                                                           */
  146. /* Description:                                                              */
  147. /*                                                                           */
  148. /*   Save the attribute names and their associated color names to            */
  149. /*   profile SD386.PRO.                                                      */
  150. /*                                                                           */
  151. /* Parameters:                                                               */
  152. /*                                                                           */
  153. /*   fn        input - filename to save color values                         */
  154. /*                                                                           */
  155. /* Return:                                                                   */
  156. /*                                                                           */
  157. /*   0         Save sucessful                                                */
  158. /*   1         Save unsucessful                                              */
  159. /*                                                                           */
  160. /*****************************************************************************/
  161.                                         /*                                   */
  162.  uint                                   /*                                   */
  163. SaveColors( uchar *fn )                 /*                                   */
  164. {                                       /*                                   */
  165.  FILE   *fp;                            /* file ptr to SD386.PRO             */
  166.  char    _word[90];                     /* buffer to scan for Start_Of_Colors*/
  167.  uchar   line[VATTLENGTH+BGLENGTH];     /* to contain attr and color names   */
  168.  uchar  *pText;                         /* pointer to a text string          */
  169.  fpos_t  pos;                           /* file position                     */
  170.  int     fh;                            /* file handle for SD386.PRO         */
  171.  uchar  *pAttByte = LocalVaMap + 1;     /* video attribute byte index        */
  172.  uint    i;                             /* attribute item index              */
  173.                                         /*                                   */
  174.  if( (fp = fopen(fn, "r+")) == NULL )   /* if can not open SD386.PRO,        */
  175.   return( FILENOTFOUND );               /* return bad code                   */
  176.                                         /*                                   */
  177.  while(fscanf(fp, "%s", _word) != EOF && /* scan while not end of file and   */
  178.        stricmp(_word, "Start_Of_Colors") /* not found "Start_Of_Colors"      */
  179.       ){;}                              /*                                   */
  180.  if( feof( fp ) )                       /* if "Start_Of_Colors" not exist,   */
  181.   fprintf( fp, "\n\n      Start_Of_Colors");/* put it into profile           */
  182.  else                                   /* else found "Start_Of_Colors",     */
  183.  {                                      /*                                   */
  184.   if( fgetpos( fp, &pos) ||             /* initialize file header position   */
  185.       fsetpos( fp, &pos)                /* for future writes to file         */
  186.     )                                   /*                                   */
  187.    return( 1 );                         /* if bad file access, return error  */
  188.  }                                      /*                                   */
  189.                                         /*                                   */
  190.  
  191.  
  192.  /****************************************************************************/
  193.  /* At this point, fscanf has left us pointing like so:                   825*/
  194.  /*                                                                       825*/
  195.  /*   Start_Of_Colors0D0A                                                 825*/
  196.  /*                    |                                                  825*/
  197.  /*  fscanf------------                                                   825*/
  198.  /*                                                                       825*/
  199.  /* - We need to bump the file position past the 0A.                      825*/
  200.  /*                                                                       825*/
  201.  /****************************************************************************/
  202.  {                                                                      /*825*/
  203.   pos.__fpos_elem[0] += 1;                                              /*825*/
  204.   fsetpos( fp, &pos);                                                   /*825*/
  205.  }                                                                      /*825*/
  206.                                                                         /*825*/
  207.  fprintf(fp, "/*\n         ATTRIBUTE TYPE     BACKGROUND  FOREGROUND");/*  */
  208.  fprintf(fp,   "\n      --------------------  ---------- -------------\n*/");
  209.                                         /* write text after "Start_Of_Colors"*/
  210.  /****************************************************************************/
  211.  /* From the first attribute item until last, write the attribute name and   */
  212.  /* its background and foreground colors out to file SD386.PRO.              */
  213.  /****************************************************************************/
  214.  line[VATTLENGTH+BGLENGTH-1] = 00;      /* line terminator                   */
  215.  for( i = 1;                            /* start with first attribute item   */
  216.       i <= MAXVIDEOATR;                 /* until the last attribute item     */
  217.       i++, pAttByte++                   /* increment attr and color indices  */
  218.     )                                   /* loop for all attribute items      */
  219.  {                                      /*                                   */
  220.   memset(line, ' ', VATTLENGTH+BGLENGTH-1);/* pad buffer with all blanks     */
  221.                                         /*                                   */
  222.   pText = vaTypes[i];                   /* get attribute name                */
  223.   strncpy(line, pText, strlen(pText));  /* copy attribute name to buffer     */
  224.                                         /*                                   */
  225.   pText = BGColor(*pAttByte);           /* get background color name         */
  226.   strncpy(line + VATTLENGTH,            /* copy background color name        */
  227.           pText, strlen(pText));        /* to buffer                         */
  228.                                         /*                                   */
  229.   fprintf(fp, "\n      %s %s",          /* write buffer and foreground color */
  230.           line, FGColor(*pAttByte));    /* name out to file                  */
  231.  }                                      /*                                   */
  232.  /****************************************************************************/
  233.  /* After we are finished writing to the file, we now want to be certain to  */
  234.  /* erase all junk text after our writing to the file.                       */
  235.  /****************************************************************************/
  236.  if( fgetpos( fp, &pos)  ||             /* get last position after our write */
  237.      fclose( fp ) == EOF ||             /* close SD386.PRO                   */
  238.     (fh = open(fn, O_WRONLY | O_TEXT))  /* open SD386.PRO to adjust file size*/
  239.         == EOF           ||             /*                                   */
  240.      chsize(fh, pos.__fpos_elem[0])  || /* truncate junk after last write 521*/
  241.      close( fh )                        /* close SD386.PRO                   */
  242.    )                                    /*                                   */
  243.   return( 1 );                          /* if bad file access, return error  */
  244.  /****************************************************************************/
  245.  /* copy the global exceptions map to local exception map array and call  521*/
  246.  /* save exception to write the exception map to profile.                 521*/
  247.  /****************************************************************************/
  248.  memcpy(LocalExcepMap, ExceptionMap, MAXEXCEPTIONS);                    /*521*/
  249.  SaveExceptions( fn ) ;                                                 /*521*/
  250.  return( 0 );                           /* else, return okay                 */
  251. }                                       /* end SaveColors                    */
  252.  
  253. /*****************************************************************************/
  254. /* Setcolors()                                                            701*/
  255. /*                                                                           */
  256. /* Description:                                                              */
  257. /*                                                                           */
  258. /*     Calls functions to display, process key & mouse events & remove the   */
  259. /*  colors dialog.                                                           */
  260. /*                                                                           */
  261. /* Parameters:                                                               */
  262. /*                                                                           */
  263. /* Return:                                                                   */
  264. /*   none                                                                    */
  265. /*****************************************************************************/
  266. void SetColors()
  267. {
  268.   /***************************************************************************/
  269.   /*  - Get the Screen write access.                                         */
  270.   /*  - Display the Colors Dialog.                                           */
  271.   /*  - Process the Events in the Colors Dialog.                             */
  272.   /*  - Remove the Colors Dialog.                                            */
  273.   /*  - Restore the Screen write access.                                     */
  274.   /***************************************************************************/
  275.   GetScrAccess();
  276.   DisplayDialog( &Dia_Color, TRUE );
  277.   ProcessDialog( &Dia_Color, &Dia_Color_Choices, TRUE, NULL );
  278.   RemoveDialog( &Dia_Color );
  279.   SetScrAccess();
  280. }
  281.  
  282. /*****************************************************************************/
  283. /* DisplayColorChoice()                                                      */
  284. /*                                                                           */
  285. /* Description:                                                              */
  286. /*                                                                           */
  287. /*   Displays the color names and the sample demo color in the dialog win.   */
  288. /*                                                                           */
  289. /* Parameters:                                                               */
  290. /*                                                                           */
  291. /*   shell   ->  pointer to a dialog shell structure.                        */
  292. /*   ptr     ->  pointer to a dialog choice structure.                       */
  293. /*                                                                           */
  294. /* Return:                                                                   */
  295. /*   none                                                                    */
  296. /*****************************************************************************/
  297. void  DisplayColorChoice( DIALOGSHELL *shell, DIALOGCHOICE *ptr )
  298. {
  299.   uint   i;
  300.   uint   StrLength;                     /*                                   */
  301.   uchar  StartIndex;                    /*                                   */
  302.   uchar *GlobalVaMap = VideoMap;        /* global va map                     */
  303.   uchar *pAttByte;                      /* video attribute type index        */
  304.  
  305.   /***************************************************************************/
  306.   /* init the variables required.                                            */
  307.   /***************************************************************************/
  308.   pAttByte = LocalVaMap + 1;
  309.   StartIndex = 1;
  310.  
  311.   /***************************************************************************/
  312.   /* Advance the startindex and attribute ptrs depending on the skip rows.   */
  313.   /***************************************************************************/
  314.   for( i = 0; i < ptr->SkipRows; i++ )
  315.    {
  316.     pAttByte++;
  317.     StartIndex++;
  318.    }
  319.  
  320.   /***************************************************************************/
  321.   /* Display the rows that can fit in the window.                            */
  322.   /***************************************************************************/
  323.   for( i = 0; i < ptr->MaxRows; i++, StartIndex++, pAttByte++ )
  324.    {
  325.     ClearField[1] = 1;
  326.     putrc( shell->row + i + shell->SkipLines, shell->col + 1, ClearField );
  327.     putrc( shell->row + i + shell->SkipLines, shell->col + 2, vaTypes[StartIndex] );
  328.     StrLength = strlen( vaTypes[StartIndex] );
  329.     ClearField[1] = shell->width - 6 - StrLength;
  330.     putrc( shell->row + i + shell->SkipLines, shell->col + 2 + StrLength, ClearField );
  331.     putrc( shell->row + i + shell->SkipLines, shell->col + 2 + VATTLENGTH,
  332.            BGColor(*pAttByte));
  333.     putrc( shell->row + i + shell->SkipLines, shell->col + 2 + VATTLENGTH + BGLENGTH,
  334.            FGColor(*pAttByte) );
  335.     /*************************************************************************/
  336.     /*  - Set up the demo sample color field.                                */
  337.     /*  - Get the sample color from the local map.                           */
  338.     /*  - Put the demo sample color field.                                   */
  339.     /*  - Restore to orginal window color map.                               */
  340.     /*************************************************************************/
  341.     DemoColor[2] = Attrib(StartIndex);
  342.     putrc( shell->row + i + shell->SkipLines,
  343.            shell->col + 2 + VATTLENGTH + BGLENGTH + FGLENGTH, "Sample" );
  344.     VideoMap = LocalVaMap;
  345.     putrc( shell->row + i + shell->SkipLines,
  346.            shell->col + 2 + VATTLENGTH + BGLENGTH + FGLENGTH - 1, DemoColor );
  347.     VideoMap = GlobalVaMap;
  348.   }
  349. }
  350.  
  351. /*****************************************************************************/
  352. /* ReDisplaySingleColor()                                                 701*/
  353. /*                                                                           */
  354. /* Description:                                                              */
  355. /*                                                                           */
  356. /*   Re Display a single row of color names and attributes.                  */
  357. /*                                                                           */
  358. /* Parameters:                                                               */
  359. /*                                                                           */
  360. /*   ScrRow   ->  Where to refresh the color names row position              */
  361. /*   ScrCol   ->  Where to refresh the color names col position              */
  362. /*   SelIndex ->  Index into various color selection array.                  */
  363. /*   pattbyte ->  pointer to attributes in the map.                          */
  364. /*                                                                           */
  365. /* Return:                                                                   */
  366. /*   none                                                                    */
  367. /*****************************************************************************/
  368.  void
  369. ReDisplaySingleColor (uint ScrRow,uint ScrCol,uint SelIndex,uchar *pAttByte)
  370. {
  371.   uchar *GlobalVaMap = VideoMap;
  372.  
  373.   ClearField[1] = BGLENGTH+FGLENGTH;
  374.   putrc(ScrRow,ScrCol+VATTLENGTH,ClearField);
  375.   putrc(ScrRow,ScrCol+VATTLENGTH,BGColor(*pAttByte));
  376.   putrc(ScrRow,ScrCol+VATTLENGTH+BGLENGTH,FGColor(*pAttByte));
  377.   /***************************************************************************/
  378.   /*  - Set up the demo sample color field.                                  */
  379.   /*  - Get the sample color from the local map.                             */
  380.   /*  - Put the demo sample color field.                                     */
  381.   /*  - Restore to orginal window color map.                                 */
  382.   /***************************************************************************/
  383.   DemoColor[2] = Attrib(SelIndex);
  384.   putrc(ScrRow,ScrCol+VATTLENGTH+BGLENGTH+FGLENGTH,"Sample");
  385.   VideoMap = LocalVaMap;
  386.   putrc(ScrRow,ScrCol+VATTLENGTH+BGLENGTH+FGLENGTH-1,DemoColor);
  387.   VideoMap = GlobalVaMap;
  388. }
  389.  
  390. /*****************************************************************************/
  391. /* SetDefaultColorMap()                                                   701*/
  392. /*                                                                           */
  393. /* Description:                                                              */
  394. /*                                                                           */
  395. /*   Copy Videocolors map to a default map used after wards.                 */
  396. /*                                                                           */
  397. /* Parameters:                                                               */
  398. /*   none                                                                    */
  399. /*                                                                           */
  400. /* Return:                                                                   */
  401. /*   none                                                                    */
  402. /*****************************************************************************/
  403. void SetDefaultColorMap()
  404. {
  405.   memcpy(DefVaMap, VideoMap, MAXVIDEOATR+1);
  406. }
  407.  
  408. /*****************************************************************************/
  409. /*                                                                           */
  410. /* ColorDialogFunction()                                                     */
  411. /*                                                                           */
  412. /* Description:                                                              */
  413. /*                                                                           */
  414. /* This is the function called by ProcessDialog (in pulldown.c) whenever an  */
  415. /* event occurs in the dialog. This fuction handles the events in a way      */
  416. /* specific to this dialog.                                                  */
  417. /*                                                                           */
  418. /* Parameters:                                                               */
  419. /*                                                                           */
  420. /*   shell         input  - Pointer to DIALOGSHELL structure.                */
  421. /*   ptr           input  - Pointer to DIALOGCHOICE structure.               */
  422. /*   nEvent        input  - Pointer to EVENT structure.                      */
  423. /*                                                                           */
  424. /* Return:                                                                   */
  425. /*        = 0     - The caller has to continue processing the dialog.        */
  426. /*       != 0     - The caller can terminate processing the dialog.          */
  427. /*****************************************************************************/
  428. uint  ColorDialogFunction( DIALOGSHELL *shell, DIALOGCHOICE *ptr,
  429.                            EVENT *nEvent, void *ParamBlock )
  430. {
  431.   uint   fldcol;
  432.   uchar  *pAttByte;                     /* Pointer to color map.             */
  433.   int    SelectIndex;                   /* Index into color map array.       */
  434.  
  435.   SelectIndex = shell->CurrentField + ptr->SkipRows;
  436.   pAttByte = LocalVaMap + SelectIndex;
  437.   for( ;; )
  438.   {
  439.     switch( nEvent->Value )
  440.     {
  441.       case INIT_DIALOG:
  442.       {
  443.         /*********************************************************************/
  444.         /* This message is sent before displaying elements in display area.  */
  445.         /* It is to initialise the locals in the dialog function.            */
  446.         /*  - Make a copy of the global color map.                           */
  447.         /*  - Set the field cursor and variables to the first field.         */
  448.         /*  - Set the length of the field highlite bar in normal and hilite  */
  449.         /*    arrays (used in the call to putrc).                            */
  450.         /*  - Return zero to denote continue dialog processing.              */
  451.         /*********************************************************************/
  452.         memcpy( LocalVaMap, VideoMap, MAXVIDEOATR + 1 );
  453.         fldcol = shell->col + 2;
  454.         VioSetCurPos( (short)(shell->row + shell->SkipLines + shell->CurrentField - 1),
  455.                       (short)fldcol, 0 );
  456.         fld = AttrField;
  457.  
  458.         hilite[1] = normal[1] = (UCHAR)shell->width - SCROLLBARCOLOFFSET -
  459.                                          (FIELDSLENGTH) - 2;
  460.         return( 0 );
  461.       }
  462.  
  463.       case ENTER:
  464.       {
  465.         /*********************************************************************/
  466.         /* This message is sent if the user clicks on the ENTER button or    */
  467.         /* presses the ENTER key.                                            */
  468.         /*  - Copy the local color map to the global color map.              */
  469.         /*  - Return non zero value to denote the end of dialog processing.  */
  470.         /*********************************************************************/
  471.         ptr->SkipRows = 0;
  472.         memcpy( VideoMap, LocalVaMap, MAXVIDEOATR + 1 );
  473.         return( ENTER );
  474.       }
  475.  
  476.       case F1:
  477.       {
  478.         uchar  *HelpMsg;
  479.  
  480.         HelpMsg = GetHelpMsg( HELP_DLG_COLORS, NULL,0 );
  481.         CuaShowHelpBox( HelpMsg );
  482.         return( 0 );
  483.       }
  484.  
  485.       case ESC:
  486.       case F10:
  487.       {
  488.         /*********************************************************************/
  489.         /* This message is sent if the user clicks on the CANCEL button or   */
  490.         /* presses the ESC/F10 keys.                                         */
  491.         /*  - Return non zero value to denote the end of dialog processing.  */
  492.         /*********************************************************************/
  493.         ptr->SkipRows = 0;
  494.         return( nEvent->Value );
  495.       }
  496.  
  497.       case MOUSEPICK:
  498.       {
  499.         /*********************************************************************/
  500.         /* This message is sent if the clicks in the dialog display area.    */
  501.         /*  - Determine on which field the user clicked.                     */
  502.         /*  - Set the cursor on that field.                                  */
  503.         /*  - If the field turns out to be either Background or Foreground   */
  504.         /*    color fields,                                                  */
  505.         /*     - Set the event value as SPACEBAR (simulate) and stay in the  */
  506.         /*       outer for loop to process SPACEBAR.                         */
  507.         /*    Else                                                           */
  508.         /*     - Return zero to denote continue dialog processing.           */
  509.         /*********************************************************************/
  510.         if( ((uint)nEvent->Col >= (shell->col+2 + VATTLENGTH)) &&
  511.             ((uint)nEvent->Col < (shell->col+2 + VATTLENGTH + BGLENGTH)))
  512.         {
  513.            fldcol = shell->col+ 2 + VATTLENGTH;
  514.            fld = BGField;
  515.         }
  516.         else
  517.         {
  518.           if( ((uint)nEvent->Col >= (shell->col+ 2 + VATTLENGTH + BGLENGTH)) &&
  519.               ((uint)nEvent->Col < (shell->col+ 2 + VATTLENGTH + BGLENGTH +
  520.                                     FGLENGTH)))
  521.           {
  522.             fldcol = shell->col+2 + VATTLENGTH + BGLENGTH;
  523.             fld = FGField;
  524.           }
  525.           else
  526.           {
  527.             fldcol = shell->col+2;
  528.             fld = AttrField;
  529.           }
  530.         }
  531.  
  532.         VioSetCurPos( (short)(shell->row + shell->SkipLines +
  533.                       shell->CurrentField - 1), (short)fldcol, 0 );
  534.  
  535.         if( (fld == BGField) || (fld == FGField) )
  536.         {
  537.           nEvent->Value = SPACEBAR;
  538.           continue;
  539.         }
  540.         return( 0 );
  541.       }
  542.  
  543.       case BGNEXT:
  544.       {
  545.         /*********************************************************************/
  546.         /* This message is sent if the user clicks in the BGNEXT button or   */
  547.         /* presses SPACEBAR when on background field.                        */
  548.         /*  - Set the field variables.                                       */
  549.         /*  - Set the event value as SPACEBAR (simulate) and stay in the     */
  550.         /*    outer for loop to process SPACEBAR.                            */
  551.         /*  - Set the cursor position.                                       */
  552.         /*********************************************************************/
  553.         fldcol = shell->col+2 + VATTLENGTH;
  554.         fld = BGField;
  555.         nEvent->Value = SPACEBAR;
  556.         VioSetCurPos( (short)(shell->row + shell->SkipLines +
  557.                        shell->CurrentField - 1), (short)fldcol, 0 );
  558.         continue;
  559.       }
  560.  
  561.       case FGNEXT:
  562.       {
  563.         /*********************************************************************/
  564.         /* This message is sent if the user clicks in the FGNEXT button or   */
  565.         /* presses SPACEBAR when on foreground field.                        */
  566.         /*  - Set the field variables.                                       */
  567.         /*  - Set the event value as SPACEBAR (simulate) and stay in the     */
  568.         /*    outer for loop to process SPACEBAR.                            */
  569.         /*  - Set the cursor position.                                       */
  570.         /*********************************************************************/
  571.         fldcol = shell->col+2 + VATTLENGTH + BGLENGTH;
  572.         fld = FGField;
  573.         nEvent->Value = SPACEBAR;
  574.         VioSetCurPos( (short)(shell->row + shell->SkipLines +
  575.                        shell->CurrentField - 1), (short)fldcol, 0 );
  576.         continue;
  577.       }
  578.  
  579.       case key_R:
  580.       case key_r:
  581.       {
  582.         /*********************************************************************/
  583.         /* This message is sent if the user clicks in the RESET button or    */
  584.         /* presses 'R' / 'r' keys.                                           */
  585.         /*  - Reset the current color to default color.                      */
  586.         /*  - Change the current color attribute and display the same in the */
  587.         /*    "Sample" area of the dialog.                                   */
  588.         /*  - Return zero to denote continue dialog processing.              */
  589.         /*********************************************************************/
  590.         *pAttByte = DefVaMap[SelectIndex];
  591.         ReDisplaySingleColor( shell->row + shell->SkipLines +
  592.                               shell->CurrentField - 1, shell->col + 2,
  593.                               SelectIndex, pAttByte );
  594.         return( 0 );
  595.       }
  596.  
  597.       case key_D:
  598.       case key_d:
  599.       {
  600.         /*********************************************************************/
  601.         /* This message is sent if the user clicks in the DEFAULT button or  */
  602.         /* presses 'D' / 'd' keys.                                           */
  603.         /*  - Copy the default color map to local color map.                 */
  604.         /*  - Redisplay the display area of the dialog.                      */
  605.         /*  - Return zero to denote continue dialog processing.              */
  606.         /*********************************************************************/
  607.         memcpy( LocalVaMap, DefVaMap, MAXVIDEOATR + 1 );
  608.         DisplayColorChoice( shell, ptr );
  609.         return( 0 );
  610.       }
  611.  
  612.       case key_S:
  613.       case key_s:
  614.       {
  615.         /*********************************************************************/
  616.         /* This message is sent if the user clicks on the SAVE button or     */
  617.         /* presses the 'S' / 's' keys.                                       */
  618.         /*  - Find the fully qualified file name for the .pro                */
  619.         /*  - Call function to save the colors.                              */
  620.         /*  - If not successfull in saving colors, display the error box     */
  621.         /*    with appropriate error message.                                */
  622.         /*  - If successfull display a timmed message and copy the local     */
  623.         /*    color map to default color map.                                */
  624.         /*  - Return zero to denote continue dialog processing.              */
  625.         /*********************************************************************/
  626.         uchar  StatusMsg[100];
  627.         uchar  fn[MAXFNAMELEN];
  628.         int    rc;
  629.  
  630.         findpro( "SD386.PRO", fn, MAXFNAMELEN );
  631.         rc = SaveColors( fn );
  632.         if( rc )
  633.         {
  634.           if( rc == FILENOTFOUND )
  635.             sprintf( StatusMsg, "Unable to find \"SD386.PRO\" in DPATH" );
  636.           else
  637.             sprintf( StatusMsg, "Unable to save to profile \"%s\"", fn );
  638.         }
  639.         else
  640.         {
  641.           sprintf( StatusMsg, "Saving Colors to profile \"%s\"", fn );
  642.           memcpy( VideoMap, LocalVaMap, MAXVIDEOATR + 1 );
  643.         }
  644.         SayMsgBox2( StatusMsg, 1200UL );
  645.         VioSetCurType( &NormalCursor, 0 );
  646.         return( 0 );
  647.       }
  648.  
  649.       case RIGHT:
  650.       case TAB:
  651.       {
  652.         /*********************************************************************/
  653.         /* This message is sent if the user presses TAB or right arrow  key.*/
  654.         /*  - Depending on the current field determine to which field we have*/
  655.         /*    to move to the right or loop around.                           */
  656.         /*  - Set the field variables.                                       */
  657.         /*  - Set the cursor position.                                       */
  658.         /*  - Return zero to denote continue dialog processing.              */
  659.         /*********************************************************************/
  660.         switch( fld )
  661.         {
  662.           case AttrField:
  663.             fldcol = shell->col+ 2 + VATTLENGTH;
  664.             fld = BGField;
  665.             break;
  666.  
  667.           case BGField:
  668.             fldcol = shell->col+ 2 + VATTLENGTH + BGLENGTH;
  669.             fld = FGField;
  670.             break;
  671.  
  672.           case FGField:
  673.             fldcol = shell->col+2;
  674.             fld = AttrField;
  675.             break;
  676.         }
  677.         VioSetCurPos( (short)(shell->row + shell->SkipLines +
  678.                        shell->CurrentField - 1), (short)fldcol, 0 );
  679.         return( 0 );
  680.       }
  681.  
  682.       case LEFT:
  683.       case S_TAB:
  684.       {
  685.         /*********************************************************************/
  686.         /* This message is sent if the user presses SHIFT TAB or left arrow  */
  687.         /*  key.                                                            */
  688.         /*  - Depending on the current field determine to which field we have*/
  689.         /*    to move to the left or loop around.                            */
  690.         /*  - Set the field variables.                                       */
  691.         /*  - Set the cursor position.                                       */
  692.         /*  - Return zero to denote continue dialog processing.              */
  693.         /*********************************************************************/
  694.         switch( fld )
  695.         {
  696.           case AttrField:
  697.             fldcol = shell->col+2 + VATTLENGTH + BGLENGTH;
  698.             fld = FGField;
  699.             break;
  700.  
  701.           case BGField:
  702.             fldcol = shell->col+2;
  703.             fld = AttrField;
  704.             break;
  705.  
  706.           case FGField:
  707.             fldcol = shell->col+2 + VATTLENGTH;
  708.             fld = BGField;
  709.             break;
  710.         }
  711.         VioSetCurPos( (short)(shell->row + shell->SkipLines +
  712.                        shell->CurrentField - 1), (short)fldcol, 0 );
  713.         return( 0 );
  714.       }
  715.  
  716.       case SPACEBAR:
  717.       {
  718.         /*********************************************************************/
  719.         /* This message is sent if the user presses the SPACEBAR.            */
  720.         /*  - If the cursor is in the forground or background fields move on */
  721.         /*    to the next color.                                             */
  722.         /*  - Change the current color attribute and display the same in the */
  723.         /*    "Sample" area of the dialog.                                   */
  724.         /*  - Return zero to denote continue dialog processing.              */
  725.         /*********************************************************************/
  726.         switch( fld )
  727.         {
  728.           case BGField:
  729.             *pAttByte = (uchar) ((*pAttByte + 0x10) & 0x7F);
  730.             ReDisplaySingleColor( shell->row + shell->SkipLines +
  731.                                   shell->CurrentField - 1, shell->col + 2,
  732.                                   SelectIndex, pAttByte );
  733.             break;
  734.  
  735.           case FGField:
  736.             *pAttByte = (uchar) ((*pAttByte & 0xF0) +
  737.                                 ((*pAttByte + 0x01) & 0x0F));
  738.             ReDisplaySingleColor( shell->row + shell->SkipLines +
  739.                                   shell->CurrentField - 1, shell->col + 2,
  740.                                   SelectIndex, pAttByte );
  741.             break;
  742.         }
  743.         return( 0 );
  744.       }
  745.  
  746.       case UP:
  747.       case DOWN:
  748.       case SCROLLUP:
  749.       case SCROLLDOWN:
  750.       case SCROLLBAR:
  751.       {
  752.         /*********************************************************************/
  753.         /* These messages are sent if the user presses up  or down  arrow  */
  754.         /* keys or the user clicks on the  or  in the scrollbar.           */
  755.         /*  - Set the field variables.                                       */
  756.         /*  - Set the cursor position.                                       */
  757.         /*  - Return zero to denote continue dialog processing.              */
  758.         /*********************************************************************/
  759.         switch( fld )
  760.         {
  761.           case AttrField:
  762.             fldcol = shell->col+2;
  763.             break;
  764.  
  765.           case BGField:
  766.             fldcol = shell->col+2 + VATTLENGTH;
  767.             break;
  768.  
  769.           case FGField:
  770.             fldcol = shell->col+2 + VATTLENGTH + BGLENGTH;
  771.             break;
  772.         }
  773.  
  774.         VioSetCurPos( (short)(shell->row + shell->SkipLines +
  775.                        shell->CurrentField - 1), (short)fldcol, 0 );
  776.         return( 0 );
  777.       }
  778.  
  779.       default:
  780.         /*********************************************************************/
  781.         /* Any other message.                                                */
  782.         /* - Return zero to denote continue dialog processing.               */
  783.         /*********************************************************************/
  784.         return( 0 );
  785.     }
  786.   }
  787. }
  788.