home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 5 Edit / 05-Edit.zip / p2demo21.exe / PEL / TYPESET.PEL < prev    next >
Text File  |  1995-04-11  |  96KB  |  2,985 lines

  1. # $Header:   P:\source\wmacros\typeset.pev   1.35.1.2   11 Apr 1995 15:09:58   WALKER  $
  2. ## $Tabs:4 7$
  3.  
  4. ##############################################################################
  5. #
  6. #       Compuware Corporation
  7. #         31440 Northwestern Highway
  8. #           Farmington Hills, Michigan 48334-2564
  9. #
  10. #   This source code listing contains information that is
  11. #   proprietary to Compuware Corporation and may not be copied
  12. #   duplicated, translated, transmitted, stored, retrieved
  13. #   or in any manner or by any method conveyed or disclosed
  14. #   to a third party or parties without express written
  15. #   permission from Compuware Corporation.
  16. #
  17. #  
  18. ##############################################################################
  19.  
  20. #### $Workfile:   typeset.pel  $: 
  21.  
  22. ############## EXTENSION/COMPILERS SETTINGS NOTEBOOK PAGE ###################
  23. local  IDE_EXTENSIONS                 = 102;
  24. local  IDC_EXPANSION                  = 101;
  25. local  IDB_ADVANCED                   = 101;
  26. local  IDD_ADVANCED_COMPILER_SETTINGS = 1082
  27. local  IDD_DOS_SETTINGS_DIALOG        = 1083
  28.  
  29. local  save_extensions;
  30. local  save_compilers;
  31. local  local_compiler;
  32. local  dos_settings_array;
  33.  
  34. global function extension_settings_notebook(dlgid)
  35. {
  36.    local phandle, dhandle = 0;
  37.  
  38.    nb_initializing = TRUE;
  39.  
  40.    if ( status_bar_flags )
  41.       message( "Creating Type Settings pages..." )
  42.  
  43.    phandle = append_notebook_page( dlgid, dhandle, " ",
  44.                                                     "Types", NBTAB_MAJOR )
  45.    nbPagePrefix[phandle].name = "exthelp";
  46.    
  47.    phandle = append_notebook_page(dlgid, dhandle, " Define Types",
  48.                                                   "Extensions", NBTAB_MINOR)
  49.    nbPagePrefix[phandle].name = "ext";
  50.  
  51.    phandle = append_notebook_page(dlgid, dhandle, " Setup Compilers",
  52.                                                   "Compilers", NBTAB_MINOR)
  53.    nbPagePrefix[phandle].name = "compiler";
  54.  
  55.    phandle = append_notebook_page(dlgid, dhandle, " Color Highlighting",
  56.                                                   "Colors", NBTAB_MINOR)
  57.    nbPagePrefix[phandle].name = "syntax";
  58.  
  59.    phandle = append_notebook_page(dlgid, dhandle, " Language Templates",
  60.                                                   "Template", NBTAB_MINOR)
  61.    nbPagePrefix[phandle].name = "template";
  62.  
  63.    nb_initializing = FALSE;
  64. }
  65.  
  66. global function reset_extension_settings_notebook()
  67. {
  68.    language_compiled = FALSE;
  69.    global_type       = FALSE;
  70.  
  71.    delete save_extensions;
  72.    delete save_compilers;
  73.    delete save_languages;
  74.    delete save_styles;
  75.    save_extensions = FALSE;
  76.    save_compilers  = FALSE;
  77.    save_languages  = FALSE;
  78.    save_styles     = FALSE;
  79. }
  80.  
  81. ###############################################################################
  82. #  
  83. #  Extension Settings Create functions
  84. #  
  85. ###############################################################################
  86.  
  87. global function create_exthelp_page(pageid, dlgid)
  88. {
  89.    local dhandle;
  90.  
  91.    dhandle = create_page(function_id( "nop_settings_callback"), 
  92.                                 dlgid, IDD_EXTENSION_HELP_PAGE, resource_dll );
  93.  
  94.    attach_help(editor_helpfile, dhandle);
  95.    if(isWindows())
  96.       nbPagePrefix[pageid].help = "Type Settings";
  97.    else
  98.       nbPagePrefix[pageid].help = "typespages";
  99.  
  100.    set_notebook_page_dialog(dlgid, pageid, dhandle);
  101.    nbPagePrefix[pageid].dialog_handle = dhandle;
  102. }
  103.  
  104. global function create_ext_page(pageid, dlgid)
  105. {
  106.    local dhandle;
  107.  
  108.    dhandle = create_page(function_id( "ext_settings_callback" ), 
  109.                                dlgid, IDD_EXT_SETTINGS, resource_dll)
  110.  
  111.    attach_help(editor_helpfile, dhandle);
  112.    if(isWindows())
  113.       nbPagePrefix[pageid].help = "Extension Settings";
  114.    else
  115.       nbPagePrefix[pageid].help = "extensionspage";
  116.  
  117.    if(!save_extensions)
  118.       save_extensions = copy_extensions_array(extensions);
  119.    if(!save_languages)
  120.       save_languages  = copy_languages_array(languages);
  121.  
  122.    add_dialog_item(dhandle, IDE_EXTENSIONS, DCTRL_EDIT);
  123.    set_dialog_item(dhandle, IDE_EXTENSIONS, DAC_SET_TEXT_LEN, 255);
  124.    add_dialog_item(dhandle, IDE_PAIRS,      DCTRL_EDIT);
  125.    set_dialog_item(dhandle, IDE_PAIRS,      DAC_SET_TEXT_LEN, 255);
  126.    set_dialog_item(dhandle, IDL_TYPE,     DAC_SORT_ASCENDING)
  127.    set_dialog_item(dhandle, IDB_CHG_COMP, DAC_DISABLE )
  128.    set_dialog_item(dhandle, IDB_CPY_COMP, DAC_DISABLE )
  129.    set_dialog_item(dhandle, IDB_DEL_COMP, DAC_DISABLE )
  130.  
  131.    set_dialog_item(dhandle, IDB_DEFAULT, DAC_DISABLE )
  132. #     set_dialog_item(dhandle, IDB_UNDO,    DAC_DISABLE )
  133.  
  134.    initialize_ext_settings(dhandle, "dummy", 1);
  135.  
  136.    set_notebook_page_dialog(dlgid, pageid, dhandle);
  137.    nbPagePrefix[pageid].dialog_handle = dhandle;
  138. }
  139.  
  140. global function create_compiler_page(pageid, dlgid)
  141. {
  142.    local dhandle;
  143.  
  144.    dhandle = create_page(function_id( "compiler_settings_callback" ), 
  145.                                     dlgid, IDD_COMP_SETTINGS, resource_dll)
  146.  
  147.    attach_help(editor_helpfile, dhandle)
  148.    if(isWindows())
  149.       nbPagePrefix[pageid].help = "Compiler Settings";
  150.    else
  151.       nbPagePrefix[pageid].help = "compilerspage";
  152.  
  153.    if(!save_compilers)
  154.        save_compilers  = copy_compilers_array(compilers);
  155.  
  156.    if(!save_languages)
  157.        save_languages  = copy_languages_array(languages);
  158.  
  159.    add_dialog_item(dhandle, IDE_OTHER,        DCTRL_EDIT);
  160. #     add_dialog_item(dhandle, IDE_INPUT_FILE,   DCTRL_EDIT);
  161.    add_dialog_item(dhandle, IDE_COMMAND_LINE, DCTRL_EDIT);
  162.  
  163.    set_dialog_item(dhandle, IDE_OTHER,        DAC_SET_TEXT_LEN, 255);
  164. #     set_dialog_item(dhandle, IDE_INPUT_FILE,   DAC_SET_TEXT_LEN, 255);
  165.    set_dialog_item(dhandle, IDE_COMMAND_LINE, DAC_SET_TEXT_LEN, 255);
  166.  
  167.    set_dialog_item(dhandle, IDL_TYPE,         DAC_SORT_ASCENDING);
  168.    set_dialog_item(dhandle, IDL_ERROR,        DAC_SORT_ASCENDING);
  169.    set_dialog_item(dhandle, IDL_COMPILER,     DAC_SORT_ASCENDING);
  170.  
  171.    set_dialog_item(dhandle, IDE_OTHER,           DAC_DISABLE)
  172. #     set_dialog_item(dhandle, IDE_INPUT_FILE,      DAC_DISABLE)
  173.    set_dialog_item(dhandle, IDT_BUFFER_DEF_TEXT, DAC_DISABLE)
  174.  
  175.    set_dialog_item(dhandle, IDL_ERROR, DAC_DELETE_ITEM);
  176.    set_dialog_item(dhandle, IDL_ERROR, DAC_ADD_ITEM, "ada");
  177.    set_dialog_item(dhandle, IDL_ERROR, DAC_ADD_ITEM, "clipper5");
  178.    set_dialog_item(dhandle, IDL_ERROR, DAC_ADD_ITEM, "clipper87");
  179.    set_dialog_item(dhandle, IDL_ERROR, DAC_ADD_ITEM, "force");
  180.    set_dialog_item(dhandle, IDL_ERROR, DAC_ADD_ITEM, "generic");
  181.    set_dialog_item(dhandle, IDL_ERROR, DAC_ADD_ITEM, "lahey");
  182.    set_dialog_item(dhandle, IDL_ERROR, DAC_ADD_ITEM, "microfocus");
  183.    set_dialog_item(dhandle, IDL_ERROR, DAC_ADD_ITEM, "other");
  184.    set_dialog_item(dhandle, IDL_ERROR, DAC_ADD_ITEM, "pel");
  185.    set_dialog_item(dhandle, IDL_ERROR, DAC_ADD_ITEM, "realia");
  186.    set_dialog_item(dhandle, IDL_ERROR, DAC_ADD_ITEM, "turboc");
  187.    set_dialog_item(dhandle, IDL_ERROR, DAC_ADD_ITEM, "watcom");
  188.    set_dialog_item(dhandle, IDL_ERROR, DAC_ADD_ITEM, "zortech");
  189.    set_dialog_item(dhandle, IDL_ERROR, DAC_ADD_ITEM, "[None]");
  190.  
  191.    initialize_compiler_settings( dhandle, "dummy", 1 )
  192.  
  193.    set_notebook_page_dialog(dlgid, pageid, dhandle);
  194.    nbPagePrefix[pageid].dialog_handle = dhandle;
  195. }
  196.  
  197. global function create_template_page(pageid, dlgid)
  198. {
  199.    local dhandle;
  200.  
  201.    dhandle = create_page(function_id( "template_settings_callback" ), 
  202.                                dlgid, IDD_TEMPL_SETTINGS, resource_dll);
  203.  
  204.    attach_help(editor_helpfile, dhandle);
  205.    if(isWindows())
  206.       nbPagePrefix[pageid].help = "Template Settings";
  207.    else
  208.       nbPagePrefix[pageid].help = "templatepage";
  209.  
  210.    if(!save_languages)
  211.       save_languages = copy_languages_array(languages);
  212.  
  213.    initialize_template_settings(dhandle, "dummy", 1);
  214.  
  215.    set_notebook_page_dialog(dlgid, pageid, dhandle);
  216.    nbPagePrefix[pageid].dialog_handle = dhandle;
  217. }
  218.  
  219. ###############################################################################
  220. #  
  221. #  Extension Settings Initialize functions
  222. #  
  223. ###############################################################################
  224.  
  225. global function initialize_ext_settings( handle, dummy, load_types )
  226. {
  227.    local list;
  228.  
  229.    nb_initializing = TRUE;
  230. #     init_extensions(handle);
  231.    if(load_types)
  232.       init_types(handle);
  233.  
  234.    establish_global_type(handle);
  235.  
  236.    list = get_ext_list(global_type);
  237.    set_dialog_item(handle, IDE_EXTENSIONS, DAC_EDIT_TEXT, list "");
  238.    set_dialog_item(handle, IDE_PAIRS, DAC_EDIT_TEXT, MatchingPairs(global_type) "");
  239.  
  240.    apply_page_to_all( "EXT_PAGE", function_id("ext_apply_to_all") )
  241.  
  242. #     set_dialog_item(handle, IDB_UNDO, DAC_DISABLE);
  243.    nb_initializing = FALSE;
  244. }
  245.  
  246. global function initialize_compiler_settings( handle, dummy, load_types )
  247. {
  248.    local name
  249.  
  250.    nb_initializing = TRUE;
  251.  
  252.    if(load_types)
  253.    {
  254.       init_types(handle);
  255.       init_compilers(handle);
  256.    }
  257.  
  258.    establish_global_type(handle);
  259.  
  260.    name = CompilerName(global_type);
  261.    if(!name)
  262.        name = "[None]";
  263.  
  264.    set_dialog_item(handle, IDL_COMPILER, DAC_SELECT_ITEM, name "");
  265.    set_compiler(handle, global_type, name)
  266.  
  267.    set_dialog_item(handle, IDB_UNDO, DAC_DISABLE);
  268.    nb_initializing = FALSE;
  269. }
  270.  
  271. local function set_compiler( handle, type, name )
  272. {
  273.    local err_format, file, num;
  274.  
  275.    set_dialog_item(handle, IDE_COMMAND_LINE, DAC_EDIT_TEXT, CommandLine(name) "")
  276.  
  277.    err_format = ErrorFormat(name)
  278.    if(prefix(err_format, 5) == "other")
  279.    {
  280.       set_dialog_item(handle, IDE_OTHER, DAC_EDIT_TEXT, substr(err_format, 7) "")
  281.       set_dialog_item(handle, IDL_ERROR, DAC_SELECT_ITEM, "other")
  282.    }
  283.    else
  284.    {
  285.       if(!err_format || err_format == "none")
  286.           err_format = "[None]";
  287.  
  288.       set_dialog_item(handle, IDE_OTHER, DAC_EDIT_TEXT, "")
  289.       if (!set_dialog_item(handle, IDL_ERROR, DAC_SELECT_ITEM, err_format""))
  290.          set_dialog_item(handle, IDL_ERROR, DAC_SELECT_ITEM, "generic")
  291.    }
  292.  
  293.    file = CompilerInput(name)
  294.    num  = file+0
  295.    if (num >= 0)
  296.    {
  297. #        set_dialog_item(handle, IDC_NEEDS_INPUT, DAC_CHECK);
  298. #        set_dialog_item(handle, IDE_INPUT_FILE,  DAC_ENABLE)
  299. #      if (num == 1)
  300. #         set_dialog_item(handle, IDE_INPUT_FILE, DAC_EDIT_TEXT, "");
  301. #      else
  302. #         set_dialog_item(handle, IDE_INPUT_FILE, DAC_EDIT_TEXT, file "");
  303.    }
  304.    else
  305.    {
  306. #      set_dialog_item(handle, IDC_NEEDS_INPUT, DAC_UNCHECK);
  307. #      set_dialog_item(handle, IDE_INPUT_FILE,  DAC_EDIT_TEXT, "");
  308. #      set_dialog_item(handle, IDE_INPUT_FILE,  DAC_DISABLE)
  309.    }
  310. }
  311.  
  312. global function initialize_template_settings( handle, dummy, load_types )
  313. {
  314.    local type, name;
  315.  
  316.    nb_initializing = TRUE;
  317.  
  318.    if(load_types)
  319.    {
  320.       init_types(handle);
  321.       init_templates(handle);
  322.    }
  323.  
  324.    establish_global_type(handle);
  325.  
  326.    set_dialog_item(handle, IDL_TEMPLATE,  DAC_SELECT_ITEM, Template(global_type) "");
  327.    if(get_expand_template(global_type))
  328.       set_dialog_item(handle, IDC_EXPANSION, DAC_CHECK);
  329.    else
  330.       set_dialog_item(handle, IDC_EXPANSION, DAC_UNCHECK);
  331.  
  332.    set_dialog_item(handle, IDB_UNDO, DAC_DISABLE);
  333.    nb_initializing = FALSE;
  334. }
  335.  
  336. #local function init_extensions(handle)
  337. #{
  338. #   local ext
  339. #
  340. #   set_dialog_item(handle, IDL_EXT, DAC_DELETE_ITEM)
  341. #   for (ext in extensions)
  342. #   {
  343. #      set_dialog_item(handle, IDL_EXT, DAC_ADD_ITEM, ext "")
  344. #   }
  345. #}
  346.  
  347. local function establish_global_type(handle)
  348. {
  349.    if(!global_type || (global_type == CURRENT_BUFFER) || (global_type == DEFAULT))
  350.       global_type = Type(path_ext(buffer_filename));
  351.  
  352.    if(global_type)
  353.       set_dialog_item(handle, IDL_TYPE, DAC_SELECT_ITEM, global_type "");
  354.    else
  355.    {
  356.       set_dialog_item(handle, IDL_TYPE, DAC_SELECT_INDEX, 0);
  357.       global_type = query_dialog_item(handle, IDL_TYPE, DAC_SELECT_ITEM);
  358.    }
  359. }
  360.  
  361. local function init_compilers(handle)
  362. {
  363.    local name;
  364.  
  365.    set_dialog_item(handle, IDL_COMPILER, DAC_DELETE_ITEM)
  366.    for (name in compilers)
  367.    {
  368.       set_dialog_item(handle, IDL_COMPILER, DAC_ADD_ITEM, name "")
  369.    }
  370. #     set_dialog_item(handle, IDL_COMPILER, DAC_ADD_ITEM, "[None]")
  371. }
  372.  
  373. local function init_templates(handle)
  374. {
  375.    local template
  376.  
  377.    set_dialog_item(handle, IDL_TEMPLATE, DAC_DELETE_ITEM)
  378.    for (template in templates)
  379.    {
  380.       set_dialog_item(handle, IDL_TEMPLATE, DAC_ADD_ITEM, template "")
  381.    }
  382. #     set_dialog_item(handle, IDL_TEMPLATE, DAC_ADD_ITEM, "[None]")
  383. }
  384.  
  385. ###############################################################################
  386. #  
  387. #  Extension Settings Callback functions
  388. #  
  389. ###############################################################################
  390.  
  391. local function valid_type_name(type)
  392. {
  393.    local retval = FALSE;
  394.  
  395.    if(!type)
  396.       nop();
  397.    else if(prefix(type, 1) == ".")
  398.       warning("You may not add a type that begins with a \".\"");
  399.    else if(match(type, "[^a-zA-Z_0-9]") || match(prefix(type, 1), "[0-9]"))
  400.       warning("Type name must be valid for use as a function name.");
  401.    else if(type in languages)
  402.       warning("\"" type "\" already exists as a type.");
  403.    else if((type == CURRENT_BUFFER) || (type == DEFAULT))
  404.       warning("\"" type "\" is a reserved type name.");
  405.    else
  406.       retval = TRUE;
  407.  
  408.    return retval;
  409. }
  410.  
  411. global function ext_settings_callback()
  412. {
  413.    local ext, type, new_type, list, handle = callback_dialog_handle;
  414.    local ret_msg = DRC_CONTINUE;
  415.  
  416. #     enable_undo(handle, callback_index);
  417.  
  418.    if(callback_msg == DM_HELPREQUESTED)
  419.    {
  420.       display_help(nbPagePrefix[current_nb_page].help, handle);
  421.       ret_msg = DRC_MSG_PROCESSED;
  422.    }
  423.    else if(callback_msg == DM_CANCEL)
  424.    {
  425.        ret_msg = DRC_MSG_PROCESSED;
  426.    }
  427.    else if((callback_msg == DM_CLICK) || (callback_msg == DM_DOUBLE_CLICK))
  428.    {
  429.       if(callback_index == IDB_UNDO)
  430.       {
  431.          #  Reset entire extensions array, TODO but what part of the languages array?;
  432.          undo_ext_settings(global_type);
  433. #           extensions = copy_extensions_array(save_extensions);
  434. #           languages  = copy_languages_array(save_languages);
  435.          initialize_ext_settings(handle);
  436.          ret_msg = DRC_MSG_PROCESSED;
  437.       }
  438.       else if ( callback_index == IDB_DEFAULT  ) 
  439.       {
  440.          #  Load the factory defaults that cannot be changed by the user;
  441.          load_factory_default_extensions();
  442.          load_factory_default_types();
  443.          initialize_ext_settings(handle);
  444.          nbPagePrefix[current_nb_page].modified = TRUE;
  445.          ret_msg = DRC_MSG_PROCESSED;
  446.       }
  447.       else if ( callback_index == IDB_ADD_COMP )
  448.       {
  449.          set_status_bar_flags( and(status_bar_flags, not(STB_PROMPTS)))
  450.          type = prompt_history("TYPE", "Enter new type :", type, 1, 1, "type_name_prompt");
  451.          restore_status_bar();
  452.          set_dialog_item(handle, IDL_TYPE, DAC_SETFOCUS);
  453.  
  454.          if(valid_type_name(type))
  455.          {
  456.             add_type(type);
  457.             set_dialog_item(handle, IDL_TYPE, DAC_ADD_ITEM, type);
  458.             propogate_type();
  459.             set_dialog_item(handle, IDL_TYPE, DAC_SELECT_ITEM, type);
  460.             nbPagePrefix[current_nb_page].modified = TRUE;
  461.          }
  462.  
  463.          ret_msg = DRC_MSG_PROCESSED;
  464.       }
  465.       else if ( callback_index == IDB_DEL_COMP )
  466.       {
  467.          type = query_dialog_item(handle, IDL_TYPE, DAC_SELECT_ITEM);
  468.          delete_type(type);
  469.  
  470.          set_dialog_item(handle, IDL_TYPE, DAC_DELETE_ITEM, type"");
  471.          set_dialog_item(handle, IDE_EXTENSIONS, DAC_EDIT_TEXT, "");
  472.          set_dialog_item(handle, IDE_PAIRS,      DAC_EDIT_TEXT, "");
  473.          set_dialog_item(handle, IDB_CHG_COMP, DAC_DISABLE);
  474.          set_dialog_item(handle, IDB_CPY_COMP, DAC_DISABLE);
  475.          set_dialog_item(handle, IDB_DEL_COMP, DAC_DISABLE);
  476.          propogate_type();
  477.          nbPagePrefix[current_nb_page].modified = TRUE;
  478.          ret_msg = DRC_MSG_PROCESSED;
  479.       }
  480.       else if ( callback_index == IDB_CHG_COMP )
  481.       {
  482.          type = query_dialog_item(handle, IDL_TYPE, DAC_SELECT_ITEM);
  483.          set_status_bar_flags( and(status_bar_flags, not(STB_PROMPTS)));
  484.          new_type = prompt_history("TYPE", "Change type name:", type, 1, 1, "type_name_prompt");
  485.          restore_status_bar();
  486.  
  487.          if(valid_type_name(new_type) && (new_type != type))
  488.          {
  489.             CopyType(type, new_type);
  490.             delete_type(type);
  491.             set_dialog_item(handle, IDL_TYPE, DAC_DELETE_ITEM, type);
  492.             set_dialog_item(handle, IDL_TYPE, DAC_ADD_ITEM, new_type);
  493.             propogate_type();
  494.             set_dialog_item(handle, IDL_TYPE, DAC_SELECT_ITEM, new_type);
  495.             nbPagePrefix[current_nb_page].modified = TRUE;
  496.          }
  497.          ret_msg = DRC_MSG_PROCESSED;
  498.       }
  499.       else if ( callback_index == IDB_CPY_COMP )
  500.       {
  501.          type = query_dialog_item(handle, IDL_TYPE, DAC_SELECT_ITEM);
  502.          set_status_bar_flags( and(status_bar_flags, not(STB_PROMPTS)));
  503.          new_type = prompt_history("TYPE", "Enter type to copy to:", type, 1, 1, "type_name_prompt" );
  504.          restore_status_bar();
  505.  
  506.          if(valid_type_name(new_type))
  507.          {
  508.             if(!(new_type in languages))
  509.             {
  510.                set_dialog_item(handle, IDL_TYPE, DAC_ADD_ITEM, new_type);
  511.                propogate_type();
  512.             }
  513.             CopyType(type, new_type);
  514.             nbPagePrefix[current_nb_page].modified = TRUE;
  515.          }
  516.  
  517.          ret_msg = DRC_MSG_PROCESSED;
  518.       }
  519.    }
  520.    else if ( callback_msg == DM_SELECT )
  521.    {
  522.       if ( callback_index == IDL_TYPE )
  523.       {
  524.          global_type = query_dialog_item(handle, IDL_TYPE, DAC_SELECT_ITEM);
  525.          set_dialog_item(handle, IDE_EXTENSIONS, DAC_EDIT_TEXT, get_ext_list(global_type)"");
  526.          set_dialog_item(handle, IDE_PAIRS, DAC_EDIT_TEXT, MatchingPairs(global_type)"");
  527.          if (global_type == "[None]")
  528.          {
  529.             set_dialog_item( handle, IDB_CHG_COMP, DAC_DISABLE )
  530.             set_dialog_item( handle, IDB_CPY_COMP, DAC_DISABLE )
  531.             set_dialog_item( handle, IDB_DEL_COMP, DAC_DISABLE )
  532.          }
  533.          else
  534.          {
  535.             set_dialog_item( handle, IDB_CHG_COMP, DAC_ENABLE )
  536.             set_dialog_item( handle, IDB_CPY_COMP, DAC_ENABLE )
  537.             set_dialog_item( handle, IDB_DEL_COMP, DAC_ENABLE )
  538.          }
  539.          ret_msg = DRC_MSG_PROCESSED;
  540.       }
  541.    }
  542.    else if(callback_msg == DM_KILL_FOCUS)
  543.    {
  544.       if(callback_index == IDE_PAIRS)
  545.       {
  546.          set_pairs(global_type, query_dialog_item(handle, IDE_PAIRS, DAC_EDIT_TEXT));
  547.          nbPagePrefix[current_nb_page].modified = TRUE;
  548.          ret_msg = DRC_MSG_PROCESSED;
  549.       }
  550.       else if(callback_index == IDE_EXTENSIONS)
  551.       {
  552.          list = query_dialog_item(handle, IDE_EXTENSIONS, DAC_EDIT_TEXT);
  553.          validate_ext_list(global_type, list);
  554.          list = get_ext_list(global_type);
  555.          set_dialog_item(handle, IDE_EXTENSIONS, DAC_EDIT_TEXT, list"");
  556.          nbPagePrefix[current_nb_page].modified = TRUE;
  557.          ret_msg = DRC_MSG_PROCESSED;
  558.       }
  559.    }
  560.    return ret_msg;
  561. }
  562.  
  563. global function compiler_settings_callback()
  564. {
  565.    local name, ext, new_name, value, file, state, err_format, cmd_line;
  566.    local advanced_dialog;
  567.    local ret_msg = DRC_CONTINUE;
  568.    local handle  = callback_dialog_handle;
  569.  
  570.    enable_undo(callback_dialog_handle, callback_index);
  571.  
  572.    if(nb_initializing)
  573.       ret_msg = DRC_MSG_PROCESSED;
  574.    else if(callback_msg == DM_HELPREQUESTED)
  575.    {
  576.       display_help(nbPagePrefix[current_nb_page].help, handle);
  577.       ret_msg = DRC_MSG_PROCESSED;
  578.    }
  579.    else if ( callback_msg == DM_CANCEL )
  580.    {
  581.        ret_msg = DRC_MSG_PROCESSED;
  582.    }
  583.    else if((callback_msg == DM_CLICK) || (callback_msg == DM_DOUBLE_CLICK))
  584.    {
  585.       if(callback_index == IDB_UNDO)
  586.       {
  587.          compilers = copy_compilers_array(save_compilers);
  588.          initialize_compiler_settings(handle);
  589.          ret_msg = DRC_MSG_PROCESSED;
  590.       }
  591.       else if ( callback_index == IDB_DEFAULT  ) 
  592.       {
  593.          #  Load factory default settings that cannot be changed by the user;
  594.          load_factory_default_compilers();
  595.          initialize_compiler_settings(handle)
  596.          nbPagePrefix[current_nb_page].modified = TRUE;
  597.          ret_msg = DRC_MSG_PROCESSED;
  598.       }
  599.       else if(callback_index == IDB_ADVANCED)
  600.       {
  601.          advanced_dialog = create_dialog( function_id("advanced_compilers_callback"), handle, IDD_ADVANCED_COMPILER_SETTINGS );
  602.          if ( advanced_dialog )
  603.          {
  604.             local_compiler = query_dialog_item(handle, IDL_COMPILER, DAC_SELECT_ITEM);
  605.             initialize_advanced_compilers_dialog(advanced_dialog, local_compiler);
  606.             attach_help(editor_helpfile, advanced_dialog);
  607.             begin_dialog(advanced_dialog);
  608.          }
  609.          ret_msg = DRC_MSG_PROCESSED;
  610.       }
  611.       else if (callback_index == IDB_ADD_COMP )
  612.       {
  613.          set_status_bar_flags( and(status_bar_flags, not(STB_PROMPTS)))
  614.          name = prompt_history("COMPILER", "Enter new compiler :", name, 1, 1, "compiler_name_prompt" );
  615.          restore_status_bar();
  616.          set_dialog_item(handle, IDL_COMPILER, DAC_SETFOCUS);
  617.  
  618.          if(!(name in compilers))
  619.          {
  620.             cmd_line   = "$<"
  621.             err_format = "[None]"
  622.             add_compiler(name, cmd_line, "none");
  623.             set_dialog_item(handle, IDL_COMPILER, DAC_ADD_ITEM, name);
  624.          }
  625.          else
  626.          {
  627.             cmd_line   = CommandLine(name)
  628.             err_format = ErrorFormat(name)
  629.             if(!err_format || err_format == "none")
  630.                 err_format = "[None]"
  631.          }
  632.          nbPagePrefix[current_nb_page].modified = TRUE;
  633.  
  634.          set_dialog_item(handle, IDL_COMPILER,     DAC_SELECT_ITEM, name "");
  635.          set_dialog_item(handle, IDE_COMMAND_LINE, DAC_EDIT_TEXT,   cmd_line "");
  636.          set_dialog_item(handle, IDL_ERROR,        DAC_SELECT_ITEM, err_format);
  637.          ret_msg = DRC_MSG_PROCESSED;
  638.       }
  639.       else if ( callback_index == IDB_DEL_COMP )
  640.       {
  641.          name = query_dialog_item(handle, IDL_COMPILER, DAC_SELECT_ITEM);
  642.          if(name)
  643.          {
  644.             delete_compiler(name);
  645.  
  646.             set_dialog_item(handle, IDL_COMPILER, DAC_DELETE_ITEM, name);
  647.             set_dialog_item(handle, IDL_COMPILER, DAC_SELECT_ITEM, "[None]");
  648.             #set_dialog_item(handle, IDB_CHG_COMP, DAC_DISABLE);
  649.             #set_dialog_item(handle, IDB_CPY_COMP, DAC_DISABLE);
  650.             #set_dialog_item(handle, IDB_DEL_COMP, DAC_DISABLE);
  651.             nbPagePrefix[current_nb_page].modified = TRUE;
  652.          }
  653.  
  654.          ret_msg = DRC_MSG_PROCESSED;
  655.       }
  656.       else if ( callback_index == IDB_CHG_COMP )
  657.       {
  658.          name = query_dialog_item(handle, IDL_COMPILER, DAC_SELECT_ITEM);
  659.          if(name)
  660.          {
  661.             set_status_bar_flags( and(status_bar_flags, not(STB_PROMPTS)));
  662.             new_name = prompt_history("COMPILER", "Change compiler name:", name, 1, 1, "compiler_name_prompt" );
  663.             restore_status_bar();
  664.             
  665.             if(new_name && (new_name != name))
  666.             {
  667.                copy_compiler(name, new_name);
  668.                delete_compiler(name);
  669.                set_dialog_item(handle, IDL_COMPILER, DAC_DELETE_ITEM, name);
  670.                set_dialog_item(handle, IDL_COMPILER, DAC_ADD_ITEM, new_name);
  671.                nbPagePrefix[current_nb_page].modified = TRUE;
  672.             }
  673.             set_dialog_item(handle, IDL_COMPILER, DAC_SELECT_ITEM, new_name);
  674.          }
  675.          ret_msg = DRC_MSG_PROCESSED;
  676.       }
  677.       else if ( callback_index == IDB_CPY_COMP )
  678.       {
  679.          name = query_dialog_item(handle, IDL_COMPILER, DAC_SELECT_ITEM);
  680.          set_status_bar_flags( and(status_bar_flags, not(STB_PROMPTS)));
  681.          new_name = prompt_history("COMPILER", "Enter compiler name to copy to:", name, 1, 1, "compiler_name_prompt" );
  682.          restore_status_bar();
  683.  
  684.          if(new_name && (new_name != name))  #  only do the copy if user entered a new name;
  685.          {
  686.             copy_compiler(name, new_name);
  687.             set_dialog_item(handle, IDL_COMPILER, DAC_ADD_ITEM, new_name);
  688.             set_dialog_item(handle, IDL_COMPILER, DAC_SELECT_ITEM, new_name);
  689.             nbPagePrefix[current_nb_page].modified = TRUE;
  690.          }
  691.          ret_msg = DRC_MSG_PROCESSED;
  692.       }
  693.    }
  694.    else if ( callback_msg == DM_SELECT )
  695.    {
  696.       if(callback_index == IDL_TYPE)
  697.       {
  698.          global_type = query_dialog_item(handle, IDL_TYPE, DAC_SELECT_ITEM);
  699.          name = CompilerName(global_type);
  700.          if(name in compilers)
  701.             set_dialog_item(handle, IDL_COMPILER, DAC_SELECT_ITEM, name);
  702.          else
  703.             set_dialog_item(handle, IDL_COMPILER, DAC_SELECT_ITEM, "[None]");
  704.          ret_msg = DRC_MSG_PROCESSED;
  705.       }
  706.       else if(callback_index == IDL_COMPILER)
  707.       {
  708.          #  type = query_dialog_item(handle, IDL_TYPE,     DAC_SELECT_ITEM);
  709.          name = query_dialog_item(handle, IDL_COMPILER, DAC_SELECT_ITEM);
  710.  
  711.          set_compiler_name(global_type, name);
  712.          if(name in compilers)
  713.             set_compiler(handle, global_type, name)
  714.          else
  715.          {
  716.             set_dialog_item(handle, IDL_COMPILER,     DAC_SELECT_ITEM, "[None]")
  717.             set_dialog_item(handle, IDE_COMMAND_LINE, DAC_EDIT_TEXT,   "[None]")
  718.             set_dialog_item(handle, IDL_ERROR,        DAC_SELECT_ITEM, "[None]")
  719.             set_dialog_item(handle, IDE_OTHER,        DAC_EDIT_TEXT,   "")
  720.          }
  721.          set_dialog_item(handle, IDB_CHG_COMP,     DAC_ENABLE )
  722.          set_dialog_item(handle, IDB_CPY_COMP,     DAC_ENABLE )
  723.          if(name != "[None]")
  724.             set_dialog_item(handle, IDB_DEL_COMP,  DAC_ENABLE )
  725.          else
  726.             set_dialog_item(handle, IDB_DEL_COMP,  DAC_DISABLE )
  727.  
  728.          nbPagePrefix[current_nb_page].modified = TRUE;
  729.          ret_msg = DRC_MSG_PROCESSED;
  730.       }
  731.       else if(callback_index == IDL_ERROR)
  732.       {
  733.          name = query_dialog_item(handle, IDL_COMPILER, DAC_SELECT_ITEM)
  734.          if (name in compilers)
  735.          {
  736.             value = query_dialog_item(handle, IDL_ERROR, DAC_SELECT_ITEM);
  737.             if(value != "other")
  738.             {
  739.                set_dialog_item(handle, IDE_OTHER,           DAC_DISABLE);
  740.                set_dialog_item(handle, IDT_BUFFER_DEF_TEXT, DAC_DISABLE);
  741.                set_error_format(name, (value == "[None]") ? "none" : value);
  742.             }
  743.             else
  744.             {
  745.                set_dialog_item(handle, IDE_OTHER,           DAC_ENABLE);
  746.                set_dialog_item(handle, IDT_BUFFER_DEF_TEXT, DAC_ENABLE);
  747.                set_error_format(name, "other," query_dialog_item(handle, IDE_OTHER, DAC_EDIT_TEXT));
  748.             }
  749.             nbPagePrefix[current_nb_page].modified = TRUE;
  750.          }
  751.          ret_msg = DRC_MSG_PROCESSED;
  752.       }
  753.    }
  754.    else if(callback_msg == DM_KILL_FOCUS)
  755.    {
  756.       if(callback_index == IDE_COMMAND_LINE)
  757.       {
  758.          name = query_dialog_item(handle, IDL_COMPILER, DAC_SELECT_ITEM)
  759.          if (name in compilers)
  760.          {
  761.             value = query_dialog_item(handle, IDE_COMMAND_LINE, DAC_EDIT_TEXT);
  762.             set_command_line(name, value);
  763.             nbPagePrefix[current_nb_page].modified = TRUE;
  764.          }
  765.          ret_msg = DRC_MSG_PROCESSED;
  766.       }
  767.       else if(callback_index == IDE_OTHER)
  768.       {
  769.          name = query_dialog_item(handle, IDL_COMPILER, DAC_SELECT_ITEM)
  770.          if (name in compilers)
  771.          {
  772.             value = query_dialog_item(handle, IDE_OTHER, DAC_EDIT_TEXT);
  773.             set_error_format(name, "other," value);
  774.             nbPagePrefix[current_nb_page].modified = TRUE;
  775.          }
  776.          ret_msg = DRC_MSG_PROCESSED;
  777.       }
  778.    }
  779.    return ret_msg;
  780. }
  781.  
  782. global function initialize_advanced_compilers_dialog(handle, name)
  783. {
  784.    local input      = CompilerInput(name);
  785.    local save       = CompilerSaveAll(name);
  786.    local output     = CompilerOutput(name);
  787.    local background = CompilerBackground(name);
  788.    local flags      = CompilerFlags(name);
  789.    local chgdir     = CompilerChdir(name);
  790.    local file;
  791.  
  792.    file  = (input+0 < 0) ? "" : input"";
  793.    input = (length(file) > 0);
  794.    file  = (file+0 == 1) ? "" : file;
  795.  
  796.    if(input)
  797.    {
  798.       set_dialog_item(handle, IDC_NEEDS_INPUT, DAC_CHECK);
  799.       set_dialog_item(handle, IDE_INPUT_FILE,  DAC_EDIT_TEXT, file"");
  800.    }
  801.    else
  802.    {
  803.       set_dialog_item(handle, IDC_NEEDS_INPUT, DAC_UNCHECK);
  804.       set_dialog_item(handle, IDE_INPUT_FILE,  DAC_DISABLE);
  805.    }
  806.  
  807.    if(save)
  808.       set_dialog_item(handle, IDC_SAVE_ALL, DAC_CHECK);
  809.    else
  810.       set_dialog_item(handle, IDC_SAVE_ALL, DAC_UNCHECK);
  811.  
  812.    if(output)
  813.       set_dialog_item(handle, IDC_LIST_ALL, DAC_CHECK);
  814.    else
  815.       set_dialog_item(handle, IDC_LIST_ALL, DAC_UNCHECK);
  816.  
  817.    if(chgdir)
  818.       set_dialog_item(handle, IDC_CHDIR, DAC_CHECK);
  819.    else
  820.       set_dialog_item(handle, IDC_CHDIR, DAC_UNCHECK);
  821.  
  822.    if(background)
  823.       set_dialog_item(handle, IDC_BACKGROUND, DAC_CHECK);
  824.    else
  825.       set_dialog_item(handle, IDC_BACKGROUND, DAC_UNCHECK);
  826.  
  827.    if (flags > 0)
  828.    {
  829.       if(and(flags, SYS_SESSION))
  830.          set_dialog_item(handle, IDC_SESSION, DAC_CHECK);
  831.       else
  832.          set_dialog_item(handle, IDC_SESSION, DAC_UNCHECK);
  833.  
  834.       if(and(flags, SYS_SHELL))
  835.          set_dialog_item(handle, IDC_SHELL, DAC_CHECK);
  836.       else
  837.          set_dialog_item(handle, IDC_SHELL, DAC_UNCHECK);
  838.  
  839.       if(and(flags, SYS_DOSSHELL))
  840.       {
  841.          set_dialog_item(handle, IDC_DOSSHELL,     DAC_CHECK);
  842.          set_dialog_item(handle, IDB_DOS_SETTINGS, DAC_ENABLE);
  843.       }
  844.       else
  845.       {
  846.          set_dialog_item(handle, IDC_DOSSHELL,     DAC_UNCHECK);
  847.          set_dialog_item(handle, IDB_DOS_SETTINGS, DAC_DISABLE);
  848.       }
  849.    }
  850.    else
  851.    {
  852.       set_dialog_item(handle, IDC_SHELL,         DAC_UNCHECK);
  853.       set_dialog_item(handle, IDC_DOSSHELL,      DAC_UNCHECK);
  854.       set_dialog_item(handle, IDC_SESSION,       DAC_UNCHECK);
  855.       set_dialog_item(handle, IDB_DOS_SETTINGS,  DAC_DISABLE);
  856.    }
  857. }
  858.  
  859. global function advanced_compilers_callback()
  860. {
  861.    local dos_settings_dialog
  862.    local shell, dos, session, flags
  863.    local state, file, ret_msg = DRC_CONTINUE;
  864.    local handle = callback_dialog_handle;
  865.  
  866.    if(nb_initializing)
  867.    {
  868.       ret_msg = DRC_MSG_PROCESSED;
  869.    }
  870.    else if(callback_msg == DM_HELPREQUESTED)
  871.    {
  872.       if(isWindows())
  873.          display_help("Advanced Compilers", handle);
  874.       else
  875.          display_help("advcomp", handle);
  876.  
  877.       ret_msg = DRC_MSG_PROCESSED;
  878.    }
  879.    else if ( callback_msg == DM_CANCEL )
  880.    {
  881.       ret_msg = DRC_EXIT;
  882.    }
  883.    else if ( callback_msg == DM_OK )
  884.    {
  885.       file  = query_dialog_item(handle, IDE_INPUT_FILE,  DAC_EDIT_TEXT);
  886.       state = query_dialog_item(handle, IDC_NEEDS_INPUT, DAC_CHECK );
  887.       set_compiler_input(local_compiler, state, file);
  888.  
  889.       state = query_dialog_item(handle, IDC_SAVE_ALL, DAC_CHECK );
  890.       set_compiler_save_all(local_compiler, state);
  891.  
  892.       state = query_dialog_item(handle, IDC_LIST_ALL, DAC_CHECK );
  893.       set_compiler_output(local_compiler, state);
  894.  
  895.       state = query_dialog_item(handle, IDC_CHDIR, DAC_CHECK );
  896.       set_compiler_chdir(local_compiler, state);
  897.  
  898.       state = query_dialog_item(handle, IDC_BACKGROUND, DAC_CHECK );
  899.       set_compiler_background(local_compiler, state);
  900.  
  901.       dos     = query_dialog_item(handle, IDC_DOSSHELL, DAC_CHECK );
  902.       shell   = query_dialog_item(handle, IDC_SHELL,    DAC_CHECK );
  903.       session = query_dialog_item(handle, IDC_SESSION,  DAC_CHECK );
  904.       flags   = (SYS_DOSSHELL * dos) + (SYS_SHELL * shell) + \
  905.                 (SYS_SESSION  * session)
  906.       set_compiler_flags(local_compiler, flags);
  907.  
  908.       nbPagePrefix[current_nb_page].modified = TRUE;
  909.       ret_msg = DRC_EXIT;
  910.    }
  911.    else if((callback_msg == DM_CLICK) || (callback_msg == DM_DOUBLE_CLICK))
  912.    {
  913.       if ( callback_index == IDC_NEEDS_INPUT )
  914.       {
  915.          state = query_dialog_item(handle, IDC_NEEDS_INPUT, DAC_CHECK );
  916.          set_dialog_item(handle, IDE_INPUT_FILE,
  917.                          state ? DAC_ENABLE : DAC_DISABLE)
  918.          ret_msg = DRC_MSG_PROCESSED;
  919.       }
  920.       else if( callback_index == IDC_DOSSHELL)
  921.       {
  922.          state = query_dialog_item(handle, IDC_DOSSHELL, DAC_CHECK );
  923.          set_dialog_item(handle, IDB_DOS_SETTINGS,
  924.                          state ? DAC_ENABLE : DAC_DISABLE)
  925.          ret_msg = DRC_MSG_PROCESSED;
  926.       }
  927.       else if( callback_index ==  IDB_DOS_SETTINGS)
  928.       {
  929.          dos_settings_dialog = create_dialog( function_id("dos_settings_callback"), handle, IDD_DOS_SETTINGS_DIALOG );
  930.          if ( dos_settings_dialog )
  931.          {
  932.             initialize_dos_settings_dialog(dos_settings_dialog, local_compiler);
  933.             attach_help(editor_helpfile, dos_settings_dialog);
  934.             begin_dialog(dos_settings_dialog);
  935.          }
  936.          ret_msg = DRC_MSG_PROCESSED;
  937.       }
  938.       else if( callback_index == IDC_SAVE_ALL )
  939.          ret_msg = DRC_MSG_PROCESSED;
  940.    }
  941.    else if(callback_msg == DM_KILL_FOCUS)
  942.    {
  943.       if(callback_index == IDE_INPUT_FILE)
  944.          ret_msg = DRC_MSG_PROCESSED;
  945.    }
  946.  
  947.    return ret_msg;
  948. }
  949.  
  950. global function initialize_dos_settings_dialog(handle, name)
  951. {
  952.    local s
  953.  
  954.    dos_settings_array = CompilerDOSSettingsArray(name);
  955.  
  956.    add_dialog_item(handle, IDE_VALUE, DCTRL_EDIT);
  957.    set_dialog_item(handle, IDE_VALUE, DAC_SET_TEXT_LEN, 255);
  958.  
  959.    add_dialog_item(handle, IDL_SETTINGS, DCTRL_COMBO_BOX);
  960.    for (s in dos_settings_array)
  961.       set_dialog_item(handle, IDL_SETTINGS, DAC_ADD_ITEM, s);
  962. }
  963.  
  964. global function dos_settings_callback()
  965. {
  966.    local setting, value
  967.    local ret_msg = DRC_CONTINUE;
  968.    local handle  = callback_dialog_handle;
  969.  
  970.    if(nb_initializing)
  971.    {
  972.       ret_msg = DRC_MSG_PROCESSED;
  973.    }
  974.    else if(callback_msg == DM_HELPREQUESTED)
  975.    {
  976.       display_help("dossettings", handle);
  977.       ret_msg = DRC_MSG_PROCESSED;
  978.    }
  979.    else if ( callback_msg == DM_CANCEL )
  980.    {
  981.       ret_msg = DRC_EXIT;
  982.    }
  983.    else if ( callback_msg == DM_OK )
  984.    {
  985.       set_compiler_dos_settings_array(local_compiler, dos_settings_array)
  986.       ret_msg = DRC_EXIT;
  987.    }
  988.    else if ( callback_msg == DM_SELECT )
  989.    {
  990.       if(callback_index == IDL_SETTINGS)
  991.       {
  992.          setting = query_dialog_item(handle, IDL_SETTINGS, DAC_SELECT_ITEM);
  993.          set_dialog_item(handle, IDE_VALUE, DAC_EDIT_TEXT, dos_settings_array[setting] "")
  994.       }
  995.    }
  996.    else if((callback_msg == DM_CLICK) || (callback_msg == DM_DOUBLE_CLICK))
  997.    {
  998.       if ( callback_index == IDB_ADD_SETTING )
  999.       {
  1000.          setting = query_dialog_item(handle, IDL_SETTINGS, DAC_EDIT_TEXT);
  1001.          value   = query_dialog_item(handle, IDE_VALUE,    DAC_EDIT_TEXT);
  1002.          if (length(setting) && length(value))
  1003.          {
  1004.             dos_settings_array[setting] = value
  1005.             set_dialog_item(handle, IDL_SETTINGS, DAC_TEXT,      "");
  1006.             set_dialog_item(handle, IDE_VALUE,    DAC_EDIT_TEXT, "");
  1007.  
  1008.             if (query_dialog_item(handle, IDL_SETTINGS, DAC_FIND, setting) < 0)
  1009.                set_dialog_item(handle, IDL_SETTINGS, DAC_ADD_ITEM,  setting);
  1010.          }
  1011.          ret_msg = DRC_MSG_PROCESSED;
  1012.       }
  1013.       else if ( callback_index == IDB_DELETE_SETTING )
  1014.       {
  1015.          setting = query_dialog_item(handle, IDL_SETTINGS, DAC_EDIT_TEXT);
  1016.          if (length(setting))
  1017.          {
  1018.             dos_settings_array[setting] = ""
  1019.             delete dos_settings_array[setting]
  1020.             set_dialog_item(handle, IDL_SETTINGS, DAC_DELETE_ITEM,  setting);
  1021.             set_dialog_item(handle, IDL_SETTINGS, DAC_TEXT,         "");
  1022.             set_dialog_item(handle, IDE_VALUE,    DAC_EDIT_TEXT,    "");
  1023.          }
  1024.          ret_msg = DRC_MSG_PROCESSED;
  1025.       }
  1026.    }
  1027.    return ret_msg;
  1028. }
  1029.  
  1030. global function template_settings_callback()
  1031. {
  1032.    local ret_msg = DRC_CONTINUE, value, type, name;
  1033.    local handle = callback_dialog_handle;
  1034.  
  1035.    enable_undo(callback_dialog_handle, callback_index);
  1036.    if(callback_msg == DM_HELPREQUESTED)
  1037.    {
  1038.       display_help(nbPagePrefix[current_nb_page].help, callback_dialog_handle);
  1039.       ret_msg = DRC_MSG_PROCESSED;
  1040.    }
  1041.    else if ( callback_msg == DM_CANCEL )
  1042.    {
  1043.       nbPagePrefix[current_nb_page].modified = FALSE;
  1044.       ret_msg = DRC_MSG_PROCESSED;
  1045.    }
  1046.    else if((callback_msg == DM_CLICK) || (callback_msg == DM_DOUBLE_CLICK))
  1047.    {
  1048.       if(callback_index == IDB_UNDO)
  1049.       {
  1050.          #  Undo the changes that could have been made on this page;
  1051.          undo_template_settings();
  1052.          initialize_template_settings(handle);
  1053.          nbPagePrefix[current_nb_page].modified = FALSE;
  1054.          ret_msg = DRC_MSG_PROCESSED;
  1055.       }
  1056.       else if ( callback_index == IDB_DEFAULT  ) 
  1057.       {  #  TODO this looks too severe
  1058.          load_factory_default_types();
  1059.          initialize_template_settings(handle)
  1060.          nbPagePrefix[current_nb_page].modified = TRUE;
  1061.          ret_msg = DRC_MSG_PROCESSED;
  1062.       }
  1063.       else if(callback_index == IDC_EXPANSION)
  1064.       {
  1065.          value = query_dialog_item(handle, IDC_EXPANSION, DAC_CHECK);
  1066.          set_expand_template(global_type, value);
  1067.  
  1068.          nbPagePrefix[current_nb_page].modified = TRUE;
  1069.          ret_msg = DRC_MSG_PROCESSED;
  1070.       }
  1071.    }
  1072.    else if ( callback_msg == DM_SELECT )
  1073.    {
  1074.       if(callback_index == IDL_TYPE)
  1075.       {
  1076.          type = query_dialog_item(handle, IDL_TYPE, DAC_SELECT_ITEM);
  1077.          global_type = type;
  1078.          name = Template(type);
  1079.          if(name in templates)
  1080.             set_dialog_item(handle, IDL_TEMPLATE,     DAC_SELECT_ITEM, name);
  1081.          else
  1082.             set_dialog_item(handle, IDL_TEMPLATE,  DAC_SELECT_ITEM, "[None]");
  1083.  
  1084.          if(get_expand_template(global_type))
  1085.             set_dialog_item(handle, IDC_EXPANSION, DAC_CHECK);
  1086.          else
  1087.             set_dialog_item(handle, IDC_EXPANSION, DAC_UNCHECK);
  1088.  
  1089.          ret_msg = DRC_MSG_PROCESSED;
  1090.       }
  1091.       else if(callback_index == IDL_TEMPLATE)
  1092.       {
  1093.          type = query_dialog_item(handle, IDL_TYPE,     DAC_SELECT_ITEM);
  1094.          name = query_dialog_item(handle, IDL_TEMPLATE, DAC_SELECT_ITEM);
  1095.  
  1096.          set_template(type, name);
  1097.          nbPagePrefix[current_nb_page].modified = TRUE;
  1098.          ret_msg = DRC_MSG_PROCESSED;
  1099.       }
  1100.    }
  1101.    return ret_msg;
  1102. }
  1103.  
  1104.  
  1105. ###############################################################################
  1106. #  
  1107. #  Extension Settings Undo functions
  1108. #  
  1109. ###############################################################################
  1110. local function undo_ext_settings(type)
  1111. {
  1112.    local list;
  1113.  
  1114.    if(type in languages)
  1115.    {
  1116.       list = get_ext_list(type, TRUE);
  1117.       validate_ext_list(type, list);
  1118.       set_pairs(type, save_languages[type].matching_pairs);
  1119.    }
  1120. }
  1121.  
  1122. local function undo_template_settings(type)
  1123. {
  1124.    if(type in languages)
  1125.    {
  1126.       languages[type].template = save_languages[type].template;
  1127.       languages[type].expand   = save_languages[type].expand;
  1128.    }
  1129. }
  1130.  
  1131. global function undo_extension_section_settings()
  1132. {
  1133.    local type;
  1134.  
  1135.    if(save_extensions)
  1136.       extensions = copy_extensions_array(save_extensions);
  1137.  
  1138.    if(save_compilers)
  1139.       compilers = copy_compilers_array(save_compilers);
  1140.  
  1141.    if(save_languages)
  1142.       languages = copy_languages_array(save_languages);
  1143.  
  1144.    for(type in syntax_loaded)
  1145.    {
  1146.       #  This removes all types that were loaded while notebook was up;
  1147.       if(syntax_loaded[type] == 23)
  1148.          delete syntax_loaded[type];
  1149.    }
  1150. }
  1151.  
  1152. ########################## COMPILER SETTINGS DIALOG ##########################
  1153.  
  1154. global function ext_apply_to_all()
  1155. {
  1156.    local ext
  1157.    local first_buf = current_buffer
  1158.    local sentinel = next_buffer("", 0, 1)
  1159.  
  1160.    # Apply to all buffers.   
  1161.    do
  1162.    {
  1163.       ext = path_ext(buffer_name)
  1164.  
  1165.       if(ext in extensions)
  1166.       {  
  1167.          if(Tabs(ext))
  1168.             buffer_tabs = Tabs(ext);
  1169.  
  1170.          if(Margins(ext))
  1171.          {
  1172.             wp_left_margin  = LeftMargin(ext);
  1173.             wp_right_margin = RightMargin(ext);
  1174.          }
  1175.          
  1176.          #  buffer_flags = BufferFlags(ext);
  1177.       }
  1178.    }
  1179.    while( next_buffer("", 0, 1) != sentinel )
  1180.  
  1181.    current_buffer = first_buf
  1182. }
  1183.  
  1184. #global function template_apply_to_all()
  1185. #{
  1186. #   nop();
  1187. #}
  1188.  
  1189. global function get_ext_list(type, in_save)
  1190. {
  1191.    local ext, result = "";
  1192.  
  1193.    if(in_save)
  1194.    {
  1195.       for(ext in save_extensions)
  1196.       {
  1197.          if(save_extensions[ext] == type)
  1198.             result = result ext " ";
  1199.       }
  1200.    }
  1201.    else
  1202.    {
  1203.       for(ext in extensions)
  1204.       {
  1205.          if(Type(ext) == type)
  1206.             result = result ext " ";
  1207.       }
  1208.    }
  1209.  
  1210.    return result;
  1211. }
  1212.  
  1213. global function validate_ext_list(type, list)
  1214. {
  1215.    local array, ext, i;
  1216.  
  1217.  
  1218.    #  This loop removes all extensions mapped to "type";
  1219.    for(ext in extensions)
  1220.    {
  1221.       if(Type(ext) == type)
  1222.          delete extensions[ext];
  1223.    }
  1224.  
  1225.    split(list, array);
  1226.  
  1227.    #  This loop maps all extensions in array to "type";
  1228.    for(i in array)
  1229.    {
  1230.       ext = (prefix(array[i], 1) == ".") ? array[i] : "."array[i];
  1231.       SetType(ext, type);
  1232.    }
  1233. }
  1234.  
  1235. local function propogate_type()
  1236. {
  1237.    local page, dlgid, page_name;
  1238.  
  1239.    for(page in nbPagePrefix)
  1240.    {
  1241.       dlgid = nbPagePrefix[page].dialog_handle
  1242.       if(dlgid)
  1243.       {
  1244.          page_name = nbPagePrefix[page].name;
  1245.  
  1246.          if((page_name == "compiler") || (page_name == "syntax") ||(page_name == "template"))
  1247.             init_types(dlgid);
  1248.          else if((page_name == "buffer1") || (page_name == "buffer2") || (page_name == "buffer3"))
  1249.             init_types(dlgid, 1);
  1250.       }
  1251.    }
  1252. }
  1253.  
  1254. ################# SYNTAX HIGHLIGHTING SETTINGS NOTEBOOK PAGE ########################
  1255. local IDV_FOREGROUND    = 101
  1256. local IDV_BACKGROUND    = 105
  1257. local IDC_DEFAULT_FG    = 104
  1258. local IDC_DEFAULT_BG    = 107
  1259. local IDB_ADVANCEDITEMS = 103
  1260. local IDD_ADVANCED_ITEM_SETTINGS = 1091
  1261. local IDE_ESCAPE_CHAR     = 102;
  1262. local IDB_CATEGORY_COLOR  = 110
  1263. local IDB_ITEM_COLOR      = 105
  1264.  
  1265. local IDD_SYNTAX_COLOR   = 1700
  1266. local IDB_CUSTOM         = 106
  1267.  
  1268. local IDD_NEW_SYTNAX_IC = 1701
  1269.  
  1270. local IDD_CONFIGURE_COLOR = 1702
  1271. local IDS_CATEGORY        = 103
  1272. local IDS_CATEGORY_COLOR  = 108;
  1273. local IDS_ITEM_COLOR      = 104;
  1274. local IDS_USING_CAT       = 111;
  1275. local IDS_USING_ITEM      = 101;
  1276.  
  1277. local IDC_CASE_SENSITIVE  = 109;
  1278. local IDR_KEYWORD         = 116;
  1279. local IDR_LINE            = 113;
  1280. local IDR_BLOCK           = 115;
  1281.  
  1282. local local_iscat    = FALSE;   #  global variables set before callbacks are 
  1283. local local_item     = FALSE;   #  called so i have access to these values.
  1284. local local_cat      = FALSE;
  1285. local local_catname  = FALSE;
  1286. local local_add      = FALSE;
  1287. local local_fgind    = FALSE;
  1288. local local_bgind    = FALSE;
  1289. local mini_storage[];
  1290. local names_added[]
  1291.  
  1292. global function create_syntax_page(pageid, dlgid)
  1293. {
  1294.    local row, col, dhandle, color;
  1295.  
  1296.    dhandle = create_page(function_id( "syntax_settings_callback" ), 
  1297.                                dlgid, IDD_SYNTAX_SETTINGS, resource_dll)
  1298.  
  1299.    attach_help(editor_helpfile, dhandle)
  1300.    if(isWindows())
  1301.       nbPagePrefix[pageid].help = "Extension Settings";
  1302.    else
  1303.       nbPagePrefix[pageid].help = "colorspage";
  1304.  
  1305.    if(!save_languages)
  1306.       save_languages = copy_languages_array(languages);
  1307.  
  1308.    set_dialog_item(dhandle, IDL_TYPE,     DAC_SORT_ASCENDING);
  1309.    set_dialog_item(dhandle, IDL_ITEMS,    DAC_SORT_ASCENDING);
  1310.    set_dialog_item(dhandle, IDL_CATEGORY, DAC_SORT_ASCENDING);
  1311.    add_dialog_item(dhandle, IDE_ESCAPE_CHAR, DCTRL_EDIT);
  1312.    add_dialog_item(dhandle, IDE_WORD_DELIMITER, DCTRL_EDIT);
  1313.    set_dialog_item(dhandle, IDE_ESCAPE_CHAR, DAC_SET_TEXT_LEN, 1);
  1314.  
  1315.    add_dialog_item(dhandle, IDR_KEYWORD, DCTRL_RADIO_BUTTON);
  1316.    add_dialog_item(dhandle, IDR_LINE, DCTRL_RADIO_BUTTON);
  1317.    add_dialog_item(dhandle, IDR_BLOCK, DCTRL_RADIO_BUTTON);
  1318.  
  1319.    set_notebook_page_dialog(dlgid, pageid, dhandle);
  1320.    initialize_syntax_settings( dhandle, "dummy" , 1 );
  1321.    nbPagePrefix[pageid].dialog_handle = dhandle;
  1322. }
  1323.  
  1324. global function initialize_syntax_settings( handle, dummy, load_types )
  1325. {
  1326.    local type, item;
  1327.  
  1328. #     nb_initializing = TRUE;
  1329.  
  1330.    if(load_types)
  1331.       init_types(handle);
  1332.  
  1333.    add_dialog_item(handle, IDL_ITEMS, DCTRL_COMBO_BOX);
  1334.  
  1335.    type = (global_type ? global_type : Type(path_ext(buffer_filename)) "" );
  1336.    set_dialog_item(handle, IDL_TYPE, DAC_SELECT_ITEM, type "");
  1337.    if(query_dialog_item(handle, IDL_TYPE, DAC_SELECT_INDEX) < 0)
  1338.       set_dialog_item(handle, IDL_TYPE, DAC_SELECT_INDEX, 0);
  1339.  
  1340.    global_type = query_dialog_item(handle, IDL_TYPE, DAC_SELECT_ITEM) "";
  1341.  
  1342.    if(!(global_type in syntax_loaded))
  1343.    {
  1344.       if(!("__styles" in syntax_loaded))
  1345.       {
  1346.          optional_function("load_user_styles");
  1347.          syntax_loaded["__styles"] = TRUE;
  1348.       }
  1349.       optional_function("load_user_" global_type "_syntax");
  1350.       save_syntax_part(global_type);
  1351.       syntax_loaded[global_type] = 23;
  1352.    }
  1353.    init_category(handle, global_type);
  1354.    enable_buttons(handle);
  1355.    set_dialog_item(handle, IDE_WORD_DELIMITER, DAC_EDIT_TEXT, StyleDelimiters(global_type) "");
  1356.    set_dialog_item(handle, IDE_ESCAPE_CHAR,    DAC_EDIT_TEXT, EscapeCharacter(global_type) "");
  1357.  
  1358.    if(get_case_sensitive(global_type))
  1359.       set_dialog_item(handle, IDC_CASE_SENSITIVE, DAC_CHECK);
  1360.    else
  1361.       set_dialog_item(handle, IDC_CASE_SENSITIVE, DAC_UNCHECK);
  1362.  
  1363.    nb_initializing = FALSE;
  1364. }
  1365.  
  1366. local function init_category(handle, type)
  1367. {
  1368.    local item, array = Category(type), count;
  1369.  
  1370.    set_busy_cursor();
  1371.    set_dialog_item(handle, IDL_CATEGORY, DAC_TEXT, "");
  1372.    set_dialog_item(handle, IDL_CATEGORY, DAC_DELETE_ITEM);
  1373.    for(item in array)
  1374.    {
  1375.       set_dialog_item(handle, IDL_CATEGORY, DAC_ADD_ITEM, array[item].name "");
  1376.    }
  1377.  
  1378.    if(!set_dialog_item(handle, IDL_CATEGORY, DAC_SELECT_ITEM, "All"))
  1379.       init_items(handle, type)
  1380.  
  1381.    set_normal_cursor();
  1382. }
  1383.  
  1384. local function init_items(handle, type, category)
  1385. {
  1386.    local item, array[], count;
  1387.    
  1388.    array = Keyword(type);
  1389.  
  1390.    set_busy_cursor();
  1391.    
  1392.    set_dialog_item(handle, IDL_ITEMS, DAC_DELETE_ITEM);
  1393.    set_dialog_item(handle, IDL_ITEMS, DAC_TEXT, "");
  1394.  
  1395.    category += 0;
  1396.    for(item in array)
  1397.    {
  1398.       if(!category || ((Keyword(type, item, CATEGORY_MASK)+0) == category))
  1399.       {
  1400.          set_dialog_item(handle, IDL_ITEMS, DAC_ADD_ITEM, item "");
  1401.       }
  1402.    }
  1403.  
  1404.    array = Line(type);
  1405.    for(item in array)
  1406.    {
  1407.       if(!category || ((Line(type, item, CATEGORY_MASK)+0) == category))
  1408.       {
  1409.          set_dialog_item(handle, IDL_ITEMS, DAC_ADD_ITEM, item "");
  1410.       }
  1411.    }
  1412.  
  1413.    array = Block(type);
  1414.    for(item in array)
  1415.    {
  1416.       if(!category || ((Block(type, item, CATEGORY_MASK)+0) == category))
  1417.       {
  1418.          set_dialog_item(handle, IDL_ITEMS, DAC_ADD_ITEM, item "");
  1419.       }
  1420.    }
  1421.  
  1422.    if(query_dialog_item(handle, IDL_ITEMS, DAC_COUNT_ITEMS))
  1423.       set_dialog_item(handle, IDL_ITEMS, DAC_SELECT_INDEX, 0);
  1424.  
  1425.    set_normal_cursor();
  1426. }
  1427.  
  1428. local do_done = FALSE;
  1429. local assign_cats = FALSE;
  1430.  
  1431. global function syntax_settings_callback()
  1432. {
  1433.    local ret_msg = DRC_CONTINUE, name, style, cat, new_name, value, type, once;
  1434.    local handle = callback_dialog_handle, response, count, word, array;
  1435.    local dfg, dbg, fgval, bgval, advanced_dialog, color_dialog, catname;
  1436.  
  1437.    enable_undo(callback_dialog_handle, callback_index);
  1438.  
  1439.    if(nb_initializing)
  1440.       ret_msg = DRC_MSG_PROCESSED;
  1441.    else if(callback_msg == DM_HELPREQUESTED)
  1442.    {
  1443.       display_help(nbPagePrefix[current_nb_page].help, handle);
  1444.       ret_msg = DRC_MSG_PROCESSED;
  1445.    }
  1446.    else if ( callback_msg == DM_CANCEL )
  1447.    {
  1448.        ret_msg = DRC_MSG_PROCESSED;
  1449.    }
  1450.    else if((callback_msg == DM_CLICK) || (callback_msg == DM_DOUBLE_CLICK))
  1451.    {
  1452.       if(callback_index == IDB_UNDO)
  1453.       {
  1454.          undo_syntax_settings(global_type);
  1455.          set_modified(global_type, FALSE);
  1456.          initialize_syntax_settings(handle);
  1457.          ret_msg = DRC_MSG_PROCESSED;
  1458.       }
  1459.       else if ( callback_index == IDB_DEFAULT  ) 
  1460.       {
  1461.          #  Load factory default settings that cannot be changed by the user;
  1462.          value = function_id("load_factory_"global_type"_syntax");
  1463.          if(value)
  1464.          {
  1465.             reset_languages(0);
  1466.             set_keyword(global_type, FALSE);
  1467.             set_line(global_type, FALSE);
  1468.             set_block(global_type, FALSE);
  1469.             set_category(global_type);       #  one parameter to set_cat. deletes all categories
  1470.             delete save_styles[global_type];
  1471.             optional_function(value);
  1472.             reset_languages(1);
  1473.             initialize_syntax_settings(handle)
  1474.             set_modified(global_type, TRUE);
  1475.          }
  1476.          else
  1477.             warning("No factory defaults defined for type " global_type);
  1478.  
  1479.          ret_msg = DRC_MSG_PROCESSED;
  1480.       }
  1481.       else if(callback_index == IDB_DEL_COMP)
  1482.       {
  1483.          set_modified(global_type, TRUE);
  1484.          count = query_dialog_item(handle, IDL_ITEMS, DAC_COUNT_ITEMS);
  1485.          set_status_bar_flags( and(status_bar_flags, not(STB_PROMPTS)));
  1486.          response = confirm("Delete entire Category of " count " items? (Y/N):", "YyNn");
  1487.          restore_status_bar();
  1488.          if(tolower(response) == "y")
  1489.          {
  1490.             if(local_catname != "All")
  1491.             {
  1492.                set_dialog_item(handle, IDL_CATEGORY, DAC_DELETE_ITEM, local_catname"");
  1493.             }
  1494.             else
  1495.             {
  1496.                set_dialog_item(handle, IDL_ITEMS, DAC_DELETE_ITEM);
  1497.                set_dialog_item(handle, IDL_ITEMS, DAC_TEXT, "");
  1498.             }
  1499.  
  1500.             delete_category(global_type, local_cat);
  1501.             set_dialog_item(handle, IDL_CATEGORY, DAC_SELECT_ITEM, "All");
  1502.             enable_buttons(handle);
  1503.          }
  1504.  
  1505.          ret_msg = DRC_MSG_PROCESSED;
  1506.       }
  1507.       else if(callback_index == IDB_DEL_EXT)
  1508.       {
  1509.          set_modified(global_type, TRUE);
  1510.          set_status_bar_flags( and(status_bar_flags, not(STB_PROMPTS)));
  1511.          response = confirm("Delete item? (Y/N):", "YyNn");
  1512.          restore_status_bar();
  1513.          if(tolower(response) == "y")
  1514.          {
  1515.             delete_item(global_type, local_item);
  1516.             set_dialog_item(handle, IDL_ITEMS, DAC_DELETE_ITEM, local_item);
  1517.             set_dialog_item(handle, IDL_ITEMS, DAC_TEXT, "");
  1518.             set_dialog_item(handle, IDL_ITEMS, DAC_SELECT_INDEX, 0);
  1519.             enable_buttons(handle);
  1520.          }
  1521.  
  1522.          ret_msg = DRC_MSG_PROCESSED;
  1523.       }
  1524.       else if(callback_index == IDB_ADD_COMP)
  1525.       {
  1526.          set_busy_cursor()
  1527.  
  1528.          set_modified(global_type, TRUE);
  1529.          local_iscat = TRUE;
  1530.          local_add = TRUE;
  1531.          color_dialog = create_dialog( function_id("create_item_callback"), handle, IDD_NEW_SYTNAX_IC);
  1532.          initialize_select_color(color_dialog, global_type, 1, "", local_catname)
  1533.  
  1534.          set_normal_cursor()
  1535.  
  1536.          begin_dialog(color_dialog)
  1537.          if(do_done)
  1538.             do_done_processing();
  1539.          local_add = FALSE;
  1540.  
  1541.          set_dialog_item(handle, IDL_CATEGORY, DAC_DESELECT_ITEM);
  1542.  
  1543.          once = 1
  1544.  
  1545.          for ( cat in names_added )
  1546.          {
  1547.             set_dialog_item(handle, IDL_CATEGORY, DAC_ADD_ITEM, cat);
  1548.             set_dialog_item(handle, IDL_CATEGORY, DAC_SELECT_ITEM, cat);
  1549.             if ( once )
  1550.             {
  1551.                enable_buttons(handle);
  1552.                once = 0
  1553.             }
  1554.          }
  1555.  
  1556.          delete names_added
  1557.  
  1558.          names_added = 0
  1559.  
  1560.          ret_msg = DRC_MSG_PROCESSED;
  1561.       }
  1562.       else if(callback_index == IDB_ADD_EXT)
  1563.       {
  1564.          set_busy_cursor()
  1565.  
  1566.          set_modified(global_type, TRUE);
  1567.          local_iscat = FALSE;
  1568.          local_add = TRUE;
  1569.          color_dialog = create_dialog( function_id("create_item_callback"), handle, IDD_NEW_SYTNAX_IC);
  1570.          initialize_select_color(color_dialog, global_type, 0, "", local_catname);
  1571.  
  1572.          set_normal_cursor()
  1573.  
  1574.          begin_dialog(color_dialog)
  1575.          if(do_done)
  1576.             do_done_processing()
  1577.          local_add = FALSE;
  1578.          #  Force updated colors to take affect.
  1579.          once = 1
  1580.  
  1581.          for ( cat in names_added )
  1582.          {
  1583.             set_dialog_item(handle, IDL_ITEMS, DAC_ADD_ITEM, cat);
  1584.             set_dialog_item(handle, IDL_ITEMS, DAC_SELECT_ITEM, cat);
  1585.             if ( once )
  1586.             {
  1587.                enable_buttons(handle);
  1588.                once = 0
  1589.             }
  1590.          }
  1591.                   
  1592.          delete names_added
  1593.          names_added = 0
  1594.  
  1595.          ret_msg = DRC_MSG_PROCESSED;
  1596.       }
  1597.       else if(callback_index == IDB_ADVANCEDITEMS)
  1598.       {
  1599.          set_modified(global_type, TRUE);
  1600.          advanced_dialog = create_dialog( function_id("advanced_items_callback"), handle, IDD_ADVANCED_ITEM_SETTINGS );
  1601.          if ( advanced_dialog )
  1602.          {
  1603.             initialize_advanced_dialog(advanced_dialog, global_type, local_item);
  1604.             attach_help(editor_helpfile, advanced_dialog);
  1605.             begin_dialog(advanced_dialog);
  1606.          }
  1607.  
  1608.          ret_msg = DRC_MSG_PROCESSED;
  1609.       }
  1610.       else if(callback_index == IDC_CASE_SENSITIVE)
  1611.       {
  1612.          value = query_dialog_item(handle, IDC_CASE_SENSITIVE, DAC_CHECK);
  1613.          set_case_sensitive(global_type, value);
  1614.          set_modified(global_type, TRUE);
  1615.          if(!value)
  1616.          {
  1617.             tolower_keywords(global_type);
  1618.             init_items(handle, global_type, local_cat);
  1619.          }
  1620.       }
  1621.       else if(callback_index == IDB_CATEGORY_COLOR)
  1622.       {
  1623.          set_modified(global_type, TRUE);
  1624.          local_iscat = TRUE;
  1625.          color_dialog = create_dialog( function_id("select_color_callback"), handle, IDD_SYNTAX_COLOR );
  1626.          save_select_color_category(global_type);
  1627.          initialize_select_color(color_dialog, global_type, 1, local_catname, local_catname)
  1628.          begin_dialog(color_dialog)
  1629.  
  1630.          if(assign_cats)
  1631.             assign_category_colors(global_type);
  1632.          assign_cats = FALSE;
  1633.          if(do_done)
  1634.             do_done_processing();
  1635.          #  Force updated colors to take affect.
  1636.          set_dialog_item(handle, IDL_CATEGORY, DAC_DESELECT_ITEM, local_catname);
  1637.          set_dialog_item(handle, IDL_CATEGORY, DAC_SELECT_ITEM, local_catname);
  1638.  
  1639.          ret_msg = DRC_MSG_PROCESSED;
  1640.       }
  1641.       else if(callback_index == IDB_ITEM_COLOR)
  1642.       {
  1643.          set_modified(global_type, TRUE);
  1644.          local_iscat = FALSE;
  1645.          color_dialog = create_dialog( function_id("select_color_callback"), handle, IDD_SYNTAX_COLOR );
  1646.          save_select_color_item(global_type);
  1647.          initialize_select_color(color_dialog, global_type, 0, local_item, local_catname)
  1648.          begin_dialog(color_dialog);
  1649.          if(do_done)
  1650.             do_done_processing()
  1651.  
  1652.          set_dialog_item(handle, IDL_ITEMS, DAC_DESELECT_ITEM);
  1653.          set_dialog_item(handle, IDL_ITEMS, DAC_SELECT_ITEM, local_item "");
  1654.          ret_msg = DRC_MSG_PROCESSED;
  1655.       }
  1656.       else if( (callback_index == IDR_KEYWORD) || (callback_index == IDR_LINE) \
  1657.                || (callback_index == IDR_BLOCK) )
  1658.       {
  1659.          #  We don't need to check if the style selected is valid, because
  1660.          #  only valid styles are enabled.
  1661.          if(callback_index == IDR_KEYWORD)
  1662.          {
  1663.             set_dialog_item(handle, IDB_ADVANCEDITEMS, DAC_DISABLE);
  1664.             style = KEYWORD;
  1665.          }
  1666.          else if(callback_index == IDR_LINE)
  1667.          {
  1668.             set_dialog_item(handle, IDB_ADVANCEDITEMS, DAC_ENABLE);
  1669.             style = LINE;
  1670.          }
  1671.          else if(callback_index == IDR_BLOCK)
  1672.          {
  1673.             set_dialog_item(handle, IDB_ADVANCEDITEMS, DAC_DISABLE);
  1674.             style = BLOCK
  1675.          }
  1676.  
  1677.          if(local_item)
  1678.          {
  1679.             set_modified(global_type, TRUE);
  1680.             value = Value(global_type, local_item);
  1681.  
  1682.             delete_item(global_type, local_item);
  1683.  
  1684.             add_syntax_item(global_type, style, local_item, value+0);
  1685.  
  1686.             value = Value(global_type, local_item);
  1687.          }
  1688.       }
  1689.    }
  1690.    else if ( callback_msg == DM_SELECT )
  1691.    {
  1692.       if(callback_index == IDL_TYPE)
  1693.       {
  1694.          global_type = query_dialog_item(handle, IDL_TYPE, DAC_SELECT_ITEM);
  1695.          initialize_syntax_settings(handle);
  1696. #         if(!(global_type in syntax_loaded))
  1697. #         {
  1698. #            if(!("__styles" in syntax_loaded))
  1699. #            {
  1700. #               optional_function("load_user_styles");
  1701. #               syntax_loaded["__styles"] = TRUE;
  1702. #            }
  1703. #            optional_function("load_user_" global_type "_syntax");
  1704. #            save_syntax_part(global_type);
  1705. #            syntax_loaded[global_type] = 23;
  1706. #         }
  1707. #         init_category(handle, global_type);
  1708. #         enable_buttons(handle);
  1709. #         set_dialog_item(handle, IDE_WORD_DELIMITER, DAC_EDIT_TEXT, StyleDelimiters(global_type) "");
  1710. #         set_dialog_item(handle, IDE_ESCAPE_CHAR,    DAC_EDIT_TEXT, EscapeCharacter(global_type) "");
  1711. #
  1712. #         if(get_case_sensitive(global_type))
  1713. #            set_dialog_item(handle, IDC_CASE_SENSITIVE, DAC_CHECK);
  1714. #         else
  1715. #            set_dialog_item(handle, IDC_CASE_SENSITIVE, DAC_UNCHECK);
  1716.             
  1717.          ret_msg = DRC_MSG_PROCESSED;
  1718.       }
  1719.       else if(callback_index == IDL_CATEGORY)
  1720.       {
  1721.          local_catname = query_dialog_item(handle, IDL_CATEGORY, DAC_SELECT_ITEM);
  1722.          local_cat = Category(global_type, local_catname) + 0;
  1723.  
  1724.          init_items(handle, global_type, local_cat);
  1725.          enable_buttons(handle);
  1726.  
  1727.          fgval = get_current_color_of_item(global_type, local_catname, 0, 1)
  1728.          bgval = get_current_color_of_item(global_type, local_catname, 1, 1)
  1729.  
  1730.          set_color(handle, fgval, bgval, 1);
  1731.  
  1732.          ret_msg = DRC_MSG_PROCESSED;
  1733.       }
  1734.       else if(callback_index == IDL_ITEMS)
  1735.       {
  1736.          local_item = query_dialog_item(handle, IDL_ITEMS, DAC_SELECT_ITEM);
  1737.          set_style(handle, isValidStyle(global_type, local_item), Style(global_type, local_item));
  1738.  
  1739.          fgval = get_current_color_of_item(global_type, local_item, 0, 0)
  1740.          bgval = get_current_color_of_item(global_type, local_item, 1, 0)
  1741.  
  1742.          set_color(handle, fgval, bgval);
  1743.  
  1744.          ret_msg = DRC_MSG_PROCESSED;
  1745.       }
  1746.    }
  1747.    else if(callback_msg == DM_KILL_FOCUS)
  1748.    {
  1749.       if(callback_index == IDE_WORD_DELIMITER)
  1750.       {
  1751.          set_modified(global_type, TRUE);
  1752.          set_style_delimiters(global_type, query_dialog_item(handle, IDE_WORD_DELIMITER, DAC_EDIT_TEXT) "");
  1753.          ret_msg = DRC_MSG_PROCESSED;
  1754.       }
  1755.       else if(callback_index == IDE_ESCAPE_CHAR)
  1756.       {
  1757.          set_modified(global_type, TRUE);
  1758.          value = query_dialog_item(handle, IDE_ESCAPE_CHAR, DAC_EDIT_TEXT)"";
  1759.          set_escape_character(global_type, value);
  1760.  
  1761.          ret_msg = DRC_MSG_PROCESSED;
  1762.       }
  1763.    }
  1764.  
  1765.    return ret_msg;
  1766. }
  1767.  
  1768. local function enable_buttons(handle)
  1769. {
  1770.    local count;
  1771.  
  1772.    count = query_dialog_item(handle, IDL_CATEGORY, DAC_COUNT_ITEMS);
  1773.    if(count < 1)
  1774.    {
  1775.       set_dialog_item(handle, IDB_CATEGORY_COLOR, DAC_DISABLE);
  1776.       set_dialog_item(handle, IDB_DEL_COMP, DAC_DISABLE);
  1777.    }
  1778.    else
  1779.    {
  1780.       set_dialog_item(handle, IDB_CATEGORY_COLOR, DAC_ENABLE);
  1781.       set_dialog_item(handle, IDB_DEL_COMP, DAC_ENABLE);
  1782.    }
  1783.  
  1784.    count = query_dialog_item(handle, IDL_ITEMS, DAC_COUNT_ITEMS);
  1785.    if(count < 1)
  1786.    {
  1787.       set_dialog_item(handle, IDB_ITEM_COLOR,    DAC_DISABLE);
  1788.       set_dialog_item(handle, IDB_DEL_EXT,       DAC_DISABLE);
  1789.       set_dialog_item(handle, IDR_KEYWORD,       DAC_DISABLE);
  1790.       set_dialog_item(handle, IDR_LINE,          DAC_DISABLE);
  1791.       set_dialog_item(handle, IDR_BLOCK,         DAC_DISABLE);
  1792.       set_dialog_item(handle, IDR_KEYWORD,       DAC_UNCHECK);
  1793.       set_dialog_item(handle, IDR_LINE,          DAC_UNCHECK);
  1794.       set_dialog_item(handle, IDR_BLOCK,         DAC_UNCHECK);
  1795.       set_dialog_item(handle, IDB_ADVANCEDITEMS, DAC_DISABLE);
  1796.    }
  1797.    else
  1798.    {
  1799.       set_dialog_item(handle, IDB_ITEM_COLOR,    DAC_ENABLE);
  1800.       set_dialog_item(handle, IDB_DEL_EXT,       DAC_ENABLE);
  1801. #      set_dialog_item(handle, IDR_KEYWORD,       DAC_ENABLE);
  1802. #      set_dialog_item(handle, IDR_LINE,          DAC_ENABLE);
  1803. #      set_dialog_item(handle, IDR_BLOCK,         DAC_ENABLE);
  1804. #      set_dialog_item(handle, IDB_ADVANCEDITEMS, DAC_ENABLE);
  1805.    }
  1806. }
  1807.  
  1808. local function assign_category_colors(type)
  1809. {
  1810.    local fg, bg, cat, item, catname, array, catarray;
  1811.  
  1812.    if(type in save_styles)
  1813.    {
  1814.       set_busy_cursor();
  1815.       notify("Assigning new category colors.");
  1816.       catarray = Category(type);
  1817.       for(cat in catarray)
  1818.       {
  1819.          cat += 0;
  1820.          catname = catarray[cat].name "";
  1821.          if((catname in save_styles[type]) && save_styles[type][catname].category)
  1822.          {
  1823.             fg = save_styles[type][catname].foreground;
  1824.             bg = save_styles[type][catname].background;
  1825.  
  1826.             array = Keyword(type);
  1827.             for(item in array)
  1828.             {
  1829.                if(!cat || (cat == (Keyword(type, item, CATEGORY_MASK)+0)))
  1830.                {
  1831.                   save_styles[type][item].foreground = fg;
  1832.                   save_styles[type][item].background = bg;
  1833.                }
  1834.             }
  1835.  
  1836.             array = Line(type);
  1837.             for(item in array)
  1838.             {
  1839.                if(!cat || (cat == (Line(type, item, CATEGORY_MASK)+0)))
  1840.                {
  1841.                   save_styles[type][item].foreground = fg;
  1842.                   save_styles[type][item].background = bg;
  1843.                }
  1844.             }
  1845.  
  1846.             array = Block(type);
  1847.             for(item in array)
  1848.             {
  1849.                if(!cat || (cat == (Block(type, item, CATEGORY_MASK)+0)))
  1850.                {
  1851.                   save_styles[type][item].foreground = fg;
  1852.                   save_styles[type][item].background = bg;
  1853.                }
  1854.             }
  1855.          }
  1856.       }
  1857.       set_normal_cursor();
  1858.    }
  1859. }
  1860.  
  1861. #  
  1862. #  Returns the current color the specified type and item.
  1863. #  If the item is in save_styles, that color is used, otherwise
  1864. #  the color from the languages array is used.
  1865. #  
  1866. local function get_current_color_of_item(type, item, isbg, cat)
  1867. {
  1868.    local result = -1, index;
  1869.  
  1870.    if((type in save_styles) && (item in save_styles[type]))
  1871.    {
  1872.       #  Get the BGR value of the color saved in save_styles
  1873.       if(isbg)
  1874.          result = save_styles[type][item].background;
  1875.       else
  1876.          result = save_styles[type][item].foreground;
  1877.    }
  1878.    else
  1879.    {
  1880.       #  Get BGR value of the color from languages array.
  1881.       if(cat)
  1882.       {
  1883. #           if(local_catname == "All")
  1884. #              result = -1;
  1885.          if(isbg)
  1886.             result = Category(type, local_cat, 2) +0;
  1887.          else
  1888.             result = Category(type, local_cat, 1) +0;
  1889.       }
  1890.       else
  1891.       {
  1892.          index = Value(type, item, ITEM_MASK) +0;
  1893.          result = query_syntax_style(index, isbg);
  1894.       }
  1895.    }
  1896.  
  1897.    return result;
  1898. }
  1899. local function delete_category(type, cat)
  1900. {
  1901.    local array, item;
  1902.  
  1903.    cat += 0;
  1904.    array = Keyword(type);
  1905.    for(item in array)
  1906.    {
  1907.       if(!cat || (Keyword(type, item, CATEGORY_MASK) == cat))
  1908.          delete_item(type, item);
  1909.    }
  1910.  
  1911.    array = Line(type);
  1912.    for(item in array)
  1913.    {
  1914.       if(!cat || (Line(type, item, CATEGORY_MASK) == cat))
  1915.          delete_item(type, item);
  1916.    }
  1917.  
  1918.    array = Block(type);
  1919.    for(item in array)
  1920.    {
  1921.       if(!cat || (Block(type, item, CATEGORY_MASK) == cat))
  1922.          delete_item(type, item);
  1923.    }
  1924.  
  1925.    if(cat)
  1926.       delete languages[type].category[cat];
  1927. }
  1928.  
  1929. local function delete_item(type, item)
  1930. {
  1931.    if(type in languages)
  1932.    {
  1933.       if(item in languages[type].block)
  1934.       {
  1935.          delete languages[type].block[item];
  1936.       }
  1937.    
  1938.       if(item in languages[type].line)
  1939.       {
  1940.          delete languages[type].line[item];
  1941.       }
  1942.    
  1943.       if(item in languages[type].keyword)
  1944.       {
  1945.          delete languages[type].keyword[item];
  1946.       }
  1947.    }
  1948. }
  1949.  
  1950. local function Value(type, word, MASK)
  1951. {
  1952.    local result = -1;
  1953.  
  1954.    result = Block(type, word, MASK);
  1955.    if(result+0 < 0)
  1956.       result = Line(type, word, MASK);
  1957.    if(result+0 < 0)
  1958.       result = Keyword(type, word, MASK);
  1959.  
  1960.    return result+0;
  1961. }
  1962.  
  1963. local function CategoryExist(type, cat)
  1964. {
  1965.    local array = Category(type), index;
  1966.  
  1967.    cat = cat"";
  1968.    for(index in array)
  1969.    {
  1970.       if(array[index].name == cat)
  1971.          return TRUE;
  1972.    }
  1973.  
  1974.    return FALSE;
  1975. }
  1976.  
  1977. local function undo_syntax_settings(type)
  1978. {
  1979.    local word;
  1980.  
  1981.    if(type in save_languages)
  1982.    {
  1983.       languages[type].stile_delimiters = save_languages[type].stile_delimiters;
  1984.  
  1985.       reset_languages(0);
  1986.       delete languages[type].category;
  1987.       for(word in save_languages[type].category)
  1988.       {
  1989.          languages[type].category[word] = save_languages[type].category[word];
  1990.       }
  1991.  
  1992.       delete languages[type].keyword;
  1993.       for(word in save_languages[type].keyword)
  1994.       {
  1995.          languages[type].keyword[word] = save_languages[type].keyword[word];
  1996.       }
  1997.  
  1998.       delete languages[type].line;
  1999.       for(word in save_languages[type].line)
  2000.       {
  2001.          languages[type].line[word] = save_languages[type].line[word];
  2002.       }
  2003.  
  2004.       delete languages[type].block;
  2005.       for(word in save_languages[type].block)
  2006.       {
  2007.          languages[type].block[word] = save_languages[type].block[word];
  2008.       }
  2009.       reset_languages(1);
  2010.       delete save_styles[type];
  2011.    }
  2012.    else
  2013.    {
  2014.       warning("Initial values of this type were not saved.");
  2015.    }
  2016. }
  2017.  
  2018. local function isValidStyle(type, item)
  2019. {
  2020.    local result = 0;
  2021.  
  2022.    result = or(result, isValidKeyword(type, item));
  2023.    result = or(result, isValidLine(type, item));
  2024.    result = or(result, isValidBlock(type, item));
  2025.  
  2026.    return result;
  2027. }
  2028.  
  2029. local function isValidKeyword(type, item)
  2030. {
  2031.    local result, pattern;
  2032.  
  2033.    pattern = "[" quote_regex(StyleDelimiters(type)) " ]+";
  2034.    result  = !match(item, pattern); 
  2035.  
  2036.    return (result ? 0x1 : 0);
  2037. }
  2038.  
  2039. local function isValidLine(type, item)
  2040. {
  2041.    local result = FALSE, array, count;
  2042.  
  2043.    count = split(item, array);
  2044.  
  2045.    result = ((count == 1) || (count == 2));
  2046.  
  2047.    return (result ? 0x2 : 0);
  2048. }
  2049.  
  2050. local function isValidBlock(type, item)
  2051. {
  2052.    local result = FALSE, array;
  2053.  
  2054.    if(split(item, array) == 2)
  2055.    {
  2056.       result = (array[1] != array[2]);
  2057.    }
  2058.  
  2059.    return (result ? 0x4 : 0);
  2060. }
  2061.  
  2062. global function isDefined(fg, bg)
  2063. {
  2064.    local ret_val  = -1;
  2065.  
  2066.    if(fg in defined_styles)
  2067.       if(bg in defined_styles[fg])
  2068.          ret_val = defined_styles[fg][bg];
  2069.  
  2070.    return ret_val;
  2071. }
  2072.  
  2073. #  
  2074. #  Saves RGB value of selected color to save_styles array
  2075. #  
  2076. local function saveItem(handle, type, dfg, dbg, add, iscat, item)
  2077. {
  2078.    local fg, bg, fgval, bgval; #  , item;
  2079.  
  2080.    #  Get the coordinates of the selected colors
  2081.    fgval = query_dialog_item(handle, IDV_FOREGROUND, DAC_VS_QUERY_SELECTED);
  2082.    bgval = query_dialog_item(handle, IDV_BACKGROUND, DAC_VS_QUERY_SELECTED);
  2083.    
  2084.    #  Get the RGB value of the selected colors
  2085.    fgval = query_dialog_item(handle, IDV_FOREGROUND, DAC_VS_QUERY_ITEM, fgval);
  2086.    bgval = query_dialog_item(handle, IDV_BACKGROUND, DAC_VS_QUERY_ITEM, bgval);
  2087.  
  2088.    fg = (dfg ? -1 : fgval); #  if default selected, use it;
  2089.    bg = (dbg ? -1 : bgval); #     otherwise use the valueset value
  2090.  
  2091.    if(add)
  2092.    {
  2093.       if(!item)
  2094.          item  = query_dialog_item(handle, IDL_ITEMS, DAC_EDIT_TEXT);
  2095.  
  2096.       if(iscat)
  2097.          save_styles[type][item].category = TRUE;
  2098.    
  2099.       #  save RGB color values
  2100.       save_styles[type][item].foreground = fg;
  2101.       save_styles[type][item].background = bg;
  2102.    }
  2103.    else
  2104.    {
  2105.       if(!item)
  2106.          item   = query_dialog_item(handle, IDL_ITEMS, DAC_FIRST_ITEM)
  2107.  
  2108.       while ( item != "" )
  2109.       {
  2110.          if(iscat)
  2111.             save_styles[type][item].category = TRUE;
  2112.    
  2113.          #  save RGB color values
  2114.          save_styles[type][item].foreground = fg;
  2115.          save_styles[type][item].background = bg;
  2116.  
  2117.          item   = query_dialog_item(handle, IDL_ITEMS, DAC_NEXT_ITEM)
  2118.       }
  2119.    }
  2120.  
  2121. }
  2122.  
  2123. global function assign_syntax_changes()
  2124. {
  2125.    local type, item, index, fg, bg;
  2126.  
  2127.    set_busy_cursor();
  2128.    notify("Creating new syntax styles.");
  2129.    for(type in save_styles)
  2130.    {
  2131.       for(item in save_styles[type])
  2132.       {
  2133.          fg = save_styles[type][item].foreground;
  2134.          bg = save_styles[type][item].background;
  2135.          index = isDefined(fg, bg);
  2136.  
  2137.          if(index < 0)
  2138.          {
  2139.             index = create_syntax_style(fg, bg);
  2140.             defined_styles[fg][bg] = index;
  2141.          }
  2142.  
  2143.          if(save_styles[type][item].category)
  2144.             add_syntax_category(type, -1, item, fg, bg);
  2145.          else
  2146.             add_syntax_item(type, Style(type, item), item, index, ITEM_MASK);
  2147.       }
  2148.    }
  2149.    notify("");
  2150.    set_normal_cursor();
  2151. }
  2152.  
  2153. #  Color values passed as BGR if more than 2 parms
  2154. local function set_color(handle, value1, value2, iscat)
  2155. {
  2156.    local row, col, fg, bg, text = "Using default ";
  2157.  
  2158.    if(argcount() == 2)
  2159.    {
  2160.       fg = query_syntax_style(value1, 0);
  2161.       bg = query_syntax_style(value1, 1);
  2162.    }
  2163.    else
  2164.    {
  2165.       fg = value1+0;
  2166.       bg = value2+0;
  2167.    }
  2168.  
  2169.    if((fg < 0) && (bg < 0))
  2170.       text = text "FG/BG";
  2171.    else if(fg < 0)
  2172.       text = text "FG";
  2173.    else if(bg < 0)
  2174.       text = text "BG";
  2175.    else
  2176.       text = "";
  2177.  
  2178.    fg = (fg < 0) ? default_color_window_fg : fg;
  2179.    bg = (bg < 0) ? default_color_window_bg : bg;
  2180.  
  2181.    if(iscat)
  2182.    {
  2183.       set_dialog_item(handle, IDS_CATEGORY_COLOR, DAC_FG_COLOR, fg);
  2184.       set_dialog_item(handle, IDS_CATEGORY_COLOR, DAC_BG_COLOR, bg);
  2185.       set_dialog_item(handle, IDS_USING_CAT,      DAC_TEXT, text);
  2186.    }
  2187.    else
  2188.    {
  2189.       set_dialog_item(handle, IDS_ITEM_COLOR, DAC_FG_COLOR, fg);
  2190.       set_dialog_item(handle, IDS_ITEM_COLOR, DAC_BG_COLOR, bg);
  2191.       set_dialog_item(handle, IDS_USING_ITEM, DAC_TEXT, text);
  2192.    }
  2193. }
  2194.  
  2195. local function set_style(handle, valid, style)
  2196. {
  2197.    if(and(valid, KEYWORD))
  2198.       set_dialog_item(handle, IDR_KEYWORD, DAC_ENABLE);
  2199.    else
  2200.       set_dialog_item(handle, IDR_KEYWORD, DAC_DISABLE);
  2201.  
  2202.    if(and(style, KEYWORD))
  2203.       set_dialog_item(handle, IDR_KEYWORD, DAC_CHECK);
  2204.    else
  2205.       set_dialog_item(handle, IDR_KEYWORD, DAC_UNCHECK);
  2206.  
  2207.  
  2208.    if(and(valid, LINE))
  2209.       set_dialog_item(handle, IDR_LINE, DAC_ENABLE);
  2210.    else
  2211.       set_dialog_item(handle, IDR_LINE, DAC_DISABLE);
  2212.  
  2213.    if(and(style, LINE))
  2214.    {
  2215.       set_dialog_item(handle, IDR_LINE,     DAC_CHECK);
  2216.       set_dialog_item(handle, IDB_ADVANCEDITEMS, DAC_ENABLE);
  2217.    }
  2218.    else
  2219.    {
  2220.       set_dialog_item(handle, IDR_LINE,     DAC_UNCHECK);
  2221.       set_dialog_item(handle, IDB_ADVANCEDITEMS, DAC_DISABLE);
  2222.    }
  2223.  
  2224.  
  2225.    if(and(valid, BLOCK))
  2226.       set_dialog_item(handle, IDR_BLOCK, DAC_ENABLE);
  2227.    else
  2228.       set_dialog_item(handle, IDR_BLOCK, DAC_DISABLE);
  2229.  
  2230.    if(and(style, BLOCK))
  2231.       set_dialog_item(handle, IDR_BLOCK, DAC_CHECK);
  2232.    else
  2233.       set_dialog_item(handle, IDR_BLOCK, DAC_UNCHECK);
  2234. }
  2235.  
  2236. local function tolower_keywords(type)
  2237. {
  2238.    local array = Keyword(type), word, new_word, value;
  2239.  
  2240.    set_busy_cursor();
  2241.  
  2242.    for(word in array)
  2243.    {
  2244.       new_word = tolower(word);
  2245.       if(word != new_word)
  2246.       {
  2247.          value = delete_keyword(type, word);
  2248.          set_keyword(type, new_word, value);
  2249.       }
  2250.    }
  2251.  
  2252.    set_normal_cursor();
  2253. }
  2254.  
  2255. local function save_syntax_part(type)
  2256. {
  2257.    local word;
  2258.  
  2259.    save_languages[type].esc_character    = languages[type].esc_character;
  2260.    save_languages[type].stile_delimiters = languages[type].stile_delimiters;
  2261.    save_languages[type].sensitive        = languages[type].sensitive;
  2262.  
  2263.    for(word in languages[type].category)
  2264.       save_languages[type].category[word] = languages[type].category[word];
  2265.  
  2266.    for(word in languages[type].keyword)
  2267.       save_languages[type].keyword[word]  = languages[type].keyword[word];
  2268.  
  2269.    for(word in languages[type].line)
  2270.       save_languages[type].line[word]     = languages[type].line[word];
  2271.  
  2272.    for(word in languages[type].block)
  2273.       save_languages[type].block[word]    = languages[type].block[word];
  2274. }
  2275.  
  2276. ################################################################################
  2277. #  
  2278. #  Advanced items
  2279. #  
  2280. ################################################################################
  2281. local IDC_IS_ESCAPABLE = 105;
  2282. local IDC_NONE = 104;
  2283. local IDE_MUST_START_IN_COLUMN = 101;
  2284. local IDC_MUST_START_IN_COLUMN = 102;
  2285. local advanced_save_value = FALSE;
  2286.  
  2287. local function initialize_advanced_dialog(handle, type, item)
  2288. {
  2289.    nb_initializing = TRUE;
  2290.  
  2291.    add_dialog_item(handle, IDC_NONE,                 DCTRL_CHECK_BOX);
  2292.    add_dialog_item(handle, IDC_IS_ESCAPABLE,         DCTRL_CHECK_BOX);
  2293.    add_dialog_item(handle, IDC_MUST_START_IN_COLUMN, DCTRL_CHECK_BOX);
  2294.    add_dialog_item(handle, IDE_MUST_START_IN_COLUMN, DCTRL_SPINBUTTON);
  2295.    set_dialog_item(handle, IDE_MUST_START_IN_COLUMN, DAC_SPIN_LIMITS, 1, 255);
  2296.  
  2297.    advanced_save_value = Line(type, item);
  2298.  
  2299.    if(length(item) > 1)
  2300.    {
  2301.       set_dialog_item(handle, IDC_MUST_START_IN_COLUMN, DAC_DISABLE);
  2302.       set_dialog_item(handle, IDE_MUST_START_IN_COLUMN, DAC_DISABLE);
  2303.    }      
  2304.  
  2305.    if(Line(type, item, COLUMN_MASK))
  2306.    {
  2307.       set_dialog_item(handle, IDC_MUST_START_IN_COLUMN, DAC_CHECK);
  2308.       set_dialog_item(handle, IDE_MUST_START_IN_COLUMN, DAC_SPIN_VALUE, 
  2309.                       Line(type, item, COLUMN_MASK)+0);
  2310.       set_dialog_item(handle, IDC_NONE, DAC_UNCHECK);
  2311.    }
  2312.    else if(Line(type, item, FLAG_MASK))
  2313.    {
  2314.       set_dialog_item(handle, IDC_IS_ESCAPABLE, DAC_CHECK);
  2315.       set_dialog_item(handle, IDC_NONE, DAC_UNCHECK); 
  2316.       set_dialog_item(handle, IDE_MUST_START_IN_COLUMN, DAC_DISABLE); 
  2317.    }
  2318.    else
  2319.    {
  2320.       set_dialog_item(handle, IDC_NONE, DAC_CHECK); 
  2321.       set_dialog_item(handle, IDE_MUST_START_IN_COLUMN, DAC_DISABLE); 
  2322.    }
  2323.  
  2324.    nb_initializing = FALSE;
  2325. }
  2326.  
  2327. global function advanced_items_callback()
  2328. {
  2329.    local ret_msg = DRC_CONTINUE
  2330.    local handle = callback_dialog_handle;
  2331.    local value;
  2332.  
  2333.    if(nb_initializing)
  2334.    {
  2335.       ret_msg = DRC_MSG_PROCESSED;
  2336.    }
  2337.    else if(callback_msg == DM_HELPREQUESTED)
  2338.    {
  2339.       display_help("advanced_items", handle);
  2340.       #  display_help(nbPagePrefix[current_nb_page].help, handle);
  2341.       ret_msg = DRC_MSG_PROCESSED;
  2342.    }
  2343.    else if ( callback_msg == DM_CANCEL )
  2344.    {
  2345.       set_line(global_type, local_item, advanced_save_value);
  2346.       ret_msg = DRC_EXIT;
  2347.    }
  2348.    else if ( callback_msg == DM_OK )
  2349.    {
  2350.       ret_msg = DRC_EXIT;
  2351.    }
  2352.    else if ( callback_msg == DM_SPIN_CHANGE )
  2353.    {
  2354.       # validate the value the user entered
  2355.       value = query_dialog_item(handle, callback_index, DAC_SPIN_VALUE );
  2356.       set_line(global_type, local_item, value, COLUMN_MASK);
  2357.    }
  2358.    else if((callback_msg == DM_CLICK) || (callback_msg == DM_DOUBLE_CLICK))
  2359.    {
  2360.       if(callback_index == IDC_IS_ESCAPABLE)
  2361.       {
  2362.          set_line(global_type, local_item, 0x1, FLAG_MASK);
  2363.          set_line(global_type, local_item, 0x0, COLUMN_MASK);
  2364.          set_dialog_item(handle, IDE_MUST_START_IN_COLUMN, DAC_DISABLE);
  2365.       }
  2366.       else if(callback_index == IDC_MUST_START_IN_COLUMN)
  2367.       {
  2368.          set_dialog_item(handle, IDE_MUST_START_IN_COLUMN, DAC_ENABLE);
  2369.          value = query_dialog_item(handle, IDE_MUST_START_IN_COLUMN, DAC_SPIN_VALUE);
  2370.          set_line(global_type, local_item, 0x0, FLAG_MASK);
  2371.          set_line(global_type, local_item, value, COLUMN_MASK);
  2372.       }
  2373.       else if(callback_index == IDC_NONE)
  2374.       {
  2375.          set_line(global_type, local_item, 0x0, FLAG_MASK);
  2376.          set_line(global_type, local_item, 0x0, COLUMN_MASK);
  2377.          set_dialog_item(handle, IDE_MUST_START_IN_COLUMN, DAC_DISABLE);
  2378.       }
  2379.    }
  2380.  
  2381.    return ret_msg
  2382. }
  2383.  
  2384. local function save_select_color_item(type)
  2385. {
  2386.    local array, item;
  2387.  
  2388.    delete mini_storage;
  2389.  
  2390.    array = Keyword(type);
  2391.    for(item in array)
  2392.    {
  2393.       mini_storage[item].foreground = get_current_color_of_item(type, item, 0, 0);
  2394.       mini_storage[item].background = get_current_color_of_item(type, item, 1, 0);
  2395.    }
  2396.  
  2397.    array = Line(type);
  2398.    for(item in array)
  2399.    {
  2400.       mini_storage[item].foreground = get_current_color_of_item(type, item, 0, 0);
  2401.       mini_storage[item].background = get_current_color_of_item(type, item, 1, 0);
  2402.    }
  2403.  
  2404.    array = Block(type);
  2405.    for(item in array)
  2406.    {
  2407.       mini_storage[item].foreground = get_current_color_of_item(type, item, 0, 0);
  2408.       mini_storage[item].background = get_current_color_of_item(type, item, 1, 0);
  2409.    }
  2410. }
  2411.  
  2412. local function save_select_color_category(type)
  2413. {
  2414.    local array, catnum;
  2415.  
  2416.    delete mini_storage;
  2417.  
  2418.    array = Category(type);
  2419.    for(catnum in array)
  2420.    {
  2421.       local_cat = catnum
  2422.       mini_storage[array[catnum].name].foreground = get_current_color_of_item(type, array[catnum].name, 0, 1);
  2423.       mini_storage[array[catnum].name].background = get_current_color_of_item(type, array[catnum].name, 1, 1);
  2424.    }
  2425. }
  2426.  
  2427. local function unsave_select_color_both(type, iscat)
  2428. {
  2429.    local array, catname;
  2430.  
  2431.    for(catname in mini_storage)
  2432.    {
  2433.       save_styles[type][catname].foreground = mini_storage[catname].foreground;
  2434.       save_styles[type][catname].background = mini_storage[catname].background;
  2435.       if(iscat)
  2436.          save_styles[type][catname].category = TRUE;
  2437.    }
  2438. }
  2439.  
  2440. local valueset_selected = FALSE;
  2441.  
  2442. local function initialize_select_color(handle, type, iscat, text, catname)
  2443. {
  2444.    local cat, col, row, color, DID_CANCEL = 2, fg, bg;
  2445.    local array[]
  2446.    
  2447.    nb_initializing = TRUE;
  2448.  
  2449.    attach_help(editor_helpfile, handle);
  2450.  
  2451.    add_dialog_item(handle, IDV_FOREGROUND, DCTRL_VALUESET);
  2452.    add_dialog_item(handle, IDV_BACKGROUND, DCTRL_VALUESET);
  2453.    add_dialog_item(handle, IDS_CATEGORY,   DCTRL_STATIC_TEXT);
  2454.  
  2455. #     set_dialog_item(handle, DID_CANCEL, DAC_DISABLE);
  2456.  
  2457.    reset_colors(handle);
  2458.  
  2459.    if(iscat)
  2460.       set_dialog_item(handle, IDS_CATEGORY, DAC_TEXT, "Category");
  2461.    else
  2462.       set_dialog_item(handle, IDS_CATEGORY, DAC_TEXT, "Item");
  2463.  
  2464.    if(local_add)
  2465.    {
  2466.       add_dialog_item(handle, IDL_ITEMS, DCTRL_EDIT);
  2467.       if(catname)
  2468.       {
  2469.          fg = get_current_color_of_item(type, catname, 0, 1); 
  2470.          bg = get_current_color_of_item(type, catname, 1, 1); 
  2471.          select_color(handle, fg, bg);
  2472.       }
  2473.    }
  2474.    else
  2475.    {
  2476.       add_dialog_item(handle, IDL_ITEMS, DCTRL_MULTI_LIST_BOX);
  2477.       set_dialog_item(handle, IDL_ITEMS, DAC_SORT_ASCENDING);
  2478.       set_dialog_item(handle, IDL_ITEMS, DAC_DELETE_ITEM);
  2479.  
  2480.       if(iscat)
  2481.       {
  2482.          array = Category(type);
  2483.          for(cat in array)
  2484.             set_dialog_item(handle, IDL_ITEMS, DAC_ADD_ITEM, array[cat].name "");
  2485.  
  2486. #           set_dialog_item(handle, IDL_ITEMS, DAC_ADD_ITEM, "All");
  2487.       }
  2488.       else
  2489.       {
  2490.          if ( catname == "All" )
  2491.             init_items(handle, type);
  2492.          else
  2493.             init_items(handle, type, Value(type, text, CATEGORY_MASK));
  2494.       }
  2495.  
  2496.       if(!text)
  2497.          set_dialog_item(handle, IDL_ITEMS, DAC_SELECT_INDEX, 0);
  2498.       else
  2499.       {
  2500.          set_dialog_item(handle, IDL_ITEMS, DAC_DESELECT_ITEM)
  2501.          set_dialog_item(handle, IDL_ITEMS, DAC_SELECT_ITEM, text);
  2502.       }
  2503.    }
  2504.    valueset_selected = FALSE;
  2505.  
  2506.    nb_initializing = FALSE;
  2507. }
  2508.  
  2509. global function create_item_callback()
  2510. {
  2511.    local handle = callback_dialog_handle;
  2512.  
  2513.    if(callback_msg == DM_HELPREQUESTED)
  2514.    {
  2515.       display_help("create_new_item", handle);
  2516.       return DRC_MSG_PROCESSED;
  2517.    }
  2518.    else
  2519.       return select_color_callback()
  2520. }
  2521.  
  2522. global function select_color_callback()
  2523. {
  2524.    local ret_msg = DRC_CONTINUE, item, dbg, dfg, cat, value;
  2525.    local custom_dlg, fgval, bgval, i;
  2526.    local handle = callback_dialog_handle;
  2527.  
  2528. #   if(nb_initializing)
  2529. #      ret_msg = DRC_MSG_PROCESSED;      
  2530.    if(callback_msg == DM_HELPREQUESTED)
  2531.    {
  2532.       display_help("select_color", handle);
  2533.       ret_msg = DRC_MSG_PROCESSED;
  2534.    }
  2535.    else if ( callback_msg == DM_CANCEL )
  2536.    {
  2537.       if(!local_add)
  2538.          unsave_select_color_both(global_type, local_iscat);
  2539.  
  2540.       ret_msg = DRC_EXIT;
  2541.    }
  2542.    else if ( callback_msg == DM_OK )
  2543.    {
  2544.       ret_msg = perform_ok( handle )
  2545.  
  2546.       assign_cats = local_iscat;
  2547.       do_done     = (ret_msg == DRC_EXIT) && local_add;
  2548.  
  2549. #         for ( i in save_styles[global_type] )
  2550. #         {
  2551. #            if ( save_styles[global_type][i].category && 
  2552. #                (i in names_added) && names_added[i] )
  2553. #            {
  2554. #               add_syntax_category(global_type, -1, i, 
  2555. #                                   save_styles[global_type][i].foreground, 
  2556. #                                   save_styles[global_type][i].background);
  2557. #            }
  2558. #            else if( (i in names_added) && names_added[i] )
  2559. #            {
  2560. #               if(isValidKeyword(global_type, i))
  2561. #                  add_syntax_item(global_type, KEYWORD, i, local_cat, CATEGORY_MASK);
  2562. #               else if(isValidLine(global_type, i))
  2563. #                  add_syntax_item(global_type, LINE, i, local_cat, CATEGORY_MASK);
  2564. #               else if(isValidBlock(global_type, i))
  2565. #                  add_syntax_item(global_type, BLOCK, i, local_cat, CATEGORY_MASK);
  2566. #            }
  2567. #         }
  2568. #      }
  2569.    }
  2570.    else if((callback_msg == DM_CLICK) || (callback_msg == DM_DOUBLE_CLICK))
  2571.    {
  2572.       if(callback_index == IDB_CUSTOM)
  2573.       {
  2574.          local_fgind = query_dialog_item(handle, IDV_FOREGROUND, DAC_VS_QUERY_SELECTED);
  2575.          local_bgind = query_dialog_item(handle, IDV_BACKGROUND, DAC_VS_QUERY_SELECTED);
  2576.  
  2577.          custom_dlg = create_dialog( function_id("custom_color_callback"), handle, IDD_CONFIGURE_COLOR );
  2578.          initialize_custom_dialog(custom_dlg, handle, local_fgind, local_bgind);
  2579.          begin_dialog(custom_dlg);
  2580.  
  2581.          reset_colors(handle);
  2582.          set_select_text(handle);
  2583.  
  2584.          #  Save new colors of selected item;
  2585.          if(!local_add)
  2586.          {
  2587.             dfg = query_dialog_item(handle, IDC_DEFAULT_FG, DAC_CHECK);
  2588.             dbg = query_dialog_item(handle, IDC_DEFAULT_BG, DAC_CHECK);
  2589.             saveItem(handle, global_type, dfg, dbg, local_add, local_iscat);
  2590.          }
  2591.  
  2592.          ret_msg = DRC_MSG_PROCESSED;
  2593.       }
  2594.       else if((callback_index == IDC_DEFAULT_FG) || (callback_index == IDC_DEFAULT_BG) )
  2595.       {
  2596.          set_select_text(handle);
  2597.          dfg = query_dialog_item(handle, IDC_DEFAULT_FG, DAC_CHECK);
  2598.          dbg = query_dialog_item(handle, IDC_DEFAULT_BG, DAC_CHECK);
  2599.          if(!local_add)
  2600.             saveItem(handle, global_type, dfg, dbg, local_add, local_iscat);
  2601.       }
  2602.       else if(callback_index == IDB_DEFAULT)
  2603.       {
  2604.          load_factory_syntax_colors();
  2605.          reset_colors(handle);
  2606.          ret_msg = DRC_MSG_PROCESSED;
  2607.       }
  2608.       else if(callback_index == IDB_ADD_COMP)
  2609.       {
  2610.          perform_ok(handle)
  2611.          # clear out edit field
  2612.          set_dialog_item(handle, IDL_ITEMS, DAC_EDIT_TEXT, "" )
  2613.          set_dialog_item(handle, IDL_ITEMS, DAC_SETFOCUS )
  2614.          ret_msg = DRC_MSG_PROCESSED;
  2615.       }
  2616.    }
  2617.    else if(callback_msg == DM_SELECT)
  2618.    {
  2619.       valueset_selected = FALSE;
  2620.       item = query_dialog_item(handle, IDL_ITEMS, DAC_SELECT_ITEM);
  2621.  
  2622.       if ( local_iscat )
  2623.          local_cat = Category(global_type, item) + 0;
  2624.  
  2625.       fgval = get_current_color_of_item(global_type, item, 0, local_iscat);
  2626.       bgval = get_current_color_of_item(global_type, item, 1, local_iscat);
  2627.  
  2628.       select_color(handle, fgval, bgval);
  2629.       valueset_selected = TRUE;
  2630.       ret_msg = DRC_MSG_PROCESSED;
  2631.    }     
  2632.    else if(callback_msg == DM_VS_SELECT)
  2633.    {
  2634.       if(callback_index == IDV_FOREGROUND)
  2635.       {
  2636.          dbg = query_dialog_item(handle, IDC_DEFAULT_BG, DAC_CHECK);
  2637.          if(!local_add && valueset_selected)
  2638.             saveItem(handle, global_type, FALSE, dbg, local_add, local_iscat);
  2639.          set_dialog_item(handle, IDC_DEFAULT_FG, DAC_UNCHECK);
  2640.  
  2641.          #  assign selected item the appropriate style;
  2642.       }
  2643.       else if(callback_index == IDV_BACKGROUND)
  2644.       {
  2645.          dfg = query_dialog_item(handle, IDC_DEFAULT_FG, DAC_CHECK);
  2646.          if(!local_add && valueset_selected)
  2647.             saveItem(handle, global_type, dfg, FALSE, local_add, local_iscat);
  2648.          set_dialog_item(handle, IDC_DEFAULT_BG, DAC_UNCHECK);
  2649.       }
  2650.       set_select_text(handle);
  2651.  
  2652.       valueset_selected = TRUE;
  2653.       ret_msg = DRC_MSG_PROCESSED;
  2654.    }
  2655.    return ret_msg
  2656. }
  2657.  
  2658. local function do_done_processing()
  2659. {
  2660.    local cat;
  2661.  
  2662.    for ( cat in save_styles[global_type] )
  2663.    {
  2664.       if ( save_styles[global_type][cat].category && 
  2665.           (cat in names_added) && names_added[cat] )
  2666.       {
  2667.          add_syntax_category(global_type, -1, cat, 
  2668.                              save_styles[global_type][cat].foreground, 
  2669.                              save_styles[global_type][cat].background);
  2670.       }
  2671.       else if( (cat in names_added) && names_added[cat] )
  2672.       {
  2673.          if(isValidKeyword(global_type, cat))
  2674.             add_syntax_item(global_type, KEYWORD, cat, local_cat, CATEGORY_MASK);
  2675.          else if(isValidLine(global_type, cat))
  2676.             add_syntax_item(global_type, LINE, cat, local_cat, CATEGORY_MASK);
  2677.          else if(isValidBlock(global_type, cat))
  2678.             add_syntax_item(global_type, BLOCK, cat, local_cat, CATEGORY_MASK);
  2679.       }
  2680.    }
  2681.    do_done = FALSE;
  2682. }
  2683.  
  2684. local function perform_ok( handle )
  2685. {
  2686.    local item, dfg, dbg
  2687.    local ret_msg = DRC_EXIT;
  2688.  
  2689.    if(local_add)
  2690.    {
  2691.       dfg = query_dialog_item(handle, IDC_DEFAULT_FG, DAC_CHECK)
  2692.       dbg = query_dialog_item(handle, IDC_DEFAULT_BG, DAC_CHECK)
  2693.       
  2694.       if(local_iscat)
  2695.       {
  2696.          item = query_dialog_item(handle, IDL_ITEMS, DAC_EDIT_TEXT);
  2697.          if(item != "" && !CategoryExist(global_type, item))
  2698.          {
  2699.             names_added[item] = 1;
  2700.             saveItem(handle, global_type, dfg, dbg, local_add, local_iscat)
  2701.          }
  2702.          else if ( item != "" )
  2703.             warning("Cannot add " item ".  It already exists as a category.");
  2704.       }
  2705.       else
  2706.       {
  2707.          local_item = query_dialog_item(handle, IDL_ITEMS, DAC_EDIT_TEXT);
  2708.          local_item = get_case_sensitive(global_type) ? local_item : tolower(local_item);
  2709.          local_item = compress(local_item) #  we need to remove any whitespace the user may have enter
  2710.          local_item = ltrim(local_item)    #  (except for a single space in line/block styles)
  2711.          local_item = trim(local_item)
  2712.          if ( local_item != "" )
  2713.          {
  2714.             if(!isValidKeyword(global_type, local_item) &&
  2715.                !isValidLine(global_type, local_item)    &&
  2716.                !isValidBlock(global_type, local_item))
  2717.             {
  2718.                warning("Not a valid item for highlighting.");
  2719.                ret_msg = DRC_MSG_PROCESSED;
  2720.             }
  2721.             else
  2722.             {
  2723.                #  If I saveItem now, cancel works, and I can set the 
  2724.                #  category without creating a syntax style;
  2725.                names_added[local_item] = 1;
  2726.                saveItem(handle, global_type, dfg, dbg, local_add, local_iscat, local_item)
  2727.             }
  2728.          }
  2729.       }
  2730.    }
  2731. #   else if(local_iscat)
  2732. #      assign_category_colors(global_type);
  2733.  
  2734.    return ret_msg
  2735. }
  2736.  
  2737. #  Color passed in as BGR if 3 parms specified
  2738. local function select_color(handle, fg, bg)
  2739. {
  2740.    local row, col, color_index;
  2741.  
  2742.    #  The if structure is implemented this way because the default check 
  2743.    #  boxes need to be set first.  If they are not, an incorrect color is
  2744.    #  saved during the initialization of the select color dialog;
  2745.  
  2746.    if(fg < 0)
  2747.       set_dialog_item(handle, IDC_DEFAULT_FG, DAC_CHECK);
  2748.    if(bg < 0)
  2749.       set_dialog_item(handle, IDC_DEFAULT_BG, DAC_CHECK);
  2750.  
  2751.    if(fg >= 0)
  2752.    {
  2753.       set_dialog_item(handle, IDC_DEFAULT_FG, DAC_UNCHECK);
  2754.       color_index = get_color_index(fg, 0);
  2755.       if(color_index)
  2756.       {
  2757.          row = and(color_index, 0xf);
  2758.          col = shiftr(and(color_index, 0xf0000), 16);
  2759.          set_dialog_item(handle, IDV_FOREGROUND, DAC_VS_SELECT_ITEM, row, col);
  2760.       }
  2761.       else
  2762.           set_dialog_item(handle, IDV_FOREGROUND, DAC_VS_SELECT_ITEM, 1, 1);
  2763.    }
  2764.  
  2765.    if(bg >= 0)
  2766.    {
  2767.       set_dialog_item(handle, IDC_DEFAULT_BG, DAC_UNCHECK);
  2768.       color_index = get_color_index(bg, 1);
  2769.       if(color_index)
  2770.       {
  2771.          row = and(color_index, 0xf);
  2772.          col = shiftr(and(color_index, 0xf0000), 16);
  2773.          set_dialog_item(handle, IDV_BACKGROUND, DAC_VS_SELECT_ITEM, row, col);
  2774.       }
  2775.       else
  2776.          set_dialog_item(handle, IDV_BACKGROUND, DAC_VS_SELECT_ITEM, 1, 1);
  2777.    }
  2778.  
  2779.    set_select_text(handle, fg, bg);
  2780. }
  2781.  
  2782. local function set_select_text(handle, fg, bg)
  2783. {
  2784.    if(argcount() < 3)
  2785.    {
  2786.       if(query_dialog_item(handle, IDC_DEFAULT_FG, DAC_CHECK))
  2787.          fg = -1;
  2788.       else
  2789.       {
  2790.          fg = query_dialog_item(handle, IDV_FOREGROUND, DAC_VS_QUERY_SELECTED);
  2791.          fg = query_dialog_item(handle, IDV_FOREGROUND, DAC_VS_QUERY_ITEM, fg);
  2792.       }
  2793.  
  2794.       if(query_dialog_item(handle, IDC_DEFAULT_BG, DAC_CHECK))
  2795.          bg = -1;
  2796.       else
  2797.       {
  2798.          bg = query_dialog_item(handle, IDV_BACKGROUND, DAC_VS_QUERY_SELECTED);
  2799.          bg = query_dialog_item(handle, IDV_BACKGROUND, DAC_VS_QUERY_ITEM, bg);
  2800.       }
  2801.    }
  2802.  
  2803.    fg = (fg < 0) ? default_color_window_fg : fg;
  2804.    bg = (bg < 0) ? default_color_window_bg : bg;
  2805.  
  2806.    set_dialog_item(handle, IDS_CATEGORY, DAC_FG_COLOR, fg);
  2807.    set_dialog_item(handle, IDS_CATEGORY, DAC_BG_COLOR, bg);
  2808. }
  2809.  
  2810. ###############################################################################
  2811. #  
  2812. #  Custom color dialog section
  2813. #  
  2814. ################################################################################
  2815.  
  2816. local IDS_FG_RED      = 119;
  2817. local IDS_FG_GREEN    = 103;
  2818. local IDS_FG_BLUE     = 104;
  2819. local IDS_BG_RED      = 112;
  2820. local IDS_BG_GREEN    = 113;
  2821. local IDS_BG_BLUE     = 114;
  2822. local IDV_FG          = 106;
  2823. local IDV_BG          = 110;
  2824. local IDT_SAMPLE_TEXT = 116;
  2825.  
  2826. local function initialize_custom_dialog(handle, col_handle, fgind, bgind)
  2827. {
  2828.    local fg, bg, value;
  2829.  
  2830.    attach_help(editor_helpfile, handle);
  2831.  
  2832.    set_dialog_item( handle, IDS_FG_RED,   DAC_SPIN_LIMITS, 0, 255 );
  2833.    set_dialog_item( handle, IDS_FG_GREEN, DAC_SPIN_LIMITS, 0, 255 );
  2834.    set_dialog_item( handle, IDS_FG_BLUE,  DAC_SPIN_LIMITS, 0, 255 );
  2835.    set_dialog_item( handle, IDS_BG_RED,   DAC_SPIN_LIMITS, 0, 255 );
  2836.    set_dialog_item( handle, IDS_BG_GREEN, DAC_SPIN_LIMITS, 0, 255 );
  2837.    set_dialog_item( handle, IDS_BG_BLUE,  DAC_SPIN_LIMITS, 0, 255 );
  2838.  
  2839.    fg = query_dialog_item(col_handle, IDV_FOREGROUND, DAC_VS_QUERY_ITEM, fgind);
  2840.    bg = query_dialog_item(col_handle, IDV_BACKGROUND, DAC_VS_QUERY_ITEM, bgind);
  2841.  
  2842.    set_dialog_item(handle, IDV_FG, DAC_VS_SET_ITEM, 1, 1, fg);
  2843.    set_dialog_item(handle, IDV_BG, DAC_VS_SET_ITEM, 1, 1, bg);
  2844.  
  2845.    value = and(fg, 0xff);
  2846.    set_dialog_item(handle, IDS_FG_BLUE, DAC_SPIN_VALUE, value);
  2847.  
  2848.    value = and(shiftr(fg, 8), 0xff);
  2849.    set_dialog_item(handle, IDS_FG_GREEN, DAC_SPIN_VALUE, value);
  2850.  
  2851.    value = and(shiftr(fg, 16), 0xff);
  2852.    set_dialog_item(handle, IDS_FG_RED, DAC_SPIN_VALUE, value);
  2853.  
  2854.    value = and(bg, 0xff);
  2855.    set_dialog_item(handle, IDS_BG_BLUE, DAC_SPIN_VALUE, value);
  2856.  
  2857.    value = and(shiftr(bg, 8), 0xff);
  2858.    set_dialog_item(handle, IDS_BG_GREEN, DAC_SPIN_VALUE, value);
  2859.  
  2860.    value = and(shiftr(bg, 16), 0xff);
  2861.    set_dialog_item(handle, IDS_BG_RED, DAC_SPIN_VALUE, value);
  2862. }
  2863.  
  2864. global function custom_color_callback()
  2865. {
  2866.    local ret_msg = DRC_CONTINUE
  2867.    local handle = callback_dialog_handle;
  2868.    local value;
  2869.  
  2870.    if(callback_msg == DM_HELPREQUESTED)
  2871.    {
  2872.       display_help("customcolor", handle);
  2873.       ret_msg = DRC_MSG_PROCESSED;
  2874.    }
  2875.    else if ( callback_msg == DM_OK )
  2876.    {
  2877.       syntax_colors_fg[local_fgind] = read_color(handle, 0);
  2878.       syntax_colors_bg[local_bgind] = read_color(handle, 1);
  2879.       ret_msg = DRC_EXIT;
  2880.    }
  2881.    else if(callback_msg == DM_CANCEL)
  2882.    {
  2883.       ret_msg = DRC_EXIT;
  2884.    }
  2885.    else if ( callback_msg == DM_SPIN_CHANGE )
  2886.    {
  2887.       # validate the value the user entered
  2888.       query_dialog_item(handle, callback_index, DAC_SPIN_VALUE );
  2889.  
  2890.       if((callback_index == IDS_FG_RED) || (callback_index == IDS_FG_GREEN) || (callback_index == IDS_FG_BLUE) )
  2891.       {
  2892.          value = read_color(handle, 0);
  2893.          set_dialog_item(handle, IDV_FG, DAC_VS_SET_ITEM, 1, 1, value);
  2894.          set_dialog_item(handle, IDT_SAMPLE_TEXT, DAC_FG_COLOR, value);
  2895.       }
  2896.       else if((callback_index == IDS_BG_RED) || (callback_index == IDS_BG_GREEN) || (callback_index == IDS_BG_BLUE) )
  2897.       {
  2898.          value = read_color(handle, 1);
  2899.          set_dialog_item(handle, IDV_BG, DAC_VS_SET_ITEM, 1, 1, value);
  2900.          set_dialog_item(handle, IDT_SAMPLE_TEXT, DAC_BG_COLOR, value);
  2901.       }
  2902.    }
  2903.  
  2904.    return ret_msg
  2905. }
  2906.  
  2907. local function reset_colors(handle)
  2908. {
  2909.    local color_index, col, row;
  2910.  
  2911.    for(color_index in syntax_colors_fg)
  2912.    {
  2913.       row = and(color_index, 0xf);
  2914.       col = shiftr(and(color_index, 0xf0000), 16);
  2915.  
  2916.       set_dialog_item(handle, IDV_FOREGROUND, DAC_VS_SET_ITEM, row, col, syntax_colors_fg[color_index]+0 );
  2917.    }
  2918.  
  2919.    for(color_index in syntax_colors_bg)
  2920.    {
  2921.       row = and(color_index, 0xf);
  2922.       col = shiftr(and(color_index, 0xf0000), 16);
  2923.  
  2924.       set_dialog_item(handle, IDV_BACKGROUND, DAC_VS_SET_ITEM, row, col, syntax_colors_bg[color_index]+0 );
  2925.    }
  2926. }
  2927.  
  2928. local function get_color_index(color, isbg)
  2929. {
  2930.    local result, ind;
  2931.  
  2932.    if(isbg)
  2933.    {
  2934.       for(ind in syntax_colors_bg)
  2935.       {
  2936.          if(color == syntax_colors_bg[ind])
  2937.          {
  2938.             result = ind;
  2939.             break;
  2940.          }
  2941.       }
  2942.    }
  2943.    else
  2944.    {
  2945.       for(ind in syntax_colors_fg)
  2946.       {
  2947.          if(color == syntax_colors_fg[ind])
  2948.          {
  2949.             result = ind;
  2950.             break;
  2951.          }
  2952.       }
  2953.    }
  2954.  
  2955.    return result;
  2956. }
  2957.  
  2958. local function read_color(handle, bg)
  2959. {
  2960.    local value;
  2961.  
  2962.    if(bg)
  2963.    {
  2964.       value = query_dialog_item(handle, IDS_BG_RED, DAC_SPIN_VALUE)+0;
  2965.       value = shiftl(value, 8);
  2966.  
  2967.       value = or(query_dialog_item(handle, IDS_BG_GREEN, DAC_SPIN_VALUE)+0, value);
  2968.       value = shiftl(value, 8);
  2969.          
  2970.       value = or(query_dialog_item(handle, IDS_BG_BLUE, DAC_SPIN_VALUE)+0, value);
  2971.    }
  2972.    else
  2973.    {
  2974.       value = query_dialog_item(handle, IDS_FG_RED, DAC_SPIN_VALUE)+0;
  2975.       value = shiftl(value, 8);
  2976.  
  2977.       value = or(query_dialog_item(handle, IDS_FG_GREEN, DAC_SPIN_VALUE)+0, value);
  2978.       value = shiftl(value, 8);
  2979.  
  2980.       value = or(query_dialog_item(handle, IDS_FG_BLUE, DAC_SPIN_VALUE)+0, value);
  2981.    }
  2982.  
  2983.    return value;
  2984. }
  2985.