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

  1. # $Header:   P:\source\wmacros\mouse.pev   1.7   11 Apr 1995 12:41:02   NOBLE  $
  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:   mouse.pel  $: Mouse support functions
  21.  
  22. local  sel_x                = 0
  23. local  sel_y                = 0
  24. local  sel_on               = 0
  25. local  sel_down             = -1
  26. global got_mouse_right_drag = 0
  27.  
  28. global function mouse_left_down()
  29. {
  30.    start_mouse_selection()
  31. }
  32.  
  33. global function lmouse_drag()
  34. {
  35.    do_mouse_drag()
  36. }
  37.  
  38. global function mouse_left_up()
  39. {
  40.    do_mouse_up()
  41. }
  42.  
  43. global function mouse_right_down()
  44. {
  45.    if (and(window_flags, WINDOW_ASCII_DUMP))
  46.       goto_buffer_offset( mouse_event_offset );
  47.    else
  48.       goto_pos(mouse_event_line, mouse_event_column);
  49.  
  50.    if (and(window_flags, WINDOW_EITHER_DUMP))
  51.    {
  52.       dump_digit = mouse_event_digit;
  53.       if (mouse_event_side)
  54.          window_flags = or(window_flags, WINDOW_NUM_SIDE)
  55.       else
  56.          window_flags = and(window_flags, not(WINDOW_NUM_SIDE))
  57.    }
  58.  
  59.    got_mouse_right_drag = FALSE
  60.    update_current_view()
  61.  
  62.    if ( mouse_event_x >= 0 && mouse_event_x < window_text_width && \
  63.         mouse_event_y >= 0 && mouse_event_y < window_text_height )
  64.    {
  65.       sel_x  = mouse_event_x
  66.       sel_y  = mouse_event_y
  67.       sel_on = FALSE
  68.    }
  69. }
  70.  
  71. global function mouse_right_drag()
  72. {
  73.    if (got_mouse_right_drag || and(keyboard_flags, 0x03)) # Check for Shift
  74.       got_mouse_right_drag = TRUE
  75.    else if ( mouse_event_x != sel_x || mouse_event_y != sel_y )
  76.       got_mouse_right_drag = TRUE
  77.  
  78.    if ( got_mouse_right_drag )
  79.    {
  80.       if ( sel_on )
  81.          do_mouse_drag()
  82.       else
  83.          start_mouse_selection(COLUMN_SELECTION)
  84.    }
  85. }
  86.  
  87. global function mouse_right_up()
  88. {
  89.    if (and(window_flags, WINDOW_ASCII_DUMP))
  90.       goto_buffer_offset( mouse_event_offset );
  91.    else
  92.       goto_pos( mouse_event_line, mouse_event_column);
  93.  
  94.    if (and(window_flags, WINDOW_EITHER_DUMP))
  95.    {
  96.       dump_digit = mouse_event_digit;
  97.       if (mouse_event_side)
  98.          window_flags = or(window_flags, WINDOW_NUM_SIDE)
  99.       else
  100.          window_flags = and(window_flags, not(WINDOW_NUM_SIDE))
  101.    }
  102.  
  103.    if ( got_mouse_right_drag )
  104.       do_mouse_up()
  105.    else
  106.       optional_function( "gui_show_popup" )
  107. }
  108.  
  109. global function start_mouse_selection(sel_type)
  110. {
  111.    local type
  112.    local endcol
  113.    local endline
  114.    local linesel
  115.    local startcol
  116.    local startline
  117.    local mark1, mark2
  118.    local diff1, diff2
  119.    local ascii_dump   = and(window_flags, WINDOW_ASCII_DUMP)
  120.    local ibm_dump     = !ascii_dump && and(window_flags, WINDOW_IBM_DUMP)
  121.    local keyflags     = keyboard_flags
  122.  
  123.    sel_down    = current_window
  124.    current_key = 0      # mouse needs to act as a keypress in some instances
  125.  
  126.    # Only start selection from inside the buffer unless shift is pressed.
  127.    if ((mouse_event_x >= 0 || and(keyflags, 0x03)))
  128.    {
  129.       if ( cua_selection )
  130.          cua_extend(1)
  131.       else
  132.       {
  133.          delete_event( EVENT.KEYPRESS_AFTER, function_id("UnhighlightMouseSel") )
  134.          attach_event_handler( EVENT.KEYPRESS_AFTER, function_id("UnhighlightMouseSel") )
  135.       }
  136.  
  137.       # remove any temporary selection that may exist before we start our selection, 
  138.       # otherwise the temporary selection will remove our new selection.
  139.       unhilight_temp_selection()
  140.  
  141.       if ( and(keyflags, 0x03) ) # Check for Shift-Button
  142.       {
  143.          if (ascii_dump || (linecommands_enabled && linenumber_width))
  144.             linesel = FALSE
  145.          else
  146.          {
  147.             linesel = mouse_event_x < 0
  148.             if (linesel)
  149.                 mouse_event_x = 0
  150.          }
  151.  
  152.          if (selection_type())
  153.          {
  154.             # extend existing selection.
  155.             if (ascii_dump)
  156.                goto_buffer_offset( mouse_event_offset );
  157.             else
  158.                goto_pos(mouse_event_line, mouse_event_column);
  159.  
  160.             mark1 = selection_mark_top()
  161.             mark2 = selection_mark_bottom()
  162.  
  163.             diff1 = abs(distance_between_marks( mark1, 0 ))
  164.             diff2 = abs(distance_between_marks( mark2, 0 ))
  165.    
  166.             if (diff1 > diff2)
  167.             {
  168.                sel_x = mark_column(mark1) - window_margin - 1
  169.                sel_y = mark_line(mark1)   - window_first
  170.             }
  171.             else
  172.             {
  173.                sel_x = mark_column(mark2) - window_margin - 1
  174.                sel_y = mark_line(mark2)   - window_first
  175.             }
  176.          }
  177.          else
  178.          {
  179.             # extend selection from current cursor position.
  180.             if (ascii_dump)
  181.             {
  182.                sel_x   = mouse_event_y
  183.                sel_y   = mouse_event_x
  184.             }
  185.             else
  186.             {
  187.                sel_x = current_column - window_margin - 1
  188.                sel_y = current_line   - window_first
  189.             }
  190.          }
  191.       }
  192.       else if (!argcount())
  193.       {
  194.          # create new selection.
  195.          sel_y   = mouse_event_y
  196.          sel_x   = mouse_event_x
  197.          linesel = FALSE
  198.       }
  199.  
  200.       remove_selection()
  201.       update_current_view()
  202.  
  203.       if (sel_x != mouse_event_x || sel_y != mouse_event_y) 
  204.       {
  205.          startline = sel_y + window_first
  206.          startcol  = sel_x + window_margin + 1
  207.       }
  208.       else
  209.       {
  210.          startline = mouse_event_line
  211.          startcol  = mouse_event_column
  212.       }
  213.  
  214.       if (ascii_dump)
  215.          goto_buffer_offset( mouse_event_offset );
  216.       else
  217.          goto_pos(mouse_event_line, mouse_event_column);
  218.  
  219.       update_current_view();
  220.  
  221.       if ( and(keyflags, 0x04) )                 # Check for Control Key
  222.          type = COLUMN_SELECTION
  223.       else if ( linesel || and(keyflags, 0x08) ) # Check for Alt Key
  224.          type = LINE_SELECTION
  225.       else if (argcount())                       # Check for argument
  226.          type = sel_type
  227.       else                                       # Must be normal
  228.          type = NORMAL_SELECTION
  229.  
  230.       if (sel_x != mouse_event_x || sel_y != mouse_event_y)
  231.          goto_pos( sel_y + window_first, sel_x + window_margin + 1 );
  232.  
  233.       begin_selection( type );
  234.  
  235.       if (sel_x != mouse_event_x || sel_y != mouse_event_y)
  236.       {
  237.          if (ascii_dump)
  238.             goto_buffer_offset( mouse_event_offset );
  239.          else
  240.             goto_pos(mouse_event_line, mouse_event_column);
  241.       }
  242.       sel_on = 1
  243.    }
  244.    else
  245.    {
  246.       remove_selection()
  247.       update_current_view()
  248.  
  249.       if (linecommands_enabled && linenumber_width && !ascii_dump)
  250.          sel_x = mouse_event_x
  251.       else
  252.          sel_x = window_margin
  253.    
  254.       sel_y  = mouse_event_y
  255.       sel_on = 0
  256.    
  257.       if (ascii_dump)
  258.          goto_buffer_offset( mouse_event_offset );
  259.       else
  260.          goto_pos(mouse_event_line, sel_x + 1 );
  261.    }
  262.  
  263.    if (ascii_dump || ibm_dump)
  264.    {
  265.       dump_digit = mouse_event_digit;
  266.       if (mouse_event_side)
  267.          window_flags = or(window_flags, WINDOW_NUM_SIDE)
  268.       else
  269.          window_flags = and(window_flags, not(WINDOW_NUM_SIDE))
  270.    }
  271.    update_current_view();
  272. }
  273.  
  274. local function do_mouse_drag()
  275. {
  276.    local row, col
  277.    local startcol
  278.    local is_inside
  279.    local startline
  280.    local was_inside
  281.    local ascii_dump = and(window_flags, WINDOW_ASCII_DUMP)
  282.    local ibm_dump   = !ascii_dump && and(window_flags, WINDOW_IBM_DUMP)
  283.  
  284.    if (sel_down == current_window)
  285.    {
  286.       if (sel_x != mouse_event_x || sel_y != mouse_event_y)
  287.       {
  288.          # The mouse cursor moved by at least one text cell.
  289.          #
  290.          if (!sel_on)
  291.          {
  292.             # There is no active selection, must have started in the
  293.             # line-command area.
  294.             #
  295.             if (mouse_event_y != sel_y || mouse_event_x > 0)
  296.             {
  297.                # The mouse cursor is either no longer in the line-command
  298.                # area or has moved at least one line up or down
  299.                #
  300.                sel_on = 1
  301.                sel_x  = window_margin + 1
  302.  
  303.                if (ascii_dump)
  304.                   goto_buffer_offset( mouse_event_offset );
  305.                else
  306.                   goto_pos( mouse_event_line, mouse_event_column);
  307.  
  308.                startline = sel_y + window_first
  309.                startcol  = sel_x + window_margin + 1
  310.  
  311.                if ( cua_selection )
  312.                   cua_extend(1)
  313.                else
  314.                {
  315.                   delete_event( EVENT.KEYPRESS_AFTER, function_id("UnhighlightMouseSel") )
  316.                   attach_event_handler( EVENT.KEYPRESS_AFTER, function_id("UnhighlightMouseSel") )
  317.                }
  318.  
  319.                save_position()
  320.                goto_pos( startline, startcol )
  321.                begin_selection( LINE_SELECTION )
  322.                restore_position( TRUE )
  323.             }
  324.             else if (mouse_event_x < 0 && (!linecommands_enabled || \
  325.                                            !linenumber_width || ascii_dump))
  326.             {
  327.                return
  328.             }
  329.             else
  330.             {
  331.                goto_pos( mouse_event_line, mouse_event_x + 1 );
  332.                update_current_view()
  333.                return
  334.             }
  335.          }
  336.  
  337.          is_inside = (mouse_event_x >= 0) && (mouse_event_x < window_text_width) && \
  338.                      (mouse_event_y >= 0) && (mouse_event_y < window_text_height)
  339.          
  340.          if ( is_inside )
  341.          {
  342.             if (ascii_dump)
  343.                goto_buffer_offset( mouse_event_offset );
  344.             else
  345.                goto_pos( mouse_event_line, mouse_event_column);
  346.          }
  347.          else 
  348.          {
  349.             was_inside = (sel_x >= 0) && (sel_x < window_text_width) && \
  350.                          (sel_y >= 0) && (sel_y < window_text_height)
  351.    
  352.             if ( was_inside )
  353.             {
  354.                # Force the cursor to the edge of the screen
  355.                #
  356.                if ( mouse_event_x <= 0 )
  357.                   col = window_margin + 1
  358.                else if ( mouse_event_x >= window_width )
  359.                   col = window_margin + window_width - 1
  360.                else
  361.                   col = mouse_event_column
  362.  
  363.                if ( mouse_event_y <= 0 )
  364.                   row = window_first
  365.                else if ( mouse_event_y > window_text_height )
  366.                   row = window_first + window_text_height - 1
  367.                else
  368.                   row = mouse_event_line
  369.  
  370.                goto_pos( row, col )
  371.             }
  372.             #
  373.             # Scroll the Window & extend the selection.
  374.             #
  375.             if ( mouse_event_x < 0 )
  376.                scroll_horizontal( min(mouse_event_x, -1), 1 );
  377.             else if ( mouse_event_x > window_width )
  378.                scroll_horizontal( max(mouse_event_x - window_width, 1), 1 );
  379.      
  380.             if ( mouse_event_y < 0 )
  381.                scroll_vertical( min(mouse_event_y, -1), 1 );
  382.             else if ( mouse_event_y > window_text_height )
  383.                scroll_vertical( max(mouse_event_y - window_text_height, 1), 1 );
  384.          }
  385.       }
  386.    }
  387.    else if ( sel_down != -1 )    # Do not remove selection from hilight_word_mouse()
  388.       remove_selection()
  389.  
  390.    if (ascii_dump || ibm_dump)
  391.    {
  392.       dump_digit = mouse_event_digit;
  393.       if (mouse_event_side)
  394.          window_flags = or(window_flags, WINDOW_NUM_SIDE)
  395.       else
  396.          window_flags = and(window_flags, not(WINDOW_NUM_SIDE))
  397.    }
  398.    update_current_view();
  399. }
  400.  
  401. local function do_mouse_up()
  402. {
  403.    local ascii_dump = and(window_flags, WINDOW_ASCII_DUMP)
  404.    local ibm_dump   = !ascii_dump && and(window_flags, WINDOW_IBM_DUMP)
  405.  
  406.    if (sel_down == current_window)
  407.    {
  408.       if (mouse_event_x < 0 && (!linecommands_enabled || \
  409.                                 !linenumber_width || ascii_dump))
  410.       {
  411.           mouse_event_x = 0
  412.       }
  413.  
  414.       if (!sel_on)
  415.       {
  416.          if (mouse_event_x >= 0)
  417.          {
  418.             if (ascii_dump)
  419.                goto_buffer_offset( mouse_event_offset );
  420.             else
  421.                goto_pos( mouse_event_line, mouse_event_column);
  422.          }
  423.          else
  424.            goto_pos( mouse_event_line, mouse_event_x + 1 );
  425.       }
  426.       else if ( (sel_x == mouse_event_x) && (sel_y == mouse_event_y) )
  427.       {
  428.          if ( cua_selection )
  429.             cua_remove_selection()
  430.          else
  431.             delete_event( EVENT.KEYPRESS_AFTER, function_id("UnhighlightMouseSel") )
  432.  
  433.          remove_selection();
  434.       }
  435.       else
  436.          end_selection();
  437.    }
  438.    else if ( sel_down != -1 )    # Do not remove selection from hilight_word_mouse()
  439.       remove_selection()
  440.  
  441.    if (ascii_dump || ibm_dump)
  442.    {
  443.       dump_digit = mouse_event_digit;
  444.       if (mouse_event_side)
  445.          window_flags = or(window_flags, WINDOW_NUM_SIDE)
  446.       else
  447.          window_flags = and(window_flags, not(WINDOW_NUM_SIDE))
  448.    }
  449.  
  450.    update_current_view();
  451.  
  452.    sel_on   = 0
  453.    sel_down = -1
  454. }
  455.  
  456. global function UnhighlightMouseSel()
  457. {
  458.    delete_event( EVENT.KEYPRESS_AFTER, function_id("UnhighlightMouseSel") )
  459.    remove_selection()
  460.    update_current_view()
  461. }
  462.  
  463. global function hilight_word_mouse()
  464. {
  465.    # so the mouse up message doesn't remove the selection
  466.    sel_x    = 0
  467.    sel_y    = 0
  468.    sel_on   = 0
  469.    sel_down = -1
  470.  
  471.    if ( cua_selection )
  472.       cua_extend(1)
  473.    else
  474.       delete_event( EVENT.KEYPRESS_AFTER, function_id("UnhighlightMouseSel") )
  475.  
  476.    remove_selection()
  477.    update_current_view()
  478.    hilight_word()
  479.  
  480.    if ( !cua_selection )
  481.       attach_event_handler( EVENT.KEYPRESS_AFTER, function_id("UnhighlightMouseSel") )
  482. }
  483.