home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 5 Edit
/
05-Edit.zip
/
p2demo21.exe
/
PEL
/
MOUSE.PEL
< prev
next >
Wrap
Text File
|
1995-04-11
|
14KB
|
483 lines
# $Header: P:\source\wmacros\mouse.pev 1.7 11 Apr 1995 12:41:02 NOBLE $
## $Tabs:4 7$
##############################################################################
#
# Compuware Corporation
# 31440 Northwestern Highway
# Farmington Hills, Michigan 48334-2564
#
# This source code listing contains information that is
# proprietary to Compuware Corporation and may not be copied
# duplicated, translated, transmitted, stored, retrieved
# or in any manner or by any method conveyed or disclosed
# to a third party or parties without express written
# permission from Compuware Corporation.
#
#
##############################################################################
#### $Workfile: mouse.pel $: Mouse support functions
local sel_x = 0
local sel_y = 0
local sel_on = 0
local sel_down = -1
global got_mouse_right_drag = 0
global function mouse_left_down()
{
start_mouse_selection()
}
global function lmouse_drag()
{
do_mouse_drag()
}
global function mouse_left_up()
{
do_mouse_up()
}
global function mouse_right_down()
{
if (and(window_flags, WINDOW_ASCII_DUMP))
goto_buffer_offset( mouse_event_offset );
else
goto_pos(mouse_event_line, mouse_event_column);
if (and(window_flags, WINDOW_EITHER_DUMP))
{
dump_digit = mouse_event_digit;
if (mouse_event_side)
window_flags = or(window_flags, WINDOW_NUM_SIDE)
else
window_flags = and(window_flags, not(WINDOW_NUM_SIDE))
}
got_mouse_right_drag = FALSE
update_current_view()
if ( mouse_event_x >= 0 && mouse_event_x < window_text_width && \
mouse_event_y >= 0 && mouse_event_y < window_text_height )
{
sel_x = mouse_event_x
sel_y = mouse_event_y
sel_on = FALSE
}
}
global function mouse_right_drag()
{
if (got_mouse_right_drag || and(keyboard_flags, 0x03)) # Check for Shift
got_mouse_right_drag = TRUE
else if ( mouse_event_x != sel_x || mouse_event_y != sel_y )
got_mouse_right_drag = TRUE
if ( got_mouse_right_drag )
{
if ( sel_on )
do_mouse_drag()
else
start_mouse_selection(COLUMN_SELECTION)
}
}
global function mouse_right_up()
{
if (and(window_flags, WINDOW_ASCII_DUMP))
goto_buffer_offset( mouse_event_offset );
else
goto_pos( mouse_event_line, mouse_event_column);
if (and(window_flags, WINDOW_EITHER_DUMP))
{
dump_digit = mouse_event_digit;
if (mouse_event_side)
window_flags = or(window_flags, WINDOW_NUM_SIDE)
else
window_flags = and(window_flags, not(WINDOW_NUM_SIDE))
}
if ( got_mouse_right_drag )
do_mouse_up()
else
optional_function( "gui_show_popup" )
}
global function start_mouse_selection(sel_type)
{
local type
local endcol
local endline
local linesel
local startcol
local startline
local mark1, mark2
local diff1, diff2
local ascii_dump = and(window_flags, WINDOW_ASCII_DUMP)
local ibm_dump = !ascii_dump && and(window_flags, WINDOW_IBM_DUMP)
local keyflags = keyboard_flags
sel_down = current_window
current_key = 0 # mouse needs to act as a keypress in some instances
# Only start selection from inside the buffer unless shift is pressed.
if ((mouse_event_x >= 0 || and(keyflags, 0x03)))
{
if ( cua_selection )
cua_extend(1)
else
{
delete_event( EVENT.KEYPRESS_AFTER, function_id("UnhighlightMouseSel") )
attach_event_handler( EVENT.KEYPRESS_AFTER, function_id("UnhighlightMouseSel") )
}
# remove any temporary selection that may exist before we start our selection,
# otherwise the temporary selection will remove our new selection.
unhilight_temp_selection()
if ( and(keyflags, 0x03) ) # Check for Shift-Button
{
if (ascii_dump || (linecommands_enabled && linenumber_width))
linesel = FALSE
else
{
linesel = mouse_event_x < 0
if (linesel)
mouse_event_x = 0
}
if (selection_type())
{
# extend existing selection.
if (ascii_dump)
goto_buffer_offset( mouse_event_offset );
else
goto_pos(mouse_event_line, mouse_event_column);
mark1 = selection_mark_top()
mark2 = selection_mark_bottom()
diff1 = abs(distance_between_marks( mark1, 0 ))
diff2 = abs(distance_between_marks( mark2, 0 ))
if (diff1 > diff2)
{
sel_x = mark_column(mark1) - window_margin - 1
sel_y = mark_line(mark1) - window_first
}
else
{
sel_x = mark_column(mark2) - window_margin - 1
sel_y = mark_line(mark2) - window_first
}
}
else
{
# extend selection from current cursor position.
if (ascii_dump)
{
sel_x = mouse_event_y
sel_y = mouse_event_x
}
else
{
sel_x = current_column - window_margin - 1
sel_y = current_line - window_first
}
}
}
else if (!argcount())
{
# create new selection.
sel_y = mouse_event_y
sel_x = mouse_event_x
linesel = FALSE
}
remove_selection()
update_current_view()
if (sel_x != mouse_event_x || sel_y != mouse_event_y)
{
startline = sel_y + window_first
startcol = sel_x + window_margin + 1
}
else
{
startline = mouse_event_line
startcol = mouse_event_column
}
if (ascii_dump)
goto_buffer_offset( mouse_event_offset );
else
goto_pos(mouse_event_line, mouse_event_column);
update_current_view();
if ( and(keyflags, 0x04) ) # Check for Control Key
type = COLUMN_SELECTION
else if ( linesel || and(keyflags, 0x08) ) # Check for Alt Key
type = LINE_SELECTION
else if (argcount()) # Check for argument
type = sel_type
else # Must be normal
type = NORMAL_SELECTION
if (sel_x != mouse_event_x || sel_y != mouse_event_y)
goto_pos( sel_y + window_first, sel_x + window_margin + 1 );
begin_selection( type );
if (sel_x != mouse_event_x || sel_y != mouse_event_y)
{
if (ascii_dump)
goto_buffer_offset( mouse_event_offset );
else
goto_pos(mouse_event_line, mouse_event_column);
}
sel_on = 1
}
else
{
remove_selection()
update_current_view()
if (linecommands_enabled && linenumber_width && !ascii_dump)
sel_x = mouse_event_x
else
sel_x = window_margin
sel_y = mouse_event_y
sel_on = 0
if (ascii_dump)
goto_buffer_offset( mouse_event_offset );
else
goto_pos(mouse_event_line, sel_x + 1 );
}
if (ascii_dump || ibm_dump)
{
dump_digit = mouse_event_digit;
if (mouse_event_side)
window_flags = or(window_flags, WINDOW_NUM_SIDE)
else
window_flags = and(window_flags, not(WINDOW_NUM_SIDE))
}
update_current_view();
}
local function do_mouse_drag()
{
local row, col
local startcol
local is_inside
local startline
local was_inside
local ascii_dump = and(window_flags, WINDOW_ASCII_DUMP)
local ibm_dump = !ascii_dump && and(window_flags, WINDOW_IBM_DUMP)
if (sel_down == current_window)
{
if (sel_x != mouse_event_x || sel_y != mouse_event_y)
{
# The mouse cursor moved by at least one text cell.
#
if (!sel_on)
{
# There is no active selection, must have started in the
# line-command area.
#
if (mouse_event_y != sel_y || mouse_event_x > 0)
{
# The mouse cursor is either no longer in the line-command
# area or has moved at least one line up or down
#
sel_on = 1
sel_x = window_margin + 1
if (ascii_dump)
goto_buffer_offset( mouse_event_offset );
else
goto_pos( mouse_event_line, mouse_event_column);
startline = sel_y + window_first
startcol = sel_x + window_margin + 1
if ( cua_selection )
cua_extend(1)
else
{
delete_event( EVENT.KEYPRESS_AFTER, function_id("UnhighlightMouseSel") )
attach_event_handler( EVENT.KEYPRESS_AFTER, function_id("UnhighlightMouseSel") )
}
save_position()
goto_pos( startline, startcol )
begin_selection( LINE_SELECTION )
restore_position( TRUE )
}
else if (mouse_event_x < 0 && (!linecommands_enabled || \
!linenumber_width || ascii_dump))
{
return
}
else
{
goto_pos( mouse_event_line, mouse_event_x + 1 );
update_current_view()
return
}
}
is_inside = (mouse_event_x >= 0) && (mouse_event_x < window_text_width) && \
(mouse_event_y >= 0) && (mouse_event_y < window_text_height)
if ( is_inside )
{
if (ascii_dump)
goto_buffer_offset( mouse_event_offset );
else
goto_pos( mouse_event_line, mouse_event_column);
}
else
{
was_inside = (sel_x >= 0) && (sel_x < window_text_width) && \
(sel_y >= 0) && (sel_y < window_text_height)
if ( was_inside )
{
# Force the cursor to the edge of the screen
#
if ( mouse_event_x <= 0 )
col = window_margin + 1
else if ( mouse_event_x >= window_width )
col = window_margin + window_width - 1
else
col = mouse_event_column
if ( mouse_event_y <= 0 )
row = window_first
else if ( mouse_event_y > window_text_height )
row = window_first + window_text_height - 1
else
row = mouse_event_line
goto_pos( row, col )
}
#
# Scroll the Window & extend the selection.
#
if ( mouse_event_x < 0 )
scroll_horizontal( min(mouse_event_x, -1), 1 );
else if ( mouse_event_x > window_width )
scroll_horizontal( max(mouse_event_x - window_width, 1), 1 );
if ( mouse_event_y < 0 )
scroll_vertical( min(mouse_event_y, -1), 1 );
else if ( mouse_event_y > window_text_height )
scroll_vertical( max(mouse_event_y - window_text_height, 1), 1 );
}
}
}
else if ( sel_down != -1 ) # Do not remove selection from hilight_word_mouse()
remove_selection()
if (ascii_dump || ibm_dump)
{
dump_digit = mouse_event_digit;
if (mouse_event_side)
window_flags = or(window_flags, WINDOW_NUM_SIDE)
else
window_flags = and(window_flags, not(WINDOW_NUM_SIDE))
}
update_current_view();
}
local function do_mouse_up()
{
local ascii_dump = and(window_flags, WINDOW_ASCII_DUMP)
local ibm_dump = !ascii_dump && and(window_flags, WINDOW_IBM_DUMP)
if (sel_down == current_window)
{
if (mouse_event_x < 0 && (!linecommands_enabled || \
!linenumber_width || ascii_dump))
{
mouse_event_x = 0
}
if (!sel_on)
{
if (mouse_event_x >= 0)
{
if (ascii_dump)
goto_buffer_offset( mouse_event_offset );
else
goto_pos( mouse_event_line, mouse_event_column);
}
else
goto_pos( mouse_event_line, mouse_event_x + 1 );
}
else if ( (sel_x == mouse_event_x) && (sel_y == mouse_event_y) )
{
if ( cua_selection )
cua_remove_selection()
else
delete_event( EVENT.KEYPRESS_AFTER, function_id("UnhighlightMouseSel") )
remove_selection();
}
else
end_selection();
}
else if ( sel_down != -1 ) # Do not remove selection from hilight_word_mouse()
remove_selection()
if (ascii_dump || ibm_dump)
{
dump_digit = mouse_event_digit;
if (mouse_event_side)
window_flags = or(window_flags, WINDOW_NUM_SIDE)
else
window_flags = and(window_flags, not(WINDOW_NUM_SIDE))
}
update_current_view();
sel_on = 0
sel_down = -1
}
global function UnhighlightMouseSel()
{
delete_event( EVENT.KEYPRESS_AFTER, function_id("UnhighlightMouseSel") )
remove_selection()
update_current_view()
}
global function hilight_word_mouse()
{
# so the mouse up message doesn't remove the selection
sel_x = 0
sel_y = 0
sel_on = 0
sel_down = -1
if ( cua_selection )
cua_extend(1)
else
delete_event( EVENT.KEYPRESS_AFTER, function_id("UnhighlightMouseSel") )
remove_selection()
update_current_view()
hilight_word()
if ( !cua_selection )
attach_event_handler( EVENT.KEYPRESS_AFTER, function_id("UnhighlightMouseSel") )
}