home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 5 Edit
/
05-Edit.zip
/
p2demo21.exe
/
PEL
/
MDI.PEL
< prev
next >
Wrap
Text File
|
1995-03-23
|
22KB
|
803 lines
# $Header: P:\source\wmacros\mdi.pev 1.71 23 Mar 1995 10:51:10 PFHJXM0 $
## $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: mdi.pel $
local ICONIZE_WINDOWS = 1
local TILE_WINDOWS = 2
local CASCADE_WINDOWS = 3
# maximum number of windows open all commands
# will open
local MAX_WINDOWS = 100
global function mdi_menu()
{
menu_function_list[IDM_NEW_WINDOW] = "create_mdi_window"
menu_function_list[IDM_CASCADE_WINDOW] = "window_cascade"
menu_function_list[IDM_TILE_WINDOW] = "window_tile"
# menu_function_list[IDM_ARRANGE_ICONS] = "arrange_icons"
menu_function_list[IDM_CASCADE_BUFFERS] = "cascade_buffers"
menu_function_list[IDM_TILE_BUFFERS] = "tile_buffers"
menu_function_list[IDM_HSPLIT_WINDOW] = "split_window_horizontal"
menu_function_list[IDM_VSPLIT_WINDOW] = "split_window_vertical"
menu_function_list[IDM_BUFFER_MASK] = "set_buffer_mask_key"
menu_function_list[IDM_NEXT_WINDOW] = "next_window"
menu_function_list[IDM_PREV_WINDOW] = "prev_window"
menu_function_list[IDM_CLOSE_ALL_WINDOWS] = "delete_all_windows"
}
global function create_mdi_window(noBuffer)
{
local w1
local width = query_editwin_property( EWC_CLIENT_WIDTH )
local height = query_editwin_property( EWC_CLIENT_HEIGHT )
# w1 = create_window( 0, 0, editwin_client_width, editwin_client_height )
if(create_new_bufwin)
{
gui_new();
}
else
{
w1 = create_window( 0, 0, width, height )
attach_window_buffer( w1, current_buffer )
current_window = w1
}
}
global function create_detached_window(noBuffer)
{
local w1
local width = screen_width / 2
local height = screen_height / 2
local x = width / 2
local y = height / 2
local wf = and(window_flags, not(WINDOW_ZOOM))
if(create_new_bufwin)
{
gui_new();
}
else
{
if(current_window)
{
x = window_x0 + 25;
y = window_y0 - 25;
height = window_height;
width = window_width;
# If more than half the window is right of the right edge of the editor window, move it to the left;
if( x + width > screen_width)
x = 0;
# If more than half the window is below the bottom of the editor window, move it up to the top;
if(y < 0)
y = screen_height - height;
}
wf = or(wf, WINDOW_NORMAL)
w1 = create_window( x, y, width, height, wf )
attach_window_buffer( w1, current_buffer )
attach_menu_to_win( w1 )
current_window = w1
}
}
global function window_tile() #PUBLIC #VOID
{
arrange_windows( TILE_WINDOWS )
}
global function window_cascade() #PUBLIC #VOID
{
arrange_windows( CASCADE_WINDOWS )
}
global function arrange_icons()
{
arrange_windows( ICONIZE_WINDOWS )
}
global function toggle_window_mode( mode )
{
# switch to mode requested. 1 = mdi 0 = sdi
if ( argcount() > 0 ) {
# only switch if we are not already in mdi mode
if ( mode && !mdi_mode ) {
switch_to_mdi()
window_tile()
}
else if ( !mode && mdi_mode )
switch_to_sdi()
}
# if no argument toggle window mode
else {
if ( mdi_mode )
switch_to_sdi()
else {
switch_to_mdi()
}
}
}
global function delete_all_windows()
{
local curr_window
while ( (curr_window = next_window("", 0, 1)) != 0 )
delete_window( curr_window )
}
global function switch_to_sdi()
{
local wf
local old_window
local curr_window
if ( mdi_mode == 0 )
return;
else if ( mdi_mode == 2 )
{
toggle_floating_toolbar(0)
delete_container_list()
mdi_mode = 0
toggle_toolbar(1)
toggle_status_bar(1)
}
else
mdi_mode = 0
toggle_create_new_win( 0 )
wf = and(default_window_flags, WINDOW_SCROLLBARS+WINDOW_DISPLAY_FULL_FILENAME)
default_window_flags = and(WINDOW_STANDARD_SDI, not(WINDOW_SCROLLBARS+WINDOW_DISPLAY_FULL_FILENAME))
default_window_flags = or(wf, default_window_flags)
while ( current_window != (curr_window = next_window("", 0, 1)) )
delete_window( curr_window )
old_window = current_window
current_window = dup_window( old_window, default_window_flags )
delete_window( old_window )
modify_mdi_menu(mdi_mode)
}
global function switch_to_mdi()
{
local i
local wf
local window_list
local start_window
local save_status_bar_flags
if ( mdi_mode == 1 )
return;
else if ( mdi_mode == 2 )
{
save_status_bar_flags = status_bar_flags
toggle_floating_toolbar(0)
delete_container_list()
mdi_mode = 1
toggle_toolbar(1)
if(save_status_bar_flags)
status_bar_flags = save_status_bar_flags
else
toggle_status_bar(1)
}
else
mdi_mode = 1
modify_mdi_menu(mdi_mode)
wf = and(default_window_flags, WINDOW_SCROLLBARS+WINDOW_DISPLAY_FULL_FILENAME)
default_window_flags = and(WINDOW_STANDARD_MDI, not(WINDOW_SCROLLBARS+WINDOW_DISPLAY_FULL_FILENAME))
default_window_flags = or(wf, default_window_flags)
copy_windows()
}
global function switch_to_detached()
{
local wf
local width, height
local old_x, old_y, old_w, old_h
local save_status_bar_flags = status_bar_flags # Saved because when
# mdi_mode is set to 2, the status_bar_flags get set to 0, and when
# toggle_status_bar(1) was called, it used STB_DEFAULT instead of
# what the user set;
if ( mdi_mode == 2 )
return;
toggle_toolbar(0)
# all new windows created will be detached child windows
mdi_mode = 2
modify_mdi_menu(mdi_mode)
wf = and(default_window_flags, WINDOW_SCROLLBARS+WINDOW_DISPLAY_FULL_FILENAME)
default_window_flags = and(WINDOW_STANDARD_MDI, not(WINDOW_SCROLLBARS+WINDOW_DISPLAY_FULL_FILENAME))
default_window_flags = or(wf, default_window_flags)
if (save_status_bar_flags)
status_bar_flags = save_status_bar_flags;
else
toggle_status_bar(1)
copy_windows()
toggle_floating_toolbar(1)
create_container_list()
width = screen_width / 2 + 50
height = screen_height / 4
set_editwin_property( EWC_WIDTH, width )
set_editwin_property( EWC_HEIGHT, height )
set_editwin_property( EWC_X_POS, screen_width - width )
set_editwin_property( EWC_Y_POS, screen_height - height )
}
global function copy_windows()
{
local i
local window_list
local delete_list
local work_window
local temp_window
local start_window
local window_count
local save_status_bar_flags
local old_create_new_bufwin = create_new_bufwin
if (old_create_new_bufwin)
toggle_create_new_win(0)
if ( !current_window )
{
if ( old_create_new_bufwin )
toggle_create_new_win(1)
return;
}
for (start_window = window_count = i = 0;
current_window != start_window || !start_window; next_window("", 0, 1))
{
if (!start_window)
start_window = current_window
if (window_text_height > 1 && window_text_width > 10 &&
window_height / text_char_height > 1 &&
window_width / text_char_width > 10)
{
window_list[window_count++] = current_window
}
else
delete_list[i++] = current_window
}
if (window_count)
{
for (i in delete_list)
delete_window(delete_list[i])
if ( mdi_mode == 2 )
{
temp_window = 0
start_window = 0
save_status_bar_flags = status_bar_flags
for (i in window_list)
{
work_window = window_list[i]
current_window = dup_window(work_window, default_window_flags)
if (save_status_bar_flags)
status_bar_flags = save_status_bar_flags;
else
toggle_status_bar(1)
attach_menu_to_win(current_window)
modify_mdi_menu(mdi_mode)
if (window_text_height > 1 && window_text_width > 10 &&
window_height / text_char_height > 1 &&
window_width / text_char_width > 10)
{
if (!start_window)
start_window = current_window
delete_window(work_window)
}
else
{
if (temp_window)
delete_window(temp_window)
temp_window = work_window
window_count--
}
}
if (start_window)
current_window = start_window
else if (temp_window)
{
current_window = temp_window
expand_window()
current_window = dup_window( temp_window, default_window_flags )
if (save_status_bar_flags)
status_bar_flags = save_status_bar_flags;
else
toggle_status_bar(1)
attach_menu_to_win(current_window)
modify_mdi_menu(mdi_mode)
delete_window( temp_window )
}
}
else
{
for (i in window_list)
{
work_window = window_list[i]
if (i == 0)
current_window = dup_window(work_window, default_window_flags)
else
dup_window(work_window, default_window_flags)
delete_window(work_window)
}
}
}
else
{
while ( current_window != (work_window = next_window("", 0, 1)) )
delete_window( work_window )
if ( mdi_mode == 2 )
expand_window()
work_window = current_window
current_window = dup_window( work_window, default_window_flags )
delete_window( work_window )
if ( mdi_mode == 2 )
{
if (save_status_bar_flags)
status_bar_flags = save_status_bar_flags;
else
toggle_status_bar(1)
attach_menu_to_win(current_window)
modify_mdi_menu(mdi_mode)
}
}
if (old_create_new_bufwin)
toggle_create_new_win(1)
if (mdi_mode != 2 && !window_count)
window_tile()
}
global function modify_mdi_menu(mode, menu)
{
local enable = ( mode ) ? MI_ENABLED : MI_DISABLED;
if ( argcount() < 2 )
menu = menu_info(0, 0x2000)
if ( mdi_mode == 2 )
{
menu_function_list[IDM_NEW_WINDOW] = "create_detached_window"
menu_function_list[IDM_TOOLBAR] = "toggle_floating_toolbar"
}
else
{
menu_function_list[IDM_NEW_WINDOW] = "create_mdi_window"
menu_function_list[IDM_TOOLBAR] = "toggle_toolbar"
}
if ( menu )
{
# disable/enable sub menus
modify_menuitem( menu, IDM_NEW_WINDOW, enable )
modify_menuitem( menu, IDM_CASCADE_WINDOW, (mode == 2) ? MI_DISABLED : enable )
modify_menuitem( menu, IDM_TILE_WINDOW, (mode == 2) ? MI_DISABLED : enable )
# modify_menuitem( menu, IDM_ARRANGE_ICONS, (mode == 2) ? MI_DISABLED : enable )
modify_menuitem( menu, IDM_CASCADE_BUFFERS, (mode == 2) ? MI_DISABLED : enable )
modify_menuitem( menu, IDM_TILE_BUFFERS, (mode == 2) ? MI_DISABLED : enable )
modify_menuitem( menu, IDM_NEXT_WINDOW, enable )
modify_menuitem( menu, IDM_PREV_WINDOW, enable )
modify_menuitem( menu, IDM_CLOSE_ALL_WINDOWS, enable )
modify_menuitem( menu, IDM_HSPLIT_WINDOW, enable )
modify_menuitem( menu, IDM_VSPLIT_WINDOW, enable )
}
}
global function tile_buffers()
{
if ( mdi_mode )
{
assign_one_buffer_per_window()
arrange_windows( TILE_WINDOWS )
}
else
warning("window_per_buffer only valid for MDI")
}
global function cascade_buffers()
{
if ( mdi_mode )
{
assign_one_buffer_per_window()
arrange_windows( CASCADE_WINDOWS )
}
else
warning("window_per_buffer only valid for MDI")
}
local function assign_one_buffer_per_window()
{
local new_win
local curr_buffer
local start_buffer
local curr_window
local prev_window
local start_window
local num_windows = 0
local used_all_buffers = 0
local used_all_windows = 0
local old_create_new_bufwin = create_new_bufwin
# One buffer per window mode screws up the tile/cascade when it is on;
create_new_bufwin = 0
start_buffer = current_buffer
curr_buffer = start_buffer
start_window = current_window
# first loop through all the windows and put a different buffer in
# each window
curr_window = next_window("", 0, 1)
if ( !curr_window )
used_all_windows = 1
while ( !used_all_buffers && !used_all_windows )
{
attach_window_buffer(curr_window, curr_buffer)
restore_window(curr_window)
if ( curr_window == start_window )
used_all_windows = 1
if ( (curr_buffer = next_buffer("", 0, 1)) == start_buffer )
used_all_buffers = 1
prev_window = curr_window
curr_window = next_window("", 0, 1)
num_windows++
}
# if all buffers are used delete extra windows and return
if ( used_all_buffers && !used_all_windows )
{
while ( curr_window != start_window )
{
prev_window = curr_window
curr_window = next_window("", 0, 1)
delete_window(prev_window)
current_window = curr_window
}
delete_window(start_window)
}
else if ( !used_all_buffers )
{
# need to create more windows for the rest of the buffers
while ( !used_all_buffers && num_windows < MAX_WINDOWS )
{
prev_window = current_window;
current_window = dup_window( prev_window )
position_window(current_window, prev_window)
if(mdi_mode == 2) # Need to attach a menu if in detached mode;
attach_menu_to_win(current_window);
attach_window_buffer(current_window, curr_buffer)
# prev_window = new_win
curr_buffer = next_buffer("", 0, 1);
# if ( (curr_buffer = next_buffer("", 0, 1)) == start_buffer )
if (curr_buffer == start_buffer )
used_all_buffers = 1
num_windows++
}
}
# DWM 8/16/94
# Have to reset at least the current window when # of buffers
# and windows are equal--one too many next_window(,,1) was done.
# start_window is gauranteed to exist because # of wins and bufs
# are equal
else
current_window = start_window
create_new_bufwin = old_create_new_bufwin
}
local function position_window(new, old)
{
local prev_win = 0;
local x, y, width, height;
local edit_width, edit_height;
if(old)
{
prev_win = current_window;
current_window = old;
}
if(mdi_mode == 2)
{
edit_width = screen_width;
edit_height = screen_height;
}
else
{
edit_width = query_editwin_property(EWC_WIDTH);
edit_height = query_editwin_property(EWC_HEIGHT);
}
if(current_window)
{
x = window_x0 + 25;
y = window_y0 - 25;
width = window_width;
height = window_height;
}
else
{
x = 0;
y = 0;
width = edit_width / 2;
height = edit_height / 2;
}
if( x > (edit_width - width) )
x = 0;
if(y < 0)
y = edit_height - height;
frame_window(x, y, width, height, new);
if(prev_win)
current_window = prev_win;
}
function mdi_settings( settings_index, settings_data )
{
local new_array;
settings_data[ settings_index++ ] = sprintf( "SET_MDI %d, %d\n",
mdi_mode,
create_new_bufwin )
new_array.array = settings_data
new_array.index = settings_index
return new_array
}
global function remove_keep_windows()
{
delete_event( EVENT.RESIZE_EDITWIN, function_id("window_tile") );
delete_event( EVENT.RESIZE_EDITWIN, function_id("window_cascade") );
delete_event( EVENT.RESIZE_EDITWIN, function_id("tile_horizontal") );
delete_event( EVENT.RESIZE_EDITWIN, function_id("tile_vertical") );
delete_event( EVENT.RESIZE_EDITWIN, function_id("window_tile") );
}
global function keep_windows_tiled()
{
window_tile()
# delete other event handlers that may be installed
delete_event( EVENT.RESIZE_EDITWIN, function_id("window_tile") );
delete_event( EVENT.RESIZE_EDITWIN, function_id("window_cascade") );
delete_event( EVENT.RESIZE_EDITWIN, function_id("tile_horizontal") );
delete_event( EVENT.RESIZE_EDITWIN, function_id("tile_vertical") );
# attach new handler
attach_event_handler( EVENT.RESIZE_EDITWIN, function_id("window_tile") );
}
global function keep_windows_cascaded()
{
window_cascade()
# delete other event handlers that may be installed
delete_event( EVENT.RESIZE_EDITWIN, function_id("window_tile") );
delete_event( EVENT.RESIZE_EDITWIN, function_id("window_cascade") );
delete_event( EVENT.RESIZE_EDITWIN, function_id("tile_horizontal") );
delete_event( EVENT.RESIZE_EDITWIN, function_id("tile_vertical") );
# attach new handler
attach_event_handler( EVENT.RESIZE_EDITWIN, function_id("window_cascade") );
}
global function keep_windows_tiled_horizontal()
{
tile_horizontal()
# delete other event handlers that may be installed
delete_event( EVENT.RESIZE_EDITWIN, function_id("window_tile") );
delete_event( EVENT.RESIZE_EDITWIN, function_id("window_cascade") );
delete_event( EVENT.RESIZE_EDITWIN, function_id("tile_horizontal") );
delete_event( EVENT.RESIZE_EDITWIN, function_id("tile_vertical") );
# attach new handler
attach_event_handler( EVENT.RESIZE_EDITWIN, function_id("tile_horizontal") );
}
global function keep_windows_tiled_vertical()
{
tile_vertical()
# delete other event handlers that may be installed
delete_event( EVENT.RESIZE_EDITWIN, function_id("window_tile") );
delete_event( EVENT.RESIZE_EDITWIN, function_id("window_cascade") );
delete_event( EVENT.RESIZE_EDITWIN, function_id("tile_horizontal") );
delete_event( EVENT.RESIZE_EDITWIN, function_id("tile_vertical") );
# attach new handler
attach_event_handler( EVENT.RESIZE_EDITWIN, function_id("tile_vertical") );
}
global function tile_horizontal()
{
local total_size
local win_size
local cur_win
local win_width
local win_height
local scr_width
local start_window = current_window
local window_count = 1
local next_win_pos = 0
if ( !start_window )
return
# first count the windows
while ( next_window( "", 0, 1) != start_window )
window_count++
if ( mdi_mode == 2 )
{
win_width = screen_width / window_count
win_height = screen_height
scr_width = screen_width
}
else
{
win_width = display_width / window_count
win_height = display_height
scr_width = display_width
}
# size the first window and then get its size
frame_window( next_win_pos, 0, win_width, win_height, current_window )
win_size = window_width
total_size = window_width
next_win_pos = win_size
# now size the rest of the windows
while ( ( cur_win = next_window("", 0, 1) ) != start_window )
{
if ( total_size > scr_width )
{
total_size = 0
next_win_pos = 0
}
frame_window(next_win_pos, 0, win_width, win_height, cur_win)
total_size += win_size
next_win_pos += win_size
}
}
global function tile_vertical()
{
local total_size
local win_size
local cur_win
local win_height
local win_width
local scr_height
local start_window = current_window
local window_count = 1
local next_win_pos = 0
if ( !start_window )
return
# first count the windows
while ( next_window( "", 0, 1) != start_window )
window_count++
if ( mdi_mode == 2 )
{
win_width = screen_width
win_height = screen_height / window_count
scr_height = screen_height
}
else
{
win_width = display_width
win_height = display_height / window_count
scr_height = display_height
}
# size the first window and then get its size
frame_window( 0, next_win_pos, win_width, win_height, current_window )
win_size = window_height
total_size = window_height
next_win_pos = win_size
# now size the rest of the windows
while ( ( cur_win = next_window("", 0, 1) ) != start_window )
{
if ( total_size > scr_height )
{
total_size = 0
next_win_pos = 0
}
frame_window( 0, next_win_pos, win_width, win_height, cur_win )
total_size += win_size
next_win_pos += win_size
}
}