home *** CD-ROM | disk | FTP | other *** search
Text File | 1990-09-27 | 26.8 KB | 1,085 lines |
- # $Header: P:/source/ppee/macros/setup.pev 1.34 20 Aug 1990 13:48:16 skipr $
-
- ##############################################################################
- #
- # Sage Software - POLYTRON Division
- # 1700 NW 167th Place
- # Beaverton, OR 97006
- #
- # Copyright 1990, Sage Software, Inc.
- #
- # Permission is hereby granted for licensed users of Sage Professional
- # Editor and PolyAwk to copy and modify this source code for their own
- # personal use. These derivative works may be distributed only to other
- # licensed Sage Professional Editor and PolyAwk users. All other usage
- # is prohibited without express written permission from Sage Software.
- #
- ##############################################################################
-
- #### $Workfile: setup.pel $: Configuration Menus
-
- local emulationMode = ""
- local windowOptions = ""
- local windowColors = ""
-
- local inColorsMenu
- local sampleColorsWindow
- local colorBarWindow
-
- #############################################
- # #
- # MENU COLORS #
- # #
- # BLACK = 0 DGRAY = 0x8 #
- # BLUE = 1 LBLUE = 0x9 #
- # GREEN = 2 LGREEN = 0xa #
- # CYAN = 3 LCYAN = 0xb #
- # RED = 4 LRED = 0xc #
- # PURPLE = 5 LPURPLE = 0xd #
- # BROWN = 6 YELLOW = 0xe #
- # GRAY = 7 WHITE = 0xf #
- # #
- #############################################
-
- # a few useful color combinations:
- local CyanOnBlack = 0x03
- local GrayOnBlack = 0x07
- local WhiteOnBlack = 0x0f
- #local BlackOnBlue = 0x10
- local CyanOnBlue = 0x13
- #local GrayOnBlue = 0x17
- #local GreenOnBlue = 0x1a
- #local YellowOnBlue = 0x1f
- local WhiteOnBlue = 0x1f
- #local CyanOnGreen = 0x23
- local YellowOnGreen = 0x2e
- local WhiteOnGreen = 0x2f
- #local WhiteOnRed = 0x4f
- #local PurpleOnPurple = 0x5d
- #local WhiteOnPurple = 0x5f
- #local GrayOnBrown = 0x67
- #local YellowOnBrown = 0x6e
- #local WhiteOnBrown = 0x6f
- local BlackOnGray = 0x70
- #local PurpleOnGray = 0x75
- local GrayOnGray = 0x78
-
- # default colors assiciated with the "windowColors" variable defined above
- local textColor = CyanOnBlack
- local highlightColor = BlackOnGray
- local borderColor = GrayOnBlack
- local titleColor = GrayOnGray
-
-
- ##############
- # setup menu #
- ##############
-
- global function setup() {
-
- local priorTextColor = default_color_text
- local priorHighlightColor = default_color_highlight
- local priorBorderColor = default_color_border
- local priorTitleColor = default_color_title
- local priorLineNumbers = default_linenumber_format
- local priorWindow = current_window
- local priorBuffer = current_buffer
- local fullScreenWindow
- local choice = 1
-
- # general initialization
-
- # colors to use for illustrateWindow functions
- textColor = default_color_text
- highlightColor = default_color_highlight
- borderColor = default_color_border
- titleColor = default_color_title
-
- # turn off visible line numbers
- default_linenumber_format = ""
-
- # set up the screen
-
- if ( !and( color_background, 0x100 ) ) {
- # turn off blinking
- color_background = or( color_background, 0x100 )
- }
- display_update()
-
- default_color_text = GrayOnBlack
- fullScreenWindow = create_window( \
- 0, 0, \
- display_width, display_height, \
- WINDOW_SYSTEM )
- if ( fullScreenWindow ) {
- current_window = fullScreenWindow
- display_update()
- }
- default_color_text = textColor
-
- # invoke setup menu
-
- while (1) {
- initMenu( 20,4, 40,11, WhiteOnGreen, YellowOnGreen, \
- "Select Editor Defaults Menu" )
-
- addMenuItem( "emulation mode", \
- "Emulate key actions and appearance of other editors")
-
- addMenuItem( "window options", \
- "Set options governing the appearance of a window")
-
- addMenuItem( "colors", \
- "Select colors to use for windows and text")
-
- addMenuItem( "save settings in SAGEEDIT.CFG", \
- "Write a new \"SAGEEDIT.CFG\" file with the current settings")
-
- addMenuItem( "temporarily accept settings", \
- "use new options without saving to \"SAGEEDIT.CFG\" file" )
-
- choice = getMenuSelection( choice )
-
- deleteMenu()
-
- if ( choice == 0 ) {
- # Esc key - reset options
- emulationMode = \
- windowColors = \
- windowOptions = ""
- break
- } else if ( choice == 1 ) {
- selectEmulationMode()
- choice = 2
- } else if ( choice == 2 ) {
- setWindowOptions()
- choice = 3
- } else if ( choice == 3 ) {
- selectColors()
- choice = 4
- } else if ( choice == 4 ) {
- # write new config file
- saveStartupFile()
- break
- } else if ( choice == 5 ) {
- # use new values without saving to config file
- break
- }
-
- } # while (1)
-
- # restore 'prior' variables
-
- if ( fullScreenWindow ) {
- delete_window( fullScreenWindow )
- }
-
- if ( emulationMode != "" ) {
- if ( emulationMode != emulation_mode ) {
- execute_function( emulationMode )
- if ( emulationMode == emulation_mode ) {
- message( emulationMode " enabled" )
- }
- }
- }
-
- if ( windowColors == "" ) {
- # restore colors
- default_color_text = priorTextColor
- default_color_highlight = priorHighlightColor
- default_color_border = priorBorderColor
- default_color_title = priorTitleColor
- } else {
- # set to colors chosen in the colors menu
- default_color_text = color_text = textColor
- default_color_highlight = color_highlight = highlightColor
- default_color_border = color_border = borderColor
- default_color_title = color_title = titleColor
- }
-
- if ( windowOptions != "" ) {
- default_window_flags = windowOptions
-
-
- if ( current_window != dialog_window ) {
- window_flags = default_window_flags
- }
- }
-
- # line numbers
- default_linenumber_format = priorLineNumbers
-
- # avoid making a system window/buffer current during startup
- if ( priorWindow )
- current_window = priorWindow
- next_buffer()
- current_buffer = priorBuffer
- }
-
- #######################
- # EMULATION MODE MENU #
- #######################
-
- local function selectEmulationMode() {
-
- local choice = 1
-
- makeWindow( 7,1, 66,10, WhiteOnBlue, CyanOnBlue, "" )
-
- put( 2,4,"Choose the Editor Emulation Mode you prefer, or hit the Esc")
- put( 3,4,"key to retain the present settings. Your selection will")
- put( 4,4,"determine what meaning is given to your keystrokes and what")
- put( 5,4,"commands are available. Native Mode is the mode in which")
- put( 6,4,"the Sage Professional Editor was designed to operate. Other")
- put( 7,4,"modes provide familiar commands for users of other editors.")
-
- initMenu( 22,12, 30,12, WhiteOnBlue, CyanOnBlue, \
- "Editor Emulation Modes" )
-
- addMenuItem("Native Mode", "")
- addMenuItem("Brief Emulation", "")
- addMenuItem("VI Emulation", "")
- addMenuItem("WordStar Emulation", "")
- addMenuItem("Epsilon Emulation", "")
- addMenuItem("MS Word Emulation", "")
-
- choice = getMenuSelection( choice )
-
- if ( choice == 1 ) {
- emulationMode = "native"
- } else if ( choice == 2 ) {
- emulationMode = "brief"
- } else if ( choice == 3 ) {
- emulationMode = "vi"
- } else if ( choice == 4 ) {
- emulationMode = "wordstar"
- } else if ( choice == 5 ) {
- emulationMode = "epsilon"
- } else if ( choice == 6 ) {
- emulationMode = "msword"
- }
-
- deleteMenu()
- delete_window()
- }
-
- #######################
- # WINDOW OPTIONS MENU #
- #######################
-
- local function setWindowOptions() {
-
- local menuWindow
- local sampleWindow
- local choice = 1
- local scrollBars = WINDOW_BORDER
-
- initMenu( 5,2, 40,12, WhiteOnBlue, CyanOnBlue, "Window Options" )
-
- addMenuItem( "Borders", "" )
- addMenuItem( "Ruler", "" )
- addMenuItem( "Title Bar", "" )
- addMenuItem( "Vertical Scroll Bar", "" )
- addMenuItem( "Horizontal Scroll Bar", "" )
- addMenuItem( "Accept Current Settings" )
-
- menuWindow = current_window
-
- # initialize a sample window
-
- default_color_text = textColor
- default_color_highlight = highlightColor
- default_color_border = borderColor
- default_color_title = titleColor
-
- sampleWindow = illustrateWindowSettings()
-
- while ( choice > 0 && choice < 6 ) {
-
- current_window = menuWindow
- choice = getMenuSelection( choice )
- current_window = sampleWindow
-
- # keep track of the status of the scroll bars
- if ( and( window_flags, WINDOW_BORDERS ) ) {
- scrollBars = and( window_flags, WINDOW_BORDERS )
- }
-
- if ( choice == 1 ) {
- # toggle borders, retaining state of scroll bars
- window_flags = xor( window_flags, scrollBars )
- if ( and( window_flags, WINDOW_BORDERS ) ) {
- window_flags = or( window_flags, \
- WINDOW_BORDER )
- }
-
- } else if ( choice == 2 ) {
- # ruler
- window_flags = xor( window_flags, WINDOW_RULER )
-
- } else if ( choice == 3 ) {
- # title bar - cycle between top/bottom/neither
- if ( and( window_flags, WINDOW_TITLEA ) ) {
- window_flags = or( \
- xor( window_flags, WINDOW_TITLEA ),
- WINDOW_TITLEB )
- } else if ( and( window_flags, WINDOW_TITLEB ) ) {
- window_flags = xor( window_flags, \
- WINDOW_TITLEB )
- } else {
- window_flags = or( window_flags, \
- WINDOW_TITLEA )
- }
-
- } else if ( choice == 4 ) {
- # vert scroll bar - cycle between right/left/neither
- if ( and( window_flags, WINDOW_SB_RIGHT ) ) {
- window_flags = or( \
- xor( window_flags, WINDOW_SB_RIGHT ),
- WINDOW_SB_LEFT )
- } else if ( and( window_flags, WINDOW_SB_LEFT ) ) {
- window_flags = xor( window_flags, \
- WINDOW_SB_LEFT )
- } else {
- window_flags = or( window_flags, \
- WINDOW_SB_RIGHT )
- }
-
- } else if ( choice == 5 ) {
- # horiz scroll bar
- window_flags = xor( window_flags, WINDOW_SB_BELOW )
-
- } else if ( choice == 6 ) {
- windowOptions = window_flags
- }
-
- }
-
- delete_window( sampleWindow )
- deleteMenu()
- }
-
- ######################
- # WINDOW COLORS MENU #
- ######################
-
- local function selectColors() {
-
- local menuWindow
- local instructWindow
- local choice = 1
-
- initMenu( 5,1, 40,12, WhiteOnBlue, CyanOnBlue, "Colors" )
-
- addMenuItem( "Normal Text", "" )
- addMenuItem( "Highlighted Text", "" )
- addMenuItem( "Borders", "" )
- addMenuItem( "Title and Scroll Bars", "" )
- addMenuItem( "Reset Colors", "" )
- addMenuItem( "Accept Current Settings" )
-
- menuWindow = current_window
-
- colorBarWindow = initColorBar()
-
- default_color_text = textColor
- default_color_highlight = highlightColor
- default_color_border = borderColor
- default_color_title = titleColor
-
- while ( choice ) {
-
- # update the colors in the sample window
- sampleColorsWindow = illustrateWindowColors()
-
- # get menu selection
- current_window = menuWindow
- inColorsMenu = 1
- choice = getMenuSelection( choice )
- inColorsMenu = 0
-
- # activate keyboard-driven color matrix
- if ( choice >= 1 && choice <= 4 ) {
-
- # put up the instructions
- if ( !instructWindow ) {
- instructWindow = makeWindow( \
- 5, 1, \
- 40, 12, \
- WhiteOnBlue, CyanOnBlue, \
- "Colors" )
-
- ctr( 2, "Use arrow keys to select colors:" )
- put( 4, 2, "Move cursor horizontally to change" )
- put( 5, 2, "the foreground color." )
- put( 7, 2, "Move cursor vertically to change" )
- put( 8, 2, "the background color." )
- }
- current_window = instructWindow
- display_update()
-
- # get color bar selection
- colorBarCmd( choice )
-
- } else if ( choice == 5 ) {
- # reset to neutral colors
- default_color_text = textColor = CyanOnBlack
- default_color_highlight = highlightColor= BlackOnGray
- default_color_border = borderColor = GrayOnBlack
- default_color_title = titleColor = GrayOnGray
-
- } else if ( choice == 6 ) {
- # accept current settings
- windowColors = TRUE
- choice = 0
-
- } else { # Esc key
- windowColors = ""
- }
-
- delete_window( sampleColorsWindow )
- }
-
- delete_window( colorBarWindow )
- if ( instructWindow ) {
- current_window = instructWindow
- delete_window()
- }
- current_window = menuWindow
- deleteMenu()
- }
-
- ###
- # illustrateWindowSettings()
- #
- # used in window options menu to display a sample window using the
- # currently defined settings
-
- local sampleBuffer
-
- local function illustrateWindowSettings() {
-
- current_window = create_window( 35,15, 40,9 )
-
- if ( !sampleBuffer ) {
- current_buffer = sampleBuffer = create_buffer( \
- "", \
- "", \
- BUFFER_SYSTEM + BUFFER_NO_UNDO + BUFFER_REAL_SPACE_ONLY )
- attach_window_buffer( current_window, current_buffer )
- display_update()
- insert_string( "\nThis window simulates an editor\n" )
- insert_string( "window. Try the <Enter> key at\n" )
- insert_string( "each menu item to change the\n" )
- insert_string( "appearance of this window.\n" )
- window_name = buffer_name = "Current Settings"
- goto_buffer_top()
- } else {
- current_buffer = sampleBuffer
- attach_window_buffer( current_window, current_buffer )
- }
-
- highlight_window( \
- 9, current_line, \
- 1, current_line_length, \
- color_highlight )
-
- return current_window
- }
-
- ###
- # illustrateWindowColors()
- #
- # used in window colors menu to display a sample window using the
- # currently defined colors
-
- local function illustrateWindowColors() {
-
- current_window = create_window( \
- 5, 14, \
- 40, 9, \
- WINDOW_SYSTEM + WINDOW_STANDARD )
-
- window_name = "Currently Selected Colors"
-
- window_cursor_x = 5
- window_cursor_y = 2
- write_window( "This is normal text." )
-
- window_cursor_x = 5
- window_cursor_y = 4
- write_window( "This is highlighted text." )
-
- highlight_window( 5, 4, window_cursor_x - 5, 1, color_highlight )
-
- return current_window
- }
-
- ###
- # initColorBar()
- # colorBarCmd( choice )
- # setNewColor( choice, x, y )
- #
- # Choose a color from a matrix of foreground and background colors
-
- local function initColorBar() {
-
- local fg, bg
- local c = 0
-
- current_window = create_window( \
- 54, 4, \
- 18, 18, \
- WINDOW_SYSTEM + WINDOW_BORDER )
- color_border = CyanOnBlack
-
- # keep the cursor out of the way
- window_cursor_x = 0
- window_cursor_y = 0
- display_update()
-
- for ( bg=0; bg<16; bg++ ) {
- # write_window( "" )
- for ( fg=0; fg<16; fg++ ) {
- write_window( "" )
- highlight_window( fg, bg, 1, 1, c++ )
- }
- }
- window_cursor_x = 0
- window_cursor_y = 0
-
- return current_window
- }
-
- local function colorBarCmd( choice ) {
-
- local color
- local key
- local scancode
- local w, x, y
-
- current_window = colorBarWindow
-
- # get initial value of color in question
- if ( choice == 1 ) {
- color = textColor
- } else if ( choice == 2 ) {
- color = highlightColor
- } else if ( choice == 3 ) {
- color = borderColor
- } else if ( choice == 4 ) {
- color = titleColor
- }
-
- if ( color < 0 || color > 255 ) {
- color = WhiteOnBlack
- }
-
- window_cursor_x = and( color, 15 )
- window_cursor_y = shiftr( color, 4 )
-
- while ( 1 ) {
-
- # get color bar command
- key = get_command()
- scancode = shiftr( key, 8 ) # ignore NumLock status
-
- if ( scancode == SCANCODE_LEFT_PRESS || \
- scancode == SCANCODE_LEFT_CLICK ) {
-
- # update text cursor in response to a mouse press
- if ( !and( x = mouse_display_x - window_text_x0, -16 ) \
- && !and( y = mouse_display_y - window_text_y0, -16 )) {
- window_cursor_x = x
- window_cursor_y = y
- }
-
- if ( and( mouse_buttons, BOTH_BUTTONS )) {
- # continue while either mouse button is down
- ungetkey( shiftl( SCANCODE_LEFT_PRESS, 8 ))
-
- } else if ( window_contains( \
- mouse_event_x, mouse_event_y ) \
- && !window_border_contains( \
- mouse_event_x, mouse_event_y )) {
- # They wound up in the text region.
- # Consider it a selection.
- ungetkey( KEYCODE_ENTER )
- }
-
- } else if ( scancode == SCANCODE_UP ) {
- # decrement background
- window_cursor_y = (window_cursor_y + 15) % 16
-
- } else if ( scancode == SCANCODE_DOWN ) {
- # increment background
- window_cursor_y = (window_cursor_y + 1) % 16
-
- } else if ( scancode == SCANCODE_LEFT ) {
- # decrement foreground
- window_cursor_x = (window_cursor_x + 15) % 16
-
- } else if ( scancode == SCANCODE_RIGHT ) {
- # increment foreground
- window_cursor_x = (window_cursor_x + 1) % 16
-
- } else if ( key == KEYCODE_ENTER \
- || key == KEYCODE_KEYPAD_ENTER ) {
- # save colors
- textColor = default_color_text
- highlightColor = default_color_highlight
- borderColor = default_color_border
- titleColor = default_color_title
- break
-
- } else if ( key == KEYCODE_ESC ) {
- # restore colors
- default_color_text = textColor
- default_color_highlight = highlightColor
- default_color_border = borderColor
- default_color_title = titleColor
- break
- }
-
- setNewColor( choice,
- window_cursor_x,
- window_cursor_y )
- }
- }
-
- local function setNewColor( choice, x, y ) {
- local color
-
- if (x < 0 || x > 15 || y < 0 || y > 15) {
- return
- }
-
- color = or( x, shiftl( y, 4 ))
-
- if ( choice == 1 ) {
- default_color_text = color
- } else if ( choice == 2 ) {
- default_color_highlight = color
- } else if ( choice == 3 ) {
- default_color_border = color
- } else if ( choice == 4 ) {
- default_color_title = color
- }
-
- # update the colors in the sample window
- delete_window( sampleColorsWindow )
- sampleColorsWindow = illustrateWindowColors()
- current_window = colorBarWindow
- display_update()
- }
-
-
- #####################
- # WRITE CONFIG FILE #
- #####################
-
- global function saveStartupFile() {
- local cfgName
- local priorBuffer = current_buffer
- local cf
- local str
- local searchFlag = 0x0034 # ignore case | regex | forward
-
- # locate the config file in the current directory or SAGEEDIT path
- if ( !(cfgName = locate_sageedit_file( SAGEEDIT_FILE_CONFIG ))) {
- cfgName = editor_path( SAGEEDIT_FILE_CONFIG )
- }
-
- # create a buffer for the config file
- #
- # (the buffer is created as a regular buffer rather than as a system
- # buffer so that if the user has manually edited the config file, the
- # changes made in the existing buffer will be reflected here and vice
- # versa)
- #
- if ( !(cf = create_buffer( \
- "", \
- cfgName, \
- BUFFER_NO_UNDO + BUFFER_REAL_SPACE_ONLY ))) {
- return 0
- }
-
- current_buffer = cf
- goto_buffer_top()
-
- #
- # clean out conflicting options
- #
- if ( emulationMode ) {
- while ( search( \
- "^[ /t]*(native|brief|vi|wordstar|epsilon|msword)>", \
- searchFlag ) ) {
- delete_line()
- goto_buffer_top()
- }
- }
- if ( windowOptions != "" ) {
- while ( search( "^[ /t]*default_window_flags", searchFlag ) ) {
- delete_line()
- goto_buffer_top()
- }
- }
- if ( windowColors != "" ) {
- while ( search( "^[ /t]*(default_color_|color_background)", \
- searchFlag ) ) {
- delete_line()
- goto_buffer_top()
- }
- }
-
- #
- # insert the new options
- #
- str = "# Sage Professional Editor - Configuration File"
- if ( !search( "^" str, searchFlag ) ) {
- insert_string( str "\n" )
- }
- if ( !search( "^[ /t]*\\$STATE\\$", searchFlag ) ) {
- goto_buffer_bottom()
- }
- if ( emulationMode ) {
- insert_string( emulationMode "\n" )
- }
- if ( windowOptions != "" ) {
- insert_string( "default_window_flags=" windowOptions "\n" )
- }
- if ( windowColors != "" ) {
- insert_string( "color_background=" color_background "\n")
- insert_string( "default_color_text=" default_color_text "\n" )
- insert_string( "default_color_highlight=" default_color_highlight "\n" )
- insert_string( "default_color_border=" default_color_border "\n" )
- insert_string( "default_color_title=" default_color_title "\n" )
- }
-
- write_buffer()
- delete_buffer()
- current_buffer = priorBuffer
-
- return TRUE
- }
-
- # ---------------------------------------------------------------------------
-
- #################
- # menu utilites #
- #################
-
- # initMenu - create a window for use as a menu
- # deleteMenu - remove window created by initMenu
- # addMenuItem - add an item to the menu
- # getMenuSelection - select an item from the menu
-
- local _menuArray
- local _menuHelpArray
- local _nMenuItems
- local _menuOriginalWindow
- local _messageWindowRequired
-
- global function initMenu( x,y, wide,high, c1,c2, header ) {
-
- _menuOriginalWindow = current_window
-
- makeWindow( x,y, wide,high, c1,c2, header )
-
- delete _menuArray
- delete _menuHelpArray
- _messageWindowRequired = 0
- _nMenuItems = 0
- }
-
- global function deleteMenu() {
- delete_window()
- if ( _menuOriginalWindow ) {
- current_window = _menuOriginalWindow
- }
- }
-
- global function addMenuItem( item, helpText ) {
- _nMenuItems++
- _menuArray[ _nMenuItems ] = item
- if ( helpText != "" ) {
- _menuHelpArray[ _nMenuItems ] = helpText
- _messageWindowRequired = 1
- }
-
- put( _nMenuItems+3, 4, " " _menuArray[ _nMenuItems ] )
- }
-
- global function getMenuSelection( choice ) {
-
- local key
- local scancode
- local prevChoice
- local result = 0
- local i
-
- if ( _messageWindowRequired ) {
- initMenuMsg( window_y0 + window_height + 1, \
- color_text, color_border )
- }
-
- do {
- highlightChoice( choice, prevChoice )
- prevChoice = choice
-
- # get menu command
- key = get_command()
- scancode = shiftr( key, 8 ) # ignore NumLock status
-
- if ( key == KEYCODE_ENTER || key == KEYCODE_KEYPAD_ENTER ) {
- result = choice
- break
- } else if ( scancode == SCANCODE_HOME ) {
- choice = 1
- } else if ( scancode == SCANCODE_END ) {
- choice = _nMenuItems
- } else if ( scancode == SCANCODE_UP ) {
- if ( choice > 1 ) {
- choice--
- }
- } else if ( scancode == SCANCODE_DOWN ) {
- if ( choice < _nMenuItems ) {
- choice++
- }
- } else if ( scancode == SCANCODE_LEFT_PRESS || \
- scancode == SCANCODE_LEFT_CLICK ) {
- choice = mouseMenuSelection( choice )
- }
-
- } while ( key != KEYCODE_ESC )
-
- # clear message line
- if ( _messageWindowRequired ) {
- endMenuMsg()
- }
-
- return result
- }
-
- # Process a mouse press from within getMenuSelection.
- # Tracks the mouse cursor, highlights and returns the current menu item.
- #
- local function mouseMenuSelection( prevChoice ){
- local y0 = window_text_y0 + 2
- local choice = prevChoice
- local where
- local prevWindow
-
- if ( window_contains( mouse_event_x, mouse_event_y )) {
- if ( mouse_position(1) == MOUSE_IN_TEXT ) {
-
- # keep choice up-to-date and highlighted, based on
- # the current mouse position
- do {
- choice = mouse_display_y - y0
-
- if ( choice < 1 ) {
- choice = 1
- } else if ( choice > _nMenuItems ) {
- choice = _nMenuItems
- }
-
- highlightChoice( choice, prevChoice )
- prevChoice = choice
-
- } while( and( mouse_buttons, BOTH_BUTTONS ))
-
- # if they end up in the text region, consider
- # it a selection
- if ( window_contains( mouse_event_x, mouse_event_y ) &&
- !window_border_contains(
- mouse_event_x, mouse_event_y )) {
- ungetkey( KEYCODE_ENTER )
- }
- }
-
- } else if ( inColorsMenu ) {
- # Provide special handling for mouse actions outside of the
- # main colors menu. Normally, mouse actions outside of a
- # menu are ignored during setup.
- #
- prevWindow = current_window
- if ( window_containing( mouse_event_x, mouse_event_y ) ==
- colorBarWindow && choice <= 4 ) {
- # mouse event in colorBar matrix
- current_window = colorBarWindow
- do {
- # get current foreground and background colors
- setNewColor( choice,
- mouse_display_x - window_text_x0,
- mouse_display_y - window_text_y0 )
- } while ( and( mouse_buttons, BOTH_BUTTONS ))
-
- # fix color changes
- textColor = default_color_text
- highlightColor = default_color_highlight
- borderColor = default_color_border
- titleColor = default_color_title
-
- } else if ( window_containing( mouse_event_x, mouse_event_y ) ==
- sampleColorsWindow ) {
- # mouse event in sample window
- where = mouse_position(1)
- if ( where == MOUSE_IN_TEXT ) {
- if ( mouse_event_y != 19 ||
- mouse_event_x < 11 &&
- mouse_event_x > 35 ) {
- choice = 1 # normal text
- } else {
- choice = 2 # highlit text
- }
- } else if ( and( where, MOUSE_N + MOUSE_E )) {
- choice = 4 # title bar
- } else if ( and( where, MOUSE_S + MOUSE_W )) {
- choice = 3 # rest of border
- }
- }
- current_window = prevWindow
- }
- return choice
- }
-
- ## function to highlight the current menu item
- #
- local function highlightChoice( choice, prevChoice ){
- if ( choice != prevChoice ) {
-
- # display help text for current selection
- if ( _messageWindowRequired ) {
- menuMsg( _menuHelpArray[ choice ] )
- }
-
- # un-highlight the previous selection
- highlight_window( \
- 0, prevChoice + 2, \
- window_text_width, 1, \
- color_text )
-
- # update the cursor position
- window_cursor_x = 4
- window_cursor_y = choice + 2
-
- # highlight the current selection
- highlight_window( \
- 1, choice + 2, \
- window_text_width - 2, 1, \
- BlackOnGray )
-
- display_update()
- }
- }
-
- # ---------------------------------------------------------------------------
-
- # low level menu window utilities
-
- # makeWindow - create a text-only window suitable for use with menus
- # put - display a line at specified position in window
- # ctr - center a line at specified row in the window
- # initMenuMsg - make a place for descriptive text to get printed
- # menuMsg - display a one line description for the current menu item
- # endMenuMsg - remove window created by initMenuMsg()
- # get_command - wait for and return a key, after updating the display
-
- # create a window and make it current
- global function makeWindow( x,y, wide,high, c1,c2, header ) {
-
- local priorTextColor = default_color_text
- local priorBorderColor = default_color_border
-
- default_color_text = c1
- default_color_border = c2
-
- current_window = create_window( \
- x,y, \
- wide,high, \
- WINDOW_SYSTEM + WINDOW_BORDER )
-
- if ( header ) {
- ctr( 2, header )
- }
-
- default_color_text = priorTextColor
- default_color_border = priorBorderColor
-
- return current_window
- }
-
- # display a line at specified position in current window
- global function put( row, col, str ) {
- window_cursor_x = col
- window_cursor_y = row - 1
- write_window( str )
- }
-
- # center a line at specified row in the current window
- global function ctr( row, str ) {
- local col = (window_text_width - length(str)) / 2
- if ( col < 1 ) {
- col = 1
- }
- put( row, col, str )
- }
-
-
-
- # make a place for messages and prompts to get printed
-
- local _messageWindow
- local _messageLength
-
- global function initMenuMsg( row, colors1, colors2 ) {
-
- local priorWindow = current_window
-
- _messageWindow = makeWindow(
- 1, row, \
- display_width - 2, 3, \
- colors1, colors2, \
- "" )
- _messageLength = 0
-
- if ( priorWindow ) {
- current_window = priorWindow
- }
- }
-
- global function menuMsg( str ) {
-
- local priorWindow = current_window
- local n = _messageLength - length( str )
-
- current_window = _messageWindow
- put( 0, 0, str )
-
- # blank text remaining from prior message
- if ( n > 0 ) {
- write_window( strrepeat( " ", n ) )
- }
- _messageLength = length( str )
-
- if ( priorWindow ) {
- current_window = priorWindow
- }
- }
-
- global function endMenuMsg() {
- delete_window( _messageWindow )
- _messageWindow = 0
- }
-
- # wait for and return a key
- local function get_command() {
- local key
-
- display_update()
- key = getkey()
- flush_keyboard()
- return key
- }
-