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

  1. # $Header:   P:\source\wmacros\notebook.pev   1.54   20 Mar 1995 10:29:34   PFHJXM0  $
  2.  
  3. ##############################################################################
  4. #
  5. #       Compuware Corporation
  6. #         31440 Northwestern Highway
  7. #           Farmington Hills, Michigan 48334-2564
  8. #
  9. #   This source code listing contains information that is
  10. #   proprietary to Compuware Corporation and may not be copied
  11. #   duplicated, translated, transmitted, stored, retrieved
  12. #   or in any manner or by any method conveyed or disclosed
  13. #   to a third party or parties without express written
  14. #   permission from Compuware Corporation.
  15. #
  16. #
  17. ##############################################################################
  18.  
  19. #### $Workfile:   notebook.pel  $: tags support
  20.  
  21. ## notebook manager functions and variables available to the user
  22. #
  23. # nbhand    create_notebook_template(callback_id, parent, label, x0, y0, width, height)
  24. #
  25. # void      delete_notebook(nbhand)
  26. #
  27. # void      begin_notebook(nbhand)
  28. #
  29. # void      set_notebook_major_tab_size(nbhand, width, height)
  30. #
  31. # void      set_notebook_minor_tab_size(nbhand, width, height)
  32. #
  33. # void      set_notebook_page_button_size(nbhand, width, height)
  34. #
  35. # void      set_notebook_binder_type(nbhand, bindertype)
  36. #
  37. # void      set_notebook_tab_type(nbhand, tabtype)
  38. #
  39. # void      set_notebook_tab_location(nbhand, tabloc)
  40. #
  41. # void      set_notebook_tab_alignment(nbhand, tabalign)
  42. #
  43. # void      set_notebook_status_alignment(nbhand, statalign)
  44. #
  45. # void      set_notebook_backpage_intersection(nbhand, backpos)
  46. #
  47. # int       count_notebook_pages(nbhand)
  48. #
  49. # hPage     append_notebook_page(nbhand, dlghand, stat_text,
  50. #                                tab_text, tab_type, resize)
  51. #
  52. # hPage     insert_notebook_page_at_top(nbhand, dlghand, stat_text,
  53. #                                       tab_text, tab_type, resize)
  54. #
  55. # hPage     insert_notebook_page_before(nbhand, before_page, dlghand,
  56. #                                       stat_text, tab_text, tab_type, resize)
  57. #
  58. # hPage     insert_notebook_page_after(nbhand, after_page, dlghand,
  59. #                                      stat_text, tab_text, tab_type, resize)
  60. #
  61. # void      delete_notebook_page(nbhand, pagehand)
  62. #
  63. # void      turnto_notebook_page(nbhand, pagehand)
  64. #
  65. # long      set_notebook_page_dialog(nbhand, pagehand, dlghand)
  66. #
  67. # long      get_notebook_page_dialog(nbhand, pagehand)
  68. #
  69. # void      set_notebook_page_tab_text(nbhand, pagehand, text)
  70. #
  71. # void      set_notebook_page_stat_text(nbhand, pagehand, text)
  72. #
  73. # dlghand   create_page_template(x0, y0, width, height)
  74. #
  75. # void      delete_page_template(dlghand)
  76. #
  77. #
  78. #
  79. # Constants
  80. #
  81.  
  82. global  NBTAB_NONE       = 0
  83. global  NBTAB_MINOR      = 1
  84. global  NBTAB_MAJOR      = 2
  85.  
  86. global  NB_NO_RESIZE     = 0
  87. global  NB_RESIZE        = 1
  88.  
  89. global  NB_BINDER_SOLID  = 0
  90. global  NB_BINDER_SPIRAL = 1
  91.  
  92. global  NB_ALIGN_LEFT    = 0
  93. global  NB_ALIGN_CENTER  = 1
  94. global  NB_ALIGN_RIGHT   = 2
  95.  
  96. global  NBTAB_SQUARE     = 0
  97. global  NBTAB_ROUNDED    = 1
  98. global  NBTAB_POLYGON    = 2
  99.  
  100. global  NBTAB_LEFT       = 0
  101. global  NBTAB_RIGHT      = 1
  102. global  NBTAB_TOP        = 2
  103. global  NBTAB_BOTTOM     = 3
  104.  
  105. global  NB_BACK_BR       = 0
  106. global  NB_BACK_BL       = 1
  107. global  NB_BACK_TR       = 2
  108. global  NB_BACK_TL       = 3
  109.  
  110. global MAJOR_TAB_WIDTH      = 78
  111. global MAJOR_TAB_HEIGHT     = 28
  112. global MINOR_TAB_WIDTH      = 128
  113. global MINOR_TAB_HEIGHT     = 30
  114.  
  115. global comp_buff = FALSE;           #  flag to compile language.pel when buffer pages are exposed
  116. #global DRC_EXIT         = 0
  117. #global DRC_CONTINUE     = 1
  118.  
  119. local assign_changes = FALSE;
  120. local dialog_return_value = 0
  121. local nhSettingsNotebook = 0
  122. global current_nb_page;
  123. global last_nb_page_name = "edithelp";
  124. global nbPagePrefix;                  #  Prefix to functions called by the dynamic
  125.                                       #  page creater; indexed by page id;
  126.  
  127. # Signals that pages are creating themselves in all notebooks
  128. global nb_initializing          = TRUE
  129.  
  130. global function settings_notebook()
  131. {
  132.    local tempid = 0, temp_name, pageid, old_level = message_level;
  133.  
  134.    if ( nhSettingsNotebook )
  135.    {
  136.       # Notebook is already active from another detached window
  137.       nb_initializing = FALSE;
  138.       set_dialog_window( nhSettingsNotebook, DWC_SHOW )
  139.    }
  140.    else
  141.    {
  142.       set_busy_cursor();
  143.    
  144.       nb_initializing = TRUE;
  145.       create_settings_notebook();
  146.  
  147.       optional_function("editor_settings_notebook",    nhSettingsNotebook);
  148.       optional_function("window_settings_notebook",    nhSettingsNotebook);
  149.       optional_function("extension_settings_notebook", nhSettingsNotebook);
  150.       optional_function("buffer_settings_notebook",    nhSettingsNotebook);
  151.       optional_function("file_settings_notebook",      nhSettingsNotebook);
  152.       if ( status_bar_flags )
  153.          message( "" );
  154.       set_normal_cursor();
  155.    
  156.       #  Find the pageid for the last exposed page in the notebook;
  157.       for(pageid in nbPagePrefix)
  158.       {
  159.          temp_name = nbPagePrefix[pageid].name;
  160.    
  161.          if(temp_name == last_nb_page_name)
  162.          {
  163.             tempid = pageid;
  164.             break;
  165.          }
  166.          else if(!tempid && (substr(temp_name, length(temp_name)-3) == "help"))
  167.          {
  168.             tempid = pageid;
  169.          }
  170.       }
  171.    
  172.       pageid = tempid;
  173.       last_nb_page_name = nbPagePrefix[pageid].name;
  174.    
  175.       #  Create the page and turn to it;
  176.       optional_function("create_" last_nb_page_name "_page", pageid, nhSettingsNotebook);
  177.       turnto_notebook_page(nhSettingsNotebook, pageid);
  178.    
  179.       #  Begin viewing notebook;
  180.       begin_notebook(nhSettingsNotebook);
  181.    
  182.       # let exposes get handled before
  183.       # we do time-consuming processing
  184.       idle()
  185.    
  186.       set_busy_cursor();
  187.       message_level = 1;
  188.    
  189.       if(assign_changes)
  190.       {
  191.          assign_notebook_changes(nhSettingsNotebook);
  192.       }
  193.    
  194.       apply_to_all();    # apply settings globally if appropriate
  195.    
  196.       set_normal_cursor();
  197.       delete_notebook(nhSettingsNotebook);
  198.    
  199.       set_busy_cursor();
  200.    
  201.       #  Restore the message_level if it was not set by the user;
  202.       for(pageid in nbPagePrefix)
  203.       {
  204.          if( (nbPagePrefix[pageid].name == "stb2") && 
  205.              (!nbPagePrefix[pageid].modified || !assign_changes) )
  206.          {
  207.             message_level = old_level;
  208.             break;
  209.          }
  210.       }
  211.    
  212.       delete nbPagePrefix;
  213.       delete nb_apply_to_all;
  214.       nhSettingsNotebook = 0;
  215.       notify("Reseting notebook variables.");
  216.       optional_function("reset_editor_settings_notebook");
  217.       optional_function("reset_extension_settings_notebook");
  218.       optional_function("reset_window_settings_notebook");
  219.       optional_function("reset_buffer_settings_notebook");
  220.       optional_function("reset_file_settings_notebook");
  221.       assign_changes = FALSE;
  222.    
  223.       set_normal_cursor();
  224.       display_redraw();
  225.       message("")
  226.    }
  227. }
  228.  
  229. global function create_settings_notebook()
  230. {
  231.    if ( status_bar_flags )
  232.       message( "Creating Settings Notebook..." )
  233.  
  234.    nhSettingsNotebook = create_notebook_template(function_id( "settings_notebook_callback" ),
  235.                                                  0, "Settings")
  236.  
  237.    set_notebook_major_tab_size(nhSettingsNotebook, MAJOR_TAB_WIDTH, MAJOR_TAB_HEIGHT)
  238.    set_notebook_minor_tab_size(nhSettingsNotebook, MINOR_TAB_WIDTH, MINOR_TAB_HEIGHT)
  239. #  set_notebook_tab_type(nhSettingsNotebook, NBTAB_SQUARE)
  240.  
  241.    attach_help(editor_helpfile, nhSettingsNotebook)
  242. }
  243.  
  244. global function settings_notebook_callback()
  245. {
  246.    local set, fid, return_msg = DRC_CONTINUE, dlgid = 0;
  247.    local name, helppage;
  248.    local ask, page;
  249.  
  250.    if ( callback_msg == DM_CLOSE )
  251.    {
  252.       #  User double clicked on the system icon;
  253.       ask = comp_buff;
  254.       if(!ask)
  255.       {
  256.          for(page in nbPagePrefix)
  257.          {
  258.             ask = nbPagePrefix[page].modified;
  259.             if(ask)
  260.                break;
  261.          }
  262.       }
  263.       if(!ask)
  264.       {
  265.          for(page in languages)
  266.          {
  267.             ask = Modified(page);
  268.             if(ask)
  269.                break;
  270.          }
  271.       }
  272.  
  273.       nb_initializing = TRUE;
  274.       if(ask)
  275.       {
  276.          set_status_bar_flags( and(status_bar_flags, not(STB_PROMPTS)));
  277.          set = confirm("Do you want to save your settings changes? (Y/N):", "YyNn");
  278.          restore_status_bar();
  279.          if(tolower(set) == "y")
  280.             assign_changes = TRUE;
  281.          else if(tolower(set) == "n")
  282.          {
  283.             optional_function("undo_cursor_settings", "all");
  284.             optional_function("undo_extension_section_settings");
  285.          }
  286.          else
  287.             return_msg = DRC_MSG_PROCESSED
  288.       }
  289.    }
  290.    else if ( callback_msg == DM_CANCEL )
  291.    {
  292.       #  User pressed the CANCEL button;
  293.       nb_initializing = TRUE;
  294.       optional_function("undo_cursor_settings", "all");
  295.       optional_function("undo_extension_section_settings");
  296.    }
  297.    else if((callback_msg == DM_PAGECHANGED) && !nb_initializing)
  298.    {
  299.       #  Save the page id and the name for access from other areas,
  300.       #  and next time notebook is opened;
  301.       set_busy_cursor()
  302.  
  303.       current_nb_page = callback_data;
  304.       last_nb_page_name = nbPagePrefix[current_nb_page].name;
  305.  
  306.  
  307.       if(!nbPagePrefix[current_nb_page].dialog_handle)
  308.       {
  309. #         name = nbPagePrefix[current_nb_page].name;
  310.          execute_function(function_id("create_" last_nb_page_name "_page", current_nb_page, nhSettingsNotebook));
  311.       }
  312.       else
  313.       {
  314.          execute_function(function_id("initialize_" last_nb_page_name "_settings", 
  315.                                       nbPagePrefix[current_nb_page].dialog_handle, 
  316.                                       global_type));
  317.       }
  318.       set_normal_cursor()
  319.    }
  320.    else if ( ( callback_msg == DM_CLICK && callback_index == DI_HELP ) ||
  321.              ( callback_msg == DM_HELPREQUESTED ) ) 
  322.    {
  323.       helppage = nbPagePrefix[current_nb_page].help;
  324.       if(helppage == "")
  325.          helppage = "settings"
  326.       display_help(helppage, callback_dialog_handle);
  327.       return_msg = DRC_MSG_PROCESSED
  328.    }
  329.    else if((callback_msg == DM_CLICK) || (callback_msg == DM_DOUBLE_CLICK))
  330.    {
  331.       if(callback_index == DI_OK)
  332.       {
  333.          assign_changes = TRUE;
  334.          nb_initializing = TRUE;
  335.       }
  336.       else if(callback_index == DI_CANCEL)
  337.       {
  338.          #  How does the user get here?;
  339.          dialog_return_value = "";
  340.          nb_initializing = TRUE;
  341.          optional_function("undo_cursor_settings", "all");
  342.          optional_function("undo_extension_section_settings");
  343.       }
  344.    }
  345.    else if(callback_msg == DM_OK)
  346.    {
  347.       #  User pressed CLOSE button;
  348.       assign_changes = TRUE;
  349.       nb_initializing = TRUE;
  350.    }
  351.  
  352.    return return_msg;
  353. }
  354.  
  355. local function assign_notebook_changes(nbHand)
  356. {
  357.    local page, name, dlgid;
  358.    local old_sb_flags;
  359.    local apply = FALSE, asked = FALSE;
  360.  
  361.    #  Syntax page assignments must be made before language.pel is written.
  362.  
  363.    notify("Assigning syntax changes.");
  364.    for(page in nbPagePrefix)
  365.    {
  366.       if((nbPagePrefix[page].name == "syntax") && nbPagePrefix[page].dialog_handle)
  367.       {
  368.          optional_function("assign_syntax_changes");
  369.          break;
  370.       }
  371.    }
  372.  
  373.    for(page in nbPagePrefix)
  374.    {
  375.       dlgid = nbPagePrefix[page].dialog_handle;
  376.       if(dlgid)
  377.       {
  378.          name = nbPagePrefix[page].name;
  379.          if((name == "buffer1") || (name == "buffer2") || (name == "buffer3"))
  380.          {
  381.             execute_function(function_id("assign_" name "_changes", dlgid));
  382.             if(comp_buff)
  383.                apply = TRUE;
  384.             if(!language_compiled && comp_buff)
  385.             {
  386.                old_sb_flags = status_bar_flags
  387.                status_bar_flags = or(status_bar_flags, STB_MESSAGES)
  388.                notify("Compiling settings changes")
  389.                status_bar_flags = old_sb_flags
  390.                write_language_data();
  391.                notify("")
  392.             }
  393.          }
  394.          else if((name == "ext") || (name == "compiler") || (name == "template") || (name == "syntax"))
  395.          {
  396.             apply = TRUE;
  397.             if(!language_compiled)
  398.             {
  399.                old_sb_flags = status_bar_flags
  400.                status_bar_flags = or(status_bar_flags, STB_MESSAGES)
  401.                notify("Compiling settings changes")
  402.                status_bar_flags = old_sb_flags
  403.                write_language_data();
  404.                notify("")
  405.             }
  406.          }
  407.          else
  408.          {
  409.             execute_function(function_id("assign_" name "_changes", dlgid));
  410.          }
  411.       }
  412.    }
  413.  
  414.    if(apply)
  415.       apply_type_changes();
  416. }
  417.  
  418. global function apply_type_changes()
  419. {
  420.    local cur_buf           = 0
  421.    local start_buf         = current_buffer
  422.    local first_buf         = current_buffer
  423.  
  424.    local set_bits, save;
  425.  
  426.    local type;
  427.    local MASK              =  BUFFER_OVERTYPE_MODE     +
  428.                               BUFFER_EXPAND_TABS       +
  429.                               BUFFER_TABS_TO_SPACES    +
  430.                               BUFFER_REAL_SPACE_ONLY   +
  431.                               BUFFER_SNAP_TO_EOL       +
  432.                               BUFFER_WP_ENABLED        +
  433.                               BUFFER_WP_CARRY_COMMENTS +
  434.                               BUFFER_WP_WRAP_CONTINUOUS
  435. #                                BUFFER_READ_ONLY        +
  436.  
  437.    # Apply to all buffers.   
  438.    # This gets a little complex.  We need to set the bits that
  439.    # are set, and unset all of the bits that are not set
  440.  
  441.    delete_event(EVENT.NEW_CURNT_BUFFER, "syntax_new_buffer")
  442.  
  443.    notify("Assigning type changes to all buffers.");
  444.    if (!(and(buffer_flags, BUFFER_SYSTEM))) 
  445.    {
  446.       next_buffer("", 0, 1);  # go to a non-system buffer
  447.       first_buf = current_buffer;
  448.    }
  449.    
  450.    do
  451.    {
  452.       type = Type(path_ext(buffer_filename));
  453.       type = (type ? type : DEFAULT);
  454.  
  455.       if(languages_id != type)
  456.          languages_id = (type == DEFAULT) ? "" : type;
  457.  
  458.       if((current_buffer == start_buf) && (Modified(CURRENT_BUFFER)))
  459.          type = CURRENT_BUFFER;
  460.  
  461. #      #  Save the bits that are curently set and we don't change;
  462. #      save = and(buffer_flags, not(flags));
  463. #
  464. #      #  Get the bits that are set and we do change;
  465. #      set_bits = and(BufferFlags(type), flags);
  466. #
  467. #      #  Add the old unchanged bits to the new changed bits;
  468. #      buffer_flags = or(save, set_bits);
  469.  
  470. #  Why isn't set_flag_bits used here???
  471.  
  472.       buffer_flags     = set_flag_bits(buffer_flags, MASK, BufferFlags(type));
  473.       buffer_tabs      = Tabs(type);
  474.       wp_left_margin   = LeftMargin(type);
  475.       wp_right_margin  = RightMargin(type);
  476.       auto_indent_mode = AutoIndent(type);
  477.       set_word_mode(get_word_mode(type));
  478.  
  479.       case_insensitive = !get_case_sensitive(type);
  480.       style_delimiter  = StyleDelimiters(type);
  481.       escape_character = EscapeCharacter(type);
  482.       syntax_highlight = Syntax(type);
  483.    } while( (cur_buf = next_buffer("", 0, 1)) != first_buf )
  484.  
  485.    attach_event_handler(EVENT.NEW_CURNT_BUFFER, "syntax_new_buffer")
  486.  
  487.    current_buffer = start_buf
  488. }
  489.  
  490. local oldIndex;
  491. global function enable_undo( handle, ind )
  492. {
  493.    if ( !nb_initializing && (ind > 0) && (callback_msg != DM_HELPREQUESTED) &&
  494.          (callback_msg != DM_SET_FOCUS) &&  (callback_msg != DM_KILL_FOCUS) &&
  495.          (ind != DI_HELP) && (ind != IDB_UNDO) )
  496.    {
  497.       set_dialog_item( handle, IDB_UNDO, DAC_ENABLE)
  498.       oldIndex = ind
  499.    }
  500. }
  501.  
  502. local nb_apply_to_all[]
  503.  
  504. global function apply_page_to_all( page, func_id )
  505. {
  506.    nb_apply_to_all[ page ] = func_id
  507. }
  508.  
  509. global function apply_to_all()
  510. {
  511.    local page  = 0
  512.    local cw    = current_window
  513.    local cb    = current_buffer
  514.  
  515.    for ( page in nb_apply_to_all )
  516.       {
  517.       current_buffer = cb
  518.       current_window = cw
  519.  
  520.       if ( nb_apply_to_all[ page ] )
  521.          execute_function( nb_apply_to_all[ page ] )
  522.       }
  523. }
  524.  
  525. global function deselect_checks(dlgid)
  526. {
  527.    set_dialog_item(dlgid, IDC_MAKE_DEFAULT, DAC_UNCHECK);
  528.    set_dialog_item(dlgid, IDC_APPLY_TO_ALL, DAC_UNCHECK);
  529. }
  530.