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

  1. # $Header:   P:\source\wmacros\toolbar.pev   1.42   07 Feb 1995 13:15:12   WALKER  $
  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:   toolbar.pel  $
  21.  
  22. ##############################################################################
  23. ### Valid Toolbar buttons are listed below:
  24. local TBMP_NEW        =  1
  25. local TBMP_OPEN       =  2
  26. local TBMP_SAVE       =  3
  27. local TBMP_PRINTER    =  4
  28.  
  29. local TBMP_CUT        =  5
  30. local TBMP_COPY       =  6
  31. local TBMP_PASTE      =  7
  32.  
  33. local TBMP_UNDO       =  8
  34. local TBMP_REDO       =  9
  35.  
  36. local TBMP_FIND       =  10
  37. local TBMP_FINDNEXT   =  11
  38. local TBMP_CHANGE     =  12
  39.  
  40. local TBMP_CLOSE      =  13
  41. local TBMP_PREVBUF    =  14
  42. local TBMP_NEXTBUF    =  15
  43. local TBMP_LISTBUF    =  16
  44.  
  45. local TBMP_PREVERR    =  17
  46. local TBMP_NEXTERR    =  18
  47. local TBMP_LISTDLG    =  19
  48.  
  49. ##############################################################################
  50.  
  51. local  BUTTON_WIDTH    = 26
  52. local  BUTTON_DISTANCE = 1
  53. local  GROUP_DISTANCE  = 8
  54. local  BUTTON_SPACING  = BUTTON_WIDTH + BUTTON_DISTANCE
  55.  
  56. global TOOLBAR_BUTTON    = 0x0001
  57. global TOOLBAR_SEPARATOR = 0x0002
  58.  
  59. # location of first button
  60. local bp = 0
  61.  
  62. local editor_toolbar
  63.  
  64. function create_default_toolbar()
  65. {
  66.  
  67.    editor_toolbar = create_toolbar()
  68.  
  69.    insert_toolbaritem(editor_toolbar, IDM_NEW, TOOLBAR_BUTTON,        bp,       4,  TBMP_NEW,       "gui_new" )
  70.    insert_toolbaritem(editor_toolbar, IDM_ADDFILE, TOOLBAR_BUTTON,    _next(),  4,  TBMP_OPEN,      "gui_open" )
  71.    insert_toolbaritem(editor_toolbar, IDM_SAVE, TOOLBAR_BUTTON,       _next(),  4,  TBMP_SAVE,      "gui_save" )
  72.    insert_toolbaritem(editor_toolbar, IDM_PRINT, TOOLBAR_BUTTON,      _next(),  4,  TBMP_PRINTER,   "gui_print" )
  73.                                                                        
  74.    insert_toolbaritem(editor_toolbar, IDM_CUT, TOOLBAR_BUTTON,        _next(1), 4, TBMP_CUT,       "gui_delete_to_scrap" )
  75.    insert_toolbaritem(editor_toolbar, IDM_COPY, TOOLBAR_BUTTON,       _next(),  4, TBMP_COPY,      "copy_to_scrap_key" )
  76.    insert_toolbaritem(editor_toolbar, IDM_PASTE, TOOLBAR_BUTTON,      _next(),  4, TBMP_PASTE,     "insert_scrap" )
  77.                                                                        
  78.    insert_toolbaritem(editor_toolbar, IDM_UNDO, TOOLBAR_BUTTON,       _next(1), 4, TBMP_UNDO,      "gui_undo" )
  79.    insert_toolbaritem(editor_toolbar, IDM_REDO, TOOLBAR_BUTTON,       _next(),  4, TBMP_REDO,      "gui_redo" )
  80.                                                                        
  81.    insert_toolbaritem(editor_toolbar, IDM_FIND, TOOLBAR_BUTTON,       _next(1), 4, TBMP_FIND,      "gui_find" )
  82.    insert_toolbaritem(editor_toolbar, IDM_FINDAGAIN, TOOLBAR_BUTTON,  _next(),  4, TBMP_FINDNEXT,  "gui_search_again" )
  83.    insert_toolbaritem(editor_toolbar, IDM_CHANGE, TOOLBAR_BUTTON,     _next(),  4, TBMP_CHANGE,    "gui_change" )
  84.                                                                        
  85.    insert_toolbaritem(editor_toolbar, IDM_CLOSE, TOOLBAR_BUTTON,      _next(1), 4, TBMP_CLOSE,     "gui_delete_buffer" )
  86.    insert_toolbaritem(editor_toolbar, IDM_PREV, TOOLBAR_BUTTON,       _next(),  4, TBMP_PREVBUF,   "prev_buffer_mask" )
  87.    insert_toolbaritem(editor_toolbar, IDM_NEXT, TOOLBAR_BUTTON,       _next(),  4, TBMP_NEXTBUF,   "next_buffer_mask" )
  88.    insert_toolbaritem(editor_toolbar, IDM_BUFFERLIST, TOOLBAR_BUTTON, _next(),  4, TBMP_LISTBUF,   "buffer_list" )
  89.  
  90.    insert_toolbaritem(editor_toolbar, IDM_PREVERR, TOOLBAR_BUTTON,    _next(1), 4, TBMP_PREVERR,   "goto_prev_error" )
  91.    insert_toolbaritem(editor_toolbar, IDM_NEXTERR, TOOLBAR_BUTTON,    _next(),  4, TBMP_NEXTERR,    "goto_next_error" )
  92.    insert_toolbaritem(editor_toolbar, IDM_DIALOG_LIST, TOOLBAR_BUTTON,_next(),  4, TBMP_LISTDLG,    "dialog_list" )
  93. }
  94.  
  95. function delete_editor_toolbar()
  96. {
  97.    if ( editor_toolbar )
  98.    {
  99.       hide_toolbar(editor_toolbar)
  100.       delete_toolbar(editor_toolbar)
  101.  
  102.       editor_toolbar = 0
  103.    }
  104. }
  105.  
  106. local x
  107. local y
  108.  
  109. local floating_tb_dialog, floating_tb
  110.  
  111. local function create_floating_toolbar()
  112. {
  113.    local starty
  114.  
  115.    x = 0
  116.    y = 4
  117.  
  118.    if ( !floating_tb_dialog )
  119.    {
  120.       floating_tb_dialog = create_mdialog_template( function_id("floating_callback"), -1, "P/2",
  121.                                       0, 0, BUTTON_SPACING * 2 + 18, BUTTON_SPACING * 10 + 36 + 28 )
  122.  
  123.       floating_tb = create_toolbar(floating_tb_dialog, BUTTON_SPACING * 10 + 6 + 28)
  124.  
  125.       insert_toolbaritem(floating_tb, IDM_DIALOG_LIST, TOOLBAR_BUTTON, x,y, TBMP_LISTDLG, "dialog_list" )
  126.  
  127.       _nexty()
  128.       x = 0
  129.  
  130.       insert_toolbaritem(floating_tb, IDM_PREVERR, TOOLBAR_BUTTON, x, y, TBMP_PREVERR, "goto_prev_error" )
  131.       insert_toolbaritem(floating_tb, IDM_NEXTERR, TOOLBAR_BUTTON, _nextx(), y, TBMP_NEXTERR, "goto_next_error" )
  132.  
  133.       y += 7
  134.       _nexty()
  135.       x = 0
  136.                                                                                  
  137.       insert_toolbaritem(floating_tb, IDM_UNDO, TOOLBAR_BUTTON, x, y, TBMP_UNDO, "gui_undo" )
  138.       insert_toolbaritem(floating_tb, IDM_REDO, TOOLBAR_BUTTON, _nextx(), y, TBMP_REDO, "gui_redo" )
  139.  
  140.       y += 7
  141.       _nexty()
  142.       x = 0
  143.                                                                                  
  144.       insert_toolbaritem(floating_tb, IDM_FINDAGAIN, TOOLBAR_BUTTON, x, y, TBMP_FINDNEXT, "gui_search_again" )
  145.       insert_toolbaritem(floating_tb, IDM_CHANGE, TOOLBAR_BUTTON, _nextx(), y, TBMP_CHANGE, "gui_change" )
  146.  
  147.       _nexty()
  148.       x = 0
  149.                                                                                  
  150.       insert_toolbaritem(floating_tb, IDM_PASTE, TOOLBAR_BUTTON, x, y,  TBMP_PASTE, "insert_scrap" )
  151.       insert_toolbaritem(floating_tb, IDM_FIND, TOOLBAR_BUTTON, _nextx(), y, TBMP_FIND,"gui_find" )
  152.  
  153.       _nexty()
  154.       x = 0
  155.                                                                           
  156.       insert_toolbaritem(floating_tb, IDM_CUT, TOOLBAR_BUTTON, x, y,  TBMP_CUT, "gui_delete_to_scrap" )
  157.       insert_toolbaritem(floating_tb, IDM_COPY, TOOLBAR_BUTTON, _nextx(), y,  TBMP_COPY, "copy_to_scrap_key" )
  158.  
  159.       y += 7
  160.       _nexty()
  161.       x = 0
  162.                                                                           
  163.       insert_toolbaritem(floating_tb, IDM_NEXT, TOOLBAR_BUTTON, x, y, TBMP_NEXTBUF, "next_buffer_mask" )
  164.       insert_toolbaritem(floating_tb, IDM_BUFFERLIST, TOOLBAR_BUTTON, _nextx(), y, TBMP_LISTBUF, "buffer_list" )
  165.  
  166.       _nexty()
  167.       x = 0
  168.                                                                           
  169.       insert_toolbaritem(floating_tb, IDM_CLOSE, TOOLBAR_BUTTON, x, y, TBMP_CLOSE, "gui_delete_buffer" )
  170.       insert_toolbaritem(floating_tb, IDM_PREV, TOOLBAR_BUTTON, _nextx(), y, TBMP_PREVBUF, "prev_buffer_mask" )
  171.  
  172.       y += 7
  173.       _nexty()
  174.       x = 0
  175.                                                                     
  176.       insert_toolbaritem(floating_tb, IDM_SAVE, TOOLBAR_BUTTON, x, y,  TBMP_SAVE, "gui_save" )
  177.       insert_toolbaritem(floating_tb, IDM_PRINT, TOOLBAR_BUTTON, _nextx(), y,  TBMP_PRINTER, "gui_print" )
  178.  
  179.       _nexty()
  180.       x = 0
  181.                                                                     
  182.       insert_toolbaritem(floating_tb, IDM_NEW, TOOLBAR_BUTTON, x, y,  TBMP_NEW, "gui_new" )
  183.       insert_toolbaritem(floating_tb, IDM_ADDFILE, TOOLBAR_BUTTON, _nextx(), y,  TBMP_OPEN, "gui_open" )
  184.  
  185.         show_toolbar( floating_tb )
  186.                                                                     
  187.       set_dialog_window( floating_tb_dialog, DWC_NORMALBORDER )
  188.  
  189.       set_dialog_window( floating_tb_dialog, DWC_STICKONTOP, 1 )
  190.    }
  191. }
  192.  
  193. global function floating_callback()
  194. {
  195.    if ( callback_msg == DM_CLOSE || callback_msg == DM_CANCEL )
  196.    {
  197.       # this gets focus put to the currently active text window
  198.       current_window = current_window
  199.    }  
  200.    else if ( callback_msg == DM_CLICK )
  201.       return DRC_MSG_PROCESSED
  202.  
  203.    return DRC_CONTINUE
  204. }
  205.  
  206. local function _nextx()
  207. {
  208.    x += BUTTON_SPACING
  209.  
  210.    return x
  211. }
  212.  
  213. local function _nexty()
  214. {
  215.    y += BUTTON_SPACING 
  216.  
  217.    return y
  218. }
  219.  
  220.  
  221. local function _next( group )
  222. {
  223.    if (group)
  224.       group = GROUP_DISTANCE
  225.    else
  226.       group = BUTTON_DISTANCE
  227.  
  228.    return bp += BUTTON_WIDTH + group
  229. }
  230.  
  231. global function toggle_floating_toolbar(enable)
  232. {
  233.    local action, old_state
  234.  
  235.    enable += 0;
  236.  
  237.    if ( (argcount() == 0 || ( argcount() == 1 && enable ) ) )
  238.    {
  239.       if ( !floating_tb_dialog )
  240.       {
  241.          create_floating_toolbar()
  242.          old_state = 0
  243.       }
  244.       else
  245.          old_state = toolbar_info(floating_tb, TB_IS_VISIBLE)
  246.    }
  247.    else if ( !floating_tb_dialog )
  248.    {
  249.       create_floating_toolbar()
  250.       return 0
  251.    }
  252.  
  253.    
  254.    if( argcount() < 1 )
  255.       enable = !old_state
  256.    
  257.    if( enable > 0 && !old_state ) 
  258.    {
  259.       set_dialog_window( floating_tb_dialog, DWC_SHOW )
  260. #      show_toolbar(floating_tb)
  261.    }
  262.    else  
  263.    {
  264.       set_dialog_window( floating_tb_dialog, DWC_HIDE )
  265. #      hide_toolbar(floating_tb)
  266.    }
  267.    
  268.    return old_state
  269. }
  270.  
  271. function toggle_toolbar( enable )
  272. {
  273.    local tbhand
  274.    local action, old_state
  275.  
  276.    tbhand = toolbar_info(0);
  277.  
  278.    if ( !tbhand )
  279.       return FALSE
  280.    
  281.    enable += 0;
  282.    old_state = toolbar_info(tbhand, TB_IS_VISIBLE)
  283.    
  284.    if( argcount() < 1 )
  285.       enable = !old_state
  286.    
  287.    if( enable > 0 && !old_state ) 
  288.       show_toolbar(tbhand)
  289.    else  
  290.       hide_toolbar(tbhand)
  291.    
  292.    return old_state
  293. }
  294.  
  295. global function position_floating_tb( x, y )
  296. {
  297.    if ( floating_tb_dialog )
  298.       set_dialog_window( floating_tb_dialog, DWC_POSITION, x+0, y+0 )
  299. }
  300.  
  301. function toolbar_settings( settings_index, settings_data )
  302. {
  303.    local pos
  304.    local new_array
  305.    local tbhand
  306.    local visible = 0
  307.  
  308.    tbhand = toolbar_info(0);
  309.  
  310.    if ( tbhand )
  311.       visible = toolbar_info(tbhand, TB_IS_VISIBLE)
  312.  
  313.    settings_data[ settings_index++ ] = sprintf( "toggle_toolbar %d\n", visible )
  314.  
  315.    if ( floating_tb_dialog )
  316.       visible = toolbar_info(floating_tb, TB_IS_VISIBLE)
  317.    else
  318.       visible = 0
  319.  
  320.  
  321.    if ( visible )
  322.    {
  323.       settings_data[ settings_index++ ] = sprintf( "toggle_floating_toolbar %d\n", 0 )
  324.       pos = query_dialog_window( floating_tb_dialog, DWC_POSITION );
  325.       settings_data[ settings_index++ ] = sprintf( "position_floating_tb %d %d\n", pos / 65536, pos % 65536)
  326.       settings_data[ settings_index++ ] = sprintf( "toggle_floating_toolbar %d\n", 1 )
  327.    }
  328.       
  329.    new_array.array = settings_data
  330.    new_array.index = settings_index
  331.    return new_array
  332. }
  333.