# $Header:   P:\source\wmacros\style.pev   1.49   27 Mar 1995 16:48:38   PFHJXM0  $

##############################################################################
#
#       Compuware Corporation
#         31440 Northwestern Highway
#           Farmington Hills, Michigan 48334-2564
#
#   This source code listing contains information that is
#   proprietary to Compuware Corporation and may not be copied
#   duplicated, translated, transmitted, stored, retrieved
#   or in any manner or by any method conveyed or disclosed
#   to a third party or parties without express written
#   permission from Compuware Corporation.
#
#  
##############################################################################

#### $Workfile:   style.pel  $: 

global defined_styles[];
global save_styles[];

global CATEGORY_ALL         = 0x0009
global CATEGORY_RESERVED    = 0x0102
global CATEGORY_COMMENT     = 0x0209
global CATEGORY_LITERAL     = 0x030D

global CATEGORY_TYPE        = 0x040A
global CATEGORY_DIRECTIVE   = 0x050B
global CATEGORY_CONSTANT    = 0x060B

global CATEGORY_FUNCTIONS   = 0x070A
global CATEGORY_PROCEDURES  = 0x0802

global CATEGORY_DIVISION    = 0x090B
global CATEGORY_CLAUSE      = 0x0A0B
global CATEGORY_EXPRESSIONS = 0x0B02
global CATEGORY_SECTION     = 0x0C02
global CATEGORY_STATEMENTS  = 0x0D0A
global CATEGORY_PARAGRAPH   = 0x0e0A

global VDIFF_PLUS           = 0x0011;
global VDIFF_MINUS          = 0x0012;
global VDIFF_BLANK          = 0x0013;

global syntax_colors_fg[];
global syntax_colors_bg[];

global function set_factory_categories(type)
{
   local index = shiftr(and(CATEGORY_RESERVED, not(CATEGORY_MASK)), 8);
   local fg    = query_syntax_style(and(CATEGORY_RESERVED, not(ITEM_MASK)), 0);
   local bg    = query_syntax_style(and(CATEGORY_RESERVED, not(ITEM_MASK)), 1);

   add_syntax_category(type, index, "Reserved words", fg, bg);

   index = shiftr(and(CATEGORY_ALL, not(CATEGORY_MASK)), 8);
   fg    = query_syntax_style(and(CATEGORY_ALL, not(ITEM_MASK)), 0);
   bg    = query_syntax_style(and(CATEGORY_ALL, not(ITEM_MASK)), 1);
   add_syntax_category(type, index, "All", fg, bg);

   index = shiftr(and(CATEGORY_COMMENT, not(CATEGORY_MASK)), 8);
   fg    = query_syntax_style(and(CATEGORY_COMMENT, not(ITEM_MASK)), 0);
   bg    = query_syntax_style(and(CATEGORY_COMMENT, not(ITEM_MASK)), 1);
   add_syntax_category(type, index, "Comments", fg, bg);

   index = shiftr(and(CATEGORY_LITERAL, not(CATEGORY_MASK)), 8);
   fg    = query_syntax_style(and(CATEGORY_LITERAL, not(ITEM_MASK)), 0);
   bg    = query_syntax_style(and(CATEGORY_LITERAL, not(ITEM_MASK)), 1);
   add_syntax_category(type, index, "Literals", fg, bg);

   index = shiftr(and(CATEGORY_TYPE, not(CATEGORY_MASK)), 8);
   fg    = query_syntax_style(and(CATEGORY_TYPE, not(ITEM_MASK)), 0);
   bg    = query_syntax_style(and(CATEGORY_TYPE, not(ITEM_MASK)), 1);
   add_syntax_category(type, index, "Types", fg, bg);

   if(type == "c")
   {
      index = shiftr(and(CATEGORY_DIRECTIVE, not(CATEGORY_MASK)), 8);
      fg    = query_syntax_style(and(CATEGORY_DIRECTIVE, not(ITEM_MASK)), 0);
      bg    = query_syntax_style(and(CATEGORY_DIRECTIVE, not(ITEM_MASK)), 1);
      add_syntax_category(type, index, "Directives", fg, bg);
       
      index = shiftr(and(CATEGORY_CONSTANT, not(CATEGORY_MASK)), 8);
      fg    = query_syntax_style(and(CATEGORY_CONSTANT, not(ITEM_MASK)), 0);
      bg    = query_syntax_style(and(CATEGORY_CONSTANT, not(ITEM_MASK)), 1);
      add_syntax_category(type, index, "Constants", fg, bg);
   }

   if(type == "cobol")
   {
      index = shiftr(and(CATEGORY_DIVISION, not(CATEGORY_MASK)), 8);
      fg    = query_syntax_style(and(CATEGORY_DIVISION, not(ITEM_MASK)), 0);
      bg    = query_syntax_style(and(CATEGORY_DIVISION, not(ITEM_MASK)), 1);
      add_syntax_category(type, index, "Divisions", fg, bg);

      index = shiftr(and(CATEGORY_PARAGRAPH, not(CATEGORY_MASK)), 8);
      fg    = query_syntax_style(and(CATEGORY_PARAGRAPH, not(ITEM_MASK)), 0);
      bg    = query_syntax_style(and(CATEGORY_PARAGRAPH, not(ITEM_MASK)), 1);
      add_syntax_category(type, index, "Paragraphs", fg, bg);

      index = shiftr(and(CATEGORY_SECTION, not(CATEGORY_MASK)), 8);
      fg    = query_syntax_style(and(CATEGORY_SECTION, not(ITEM_MASK)), 0);
      bg    = query_syntax_style(and(CATEGORY_SECTION, not(ITEM_MASK)), 1);
      add_syntax_category(type, index, "Sections", fg, bg);

      index = shiftr(and(CATEGORY_CLAUSE, not(CATEGORY_MASK)), 8);
      fg    = query_syntax_style(and(CATEGORY_CLAUSE, not(ITEM_MASK)), 0);
      bg    = query_syntax_style(and(CATEGORY_CLAUSE, not(ITEM_MASK)), 1);
      add_syntax_category(type, index, "Clauses", fg, bg);

      index = shiftr(and(CATEGORY_EXPRESSIONS, not(CATEGORY_MASK)), 8);
      fg    = query_syntax_style(and(CATEGORY_EXPRESSIONS, not(ITEM_MASK)), 0);
      bg    = query_syntax_style(and(CATEGORY_EXPRESSIONS, not(ITEM_MASK)), 1);
      add_syntax_category(type, index, "Expressions", fg, bg);

      index = shiftr(and(CATEGORY_STATEMENTS, not(CATEGORY_MASK)), 8);
      fg    = query_syntax_style(and(CATEGORY_STATEMENTS, not(ITEM_MASK)), 0);
      bg    = query_syntax_style(and(CATEGORY_STATEMENTS, not(ITEM_MASK)), 1);
      add_syntax_category(type, index, "Statements", fg, bg);
   }

   if(type == "pascal")
   {
      index = shiftr(and(CATEGORY_FUNCTIONS, not(CATEGORY_MASK)), 8);
      fg    = query_syntax_style(and(CATEGORY_FUNCTIONS, not(ITEM_MASK)), 0);
      bg    = query_syntax_style(and(CATEGORY_FUNCTIONS, not(ITEM_MASK)), 1);
      add_syntax_category(type, index, "Functions", fg, bg);

      index = shiftr(and(CATEGORY_PROCEDURES, not(CATEGORY_MASK)), 8);
      fg    = query_syntax_style(and(CATEGORY_PROCEDURES, not(ITEM_MASK)), 0);
      bg    = query_syntax_style(and(CATEGORY_PROCEDURES, not(ITEM_MASK)), 1);
      add_syntax_category(type, index, "Procedures", fg, bg);
   }

   if(type == "rexx")
   {
      index = shiftr(and(CATEGORY_FUNCTIONS, not(CATEGORY_MASK)), 8);
      fg    = query_syntax_style(and(CATEGORY_FUNCTIONS, not(ITEM_MASK)), 0);
      bg    = query_syntax_style(and(CATEGORY_FUNCTIONS, not(ITEM_MASK)), 1);
      add_syntax_category(type, index, "Functions", fg, bg);
   }
}
  
# These are the colors returned in the first
# 16 entries of get_color_table().  
#local SI_BACKGROUND    = 0x000000
#local SI_BLUE          = 0x000001
#local SI_RED           = 0x000002
#local SI_PINK          = 0x000003
#local SI_GREEN         = 0x000004
#local SI_CYAN          = 0x000005
#local SI_YELLOW        = 0x000006
#local SI_NUETRAL       = 0x000007
#
#local SI_DARK_GRAY     = 0x000008
#local SI_DARK_BLUE     = 0x000009
#local SI_DARK_RED      = 0x00000A
#local SI_DARK_PINK     = 0x00000B
#local SI_DARK_GREEN    = 0x00000C
#local SI_DARK_CYAN     = 0x00000D
#local SI_BROWN         = 0x00000E
#local SI_PALE_GRAY     = 0x00000F

global function load_factory_syntax_colors()
{
   local available_colors = get_color_table()

   delete syntax_colors_fg;
   delete syntax_colors_bg;

   syntax_colors_fg[0x10001] = available_colors[0]
   syntax_colors_fg[0x20001] = available_colors[1]
   syntax_colors_fg[0x30001] = available_colors[2]
   syntax_colors_fg[0x40001] = available_colors[3]
   syntax_colors_fg[0x50001] = available_colors[4]
   syntax_colors_fg[0x60001] = available_colors[5]
   syntax_colors_fg[0x70001] = available_colors[6]
   syntax_colors_fg[0x80001] = available_colors[7]

   syntax_colors_fg[0x10002] = available_colors[8]
   syntax_colors_fg[0x20002] = available_colors[9]
   syntax_colors_fg[0x30002] = available_colors[10]
   syntax_colors_fg[0x40002] = available_colors[11]
   syntax_colors_fg[0x50002] = available_colors[12]
   syntax_colors_fg[0x60002] = available_colors[13]
   syntax_colors_fg[0x70002] = available_colors[14]
   syntax_colors_fg[0x80002] = available_colors[15]

   #  Background colors
   syntax_colors_bg[0x10001] = available_colors[0]
   syntax_colors_bg[0x20001] = available_colors[1]
   syntax_colors_bg[0x30001] = available_colors[2]
   syntax_colors_bg[0x40001] = available_colors[3]
   syntax_colors_bg[0x50001] = available_colors[4]
   syntax_colors_bg[0x60001] = available_colors[5]
   syntax_colors_bg[0x70001] = available_colors[6]
   syntax_colors_bg[0x80001] = available_colors[7]

   syntax_colors_bg[0x10002] = available_colors[8]
   syntax_colors_bg[0x20002] = available_colors[9]
   syntax_colors_bg[0x30002] = available_colors[10]
   syntax_colors_bg[0x40002] = available_colors[11]
   syntax_colors_bg[0x50002] = available_colors[12]
   syntax_colors_bg[0x60002] = available_colors[13]
   syntax_colors_bg[0x70002] = available_colors[14]
   syntax_colors_bg[0x80002] = available_colors[15]
}

#  
#  No styles may be created before this function is called;
#  This function assumes no styles exist.
#  The syntax_colors array must also be defined.  The colors defined
#  there are accessed in this function.
#  
global function load_factory_default_styles()
{
   local DEFAULT  = -1, index, row, col;
   
   #  Create the 16 default styles (16 foreground colors on default background);
   for(row = 1; row <= 2; row++)
   {
      for(col = 1; col <= 8; col++)
      {
         index = or(shiftl(col, 16), row);

         create_syntax_style(syntax_colors_fg[index] , DEFAULT);
         defined_styles[syntax_colors_fg[index]][DEFAULT] = ((row-1)*8)+col;
      }
   }

   #  Create VDIFF styles;
   create_syntax_style(COLOR_WHITE, COLOR_BROWN);
   defined_styles[COLOR_WHITE][COLOR_BROWN] = 0x11;

   create_syntax_style(COLOR_WHITE, COLOR_DARK_BLUE);
   defined_styles[COLOR_WHITE][COLOR_DARK_BLUE] = 0x12;

   create_syntax_style(COLOR_DARK_BLUE, COLOR_DARK_BLUE);
   defined_styles[COLOR_DARK_BLUE][COLOR_DARK_BLUE] = 0x13;
}

global function syntax_new_buffer()
{
   local ext = path_ext(buffer_filename);

   if(!and(buffer_flags, BUFFER_SYSTEM))
   {
      #  TODO: this is here until electric_mode is turned into a buffer variable;
      #  if(Template(ext) != ELEC_LANG)
      #  {  this "if" was not correct.  we can have the same template mapped
      #     to different types with one on and the other off

      #  If we have a deifferent template or the same template with a different status, toggle;
      if((Template(ext) != ELEC_LANG) || xor(get_expand_template(ext), electric_mode))
          toggle_electric(get_expand_template(ext));

      matching_pairs = MatchingPairs(ext);
      #     languages_id = languages_id;

      #  These variables were made buffer variables and don't need to be set here;
      #  style_delimiter = StyleDelimiters(ext) "";
      #  escape_character = EscapeCharacter(ext) "";
   }
}
