home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 5 Edit
/
05-Edit.zip
/
p2demo21.exe
/
PEL
/
WINDOWS.PEL
< prev
next >
Wrap
Text File
|
1995-03-16
|
34KB
|
1,211 lines
# $Header: P:\source\wmacros\windows.pev 1.55 16 Mar 1995 14:02:22 pfhmlw0 $
##############################################################################
#
# 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: windows.pel $: support for windows
#### symbolic window flag values
#
global WINDOW_COLLAPSED = 0x00000000 # window collapsed
global WINDOW_NORMAL = 0x00000001 # window normal
global WINDOW_EXPANDED = 0x00000002 # window expanded
global WINDOW_HIDDEN = 0x00000003 # window state: one of the above
global WINDOW_ZOOM = 0x00000003 # read-only window is zoomed
global WINDOW_SYSTEM = 0x00000004 # read-only window is a "system" window
global WINDOW_SHOW_SYSTEM = 0x00000008 # allow system buffers to be visible
global WINDOW_BORDERS = 0x00000030 # all border flags
global WINDOW_NOBORDER = 0x00000000 # no border, no title, no nothing
global WINDOW_NORM_BORDER = 0x00000010 # non-sizing border
global WINDOW_SIZE_BORDER = 0x00000020 # sizing border
global WINDOW_SCROLLBARS = 0x000000C0 # both scroll bars
global WINDOW_VERT_SB = 0x00000040 # border w/scroll bar right
global WINDOW_HORIZ_SB = 0x00000080 # border w/scroll bar below
global WINDOW_TITLEBAR = 0x00000F00 # all title bar flags
global WINDOW_NO_TITLE = 0x00000000 # no title bar
global WINDOW_TITLE = 0x00000100 # title bar visible
global WINDOW_SYS_MENU = 0x00000200 # system menu
global WINDOW_MIN_BOX = 0x00000400 # min box
global WINDOW_MAX_BOX = 0x00000800 # max box
global WINDOW_CARAT = 0x00001000 # display control chars as ^X
global WINDOW_CHARS = 0x00006000 # non-ascii character mapping bits
global WINDOW_IBM = 0x00000000 # non-ascii as IBM chars
global WINDOW_DUMP = 0x00000000 # non-ascii as HEX dump (no \ or X)
global WINDOW_OCTAL = 0x00002000 # non-ascii as OCTAL
global WINDOW_HEX = 0x00004000 # non-ascii as HEX
global WINDOW_DEC = 0x00006000 # non-ascii as DECIMAL
global WINDOW_EXPAND_ALL = 0x00020000 # expand all chars using the
# WINDOW_CHARS, not just ctrl chars.
global WINDOW_ASCII_DUMP = 0x00040000 # display as ASCII format dump
global WINDOW_IBM_DUMP = 0x00080000 # display as IBM format dump
global WINDOW_EITHER_DUMP = 0x000C0000 # display is in either dump format
global WINDOW_NUM_SIDE = 0x00100000 # cursor is on hex side of dump
global WINDOW_DISPLAY_FULL_FILENAME = 0x00010000
# some useful combinations:
global WINDOW_STANDARD_MDI = 0x00010FE1 # title and border w/scroll bar right
global WINDOW_STANDARD_SDI = 0x000100C2 # no title and border
global WINDOW_STANDARD = 0x000100C2 # no title and border
global WINDOW_PLAIN = 0x00010111 # title and plain border
global WINDOW_HEX_DUMP_MDI = 0x00050FE1 # ascii hex dump format for MDI Mode
global WINDOW_HEX_DUMP_SDI = 0x000500C2 # ascii hex dump format for SDI Mode
global WINDOW_HEX_DUMP = 0x00050000 # ascii hex dump format (Only)
# user definable window flags
global DOS_WINDOW_FLAG = 0x00200000;
# System primitives allow windows as small as 1x1.
# This package enforces a larger minimum window size:
global WINDOW_MIN_WIDTH = 12
global WINDOW_MIN_HEIGHT = 2
#--------------------------------------------------------------
# Windows
#--------------------------------------------------------------
### window creation/deletion
## gui-style window creation
#
#function gui_create_window()
#{
# if ( window_width > window_height )
# split_window_horizontal()
# else
# split_window_vertical()
#}
### create a window, using mouse if enabled, otherwise keyboard
#
function make_window() #PUBLIC #VOID
{
current_window = create_window()
attach_window_buffer( current_window, current_buffer )
}
## create a 1/4 sized window in the middle of the screen:
#
local function create_medium_window()
{
local w1
w1 = create_window( display_width / 4, display_height / 4,
display_width / 2, display_height / 2 )
return w1
}
## bleep and return 1 if current_window is a system window
# current_window by default
function is_system_window() #PUBLIC #VOID
{
if( !current_window )
return 1
else if( and( window_flags, WINDOW_SYSTEM ))
{
beep()
return 1
}
else
return 0
}
### create a window, with all per-window attributes set to "standard" values
#
# an optional fifth argument sets the window flags
#
# this code can generate 2 window-changed events because
# the new window has to temporarily become current so the attributes
# can be changed.
#
function create_factory_window( x, y, xl, yl, flags, parent ) #PUBLIC #VOID
{
local win, fg, bg
local old = current_window
local oldlineformat = default_linenumber_format;
if( argcount() < 5 )
flags = default_window_flags
default_linenumber_format = ""
if ( argcount() < 6 )
win = create_window( x, y, xl, yl, flags )
else
win = create_window( x, y, xl, yl, flags, parent )
default_linenumber_format = oldlineformat;
if( win )
{
current_window = win
# reset visible attributes, depending on display in use
visible_newlines = \
visible_virtual_lines = \
visible_end_buffer = \
visible_spaces = \
visible_tabs = \
visible_virtual_spaces = ""
scroll_context_top = \
scroll_context_left = \
scroll_context_right = \
scroll_context_bottom = \
window_page_offset = \
window_page_overlap = 0
scroll_unit_horizontal = \
scroll_unit_vertical = \
scroll_means_pan = 1
if ( window_valid( old ))
current_window = old
}
return win
}
## delete a window and it's attached buffer, if any
# this routine navigates around a common programming hazard when
# deleting temporary windows with attached buffers
# (the order of the deletes is very important)
#
function delete_window_and_buffer( win )
{
local oldwin = current_window
if( argcount())
assign_current_window( win )
else
win = current_window
delete_buffer( current_buffer )
delete_window( current_window )
if( oldwin != win )
assign_current_window( oldwin )
}
## delete_window function to be bound to function keys
# it protects the user from accidently having a system window
# becoming current or being deleted.
#
# delete_tiled_window offers similar protection
#
function delete_window_key() #PUBLIC #VOID
{
if ( is_system_window() )
return
else
{
delete_window()
if ( and( window_flags, WINDOW_SYSTEM ))
next_window()
}
}
#function create_tiled_window( pct, vert ) #PUBLIC #VOID
#{
# if( vert )
# split_window_vertical( window_width * pct / 100 )
# else
# split_window_horizontal( window_height * pct / 100 )
#}
function split_window_horizontal( height ) #PUBLIC #VOID
{
local newBuffer;
local x0 = window_x0
local y0 = window_y0
local xex = window_width
local yex0 = ( argcount() && height > 0 ? height : window_height / 2 )
local yex1 = window_height - yex0
local y1 = y0 + yex0 # - 1
local w1
if( is_system_window())
return FALSE
else if ( !mdi_mode )
{
warning("Command only valid in MDI mode")
return FALSE
}
if( yex0 < WINDOW_MIN_HEIGHT || yex1 < WINDOW_MIN_HEIGHT )
{
warning( "window would be too small" )
return FALSE;
}
# shrink current window and create a new one using same window flags as
# the existing window
frame_window( x0, y0, xex, yex0 )
w1 = create_window( x0, y1, xex, yex1, window_flags )
if(mdi_mode == 2)
attach_menu_to_win(w1);
if ( w1 )
{
# make w1 have the same settings a current_window and set
# current window to w1
dup_window_state(w1)
if(create_new_bufwin)
{
newBuffer = gui_new(1);
attach_window_buffer(current_window, create_buffer(newBuffer, newBuffer,
or(default_buffer_flags, BUFFER_SCRATCH)) )
}
else
attach_window_buffer( current_window, current_buffer )
return TRUE;
}
else
{
warning( "unable to create window" )
return FALSE;
}
}
function split_window_vertical( width ) #PUBLIC #VOID
{
local newBuffer;
local x0 = window_x0
local y0 = window_y0
local yex = window_height
local xex0 = ( argcount() && width > 0 ? width : window_width / 2 )
local xex1 = window_width - xex0
local x1 = x0 + xex0 # - 1
local w1
if( is_system_window())
return FALSE
else if ( !mdi_mode )
{
warning("Command only valid in MDI mode")
return FALSE
}
if( xex0 < WINDOW_MIN_WIDTH || xex1 < WINDOW_MIN_WIDTH )
{
warning( "window would be too small" )
return FALSE;
}
# shrink current window and create a new one using same window flags as
# the existing window
frame_window( x0, y0, xex0, yex )
w1 = create_window( x1, y0, xex1, yex, window_flags )
if(mdi_mode == 2)
attach_menu_to_win(w1);
if ( w1 )
{
# make w1 have the same settings a current_window and set
# current window to w1
dup_window_state(w1)
if(create_new_bufwin)
{
newBuffer = gui_new(1);
attach_window_buffer(current_window, create_buffer(newBuffer, newBuffer,
or(default_buffer_flags, BUFFER_SCRATCH)) )
}
else
attach_window_buffer( current_window, current_buffer )
return TRUE;
}
else
{
warning( "unable to create window" )
return FALSE;
}
}
#global function dup_window( curr_window, flags )
#{
# local new_window
# local curr_buf = current_buffer
# local height = window_height
# local width = window_width
# local x0 = window_x0
# local y0 = window_y0
#
# # if flags are specified use them, otherwise use existing
# # window flags
# if ( flags )
# new_window = create_window( x0, y0, width, height, flags)
# else
# new_window = create_window( x0, y0, width, height, window_flags)
#
# attach_window_buffer( new_window, curr_buf )
# dup_window_state(new_window)
# return new_window
#}
global function dup_window_state(w1)
{
local old
# save all current window settings
old.linenumber_format = linenumber_format
old.color_window_fg = color_window_fg
old.color_window_bg = color_window_bg
old.color_linenumbers_bg = color_linenumbers_bg
old.color_linenumbers_fg = color_linenumbers_fg
old.color_linecommands_bg = color_linecommands_bg
old.color_linecommands_fg = color_linecommands_fg
old.scroll_context_top = scroll_context_top
old.scroll_context_bottom = scroll_context_bottom
old.scroll_context_right = scroll_context_right
old.scroll_context_left = scroll_context_left
old.scroll_unit_horizontal = scroll_unit_horizontal
old.scroll_unit_vertical = scroll_unit_vertical
old.scroll_means_pan = scroll_means_pan
current_window = w1
# set all window settings the same as old window
linenumber_format = old.linenumber_format
color_window_fg = old.color_window_fg
color_window_bg = old.color_window_bg
color_linenumbers_bg = old.color_linenumbers_bg
color_linenumbers_fg = old.color_linenumbers_fg
color_linecommands_bg = old.color_linecommands_bg
color_linecommands_fg = old.color_linecommands_fg
scroll_context_top = old.scroll_context_top
scroll_context_bottom = old.scroll_context_bottom
scroll_context_right = old.scroll_context_right
scroll_context_left = old.scroll_context_left
scroll_unit_horizontal = old.scroll_unit_horizontal
scroll_unit_vertical = old.scroll_unit_vertical
scroll_means_pan = old.scroll_means_pan
}
# toggle line commands in the current window
#
function toggle_linecommands( enable )
{
if( argcount() < 1 )
enable = !linenumber_format
linecommands_enabled = 0+enable
if( linecommands_enabled && current_window )
toggle_linenumbers( 1 )
}
# toggle line numbers in the current window
#
global nominal_linenumber_format = "%06d%v"
function toggle_linenumbers( enable )
{
local action
enable += 0;
if( (enable != 2) && is_system_window() )
return FALSE
if( argcount() < 1 )
enable = !linenumber_format
if ( linenumber_format )
nominal_linenumber_format = linenumber_format
if( enable > 0 )
linenumber_format = nominal_linenumber_format
else
linenumber_format = ""
message( "Line numbers %s.", enable ? "on" : "off" )
}
## toggle presence/absence of borders
#
# Toggle_borders accepts an optional argument:
# true => set borders to their nominal value
# false => remove borders and titles.
# If the argument is omitted, the borders are "toggled".
#
# Since there are several border styles we cannot simply toggle bits.
# Instead, we save the border setting when it is turned off, and
# restore the previously saved setting when toggeling it on.
#
# When there are multiple border styles, and current_window is changed
# between calls to toggle_border, the effect may be to transfer border
# styles from window to window.
#
# If borders are to be turned-off by default, then nominal_border_flags
# should be set in addition to default_window_flags.
global nominal_border_flags = WINDOW_STANDARD
function toggle_borders( enable ) #PUBLIC #VOID
{
local border_flags = WINDOW_SIZE_BORDER + WINDOW_TITLEBAR
local noborders = and( window_flags, not( border_flags ))
local borders = and( window_flags, border_flags )
if( is_system_window())
return FALSE
if( argcount() < 1 )
enable = !borders # toggle if no arg
if( 0+enable ) # restore nominal borders
{
window_flags = nominal_border_flags
}
else # remove nominal borders
{
nominal_border_flags = window_flags
window_flags = noborders
}
}
### toggle border
function set_win_border( bordertype ) #PUBLIC #VOID
{
if( is_system_window())
return FALSE
if ( argcount() < 1 )
return FALSE
# clear any old window flags
window_flags = and( window_flags, not(WINDOW_BORDERS) )
# set new window flags
window_flags = or( window_flags, bordertype )
message( "Window borders set to %d.", bordertype )
}
function toggle_min_box( on )
{
if( is_system_window())
return FALSE
if ( argcount() < 1 )
on = ! and( window_flags, WINDOW_MIN_BOX )
else
on = 0+on
#
# toggle the setting
#
if ( on )
window_flags = or( window_flags, WINDOW_MIN_BOX )
else
window_flags = and( window_flags, not( WINDOW_MIN_BOX ))
message( "Minimize box is %s.", on ? "on" : "off" )
return on
}
function toggle_max_box( on )
{
if( is_system_window())
return FALSE
if ( argcount() < 1 )
on = ! and( window_flags, WINDOW_MAX_BOX )
else
on = 0+on
#
# toggle the setting
#
if ( on )
window_flags = or( window_flags, WINDOW_MAX_BOX )
else
window_flags = and( window_flags, not( WINDOW_MAX_BOX ))
message( "Maximize box is %s.", on ? "on" : "off" )
return on
}
function toggle_sys_menu( on )
{
if( is_system_window())
return FALSE
if ( argcount() < 1 )
on = ! and( window_flags, WINDOW_SYS_MENU )
else
on = 0+on
#
# toggle the setting
#
if ( on )
window_flags = or( window_flags, WINDOW_SYS_MENU )
else
window_flags = and( window_flags, not( WINDOW_SYS_MENU ))
message( "System menu is %s.", on ? "on" : "off" )
return on
}
### toggle vertical scroll bars cursor
function toggle_win_pathinfo( on )
{
if( is_system_window())
return FALSE
if ( argcount() < 1 )
on = ! and( window_flags, WINDOW_DISPLAY_FULL_FILENAME )
else
on = 0+on
#
# toggle the setting
#
if ( on )
window_flags = or( window_flags, WINDOW_DISPLAY_FULL_FILENAME )
else
window_flags = and( window_flags, not( WINDOW_DISPLAY_FULL_FILENAME ))
update_current_caption()
message( "Fully qualified path name on title bar is %s.", on ? "on" : "off" )
return on
}
function toggle_win_vscroll( on ) #PUBLIC #VOID
{
if( is_system_window())
return FALSE
if ( argcount() < 1 )
on = ! and( window_flags, WINDOW_VERT_SB )
else
on = 0+on
#
# toggle the setting
#
if ( on )
window_flags = or( window_flags, WINDOW_VERT_SB )
else
window_flags = and( window_flags, not( WINDOW_VERT_SB ))
message( "Vertical scroll bars %s.", on ? "on" : "off" )
return on
}
### toggle horizontal scroll bars
function toggle_win_hscroll( on ) #PUBLIC #VOID
{
if( is_system_window())
return FALSE
if ( argcount() < 1 )
on = ! and( window_flags, WINDOW_HORIZ_SB )
else
on = 0+on
#
# toggle the setting
#
if ( on )
window_flags = or( window_flags, WINDOW_HORIZ_SB )
else
window_flags = and( window_flags, not( WINDOW_HORIZ_SB ))
message( "Horizontal scroll bars %s.", on ? "on" : "off" )
return on
}
function toggle_scrollbars( enable )
{
local action
enable += 0;
if( (enable != 2) && is_system_window() )
return FALSE
if( argcount() < 1 )
enable = !and( window_flags, WINDOW_SCROLLBARS )
if ( enable )
window_flags = or( window_flags, WINDOW_SCROLLBARS )
else
window_flags = and( window_flags, not(WINDOW_SCROLLBARS) )
message( "Scroll bars %s.", enable ? "on" : "off" )
}
### toggle window titles
function toggle_win_title( on ) #PUBLIC #VOID
{
if( is_system_window())
return FALSE
if ( argcount() < 1 )
on = ! and( window_flags, WINDOW_TITLE )
else
on = 0+on
#
# toggle the setting
#
if ( on )
window_flags = or( window_flags, WINDOW_TITLE )
else
window_flags = and( window_flags, not( WINDOW_TITLE ))
message( "Window title %s.", on ? "on" : "off" )
return on
}
### window resizing, positioning & scrolling
function larger_window()
{
local wz = and( window_flags, WINDOW_ZOOM )
if( is_system_window())
return FALSE
if( wz == WINDOW_COLLAPSED )
restore_window()
else if( wz == WINDOW_NORMAL )
expand_window()
}
function smaller_window()
{
local wz = and( window_flags, WINDOW_ZOOM )
if( is_system_window())
return FALSE
if( wz == WINDOW_EXPANDED )
restore_window()
else if( wz == WINDOW_NORMAL )
collapse_window()
}
function scroll_down_1()
{
scroll_vertical( 1, scroll_or_pan())
}
function scroll_up_1()
{
scroll_vertical( -1, scroll_or_pan())
}
function scroll_down_half()
{
local h = window_text_height / 2
scroll_vertical(( h <= 0 ? 1 : h ), scroll_or_pan())
}
function scroll_up_half()
{
local h = window_text_height / 2
scroll_vertical( -( h <= 0 ? 1 : h ), scroll_or_pan())
}
function scroll_left_1()
{
scroll_horizontal( -1, scroll_or_pan())
}
function scroll_right_1()
{
scroll_horizontal( 1, scroll_or_pan())
}
# these functions reposition the window so that the current line is
# in the indicated position (if possible):
global function scroll_window_top( n ) #PUBLIC #VOID
{
if( n >= window_text_height )
n = window_text_height - font_height
scroll_vertical( distance_to_window_top() - n, scroll_or_pan())
}
global function scroll_window_bottom( n ) #PUBLIC #VOID
{
if( n >= window_text_height )
n = window_text_height - 1
scroll_vertical( - distance_to_window_bottom() + n, scroll_or_pan())
}
global function scroll_window_middle( n ) #PUBLIC #VOID
{
# arguably should guard against too large values of abs(n)
scroll_vertical( -distance_to_window_middle() - n, scroll_or_pan())
}
## center_cursor
# similar to scroll_window_middle but never changes the position in
# the buffer (i.e. current_line or current_column). This function is
# useful for restoring a convenient window orientation when the cursor
# has drifted too far to the top or bottom.
#
global function center_cursor() #PUBLIC #VOID
{
local save_context_top = scroll_context_top
scroll_context_top = 0
scroll_vertical( current_line - window_first - shiftr( window_text_height, 1 ), 0 )
scroll_context_top = save_context_top
}
## scroll_or_pan -- determine to scroll or pan by
# interrogating the scroll_means_pan status and
# complementing it if the SCROLL_LOCK key is pressed
#
global function scroll_or_pan()
{
local smp = !scroll_means_pan # !! smp default should be reversed
return xor_scroll_lock( smp )
}
## interrogate status of scroll-lock key
function scroll_lock_status()
{
return !!and( keyboard_flags, KB_SCROLL_LOCK )
##!!?? above isn't working consistently
# return 0
}
## xor the argument with scroll_lock_status()
function xor_scroll_lock( var )
{
return xor( var, scroll_lock_status())
}
### distances from the cursor to current_window's borders
# these are relative to a position within the window to the given edge.
# if the cursor happens to be outside window-borders the values may
# be negative.
function distance_to_window_top() #PUBLIC #INT
{
return current_line - window_first
}
function distance_to_window_bottom() #PUBLIC #INT
{
return window_first + window_text_height - current_line - 1
}
function distance_to_window_left() #PUBLIC #INT
{
return current_column - window_margin - 1
}
function distance_to_window_right() #PUBLIC #INT
{
return window_margin + window_text_width - linenumber_width - current_column
}
# This function lacks symmetry with the four above. We eventually may need
# to distinguish between horizontal, vertical and combined centering. For
# now we only need vertical motion, and this computes the quantity, m,
# such that current_line += m
# and scroll_vertical( m )
# both put the current line into the middle of the screen.
#
function distance_to_window_middle()
{
# message( "wf: %d, wth: %d, line=%d", \
# window_first, \
# window_text_height, \
# current_line )
return window_first + window_text_height / 2 - current_line
}
### window/buffer organization
#
# collapse all windows to an orderly array of icons
#
global function organize_windows() #PUBLIC #VOID
{
local w
local window_list
local name
local tie
local n
if ( !(w = current_window))
return
do {
if( !and( window_flags, WINDOW_SYSTEM ))
{
name = window_name
tie = 1
while ( name in window_list )
{
# break ties in sorting order
name = window_name "~" tie++
}
collapse_window()
window_list[ name ] = current_window
n++
}
next_window( "", 1 )
} while( w != current_window ) # restores current_window
relocate_icons( window_list, n )
}
# create an icon for each non-system buffer and then organize the
# resulting windows in filename order. The windows and icons are
# initially created all on top of each other.
#
global function organize_buffers() #PUBLIC #VOID
{
local w
local b
local window_list
local n
local dw
if ( !(w = current_window))
return
# get buffers already attached to windows
do {
if ( !and( window_flags, WINDOW_SYSTEM ))
{
if ( buffer_filename in window_list )
{
# remove redundant window
dw = current_window
next_window( "", 1 )
delete_window( dw )
continue
}
else
{
# iconize this window and add to the list
collapse_window()
window_list[ buffer_filename ] = current_window
n++
}
}
next_window( "", 1 )
} while( w != current_window )
# create icons for all remaining non-system buffers
b = current_buffer
do {
if ( !and( buffer_flags, BUFFER_SYSTEM ) \
&& !( buffer_filename in window_list ))
{
current_window = create_medium_window()
attach_window_buffer( current_window, current_buffer )
collapse_window()
window_list[ buffer_filename ] = current_window
n++
current_window = w
}
next_buffer( "", 1 )
} while( b != current_buffer )
relocate_icons( window_list, n )
}
# position icons in the order defined by array window_list
#
local function relocate_icons( window_list, n )
{
local prevWindow = current_window
local start_x = 1
local start_y = 1
local dx = 16
local dy = 2
local x, y
local i
if ( !window_list || n < 1 || typeof( window_list ) != "array" )
return
# if the number of windows is large, fill the screen more efficiently
if ( n > display_height/dy * display_width/dx )
{
start_x = 1
start_y = 0
dy = 1
}
# position icons in a grid
x = start_x
y = start_y
for ( i in window_list )
{
current_window = window_list[ i ]
move_window( x, y )
y += dy
if ( y >= display_height - 1 )
{
x += dx
if ( x >= display_width - 14 )
{
start_x += 4
x = start_x
}
y = start_y
}
}
assign_current_window( prevWindow )
}
### fine-grain window positioning & resizing -- mouse alternates
#
# These functions support moving and resizing windows via the keypad.
#
##
local adjust_move_resize_flag # true if moving, false if resizing
local adjustWindowVars[]
## resize or move a window (opposite if scroll lock is on)
#
# xor( pos, scroll_lock_status()) => moving
# xor( !pos, scroll_lock_status()) => resizing (default if called from keymap)
global function adjust_window( pos ) #PUBLIC #VOID
{
local windowZoom = and( window_flags, WINDOW_ZOOM )
if ( is_system_window() )
return FALSE
# we don't move or resize an icon or expanded window
restore_window()
# save current window position and size
adjustWindowVars[ "zoom" ] = windowZoom
adjustWindowVars[ "x" ] = window_x0
adjustWindowVars[ "y" ] = window_y0
adjustWindowVars[ "w" ] = window_width
adjustWindowVars[ "h" ] = window_height
# save a flag indicating whether we should move or resize the window
adjust_move_resize_flag = !!pos
# define a keymap to use while resizing
push_keymap( create_keymap( empty_keymap ))
assign_key( "<Up>", "adjust_window_key 0 -1" )
assign_key( "<Down>", "adjust_window_key 0 1" )
assign_key( "<Right>", "adjust_window_key 1 0" )
assign_key( "<Left>", "adjust_window_key -1 0" )
assign_key( "<Enter>", "adjust_window_exit 1" )
assign_key( "<Esc>", "adjust_window_exit 0" )
# create a temporary status bar at the bottom of the screen
optional_function( "enable_status_bar_messages" )
notify( "Use arrow keys to adjust window, ENTER to accept, and ESC to cancel." )
}
function adjust_window_key( x, y )
{
if ( xor_scroll_lock( adjust_move_resize_flag )) # move
{
frame_window( window_x0 + x, window_y0 + y, \
window_width, window_height )
}
else # resize
{
frame_window( window_x0, window_y0, \
window_width + x, window_height + y )
}
}
function adjust_window_exit( accept )
{
local x, y
local w, h
local zoom
# restore the original keymap
pop_keymap()
# accept or cancel the new configuration
if ( 0+accept )
message( "" )
else
{
# restore window pos/size
x = adjustWindowVars[ "x" ]
y = adjustWindowVars[ "y" ]
w = adjustWindowVars[ "w" ]
h = adjustWindowVars[ "h" ]
frame_window( x, y, w, h )
# restore window zoom state
zoom = adjustWindowVars[ "zoom" ]
if ( zoom == WINDOW_COLLAPSED )
collapse_window()
else if ( zoom == WINDOW_EXPANDED )
expand_window()
message( "Window adjustment canceled." )
}
# deallocate the temp array
delete( adjustWindowVars )
# restore the status bar
optional_function( "restore_status_bar" )
}
## show_visibles()
#
# This function displays all tabs, spaces, newline chars, etc. which
# are accessible via visible_xxx variables.
global function show_visibles() #PUBLIC #VOID
{
visible_virtual_lines = "~"
visible_end_buffer = ""
visible_newlines = "■"
visible_spaces = "·"
visible_tabs = ""
visible_virtual_spaces = " "
}
## reset_visibles()
#
# This function resets all of the "visible" representations for
# otherwise non-printing attributes to their less visible defaults.
function reset_visibles() #PUBLIC #VOID
{
visible_virtual_lines = ""
visible_end_buffer = ""
visible_newlines = ""
visible_spaces = " "
visible_tabs = " "
visible_virtual_spaces = " "
default_visible_virtual_lines = ""
default_visible_end_buffer = ""
default_visible_newlines = ""
default_visible_spaces = " "
default_visible_tabs = " "
default_visible_virtual_spaces = " "
}
## assign_current_window()
#
# assign a window id to the current window iff the window id is valid
#
function assign_current_window( winid )
{
if (window_valid( winid ))
current_window = winid;
}
## toggle_window_zoom()
#
# toggles the WINDOW_EXPANDED bit in the window_flags. This
# has the effect of alternately expanding and restoring the size
# of the current window.
#
global function toggle_window_zoom( expand )
{
expand = ( argcount() < 1 ) ? !and( window_flags, WINDOW_EXPANDED ) \
: 0+expand
if ( expand )
expand_window()
else
restore_window()
}
global function next_window_key() #PUBLIC #VOID
{
local cw = current_window
while( (next_window() != cw) &&
and( window_flags,WINDOW_ZOOM) == WINDOW_HIDDEN )
{
continue;
}
}
global function prev_window_key() #PUBLIC #VOID
{
local cw = current_window
while( (prev_window() != cw) &&
and( window_flags,WINDOW_ZOOM) == WINDOW_HIDDEN )
{
continue;
}
}