;************************************************************************
;**                  for   B R I E F   ver. 2.1                         *
;**                                                                     *
;**   Clrauto Macro - Change the status of Automatic Color Generation   *
;**                                                                     *
;**         By Tom Bentley     November 1988     Ver. 1.1               *
;**                                                                     *
;**                 (C) Copyright - All rights reserved                 *
;**                                                                     *
;************************************************************************

#include "dialog.h"

(extern auto_color_flag window_color_flag clr_button_text clr_flag)

(macro clrauto
   (
      (int       curr_buff ac_buf_id backup_status)
      (int       clr_chg_auto clr_chg_window)
      (string    env_help insert_string)

      (global    clr_chg_auto clr_chg_window)

      (= clr_chg_auto auto_color_flag)
      (= clr_chg_window window_color_flag)
      (= clr_flag 0)
      (= curr_buff (inq_buffer))
      (= ac_buf_id (create_buffer "clrauto.box" NULL 0))
      (set_buffer ac_buf_id)
      (top_of_buffer)
      (insert "T (3,5) \"Auto Color?\"\n")
      (if (== auto_color_flag 0)
         (
            (insert "L (3,18) \"On(Off)\"\n")
         )
      ;else
         (
            (insert "L (3,18) \"(On)Off\"\n")
         )
      )
      (insert "T (5,3) \"Auto Windows?\"\n")
      (switch window_color_flag
       0
         (
            (insert "L (5,18) \"(None)Color\tBrief\"\n")
         )
       1
         (
            (insert "L (5,18) \"None(Color)Brief\"\n")
         )
       2
         (
            (insert "L (5,18) \"None\tColor(Brief)\"")
         )
      )
      (set_buffer curr_buff)
      (_process_dialog_box 10 18 47 10 "Set Auto Clr" "F10 to Set"
          NULL ac_buf_id "auto_clr_action")
      (delete_buffer ac_buf_id)
      (if (== clr_flag 0)
         (
            (return 0)
         )
      )
      (= env_help (inq_environment "BHELP"))
      (= ac_buf_id (create_buffer "clrauto.rst"
         (+ env_help "\\clrauto.rst") 0))
      (set_buffer ac_buf_id)
      (while (! (inq_position 1 3))
         (
            (delete_line)
         )
      )
      (goto_line 1)
      (delete_to_eol)
      (sprintf insert_string "%d%d" auto_color_flag window_color_flag)
      (insert insert_string)
      (= backup_status (set_backup 0))
      (write_buffer)
      (set_backup backup_status)
      (set_buffer curr_buff)
      (delete_buffer ac_buf_id)
      (return 1)
   )
)

(macro auto_clr_action
   (
      (int   event_type line_no)

      (get_parm 0 event_type)
      (switch event_type
        DIALOG_EXIT_LIST
         (
            (get_parm 1 line_no)
            (get_parm 2 clr_button_text)
            (if (== line_no 3)
               (
                  (if (== clr_button_text "On")
                     (= clr_chg_auto 1)
                  ;else
                     (= clr_chg_auto 0)
                  )
               )
            ;else
               (
                  (if (== clr_button_text "None")
                     (= clr_chg_window 0)
                  )
                  (if (== clr_button_text "Color")
                     (= clr_chg_window 1)
                  )
                  (if (== clr_button_text "Brief")
                     (= clr_chg_window 2)
                  )
               )
            )
         )
        DIALOG_F10
         (
            (= auto_color_flag clr_chg_auto)
            (= window_color_flag clr_chg_window)
            (= clr_flag 1)
         )
      )
      (return TRUE)
   )
)
