home *** CD-ROM | disk | FTP | other *** search
Text File | 1990-09-27 | 27.7 KB | 1,053 lines |
- # $Header: P:/source/ppee/macros/help.pev 1.68 24 Sep 1990 17:24:50 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: help.pel $: help menus
-
-
- global BAR_COLOR = 0x0030 # color of top bar line and pulldown windows
- global HBAR_COLOR = 0x004F # color of highlighted items
- global TBAR_COLOR = 0x0013 # color of factory window title bar
- global SHADOW_COLOR = 0x0008 # color of window shadows
-
- local help_offsets; # offsets of items on title bar
- local help_length; # lengths of each item on title bar
- local help_list; # list of all items in pulldown menus
- local help_names; # names on title bar
- local help_names_length; # length of all items on title bar
- local help_heights; # number of entries for each pulldown menu
- global help_resident = 0 # 1 if help bar is to remain
-
- local MINUS = 45
- local ALT_H = 0x2300
-
- local SEPARATOR = "" # name separator in help file
- local MAX_INDEX; # number of entries on top line
- local help_index; # index into top line entries
- local pulldown_index; # index into pulldown menu
- local pulldown_window = 0; # current pulldown window
- local pulldown_shadow = 0; # current pulldown shadow window
- local pulldown_width; # width of text in current pulldown_window
- local pulldown_height; # height of text in current pulldown_window
- local pulldown_x; # starting x of pulldown window text
- local pulldown_y; # starting y of pulldown window text
- local help_selection; # if ENTER pressed, hold string of selection
- local help_buffer = 0; # buffer containing the help database
- local help_calls; # function names to call when a selection is made
- local help_keymap; # keymap to use during help
- local help_window = 0; # handle for top title bar
- local help_mouse_handler_id=0;# id of mouse event handler
- local helpInitialized = 0; # indicates whether the help data structures
- # have been initialized
- local save_last_window = 0; # save the window before help was called
-
-
- local item_window_x0 = 5 # current displayed help item coordinates
- local item_window_y0 = 2
- local item_window_width = 66
- local item_window_height = 20
-
-
-
- global menu_colors_initialized = 0;
-
-
- ## initialize menu and other system colors dependent upon the
- # current display mode (7 = mono, !7 = assume color)
- #
- global function init_menu_colors(){
-
- if (!menu_colors_initialized) {
- menu_colors_initialized = 1;
-
- # color of top bar line and pulldown windows
- if (display_mode() == 7) {
- # mono
- BAR_COLOR = 0x0007;
- HBAR_COLOR = 0x0070;
- TBAR_COLOR = 0x0070;
- SHADOW_COLOR = 0x0007;
- } else {
- # color
- BAR_COLOR = 0x0030;
- HBAR_COLOR = 0x004F;
- TBAR_COLOR = and( default_color_text, 0xf0) \
- ? 0x03 \
- : 0x13
- SHADOW_COLOR = 0x0008;
- }
- }
- }
-
-
-
-
- #--------------------------------------------------------------------------
- #
- # Help file format:
- #
- # Line
- # 1 Header line - names that appear on title bar
- # 2 Menu items - items for first name on line 1
- # 3 Function calls - for items listed on line 2
- # 4 Menu items - items for second name on line 1
- # 5 Function calls - for items listed on line 4
- # .
- # .
- # .
- # 2n Menu items - items for nth name on line 1
- # 2n+1 Function calls - for items listed on line 2n
- # 2n+2 Menu headings - names associated with information below
- # 2n+3 Menu information - any help info
- # .
- # .
- # .
- # 2n+x
- # 2n+x+1 repeat lines 2n+2 to 2n+x
- #
- #
- # The field separator for all names is SEPARATOR ()
- #
- # "Header line" - a list of names to appear on the top level title bar.
- # "Menu items" - a list of names to appear in the pulldown window.
- # The capital letter in each name can be used as an
- # excellerator key. All names must be padded with
- # spaces to the same length or else the will appear
- # scrambled when pulled down.
- # "Function calls" - a list of function calls to make. If no call is to be
- # made, just leave it blank and add the field separator.
- # If no function name is entered, the name that was
- # selected from a pulldown window is search for in
- # the "Menu headings". If one is found, the "Menu
- # information" for that heading is displayed.
- # "Menu headings" - a list of names that are associated with the "Menu
- # information" listed below it; separated by .
- # "Menu information" - a text page (or more) of help information for the
- # names listed in the associated "Menu headings" list.
- #
- #
- # To invoke a menu item directly from the title menu, leave the "Menu items"
- # blank but still add the function to invoke on the "Function calls" line.
- #----------------------------------------------------------------------------
-
- ## invoke the help pulldown menus
- #
- global function help(){
- pulldown_index = 0;
- help_start( help_index > 0 ? help_index - 1 : 0);
- }
-
-
- ## install or remove the help title bar
- #
- # 0 == remove
- # 1 == install
- # "" == toggle current setting
- #
- global function help_install( mode ){
- local resident = argcount() ? mode + 0 : !help_resident;
- if (resident != help_resident) {
- if (resident)
- shrink_windows_down_1();
- else
- grow_windows_up_1();
- }
- help_resident = resident;
- help_start( -1 );
- }
-
- ## toggle the installation of the help menu bar
- #
- global function toggle_help( mode ){
- if (argcount())
- help_install( mode );
- else
- help_install();
- }
-
-
-
- ## Initialize the help data structures to a given filename.
- # No validation is made on the new file to ensure is actually
- # is in the help file format.
- #
- global function help_init( fn ){
- if (!argcount())
- return;
- help_install( fn );
- }
-
- ## pulldown the index'th help item window immediately
- #
- global function help_immediate( index ){
- pulldown_index = 1;
- help_start( index );
- }
-
-
- #
- # Initialize the help data structures by opening the help file and
- # reading the initial title bar and pulldown selection names.
- #
- # This function can be called more than once with a different txtfile.
- # If txtfile == "" or none specified, the default name found in
- # help_txt_name is used and searched for in the directory that
- # the environment variable SAGEEDIT points to.
- #
- local function help_initialize( txtfile ){
- local save_buffer = current_buffer;
- local names;
- local save_keymap = current_keymap;
- local i;
- local help_menu;
- local str;
- local eol_str;
-
-
- init_menu_colors();
-
- #
- # free all of the previous data structures.
- #
- delete( help_names );
- delete( help_calls );
- delete( help_list );
- delete( help_length );
- delete( help_heights );
- if (help_window)
- delete_window( help_window );
-
- if (help_buffer)
- delete_buffer( help_buffer );
-
- #
- # try to open the help text file and put the data in a buffer
- #
- if (!argcount() || !txtfile) {
- if ( !(txtfile = locate_sageedit_file(SAGEEDIT_FILE_HELP))) {
- txtfile = editor_path( SAGEEDIT_FILE_HELP )
- }
- }
-
- eol_str = default_buffer_eol_string;
- default_buffer_eol_string = "\r\n";
- current_buffer = help_buffer = create_buffer( "", txtfile,
- BUFFER_READ_ONLY + BUFFER_NO_UNDO + BUFFER_SYSTEM );
- default_buffer_eol_string = eol_str;
-
-
- buffer_flags = and( buffer_flags, not(BUFFER_READ_ONLY) );
- if (!buffer_size || !help_buffer) {
- #
- # the file is new, empty, or invalid
- #
- delete_buffer();
- current_buffer = save_buffer;
- warning( "No help available in file: %s", txtfile );
- return FALSE;
- }
-
- #
- # read in the help header information.
- #
- MAX_INDEX = split( read_buffer(), help_names, SEPARATOR);
- if (!MAX_INDEX) {
- current_keymap = save_keymap;
- current_buffer = save_buffer;
- return FALSE;
- }
-
- down();
-
- #
- # initialize the lengths of each pulldown name and compute a total
- # length of all names.
- #
- help_names_length = 0;
- for (i in help_names)
- help_names_length += (help_length[ i ] = length(help_names[i]));
-
- #
- # read in all of the pulldown window items
- #
- for (i in help_names) {
- #
- # read in the pulldown names. They should already be padded
- # with spaces to make them all the same length
- #
- help_list[i] = read_buffer();
- help_heights[ i ] = gsub( "", "", help_list[i] );
- down(1);
- help_calls[ i ] = read_buffer();
- down(1);
- }
-
- #
- # delete the header information from the buffer.
- #
- drop_anchor( NORMAL_SELECTION );
- goto_buffer_top();
- delete_chars();
-
- #
- # create a keymap to use when the help is activated.
- #
- current_keymap = help_keymap = create_keymap( empty_keymap );
-
- assign_key( "<Up>", "help_up" );
- assign_key( "<Down>", "help_down" );
- assign_key( "<Left>", "help_left" );
- assign_key( "<Right>", "help_right" );
- assign_key( "<Esc>", "help_esc" );
- assign_key( "<Enter>", "help_enter" );
- assign_key( "<Keypad-Enter>", "help_enter" );
- assign_key( "<Alt-H>", "help_enter" );
-
- assign_key( "#61440", "left_press_help" ) # left press
- assign_key( "#62208", "left_release_help" ) # left release
- assign_key( "#62976", "left_click_help" ) # left click
-
- current_keymap = save_keymap;
- current_buffer = save_buffer;
-
- return TRUE;
- }
-
- #
- # help_start()
- #
- # Actually invoke the help system and display the top title bar
- # (if it isn't already).
- #
- # index >= 0 the pulldown menu to be displayed ( indices from 0..n )
- # == -1 no pulldown, no highlight, just display title and return
- #
- local function help_start( index ) {
- local ch;
- local save_keymap;
- local save_window = current_window;
- local save_buffer = current_buffer;
- local save_buffer_keymap = buffer_keymap;
- local save_cursor_normal = cursor_normal;
- local save_cursor_virtual = cursor_virtual;
- local save_cursor_overtype = cursor_overtype;
- local save_cursor_virtual_overtype = cursor_virtual_overtype;
- local i;
- local unassign_key_event = function_id( "help_excellerator" )
- local spaces;
- local id_name;
- local more_help = 1;
-
- #
- # delete the mouse event if there is one.
- #
- if (help_mouse_handler_id) {
- delete_event( EVENT_NEW_CURNT_WINDOW, \
- help_mouse_handler_id );
- help_mouse_handler_id = 0;
- }
-
-
- #
- # initialize the help data structures if they haven't been already
- #
- if ( !helpInitialized ) {
- if ( !(helpInitialized = help_initialize()) ) {
- restorePrevWindow();
- return;
- }
- }
-
- # compute the amount of white space to go between each entry
- i = MAX_INDEX > 1 ? MAX_INDEX - 1 : 1
- spaces = (display_width - 1 - help_names_length) / i;
-
- help_selection = "";
- pulldown_shadow = pulldown_window = 0;
-
- #
- # create the top title bar window if it doesn't exist
- #
- if (help_window) {
- current_window = help_window;
- } else {
- current_window =
- help_window =
- create_factory_window( 0, 0, display_width, 1, WINDOW_NOBORDER + WINDOW_SYSTEM);
- }
- color_border = BAR_COLOR
-
-
- #
- # display the names in the title bar
- #
- display_update();
- highlight_window( 0, 0, display_width, 1, BAR_COLOR, help_window );
- window_cursor_x = 1;
- window_cursor_y = 0;
- for (i in help_names) {
- help_offsets[ i ] = window_cursor_x;
- write_window( help_names[ i ] );
- window_cursor_x += spaces;
- }
-
- #
- # should a pulldown window be displayed?
- #
- if (index >= 0) {
- # erase cursor
- #
- cursor_overtype = cursor_virtual_overtype = \
- cursor_virtual = cursor_normal = 0x0FFFF;
-
- # help_indices run from 1 to n+1
- help_index = 1 + index;
-
- help_show( help_index );
-
- while( more_help ) {
- more_help = 0;
- #
- # swap keymaps and begin the help menu process
- #
- save_keymap = current_keymap;
- current_keymap = buffer_keymap = help_keymap;
- attach_event_handler( EVENT_UNASSGN_KEY, unassign_key_event );
- process_begin();
- delete_event( EVENT_UNASSGN_KEY, unassign_key_event );
- current_keymap = save_keymap;
-
- #
- # help is now done. Put back original keymap and restore
- # cursor.
- #
- buffer_keymap = save_buffer_keymap;
- cursor_normal = save_cursor_normal;
- cursor_virtual = save_cursor_virtual;
- cursor_overtype = save_cursor_overtype;
- cursor_virtual_overtype = save_cursor_virtual_overtype;
- id_name = help_call_id(); # if an item was selected, what was is
- if ((current_key == ALT_H) \
- || (help_selection && (id_name == ""))) {
-
- # no associated function, try to display
- # some help information
- more_help = help_selection \
- ? display_help_item( help_selection ) \
- : TRUE;
- help_selection = "";
- }
- }
- free_pulldown_window(); # free the pulldown window
- help_xshow( help_index ); # clear highlighted title
- }
-
-
-
- if (window_valid(save_window)) {
- current_window = save_window; # restore original window.
- current_buffer = save_buffer;
- }
-
- # if the menu bar is NOT to remain, delete the window.
- if (!(help_resident+0)) {
- delete_window( help_window );
- help_window = 0;
- }
-
- restorePrevWindow();
-
- display_update()
-
- if (help_selection && (id_name != "")) {
- # execute the associated function
- execute_function( id_name );
- }
-
-
- if (help_resident) {
- #
- # remain resident and install a mouse handler to
- # allow invocation with a mouse
- #
- help_mouse_handler_id = function_id( "help_mouse_handler" );
- attach_event_handler( EVENT_NEW_CURNT_WINDOW, help_mouse_handler_id );
- }
- }
-
-
- ## <ESC> key was pressed from within a pulldown window.
- #
- # backup one level or exit if at the top level.
- #
- function help_esc(){
- if (pulldown_window) {
- free_pulldown_window(); # free the pulldown window
- pulldown_index = 0;
- } else {
- process_end();
- }
- }
-
-
- ## <Enter> key was pressed from within a pulldown window.
- #
- # Set "help_selection" to the name of the item which was pressed.
- #
- function help_enter(){
- local save_window = current_window;
-
- if (pulldown_index && pulldown_window) {
- current_window = pulldown_window;
-
- window_cursor_x = 0;
- window_cursor_y = pulldown_index - 1;
- help_selection = trim( read_window( pulldown_width ));
-
- assign_current_window( save_window );
- process_end();
- } else if (help_heights[ help_index ] == 0){
- help_selection = help_names[ help_index ]
- process_end();
- } else {
- help_down()
- }
- }
-
-
-
- ## process a down arrow press within a pulldown window
- #
- function help_down(){
- help_vertical( (pulldown_index >= pulldown_height) \
- ? 1 \
- : pulldown_index + 1);
- }
-
- ## process an up arrow press within a pulldown window
- #
- function help_up(){
- help_vertical( (pulldown_index <= 1 ) \
- ? pulldown_height \
- : pulldown_index - 1);
- }
-
-
- ## move vertically within a pulldown window
- #
- # i == the i-th element in the window to display.
- #
- function help_vertical( i ){
- if (pulldown_window) {
- # a window is visible
- if (pulldown_index) {
- # an item is highlighted
- highlight_window( 0, pulldown_index-1, \
- pulldown_width, 1, \
- BAR_COLOR, pulldown_window );
- display_update();
- }
- pulldown_index = (i + 0);
- if (pulldown_index) {
- # a new item is to be highlighted
- highlight_window( 0, pulldown_index-1, \
- pulldown_width, 1, \
- HBAR_COLOR, pulldown_window );
- display_update();
- }
- } else {
- # no pulldown window yet, display one now
- # highlight the first item only if no left mouse press
- if ( !and( mouse_buttons, LEFT_BUTTON ))
- pulldown_index = 1;
- help_pulldown( help_offsets[ help_index ], 1, help_index );
- }
- # flush_keyboard();
- }
-
- ## Move left to a new pulldown window. Wrap if before left edge.
- #
- function help_left(){
- if (pulldown_index)
- pulldown_index = 1;
- help_horizontal( -1 );
- }
-
- ## Move right to a new pulldown window. Wrap if past the right edge.
- #
- function help_right(){
- if (pulldown_index)
- pulldown_index = 1;
- help_horizontal( 1 );
- }
-
- #
- # Move horizontally to a new pulldown window.
- #
- # i == the relative number of windows to move left or right.
- #
- function help_horizontal( i ){
- help_xshow( help_index );
- help_index += (i + 0);
- if (help_index <= 0)
- help_index = MAX_INDEX;
- else if (help_index > MAX_INDEX)
- help_index = 1;
- help_show( help_index );
- display_update();
- # flush_keyboard();
- }
-
- #
- # highlight the "help_index"-th name on the title bar and
- # display a pulldown window if "pulldown_index > 0"
- #
- function help_show( help_index ){
- highlight_window( help_offsets[help_index], 0, \
- help_length[help_index], 1, HBAR_COLOR );
- if (pulldown_index)
- help_pulldown( help_offsets[ help_index ], 1, help_index );
- }
-
- #
- # unhighlight the "help_index"-th name on the title bar and
- #
- local function help_xshow( help_index ){
- free_pulldown_window();
- highlight_window( help_offsets[help_index], 0, \
- help_length[help_index], 1, BAR_COLOR );
- }
-
- #
- # help_pulldown(x,y,index)
- #
- # Display a pulldown window with all names.
- # If "pulldown_index" > 0, highlight that element in the window.
- #
- # index == the i-th window to pulldown
- # x == left edge of window
- # y == top line of window
- #
- local function help_pulldown( x, y, index ){
- local maxlength = 0;
- local save_window = current_window;
- local list = help_list[ index ];
-
- #
- # determine the height and width of the window
- #
- pulldown_height = help_heights[ index ];
-
- free_pulldown_window(); # free any current pulldown window.
-
- if (pulldown_height == 0) {
- pulldown_index = 1;
- return
- }
-
- pulldown_width = maxlength = length( list ) / pulldown_height;
- maxlength += 2; # add 2 for borders
-
- # adjust "x" so it fits on the display
- if (x+maxlength > display_width)
- x = display_width - maxlength;
-
-
- #
- # create a black pulldown shadow window
- #
- pulldown_shadow =
- current_window =
- create_factory_window( x+1, y+1, maxlength, pulldown_height+2, WINDOW_NOBORDER );
- color_text = 0x0000;
-
- #
- # create the new pulldown window
- #
- pulldown_window =
- current_window =
- create_factory_window( pulldown_x = x,
- pulldown_y = y,
- maxlength,
- pulldown_height+2,
- WINDOW_BORDER );
- color_text = BAR_COLOR;
- color_border = BAR_COLOR;
-
- #
- # write the list of name to the window.
- #
- display_update();
- window_cursor_x = window_cursor_y = 0;
- write_window( list, pulldown_window );
-
- if (pulldown_index) {
- #
- # highlight an element in the window.
- #
- window_cursor_x = window_cursor_y = 0;
- highlight_window( 0, 0, pulldown_width, 1, HBAR_COLOR );
- # flush_keyboard();
- }
-
- assign_current_window( save_window );
- display_update();
- }
-
- #
- # Free the current pulldown window and its shadow window (if they exist)
- #
- local function free_pulldown_window(){
- if (pulldown_window) {
- delete_window( pulldown_window );
- delete_window( pulldown_shadow );
- }
- pulldown_shadow = pulldown_window = 0;
- }
-
- #
- # determine what to do when an item is selected
- #
- # Returns:
- # str id_name = the name of the associated function to execute.
- # = "" if nothing to do.
- #
- local function help_call_id() {
- local help_call_array;
- local id_name;
- local index;
-
- #
- # determine the associated function for the current
- # help_index and pulldown_index.
- #
- split( help_calls[ help_index ], help_call_array, SEPARATOR );
- index = pulldown_index;
- if (!index) index++;
- id_name = (index in help_call_array) \
- ? help_call_array[ index ] \
- : ""
- delete( help_call_array );
- return id_name;
- }
-
- #
- # given a name, look through the remainder of the help file for
- # "" name "". If one is found, display the help information for it.
- #
- global function display_help_item( name ){
- local save_buffer = current_buffer
- local found = FALSE;
- local first_line, last_line;
- local ch;
- local display_window;
- local display_buffer;
- local continue_help = FALSE;
-
-
- if ( !helpInitialized )
- if ( !(helpInitialized = help_initialize()) )
- return;
-
- name = tolower(ltrim(trim( name )))
-
- current_buffer = help_buffer;
- goto_buffer_top();
- goto_bol();
- if ( (found = search( "" name "", SEARCH_FORWARD+SEARCH_IGNORE_CASE )) ) {
- #
- # Help information exists for this name.
- # Compute the number of lines from the current line + 1
- # to the end of the help information (i.e. end of buffer
- # or next help item).
- #
- down();
- first_line = current_line;
- if (search( "^", SEARCH_REGEX + SEARCH_FORWARD ))
- # found next help item
- last_line = current_line - 1;
- else {
- goto_buffer_bottom();
- last_line = current_line;
- }
- }
- current_buffer = save_buffer;
-
- if (found) {
- #
- # display the help information, but first transfer the
- # data to a new buffer.
- #
- current_window =
- display_window =
- create_factory_window( item_window_x0,
- item_window_y0,
- item_window_width,
- item_window_height,
- WINDOW_SB_BELOW + WINDOW_SB_RIGHT + WINDOW_BORDER + WINDOW_SYSTEM );
- current_buffer =
- display_buffer = create_buffer( "", "", BUFFER_SYSTEM + BUFFER_NO_UNDO );
- transfer( help_buffer, first_line, 1, last_line, 80 );
- attach_window_buffer( display_window, display_buffer );
- color_text = color_border = BAR_COLOR;
- color_highlight = HBAR_COLOR;
-
- do {
- #
- # process all of the keys which are pressed while
- # the help is displayed.
- #
- display_update(); # update the screen
-
- ch = getchar();
-
- if (ch == 0) {
- ch = getchar(); # expanded code, get rest of key
- if (ch == SCANCODE_DOWN) {
- scroll_vertical(1);
- } else if (ch == SCANCODE_UP) {
- scroll_vertical(-1);
- } else if (ch == SCANCODE_LEFT) {
- scroll_horizontal(-1);
- } else if (ch == SCANCODE_RIGHT) {
- scroll_horizontal(1);
- } else if (ch == SCANCODE_PGUP) {
- page_up();
- } else if (ch == SCANCODE_PGDN) {
- page_down();
- } else if (ch == SCANCODE_LEFT_PRESS) {
- if (window_contains( mouse_event_x, mouse_event_y ))
- if ( !and(mouse_position(1), MOUSE_LEFT ))
- left_press( 1 );
- } else if (ch == SCANCODE_RIGHT_PRESS) {
- if (window_contains( mouse_event_x, mouse_event_y ))
- if ( and(mouse_position(1), MOUSE_IN_TEXT ))
- dynamic_selection( COLUMN_SELECTION, RIGHT_BUTTON )
- }
- } else {
- if (ch == ASCII_ESC) {
- continue_help = TRUE;
- break;
- } else if (ch == ASCII_CR) {
- #
- # copy any marked block to scrap
- # and return
- #
- if (region_type()) {
- copy_to_scrap();
- raise_anchor();
- }
- break;
- } else if ((ch == MINUS) || (ch == ASCII_BACKSPACE)) {
- continue_help = TRUE;
- break;
- }
- }
- } while (TRUE);
-
- #
- # set coordinates for the next time this
- # window is displayed
- #
- item_window_x0 = window_x0
- item_window_y0 = window_y0
- item_window_width = window_width
- item_window_height = window_height
-
- delete_buffer( display_buffer );
- delete_window( display_window );
- current_buffer = save_buffer;
- } else {
- warning( "No help available for: %s", name );
- }
- return continue_help;
- }
-
- #
- # Process any characters which are pressed when a pulldown window is visible.
- # The processing includes searching through the list of elements with
- # an upper case character matching the character which was pressed.
- #
- function help_excellerator(){
- local save_window = current_window;
- local str;
- local index;
- local ch = and(current_key, 0x00FF);
- local i = 0;
-
- if (((ch >= 65) && (ch <= 90)) || ((ch >= 97) && (ch <= 122))) {
- if (pulldown_window) {
- current_window = pulldown_window;
- window_cursor_x = window_cursor_y = 0;
- str = read_window( pulldown_height * pulldown_width - 1);
- index = cindex( str, toupper( chr( ch )))
- if (index) {
- #
- # A match was found. Set pulldown index to
- # that element and return to help processing
- #
- pulldown_index = (index / pulldown_width) + 1;
- current_key = 0;
- help_enter();
- } else {
- beep();
- }
- assign_current_window( save_window );
- } else {
- str = toupper(chr(ch));
- for (i in help_names) {
- if (index(help_names[i], str)) {
- help_horizontal(i - help_index)
- current_key = 0;
- help_vertical(1);
- break;
- }
- }
- }
- }
- }
-
- #------------ Mouse support ------------------------------------------------
-
- #
- # Process left mouse button presses while the help menu is active.
- #
- function left_press_help(){
- local x;
- local y;
- local i;
- local wc;
-
- do {
- wc = window_containing( x = mouse_display_x, y = mouse_display_y );
- if ( wc == help_window ) {
- #
- # an item on the top title menu is now selected.
- #
- if (pulldown_window)
- help_vertical( 0 ); # clear pulldown highlight
- i = MAX_INDEX; # find title menu selection
- while (x < help_offsets[i])
- i--;
- if ( (i = (i ? i : 1) - help_index) ) { # move left or right
- # raise the pulldown window.
- pulldown_index = 0;
- help_horizontal( i );
- help_pulldown( help_offsets[ help_index ], 1, \
- help_index );
- }
- } else if ( wc == pulldown_window ) {
- #
- # an item in the pulldown window is now selected
- x -= pulldown_x;
- if ((x <= 0) || (x > pulldown_width)) {
- help_vertical( 0 );
- } else {
- y -= pulldown_y;
- if (y != pulldown_index) {
- if ((y <= 0) || (y > pulldown_height))
- y = 0;
- help_vertical( y );
- }
- }
- } else
- # remove highlight within a pulldown window.
- help_vertical( 0 );
- } while (and(mouse_buttons,LEFT_BUTTON));
-
- #
- # signal that the button was released.
- # This may or may not be overkill if the keyboard buffer actually
- # receives a left_release button.
- #
- left_release_help();
- }
-
- function left_click_help(){
- left_press_help();
- }
-
- function left_release_help(){
- local wc = window_containing( mouse_event_x, mouse_event_y );
- if ((pulldown_window == 0) && (help_heights[ help_index ] != 0) )
- help_pulldown( help_offsets[ help_index ], 1, help_index );
- else if ( (wc == pulldown_window ) || (help_heights[ help_index ] == 0) )
- help_enter();
- else if ( wc != help_window )
- process_end();
- }
-
-
- local in_mouse_handler = FALSE;
-
- ## Handle all current_window changes made while the help title bar is
- # resident. When the help_window becomes current, invoke the
- # help system. Normally, clicking on the help_window will
- # not make it permanently current because it is a system window.
- #
- function help_mouse_handler(){
- local i;
- local x;
-
- #
- # avoid event calls to this function if left_press_help()
- # is called. help_start() will delete the event so in that
- # case, there's nothing to worry about
- #
- if ( ( !in_mouse_handler ) &&
- ( and(mouse_buttons, LEFT_BUTTON) ||
- (current_key == LEFT_CLICK) ||
- (current_key == LEFT_PRESS) )) {
- in_mouse_handler = TRUE;
-
- if ((current_window == help_window) &&
- window_contains(mouse_event_x, mouse_event_y, help_window )){
- i = MAX_INDEX;
- x = mouse_event_x;
- while (x < help_offsets[i--])
- continue;
-
- pulldown_index = 1;
- if (and(mouse_buttons, LEFT_BUTTON))
- ungetkey( 61440 ); # left_press
- help_start( i );
-
- # flush_keyboard();
- }
- in_mouse_handler = FALSE;
- }
- save_last_window = current_window;
- }
-
- ## restore the previous window before help was invoked. This may
- # be tricky if the previous window was deleted.
- #
- local function restorePrevWindow(){
- if (in_mouse_handler) {
- if (save_last_window)
- if (window_valid( save_last_window ))
- current_window = save_last_window;
- if ( !save_last_window ||
- (current_window != save_last_window) ||
- (current_window == help_window))
- # see if the save_last_window was deleted
- prev_window();
- }
- }
-
-