home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 5 Edit / 05-Edit.zip / p2demo21.exe / PEL / MDI.PEL < prev    next >
Text File  |  1995-03-23  |  22KB  |  803 lines

  1. # $Header:   P:\source\wmacros\mdi.pev   1.71   23 Mar 1995 10:51:10   PFHJXM0  $
  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:   mdi.pel  $
  21.  
  22. local ICONIZE_WINDOWS            = 1
  23. local TILE_WINDOWS               = 2
  24. local CASCADE_WINDOWS            = 3
  25.  
  26. # maximum number of windows open all commands
  27. # will open
  28. local MAX_WINDOWS                = 100
  29.  
  30. global function mdi_menu()
  31. {
  32.    menu_function_list[IDM_NEW_WINDOW] = "create_mdi_window" 
  33.  
  34.    menu_function_list[IDM_CASCADE_WINDOW] = "window_cascade" 
  35.    menu_function_list[IDM_TILE_WINDOW] = "window_tile" 
  36. #  menu_function_list[IDM_ARRANGE_ICONS] = "arrange_icons" 
  37.  
  38.    menu_function_list[IDM_CASCADE_BUFFERS] = "cascade_buffers" 
  39.    menu_function_list[IDM_TILE_BUFFERS] = "tile_buffers" 
  40.  
  41.    menu_function_list[IDM_HSPLIT_WINDOW] = "split_window_horizontal" 
  42.    menu_function_list[IDM_VSPLIT_WINDOW] = "split_window_vertical" 
  43.  
  44.    menu_function_list[IDM_BUFFER_MASK] = "set_buffer_mask_key" 
  45.  
  46.    menu_function_list[IDM_NEXT_WINDOW] = "next_window" 
  47.    menu_function_list[IDM_PREV_WINDOW] = "prev_window" 
  48.    menu_function_list[IDM_CLOSE_ALL_WINDOWS] = "delete_all_windows" 
  49. }
  50.  
  51. global function create_mdi_window(noBuffer)
  52. {
  53.    local w1
  54.    local width    = query_editwin_property( EWC_CLIENT_WIDTH )
  55.    local height   = query_editwin_property( EWC_CLIENT_HEIGHT )
  56.  
  57. #  w1 = create_window( 0, 0, editwin_client_width, editwin_client_height )
  58.  
  59.    if(create_new_bufwin)
  60.    {
  61.       gui_new();
  62.    }
  63.    else
  64.    {
  65.       w1 = create_window( 0, 0, width, height )
  66.       attach_window_buffer( w1, current_buffer )
  67.       current_window = w1
  68.    }
  69. }
  70.  
  71. global function create_detached_window(noBuffer)
  72. {
  73.    local w1
  74.    local width    = screen_width / 2
  75.    local height   = screen_height / 2
  76.    local x        = width / 2
  77.    local y        = height / 2
  78.    local wf       = and(window_flags, not(WINDOW_ZOOM))
  79.  
  80.  
  81.    if(create_new_bufwin)
  82.    {
  83.          gui_new();
  84.    }
  85.    else
  86.    {
  87.       if(current_window)
  88.       {
  89.          x = window_x0 + 25;
  90.          y = window_y0 - 25;
  91.          height = window_height;
  92.          width  = window_width;
  93.    
  94.          #  If more than half the window is right of the right edge of the editor window, move it to the left;
  95.          if( x + width > screen_width)
  96.             x = 0;
  97.    
  98.          #  If more than half the window is below the bottom of the editor window, move it up to the top;
  99.          if(y < 0)
  100.             y = screen_height - height;
  101.    
  102.       }
  103.    
  104.       wf = or(wf, WINDOW_NORMAL)
  105.       w1 = create_window( x, y, width, height, wf )
  106.       attach_window_buffer( w1, current_buffer )
  107.       attach_menu_to_win( w1 )
  108.       current_window = w1
  109.    }
  110. }
  111.  
  112. global function window_tile()                    #PUBLIC #VOID
  113. {
  114.    arrange_windows( TILE_WINDOWS )
  115. }
  116.  
  117.  
  118. global function window_cascade()                 #PUBLIC #VOID
  119. {
  120.    arrange_windows( CASCADE_WINDOWS )
  121. }
  122.  
  123. global function arrange_icons()
  124. {
  125.    arrange_windows( ICONIZE_WINDOWS )
  126. }
  127.  
  128. global function toggle_window_mode( mode )
  129. {
  130.    # switch to mode requested. 1 = mdi 0 = sdi
  131.    if ( argcount() > 0 ) {
  132.       # only switch if we are not already in mdi mode
  133.       if ( mode && !mdi_mode ) {
  134.          switch_to_mdi()
  135.          window_tile()
  136.       }
  137.       else if ( !mode && mdi_mode )
  138.          switch_to_sdi()
  139.    }
  140.    # if no argument toggle window mode
  141.    else {
  142.       if ( mdi_mode )
  143.          switch_to_sdi()
  144.       else {
  145.          switch_to_mdi()
  146.       }
  147.    }
  148.  
  149. }
  150.  
  151. global function delete_all_windows()
  152. {
  153.    local curr_window
  154.  
  155.    while ( (curr_window = next_window("", 0, 1)) != 0 )
  156.       delete_window( curr_window )
  157. }
  158.  
  159. global function switch_to_sdi()
  160. {
  161.    local wf
  162.    local old_window
  163.    local curr_window
  164.  
  165.    if ( mdi_mode == 0 )
  166.       return;
  167.    else if ( mdi_mode == 2 )
  168.    {
  169.       toggle_floating_toolbar(0)
  170.       delete_container_list()
  171.  
  172.       mdi_mode = 0
  173.  
  174.       toggle_toolbar(1)
  175.       toggle_status_bar(1)
  176.    }
  177.    else
  178.       mdi_mode = 0
  179.  
  180.    toggle_create_new_win( 0 )  
  181.  
  182.    wf = and(default_window_flags, WINDOW_SCROLLBARS+WINDOW_DISPLAY_FULL_FILENAME)
  183.    default_window_flags = and(WINDOW_STANDARD_SDI, not(WINDOW_SCROLLBARS+WINDOW_DISPLAY_FULL_FILENAME))
  184.    default_window_flags = or(wf, default_window_flags)
  185.  
  186.    while ( current_window != (curr_window = next_window("", 0, 1)) )
  187.       delete_window( curr_window )
  188.  
  189.    old_window     = current_window
  190.    current_window = dup_window( old_window, default_window_flags )
  191.    delete_window( old_window )
  192.  
  193.    modify_mdi_menu(mdi_mode)
  194. }
  195.  
  196. global function switch_to_mdi()
  197. {
  198.    local i
  199.    local wf
  200.    local window_list
  201.    local start_window
  202.    local save_status_bar_flags
  203.              
  204.    if ( mdi_mode == 1 )
  205.       return;
  206.    else if ( mdi_mode == 2 )
  207.    {
  208.       save_status_bar_flags = status_bar_flags
  209.       toggle_floating_toolbar(0)
  210.       delete_container_list()
  211.  
  212.       mdi_mode = 1
  213.  
  214.       toggle_toolbar(1)
  215.       if(save_status_bar_flags)
  216.          status_bar_flags = save_status_bar_flags
  217.       else
  218.          toggle_status_bar(1)
  219.    }
  220.    else
  221.       mdi_mode = 1
  222.  
  223.    modify_mdi_menu(mdi_mode)
  224.  
  225.    wf = and(default_window_flags, WINDOW_SCROLLBARS+WINDOW_DISPLAY_FULL_FILENAME)
  226.    default_window_flags = and(WINDOW_STANDARD_MDI, not(WINDOW_SCROLLBARS+WINDOW_DISPLAY_FULL_FILENAME))
  227.    default_window_flags = or(wf, default_window_flags)
  228.  
  229.    copy_windows()
  230. }
  231.  
  232. global function switch_to_detached()
  233. {
  234.    local wf
  235.    local width, height
  236.    local old_x, old_y, old_w, old_h
  237.    local save_status_bar_flags = status_bar_flags #  Saved because when
  238.    #  mdi_mode is set to 2, the status_bar_flags get set to 0, and when
  239.    #  toggle_status_bar(1) was called, it used STB_DEFAULT instead of
  240.    #  what the user set;
  241.  
  242.    if ( mdi_mode == 2 )
  243.       return;
  244.  
  245.    toggle_toolbar(0)
  246.  
  247.    # all new windows created will be detached child windows
  248.    mdi_mode = 2
  249.    modify_mdi_menu(mdi_mode)
  250.  
  251.    wf = and(default_window_flags, WINDOW_SCROLLBARS+WINDOW_DISPLAY_FULL_FILENAME)
  252.    default_window_flags = and(WINDOW_STANDARD_MDI, not(WINDOW_SCROLLBARS+WINDOW_DISPLAY_FULL_FILENAME))
  253.    default_window_flags = or(wf, default_window_flags)
  254.  
  255.    if (save_status_bar_flags)
  256.       status_bar_flags = save_status_bar_flags;
  257.    else
  258.       toggle_status_bar(1)
  259.  
  260.    copy_windows()
  261.  
  262.    toggle_floating_toolbar(1)
  263.    create_container_list()
  264.  
  265.    width  = screen_width / 2 + 50
  266.    height = screen_height / 4
  267.  
  268.    set_editwin_property( EWC_WIDTH, width )
  269.    set_editwin_property( EWC_HEIGHT, height )
  270.    set_editwin_property( EWC_X_POS, screen_width - width )
  271.    set_editwin_property( EWC_Y_POS, screen_height - height )
  272. }
  273.  
  274. global function copy_windows()
  275. {
  276.    local i
  277.    local window_list
  278.    local delete_list
  279.    local work_window
  280.    local temp_window
  281.    local start_window
  282.    local window_count
  283.    local save_status_bar_flags
  284.    local old_create_new_bufwin = create_new_bufwin
  285.  
  286.    if (old_create_new_bufwin)
  287.       toggle_create_new_win(0)
  288.  
  289.    if ( !current_window )
  290.    {
  291.       if ( old_create_new_bufwin )
  292.          toggle_create_new_win(1)
  293.       return;
  294.    }
  295.  
  296.    for (start_window = window_count = i = 0;
  297.         current_window != start_window || !start_window; next_window("", 0, 1))
  298.    {
  299.       if (!start_window)
  300.            start_window = current_window
  301.  
  302.       if (window_text_height > 1 && window_text_width > 10 &&
  303.           window_height / text_char_height > 1 &&
  304.           window_width  / text_char_width  > 10)
  305.       {
  306.          window_list[window_count++] = current_window
  307.       }
  308.       else
  309.          delete_list[i++] = current_window
  310.    }
  311.  
  312.    if (window_count)
  313.    {
  314.       for (i in delete_list)
  315.          delete_window(delete_list[i])
  316.  
  317.       if ( mdi_mode == 2 )
  318.       {
  319.          temp_window           = 0
  320.          start_window          = 0
  321.          save_status_bar_flags = status_bar_flags
  322.          for (i in window_list)
  323.          {
  324.             work_window    = window_list[i]
  325.             current_window = dup_window(work_window, default_window_flags)
  326.  
  327.             if (save_status_bar_flags)
  328.                status_bar_flags = save_status_bar_flags;
  329.             else
  330.                toggle_status_bar(1)
  331.  
  332.             attach_menu_to_win(current_window)
  333.             modify_mdi_menu(mdi_mode)
  334.  
  335.             if (window_text_height > 1 && window_text_width > 10 &&
  336.                 window_height / text_char_height > 1 &&
  337.                 window_width  / text_char_width  > 10)
  338.             {
  339.                if (!start_window)
  340.                     start_window = current_window
  341.                delete_window(work_window)
  342.             }
  343.             else
  344.             {
  345.                if (temp_window)
  346.                   delete_window(temp_window)
  347.                temp_window = work_window
  348.                window_count--
  349.             }
  350.          }
  351.  
  352.          if (start_window)
  353.             current_window = start_window
  354.          else if (temp_window)
  355.          {
  356.             current_window = temp_window
  357.             expand_window()
  358.             current_window = dup_window( temp_window, default_window_flags )
  359.  
  360.             if (save_status_bar_flags)
  361.                status_bar_flags = save_status_bar_flags;
  362.             else
  363.                toggle_status_bar(1)
  364.  
  365.             attach_menu_to_win(current_window)
  366.             modify_mdi_menu(mdi_mode)
  367.             delete_window( temp_window )
  368.          }
  369.       }
  370.       else
  371.       {
  372.          for (i in window_list)
  373.          {
  374.             work_window = window_list[i]
  375.             if (i == 0)
  376.                current_window = dup_window(work_window, default_window_flags)
  377.             else
  378.                dup_window(work_window, default_window_flags)
  379.             delete_window(work_window)
  380.          }
  381.       }
  382.    }
  383.    else
  384.    {
  385.       while ( current_window != (work_window = next_window("", 0, 1)) )
  386.          delete_window( work_window )
  387.  
  388.       if ( mdi_mode == 2 )
  389.          expand_window()
  390.  
  391.       work_window    = current_window
  392.       current_window = dup_window( work_window, default_window_flags )
  393.       delete_window( work_window )
  394.  
  395.       if ( mdi_mode == 2 )
  396.       {
  397.          if (save_status_bar_flags)
  398.             status_bar_flags = save_status_bar_flags;
  399.          else
  400.             toggle_status_bar(1)
  401.  
  402.          attach_menu_to_win(current_window)
  403.          modify_mdi_menu(mdi_mode)
  404.       }
  405.    }
  406.  
  407.    if (old_create_new_bufwin)
  408.       toggle_create_new_win(1)
  409.  
  410.    if (mdi_mode != 2 && !window_count)
  411.       window_tile()
  412. }
  413.  
  414. global function modify_mdi_menu(mode, menu)
  415. {
  416.    local enable = ( mode ) ? MI_ENABLED : MI_DISABLED;
  417.  
  418.    if ( argcount() < 2 )
  419.       menu = menu_info(0, 0x2000)
  420.  
  421.    if ( mdi_mode == 2 )
  422.    {
  423.       menu_function_list[IDM_NEW_WINDOW] = "create_detached_window" 
  424.       menu_function_list[IDM_TOOLBAR]    = "toggle_floating_toolbar"
  425.    }
  426.    else
  427.    {
  428.       menu_function_list[IDM_NEW_WINDOW] = "create_mdi_window" 
  429.       menu_function_list[IDM_TOOLBAR]    = "toggle_toolbar" 
  430.    }
  431.  
  432.    if ( menu )
  433.    {
  434.       # disable/enable sub menus
  435.       modify_menuitem( menu, IDM_NEW_WINDOW, enable )
  436.       
  437.       modify_menuitem( menu, IDM_CASCADE_WINDOW, (mode == 2) ? MI_DISABLED : enable )
  438.       modify_menuitem( menu, IDM_TILE_WINDOW, (mode == 2) ? MI_DISABLED : enable )
  439. #     modify_menuitem( menu, IDM_ARRANGE_ICONS, (mode == 2) ? MI_DISABLED : enable )
  440.       modify_menuitem( menu, IDM_CASCADE_BUFFERS, (mode == 2) ? MI_DISABLED : enable )
  441.       modify_menuitem( menu, IDM_TILE_BUFFERS, (mode == 2) ? MI_DISABLED : enable )
  442.       modify_menuitem( menu, IDM_NEXT_WINDOW, enable )
  443.       modify_menuitem( menu, IDM_PREV_WINDOW, enable )
  444.       modify_menuitem( menu, IDM_CLOSE_ALL_WINDOWS, enable )
  445.       
  446.       modify_menuitem( menu, IDM_HSPLIT_WINDOW,    enable )
  447.       modify_menuitem( menu, IDM_VSPLIT_WINDOW,    enable )
  448.    }
  449. }
  450.  
  451. global function tile_buffers()
  452. {
  453.    if ( mdi_mode )
  454.    {
  455.       assign_one_buffer_per_window()
  456.       arrange_windows( TILE_WINDOWS )
  457.    }
  458.    else
  459.       warning("window_per_buffer only valid for MDI")
  460. }
  461.  
  462. global function cascade_buffers()
  463. {
  464.    if ( mdi_mode )
  465.    {
  466.       assign_one_buffer_per_window()
  467.       arrange_windows( CASCADE_WINDOWS )
  468.    }
  469.    else
  470.       warning("window_per_buffer only valid for MDI")
  471. }
  472.  
  473. local function assign_one_buffer_per_window()
  474. {
  475.    local new_win
  476.    local curr_buffer
  477.    local start_buffer
  478.    local curr_window
  479.    local prev_window
  480.    local start_window
  481.    local num_windows           = 0
  482.    local used_all_buffers      = 0
  483.    local used_all_windows      = 0
  484.    local old_create_new_bufwin = create_new_bufwin
  485.  
  486.    #  One buffer per window mode screws up the tile/cascade when it is on;
  487.    create_new_bufwin = 0
  488.  
  489.    start_buffer = current_buffer
  490.    curr_buffer  = start_buffer
  491.    start_window = current_window
  492.  
  493.    # first loop through all the windows and put a different buffer in
  494.    # each window
  495.    curr_window = next_window("", 0, 1)
  496.    if ( !curr_window )
  497.       used_all_windows = 1
  498.  
  499.    while ( !used_all_buffers && !used_all_windows )
  500.    {
  501.       attach_window_buffer(curr_window, curr_buffer)
  502.       restore_window(curr_window)
  503.  
  504.       if ( curr_window == start_window )
  505.          used_all_windows = 1
  506.  
  507.       if ( (curr_buffer = next_buffer("", 0, 1)) == start_buffer ) 
  508.          used_all_buffers = 1
  509.  
  510.       prev_window = curr_window
  511.       curr_window = next_window("", 0, 1)
  512.       num_windows++
  513.    }
  514.  
  515.    # if all buffers are used delete extra windows and return
  516.    if ( used_all_buffers && !used_all_windows )
  517.    {
  518.       while ( curr_window != start_window )
  519.       {
  520.          prev_window = curr_window
  521.          curr_window = next_window("", 0, 1)
  522.          delete_window(prev_window)
  523.          current_window = curr_window
  524.       }
  525.       delete_window(start_window)
  526.    }
  527.    else if ( !used_all_buffers )
  528.    {
  529.       # need to create more windows for the rest of the buffers
  530.       while ( !used_all_buffers && num_windows < MAX_WINDOWS )
  531.       {
  532.          prev_window = current_window;
  533.          current_window = dup_window( prev_window )
  534.          position_window(current_window, prev_window)
  535.  
  536.          if(mdi_mode == 2)   #  Need to attach a menu if in detached mode;
  537.             attach_menu_to_win(current_window);
  538.          attach_window_buffer(current_window, curr_buffer)
  539.  
  540.          #  prev_window = new_win
  541.          curr_buffer = next_buffer("", 0, 1);
  542. #           if ( (curr_buffer = next_buffer("", 0, 1)) == start_buffer )
  543.          if (curr_buffer == start_buffer )
  544.             used_all_buffers = 1
  545.  
  546.          num_windows++
  547.       }
  548.    }
  549.    # DWM 8/16/94
  550.    # Have to reset at least the current window when # of buffers
  551.    # and windows are equal--one too many next_window(,,1) was done.
  552.    # start_window is gauranteed to exist because # of wins and bufs
  553.    # are equal
  554.    else 
  555.       current_window = start_window
  556.  
  557.    create_new_bufwin = old_create_new_bufwin
  558. }
  559.  
  560. local function position_window(new, old)
  561. {
  562.    local prev_win = 0;
  563.    local x, y, width, height;
  564.    local edit_width, edit_height;
  565.  
  566.  
  567.    if(old)
  568.    {
  569.       prev_win = current_window;
  570.       current_window = old;
  571.    }
  572.  
  573.    if(mdi_mode == 2)
  574.    {
  575.       edit_width  = screen_width;
  576.       edit_height = screen_height;
  577.    }
  578.    else
  579.    {
  580.       edit_width  = query_editwin_property(EWC_WIDTH);
  581.       edit_height = query_editwin_property(EWC_HEIGHT);
  582.    }
  583.  
  584.    if(current_window)
  585.    {
  586.       x      = window_x0 + 25;
  587.       y      = window_y0 - 25;
  588.       width  = window_width;
  589.       height = window_height;
  590.    }
  591.    else
  592.    {
  593.       x = 0;
  594.       y = 0;
  595.       width  = edit_width  / 2;
  596.       height = edit_height / 2;
  597.    }
  598.  
  599.    if( x > (edit_width - width) )
  600.       x = 0;
  601.          
  602.    if(y < 0)
  603.       y = edit_height - height;
  604.  
  605.    frame_window(x, y, width, height, new);
  606.  
  607.    if(prev_win)
  608.       current_window = prev_win;
  609. }
  610.  
  611. function mdi_settings( settings_index, settings_data )
  612. {
  613.    local new_array;
  614.  
  615.    settings_data[ settings_index++ ] = sprintf( "SET_MDI %d, %d\n", 
  616.                                                 mdi_mode, 
  617.                                                 create_new_bufwin )
  618.  
  619.    new_array.array = settings_data
  620.    new_array.index = settings_index
  621.    return new_array
  622. }
  623.  
  624. global function remove_keep_windows()
  625. {
  626.    delete_event( EVENT.RESIZE_EDITWIN, function_id("window_tile") );
  627.    delete_event( EVENT.RESIZE_EDITWIN, function_id("window_cascade") );
  628.    delete_event( EVENT.RESIZE_EDITWIN, function_id("tile_horizontal") );
  629.    delete_event( EVENT.RESIZE_EDITWIN, function_id("tile_vertical") );
  630.    delete_event( EVENT.RESIZE_EDITWIN, function_id("window_tile") );
  631. }
  632.  
  633. global function keep_windows_tiled()
  634. {
  635.    window_tile()
  636.  
  637.    # delete other event handlers that may be installed
  638.    delete_event( EVENT.RESIZE_EDITWIN, function_id("window_tile") );
  639.    delete_event( EVENT.RESIZE_EDITWIN, function_id("window_cascade") );
  640.    delete_event( EVENT.RESIZE_EDITWIN, function_id("tile_horizontal") );
  641.    delete_event( EVENT.RESIZE_EDITWIN, function_id("tile_vertical") );
  642.  
  643.    # attach new handler
  644.    attach_event_handler( EVENT.RESIZE_EDITWIN, function_id("window_tile") );
  645. }
  646.  
  647. global function keep_windows_cascaded()
  648. {
  649.    window_cascade()
  650.  
  651.    # delete other event handlers that may be installed
  652.    delete_event( EVENT.RESIZE_EDITWIN, function_id("window_tile") );
  653.    delete_event( EVENT.RESIZE_EDITWIN, function_id("window_cascade") );
  654.    delete_event( EVENT.RESIZE_EDITWIN, function_id("tile_horizontal") );
  655.    delete_event( EVENT.RESIZE_EDITWIN, function_id("tile_vertical") );
  656.  
  657.    # attach new handler
  658.    attach_event_handler( EVENT.RESIZE_EDITWIN, function_id("window_cascade") );
  659. }
  660.  
  661. global function keep_windows_tiled_horizontal()
  662. {
  663.    tile_horizontal()
  664.  
  665.    # delete other event handlers that may be installed
  666.    delete_event( EVENT.RESIZE_EDITWIN, function_id("window_tile") );
  667.    delete_event( EVENT.RESIZE_EDITWIN, function_id("window_cascade") );
  668.    delete_event( EVENT.RESIZE_EDITWIN, function_id("tile_horizontal") );
  669.    delete_event( EVENT.RESIZE_EDITWIN, function_id("tile_vertical") );
  670.  
  671.    # attach new handler
  672.    attach_event_handler( EVENT.RESIZE_EDITWIN, function_id("tile_horizontal") );
  673. }
  674.  
  675. global function keep_windows_tiled_vertical()
  676. {
  677.    tile_vertical()
  678.  
  679.    # delete other event handlers that may be installed
  680.    delete_event( EVENT.RESIZE_EDITWIN, function_id("window_tile") );
  681.    delete_event( EVENT.RESIZE_EDITWIN, function_id("window_cascade") );
  682.    delete_event( EVENT.RESIZE_EDITWIN, function_id("tile_horizontal") );
  683.    delete_event( EVENT.RESIZE_EDITWIN, function_id("tile_vertical") );
  684.  
  685.    # attach new handler
  686.    attach_event_handler( EVENT.RESIZE_EDITWIN, function_id("tile_vertical") );
  687. }
  688.  
  689.  
  690. global function tile_horizontal()
  691. {
  692.    local total_size
  693.    local win_size
  694.    local cur_win
  695.    local win_width
  696.    local win_height
  697.    local scr_width
  698.  
  699.    local start_window = current_window
  700.    local window_count = 1
  701.    local next_win_pos = 0
  702.  
  703.    if ( !start_window )
  704.       return
  705.  
  706.    # first count the windows
  707.  
  708.    while ( next_window( "", 0, 1) != start_window )
  709.       window_count++
  710.  
  711.    if ( mdi_mode == 2 )
  712.    {
  713.       win_width  = screen_width / window_count
  714.       win_height = screen_height
  715.       scr_width  = screen_width
  716.    }
  717.    else
  718.    {
  719.       win_width  = display_width / window_count
  720.       win_height = display_height
  721.       scr_width  = display_width
  722.    }
  723.  
  724.    # size the first window and then get its size
  725.    frame_window( next_win_pos, 0, win_width, win_height, current_window )
  726.  
  727.    win_size = window_width
  728.    total_size = window_width
  729.  
  730.    next_win_pos = win_size
  731.  
  732.    # now size the rest of the windows
  733.    while ( ( cur_win = next_window("", 0, 1) ) != start_window )
  734.    {
  735.       if ( total_size > scr_width )
  736.       {
  737.          total_size = 0
  738.          next_win_pos = 0
  739.       }
  740.  
  741.       frame_window(next_win_pos, 0, win_width, win_height, cur_win)
  742.       total_size += win_size
  743.       next_win_pos += win_size
  744.    }
  745. }
  746.  
  747. global function tile_vertical()
  748. {
  749.    local total_size
  750.    local win_size
  751.    local cur_win
  752.    local win_height
  753.    local win_width
  754.    local scr_height
  755.  
  756.    local start_window = current_window
  757.    local window_count = 1
  758.    local next_win_pos = 0
  759.  
  760.    if ( !start_window )
  761.       return
  762.  
  763.    # first count the windows
  764.  
  765.    while ( next_window( "", 0, 1) != start_window )
  766.       window_count++
  767.  
  768.    if ( mdi_mode == 2 )
  769.    {
  770.       win_width  = screen_width
  771.       win_height = screen_height / window_count
  772.       scr_height = screen_height
  773.    }
  774.    else
  775.    {
  776.       win_width  = display_width
  777.       win_height = display_height / window_count
  778.       scr_height = display_height
  779.    }
  780.  
  781.    # size the first window and then get its size
  782.    frame_window( 0, next_win_pos, win_width, win_height, current_window )
  783.  
  784.    win_size = window_height
  785.    total_size = window_height
  786.  
  787.    next_win_pos = win_size
  788.  
  789.    # now size the rest of the windows
  790.    while ( ( cur_win = next_window("", 0, 1) ) != start_window )
  791.    {
  792.       if ( total_size > scr_height )
  793.       {
  794.          total_size = 0
  795.          next_win_pos = 0
  796.       }
  797.  
  798.       frame_window( 0, next_win_pos, win_width, win_height, cur_win )
  799.       total_size += win_size
  800.       next_win_pos += win_size
  801.    }
  802. }
  803.